11e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)// Copyright 2013 The Chromium Authors. All rights reserved. 21e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)// Use of this source code is governed by a BSD-style license that can be 31e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)// found in the LICENSE file. 41e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) 51e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)#include "chrome/browser/ui/views/location_bar/bubble_icon_view.h" 61e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) 71e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)#include "chrome/browser/command_updater.h" 8a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)#include "ui/accessibility/ax_view_state.h" 91e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)#include "ui/events/event.h" 101e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) 111e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)BubbleIconView::BubbleIconView(CommandUpdater* command_updater, int command_id) 121e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) : command_updater_(command_updater), 131e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) command_id_(command_id), 141e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) suppress_mouse_released_action_(false) { 155d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) SetAccessibilityFocusable(true); 161e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)} 171e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) 181e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)BubbleIconView::~BubbleIconView() { 191e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)} 201e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) 21a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)void BubbleIconView::GetAccessibleState(ui::AXViewState* state) { 221e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) views::ImageView::GetAccessibleState(state); 23a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) state->role = ui::AX_ROLE_BUTTON; 241e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)} 251e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) 261e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)bool BubbleIconView::GetTooltipText(const gfx::Point& p, 27a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) base::string16* tooltip) const { 281e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) if (IsBubbleShowing()) 291e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) return false; 301e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) 311e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) return views::ImageView::GetTooltipText(p, tooltip); 321e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)} 331e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) 341e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)bool BubbleIconView::OnMousePressed(const ui::MouseEvent& event) { 351e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) // If the bubble is showing then don't reshow it when the mouse is released. 361e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) suppress_mouse_released_action_ = IsBubbleShowing(); 371e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) 381e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) // We want to show the bubble on mouse release; that is the standard behavior 391e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) // for buttons. 401e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) return true; 411e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)} 421e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) 431e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)void BubbleIconView::OnMouseReleased(const ui::MouseEvent& event) { 441e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) // If this is the second click on this view then the bubble was showing on the 451e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) // mouse pressed event and is hidden now. Prevent the bubble from reshowing by 461e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) // doing nothing here. 471e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) if (suppress_mouse_released_action_) { 481e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) suppress_mouse_released_action_ = false; 491e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) return; 501e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) } 511e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) 521e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) if (event.IsOnlyLeftMouseButton() && HitTestPoint(event.location())) { 531e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) OnExecuting(EXECUTE_SOURCE_MOUSE); 541e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) command_updater_->ExecuteCommand(command_id_); 551e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) } 561e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)} 571e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) 581e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)bool BubbleIconView::OnKeyPressed(const ui::KeyEvent& event) { 591e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) if (event.key_code() == ui::VKEY_SPACE || 601e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) event.key_code() == ui::VKEY_RETURN) { 611e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) OnExecuting(EXECUTE_SOURCE_KEYBOARD); 621e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) command_updater_->ExecuteCommand(command_id_); 631e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) return true; 641e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) } 651e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) return false; 661e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)} 671e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) 681e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)void BubbleIconView::OnGestureEvent(ui::GestureEvent* event) { 691e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) if (event->type() == ui::ET_GESTURE_TAP) { 701e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) OnExecuting(EXECUTE_SOURCE_GESTURE); 711e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) command_updater_->ExecuteCommand(command_id_); 721e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) event->SetHandled(); 731e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) } 741e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)} 75