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; |
(...skipping 221 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
232 int item_index = FlipIndex(index); | 232 int item_index = FlipIndex(index); |
233 MenuModel::ItemType item_type = items_[item_index].type; | 233 MenuModel::ItemType item_type = items_[item_index].type; |
234 return (item_type == TYPE_CHECK || item_type == TYPE_RADIO) ? | 234 return (item_type == TYPE_CHECK || item_type == TYPE_RADIO) ? |
235 delegate_->IsCommandIdChecked(GetCommandIdAt(index)) : false; | 235 delegate_->IsCommandIdChecked(GetCommandIdAt(index)) : false; |
236 } | 236 } |
237 | 237 |
238 int SimpleMenuModel::GetGroupIdAt(int index) const { | 238 int SimpleMenuModel::GetGroupIdAt(int index) const { |
239 return items_.at(FlipIndex(index)).group_id; | 239 return items_.at(FlipIndex(index)).group_id; |
240 } | 240 } |
241 | 241 |
242 bool SimpleMenuModel::GetIconAt(int index, SkBitmap* icon) const { | 242 bool SimpleMenuModel::GetIconAt(int index, SkBitmap* icon) { |
243 if (IsItemDynamicAt(index)) | 243 if (IsItemDynamicAt(index)) |
244 return delegate_->GetIconForCommandId(GetCommandIdAt(index), icon); | 244 return delegate_->GetIconForCommandId(GetCommandIdAt(index), icon); |
245 | 245 |
246 if (items_[index].icon.isNull()) | 246 if (items_[index].icon.isNull()) |
247 return false; | 247 return false; |
248 | 248 |
249 *icon = items_[index].icon; | 249 *icon = items_[index].icon; |
250 return true; | 250 return true; |
251 } | 251 } |
252 | 252 |
(...skipping 24 matching lines...) Expand all Loading... |
277 | 277 |
278 void SimpleMenuModel::ActivatedAt(int index) { | 278 void SimpleMenuModel::ActivatedAt(int index) { |
279 if (delegate_) | 279 if (delegate_) |
280 delegate_->ExecuteCommand(GetCommandIdAt(index)); | 280 delegate_->ExecuteCommand(GetCommandIdAt(index)); |
281 } | 281 } |
282 | 282 |
283 MenuModel* SimpleMenuModel::GetSubmenuModelAt(int index) const { | 283 MenuModel* SimpleMenuModel::GetSubmenuModelAt(int index) const { |
284 return items_.at(FlipIndex(index)).submenu; | 284 return items_.at(FlipIndex(index)).submenu; |
285 } | 285 } |
286 | 286 |
| 287 void SimpleMenuModel::SetDelegate(menus::MenuModel::Delegate* delegate) { |
| 288 } |
| 289 |
287 int SimpleMenuModel::FlipIndex(int index) const { | 290 int SimpleMenuModel::FlipIndex(int index) const { |
288 return index; | 291 return index; |
289 } | 292 } |
290 | 293 |
291 //////////////////////////////////////////////////////////////////////////////// | 294 //////////////////////////////////////////////////////////////////////////////// |
292 // SimpleMenuModel, Private: | 295 // SimpleMenuModel, Private: |
293 | 296 |
294 void SimpleMenuModel::AppendItem(const Item& item) { | 297 void SimpleMenuModel::AppendItem(const Item& item) { |
295 ValidateItem(item); | 298 ValidateItem(item); |
296 items_.push_back(item); | 299 items_.push_back(item); |
297 } | 300 } |
298 | 301 |
299 void SimpleMenuModel::InsertItemAtIndex(const Item& item, int index) { | 302 void SimpleMenuModel::InsertItemAtIndex(const Item& item, int index) { |
300 ValidateItem(item); | 303 ValidateItem(item); |
301 items_.insert(items_.begin() + FlipIndex(index), item); | 304 items_.insert(items_.begin() + FlipIndex(index), item); |
302 } | 305 } |
303 | 306 |
304 void SimpleMenuModel::ValidateItem(const Item& item) { | 307 void SimpleMenuModel::ValidateItem(const Item& item) { |
305 #ifndef NDEBUG | 308 #ifndef NDEBUG |
306 if (item.type == TYPE_SEPARATOR) { | 309 if (item.type == TYPE_SEPARATOR) { |
307 DCHECK_EQ(item.command_id, kSeparatorId); | 310 DCHECK_EQ(item.command_id, kSeparatorId); |
308 } else { | 311 } else { |
309 DCHECK_GE(item.command_id, 0); | 312 DCHECK_GE(item.command_id, 0); |
310 } | 313 } |
311 #endif // NDEBUG | 314 #endif // NDEBUG |
312 } | 315 } |
313 | 316 |
314 } // namespace menus | 317 } // namespace menus |
OLD | NEW |