Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #ifndef CHROME_BROWSER_UI_VIEWS_OMNIBOX_OMNIBOX_RESULT_VIEW_H_ | 5 #ifndef CHROME_BROWSER_UI_VIEWS_OMNIBOX_OMNIBOX_RESULT_VIEW_H_ |
| 6 #define CHROME_BROWSER_UI_VIEWS_OMNIBOX_OMNIBOX_RESULT_VIEW_H_ | 6 #define CHROME_BROWSER_UI_VIEWS_OMNIBOX_OMNIBOX_RESULT_VIEW_H_ |
| 7 | 7 |
| 8 #include <vector> | 8 #include <vector> |
| 9 | 9 |
| 10 #include "base/gtest_prod_util.h" | 10 #include "base/gtest_prod_util.h" |
| 11 #include "chrome/browser/bitmap_fetcher/bitmap_fetcher_service.h" | 11 #include "chrome/browser/bitmap_fetcher/bitmap_fetcher_service.h" |
| 12 #include "components/omnibox/autocomplete_match.h" | 12 #include "components/omnibox/autocomplete_match.h" |
| 13 #include "components/omnibox/suggestion_answer.h" | |
| 13 #include "third_party/skia/include/core/SkColor.h" | 14 #include "third_party/skia/include/core/SkColor.h" |
| 14 #include "ui/gfx/animation/animation_delegate.h" | 15 #include "ui/gfx/animation/animation_delegate.h" |
| 15 #include "ui/gfx/animation/slide_animation.h" | 16 #include "ui/gfx/animation/slide_animation.h" |
| 16 #include "ui/gfx/font_list.h" | 17 #include "ui/gfx/font_list.h" |
| 17 #include "ui/gfx/geometry/rect.h" | 18 #include "ui/gfx/geometry/rect.h" |
| 18 #include "ui/views/controls/image_view.h" | 19 #include "ui/views/controls/image_view.h" |
| 19 #include "ui/views/view.h" | 20 #include "ui/views/view.h" |
| 20 | 21 |
| 21 class LocationBarView; | 22 class LocationBarView; |
| 22 class OmniboxPopupContentsView; | 23 class OmniboxPopupContentsView; |
| 24 struct TextStyle; | |
| 23 | 25 |
| 24 namespace gfx { | 26 namespace gfx { |
| 25 class Canvas; | 27 class Canvas; |
| 26 class RenderText; | 28 class RenderText; |
| 27 } | 29 } |
| 28 | 30 |
| 29 class OmniboxResultView : public views::View, | 31 class OmniboxResultView : public views::View, |
| 30 private gfx::AnimationDelegate { | 32 private gfx::AnimationDelegate { |
| 31 public: | 33 public: |
| 32 // Keep these ordered from least dominant (normal) to most dominant | 34 // Keep these ordered from least dominant (normal) to most dominant |
| 33 // (selected). | 35 // (selected). |
| 34 enum ResultViewState { | 36 enum ResultViewState { |
| 35 NORMAL = 0, | 37 NORMAL = 0, |
| 36 HOVERED, | 38 HOVERED, |
| 37 SELECTED, | 39 SELECTED, |
| 38 NUM_STATES | 40 NUM_STATES |
| 39 }; | 41 }; |
| 40 | 42 |
| 41 enum ColorKind { | 43 enum ColorKind { |
| 42 BACKGROUND = 0, | 44 BACKGROUND = 0, |
| 43 TEXT, | 45 TEXT, |
| 44 DIMMED_TEXT, | 46 DIMMED_TEXT, |
| 45 URL, | 47 URL, |
| 46 DIVIDER, | 48 DIVIDER, |
| 47 NUM_KINDS | 49 NUM_KINDS |
| 48 }; | 50 }; |
| 49 | 51 |
| 52 // The minimum distance between the top and bottom of the {icon|text} and the | |
| 53 // top or bottom of the row. | |
| 54 enum { | |
| 55 kMinimumIconVerticalPadding = 2, | |
|
Peter Kasting
2015/03/17 22:01:44
The icon padding should still be a file-scoped con
dschuyler
2015/03/17 22:57:55
Done.
| |
| 56 kMinimumTextVerticalPadding = 3, | |
|
Peter Kasting
2015/03/17 22:01:44
Don't use the "enum hack" to declare constants lik
dschuyler
2015/03/17 22:57:55
Done.
| |
| 57 }; | |
| 58 | |
| 50 OmniboxResultView(OmniboxPopupContentsView* model, | 59 OmniboxResultView(OmniboxPopupContentsView* model, |
| 51 int model_index, | 60 int model_index, |
| 52 LocationBarView* location_bar_view, | 61 LocationBarView* location_bar_view, |
| 53 const gfx::FontList& font_list); | 62 const gfx::FontList& font_list); |
| 54 ~OmniboxResultView() override; | 63 ~OmniboxResultView() override; |
| 55 | 64 |
| 56 SkColor GetColor(ResultViewState state, ColorKind kind) const; | 65 SkColor GetColor(ResultViewState state, ColorKind kind) const; |
| 57 | 66 |
| 58 // Updates the match used to paint the contents of this result view. We copy | 67 // Updates the match used to paint the contents of this result view. We copy |
| 59 // the match so that we can continue to paint the last result even after the | 68 // the match so that we can continue to paint the last result even after the |
| (...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 110 // |classifications| and |force_dim| are used to style the text. | 119 // |classifications| and |force_dim| are used to style the text. |
| 111 scoped_ptr<gfx::RenderText> CreateClassifiedRenderText( | 120 scoped_ptr<gfx::RenderText> CreateClassifiedRenderText( |
| 112 const base::string16& text, | 121 const base::string16& text, |
| 113 const ACMatchClassifications& classifications, | 122 const ACMatchClassifications& classifications, |
| 114 bool force_dim) const; | 123 bool force_dim) const; |
| 115 | 124 |
| 116 const gfx::Rect& text_bounds() const { return text_bounds_; } | 125 const gfx::Rect& text_bounds() const { return text_bounds_; } |
| 117 | 126 |
| 118 void set_edge_item_padding(int value) { edge_item_padding_ = value; } | 127 void set_edge_item_padding(int value) { edge_item_padding_ = value; } |
| 119 void set_item_padding(int value) { item_padding_ = value; } | 128 void set_item_padding(int value) { item_padding_ = value; } |
| 120 void set_minimum_text_vertical_padding(int value) { | |
| 121 minimum_text_vertical_padding_ = value; | |
| 122 } | |
| 123 | 129 |
| 124 private: | 130 private: |
| 125 // views::View: | 131 // views::View: |
| 126 const char* GetClassName() const override; | 132 const char* GetClassName() const override; |
| 127 | 133 |
| 128 gfx::ImageSkia GetIcon() const; | 134 gfx::ImageSkia GetIcon() const; |
| 129 const gfx::ImageSkia* GetKeywordIcon() const; | 135 const gfx::ImageSkia* GetKeywordIcon() const; |
| 130 | 136 |
| 131 // Whether to render only the keyword match. Returns true if |match_| has an | 137 // Whether to render only the keyword match. Returns true if |match_| has an |
| 132 // associated keyword match that has been animated so close to the start that | 138 // associated keyword match that has been animated so close to the start that |
| (...skipping 15 matching lines...) Expand all Loading... | |
| 148 // gfx::AnimationDelegate: | 154 // gfx::AnimationDelegate: |
| 149 void AnimationProgressed(const gfx::Animation* animation) override; | 155 void AnimationProgressed(const gfx::Animation* animation) override; |
| 150 | 156 |
| 151 // Returns the offset at which the contents of the |match| should be displayed | 157 // Returns the offset at which the contents of the |match| should be displayed |
| 152 // within the text bounds. The directionality of UI and match contents is used | 158 // within the text bounds. The directionality of UI and match contents is used |
| 153 // to determine the offset relative to the correct edge. | 159 // to determine the offset relative to the correct edge. |
| 154 int GetDisplayOffset(const AutocompleteMatch& match, | 160 int GetDisplayOffset(const AutocompleteMatch& match, |
| 155 bool is_ui_rtl, | 161 bool is_ui_rtl, |
| 156 bool is_match_contents_rtl) const; | 162 bool is_match_contents_rtl) const; |
| 157 | 163 |
| 164 int StyleAnswerText(gfx::RenderText* render_text, | |
| 165 int offset, | |
| 166 const SuggestionAnswer::TextField& text_field) const; | |
| 167 | |
| 168 int GetAnswerLineHeight() const; | |
| 169 int GetContentLineHeight() const; | |
| 170 SkColor GetStateColor(const TextStyle& text_style) const; | |
| 171 void AppendAnswerText(gfx::RenderText* render_text, | |
| 172 const SuggestionAnswer::TextField& text_field); | |
| 173 | |
| 158 static int default_icon_size_; | 174 static int default_icon_size_; |
| 159 | 175 |
| 160 // Default values cached here, may be overridden using the setters above. | 176 // Default values cached here, may be overridden using the setters above. |
| 161 int edge_item_padding_; | 177 int edge_item_padding_; |
| 162 int item_padding_; | 178 int item_padding_; |
| 163 int minimum_text_vertical_padding_; | |
| 164 | 179 |
| 165 // This row's model and model index. | 180 // This row's model and model index. |
| 166 OmniboxPopupContentsView* model_; | 181 OmniboxPopupContentsView* model_; |
| 167 size_t model_index_; | 182 size_t model_index_; |
| 168 | 183 |
| 169 LocationBarView* location_bar_view_; | 184 LocationBarView* location_bar_view_; |
| 170 // Note: image_service_ may be null in some unit tests. | 185 // Note: image_service_ may be null in some unit tests. |
| 171 BitmapFetcherService* image_service_; | 186 BitmapFetcherService* image_service_; |
| 172 | 187 |
| 173 const gfx::FontList font_list_; | 188 const gfx::FontList font_list_; |
| (...skipping 27 matching lines...) Expand all Loading... | |
| 201 mutable scoped_ptr<gfx::RenderText> keyword_description_rendertext_; | 216 mutable scoped_ptr<gfx::RenderText> keyword_description_rendertext_; |
| 202 | 217 |
| 203 mutable int separator_width_; | 218 mutable int separator_width_; |
| 204 | 219 |
| 205 base::WeakPtrFactory<OmniboxResultView> weak_ptr_factory_; | 220 base::WeakPtrFactory<OmniboxResultView> weak_ptr_factory_; |
| 206 | 221 |
| 207 DISALLOW_COPY_AND_ASSIGN(OmniboxResultView); | 222 DISALLOW_COPY_AND_ASSIGN(OmniboxResultView); |
| 208 }; | 223 }; |
| 209 | 224 |
| 210 #endif // CHROME_BROWSER_UI_VIEWS_OMNIBOX_OMNIBOX_RESULT_VIEW_H_ | 225 #endif // CHROME_BROWSER_UI_VIEWS_OMNIBOX_OMNIBOX_RESULT_VIEW_H_ |
| OLD | NEW |