OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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_AUTOCOMPLETE_AUTOCOMPLETE_RESULT_VIEW_H_ | 5 #ifndef CHROME_BROWSER_UI_VIEWS_AUTOCOMPLETE_AUTOCOMPLETE_RESULT_VIEW_H_ |
6 #define CHROME_BROWSER_UI_VIEWS_AUTOCOMPLETE_AUTOCOMPLETE_RESULT_VIEW_H_ | 6 #define CHROME_BROWSER_UI_VIEWS_AUTOCOMPLETE_AUTOCOMPLETE_RESULT_VIEW_H_ |
7 #pragma once | 7 #pragma once |
8 | 8 |
9 #include "chrome/browser/autocomplete/autocomplete_match.h" | 9 #include "chrome/browser/autocomplete/autocomplete_match.h" |
10 #include "third_party/skia/include/core/SkColor.h" | 10 #include "third_party/skia/include/core/SkColor.h" |
| 11 #include "ui/base/animation/animation_delegate.h" |
| 12 #include "ui/base/animation/slide_animation.h" |
11 #include "ui/gfx/font.h" | 13 #include "ui/gfx/font.h" |
12 #include "ui/gfx/rect.h" | 14 #include "ui/gfx/rect.h" |
| 15 #include "views/controls/button/image_button.h" |
13 #include "views/view.h" | 16 #include "views/view.h" |
14 | 17 |
15 class AutocompleteResultViewModel; | 18 class AutocompleteResultViewModel; |
| 19 class AutocompletePopupModel; |
| 20 |
16 namespace gfx { | 21 namespace gfx { |
17 class Canvas; | 22 class Canvas; |
18 } | 23 } |
19 | 24 |
20 class AutocompleteResultView : public views::View { | 25 class AutocompleteResultView : public views::View, |
| 26 private ui::AnimationDelegate, |
| 27 private views::ButtonListener { |
21 public: | 28 public: |
22 enum ResultViewState { | 29 enum ResultViewState { |
23 NORMAL = 0, | 30 NORMAL = 0, |
24 SELECTED, | 31 SELECTED, |
25 HOVERED, | 32 HOVERED, |
26 NUM_STATES | 33 NUM_STATES |
27 }; | 34 }; |
28 | 35 |
29 enum ColorKind { | 36 enum ColorKind { |
30 BACKGROUND = 0, | 37 BACKGROUND = 0, |
31 TEXT, | 38 TEXT, |
32 DIMMED_TEXT, | 39 DIMMED_TEXT, |
33 URL, | 40 URL, |
34 NUM_KINDS | 41 NUM_KINDS |
35 }; | 42 }; |
36 | 43 |
| 44 enum ViewID { |
| 45 VIEW_ID_KEYWORD = 1, |
| 46 }; |
| 47 |
37 AutocompleteResultView(AutocompleteResultViewModel* model, | 48 AutocompleteResultView(AutocompleteResultViewModel* model, |
38 int model_index, | 49 int model_index, |
39 const gfx::Font& font, | 50 const gfx::Font& font, |
40 const gfx::Font& bold_font); | 51 const gfx::Font& bold_font); |
41 virtual ~AutocompleteResultView(); | 52 virtual ~AutocompleteResultView(); |
42 | 53 |
43 static SkColor GetColor(ResultViewState state, ColorKind kind); | 54 static SkColor GetColor(ResultViewState state, ColorKind kind); |
44 | 55 |
45 // Updates the match used to paint the contents of this result view. We copy | 56 // Updates the match used to paint the contents of this result view. We copy |
46 // the match so that we can continue to paint the last result even after the | 57 // the match so that we can continue to paint the last result even after the |
47 // model has changed. | 58 // model has changed. |
48 void SetMatch(const AutocompleteMatch& match); | 59 void SetMatch(const AutocompleteMatch& match); |
49 | 60 |
| 61 void set_popup_model(AutocompletePopupModel* popup_model) { |
| 62 popup_model_ = popup_model; |
| 63 } |
| 64 |
| 65 void ShowKeyword(bool show_keyword); |
| 66 |
| 67 // views::View: |
| 68 virtual gfx::Size GetPreferredSize() OVERRIDE; |
| 69 |
50 protected: | 70 protected: |
51 virtual void PaintMatch(gfx::Canvas* canvas, | 71 virtual void PaintMatch(gfx::Canvas* canvas, |
52 const AutocompleteMatch& match, | 72 const AutocompleteMatch& match, |
53 int x); | 73 int x); |
54 | 74 |
55 // Returns the height of the text portion of the result view. In the base | 75 // Returns the height of the text portion of the result view. In the base |
56 // class, this is the height of one line of text. | 76 // class, this is the height of one line of text. |
57 virtual int GetTextHeight() const; | 77 virtual int GetTextHeight() const; |
58 | 78 |
59 // Draws the specified |text| into the canvas, using highlighting provided by | 79 // Draws the specified |text| into the canvas, using highlighting provided by |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
93 // "LTR_STRING" and the RTL run "RTL_STRING", the unelided text would be drawn | 113 // "LTR_STRING" and the RTL run "RTL_STRING", the unelided text would be drawn |
94 // like: | 114 // like: |
95 // LTR_STRING GNIRTS_LTR | 115 // LTR_STRING GNIRTS_LTR |
96 // If we need to elide the RTL run, then it will be drawn like: | 116 // If we need to elide the RTL run, then it will be drawn like: |
97 // LTR_STRING ...RTS_LTR | 117 // LTR_STRING ...RTS_LTR |
98 // Instead of: | 118 // Instead of: |
99 // LTR_STRING RTS_LTR... | 119 // LTR_STRING RTS_LTR... |
100 void Elide(Runs* runs, int remaining_width) const; | 120 void Elide(Runs* runs, int remaining_width) const; |
101 | 121 |
102 // views::View: | 122 // views::View: |
103 virtual gfx::Size GetPreferredSize() OVERRIDE; | |
104 virtual void Layout() OVERRIDE; | 123 virtual void Layout() OVERRIDE; |
105 virtual void OnPaint(gfx::Canvas* canvas) OVERRIDE; | 124 virtual void OnPaint(gfx::Canvas* canvas) OVERRIDE; |
106 | 125 |
| 126 // ui::AnimationDelegate: |
| 127 virtual void AnimationProgressed(const ui::Animation* animation) OVERRIDE; |
| 128 |
| 129 // views::ButtonListener: |
| 130 virtual void ButtonPressed(views::Button* sender, |
| 131 const views::Event& event) OVERRIDE; |
| 132 |
107 static int default_icon_size_; | 133 static int default_icon_size_; |
108 | 134 |
109 // This row's model and model index. | 135 // This row's model and model index. |
110 AutocompleteResultViewModel* model_; | 136 AutocompleteResultViewModel* model_; |
| 137 AutocompletePopupModel* popup_model_; |
111 size_t model_index_; | 138 size_t model_index_; |
112 | 139 |
113 const gfx::Font normal_font_; | 140 const gfx::Font normal_font_; |
114 const gfx::Font bold_font_; | 141 const gfx::Font bold_font_; |
115 | 142 |
116 // Width of the ellipsis in the normal font. | 143 // Width of the ellipsis in the normal font. |
117 int ellipsis_width_; | 144 int ellipsis_width_; |
118 | 145 |
119 // A context used for mirroring regions. | 146 // A context used for mirroring regions. |
120 class MirroringContext; | 147 class MirroringContext; |
121 scoped_ptr<MirroringContext> mirroring_context_; | 148 scoped_ptr<MirroringContext> mirroring_context_; |
122 | 149 |
123 AutocompleteMatch match_; | 150 AutocompleteMatch match_; |
124 | 151 |
125 gfx::Rect text_bounds_; | 152 gfx::Rect text_bounds_; |
126 gfx::Rect icon_bounds_; | 153 gfx::Rect icon_bounds_; |
127 | 154 |
| 155 gfx::Rect keyword_text_bounds_; |
| 156 scoped_ptr<views::ImageButton> keyword_button_; |
| 157 |
| 158 scoped_ptr<ui::SlideAnimation> animation_; |
| 159 |
128 DISALLOW_COPY_AND_ASSIGN(AutocompleteResultView); | 160 DISALLOW_COPY_AND_ASSIGN(AutocompleteResultView); |
129 }; | 161 }; |
130 | 162 |
131 #endif // CHROME_BROWSER_UI_VIEWS_AUTOCOMPLETE_AUTOCOMPLETE_RESULT_VIEW_H_ | 163 #endif // CHROME_BROWSER_UI_VIEWS_AUTOCOMPLETE_AUTOCOMPLETE_RESULT_VIEW_H_ |
OLD | NEW |