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

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

Issue 6811025: Change status button menu implementation from Menu2 to MenuItemView. (Closed) Base URL: http://git.chromium.org/git/chromium.git@trunk
Patch Set: Changed refcount guard to use OS_CHROMEOS. Created 9 years, 8 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) 2010 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/utf_string_conversions.h" 7 #include "base/utf_string_conversions.h"
8 #include "grit/app_strings.h" 8 #include "grit/app_strings.h"
9 #include "ui/base/accessibility/accessible_view_state.h" 9 #include "ui/base/accessibility/accessible_view_state.h"
10 #include "ui/base/l10n/l10n_util.h" 10 #include "ui/base/l10n/l10n_util.h"
11 #include "ui/base/models/menu_model.h" 11 #include "ui/base/models/menu_model.h"
(...skipping 437 matching lines...) Expand 10 before | Expand all | Expand 10 after
449 --i) { 449 --i) {
450 View* child = GetChildViewAt(i); 450 View* child = GetChildViewAt(i);
451 int width = child->GetPreferredSize().width(); 451 int width = child->GetPreferredSize().width();
452 child->SetBounds(x - width, 0, width, height()); 452 child->SetBounds(x - width, 0, width, height());
453 x -= width - kChildXPadding; 453 x -= width - kChildXPadding;
454 } 454 }
455 } 455 }
456 456
457 int MenuItemView::GetAcceleratorTextWidth() { 457 int MenuItemView::GetAcceleratorTextWidth() {
458 string16 text = GetAcceleratorText(); 458 string16 text = GetAcceleratorText();
459 return text.empty() ? 0 : MenuConfig::instance().font.GetStringWidth(text); 459 return text.empty() ? 0 : GetFont()->GetStringWidth(text);
460 } 460 }
461 461
462 MenuItemView::MenuItemView(MenuItemView* parent, 462 MenuItemView::MenuItemView(MenuItemView* parent,
463 int command, 463 int command,
464 MenuItemView::Type type) 464 MenuItemView::Type type)
465 : delegate_(NULL), 465 : delegate_(NULL),
466 controller_(NULL), 466 controller_(NULL),
467 canceled_(false), 467 canceled_(false),
468 parent_menu_item_(parent), 468 parent_menu_item_(parent),
469 type_(type), 469 type_(type),
(...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after
577 if (MenuConfig::instance().show_mnemonics || 577 if (MenuConfig::instance().show_mnemonics ||
578 GetRootMenuItem()->show_mnemonics_) { 578 GetRootMenuItem()->show_mnemonics_) {
579 flags |= gfx::Canvas::SHOW_PREFIX; 579 flags |= gfx::Canvas::SHOW_PREFIX;
580 } else { 580 } else {
581 flags |= gfx::Canvas::HIDE_PREFIX; 581 flags |= gfx::Canvas::HIDE_PREFIX;
582 } 582 }
583 } 583 }
584 return flags; 584 return flags;
585 } 585 }
586 586
587 const gfx::Font* MenuItemView::GetFont() {
588 // Check for item-specific font.
589 const MenuDelegate* delegate = GetDelegate();
590 if (delegate)
591 {
oshima 2011/04/14 17:27:31 move { to previous line
rhashimoto 2011/04/14 18:27:04 Done.
592 const gfx::Font* font = delegate->GetLabelFont(GetCommand());
593 if (font)
594 return font;
595 }
596
597 return &MenuConfig::instance().font;
598 }
599
587 void MenuItemView::AddEmptyMenus() { 600 void MenuItemView::AddEmptyMenus() {
588 DCHECK(HasSubmenu()); 601 DCHECK(HasSubmenu());
589 if (!submenu_->has_children()) { 602 if (!submenu_->has_children()) {
590 submenu_->AddChildViewAt(new EmptyMenuMenuItem(this), 0); 603 submenu_->AddChildViewAt(new EmptyMenuMenuItem(this), 0);
591 } else { 604 } else {
592 for (int i = 0, item_count = submenu_->GetMenuItemCount(); i < item_count; 605 for (int i = 0, item_count = submenu_->GetMenuItemCount(); i < item_count;
593 ++i) { 606 ++i) {
594 MenuItemView* child = submenu_->GetMenuItemAt(i); 607 MenuItemView* child = submenu_->GetMenuItemAt(i);
595 if (child->HasSubmenu()) 608 if (child->HasSubmenu())
596 child->AddEmptyMenus(); 609 child->AddEmptyMenus();
(...skipping 19 matching lines...) Expand all
616 629
617 void MenuItemView::AdjustBoundsForRTLUI(gfx::Rect* rect) const { 630 void MenuItemView::AdjustBoundsForRTLUI(gfx::Rect* rect) const {
618 rect->set_x(GetMirroredXForRect(*rect)); 631 rect->set_x(GetMirroredXForRect(*rect));
619 } 632 }
620 633
621 void MenuItemView::PaintAccelerator(gfx::Canvas* canvas) { 634 void MenuItemView::PaintAccelerator(gfx::Canvas* canvas) {
622 string16 accel_text = GetAcceleratorText(); 635 string16 accel_text = GetAcceleratorText();
623 if (accel_text.empty()) 636 if (accel_text.empty())
624 return; 637 return;
625 638
626 const gfx::Font& font = MenuConfig::instance().font; 639 const gfx::Font* font = GetFont();
627 int available_height = height() - GetTopMargin() - GetBottomMargin(); 640 int available_height = height() - GetTopMargin() - GetBottomMargin();
628 int max_accel_width = 641 int max_accel_width =
629 parent_menu_item_->GetSubmenu()->max_accelerator_width(); 642 parent_menu_item_->GetSubmenu()->max_accelerator_width();
630 gfx::Rect accel_bounds(width() - item_right_margin_ - max_accel_width, 643 gfx::Rect accel_bounds(width() - item_right_margin_ - max_accel_width,
631 GetTopMargin(), max_accel_width, available_height); 644 GetTopMargin(), max_accel_width, available_height);
632 accel_bounds.set_x(GetMirroredXForRect(accel_bounds)); 645 accel_bounds.set_x(GetMirroredXForRect(accel_bounds));
633 int flags = GetRootMenuItem()->GetDrawStringFlags() | 646 int flags = GetRootMenuItem()->GetDrawStringFlags() |
634 gfx::Canvas::TEXT_VALIGN_MIDDLE; 647 gfx::Canvas::TEXT_VALIGN_MIDDLE;
635 flags &= ~(gfx::Canvas::TEXT_ALIGN_RIGHT | gfx::Canvas::TEXT_ALIGN_LEFT); 648 flags &= ~(gfx::Canvas::TEXT_ALIGN_RIGHT | gfx::Canvas::TEXT_ALIGN_LEFT);
636 if (base::i18n::IsRTL()) 649 if (base::i18n::IsRTL())
637 flags |= gfx::Canvas::TEXT_ALIGN_LEFT; 650 flags |= gfx::Canvas::TEXT_ALIGN_LEFT;
638 else 651 else
639 flags |= gfx::Canvas::TEXT_ALIGN_RIGHT; 652 flags |= gfx::Canvas::TEXT_ALIGN_RIGHT;
640 canvas->DrawStringInt( 653 canvas->DrawStringInt(
641 accel_text, font, TextButton::kDisabledColor, 654 accel_text, *font, TextButton::kDisabledColor,
642 accel_bounds.x(), accel_bounds.y(), accel_bounds.width(), 655 accel_bounds.x(), accel_bounds.y(), accel_bounds.width(),
643 accel_bounds.height(), flags); 656 accel_bounds.height(), flags);
644 } 657 }
645 658
646 void MenuItemView::DestroyAllMenuHosts() { 659 void MenuItemView::DestroyAllMenuHosts() {
647 if (!HasSubmenu()) 660 if (!HasSubmenu())
648 return; 661 return;
649 662
650 submenu_->Close(); 663 submenu_->Close();
651 for (int i = 0, item_count = submenu_->GetMenuItemCount(); i < item_count; 664 for (int i = 0, item_count = submenu_->GetMenuItemCount(); i < item_count;
(...skipping 30 matching lines...) Expand all
682 } 695 }
683 696
684 string16 MenuItemView::GetAcceleratorText() { 697 string16 MenuItemView::GetAcceleratorText() {
685 Accelerator accelerator; 698 Accelerator accelerator;
686 return (GetDelegate() && 699 return (GetDelegate() &&
687 GetDelegate()->GetAccelerator(GetCommand(), &accelerator)) ? 700 GetDelegate()->GetAccelerator(GetCommand(), &accelerator)) ?
688 accelerator.GetShortcutText() : string16(); 701 accelerator.GetShortcutText() : string16();
689 } 702 }
690 703
691 } // namespace views 704 } // namespace views
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698