bubble_icon_view.cc revision 1e9bf3e0803691d0a228da41fc608347b6db4340
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 "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" 11 12BubbleIconView::BubbleIconView(CommandUpdater* command_updater, int command_id) 13 : command_updater_(command_updater), 14 command_id_(command_id), 15 suppress_mouse_released_action_(false) { 16 set_accessibility_focusable(true); 17 LocationBarView::InitTouchableLocationBarChildView(this); 18} 19 20BubbleIconView::~BubbleIconView() { 21} 22 23void BubbleIconView::GetAccessibleState(ui::AccessibleViewState* state) { 24 views::ImageView::GetAccessibleState(state); 25 state->role = ui::AccessibilityTypes::ROLE_PUSHBUTTON; 26} 27 28bool BubbleIconView::GetTooltipText(const gfx::Point& p, 29 string16* tooltip) const { 30 if (IsBubbleShowing()) 31 return false; 32 33 return views::ImageView::GetTooltipText(p, tooltip); 34} 35 36bool 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(); 39 40 // We want to show the bubble on mouse release; that is the standard behavior 41 // for buttons. 42 return true; 43} 44 45void 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; 52 } 53 54 if (event.IsOnlyLeftMouseButton() && HitTestPoint(event.location())) { 55 OnExecuting(EXECUTE_SOURCE_MOUSE); 56 command_updater_->ExecuteCommand(command_id_); 57 } 58} 59 60bool 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; 66 } 67 return false; 68} 69 70void 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(); 75 } 76} 77