OLD | NEW |
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 Loading... |
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 Loading... |
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 return delegate->GetLabelFont(GetCommand()); |
| 592 else |
| 593 return MenuConfig::instance().font; |
| 594 } |
| 595 |
587 void MenuItemView::AddEmptyMenus() { | 596 void MenuItemView::AddEmptyMenus() { |
588 DCHECK(HasSubmenu()); | 597 DCHECK(HasSubmenu()); |
589 if (!submenu_->has_children()) { | 598 if (!submenu_->has_children()) { |
590 submenu_->AddChildViewAt(new EmptyMenuMenuItem(this), 0); | 599 submenu_->AddChildViewAt(new EmptyMenuMenuItem(this), 0); |
591 } else { | 600 } else { |
592 for (int i = 0, item_count = submenu_->GetMenuItemCount(); i < item_count; | 601 for (int i = 0, item_count = submenu_->GetMenuItemCount(); i < item_count; |
593 ++i) { | 602 ++i) { |
594 MenuItemView* child = submenu_->GetMenuItemAt(i); | 603 MenuItemView* child = submenu_->GetMenuItemAt(i); |
595 if (child->HasSubmenu()) | 604 if (child->HasSubmenu()) |
596 child->AddEmptyMenus(); | 605 child->AddEmptyMenus(); |
(...skipping 19 matching lines...) Expand all Loading... |
616 | 625 |
617 void MenuItemView::AdjustBoundsForRTLUI(gfx::Rect* rect) const { | 626 void MenuItemView::AdjustBoundsForRTLUI(gfx::Rect* rect) const { |
618 rect->set_x(GetMirroredXForRect(*rect)); | 627 rect->set_x(GetMirroredXForRect(*rect)); |
619 } | 628 } |
620 | 629 |
621 void MenuItemView::PaintAccelerator(gfx::Canvas* canvas) { | 630 void MenuItemView::PaintAccelerator(gfx::Canvas* canvas) { |
622 string16 accel_text = GetAcceleratorText(); | 631 string16 accel_text = GetAcceleratorText(); |
623 if (accel_text.empty()) | 632 if (accel_text.empty()) |
624 return; | 633 return; |
625 | 634 |
626 const gfx::Font& font = MenuConfig::instance().font; | 635 const gfx::Font& font = GetFont(); |
627 int available_height = height() - GetTopMargin() - GetBottomMargin(); | 636 int available_height = height() - GetTopMargin() - GetBottomMargin(); |
628 int max_accel_width = | 637 int max_accel_width = |
629 parent_menu_item_->GetSubmenu()->max_accelerator_width(); | 638 parent_menu_item_->GetSubmenu()->max_accelerator_width(); |
630 gfx::Rect accel_bounds(width() - item_right_margin_ - max_accel_width, | 639 gfx::Rect accel_bounds(width() - item_right_margin_ - max_accel_width, |
631 GetTopMargin(), max_accel_width, available_height); | 640 GetTopMargin(), max_accel_width, available_height); |
632 accel_bounds.set_x(GetMirroredXForRect(accel_bounds)); | 641 accel_bounds.set_x(GetMirroredXForRect(accel_bounds)); |
633 int flags = GetRootMenuItem()->GetDrawStringFlags() | | 642 int flags = GetRootMenuItem()->GetDrawStringFlags() | |
634 gfx::Canvas::TEXT_VALIGN_MIDDLE; | 643 gfx::Canvas::TEXT_VALIGN_MIDDLE; |
635 flags &= ~(gfx::Canvas::TEXT_ALIGN_RIGHT | gfx::Canvas::TEXT_ALIGN_LEFT); | 644 flags &= ~(gfx::Canvas::TEXT_ALIGN_RIGHT | gfx::Canvas::TEXT_ALIGN_LEFT); |
636 if (base::i18n::IsRTL()) | 645 if (base::i18n::IsRTL()) |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
682 } | 691 } |
683 | 692 |
684 string16 MenuItemView::GetAcceleratorText() { | 693 string16 MenuItemView::GetAcceleratorText() { |
685 Accelerator accelerator; | 694 Accelerator accelerator; |
686 return (GetDelegate() && | 695 return (GetDelegate() && |
687 GetDelegate()->GetAccelerator(GetCommand(), &accelerator)) ? | 696 GetDelegate()->GetAccelerator(GetCommand(), &accelerator)) ? |
688 accelerator.GetShortcutText() : string16(); | 697 accelerator.GetShortcutText() : string16(); |
689 } | 698 } |
690 | 699 |
691 } // namespace views | 700 } // namespace views |
OLD | NEW |