diff options
author | flackr@chromium.org <flackr@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-06-12 15:44:26 +0000 |
---|---|---|
committer | flackr@chromium.org <flackr@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-06-12 15:44:26 +0000 |
commit | feca7602c5acb99dadd8946a7fe6d66fadfde075 (patch) | |
tree | dda3819874bd077814cfdf77beaa42c7cb1f5cad /ui/views | |
parent | beb3d42b84329e24ef92dd441d8c79c6783e2731 (diff) | |
download | chromium_src-feca7602c5acb99dadd8946a7fe6d66fadfde075.zip chromium_src-feca7602c5acb99dadd8946a7fe6d66fadfde075.tar.gz chromium_src-feca7602c5acb99dadd8946a7fe6d66fadfde075.tar.bz2 |
Make IsTriggerableEvent take Event objects and use it to verify whether tap events should trigger.
BUG=131184,131200
TEST=Click on a bookmark folder button, it should not try / prompt to open all of the links in the folder.
Review URL: https://chromiumcodereview.appspot.com/10546104
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@141664 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'ui/views')
-rw-r--r-- | ui/views/controls/button/button_dropdown.cc | 12 | ||||
-rw-r--r-- | ui/views/controls/button/button_dropdown.h | 4 | ||||
-rw-r--r-- | ui/views/controls/button/custom_button.cc | 14 | ||||
-rw-r--r-- | ui/views/controls/button/custom_button.h | 4 | ||||
-rw-r--r-- | ui/views/controls/menu/menu_delegate.cc | 9 | ||||
-rw-r--r-- | ui/views/controls/menu/menu_delegate.h | 8 | ||||
-rw-r--r-- | ui/views/controls/menu/menu_model_adapter.cc | 6 | ||||
-rw-r--r-- | ui/views/controls/menu/menu_model_adapter.h | 4 |
8 files changed, 36 insertions, 25 deletions
diff --git a/ui/views/controls/button/button_dropdown.cc b/ui/views/controls/button/button_dropdown.cc index 3fcfb61..3a0e866 100644 --- a/ui/views/controls/button/button_dropdown.cc +++ b/ui/views/controls/button/button_dropdown.cc @@ -123,11 +123,13 @@ void ButtonDropDown::GetAccessibleState(ui::AccessibleViewState* state) { state->state = ui::AccessibilityTypes::STATE_HASPOPUP; } -bool ButtonDropDown::ShouldEnterPushedState(const MouseEvent& event) { - // Enter PUSHED state on press with Left or Right mouse button. Remain - // in this state while the context menu is open. - return ((ui::EF_LEFT_MOUSE_BUTTON | - ui::EF_RIGHT_MOUSE_BUTTON) & event.flags()) != 0; +bool ButtonDropDown::ShouldEnterPushedState(const Event& event) { + // Enter PUSHED state on press with Left or Right mouse button or on taps. + // Remain in this state while the context menu is open. + return event.type() == ui::ET_GESTURE_TAP || + event.type() == ui::ET_GESTURE_TAP_DOWN || + (event.IsMouseEvent() && ((ui::EF_LEFT_MOUSE_BUTTON | + ui::EF_RIGHT_MOUSE_BUTTON) & event.flags()) != 0); } void ButtonDropDown::ShowDropDownMenu(gfx::NativeView window) { diff --git a/ui/views/controls/button/button_dropdown.h b/ui/views/controls/button/button_dropdown.h index e5f464b..eec7cbe 100644 --- a/ui/views/controls/button/button_dropdown.h +++ b/ui/views/controls/button/button_dropdown.h @@ -1,4 +1,4 @@ -// Copyright (c) 2011 The Chromium Authors. All rights reserved. +// Copyright (c) 2012 The Chromium Authors. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. @@ -50,7 +50,7 @@ class VIEWS_EXPORT ButtonDropDown : public ImageButton { // pressed when a user holds the mouse down over the button. For this // implementation, both left and right mouse buttons can trigger a change // to the PUSHED state. - virtual bool ShouldEnterPushedState(const MouseEvent& event) OVERRIDE; + virtual bool ShouldEnterPushedState(const Event& event) OVERRIDE; private: // Internal function to show the dropdown menu diff --git a/ui/views/controls/button/custom_button.cc b/ui/views/controls/button/custom_button.cc index 897c772..c45f573 100644 --- a/ui/views/controls/button/custom_button.cc +++ b/ui/views/controls/button/custom_button.cc @@ -197,7 +197,7 @@ ui::GestureStatus CustomButton::OnGestureEvent(const GestureEvent& event) { if (state_ == BS_DISABLED) return ui::GESTURE_STATUS_UNKNOWN; - if (event.type() == ui::ET_GESTURE_TAP) { + if (event.type() == ui::ET_GESTURE_TAP && IsTriggerableEvent(event)) { // Set the button state to hot and start the animation fully faded in. The // TAP_UP event issued immediately after will set the state to BS_NORMAL // beginning the fade out animation. See http://crbug.com/131184. @@ -205,7 +205,8 @@ ui::GestureStatus CustomButton::OnGestureEvent(const GestureEvent& event) { hover_animation_->Reset(1.0); NotifyClick(event); return ui::GESTURE_STATUS_CONSUMED; - } else if (event.type() == ui::ET_GESTURE_TAP_DOWN) { + } else if (event.type() == ui::ET_GESTURE_TAP_DOWN && + ShouldEnterPushedState(event)) { SetState(BS_PUSHED); if (request_focus_on_press_) RequestFocus(); @@ -282,11 +283,14 @@ CustomButton::CustomButton(ButtonListener* listener) void CustomButton::StateChanged() { } -bool CustomButton::IsTriggerableEvent(const MouseEvent& event) { - return (triggerable_event_flags_ & event.flags()) != 0; +bool CustomButton::IsTriggerableEvent(const Event& event) { + return event.type() == ui::ET_GESTURE_TAP_DOWN || + event.type() == ui::ET_GESTURE_TAP || + (event.IsMouseEvent() && + (triggerable_event_flags_ & event.flags()) != 0); } -bool CustomButton::ShouldEnterPushedState(const MouseEvent& event) { +bool CustomButton::ShouldEnterPushedState(const Event& event) { return IsTriggerableEvent(event); } diff --git a/ui/views/controls/button/custom_button.h b/ui/views/controls/button/custom_button.h index 46a99ea..0d30ee4 100644 --- a/ui/views/controls/button/custom_button.h +++ b/ui/views/controls/button/custom_button.h @@ -110,12 +110,12 @@ class VIEWS_EXPORT CustomButton : public Button, // Returns true if the event is one that can trigger notifying the listener. // This implementation returns true if the left mouse button is down. - virtual bool IsTriggerableEvent(const MouseEvent& event); + virtual bool IsTriggerableEvent(const Event& event); // Returns true if the button should become pressed when the user // holds the mouse down over the button. For this implementation, // we simply return IsTriggerableEvent(event). - virtual bool ShouldEnterPushedState(const MouseEvent& event); + virtual bool ShouldEnterPushedState(const Event& event); // Overridden from View: virtual void ViewHierarchyChanged(bool is_add, diff --git a/ui/views/controls/menu/menu_delegate.cc b/ui/views/controls/menu/menu_delegate.cc index 0663659..48a6210 100644 --- a/ui/views/controls/menu/menu_delegate.cc +++ b/ui/views/controls/menu/menu_delegate.cc @@ -1,4 +1,4 @@ -// Copyright (c) 2011 The Chromium Authors. All rights reserved. +// Copyright (c) 2012 The Chromium Authors. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. @@ -58,8 +58,11 @@ void MenuDelegate::ExecuteCommand(int id, int mouse_event_flags) { } bool MenuDelegate::IsTriggerableEvent(MenuItemView* source, - const MouseEvent& e) { - return e.IsLeftMouseButton() || e.IsRightMouseButton(); + const Event& e) { + return e.type() == ui::ET_GESTURE_TAP || + e.type() == ui::ET_GESTURE_TAP_DOWN || + (e.IsMouseEvent() && (e.flags() & + (ui::EF_LEFT_MOUSE_BUTTON | ui::EF_RIGHT_MOUSE_BUTTON))); } bool MenuDelegate::CanDrop(MenuItemView* menu, const OSExchangeData& data) { diff --git a/ui/views/controls/menu/menu_delegate.h b/ui/views/controls/menu/menu_delegate.h index a740a43..b88182b 100644 --- a/ui/views/controls/menu/menu_delegate.h +++ b/ui/views/controls/menu/menu_delegate.h @@ -1,4 +1,4 @@ -// Copyright (c) 2011 The Chromium Authors. All rights reserved. +// Copyright (c) 2012 The Chromium Authors. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. @@ -114,9 +114,9 @@ class VIEWS_EXPORT MenuDelegate { // other than a mouse event. virtual void ExecuteCommand(int id, int mouse_event_flags); - // Returns true if the specified mouse event is one the user can use - // to trigger, or accept, the mouse. Defaults to left or right mouse buttons. - virtual bool IsTriggerableEvent(MenuItemView* view, const MouseEvent& e); + // Returns true if the specified event is one the user can use to trigger, or + // accept, the item. Defaults to left or right mouse buttons or tap. + virtual bool IsTriggerableEvent(MenuItemView* view, const Event& e); // Invoked to determine if drops can be accepted for a submenu. This is // ONLY invoked for menus that have submenus and indicates whether or not diff --git a/ui/views/controls/menu/menu_model_adapter.cc b/ui/views/controls/menu/menu_model_adapter.cc index 583c74a..97b3266 100644 --- a/ui/views/controls/menu/menu_model_adapter.cc +++ b/ui/views/controls/menu/menu_model_adapter.cc @@ -75,8 +75,10 @@ void MenuModelAdapter::ExecuteCommand(int id, int mouse_event_flags) { } bool MenuModelAdapter::IsTriggerableEvent(MenuItemView* source, - const MouseEvent& e) { - return (triggerable_event_flags_ & e.flags()) != 0; + const Event& e) { + return e.type() == ui::ET_GESTURE_TAP || + e.type() == ui::ET_GESTURE_TAP_DOWN || + (e.IsMouseEvent() && (triggerable_event_flags_ & e.flags()) != 0); } bool MenuModelAdapter::GetAccelerator(int id, diff --git a/ui/views/controls/menu/menu_model_adapter.h b/ui/views/controls/menu/menu_model_adapter.h index 6bc9e51..8397d94 100644 --- a/ui/views/controls/menu/menu_model_adapter.h +++ b/ui/views/controls/menu/menu_model_adapter.h @@ -1,4 +1,4 @@ -// Copyright (c) 2011 The Chromium Authors. All rights reserved. +// Copyright (c) 2012 The Chromium Authors. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. @@ -44,7 +44,7 @@ class VIEWS_EXPORT MenuModelAdapter : public MenuDelegate { virtual void ExecuteCommand(int id) OVERRIDE; virtual void ExecuteCommand(int id, int mouse_event_flags) OVERRIDE; virtual bool IsTriggerableEvent(MenuItemView* source, - const MouseEvent& e) OVERRIDE; + const Event& e) OVERRIDE; virtual bool GetAccelerator(int id, ui::Accelerator* accelerator) OVERRIDE; virtual string16 GetLabel(int id) const OVERRIDE; |