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

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

Issue 98493004: Revert 238732 "[SiteChip] Add the basic painting of the site chi..." (Closed) Base URL: svn://svn.chromium.org/chrome/
Patch Set: 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 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 if (!ShouldShow())
52 return;
53
54 AddChildView(location_icon_view_);
55 AddChildView(host_label_);
56
57 // temporary background painter
58 const int kBackgroundImages[] = IMAGE_GRID(IDR_SITE_CHIP_EV);
59 background_painter_.reset(
60 views::Painter::CreateImageGridPainter(kBackgroundImages));
61
62 // temporary icon filler
63 location_icon_view_->SetImage(GetThemeProvider()->GetImageSkiaNamed(
64 IDR_OMNIBOX_HTTPS_VALID));
65 location_icon_view_->ShowTooltip(true);
66
67 // temporary filler text.
68 host_label_->SetText(ASCIIToUTF16("site.chip"));
69 }
70
71 bool SiteChipView::ShouldShow() {
72 return chrome::ShouldDisplayOriginChip();
73 }
74
75 void SiteChipView::Update(content::WebContents* tab) {
76 Layout();
77 SchedulePaint();
78 }
79
80 gfx::Size SiteChipView::GetPreferredSize() {
81 if (!ShouldShow())
82 return gfx::Size();
83
84 gfx::Size label_size = host_label_->GetPreferredSize();
85 gfx::Size icon_size = location_icon_view_->GetPreferredSize();
86 return gfx::Size(icon_size.width() + label_size.width() +
87 kIconTextSpacing + kTrailingLabelMargin +
88 2 * kEdgeThickness,
89 icon_size.height());
90 }
91
92 void SiteChipView::Layout() {
93 location_icon_view_->SetBounds(
94 kEdgeThickness,
95 LocationBarView::kNormalEdgeThickness,
96 location_icon_view_->GetPreferredSize().width(),
97 height() - 2 * LocationBarView::kNormalEdgeThickness);
98
99 int host_label_x = location_icon_view_->x() + location_icon_view_->width() +
100 kIconTextSpacing;
101 int host_label_width =
102 width() - host_label_x - kEdgeThickness - kTrailingLabelMargin;
103 host_label_->SetBounds(host_label_x,
104 LocationBarView::kNormalEdgeThickness,
105 host_label_width,
106 height() - 2 * LocationBarView::kNormalEdgeThickness);
107 }
108
109 void SiteChipView::OnPaint(gfx::Canvas* canvas) {
110 gfx::Rect rect(GetLocalBounds());
111 rect.Inset(LocationBarView::kNormalEdgeThickness,
112 LocationBarView::kNormalEdgeThickness);
113 if (background_painter_.get())
114 views::Painter::PaintPainterAt(canvas, background_painter_.get(), rect);
115
116 ToolbarButton::OnPaint(canvas);
117 }
118
119 // TODO(gbillock): Make the LocationBarView or OmniboxView the listener for
120 // this button.
121 void SiteChipView::ButtonPressed(views::Button* sender,
122 const ui::Event& event) {
123 toolbar_view_->location_bar()->GetOmniboxView()->SetFocus();
124 toolbar_view_->location_bar()->GetOmniboxView()->SelectAll(true);
125 toolbar_view_->location_bar()->GetOmniboxView()->model()->
126 SetCaretVisibility(true);
127 }
OLDNEW
« no previous file with comments | « trunk/src/chrome/browser/ui/views/toolbar/site_chip_view.h ('k') | trunk/src/chrome/browser/ui/views/toolbar/toolbar_view.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698