[Metrics] Make MetricsStateManager take a callback param to check if UMA is enabled.
[chromium-blink-merge.git] / chrome / browser / ui / views / location_bar / zoom_view.cc
blobe07c7e2202e7c4333844dc03f727f71bc6b360bb
1 // Copyright (c) 2012 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.
5 #include "chrome/browser/ui/views/location_bar/zoom_view.h"
7 #include "chrome/browser/ui/toolbar/toolbar_model.h"
8 #include "chrome/browser/ui/view_ids.h"
9 #include "chrome/browser/ui/views/location_bar/zoom_bubble_view.h"
10 #include "chrome/browser/ui/zoom/zoom_controller.h"
11 #include "grit/generated_resources.h"
12 #include "grit/theme_resources.h"
13 #include "ui/accessibility/ax_view_state.h"
14 #include "ui/base/l10n/l10n_util.h"
15 #include "ui/base/resource/resource_bundle.h"
16 #include "ui/events/event.h"
17 #include "ui/gfx/size.h"
19 ZoomView::ZoomView(LocationBarView::Delegate* location_bar_delegate)
20 : location_bar_delegate_(location_bar_delegate) {
21 SetAccessibilityFocusable(true);
22 Update(NULL);
25 ZoomView::~ZoomView() {
28 void ZoomView::Update(ZoomController* zoom_controller) {
29 if (!zoom_controller || zoom_controller->IsAtDefaultZoom() ||
30 location_bar_delegate_->GetToolbarModel()->input_in_progress()) {
31 SetVisible(false);
32 ZoomBubbleView::CloseBubble();
33 return;
36 SetTooltipText(l10n_util::GetStringFUTF16Int(IDS_TOOLTIP_ZOOM,
37 zoom_controller->zoom_percent()));
38 SetImage(ui::ResourceBundle::GetSharedInstance().GetImageSkiaNamed(
39 zoom_controller->GetResourceForZoomLevel()));
40 SetVisible(true);
43 void ZoomView::GetAccessibleState(ui::AXViewState* state) {
44 state->name = l10n_util::GetStringUTF16(IDS_ACCNAME_ZOOM);
45 state->role = ui::AX_ROLE_BUTTON;
48 bool ZoomView::GetTooltipText(const gfx::Point& p,
49 base::string16* tooltip) const {
50 // Don't show tooltip if the zoom bubble is displayed.
51 return !ZoomBubbleView::IsShowing() && ImageView::GetTooltipText(p, tooltip);
54 bool ZoomView::OnMousePressed(const ui::MouseEvent& event) {
55 // Do nothing until mouse is released.
56 return true;
59 void ZoomView::OnMouseReleased(const ui::MouseEvent& event) {
60 if (event.IsOnlyLeftMouseButton() && HitTestPoint(event.location()))
61 ActivateBubble();
64 bool ZoomView::OnKeyPressed(const ui::KeyEvent& event) {
65 if (event.key_code() != ui::VKEY_SPACE &&
66 event.key_code() != ui::VKEY_RETURN) {
67 return false;
70 ActivateBubble();
71 return true;
74 void ZoomView::OnGestureEvent(ui::GestureEvent* event) {
75 if (event->type() == ui::ET_GESTURE_TAP) {
76 ActivateBubble();
77 event->SetHandled();
81 void ZoomView::ActivateBubble() {
82 ZoomBubbleView::ShowBubble(location_bar_delegate_->GetWebContents(), false);