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

Side by Side Diff: chrome/browser/ui/views/autocomplete/touch_autocomplete_popup_contents_view.cc

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 #include "chrome/browser/ui/views/autocomplete/touch_autocomplete_popup_contents _view.h" 5 #include "chrome/browser/ui/views/autocomplete/touch_autocomplete_popup_contents _view.h"
6 6
7 #include "chrome/browser/ui/omnibox/omnibox_view.h" 7 #include "chrome/browser/ui/omnibox/omnibox_view.h"
8 #include "third_party/skia/include/core/SkPaint.h" 8 #include "third_party/skia/include/core/SkPaint.h"
9 #include "ui/gfx/canvas.h" 9 #include "ui/gfx/canvas.h"
10 #include "ui/gfx/font.h" 10 #include "ui/gfx/font.h"
11 #include "ui/gfx/path.h" 11 #include "ui/gfx/path.h"
12 #include "ui/gfx/rect.h" 12 #include "ui/gfx/rect.h"
13 #include "ui/gfx/size.h" 13 #include "ui/gfx/size.h"
14 #include "ui/views/view.h" 14 #include "ui/views/view.h"
15 15
16 namespace {
17
18 SkColor GetDividerLineColor(bool top) {
19 bool initialized = false;
20 static SkColor top_color;
21 static SkColor bottom_color;
22 if (!initialized) {
23 #if defined(OS_WIN)
24 top_color = color_utils::GetSysSkColor(COLOR_3DDKSHADOW);
Peter Kasting 2012/05/07 21:03:12 Make sure that the colors you choose are guarantee
Jói 2012/05/10 18:33:07 Done.
Jói 2012/05/10 18:33:07 Done.
25 bottom_color = color_utils::GetSysSkColor(COLOR_3DLIGHT);
26 #elif defined(USE_AURA)
27 const gfx::NativeTheme* theme = gfx::NativeTheme::instance();
28 top_color = theme->GetSystemColor(gfx::NativeTheme::kColorId_ThreeDShadow);
29 bottom_color = theme->GetSystemColor(
30 gfx::NativeTheme::kColorId_ThreeDLightShadow);
31 #else
32 top_color = SkColorSetRGB(0xe3, 0xe3, 0xe3);
33 bottom_color = SkColorSetRGB(0xfe, 0xfe, 0xfe);
34 #endif
35 initialized = true;
36 }
37 }
38
39 SkColor GetDividerLineBottomColor {
40 }
41
42 // Colors for a light-gray 3D-looking divider made up of two lines.
Peter Kasting 2012/05/07 21:03:12 Nit: This can be removed
Jói 2012/05/10 18:33:07 Done.
43 const SkColor kDividerLineTopColor =
44 SkColorSetARGBMacro(0xff, 0xe3, 0xe3, 0xe3);
45 const SkColor kDividerLineBottomColor =
46 SkColorSetARGBMacro(0xff, 0xfe, 0xfe, 0xfe);
47
48 } // namespace
49
16 50
17 // TouchAutocompleteResultView ------------------------------------------------ 51 // TouchAutocompleteResultView ------------------------------------------------
18 52
19 TouchAutocompleteResultView::TouchAutocompleteResultView( 53 TouchAutocompleteResultView::TouchAutocompleteResultView(
20 AutocompleteResultViewModel* model, 54 AutocompleteResultViewModel* model,
21 int model_index, 55 int model_index,
22 const gfx::Font& font, 56 const gfx::Font& font,
23 const gfx::Font& bold_font) 57 const gfx::Font& bold_font)
24 : AutocompleteResultView(model, model_index, font, bold_font) { 58 : AutocompleteResultView(model, model_index, font, bold_font) {
59 set_edge_item_padding(9);
60 set_item_padding_(9);
61 set_minimum_text_vertical_padding(10);
25 } 62 }
26 63
27 TouchAutocompleteResultView::~TouchAutocompleteResultView() { 64 TouchAutocompleteResultView::~TouchAutocompleteResultView() {
28 } 65 }
29 66
30 void TouchAutocompleteResultView::PaintMatch(gfx::Canvas* canvas, 67 void TouchAutocompleteResultView::PaintMatch(gfx::Canvas* canvas,
31 const AutocompleteMatch& match, 68 const AutocompleteMatch& match,
32 int x) { 69 int x) {
33 DrawString(canvas, match.contents, match.contents_class, false, x, 70 int y = text_bounds().y();
34 text_bounds().y());
35 71
36 if (!match.description.empty()) { 72 if (!match.description.empty()) {
37 // We use our base class's GetTextHeight below because we need the height 73 // We use our base class's GetTextHeight below because we need the height
38 // of a single line of text. 74 // of a single line of text.
39 DrawString(canvas, match.description, match.description_class, true, x, 75 DrawString(canvas, match.description, match.description_class, true, x, y);
40 text_bounds().y() + AutocompleteResultView::GetTextHeight()); 76 y += AutocompleteResultView::GetTextHeight();
77 } else {
78 // When we have only one line of content (no description), we center the
79 // single line vertically on our two-lines-tall results box.
80 y += AutocompleteResultView::GetTextHeight() / 2;
41 } 81 }
82
83 DrawString(canvas, match.contents, match.contents_class, false, x, y);
42 } 84 }
43 85
44 int TouchAutocompleteResultView::GetTextHeight() const { 86 int TouchAutocompleteResultView::GetTextHeight() const {
45 // In the touch version of the autocomplete popup, the text is displayed in
46 // two lines: First line is the title of the suggestion and second is the
47 // description. Hence, the total text height is twice the height of one line.
48 return AutocompleteResultView::GetTextHeight() * 2; 87 return AutocompleteResultView::GetTextHeight() * 2;
49 } 88 }
50 89
90 void TouchAutocompleteResultView::AdjustIconBounds(
91 const AutocompleteMatch& match, gfx::Rect* bounds) {
92 // We show the icon centered on the first line of content, so we
Peter Kasting 2012/05/07 21:03:12 Nit: We show -> we want to show
93 // need to adjust the bounds when there are two lines. The default
94 // layout in the base class is to center on the whole results view,
95 // which places th eicon correctly when there are two lines.
Peter Kasting 2012/05/07 21:03:12 Nit: th eicon -> the icon; are two lines -> is one
96 if (!match.description.empty()) {
97 bounds->set_y(
98 (AutocompleteResultView::GetTextHeight() - bounds->height()) / 2 +
99 minimum_text_vertical_padding_);
100 }
101 }
102
51 103
52 // TouchAutocompletePopupContentsView ----------------------------------------- 104 // TouchAutocompletePopupContentsView -----------------------------------------
53 105
54 TouchAutocompletePopupContentsView::TouchAutocompletePopupContentsView( 106 TouchAutocompletePopupContentsView::TouchAutocompletePopupContentsView(
55 const gfx::Font& font, 107 const gfx::Font& font,
56 OmniboxView* omnibox_view, 108 OmniboxView* omnibox_view,
57 AutocompleteEditModel* edit_model, 109 AutocompleteEditModel* edit_model,
58 views::View* location_bar) 110 views::View* location_bar)
59 : AutocompletePopupContentsView(font, omnibox_view, edit_model, 111 : AutocompletePopupContentsView(font, omnibox_view, edit_model,
60 location_bar) { 112 location_bar) {
61 } 113 }
62 114
63 TouchAutocompletePopupContentsView::~TouchAutocompletePopupContentsView() { 115 TouchAutocompletePopupContentsView::~TouchAutocompletePopupContentsView() {
64 } 116 }
65 117
66 void TouchAutocompletePopupContentsView::UpdatePopupAppearance() { 118 void TouchAutocompletePopupContentsView::UpdatePopupAppearance() {
67 AutocompletePopupContentsView::UpdatePopupAppearance(); 119 AutocompletePopupContentsView::UpdatePopupAppearance();
68 Layout(); 120 Layout();
69 } 121 }
70 122
71 void TouchAutocompletePopupContentsView::LayoutChildren() {
72 std::vector<View*> visible_children(GetVisibleChildren());
73 gfx::Rect bounds(GetContentsBounds());
74 double child_width =
75 static_cast<double>(bounds.width()) / visible_children.size();
76 int x = bounds.x();
77 for (size_t i = 0; i < visible_children.size(); ++i) {
78 int next_x = bounds.x() + static_cast<int>(((i + 1) * child_width) + 0.5);
79 visible_children[i]->SetBounds(x, bounds.y(), next_x - x, bounds.height());
80 x = next_x;
81 }
82 }
83
84 void TouchAutocompletePopupContentsView::PaintResultViews(gfx::Canvas* canvas) { 123 void TouchAutocompletePopupContentsView::PaintResultViews(gfx::Canvas* canvas) {
85 AutocompletePopupContentsView::PaintResultViews(canvas); 124 AutocompletePopupContentsView::PaintResultViews(canvas);
86 125
87 // Draw divider lines. 126 // Draw divider lines.
88 std::vector<View*> visible_children(GetVisibleChildren()); 127 std::vector<View*> visible_children(GetVisibleChildren());
89 if (visible_children.size() < 2) 128 if (visible_children.size() < 2)
90 return; 129 return;
91 SkColor color = AutocompleteResultView::GetColor(
92 AutocompleteResultView::NORMAL, AutocompleteResultView::DIMMED_TEXT);
93 gfx::Rect bounds(GetContentsBounds()); 130 gfx::Rect bounds(GetContentsBounds());
94 for (std::vector<View*>::const_iterator i(visible_children.begin() + 1); 131 for (std::vector<View*>::const_iterator i(visible_children.begin() + 1);
Peter Kasting 2012/05/07 21:03:12 Nit: I think it would be slightly better to iterat
95 i != visible_children.end(); ++i) { 132 i != visible_children.end(); ++i) {
96 canvas->DrawLine(gfx::Point((*i)->x(), bounds.y()), 133 TouchAutocompleteResultView* child =
97 gfx::Point((*i)->x(), bounds.bottom()), color); 134 static_cast<TouchAutocompleteResultView*>(*i);
135 canvas->DrawLine(
136 gfx::Point(bounds.x(), child->y() - 1),
137 gfx::Point(bounds.right(), child->y() - 1),
138 kDividerLineTopColor);
139 if (child->GetState() == AutocompleteResultView::NORMAL) {
140 canvas->DrawLine(
141 gfx::Point(bounds.x(), child->y()),
142 gfx::Point(bounds.right(), child->y()),
143 kDividerLineBottomColor);
144 }
98 } 145 }
99 } 146 }
100 147
101 int TouchAutocompletePopupContentsView::CalculatePopupHeight() {
102 DCHECK_GE(static_cast<size_t>(child_count()), model_->result().size());
103 int popup_height = 0;
104 for (size_t i = 0; i < model_->result().size(); ++i) {
105 popup_height = std::max(popup_height,
106 child_at(i)->GetPreferredSize().height());
107 }
108 return popup_height;
109 }
110
111 AutocompleteResultView* TouchAutocompletePopupContentsView::CreateResultView( 148 AutocompleteResultView* TouchAutocompletePopupContentsView::CreateResultView(
112 AutocompleteResultViewModel* model, 149 AutocompleteResultViewModel* model,
113 int model_index, 150 int model_index,
114 const gfx::Font& font, 151 const gfx::Font& font,
115 const gfx::Font& bold_font) { 152 const gfx::Font& bold_font) {
116 return new TouchAutocompleteResultView(model, model_index, font, bold_font); 153 return new TouchAutocompleteResultView(model, model_index, font, bold_font);
117 } 154 }
118 155
119 std::vector<views::View*> 156 std::vector<views::View*>
120 TouchAutocompletePopupContentsView::GetVisibleChildren() { 157 TouchAutocompletePopupContentsView::GetVisibleChildren() {
121 std::vector<View*> visible_children; 158 std::vector<View*> visible_children;
122 for (int i = 0; i < child_count(); ++i) { 159 for (int i = 0; i < child_count(); ++i) {
123 View* v = child_at(i); 160 View* v = child_at(i);
124 if (child_at(i)->visible()) 161 if (child_at(i)->visible())
125 visible_children.push_back(v); 162 visible_children.push_back(v);
126 } 163 }
127 return visible_children; 164 return visible_children;
128 } 165 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698