Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/message_loop.h" | 8 #include "base/message_loop.h" |
| 9 #include "ui/base/l10n/l10n_util.h" | 9 #include "ui/base/l10n/l10n_util.h" |
| 10 #include "ui/gfx/image/image_skia.h" | 10 #include "ui/gfx/image/image_skia.h" |
| (...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 73 void SimpleMenuModel::AddItem(int command_id, const string16& label) { | 73 void SimpleMenuModel::AddItem(int command_id, const string16& label) { |
| 74 Item item = { command_id, label, gfx::ImageSkia(), TYPE_COMMAND, -1, NULL, | 74 Item item = { command_id, label, gfx::ImageSkia(), TYPE_COMMAND, -1, NULL, |
| 75 NULL }; | 75 NULL }; |
| 76 AppendItem(item); | 76 AppendItem(item); |
| 77 } | 77 } |
| 78 | 78 |
| 79 void SimpleMenuModel::AddItemWithStringId(int command_id, int string_id) { | 79 void SimpleMenuModel::AddItemWithStringId(int command_id, int string_id) { |
| 80 AddItem(command_id, l10n_util::GetStringUTF16(string_id)); | 80 AddItem(command_id, l10n_util::GetStringUTF16(string_id)); |
| 81 } | 81 } |
| 82 | 82 |
| 83 void SimpleMenuModel::AddSeparator() { | 83 void SimpleMenuModel::AddSeparator(const string16& separator_type) { |
| 84 Item item = { kSeparatorId, string16(), gfx::ImageSkia(), TYPE_SEPARATOR, -1, | 84 #if defined(OS_WINDOWS) |
| 85 NULL, NULL }; | 85 DCHECK(separator_type == MenuModel::NORMAL_SEPARATOR) |
| 86 #endif | |
| 87 Item item = { kSeparatorId, separator_type, gfx::ImageSkia(), TYPE_SEPARATOR, | |
|
sky
2012/08/20 15:58:17
Embedding the separator type in the label is a hac
Mr4D (OOO till 08-26)
2012/08/21 01:13:18
Okay, done.
| |
| 88 -1, NULL, NULL }; | |
| 86 AppendItem(item); | 89 AppendItem(item); |
| 87 } | 90 } |
| 88 | 91 |
| 89 void SimpleMenuModel::AddCheckItem(int command_id, const string16& label) { | 92 void SimpleMenuModel::AddCheckItem(int command_id, const string16& label) { |
| 90 Item item = { command_id, label, gfx::ImageSkia(), TYPE_CHECK, -1, NULL, | 93 Item item = { command_id, label, gfx::ImageSkia(), TYPE_CHECK, -1, NULL, |
| 91 NULL }; | 94 NULL }; |
| 92 AppendItem(item); | 95 AppendItem(item); |
| 93 } | 96 } |
| 94 | 97 |
| 95 void SimpleMenuModel::AddCheckItemWithStringId(int command_id, int string_id) { | 98 void SimpleMenuModel::AddCheckItemWithStringId(int command_id, int string_id) { |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 132 Item item = { command_id, label, gfx::ImageSkia(), TYPE_COMMAND, -1, NULL, | 135 Item item = { command_id, label, gfx::ImageSkia(), TYPE_COMMAND, -1, NULL, |
| 133 NULL }; | 136 NULL }; |
| 134 InsertItemAtIndex(item, index); | 137 InsertItemAtIndex(item, index); |
| 135 } | 138 } |
| 136 | 139 |
| 137 void SimpleMenuModel::InsertItemWithStringIdAt( | 140 void SimpleMenuModel::InsertItemWithStringIdAt( |
| 138 int index, int command_id, int string_id) { | 141 int index, int command_id, int string_id) { |
| 139 InsertItemAt(index, command_id, l10n_util::GetStringUTF16(string_id)); | 142 InsertItemAt(index, command_id, l10n_util::GetStringUTF16(string_id)); |
| 140 } | 143 } |
| 141 | 144 |
| 142 void SimpleMenuModel::InsertSeparatorAt(int index) { | 145 void SimpleMenuModel::InsertSeparatorAt(int index, |
| 143 Item item = { kSeparatorId, string16(), gfx::ImageSkia(), TYPE_SEPARATOR, -1, | 146 const string16& separator_type) { |
| 144 NULL, NULL }; | 147 #if defined(OS_WINDOWS) |
| 148 DCHECK(separator_type == MenuModel::NORMAL_SEPARATOR) | |
| 149 #endif | |
| 150 Item item = { kSeparatorId, separator_type, gfx::ImageSkia(), TYPE_SEPARATOR, | |
| 151 -1, NULL, NULL }; | |
| 145 InsertItemAtIndex(item, index); | 152 InsertItemAtIndex(item, index); |
| 146 } | 153 } |
| 147 | 154 |
| 148 void SimpleMenuModel::InsertCheckItemAt( | 155 void SimpleMenuModel::InsertCheckItemAt( |
| 149 int index, int command_id, const string16& label) { | 156 int index, int command_id, const string16& label) { |
| 150 Item item = { command_id, label, gfx::ImageSkia(), TYPE_CHECK, -1, NULL, | 157 Item item = { command_id, label, gfx::ImageSkia(), TYPE_CHECK, -1, NULL, |
| 151 NULL }; | 158 NULL }; |
| 152 InsertItemAtIndex(item, index); | 159 InsertItemAtIndex(item, index); |
| 153 } | 160 } |
| 154 | 161 |
| (...skipping 203 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 358 #ifndef NDEBUG | 365 #ifndef NDEBUG |
| 359 if (item.type == TYPE_SEPARATOR) { | 366 if (item.type == TYPE_SEPARATOR) { |
| 360 DCHECK_EQ(item.command_id, kSeparatorId); | 367 DCHECK_EQ(item.command_id, kSeparatorId); |
| 361 } else { | 368 } else { |
| 362 DCHECK_GE(item.command_id, 0); | 369 DCHECK_GE(item.command_id, 0); |
| 363 } | 370 } |
| 364 #endif // NDEBUG | 371 #endif // NDEBUG |
| 365 } | 372 } |
| 366 | 373 |
| 367 } // namespace ui | 374 } // namespace ui |
| OLD | NEW |