| 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/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 185 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 196 void MenuItemView::Cancel() { | 196 void MenuItemView::Cancel() { |
| 197 if (controller_ && !canceled_) { | 197 if (controller_ && !canceled_) { |
| 198 canceled_ = true; | 198 canceled_ = true; |
| 199 controller_->Cancel(MenuController::EXIT_ALL); | 199 controller_->Cancel(MenuController::EXIT_ALL); |
| 200 } | 200 } |
| 201 } | 201 } |
| 202 | 202 |
| 203 MenuItemView* MenuItemView::AddMenuItemAt(int index, | 203 MenuItemView* MenuItemView::AddMenuItemAt(int index, |
| 204 int item_id, | 204 int item_id, |
| 205 const string16& label, | 205 const string16& label, |
| 206 const SkBitmap& icon, | 206 const gfx::ImageSkia& icon, |
| 207 Type type) { | 207 Type type) { |
| 208 DCHECK_NE(type, EMPTY); | 208 DCHECK_NE(type, EMPTY); |
| 209 DCHECK_LE(0, index); | 209 DCHECK_LE(0, index); |
| 210 if (!submenu_) | 210 if (!submenu_) |
| 211 CreateSubmenu(); | 211 CreateSubmenu(); |
| 212 DCHECK_GE(submenu_->child_count(), index); | 212 DCHECK_GE(submenu_->child_count(), index); |
| 213 if (type == SEPARATOR) { | 213 if (type == SEPARATOR) { |
| 214 submenu_->AddChildViewAt(new MenuSeparator(), index); | 214 submenu_->AddChildViewAt(new MenuSeparator(), index); |
| 215 return NULL; | 215 return NULL; |
| 216 } | 216 } |
| (...skipping 20 matching lines...) Expand all Loading... |
| 237 | 237 |
| 238 // RemoveChildView() does not delete the item, which is a good thing | 238 // RemoveChildView() does not delete the item, which is a good thing |
| 239 // in case a submenu is being displayed while items are being removed. | 239 // in case a submenu is being displayed while items are being removed. |
| 240 // Deletion will be done by ChildrenChanged() or at destruction. | 240 // Deletion will be done by ChildrenChanged() or at destruction. |
| 241 removed_items_.push_back(item); | 241 removed_items_.push_back(item); |
| 242 } | 242 } |
| 243 | 243 |
| 244 MenuItemView* MenuItemView::AppendMenuItem(int item_id, | 244 MenuItemView* MenuItemView::AppendMenuItem(int item_id, |
| 245 const string16& label, | 245 const string16& label, |
| 246 Type type) { | 246 Type type) { |
| 247 return AppendMenuItemImpl(item_id, label, SkBitmap(), type); | 247 return AppendMenuItemImpl(item_id, label, gfx::ImageSkia(), type); |
| 248 } | 248 } |
| 249 | 249 |
| 250 MenuItemView* MenuItemView::AppendSubMenu(int item_id, | 250 MenuItemView* MenuItemView::AppendSubMenu(int item_id, |
| 251 const string16& label) { | 251 const string16& label) { |
| 252 return AppendMenuItemImpl(item_id, label, SkBitmap(), SUBMENU); | 252 return AppendMenuItemImpl(item_id, label, gfx::ImageSkia(), SUBMENU); |
| 253 } | 253 } |
| 254 | 254 |
| 255 MenuItemView* MenuItemView::AppendSubMenuWithIcon(int item_id, | 255 MenuItemView* MenuItemView::AppendSubMenuWithIcon(int item_id, |
| 256 const string16& label, | 256 const string16& label, |
| 257 const SkBitmap& icon) { | 257 const gfx::ImageSkia& icon) { |
| 258 return AppendMenuItemImpl(item_id, label, icon, SUBMENU); | 258 return AppendMenuItemImpl(item_id, label, icon, SUBMENU); |
| 259 } | 259 } |
| 260 | 260 |
| 261 MenuItemView* MenuItemView::AppendMenuItemWithLabel(int item_id, | 261 MenuItemView* MenuItemView::AppendMenuItemWithLabel(int item_id, |
| 262 const string16& label) { | 262 const string16& label) { |
| 263 return AppendMenuItem(item_id, label, NORMAL); | 263 return AppendMenuItem(item_id, label, NORMAL); |
| 264 } | 264 } |
| 265 | 265 |
| 266 MenuItemView* MenuItemView::AppendDelegateMenuItem(int item_id) { | 266 MenuItemView* MenuItemView::AppendDelegateMenuItem(int item_id) { |
| 267 return AppendMenuItem(item_id, string16(), NORMAL); | 267 return AppendMenuItem(item_id, string16(), NORMAL); |
| 268 } | 268 } |
| 269 | 269 |
| 270 void MenuItemView::AppendSeparator() { | 270 void MenuItemView::AppendSeparator() { |
| 271 AppendMenuItemImpl(0, string16(), SkBitmap(), SEPARATOR); | 271 AppendMenuItemImpl(0, string16(), gfx::ImageSkia(), SEPARATOR); |
| 272 } | 272 } |
| 273 | 273 |
| 274 MenuItemView* MenuItemView::AppendMenuItemWithIcon(int item_id, | 274 MenuItemView* MenuItemView::AppendMenuItemWithIcon(int item_id, |
| 275 const string16& label, | 275 const string16& label, |
| 276 const SkBitmap& icon) { | 276 const gfx::ImageSkia& icon) { |
| 277 return AppendMenuItemImpl(item_id, label, icon, NORMAL); | 277 return AppendMenuItemImpl(item_id, label, icon, NORMAL); |
| 278 } | 278 } |
| 279 | 279 |
| 280 MenuItemView* MenuItemView::AppendMenuItemFromModel(ui::MenuModel* model, | 280 MenuItemView* MenuItemView::AppendMenuItemFromModel(ui::MenuModel* model, |
| 281 int index, | 281 int index, |
| 282 int id) { | 282 int id) { |
| 283 SkBitmap icon; | 283 gfx::ImageSkia icon; |
| 284 string16 label; | 284 string16 label; |
| 285 MenuItemView::Type type; | 285 MenuItemView::Type type; |
| 286 ui::MenuModel::ItemType menu_type = model->GetTypeAt(index); | 286 ui::MenuModel::ItemType menu_type = model->GetTypeAt(index); |
| 287 switch (menu_type) { | 287 switch (menu_type) { |
| 288 case ui::MenuModel::TYPE_COMMAND: | 288 case ui::MenuModel::TYPE_COMMAND: |
| 289 model->GetIconAt(index, &icon); | 289 model->GetIconAt(index, &icon); |
| 290 type = MenuItemView::NORMAL; | 290 type = MenuItemView::NORMAL; |
| 291 label = model->GetLabelAt(index); | 291 label = model->GetLabelAt(index); |
| 292 break; | 292 break; |
| 293 case ui::MenuModel::TYPE_CHECK: | 293 case ui::MenuModel::TYPE_CHECK: |
| (...skipping 16 matching lines...) Expand all Loading... |
| 310 NOTREACHED(); | 310 NOTREACHED(); |
| 311 type = MenuItemView::NORMAL; | 311 type = MenuItemView::NORMAL; |
| 312 break; | 312 break; |
| 313 } | 313 } |
| 314 | 314 |
| 315 return AppendMenuItemImpl(id, label, icon, type); | 315 return AppendMenuItemImpl(id, label, icon, type); |
| 316 } | 316 } |
| 317 | 317 |
| 318 MenuItemView* MenuItemView::AppendMenuItemImpl(int item_id, | 318 MenuItemView* MenuItemView::AppendMenuItemImpl(int item_id, |
| 319 const string16& label, | 319 const string16& label, |
| 320 const SkBitmap& icon, | 320 const gfx::ImageSkia& icon, |
| 321 Type type) { | 321 Type type) { |
| 322 const int index = submenu_ ? submenu_->child_count() : 0; | 322 const int index = submenu_ ? submenu_->child_count() : 0; |
| 323 return AddMenuItemAt(index, item_id, label, icon, type); | 323 return AddMenuItemAt(index, item_id, label, icon, type); |
| 324 } | 324 } |
| 325 | 325 |
| 326 SubmenuView* MenuItemView::CreateSubmenu() { | 326 SubmenuView* MenuItemView::CreateSubmenu() { |
| 327 if (!submenu_) | 327 if (!submenu_) |
| 328 submenu_ = new SubmenuView(this); | 328 submenu_ = new SubmenuView(this); |
| 329 return submenu_; | 329 return submenu_; |
| 330 } | 330 } |
| (...skipping 15 matching lines...) Expand all Loading... |
| 346 selected_ = selected; | 346 selected_ = selected; |
| 347 SchedulePaint(); | 347 SchedulePaint(); |
| 348 } | 348 } |
| 349 | 349 |
| 350 void MenuItemView::SetTooltip(const string16& tooltip, int item_id) { | 350 void MenuItemView::SetTooltip(const string16& tooltip, int item_id) { |
| 351 MenuItemView* item = GetMenuItemByID(item_id); | 351 MenuItemView* item = GetMenuItemByID(item_id); |
| 352 DCHECK(item); | 352 DCHECK(item); |
| 353 item->tooltip_ = tooltip; | 353 item->tooltip_ = tooltip; |
| 354 } | 354 } |
| 355 | 355 |
| 356 void MenuItemView::SetIcon(const SkBitmap& icon, int item_id) { | 356 void MenuItemView::SetIcon(const gfx::ImageSkia& icon, int item_id) { |
| 357 MenuItemView* item = GetMenuItemByID(item_id); | 357 MenuItemView* item = GetMenuItemByID(item_id); |
| 358 DCHECK(item); | 358 DCHECK(item); |
| 359 item->SetIcon(icon); | 359 item->SetIcon(icon); |
| 360 } | 360 } |
| 361 | 361 |
| 362 void MenuItemView::SetIcon(const SkBitmap& icon) { | 362 void MenuItemView::SetIcon(const gfx::ImageSkia& icon) { |
| 363 icon_ = icon; | 363 icon_ = icon; |
| 364 SchedulePaint(); | 364 SchedulePaint(); |
| 365 } | 365 } |
| 366 | 366 |
| 367 void MenuItemView::OnPaint(gfx::Canvas* canvas) { | 367 void MenuItemView::OnPaint(gfx::Canvas* canvas) { |
| 368 PaintButton(canvas, PB_NORMAL); | 368 PaintButton(canvas, PB_NORMAL); |
| 369 } | 369 } |
| 370 | 370 |
| 371 gfx::Size MenuItemView::GetPreferredSize() { | 371 gfx::Size MenuItemView::GetPreferredSize() { |
| 372 if (pref_size_.IsEmpty()) | 372 if (pref_size_.IsEmpty()) |
| (...skipping 404 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 777 } | 777 } |
| 778 | 778 |
| 779 bool MenuItemView::IsContainer() const { | 779 bool MenuItemView::IsContainer() const { |
| 780 // Let the first child take over |this| when we only have one child and no | 780 // Let the first child take over |this| when we only have one child and no |
| 781 // title. Note that what child_count() returns is the number of children, | 781 // title. Note that what child_count() returns is the number of children, |
| 782 // not the number of menu items. | 782 // not the number of menu items. |
| 783 return child_count() == 1 && title_.empty(); | 783 return child_count() == 1 && title_.empty(); |
| 784 } | 784 } |
| 785 | 785 |
| 786 } // namespace views | 786 } // namespace views |
| OLD | NEW |