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

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: Fixed build problems 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::MenuSeparatorType 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::NORMAL_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::NORMAL_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(
269 item_id, label, icon, SUBMENU, ui::NORMAL_SEPARATOR);
265 } 270 }
266 271
267 MenuItemView* MenuItemView::AppendMenuItemWithLabel(int item_id, 272 MenuItemView* MenuItemView::AppendMenuItemWithLabel(int item_id,
268 const string16& label) { 273 const string16& label) {
269 return AppendMenuItem(item_id, label, NORMAL); 274 return AppendMenuItem(item_id, label, NORMAL);
270 } 275 }
271 276
272 MenuItemView* MenuItemView::AppendDelegateMenuItem(int item_id) { 277 MenuItemView* MenuItemView::AppendDelegateMenuItem(int item_id) {
273 return AppendMenuItem(item_id, string16(), NORMAL); 278 return AppendMenuItem(item_id, string16(), NORMAL);
274 } 279 }
275 280
276 void MenuItemView::AppendSeparator() { 281 void MenuItemView::AppendSeparator() {
277 AppendMenuItemImpl(0, string16(), gfx::ImageSkia(), SEPARATOR); 282 AppendMenuItemImpl(
283 0, string16(), gfx::ImageSkia(), SEPARATOR, ui::NORMAL_SEPARATOR);
278 } 284 }
279 285
280 MenuItemView* MenuItemView::AppendMenuItemWithIcon(int item_id, 286 MenuItemView* MenuItemView::AppendMenuItemWithIcon(int item_id,
281 const string16& label, 287 const string16& label,
282 const gfx::ImageSkia& icon) { 288 const gfx::ImageSkia& icon) {
283 return AppendMenuItemImpl(item_id, label, icon, NORMAL); 289 return AppendMenuItemImpl(
290 item_id, label, icon, NORMAL, ui::NORMAL_SEPARATOR);
284 } 291 }
285 292
286 MenuItemView* MenuItemView::AppendMenuItemFromModel(ui::MenuModel* model, 293 MenuItemView* MenuItemView::AppendMenuItemFromModel(ui::MenuModel* model,
287 int index, 294 int index,
288 int id) { 295 int id) {
289 gfx::ImageSkia icon; 296 gfx::ImageSkia icon;
290 string16 label; 297 string16 label;
298 ui::MenuSeparatorType separator_style = ui::NORMAL_SEPARATOR;
291 MenuItemView::Type type; 299 MenuItemView::Type type;
292 ui::MenuModel::ItemType menu_type = model->GetTypeAt(index); 300 ui::MenuModel::ItemType menu_type = model->GetTypeAt(index);
293 switch (menu_type) { 301 switch (menu_type) {
294 case ui::MenuModel::TYPE_COMMAND: 302 case ui::MenuModel::TYPE_COMMAND:
295 model->GetIconAt(index, &icon); 303 model->GetIconAt(index, &icon);
296 type = MenuItemView::NORMAL; 304 type = MenuItemView::NORMAL;
297 label = model->GetLabelAt(index); 305 label = model->GetLabelAt(index);
298 break; 306 break;
299 case ui::MenuModel::TYPE_CHECK: 307 case ui::MenuModel::TYPE_CHECK:
300 type = MenuItemView::CHECKBOX; 308 type = MenuItemView::CHECKBOX;
301 label = model->GetLabelAt(index); 309 label = model->GetLabelAt(index);
302 break; 310 break;
303 case ui::MenuModel::TYPE_RADIO: 311 case ui::MenuModel::TYPE_RADIO:
304 type = MenuItemView::RADIO; 312 type = MenuItemView::RADIO;
305 label = model->GetLabelAt(index); 313 label = model->GetLabelAt(index);
306 break; 314 break;
307 case ui::MenuModel::TYPE_SEPARATOR: 315 case ui::MenuModel::TYPE_SEPARATOR:
308 type = MenuItemView::SEPARATOR; 316 type = MenuItemView::SEPARATOR;
317 separator_style = model->GetSeparatorTypeAt(index);
309 break; 318 break;
310 case ui::MenuModel::TYPE_SUBMENU: 319 case ui::MenuModel::TYPE_SUBMENU:
311 model->GetIconAt(index, &icon); 320 model->GetIconAt(index, &icon);
312 type = MenuItemView::SUBMENU; 321 type = MenuItemView::SUBMENU;
313 label = model->GetLabelAt(index); 322 label = model->GetLabelAt(index);
314 break; 323 break;
315 default: 324 default:
316 NOTREACHED(); 325 NOTREACHED();
317 type = MenuItemView::NORMAL; 326 type = MenuItemView::NORMAL;
318 break; 327 break;
319 } 328 }
320 329
321 return AppendMenuItemImpl(id, label, icon, type); 330 return AppendMenuItemImpl(id, label, icon, type, separator_style);
322 } 331 }
323 332
324 MenuItemView* MenuItemView::AppendMenuItemImpl(int item_id, 333 MenuItemView* MenuItemView::AppendMenuItemImpl(
325 const string16& label, 334 int item_id,
326 const gfx::ImageSkia& icon, 335 const string16& label,
327 Type type) { 336 const gfx::ImageSkia& icon,
337 Type type,
338 ui::MenuSeparatorType separator_style) {
328 const int index = submenu_ ? submenu_->child_count() : 0; 339 const int index = submenu_ ? submenu_->child_count() : 0;
329 return AddMenuItemAt(index, item_id, label, icon, type); 340 return AddMenuItemAt(index, item_id, label, icon, type, separator_style);
330 } 341 }
331 342
332 SubmenuView* MenuItemView::CreateSubmenu() { 343 SubmenuView* MenuItemView::CreateSubmenu() {
333 if (!submenu_) 344 if (!submenu_)
334 submenu_ = new SubmenuView(this); 345 submenu_ = new SubmenuView(this);
335 return submenu_; 346 return submenu_;
336 } 347 }
337 348
338 bool MenuItemView::HasSubmenu() const { 349 bool MenuItemView::HasSubmenu() const {
339 return (submenu_ != NULL); 350 return (submenu_ != NULL);
(...skipping 506 matching lines...) Expand 10 before | Expand all | Expand 10 after
846 temp_width = menu_item->GetMaxIconViewWidth(); 857 temp_width = menu_item->GetMaxIconViewWidth();
847 } else if (menu_item->icon_view()) { 858 } else if (menu_item->icon_view()) {
848 temp_width = menu_item->icon_view()->GetPreferredSize().width(); 859 temp_width = menu_item->icon_view()->GetPreferredSize().width();
849 } 860 }
850 width = std::max(width, temp_width); 861 width = std::max(width, temp_width);
851 } 862 }
852 return width; 863 return width;
853 } 864 }
854 865
855 } // namespace views 866 } // namespace views
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698