OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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> | 7 #include <algorithm> |
8 | 8 |
9 #include "base/compiler_specific.h" | 9 #include "base/compiler_specific.h" |
10 #include "ui/accessibility/ax_view_state.h" | 10 #include "ui/accessibility/ax_view_state.h" |
(...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
114 for (int i = 0; i < child_count(); ++i) { | 114 for (int i = 0; i < child_count(); ++i) { |
115 View* child = child_at(i); | 115 View* child = child_at(i); |
116 if (child->visible()) { | 116 if (child->visible()) { |
117 gfx::Size child_pref_size = child->GetPreferredSize(); | 117 gfx::Size child_pref_size = child->GetPreferredSize(); |
118 child->SetBounds(x, y, menu_item_width, child_pref_size.height()); | 118 child->SetBounds(x, y, menu_item_width, child_pref_size.height()); |
119 y += child_pref_size.height(); | 119 y += child_pref_size.height(); |
120 } | 120 } |
121 } | 121 } |
122 } | 122 } |
123 | 123 |
124 gfx::Size SubmenuView::GetPreferredSize() { | 124 gfx::Size SubmenuView::GetPreferredSize() const { |
125 if (!has_children()) | 125 if (!has_children()) |
126 return gfx::Size(); | 126 return gfx::Size(); |
127 | 127 |
128 max_minor_text_width_ = 0; | 128 max_minor_text_width_ = 0; |
129 // The maximum width of items which contain maybe a label and multiple views. | 129 // The maximum width of items which contain maybe a label and multiple views. |
130 int max_complex_width = 0; | 130 int max_complex_width = 0; |
131 // The max. width of items which contain a label and maybe an accelerator. | 131 // The max. width of items which contain a label and maybe an accelerator. |
132 int max_simple_width = 0; | 132 int max_simple_width = 0; |
133 int height = 0; | 133 int height = 0; |
134 for (int i = 0; i < child_count(); ++i) { | 134 for (int i = 0; i < child_count(); ++i) { |
135 View* child = child_at(i); | 135 const View* child = child_at(i); |
136 if (!child->visible()) | 136 if (!child->visible()) |
137 continue; | 137 continue; |
138 if (child->id() == MenuItemView::kMenuItemViewID) { | 138 if (child->id() == MenuItemView::kMenuItemViewID) { |
139 MenuItemView* menu = static_cast<MenuItemView*>(child); | 139 const MenuItemView* menu = static_cast<const MenuItemView*>(child); |
140 const MenuItemView::MenuItemDimensions& dimensions = | 140 const MenuItemView::MenuItemDimensions& dimensions = |
141 menu->GetDimensions(); | 141 menu->GetDimensions(); |
142 max_simple_width = std::max( | 142 max_simple_width = std::max( |
143 max_simple_width, dimensions.standard_width); | 143 max_simple_width, dimensions.standard_width); |
144 max_minor_text_width_ = | 144 max_minor_text_width_ = |
145 std::max(max_minor_text_width_, dimensions.minor_text_width); | 145 std::max(max_minor_text_width_, dimensions.minor_text_width); |
146 max_complex_width = std::max(max_complex_width, | 146 max_complex_width = std::max(max_complex_width, |
147 dimensions.standard_width + dimensions.children_width); | 147 dimensions.standard_width + dimensions.children_width); |
148 height += dimensions.height; | 148 height += dimensions.height; |
149 } else { | 149 } else { |
(...skipping 342 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
492 y = std::max(y, 0); | 492 y = std::max(y, 0); |
493 gfx::Rect new_vis_bounds(x, y, vis_bounds.width(), vis_bounds.height()); | 493 gfx::Rect new_vis_bounds(x, y, vis_bounds.width(), vis_bounds.height()); |
494 if (new_vis_bounds != vis_bounds) { | 494 if (new_vis_bounds != vis_bounds) { |
495 ScrollRectToVisible(new_vis_bounds); | 495 ScrollRectToVisible(new_vis_bounds); |
496 return true; | 496 return true; |
497 } | 497 } |
498 return false; | 498 return false; |
499 } | 499 } |
500 | 500 |
501 } // namespace views | 501 } // namespace views |
OLD | NEW |