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 227 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
238 int item_index = FlipIndex(index); | 238 int item_index = FlipIndex(index); |
239 MenuModel::ItemType item_type = items_[item_index].type; | 239 MenuModel::ItemType item_type = items_[item_index].type; |
240 return (item_type == TYPE_CHECK || item_type == TYPE_RADIO) ? | 240 return (item_type == TYPE_CHECK || item_type == TYPE_RADIO) ? |
241 delegate_->IsCommandIdChecked(GetCommandIdAt(index)) : false; | 241 delegate_->IsCommandIdChecked(GetCommandIdAt(index)) : false; |
242 } | 242 } |
243 | 243 |
244 int SimpleMenuModel::GetGroupIdAt(int index) const { | 244 int SimpleMenuModel::GetGroupIdAt(int index) const { |
245 return items_.at(FlipIndex(index)).group_id; | 245 return items_.at(FlipIndex(index)).group_id; |
246 } | 246 } |
247 | 247 |
248 bool SimpleMenuModel::GetIconAt(int index, SkBitmap* icon) const { | 248 bool SimpleMenuModel::GetIconAt(int index, SkBitmap* icon) { |
249 if (IsItemDynamicAt(index)) | 249 if (IsItemDynamicAt(index)) |
250 return delegate_->GetIconForCommandId(GetCommandIdAt(index), icon); | 250 return delegate_->GetIconForCommandId(GetCommandIdAt(index), icon); |
251 | 251 |
252 if (items_[index].icon.isNull()) | 252 if (items_[index].icon.isNull()) |
253 return false; | 253 return false; |
254 | 254 |
255 *icon = items_[index].icon; | 255 *icon = items_[index].icon; |
256 return true; | 256 return true; |
257 } | 257 } |
258 | 258 |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
297 MessageLoop::current()->PostTask( | 297 MessageLoop::current()->PostTask( |
298 FROM_HERE, | 298 FROM_HERE, |
299 method_factory_.NewRunnableMethod(&SimpleMenuModel::OnMenuClosed)); | 299 method_factory_.NewRunnableMethod(&SimpleMenuModel::OnMenuClosed)); |
300 } | 300 } |
301 | 301 |
302 void SimpleMenuModel::OnMenuClosed() { | 302 void SimpleMenuModel::OnMenuClosed() { |
303 if (delegate_) | 303 if (delegate_) |
304 delegate_->MenuClosed(); | 304 delegate_->MenuClosed(); |
305 } | 305 } |
306 | 306 |
307 void SimpleMenuModel::SetDelegate(ui::MenuModel::Delegate* delegate) { | |
308 } | |
sky
2011/02/22 18:28:28
SimpleMenuModel should maintain the delegate as a
dill
2011/02/25 15:16:43
BackForwardMenuModel extends ui::MenuModel, not ui
sky
2011/02/25 15:48:57
I don't realize that. Have the implementation in b
| |
309 | |
307 int SimpleMenuModel::FlipIndex(int index) const { | 310 int SimpleMenuModel::FlipIndex(int index) const { |
308 return index; | 311 return index; |
309 } | 312 } |
310 | 313 |
311 //////////////////////////////////////////////////////////////////////////////// | 314 //////////////////////////////////////////////////////////////////////////////// |
312 // SimpleMenuModel, Private: | 315 // SimpleMenuModel, Private: |
313 | 316 |
314 void SimpleMenuModel::AppendItem(const Item& item) { | 317 void SimpleMenuModel::AppendItem(const Item& item) { |
315 ValidateItem(item); | 318 ValidateItem(item); |
316 items_.push_back(item); | 319 items_.push_back(item); |
317 } | 320 } |
318 | 321 |
319 void SimpleMenuModel::InsertItemAtIndex(const Item& item, int index) { | 322 void SimpleMenuModel::InsertItemAtIndex(const Item& item, int index) { |
320 ValidateItem(item); | 323 ValidateItem(item); |
321 items_.insert(items_.begin() + FlipIndex(index), item); | 324 items_.insert(items_.begin() + FlipIndex(index), item); |
322 } | 325 } |
323 | 326 |
324 void SimpleMenuModel::ValidateItem(const Item& item) { | 327 void SimpleMenuModel::ValidateItem(const Item& item) { |
325 #ifndef NDEBUG | 328 #ifndef NDEBUG |
326 if (item.type == TYPE_SEPARATOR) { | 329 if (item.type == TYPE_SEPARATOR) { |
327 DCHECK_EQ(item.command_id, kSeparatorId); | 330 DCHECK_EQ(item.command_id, kSeparatorId); |
328 } else { | 331 } else { |
329 DCHECK_GE(item.command_id, 0); | 332 DCHECK_GE(item.command_id, 0); |
330 } | 333 } |
331 #endif // NDEBUG | 334 #endif // NDEBUG |
332 } | 335 } |
333 | 336 |
334 } // namespace ui | 337 } // namespace ui |
OLD | NEW |