OLD | NEW |
(Empty) | |
| 1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. Use of this |
| 2 // source code is governed by a BSD-style license that can be found in the |
| 3 // LICENSE file. |
| 4 |
| 5 #include "views/controls/menu/menu_2.h" |
| 6 |
| 7 #include "base/compiler_specific.h" |
| 8 #include "views/controls/menu/menu_wrapper.h" |
| 9 |
| 10 namespace views { |
| 11 |
| 12 //////////////////////////////////////////////////////////////////////////////// |
| 13 // Menu2Model, public: |
| 14 |
| 15 // static |
| 16 bool Menu2Model::GetModelAndIndexForCommandId(int command_id, |
| 17 Menu2Model** model, int* index) { |
| 18 int item_count = (*model)->GetItemCount(); |
| 19 for (int i = 0; i < item_count; ++i) { |
| 20 if ((*model)->GetTypeAt(i) == TYPE_SUBMENU) { |
| 21 Menu2Model* submenu_model = (*model)->GetSubmenuModelAt(i); |
| 22 if (GetModelAndIndexForCommandId(command_id, &submenu_model, index)) { |
| 23 *model = submenu_model; |
| 24 return true; |
| 25 } |
| 26 } |
| 27 if ((*model)->GetCommandIdAt(i) == command_id) { |
| 28 *index = i; |
| 29 return true; |
| 30 } |
| 31 } |
| 32 return false; |
| 33 } |
| 34 |
| 35 //////////////////////////////////////////////////////////////////////////////// |
| 36 // Menu2, public: |
| 37 |
| 38 Menu2::Menu2(Menu2Model* model, Menu2Delegate* delegate) |
| 39 : model_(model), |
| 40 delegate_(delegate), |
| 41 ALLOW_THIS_IN_INITIALIZER_LIST( |
| 42 wrapper_(MenuWrapper::CreateWrapper(this))) { |
| 43 Rebuild(); |
| 44 } |
| 45 |
| 46 gfx::NativeMenu Menu2::GetNativeMenu() const { |
| 47 return wrapper_->GetNativeMenu(); |
| 48 } |
| 49 |
| 50 void Menu2::RunMenuAt(const gfx::Point& point, Alignment alignment) { |
| 51 wrapper_->RunMenuAt(point, alignment); |
| 52 } |
| 53 |
| 54 void Menu2::Rebuild() { |
| 55 wrapper_->Rebuild(); |
| 56 } |
| 57 |
| 58 void Menu2::UpdateStates() { |
| 59 wrapper_->UpdateStates(); |
| 60 } |
| 61 |
| 62 } // namespace |
OLD | NEW |