| 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 "components/search_engines/template_url_service.h" | 14 #include "components/search_engines/template_url_service.h" |
| 15 #include "grit/components_scaled_resources.h" |
| 15 #include "grit/theme_resources.h" | 16 #include "grit/theme_resources.h" |
| 16 #include "ui/base/l10n/l10n_util.h" | 17 #include "ui/base/l10n/l10n_util.h" |
| 17 #include "ui/base/resource/material_design/material_design_controller.h" | 18 #include "ui/base/resource/material_design/material_design_controller.h" |
| 19 #include "ui/base/theme_provider.h" |
| 20 #include "ui/gfx/paint_vector_icon.h" |
| 21 #include "ui/gfx/vector_icons_public.h" |
| 22 #include "ui/native_theme/native_theme.h" |
| 18 #include "ui/views/painter.h" | 23 #include "ui/views/painter.h" |
| 19 | 24 |
| 20 SelectedKeywordView::SelectedKeywordView(const gfx::FontList& font_list, | 25 SelectedKeywordView::SelectedKeywordView(const gfx::FontList& font_list, |
| 21 SkColor text_color, | 26 SkColor text_color, |
| 22 SkColor parent_background_color, | 27 SkColor parent_background_color, |
| 23 Profile* profile) | 28 Profile* profile) |
| 24 : IconLabelBubbleView(IDR_KEYWORD_SEARCH_MAGNIFIER, | 29 : IconLabelBubbleView(0, |
| 25 font_list, | 30 font_list, |
| 26 text_color, | 31 text_color, |
| 27 parent_background_color, | 32 parent_background_color, |
| 28 false), | 33 false), |
| 29 profile_(profile) { | 34 profile_(profile) { |
| 30 if (ui::MaterialDesignController::IsModeMaterial()) { | 35 if (ui::MaterialDesignController::IsModeMaterial()) { |
| 31 // The inset for IDR_OMNIBOX_SELECTED_KEYWORD_BUBBLE for which to perfom | 36 // The inset for IDR_OMNIBOX_SELECTED_KEYWORD_BUBBLE for which to perfom |
| 32 // nine-slicing. | 37 // nine-slicing. |
| 33 static const int kImageInset = 4; | 38 static const int kImageInset = 4; |
| 34 gfx::Insets insets(kImageInset, kImageInset, kImageInset, kImageInset); | 39 gfx::Insets insets(kImageInset, kImageInset, kImageInset, kImageInset); |
| 35 SetBackgroundImageWithInsets(IDR_OMNIBOX_SELECTED_KEYWORD_BUBBLE, insets); | 40 SetBackgroundImageWithInsets(IDR_OMNIBOX_SELECTED_KEYWORD_BUBBLE, insets); |
| 36 } else { | 41 } else { |
| 37 static const int kBackgroundImages[] = | 42 static const int kBackgroundImages[] = |
| 38 IMAGE_GRID(IDR_OMNIBOX_SELECTED_KEYWORD_BUBBLE); | 43 IMAGE_GRID(IDR_OMNIBOX_SELECTED_KEYWORD_BUBBLE); |
| 39 SetBackgroundImageGrid(kBackgroundImages); | 44 SetBackgroundImageGrid(kBackgroundImages); |
| 40 } | 45 } |
| 41 full_label_.SetFontList(font_list); | 46 full_label_.SetFontList(font_list); |
| 42 full_label_.SetVisible(false); | 47 full_label_.SetVisible(false); |
| 43 partial_label_.SetFontList(font_list); | 48 partial_label_.SetFontList(font_list); |
| 44 partial_label_.SetVisible(false); | 49 partial_label_.SetVisible(false); |
| 45 } | 50 } |
| 46 | 51 |
| 47 SelectedKeywordView::~SelectedKeywordView() { | 52 SelectedKeywordView::~SelectedKeywordView() { |
| 48 } | 53 } |
| 49 | 54 |
| 55 void SelectedKeywordView::ResetImage() { |
| 56 if (ui::MaterialDesignController::IsModeMaterial()) { |
| 57 SkColor link_color = |
| 58 GetNativeTheme()->GetSystemColor(ui::NativeTheme::kColorId_LinkEnabled); |
| 59 SetImage(gfx::CreateVectorIcon(gfx::VectorIconId::KEYWORD_SEARCH, 16, |
| 60 link_color)); |
| 61 } else { |
| 62 SetImage(*GetThemeProvider()->GetImageSkiaNamed(IDR_OMNIBOX_SEARCH)); |
| 63 } |
| 64 } |
| 65 |
| 50 gfx::Size SelectedKeywordView::GetPreferredSize() const { | 66 gfx::Size SelectedKeywordView::GetPreferredSize() const { |
| 51 // Height will be ignored by the LocationBarView. | 67 // Height will be ignored by the LocationBarView. |
| 52 return GetSizeForLabelWidth(full_label_.GetPreferredSize().width()); | 68 return GetSizeForLabelWidth(full_label_.GetPreferredSize().width()); |
| 53 } | 69 } |
| 54 | 70 |
| 55 gfx::Size SelectedKeywordView::GetMinimumSize() const { | 71 gfx::Size SelectedKeywordView::GetMinimumSize() const { |
| 56 // Height will be ignored by the LocationBarView. | 72 // Height will be ignored by the LocationBarView. |
| 57 return GetSizeForLabelWidth(partial_label_.GetMinimumSize().width()); | 73 return GetSizeForLabelWidth(partial_label_.GetMinimumSize().width()); |
| 58 } | 74 } |
| 59 | 75 |
| (...skipping 26 matching lines...) Expand all Loading... |
| 86 const base::string16 partial_name = is_extension_keyword ? | 102 const base::string16 partial_name = is_extension_keyword ? |
| 87 min_string : | 103 min_string : |
| 88 l10n_util::GetStringFUTF16(IDS_OMNIBOX_KEYWORD_TEXT, min_string); | 104 l10n_util::GetStringFUTF16(IDS_OMNIBOX_KEYWORD_TEXT, min_string); |
| 89 partial_label_.SetText(min_string.empty() ? | 105 partial_label_.SetText(min_string.empty() ? |
| 90 full_label_.text() : partial_name); | 106 full_label_.text() : partial_name); |
| 91 } | 107 } |
| 92 | 108 |
| 93 const char* SelectedKeywordView::GetClassName() const { | 109 const char* SelectedKeywordView::GetClassName() const { |
| 94 return "SelectedKeywordView"; | 110 return "SelectedKeywordView"; |
| 95 } | 111 } |
| OLD | NEW |