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

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

Issue 1338103002: Create c/b/ui/views/layout_constants.*. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Review comments Created 5 years, 3 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 #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
11 11
12 #include "chrome/browser/ui/views/omnibox/omnibox_result_view.h" 12 #include "chrome/browser/ui/views/omnibox/omnibox_result_view.h"
13 13
14 #include <algorithm> // NOLINT 14 #include <algorithm> // NOLINT
15 15
16 #include "base/i18n/bidi_line_iterator.h" 16 #include "base/i18n/bidi_line_iterator.h"
17 #include "base/strings/string_number_conversions.h" 17 #include "base/strings/string_number_conversions.h"
18 #include "base/strings/string_util.h" 18 #include "base/strings/string_util.h"
19 #include "chrome/browser/themes/theme_properties.h" 19 #include "chrome/browser/ui/views/layout_constants.h"
20 #include "chrome/browser/ui/views/location_bar/location_bar_view.h" 20 #include "chrome/browser/ui/views/location_bar/location_bar_view.h"
21 #include "chrome/browser/ui/views/omnibox/omnibox_popup_contents_view.h" 21 #include "chrome/browser/ui/views/omnibox/omnibox_popup_contents_view.h"
22 #include "chrome/grit/generated_resources.h" 22 #include "chrome/grit/generated_resources.h"
23 #include "components/omnibox/browser/omnibox_popup_model.h" 23 #include "components/omnibox/browser/omnibox_popup_model.h"
24 #include "grit/components_scaled_resources.h" 24 #include "grit/components_scaled_resources.h"
25 #include "grit/theme_resources.h" 25 #include "grit/theme_resources.h"
26 #include "third_party/skia/include/core/SkColor.h" 26 #include "third_party/skia/include/core/SkColor.h"
27 #include "ui/base/l10n/l10n_util.h" 27 #include "ui/base/l10n/l10n_util.h"
28 #include "ui/base/resource/material_design/material_design_controller.h" 28 #include "ui/base/resource/material_design/material_design_controller.h"
29 #include "ui/base/resource/resource_bundle.h" 29 #include "ui/base/resource/resource_bundle.h"
(...skipping 316 matching lines...) Expand 10 before | Expand all | Expand 10 after
346 if (match.answer) { 346 if (match.answer) {
347 y += GetContentLineHeight(); 347 y += GetContentLineHeight();
348 if (!answer_image_.isNull()) { 348 if (!answer_image_.isNull()) {
349 int answer_icon_size = GetAnswerLineHeight(); 349 int answer_icon_size = GetAnswerLineHeight();
350 canvas->DrawImageInt( 350 canvas->DrawImageInt(
351 answer_image_, 351 answer_image_,
352 0, 0, answer_image_.width(), answer_image_.height(), 352 0, 0, answer_image_.width(), answer_image_.height(),
353 GetMirroredXInView(x), y, answer_icon_size, answer_icon_size, true); 353 GetMirroredXInView(x), y, answer_icon_size, answer_icon_size, true);
354 // See TODO in Layout(). 354 // See TODO in Layout().
355 x += answer_icon_size + 355 x += answer_icon_size +
356 location_bar_view_->GetThemeProvider()->GetDisplayProperty( 356 GetLayoutConstant(ICON_LABEL_VIEW_TRAILING_PADDING);
357 ThemeProperties::PROPERTY_ICON_LABEL_VIEW_TRAILING_PADDING);
358 } 357 }
359 } else { 358 } else {
360 x = DrawRenderText(match, separator_rendertext_.get(), false, canvas, 359 x = DrawRenderText(match, separator_rendertext_.get(), false, canvas,
361 after_contents_x, y, separator_width_); 360 after_contents_x, y, separator_width_);
362 } 361 }
363 362
364 DrawRenderText(match, description, false, canvas, x, y, 363 DrawRenderText(match, description, false, canvas, x, y,
365 description_max_width); 364 description_max_width);
366 } 365 }
367 } 366 }
(...skipping 233 matching lines...) Expand 10 before | Expand all | Expand 10 after
601 600
602 void OmniboxResultView::InitContentsRenderTextIfNecessary() const { 601 void OmniboxResultView::InitContentsRenderTextIfNecessary() const {
603 if (!contents_rendertext_) { 602 if (!contents_rendertext_) {
604 contents_rendertext_.reset( 603 contents_rendertext_.reset(
605 CreateClassifiedRenderText( 604 CreateClassifiedRenderText(
606 match_.contents, match_.contents_class, false).release()); 605 match_.contents, match_.contents_class, false).release());
607 } 606 }
608 } 607 }
609 608
610 void OmniboxResultView::Layout() { 609 void OmniboxResultView::Layout() {
611 const gfx::ImageSkia icon = GetIcon(); 610 const int horizontal_padding =
612 // TODO(jonross): Currently |location_bar_view_| provides the correct 611 GetLayoutConstant(LOCATION_BAR_HORIZONTAL_PADDING);
613 // ThemeProvider, as it is loaded on the BrowserFrame widget. The root widget
614 // for OmniboxResultView is AutocompletePopupWidget, which is not loading the
615 // theme. We should update the omnibox code to also track its own
616 // ThemeProvider in order to reduce dependancy on LocationBarView.
617 ui::ThemeProvider* theme_provider = location_bar_view_->GetThemeProvider();
618 // |theme_provider| can be null when animations are running during shutdown,
619 // after OmniboxResultView has been removed from the tree of Views.
620 if (!theme_provider)
621 return;
622 const int horizontal_padding = theme_provider->GetDisplayProperty(
623 ThemeProperties::PROPERTY_LOCATION_BAR_HORIZONTAL_PADDING);
624 const int trailing_padding = theme_provider->GetDisplayProperty(
625 ThemeProperties::PROPERTY_ICON_LABEL_VIEW_TRAILING_PADDING);
626
627 const int start_x = StartMargin() + horizontal_padding; 612 const int start_x = StartMargin() + horizontal_padding;
628 const int end_x = width() - EndMargin() - horizontal_padding; 613 const int end_x = width() - EndMargin() - horizontal_padding;
629 614
615 const gfx::ImageSkia icon = GetIcon();
630 icon_bounds_.SetRect( 616 icon_bounds_.SetRect(
631 start_x + ((icon.width() == default_icon_size_) ? 0 : trailing_padding), 617 start_x + ((icon.width() == default_icon_size_) ?
618 0 : GetLayoutConstant(ICON_LABEL_VIEW_TRAILING_PADDING)),
632 (GetContentLineHeight() - icon.height()) / 2, 619 (GetContentLineHeight() - icon.height()) / 2,
633 icon.width(), icon.height()); 620 icon.width(), icon.height());
634 621
635 const int text_x = start_x + default_icon_size_ + horizontal_padding; 622 const int text_x = start_x + default_icon_size_ + horizontal_padding;
636 int text_width = end_x - text_x; 623 int text_width = end_x - text_x;
637 624
638 if (match_.associated_keyword.get()) { 625 if (match_.associated_keyword.get()) {
639 const int max_kw_x = end_x - keyword_icon_->width(); 626 const int max_kw_x = end_x - keyword_icon_->width();
640 const int kw_x = animation_->CurrentValueBetween(max_kw_x, start_x); 627 const int kw_x = animation_->CurrentValueBetween(max_kw_x, start_x);
641 const int kw_text_x = kw_x + keyword_icon_->width() + horizontal_padding; 628 const int kw_text_x = kw_x + keyword_icon_->width() + horizontal_padding;
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after
714 701
715 int OmniboxResultView::GetAnswerLineHeight() const { 702 int OmniboxResultView::GetAnswerLineHeight() const {
716 // GetTextStyle(1) is the largest font used and so defines the boundary that 703 // GetTextStyle(1) is the largest font used and so defines the boundary that
717 // all the other answer styles fit within. 704 // all the other answer styles fit within.
718 return ui::ResourceBundle::GetSharedInstance() 705 return ui::ResourceBundle::GetSharedInstance()
719 .GetFontList(GetTextStyle(1).font) 706 .GetFontList(GetTextStyle(1).font)
720 .GetHeight(); 707 .GetHeight();
721 } 708 }
722 709
723 int OmniboxResultView::GetContentLineHeight() const { 710 int OmniboxResultView::GetContentLineHeight() const {
724 ui::ThemeProvider* theme_provider = location_bar_view_->GetThemeProvider(); 711 return std::max(
725 const int min_icon_vertical_padding = theme_provider->GetDisplayProperty( 712 default_icon_size_ + GetLayoutInsets(OMNIBOX_DROPDOWN_ICON).height(),
726 ThemeProperties::PROPERTY_OMNIBOX_DROPDOWN_MIN_ICON_VERTICAL_PADDING); 713 GetTextHeight() + GetLayoutInsets(OMNIBOX_DROPDOWN_TEXT).height());
727 const int min_text_vertical_padding = theme_provider->GetDisplayProperty(
728 ThemeProperties::PROPERTY_OMNIBOX_DROPDOWN_MIN_TEXT_VERTICAL_PADDING);
729
730 return std::max(default_icon_size_ + (min_icon_vertical_padding * 2),
731 GetTextHeight() + (min_text_vertical_padding * 2));
732 } 714 }
733 715
734 scoped_ptr<gfx::RenderText> OmniboxResultView::CreateAnswerLine( 716 scoped_ptr<gfx::RenderText> OmniboxResultView::CreateAnswerLine(
735 const SuggestionAnswer::ImageLine& line, 717 const SuggestionAnswer::ImageLine& line,
736 gfx::FontList font_list) { 718 gfx::FontList font_list) {
737 scoped_ptr<gfx::RenderText> destination = CreateRenderText(base::string16()); 719 scoped_ptr<gfx::RenderText> destination = CreateRenderText(base::string16());
738 destination->SetFontList(font_list); 720 destination->SetFontList(font_list);
739 721
740 for (const SuggestionAnswer::TextField& text_field : line.text_fields()) 722 for (const SuggestionAnswer::TextField& text_field : line.text_fields())
741 AppendAnswerText(destination.get(), text_field.text(), text_field.type()); 723 AppendAnswerText(destination.get(), text_field.text(), text_field.type());
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after
801 783
802 int OmniboxResultView::StartMargin() const { 784 int OmniboxResultView::StartMargin() const {
803 return ui::MaterialDesignController::IsModeMaterial() ? 785 return ui::MaterialDesignController::IsModeMaterial() ?
804 model_->start_margin() : 0; 786 model_->start_margin() : 0;
805 } 787 }
806 788
807 int OmniboxResultView::EndMargin() const { 789 int OmniboxResultView::EndMargin() const {
808 return ui::MaterialDesignController::IsModeMaterial() ? 790 return ui::MaterialDesignController::IsModeMaterial() ?
809 model_->end_margin() : 0; 791 model_->end_margin() : 0;
810 } 792 }
OLDNEW
« no previous file with comments | « chrome/browser/ui/views/omnibox/omnibox_popup_contents_view.cc ('k') | chrome/browser/ui/views/toolbar/toolbar_button.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698