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

Unified Diff: ui/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: No reason menu gestures should be linux-only. Created 8 years, 11 months 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: ui/views/controls/menu/submenu_view.cc
diff --git a/ui/views/controls/menu/submenu_view.cc b/ui/views/controls/menu/submenu_view.cc
index 37f199b3fa64655ee9fe79f76de8e9b5ab136996..a2097bfb7ad808400407cfb43ce679179022141d 100644
--- a/ui/views/controls/menu/submenu_view.cc
+++ b/ui/views/controls/menu/submenu_view.cc
@@ -4,6 +4,9 @@
#include "ui/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 "ui/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,26 @@ bool SubmenuView::OnMouseWheel(const MouseWheelEvent& e) {
return true;
}
+ui::GestureStatus SubmenuView::OnGestureEvent(const GestureEvent& e) {
+ ui::GestureStatus to_return = ui::GESTURE_STATUS_CONSUMED;
+ 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:
+ to_return = ui::GESTURE_STATUS_UNKNOWN;
+ break;
+ }
+ return to_return;
+}
+
bool SubmenuView::IsShowing() {
return host_ && host_->IsMenuHostVisible();
}
@@ -395,4 +420,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