| 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" |
| (...skipping 14 matching lines...) Expand all Loading... |
| 25 SelectedKeywordView::SelectedKeywordView(const gfx::FontList& font_list, | 25 SelectedKeywordView::SelectedKeywordView(const gfx::FontList& font_list, |
| 26 SkColor text_color, | 26 SkColor text_color, |
| 27 SkColor parent_background_color, | 27 SkColor parent_background_color, |
| 28 Profile* profile) | 28 Profile* profile) |
| 29 : IconLabelBubbleView(0, | 29 : IconLabelBubbleView(0, |
| 30 font_list, | 30 font_list, |
| 31 text_color, | 31 text_color, |
| 32 parent_background_color, | 32 parent_background_color, |
| 33 false), | 33 false), |
| 34 profile_(profile) { | 34 profile_(profile) { |
| 35 if (ui::MaterialDesignController::IsModeMaterial()) { | 35 if (!ui::MaterialDesignController::IsModeMaterial()) { |
| 36 // The inset for IDR_OMNIBOX_SELECTED_KEYWORD_BUBBLE for which to perfom | |
| 37 // nine-slicing. | |
| 38 static const int kImageInset = 4; | |
| 39 gfx::Insets insets(kImageInset, kImageInset, kImageInset, kImageInset); | |
| 40 SetBackgroundImageWithInsets(IDR_OMNIBOX_SELECTED_KEYWORD_BUBBLE, insets); | |
| 41 } else { | |
| 42 static const int kBackgroundImages[] = | 36 static const int kBackgroundImages[] = |
| 43 IMAGE_GRID(IDR_OMNIBOX_SELECTED_KEYWORD_BUBBLE); | 37 IMAGE_GRID(IDR_OMNIBOX_SELECTED_KEYWORD_BUBBLE); |
| 44 SetBackgroundImageGrid(kBackgroundImages); | 38 SetBackgroundImageGrid(kBackgroundImages); |
| 45 } | 39 } |
| 46 full_label_.SetFontList(font_list); | 40 full_label_.SetFontList(font_list); |
| 47 full_label_.SetVisible(false); | 41 full_label_.SetVisible(false); |
| 48 partial_label_.SetFontList(font_list); | 42 partial_label_.SetFontList(font_list); |
| 49 partial_label_.SetVisible(false); | 43 partial_label_.SetVisible(false); |
| 50 } | 44 } |
| 51 | 45 |
| 52 SelectedKeywordView::~SelectedKeywordView() { | 46 SelectedKeywordView::~SelectedKeywordView() { |
| 53 } | 47 } |
| 54 | 48 |
| 55 void SelectedKeywordView::ResetImage() { | 49 void SelectedKeywordView::ResetImage() { |
| 56 if (ui::MaterialDesignController::IsModeMaterial()) { | 50 if (ui::MaterialDesignController::IsModeMaterial()) { |
| 57 SkColor link_color = | |
| 58 GetNativeTheme()->GetSystemColor(ui::NativeTheme::kColorId_LinkEnabled); | |
| 59 SetImage(gfx::CreateVectorIcon(gfx::VectorIconId::KEYWORD_SEARCH, 16, | 51 SetImage(gfx::CreateVectorIcon(gfx::VectorIconId::KEYWORD_SEARCH, 16, |
| 60 link_color)); | 52 GetTextColor())); |
| 61 } else { | 53 } else { |
| 62 SetImage(*GetThemeProvider()->GetImageSkiaNamed(IDR_OMNIBOX_SEARCH)); | 54 SetImage(*GetThemeProvider()->GetImageSkiaNamed(IDR_OMNIBOX_SEARCH)); |
| 63 } | 55 } |
| 64 } | 56 } |
| 65 | 57 |
| 66 gfx::Size SelectedKeywordView::GetPreferredSize() const { | 58 gfx::Size SelectedKeywordView::GetPreferredSize() const { |
| 67 // Height will be ignored by the LocationBarView. | 59 // Height will be ignored by the LocationBarView. |
| 68 return GetSizeForLabelWidth(full_label_.GetPreferredSize().width()); | 60 return GetSizeForLabelWidth(full_label_.GetPreferredSize().width()); |
| 69 } | 61 } |
| 70 | 62 |
| 71 gfx::Size SelectedKeywordView::GetMinimumSize() const { | 63 gfx::Size SelectedKeywordView::GetMinimumSize() const { |
| 72 // Height will be ignored by the LocationBarView. | 64 // Height will be ignored by the LocationBarView. |
| 73 return GetSizeForLabelWidth(partial_label_.GetMinimumSize().width()); | 65 return GetSizeForLabelWidth(partial_label_.GetMinimumSize().width()); |
| 74 } | 66 } |
| 75 | 67 |
| 76 void SelectedKeywordView::Layout() { | 68 void SelectedKeywordView::Layout() { |
| 77 SetLabel(((width() == GetPreferredSize().width()) ? | 69 SetLabel(((width() == GetPreferredSize().width()) ? |
| 78 full_label_ : partial_label_).text()); | 70 full_label_ : partial_label_).text()); |
| 79 IconLabelBubbleView::Layout(); | 71 IconLabelBubbleView::Layout(); |
| 80 } | 72 } |
| 81 | 73 |
| 74 SkColor SelectedKeywordView::GetTextColor() const { |
| 75 return GetNativeTheme()->GetSystemColor( |
| 76 ui::NativeTheme::kColorId_LinkEnabled); |
| 77 } |
| 78 |
| 79 SkColor SelectedKeywordView::GetBorderColor() const { |
| 80 return GetTextColor(); |
| 81 } |
| 82 |
| 82 void SelectedKeywordView::SetKeyword(const base::string16& keyword) { | 83 void SelectedKeywordView::SetKeyword(const base::string16& keyword) { |
| 83 keyword_ = keyword; | 84 keyword_ = keyword; |
| 84 if (keyword.empty()) | 85 if (keyword.empty()) |
| 85 return; | 86 return; |
| 86 DCHECK(profile_); | 87 DCHECK(profile_); |
| 87 TemplateURLService* model = | 88 TemplateURLService* model = |
| 88 TemplateURLServiceFactory::GetForProfile(profile_); | 89 TemplateURLServiceFactory::GetForProfile(profile_); |
| 89 if (!model) | 90 if (!model) |
| 90 return; | 91 return; |
| 91 | 92 |
| (...skipping 10 matching lines...) Expand all Loading... |
| 102 const base::string16 partial_name = is_extension_keyword ? | 103 const base::string16 partial_name = is_extension_keyword ? |
| 103 min_string : | 104 min_string : |
| 104 l10n_util::GetStringFUTF16(IDS_OMNIBOX_KEYWORD_TEXT, min_string); | 105 l10n_util::GetStringFUTF16(IDS_OMNIBOX_KEYWORD_TEXT, min_string); |
| 105 partial_label_.SetText(min_string.empty() ? | 106 partial_label_.SetText(min_string.empty() ? |
| 106 full_label_.text() : partial_name); | 107 full_label_.text() : partial_name); |
| 107 } | 108 } |
| 108 | 109 |
| 109 const char* SelectedKeywordView::GetClassName() const { | 110 const char* SelectedKeywordView::GetClassName() const { |
| 110 return "SelectedKeywordView"; | 111 return "SelectedKeywordView"; |
| 111 } | 112 } |
| OLD | NEW |