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

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 focus set to ToolbarView 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/resource/resource_bundle.h"
23 #include "ui/base/theme_provider.h"
24 #include "ui/views/background.h"
25 #include "ui/views/controls/button/label_button.h"
26 #include "ui/views/controls/button/label_button_border.h"
27 #include "ui/views/controls/label.h"
28 #include "ui/views/painter.h"
29
30 const int kEdgeThickness = 4;
31 const int kIconTextSpacing = 4;
32 const int kTrailingLabelMargin = 2;
33
34 SiteChipView::SiteChipView(ToolbarView* toolbar_view)
35 : ToolbarButton(this, NULL),
36 toolbar_view_(toolbar_view) {
37 }
38
39 SiteChipView::~SiteChipView() {
40 }
41
42 void SiteChipView::Init() {
43 ToolbarButton::Init();
44
45 // TODO(gbillock): Would be nice to just use stock LabelButton stuff here.
46 location_icon_view_ = new LocationIconView(toolbar_view_->location_bar());
47 host_label_ = new views::Label();
48 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance();
49 host_label_->SetFont(rb.GetFont(ui::ResourceBundle::MediumFont));
50
51 AddChildView(location_icon_view_);
52 AddChildView(host_label_);
53
54 // temporary background painter
55 const int kBackgroundImages[] = IMAGE_GRID(IDR_SITE_CHIP_EV);
56 background_painter_.reset(
57 views::Painter::CreateImageGridPainter(kBackgroundImages));
58
59 // temporary icon filler
60 location_icon_view_->SetImage(GetThemeProvider()->GetImageSkiaNamed(
61 IDR_OMNIBOX_HTTPS_VALID));
62 location_icon_view_->ShowTooltip(true);
63
64 // temporary filler text.
65 host_label_->SetText(ASCIIToUTF16("site.chip"));
66 }
67
68 bool SiteChipView::ShouldShow() {
69 return chrome::ShouldDisplayOriginChip();
70 }
71
72 void SiteChipView::Update(content::WebContents* tab) {
73 Layout();
74 SchedulePaint();
75 }
76
77 gfx::Size SiteChipView::GetPreferredSize() {
78 if (!ShouldShow())
79 return gfx::Size();
80
81 gfx::Size label_size = host_label_->GetPreferredSize();
82 gfx::Size icon_size = location_icon_view_->GetPreferredSize();
83 return gfx::Size(icon_size.width() + label_size.width() +
84 kIconTextSpacing + kTrailingLabelMargin +
85 2 * kEdgeThickness,
86 icon_size.height());
87 }
88
89 void SiteChipView::Layout() {
90 location_icon_view_->SetBounds(
91 kEdgeThickness,
92 LocationBarView::kNormalEdgeThickness,
93 location_icon_view_->GetPreferredSize().width(),
94 height() - 2 * LocationBarView::kNormalEdgeThickness);
95
96 int host_label_x = location_icon_view_->x() + location_icon_view_->width() +
97 kIconTextSpacing;
98 int host_label_width =
99 width() - host_label_x - kEdgeThickness - kTrailingLabelMargin;
100 host_label_->SetBounds(host_label_x,
101 LocationBarView::kNormalEdgeThickness,
102 host_label_width,
103 height() - 2 * LocationBarView::kNormalEdgeThickness);
104 }
105
106 void SiteChipView::OnPaint(gfx::Canvas* canvas) {
107 gfx::Rect rect(GetLocalBounds());
108 rect.Inset(LocationBarView::kNormalEdgeThickness,
109 LocationBarView::kNormalEdgeThickness);
110 if (background_painter_.get())
111 views::Painter::PaintPainterAt(canvas, background_painter_.get(), rect);
112
113 ToolbarButton::OnPaint(canvas);
114 }
115
116 // TODO(gbillock): Make the LocationBarView or OmniboxView the listener for
117 // this button.
118 void SiteChipView::ButtonPressed(views::Button* sender,
119 const ui::Event& event) {
120 toolbar_view_->location_bar()->GetOmniboxView()->SetFocus();
121 toolbar_view_->location_bar()->GetOmniboxView()->SelectAll(true);
122 toolbar_view_->location_bar()->GetOmniboxView()->model()->
123 SetCaretVisibility(true);
124 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698