Chromium Code Reviews| OLD | NEW |
|---|---|
| 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/location_bar/selected_keyword_view.h" | 5 #include "chrome/browser/ui/views/location_bar/selected_keyword_view.h" |
| 6 | 6 |
| 7 #include "base/logging.h" | 7 #include "base/logging.h" |
| 8 #include "base/strings/utf_string_conversions.h" | 8 #include "base/strings/utf_string_conversions.h" |
| 9 #include "chrome/browser/profiles/profile.h" | 9 #include "chrome/browser/profiles/profile.h" |
| 10 #include "chrome/browser/search_engines/template_url_service_factory.h" | 10 #include "chrome/browser/search_engines/template_url_service_factory.h" |
| 11 #include "chrome/browser/ui/location_bar/location_bar_util.h" | 11 #include "chrome/browser/ui/location_bar/location_bar_util.h" |
| 12 #include "chrome/browser/ui/views/location_bar/keyword_hint_view.h" | 12 #include "chrome/browser/ui/views/location_bar/keyword_hint_view.h" |
| 13 #include "chrome/grit/generated_resources.h" | 13 #include "chrome/grit/generated_resources.h" |
| 14 #include "chrome/grit/theme_resources.h" | 14 #include "chrome/grit/theme_resources.h" |
| 15 #include "components/grit/components_scaled_resources.h" | 15 #include "components/grit/components_scaled_resources.h" |
| 16 #include "components/search_engines/template_url_service.h" | 16 #include "components/search_engines/template_url_service.h" |
| 17 #include "ui/base/l10n/l10n_util.h" | 17 #include "ui/base/l10n/l10n_util.h" |
| 18 #include "ui/base/material_design/material_design_controller.h" | |
| 19 #include "ui/base/theme_provider.h" | 18 #include "ui/base/theme_provider.h" |
| 20 #include "ui/gfx/color_palette.h" | 19 #include "ui/gfx/color_palette.h" |
| 21 #include "ui/gfx/color_utils.h" | 20 #include "ui/gfx/color_utils.h" |
| 22 #include "ui/gfx/paint_vector_icon.h" | 21 #include "ui/gfx/paint_vector_icon.h" |
| 23 #include "ui/gfx/vector_icons_public.h" | 22 #include "ui/gfx/vector_icons_public.h" |
| 24 #include "ui/native_theme/native_theme.h" | 23 #include "ui/native_theme/native_theme.h" |
| 25 #include "ui/views/painter.h" | 24 #include "ui/views/painter.h" |
| 26 | 25 |
| 27 SelectedKeywordView::SelectedKeywordView(const gfx::FontList& font_list, | 26 SelectedKeywordView::SelectedKeywordView(const gfx::FontList& font_list, |
| 28 SkColor text_color, | |
| 29 SkColor parent_background_color, | |
| 30 Profile* profile) | 27 Profile* profile) |
| 31 : IconLabelBubbleView(0, font_list, parent_background_color, false), | 28 : IconLabelBubbleView(font_list, false), profile_(profile) { |
| 32 text_color_(text_color), | |
| 33 profile_(profile) { | |
| 34 static const int kBackgroundImages[] = | |
| 35 IMAGE_GRID(IDR_OMNIBOX_SELECTED_KEYWORD_BUBBLE); | |
| 36 SetBackgroundImageGrid(kBackgroundImages); | |
| 37 full_label_.SetFontList(font_list); | 29 full_label_.SetFontList(font_list); |
| 38 full_label_.SetVisible(false); | 30 full_label_.SetVisible(false); |
| 39 partial_label_.SetFontList(font_list); | 31 partial_label_.SetFontList(font_list); |
| 40 partial_label_.SetVisible(false); | 32 partial_label_.SetVisible(false); |
| 41 } | 33 } |
| 42 | 34 |
| 43 SelectedKeywordView::~SelectedKeywordView() { | 35 SelectedKeywordView::~SelectedKeywordView() { |
| 44 } | 36 } |
| 45 | 37 |
| 46 void SelectedKeywordView::ResetImage() { | 38 void SelectedKeywordView::ResetImage() { |
| 47 if (ui::MaterialDesignController::IsModeMaterial()) { | 39 SetImage(gfx::CreateVectorIcon(gfx::VectorIconId::OMNIBOX_SEARCH, 16, |
| 48 SetImage(gfx::CreateVectorIcon(gfx::VectorIconId::OMNIBOX_SEARCH, | 40 GetTextColor())); |
| 49 16, | |
| 50 GetTextColor())); | |
| 51 } else { | |
| 52 SetImage(*GetThemeProvider()->GetImageSkiaNamed(IDR_OMNIBOX_SEARCH)); | |
| 53 } | |
| 54 } | 41 } |
| 55 | 42 |
| 56 SkColor SelectedKeywordView::GetTextColor() const { | 43 SkColor SelectedKeywordView::GetTextColor() const { |
| 57 if (!ui::MaterialDesignController::IsModeMaterial()) | |
| 58 return text_color_; | |
| 59 | |
| 60 return GetNativeTheme()->GetSystemColor( | 44 return GetNativeTheme()->GetSystemColor( |
| 61 color_utils::IsDark(GetParentBackgroundColor()) | 45 color_utils::IsDark(GetParentBackgroundColor()) |
| 62 ? ui::NativeTheme::kColorId_TextfieldDefaultColor | 46 ? ui::NativeTheme::kColorId_TextfieldDefaultColor |
| 63 : ui::NativeTheme::kColorId_LinkEnabled); | 47 : ui::NativeTheme::kColorId_LinkEnabled); |
| 64 } | 48 } |
| 65 | 49 |
| 66 SkColor SelectedKeywordView::GetBorderColor() const { | 50 SkColor SelectedKeywordView::GetBorderColor() const { |
| 67 DCHECK(ui::MaterialDesignController::IsModeMaterial()); | |
| 68 return GetTextColor(); | 51 return GetTextColor(); |
| 69 } | 52 } |
| 70 | 53 |
| 71 gfx::Size SelectedKeywordView::GetPreferredSize() const { | 54 gfx::Size SelectedKeywordView::GetPreferredSize() const { |
| 72 // Height will be ignored by the LocationBarView. | 55 // Height will be ignored by the LocationBarView. |
| 73 return GetSizeForLabelWidth(full_label_.GetPreferredSize().width()); | 56 return GetSizeForLabelWidth(full_label_.GetPreferredSize().width()); |
| 74 } | 57 } |
| 75 | 58 |
| 76 gfx::Size SelectedKeywordView::GetMinimumSize() const { | 59 gfx::Size SelectedKeywordView::GetMinimumSize() const { |
| 77 // Height will be ignored by the LocationBarView. | 60 // Height will be ignored by the LocationBarView. |
| (...skipping 12 matching lines...) Expand all Loading... | |
| 90 return; | 73 return; |
| 91 DCHECK(profile_); | 74 DCHECK(profile_); |
| 92 TemplateURLService* model = | 75 TemplateURLService* model = |
| 93 TemplateURLServiceFactory::GetForProfile(profile_); | 76 TemplateURLServiceFactory::GetForProfile(profile_); |
| 94 if (!model) | 77 if (!model) |
| 95 return; | 78 return; |
| 96 | 79 |
| 97 bool is_extension_keyword; | 80 bool is_extension_keyword; |
| 98 const base::string16 short_name = | 81 const base::string16 short_name = |
| 99 model->GetKeywordShortName(keyword, &is_extension_keyword); | 82 model->GetKeywordShortName(keyword, &is_extension_keyword); |
| 100 int keyword_text_id = ui::MaterialDesignController::IsModeMaterial() | |
| 101 ? IDS_OMNIBOX_KEYWORD_TEXT_MD | |
| 102 : IDS_OMNIBOX_KEYWORD_TEXT; | |
| 103 const base::string16 full_name = | 83 const base::string16 full_name = |
| 104 is_extension_keyword ? short_name : l10n_util::GetStringFUTF16( | 84 is_extension_keyword |
| 105 keyword_text_id, short_name); | 85 ? short_name |
| 86 : l10n_util::GetStringFUTF16(IDS_OMNIBOX_KEYWORD_TEXT_MD, short_name); | |
| 106 full_label_.SetText(full_name); | 87 full_label_.SetText(full_name); |
| 107 | 88 |
| 108 const base::string16 min_string( | 89 const base::string16 min_string( |
| 109 location_bar_util::CalculateMinString(short_name)); | 90 location_bar_util::CalculateMinString(short_name)); |
| 110 const base::string16 partial_name = | 91 const base::string16 partial_name = |
| 111 is_extension_keyword ? min_string : l10n_util::GetStringFUTF16( | 92 is_extension_keyword |
| 112 keyword_text_id, min_string); | 93 ? min_string |
| 94 : l10n_util::GetStringFUTF16(IDS_OMNIBOX_KEYWORD_TEXT_MD, min_string); | |
| 113 partial_label_.SetText(min_string.empty() ? | 95 partial_label_.SetText(min_string.empty() ? |
| 114 full_label_.text() : partial_name); | 96 full_label_.text() : partial_name); |
| 97 | |
| 98 SetLabel(full_name); | |
|
Peter Kasting
2016/09/19 23:46:46
Is this a bugfix?
Evan Stade
2016/09/20 17:37:04
not really, it replaces the SetBackgroundImageGrid
Peter Kasting
2016/09/20 20:18:05
Should we just call Layout() here?
Maybe this des
Evan Stade
2016/09/21 17:05:00
added a comment
| |
| 115 } | 99 } |
| 116 | 100 |
| 117 const char* SelectedKeywordView::GetClassName() const { | 101 const char* SelectedKeywordView::GetClassName() const { |
| 118 return "SelectedKeywordView"; | 102 return "SelectedKeywordView"; |
| 119 } | 103 } |
| OLD | NEW |