Upstream version 7.36.149.0
[platform/framework/web/crosswalk.git] / src / chrome / browser / ui / views / location_bar / bubble_icon_view.cc
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.
4
5 #include "chrome/browser/ui/views/location_bar/bubble_icon_view.h"
6
7 #include "chrome/browser/command_updater.h"
8 #include "ui/accessibility/ax_view_state.h"
9 #include "ui/events/event.h"
10
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);
16 }
17
18 BubbleIconView::~BubbleIconView() {
19 }
20
21 void BubbleIconView::GetAccessibleState(ui::AXViewState* state) {
22   views::ImageView::GetAccessibleState(state);
23   state->role = ui::AX_ROLE_BUTTON;
24 }
25
26 bool BubbleIconView::GetTooltipText(const gfx::Point& p,
27                                     base::string16* tooltip) const {
28   if (IsBubbleShowing())
29     return false;
30
31   return views::ImageView::GetTooltipText(p, tooltip);
32 }
33
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();
37
38   // We want to show the bubble on mouse release; that is the standard behavior
39   // for buttons.
40   return true;
41 }
42
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;
50   }
51
52   if (event.IsOnlyLeftMouseButton() && HitTestPoint(event.location())) {
53     OnExecuting(EXECUTE_SOURCE_MOUSE);
54     command_updater_->ExecuteCommand(command_id_);
55   }
56 }
57
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;
64   }
65   return false;
66 }
67
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();
73   }
74 }