Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(417)

Side by Side Diff: ui/views/controls/menu/menu_item_view.cc

Issue 10837317: Setting the touch wrench menu as default menu for ChromeOS (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: And another merge! Created 8 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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/views/controls/menu/menu_item_view.h" 5 #include "ui/views/controls/menu/menu_item_view.h"
6 6
7 #include "base/i18n/case_conversion.h" 7 #include "base/i18n/case_conversion.h"
8 #include "base/stl_util.h" 8 #include "base/stl_util.h"
9 #include "base/utf_string_conversions.h" 9 #include "base/utf_string_conversions.h"
10 #include "grit/ui_strings.h" 10 #include "grit/ui_strings.h"
(...skipping 188 matching lines...) Expand 10 before | Expand all | Expand 10 after
199 return accessible_name; 199 return accessible_name;
200 } 200 }
201 201
202 void MenuItemView::Cancel() { 202 void MenuItemView::Cancel() {
203 if (controller_ && !canceled_) { 203 if (controller_ && !canceled_) {
204 canceled_ = true; 204 canceled_ = true;
205 controller_->Cancel(MenuController::EXIT_ALL); 205 controller_->Cancel(MenuController::EXIT_ALL);
206 } 206 }
207 } 207 }
208 208
209 MenuItemView* MenuItemView::AddMenuItemAt(int index, 209 MenuItemView* MenuItemView::AddMenuItemAt(
210 int item_id, 210 int index,
211 const string16& label, 211 int item_id,
212 const gfx::ImageSkia& icon, 212 const string16& label,
213 Type type) { 213 const gfx::ImageSkia& icon,
214 Type type,
215 ui::MenuSeparatorType separator_style) {
214 DCHECK_NE(type, EMPTY); 216 DCHECK_NE(type, EMPTY);
215 DCHECK_LE(0, index); 217 DCHECK_LE(0, index);
216 if (!submenu_) 218 if (!submenu_)
217 CreateSubmenu(); 219 CreateSubmenu();
218 DCHECK_GE(submenu_->child_count(), index); 220 DCHECK_GE(submenu_->child_count(), index);
219 if (type == SEPARATOR) { 221 if (type == SEPARATOR) {
220 submenu_->AddChildViewAt(new MenuSeparator(), index); 222 submenu_->AddChildViewAt(new MenuSeparator(separator_style), index);
221 return NULL; 223 return NULL;
222 } 224 }
223 MenuItemView* item = new MenuItemView(this, item_id, type); 225 MenuItemView* item = new MenuItemView(this, item_id, type);
224 if (label.empty() && GetDelegate()) 226 if (label.empty() && GetDelegate())
225 item->SetTitle(GetDelegate()->GetLabel(item_id)); 227 item->SetTitle(GetDelegate()->GetLabel(item_id));
226 else 228 else
227 item->SetTitle(label); 229 item->SetTitle(label);
228 if (!icon.isNull()) 230 if (!icon.isNull())
229 item->SetIcon(icon); 231 item->SetIcon(icon);
230 if (type == SUBMENU) 232 if (type == SUBMENU)
(...skipping 13 matching lines...) Expand all
244 246
245 // RemoveChildView() does not delete the item, which is a good thing 247 // RemoveChildView() does not delete the item, which is a good thing
246 // in case a submenu is being displayed while items are being removed. 248 // in case a submenu is being displayed while items are being removed.
247 // Deletion will be done by ChildrenChanged() or at destruction. 249 // Deletion will be done by ChildrenChanged() or at destruction.
248 removed_items_.push_back(item); 250 removed_items_.push_back(item);
249 } 251 }
250 252
251 MenuItemView* MenuItemView::AppendMenuItem(int item_id, 253 MenuItemView* MenuItemView::AppendMenuItem(int item_id,
252 const string16& label, 254 const string16& label,
253 Type type) { 255 Type type) {
254 return AppendMenuItemImpl(item_id, label, gfx::ImageSkia(), type); 256 return AppendMenuItemImpl(item_id, label, gfx::ImageSkia(), type,
257 ui::NORMAL_SEPARATOR);
255 } 258 }
256 259
257 MenuItemView* MenuItemView::AppendSubMenu(int item_id, 260 MenuItemView* MenuItemView::AppendSubMenu(int item_id,
258 const string16& label) { 261 const string16& label) {
259 return AppendMenuItemImpl(item_id, label, gfx::ImageSkia(), SUBMENU); 262 return AppendMenuItemImpl(item_id, label, gfx::ImageSkia(), SUBMENU,
263 ui::NORMAL_SEPARATOR);
260 } 264 }
261 265
262 MenuItemView* MenuItemView::AppendSubMenuWithIcon(int item_id, 266 MenuItemView* MenuItemView::AppendSubMenuWithIcon(int item_id,
263 const string16& label, 267 const string16& label,
264 const gfx::ImageSkia& icon) { 268 const gfx::ImageSkia& icon) {
265 return AppendMenuItemImpl(item_id, label, icon, SUBMENU); 269 return AppendMenuItemImpl(
270 item_id, label, icon, SUBMENU, ui::NORMAL_SEPARATOR);
266 } 271 }
267 272
268 MenuItemView* MenuItemView::AppendMenuItemWithLabel(int item_id, 273 MenuItemView* MenuItemView::AppendMenuItemWithLabel(int item_id,
269 const string16& label) { 274 const string16& label) {
270 return AppendMenuItem(item_id, label, NORMAL); 275 return AppendMenuItem(item_id, label, NORMAL);
271 } 276 }
272 277
273 MenuItemView* MenuItemView::AppendDelegateMenuItem(int item_id) { 278 MenuItemView* MenuItemView::AppendDelegateMenuItem(int item_id) {
274 return AppendMenuItem(item_id, string16(), NORMAL); 279 return AppendMenuItem(item_id, string16(), NORMAL);
275 } 280 }
276 281
277 void MenuItemView::AppendSeparator() { 282 void MenuItemView::AppendSeparator() {
278 AppendMenuItemImpl(0, string16(), gfx::ImageSkia(), SEPARATOR); 283 AppendMenuItemImpl(
284 0, string16(), gfx::ImageSkia(), SEPARATOR, ui::NORMAL_SEPARATOR);
279 } 285 }
280 286
281 MenuItemView* MenuItemView::AppendMenuItemWithIcon(int item_id, 287 MenuItemView* MenuItemView::AppendMenuItemWithIcon(int item_id,
282 const string16& label, 288 const string16& label,
283 const gfx::ImageSkia& icon) { 289 const gfx::ImageSkia& icon) {
284 return AppendMenuItemImpl(item_id, label, icon, NORMAL); 290 return AppendMenuItemImpl(
291 item_id, label, icon, NORMAL, ui::NORMAL_SEPARATOR);
285 } 292 }
286 293
287 MenuItemView* MenuItemView::AppendMenuItemFromModel(ui::MenuModel* model, 294 MenuItemView* MenuItemView::AppendMenuItemFromModel(ui::MenuModel* model,
288 int index, 295 int index,
289 int id) { 296 int id) {
290 gfx::Image icon; 297 gfx::Image icon;
291 string16 label; 298 string16 label;
299 ui::MenuSeparatorType separator_style = ui::NORMAL_SEPARATOR;
292 MenuItemView::Type type; 300 MenuItemView::Type type;
293 ui::MenuModel::ItemType menu_type = model->GetTypeAt(index); 301 ui::MenuModel::ItemType menu_type = model->GetTypeAt(index);
294 switch (menu_type) { 302 switch (menu_type) {
295 case ui::MenuModel::TYPE_COMMAND: 303 case ui::MenuModel::TYPE_COMMAND:
296 model->GetIconAt(index, &icon); 304 model->GetIconAt(index, &icon);
297 type = MenuItemView::NORMAL; 305 type = MenuItemView::NORMAL;
298 label = model->GetLabelAt(index); 306 label = model->GetLabelAt(index);
299 break; 307 break;
300 case ui::MenuModel::TYPE_CHECK: 308 case ui::MenuModel::TYPE_CHECK:
301 type = MenuItemView::CHECKBOX; 309 type = MenuItemView::CHECKBOX;
302 label = model->GetLabelAt(index); 310 label = model->GetLabelAt(index);
303 break; 311 break;
304 case ui::MenuModel::TYPE_RADIO: 312 case ui::MenuModel::TYPE_RADIO:
305 type = MenuItemView::RADIO; 313 type = MenuItemView::RADIO;
306 label = model->GetLabelAt(index); 314 label = model->GetLabelAt(index);
307 break; 315 break;
308 case ui::MenuModel::TYPE_SEPARATOR: 316 case ui::MenuModel::TYPE_SEPARATOR:
309 type = MenuItemView::SEPARATOR; 317 type = MenuItemView::SEPARATOR;
318 separator_style = model->GetSeparatorTypeAt(index);
310 break; 319 break;
311 case ui::MenuModel::TYPE_SUBMENU: 320 case ui::MenuModel::TYPE_SUBMENU:
312 model->GetIconAt(index, &icon); 321 model->GetIconAt(index, &icon);
313 type = MenuItemView::SUBMENU; 322 type = MenuItemView::SUBMENU;
314 label = model->GetLabelAt(index); 323 label = model->GetLabelAt(index);
315 break; 324 break;
316 default: 325 default:
317 NOTREACHED(); 326 NOTREACHED();
318 type = MenuItemView::NORMAL; 327 type = MenuItemView::NORMAL;
319 break; 328 break;
320 } 329 }
321 330
322 return AppendMenuItemImpl(id, 331 return AppendMenuItemImpl(id,
323 label, 332 label,
324 icon.IsEmpty() ? gfx::ImageSkia() : *icon.ToImageSkia(), 333 icon.IsEmpty() ? gfx::ImageSkia() : *icon.ToImageSkia(),
325 type); 334 type,
335 separator_style);
326 } 336 }
327 337
328 MenuItemView* MenuItemView::AppendMenuItemImpl(int item_id, 338 MenuItemView* MenuItemView::AppendMenuItemImpl(
329 const string16& label, 339 int item_id,
330 const gfx::ImageSkia& icon, 340 const string16& label,
331 Type type) { 341 const gfx::ImageSkia& icon,
342 Type type,
343 ui::MenuSeparatorType separator_style) {
332 const int index = submenu_ ? submenu_->child_count() : 0; 344 const int index = submenu_ ? submenu_->child_count() : 0;
333 return AddMenuItemAt(index, item_id, label, icon, type); 345 return AddMenuItemAt(index, item_id, label, icon, type, separator_style);
334 } 346 }
335 347
336 SubmenuView* MenuItemView::CreateSubmenu() { 348 SubmenuView* MenuItemView::CreateSubmenu() {
337 if (!submenu_) 349 if (!submenu_)
338 submenu_ = new SubmenuView(this); 350 submenu_ = new SubmenuView(this);
339 return submenu_; 351 return submenu_;
340 } 352 }
341 353
342 bool MenuItemView::HasSubmenu() const { 354 bool MenuItemView::HasSubmenu() const {
343 return (submenu_ != NULL); 355 return (submenu_ != NULL);
(...skipping 506 matching lines...) Expand 10 before | Expand all | Expand 10 after
850 temp_width = menu_item->GetMaxIconViewWidth(); 862 temp_width = menu_item->GetMaxIconViewWidth();
851 } else if (menu_item->icon_view()) { 863 } else if (menu_item->icon_view()) {
852 temp_width = menu_item->icon_view()->GetPreferredSize().width(); 864 temp_width = menu_item->icon_view()->GetPreferredSize().width();
853 } 865 }
854 width = std::max(width, temp_width); 866 width = std::max(width, temp_width);
855 } 867 }
856 return width; 868 return width;
857 } 869 }
858 870
859 } // namespace views 871 } // namespace views
OLDNEW
« no previous file with comments | « ui/views/controls/menu/menu_item_view.h ('k') | ui/views/controls/menu/menu_model_adapter_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698