| 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 <stddef.h> | 7 #include <stddef.h> |
| 8 | 8 |
| 9 #include "base/i18n/case_conversion.h" | 9 #include "base/i18n/case_conversion.h" |
| 10 #include "base/macros.h" | 10 #include "base/macros.h" |
| 11 #include "base/stl_util.h" | |
| 12 #include "base/strings/utf_string_conversions.h" | 11 #include "base/strings/utf_string_conversions.h" |
| 13 #include "ui/accessibility/ax_view_state.h" | 12 #include "ui/accessibility/ax_view_state.h" |
| 14 #include "ui/base/l10n/l10n_util.h" | 13 #include "ui/base/l10n/l10n_util.h" |
| 15 #include "ui/base/models/menu_model.h" | 14 #include "ui/base/models/menu_model.h" |
| 16 #include "ui/gfx/canvas.h" | 15 #include "ui/gfx/canvas.h" |
| 17 #include "ui/gfx/color_utils.h" | 16 #include "ui/gfx/color_utils.h" |
| 18 #include "ui/gfx/geometry/rect.h" | 17 #include "ui/gfx/geometry/rect.h" |
| 19 #include "ui/gfx/geometry/vector2d.h" | 18 #include "ui/gfx/geometry/vector2d.h" |
| 20 #include "ui/gfx/image/image.h" | 19 #include "ui/gfx/image/image.h" |
| 21 #include "ui/gfx/text_utils.h" | 20 #include "ui/gfx/text_utils.h" |
| (...skipping 496 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 518 // Force a paint and layout. This handles the case of the top | 517 // Force a paint and layout. This handles the case of the top |
| 519 // level window's size remaining the same, resulting in no | 518 // level window's size remaining the same, resulting in no |
| 520 // change to the submenu's size and no layout. | 519 // change to the submenu's size and no layout. |
| 521 submenu_->Layout(); | 520 submenu_->Layout(); |
| 522 submenu_->SchedulePaint(); | 521 submenu_->SchedulePaint(); |
| 523 // Update the menu selection after layout. | 522 // Update the menu selection after layout. |
| 524 controller->UpdateSubmenuSelection(submenu_); | 523 controller->UpdateSubmenuSelection(submenu_); |
| 525 } | 524 } |
| 526 } | 525 } |
| 527 | 526 |
| 528 base::STLDeleteElements(&removed_items_); | 527 for (auto item : removed_items_) |
| 528 delete item; |
| 529 removed_items_.clear(); |
| 529 } | 530 } |
| 530 | 531 |
| 531 void MenuItemView::Layout() { | 532 void MenuItemView::Layout() { |
| 532 if (!has_children()) | 533 if (!has_children()) |
| 533 return; | 534 return; |
| 534 | 535 |
| 535 if (IsContainer()) { | 536 if (IsContainer()) { |
| 536 View* child = child_at(0); | 537 View* child = child_at(0); |
| 537 gfx::Size size = child->GetPreferredSize(); | 538 gfx::Size size = child->GetPreferredSize(); |
| 538 child->SetBounds(0, GetTopMargin(), size.width(), size.height()); | 539 child->SetBounds(0, GetTopMargin(), size.width(), size.height()); |
| (...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 591 left_icon_margin_(0), | 592 left_icon_margin_(0), |
| 592 right_icon_margin_(0), | 593 right_icon_margin_(0), |
| 593 requested_menu_position_(POSITION_BEST_FIT), | 594 requested_menu_position_(POSITION_BEST_FIT), |
| 594 actual_menu_position_(requested_menu_position_), | 595 actual_menu_position_(requested_menu_position_), |
| 595 use_right_margin_(true) { | 596 use_right_margin_(true) { |
| 596 Init(parent, command, type, NULL); | 597 Init(parent, command, type, NULL); |
| 597 } | 598 } |
| 598 | 599 |
| 599 MenuItemView::~MenuItemView() { | 600 MenuItemView::~MenuItemView() { |
| 600 delete submenu_; | 601 delete submenu_; |
| 601 base::STLDeleteElements(&removed_items_); | 602 for (auto item : removed_items_) |
| 603 delete item; |
| 602 } | 604 } |
| 603 | 605 |
| 604 const char* MenuItemView::GetClassName() const { | 606 const char* MenuItemView::GetClassName() const { |
| 605 return kViewClassName; | 607 return kViewClassName; |
| 606 } | 608 } |
| 607 | 609 |
| 608 // Calculates all sizes that we can from the OS. | 610 // Calculates all sizes that we can from the OS. |
| 609 // | 611 // |
| 610 // This is invoked prior to Running a menu. | 612 // This is invoked prior to Running a menu. |
| 611 void MenuItemView::UpdateMenuPartSizes() { | 613 void MenuItemView::UpdateMenuPartSizes() { |
| (...skipping 464 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1076 } else { | 1078 } else { |
| 1077 const Type& type = menu_item->GetType(); | 1079 const Type& type = menu_item->GetType(); |
| 1078 if (type == CHECKBOX || type == RADIO) | 1080 if (type == CHECKBOX || type == RADIO) |
| 1079 return true; | 1081 return true; |
| 1080 } | 1082 } |
| 1081 } | 1083 } |
| 1082 return false; | 1084 return false; |
| 1083 } | 1085 } |
| 1084 | 1086 |
| 1085 } // namespace views | 1087 } // namespace views |
| OLD | NEW |