diff options
author | xiyuan@chromium.org <xiyuan@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-06-22 04:29:31 +0000 |
---|---|---|
committer | xiyuan@chromium.org <xiyuan@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-06-22 04:29:31 +0000 |
commit | 6b28dd277bf26851288a4e435e67f88af24d0da2 (patch) | |
tree | 9253a38debce2d89cc8effa624fe12de36ad283b /ui | |
parent | ff51c40874d8df74882a615781887eeb5f29a404 (diff) | |
download | chromium_src-6b28dd277bf26851288a4e435e67f88af24d0da2.zip chromium_src-6b28dd277bf26851288a4e435e67f88af24d0da2.tar.gz chromium_src-6b28dd277bf26851288a4e435e67f88af24d0da2.tar.bz2 |
Wire ScrollEvent to views and handle it in app list.
- Pass ScrollEvent to views system;
- Add a OnScrollEvent to View;
- Forward ScrollEvent to RootView in Widget;
- RootView dispatches ScrollEvent to view under where event happens
and if not processed, pass it to the parent;
- Handle ScrollEvent to switch pages in app list;
BUG=131075
TEST=Verify two-finger scroll on touch pad switches pages in app list;
Review URL: https://chromiumcodereview.appspot.com/10577045
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@143531 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'ui')
-rw-r--r-- | ui/app_list/apps_grid_view.cc | 16 | ||||
-rw-r--r-- | ui/app_list/apps_grid_view.h | 1 | ||||
-rw-r--r-- | ui/app_list/pagination_model.h | 8 | ||||
-rw-r--r-- | ui/app_list/search_box_view.cc | 2 | ||||
-rw-r--r-- | ui/views/events/event.h | 9 | ||||
-rw-r--r-- | ui/views/view.cc | 4 | ||||
-rw-r--r-- | ui/views/view.h | 6 | ||||
-rw-r--r-- | ui/views/widget/root_view.cc | 9 | ||||
-rw-r--r-- | ui/views/widget/root_view.h | 1 | ||||
-rw-r--r-- | ui/views/widget/widget.cc | 3 |
10 files changed, 53 insertions, 6 deletions
diff --git a/ui/app_list/apps_grid_view.cc b/ui/app_list/apps_grid_view.cc index 38bbda4..50b2948 100644 --- a/ui/app_list/apps_grid_view.cc +++ b/ui/app_list/apps_grid_view.cc @@ -27,6 +27,7 @@ const int kPreferredTileHeight = 98; const int kMaxExtraColPaddingForInvalidTransition = 80; const int kMinMouseWheelToSwitchPage = 20; +const int kMinScrollToSwitchPage = 20; const int kMinHorizVelocityToSwitchPage = 1100; } // namespace @@ -261,7 +262,20 @@ bool AppsGridView::OnKeyReleased(const views::KeyEvent& event) { bool AppsGridView::OnMouseWheel(const views::MouseWheelEvent& event) { if (abs(event.offset()) > kMinMouseWheelToSwitchPage) { - pagination_model_->SelectPageRelative(event.offset() > 0 ? -1 : 1, true); + if (!pagination_model_->has_transition()) + pagination_model_->SelectPageRelative(event.offset() > 0 ? -1 : 1, true); + return true; + } + + return false; +} + +bool AppsGridView::OnScrollEvent(const views::ScrollEvent & event) { + if (abs(event.x_offset()) > kMinScrollToSwitchPage) { + if (!pagination_model_->has_transition()) { + pagination_model_->SelectPageRelative(event.x_offset() > 0 ? 1 : -1, + true); + } return true; } diff --git a/ui/app_list/apps_grid_view.h b/ui/app_list/apps_grid_view.h index 97ab5bb..4cff9ce 100644 --- a/ui/app_list/apps_grid_view.h +++ b/ui/app_list/apps_grid_view.h @@ -55,6 +55,7 @@ class APP_LIST_EXPORT AppsGridView : public views::View, virtual bool OnKeyPressed(const views::KeyEvent& event) OVERRIDE; virtual bool OnKeyReleased(const views::KeyEvent& event) OVERRIDE; virtual bool OnMouseWheel(const views::MouseWheelEvent& event) OVERRIDE; + virtual bool OnScrollEvent(const views::ScrollEvent & event) OVERRIDE; virtual void OnPaintFocusBorder(gfx::Canvas* canvas) OVERRIDE; private: diff --git a/ui/app_list/pagination_model.h b/ui/app_list/pagination_model.h index c61177f..ce013be 100644 --- a/ui/app_list/pagination_model.h +++ b/ui/app_list/pagination_model.h @@ -86,14 +86,14 @@ class APP_LIST_EXPORT PaginationModel : public ui::AnimationDelegate { return page >= 0 && page < total_pages_; } - private: - void NotifySelectedPageChanged(int old_selected, int new_selected); - void NotifyTransitionChanged(); - bool has_transition() const { return transition_.target_page != -1 || transition_.progress != 0; } + private: + void NotifySelectedPageChanged(int old_selected, int new_selected); + void NotifyTransitionChanged(); + void clear_transition() { SetTransition(Transition(-1, 0)); } diff --git a/ui/app_list/search_box_view.cc b/ui/app_list/search_box_view.cc index ab3dd11..1c5a6df 100644 --- a/ui/app_list/search_box_view.cc +++ b/ui/app_list/search_box_view.cc @@ -88,7 +88,7 @@ void SearchBoxView::Layout() { bool SearchBoxView::OnMouseWheel(const views::MouseWheelEvent& event) { if (contents_view_) - contents_view_->OnMouseWheel(event); + return contents_view_->OnMouseWheel(event); return false; } diff --git a/ui/views/events/event.h b/ui/views/events/event.h index d0fb969..44ef1b6 100644 --- a/ui/views/events/event.h +++ b/ui/views/events/event.h @@ -391,10 +391,19 @@ class VIEWS_EXPORT DropTargetEvent : public LocatedEvent { class VIEWS_EXPORT ScrollEvent : public MouseEvent { public: explicit ScrollEvent(const NativeEvent& native_event); + float x_offset() const { return x_offset_; } float y_offset() const { return y_offset_; } private: + friend class internal::RootView; + + ScrollEvent(const ScrollEvent& model, View* root) + : MouseEvent(model, root), + x_offset_(model.x_offset()), + y_offset_(model.y_offset()) { + } + float x_offset_; float y_offset_; diff --git a/ui/views/view.cc b/ui/views/view.cc index 9541ab5..d200d03 100644 --- a/ui/views/view.cc +++ b/ui/views/view.cc @@ -846,6 +846,10 @@ bool View::OnMouseWheel(const MouseWheelEvent& event) { return false; } +bool View::OnScrollEvent(const ScrollEvent& event) { + return false; +} + ui::TextInputClient* View::GetTextInputClient() { return NULL; } diff --git a/ui/views/view.h b/ui/views/view.h index f656747..10c2806 100644 --- a/ui/views/view.h +++ b/ui/views/view.h @@ -617,6 +617,12 @@ class VIEWS_EXPORT View : public ui::LayerDelegate, // will be given a chance. virtual bool OnMouseWheel(const 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 ScrollEvent& event); + // See field for description. void set_notify_enter_exit_on_child(bool notify) { notify_enter_exit_on_child_ = notify; diff --git a/ui/views/widget/root_view.cc b/ui/views/widget/root_view.cc index 515fa23..5d2aba3 100644 --- a/ui/views/widget/root_view.cc +++ b/ui/views/widget/root_view.cc @@ -381,6 +381,15 @@ bool RootView::OnMouseWheel(const MouseWheelEvent& event) { return consumed; } +bool RootView::OnScrollEvent(const ScrollEvent& event) { + ScrollEvent e(event, this); + bool consumed = false; + for (View* v = GetEventHandlerForPoint(e.location()); + v && v != this && !consumed; v = v->parent()) + consumed = v->OnScrollEvent(e); + return consumed; +} + ui::TouchStatus RootView::OnTouchEvent(const 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 diff --git a/ui/views/widget/root_view.h b/ui/views/widget/root_view.h index 9ffd601..2db8a91 100644 --- a/ui/views/widget/root_view.h +++ b/ui/views/widget/root_view.h @@ -105,6 +105,7 @@ class VIEWS_EXPORT RootView : public View, public FocusTraversable { virtual void OnMouseMoved(const MouseEvent& event) OVERRIDE; virtual void OnMouseExited(const MouseEvent& event) OVERRIDE; virtual bool OnMouseWheel(const MouseWheelEvent& event) OVERRIDE; + virtual bool OnScrollEvent(const ScrollEvent& event) OVERRIDE; virtual ui::TouchStatus OnTouchEvent(const TouchEvent& event) OVERRIDE; virtual ui::GestureStatus OnGestureEvent(const GestureEvent& event) OVERRIDE; virtual void SetMouseHandler(View* new_mouse_handler) OVERRIDE; diff --git a/ui/views/widget/widget.cc b/ui/views/widget/widget.cc index 31748ed..21c6735 100644 --- a/ui/views/widget/widget.cc +++ b/ui/views/widget/widget.cc @@ -1116,6 +1116,9 @@ bool Widget::OnMouseEvent(const MouseEvent& event) { case ui::ET_MOUSEWHEEL: return GetRootView()->OnMouseWheel( reinterpret_cast<const MouseWheelEvent&>(event)); + case ui::ET_SCROLL: + return GetRootView()->OnScrollEvent( + reinterpret_cast<const ScrollEvent&>(event)); default: return false; } |