| 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 "app/l10n_util.h" | 7 #include "app/l10n_util.h" |
| 8 #include "third_party/skia/include/core/SkBitmap.h" | 8 #include "third_party/skia/include/core/SkBitmap.h" |
| 9 | 9 |
| 10 namespace ui { | 10 namespace ui { |
| (...skipping 27 matching lines...) Expand all Loading... |
| 38 } | 38 } |
| 39 | 39 |
| 40 bool SimpleMenuModel::Delegate::GetIconForCommandId( | 40 bool SimpleMenuModel::Delegate::GetIconForCommandId( |
| 41 int command_id, SkBitmap* bitmap) const { | 41 int command_id, SkBitmap* bitmap) const { |
| 42 return false; | 42 return false; |
| 43 } | 43 } |
| 44 | 44 |
| 45 void SimpleMenuModel::Delegate::CommandIdHighlighted(int command_id) { | 45 void SimpleMenuModel::Delegate::CommandIdHighlighted(int command_id) { |
| 46 } | 46 } |
| 47 | 47 |
| 48 void SimpleMenuModel::Delegate::MenuClosed() { |
| 49 } |
| 50 |
| 48 //////////////////////////////////////////////////////////////////////////////// | 51 //////////////////////////////////////////////////////////////////////////////// |
| 49 // SimpleMenuModel, public: | 52 // SimpleMenuModel, public: |
| 50 | 53 |
| 51 SimpleMenuModel::SimpleMenuModel(Delegate* delegate) : delegate_(delegate) { | 54 SimpleMenuModel::SimpleMenuModel(Delegate* delegate) : delegate_(delegate) { |
| 52 } | 55 } |
| 53 | 56 |
| 54 SimpleMenuModel::~SimpleMenuModel() { | 57 SimpleMenuModel::~SimpleMenuModel() { |
| 55 } | 58 } |
| 56 | 59 |
| 57 void SimpleMenuModel::AddItem(int command_id, const string16& label) { | 60 void SimpleMenuModel::AddItem(int command_id, const string16& label) { |
| (...skipping 219 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 277 | 280 |
| 278 void SimpleMenuModel::ActivatedAt(int index) { | 281 void SimpleMenuModel::ActivatedAt(int index) { |
| 279 if (delegate_) | 282 if (delegate_) |
| 280 delegate_->ExecuteCommand(GetCommandIdAt(index)); | 283 delegate_->ExecuteCommand(GetCommandIdAt(index)); |
| 281 } | 284 } |
| 282 | 285 |
| 283 MenuModel* SimpleMenuModel::GetSubmenuModelAt(int index) const { | 286 MenuModel* SimpleMenuModel::GetSubmenuModelAt(int index) const { |
| 284 return items_.at(FlipIndex(index)).submenu; | 287 return items_.at(FlipIndex(index)).submenu; |
| 285 } | 288 } |
| 286 | 289 |
| 290 void SimpleMenuModel::MenuClosed() { |
| 291 if (delegate_) |
| 292 delegate_->MenuClosed(); |
| 293 } |
| 294 |
| 287 int SimpleMenuModel::FlipIndex(int index) const { | 295 int SimpleMenuModel::FlipIndex(int index) const { |
| 288 return index; | 296 return index; |
| 289 } | 297 } |
| 290 | 298 |
| 291 //////////////////////////////////////////////////////////////////////////////// | 299 //////////////////////////////////////////////////////////////////////////////// |
| 292 // SimpleMenuModel, Private: | 300 // SimpleMenuModel, Private: |
| 293 | 301 |
| 294 void SimpleMenuModel::AppendItem(const Item& item) { | 302 void SimpleMenuModel::AppendItem(const Item& item) { |
| 295 ValidateItem(item); | 303 ValidateItem(item); |
| 296 items_.push_back(item); | 304 items_.push_back(item); |
| 297 } | 305 } |
| 298 | 306 |
| 299 void SimpleMenuModel::InsertItemAtIndex(const Item& item, int index) { | 307 void SimpleMenuModel::InsertItemAtIndex(const Item& item, int index) { |
| 300 ValidateItem(item); | 308 ValidateItem(item); |
| 301 items_.insert(items_.begin() + FlipIndex(index), item); | 309 items_.insert(items_.begin() + FlipIndex(index), item); |
| 302 } | 310 } |
| 303 | 311 |
| 304 void SimpleMenuModel::ValidateItem(const Item& item) { | 312 void SimpleMenuModel::ValidateItem(const Item& item) { |
| 305 #ifndef NDEBUG | 313 #ifndef NDEBUG |
| 306 if (item.type == TYPE_SEPARATOR) { | 314 if (item.type == TYPE_SEPARATOR) { |
| 307 DCHECK_EQ(item.command_id, kSeparatorId); | 315 DCHECK_EQ(item.command_id, kSeparatorId); |
| 308 } else { | 316 } else { |
| 309 DCHECK_GE(item.command_id, 0); | 317 DCHECK_GE(item.command_id, 0); |
| 310 } | 318 } |
| 311 #endif // NDEBUG | 319 #endif // NDEBUG |
| 312 } | 320 } |
| 313 | 321 |
| 314 } // namespace ui | 322 } // namespace ui |
| OLD | NEW |