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