Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(352)

Side by Side Diff: chrome/browser/ui/views/autocomplete/autocomplete_result_view.h

Issue 10384007: First stab at touch optimized omnibox auto-complete per sgabriel's mocks. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Address review comments. Created 8 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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_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" 11 #include "ui/base/animation/animation_delegate.h"
12 #include "ui/base/animation/slide_animation.h" 12 #include "ui/base/animation/slide_animation.h"
13 #include "ui/gfx/font.h" 13 #include "ui/gfx/font.h"
14 #include "ui/gfx/rect.h" 14 #include "ui/gfx/rect.h"
15 #include "ui/views/controls/image_view.h" 15 #include "ui/views/controls/image_view.h"
16 #include "ui/views/view.h" 16 #include "ui/views/view.h"
17 17
18 class AutocompleteResultViewModel; 18 class AutocompleteResultViewModel;
19 19
20 namespace gfx { 20 namespace gfx {
21 class Canvas; 21 class Canvas;
22 } 22 }
23 23
24 class AutocompleteResultView : public views::View, 24 class AutocompleteResultView : public views::View,
25 private ui::AnimationDelegate { 25 private ui::AnimationDelegate {
26 public: 26 public:
27 // Keep these ordered from least dominant (normal) to most dominant
28 // (selected).
27 enum ResultViewState { 29 enum ResultViewState {
28 NORMAL = 0, 30 NORMAL = 0,
31 HOVERED,
29 SELECTED, 32 SELECTED,
30 HOVERED,
31 NUM_STATES 33 NUM_STATES
32 }; 34 };
33 35
34 enum ColorKind { 36 enum ColorKind {
35 BACKGROUND = 0, 37 BACKGROUND = 0,
36 TEXT, 38 TEXT,
37 DIMMED_TEXT, 39 DIMMED_TEXT,
38 URL, 40 URL,
41 DIVIDER,
39 NUM_KINDS 42 NUM_KINDS
40 }; 43 };
41 44
42 AutocompleteResultView(AutocompleteResultViewModel* model, 45 AutocompleteResultView(AutocompleteResultViewModel* model,
43 int model_index, 46 int model_index,
44 const gfx::Font& font, 47 const gfx::Font& font,
45 const gfx::Font& bold_font); 48 const gfx::Font& bold_font);
46 virtual ~AutocompleteResultView(); 49 virtual ~AutocompleteResultView();
47 50
48 static SkColor GetColor(ResultViewState state, ColorKind kind); 51 static SkColor GetColor(ResultViewState state, ColorKind kind);
49 52
50 // Updates the match used to paint the contents of this result view. We copy 53 // 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 54 // the match so that we can continue to paint the last result even after the
52 // model has changed. 55 // model has changed.
53 void SetMatch(const AutocompleteMatch& match); 56 void SetMatch(const AutocompleteMatch& match);
54 57
55 void ShowKeyword(bool show_keyword); 58 void ShowKeyword(bool show_keyword);
56 59
57 void Invalidate(); 60 void Invalidate();
58 61
59 // views::View: 62 // views::View:
60 virtual gfx::Size GetPreferredSize() OVERRIDE; 63 virtual gfx::Size GetPreferredSize() OVERRIDE;
61 64
65 ResultViewState GetState() const;
66
62 protected: 67 protected:
63 virtual void PaintMatch(gfx::Canvas* canvas, 68 virtual void PaintMatch(gfx::Canvas* canvas,
64 const AutocompleteMatch& match, 69 const AutocompleteMatch& match,
65 int x); 70 int x);
66 71
67 // Returns the height of the text portion of the result view. In the base 72 // 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. 73 // class, this is the height of one line of text.
69 virtual int GetTextHeight() const; 74 virtual int GetTextHeight() const;
70 75
71 // Draws the specified |text| into the canvas, using highlighting provided by 76 // Draws the specified |text| into the canvas, using highlighting provided by
72 // |classifications|. If |force_dim| is true, ACMatchClassification::DIM is 77 // |classifications|. If |force_dim| is true, ACMatchClassification::DIM is
73 // added to all of the classifications. Returns the x position to the right 78 // added to all of the classifications. Returns the x position to the right
74 // of the string. 79 // of the string.
75 int DrawString(gfx::Canvas* canvas, 80 int DrawString(gfx::Canvas* canvas,
76 const string16& text, 81 const string16& text,
77 const ACMatchClassifications& classifications, 82 const ACMatchClassifications& classifications,
78 bool force_dim, 83 bool force_dim,
79 int x, 84 int x,
80 int y); 85 int y);
81 86
82 const gfx::Rect& text_bounds() const { return text_bounds_; } 87 const gfx::Rect& text_bounds() const { return text_bounds_; }
83 88
89 void set_edge_item_padding(int value) { edge_item_padding_ = value; }
90 void set_item_padding(int value) { item_padding_ = value; }
91 void set_minimum_text_vertical_padding(int value) {
92 minimum_text_vertical_padding_ = value;
93 }
94
84 private: 95 private:
85 struct ClassificationData; 96 struct ClassificationData;
86 typedef std::vector<ClassificationData> Classifications; 97 typedef std::vector<ClassificationData> Classifications;
87 98
88 struct RunData; 99 struct RunData;
89 typedef std::vector<RunData> Runs; 100 typedef std::vector<RunData> Runs;
90 101
91 // Predicate functions for use when sorting the runs. 102 // Predicate functions for use when sorting the runs.
92 static bool SortRunsLogically(const RunData& lhs, const RunData& rhs); 103 static bool SortRunsLogically(const RunData& lhs, const RunData& rhs);
93 static bool SortRunsVisually(const RunData& lhs, const RunData& rhs); 104 static bool SortRunsVisually(const RunData& lhs, const RunData& rhs);
94 105
95 ResultViewState GetState() const;
96 const SkBitmap* GetIcon() const; 106 const SkBitmap* GetIcon() const;
97 const SkBitmap* GetKeywordIcon() const; 107 const SkBitmap* GetKeywordIcon() const;
98 108
99 // Elides |runs| to fit in |remaining_width|. The runs in |runs| should be in 109 // Elides |runs| to fit in |remaining_width|. The runs in |runs| should be in
100 // logical order. 110 // logical order.
101 // 111 //
102 // When we need to elide a run, the ellipsis will be placed at the end of that 112 // 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 113 // 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 114 // 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 115 // 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 116 // "LTR_STRING" and the RTL run "RTL_STRING", the unelided text would be drawn
107 // like: 117 // like:
108 // LTR_STRING GNIRTS_LTR 118 // LTR_STRING GNIRTS_LTR
109 // If we need to elide the RTL run, then it will be drawn like: 119 // If we need to elide the RTL run, then it will be drawn like:
110 // LTR_STRING ...RTS_LTR 120 // LTR_STRING ...RTS_LTR
111 // Instead of: 121 // Instead of:
112 // LTR_STRING RTS_LTR... 122 // LTR_STRING RTS_LTR...
113 void Elide(Runs* runs, int remaining_width) const; 123 void Elide(Runs* runs, int remaining_width) const;
114 124
115 // views::View: 125 // views::View:
116 virtual void Layout() OVERRIDE; 126 virtual void Layout() OVERRIDE;
117 virtual void OnBoundsChanged(const gfx::Rect& previous_bounds) OVERRIDE; 127 virtual void OnBoundsChanged(const gfx::Rect& previous_bounds) OVERRIDE;
118 virtual void OnPaint(gfx::Canvas* canvas) OVERRIDE; 128 virtual void OnPaint(gfx::Canvas* canvas) OVERRIDE;
119 129
120 // ui::AnimationDelegate: 130 // ui::AnimationDelegate:
121 virtual void AnimationProgressed(const ui::Animation* animation) OVERRIDE; 131 virtual void AnimationProgressed(const ui::Animation* animation) OVERRIDE;
122 132
123 static int default_icon_size_; 133 static int default_icon_size_;
124 134
135 // Default values cached here, may be overridden using the setters above.
136 int edge_item_padding_;
137 int item_padding_;
138 int minimum_text_vertical_padding_;
139
125 // This row's model and model index. 140 // This row's model and model index.
126 AutocompleteResultViewModel* model_; 141 AutocompleteResultViewModel* model_;
127 size_t model_index_; 142 size_t model_index_;
128 143
129 const gfx::Font normal_font_; 144 const gfx::Font normal_font_;
130 const gfx::Font bold_font_; 145 const gfx::Font bold_font_;
131 146
132 // Width of the ellipsis in the normal font. 147 // Width of the ellipsis in the normal font.
133 int ellipsis_width_; 148 int ellipsis_width_;
134 149
135 // A context used for mirroring regions. 150 // A context used for mirroring regions.
136 class MirroringContext; 151 class MirroringContext;
137 scoped_ptr<MirroringContext> mirroring_context_; 152 scoped_ptr<MirroringContext> mirroring_context_;
138 153
139 AutocompleteMatch match_; 154 AutocompleteMatch match_;
140 155
141 gfx::Rect text_bounds_; 156 gfx::Rect text_bounds_;
142 gfx::Rect icon_bounds_; 157 gfx::Rect icon_bounds_;
143 158
144 gfx::Rect keyword_text_bounds_; 159 gfx::Rect keyword_text_bounds_;
145 scoped_ptr<views::ImageView> keyword_icon_; 160 scoped_ptr<views::ImageView> keyword_icon_;
146 161
147 scoped_ptr<ui::SlideAnimation> animation_; 162 scoped_ptr<ui::SlideAnimation> animation_;
148 163
149 DISALLOW_COPY_AND_ASSIGN(AutocompleteResultView); 164 DISALLOW_COPY_AND_ASSIGN(AutocompleteResultView);
150 }; 165 };
151 166
152 #endif // CHROME_BROWSER_UI_VIEWS_AUTOCOMPLETE_AUTOCOMPLETE_RESULT_VIEW_H_ 167 #endif // CHROME_BROWSER_UI_VIEWS_AUTOCOMPLETE_AUTOCOMPLETE_RESULT_VIEW_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698