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

Unified Diff: chrome/browser/ui/views/location_bar/zoom_bubble_view.cc

Issue 10494004: Implements a zoom icon in the Omnibox for Views. (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: Created 8 years, 7 months 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 side-by-side diff with in-line comments
Download patch
Index: chrome/browser/ui/views/location_bar/zoom_bubble_view.cc
diff --git a/chrome/browser/ui/views/location_bar/zoom_bubble_view.cc b/chrome/browser/ui/views/location_bar/zoom_bubble_view.cc
new file mode 100644
index 0000000000000000000000000000000000000000..f32d9363b65295361878c6e1d4f8ab97813fa9f1
--- /dev/null
+++ b/chrome/browser/ui/views/location_bar/zoom_bubble_view.cc
@@ -0,0 +1,100 @@
+// Copyright (c) 2012 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/location_bar/zoom_bubble_view.h"
+
+#include "base/bind.h"
+#include "base/message_loop.h"
+#include "grit/generated_resources.h"
+#include "ui/base/l10n/l10n_util.h"
+#include "ui/views/layout/fill_layout.h"
+
+namespace {
+
+// The number of milliseconds the bubble should stay on the screen for if it
+// will autoclose.
+const int kBubbleCloseDelay = 400;
+
+}
+
+// Singleton instance.
+ZoomBubbleView* ZoomBubbleView::zoom_bubble_ = NULL;
+
+// Declared in browser_dialogs.h..
+namespace browser {
+
+void ShowZoomBubbleView(views::View* anchor_view,
+ int zoom_percent,
+ bool autoclose) {
+ ZoomBubbleView::ShowBubble(anchor_view, zoom_percent, autoclose);
+}
+
+void HideZoomBubbleView() {
+ ZoomBubbleView::CloseBubble();
+}
+
+bool IsZoomBubbleViewShowing() {
+ return ZoomBubbleView::IsShowing();
+}
+
+}
+
+// static
+void ZoomBubbleView::ShowBubble(views::View* anchor_view,
+ int zoom_percent,
+ bool autoclose) {
+ if (IsShowing())
+ CloseBubble();
+
+ zoom_bubble_ = new ZoomBubbleView(anchor_view, zoom_percent, autoclose);
+ views::BubbleDelegateView::CreateBubble(zoom_bubble_);
+ zoom_bubble_->Show();
+}
+
+// static
+void ZoomBubbleView::CloseBubble() {
+ if (IsShowing())
+ zoom_bubble_->Close();
+}
+
+// static
+bool ZoomBubbleView::IsShowing() {
+ return zoom_bubble_ != NULL;
+}
+
+void ZoomBubbleView::WindowClosing() {
+ DCHECK(zoom_bubble_ == this);
+ zoom_bubble_ = NULL;
+}
+
+void ZoomBubbleView::Init() {
+ SetLayoutManager(new views::FillLayout());
+ zoom_percent_label_ = new views::Label(
+ l10n_util::GetStringFUTF16Int(IDS_ZOOM_PERCENT, zoom_percent_));
+ AddChildView(zoom_percent_label_);
+
+ if (autoclose_)
+ MessageLoop::current()->PostDelayedTask(
+ FROM_HERE,
+ base::Bind(&ZoomBubbleView::Close, factory_.GetWeakPtr()),
+ kBubbleCloseDelay);
+}
+
+ZoomBubbleView::ZoomBubbleView(views::View* anchor_view,
+ int zoom_percent,
+ bool autoclose)
+ : BubbleDelegateView(anchor_view, views::BubbleBorder::TOP_RIGHT),
+ ALLOW_THIS_IN_INITIALIZER_LIST(factory_(this)),
+ zoom_percent_(zoom_percent),
+ autoclose_(autoclose),
+ zoom_percent_label_(NULL) {
+ set_use_focusless(autoclose);
+}
+
+ZoomBubbleView::~ZoomBubbleView() {
+}
+
+void ZoomBubbleView::Close() {
+ GetWidget()->Close();
+}

Powered by Google App Engine
This is Rietveld 408576698