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 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
48 // The menu may not have been closed yet (it will be hidden, but not | 48 // The menu may not have been closed yet (it will be hidden, but not |
49 // necessarily closed). | 49 // necessarily closed). |
50 Close(); | 50 Close(); |
51 | 51 |
52 delete scroll_view_container_; | 52 delete scroll_view_container_; |
53 } | 53 } |
54 | 54 |
55 int SubmenuView::GetMenuItemCount() { | 55 int SubmenuView::GetMenuItemCount() { |
56 int count = 0; | 56 int count = 0; |
57 for (int i = 0; i < child_count(); ++i) { | 57 for (int i = 0; i < child_count(); ++i) { |
58 if (GetChildViewAt(i)->GetID() == MenuItemView::kMenuItemViewID) | 58 if (GetChildViewAt(i)->id() == MenuItemView::kMenuItemViewID) |
59 count++; | 59 count++; |
60 } | 60 } |
61 return count; | 61 return count; |
62 } | 62 } |
63 | 63 |
64 MenuItemView* SubmenuView::GetMenuItemAt(int index) { | 64 MenuItemView* SubmenuView::GetMenuItemAt(int index) { |
65 for (int i = 0, count = 0; i < child_count(); ++i) { | 65 for (int i = 0, count = 0; i < child_count(); ++i) { |
66 if (GetChildViewAt(i)->GetID() == MenuItemView::kMenuItemViewID && | 66 if (GetChildViewAt(i)->id() == MenuItemView::kMenuItemViewID && |
67 count++ == index) { | 67 count++ == index) { |
68 return static_cast<MenuItemView*>(GetChildViewAt(i)); | 68 return static_cast<MenuItemView*>(GetChildViewAt(i)); |
69 } | 69 } |
70 } | 70 } |
71 NOTREACHED(); | 71 NOTREACHED(); |
72 return NULL; | 72 return NULL; |
73 } | 73 } |
74 | 74 |
75 void SubmenuView::Layout() { | 75 void SubmenuView::Layout() { |
76 // We're in a ScrollView, and need to set our width/height ourselves. | 76 // We're in a ScrollView, and need to set our width/height ourselves. |
77 if (!parent()) | 77 if (!parent()) |
78 return; | 78 return; |
79 | 79 |
80 // Use our current y, unless it means part of the menu isn't visible anymore. | 80 // Use our current y, unless it means part of the menu isn't visible anymore. |
81 int pref_height = GetPreferredSize().height(); | 81 int pref_height = GetPreferredSize().height(); |
82 int new_y; | 82 int new_y; |
83 if (pref_height > parent()->height()) | 83 if (pref_height > parent()->height()) |
84 new_y = std::max(parent()->height() - pref_height, y()); | 84 new_y = std::max(parent()->height() - pref_height, y()); |
85 else | 85 else |
86 new_y = 0; | 86 new_y = 0; |
87 SetBounds(x(), new_y, parent()->width(), pref_height); | 87 SetBounds(x(), new_y, parent()->width(), pref_height); |
88 | 88 |
89 gfx::Insets insets = GetInsets(); | 89 gfx::Insets insets = GetInsets(); |
90 int x = insets.left(); | 90 int x = insets.left(); |
91 int y = insets.top(); | 91 int y = insets.top(); |
92 int menu_item_width = width() - insets.width(); | 92 int menu_item_width = width() - insets.width(); |
93 for (int i = 0; i < child_count(); ++i) { | 93 for (int i = 0; i < child_count(); ++i) { |
94 View* child = GetChildViewAt(i); | 94 View* child = GetChildViewAt(i); |
95 if (child->IsVisible()) { | 95 if (child->visible()) { |
96 gfx::Size child_pref_size = child->GetPreferredSize(); | 96 gfx::Size child_pref_size = child->GetPreferredSize(); |
97 child->SetBounds(x, y, menu_item_width, child_pref_size.height()); | 97 child->SetBounds(x, y, menu_item_width, child_pref_size.height()); |
98 y += child_pref_size.height(); | 98 y += child_pref_size.height(); |
99 } | 99 } |
100 } | 100 } |
101 } | 101 } |
102 | 102 |
103 gfx::Size SubmenuView::GetPreferredSize() { | 103 gfx::Size SubmenuView::GetPreferredSize() { |
104 if (!has_children()) | 104 if (!has_children()) |
105 return gfx::Size(); | 105 return gfx::Size(); |
106 | 106 |
107 max_accelerator_width_ = 0; | 107 max_accelerator_width_ = 0; |
108 int max_width = 0; | 108 int max_width = 0; |
109 int height = 0; | 109 int height = 0; |
110 for (int i = 0; i < child_count(); ++i) { | 110 for (int i = 0; i < child_count(); ++i) { |
111 View* child = GetChildViewAt(i); | 111 View* child = GetChildViewAt(i); |
112 gfx::Size child_pref_size = child->IsVisible() ? | 112 gfx::Size child_pref_size = child->visible() ? |
113 child->GetPreferredSize() : gfx::Size(); | 113 child->GetPreferredSize() : gfx::Size(); |
114 max_width = std::max(max_width, child_pref_size.width()); | 114 max_width = std::max(max_width, child_pref_size.width()); |
115 height += child_pref_size.height(); | 115 height += child_pref_size.height(); |
116 if (child->GetID() == MenuItemView::kMenuItemViewID) { | 116 if (child->id() == MenuItemView::kMenuItemViewID) { |
117 MenuItemView* menu = static_cast<MenuItemView*>(child); | 117 MenuItemView* menu = static_cast<MenuItemView*>(child); |
118 max_accelerator_width_ = | 118 max_accelerator_width_ = |
119 std::max(max_accelerator_width_, menu->GetAcceleratorTextWidth()); | 119 std::max(max_accelerator_width_, menu->GetAcceleratorTextWidth()); |
120 } | 120 } |
121 } | 121 } |
122 if (max_accelerator_width_ > 0) { | 122 if (max_accelerator_width_ > 0) { |
123 max_accelerator_width_ += | 123 max_accelerator_width_ += |
124 MenuConfig::instance().label_to_accelerator_padding; | 124 MenuConfig::instance().label_to_accelerator_padding; |
125 } | 125 } |
126 gfx::Insets insets = GetInsets(); | 126 gfx::Insets insets = GetInsets(); |
(...skipping 248 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
375 item_bounds.set_height(kDropIndicatorHeight); | 375 item_bounds.set_height(kDropIndicatorHeight); |
376 return item_bounds; | 376 return item_bounds; |
377 | 377 |
378 default: | 378 default: |
379 // Don't render anything for on. | 379 // Don't render anything for on. |
380 return gfx::Rect(); | 380 return gfx::Rect(); |
381 } | 381 } |
382 } | 382 } |
383 | 383 |
384 } // namespace views | 384 } // namespace views |
OLD | NEW |