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