Revert of Add button to add new FSP services to Files app. (patchset #8 id:140001...
[chromium-blink-merge.git] / chrome / browser / ui / views / location_bar / bubble_icon_view.cc
blobd74f32937b6aa3edd0a181bb149c653e97b45caf
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 ExecuteCommand(EXECUTE_SOURCE_MOUSE);
56 bool BubbleIconView::OnKeyPressed(const ui::KeyEvent& event) {
57 if (event.key_code() == ui::VKEY_SPACE ||
58 event.key_code() == ui::VKEY_RETURN) {
59 ExecuteCommand(EXECUTE_SOURCE_KEYBOARD);
60 return true;
62 return false;
65 void BubbleIconView::OnGestureEvent(ui::GestureEvent* event) {
66 if (event->type() == ui::ET_GESTURE_TAP) {
67 ExecuteCommand(EXECUTE_SOURCE_GESTURE);
68 event->SetHandled();
72 void BubbleIconView::ExecuteCommand(ExecuteSource source) {
73 OnExecuting(source);
74 if (command_updater_)
75 command_updater_->ExecuteCommand(command_id_);