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 "ui/views/controls/image_view.h" |
13 #include "ui/views/view.h" | 16 #include "ui/views/view.h" |
14 | 17 |
15 class AutocompleteResultViewModel; | 18 class AutocompleteResultViewModel; |
| 19 |
16 namespace gfx { | 20 namespace gfx { |
17 class Canvas; | 21 class Canvas; |
18 } | 22 } |
19 | 23 |
20 class AutocompleteResultView : public views::View { | 24 class AutocompleteResultView : public views::View, |
| 25 private ui::AnimationDelegate { |
21 public: | 26 public: |
22 enum ResultViewState { | 27 enum ResultViewState { |
23 NORMAL = 0, | 28 NORMAL = 0, |
24 SELECTED, | 29 SELECTED, |
25 HOVERED, | 30 HOVERED, |
26 NUM_STATES | 31 NUM_STATES |
27 }; | 32 }; |
28 | 33 |
29 enum ColorKind { | 34 enum ColorKind { |
30 BACKGROUND = 0, | 35 BACKGROUND = 0, |
31 TEXT, | 36 TEXT, |
32 DIMMED_TEXT, | 37 DIMMED_TEXT, |
33 URL, | 38 URL, |
34 NUM_KINDS | 39 NUM_KINDS |
35 }; | 40 }; |
36 | 41 |
37 AutocompleteResultView(AutocompleteResultViewModel* model, | 42 AutocompleteResultView(AutocompleteResultViewModel* model, |
38 int model_index, | 43 int model_index, |
39 const gfx::Font& font, | 44 const gfx::Font& font, |
40 const gfx::Font& bold_font); | 45 const gfx::Font& bold_font); |
41 virtual ~AutocompleteResultView(); | 46 virtual ~AutocompleteResultView(); |
42 | 47 |
43 static SkColor GetColor(ResultViewState state, ColorKind kind); | 48 static SkColor GetColor(ResultViewState state, ColorKind kind); |
44 | 49 |
45 // Updates the match used to paint the contents of this result view. We copy | 50 // 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 | 51 // the match so that we can continue to paint the last result even after the |
47 // model has changed. | 52 // model has changed. |
48 void SetMatch(const AutocompleteMatch& match); | 53 void SetMatch(const AutocompleteMatch& match); |
49 | 54 |
| 55 void ShowKeyword(bool show_keyword); |
| 56 |
| 57 void Invalidate(); |
| 58 |
| 59 // views::View: |
| 60 virtual gfx::Size GetPreferredSize() OVERRIDE; |
| 61 |
50 protected: | 62 protected: |
51 virtual void PaintMatch(gfx::Canvas* canvas, | 63 virtual void PaintMatch(gfx::Canvas* canvas, |
52 const AutocompleteMatch& match, | 64 const AutocompleteMatch& match, |
53 int x); | 65 int x); |
54 | 66 |
55 // Returns the height of the text portion of the result view. In the base | 67 // 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. | 68 // class, this is the height of one line of text. |
57 virtual int GetTextHeight() const; | 69 virtual int GetTextHeight() const; |
58 | 70 |
59 // Draws the specified |text| into the canvas, using highlighting provided by | 71 // Draws the specified |text| into the canvas, using highlighting provided by |
(...skipping 15 matching lines...) Expand all Loading... |
75 | 87 |
76 struct RunData; | 88 struct RunData; |
77 typedef std::vector<RunData> Runs; | 89 typedef std::vector<RunData> Runs; |
78 | 90 |
79 // Predicate functions for use when sorting the runs. | 91 // Predicate functions for use when sorting the runs. |
80 static bool SortRunsLogically(const RunData& lhs, const RunData& rhs); | 92 static bool SortRunsLogically(const RunData& lhs, const RunData& rhs); |
81 static bool SortRunsVisually(const RunData& lhs, const RunData& rhs); | 93 static bool SortRunsVisually(const RunData& lhs, const RunData& rhs); |
82 | 94 |
83 ResultViewState GetState() const; | 95 ResultViewState GetState() const; |
84 const SkBitmap* GetIcon() const; | 96 const SkBitmap* GetIcon() const; |
| 97 const SkBitmap* GetKeywordIcon() const; |
85 | 98 |
86 // Elides |runs| to fit in |remaining_width|. The runs in |runs| should be in | 99 // Elides |runs| to fit in |remaining_width|. The runs in |runs| should be in |
87 // logical order. | 100 // logical order. |
88 // | 101 // |
89 // When we need to elide a run, the ellipsis will be placed at the end of that | 102 // When we need to elide a run, the ellipsis will be placed at the end of that |
90 // run. This means that if we elide a run whose visual direction is opposite | 103 // run. This means that if we elide a run whose visual direction is opposite |
91 // that of the drawing context, the ellipsis will not be at the "end" of the | 104 // that of the drawing context, the ellipsis will not be at the "end" of the |
92 // drawn string. For example, if in an LTR context we have the LTR run | 105 // drawn string. For example, if in an LTR context we have the LTR run |
93 // "LTR_STRING" and the RTL run "RTL_STRING", the unelided text would be drawn | 106 // "LTR_STRING" and the RTL run "RTL_STRING", the unelided text would be drawn |
94 // like: | 107 // like: |
95 // LTR_STRING GNIRTS_LTR | 108 // LTR_STRING GNIRTS_LTR |
96 // If we need to elide the RTL run, then it will be drawn like: | 109 // If we need to elide the RTL run, then it will be drawn like: |
97 // LTR_STRING ...RTS_LTR | 110 // LTR_STRING ...RTS_LTR |
98 // Instead of: | 111 // Instead of: |
99 // LTR_STRING RTS_LTR... | 112 // LTR_STRING RTS_LTR... |
100 void Elide(Runs* runs, int remaining_width) const; | 113 void Elide(Runs* runs, int remaining_width) const; |
101 | 114 |
102 // views::View: | 115 // views::View: |
103 virtual gfx::Size GetPreferredSize() OVERRIDE; | |
104 virtual void Layout() OVERRIDE; | 116 virtual void Layout() OVERRIDE; |
| 117 virtual void OnBoundsChanged(const gfx::Rect& previous_bounds); |
105 virtual void OnPaint(gfx::Canvas* canvas) OVERRIDE; | 118 virtual void OnPaint(gfx::Canvas* canvas) OVERRIDE; |
106 | 119 |
| 120 // ui::AnimationDelegate: |
| 121 virtual void AnimationProgressed(const ui::Animation* animation) OVERRIDE; |
| 122 |
107 static int default_icon_size_; | 123 static int default_icon_size_; |
108 | 124 |
109 // This row's model and model index. | 125 // This row's model and model index. |
110 AutocompleteResultViewModel* model_; | 126 AutocompleteResultViewModel* model_; |
111 size_t model_index_; | 127 size_t model_index_; |
112 | 128 |
113 const gfx::Font normal_font_; | 129 const gfx::Font normal_font_; |
114 const gfx::Font bold_font_; | 130 const gfx::Font bold_font_; |
115 | 131 |
116 // Width of the ellipsis in the normal font. | 132 // Width of the ellipsis in the normal font. |
117 int ellipsis_width_; | 133 int ellipsis_width_; |
118 | 134 |
119 // A context used for mirroring regions. | 135 // A context used for mirroring regions. |
120 class MirroringContext; | 136 class MirroringContext; |
121 scoped_ptr<MirroringContext> mirroring_context_; | 137 scoped_ptr<MirroringContext> mirroring_context_; |
122 | 138 |
123 AutocompleteMatch match_; | 139 AutocompleteMatch match_; |
124 | 140 |
125 gfx::Rect text_bounds_; | 141 gfx::Rect text_bounds_; |
126 gfx::Rect icon_bounds_; | 142 gfx::Rect icon_bounds_; |
127 | 143 |
| 144 gfx::Rect keyword_text_bounds_; |
| 145 scoped_ptr<views::ImageView> keyword_icon_; |
| 146 |
| 147 scoped_ptr<ui::SlideAnimation> animation_; |
| 148 |
128 DISALLOW_COPY_AND_ASSIGN(AutocompleteResultView); | 149 DISALLOW_COPY_AND_ASSIGN(AutocompleteResultView); |
129 }; | 150 }; |
130 | 151 |
131 #endif // CHROME_BROWSER_UI_VIEWS_AUTOCOMPLETE_AUTOCOMPLETE_RESULT_VIEW_H_ | 152 #endif // CHROME_BROWSER_UI_VIEWS_AUTOCOMPLETE_AUTOCOMPLETE_RESULT_VIEW_H_ |
OLD | NEW |