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

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: Addressed review Created 8 years, 4 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 187 matching lines...) Expand 10 before | Expand all | Expand 10 after
198 return accessible_name; 198 return accessible_name;
199 } 199 }
200 200
201 void MenuItemView::Cancel() { 201 void MenuItemView::Cancel() {
202 if (controller_ && !canceled_) { 202 if (controller_ && !canceled_) {
203 canceled_ = true; 203 canceled_ = true;
204 controller_->Cancel(MenuController::EXIT_ALL); 204 controller_->Cancel(MenuController::EXIT_ALL);
205 } 205 }
206 } 206 }
207 207
208 MenuItemView* MenuItemView::AddMenuItemAt(int index, 208 MenuItemView* MenuItemView::AddMenuItemAt(
209 int item_id, 209 int index,
210 const string16& label, 210 int item_id,
211 const gfx::ImageSkia& icon, 211 const string16& label,
212 Type type) { 212 const gfx::ImageSkia& icon,
213 Type type,
214 ui::MenuSeparatorStyle separator_style) {
213 DCHECK_NE(type, EMPTY); 215 DCHECK_NE(type, EMPTY);
214 DCHECK_LE(0, index); 216 DCHECK_LE(0, index);
215 if (!submenu_) 217 if (!submenu_)
216 CreateSubmenu(); 218 CreateSubmenu();
217 DCHECK_GE(submenu_->child_count(), index); 219 DCHECK_GE(submenu_->child_count(), index);
218 if (type == SEPARATOR) { 220 if (type == SEPARATOR) {
219 submenu_->AddChildViewAt(new MenuSeparator(), index); 221 submenu_->AddChildViewAt(new MenuSeparator(separator_style), index);
220 return NULL; 222 return NULL;
221 } 223 }
222 MenuItemView* item = new MenuItemView(this, item_id, type); 224 MenuItemView* item = new MenuItemView(this, item_id, type);
223 if (label.empty() && GetDelegate()) 225 if (label.empty() && GetDelegate())
224 item->SetTitle(GetDelegate()->GetLabel(item_id)); 226 item->SetTitle(GetDelegate()->GetLabel(item_id));
225 else 227 else
226 item->SetTitle(label); 228 item->SetTitle(label);
227 if (!icon.empty()) 229 if (!icon.empty())
228 item->SetIcon(icon); 230 item->SetIcon(icon);
229 if (type == SUBMENU) 231 if (type == SUBMENU)
(...skipping 13 matching lines...) Expand all
243 245
244 // RemoveChildView() does not delete the item, which is a good thing 246 // RemoveChildView() does not delete the item, which is a good thing
245 // in case a submenu is being displayed while items are being removed. 247 // in case a submenu is being displayed while items are being removed.
246 // Deletion will be done by ChildrenChanged() or at destruction. 248 // Deletion will be done by ChildrenChanged() or at destruction.
247 removed_items_.push_back(item); 249 removed_items_.push_back(item);
248 } 250 }
249 251
250 MenuItemView* MenuItemView::AppendMenuItem(int item_id, 252 MenuItemView* MenuItemView::AppendMenuItem(int item_id,
251 const string16& label, 253 const string16& label,
252 Type type) { 254 Type type) {
253 return AppendMenuItemImpl(item_id, label, gfx::ImageSkia(), type); 255 return AppendMenuItemImpl(item_id, label, gfx::ImageSkia(), type,
256 ui::NO_SEPARATOR);
254 } 257 }
255 258
256 MenuItemView* MenuItemView::AppendSubMenu(int item_id, 259 MenuItemView* MenuItemView::AppendSubMenu(int item_id,
257 const string16& label) { 260 const string16& label) {
258 return AppendMenuItemImpl(item_id, label, gfx::ImageSkia(), SUBMENU); 261 return AppendMenuItemImpl(item_id, label, gfx::ImageSkia(), SUBMENU,
262 ui::NO_SEPARATOR);
259 } 263 }
260 264
261 MenuItemView* MenuItemView::AppendSubMenuWithIcon(int item_id, 265 MenuItemView* MenuItemView::AppendSubMenuWithIcon(int item_id,
262 const string16& label, 266 const string16& label,
263 const gfx::ImageSkia& icon) { 267 const gfx::ImageSkia& icon) {
264 return AppendMenuItemImpl(item_id, label, icon, SUBMENU); 268 return AppendMenuItemImpl(item_id, label, icon, SUBMENU, ui::NO_SEPARATOR);
265 } 269 }
266 270
267 MenuItemView* MenuItemView::AppendMenuItemWithLabel(int item_id, 271 MenuItemView* MenuItemView::AppendMenuItemWithLabel(int item_id,
268 const string16& label) { 272 const string16& label) {
269 return AppendMenuItem(item_id, label, NORMAL); 273 return AppendMenuItem(item_id, label, NORMAL);
270 } 274 }
271 275
272 MenuItemView* MenuItemView::AppendDelegateMenuItem(int item_id) { 276 MenuItemView* MenuItemView::AppendDelegateMenuItem(int item_id) {
273 return AppendMenuItem(item_id, string16(), NORMAL); 277 return AppendMenuItem(item_id, string16(), NORMAL);
274 } 278 }
275 279
276 void MenuItemView::AppendSeparator() { 280 void MenuItemView::AppendSeparator() {
277 AppendMenuItemImpl(0, string16(), gfx::ImageSkia(), SEPARATOR); 281 AppendMenuItemImpl(
282 0, string16(), gfx::ImageSkia(), SEPARATOR, ui::NORMAL_SEPARATOR);
278 } 283 }
279 284
280 MenuItemView* MenuItemView::AppendMenuItemWithIcon(int item_id, 285 MenuItemView* MenuItemView::AppendMenuItemWithIcon(int item_id,
281 const string16& label, 286 const string16& label,
282 const gfx::ImageSkia& icon) { 287 const gfx::ImageSkia& icon) {
283 return AppendMenuItemImpl(item_id, label, icon, NORMAL); 288 return AppendMenuItemImpl(item_id, label, icon, NORMAL, ui::NO_SEPARATOR);
284 } 289 }
285 290
286 MenuItemView* MenuItemView::AppendMenuItemFromModel(ui::MenuModel* model, 291 MenuItemView* MenuItemView::AppendMenuItemFromModel(ui::MenuModel* model,
287 int index, 292 int index,
288 int id) { 293 int id) {
289 gfx::ImageSkia icon; 294 gfx::ImageSkia icon;
290 string16 label; 295 string16 label;
296 ui::MenuSeparatorStyle separator_style = ui::NO_SEPARATOR;
291 MenuItemView::Type type; 297 MenuItemView::Type type;
292 ui::MenuModel::ItemType menu_type = model->GetTypeAt(index); 298 ui::MenuModel::ItemType menu_type = model->GetTypeAt(index);
293 switch (menu_type) { 299 switch (menu_type) {
294 case ui::MenuModel::TYPE_COMMAND: 300 case ui::MenuModel::TYPE_COMMAND:
295 model->GetIconAt(index, &icon); 301 model->GetIconAt(index, &icon);
296 type = MenuItemView::NORMAL; 302 type = MenuItemView::NORMAL;
297 label = model->GetLabelAt(index); 303 label = model->GetLabelAt(index);
298 break; 304 break;
299 case ui::MenuModel::TYPE_CHECK: 305 case ui::MenuModel::TYPE_CHECK:
300 type = MenuItemView::CHECKBOX; 306 type = MenuItemView::CHECKBOX;
301 label = model->GetLabelAt(index); 307 label = model->GetLabelAt(index);
302 break; 308 break;
303 case ui::MenuModel::TYPE_RADIO: 309 case ui::MenuModel::TYPE_RADIO:
304 type = MenuItemView::RADIO; 310 type = MenuItemView::RADIO;
305 label = model->GetLabelAt(index); 311 label = model->GetLabelAt(index);
306 break; 312 break;
307 case ui::MenuModel::TYPE_SEPARATOR: 313 case ui::MenuModel::TYPE_SEPARATOR:
308 type = MenuItemView::SEPARATOR; 314 type = MenuItemView::SEPARATOR;
315 separator_style = model->GetSeparatorStyleAt(index);
309 break; 316 break;
310 case ui::MenuModel::TYPE_SUBMENU: 317 case ui::MenuModel::TYPE_SUBMENU:
311 model->GetIconAt(index, &icon); 318 model->GetIconAt(index, &icon);
312 type = MenuItemView::SUBMENU; 319 type = MenuItemView::SUBMENU;
313 label = model->GetLabelAt(index); 320 label = model->GetLabelAt(index);
314 break; 321 break;
315 default: 322 default:
316 NOTREACHED(); 323 NOTREACHED();
317 type = MenuItemView::NORMAL; 324 type = MenuItemView::NORMAL;
318 break; 325 break;
319 } 326 }
320 327
321 return AppendMenuItemImpl(id, label, icon, type); 328 return AppendMenuItemImpl(id, label, icon, type, separator_style);
322 } 329 }
323 330
324 MenuItemView* MenuItemView::AppendMenuItemImpl(int item_id, 331 MenuItemView* MenuItemView::AppendMenuItemImpl(
325 const string16& label, 332 int item_id,
326 const gfx::ImageSkia& icon, 333 const string16& label,
327 Type type) { 334 const gfx::ImageSkia& icon,
335 Type type,
336 ui::MenuSeparatorStyle separator_style) {
328 const int index = submenu_ ? submenu_->child_count() : 0; 337 const int index = submenu_ ? submenu_->child_count() : 0;
329 return AddMenuItemAt(index, item_id, label, icon, type); 338 return AddMenuItemAt(index, item_id, label, icon, type, separator_style);
330 } 339 }
331 340
332 SubmenuView* MenuItemView::CreateSubmenu() { 341 SubmenuView* MenuItemView::CreateSubmenu() {
333 if (!submenu_) 342 if (!submenu_)
334 submenu_ = new SubmenuView(this); 343 submenu_ = new SubmenuView(this);
335 return submenu_; 344 return submenu_;
336 } 345 }
337 346
338 bool MenuItemView::HasSubmenu() const { 347 bool MenuItemView::HasSubmenu() const {
339 return (submenu_ != NULL); 348 return (submenu_ != NULL);
(...skipping 506 matching lines...) Expand 10 before | Expand all | Expand 10 after
846 temp_width = menu_item->GetMaxIconViewWidth(); 855 temp_width = menu_item->GetMaxIconViewWidth();
847 } else if (menu_item->icon_view()) { 856 } else if (menu_item->icon_view()) {
848 temp_width = menu_item->icon_view()->GetPreferredSize().width(); 857 temp_width = menu_item->icon_view()->GetPreferredSize().width();
849 } 858 }
850 width = std::max(width, temp_width); 859 width = std::max(width, temp_width);
851 } 860 }
852 return width; 861 return width;
853 } 862 }
854 863
855 } // namespace views 864 } // namespace views
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698