1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #ifndef CHROME_BROWSER_UI_VIEWS_OMNIBOX_OMNIBOX_RESULT_VIEW_H_
6 #define CHROME_BROWSER_UI_VIEWS_OMNIBOX_OMNIBOX_RESULT_VIEW_H_
10 #include "base/gtest_prod_util.h"
11 #include "chrome/browser/autocomplete/autocomplete_match.h"
12 #include "third_party/skia/include/core/SkColor.h"
13 #include "ui/gfx/animation/animation_delegate.h"
14 #include "ui/gfx/animation/slide_animation.h"
15 #include "ui/gfx/font_list.h"
16 #include "ui/gfx/rect.h"
17 #include "ui/views/controls/image_view.h"
18 #include "ui/views/view.h"
20 class LocationBarView
;
21 class OmniboxPopupContentsView
;
28 class OmniboxResultView
: public views::View
,
29 private gfx::AnimationDelegate
{
31 // Keep these ordered from least dominant (normal) to most dominant
33 enum ResultViewState
{
49 OmniboxResultView(OmniboxPopupContentsView
* model
,
51 LocationBarView
* location_bar_view
,
52 const gfx::FontList
& font_list
);
53 virtual ~OmniboxResultView();
55 SkColor
GetColor(ResultViewState state
, ColorKind kind
) const;
57 // Updates the match used to paint the contents of this result view. We copy
58 // the match so that we can continue to paint the last result even after the
60 void SetMatch(const AutocompleteMatch
& match
);
62 void ShowKeyword(bool show_keyword
);
67 virtual gfx::Size
GetPreferredSize() const OVERRIDE
;
69 ResultViewState
GetState() const;
71 // Returns the height of the text portion of the result view. In the base
72 // class, this is the height of one line of text.
73 virtual int GetTextHeight() const;
75 // Returns the display width required for the match contents.
76 int GetMatchContentsWidth() const;
79 // Paints the given |match| using the RenderText instances |contents| and
80 // |description| at offset |x| in the bounds of this view.
81 virtual void PaintMatch(const AutocompleteMatch
& match
,
82 gfx::RenderText
* contents
,
83 gfx::RenderText
* description
,
87 // Draws given |render_text| on |canvas| at given location (|x|, |y|).
88 // |contents| indicates whether the |render_text| is for the match contents
89 // (rather than the separator or the description). Additional properties from
90 // |match| are used to render Infinite suggestions correctly. If |max_width|
91 // is a non-negative number, the text will be elided to fit within
92 // |max_width|. Returns the x position to the right of the string.
93 int DrawRenderText(const AutocompleteMatch
& match
,
94 gfx::RenderText
* render_text
,
101 // Creates a RenderText with given |text| and rendering defaults.
102 scoped_ptr
<gfx::RenderText
> CreateRenderText(
103 const base::string16
& text
) const;
105 // Creates a RenderText with default rendering for the given |text|. The
106 // |classifications| and |force_dim| are used to style the text.
107 scoped_ptr
<gfx::RenderText
> CreateClassifiedRenderText(
108 const base::string16
& text
,
109 const ACMatchClassifications
& classifications
,
110 bool force_dim
) const;
112 const gfx::Rect
& text_bounds() const { return text_bounds_
; }
114 void set_edge_item_padding(int value
) { edge_item_padding_
= value
; }
115 void set_item_padding(int value
) { item_padding_
= value
; }
116 void set_minimum_text_vertical_padding(int value
) {
117 minimum_text_vertical_padding_
= value
;
121 gfx::ImageSkia
GetIcon() const;
122 const gfx::ImageSkia
* GetKeywordIcon() const;
124 // Whether to render only the keyword match. Returns true if |match_| has an
125 // associated keyword match that has been animated so close to the start that
126 // the keyword match will hide even the icon of the regular match.
127 bool ShowOnlyKeywordMatch() const;
129 // Resets all RenderTexts for contents and description of the |match_| and its
130 // associated keyword match.
131 void ResetRenderTexts() const;
133 // Initializes |contents_rendertext_| if it is NULL.
134 void InitContentsRenderTextIfNecessary() const;
137 virtual void Layout() OVERRIDE
;
138 virtual void OnBoundsChanged(const gfx::Rect
& previous_bounds
) OVERRIDE
;
139 virtual void OnPaint(gfx::Canvas
* canvas
) OVERRIDE
;
141 // gfx::AnimationDelegate:
142 virtual void AnimationProgressed(const gfx::Animation
* animation
) OVERRIDE
;
144 // Returns the offset at which the contents of the |match| should be displayed
145 // within the text bounds. The directionality of UI and match contents is used
146 // to determine the offset relative to the correct edge.
147 int GetDisplayOffset(const AutocompleteMatch
& match
,
149 bool is_match_contents_rtl
) const;
151 static int default_icon_size_
;
153 // Default values cached here, may be overridden using the setters above.
154 int edge_item_padding_
;
156 int minimum_text_vertical_padding_
;
158 // This row's model and model index.
159 OmniboxPopupContentsView
* model_
;
162 LocationBarView
* location_bar_view_
;
164 const gfx::FontList font_list_
;
167 // A context used for mirroring regions.
168 class MirroringContext
;
169 scoped_ptr
<MirroringContext
> mirroring_context_
;
171 AutocompleteMatch match_
;
173 gfx::Rect text_bounds_
;
174 gfx::Rect icon_bounds_
;
176 gfx::Rect keyword_text_bounds_
;
177 scoped_ptr
<views::ImageView
> keyword_icon_
;
179 scoped_ptr
<gfx::SlideAnimation
> animation_
;
181 // We preserve these RenderTexts so that we won't recreate them on every call
182 // to GetMatchContentsWidth() or OnPaint().
183 mutable scoped_ptr
<gfx::RenderText
> contents_rendertext_
;
184 mutable scoped_ptr
<gfx::RenderText
> description_rendertext_
;
185 mutable scoped_ptr
<gfx::RenderText
> separator_rendertext_
;
186 mutable scoped_ptr
<gfx::RenderText
> keyword_contents_rendertext_
;
187 mutable scoped_ptr
<gfx::RenderText
> keyword_description_rendertext_
;
189 mutable int separator_width_
;
191 DISALLOW_COPY_AND_ASSIGN(OmniboxResultView
);
194 #endif // CHROME_BROWSER_UI_VIEWS_OMNIBOX_OMNIBOX_RESULT_VIEW_H_