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 "app/menus/simple_menu_model.h" | 5 #include "app/menus/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 static const int kSeparatorId = -1; | 10 static const int kSeparatorId = -1; |
11 | 11 |
12 namespace menus { | 12 namespace menus { |
13 | 13 |
14 struct SimpleMenuModel::Item { | 14 struct SimpleMenuModel::Item { |
15 int command_id; | 15 int command_id; |
16 string16 label; | 16 string16 label; |
17 SkBitmap icon; | 17 SkBitmap icon; |
18 ItemType type; | 18 ItemType type; |
19 int group_id; | 19 int group_id; |
20 MenuModel* submenu; | 20 MenuModel* submenu; |
21 ButtonMenuItemModel* button_model; | 21 ButtonMenuItemModel* button_model; |
22 }; | 22 }; |
23 | 23 |
24 //////////////////////////////////////////////////////////////////////////////// | 24 //////////////////////////////////////////////////////////////////////////////// |
25 // SimpleMenuModel::Delegate, public: | 25 // SimpleMenuModel::Delegate, public: |
26 | 26 |
| 27 bool SimpleMenuModel::Delegate::IsCommandIdVisible(int command_id) const { |
| 28 return true; |
| 29 } |
| 30 |
27 bool SimpleMenuModel::Delegate::IsLabelForCommandIdDynamic( | 31 bool SimpleMenuModel::Delegate::IsLabelForCommandIdDynamic( |
28 int command_id) const { | 32 int command_id) const { |
29 return false; | 33 return false; |
30 } | 34 } |
31 | 35 |
32 string16 SimpleMenuModel::Delegate::GetLabelForCommandId(int command_id) const { | 36 string16 SimpleMenuModel::Delegate::GetLabelForCommandId(int command_id) const { |
33 return string16(); | 37 return string16(); |
34 } | 38 } |
35 | 39 |
36 void SimpleMenuModel::Delegate::CommandIdHighlighted(int command_id) { | 40 void SimpleMenuModel::Delegate::CommandIdHighlighted(int command_id) { |
(...skipping 206 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
243 } | 247 } |
244 | 248 |
245 bool SimpleMenuModel::IsEnabledAt(int index) const { | 249 bool SimpleMenuModel::IsEnabledAt(int index) const { |
246 int command_id = GetCommandIdAt(index); | 250 int command_id = GetCommandIdAt(index); |
247 if (!delegate_ || command_id == kSeparatorId || | 251 if (!delegate_ || command_id == kSeparatorId || |
248 items_.at(FlipIndex(index)).button_model) | 252 items_.at(FlipIndex(index)).button_model) |
249 return true; | 253 return true; |
250 return delegate_->IsCommandIdEnabled(command_id); | 254 return delegate_->IsCommandIdEnabled(command_id); |
251 } | 255 } |
252 | 256 |
| 257 bool SimpleMenuModel::IsVisibleAt(int index) const { |
| 258 int command_id = GetCommandIdAt(index); |
| 259 if (!delegate_ || command_id == kSeparatorId || |
| 260 items_.at(FlipIndex(index)).button_model) |
| 261 return true; |
| 262 return delegate_->IsCommandIdVisible(command_id); |
| 263 } |
| 264 |
253 void SimpleMenuModel::HighlightChangedTo(int index) { | 265 void SimpleMenuModel::HighlightChangedTo(int index) { |
254 if (delegate_) | 266 if (delegate_) |
255 delegate_->CommandIdHighlighted(GetCommandIdAt(index)); | 267 delegate_->CommandIdHighlighted(GetCommandIdAt(index)); |
256 } | 268 } |
257 | 269 |
258 void SimpleMenuModel::ActivatedAt(int index) { | 270 void SimpleMenuModel::ActivatedAt(int index) { |
259 if (delegate_) | 271 if (delegate_) |
260 delegate_->ExecuteCommand(GetCommandIdAt(index)); | 272 delegate_->ExecuteCommand(GetCommandIdAt(index)); |
261 } | 273 } |
262 | 274 |
263 MenuModel* SimpleMenuModel::GetSubmenuModelAt(int index) const { | 275 MenuModel* SimpleMenuModel::GetSubmenuModelAt(int index) const { |
264 return items_.at(FlipIndex(index)).submenu; | 276 return items_.at(FlipIndex(index)).submenu; |
265 } | 277 } |
266 | 278 |
| 279 int SimpleMenuModel::FlipIndex(int index) const { |
| 280 return index; |
| 281 } |
| 282 |
267 //////////////////////////////////////////////////////////////////////////////// | 283 //////////////////////////////////////////////////////////////////////////////// |
268 // SimpleMenuModel, Private: | 284 // SimpleMenuModel, Private: |
269 | 285 |
270 void SimpleMenuModel::AppendItem(const Item& item) { | 286 void SimpleMenuModel::AppendItem(const Item& item) { |
271 ValidateItem(item); | 287 ValidateItem(item); |
272 items_.push_back(item); | 288 items_.push_back(item); |
273 } | 289 } |
274 | 290 |
275 void SimpleMenuModel::InsertItemAtIndex(const Item& item, int index) { | 291 void SimpleMenuModel::InsertItemAtIndex(const Item& item, int index) { |
276 ValidateItem(item); | 292 ValidateItem(item); |
277 items_.insert(items_.begin() + FlipIndex(index), item); | 293 items_.insert(items_.begin() + FlipIndex(index), item); |
278 } | 294 } |
279 | 295 |
280 void SimpleMenuModel::ValidateItem(const Item& item) { | 296 void SimpleMenuModel::ValidateItem(const Item& item) { |
281 #ifndef NDEBUG | 297 #ifndef NDEBUG |
282 if (item.type == TYPE_SEPARATOR) { | 298 if (item.type == TYPE_SEPARATOR) { |
283 DCHECK_EQ(item.command_id, kSeparatorId); | 299 DCHECK_EQ(item.command_id, kSeparatorId); |
284 } else { | 300 } else { |
285 DCHECK_GE(item.command_id, 0); | 301 DCHECK_GE(item.command_id, 0); |
286 } | 302 } |
287 #endif // NDEBUG | 303 #endif // NDEBUG |
288 } | 304 } |
289 | 305 |
290 } // namespace menus | 306 } // namespace menus |
OLD | NEW |