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

Side by Side Diff: chrome/browser/ui/views/toolbar/site_chip_view.cc

Issue 75873002: [SiteChip] Add the basic painting of the site chip button (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Move painter, etc. Created 7 years 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 | Annotate | Revision Log
OLDNEW
(Empty)
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include "chrome/browser/ui/views/toolbar/site_chip_view.h"
6
7 #include "base/prefs/pref_service.h"
8 #include "base/strings/string_util.h"
9 #include "base/strings/utf_string_conversions.h"
10 #include "chrome/browser/profiles/profile.h"
11 #include "chrome/browser/search/search.h"
12 #include "chrome/browser/themes/theme_properties.h"
13 #include "chrome/browser/ui/browser.h"
14 #include "chrome/browser/ui/omnibox/omnibox_view.h"
15 #include "chrome/browser/ui/toolbar/toolbar_model.h"
16 #include "chrome/browser/ui/views/location_bar/location_bar_view.h"
17 #include "chrome/browser/ui/views/toolbar/toolbar_view.h"
18 #include "chrome/common/pref_names.h"
19 #include "content/public/browser/web_contents.h"
20 #include "grit/theme_resources.h"
21 #include "net/base/net_util.h"
22 #include "ui/base/theme_provider.h"
23 #include "ui/views/background.h"
24 #include "ui/views/controls/button/label_button.h"
25 #include "ui/views/controls/button/label_button_border.h"
26 #include "ui/views/controls/label.h"
27 #include "ui/views/painter.h"
28
29 const int kEdgeThickness = 4;
Peter Kasting 2013/12/03 23:04:52 I think we can get the right value for this and kT
Greg Billock 2013/12/04 00:33:34 I have no problem with making those changes. I don
Peter Kasting 2013/12/04 00:55:30 Yes, though I don't think this change is very cont
30 const int kIconTextSpacing = 4;
31 const int kTrailingLabelMargin = 3;
32
33 SiteChipView::SiteChipView(ToolbarView* toolbar_view)
34 : ToolbarButton(this, NULL),
35 toolbar_view_(toolbar_view) {
36 }
37
38 SiteChipView::~SiteChipView() {
39 }
40
41 void SiteChipView::Init() {
42 ToolbarButton::Init();
43
44 // TODO(gbillock): Would be nice to just use stock LabelButton stuff here.
45 location_icon_view_ = new LocationIconView(toolbar_view_->location_bar());
46 AddChildView(location_icon_view_);
47
48 host_label_ = new views::Label();
49 AddChildView(host_label_);
50
51 // temporary background painter
52 const int kBackgroundImages[] = IMAGE_GRID(IDR_SITE_CHIP_EV);
53 background_painter_.reset(
54 views::Painter::CreateImageGridPainter(kBackgroundImages));
55
56 // temporary icon filler
57 location_icon_view_->SetImage(GetThemeProvider()->GetImageSkiaNamed(
58 IDR_OMNIBOX_HTTPS_VALID));
59 location_icon_view_->ShowTooltip(true);
60
61 // temporary filler text.
62 host_label_->SetText(ASCIIToUTF16("site.chip"));
63 }
64
65 bool SiteChipView::ShouldShow() {
66 return chrome::ShouldDisplayOriginChip();
67 }
68
69 void SiteChipView::Update(content::WebContents* tab) {
70 Layout();
71 SchedulePaint();
72 }
73
74 gfx::Size SiteChipView::GetPreferredSize() {
75 host_label_->SetFontList(
76 toolbar_view_->location_bar()->GetOmniboxFontList());
77
78 gfx::Size label_size = host_label_->GetPreferredSize();
79 gfx::Size icon_size = location_icon_view_->GetPreferredSize();
80 return gfx::Size(icon_size.width() + label_size.width() +
81 kIconTextSpacing + kTrailingLabelMargin +
82 2 * kEdgeThickness,
83 icon_size.height());
84 }
85
86 void SiteChipView::Layout() {
87 location_icon_view_->SetBounds(
88 kEdgeThickness,
89 LocationBarView::kNormalEdgeThickness,
90 location_icon_view_->GetPreferredSize().width(),
91 height() - 2 * LocationBarView::kNormalEdgeThickness);
92
93 int host_label_x = location_icon_view_->x() + location_icon_view_->width() +
94 kIconTextSpacing;
Peter Kasting 2013/12/03 23:04:52 Nit: I didn't mean "Indent even + 4" -- just "Inde
Greg Billock 2013/12/04 00:33:34 Done.
95 int host_label_width =
96 width() - host_label_x - kEdgeThickness - kTrailingLabelMargin;
97 host_label_->SetBounds(host_label_x,
98 LocationBarView::kNormalEdgeThickness,
99 host_label_width,
100 height() - 2 * LocationBarView::kNormalEdgeThickness);
101 }
102
103 void SiteChipView::OnPaint(gfx::Canvas* canvas) {
104 gfx::Rect rect(GetLocalBounds());
105 rect.Inset(LocationBarView::kNormalEdgeThickness,
106 LocationBarView::kNormalEdgeThickness);
107 if (background_painter_.get())
Peter Kasting 2013/12/03 23:04:52 Nit: get() unnecessary Can we ever reach here wit
Greg Billock 2013/12/04 00:33:34 Correct. (This will be the usual case in the end.)
108 views::Painter::PaintPainterAt(canvas, background_painter_.get(), rect);
109
110 ToolbarButton::OnPaint(canvas);
111 }
112
113 // TODO(gbillock): Make the LocationBarView or OmniboxView the listener for
114 // this button.
115 void SiteChipView::ButtonPressed(views::Button* sender,
116 const ui::Event& event) {
117 toolbar_view_->location_bar()->GetOmniboxView()->SetFocus();
118 toolbar_view_->location_bar()->GetOmniboxView()->SelectAll(true);
119 toolbar_view_->location_bar()->GetOmniboxView()->model()->
120 SetCaretVisibility(true);
121 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698