Chromium Code Reviews| 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/strings/utf_string_conversions.h" | 9 #include "base/strings/utf_string_conversions.h" |
| 10 #include "grit/ui_resources.h" | 10 #include "grit/ui_resources.h" |
| (...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 100 has_mnemonics_(false), | 100 has_mnemonics_(false), |
| 101 show_mnemonics_(false), | 101 show_mnemonics_(false), |
| 102 has_icons_(false), | 102 has_icons_(false), |
| 103 icon_view_(NULL), | 103 icon_view_(NULL), |
| 104 top_margin_(-1), | 104 top_margin_(-1), |
| 105 bottom_margin_(-1), | 105 bottom_margin_(-1), |
| 106 left_icon_margin_(0), | 106 left_icon_margin_(0), |
| 107 right_icon_margin_(0), | 107 right_icon_margin_(0), |
| 108 requested_menu_position_(POSITION_BEST_FIT), | 108 requested_menu_position_(POSITION_BEST_FIT), |
| 109 actual_menu_position_(requested_menu_position_), | 109 actual_menu_position_(requested_menu_position_), |
| 110 use_right_margin_(true) { | 110 use_right_margin_(true), |
| 111 lifecycle_observer_(NULL) { | |
| 111 // NOTE: don't check the delegate for NULL, UpdateMenuPartSizes() supplies a | 112 // NOTE: don't check the delegate for NULL, UpdateMenuPartSizes() supplies a |
| 112 // NULL delegate. | 113 // NULL delegate. |
| 113 Init(NULL, 0, SUBMENU, delegate); | 114 Init(NULL, 0, SUBMENU, delegate); |
| 114 } | 115 } |
| 115 | 116 |
| 116 void MenuItemView::ChildPreferredSizeChanged(View* child) { | 117 void MenuItemView::ChildPreferredSizeChanged(View* child) { |
| 117 invalidate_dimensions(); | 118 invalidate_dimensions(); |
| 118 PreferredSizeChanged(); | 119 PreferredSizeChanged(); |
| 119 } | 120 } |
| 120 | 121 |
| (...skipping 431 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 552 invalidate_dimensions(); | 553 invalidate_dimensions(); |
| 553 } | 554 } |
| 554 | 555 |
| 555 const MenuConfig& MenuItemView::GetMenuConfig() const { | 556 const MenuConfig& MenuItemView::GetMenuConfig() const { |
| 556 const MenuController* controller = GetMenuController(); | 557 const MenuController* controller = GetMenuController(); |
| 557 if (controller) | 558 if (controller) |
| 558 return controller->menu_config_; | 559 return controller->menu_config_; |
| 559 return MenuConfig::instance(NULL); | 560 return MenuConfig::instance(NULL); |
| 560 } | 561 } |
| 561 | 562 |
| 562 MenuItemView::MenuItemView(MenuItemView* parent, | 563 MenuItemView::MenuItemView(MenuItemView* parent, |
|
Finnur
2014/02/12 11:19:52
Can you add a comment saying:
// Note: This class
| |
| 563 int command, | 564 int command, |
| 564 MenuItemView::Type type) | 565 MenuItemView::Type type) |
| 565 : delegate_(NULL), | 566 : delegate_(NULL), |
| 566 controller_(NULL), | 567 controller_(NULL), |
| 567 canceled_(false), | 568 canceled_(false), |
| 568 parent_menu_item_(parent), | 569 parent_menu_item_(parent), |
| 569 type_(type), | 570 type_(type), |
| 570 selected_(false), | 571 selected_(false), |
| 571 command_(command), | 572 command_(command), |
| 572 submenu_(NULL), | 573 submenu_(NULL), |
| 573 has_mnemonics_(false), | 574 has_mnemonics_(false), |
| 574 show_mnemonics_(false), | 575 show_mnemonics_(false), |
| 575 has_icons_(false), | 576 has_icons_(false), |
| 576 icon_view_(NULL), | 577 icon_view_(NULL), |
| 577 top_margin_(-1), | 578 top_margin_(-1), |
| 578 bottom_margin_(-1), | 579 bottom_margin_(-1), |
| 579 left_icon_margin_(0), | 580 left_icon_margin_(0), |
| 580 right_icon_margin_(0), | 581 right_icon_margin_(0), |
| 581 requested_menu_position_(POSITION_BEST_FIT), | 582 requested_menu_position_(POSITION_BEST_FIT), |
| 582 actual_menu_position_(requested_menu_position_), | 583 actual_menu_position_(requested_menu_position_), |
| 583 use_right_margin_(true) { | 584 use_right_margin_(true) { |
| 584 Init(parent, command, type, NULL); | 585 Init(parent, command, type, NULL); |
| 585 } | 586 } |
| 586 | 587 |
| 587 MenuItemView::~MenuItemView() { | 588 MenuItemView::~MenuItemView() { |
| 588 delete submenu_; | 589 delete submenu_; |
| 589 STLDeleteElements(&removed_items_); | 590 STLDeleteElements(&removed_items_); |
| 591 if (lifecycle_observer_) | |
| 592 lifecycle_observer_->OnDeleted(this); | |
| 590 } | 593 } |
| 591 | 594 |
| 592 const char* MenuItemView::GetClassName() const { | 595 const char* MenuItemView::GetClassName() const { |
| 593 return kViewClassName; | 596 return kViewClassName; |
| 594 } | 597 } |
| 595 | 598 |
| 596 // Calculates all sizes that we can from the OS. | 599 // Calculates all sizes that we can from the OS. |
| 597 // | 600 // |
| 598 // This is invoked prior to Running a menu. | 601 // This is invoked prior to Running a menu. |
| 599 void MenuItemView::UpdateMenuPartSizes() { | 602 void MenuItemView::UpdateMenuPartSizes() { |
| (...skipping 18 matching lines...) Expand all Loading... | |
| 618 label_start_ += padding; | 621 label_start_ += padding; |
| 619 | 622 |
| 620 if (config.render_gutter) | 623 if (config.render_gutter) |
| 621 label_start_ += config.gutter_width + config.gutter_to_label; | 624 label_start_ += config.gutter_width + config.gutter_to_label; |
| 622 | 625 |
| 623 EmptyMenuMenuItem menu_item(this); | 626 EmptyMenuMenuItem menu_item(this); |
| 624 menu_item.set_controller(GetMenuController()); | 627 menu_item.set_controller(GetMenuController()); |
| 625 pref_menu_height_ = menu_item.GetPreferredSize().height(); | 628 pref_menu_height_ = menu_item.GetPreferredSize().height(); |
| 626 } | 629 } |
| 627 | 630 |
| 628 void MenuItemView::Init(MenuItemView* parent, | 631 void MenuItemView::Init(MenuItemView* parent, |
|
Finnur
2014/02/12 11:19:52
Can you add a comment saying:
// Note: This class
| |
| 629 int command, | 632 int command, |
| 630 MenuItemView::Type type, | 633 MenuItemView::Type type, |
| 631 MenuDelegate* delegate) { | 634 MenuDelegate* delegate) { |
| 632 delegate_ = delegate; | 635 delegate_ = delegate; |
| 633 controller_ = NULL; | 636 controller_ = NULL; |
| 634 canceled_ = false; | 637 canceled_ = false; |
| 635 parent_menu_item_ = parent; | 638 parent_menu_item_ = parent; |
| 636 type_ = type; | 639 type_ = type; |
| 637 selected_ = false; | 640 selected_ = false; |
| 638 command_ = command; | 641 command_ = command; |
| (...skipping 421 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1060 } else { | 1063 } else { |
| 1061 const Type& type = menu_item->GetType(); | 1064 const Type& type = menu_item->GetType(); |
| 1062 if (type == CHECKBOX || type == RADIO) | 1065 if (type == CHECKBOX || type == RADIO) |
| 1063 return true; | 1066 return true; |
| 1064 } | 1067 } |
| 1065 } | 1068 } |
| 1066 return false; | 1069 return false; |
| 1067 } | 1070 } |
| 1068 | 1071 |
| 1069 } // namespace views | 1072 } // namespace views |
| OLD | NEW |