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/location_bar/location_icon_view.h" | |
18 #include "chrome/browser/ui/views/toolbar/toolbar_view.h" | |
19 #include "chrome/common/pref_names.h" | |
20 #include "content/public/browser/web_contents.h" | |
21 #include "grit/theme_resources.h" | |
22 #include "net/base/net_util.h" | |
23 #include "ui/base/theme_provider.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 | |
28 // use --force-fieldtrials=EmbeddedSearch/Group1 origin_chip:1/ to force | |
Peter Kasting
2013/11/20 01:49:13
Nit: Comments should be complete sentences.
Does
Greg Billock
2013/11/21 19:29:34
No. I just have to look to remember it. :-)
| |
29 | |
30 SiteChipView::SiteChipView(ToolbarView* toolbar_view) | |
31 : ToolbarButton(this, NULL), | |
32 toolbar_view_(toolbar_view) { | |
33 } | |
34 | |
35 SiteChipView::~SiteChipView() { | |
36 } | |
37 | |
38 void SiteChipView::ButtonPressed(views::Button* sender, | |
39 const ui::Event& event) { | |
40 toolbar_view_->location_bar()->GetLocationEntry()->SetFocus(); | |
41 toolbar_view_->location_bar()->GetLocationEntry()->SelectAll(true); | |
42 toolbar_view_->location_bar()->GetLocationEntry()->model()-> | |
43 SetCaretVisibility(true); | |
44 } | |
45 | |
46 void SiteChipView::Init() { | |
47 ToolbarButton::Init(); | |
48 | |
49 // TODO(gbillock): Would be nice to just use stock LabelButton stuff here. | |
50 location_icon_view_ = new LocationIconView(toolbar_view_->location_bar()); | |
51 AddChildView(location_icon_view_); | |
52 | |
53 host_label_ = new views::Label(); | |
54 AddChildView(host_label_); | |
55 | |
56 // temporary icon filler | |
57 location_icon_view_->SetImage(GetThemeProvider()->GetImageSkiaNamed( | |
58 IDR_LOCATION_BAR_HTTP)); | |
59 location_icon_view_->ShowTooltip(true); | |
60 | |
61 // temporary filler text. | |
62 host_label_->SetText(ASCIIToUTF16("Site Chip")); | |
63 } | |
64 | |
65 void SiteChipView::Update(content::WebContents* tab) { | |
66 Layout(); | |
67 SchedulePaint(); | |
68 } | |
69 | |
70 views::ImageView* SiteChipView::GetLocationIconView() { | |
71 return location_icon_view_; | |
72 } | |
73 | |
74 const views::ImageView* SiteChipView::GetLocationIconView() const { | |
75 return location_icon_view_; | |
76 } | |
77 | |
78 gfx::Size SiteChipView::GetPreferredSize() { | |
79 gfx::Size label_size = host_label_->GetPreferredSize(); | |
80 gfx::Size icon_size = location_icon_view_->GetPreferredSize(); | |
81 | |
82 // Add on two spacing widths before and aft, as well as one | |
83 // between icon and label. | |
84 return gfx::Size(icon_size.width() + label_size.width() + | |
85 2 * ToolbarView::kStandardSpacing + | |
86 LocationBarView::GetItemPadding(), | |
87 icon_size.height()); | |
88 } | |
89 | |
90 void SiteChipView::Layout() { | |
91 location_icon_view_->SetBounds( | |
92 ToolbarView::kStandardSpacing, | |
93 LocationBarView::kNormalEdgeThickness, | |
94 location_icon_view_->GetPreferredSize().width(), | |
95 height() - 2 * LocationBarView::kNormalEdgeThickness); | |
96 | |
97 int host_label_x = ToolbarView::kStandardSpacing + | |
98 location_icon_view_->GetPreferredSize().width() + | |
99 LocationBarView::GetItemPadding(); | |
100 int host_label_width = width() - host_label_x - ToolbarView::kStandardSpacing; | |
101 host_label_->SetBounds(host_label_x, | |
102 LocationBarView::kNormalEdgeThickness, | |
103 host_label_width, | |
104 height() - LocationBarView::kNormalEdgeThickness*2); | |
105 } | |
106 | |
OLD | NEW |