NaCl: Update revision in DEPS, r12770 -> r12773
[chromium-blink-merge.git] / chrome / browser / ui / views / location_bar / bubble_icon_view.cc
blob001e1e4f1f910370df50f1b69b1a71f722e0e5dc
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 "chrome/browser/ui/views/location_bar/location_bar_view.h"
9 #include "ui/base/accessibility/accessible_view_state.h"
10 #include "ui/events/event.h"
12 BubbleIconView::BubbleIconView(CommandUpdater* command_updater, int command_id)
13 : command_updater_(command_updater),
14 command_id_(command_id),
15 suppress_mouse_released_action_(false) {
16 SetAccessibilityFocusable(true);
17 LocationBarView::InitTouchableLocationBarChildView(this);
20 BubbleIconView::~BubbleIconView() {
23 void BubbleIconView::GetAccessibleState(ui::AccessibleViewState* state) {
24 views::ImageView::GetAccessibleState(state);
25 state->role = ui::AccessibilityTypes::ROLE_PUSHBUTTON;
28 bool BubbleIconView::GetTooltipText(const gfx::Point& p,
29 base::string16* tooltip) const {
30 if (IsBubbleShowing())
31 return false;
33 return views::ImageView::GetTooltipText(p, tooltip);
36 bool BubbleIconView::OnMousePressed(const ui::MouseEvent& event) {
37 // If the bubble is showing then don't reshow it when the mouse is released.
38 suppress_mouse_released_action_ = IsBubbleShowing();
40 // We want to show the bubble on mouse release; that is the standard behavior
41 // for buttons.
42 return true;
45 void BubbleIconView::OnMouseReleased(const ui::MouseEvent& event) {
46 // If this is the second click on this view then the bubble was showing on the
47 // mouse pressed event and is hidden now. Prevent the bubble from reshowing by
48 // doing nothing here.
49 if (suppress_mouse_released_action_) {
50 suppress_mouse_released_action_ = false;
51 return;
54 if (event.IsOnlyLeftMouseButton() && HitTestPoint(event.location())) {
55 OnExecuting(EXECUTE_SOURCE_MOUSE);
56 command_updater_->ExecuteCommand(command_id_);
60 bool BubbleIconView::OnKeyPressed(const ui::KeyEvent& event) {
61 if (event.key_code() == ui::VKEY_SPACE ||
62 event.key_code() == ui::VKEY_RETURN) {
63 OnExecuting(EXECUTE_SOURCE_KEYBOARD);
64 command_updater_->ExecuteCommand(command_id_);
65 return true;
67 return false;
70 void BubbleIconView::OnGestureEvent(ui::GestureEvent* event) {
71 if (event->type() == ui::ET_GESTURE_TAP) {
72 OnExecuting(EXECUTE_SOURCE_GESTURE);
73 command_updater_->ExecuteCommand(command_id_);
74 event->SetHandled();