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 "ui/base/accessibility/accessible_view_state.h" | 7 #include "ui/base/accessibility/accessible_view_state.h" |
8 #include "ui/gfx/canvas.h" | 8 #include "ui/gfx/canvas.h" |
9 #include "views/controls/menu/menu_config.h" | 9 #include "views/controls/menu/menu_config.h" |
10 #include "views/controls/menu/menu_controller.h" | 10 #include "views/controls/menu/menu_controller.h" |
(...skipping 20 matching lines...) Expand all Loading... |
31 // static | 31 // static |
32 const char SubmenuView::kViewClassName[] = "views/SubmenuView"; | 32 const char SubmenuView::kViewClassName[] = "views/SubmenuView"; |
33 | 33 |
34 SubmenuView::SubmenuView(MenuItemView* parent) | 34 SubmenuView::SubmenuView(MenuItemView* parent) |
35 : parent_menu_item_(parent), | 35 : parent_menu_item_(parent), |
36 host_(NULL), | 36 host_(NULL), |
37 drop_item_(NULL), | 37 drop_item_(NULL), |
38 drop_position_(MenuDelegate::DROP_NONE), | 38 drop_position_(MenuDelegate::DROP_NONE), |
39 scroll_view_container_(NULL), | 39 scroll_view_container_(NULL), |
40 max_accelerator_width_(0), | 40 max_accelerator_width_(0), |
41 minimum_preferred_width_(0) { | 41 minimum_preferred_width_(0), |
| 42 resize_open_menu_(false) { |
42 DCHECK(parent); | 43 DCHECK(parent); |
43 // We'll delete ourselves, otherwise the ScrollView would delete us on close. | 44 // We'll delete ourselves, otherwise the ScrollView would delete us on close. |
44 set_parent_owned(false); | 45 set_parent_owned(false); |
45 } | 46 } |
46 | 47 |
47 SubmenuView::~SubmenuView() { | 48 SubmenuView::~SubmenuView() { |
48 // The menu may not have been closed yet (it will be hidden, but not | 49 // The menu may not have been closed yet (it will be hidden, but not |
49 // necessarily closed). | 50 // necessarily closed). |
50 Close(); | 51 Close(); |
51 | 52 |
(...skipping 13 matching lines...) Expand all Loading... |
65 for (int i = 0, count = 0; i < child_count(); ++i) { | 66 for (int i = 0, count = 0; i < child_count(); ++i) { |
66 if (child_at(i)->id() == MenuItemView::kMenuItemViewID && | 67 if (child_at(i)->id() == MenuItemView::kMenuItemViewID && |
67 count++ == index) { | 68 count++ == index) { |
68 return static_cast<MenuItemView*>(child_at(i)); | 69 return static_cast<MenuItemView*>(child_at(i)); |
69 } | 70 } |
70 } | 71 } |
71 NOTREACHED(); | 72 NOTREACHED(); |
72 return NULL; | 73 return NULL; |
73 } | 74 } |
74 | 75 |
| 76 void SubmenuView::ChildPreferredSizeChanged(View* child) { |
| 77 if (!resize_open_menu_) |
| 78 return; |
| 79 |
| 80 MenuItemView *item = GetMenuItem(); |
| 81 MenuController* controller = item->GetMenuController(); |
| 82 |
| 83 if (controller) { |
| 84 bool dir; |
| 85 gfx::Rect bounds = controller->CalculateMenuBounds(item, false, &dir); |
| 86 Reposition(bounds); |
| 87 } |
| 88 } |
| 89 |
75 void SubmenuView::Layout() { | 90 void SubmenuView::Layout() { |
76 // We're in a ScrollView, and need to set our width/height ourselves. | 91 // We're in a ScrollView, and need to set our width/height ourselves. |
77 if (!parent()) | 92 if (!parent()) |
78 return; | 93 return; |
79 | 94 |
80 // Use our current y, unless it means part of the menu isn't visible anymore. | 95 // Use our current y, unless it means part of the menu isn't visible anymore. |
81 int pref_height = GetPreferredSize().height(); | 96 int pref_height = GetPreferredSize().height(); |
82 int new_y; | 97 int new_y; |
83 if (pref_height > parent()->height()) | 98 if (pref_height > parent()->height()) |
84 new_y = std::max(parent()->height() - pref_height, y()); | 99 new_y = std::max(parent()->height() - pref_height, y()); |
(...skipping 290 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
375 item_bounds.set_height(kDropIndicatorHeight); | 390 item_bounds.set_height(kDropIndicatorHeight); |
376 return item_bounds; | 391 return item_bounds; |
377 | 392 |
378 default: | 393 default: |
379 // Don't render anything for on. | 394 // Don't render anything for on. |
380 return gfx::Rect(); | 395 return gfx::Rect(); |
381 } | 396 } |
382 } | 397 } |
383 | 398 |
384 } // namespace views | 399 } // namespace views |
OLD | NEW |