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

Side by Side 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: Gardening. 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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "ui/views/controls/menu/submenu_view.h" 5 #include "ui/views/controls/menu/submenu_view.h"
6 6
7 #include <algorithm>
8
9 #include "base/compiler_specific.h"
7 #include "ui/base/accessibility/accessible_view_state.h" 10 #include "ui/base/accessibility/accessible_view_state.h"
8 #include "ui/gfx/canvas.h" 11 #include "ui/gfx/canvas.h"
9 #include "ui/views/controls/menu/menu_config.h" 12 #include "ui/views/controls/menu/menu_config.h"
10 #include "ui/views/controls/menu/menu_controller.h" 13 #include "ui/views/controls/menu/menu_controller.h"
11 #include "ui/views/controls/menu/menu_host.h" 14 #include "ui/views/controls/menu/menu_host.h"
12 #include "ui/views/controls/menu/menu_scroll_view_container.h" 15 #include "ui/views/controls/menu/menu_scroll_view_container.h"
13 #include "ui/views/widget/root_view.h" 16 #include "ui/views/widget/root_view.h"
14 #include "ui/views/widget/widget.h" 17 #include "ui/views/widget/widget.h"
15 18
16 namespace { 19 namespace {
(...skipping 15 matching lines...) Expand all
32 const char SubmenuView::kViewClassName[] = "views/SubmenuView"; 35 const char SubmenuView::kViewClassName[] = "views/SubmenuView";
33 36
34 SubmenuView::SubmenuView(MenuItemView* parent) 37 SubmenuView::SubmenuView(MenuItemView* parent)
35 : parent_menu_item_(parent), 38 : parent_menu_item_(parent),
36 host_(NULL), 39 host_(NULL),
37 drop_item_(NULL), 40 drop_item_(NULL),
38 drop_position_(MenuDelegate::DROP_NONE), 41 drop_position_(MenuDelegate::DROP_NONE),
39 scroll_view_container_(NULL), 42 scroll_view_container_(NULL),
40 max_accelerator_width_(0), 43 max_accelerator_width_(0),
41 minimum_preferred_width_(0), 44 minimum_preferred_width_(0),
42 resize_open_menu_(false) { 45 resize_open_menu_(false),
46 ALLOW_THIS_IN_INITIALIZER_LIST(
47 scroll_animator_(new ScrollAnimator(this))) {
43 DCHECK(parent); 48 DCHECK(parent);
44 // We'll delete ourselves, otherwise the ScrollView would delete us on close. 49 // We'll delete ourselves, otherwise the ScrollView would delete us on close.
45 set_parent_owned(false); 50 set_parent_owned(false);
46 } 51 }
47 52
48 SubmenuView::~SubmenuView() { 53 SubmenuView::~SubmenuView() {
49 // The menu may not have been closed yet (it will be hidden, but not 54 // The menu may not have been closed yet (it will be hidden, but not
50 // necessarily closed). 55 // necessarily closed).
51 Close(); 56 Close();
52 57
(...skipping 182 matching lines...) Expand 10 before | Expand all | Expand 10 after
235 first_vis_index++; 240 first_vis_index++;
236 } 241 }
237 ScrollRectToVisible(gfx::Rect(gfx::Point(0, scroll_target), 242 ScrollRectToVisible(gfx::Rect(gfx::Point(0, scroll_target),
238 vis_bounds.size())); 243 vis_bounds.size()));
239 vis_bounds = GetVisibleBounds(); 244 vis_bounds = GetVisibleBounds();
240 } 245 }
241 246
242 return true; 247 return true;
243 } 248 }
244 249
250 ui::GestureStatus SubmenuView::OnGestureEvent(const GestureEvent& e) {
251 ui::GestureStatus to_return = ui::GESTURE_STATUS_CONSUMED;
252 switch (e.type()) {
253 case ui::ET_GESTURE_SCROLL_BEGIN:
254 scroll_animator_->Stop();
255 break;
256 case ui::ET_GESTURE_SCROLL_UPDATE:
257 OnScroll(0, e.delta_y());
258 break;
259 case ui::ET_GESTURE_SCROLL_END:
260 if (e.delta_y() != 0.0f)
261 scroll_animator_->Start(0, e.delta_y());
262 break;
263 default:
264 to_return = ui::GESTURE_STATUS_UNKNOWN;
265 break;
266 }
267 return to_return;
268 }
269
245 bool SubmenuView::IsShowing() { 270 bool SubmenuView::IsShowing() {
246 return host_ && host_->IsMenuHostVisible(); 271 return host_ && host_->IsMenuHostVisible();
247 } 272 }
248 273
249 void SubmenuView::ShowAt(Widget* parent, 274 void SubmenuView::ShowAt(Widget* parent,
250 const gfx::Rect& bounds, 275 const gfx::Rect& bounds,
251 bool do_capture) { 276 bool do_capture) {
252 if (host_) { 277 if (host_) {
253 host_->ShowMenuHost(do_capture); 278 host_->ShowMenuHost(do_capture);
254 } else { 279 } else {
(...skipping 133 matching lines...) Expand 10 before | Expand all | Expand 10 after
388 item_bounds.Offset(0, item_bounds.height() - kDropIndicatorHeight / 2); 413 item_bounds.Offset(0, item_bounds.height() - kDropIndicatorHeight / 2);
389 item_bounds.set_height(kDropIndicatorHeight); 414 item_bounds.set_height(kDropIndicatorHeight);
390 return item_bounds; 415 return item_bounds;
391 416
392 default: 417 default:
393 // Don't render anything for on. 418 // Don't render anything for on.
394 return gfx::Rect(); 419 return gfx::Rect();
395 } 420 }
396 } 421 }
397 422
423 void SubmenuView::OnScroll(float dx, float dy) {
424 const gfx::Rect& vis_bounds = GetVisibleBounds();
425 const gfx::Rect& full_bounds = bounds();
426 int x = vis_bounds.x();
427 int y = vis_bounds.y() - static_cast<int>(dy);
428 // clamp y to [0, full_height - vis_height)
429 y = std::max(y, 0);
430 y = std::min(y, full_bounds.height() - vis_bounds.height() - 1);
431 gfx::Rect new_vis_bounds(x, y, vis_bounds.width(), vis_bounds.height());
432 if (new_vis_bounds != vis_bounds)
433 ScrollRectToVisible(new_vis_bounds);
434 }
435
398 } // namespace views 436 } // namespace views
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698