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

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

Issue 1416683003: MD: Implement tab button for location bar's tab to search message (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: better string Created 5 years, 1 month 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
« no previous file with comments | « chrome/browser/ui/views/location_bar/keyword_hint_view.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 <vector> 7 #include <vector>
8 8
9 #include "base/logging.h" 9 #include "base/logging.h"
10 #include "base/strings/utf_string_conversions.h" 10 #include "base/strings/utf_string_conversions.h"
11 #include "chrome/app/chrome_command_ids.h" 11 #include "chrome/app/chrome_command_ids.h"
12 #include "chrome/browser/profiles/profile.h" 12 #include "chrome/browser/profiles/profile.h"
13 #include "chrome/browser/search_engines/template_url_service_factory.h" 13 #include "chrome/browser/search_engines/template_url_service_factory.h"
14 #include "chrome/browser/ui/views/location_bar/location_bar_view.h" 14 #include "chrome/browser/ui/views/location_bar/location_bar_view.h"
15 #include "chrome/grit/generated_resources.h" 15 #include "chrome/grit/generated_resources.h"
16 #include "components/search_engines/template_url_service.h" 16 #include "components/search_engines/template_url_service.h"
17 #include "grit/theme_resources.h" 17 #include "grit/theme_resources.h"
18 #include "ui/base/l10n/l10n_util.h" 18 #include "ui/base/l10n/l10n_util.h"
19 #include "ui/base/resource/material_design/material_design_controller.h"
19 #include "ui/base/resource/resource_bundle.h" 20 #include "ui/base/resource/resource_bundle.h"
20 #include "ui/gfx/canvas.h" 21 #include "ui/gfx/canvas.h"
22 #include "ui/gfx/color_utils.h"
21 #include "ui/views/controls/image_view.h" 23 #include "ui/views/controls/image_view.h"
22 #include "ui/views/controls/label.h" 24 #include "ui/views/controls/label.h"
23 25
26 namespace {
27
28 class TabKeyImage : public views::View {
29 public:
30 TabKeyImage() {}
Peter Kasting 2015/10/29 03:48:43 Nit: Avoid inlining these methods even for classes
31
32 // views::View implementation
Peter Kasting 2015/10/29 03:48:43 Nit: Just "// views::View:"
33 gfx::Size GetPreferredSize() const override { return gfx::Size(34, 18); }
Peter Kasting 2015/10/29 03:48:43 We definitely shouldn't hardcode the width, and we
34
35 void OnPaint(gfx::Canvas* canvas) override {
Peter Kasting 2015/10/29 03:48:43 It seems like you probably want to SaveAndUnscale(
36 gfx::RectF round_rect_bounds(GetLocalBounds());
37 round_rect_bounds.Inset(0.5f, 0.5f);
38 SkScalar radius = SkIntToScalar(2);
Peter Kasting 2015/10/29 03:48:43 Does this match the EV/keyword search bubble corne
39 SkPaint paint;
40 paint.setAntiAlias(true);
41 paint.setStrokeWidth(1);
42 paint.setColor(
43 color_utils::DeriveDefaultIconColor(GetNativeTheme()->GetSystemColor(
44 ui::NativeTheme::kColorId_TextfieldDefaultColor)));
45 paint.setStyle(SkPaint::kStroke_Style);
46 canvas->sk_canvas()->drawRoundRect(gfx::RectFToSkRect(round_rect_bounds),
47 radius, radius, paint);
48
49 gfx::Rect text_bounds(GetLocalBounds());
50 const int kTopPadding = 3;
51 const int kBottomPadding = 2;
52 text_bounds.Inset(0, kTopPadding, 0, kBottomPadding);
Peter Kasting 2015/10/29 03:48:43 I'm concerned about this implementation with diffe
53 canvas->DrawStringRectWithFlags(
54 l10n_util::GetStringUTF16(IDS_TAB_KEY),
55 gfx::FontList().DeriveWithHeightUpperBound(text_bounds.height()),
56 paint.getColor(), text_bounds, gfx::Canvas::TEXT_ALIGN_CENTER);
57 }
58
59 private:
60 DISALLOW_COPY_AND_ASSIGN(TabKeyImage);
61 };
62
63 // Creates and returns a view for depicting the tab key.
64 views::View* CreateTabKeyImage() {
Peter Kasting 2015/10/29 03:48:43 Nit: For clarity (that the caller is expected to t
65 if (ui::MaterialDesignController::IsModeMaterial())
66 return new TabKeyImage();
67
68 views::ImageView* tab = new views::ImageView();
69 tab->SetImage(ui::ResourceBundle::GetSharedInstance().GetImageSkiaNamed(
70 IDR_OMNIBOX_KEYWORD_HINT_TAB));
71 return tab;
72 }
73
74 } // namespace
24 75
25 KeywordHintView::KeywordHintView(Profile* profile, 76 KeywordHintView::KeywordHintView(Profile* profile,
26 const gfx::FontList& font_list, 77 const gfx::FontList& font_list,
27 SkColor text_color, 78 SkColor text_color,
28 SkColor background_color) 79 SkColor background_color)
29 : profile_(profile), 80 : profile_(profile), tab_key_image_(CreateTabKeyImage()) {
30 tab_image_(new views::ImageView()) {
31 leading_label_ = 81 leading_label_ =
32 CreateLabel(font_list, text_color, background_color); 82 CreateLabel(font_list, text_color, background_color);
33 tab_image_->SetImage( 83 AddChildView(tab_key_image_);
34 ui::ResourceBundle::GetSharedInstance().GetImageSkiaNamed(
35 IDR_OMNIBOX_KEYWORD_HINT_TAB));
36 AddChildView(tab_image_);
37 trailing_label_ = 84 trailing_label_ =
38 CreateLabel(font_list, text_color, background_color); 85 CreateLabel(font_list, text_color, background_color);
39 } 86 }
40 87
41 KeywordHintView::~KeywordHintView() { 88 KeywordHintView::~KeywordHintView() {
42 } 89 }
43 90
44 void KeywordHintView::SetKeyword(const base::string16& keyword) { 91 void KeywordHintView::SetKeyword(const base::string16& keyword) {
45 keyword_ = keyword; 92 keyword_ = keyword;
46 if (keyword_.empty()) 93 if (keyword_.empty())
(...skipping 14 matching lines...) Expand all
61 message_id, base::string16(), short_name, &content_param_offsets); 108 message_id, base::string16(), short_name, &content_param_offsets);
62 DCHECK_EQ(2U, content_param_offsets.size()); 109 DCHECK_EQ(2U, content_param_offsets.size());
63 leading_label_->SetText( 110 leading_label_->SetText(
64 keyword_hint.substr(0, content_param_offsets.front())); 111 keyword_hint.substr(0, content_param_offsets.front()));
65 trailing_label_->SetText(keyword_hint.substr(content_param_offsets.front())); 112 trailing_label_->SetText(keyword_hint.substr(content_param_offsets.front()));
66 } 113 }
67 114
68 gfx::Size KeywordHintView::GetPreferredSize() const { 115 gfx::Size KeywordHintView::GetPreferredSize() const {
69 // Height will be ignored by the LocationBarView. 116 // Height will be ignored by the LocationBarView.
70 return gfx::Size(leading_label_->GetPreferredSize().width() + 117 return gfx::Size(leading_label_->GetPreferredSize().width() +
71 tab_image_->GetPreferredSize().width() + 118 tab_key_image_->GetPreferredSize().width() +
72 trailing_label_->GetPreferredSize().width(), 119 trailing_label_->GetPreferredSize().width(),
73 0); 120 0);
74 } 121 }
75 122
76 gfx::Size KeywordHintView::GetMinimumSize() const { 123 gfx::Size KeywordHintView::GetMinimumSize() const {
77 // Height will be ignored by the LocationBarView. 124 // Height will be ignored by the LocationBarView.
78 return tab_image_->GetPreferredSize(); 125 return tab_key_image_->GetPreferredSize();
79 } 126 }
80 127
81 void KeywordHintView::Layout() { 128 void KeywordHintView::Layout() {
82 int tab_width = tab_image_->GetPreferredSize().width(); 129 gfx::Size tab_size = tab_key_image_->GetPreferredSize();
83 bool show_labels = (width() != tab_width); 130 bool show_labels = (width() != tab_size.width());
84 gfx::Size leading_size(leading_label_->GetPreferredSize()); 131 gfx::Size leading_size(leading_label_->GetPreferredSize());
85 leading_label_->SetBounds(0, 0, show_labels ? leading_size.width() : 0, 132 leading_label_->SetBounds(0, 0, show_labels ? leading_size.width() : 0,
86 height()); 133 height());
87 tab_image_->SetBounds(leading_label_->bounds().right(), 0, tab_width, 134 tab_key_image_->SetBounds(leading_label_->bounds().right(),
88 height()); 135 (height() - tab_size.height()) / 2,
136 tab_size.width(), tab_size.height());
89 gfx::Size trailing_size(trailing_label_->GetPreferredSize()); 137 gfx::Size trailing_size(trailing_label_->GetPreferredSize());
90 trailing_label_->SetBounds(tab_image_->bounds().right(), 0, 138 trailing_label_->SetBounds(tab_key_image_->bounds().right(), 0,
91 show_labels ? trailing_size.width() : 0, 139 show_labels ? trailing_size.width() : 0, height());
92 height());
93 } 140 }
94 141
95 const char* KeywordHintView::GetClassName() const { 142 const char* KeywordHintView::GetClassName() const {
96 return "KeywordHintView"; 143 return "KeywordHintView";
97 } 144 }
98 145
99 views::Label* KeywordHintView::CreateLabel(const gfx::FontList& font_list, 146 views::Label* KeywordHintView::CreateLabel(const gfx::FontList& font_list,
100 SkColor text_color, 147 SkColor text_color,
101 SkColor background_color) { 148 SkColor background_color) {
102 views::Label* label = new views::Label(base::string16(), font_list); 149 views::Label* label = new views::Label(base::string16(), font_list);
103 label->SetEnabledColor(text_color); 150 label->SetEnabledColor(text_color);
104 label->SetBackgroundColor(background_color); 151 label->SetBackgroundColor(background_color);
105 AddChildView(label); 152 AddChildView(label);
106 return label; 153 return label;
107 } 154 }
OLDNEW
« no previous file with comments | « chrome/browser/ui/views/location_bar/keyword_hint_view.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698