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 "ui/accessibility/ax_view_state.h" | 10 #include "ui/accessibility/ax_view_state.h" |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 52 bool GetTooltipText(const gfx::Point& p, | 52 bool GetTooltipText(const gfx::Point& p, |
| 53 base::string16* tooltip) const override { | 53 base::string16* tooltip) const override { |
| 54 // Empty menu items shouldn't have a tooltip. | 54 // Empty menu items shouldn't have a tooltip. |
| 55 return false; | 55 return false; |
| 56 } | 56 } |
| 57 | 57 |
| 58 private: | 58 private: |
| 59 DISALLOW_COPY_AND_ASSIGN(EmptyMenuMenuItem); | 59 DISALLOW_COPY_AND_ASSIGN(EmptyMenuMenuItem); |
| 60 }; | 60 }; |
| 61 | 61 |
| 62 // Helper that returns a reference to the MenuConfig to be used with menus. | |
| 63 const MenuConfig& GetMenuConfig() { | |
| 64 return MenuConfig::instance(); | |
|
Evan Stade
2015/12/07 19:51:42
inline this instead of having a helper?
tapted
2015/12/08 11:49:23
Done. I thought it would be a lot of churn, but I
| |
| 65 } | |
| 66 | |
| 62 } // namespace | 67 } // namespace |
| 63 | 68 |
| 64 // Padding between child views. | 69 // Padding between child views. |
| 65 static const int kChildXPadding = 8; | 70 static const int kChildXPadding = 8; |
| 66 | 71 |
| 67 // MenuItemView --------------------------------------------------------------- | 72 // MenuItemView --------------------------------------------------------------- |
| 68 | 73 |
| 69 // static | 74 // static |
| 70 const int MenuItemView::kMenuItemViewID = 1001; | 75 const int MenuItemView::kMenuItemViewID = 1001; |
| 71 | 76 |
| (...skipping 161 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 233 const base::string16& minor_text, | 238 const base::string16& minor_text, |
| 234 const gfx::ImageSkia& icon, | 239 const gfx::ImageSkia& icon, |
| 235 Type type, | 240 Type type, |
| 236 ui::MenuSeparatorType separator_style) { | 241 ui::MenuSeparatorType separator_style) { |
| 237 DCHECK_NE(type, EMPTY); | 242 DCHECK_NE(type, EMPTY); |
| 238 DCHECK_LE(0, index); | 243 DCHECK_LE(0, index); |
| 239 if (!submenu_) | 244 if (!submenu_) |
| 240 CreateSubmenu(); | 245 CreateSubmenu(); |
| 241 DCHECK_GE(submenu_->child_count(), index); | 246 DCHECK_GE(submenu_->child_count(), index); |
| 242 if (type == SEPARATOR) { | 247 if (type == SEPARATOR) { |
| 243 submenu_->AddChildViewAt(new MenuSeparator(this, separator_style), index); | 248 submenu_->AddChildViewAt(new MenuSeparator(separator_style), index); |
| 244 return NULL; | 249 return NULL; |
| 245 } | 250 } |
| 246 MenuItemView* item = new MenuItemView(this, item_id, type); | 251 MenuItemView* item = new MenuItemView(this, item_id, type); |
| 247 if (label.empty() && GetDelegate()) | 252 if (label.empty() && GetDelegate()) |
| 248 item->SetTitle(GetDelegate()->GetLabel(item_id)); | 253 item->SetTitle(GetDelegate()->GetLabel(item_id)); |
| 249 else | 254 else |
| 250 item->SetTitle(label); | 255 item->SetTitle(label); |
| 251 item->SetSubtitle(sublabel); | 256 item->SetSubtitle(sublabel); |
| 252 item->SetMinorText(minor_text); | 257 item->SetMinorText(minor_text); |
| 253 if (!icon.isNull()) | 258 if (!icon.isNull()) |
| (...skipping 306 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 560 } | 565 } |
| 561 } | 566 } |
| 562 | 567 |
| 563 void MenuItemView::SetMargins(int top_margin, int bottom_margin) { | 568 void MenuItemView::SetMargins(int top_margin, int bottom_margin) { |
| 564 top_margin_ = top_margin; | 569 top_margin_ = top_margin; |
| 565 bottom_margin_ = bottom_margin; | 570 bottom_margin_ = bottom_margin; |
| 566 | 571 |
| 567 invalidate_dimensions(); | 572 invalidate_dimensions(); |
| 568 } | 573 } |
| 569 | 574 |
| 570 const MenuConfig& MenuItemView::GetMenuConfig() const { | |
| 571 return MenuConfig::instance(GetNativeTheme()); | |
| 572 } | |
| 573 | |
| 574 MenuItemView::MenuItemView(MenuItemView* parent, | 575 MenuItemView::MenuItemView(MenuItemView* parent, |
| 575 int command, | 576 int command, |
| 576 MenuItemView::Type type) | 577 MenuItemView::Type type) |
| 577 : delegate_(NULL), | 578 : delegate_(NULL), |
| 578 controller_(NULL), | 579 controller_(NULL), |
| 579 canceled_(false), | 580 canceled_(false), |
| 580 parent_menu_item_(parent), | 581 parent_menu_item_(parent), |
| 581 type_(type), | 582 type_(type), |
| 582 selected_(false), | 583 selected_(false), |
| 583 command_(command), | 584 command_(command), |
| (...skipping 487 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1071 } else { | 1072 } else { |
| 1072 const Type& type = menu_item->GetType(); | 1073 const Type& type = menu_item->GetType(); |
| 1073 if (type == CHECKBOX || type == RADIO) | 1074 if (type == CHECKBOX || type == RADIO) |
| 1074 return true; | 1075 return true; |
| 1075 } | 1076 } |
| 1076 } | 1077 } |
| 1077 return false; | 1078 return false; |
| 1078 } | 1079 } |
| 1079 | 1080 |
| 1080 } // namespace views | 1081 } // namespace views |
| OLD | NEW |