[Metrics] Make MetricsStateManager take a callback param to check if UMA is enabled.
[chromium-blink-merge.git] / chrome / browser / ui / views / location_bar / bubble_icon_view.cc
blob68949b4b160a48130c4fb31599daf7028c4684b2
1 // Copyright 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.
5 #include "chrome/browser/ui/views/location_bar/bubble_icon_view.h"
7 #include "chrome/browser/command_updater.h"
8 #include "ui/accessibility/ax_view_state.h"
9 #include "ui/events/event.h"
11 BubbleIconView::BubbleIconView(CommandUpdater* command_updater, int command_id)
12 : command_updater_(command_updater),
13 command_id_(command_id),
14 suppress_mouse_released_action_(false) {
15 SetAccessibilityFocusable(true);
18 BubbleIconView::~BubbleIconView() {
21 void BubbleIconView::GetAccessibleState(ui::AXViewState* state) {
22 views::ImageView::GetAccessibleState(state);
23 state->role = ui::AX_ROLE_BUTTON;
26 bool BubbleIconView::GetTooltipText(const gfx::Point& p,
27 base::string16* tooltip) const {
28 if (IsBubbleShowing())
29 return false;
31 return views::ImageView::GetTooltipText(p, tooltip);
34 bool BubbleIconView::OnMousePressed(const ui::MouseEvent& event) {
35 // If the bubble is showing then don't reshow it when the mouse is released.
36 suppress_mouse_released_action_ = IsBubbleShowing();
38 // We want to show the bubble on mouse release; that is the standard behavior
39 // for buttons.
40 return true;
43 void BubbleIconView::OnMouseReleased(const ui::MouseEvent& event) {
44 // If this is the second click on this view then the bubble was showing on the
45 // mouse pressed event and is hidden now. Prevent the bubble from reshowing by
46 // doing nothing here.
47 if (suppress_mouse_released_action_) {
48 suppress_mouse_released_action_ = false;
49 return;
52 if (event.IsOnlyLeftMouseButton() && HitTestPoint(event.location())) {
53 OnExecuting(EXECUTE_SOURCE_MOUSE);
54 command_updater_->ExecuteCommand(command_id_);
58 bool BubbleIconView::OnKeyPressed(const ui::KeyEvent& event) {
59 if (event.key_code() == ui::VKEY_SPACE ||
60 event.key_code() == ui::VKEY_RETURN) {
61 OnExecuting(EXECUTE_SOURCE_KEYBOARD);
62 command_updater_->ExecuteCommand(command_id_);
63 return true;
65 return false;
68 void BubbleIconView::OnGestureEvent(ui::GestureEvent* event) {
69 if (event->type() == ui::ET_GESTURE_TAP) {
70 OnExecuting(EXECUTE_SOURCE_GESTURE);
71 command_updater_->ExecuteCommand(command_id_);
72 event->SetHandled();