| OLD | NEW |
| (Empty) | |
| 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/bubble_icon_view_delegate.h" |
| 9 #include "chrome/browser/ui/views/location_bar/location_bar_view.h" |
| 10 #include "ui/base/accessibility/accessible_view_state.h" |
| 11 #include "ui/events/event.h" |
| 12 |
| 13 BubbleIconView::BubbleIconView(CommandUpdater* command_updater, int command_id) |
| 14 : command_updater_(command_updater), |
| 15 command_id_(command_id), |
| 16 suppress_mouse_released_action_(false) { |
| 17 set_accessibility_focusable(true); |
| 18 LocationBarView::InitTouchableLocationBarChildView(this); |
| 19 } |
| 20 |
| 21 BubbleIconView::~BubbleIconView() { |
| 22 } |
| 23 |
| 24 void BubbleIconView::GetAccessibleState(ui::AccessibleViewState* state) { |
| 25 views::ImageView::GetAccessibleState(state); |
| 26 state->role = ui::AccessibilityTypes::ROLE_PUSHBUTTON; |
| 27 } |
| 28 |
| 29 bool BubbleIconView::GetTooltipText(const gfx::Point& p, |
| 30 string16* tooltip) const { |
| 31 if (delegate_->IsBubbleShowing()) |
| 32 return false; |
| 33 |
| 34 return views::ImageView::GetTooltipText(p, tooltip); |
| 35 } |
| 36 |
| 37 bool BubbleIconView::OnMousePressed(const ui::MouseEvent& event) { |
| 38 // If the bubble is showing then don't reshow it when the mouse is released. |
| 39 suppress_mouse_released_action_ = delegate_->IsBubbleShowing(); |
| 40 |
| 41 // We want to show the bubble on mouse release; that is the standard behavior |
| 42 // for buttons. |
| 43 return true; |
| 44 } |
| 45 |
| 46 void BubbleIconView::OnMouseReleased(const ui::MouseEvent& event) { |
| 47 // If this is the second click on this view then the bubble was showing on the |
| 48 // mouse pressed event and is hidden now. Prevent the bubble from reshowing by |
| 49 // doing nothing here. |
| 50 if (suppress_mouse_released_action_) { |
| 51 suppress_mouse_released_action_ = false; |
| 52 return; |
| 53 } |
| 54 |
| 55 if (event.IsOnlyLeftMouseButton() && HitTestPoint(event.location())) { |
| 56 delegate_->OnExecutingByMouse(); |
| 57 command_updater_->ExecuteCommand(command_id_); |
| 58 } |
| 59 } |
| 60 |
| 61 bool BubbleIconView::OnKeyPressed(const ui::KeyEvent& event) { |
| 62 if (event.key_code() == ui::VKEY_SPACE || |
| 63 event.key_code() == ui::VKEY_RETURN) { |
| 64 delegate_->OnExecutingByKey(); |
| 65 command_updater_->ExecuteCommand(command_id_); |
| 66 return true; |
| 67 } |
| 68 return false; |
| 69 } |
| 70 |
| 71 void BubbleIconView::OnGestureEvent(ui::GestureEvent* event) { |
| 72 if (event->type() == ui::ET_GESTURE_TAP) { |
| 73 delegate_->OnExecutingByGesture(); |
| 74 command_updater_->ExecuteCommand(command_id_); |
| 75 event->SetHandled(); |
| 76 } |
| 77 } |
| OLD | NEW |