| OLD | NEW |
| 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 "views/controls/menu/submenu_view.h" | 5 #include "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 "views/controls/menu/menu_config.h" | 12 #include "views/controls/menu/menu_config.h" |
| 10 #include "views/controls/menu/menu_controller.h" | 13 #include "views/controls/menu/menu_controller.h" |
| 11 #include "views/controls/menu/menu_host.h" | 14 #include "views/controls/menu/menu_host.h" |
| 12 #include "views/controls/menu/menu_scroll_view_container.h" | 15 #include "views/controls/menu/menu_scroll_view_container.h" |
| 13 #include "views/widget/root_view.h" | 16 #include "views/widget/root_view.h" |
| 14 #include "views/widget/widget.h" | 17 #include "views/widget/widget.h" |
| 15 | 18 |
| 16 namespace { | 19 namespace { |
| (...skipping 15 matching lines...) Expand all Loading... |
| 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 Loading... |
| 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 switch (e.type()) { |
| 252 case ui::ET_GESTURE_SCROLL_BEGIN: |
| 253 scroll_animator_->Stop(); |
| 254 break; |
| 255 case ui::ET_GESTURE_SCROLL_UPDATE: |
| 256 OnScroll(0, e.delta_y()); |
| 257 break; |
| 258 case ui::ET_GESTURE_SCROLL_END: |
| 259 if (e.delta_y() != 0.0f) |
| 260 scroll_animator_->Start(0, e.delta_y()); |
| 261 break; |
| 262 default: |
| 263 break; |
| 264 } |
| 265 return ui::GESTURE_STATUS_CONSUMED; |
| 266 } |
| 267 |
| 245 bool SubmenuView::IsShowing() { | 268 bool SubmenuView::IsShowing() { |
| 246 return host_ && host_->IsMenuHostVisible(); | 269 return host_ && host_->IsMenuHostVisible(); |
| 247 } | 270 } |
| 248 | 271 |
| 249 void SubmenuView::ShowAt(Widget* parent, | 272 void SubmenuView::ShowAt(Widget* parent, |
| 250 const gfx::Rect& bounds, | 273 const gfx::Rect& bounds, |
| 251 bool do_capture) { | 274 bool do_capture) { |
| 252 if (host_) { | 275 if (host_) { |
| 253 host_->ShowMenuHost(do_capture); | 276 host_->ShowMenuHost(do_capture); |
| 254 } else { | 277 } else { |
| (...skipping 133 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 388 item_bounds.Offset(0, item_bounds.height() - kDropIndicatorHeight / 2); | 411 item_bounds.Offset(0, item_bounds.height() - kDropIndicatorHeight / 2); |
| 389 item_bounds.set_height(kDropIndicatorHeight); | 412 item_bounds.set_height(kDropIndicatorHeight); |
| 390 return item_bounds; | 413 return item_bounds; |
| 391 | 414 |
| 392 default: | 415 default: |
| 393 // Don't render anything for on. | 416 // Don't render anything for on. |
| 394 return gfx::Rect(); | 417 return gfx::Rect(); |
| 395 } | 418 } |
| 396 } | 419 } |
| 397 | 420 |
| 421 void SubmenuView::OnScroll(float dx, float dy) { |
| 422 const gfx::Rect& vis_bounds = GetVisibleBounds(); |
| 423 const gfx::Rect& full_bounds = bounds(); |
| 424 int x = vis_bounds.x(); |
| 425 int y = vis_bounds.y() - static_cast<int>(dy); |
| 426 // clamp y to [0, full_height - vis_height) |
| 427 y = std::max(y, 0); |
| 428 y = std::min(y, full_bounds.height() - vis_bounds.height() - 1); |
| 429 gfx::Rect new_vis_bounds(x, y, vis_bounds.width(), vis_bounds.height()); |
| 430 if (new_vis_bounds != vis_bounds) |
| 431 ScrollRectToVisible(new_vis_bounds); |
| 432 } |
| 433 |
| 398 } // namespace views | 434 } // namespace views |
| OLD | NEW |