OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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/base/models/simple_menu_model.h" | 5 #include "ui/base/models/simple_menu_model.h" |
6 | 6 |
7 #include "base/message_loop.h" | 7 #include "base/message_loop.h" |
8 #include "third_party/skia/include/core/SkBitmap.h" | 8 #include "third_party/skia/include/core/SkBitmap.h" |
9 #include "ui/base/l10n/l10n_util.h" | 9 #include "ui/base/l10n/l10n_util.h" |
10 | 10 |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
42 int command_id, SkBitmap* bitmap) const { | 42 int command_id, SkBitmap* bitmap) const { |
43 return false; | 43 return false; |
44 } | 44 } |
45 | 45 |
46 void SimpleMenuModel::Delegate::CommandIdHighlighted(int command_id) { | 46 void SimpleMenuModel::Delegate::CommandIdHighlighted(int command_id) { |
47 } | 47 } |
48 | 48 |
49 void SimpleMenuModel::Delegate::MenuClosed() { | 49 void SimpleMenuModel::Delegate::MenuClosed() { |
50 } | 50 } |
51 | 51 |
| 52 void SimpleMenuModel::Delegate::ExecuteCommandWithDisposition( |
| 53 int command_id, int disposition) { |
| 54 ExecuteCommand(command_id); |
| 55 } |
| 56 |
52 //////////////////////////////////////////////////////////////////////////////// | 57 //////////////////////////////////////////////////////////////////////////////// |
53 // SimpleMenuModel, public: | 58 // SimpleMenuModel, public: |
54 | 59 |
55 SimpleMenuModel::SimpleMenuModel(Delegate* delegate) | 60 SimpleMenuModel::SimpleMenuModel(Delegate* delegate) |
56 : delegate_(delegate), | 61 : delegate_(delegate), |
57 menu_model_delegate_(NULL), | 62 menu_model_delegate_(NULL), |
58 ALLOW_THIS_IN_INITIALIZER_LIST(method_factory_(this)) { | 63 ALLOW_THIS_IN_INITIALIZER_LIST(method_factory_(this)) { |
59 } | 64 } |
60 | 65 |
61 SimpleMenuModel::~SimpleMenuModel() { | 66 SimpleMenuModel::~SimpleMenuModel() { |
(...skipping 218 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
280 void SimpleMenuModel::HighlightChangedTo(int index) { | 285 void SimpleMenuModel::HighlightChangedTo(int index) { |
281 if (delegate_) | 286 if (delegate_) |
282 delegate_->CommandIdHighlighted(GetCommandIdAt(index)); | 287 delegate_->CommandIdHighlighted(GetCommandIdAt(index)); |
283 } | 288 } |
284 | 289 |
285 void SimpleMenuModel::ActivatedAt(int index) { | 290 void SimpleMenuModel::ActivatedAt(int index) { |
286 if (delegate_) | 291 if (delegate_) |
287 delegate_->ExecuteCommand(GetCommandIdAt(index)); | 292 delegate_->ExecuteCommand(GetCommandIdAt(index)); |
288 } | 293 } |
289 | 294 |
| 295 void SimpleMenuModel::ActivatedAtWithDisposition(int index, int disposition) { |
| 296 if (delegate_) |
| 297 delegate_->ExecuteCommandWithDisposition(GetCommandIdAt(index), |
| 298 disposition); |
| 299 } |
| 300 |
290 MenuModel* SimpleMenuModel::GetSubmenuModelAt(int index) const { | 301 MenuModel* SimpleMenuModel::GetSubmenuModelAt(int index) const { |
291 return items_.at(FlipIndex(index)).submenu; | 302 return items_.at(FlipIndex(index)).submenu; |
292 } | 303 } |
293 | 304 |
294 void SimpleMenuModel::MenuClosed() { | 305 void SimpleMenuModel::MenuClosed() { |
295 // Due to how menus work on the different platforms, ActivatedAt will be | 306 // Due to how menus work on the different platforms, ActivatedAt will be |
296 // called after this. It's more convenient for the delegate to be called | 307 // called after this. It's more convenient for the delegate to be called |
297 // afterwards though, so post a task. | 308 // afterwards though, so post a task. |
298 MessageLoop::current()->PostTask( | 309 MessageLoop::current()->PostTask( |
299 FROM_HERE, | 310 FROM_HERE, |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
331 #ifndef NDEBUG | 342 #ifndef NDEBUG |
332 if (item.type == TYPE_SEPARATOR) { | 343 if (item.type == TYPE_SEPARATOR) { |
333 DCHECK_EQ(item.command_id, kSeparatorId); | 344 DCHECK_EQ(item.command_id, kSeparatorId); |
334 } else { | 345 } else { |
335 DCHECK_GE(item.command_id, 0); | 346 DCHECK_GE(item.command_id, 0); |
336 } | 347 } |
337 #endif // NDEBUG | 348 #endif // NDEBUG |
338 } | 349 } |
339 | 350 |
340 } // namespace ui | 351 } // namespace ui |
OLD | NEW |