diff options
author | yefim@chromium.org <yefim@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-09-14 17:32:21 +0000 |
---|---|---|
committer | yefim@chromium.org <yefim@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-09-14 17:32:21 +0000 |
commit | f3640a493bd9a0da8b6aecd817218ea2dee61a7b (patch) | |
tree | a89431d32dc20a104c62debf061b4b7b53bf6d43 | |
parent | a37394dd337ce3fc96635ebb76e5dd4accf7e80b (diff) | |
download | chromium_src-f3640a493bd9a0da8b6aecd817218ea2dee61a7b.zip chromium_src-f3640a493bd9a0da8b6aecd817218ea2dee61a7b.tar.gz chromium_src-f3640a493bd9a0da8b6aecd817218ea2dee61a7b.tar.bz2 |
Fixed position of plus image on action box button; added ICON_CENTERED placement to TextButton
BUG=147330
Committed: http://src.chromium.org/viewvc/chrome?view=rev&revision=156599
Review URL: https://chromiumcodereview.appspot.com/10933049
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@156824 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r-- | chrome/browser/ui/views/location_bar/action_box_button_view.cc | 1 | ||||
-rw-r--r-- | ui/views/controls/button/text_button.cc | 9 | ||||
-rw-r--r-- | ui/views/controls/button/text_button.h | 5 | ||||
-rw-r--r-- | ui/views/examples/button_example.cc | 3 |
4 files changed, 14 insertions, 4 deletions
diff --git a/chrome/browser/ui/views/location_bar/action_box_button_view.cc b/chrome/browser/ui/views/location_bar/action_box_button_view.cc index 98f1700..5b3abc7 100644 --- a/chrome/browser/ui/views/location_bar/action_box_button_view.cc +++ b/chrome/browser/ui/views/location_bar/action_box_button_view.cc @@ -35,6 +35,7 @@ ActionBoxButtonView::ActionBoxButtonView(Browser* browser) SetTooltipText(l10n_util::GetStringUTF16(IDS_TOOLTIP_ACTION_BOX_BUTTON)); SetIcon(*ui::ResourceBundle::GetSharedInstance().GetImageSkiaNamed( IDR_ACTION_BOX_BUTTON)); + set_icon_placement(ICON_CENTERED); set_accessibility_focusable(true); set_border(NULL); } diff --git a/ui/views/controls/button/text_button.cc b/ui/views/controls/button/text_button.cc index 1a4c4e7..93644c3 100644 --- a/ui/views/controls/button/text_button.cc +++ b/ui/views/controls/button/text_button.cc @@ -730,13 +730,16 @@ void TextButton::PaintButton(gfx::Canvas* canvas, PaintButtonMode mode) { gfx::Rect text_bounds = GetTextBounds(); int icon_x; int spacing = text_.empty() ? 0 : icon_text_spacing_; + gfx::Insets insets = GetInsets(); if (icon_placement_ == ICON_ON_LEFT) { icon_x = text_bounds.x() - icon.width() - spacing; - } else { + } else if (icon_placement_ == ICON_ON_RIGHT) { icon_x = text_bounds.right() + spacing; + } else { // ICON_CENTERED + DCHECK(text_.empty()); + icon_x = (width() - insets.width() - icon.width()) / 2 + insets.left(); } - gfx::Insets insets = GetInsets(); int available_height = height() - insets.height(); int icon_y = (available_height - icon.height()) / 2 + insets.top(); @@ -785,7 +788,7 @@ gfx::Rect TextButton::GetTextBounds() const { // Make sure the icon is always fully visible. if (icon_placement_ == ICON_ON_LEFT) { bounds.Inset(extra_width, 0, 0, 0); - } else { + } else if (icon_placement_ == ICON_ON_RIGHT) { bounds.Inset(0, 0, extra_width, 0); } } diff --git a/ui/views/controls/button/text_button.h b/ui/views/controls/button/text_button.h index 99feea6..233d791 100644 --- a/ui/views/controls/button/text_button.h +++ b/ui/views/controls/button/text_button.h @@ -328,11 +328,14 @@ class VIEWS_EXPORT TextButton : public TextButtonBase { // Meanings are reversed for right-to-left layouts. enum IconPlacement { ICON_ON_LEFT, - ICON_ON_RIGHT + ICON_ON_RIGHT, + ICON_CENTERED // Centered is valid only when text is empty. }; IconPlacement icon_placement() { return icon_placement_; } void set_icon_placement(IconPlacement icon_placement) { + // ICON_CENTERED works only when |text_| is empty. + DCHECK((icon_placement != ICON_CENTERED) || text_.empty()); icon_placement_ = icon_placement; } diff --git a/ui/views/examples/button_example.cc b/ui/views/examples/button_example.cc index 8f1c46f..ce1d6d0 100644 --- a/ui/views/examples/button_example.cc +++ b/ui/views/examples/button_example.cc @@ -77,6 +77,9 @@ void ButtonExample::ButtonPressed(Button* sender, const ui::Event& event) { case TextButton::ICON_ON_RIGHT: text_button_->set_icon_placement(TextButton::ICON_ON_LEFT); break; + case TextButton::ICON_CENTERED: + // Do nothing. + break; } } } else if (event.IsAltDown()) { |