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/menu_item_view.h" | 5 #include "ui/views/controls/menu/menu_item_view.h" |
6 | 6 |
7 #include "base/i18n/case_conversion.h" | 7 #include "base/i18n/case_conversion.h" |
8 #include "base/stl_util.h" | 8 #include "base/stl_util.h" |
9 #include "base/strings/utf_string_conversions.h" | 9 #include "base/strings/utf_string_conversions.h" |
10 #include "ui/accessibility/ax_view_state.h" | 10 #include "ui/accessibility/ax_view_state.h" |
(...skipping 392 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
403 void MenuItemView::OnPaint(gfx::Canvas* canvas) { | 403 void MenuItemView::OnPaint(gfx::Canvas* canvas) { |
404 PaintButton(canvas, PB_NORMAL); | 404 PaintButton(canvas, PB_NORMAL); |
405 } | 405 } |
406 | 406 |
407 gfx::Size MenuItemView::GetPreferredSize() const { | 407 gfx::Size MenuItemView::GetPreferredSize() const { |
408 const MenuItemDimensions& dimensions(GetDimensions()); | 408 const MenuItemDimensions& dimensions(GetDimensions()); |
409 return gfx::Size(dimensions.standard_width + dimensions.children_width, | 409 return gfx::Size(dimensions.standard_width + dimensions.children_width, |
410 dimensions.height); | 410 dimensions.height); |
411 } | 411 } |
412 | 412 |
413 int MenuItemView::GetHeightForWidth(int width) const { | |
414 int height = 0; | |
415 // If this is a container, check the child view. Otherwise, we use the | |
416 // default menu height for everything but the icon. | |
417 if (!IsContainer()) | |
sky
2014/09/12 20:09:37
If !container, can't you just use GetPreferredSize
Devlin
2014/09/12 22:41:37
As long as we don't mind being inconsistent for ic
| |
418 height = icon_view_ ? icon_view_->GetHeightForWidth(width) : 0; | |
sky
2014/09/12 20:09:37
nit: spacing.
Devlin
2014/09/12 22:41:37
moot (line gone).
| |
419 else | |
420 height = child_at(0)->GetHeightForWidth(width); | |
421 | |
422 if (!icon_view_ && GetRootMenuItem()->has_icons()) | |
423 height = std::max(height, GetMenuConfig().check_height); | |
424 height += GetBottomMargin() + GetTopMargin(); | |
425 | |
426 // There's a chance our dimensions changed as a result of this. If so, | |
427 // invalidate them so they get recalculated as needed. | |
428 if (is_dimensions_valid() && height != GetDimensions().height) | |
sky
2014/09/12 20:09:37
I don't understand the need for this. Can you elab
Devlin
2014/09/12 22:41:37
But the Dimensions are used in GetPreferredSize(),
sky
2014/09/15 15:29:54
Why does that matter though? GetPreferredSize and
Devlin
2014/09/15 15:39:20
In SubmenuView::GetPreferredSize(), we loop over t
| |
429 invalidate_dimensions(); | |
430 | |
431 return height; | |
432 } | |
433 | |
413 const MenuItemView::MenuItemDimensions& MenuItemView::GetDimensions() const { | 434 const MenuItemView::MenuItemDimensions& MenuItemView::GetDimensions() const { |
414 if (!is_dimensions_valid()) | 435 if (!is_dimensions_valid()) |
415 dimensions_ = CalculateDimensions(); | 436 dimensions_ = CalculateDimensions(); |
416 DCHECK(is_dimensions_valid()); | 437 DCHECK(is_dimensions_valid()); |
417 return dimensions_; | 438 return dimensions_; |
418 } | 439 } |
419 | 440 |
420 MenuController* MenuItemView::GetMenuController() { | 441 MenuController* MenuItemView::GetMenuController() { |
421 return GetRootMenuItem()->controller_; | 442 return GetRootMenuItem()->controller_; |
422 } | 443 } |
(...skipping 641 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1064 } else { | 1085 } else { |
1065 const Type& type = menu_item->GetType(); | 1086 const Type& type = menu_item->GetType(); |
1066 if (type == CHECKBOX || type == RADIO) | 1087 if (type == CHECKBOX || type == RADIO) |
1067 return true; | 1088 return true; |
1068 } | 1089 } |
1069 } | 1090 } |
1070 return false; | 1091 return false; |
1071 } | 1092 } |
1072 | 1093 |
1073 } // namespace views | 1094 } // namespace views |
OLD | NEW |