OLD | NEW |
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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 "gfx/canvas.h" | 7 #include "gfx/canvas.h" |
| 8 #include "views/controls/menu/menu_config.h" |
8 #include "views/controls/menu/menu_controller.h" | 9 #include "views/controls/menu/menu_controller.h" |
9 #include "views/controls/menu/menu_host.h" | 10 #include "views/controls/menu/menu_host.h" |
10 #include "views/controls/menu/menu_scroll_view_container.h" | 11 #include "views/controls/menu/menu_scroll_view_container.h" |
11 #include "views/widget/root_view.h" | 12 #include "views/widget/root_view.h" |
12 | 13 |
13 // Height of the drop indicator. This should be an even number. | 14 // Height of the drop indicator. This should be an even number. |
14 static const int kDropIndicatorHeight = 2; | 15 static const int kDropIndicatorHeight = 2; |
15 | 16 |
16 // Color of the drop indicator. | 17 // Color of the drop indicator. |
17 static const SkColor kDropIndicatorColor = SK_ColorBLACK; | 18 static const SkColor kDropIndicatorColor = SK_ColorBLACK; |
18 | 19 |
19 namespace views { | 20 namespace views { |
20 | 21 |
21 // static | 22 // static |
22 const int SubmenuView::kSubmenuBorderSize = 3; | 23 const int SubmenuView::kSubmenuBorderSize = 3; |
23 | 24 |
24 SubmenuView::SubmenuView(MenuItemView* parent) | 25 SubmenuView::SubmenuView(MenuItemView* parent) |
25 : parent_menu_item_(parent), | 26 : parent_menu_item_(parent), |
26 host_(NULL), | 27 host_(NULL), |
27 drop_item_(NULL), | 28 drop_item_(NULL), |
28 drop_position_(MenuDelegate::DROP_NONE), | 29 drop_position_(MenuDelegate::DROP_NONE), |
29 scroll_view_container_(NULL) { | 30 scroll_view_container_(NULL), |
| 31 max_accelerator_width_(0) { |
30 DCHECK(parent); | 32 DCHECK(parent); |
31 // We'll delete ourselves, otherwise the ScrollView would delete us on close. | 33 // We'll delete ourselves, otherwise the ScrollView would delete us on close. |
32 set_parent_owned(false); | 34 set_parent_owned(false); |
33 } | 35 } |
34 | 36 |
35 SubmenuView::~SubmenuView() { | 37 SubmenuView::~SubmenuView() { |
36 // The menu may not have been closed yet (it will be hidden, but not | 38 // The menu may not have been closed yet (it will be hidden, but not |
37 // necessarily closed). | 39 // necessarily closed). |
38 Close(); | 40 Close(); |
39 | 41 |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
84 gfx::Size child_pref_size = child->GetPreferredSize(); | 86 gfx::Size child_pref_size = child->GetPreferredSize(); |
85 child->SetBounds(x, y, menu_item_width, child_pref_size.height()); | 87 child->SetBounds(x, y, menu_item_width, child_pref_size.height()); |
86 y += child_pref_size.height(); | 88 y += child_pref_size.height(); |
87 } | 89 } |
88 } | 90 } |
89 | 91 |
90 gfx::Size SubmenuView::GetPreferredSize() { | 92 gfx::Size SubmenuView::GetPreferredSize() { |
91 if (GetChildViewCount() == 0) | 93 if (GetChildViewCount() == 0) |
92 return gfx::Size(); | 94 return gfx::Size(); |
93 | 95 |
| 96 max_accelerator_width_ = 0; |
94 int max_width = 0; | 97 int max_width = 0; |
95 int height = 0; | 98 int height = 0; |
96 for (int i = 0; i < GetChildViewCount(); ++i) { | 99 for (int i = 0; i < GetChildViewCount(); ++i) { |
97 View* child = GetChildViewAt(i); | 100 View* child = GetChildViewAt(i); |
98 gfx::Size child_pref_size = child->GetPreferredSize(); | 101 gfx::Size child_pref_size = child->GetPreferredSize(); |
99 max_width = std::max(max_width, child_pref_size.width()); | 102 max_width = std::max(max_width, child_pref_size.width()); |
100 height += child_pref_size.height(); | 103 height += child_pref_size.height(); |
| 104 if (child->GetID() == MenuItemView::kMenuItemViewID) { |
| 105 MenuItemView* menu = static_cast<MenuItemView*>(child); |
| 106 max_accelerator_width_ = |
| 107 std::max(max_accelerator_width_, menu->GetAcceleratorTextWidth()); |
| 108 } |
| 109 } |
| 110 if (max_accelerator_width_ > 0) { |
| 111 max_accelerator_width_ += |
| 112 MenuConfig::instance().label_to_accelerator_padding; |
101 } | 113 } |
102 gfx::Insets insets = GetInsets(); | 114 gfx::Insets insets = GetInsets(); |
103 return gfx::Size(max_width + insets.width(), height + insets.height()); | 115 return gfx::Size(max_width + max_accelerator_width_ + insets.width(), |
| 116 height + insets.height()); |
104 } | 117 } |
105 | 118 |
106 void SubmenuView::DidChangeBounds(const gfx::Rect& previous, | 119 void SubmenuView::DidChangeBounds(const gfx::Rect& previous, |
107 const gfx::Rect& current) { | 120 const gfx::Rect& current) { |
108 SchedulePaint(); | 121 SchedulePaint(); |
109 } | 122 } |
110 | 123 |
111 void SubmenuView::PaintChildren(gfx::Canvas* canvas) { | 124 void SubmenuView::PaintChildren(gfx::Canvas* canvas) { |
112 View::PaintChildren(canvas); | 125 View::PaintChildren(canvas); |
113 | 126 |
(...skipping 211 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
325 item_bounds.set_height(kDropIndicatorHeight); | 338 item_bounds.set_height(kDropIndicatorHeight); |
326 return item_bounds; | 339 return item_bounds; |
327 | 340 |
328 default: | 341 default: |
329 // Don't render anything for on. | 342 // Don't render anything for on. |
330 return gfx::Rect(); | 343 return gfx::Rect(); |
331 } | 344 } |
332 } | 345 } |
333 | 346 |
334 } // namespace views | 347 } // namespace views |
OLD | NEW |