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

Unified Diff: chrome/browser/ui/views/location_bar/zoom_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_view.cc
diff --git a/chrome/browser/ui/views/location_bar/zoom_view.cc b/chrome/browser/ui/views/location_bar/zoom_view.cc
new file mode 100644
index 0000000000000000000000000000000000000000..be1acf125556076a14aa5529bde4fb1c4b0454fd
--- /dev/null
+++ b/chrome/browser/ui/views/location_bar/zoom_view.cc
@@ -0,0 +1,102 @@
+// 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_view.h"
+
+#include "chrome/browser/ui/views/browser_dialogs.h"
+#include "chrome/browser/ui/views/location_bar/zoom_bubble_view.h"
+#include "chrome/browser/ui/view_ids.h"
+#include "grit/generated_resources.h"
+#include "grit/theme_resources_standard.h"
+#include "ui/base/accessibility/accessible_view_state.h"
+#include "ui/base/l10n/l10n_util.h"
+#include "ui/base/resource/resource_bundle.h"
+
+ZoomView::ZoomView()
+ // Initially set the icon state to the plus icon even if it should be
+ // something else so that the location bar's layout can account for the
+ // width needed to display it.
+ : zoom_icon_state_(ZoomController::ZOOM_PLUS_ICON),
+ zoom_percent_(100) {
+ set_id(VIEW_ID_ZOOM_BUTTON);
+ set_accessibility_focusable(true);
+
+ Update();
+}
+
+ZoomView::~ZoomView() {
+}
+
+void ZoomView::SetZoomIconState(ZoomController::ZoomIconState zoom_icon_state) {
+ if (zoom_icon_state == zoom_icon_state_)
+ return;
+
+ zoom_icon_state_ = zoom_icon_state;
+ Update();
+}
+
+void ZoomView::SetZoomIconTooltipPercent(int zoom_percent) {
+ if (zoom_percent == zoom_percent_)
+ return;
+
+ zoom_percent_ = zoom_percent;
+ Update();
+}
+
+void ZoomView::Update() {
+ switch (zoom_icon_state_) {
+ case ZoomController::NONE:
+ SetVisible(false);
+ browser::HideZoomBubbleView();
+ break;
+ case ZoomController::ZOOM_PLUS_ICON:
+ SetVisible(true);
+ SetTooltipText(
+ l10n_util::GetStringFUTF16Int(IDS_TOOLTIP_ZOOM, zoom_percent_));
+ SetImage(ui::ResourceBundle::GetSharedInstance().GetImageSkiaNamed(
+ IDR_ZOOM_PLUS));
+ break;
+ case ZoomController::ZOOM_MINUS_ICON:
+ SetVisible(true);
+ SetTooltipText(
+ l10n_util::GetStringFUTF16Int(IDS_TOOLTIP_ZOOM, zoom_percent_));
+ SetImage(ui::ResourceBundle::GetSharedInstance().GetImageSkiaNamed(
+ IDR_ZOOM_MINUS));
+ break;
+ default:
+ NOTREACHED();
+ }
+}
+
+void ZoomView::GetAccessibleState(ui::AccessibleViewState* state) {
+ state->name = l10n_util::GetStringUTF16(IDS_ACCNAME_ZOOM);
+ state->role = ui::AccessibilityTypes::ROLE_PUSHBUTTON;
+}
+
+bool ZoomView::GetTooltipText(const gfx::Point& p, string16* tooltip) const {
+ // Don't show tooltip if the zoom bubble is displayed.
+ if (browser::IsZoomBubbleViewShowing())
+ return false;
+
+ return ImageView::GetTooltipText(p, tooltip);
+}
+
+bool ZoomView::OnMousePressed(const views::MouseEvent& event) {
+ // Do nothing until mouse is released.
+ return true;
+}
+
+void ZoomView::OnMouseReleased(const views::MouseEvent& event) {
+ if (event.IsOnlyLeftMouseButton() && HitTest(event.location()))
+ browser::ShowZoomBubbleView(this, zoom_percent_, false);
+}
+
+bool ZoomView::OnKeyPressed(const views::KeyEvent& event) {
+ if (event.key_code() == ui::VKEY_SPACE ||
+ event.key_code() == ui::VKEY_RETURN) {
+ browser::ShowZoomBubbleView(this, zoom_percent_, false);
+ return true;
+ }
+ return false;
+}

Powered by Google App Engine
This is Rietveld 408576698