Index: chrome/browser/ui/views/toolbar/site_chip_view.cc |
diff --git a/chrome/browser/ui/views/toolbar/site_chip_view.cc b/chrome/browser/ui/views/toolbar/site_chip_view.cc |
new file mode 100644 |
index 0000000000000000000000000000000000000000..ce22b1facd7dd6e39072bbf7836820e6abb5a096 |
--- /dev/null |
+++ b/chrome/browser/ui/views/toolbar/site_chip_view.cc |
@@ -0,0 +1,121 @@ |
+// Copyright (c) 2013 The Chromium Authors. All rights reserved. |
+// Use of this source code is governed by a BSD-style license that can be |
+// found in the LICENSE file. |
+ |
+#include "chrome/browser/ui/views/toolbar/site_chip_view.h" |
+ |
+#include "base/prefs/pref_service.h" |
+#include "base/strings/string_util.h" |
+#include "base/strings/utf_string_conversions.h" |
+#include "chrome/browser/profiles/profile.h" |
+#include "chrome/browser/search/search.h" |
+#include "chrome/browser/themes/theme_properties.h" |
+#include "chrome/browser/ui/browser.h" |
+#include "chrome/browser/ui/omnibox/omnibox_view.h" |
+#include "chrome/browser/ui/toolbar/toolbar_model.h" |
+#include "chrome/browser/ui/views/location_bar/location_bar_view.h" |
+#include "chrome/browser/ui/views/toolbar/toolbar_view.h" |
+#include "chrome/common/pref_names.h" |
+#include "content/public/browser/web_contents.h" |
+#include "grit/theme_resources.h" |
+#include "net/base/net_util.h" |
+#include "ui/base/theme_provider.h" |
+#include "ui/views/background.h" |
+#include "ui/views/controls/button/label_button.h" |
+#include "ui/views/controls/button/label_button_border.h" |
+#include "ui/views/controls/label.h" |
+#include "ui/views/painter.h" |
+ |
+// static |
+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
|
+const int SiteChipView::kIconTextSpacing = 4; |
+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
|
+ |
+SiteChipView::SiteChipView(ToolbarView* toolbar_view) |
+ : ToolbarButton(this, NULL), |
+ toolbar_view_(toolbar_view) { |
+} |
+ |
+SiteChipView::~SiteChipView() { |
+} |
+ |
+void SiteChipView::Init() { |
+ ToolbarButton::Init(); |
+ |
+ // TODO(gbillock): Would be nice to just use stock LabelButton stuff here. |
+ location_icon_view_ = new LocationIconView(toolbar_view_->location_bar()); |
+ AddChildView(location_icon_view_); |
+ |
+ host_label_ = new views::Label(); |
+ AddChildView(host_label_); |
+ |
+ // temporary icon filler |
+ location_icon_view_->SetImage(GetThemeProvider()->GetImageSkiaNamed( |
+ IDR_OMNIBOX_HTTPS_VALID)); |
+ location_icon_view_->ShowTooltip(true); |
+ |
+ // temporary filler text. |
+ host_label_->SetText(ASCIIToUTF16("site.chip")); |
+} |
+ |
+bool SiteChipView::ShouldShow() { |
+ 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
|
+} |
+ |
+void SiteChipView::Update(content::WebContents* tab) { |
+ Layout(); |
+ SchedulePaint(); |
+} |
+ |
+gfx::Size SiteChipView::GetPreferredSize() { |
+ host_label_->SetFontList( |
+ 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
|
+ |
+ gfx::Size label_size = host_label_->GetPreferredSize(); |
+ gfx::Size icon_size = location_icon_view_->GetPreferredSize(); |
+ return gfx::Size(icon_size.width() + label_size.width() + |
+ kIconTextSpacing + kTrailingLabelMargin + |
+ 2 * kEdgeThickness, |
+ icon_size.height()); |
+} |
+ |
+void SiteChipView::Layout() { |
+ location_icon_view_->SetBounds( |
+ kEdgeThickness, |
+ LocationBarView::kNormalEdgeThickness, |
+ location_icon_view_->GetPreferredSize().width(), |
+ height() - 2 * LocationBarView::kNormalEdgeThickness); |
+ |
+ int host_label_x = location_icon_view_->x() + location_icon_view_->width() + |
+ kIconTextSpacing; |
Peter Kasting
2013/12/03 00:58:10
Nit: Indent 4, not even
Greg Billock
2013/12/03 17:35:08
Done.
|
+ int host_label_width = width() - host_label_x - kEdgeThickness - |
+ 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.
|
+ host_label_->SetBounds(host_label_x, |
+ LocationBarView::kNormalEdgeThickness, |
+ host_label_width, |
+ height() - LocationBarView::kNormalEdgeThickness*2); |
+} |
+ |
+void SiteChipView::OnPaint(gfx::Canvas* canvas) { |
+ const int kBackgroundImages[] = IMAGE_GRID(IDR_SITE_CHIP_EV); |
+ scoped_ptr<views::Painter> p( |
+ 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.
|
+ gfx::Rect rect(GetLocalBounds()); |
+ rect.Inset(LocationBarView::kNormalEdgeThickness, |
+ 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
|
+ views::Painter::PaintPainterAt(canvas, p.get(), rect); |
+ |
+ ToolbarButton::OnPaint(canvas); |
+} |
+ |
+void SiteChipView::ButtonPressed(views::Button* sender, |
+ const ui::Event& event) { |
+ 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.
|
+ toolbar_view_->location_bar()->GetOmniboxView()->SelectAll(true); |
+ toolbar_view_->location_bar()->GetOmniboxView()->model()-> |
+ SetCaretVisibility(true); |
+} |
+ |
+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
|
+ return true; |
+} |