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

Side by Side Diff: chrome/browser/ui/views/omnibox/omnibox_result_view.cc

Issue 2901953002: Omnibox UI Experiments: Add Vertical Layout experiment (title-on-top). (Closed)
Patch Set: swap text in some circumstances to match mobile Created 3 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
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 7
8 #if defined(OS_WIN) 8 #if defined(OS_WIN)
9 #include <atlbase.h> // NOLINT 9 #include <atlbase.h> // NOLINT
10 #include <atlwin.h> // NOLINT 10 #include <atlwin.h> // NOLINT
11 #endif 11 #endif
12 12
13 #include "base/macros.h" 13 #include "base/macros.h"
14 #include "chrome/browser/ui/views/omnibox/omnibox_result_view.h" 14 #include "chrome/browser/ui/views/omnibox/omnibox_result_view.h"
15 15
16 #include <limits.h> 16 #include <limits.h>
17 17
18 #include <algorithm> // NOLINT 18 #include <algorithm> // NOLINT
19 19
20 #include "base/feature_list.h"
20 #include "base/i18n/bidi_line_iterator.h" 21 #include "base/i18n/bidi_line_iterator.h"
21 #include "base/metrics/field_trial_params.h" 22 #include "base/metrics/field_trial_params.h"
22 #include "base/strings/string_number_conversions.h" 23 #include "base/strings/string_number_conversions.h"
23 #include "base/strings/string_util.h" 24 #include "base/strings/string_util.h"
24 #include "chrome/browser/ui/layout_constants.h" 25 #include "chrome/browser/ui/layout_constants.h"
25 #include "chrome/browser/ui/views/location_bar/background_with_1_px_border.h" 26 #include "chrome/browser/ui/views/location_bar/background_with_1_px_border.h"
26 #include "chrome/browser/ui/views/location_bar/location_bar_view.h" 27 #include "chrome/browser/ui/views/location_bar/location_bar_view.h"
27 #include "chrome/browser/ui/views/omnibox/omnibox_popup_contents_view.h" 28 #include "chrome/browser/ui/views/omnibox/omnibox_popup_contents_view.h"
28 #include "chrome/grit/generated_resources.h" 29 #include "chrome/grit/generated_resources.h"
29 #include "components/grit/components_scaled_resources.h" 30 #include "components/grit/components_scaled_resources.h"
(...skipping 266 matching lines...) Expand 10 before | Expand all | Expand 10 after
296 // updating the text in the omnibox but this alert and GetAccessibleNodeData 297 // updating the text in the omnibox but this alert and GetAccessibleNodeData
297 // below make the answer contents accessible. 298 // below make the answer contents accessible.
298 if (match_.answer) 299 if (match_.answer)
299 NotifyAccessibilityEvent(ui::AX_EVENT_SELECTION, true); 300 NotifyAccessibilityEvent(ui::AX_EVENT_SELECTION, true);
300 } 301 }
301 302
302 gfx::Size OmniboxResultView::GetPreferredSize() const { 303 gfx::Size OmniboxResultView::GetPreferredSize() const {
303 int height = GetTextHeight() + (2 * GetVerticalMargin()); 304 int height = GetTextHeight() + (2 * GetVerticalMargin());
304 if (match_.answer) 305 if (match_.answer)
305 height += GetAnswerHeight() + kVerticalPadding; 306 height += GetAnswerHeight() + kVerticalPadding;
307 else if (base::FeatureList::IsEnabled(omnibox::kUIExperimentVerticalLayout))
308 height += GetTextHeight() + kVerticalPadding;
306 return gfx::Size(0, height); 309 return gfx::Size(0, height);
307 } 310 }
308 311
309 void OmniboxResultView::GetAccessibleNodeData(ui::AXNodeData* node_data) { 312 void OmniboxResultView::GetAccessibleNodeData(ui::AXNodeData* node_data) {
310 node_data->SetName(match_.answer 313 node_data->SetName(match_.answer
311 ? l10n_util::GetStringFUTF16( 314 ? l10n_util::GetStringFUTF16(
312 IDS_OMNIBOX_ACCESSIBLE_ANSWER, match_.contents, 315 IDS_OMNIBOX_ACCESSIBLE_ANSWER, match_.contents,
313 match_.answer->second_line().AccessibleText()) 316 match_.answer->second_line().AccessibleText())
314 : match_.contents); 317 : match_.contents);
315 } 318 }
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
354 OmniboxPopupModel::ComputeMatchMaxWidths( 357 OmniboxPopupModel::ComputeMatchMaxWidths(
355 contents->GetContentWidth(), 358 contents->GetContentWidth(),
356 separator_width_, 359 separator_width_,
357 description ? description->GetContentWidth() : 0, 360 description ? description->GetContentWidth() : 0,
358 mirroring_context_->remaining_width(x), 361 mirroring_context_->remaining_width(x),
359 match.answer != nullptr, 362 match.answer != nullptr,
360 !AutocompleteMatch::IsSearchType(match.type), 363 !AutocompleteMatch::IsSearchType(match.type),
361 &contents_max_width, 364 &contents_max_width,
362 &description_max_width); 365 &description_max_width);
363 366
364 int after_contents_x = DrawRenderText(match, contents, CONTENTS, canvas, 367 // Answers in Suggest results.
365 x, y, contents_max_width); 368 if (match.answer && description_max_width != 0) {
369 DrawRenderText(match, contents, CONTENTS, canvas, x, y, contents_max_width);
370 y += GetTextHeight() + kVerticalPadding;
371 if (!answer_image_.isNull()) {
372 int answer_icon_size = GetAnswerHeight();
373 canvas->DrawImageInt(answer_image_, 0, 0, answer_image_.width(),
374 answer_image_.height(), GetMirroredXInView(x), y,
375 answer_icon_size, answer_icon_size, true);
376 // TODO(dschuyler): Perhaps this should be based on the font size
377 // instead of hardcoded to 2 dp (e.g. by adding a space in an
378 // appropriate font to the beginning of the description, then reducing
379 // the additional padding here to zero).
380 const int kAnswerIconToTextPadding = 2;
381 x += answer_icon_size + kAnswerIconToTextPadding;
382 }
383 return;
384 }
366 385
367 if (description_max_width != 0) { 386 // Regular results.
368 if (match.answer) { 387 if (base::FeatureList::IsEnabled(omnibox::kUIExperimentVerticalLayout)) {
388 if (description_max_width == 0) {
389 // For no description, shift down halfways to draw contents in middle.
390 y += (GetTextHeight() + kVerticalPadding) / 2;
391 DrawRenderText(match, contents, CONTENTS, canvas, x, y,
392 contents_max_width);
Peter Kasting 2017/05/25 20:24:39 Nit: I'd probably rework this to avoid the duplica
tommycli 2017/05/25 21:59:10 Done. I was not able to combine it with the old b
393 } else {
394 DrawRenderText(match, contents, CONTENTS, canvas, x, y,
395 contents_max_width);
369 y += GetTextHeight() + kVerticalPadding; 396 y += GetTextHeight() + kVerticalPadding;
370 if (!answer_image_.isNull()) { 397 DrawRenderText(match, description, DESCRIPTION, canvas, x, y,
371 int answer_icon_size = GetAnswerHeight(); 398 description_max_width);
372 canvas->DrawImageInt( 399 }
373 answer_image_, 400 } else {
374 0, 0, answer_image_.width(), answer_image_.height(), 401 x = DrawRenderText(match, contents, CONTENTS, canvas, x, y,
375 GetMirroredXInView(x), y, answer_icon_size, answer_icon_size, true); 402 contents_max_width);
376 // TODO(dschuyler): Perhaps this should be based on the font size 403 if (description_max_width != 0) {
377 // instead of hardcoded to 2 dp (e.g. by adding a space in an
378 // appropriate font to the beginning of the description, then reducing
379 // the additional padding here to zero).
380 const int kAnswerIconToTextPadding = 2;
381 x += answer_icon_size + kAnswerIconToTextPadding;
382 }
383 } else {
384 x = DrawRenderText(match, separator_rendertext_.get(), SEPARATOR, canvas, 404 x = DrawRenderText(match, separator_rendertext_.get(), SEPARATOR, canvas,
385 after_contents_x, y, separator_width_); 405 x, y, separator_width_);
406 DrawRenderText(match, description, DESCRIPTION, canvas, x, y,
407 description_max_width);
386 } 408 }
387
388 DrawRenderText(match, description, DESCRIPTION, canvas, x, y,
389 description_max_width);
390 } 409 }
391 } 410 }
392 411
393 int OmniboxResultView::DrawRenderText( 412 int OmniboxResultView::DrawRenderText(
394 const AutocompleteMatch& match, 413 const AutocompleteMatch& match,
395 gfx::RenderText* render_text, 414 gfx::RenderText* render_text,
396 RenderTextType render_text_type, 415 RenderTextType render_text_type,
397 gfx::Canvas* canvas, 416 gfx::Canvas* canvas,
398 int x, 417 int x,
399 int y, 418 int y,
(...skipping 192 matching lines...) Expand 10 before | Expand all | Expand 10 after
592 return match_.associated_keyword && 611 return match_.associated_keyword &&
593 (keyword_icon_->x() <= icon_bounds_.right()); 612 (keyword_icon_->x() <= icon_bounds_.right());
594 } 613 }
595 614
596 void OmniboxResultView::InitContentsRenderTextIfNecessary() const { 615 void OmniboxResultView::InitContentsRenderTextIfNecessary() const {
597 if (!contents_rendertext_) { 616 if (!contents_rendertext_) {
598 if (match_.answer) { 617 if (match_.answer) {
599 contents_rendertext_ = 618 contents_rendertext_ =
600 CreateAnswerText(match_.answer->first_line(), font_list_); 619 CreateAnswerText(match_.answer->first_line(), font_list_);
601 } else { 620 } else {
621 bool swap_match_text =
Peter Kasting 2017/05/25 20:24:39 Don't we have an experiment somewhere that sometim
tommycli 2017/05/25 21:59:10 Hey Peter -- Looking at what ZeroSuggest does, the
622 base::FeatureList::IsEnabled(omnibox::kUIExperimentVerticalLayout) &&
623 !AutocompleteMatch::IsSearchType(match_.type) &&
624 !match_.description.empty();
625
602 contents_rendertext_ = CreateClassifiedRenderText( 626 contents_rendertext_ = CreateClassifiedRenderText(
603 match_.contents, match_.contents_class, false); 627 swap_match_text ? match_.description : match_.contents,
628 swap_match_text ? match_.description_class : match_.contents_class,
629 false);
604 } 630 }
605 } 631 }
606 } 632 }
607 633
608 void OmniboxResultView::Layout() { 634 void OmniboxResultView::Layout() {
609 const int horizontal_padding = 635 const int horizontal_padding =
610 GetLayoutConstant(LOCATION_BAR_ELEMENT_PADDING) + 636 GetLayoutConstant(LOCATION_BAR_ELEMENT_PADDING) +
611 LocationBarView::kIconInteriorPadding; 637 LocationBarView::kIconInteriorPadding;
612 // The horizontal bounds we're given are the outside bounds, so we can match 638 // The horizontal bounds we're given are the outside bounds, so we can match
613 // the omnibox border outline shape exactly in OnPaint(). We have to inset 639 // the omnibox border outline shape exactly in OnPaint(). We have to inset
614 // here to keep the icons lined up. 640 // here to keep the icons lined up.
615 const int start_x = BackgroundWith1PxBorder::kLocationBarBorderThicknessDip + 641 const int start_x = BackgroundWith1PxBorder::kLocationBarBorderThicknessDip +
616 horizontal_padding; 642 horizontal_padding;
617 const int end_x = width() - start_x; 643 const int end_x = width() - start_x;
618 644
619 const gfx::ImageSkia icon = GetIcon(); 645 const gfx::ImageSkia icon = GetIcon();
620 const int icon_y = 646 int icon_y = GetVerticalMargin();
621 GetVerticalMargin() + (GetTextHeight() - icon.height()) / 2; 647 if (base::FeatureList::IsEnabled(omnibox::kUIExperimentVerticalLayout)) {
Peter Kasting 2017/05/25 20:24:39 Nit: {} not necessary Another way to write all th
tommycli 2017/05/25 21:59:09 Done. Thanks for the concrete suggestions!
648 icon_y += (2 * GetTextHeight() + kVerticalPadding - icon.height()) / 2;
649 } else {
650 icon_y += (GetTextHeight() - icon.height()) / 2;
651 }
622 icon_bounds_.SetRect(start_x, icon_y, icon.width(), icon.height()); 652 icon_bounds_.SetRect(start_x, icon_y, icon.width(), icon.height());
623 653
624 const int text_x = start_x + LocationBarView::kIconWidth + horizontal_padding; 654 const int text_x = start_x + LocationBarView::kIconWidth + horizontal_padding;
625 int text_width = end_x - text_x; 655 int text_width = end_x - text_x;
626 656
627 if (match_.associated_keyword.get()) { 657 if (match_.associated_keyword.get()) {
628 const int max_kw_x = end_x - keyword_icon_->width(); 658 const int max_kw_x = end_x - keyword_icon_->width();
629 const int kw_x = animation_->CurrentValueBetween(max_kw_x, start_x); 659 const int kw_x = animation_->CurrentValueBetween(max_kw_x, start_x);
630 const int kw_text_x = kw_x + keyword_icon_->width() + horizontal_padding; 660 const int kw_text_x = kw_x + keyword_icon_->width() + horizontal_padding;
631 661
(...skipping 21 matching lines...) Expand all
653 icon_bounds_.y()); 683 icon_bounds_.y());
654 int x = GetMirroredXForRect(text_bounds_); 684 int x = GetMirroredXForRect(text_bounds_);
655 mirroring_context_->Initialize(x, text_bounds_.width()); 685 mirroring_context_->Initialize(x, text_bounds_.width());
656 InitContentsRenderTextIfNecessary(); 686 InitContentsRenderTextIfNecessary();
657 687
658 if (!description_rendertext_) { 688 if (!description_rendertext_) {
659 if (match_.answer) { 689 if (match_.answer) {
660 description_rendertext_ = 690 description_rendertext_ =
661 CreateAnswerText(match_.answer->second_line(), GetAnswerFont()); 691 CreateAnswerText(match_.answer->second_line(), GetAnswerFont());
662 } else if (!match_.description.empty()) { 692 } else if (!match_.description.empty()) {
693 // If the description is empty, we wouldn't swap with the contents --
694 // nor would we create the description RenderText object anyways.
695 bool swap_match_text = base::FeatureList::IsEnabled(
696 omnibox::kUIExperimentVerticalLayout) &&
697 !AutocompleteMatch::IsSearchType(match_.type);
698
663 description_rendertext_ = CreateClassifiedRenderText( 699 description_rendertext_ = CreateClassifiedRenderText(
664 match_.description, match_.description_class, true); 700 swap_match_text ? match_.contents : match_.description,
701 swap_match_text ? match_.contents_class : match_.description_class,
702 false);
665 } 703 }
666 } 704 }
667 PaintMatch(match_, contents_rendertext_.get(), 705 PaintMatch(match_, contents_rendertext_.get(),
668 description_rendertext_.get(), canvas, x); 706 description_rendertext_.get(), canvas, x);
669 } 707 }
670 708
671 AutocompleteMatch* keyword_match = match_.associated_keyword.get(); 709 AutocompleteMatch* keyword_match = match_.associated_keyword.get();
672 if (keyword_match) { 710 if (keyword_match) {
673 int x = GetMirroredXForRect(keyword_text_bounds_); 711 int x = GetMirroredXForRect(keyword_text_bounds_);
674 mirroring_context_->Initialize(x, keyword_text_bounds_.width()); 712 mirroring_context_->Initialize(x, keyword_text_bounds_.width());
(...skipping 132 matching lines...) Expand 10 before | Expand all | Expand 10 after
807 destination->AppendText(text); 845 destination->AppendText(text);
808 const TextStyle& text_style = GetTextStyle(text_type); 846 const TextStyle& text_style = GetTextStyle(text_type);
809 // TODO(dschuyler): follow up on the problem of different font sizes within 847 // TODO(dschuyler): follow up on the problem of different font sizes within
810 // one RenderText. Maybe with destination->SetFontList(...). 848 // one RenderText. Maybe with destination->SetFontList(...).
811 destination->ApplyWeight( 849 destination->ApplyWeight(
812 is_bold ? gfx::Font::Weight::BOLD : gfx::Font::Weight::NORMAL, range); 850 is_bold ? gfx::Font::Weight::BOLD : gfx::Font::Weight::NORMAL, range);
813 destination->ApplyColor( 851 destination->ApplyColor(
814 GetNativeTheme()->GetSystemColor(text_style.colors[GetState()]), range); 852 GetNativeTheme()->GetSystemColor(text_style.colors[GetState()]), range);
815 destination->ApplyBaselineStyle(text_style.baseline, range); 853 destination->ApplyBaselineStyle(text_style.baseline, range);
816 } 854 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698