diff options
author | sadrul@chromium.org <sadrul@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-11-01 04:31:58 +0000 |
---|---|---|
committer | sadrul@chromium.org <sadrul@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-11-01 04:31:58 +0000 |
commit | 3630942bd18a8f06d67412b737340a2eaa845753 (patch) | |
tree | fc9a5be75d6b2aa223e3c901bea2b3eb6a2be4da /ui | |
parent | cba02a81e3e7a84663975d741276a842794ad95f (diff) | |
download | chromium_src-3630942bd18a8f06d67412b737340a2eaa845753.zip chromium_src-3630942bd18a8f06d67412b737340a2eaa845753.tar.gz chromium_src-3630942bd18a8f06d67412b737340a2eaa845753.tar.bz2 |
views: Start converting View into an EventTarget.
The EventDispatcher interface is not acually used for dispatching events yet.
That will happen once RootView is turned into an EventDispatcher. But this first
step prepares scroll, touch, and gesture event dispatching in views so that it
is compatible with the EventDispatcher interface.
BUG=none
Review URL: https://codereview.chromium.org/11364015
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@165288 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'ui')
45 files changed, 511 insertions, 505 deletions
diff --git a/ui/app_list/app_list_item_view.cc b/ui/app_list/app_list_item_view.cc index 2e54825..9500e26 100644 --- a/ui/app_list/app_list_item_view.cc +++ b/ui/app_list/app_list_item_view.cc @@ -307,18 +307,17 @@ bool AppListItemView::OnMouseDragged(const ui::MouseEvent& event) { return true; } -ui::EventResult AppListItemView::OnGestureEvent( - const ui::GestureEvent& event) { - switch (event.type()) { +ui::EventResult AppListItemView::OnGestureEvent(ui::GestureEvent* event) { + switch (event->type()) { case ui::ET_GESTURE_SCROLL_BEGIN: if (touch_dragging_) { - apps_grid_view_->InitiateDrag(this, AppsGridView::TOUCH, event); + apps_grid_view_->InitiateDrag(this, AppsGridView::TOUCH, *event); return ui::ER_CONSUMED; } break; case ui::ET_GESTURE_SCROLL_UPDATE: if (touch_dragging_) { - apps_grid_view_->UpdateDrag(this, AppsGridView::TOUCH, event); + apps_grid_view_->UpdateDrag(this, AppsGridView::TOUCH, *event); return ui::ER_CONSUMED; } break; @@ -338,7 +337,7 @@ ui::EventResult AppListItemView::OnGestureEvent( if (touch_dragging_) { SetTouchDragging(false); - gfx::Point location(event.location()); + gfx::Point location(event->location()); ConvertPointToScreen(this, &location); ShowContextMenu(location, true); } diff --git a/ui/app_list/app_list_item_view.h b/ui/app_list/app_list_item_view.h index 42f2493..0e1937c 100644 --- a/ui/app_list/app_list_item_view.h +++ b/ui/app_list/app_list_item_view.h @@ -84,8 +84,9 @@ class APP_LIST_EXPORT AppListItemView : public views::CustomButton, virtual void OnMouseReleased(const ui::MouseEvent& event) OVERRIDE; virtual void OnMouseCaptureLost() OVERRIDE; virtual bool OnMouseDragged(const ui::MouseEvent& event) OVERRIDE; - virtual ui::EventResult OnGestureEvent( - const ui::GestureEvent& event) OVERRIDE; + + // ui::EventHandler overrides: + virtual ui::EventResult OnGestureEvent(ui::GestureEvent* event) OVERRIDE; AppListItemModel* model_; // Owned by AppListModel::Apps. diff --git a/ui/app_list/contents_view.cc b/ui/app_list/contents_view.cc index 4b9e8b6..5aa9c58 100644 --- a/ui/app_list/contents_view.cc +++ b/ui/app_list/contents_view.cc @@ -158,20 +158,44 @@ void ContentsView::Layout() { views::ViewModelUtils::SetViewBoundsToIdealBounds(*view_model_); } -ui::EventResult ContentsView::OnGestureEvent( - const ui::GestureEvent& event) { +bool ContentsView::OnKeyPressed(const ui::KeyEvent& event) { + switch (show_state_) { + case SHOW_APPS: + return GetAppsGridView(view_model_.get())->OnKeyPressed(event); + case SHOW_SEARCH_RESULTS: + return GetSearchResultListView(view_model_.get())->OnKeyPressed(event); + default: + NOTREACHED() << "Unknown show state " << show_state_; + } + return false; +} + +bool ContentsView::OnMouseWheel(const ui::MouseWheelEvent& event) { + if (show_state_ != SHOW_APPS) + return false; + + if (abs(event.offset()) > kMinMouseWheelToSwitchPage) { + if (!pagination_model_->has_transition()) + pagination_model_->SelectPageRelative(event.offset() > 0 ? -1 : 1, true); + return true; + } + + return false; +} + +ui::EventResult ContentsView::OnGestureEvent(ui::GestureEvent* event) { if (show_state_ != SHOW_APPS) return ui::ER_UNHANDLED; - switch (event.type()) { + switch (event->type()) { case ui::ET_GESTURE_SCROLL_BEGIN: pagination_model_->StartScroll(); return ui::ER_CONSUMED; case ui::ET_GESTURE_SCROLL_UPDATE: - // event.details.scroll_x() > 0 means moving contents to right. That is, + // event->details.scroll_x() > 0 means moving contents to right. That is, // transitioning to previous page. pagination_model_->UpdateScroll( - event.details().scroll_x() / GetContentsBounds().width()); + event->details().scroll_x() / GetContentsBounds().width()); return ui::ER_CONSUMED; case ui::ET_GESTURE_SCROLL_END: pagination_model_->EndScroll(pagination_model_-> @@ -179,9 +203,9 @@ ui::EventResult ContentsView::OnGestureEvent( return ui::ER_CONSUMED; case ui::ET_SCROLL_FLING_START: { pagination_model_->EndScroll(true); - if (fabs(event.details().velocity_x()) > kMinHorizVelocityToSwitchPage) { + if (fabs(event->details().velocity_x()) > kMinHorizVelocityToSwitchPage) { pagination_model_->SelectPageRelative( - event.details().velocity_x() < 0 ? 1 : -1, + event->details().velocity_x() < 0 ? 1 : -1, true); } return ui::ER_CONSUMED; @@ -193,44 +217,19 @@ ui::EventResult ContentsView::OnGestureEvent( return ui::ER_UNHANDLED; } -bool ContentsView::OnKeyPressed(const ui::KeyEvent& event) { - switch (show_state_) { - case SHOW_APPS: - return GetAppsGridView(view_model_.get())->OnKeyPressed(event); - case SHOW_SEARCH_RESULTS: - return GetSearchResultListView(view_model_.get())->OnKeyPressed(event); - default: - NOTREACHED() << "Unknown show state " << show_state_; - } - return false; -} - -bool ContentsView::OnMouseWheel(const ui::MouseWheelEvent& event) { +ui::EventResult ContentsView::OnScrollEvent(ui::ScrollEvent* event) { if (show_state_ != SHOW_APPS) - return false; - - if (abs(event.offset()) > kMinMouseWheelToSwitchPage) { - if (!pagination_model_->has_transition()) - pagination_model_->SelectPageRelative(event.offset() > 0 ? -1 : 1, true); - return true; - } - - return false; -} - -bool ContentsView::OnScrollEvent(const ui::ScrollEvent& event) { - if (show_state_ != SHOW_APPS) - return false; + return ui::ER_UNHANDLED; - if (abs(event.x_offset()) > kMinScrollToSwitchPage) { + if (abs(event->x_offset()) > kMinScrollToSwitchPage) { if (!pagination_model_->has_transition()) { - pagination_model_->SelectPageRelative(event.x_offset() > 0 ? -1 : 1, + pagination_model_->SelectPageRelative(event->x_offset() > 0 ? -1 : 1, true); } - return true; + return ui::ER_HANDLED; } - return false; + return ui::ER_UNHANDLED; } } // namespace app_list diff --git a/ui/app_list/contents_view.h b/ui/app_list/contents_view.h index a6f6fe7..7a2160e 100644 --- a/ui/app_list/contents_view.h +++ b/ui/app_list/contents_view.h @@ -53,11 +53,12 @@ class ContentsView : public views::View { // Overridden from views::View: virtual gfx::Size GetPreferredSize() OVERRIDE; virtual void Layout() OVERRIDE; - virtual ui::EventResult OnGestureEvent( - const ui::GestureEvent& event) OVERRIDE; virtual bool OnKeyPressed(const ui::KeyEvent& event) OVERRIDE; virtual bool OnMouseWheel(const ui::MouseWheelEvent& event) OVERRIDE; - virtual bool OnScrollEvent(const ui::ScrollEvent& event) OVERRIDE; + + // Overridden from ui::EventHandler: + virtual ui::EventResult OnGestureEvent(ui::GestureEvent* event) OVERRIDE; + virtual ui::EventResult OnScrollEvent(ui::ScrollEvent* event) OVERRIDE; ShowState show_state_; PaginationModel* pagination_model_; // Owned by AppListController. diff --git a/ui/base/events/event_target.cc b/ui/base/events/event_target.cc index 505c299..1f8db028 100644 --- a/ui/base/events/event_target.cc +++ b/ui/base/events/event_target.cc @@ -44,31 +44,6 @@ void EventTarget::RemovePostTargetHandler(EventHandler* handler) { post_target_list_.erase(find); } -void EventTarget::GetPreTargetHandlers(EventHandlerList* list) { - EventTarget* target = this; - while (target) { - EventHandlerList::reverse_iterator it, rend; - for (it = target->pre_target_list_.rbegin(), - rend = target->pre_target_list_.rend(); - it != rend; - ++it) { - list->insert(list->begin(), *it); - } - target = target->GetParentTarget(); - } -} - -void EventTarget::GetPostTargetHandlers(EventHandlerList* list) { - EventTarget* target = this; - while (target) { - for (EventHandlerList::iterator it = target->post_target_list_.begin(), - end = target->post_target_list_.end(); it != end; ++it) { - list->push_back(*it); - } - target = target->GetParentTarget(); - } -} - EventResult EventTarget::OnKeyEvent(KeyEvent* event) { CHECK_EQ(this, event->target()); return target_handler_ ? target_handler_->OnKeyEvent(event) : ER_UNHANDLED; @@ -96,4 +71,29 @@ EventResult EventTarget::OnGestureEvent(GestureEvent* event) { ER_UNHANDLED; } +void EventTarget::GetPreTargetHandlers(EventHandlerList* list) { + EventTarget* target = this; + while (target) { + EventHandlerList::reverse_iterator it, rend; + for (it = target->pre_target_list_.rbegin(), + rend = target->pre_target_list_.rend(); + it != rend; + ++it) { + list->insert(list->begin(), *it); + } + target = target->GetParentTarget(); + } +} + +void EventTarget::GetPostTargetHandlers(EventHandlerList* list) { + EventTarget* target = this; + while (target) { + for (EventHandlerList::iterator it = target->post_target_list_.begin(), + end = target->post_target_list_.end(); it != end; ++it) { + list->push_back(*it); + } + target = target->GetParentTarget(); + } +} + } // namespace ui diff --git a/ui/base/events/event_target.h b/ui/base/events/event_target.h index 4215dcb..eebfc67 100644 --- a/ui/base/events/event_target.h +++ b/ui/base/events/event_target.h @@ -70,6 +70,13 @@ class UI_EXPORT EventTarget : public EventHandler { target_handler_ = handler; } + // Overridden from EventHandler: + virtual EventResult OnKeyEvent(KeyEvent* event) OVERRIDE; + virtual EventResult OnMouseEvent(MouseEvent* event) OVERRIDE; + virtual EventResult OnScrollEvent(ScrollEvent* event) OVERRIDE; + virtual EventResult OnTouchEvent(TouchEvent* event) OVERRIDE; + virtual EventResult OnGestureEvent(GestureEvent* event) OVERRIDE; + private: friend class EventDispatcher; @@ -83,13 +90,6 @@ class UI_EXPORT EventTarget : public EventHandler { // the handlers on |this| are the first in the list. void GetPostTargetHandlers(EventHandlerList* list); - // Overridden from EventHandler: - virtual EventResult OnKeyEvent(KeyEvent* event) OVERRIDE; - virtual EventResult OnMouseEvent(MouseEvent* event) OVERRIDE; - virtual EventResult OnScrollEvent(ScrollEvent* event) OVERRIDE; - virtual EventResult OnTouchEvent(TouchEvent* event) OVERRIDE; - virtual EventResult OnGestureEvent(GestureEvent* event) OVERRIDE; - EventHandlerList pre_target_list_; EventHandlerList post_target_list_; EventHandler* target_handler_; diff --git a/ui/message_center/message_view.cc b/ui/message_center/message_view.cc index 816ed3d..9225995 100644 --- a/ui/message_center/message_view.cc +++ b/ui/message_center/message_view.cc @@ -209,24 +209,23 @@ bool MessageView::OnMousePressed(const ui::MouseEvent& event) { return true; } -ui::EventResult MessageView::OnGestureEvent( - const ui::GestureEvent& event) { - if (event.type() == ui::ET_GESTURE_TAP) { +ui::EventResult MessageView::OnGestureEvent(ui::GestureEvent* event) { + if (event->type() == ui::ET_GESTURE_TAP) { list_delegate_->OnNotificationClicked(notification_.id); return ui::ER_CONSUMED; } - if (event.type() == ui::ET_GESTURE_LONG_PRESS) { - ShowMenu(event.location()); + if (event->type() == ui::ET_GESTURE_LONG_PRESS) { + ShowMenu(event->location()); return ui::ER_CONSUMED; } - if (event.type() == ui::ET_SCROLL_FLING_START) { + if (event->type() == ui::ET_SCROLL_FLING_START) { // The threshold for the fling velocity is computed empirically. // The unit is in pixels/second. const float kFlingThresholdForClose = 800.f; - if (fabsf(event.details().velocity_x()) > kFlingThresholdForClose) { - SlideOutAndClose(event.details().velocity_x() < 0 ? SLIDE_LEFT : + if (fabsf(event->details().velocity_x()) > kFlingThresholdForClose) { + SlideOutAndClose(event->details().velocity_x() < 0 ? SLIDE_LEFT : SLIDE_RIGHT); } else if (scroller_) { RestoreVisualState(); @@ -235,14 +234,14 @@ ui::EventResult MessageView::OnGestureEvent( return ui::ER_CONSUMED; } - if (!event.IsScrollGestureEvent()) + if (!event->IsScrollGestureEvent()) return ui::ER_UNHANDLED; - if (event.type() == ui::ET_GESTURE_SCROLL_BEGIN) { + if (event->type() == ui::ET_GESTURE_SCROLL_BEGIN) { gesture_scroll_amount_ = 0.f; - } else if (event.type() == ui::ET_GESTURE_SCROLL_UPDATE) { + } else if (event->type() == ui::ET_GESTURE_SCROLL_UPDATE) { // The scroll-update events include the incremental scroll amount. - gesture_scroll_amount_ += event.details().scroll_x(); + gesture_scroll_amount_ += event->details().scroll_x(); gfx::Transform transform; transform.SetTranslateX(gesture_scroll_amount_); @@ -250,7 +249,7 @@ ui::EventResult MessageView::OnGestureEvent( layer()->SetOpacity( 1.f - std::min(fabsf(gesture_scroll_amount_) / width(), 1.f)); - } else if (event.type() == ui::ET_GESTURE_SCROLL_END) { + } else if (event->type() == ui::ET_GESTURE_SCROLL_END) { const float kScrollRatioForClosingNotification = 0.5f; float scrolled_ratio = fabsf(gesture_scroll_amount_) / width(); if (scrolled_ratio >= kScrollRatioForClosingNotification) diff --git a/ui/message_center/message_view.h b/ui/message_center/message_view.h index 94a268f..6ec3d30 100644 --- a/ui/message_center/message_view.h +++ b/ui/message_center/message_view.h @@ -39,8 +39,8 @@ class MessageView : public views::View, // views::View overrides. virtual bool OnMousePressed(const ui::MouseEvent& event) OVERRIDE; - virtual ui::EventResult OnGestureEvent( - const ui::GestureEvent& event) OVERRIDE; + // ui::EventHandler overrides. + virtual ui::EventResult OnGestureEvent(ui::GestureEvent* event) OVERRIDE; // Overridden from ButtonListener. virtual void ButtonPressed(views::Button* sender, diff --git a/ui/views/color_chooser/color_chooser_view.cc b/ui/views/color_chooser/color_chooser_view.cc index f6e16d3..fb23fce 100644 --- a/ui/views/color_chooser/color_chooser_view.cc +++ b/ui/views/color_chooser/color_chooser_view.cc @@ -73,12 +73,11 @@ class LocatedEventHandlerView : public views::View { return true; } - virtual ui::EventResult OnGestureEvent( - const ui::GestureEvent& event) OVERRIDE { - if (event.type() == ui::ET_GESTURE_TAP || - event.type() == ui::ET_GESTURE_TAP_DOWN || - event.IsScrollGestureEvent()) { - ProcessEventAtLocation(event.location()); + virtual ui::EventResult OnGestureEvent(ui::GestureEvent* event) OVERRIDE { + if (event->type() == ui::ET_GESTURE_TAP || + event->type() == ui::ET_GESTURE_TAP_DOWN || + event->IsScrollGestureEvent()) { + ProcessEventAtLocation(event->location()); return ui::ER_CONSUMED; } return ui::ER_UNHANDLED; diff --git a/ui/views/controls/button/custom_button.cc b/ui/views/controls/button/custom_button.cc index 6e98141..1fa9dcb 100644 --- a/ui/views/controls/button/custom_button.cc +++ b/ui/views/controls/button/custom_button.cc @@ -207,20 +207,20 @@ bool CustomButton::OnKeyReleased(const ui::KeyEvent& event) { return true; } -ui::EventResult CustomButton::OnGestureEvent(const ui::GestureEvent& event) { +ui::EventResult CustomButton::OnGestureEvent(ui::GestureEvent* event) { if (state_ == BS_DISABLED) return Button::OnGestureEvent(event); - if (event.type() == ui::ET_GESTURE_TAP && IsTriggerableEvent(event)) { + 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. SetState(BS_HOT); hover_animation_->Reset(1.0); - NotifyClick(event); + NotifyClick(*event); return ui::ER_CONSUMED; - } else if (event.type() == ui::ET_GESTURE_TAP_DOWN && - ShouldEnterPushedState(event)) { + } else if (event->type() == ui::ET_GESTURE_TAP_DOWN && + ShouldEnterPushedState(*event)) { SetState(BS_PUSHED); if (request_focus_on_press_) RequestFocus(); diff --git a/ui/views/controls/button/custom_button.h b/ui/views/controls/button/custom_button.h index 1002fee..7370487 100644 --- a/ui/views/controls/button/custom_button.h +++ b/ui/views/controls/button/custom_button.h @@ -90,8 +90,7 @@ class VIEWS_EXPORT CustomButton : public Button, virtual void OnMouseMoved(const ui::MouseEvent& event) OVERRIDE; virtual bool OnKeyPressed(const ui::KeyEvent& event) OVERRIDE; virtual bool OnKeyReleased(const ui::KeyEvent& event) OVERRIDE; - virtual ui::EventResult OnGestureEvent( - const ui::GestureEvent& event) OVERRIDE; + virtual ui::EventResult OnGestureEvent(ui::GestureEvent* event) OVERRIDE; virtual bool AcceleratorPressed(const ui::Accelerator& accelerator) OVERRIDE; virtual void ShowContextMenu(const gfx::Point& p, bool is_mouse_gesture) OVERRIDE; diff --git a/ui/views/controls/button/menu_button.cc b/ui/views/controls/button/menu_button.cc index a61a74e..5d16735 100644 --- a/ui/views/controls/button/menu_button.cc +++ b/ui/views/controls/button/menu_button.cc @@ -219,8 +219,8 @@ void MenuButton::OnMouseExited(const ui::MouseEvent& event) { } } -ui::EventResult MenuButton::OnGestureEvent(const ui::GestureEvent& event) { - if (state() != BS_DISABLED && event.type() == ui::ET_GESTURE_TAP) { +ui::EventResult MenuButton::OnGestureEvent(ui::GestureEvent* event) { + if (state() != BS_DISABLED && event->type() == ui::ET_GESTURE_TAP) { if (Activate()) return ui::ER_CONSUMED; return ui::ER_UNHANDLED; diff --git a/ui/views/controls/button/menu_button.h b/ui/views/controls/button/menu_button.h index 34f1866..cb48bb5 100644 --- a/ui/views/controls/button/menu_button.h +++ b/ui/views/controls/button/menu_button.h @@ -62,8 +62,7 @@ class VIEWS_EXPORT MenuButton : public TextButton { virtual bool OnMousePressed(const ui::MouseEvent& event) OVERRIDE; virtual void OnMouseReleased(const ui::MouseEvent& event) OVERRIDE; virtual void OnMouseExited(const ui::MouseEvent& event) OVERRIDE; - virtual ui::EventResult OnGestureEvent( - const ui::GestureEvent& event) OVERRIDE; + virtual ui::EventResult OnGestureEvent(ui::GestureEvent* event) OVERRIDE; virtual bool OnKeyPressed(const ui::KeyEvent& event) OVERRIDE; virtual bool OnKeyReleased(const ui::KeyEvent& event) OVERRIDE; virtual void GetAccessibleState(ui::AccessibleViewState* state) OVERRIDE; diff --git a/ui/views/controls/combobox/native_combobox_views.cc b/ui/views/controls/combobox/native_combobox_views.cc index 67c49ed..9f67153 100644 --- a/ui/views/controls/combobox/native_combobox_views.cc +++ b/ui/views/controls/combobox/native_combobox_views.cc @@ -92,16 +92,6 @@ bool NativeComboboxViews::OnMouseDragged(const ui::MouseEvent& mouse_event) { return true; } -ui::EventResult NativeComboboxViews::OnGestureEvent( - const ui::GestureEvent& gesture_event) { - if (gesture_event.type() == ui::ET_GESTURE_TAP) { - UpdateFromModel(); - ShowDropDownMenu(); - return ui::ER_CONSUMED; - } - return View::OnGestureEvent(gesture_event); -} - bool NativeComboboxViews::OnKeyPressed(const ui::KeyEvent& key_event) { // TODO(oshima): handle IME. DCHECK_EQ(key_event.type(), ui::ET_KEY_PRESSED); @@ -169,6 +159,18 @@ void NativeComboboxViews::OnBlur() { } ///////////////////////////////////////////////////////////////// +// NativeComboboxViews, ui::EventHandler overrides: + +ui::EventResult NativeComboboxViews::OnGestureEvent(ui::GestureEvent* gesture) { + if (gesture->type() == ui::ET_GESTURE_TAP) { + UpdateFromModel(); + ShowDropDownMenu(); + return ui::ER_CONSUMED; + } + return View::OnGestureEvent(gesture); +} + +///////////////////////////////////////////////////////////////// // NativeComboboxViews, NativeComboboxWrapper overrides: void NativeComboboxViews::UpdateFromModel() { diff --git a/ui/views/controls/combobox/native_combobox_views.h b/ui/views/controls/combobox/native_combobox_views.h index b23c268..780c344 100644 --- a/ui/views/controls/combobox/native_combobox_views.h +++ b/ui/views/controls/combobox/native_combobox_views.h @@ -33,14 +33,15 @@ class NativeComboboxViews : public views::View, // views::View overrides: virtual bool OnMousePressed(const ui::MouseEvent& mouse_event) OVERRIDE; virtual bool OnMouseDragged(const ui::MouseEvent& mouse_event) OVERRIDE; - virtual ui::EventResult OnGestureEvent( - const ui::GestureEvent& gesture_event) OVERRIDE; virtual bool OnKeyPressed(const ui::KeyEvent& key_event) OVERRIDE; virtual bool OnKeyReleased(const ui::KeyEvent& key_event) OVERRIDE; virtual void OnPaint(gfx::Canvas* canvas) OVERRIDE; virtual void OnFocus() OVERRIDE; virtual void OnBlur() OVERRIDE; + // ui::EventHandler overrides: + virtual ui::EventResult OnGestureEvent(ui::GestureEvent* gesture) OVERRIDE; + // NativeComboboxWrapper overrides: virtual void UpdateFromModel() OVERRIDE; virtual void UpdateSelectedIndex() OVERRIDE; diff --git a/ui/views/controls/link.cc b/ui/views/controls/link.cc index d116aa3..c730c4a 100644 --- a/ui/views/controls/link.cc +++ b/ui/views/controls/link.cc @@ -111,16 +111,27 @@ bool Link::OnKeyPressed(const ui::KeyEvent& event) { return true; } -ui::EventResult Link::OnGestureEvent(const ui::GestureEvent& event) { +bool Link::SkipDefaultKeyEventProcessing(const ui::KeyEvent& event) { + // Make sure we don't process space or enter as accelerators. + return (event.key_code() == ui::VKEY_SPACE) || + (event.key_code() == ui::VKEY_RETURN); +} + +void Link::GetAccessibleState(ui::AccessibleViewState* state) { + Label::GetAccessibleState(state); + state->role = ui::AccessibilityTypes::ROLE_LINK; +} + +ui::EventResult Link::OnGestureEvent(ui::GestureEvent* event) { if (!enabled()) return ui::ER_UNHANDLED; - if (event.type() == ui::ET_GESTURE_TAP_DOWN) { + if (event->type() == ui::ET_GESTURE_TAP_DOWN) { SetPressed(true); - } else if (event.type() == ui::ET_GESTURE_TAP) { + } else if (event->type() == ui::ET_GESTURE_TAP) { RequestFocus(); if (listener_) - listener_->LinkClicked(this, event.flags()); + listener_->LinkClicked(this, event->flags()); } else { SetPressed(false); return ui::ER_UNHANDLED; @@ -128,17 +139,6 @@ ui::EventResult Link::OnGestureEvent(const ui::GestureEvent& event) { return ui::ER_CONSUMED; } -bool Link::SkipDefaultKeyEventProcessing(const ui::KeyEvent& event) { - // Make sure we don't process space or enter as accelerators. - return (event.key_code() == ui::VKEY_SPACE) || - (event.key_code() == ui::VKEY_RETURN); -} - -void Link::GetAccessibleState(ui::AccessibleViewState* state) { - Label::GetAccessibleState(state); - state->role = ui::AccessibilityTypes::ROLE_LINK; -} - void Link::SetFont(const gfx::Font& font) { Label::SetFont(font); RecalculateFont(); diff --git a/ui/views/controls/link.h b/ui/views/controls/link.h index 5fcce6f..3ea7147 100644 --- a/ui/views/controls/link.h +++ b/ui/views/controls/link.h @@ -39,13 +39,14 @@ class VIEWS_EXPORT Link : public Label { virtual bool OnMouseDragged(const ui::MouseEvent& event) OVERRIDE; virtual void OnMouseReleased(const ui::MouseEvent& event) OVERRIDE; virtual void OnMouseCaptureLost() OVERRIDE; - virtual ui::EventResult OnGestureEvent( - const ui::GestureEvent& event) OVERRIDE; virtual bool OnKeyPressed(const ui::KeyEvent& event) OVERRIDE; virtual bool SkipDefaultKeyEventProcessing( const ui::KeyEvent& event) OVERRIDE; virtual void GetAccessibleState(ui::AccessibleViewState* state) OVERRIDE; + // Overridden from ui::EventHandler: + virtual ui::EventResult OnGestureEvent(ui::GestureEvent* event) OVERRIDE; + // Overridden from Label: virtual void SetFont(const gfx::Font& font) OVERRIDE; diff --git a/ui/views/controls/menu/menu_controller.cc b/ui/views/controls/menu/menu_controller.cc index 796b45f..2bba402 100644 --- a/ui/views/controls/menu/menu_controller.cc +++ b/ui/views/controls/menu/menu_controller.cc @@ -525,21 +525,21 @@ bool MenuController::OnMouseWheel(SubmenuView* source, ui::EventResult MenuController::OnGestureEvent( SubmenuView* source, - const ui::GestureEvent& event) { - MenuPart part = GetMenuPart(source, event.location()); - if (event.type() == ui::ET_GESTURE_TAP_DOWN) { - SetSelectionOnPointerDown(source, event); + ui::GestureEvent* event) { + MenuPart part = GetMenuPart(source, event->location()); + if (event->type() == ui::ET_GESTURE_TAP_DOWN) { + SetSelectionOnPointerDown(source, *event); return ui::ER_CONSUMED; - } else if (event.type() == ui::ET_GESTURE_LONG_PRESS) { + } else if (event->type() == ui::ET_GESTURE_LONG_PRESS) { if (part.type == MenuPart::MENU_ITEM && part.menu) { - if (ShowContextMenu(part.menu, source, event)) + if (ShowContextMenu(part.menu, source, *event)) return ui::ER_CONSUMED; } - } else if (event.type() == ui::ET_GESTURE_TAP) { + } else if (event->type() == ui::ET_GESTURE_TAP) { if (!part.is_scroll() && part.menu && !(part.menu->HasSubmenu())) { if (part.menu->GetDelegate()->IsTriggerableEvent( - part.menu, event)) { + part.menu, *event)) { Accept(part.menu, 0); } return ui::ER_CONSUMED; diff --git a/ui/views/controls/menu/menu_controller.h b/ui/views/controls/menu/menu_controller.h index b22bc22..2486fa5 100644 --- a/ui/views/controls/menu/menu_controller.h +++ b/ui/views/controls/menu/menu_controller.h @@ -122,7 +122,7 @@ class VIEWS_EXPORT MenuController bool OnMouseWheel(SubmenuView* source, const ui::MouseWheelEvent& event); #endif ui::EventResult OnGestureEvent(SubmenuView* source, - const ui::GestureEvent& event); + ui::GestureEvent* event); bool GetDropFormats( SubmenuView* source, diff --git a/ui/views/controls/menu/menu_host_root_view.cc b/ui/views/controls/menu/menu_host_root_view.cc index 3e266f8..9555354 100644 --- a/ui/views/controls/menu/menu_host_root_view.cc +++ b/ui/views/controls/menu/menu_host_root_view.cc @@ -62,8 +62,7 @@ bool MenuHostRootView::OnMouseWheel(const ui::MouseWheelEvent& event) { #endif } -ui::EventResult MenuHostRootView::OnGestureEvent( - const ui::GestureEvent& event) { +ui::EventResult MenuHostRootView::OnGestureEvent(ui::GestureEvent* event) { ui::EventResult result = RootView::OnGestureEvent(event); if (result != ui::ER_UNHANDLED) return result; diff --git a/ui/views/controls/menu/menu_host_root_view.h b/ui/views/controls/menu/menu_host_root_view.h index b47d396..13e94e1 100644 --- a/ui/views/controls/menu/menu_host_root_view.h +++ b/ui/views/controls/menu/menu_host_root_view.h @@ -30,8 +30,9 @@ class MenuHostRootView : public internal::RootView { virtual void OnMouseReleased(const ui::MouseEvent& event) OVERRIDE; virtual void OnMouseMoved(const ui::MouseEvent& event) OVERRIDE; virtual bool OnMouseWheel(const ui::MouseWheelEvent& event) OVERRIDE; - virtual ui::EventResult OnGestureEvent( - const ui::GestureEvent& event) OVERRIDE; + + // Overridden from ui::EventHandler: + virtual ui::EventResult OnGestureEvent(ui::GestureEvent* event) OVERRIDE; private: // Returns the MenuController for this MenuHostRootView. diff --git a/ui/views/controls/menu/submenu_view.cc b/ui/views/controls/menu/submenu_view.cc index 2f52e17..71da326 100644 --- a/ui/views/controls/menu/submenu_view.cc +++ b/ui/views/controls/menu/submenu_view.cc @@ -260,20 +260,20 @@ bool SubmenuView::OnMouseWheel(const ui::MouseWheelEvent& e) { return true; } -ui::EventResult SubmenuView::OnGestureEvent(const ui::GestureEvent& e) { +ui::EventResult SubmenuView::OnGestureEvent(ui::GestureEvent* event) { ui::EventResult to_return = ui::ER_CONSUMED; - switch (e.type()) { + switch (event->type()) { case ui::ET_GESTURE_SCROLL_BEGIN: scroll_animator_->Stop(); break; case ui::ET_GESTURE_SCROLL_UPDATE: - OnScroll(0, e.details().scroll_y()); + OnScroll(0, event->details().scroll_y()); break; case ui::ET_GESTURE_SCROLL_END: break; case ui::ET_SCROLL_FLING_START: - if (e.details().velocity_y() != 0.0f) - scroll_animator_->Start(0, e.details().velocity_y()); + if (event->details().velocity_y() != 0.0f) + scroll_animator_->Start(0, event->details().velocity_y()); break; case ui::ET_GESTURE_TAP_DOWN: case ui::ET_SCROLL_FLING_CANCEL: diff --git a/ui/views/controls/menu/submenu_view.h b/ui/views/controls/menu/submenu_view.h index 1a7db2d..2ef095a 100644 --- a/ui/views/controls/menu/submenu_view.h +++ b/ui/views/controls/menu/submenu_view.h @@ -75,8 +75,9 @@ class VIEWS_EXPORT SubmenuView : public View, // Scrolls on menu item boundaries. virtual bool OnMouseWheel(const ui::MouseWheelEvent& e) OVERRIDE; + // Overridden from ui::EventHandler. // Scrolls on menu item boundaries. - virtual ui::EventResult OnGestureEvent(const ui::GestureEvent& e) OVERRIDE; + virtual ui::EventResult OnGestureEvent(ui::GestureEvent* event) OVERRIDE; // Returns true if the menu is showing. bool IsShowing(); diff --git a/ui/views/controls/scroll_view.cc b/ui/views/controls/scroll_view.cc index 0d8823e..4f6feae 100644 --- a/ui/views/controls/scroll_view.cc +++ b/ui/views/controls/scroll_view.cc @@ -400,23 +400,23 @@ bool ScrollView::OnKeyPressed(const ui::KeyEvent& event) { return processed; } -ui::EventResult ScrollView::OnGestureEvent(const ui::GestureEvent& event) { +ui::EventResult ScrollView::OnGestureEvent(ui::GestureEvent* event) { ui::EventResult status = ui::ER_UNHANDLED; // If the event happened on one of the scrollbars, then those events are // sent directly to the scrollbars. Otherwise, only scroll events are sent to // the scrollbars. - bool scroll_event = event.type() == ui::ET_GESTURE_SCROLL_UPDATE || - event.type() == ui::ET_GESTURE_SCROLL_BEGIN || - event.type() == ui::ET_GESTURE_SCROLL_END || - event.type() == ui::ET_SCROLL_FLING_START; + bool scroll_event = event->type() == ui::ET_GESTURE_SCROLL_UPDATE || + event->type() == ui::ET_GESTURE_SCROLL_BEGIN || + event->type() == ui::ET_GESTURE_SCROLL_END || + event->type() == ui::ET_SCROLL_FLING_START; if (vert_sb_->visible()) { - if (vert_sb_->bounds().Contains(event.location()) || scroll_event) + if (vert_sb_->bounds().Contains(event->location()) || scroll_event) status = vert_sb_->OnGestureEvent(event); } if (status == ui::ER_UNHANDLED && horiz_sb_->visible()) { - if (horiz_sb_->bounds().Contains(event.location()) || scroll_event) + if (horiz_sb_->bounds().Contains(event->location()) || scroll_event) status = horiz_sb_->OnGestureEvent(event); } return status; diff --git a/ui/views/controls/scroll_view.h b/ui/views/controls/scroll_view.h index 29ad616..51f2bc0 100644 --- a/ui/views/controls/scroll_view.h +++ b/ui/views/controls/scroll_view.h @@ -73,10 +73,11 @@ class VIEWS_EXPORT ScrollView : public View, public ScrollBarController { // Keyboard events virtual bool OnKeyPressed(const ui::KeyEvent& event) OVERRIDE; - virtual ui::EventResult OnGestureEvent( - const ui::GestureEvent& event) OVERRIDE; virtual bool OnMouseWheel(const ui::MouseWheelEvent& e) OVERRIDE; + // Overridden from ui::EventHandler: + virtual ui::EventResult OnGestureEvent(ui::GestureEvent* event) OVERRIDE; + virtual std::string GetClassName() const OVERRIDE; // Retrieves the vertical scrollbar width. diff --git a/ui/views/controls/scrollbar/base_scroll_bar.cc b/ui/views/controls/scrollbar/base_scroll_bar.cc index ef5c68e..39973af 100644 --- a/ui/views/controls/scrollbar/base_scroll_bar.cc +++ b/ui/views/controls/scrollbar/base_scroll_bar.cc @@ -167,22 +167,27 @@ bool BaseScrollBar::OnKeyPressed(const ui::KeyEvent& event) { return false; } -ui::EventResult BaseScrollBar::OnGestureEvent(const ui::GestureEvent& event) { +bool BaseScrollBar::OnMouseWheel(const ui::MouseWheelEvent& event) { + ScrollByContentsOffset(event.offset()); + return true; +} + +ui::EventResult BaseScrollBar::OnGestureEvent(ui::GestureEvent* event) { // If a fling is in progress, then stop the fling for any incoming gesture // event (except for the GESTURE_END event that is generated at the end of the // fling). if (scroll_animator_.get() && scroll_animator_->is_scrolling() && - (event.type() != ui::ET_GESTURE_END || - event.details().touch_points() > 1)) { + (event->type() != ui::ET_GESTURE_END || + event->details().touch_points() > 1)) { scroll_animator_->Stop(); } - if (event.type() == ui::ET_GESTURE_TAP_DOWN) { - ProcessPressEvent(event); + if (event->type() == ui::ET_GESTURE_TAP_DOWN) { + ProcessPressEvent(*event); return ui::ER_CONSUMED; } - if (event.type() == ui::ET_GESTURE_LONG_PRESS) { + if (event->type() == ui::ET_GESTURE_LONG_PRESS) { // For a long-press, the repeater started in tap-down should continue. So // return early. return ui::ER_UNHANDLED; @@ -190,38 +195,34 @@ ui::EventResult BaseScrollBar::OnGestureEvent(const ui::GestureEvent& event) { ResetState(); - if (event.type() == ui::ET_GESTURE_TAP) { + if (event->type() == ui::ET_GESTURE_TAP) { // TAP_DOWN would have already scrolled some amount. So scrolling again on // TAP is not necessary. return ui::ER_CONSUMED; } - if (event.type() == ui::ET_GESTURE_SCROLL_BEGIN || - event.type() == ui::ET_GESTURE_SCROLL_END) + if (event->type() == ui::ET_GESTURE_SCROLL_BEGIN || + event->type() == ui::ET_GESTURE_SCROLL_END) return ui::ER_CONSUMED; - if (event.type() == ui::ET_GESTURE_SCROLL_UPDATE) { - ScrollByContentsOffset(IsHorizontal() ? event.details().scroll_x() : - event.details().scroll_y()); + if (event->type() == ui::ET_GESTURE_SCROLL_UPDATE) { + ScrollByContentsOffset(IsHorizontal() ? event->details().scroll_x() : + event->details().scroll_y()); return ui::ER_CONSUMED; } - if (event.type() == ui::ET_SCROLL_FLING_START) { + if (event->type() == ui::ET_SCROLL_FLING_START) { if (!scroll_animator_.get()) scroll_animator_.reset(new ScrollAnimator(this)); - scroll_animator_->Start(IsHorizontal() ? event.details().velocity_x() : 0.f, - IsHorizontal() ? 0.f : event.details().velocity_y()); + scroll_animator_->Start( + IsHorizontal() ? event->details().velocity_x() : 0.f, + IsHorizontal() ? 0.f : event->details().velocity_y()); return ui::ER_CONSUMED; } return ui::ER_UNHANDLED; } -bool BaseScrollBar::OnMouseWheel(const ui::MouseWheelEvent& event) { - ScrollByContentsOffset(event.offset()); - return true; -} - /////////////////////////////////////////////////////////////////////////////// // BaseScrollBar, ScrollDelegate implementation: diff --git a/ui/views/controls/scrollbar/base_scroll_bar.h b/ui/views/controls/scrollbar/base_scroll_bar.h index c674dde1..060f397 100644 --- a/ui/views/controls/scrollbar/base_scroll_bar.h +++ b/ui/views/controls/scrollbar/base_scroll_bar.h @@ -64,10 +64,11 @@ class VIEWS_EXPORT BaseScrollBar : public ScrollBar, virtual void OnMouseReleased(const ui::MouseEvent& event) OVERRIDE; virtual void OnMouseCaptureLost() OVERRIDE; virtual bool OnKeyPressed(const ui::KeyEvent& event) OVERRIDE; - virtual ui::EventResult OnGestureEvent( - const ui::GestureEvent& event) OVERRIDE; virtual bool OnMouseWheel(const ui::MouseWheelEvent& event) OVERRIDE; + // ui::EventHandler overrides: + virtual ui::EventResult OnGestureEvent(ui::GestureEvent* event) OVERRIDE; + // ScrollBar overrides: virtual void Update(int viewport_size, int content_size, diff --git a/ui/views/controls/scrollbar/native_scroll_bar.cc b/ui/views/controls/scrollbar/native_scroll_bar.cc index e19e117..d696db8 100644 --- a/ui/views/controls/scrollbar/native_scroll_bar.cc +++ b/ui/views/controls/scrollbar/native_scroll_bar.cc @@ -76,8 +76,7 @@ bool NativeScrollBar::OnKeyPressed(const ui::KeyEvent& event) { return native_wrapper_->GetView()->OnKeyPressed(event); } -ui::EventResult NativeScrollBar::OnGestureEvent( - const ui::GestureEvent& event) { +ui::EventResult NativeScrollBar::OnGestureEvent(ui::GestureEvent* event) { if (!native_wrapper_) return ui::ER_UNHANDLED; return native_wrapper_->GetView()->OnGestureEvent(event); diff --git a/ui/views/controls/scrollbar/native_scroll_bar.h b/ui/views/controls/scrollbar/native_scroll_bar.h index 7e3416c..d737d84 100644 --- a/ui/views/controls/scrollbar/native_scroll_bar.h +++ b/ui/views/controls/scrollbar/native_scroll_bar.h @@ -45,9 +45,11 @@ class VIEWS_EXPORT NativeScrollBar : public ScrollBar { // Overrideen from View for keyboard UI purpose. virtual bool OnKeyPressed(const ui::KeyEvent& event) OVERRIDE; - virtual ui::EventResult OnGestureEvent(const ui::GestureEvent& e) OVERRIDE; virtual bool OnMouseWheel(const ui::MouseWheelEvent& e) OVERRIDE; + // Overridden from ui::EventHandler. + virtual ui::EventResult OnGestureEvent(ui::GestureEvent* event) OVERRIDE; + // Overridden from ScrollBar. virtual void Update(int viewport_size, int content_size, diff --git a/ui/views/controls/slider.cc b/ui/views/controls/slider.cc index 140df74..99a0a9f 100644 --- a/ui/views/controls/slider.cc +++ b/ui/views/controls/slider.cc @@ -291,16 +291,16 @@ bool Slider::OnKeyPressed(const ui::KeyEvent& event) { return false; } -ui::EventResult Slider::OnGestureEvent(const ui::GestureEvent& event) { - if (event.type() == ui::ET_GESTURE_SCROLL_BEGIN || - event.type() == ui::ET_GESTURE_TAP_DOWN) { - PrepareForMove(event.location()); - MoveButtonTo(event.location()); +ui::EventResult Slider::OnGestureEvent(ui::GestureEvent* event) { + if (event->type() == ui::ET_GESTURE_SCROLL_BEGIN || + event->type() == ui::ET_GESTURE_TAP_DOWN) { + PrepareForMove(event->location()); + MoveButtonTo(event->location()); return ui::ER_CONSUMED; } else - if (event.type() == ui::ET_GESTURE_SCROLL_UPDATE || - event.type() == ui::ET_GESTURE_SCROLL_END) { - MoveButtonTo(event.location()); + if (event->type() == ui::ET_GESTURE_SCROLL_UPDATE || + event->type() == ui::ET_GESTURE_SCROLL_END) { + MoveButtonTo(event->location()); return ui::ER_CONSUMED; } return ui::ER_UNHANDLED; diff --git a/ui/views/controls/slider.h b/ui/views/controls/slider.h index bc88167..3b6338c 100644 --- a/ui/views/controls/slider.h +++ b/ui/views/controls/slider.h @@ -89,12 +89,13 @@ class VIEWS_EXPORT Slider : public View, virtual bool OnMousePressed(const ui::MouseEvent& event) OVERRIDE; virtual bool OnMouseDragged(const ui::MouseEvent& event) OVERRIDE; virtual void OnMouseReleased(const ui::MouseEvent& event) OVERRIDE; - virtual ui::EventResult OnGestureEvent( - const ui::GestureEvent& event) OVERRIDE; virtual bool OnKeyPressed(const ui::KeyEvent& event) OVERRIDE; virtual void GetAccessibleState(ui::AccessibleViewState* state) OVERRIDE; virtual void OnPaintFocusBorder(gfx::Canvas* canvas) OVERRIDE; + // ui::EventHandler overrides: + virtual ui::EventResult OnGestureEvent(ui::GestureEvent* event) OVERRIDE; + // ui::AnimationDelegate overrides: virtual void AnimationProgressed(const ui::Animation* animation) OVERRIDE; diff --git a/ui/views/controls/textfield/native_textfield_views.cc b/ui/views/controls/textfield/native_textfield_views.cc index 28ccdcb..aa1d3f3 100644 --- a/ui/views/controls/textfield/native_textfield_views.cc +++ b/ui/views/controls/textfield/native_textfield_views.cc @@ -144,20 +144,19 @@ void NativeTextfieldViews::OnMouseReleased(const ui::MouseEvent& event) { OnAfterUserAction(); } -ui::EventResult NativeTextfieldViews::OnGestureEvent( - const ui::GestureEvent& event) { +ui::EventResult NativeTextfieldViews::OnGestureEvent(ui::GestureEvent* event) { ui::EventResult status = textfield_->OnGestureEvent(event); if (status != ui::ER_UNHANDLED) return status; - switch (event.type()) { + switch (event->type()) { case ui::ET_GESTURE_TAP_DOWN: OnBeforeUserAction(); textfield_->RequestFocus(); // We don't deselect if the point is in the selection // because TAP_DOWN may turn into a LONG_PRESS. - if (!GetRenderText()->IsPointInSelection(event.location()) && - MoveCursorTo(event.location(), false)) + if (!GetRenderText()->IsPointInSelection(event->location()) && + MoveCursorTo(event->location(), false)) SchedulePaint(); OnAfterUserAction(); return ui::ER_CONSUMED; @@ -166,7 +165,7 @@ ui::EventResult NativeTextfieldViews::OnGestureEvent( return ui::ER_CONSUMED; case ui::ET_GESTURE_SCROLL_UPDATE: OnBeforeUserAction(); - if (MoveCursorTo(event.location(), true)) + if (MoveCursorTo(event->location(), true)) SchedulePaint(); OnAfterUserAction(); return ui::ER_CONSUMED; diff --git a/ui/views/controls/textfield/native_textfield_views.h b/ui/views/controls/textfield/native_textfield_views.h index ce525a7..80fee72 100644 --- a/ui/views/controls/textfield/native_textfield_views.h +++ b/ui/views/controls/textfield/native_textfield_views.h @@ -56,8 +56,7 @@ class VIEWS_EXPORT NativeTextfieldViews : public TouchSelectionClientView, virtual bool OnMousePressed(const ui::MouseEvent& event) OVERRIDE; virtual bool OnMouseDragged(const ui::MouseEvent& event) OVERRIDE; virtual void OnMouseReleased(const ui::MouseEvent& event) OVERRIDE; - virtual ui::EventResult OnGestureEvent( - const ui::GestureEvent& event) OVERRIDE; + virtual ui::EventResult OnGestureEvent(ui::GestureEvent* event) OVERRIDE; virtual bool OnKeyPressed(const ui::KeyEvent& event) OVERRIDE; virtual bool GetDropFormats( int* formats, diff --git a/ui/views/view.cc b/ui/views/view.cc index 8faa77b..3f36ec1 100644 --- a/ui/views/view.cc +++ b/ui/views/view.cc @@ -832,14 +832,6 @@ void View::OnMouseEntered(const ui::MouseEvent& event) { void View::OnMouseExited(const ui::MouseEvent& event) { } -ui::TouchStatus View::OnTouchEvent(const ui::TouchEvent& event) { - return ui::TOUCH_STATUS_UNKNOWN; -} - -ui::EventResult View::OnGestureEvent(const ui::GestureEvent& event) { - return ui::ER_UNHANDLED; -} - void View::SetMouseHandler(View* new_mouse_handler) { // |new_mouse_handler| may be NULL. if (parent_) @@ -858,8 +850,24 @@ bool View::OnMouseWheel(const ui::MouseWheelEvent& event) { return false; } -bool View::OnScrollEvent(const ui::ScrollEvent& event) { - return false; +ui::EventResult View::OnKeyEvent(ui::KeyEvent* event) { + return ui::ER_UNHANDLED; +} + +ui::EventResult View::OnMouseEvent(ui::MouseEvent* event) { + return ui::ER_UNHANDLED; +} + +ui::EventResult View::OnScrollEvent(ui::ScrollEvent* event) { + return ui::ER_UNHANDLED; +} + +ui::EventResult View::OnTouchEvent(ui::TouchEvent* event) { + return ui::ER_UNHANDLED; +} + +ui::EventResult View::OnGestureEvent(ui::GestureEvent* event) { + return ui::ER_UNHANDLED; } ui::TextInputClient* View::GetTextInputClient() { @@ -871,6 +879,14 @@ InputMethod* View::GetInputMethod() { return widget ? widget->GetInputMethod() : NULL; } +bool View::CanAcceptEvents() { + return IsDrawn(); +} + +ui::EventTarget* View::GetParentTarget() { + return parent_; +} + // Accelerators ---------------------------------------------------------------- void View::AddAccelerator(const ui::Accelerator& accelerator) { @@ -1968,21 +1984,19 @@ void View::ProcessMouseReleased(const ui::MouseEvent& event) { // WARNING: we may have been deleted. } -ui::TouchStatus View::ProcessTouchEvent(const ui::TouchEvent& event) { - // TODO(rjkroege): Implement a grab scheme similar to as as is found in - // MousePressed. +ui::EventResult View::ProcessTouchEvent(ui::TouchEvent* event) { return OnTouchEvent(event); } -ui::EventResult View::ProcessGestureEvent(const ui::GestureEvent& event) { +ui::EventResult View::ProcessGestureEvent(ui::GestureEvent* event) { ui::EventResult status = OnGestureEvent(event); if (status != ui::ER_UNHANDLED) return status; if (context_menu_controller_ && - (event.type() == ui::ET_GESTURE_LONG_PRESS || - event.type() == ui::ET_GESTURE_TWO_FINGER_TAP)) { - gfx::Point location(event.location()); + (event->type() == ui::ET_GESTURE_LONG_PRESS || + event->type() == ui::ET_GESTURE_TWO_FINGER_TAP)) { + gfx::Point location(event->location()); ConvertPointToScreen(this, &location); ShowContextMenu(location, true); return ui::ER_CONSUMED; diff --git a/ui/views/view.h b/ui/views/view.h index 3f05eeb..76d09d4 100644 --- a/ui/views/view.h +++ b/ui/views/view.h @@ -19,6 +19,7 @@ #include "ui/base/accelerators/accelerator.h" #include "ui/base/dragdrop/os_exchange_data.h" #include "ui/base/events/event.h" +#include "ui/base/events/event_target.h" #include "ui/compositor/layer_delegate.h" #include "ui/compositor/layer_owner.h" #include "ui/gfx/native_widget_types.h" @@ -100,7 +101,8 @@ class RootView; ///////////////////////////////////////////////////////////////////////////// class VIEWS_EXPORT View : public ui::LayerDelegate, public ui::LayerOwner, - public ui::AcceleratorTarget { + public ui::AcceleratorTarget, + public ui::EventTarget { public: typedef std::vector<View*> Views; @@ -581,25 +583,6 @@ class VIEWS_EXPORT View : public ui::LayerDelegate, // Default implementation does nothing. Override as needed. virtual void OnMouseExited(const ui::MouseEvent& event); - // This method is invoked for each touch event. Default implementation - // does nothing. Override as needed. - virtual ui::TouchStatus OnTouchEvent(const ui::TouchEvent& event); - - // This method is invoked for each GestureEvent created by GestureRecognizer. - // Default implementation does nothing. Override as needed. - // If a View returns ui::ER_CONSUMED from OnGestureEvent, then - // subsequent gestures will be dispatched to the same View, until the gesture - // ends (i.e. all touch-points are released). - // Scroll gesture events are handled slightly differently: if a View starts - // processing gesture events, but does not process an ET_GESTURE_SCROLL_BEGIN - // gesture, then the scroll-gesture event will bubble up (i.e. will be sent to - // the parent view for processing). If a View then returns - // GESTURE_STATUS_CONSUMED from OnGestureEvent, then the subsequent - // scroll-gesture events will be sent to this View. However all the other - // gesture-events (e.g. ET_GESTURE_END, ET_GESTURE_PINCH_BEGIN etc.) will - // continue to be dispatched to the first View. - virtual ui::EventResult OnGestureEvent(const ui::GestureEvent& event); - // Set the MouseHandler for a drag session. // // A drag session is a stream of mouse events starting @@ -634,11 +617,6 @@ class VIEWS_EXPORT View : public ui::LayerDelegate, // will be given a chance. virtual bool OnMouseWheel(const ui::MouseWheelEvent& event); - // Invoked when user scrolls (e.g. using two-finger scroll on touch pad). - // Returns true if the event has been processed and false otherwise. The event - // is sent to the view where the event happens first. If it has not been - // processed, the parent will be given a chance. - virtual bool OnScrollEvent(const ui::ScrollEvent& event); // See field for description. void set_notify_enter_exit_on_child(bool notify) { @@ -657,6 +635,17 @@ class VIEWS_EXPORT View : public ui::LayerDelegate, // view hierarchy with a Widget. virtual InputMethod* GetInputMethod(); + // Overridden from ui::EventTarget: + virtual bool CanAcceptEvents() OVERRIDE; + virtual ui::EventTarget* GetParentTarget() OVERRIDE; + + // Overridden from ui::EventHandler: + virtual ui::EventResult OnKeyEvent(ui::KeyEvent* event) OVERRIDE; + virtual ui::EventResult OnMouseEvent(ui::MouseEvent* event) OVERRIDE; + virtual ui::EventResult OnScrollEvent(ui::ScrollEvent* event) OVERRIDE; + virtual ui::EventResult OnTouchEvent(ui::TouchEvent* event) OVERRIDE; + virtual ui::EventResult OnGestureEvent(ui::GestureEvent* event) OVERRIDE; + // Accelerators -------------------------------------------------------------- // Sets a keyboard accelerator for that view. When the user presses the @@ -1290,11 +1279,11 @@ class VIEWS_EXPORT View : public ui::LayerDelegate, // RootView will invoke this with incoming TouchEvents. Returns the result // of OnTouchEvent. - ui::TouchStatus ProcessTouchEvent(const ui::TouchEvent& event); + ui::EventResult ProcessTouchEvent(ui::TouchEvent* event); // RootView will invoke this with incoming GestureEvents. This will invoke // OnGestureEvent and return the result. - ui::EventResult ProcessGestureEvent(const ui::GestureEvent& event); + ui::EventResult ProcessGestureEvent(ui::GestureEvent* event); // Accelerators -------------------------------------------------------------- diff --git a/ui/views/view_unittest.cc b/ui/views/view_unittest.cc index 484b70a..a9ab0aa 100644 --- a/ui/views/view_unittest.cc +++ b/ui/views/view_unittest.cc @@ -230,10 +230,11 @@ class TestView : public View { virtual void OnMouseReleased(const ui::MouseEvent& event) OVERRIDE; virtual void OnMouseEntered(const ui::MouseEvent& event) OVERRIDE; virtual void OnMouseExited(const ui::MouseEvent& event) OVERRIDE; - virtual ui::TouchStatus OnTouchEvent(const ui::TouchEvent& event) OVERRIDE; + + virtual ui::EventResult OnTouchEvent(ui::TouchEvent* event) OVERRIDE; // Ignores GestureEvent by default. - virtual ui::EventResult OnGestureEvent( - const ui::GestureEvent& event) OVERRIDE; + virtual ui::EventResult OnGestureEvent(ui::GestureEvent* event) OVERRIDE; + virtual void Paint(gfx::Canvas* canvas) OVERRIDE; virtual void SchedulePaintInRect(const gfx::Rect& rect) OVERRIDE; virtual bool AcceleratorPressed(const ui::Accelerator& accelerator) OVERRIDE; @@ -275,7 +276,7 @@ class TestViewIgnoreTouch : public TestView { virtual ~TestViewIgnoreTouch() {} private: - virtual ui::TouchStatus OnTouchEvent(const ui::TouchEvent& event) OVERRIDE; + virtual ui::EventResult OnTouchEvent(ui::TouchEvent* event) OVERRIDE; }; // A view subclass that consumes all Gesture events for testing purposes. @@ -285,10 +286,9 @@ class TestViewConsumeGesture : public TestView { virtual ~TestViewConsumeGesture() {} protected: - virtual ui::EventResult OnGestureEvent( - const ui::GestureEvent& event) OVERRIDE { - last_gesture_event_type_ = event.type(); - location_.SetPoint(event.x(), event.y()); + virtual ui::EventResult OnGestureEvent(ui::GestureEvent* event) OVERRIDE { + last_gesture_event_type_ = event->type(); + location_.SetPoint(event->x(), event->y()); return ui::ER_CONSUMED; } @@ -303,8 +303,7 @@ class TestViewIgnoreGesture: public TestView { virtual ~TestViewIgnoreGesture() {} private: - virtual ui::EventResult OnGestureEvent( - const ui::GestureEvent& event) OVERRIDE { + virtual ui::EventResult OnGestureEvent(ui::GestureEvent* event) OVERRIDE { return ui::ER_UNHANDLED; } @@ -319,9 +318,8 @@ class TestViewIgnoreScrollGestures : public TestViewConsumeGesture { virtual ~TestViewIgnoreScrollGestures() {} private: - virtual ui::EventResult OnGestureEvent( - const ui::GestureEvent& event) OVERRIDE { - if (event.IsScrollGestureEvent()) + virtual ui::EventResult OnGestureEvent(ui::GestureEvent* event) OVERRIDE { + if (event->IsScrollGestureEvent()) return ui::ER_UNHANDLED; return TestViewConsumeGesture::OnGestureEvent(event); } @@ -396,7 +394,8 @@ TEST_F(ViewTest, MouseEvent) { params.ownership = views::Widget::InitParams::WIDGET_OWNS_NATIVE_WIDGET; params.bounds = gfx::Rect(50, 50, 650, 650); widget->Init(params); - View* root = widget->GetRootView(); + internal::RootView* root = + static_cast<internal::RootView*>(widget->GetRootView()); root->AddChildView(v1); v1->AddChildView(v2); @@ -475,27 +474,27 @@ TEST_F(ViewTest, DeleteOnPressed) { //////////////////////////////////////////////////////////////////////////////// // TouchEvent //////////////////////////////////////////////////////////////////////////////// -ui::TouchStatus TestView::OnTouchEvent(const ui::TouchEvent& event) { - last_touch_event_type_ = event.type(); - location_.SetPoint(event.x(), event.y()); +ui::EventResult TestView::OnTouchEvent(ui::TouchEvent* event) { + last_touch_event_type_ = event->type(); + location_.SetPoint(event->x(), event->y()); if (!in_touch_sequence_) { - if (event.type() == ui::ET_TOUCH_PRESSED) { + if (event->type() == ui::ET_TOUCH_PRESSED) { in_touch_sequence_ = true; - return ui::TOUCH_STATUS_START; + return ui::ER_CONSUMED; } } else { - if (event.type() == ui::ET_TOUCH_RELEASED) { + if (event->type() == ui::ET_TOUCH_RELEASED) { in_touch_sequence_ = false; - return ui::TOUCH_STATUS_END; + return ui::ER_HANDLED; } - return ui::TOUCH_STATUS_CONTINUE; + return ui::ER_CONSUMED; } - return last_touch_event_was_handled_ ? ui::TOUCH_STATUS_CONTINUE : - ui::TOUCH_STATUS_UNKNOWN; + return last_touch_event_was_handled_ ? ui::ER_CONSUMED : + ui::ER_UNHANDLED; } -ui::TouchStatus TestViewIgnoreTouch::OnTouchEvent(const ui::TouchEvent& event) { - return ui::TOUCH_STATUS_UNKNOWN; +ui::EventResult TestViewIgnoreTouch::OnTouchEvent(ui::TouchEvent* event) { + return ui::ER_UNHANDLED; } TEST_F(ViewTest, TouchEvent) { @@ -513,7 +512,8 @@ TEST_F(ViewTest, TouchEvent) { params.ownership = views::Widget::InitParams::WIDGET_OWNS_NATIVE_WIDGET; params.bounds = gfx::Rect(50, 50, 650, 650); widget->Init(params); - View* root = widget->GetRootView(); + internal::RootView* root = + static_cast<internal::RootView*>(widget->GetRootView()); root->AddChildView(v1); v1->AddChildView(v2); @@ -533,7 +533,7 @@ TEST_F(ViewTest, TouchEvent) { 0, /* first finger touch */ base::TimeDelta(), 1.0, 0.0, 1.0, 0.0); - root->OnTouchEvent(unhandled); + root->DispatchTouchEvent(&unhandled); EXPECT_EQ(v1->last_touch_event_type_, 0); EXPECT_EQ(v2->last_touch_event_type_, 0); @@ -549,7 +549,7 @@ TEST_F(ViewTest, TouchEvent) { base::TimeDelta(), 1.0, 0.0, 1.0, 0.0); v2->last_touch_event_was_handled_ = true; - root->OnTouchEvent(pressed); + root->DispatchTouchEvent(&pressed); EXPECT_EQ(v2->last_touch_event_type_, ui::ET_TOUCH_PRESSED); EXPECT_EQ(v2->location_.x(), 10); @@ -567,7 +567,7 @@ TEST_F(ViewTest, TouchEvent) { base::TimeDelta(), 1.0, 0.0, 1.0, 0.0); - root->OnTouchEvent(dragged); + root->DispatchTouchEvent(&dragged); EXPECT_EQ(v2->last_touch_event_type_, ui::ET_TOUCH_MOVED); EXPECT_EQ(v2->location_.x(), -50); EXPECT_EQ(v2->location_.y(), -60); @@ -583,7 +583,7 @@ TEST_F(ViewTest, TouchEvent) { base::TimeDelta(), 1.0, 0.0, 1.0, 0.0); v2->last_touch_event_was_handled_ = true; - root->OnTouchEvent(released); + root->DispatchTouchEvent(&released); EXPECT_EQ(v2->last_touch_event_type_, ui::ET_TOUCH_RELEASED); EXPECT_EQ(v2->location_.x(), -100); EXPECT_EQ(v2->location_.y(), -100); @@ -593,7 +593,7 @@ TEST_F(ViewTest, TouchEvent) { widget->CloseNow(); } -ui::EventResult TestView::OnGestureEvent(const ui::GestureEvent& event) { +ui::EventResult TestView::OnGestureEvent(ui::GestureEvent* event) { return ui::ER_UNHANDLED; } @@ -613,7 +613,8 @@ TEST_F(ViewTest, GestureEvent) { params.ownership = views::Widget::InitParams::WIDGET_OWNS_NATIVE_WIDGET; params.bounds = gfx::Rect(50, 50, 650, 650); widget->Init(params); - View* root = widget->GetRootView(); + internal::RootView* root = + static_cast<internal::RootView*>(widget->GetRootView()); root->AddChildView(v1); v1->AddChildView(v2); @@ -630,14 +631,14 @@ TEST_F(ViewTest, GestureEvent) { // Gesture on |v3| GestureEventForTest g1(ui::ET_GESTURE_TAP, 110, 110, 0); - root->OnGestureEvent(g1); + root->DispatchGestureEvent(&g1); EXPECT_EQ(ui::ET_GESTURE_TAP, v2->last_gesture_event_type_); EXPECT_EQ(gfx::Point(10, 10), v2->location_); EXPECT_EQ(ui::ET_UNKNOWN, v1->last_gesture_event_type_); // Simulate an up so that RootView is no longer targetting |v3|. GestureEventForTest g1_up(ui::ET_GESTURE_END, 110, 110, 0); - root->OnGestureEvent(g1_up); + root->DispatchGestureEvent(&g1_up); v1->Reset(); v2->Reset(); @@ -645,7 +646,7 @@ TEST_F(ViewTest, GestureEvent) { // Gesture on |v1| GestureEventForTest g2(ui::ET_GESTURE_TAP, 80, 80, 0); - root->OnGestureEvent(g2); + root->DispatchGestureEvent(&g2); EXPECT_EQ(ui::ET_GESTURE_TAP, v1->last_gesture_event_type_); EXPECT_EQ(gfx::Point(80, 80), v1->location_); EXPECT_EQ(ui::ET_UNKNOWN, v2->last_gesture_event_type_); @@ -654,7 +655,7 @@ TEST_F(ViewTest, GestureEvent) { // to |v1| as that is the view the touch was initially down on. v1->last_gesture_event_type_ = ui::ET_UNKNOWN; v3->last_gesture_event_type_ = ui::ET_UNKNOWN; - root->OnGestureEvent(g1); + root->DispatchGestureEvent(&g1); EXPECT_EQ(ui::ET_GESTURE_TAP, v1->last_gesture_event_type_); EXPECT_EQ(ui::ET_UNKNOWN, v3->last_gesture_event_type_); EXPECT_EQ("110,110", v1->location_.ToString()); @@ -678,7 +679,8 @@ TEST_F(ViewTest, ScrollGestureEvent) { params.ownership = views::Widget::InitParams::WIDGET_OWNS_NATIVE_WIDGET; params.bounds = gfx::Rect(50, 50, 650, 650); widget->Init(params); - View* root = widget->GetRootView(); + internal::RootView* root = + static_cast<internal::RootView*>(widget->GetRootView()); root->AddChildView(v1); v1->AddChildView(v2); @@ -695,7 +697,7 @@ TEST_F(ViewTest, ScrollGestureEvent) { // Gesture on |v3| GestureEventForTest g1(ui::ET_GESTURE_TAP, 110, 110, 0); - root->OnGestureEvent(g1); + root->DispatchGestureEvent(&g1); EXPECT_EQ(ui::ET_GESTURE_TAP, v2->last_gesture_event_type_); EXPECT_EQ(gfx::Point(10, 10), v2->location_); EXPECT_EQ(ui::ET_UNKNOWN, v1->last_gesture_event_type_); @@ -706,7 +708,7 @@ TEST_F(ViewTest, ScrollGestureEvent) { // since it does not process scroll-gesture events, these events should reach // |v1|. GestureEventForTest gscroll_begin(ui::ET_GESTURE_SCROLL_BEGIN, 115, 115, 0); - root->OnGestureEvent(gscroll_begin); + root->DispatchGestureEvent(&gscroll_begin); EXPECT_EQ(ui::ET_UNKNOWN, v2->last_gesture_event_type_); EXPECT_EQ(ui::ET_GESTURE_SCROLL_BEGIN, v1->last_gesture_event_type_); v1->Reset(); @@ -715,19 +717,19 @@ TEST_F(ViewTest, ScrollGestureEvent) { // default gesture handler, and not |v1| (even though it is the view under the // point, and is the scroll event handler). GestureEventForTest second_tap(ui::ET_GESTURE_TAP, 70, 70, 0); - root->OnGestureEvent(second_tap); + root->DispatchGestureEvent(&second_tap); EXPECT_EQ(ui::ET_GESTURE_TAP, v2->last_gesture_event_type_); EXPECT_EQ(ui::ET_UNKNOWN, v1->last_gesture_event_type_); v2->Reset(); GestureEventForTest gscroll_end(ui::ET_GESTURE_SCROLL_END, 50, 50, 0); - root->OnGestureEvent(gscroll_end); + root->DispatchGestureEvent(&gscroll_end); EXPECT_EQ(ui::ET_GESTURE_SCROLL_END, v1->last_gesture_event_type_); v1->Reset(); // Simulate an up so that RootView is no longer targetting |v3|. GestureEventForTest g1_up(ui::ET_GESTURE_END, 110, 110, 0); - root->OnGestureEvent(g1_up); + root->DispatchGestureEvent(&g1_up); EXPECT_EQ(ui::ET_GESTURE_END, v2->last_gesture_event_type_); v1->Reset(); @@ -736,7 +738,7 @@ TEST_F(ViewTest, ScrollGestureEvent) { // Gesture on |v1| GestureEventForTest g2(ui::ET_GESTURE_TAP, 80, 80, 0); - root->OnGestureEvent(g2); + root->DispatchGestureEvent(&g2); EXPECT_EQ(ui::ET_GESTURE_TAP, v1->last_gesture_event_type_); EXPECT_EQ(gfx::Point(80, 80), v1->location_); EXPECT_EQ(ui::ET_UNKNOWN, v2->last_gesture_event_type_); @@ -745,7 +747,7 @@ TEST_F(ViewTest, ScrollGestureEvent) { // to |v1| as that is the view the touch was initially down on. v1->last_gesture_event_type_ = ui::ET_UNKNOWN; v3->last_gesture_event_type_ = ui::ET_UNKNOWN; - root->OnGestureEvent(g1); + root->DispatchGestureEvent(&g1); EXPECT_EQ(ui::ET_GESTURE_TAP, v1->last_gesture_event_type_); EXPECT_EQ(ui::ET_UNKNOWN, v3->last_gesture_event_type_); EXPECT_EQ("110,110", v1->location_.ToString()); diff --git a/ui/views/widget/desktop_native_widget_aura.cc b/ui/views/widget/desktop_native_widget_aura.cc index 73ef5de..8167153d 100644 --- a/ui/views/widget/desktop_native_widget_aura.cc +++ b/ui/views/widget/desktop_native_widget_aura.cc @@ -542,13 +542,12 @@ ui::EventResult DesktopNativeWidgetAura::OnMouseEvent(ui::MouseEvent* event) { } ui::EventResult DesktopNativeWidgetAura::OnTouchEvent(ui::TouchEvent* event) { - ui::TouchStatus status = native_widget_delegate_->OnTouchEvent(*event); - return ui::EventResultFromTouchStatus(status); + return native_widget_delegate_->OnTouchEvent(event); } ui::EventResult DesktopNativeWidgetAura::OnGestureEvent( ui::GestureEvent* event) { - return native_widget_delegate_->OnGestureEvent(*event); + return native_widget_delegate_->OnGestureEvent(event); } //////////////////////////////////////////////////////////////////////////////// diff --git a/ui/views/widget/native_widget_aura.cc b/ui/views/widget/native_widget_aura.cc index 85fafe1..9ce9723 100644 --- a/ui/views/widget/native_widget_aura.cc +++ b/ui/views/widget/native_widget_aura.cc @@ -782,7 +782,7 @@ ui::EventResult NativeWidgetAura::OnMouseEvent(ui::MouseEvent* event) { return delegate_->OnMouseEvent(*event) ? ui::ER_HANDLED : ui::ER_UNHANDLED; if (event->type() == ui::ET_SCROLL) { - if (delegate_->OnMouseEvent(*event)) + if (delegate_->OnScrollEvent(static_cast<ui::ScrollEvent*>(event))) return ui::ER_HANDLED; // Convert unprocessed scroll events into wheel events. @@ -796,13 +796,12 @@ ui::EventResult NativeWidgetAura::OnMouseEvent(ui::MouseEvent* event) { ui::EventResult NativeWidgetAura::OnTouchEvent(ui::TouchEvent* event) { DCHECK(window_->IsVisible()); - ui::TouchStatus status = delegate_->OnTouchEvent(*event); - return ui::EventResultFromTouchStatus(status); + return delegate_->OnTouchEvent(event); } ui::EventResult NativeWidgetAura::OnGestureEvent(ui::GestureEvent* event) { DCHECK(window_->IsVisible()); - return delegate_->OnGestureEvent(*event); + return delegate_->OnGestureEvent(event); } //////////////////////////////////////////////////////////////////////////////// diff --git a/ui/views/widget/native_widget_aura_unittest.cc b/ui/views/widget/native_widget_aura_unittest.cc index 0dec3d71..b9a7dc3 100644 --- a/ui/views/widget/native_widget_aura_unittest.cc +++ b/ui/views/widget/native_widget_aura_unittest.cc @@ -216,11 +216,9 @@ class GestureTrackingView : public views::View { } // View overrides: - virtual ui::EventResult OnGestureEvent( - const ui::GestureEvent& event) OVERRIDE { + virtual ui::EventResult OnGestureEvent(ui::GestureEvent* event) OVERRIDE { got_gesture_event_ = true; - return consume_gesture_event_ ? ui::ER_CONSUMED : - ui::ER_UNHANDLED; + return consume_gesture_event_ ? ui::ER_CONSUMED : ui::ER_UNHANDLED; } private: diff --git a/ui/views/widget/native_widget_delegate.h b/ui/views/widget/native_widget_delegate.h index 604f328..29ab54f 100644 --- a/ui/views/widget/native_widget_delegate.h +++ b/ui/views/widget/native_widget_delegate.h @@ -23,6 +23,7 @@ class KeyEvent; class Layer; class MouseEvent; class TouchEvent; +class ScrollEvent; } namespace views { @@ -108,8 +109,10 @@ class VIEWS_EXPORT NativeWidgetDelegate { virtual bool OnKeyEvent(const ui::KeyEvent& event) = 0; virtual bool OnMouseEvent(const ui::MouseEvent& event) = 0; virtual void OnMouseCaptureLost() = 0; - virtual ui::TouchStatus OnTouchEvent(const ui::TouchEvent& event) = 0; - virtual ui::EventResult OnGestureEvent(const ui::GestureEvent& event) = 0; + + virtual ui::EventResult OnTouchEvent(ui::TouchEvent* event) = 0; + virtual ui::EventResult OnScrollEvent(ui::ScrollEvent* event) = 0; + virtual ui::EventResult OnGestureEvent(ui::GestureEvent* event) = 0; // Runs the specified native command. Returns true if the command is handled. virtual bool ExecuteCommand(int command_id) = 0; diff --git a/ui/views/widget/root_view.cc b/ui/views/widget/root_view.cc index 706409c..b8cac10 100644 --- a/ui/views/widget/root_view.cc +++ b/ui/views/widget/root_view.cc @@ -111,7 +111,7 @@ void RootView::NotifyNativeViewHierarchyChanged(bool attached, // Input ----------------------------------------------------------------------- -bool RootView::OnKeyEvent(const ui::KeyEvent& event) { +ui::EventResult RootView::DispatchKeyEvent(const ui::KeyEvent& event) { bool consumed = false; View* v = NULL; @@ -122,13 +122,169 @@ bool RootView::OnKeyEvent(const ui::KeyEvent& event) { if (v && v->enabled() && ((event.key_code() == ui::VKEY_APPS) || (event.key_code() == ui::VKEY_F10 && event.IsShiftDown()))) { v->ShowContextMenu(v->GetKeyboardContextMenuLocation(), false); - return true; + return ui::ER_CONSUMED; } for (; v && v != this && !consumed; v = v->parent()) { consumed = (event.type() == ui::ET_KEY_PRESSED) ? v->OnKeyPressed(event) : v->OnKeyReleased(event); } - return consumed; + + return consumed ? ui::ER_CONSUMED : ui::ER_HANDLED; +} + +ui::EventResult RootView::DispatchScrollEvent(ui::ScrollEvent* event) { + int result = ui::ER_UNHANDLED; + for (View* v = GetEventHandlerForPoint(event->location()); + v && v != this && !(result & ui::ER_CONSUMED); v = v->parent()) + result |= v->OnScrollEvent(event); + return static_cast<ui::EventResult>(result); +} + +ui::EventResult RootView::DispatchTouchEvent(ui::TouchEvent* event) { + // TODO: this looks all wrong. On a TOUCH_PRESSED we should figure out the + // view and target that view with all touches with the same id until the + // release (or keep it if captured). + + // If touch_pressed_handler_ is non null, we are currently processing + // a touch down on the screen situation. In that case we send the + // event to touch_pressed_handler_ + ui::EventResult status = ui::ER_UNHANDLED; + + if (touch_pressed_handler_) { + ui::TouchEvent touch_event(*event, static_cast<View*>(this), + touch_pressed_handler_); + status = touch_pressed_handler_->ProcessTouchEvent(&touch_event); + return status; + } + + // Walk up the tree until we find a view that wants the touch event. + for (touch_pressed_handler_ = GetEventHandlerForPoint(event->location()); + touch_pressed_handler_ && (touch_pressed_handler_ != this); + touch_pressed_handler_ = touch_pressed_handler_->parent()) { + if (!touch_pressed_handler_->enabled()) { + // Disabled views eat events but are treated as not handled. + break; + } + + // See if this view wants to handle the touch + ui::TouchEvent touch_event(*event, static_cast<View*>(this), + touch_pressed_handler_); + status = touch_pressed_handler_->ProcessTouchEvent(&touch_event); + + // The view could have removed itself from the tree when handling + // OnTouchEvent(). So handle as per OnMousePressed. NB: we + // assume that the RootView itself cannot be so removed. + if (!touch_pressed_handler_) + break; + + // The touch event wasn't processed. Go up the view hierarchy and dispatch + // the touch event. + if (status == ui::ER_UNHANDLED) + continue; + + // If a View consumed the event, that means future touch-events should go to + // that View. If the event wasn't consumed, then reset the handler. + if (!(status & ui::ER_CONSUMED)) + touch_pressed_handler_ = NULL; + + return status; + } + + // Reset touch_pressed_handler_ to indicate that no processing is occurring. + touch_pressed_handler_ = NULL; + + return status; +} + +ui::EventResult RootView::DispatchGestureEvent(ui::GestureEvent* event) { + ui::EventResult status = ui::ER_UNHANDLED; + + if (gesture_handler_) { + // |gesture_handler_| (or |scroll_gesture_handler_|) can be deleted during + // processing. + View* handler = scroll_gesture_handler_ && + (event->IsScrollGestureEvent() || event->IsFlingScrollEvent()) ? + scroll_gesture_handler_ : gesture_handler_; + ui::GestureEvent handler_event(*event, static_cast<View*>(this), handler); + + ui::EventResult status = handler->ProcessGestureEvent(&handler_event); + + if (event->type() == ui::ET_GESTURE_END && + event->details().touch_points() <= 1) { + // In case a drag was in progress, reset all the handlers. Otherwise, just + // reset the gesture handler. + if (gesture_handler_ == mouse_pressed_handler_) + SetMouseHandler(NULL); + else + gesture_handler_ = NULL; + } + + if (scroll_gesture_handler_ && + (event->type() == ui::ET_GESTURE_SCROLL_END || + event->type() == ui::ET_SCROLL_FLING_START)) { + scroll_gesture_handler_ = NULL; + } + + if (status == ui::ER_CONSUMED) + return status; + + DCHECK_EQ(ui::ER_UNHANDLED, status); + + if (event->type() == ui::ET_GESTURE_SCROLL_BEGIN && + !scroll_gesture_handler_) { + // Some view started processing gesture events, however it does not + // process scroll-gesture events. In such case, we allow the event to + // bubble up, and install a different scroll-gesture handler different + // from the default gesture handler. + for (scroll_gesture_handler_ = gesture_handler_->parent(); + scroll_gesture_handler_ && scroll_gesture_handler_ != this; + scroll_gesture_handler_ = scroll_gesture_handler_->parent()) { + ui::GestureEvent gesture_event(*event, static_cast<View*>(this), + scroll_gesture_handler_); + status = scroll_gesture_handler_->ProcessGestureEvent(&gesture_event); + if (status == ui::ER_CONSUMED) + return status; + } + scroll_gesture_handler_ = NULL; + } + + return ui::ER_UNHANDLED; + } + + // Walk up the tree until we find a view that wants the gesture event. + for (gesture_handler_ = GetEventHandlerForPoint(event->location()); + gesture_handler_ && (gesture_handler_ != this); + gesture_handler_ = gesture_handler_->parent()) { + if (!gesture_handler_->enabled()) { + // Disabled views eat events but are treated as not handled. + return ui::ER_UNHANDLED; + } + + // See if this view wants to handle the Gesture. + ui::GestureEvent gesture_event(*event, static_cast<View*>(this), + gesture_handler_); + status = gesture_handler_->ProcessGestureEvent(&gesture_event); + + // The view could have removed itself from the tree when handling + // OnGestureEvent(). So handle as per OnMousePressed. NB: we + // assume that the RootView itself cannot be so removed. + if (!gesture_handler_) + return ui::ER_UNHANDLED; + + if (status == ui::ER_CONSUMED) { + if (gesture_event.type() == ui::ET_GESTURE_SCROLL_BEGIN) + scroll_gesture_handler_ = gesture_handler_; + return status; + } + + // The gesture event wasn't processed. Go up the view hierarchy and + // dispatch the gesture event. + DCHECK_EQ(ui::ER_UNHANDLED, status); + } + + gesture_handler_ = NULL; + + return status; } // Focus ----------------------------------------------------------------------- @@ -387,163 +543,6 @@ bool RootView::OnMouseWheel(const ui::MouseWheelEvent& event) { return consumed; } -bool RootView::OnScrollEvent(const ui::ScrollEvent& event) { - bool consumed = false; - for (View* v = GetEventHandlerForPoint(event.location()); - v && v != this && !consumed; v = v->parent()) - consumed = v->OnScrollEvent(event); - return consumed; -} - -ui::TouchStatus RootView::OnTouchEvent(const ui::TouchEvent& event) { - // TODO: this looks all wrong. On a TOUCH_PRESSED we should figure out the - // view and target that view with all touches with the same id until the - // release (or keep it if captured). - - // If touch_pressed_handler_ is non null, we are currently processing - // a touch down on the screen situation. In that case we send the - // event to touch_pressed_handler_ - ui::TouchStatus status = ui::TOUCH_STATUS_UNKNOWN; - - if (touch_pressed_handler_) { - ui::TouchEvent touch_event(event, static_cast<View*>(this), - touch_pressed_handler_); - status = touch_pressed_handler_->ProcessTouchEvent(touch_event); - if (status == ui::TOUCH_STATUS_END) - touch_pressed_handler_ = NULL; - return status; - } - - // Walk up the tree until we find a view that wants the touch event. - for (touch_pressed_handler_ = GetEventHandlerForPoint(event.location()); - touch_pressed_handler_ && (touch_pressed_handler_ != this); - touch_pressed_handler_ = touch_pressed_handler_->parent()) { - if (!touch_pressed_handler_->enabled()) { - // Disabled views eat events but are treated as not handled. - status = ui::TOUCH_STATUS_UNKNOWN; - break; - } - - // See if this view wants to handle the touch - ui::TouchEvent touch_event(event, static_cast<View*>(this), - touch_pressed_handler_); - status = touch_pressed_handler_->ProcessTouchEvent(touch_event); - - // The view could have removed itself from the tree when handling - // OnTouchEvent(). So handle as per OnMousePressed. NB: we - // assume that the RootView itself cannot be so removed. - if (!touch_pressed_handler_) - break; - - // The touch event wasn't processed. Go up the view hierarchy and dispatch - // the touch event. - if (status == ui::TOUCH_STATUS_UNKNOWN) - continue; - - // If the touch didn't initiate a touch-sequence, then reset the touch event - // handler. Otherwise, leave it set so that subsequent touch events are - // dispatched to the same handler. - if (status != ui::TOUCH_STATUS_START) - touch_pressed_handler_ = NULL; - - return status; - } - - // Reset touch_pressed_handler_ to indicate that no processing is occurring. - touch_pressed_handler_ = NULL; - - return status; -} - -ui::EventResult RootView::OnGestureEvent(const ui::GestureEvent& event) { - ui::EventResult status = ui::ER_UNHANDLED; - - if (gesture_handler_) { - // |gesture_handler_| (or |scroll_gesture_handler_|) can be deleted during - // processing. - View* handler = scroll_gesture_handler_ && - (event.IsScrollGestureEvent() || event.IsFlingScrollEvent()) ? - scroll_gesture_handler_ : gesture_handler_; - ui::GestureEvent handler_event(event, static_cast<View*>(this), handler); - - ui::EventResult status = handler->ProcessGestureEvent(handler_event); - - if (event.type() == ui::ET_GESTURE_END && - event.details().touch_points() <= 1) { - // In case a drag was in progress, reset all the handlers. Otherwise, just - // reset the gesture handler. - if (gesture_handler_ == mouse_pressed_handler_) - SetMouseHandler(NULL); - else - gesture_handler_ = NULL; - } - - if (scroll_gesture_handler_ && (event.type() == ui::ET_GESTURE_SCROLL_END || - event.type() == ui::ET_SCROLL_FLING_START)) - scroll_gesture_handler_ = NULL; - - if (status == ui::ER_CONSUMED) - return status; - - DCHECK_EQ(ui::ER_UNHANDLED, status); - - if (event.type() == ui::ET_GESTURE_SCROLL_BEGIN && - !scroll_gesture_handler_) { - // Some view started processing gesture events, however it does not - // process scroll-gesture events. In such case, we allow the event to - // bubble up, and install a different scroll-gesture handler different - // from the default gesture handler. - for (scroll_gesture_handler_ = gesture_handler_->parent(); - scroll_gesture_handler_ && scroll_gesture_handler_ != this; - scroll_gesture_handler_ = scroll_gesture_handler_->parent()) { - ui::GestureEvent gesture_event(event, static_cast<View*>(this), - scroll_gesture_handler_); - status = scroll_gesture_handler_->ProcessGestureEvent(gesture_event); - if (status == ui::ER_CONSUMED) - return status; - } - scroll_gesture_handler_ = NULL; - } - - return ui::ER_UNHANDLED; - } - - // Walk up the tree until we find a view that wants the gesture event. - for (gesture_handler_ = GetEventHandlerForPoint(event.location()); - gesture_handler_ && (gesture_handler_ != this); - gesture_handler_ = gesture_handler_->parent()) { - if (!gesture_handler_->enabled()) { - // Disabled views eat events but are treated as not handled. - return ui::ER_UNHANDLED; - } - - // See if this view wants to handle the Gesture. - ui::GestureEvent gesture_event(event, static_cast<View*>(this), - gesture_handler_); - status = gesture_handler_->ProcessGestureEvent(gesture_event); - - // The view could have removed itself from the tree when handling - // OnGestureEvent(). So handle as per OnMousePressed. NB: we - // assume that the RootView itself cannot be so removed. - if (!gesture_handler_) - return ui::ER_UNHANDLED; - - if (status == ui::ER_CONSUMED) { - if (gesture_event.type() == ui::ET_GESTURE_SCROLL_BEGIN) - scroll_gesture_handler_ = gesture_handler_; - return status; - } - - // The gesture event wasn't processed. Go up the view hierarchy and - // dispatch the gesture event. - DCHECK_EQ(ui::ER_UNHANDLED, status); - } - - gesture_handler_ = NULL; - - return status; -} - void RootView::SetMouseHandler(View* new_mh) { // If we're clearing the mouse handler, clear explicit_mouse_handler_ as well. explicit_mouse_handler_ = (new_mh != NULL); diff --git a/ui/views/widget/root_view.h b/ui/views/widget/root_view.h index 1af6d59..66ffc06 100644 --- a/ui/views/widget/root_view.h +++ b/ui/views/widget/root_view.h @@ -12,10 +12,6 @@ #include "ui/views/focus/focus_search.h" #include "ui/views/view.h" -namespace ui { -enum TouchStatus; -} - namespace views { class Widget; @@ -65,7 +61,10 @@ class VIEWS_EXPORT RootView : public View, public FocusTraversable { // Process a key event. Send the event to the focused view and up the focus // path, and finally to the default keyboard handler, until someone consumes // it. Returns whether anyone consumed the event. - bool OnKeyEvent(const ui::KeyEvent& event); + ui::EventResult DispatchKeyEvent(const ui::KeyEvent& event); + ui::EventResult DispatchScrollEvent(ui::ScrollEvent* event); + ui::EventResult DispatchTouchEvent(ui::TouchEvent* event); + ui::EventResult DispatchGestureEvent(ui::GestureEvent* event); // Focus --------------------------------------------------------------------- @@ -104,10 +103,6 @@ class VIEWS_EXPORT RootView : public View, public FocusTraversable { virtual void OnMouseMoved(const ui::MouseEvent& event) OVERRIDE; virtual void OnMouseExited(const ui::MouseEvent& event) OVERRIDE; virtual bool OnMouseWheel(const ui::MouseWheelEvent& event) OVERRIDE; - virtual bool OnScrollEvent(const ui::ScrollEvent& event) OVERRIDE; - virtual ui::TouchStatus OnTouchEvent(const ui::TouchEvent& event) OVERRIDE; - virtual ui::EventResult OnGestureEvent( - const ui::GestureEvent& event) OVERRIDE; virtual void SetMouseHandler(View* new_mouse_handler) OVERRIDE; virtual void GetAccessibleState(ui::AccessibleViewState* state) OVERRIDE; virtual void ReorderChildLayers(ui::Layer* parent_layer) OVERRIDE; diff --git a/ui/views/widget/widget.cc b/ui/views/widget/widget.cc index 8a42f91..a4d48bb 100644 --- a/ui/views/widget/widget.cc +++ b/ui/views/widget/widget.cc @@ -1086,7 +1086,8 @@ int Widget::GetNonClientComponent(const gfx::Point& point) { bool Widget::OnKeyEvent(const ui::KeyEvent& event) { ScopedEvent scoped(this, event); - return static_cast<internal::RootView*>(GetRootView())->OnKeyEvent(event); + return static_cast<internal::RootView*>(GetRootView())-> + DispatchKeyEvent(event) == ui::ER_UNHANDLED; } bool Widget::OnMouseEvent(const ui::MouseEvent& event) { @@ -1132,9 +1133,6 @@ bool Widget::OnMouseEvent(const ui::MouseEvent& event) { case ui::ET_MOUSEWHEEL: return GetRootView()->OnMouseWheel( reinterpret_cast<const ui::MouseWheelEvent&>(event)); - case ui::ET_SCROLL: - return GetRootView()->OnScrollEvent( - reinterpret_cast<const ui::ScrollEvent&>(event)); default: return false; } @@ -1148,14 +1146,21 @@ void Widget::OnMouseCaptureLost() { is_mouse_button_pressed_ = false; } -ui::TouchStatus Widget::OnTouchEvent(const ui::TouchEvent& event) { - ScopedEvent scoped(this, event); - return GetRootView()->OnTouchEvent(event); +ui::EventResult Widget::OnTouchEvent(ui::TouchEvent* event) { + ScopedEvent scoped(this, *event); + return static_cast<internal::RootView*>(GetRootView())-> + DispatchTouchEvent(event); } -ui::EventResult Widget::OnGestureEvent(const ui::GestureEvent& event) { - ScopedEvent scoped(this, event); - switch (event.type()) { +ui::EventResult Widget::OnScrollEvent(ui::ScrollEvent* event) { + ScopedEvent scoped(this, *event); + return static_cast<internal::RootView*>(GetRootView())-> + DispatchScrollEvent(event); +} + +ui::EventResult Widget::OnGestureEvent(ui::GestureEvent* event) { + ScopedEvent scoped(this, *event); + switch (event->type()) { case ui::ET_GESTURE_TAP_DOWN: is_touch_down_ = true; // We explicitly don't capture here. Not capturing enables multiple @@ -1164,7 +1169,7 @@ ui::EventResult Widget::OnGestureEvent(const ui::GestureEvent& event) { break; case ui::ET_GESTURE_END: - if (event.details().touch_points() == 1) { + if (event->details().touch_points() == 1) { is_touch_down_ = false; if (ShouldReleaseCaptureOnMouseReleased()) ReleaseCapture(); @@ -1174,7 +1179,8 @@ ui::EventResult Widget::OnGestureEvent(const ui::GestureEvent& event) { default: break; } - return GetRootView()->OnGestureEvent(event); + return static_cast<internal::RootView*>(GetRootView())-> + DispatchGestureEvent(event); } bool Widget::ExecuteCommand(int command_id) { diff --git a/ui/views/widget/widget.h b/ui/views/widget/widget.h index 224d7b6..e906327 100644 --- a/ui/views/widget/widget.h +++ b/ui/views/widget/widget.h @@ -47,7 +47,6 @@ class Compositor; class Layer; class OSExchangeData; class ThemeProvider; -enum TouchStatus; } namespace views { @@ -646,9 +645,9 @@ class VIEWS_EXPORT Widget : public internal::NativeWidgetDelegate, virtual bool OnKeyEvent(const ui::KeyEvent& event) OVERRIDE; virtual bool OnMouseEvent(const ui::MouseEvent& event) OVERRIDE; virtual void OnMouseCaptureLost() OVERRIDE; - virtual ui::TouchStatus OnTouchEvent(const ui::TouchEvent& event) OVERRIDE; - virtual ui::EventResult OnGestureEvent( - const ui::GestureEvent& event) OVERRIDE; + virtual ui::EventResult OnTouchEvent(ui::TouchEvent* event) OVERRIDE; + virtual ui::EventResult OnScrollEvent(ui::ScrollEvent* event) OVERRIDE; + virtual ui::EventResult OnGestureEvent(ui::GestureEvent* event) OVERRIDE; virtual bool ExecuteCommand(int command_id) OVERRIDE; virtual InputMethod* GetInputMethodDirect() OVERRIDE; virtual const std::vector<ui::Layer*>& GetRootLayers() OVERRIDE; diff --git a/ui/views/widget/widget_unittest.cc b/ui/views/widget/widget_unittest.cc index abc416a..4b75f51 100644 --- a/ui/views/widget/widget_unittest.cc +++ b/ui/views/widget/widget_unittest.cc @@ -125,9 +125,8 @@ class GestureCaptureView : public View { private: // Overridden from View: - virtual ui::EventResult OnGestureEvent( - const ui::GestureEvent& event) OVERRIDE { - if (event.type() == ui::ET_GESTURE_BEGIN) { + virtual ui::EventResult OnGestureEvent(ui::GestureEvent* event) OVERRIDE { + if (event->type() == ui::ET_GESTURE_BEGIN) { GetWidget()->SetCapture(this); return ui::ER_CONSUMED; } @@ -951,7 +950,7 @@ TEST_F(WidgetTest, ResetCaptureOnGestureEnd) { ui::GestureEvent end(ui::ET_GESTURE_END, 15, 15, 0, base::TimeDelta(), ui::GestureEventDetails(ui::ET_GESTURE_END, 0, 0), 1); - toplevel->OnGestureEvent(begin); + toplevel->OnGestureEvent(&begin); // Now try to click on |mouse|. Since |gesture| will have capture, |mouse| // will not receive the event. @@ -967,7 +966,7 @@ TEST_F(WidgetTest, ResetCaptureOnGestureEnd) { // The end of the gesture should release the capture, and pressing on |mouse| // should now reach |mouse|. - toplevel->OnGestureEvent(end); + toplevel->OnGestureEvent(&end); toplevel->OnMouseEvent(press); toplevel->OnMouseEvent(release); EXPECT_EQ(1, mouse->pressed()); |