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

Side by Side Diff: views/controls/menu/menu_item_view.cc

Issue 7057014: Variety of tweaks to View API. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: Created 9 years, 7 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) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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 "views/controls/menu/menu_item_view.h" 5 #include "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-inl.h" 8 #include "base/stl_util-inl.h"
9 #include "base/utf_string_conversions.h" 9 #include "base/utf_string_conversions.h"
10 #include "grit/app_strings.h" 10 #include "grit/app_strings.h"
(...skipping 22 matching lines...) Expand all
33 // is itself a MenuItemView, but it uses a different ID so that it isn't 33 // is itself a MenuItemView, but it uses a different ID so that it isn't
34 // identified as a MenuItemView. 34 // identified as a MenuItemView.
35 35
36 class EmptyMenuMenuItem : public MenuItemView { 36 class EmptyMenuMenuItem : public MenuItemView {
37 public: 37 public:
38 explicit EmptyMenuMenuItem(MenuItemView* parent) 38 explicit EmptyMenuMenuItem(MenuItemView* parent)
39 : MenuItemView(parent, 0, NORMAL) { 39 : MenuItemView(parent, 0, NORMAL) {
40 SetTitle(UTF16ToWide( 40 SetTitle(UTF16ToWide(
41 l10n_util::GetStringUTF16(IDS_APP_MENU_EMPTY_SUBMENU))); 41 l10n_util::GetStringUTF16(IDS_APP_MENU_EMPTY_SUBMENU)));
42 // Set this so that we're not identified as a normal menu item. 42 // Set this so that we're not identified as a normal menu item.
43 SetID(kEmptyMenuItemViewID); 43 set_id(kEmptyMenuItemViewID);
44 SetEnabled(false); 44 SetEnabled(false);
45 } 45 }
46 46
47 virtual bool GetTooltipText(const gfx::Point& p, std::wstring* tooltip) { 47 virtual bool GetTooltipText(const gfx::Point& p, std::wstring* tooltip) {
48 // Empty menu items shouldn't have a tooltip. 48 // Empty menu items shouldn't have a tooltip.
49 return false; 49 return false;
50 } 50 }
51 51
52 private: 52 private:
53 DISALLOW_COPY_AND_ASSIGN(EmptyMenuMenuItem); 53 DISALLOW_COPY_AND_ASSIGN(EmptyMenuMenuItem);
(...skipping 380 matching lines...) Expand 10 before | Expand all | Expand 10 after
434 return 0; 434 return 0;
435 } 435 }
436 436
437 MenuItemView* MenuItemView::GetMenuItemByID(int id) { 437 MenuItemView* MenuItemView::GetMenuItemByID(int id) {
438 if (GetCommand() == id) 438 if (GetCommand() == id)
439 return this; 439 return this;
440 if (!HasSubmenu()) 440 if (!HasSubmenu())
441 return NULL; 441 return NULL;
442 for (int i = 0; i < GetSubmenu()->child_count(); ++i) { 442 for (int i = 0; i < GetSubmenu()->child_count(); ++i) {
443 View* child = GetSubmenu()->GetChildViewAt(i); 443 View* child = GetSubmenu()->GetChildViewAt(i);
444 if (child->GetID() == MenuItemView::kMenuItemViewID) { 444 if (child->id() == MenuItemView::kMenuItemViewID) {
445 MenuItemView* result = static_cast<MenuItemView*>(child)-> 445 MenuItemView* result = static_cast<MenuItemView*>(child)->
446 GetMenuItemByID(id); 446 GetMenuItemByID(id);
447 if (result) 447 if (result)
448 return result; 448 return result;
449 } 449 }
450 } 450 }
451 return NULL; 451 return NULL;
452 } 452 }
453 453
454 void MenuItemView::ChildrenChanged() { 454 void MenuItemView::ChildrenChanged() {
(...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after
548 delegate_ = delegate; 548 delegate_ = delegate;
549 controller_ = NULL; 549 controller_ = NULL;
550 canceled_ = false; 550 canceled_ = false;
551 parent_menu_item_ = parent; 551 parent_menu_item_ = parent;
552 type_ = type; 552 type_ = type;
553 selected_ = false; 553 selected_ = false;
554 command_ = command; 554 command_ = command;
555 submenu_ = NULL; 555 submenu_ = NULL;
556 show_mnemonics_ = false; 556 show_mnemonics_ = false;
557 // Assign our ID, this allows SubmenuItemView to find MenuItemViews. 557 // Assign our ID, this allows SubmenuItemView to find MenuItemViews.
558 SetID(kMenuItemViewID); 558 set_id(kMenuItemViewID);
559 has_icons_ = false; 559 has_icons_ = false;
560 560
561 MenuDelegate* root_delegate = GetDelegate(); 561 MenuDelegate* root_delegate = GetDelegate();
562 if (root_delegate) 562 if (root_delegate)
563 SetEnabled(root_delegate->IsCommandEnabled(command)); 563 SetEnabled(root_delegate->IsCommandEnabled(command));
564 } 564 }
565 565
566 void MenuItemView::DropMenuClosed(bool notify_delegate) { 566 void MenuItemView::DropMenuClosed(bool notify_delegate) {
567 DCHECK(controller_); 567 DCHECK(controller_);
568 DCHECK(!controller_->IsBlockingRun()); 568 DCHECK(!controller_->IsBlockingRun());
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after
641 } 641 }
642 } 642 }
643 } 643 }
644 644
645 void MenuItemView::RemoveEmptyMenus() { 645 void MenuItemView::RemoveEmptyMenus() {
646 DCHECK(HasSubmenu()); 646 DCHECK(HasSubmenu());
647 // Iterate backwards as we may end up removing views, which alters the child 647 // Iterate backwards as we may end up removing views, which alters the child
648 // view count. 648 // view count.
649 for (int i = submenu_->child_count() - 1; i >= 0; --i) { 649 for (int i = submenu_->child_count() - 1; i >= 0; --i) {
650 View* child = submenu_->GetChildViewAt(i); 650 View* child = submenu_->GetChildViewAt(i);
651 if (child->GetID() == MenuItemView::kMenuItemViewID) { 651 if (child->id() == MenuItemView::kMenuItemViewID) {
652 MenuItemView* menu_item = static_cast<MenuItemView*>(child); 652 MenuItemView* menu_item = static_cast<MenuItemView*>(child);
653 if (menu_item->HasSubmenu()) 653 if (menu_item->HasSubmenu())
654 menu_item->RemoveEmptyMenus(); 654 menu_item->RemoveEmptyMenus();
655 } else if (child->GetID() == EmptyMenuMenuItem::kEmptyMenuItemViewID) { 655 } else if (child->id() == EmptyMenuMenuItem::kEmptyMenuItemViewID) {
656 submenu_->RemoveChildView(child); 656 submenu_->RemoveChildView(child);
657 delete child; 657 delete child;
658 child = NULL; 658 child = NULL;
659 } 659 }
660 } 660 }
661 } 661 }
662 662
663 void MenuItemView::AdjustBoundsForRTLUI(gfx::Rect* rect) const { 663 void MenuItemView::AdjustBoundsForRTLUI(gfx::Rect* rect) const {
664 rect->set_x(GetMirroredXForRect(*rect)); 664 rect->set_x(GetMirroredXForRect(*rect));
665 } 665 }
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after
728 } 728 }
729 729
730 string16 MenuItemView::GetAcceleratorText() { 730 string16 MenuItemView::GetAcceleratorText() {
731 Accelerator accelerator; 731 Accelerator accelerator;
732 return (GetDelegate() && 732 return (GetDelegate() &&
733 GetDelegate()->GetAccelerator(GetCommand(), &accelerator)) ? 733 GetDelegate()->GetAccelerator(GetCommand(), &accelerator)) ?
734 accelerator.GetShortcutText() : string16(); 734 accelerator.GetShortcutText() : string16();
735 } 735 }
736 736
737 } // namespace views 737 } // namespace views
OLDNEW
« no previous file with comments | « views/controls/menu/menu_controller.cc ('k') | views/controls/menu/menu_scroll_view_container.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698