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

Side by Side Diff: chrome/browser/ui/views/autocomplete/autocomplete_result_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 // For WinDDK ATL compatibility, these ATL headers must come first. 5 // For WinDDK ATL compatibility, these ATL headers must come first.
6 #include "build/build_config.h" 6 #include "build/build_config.h"
7 #if defined(OS_WIN) 7 #if defined(OS_WIN)
8 #include <atlbase.h> // NOLINT 8 #include <atlbase.h> // NOLINT
9 #include <atlwin.h> // NOLINT 9 #include <atlwin.h> // NOLINT
10 #endif 10 #endif
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after
96 int right_; 96 int right_;
97 97
98 DISALLOW_COPY_AND_ASSIGN(MirroringContext); 98 DISALLOW_COPY_AND_ASSIGN(MirroringContext);
99 }; 99 };
100 100
101 AutocompleteResultView::AutocompleteResultView( 101 AutocompleteResultView::AutocompleteResultView(
102 AutocompleteResultViewModel* model, 102 AutocompleteResultViewModel* model,
103 int model_index, 103 int model_index,
104 const gfx::Font& font, 104 const gfx::Font& font,
105 const gfx::Font& bold_font) 105 const gfx::Font& bold_font)
106 : model_(model), 106 : edge_item_padding_(LocationBarView::GetItemPadding()),
107 item_padding_(LocationBarView::GetItemPadding()),
108 minimum_text_vertical_padding_(kMinimumTextVerticalPadding),
109 model_(model),
107 model_index_(model_index), 110 model_index_(model_index),
108 normal_font_(font), 111 normal_font_(font),
109 bold_font_(bold_font), 112 bold_font_(bold_font),
110 ellipsis_width_(font.GetStringWidth(string16(kEllipsis))), 113 ellipsis_width_(font.GetStringWidth(string16(kEllipsis))),
111 mirroring_context_(new MirroringContext()), 114 mirroring_context_(new MirroringContext()),
112 keyword_icon_(new views::ImageView()), 115 keyword_icon_(new views::ImageView()),
113 ALLOW_THIS_IN_INITIALIZER_LIST( 116 ALLOW_THIS_IN_INITIALIZER_LIST(
114 animation_(new ui::SlideAnimation(this))) { 117 animation_(new ui::SlideAnimation(this))) {
115 CHECK_GE(model_index, 0); 118 CHECK_GE(model_index, 0);
116 if (default_icon_size_ == 0) { 119 if (default_icon_size_ == 0) {
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
163 colors[i][TEXT] = 166 colors[i][TEXT] =
164 color_utils::AlphaBlend(SK_ColorBLACK, colors[i][BACKGROUND], 0xdd); 167 color_utils::AlphaBlend(SK_ColorBLACK, colors[i][BACKGROUND], 0xdd);
165 colors[i][DIMMED_TEXT] = 168 colors[i][DIMMED_TEXT] =
166 color_utils::AlphaBlend(SK_ColorBLACK, colors[i][BACKGROUND], 0xbb); 169 color_utils::AlphaBlend(SK_ColorBLACK, colors[i][BACKGROUND], 0xbb);
167 #else 170 #else
168 colors[i][DIMMED_TEXT] = 171 colors[i][DIMMED_TEXT] =
169 color_utils::AlphaBlend(colors[i][TEXT], colors[i][BACKGROUND], 128); 172 color_utils::AlphaBlend(colors[i][TEXT], colors[i][BACKGROUND], 128);
170 colors[i][URL] = color_utils::GetReadableColor(SkColorSetRGB(0, 128, 0), 173 colors[i][URL] = color_utils::GetReadableColor(SkColorSetRGB(0, 128, 0),
171 colors[i][BACKGROUND]); 174 colors[i][BACKGROUND]);
172 #endif 175 #endif
176
177 // TODO(joi): Programmatically draw the dropdown border using
178 // this color as well. (Right now it's drawn as black with 25%
179 // alpha.)
180 colors[i][DIVIDER] =
181 color_utils::AlphaBlend(colors[i][TEXT], colors[i][BACKGROUND], 0x34);
173 } 182 }
174 initialized = true; 183 initialized = true;
175 } 184 }
176 185
177 return colors[state][kind]; 186 return colors[state][kind];
178 } 187 }
179 188
180 void AutocompleteResultView::SetMatch(const AutocompleteMatch& match) { 189 void AutocompleteResultView::SetMatch(const AutocompleteMatch& match) {
181 match_ = match; 190 match_ = match;
182 animation_->Reset(); 191 animation_->Reset();
(...skipping 18 matching lines...) Expand all
201 } 210 }
202 211
203 void AutocompleteResultView::Invalidate() { 212 void AutocompleteResultView::Invalidate() {
204 keyword_icon_->SetImage(GetKeywordIcon()); 213 keyword_icon_->SetImage(GetKeywordIcon());
205 SchedulePaint(); 214 SchedulePaint();
206 } 215 }
207 216
208 gfx::Size AutocompleteResultView::GetPreferredSize() { 217 gfx::Size AutocompleteResultView::GetPreferredSize() {
209 return gfx::Size(0, std::max( 218 return gfx::Size(0, std::max(
210 default_icon_size_ + (kMinimumIconVerticalPadding * 2), 219 default_icon_size_ + (kMinimumIconVerticalPadding * 2),
211 GetTextHeight() + (kMinimumTextVerticalPadding * 2))); 220 GetTextHeight() + (minimum_text_vertical_padding_ * 2)));
212 } 221 }
213 222
214 //////////////////////////////////////////////////////////////////////////////// 223 ////////////////////////////////////////////////////////////////////////////////
215 // AutocompleteResultView, protected: 224 // AutocompleteResultView, protected:
216 225
226 AutocompleteResultView::ResultViewState
227 AutocompleteResultView::GetState() const {
228 if (model_->IsSelectedIndex(model_index_))
229 return SELECTED;
230 return model_->IsHoveredIndex(model_index_) ? HOVERED : NORMAL;
231 }
232
217 void AutocompleteResultView::PaintMatch(gfx::Canvas* canvas, 233 void AutocompleteResultView::PaintMatch(gfx::Canvas* canvas,
218 const AutocompleteMatch& match, 234 const AutocompleteMatch& match,
219 int x) { 235 int x) {
220 x = DrawString(canvas, match.contents, match.contents_class, false, x, 236 x = DrawString(canvas, match.contents, match.contents_class, false, x,
221 text_bounds_.y()); 237 text_bounds_.y());
222 238
223 // Paint the description. 239 // Paint the description.
224 // TODO(pkasting): Because we paint in multiple separate pieces, we can wind 240 // TODO(pkasting): Because we paint in multiple separate pieces, we can wind
225 // up with no space even for an ellipsis for one or both of these pieces. 241 // up with no space even for an ellipsis for one or both of these pieces.
226 // Instead, we should paint the entire match as a single long string. This 242 // Instead, we should paint the entire match as a single long string. This
(...skipping 25 matching lines...) Expand all
252 268
253 // static 269 // static
254 bool AutocompleteResultView::SortRunsVisually(const RunData& lhs, 270 bool AutocompleteResultView::SortRunsVisually(const RunData& lhs,
255 const RunData& rhs) { 271 const RunData& rhs) {
256 return lhs.visual_order < rhs.visual_order; 272 return lhs.visual_order < rhs.visual_order;
257 } 273 }
258 274
259 // static 275 // static
260 int AutocompleteResultView::default_icon_size_ = 0; 276 int AutocompleteResultView::default_icon_size_ = 0;
261 277
262 AutocompleteResultView::ResultViewState
263 AutocompleteResultView::GetState() const {
264 if (model_->IsSelectedIndex(model_index_))
265 return SELECTED;
266 return model_->IsHoveredIndex(model_index_) ? HOVERED : NORMAL;
267 }
268
269 const SkBitmap* AutocompleteResultView::GetIcon() const { 278 const SkBitmap* AutocompleteResultView::GetIcon() const {
270 const SkBitmap* bitmap = model_->GetIconIfExtensionMatch(model_index_); 279 const SkBitmap* bitmap = model_->GetIconIfExtensionMatch(model_index_);
271 if (bitmap) 280 if (bitmap)
272 return bitmap; 281 return bitmap;
273 282
274 int icon = match_.starred ? 283 int icon = match_.starred ?
275 IDR_OMNIBOX_STAR : AutocompleteMatch::TypeToIcon(match_.type); 284 IDR_OMNIBOX_STAR : AutocompleteMatch::TypeToIcon(match_.type);
276 if (GetState() == SELECTED) { 285 if (GetState() == SELECTED) {
277 switch (icon) { 286 switch (icon) {
278 case IDR_OMNIBOX_EXTENSION_APP: 287 case IDR_OMNIBOX_EXTENSION_APP:
(...skipping 252 matching lines...) Expand 10 before | Expand all | Expand 10 after
531 } 540 }
532 } 541 }
533 542
534 // We couldn't draw anything. 543 // We couldn't draw anything.
535 runs->clear(); 544 runs->clear();
536 } 545 }
537 546
538 void AutocompleteResultView::Layout() { 547 void AutocompleteResultView::Layout() {
539 const SkBitmap* icon = GetIcon(); 548 const SkBitmap* icon = GetIcon();
540 549
541 icon_bounds_.SetRect(LocationBarView::kEdgeItemPadding + 550 icon_bounds_.SetRect(edge_item_padding_ +
542 ((icon->width() == default_icon_size_) ? 551 ((icon->width() == default_icon_size_) ?
543 0 : LocationBarView::kIconInternalPadding), 552 0 : LocationBarView::kIconInternalPadding),
544 (height() - icon->height()) / 2, icon->width(), icon->height()); 553 (height() - icon->height()) / 2, icon->width(), icon->height());
545 554
546 int text_x = LocationBarView::kEdgeItemPadding + default_icon_size_ + 555 int text_x = edge_item_padding_ + default_icon_size_ + item_padding_;
547 LocationBarView::kItemPadding;
548 int text_height = GetTextHeight(); 556 int text_height = GetTextHeight();
549 int text_width; 557 int text_width;
550 558
551 if (match_.associated_keyword.get()) { 559 if (match_.associated_keyword.get()) {
552 const int kw_collapsed_size = keyword_icon_->width() + 560 const int kw_collapsed_size =
553 LocationBarView::kEdgeItemPadding; 561 keyword_icon_->width() + edge_item_padding_;
554 const int max_kw_x = width() - kw_collapsed_size; 562 const int max_kw_x = width() - kw_collapsed_size;
555 const int kw_x = animation_->CurrentValueBetween(max_kw_x, 563 const int kw_x =
556 LocationBarView::kEdgeItemPadding); 564 animation_->CurrentValueBetween(max_kw_x, edge_item_padding_);
557 const int kw_text_x = kw_x + keyword_icon_->width() + 565 const int kw_text_x = kw_x + keyword_icon_->width() + item_padding_;
558 LocationBarView::kItemPadding;
559 566
560 text_width = kw_x - text_x - LocationBarView::kItemPadding; 567 text_width = kw_x - text_x - item_padding_;
561 keyword_text_bounds_.SetRect(kw_text_x, 0, std::max( 568 keyword_text_bounds_.SetRect(kw_text_x, 0,
562 width() - kw_text_x - LocationBarView::kEdgeItemPadding, 0), 569 std::max(width() - kw_text_x - edge_item_padding_, 0), text_height);
563 text_height);
564 keyword_icon_->SetPosition(gfx::Point(kw_x, 570 keyword_icon_->SetPosition(gfx::Point(kw_x,
565 (height() - keyword_icon_->height()) / 2)); 571 (height() - keyword_icon_->height()) / 2));
566 } else { 572 } else {
567 text_width = width() - text_x - LocationBarView::kEdgeItemPadding; 573 text_width = width() - text_x - edge_item_padding_;
568 } 574 }
569 575
570 text_bounds_.SetRect(text_x, std::max(0, (height() - text_height) / 2), 576 text_bounds_.SetRect(text_x, std::max(0, (height() - text_height) / 2),
571 std::max(text_width, 0), text_height); 577 std::max(text_width, 0), text_height);
572 } 578 }
573 579
574 void AutocompleteResultView::OnBoundsChanged( 580 void AutocompleteResultView::OnBoundsChanged(
575 const gfx::Rect& previous_bounds) { 581 const gfx::Rect& previous_bounds) {
576 animation_->SetSlideDuration(width() / 4); 582 animation_->SetSlideDuration(width() / 4);
577 } 583 }
578 584
579 void AutocompleteResultView::OnPaint(gfx::Canvas* canvas) { 585 void AutocompleteResultView::OnPaint(gfx::Canvas* canvas) {
580 const ResultViewState state = GetState(); 586 const ResultViewState state = GetState();
581 if (state != NORMAL) 587 if (state != NORMAL)
582 canvas->DrawColor(GetColor(state, BACKGROUND)); 588 canvas->DrawColor(GetColor(state, BACKGROUND));
583 589
584 if (!match_.associated_keyword.get() || 590 if (!match_.associated_keyword.get() ||
585 keyword_icon_->x() > icon_bounds_.right()) { 591 keyword_icon_->x() > icon_bounds_.right()) {
586 // Paint the icon. 592 // Paint the icon.
587 canvas->DrawBitmapInt(*GetIcon(), GetMirroredXForRect(icon_bounds_), 593 canvas->DrawBitmapInt(*GetIcon(), GetMirroredXForRect(icon_bounds_),
588 icon_bounds_.y()); 594 icon_bounds_.y());
589 595
590 // Paint the text. 596 // Paint the text.
591 int x = GetMirroredXForRect(text_bounds_); 597 int x = GetMirroredXForRect(text_bounds_);
592 mirroring_context_->Initialize(x, text_bounds_.width()); 598 mirroring_context_->Initialize(x, text_bounds_.width());
593 PaintMatch(canvas, match_, x); 599 PaintMatch(canvas, match_, x);
594 } 600 }
595 601
596 if (match_.associated_keyword.get()) { 602 if (match_.associated_keyword.get()) {
597 // Paint the keyword text. 603 // Paint the keyword text.
598 int x = GetMirroredXForRect(keyword_text_bounds_); 604 int x = GetMirroredXForRect(keyword_text_bounds_);
599 mirroring_context_->Initialize(x, keyword_text_bounds_.width()); 605 mirroring_context_->Initialize(x, keyword_text_bounds_.width());
600 PaintMatch(canvas, *match_.associated_keyword.get(), x); 606 PaintMatch(canvas, *match_.associated_keyword.get(), x);
601 } 607 }
602 } 608 }
603 609
604 void AutocompleteResultView::AnimationProgressed( 610 void AutocompleteResultView::AnimationProgressed(
605 const ui::Animation* animation) { 611 const ui::Animation* animation) {
606 Layout(); 612 Layout();
607 SchedulePaint(); 613 SchedulePaint();
608 } 614 }
609 615
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698