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_border.h" |
| 25 #include "ui/views/controls/label.h" |
| 26 |
| 27 SiteChipView::SiteChipView(ToolbarView* toolbar_view) |
| 28 : ToolbarButton(NULL), |
| 29 toolbar_view_(toolbar_view) {} |
| 30 |
| 31 SiteChipView::~SiteChipView() {} |
| 32 |
| 33 void SiteChipView::ButtonPressed(views::Button* sender, |
| 34 const ui::Event& event) { |
| 35 toolbar_view_->location_bar()->GetLocationEntry()->SetFocus(); |
| 36 toolbar_view_->location_bar()->GetLocationEntry()->SelectAll(true); |
| 37 toolbar_view_->location_bar()->GetLocationEntry()->model()-> |
| 38 SetCaretVisibility(true); |
| 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 icon filler |
| 52 location_icon_view_->SetImage(GetThemeProvider()->GetImageSkiaNamed( |
| 53 IDR_LOCATION_BAR_HTTP)); |
| 54 location_icon_view_->ShowTooltip(true); |
| 55 |
| 56 // temporary filler text. |
| 57 host_label_->SetText(ASCIIToUTF16("Site Chip")); |
| 58 } |
| 59 |
| 60 void SiteChipView::Update(content::WebContents* tab) { |
| 61 Layout(); |
| 62 SchedulePaint(); |
| 63 } |
| 64 |
| 65 void SiteChipView::OnChanged() { |
| 66 Update(toolbar_view_->GetWebContents()); |
| 67 } |
| 68 |
| 69 views::ImageView* SiteChipView::GetLocationIconView() { |
| 70 return location_icon_view_; |
| 71 } |
| 72 |
| 73 const views::ImageView* SiteChipView::GetLocationIconView() const { |
| 74 return location_icon_view_; |
| 75 } |
| 76 |
| 77 // Margin padding at the edges of the site chip are |
| 78 // ToolbarView::kStandardSpacing. |
| 79 // Item spacing within the chip are LocationBarView::GetItemPadding. |
| 80 gfx::Size SiteChipView::GetPreferredSize() { |
| 81 gfx::Size label_size = host_label_->GetPreferredSize(); |
| 82 gfx::Size icon_size = location_icon_view_->GetPreferredSize(); |
| 83 |
| 84 // Add on two spacing widths before and aft, as well as one |
| 85 // between icon and label. |
| 86 gfx::Size size = |
| 87 gfx::Size(icon_size.width() + label_size.width() + |
| 88 2*ToolbarView::kStandardSpacing + |
| 89 LocationBarView::GetItemPadding(), |
| 90 icon_size.height()); |
| 91 |
| 92 return size; |
| 93 } |
| 94 |
| 95 void SiteChipView::Layout() { |
| 96 location_icon_view_->SetBounds( |
| 97 ToolbarView::kStandardSpacing, |
| 98 LocationBarView::kNormalEdgeThickness, |
| 99 location_icon_view_->GetPreferredSize().width(), |
| 100 height() - LocationBarView::kNormalEdgeThickness*2); |
| 101 |
| 102 int host_label_x = ToolbarView::kStandardSpacing + |
| 103 location_icon_view_->GetPreferredSize().width() + |
| 104 LocationBarView::GetItemPadding(); |
| 105 int host_label_width = width() - host_label_x - ToolbarView::kStandardSpacing; |
| 106 host_label_->SetBounds(host_label_x, LocationBarView::kNormalEdgeThickness, |
| 107 host_label_width, height() - LocationBarView::kNormalEdgeThickness*2); |
| 108 } |
| 109 |
OLD | NEW |