OLD | NEW |
---|---|
(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 // static | |
30 const int SiteChipView::kEdgeThickness = 4; | |
Peter Kasting
2013/12/03 00:58:10
Is this a value we can auto-calculate from some im
Greg Billock
2013/12/03 17:35:08
It's more a quality of the image bits themselves a
| |
31 const int SiteChipView::kIconTextSpacing = 4; | |
32 const int SiteChipView::kTrailingLabelMargin = 3; | |
Peter Kasting
2013/12/03 00:58:10
Could we change these two values into some common
Greg Billock
2013/12/03 17:35:08
Yeah, these are definitely unsatisfying. The deal
Peter Kasting
2013/12/03 19:08:19
We're using the same icons for the location icon i
| |
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 AddChildView(location_icon_view_); | |
48 | |
49 host_label_ = new views::Label(); | |
50 AddChildView(host_label_); | |
51 | |
52 // temporary icon filler | |
53 location_icon_view_->SetImage(GetThemeProvider()->GetImageSkiaNamed( | |
54 IDR_OMNIBOX_HTTPS_VALID)); | |
55 location_icon_view_->ShowTooltip(true); | |
56 | |
57 // temporary filler text. | |
58 host_label_->SetText(ASCIIToUTF16("site.chip")); | |
59 } | |
60 | |
61 bool SiteChipView::ShouldShow() { | |
62 return chrome::ShouldDisplayOriginChip(); | |
Peter Kasting
2013/12/03 00:58:10
Are you planning on some more complex functionalit
Greg Billock
2013/12/03 17:35:08
Yes. There's still some policy issues around wheth
| |
63 } | |
64 | |
65 void SiteChipView::Update(content::WebContents* tab) { | |
66 Layout(); | |
67 SchedulePaint(); | |
68 } | |
69 | |
70 gfx::Size SiteChipView::GetPreferredSize() { | |
71 host_label_->SetFontList( | |
72 toolbar_view_->location_bar()->GetOmniboxFontList()); | |
Peter Kasting
2013/12/03 00:58:10
Instead of a GetOmniboxFontList() accessor, we sho
Greg Billock
2013/12/03 17:35:08
This FontList is calculated in LocationBarView. I
Peter Kasting
2013/12/03 19:08:19
If we want the same fonts in both locations, I mig
| |
73 | |
74 gfx::Size label_size = host_label_->GetPreferredSize(); | |
75 gfx::Size icon_size = location_icon_view_->GetPreferredSize(); | |
76 return gfx::Size(icon_size.width() + label_size.width() + | |
77 kIconTextSpacing + kTrailingLabelMargin + | |
78 2 * kEdgeThickness, | |
79 icon_size.height()); | |
80 } | |
81 | |
82 void SiteChipView::Layout() { | |
83 location_icon_view_->SetBounds( | |
84 kEdgeThickness, | |
85 LocationBarView::kNormalEdgeThickness, | |
86 location_icon_view_->GetPreferredSize().width(), | |
87 height() - 2 * LocationBarView::kNormalEdgeThickness); | |
88 | |
89 int host_label_x = location_icon_view_->x() + location_icon_view_->width() + | |
90 kIconTextSpacing; | |
Peter Kasting
2013/12/03 00:58:10
Nit: Indent 4, not even
Greg Billock
2013/12/03 17:35:08
Done.
| |
91 int host_label_width = width() - host_label_x - kEdgeThickness - | |
92 kTrailingLabelMargin; | |
Peter Kasting
2013/12/03 00:58:10
Nit: Break after "=" to avoid wrapping the calcula
Greg Billock
2013/12/03 17:35:08
Done.
| |
93 host_label_->SetBounds(host_label_x, | |
94 LocationBarView::kNormalEdgeThickness, | |
95 host_label_width, | |
96 height() - LocationBarView::kNormalEdgeThickness*2); | |
97 } | |
98 | |
99 void SiteChipView::OnPaint(gfx::Canvas* canvas) { | |
100 const int kBackgroundImages[] = IMAGE_GRID(IDR_SITE_CHIP_EV); | |
101 scoped_ptr<views::Painter> p( | |
102 views::Painter::CreateImageGridPainter(kBackgroundImages)); | |
Peter Kasting
2013/12/03 00:58:10
Creating this painter in every OnPaint() call is h
Greg Billock
2013/12/03 17:35:08
Oops! Thanks for reminding me. Done.
| |
103 gfx::Rect rect(GetLocalBounds()); | |
104 rect.Inset(LocationBarView::kNormalEdgeThickness, | |
105 LocationBarView::kNormalEdgeThickness); | |
Peter Kasting
2013/12/03 00:58:10
Can we avoid this inset call by just setting our o
Greg Billock
2013/12/03 17:35:08
I think I tried that, but that brings the border p
| |
106 views::Painter::PaintPainterAt(canvas, p.get(), rect); | |
107 | |
108 ToolbarButton::OnPaint(canvas); | |
109 } | |
110 | |
111 void SiteChipView::ButtonPressed(views::Button* sender, | |
112 const ui::Event& event) { | |
113 toolbar_view_->location_bar()->GetOmniboxView()->SetFocus(); | |
Peter Kasting
2013/12/03 00:58:10
Nit: You probably still want a TODO here to make t
Greg Billock
2013/12/03 17:35:08
Done.
| |
114 toolbar_view_->location_bar()->GetOmniboxView()->SelectAll(true); | |
115 toolbar_view_->location_bar()->GetOmniboxView()->model()-> | |
116 SetCaretVisibility(true); | |
117 } | |
118 | |
119 bool SiteChipView::DrawingBackground() { | |
Peter Kasting
2013/12/03 00:58:10
Nit: This isn't called or implemented yet, so I'd
Greg Billock
2013/12/03 17:35:08
deleted. At one point I thought we'd need the marg
| |
120 return true; | |
121 } | |
OLD | NEW |