1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194
|
// Copyright (c) 2012 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef CHROME_BROWSER_UI_VIEWS_OMNIBOX_OMNIBOX_RESULT_VIEW_H_
#define CHROME_BROWSER_UI_VIEWS_OMNIBOX_OMNIBOX_RESULT_VIEW_H_
#include <vector>
#include "base/gtest_prod_util.h"
#include "components/omnibox/autocomplete_match.h"
#include "third_party/skia/include/core/SkColor.h"
#include "ui/gfx/animation/animation_delegate.h"
#include "ui/gfx/animation/slide_animation.h"
#include "ui/gfx/font_list.h"
#include "ui/gfx/geometry/rect.h"
#include "ui/views/controls/image_view.h"
#include "ui/views/view.h"
class LocationBarView;
class OmniboxPopupContentsView;
namespace gfx {
class Canvas;
class RenderText;
}
class OmniboxResultView : public views::View,
private gfx::AnimationDelegate {
public:
// Keep these ordered from least dominant (normal) to most dominant
// (selected).
enum ResultViewState {
NORMAL = 0,
HOVERED,
SELECTED,
NUM_STATES
};
enum ColorKind {
BACKGROUND = 0,
TEXT,
DIMMED_TEXT,
URL,
DIVIDER,
NUM_KINDS
};
OmniboxResultView(OmniboxPopupContentsView* model,
int model_index,
LocationBarView* location_bar_view,
const gfx::FontList& font_list);
~OmniboxResultView() override;
SkColor GetColor(ResultViewState state, ColorKind kind) const;
// Updates the match used to paint the contents of this result view. We copy
// the match so that we can continue to paint the last result even after the
// model has changed.
void SetMatch(const AutocompleteMatch& match);
void ShowKeyword(bool show_keyword);
void Invalidate();
// views::View:
gfx::Size GetPreferredSize() const override;
ResultViewState GetState() const;
// Returns the height of the text portion of the result view. In the base
// class, this is the height of one line of text.
virtual int GetTextHeight() const;
// Returns the display width required for the match contents.
int GetMatchContentsWidth() const;
protected:
// Paints the given |match| using the RenderText instances |contents| and
// |description| at offset |x| in the bounds of this view.
virtual void PaintMatch(const AutocompleteMatch& match,
gfx::RenderText* contents,
gfx::RenderText* description,
gfx::Canvas* canvas,
int x) const;
// Draws given |render_text| on |canvas| at given location (|x|, |y|).
// |contents| indicates whether the |render_text| is for the match contents
// (rather than the separator or the description). Additional properties from
// |match| are used to render Infinite suggestions correctly. If |max_width|
// is a non-negative number, the text will be elided to fit within
// |max_width|. Returns the x position to the right of the string.
int DrawRenderText(const AutocompleteMatch& match,
gfx::RenderText* render_text,
bool contents,
gfx::Canvas* canvas,
int x,
int y,
int max_width) const;
// Creates a RenderText with given |text| and rendering defaults.
scoped_ptr<gfx::RenderText> CreateRenderText(
const base::string16& text) const;
// Creates a RenderText with default rendering for the given |text|. The
// |classifications| and |force_dim| are used to style the text.
scoped_ptr<gfx::RenderText> CreateClassifiedRenderText(
const base::string16& text,
const ACMatchClassifications& classifications,
bool force_dim) const;
const gfx::Rect& text_bounds() const { return text_bounds_; }
void set_edge_item_padding(int value) { edge_item_padding_ = value; }
void set_item_padding(int value) { item_padding_ = value; }
void set_minimum_text_vertical_padding(int value) {
minimum_text_vertical_padding_ = value;
}
private:
gfx::ImageSkia GetIcon() const;
const gfx::ImageSkia* GetKeywordIcon() const;
// Whether to render only the keyword match. Returns true if |match_| has an
// associated keyword match that has been animated so close to the start that
// the keyword match will hide even the icon of the regular match.
bool ShowOnlyKeywordMatch() const;
// Resets all RenderTexts for contents and description of the |match_| and its
// associated keyword match.
void ResetRenderTexts() const;
// Initializes |contents_rendertext_| if it is NULL.
void InitContentsRenderTextIfNecessary() const;
// views::View:
void Layout() override;
void OnBoundsChanged(const gfx::Rect& previous_bounds) override;
void OnPaint(gfx::Canvas* canvas) override;
// gfx::AnimationDelegate:
void AnimationProgressed(const gfx::Animation* animation) override;
// Returns the offset at which the contents of the |match| should be displayed
// within the text bounds. The directionality of UI and match contents is used
// to determine the offset relative to the correct edge.
int GetDisplayOffset(const AutocompleteMatch& match,
bool is_ui_rtl,
bool is_match_contents_rtl) const;
static int default_icon_size_;
// Default values cached here, may be overridden using the setters above.
int edge_item_padding_;
int item_padding_;
int minimum_text_vertical_padding_;
// This row's model and model index.
OmniboxPopupContentsView* model_;
size_t model_index_;
LocationBarView* location_bar_view_;
const gfx::FontList font_list_;
int font_height_;
// A context used for mirroring regions.
class MirroringContext;
scoped_ptr<MirroringContext> mirroring_context_;
AutocompleteMatch match_;
gfx::Rect text_bounds_;
gfx::Rect icon_bounds_;
gfx::Rect keyword_text_bounds_;
scoped_ptr<views::ImageView> keyword_icon_;
scoped_ptr<gfx::SlideAnimation> animation_;
// We preserve these RenderTexts so that we won't recreate them on every call
// to GetMatchContentsWidth() or OnPaint().
mutable scoped_ptr<gfx::RenderText> contents_rendertext_;
mutable scoped_ptr<gfx::RenderText> description_rendertext_;
mutable scoped_ptr<gfx::RenderText> separator_rendertext_;
mutable scoped_ptr<gfx::RenderText> keyword_contents_rendertext_;
mutable scoped_ptr<gfx::RenderText> keyword_description_rendertext_;
mutable int separator_width_;
DISALLOW_COPY_AND_ASSIGN(OmniboxResultView);
};
#endif // CHROME_BROWSER_UI_VIEWS_OMNIBOX_OMNIBOX_RESULT_VIEW_H_
|