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

Side by Side Diff: ui/views/controls/menu/submenu_view.cc

Issue 553233002: Dynamically calculate the number of extension icons to show per row in overflow (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Test fix Created 6 years, 3 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
« no previous file with comments | « ui/views/controls/menu/menu_item_view.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 96 matching lines...) Expand 10 before | Expand all | Expand 10 after
107 new_y = 0; 107 new_y = 0;
108 SetBounds(x(), new_y, parent()->width(), pref_height); 108 SetBounds(x(), new_y, parent()->width(), pref_height);
109 109
110 gfx::Insets insets = GetInsets(); 110 gfx::Insets insets = GetInsets();
111 int x = insets.left(); 111 int x = insets.left();
112 int y = insets.top(); 112 int y = insets.top();
113 int menu_item_width = width() - insets.width(); 113 int menu_item_width = width() - insets.width();
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();
sky 2014/09/15 16:21:24 Is this the bug you're working around? Now that we
Devlin 2014/09/15 16:57:55 Yeah, if we change this to GetHeightForWidth(), it
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() const { 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
134 // We perform the size calculation in two passes. In the first pass, we
135 // calculate the width of the menu. In the second, we calculate the height
136 // using that width. This allows views that have flexible widths to adjust
137 // accordingly.
134 for (int i = 0; i < child_count(); ++i) { 138 for (int i = 0; i < child_count(); ++i) {
135 const View* child = child_at(i); 139 const View* child = child_at(i);
136 if (!child->visible()) 140 if (!child->visible())
137 continue; 141 continue;
138 if (child->id() == MenuItemView::kMenuItemViewID) { 142 if (child->id() == MenuItemView::kMenuItemViewID) {
139 const MenuItemView* menu = static_cast<const MenuItemView*>(child); 143 const MenuItemView* menu = static_cast<const MenuItemView*>(child);
140 const MenuItemView::MenuItemDimensions& dimensions = 144 const MenuItemView::MenuItemDimensions& dimensions =
141 menu->GetDimensions(); 145 menu->GetDimensions();
142 max_simple_width = std::max( 146 max_simple_width = std::max(
143 max_simple_width, dimensions.standard_width); 147 max_simple_width, dimensions.standard_width);
144 max_minor_text_width_ = 148 max_minor_text_width_ =
145 std::max(max_minor_text_width_, dimensions.minor_text_width); 149 std::max(max_minor_text_width_, dimensions.minor_text_width);
146 max_complex_width = std::max(max_complex_width, 150 max_complex_width = std::max(max_complex_width,
147 dimensions.standard_width + dimensions.children_width); 151 dimensions.standard_width + dimensions.children_width);
148 height += dimensions.height;
149 } else { 152 } else {
150 gfx::Size child_pref_size = 153 max_complex_width = std::max(max_complex_width,
151 child->visible() ? child->GetPreferredSize() : gfx::Size(); 154 child->GetPreferredSize().width());
152 max_complex_width = std::max(max_complex_width, child_pref_size.width());
153 height += child_pref_size.height();
154 } 155 }
155 } 156 }
156 if (max_minor_text_width_ > 0) { 157 if (max_minor_text_width_ > 0) {
157 max_minor_text_width_ += 158 max_minor_text_width_ +=
158 GetMenuItem()->GetMenuConfig().label_to_minor_text_padding; 159 GetMenuItem()->GetMenuConfig().label_to_minor_text_padding;
159 } 160 }
161 // Finish calculating our optimum width.
160 gfx::Insets insets = GetInsets(); 162 gfx::Insets insets = GetInsets();
161 return gfx::Size( 163 int width = std::max(max_complex_width,
162 std::max(max_complex_width, 164 std::max(max_simple_width + max_minor_text_width_ +
163 std::max(max_simple_width + max_minor_text_width_ + 165 insets.width(),
164 insets.width(), 166 minimum_preferred_width_ - 2 * insets.width()));
165 minimum_preferred_width_ - 2 * insets.width())), 167
166 height + insets.height()); 168 // Then, the height for that width.
169 int height = 0;
170 for (int i = 0; i < child_count(); ++i) {
171 const View* child = child_at(i);
172 height += child->visible() ? child->GetHeightForWidth(width) : 0;
173 }
174
175 return gfx::Size(width, height + insets.height());
167 } 176 }
168 177
169 void SubmenuView::GetAccessibleState(ui::AXViewState* state) { 178 void SubmenuView::GetAccessibleState(ui::AXViewState* state) {
170 // Inherit most of the state from the parent menu item, except the role. 179 // Inherit most of the state from the parent menu item, except the role.
171 if (GetMenuItem()) 180 if (GetMenuItem())
172 GetMenuItem()->GetAccessibleState(state); 181 GetMenuItem()->GetAccessibleState(state);
173 state->role = ui::AX_ROLE_MENU_LIST_POPUP; 182 state->role = ui::AX_ROLE_MENU_LIST_POPUP;
174 } 183 }
175 184
176 ui::TextInputClient* SubmenuView::GetTextInputClient() { 185 ui::TextInputClient* SubmenuView::GetTextInputClient() {
(...skipping 315 matching lines...) Expand 10 before | Expand all | Expand 10 after
492 y = std::max(y, 0); 501 y = std::max(y, 0);
493 gfx::Rect new_vis_bounds(x, y, vis_bounds.width(), vis_bounds.height()); 502 gfx::Rect new_vis_bounds(x, y, vis_bounds.width(), vis_bounds.height());
494 if (new_vis_bounds != vis_bounds) { 503 if (new_vis_bounds != vis_bounds) {
495 ScrollRectToVisible(new_vis_bounds); 504 ScrollRectToVisible(new_vis_bounds);
496 return true; 505 return true;
497 } 506 }
498 return false; 507 return false;
499 } 508 }
500 509
501 } // namespace views 510 } // namespace views
OLDNEW
« no previous file with comments | « ui/views/controls/menu/menu_item_view.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698