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/menu_item_view.h" | 5 #include "views/controls/menu/menu_item_view.h" |
6 | 6 |
7 #include "app/l10n_util.h" | 7 #include "app/l10n_util.h" |
8 #include "gfx/canvas.h" | 8 #include "gfx/canvas.h" |
9 #include "grit/app_strings.h" | 9 #include "grit/app_strings.h" |
10 #include "views/controls/menu/menu_config.h" | 10 #include "views/controls/menu/menu_config.h" |
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
91 bool has_mnemonics) { | 91 bool has_mnemonics) { |
92 PrepareForRun(has_mnemonics); | 92 PrepareForRun(has_mnemonics); |
93 | 93 |
94 int mouse_event_flags; | 94 int mouse_event_flags; |
95 | 95 |
96 MenuController* controller = MenuController::GetActiveInstance(); | 96 MenuController* controller = MenuController::GetActiveInstance(); |
97 if (controller && !controller->IsBlockingRun()) { | 97 if (controller && !controller->IsBlockingRun()) { |
98 // A menu is already showing, but it isn't a blocking menu. Cancel it. | 98 // A menu is already showing, but it isn't a blocking menu. Cancel it. |
99 // We can get here during drag and drop if the user right clicks on the | 99 // We can get here during drag and drop if the user right clicks on the |
100 // menu quickly after the drop. | 100 // menu quickly after the drop. |
101 controller->Cancel(true); | 101 controller->Cancel(MenuController::EXIT_ALL); |
102 controller = NULL; | 102 controller = NULL; |
103 } | 103 } |
104 bool owns_controller = false; | 104 bool owns_controller = false; |
105 if (!controller) { | 105 if (!controller) { |
106 // No menus are showing, show one. | 106 // No menus are showing, show one. |
107 controller = new MenuController(true); | 107 controller = new MenuController(true); |
108 MenuController::SetActiveInstance(controller); | 108 MenuController::SetActiveInstance(controller); |
109 owns_controller = true; | 109 owns_controller = true; |
110 } else { | 110 } else { |
111 // A menu is already showing, use the same controller. | 111 // A menu is already showing, use the same controller. |
(...skipping 26 matching lines...) Expand all Loading... |
138 } | 138 } |
139 | 139 |
140 void MenuItemView::RunMenuForDropAt(gfx::NativeWindow parent, | 140 void MenuItemView::RunMenuForDropAt(gfx::NativeWindow parent, |
141 const gfx::Rect& bounds, | 141 const gfx::Rect& bounds, |
142 AnchorPosition anchor) { | 142 AnchorPosition anchor) { |
143 PrepareForRun(false); | 143 PrepareForRun(false); |
144 | 144 |
145 // If there is a menu, hide it so that only one menu is shown during dnd. | 145 // If there is a menu, hide it so that only one menu is shown during dnd. |
146 MenuController* current_controller = MenuController::GetActiveInstance(); | 146 MenuController* current_controller = MenuController::GetActiveInstance(); |
147 if (current_controller) { | 147 if (current_controller) { |
148 current_controller->Cancel(true); | 148 current_controller->Cancel(MenuController::EXIT_ALL); |
149 } | 149 } |
150 | 150 |
151 // Always create a new controller for non-blocking. | 151 // Always create a new controller for non-blocking. |
152 controller_ = new MenuController(false); | 152 controller_ = new MenuController(false); |
153 | 153 |
154 // Set the instance, that way it can be canceled by another menu. | 154 // Set the instance, that way it can be canceled by another menu. |
155 MenuController::SetActiveInstance(controller_); | 155 MenuController::SetActiveInstance(controller_); |
156 | 156 |
157 controller_->Run(parent, NULL, this, bounds, anchor, NULL); | 157 controller_->Run(parent, NULL, this, bounds, anchor, NULL); |
158 } | 158 } |
159 | 159 |
160 void MenuItemView::Cancel() { | 160 void MenuItemView::Cancel() { |
161 if (controller_ && !canceled_) { | 161 if (controller_ && !canceled_) { |
162 canceled_ = true; | 162 canceled_ = true; |
163 controller_->Cancel(true); | 163 controller_->Cancel(MenuController::EXIT_ALL); |
164 } | 164 } |
165 } | 165 } |
166 | 166 |
167 SubmenuView* MenuItemView::CreateSubmenu() { | 167 SubmenuView* MenuItemView::CreateSubmenu() { |
168 if (!submenu_) | 168 if (!submenu_) |
169 submenu_ = new SubmenuView(this); | 169 submenu_ = new SubmenuView(this); |
170 return submenu_; | 170 return submenu_; |
171 } | 171 } |
172 | 172 |
173 void MenuItemView::SetSelected(bool selected) { | 173 void MenuItemView::SetSelected(bool selected) { |
(...skipping 280 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
454 } | 454 } |
455 | 455 |
456 int MenuItemView::GetBottomMargin() { | 456 int MenuItemView::GetBottomMargin() { |
457 MenuItemView* root = GetRootMenuItem(); | 457 MenuItemView* root = GetRootMenuItem(); |
458 return root && root->has_icons_ | 458 return root && root->has_icons_ |
459 ? MenuConfig::instance().item_bottom_margin : | 459 ? MenuConfig::instance().item_bottom_margin : |
460 MenuConfig::instance().item_no_icon_bottom_margin; | 460 MenuConfig::instance().item_no_icon_bottom_margin; |
461 } | 461 } |
462 | 462 |
463 } // namespace views | 463 } // namespace views |
OLD | NEW |