Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(496)

Unified Diff: views/controls/menu/submenu_view.cc

Issue 8508024: Support touch scroll gestures in menus. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Gardening. Created 9 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: views/controls/menu/submenu_view.cc
diff --git a/views/controls/menu/submenu_view.cc b/views/controls/menu/submenu_view.cc
index 50cb44044a2bdcc1fa5860a366e55002c3654b48..1f9b38be80ee6ee890266180ce7892d4156caa6e 100644
--- a/views/controls/menu/submenu_view.cc
+++ b/views/controls/menu/submenu_view.cc
@@ -4,6 +4,9 @@
#include "views/controls/menu/submenu_view.h"
+#include <algorithm>
+
+#include "base/compiler_specific.h"
#include "ui/base/accessibility/accessible_view_state.h"
#include "ui/gfx/canvas.h"
#include "views/controls/menu/menu_config.h"
@@ -39,7 +42,9 @@ SubmenuView::SubmenuView(MenuItemView* parent)
scroll_view_container_(NULL),
max_accelerator_width_(0),
minimum_preferred_width_(0),
- resize_open_menu_(false) {
+ resize_open_menu_(false),
+ ALLOW_THIS_IN_INITIALIZER_LIST(
+ scroll_animator_(new ScrollAnimator(this))) {
DCHECK(parent);
// We'll delete ourselves, otherwise the ScrollView would delete us on close.
set_parent_owned(false);
@@ -242,6 +247,24 @@ bool SubmenuView::OnMouseWheel(const MouseWheelEvent& e) {
return true;
}
+ui::GestureStatus SubmenuView::OnGestureEvent(const GestureEvent& e) {
+ switch (e.type()) {
+ case ui::ET_GESTURE_SCROLL_BEGIN:
+ scroll_animator_->Stop();
+ break;
+ case ui::ET_GESTURE_SCROLL_UPDATE:
+ OnScroll(0, e.delta_y());
+ break;
+ case ui::ET_GESTURE_SCROLL_END:
+ if (e.delta_y() != 0.0f)
+ scroll_animator_->Start(0, e.delta_y());
+ break;
+ default:
+ break;
+ }
+ return ui::GESTURE_STATUS_CONSUMED;
+}
+
bool SubmenuView::IsShowing() {
return host_ && host_->IsMenuHostVisible();
}
@@ -395,4 +418,17 @@ gfx::Rect SubmenuView::CalculateDropIndicatorBounds(
}
}
+void SubmenuView::OnScroll(float dx, float dy) {
+ const gfx::Rect& vis_bounds = GetVisibleBounds();
+ const gfx::Rect& full_bounds = bounds();
+ int x = vis_bounds.x();
+ int y = vis_bounds.y() - static_cast<int>(dy);
+ // clamp y to [0, full_height - vis_height)
+ y = std::max(y, 0);
+ y = std::min(y, full_bounds.height() - vis_bounds.height() - 1);
+ gfx::Rect new_vis_bounds(x, y, vis_bounds.width(), vis_bounds.height());
+ if (new_vis_bounds != vis_bounds)
+ ScrollRectToVisible(new_vis_bounds);
+}
+
} // namespace views

Powered by Google App Engine
This is Rietveld 408576698