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

Side by Side Diff: chrome/browser/ui/views/location_bar/keyword_hint_view.cc

Issue 1998493002: Update omnibox chips in MD (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: slight refactor Created 4 years, 7 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 #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/gfx/color_utils.h"
30 #include "ui/native_theme/native_theme.h"
28 #include "ui/strings/grit/ui_strings.h" 31 #include "ui/strings/grit/ui_strings.h"
29 #include "ui/views/controls/image_view.h" 32 #include "ui/views/controls/image_view.h"
30 #include "ui/views/controls/label.h" 33 #include "ui/views/controls/label.h"
31 34
32 namespace { 35 namespace {
33 36
34 // For MD, the tab key looks just like other omnibox chips. 37 // This view sort of looks like a tab key.
35 class TabKeyBubbleView : public IconLabelBubbleView { 38 class TabKeyBubbleView : public views::Label {
36 public: 39 public:
37 TabKeyBubbleView(const gfx::FontList& font_list, 40 TabKeyBubbleView();
38 SkColor text_color,
39 SkColor background_color);
40 ~TabKeyBubbleView() override; 41 ~TabKeyBubbleView() override;
41 42
42 private: 43 private:
43 // IconLabelBubbleView: 44 // views::Label:
44 SkColor GetTextColor() const override; 45 gfx::Size GetPreferredSize() const override;
45 SkColor GetBorderColor() 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 gfx::Size TabKeyBubbleView::GetPreferredSize() const {
67 return text_color_; 59 gfx::Size size = views::Label::GetPreferredSize();
68 } 60 size.Enlarge(2 * GetLayoutConstant(ICON_LABEL_VIEW_TRAILING_PADDING), 0);
69 61 return size;
70 SkColor TabKeyBubbleView::GetBorderColor() const {
71 return text_color_;
72 }
73
74 bool TabKeyBubbleView::ShouldShowBackground() const {
75 return true;
76 } 62 }
77 63
78 } // namespace 64 } // namespace
79 65
80 KeywordHintView::KeywordHintView(Profile* profile, 66 KeywordHintView::KeywordHintView(Profile* profile,
81 const gfx::FontList& font_list, 67 const gfx::FontList& font_list,
82 const gfx::FontList& bubble_font_list, 68 const gfx::FontList& bubble_font_list,
83 int bubble_height, 69 int bubble_height,
84 SkColor text_color, 70 SkColor text_color,
85 SkColor background_color) 71 SkColor background_color)
86 : profile_(profile), 72 : profile_(profile),
87 leading_label_(nullptr), 73 leading_label_(nullptr),
88 tab_key_view_(nullptr), 74 tab_key_view_(nullptr),
89 trailing_label_(nullptr), 75 trailing_label_(nullptr),
90 tab_key_height_(bubble_height) { 76 tab_key_height_(bubble_height) {
91 leading_label_ = 77 leading_label_ =
92 CreateLabel(font_list, text_color, background_color); 78 CreateLabel(font_list, text_color, background_color);
93 if (ui::MaterialDesignController::IsModeMaterial()) { 79 if (ui::MaterialDesignController::IsModeMaterial()) {
94 tab_key_view_ = 80 TabKeyBubbleView* tab_key = new TabKeyBubbleView();
95 new TabKeyBubbleView(bubble_font_list, text_color, background_color); 81 tab_key->SetFontList(bubble_font_list);
82 tab_key->SetEnabledColor(text_color);
83 bool inverted = color_utils::IsDark(background_color);
84 SkColor tab_bg_color =
85 inverted ? SK_ColorWHITE : SkColorSetA(text_color, 0x13);
Peter Kasting 2016/05/25 00:03:27 I assume this was explicit direction from Max? Ki
Evan Stade 2016/05/25 20:03:44 No, this didn't change. This is pre-existing code,
Peter Kasting 2016/05/25 20:23:02 Ah. Well, it's fine to leave this way or change,
86 SkColor tab_border_color = inverted ? SK_ColorWHITE : text_color;
87 tab_key->SetBackgroundColor(tab_bg_color);
88 tab_key->set_background(
89 new BackgroundWith1PxBorder(tab_bg_color, tab_border_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
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 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698