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/keyword_hint_view.h" | 5 #include "chrome/browser/ui/views/location_bar/keyword_hint_view.h" |
| 6 | 6 |
| 7 #include <stddef.h> | 7 #include <stddef.h> |
| 8 | 8 |
| 9 #include <vector> | 9 #include <vector> |
| 10 | 10 |
| 11 #include "base/logging.h" | 11 #include "base/logging.h" |
| 12 #include "base/macros.h" | 12 #include "base/macros.h" |
| 13 #include "base/strings/utf_string_conversions.h" | 13 #include "base/strings/utf_string_conversions.h" |
| 14 #include "chrome/app/chrome_command_ids.h" | 14 #include "chrome/app/chrome_command_ids.h" |
| 15 #include "chrome/browser/profiles/profile.h" | 15 #include "chrome/browser/profiles/profile.h" |
| 16 #include "chrome/browser/search_engines/template_url_service_factory.h" | 16 #include "chrome/browser/search_engines/template_url_service_factory.h" |
| 17 #include "chrome/browser/ui/layout_constants.h" | |
| 17 #include "chrome/browser/ui/views/location_bar/background_with_1_px_border.h" | 18 #include "chrome/browser/ui/views/location_bar/background_with_1_px_border.h" |
| 18 #include "chrome/browser/ui/views/location_bar/icon_label_bubble_view.h" | 19 #include "chrome/browser/ui/views/location_bar/icon_label_bubble_view.h" |
| 19 #include "chrome/browser/ui/views/location_bar/location_bar_view.h" | 20 #include "chrome/browser/ui/views/location_bar/location_bar_view.h" |
| 20 #include "chrome/grit/generated_resources.h" | 21 #include "chrome/grit/generated_resources.h" |
| 21 #include "components/search_engines/template_url_service.h" | 22 #include "components/search_engines/template_url_service.h" |
| 22 #include "grit/theme_resources.h" | 23 #include "grit/theme_resources.h" |
| 23 #include "ui/base/l10n/l10n_util.h" | 24 #include "ui/base/l10n/l10n_util.h" |
| 24 #include "ui/base/material_design/material_design_controller.h" | 25 #include "ui/base/material_design/material_design_controller.h" |
| 25 #include "ui/base/resource/resource_bundle.h" | 26 #include "ui/base/resource/resource_bundle.h" |
| 26 #include "ui/gfx/canvas.h" | 27 #include "ui/gfx/canvas.h" |
| 27 #include "ui/gfx/color_palette.h" | 28 #include "ui/gfx/color_palette.h" |
| 29 #include "ui/native_theme/native_theme.h" | |
| 28 #include "ui/strings/grit/ui_strings.h" | 30 #include "ui/strings/grit/ui_strings.h" |
| 29 #include "ui/views/controls/image_view.h" | 31 #include "ui/views/controls/image_view.h" |
| 30 #include "ui/views/controls/label.h" | 32 #include "ui/views/controls/label.h" |
| 31 | 33 |
| 32 namespace { | 34 namespace { |
| 33 | 35 |
| 34 // For MD, the tab key looks just like other omnibox chips. | 36 // This view sort of looks like a tab key. |
| 35 class TabKeyBubbleView : public IconLabelBubbleView { | 37 class TabKeyBubbleView : public views::Label { |
| 36 public: | 38 public: |
| 37 TabKeyBubbleView(const gfx::FontList& font_list, | 39 TabKeyBubbleView(); |
| 38 SkColor text_color, | |
| 39 SkColor background_color); | |
| 40 ~TabKeyBubbleView() override; | 40 ~TabKeyBubbleView() override; |
| 41 | 41 |
| 42 private: | 42 private: |
| 43 // IconLabelBubbleView: | 43 // views::Label |
|
Peter Kasting
2016/05/20 20:54:11
Nit: Trailing colon
Evan Stade
2016/05/20 22:33:53
Done.
| |
| 44 SkColor GetTextColor() const override; | 44 void OnNativeThemeChanged(const ui::NativeTheme* theme) override; |
| 45 SkColor GetBorderColor() const override; | 45 gfx::Size GetPreferredSize() const override; |
| 46 bool ShouldShowBackground() const override; | |
| 47 | |
| 48 SkColor text_color_; | |
| 49 | 46 |
| 50 DISALLOW_COPY_AND_ASSIGN(TabKeyBubbleView); | 47 DISALLOW_COPY_AND_ASSIGN(TabKeyBubbleView); |
| 51 }; | 48 }; |
| 52 | 49 |
| 53 TabKeyBubbleView::TabKeyBubbleView(const gfx::FontList& font_list, | 50 TabKeyBubbleView::TabKeyBubbleView() |
| 54 SkColor text_color, | 51 : views::Label(l10n_util::GetStringUTF16(IDS_APP_TAB_KEY)) { |
| 55 SkColor background_color) | 52 SetBorder(views::Border::CreateEmptyBorder( |
| 56 : IconLabelBubbleView(0, | 53 gfx::Insets(GetLayoutConstant(LOCATION_BAR_BUBBLE_VERTICAL_PADDING), 0))); |
| 57 font_list, | |
| 58 background_color, | |
| 59 false), | |
| 60 text_color_(text_color) { | |
| 61 SetLabel(l10n_util::GetStringUTF16(IDS_APP_TAB_KEY)); | |
| 62 } | 54 } |
| 63 | 55 |
| 64 TabKeyBubbleView::~TabKeyBubbleView() {} | 56 TabKeyBubbleView::~TabKeyBubbleView() {} |
| 65 | 57 |
| 66 SkColor TabKeyBubbleView::GetTextColor() const { | 58 void TabKeyBubbleView::OnNativeThemeChanged(const ui::NativeTheme* theme) { |
| 67 return text_color_; | 59 SkColor bg_color = theme->GetSystemColor( |
| 60 ui::NativeTheme::kColorId_TextfieldDefaultBackground); | |
| 61 set_background(new BackgroundWith1PxBorder(bg_color, enabled_color())); | |
| 62 SetBackgroundColor(bg_color); | |
| 68 } | 63 } |
| 69 | 64 |
| 70 SkColor TabKeyBubbleView::GetBorderColor() const { | 65 gfx::Size TabKeyBubbleView::GetPreferredSize() const { |
| 71 return text_color_; | 66 gfx::Size size = views::Label::GetPreferredSize(); |
| 72 } | 67 size.Enlarge(GetLayoutConstant(ICON_LABEL_VIEW_TRAILING_PADDING), 0); |
| 73 | 68 return size; |
| 74 bool TabKeyBubbleView::ShouldShowBackground() const { | |
| 75 return true; | |
| 76 } | 69 } |
| 77 | 70 |
| 78 } // namespace | 71 } // namespace |
| 79 | 72 |
| 80 KeywordHintView::KeywordHintView(Profile* profile, | 73 KeywordHintView::KeywordHintView(Profile* profile, |
| 81 const gfx::FontList& font_list, | 74 const gfx::FontList& font_list, |
| 82 const gfx::FontList& bubble_font_list, | 75 const gfx::FontList& bubble_font_list, |
| 83 int bubble_height, | 76 int bubble_height, |
| 84 SkColor text_color, | 77 SkColor text_color, |
| 85 SkColor background_color) | 78 SkColor background_color) |
| 86 : profile_(profile), | 79 : profile_(profile), |
| 87 leading_label_(nullptr), | 80 leading_label_(nullptr), |
| 88 tab_key_view_(nullptr), | 81 tab_key_view_(nullptr), |
| 89 trailing_label_(nullptr), | 82 trailing_label_(nullptr), |
| 90 tab_key_height_(bubble_height) { | 83 tab_key_height_(bubble_height) { |
| 91 leading_label_ = | 84 leading_label_ = |
| 92 CreateLabel(font_list, text_color, background_color); | 85 CreateLabel(font_list, text_color, background_color); |
| 93 if (ui::MaterialDesignController::IsModeMaterial()) { | 86 if (ui::MaterialDesignController::IsModeMaterial()) { |
| 94 tab_key_view_ = | 87 TabKeyBubbleView* tab_key = new TabKeyBubbleView(); |
| 95 new TabKeyBubbleView(bubble_font_list, text_color, background_color); | 88 tab_key->SetFontList(bubble_font_list); |
| 89 tab_key->SetEnabledColor(text_color); | |
| 90 tab_key_view_ = tab_key; | |
| 96 } else { | 91 } else { |
| 97 views::ImageView* tab_image = new views::ImageView(); | 92 views::ImageView* tab_image = new views::ImageView(); |
| 98 tab_image->SetImage( | 93 tab_image->SetImage( |
| 99 ui::ResourceBundle::GetSharedInstance().GetImageSkiaNamed( | 94 ui::ResourceBundle::GetSharedInstance().GetImageSkiaNamed( |
| 100 IDR_OMNIBOX_KEYWORD_HINT_TAB)); | 95 IDR_OMNIBOX_KEYWORD_HINT_TAB)); |
| 101 tab_key_view_ = tab_image; | 96 tab_key_view_ = tab_image; |
| 102 } | 97 } |
| 103 AddChildView(tab_key_view_); | 98 AddChildView(tab_key_view_); |
| 104 trailing_label_ = | 99 trailing_label_ = |
| 105 CreateLabel(font_list, text_color, background_color); | 100 CreateLabel(font_list, text_color, background_color); |
| (...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 165 | 160 |
| 166 views::Label* KeywordHintView::CreateLabel(const gfx::FontList& font_list, | 161 views::Label* KeywordHintView::CreateLabel(const gfx::FontList& font_list, |
| 167 SkColor text_color, | 162 SkColor text_color, |
| 168 SkColor background_color) { | 163 SkColor background_color) { |
| 169 views::Label* label = new views::Label(base::string16(), font_list); | 164 views::Label* label = new views::Label(base::string16(), font_list); |
| 170 label->SetEnabledColor(text_color); | 165 label->SetEnabledColor(text_color); |
| 171 label->SetBackgroundColor(background_color); | 166 label->SetBackgroundColor(background_color); |
| 172 AddChildView(label); | 167 AddChildView(label); |
| 173 return label; | 168 return label; |
| 174 } | 169 } |
| OLD | NEW |