diff options
author | sky@chromium.org <sky@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-05-24 19:54:20 +0000 |
---|---|---|
committer | sky@chromium.org <sky@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-05-24 19:54:20 +0000 |
commit | 54a7c5ac810152fbdb3604b51933926fda79800f (patch) | |
tree | ab914dfb2916d22b3b9fb4a74b57fdc626260146 /ash | |
parent | a435560cfe442b7e735cb65cd2afdc22343c0797 (diff) | |
download | chromium_src-54a7c5ac810152fbdb3604b51933926fda79800f.zip chromium_src-54a7c5ac810152fbdb3604b51933926fda79800f.tar.gz chromium_src-54a7c5ac810152fbdb3604b51933926fda79800f.tar.bz2 |
Adjust the launcher buttons for vertical alignment. The images are
still wrong. I'll update them when I get new ones.
BUG=127583
TEST=none
R=davemoore@chromium.org
Review URL: https://chromiumcodereview.appspot.com/10423011
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@138871 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'ash')
-rw-r--r-- | ash/launcher/launcher_button.cc | 75 | ||||
-rw-r--r-- | ash/launcher/launcher_button.h | 14 | ||||
-rw-r--r-- | ash/wm/shelf_layout_manager.cc | 4 |
3 files changed, 71 insertions, 22 deletions
diff --git a/ash/launcher/launcher_button.cc b/ash/launcher/launcher_button.cc index a5a739e..c16f115 100644 --- a/ash/launcher/launcher_button.cc +++ b/ash/launcher/launcher_button.cc @@ -20,10 +20,11 @@ #include "ui/views/controls/image_view.h" namespace { -const int kBarHeight = 3; +// Size of the bar. This is along the opposite axis of the shelf. For example, +// if the shelf is aligned horizontally then this is the height of the bar. +const int kBarSize = 3; const int kBarSpacing = 5; -const int kIconHeight = 32; -const int kIconWidth = 48; +const int kIconSize = 32; const int kHopSpacing = 2; const int kActiveBarColor = 0xe6ffffff; const int kInactiveBarColor = 0x80ffffff; @@ -88,13 +89,14 @@ class LauncherButton::BarView : public views::ImageView, DISALLOW_COPY_AND_ASSIGN(BarView); }; -LauncherButton::IconView::IconView() : icon_size_(kIconHeight) { +LauncherButton::IconView::IconView() : icon_size_(kIconSize) { } LauncherButton::IconView::~IconView() { } bool LauncherButton::IconView::HitTest(const gfx::Point& l) const { + // Return false so that LauncherButton gets all the mouse events. return false; } @@ -113,8 +115,6 @@ LauncherButton::LauncherButton(views::ButtonListener* listener, bar_(new BarView), state_(STATE_NORMAL) { set_accessibility_focusable(true); - bar_->SetHorizontalAlignment(views::ImageView::CENTER); - bar_->SetVerticalAlignment(views::ImageView::TRAILING); AddChildView(bar_); } @@ -262,11 +262,25 @@ void LauncherButton::GetAccessibleState(ui::AccessibleViewState* state) { } void LauncherButton::Layout() { - int image_x = (width() - icon_view_->width()) / 2; - int image_y = height() - (icon_view_->height() + kBarHeight + kBarSpacing); + int image_x, image_y; - if (ShouldHop(state_)) - image_y -= kHopSpacing; + if (IsShelfHorizontal()) { + image_x = (width() - icon_view_->width()) / 2; + image_y = height() - (icon_view_->height() + kBarSize + kBarSpacing); + if (ShouldHop(state_)) + image_y -= kHopSpacing; + } else { + image_y = (height() - icon_view_->height()) / 2; + if (host_->GetShelfAlignment() == SHELF_ALIGNMENT_LEFT) { + image_x = kBarSize + kBarSpacing; + if (ShouldHop(state_)) + image_x += kHopSpacing; + } else { + image_x = width() - (icon_view_->width() + kBarSize + kBarSpacing); + if (ShouldHop(state_)) + image_x -= kHopSpacing; + } + } icon_view_->SetPosition(gfx::Point(image_x, image_y)); bar_->SetBounds(0, 0, width(), height()); @@ -284,7 +298,7 @@ void LauncherButton::Init() { // TODO: refactor the layers so each button doesn't require 2. icon_view_->SetPaintToLayer(true); icon_view_->SetFillsBoundsOpaquely(false); - icon_view_->SetSize(gfx::Size(kIconWidth, kIconHeight)); + icon_view_->SetSize(gfx::Size(kIconSize, kIconSize)); icon_view_->SetHorizontalAlignment(views::ImageView::CENTER); icon_view_->SetVerticalAlignment(views::ImageView::CENTER); AddChildView(icon_view_); @@ -294,6 +308,10 @@ LauncherButton::IconView* LauncherButton::CreateIconView() { return new IconView; } +bool LauncherButton::IsShelfHorizontal() const { + return host_->GetShelfAlignment() == SHELF_ALIGNMENT_BOTTOM; +} + void LauncherButton::UpdateState() { if (state_ == STATE_NORMAL) { bar_->SetVisible(false); @@ -302,16 +320,39 @@ void LauncherButton::UpdateState() { int bar_id; bar_->SetVisible(true); - if (state_ & STATE_ACTIVE || state_ & STATE_ATTENTION) - bar_id = IDR_AURA_LAUNCHER_UNDERLINE_ACTIVE; - else if (state_ & STATE_HOVERED) - bar_id = IDR_AURA_LAUNCHER_UNDERLINE_HOVER; - else - bar_id = IDR_AURA_LAUNCHER_UNDERLINE_RUNNING; + if (state_ & STATE_ACTIVE || state_ & STATE_ATTENTION) { + bar_id = IsShelfHorizontal() ? IDR_AURA_LAUNCHER_UNDERLINE_ACTIVE : + IDR_AURA_LAUNCHER_UNDERLINE_VERTICAL_ACTIVE; + } else if (state_ & STATE_HOVERED) { + bar_id = IsShelfHorizontal() ? IDR_AURA_LAUNCHER_UNDERLINE_HOVER : + IDR_AURA_LAUNCHER_UNDERLINE_VERTICAL_HOVER; + } else { + bar_id = IsShelfHorizontal() ? IDR_AURA_LAUNCHER_UNDERLINE_RUNNING : + IDR_AURA_LAUNCHER_UNDERLINE_VERTICAL_RUNNING; + } bar_->SetImage(rb.GetImageNamed(bar_id).ToImageSkia()); } + switch (host_->GetShelfAlignment()) { + case SHELF_ALIGNMENT_BOTTOM: + bar_->SetHorizontalAlignment(views::ImageView::CENTER); + bar_->SetVerticalAlignment(views::ImageView::TRAILING); + break; + case SHELF_ALIGNMENT_LEFT: + bar_->SetHorizontalAlignment( + base::i18n::IsRTL() ? views::ImageView::TRAILING : + views::ImageView::LEADING); + bar_->SetVerticalAlignment(views::ImageView::CENTER); + break; + case SHELF_ALIGNMENT_RIGHT: + bar_->SetHorizontalAlignment( + base::i18n::IsRTL() ? views::ImageView::LEADING : + views::ImageView::TRAILING); + bar_->SetVerticalAlignment(views::ImageView::CENTER); + break; + } + Layout(); SchedulePaint(); } diff --git a/ash/launcher/launcher_button.h b/ash/launcher/launcher_button.h index e1278b8..91ceca1 100644 --- a/ash/launcher/launcher_button.h +++ b/ash/launcher/launcher_button.h @@ -53,10 +53,13 @@ class LauncherButton : public views::CustomButton { public: IconView(); virtual ~IconView(); - virtual bool HitTest(const gfx::Point& l) const OVERRIDE; + void set_icon_size(int icon_size) { icon_size_ = icon_size; } int icon_size() const { return icon_size_; } + // views::View overrides. + virtual bool HitTest(const gfx::Point& l) const OVERRIDE; + private: // Set to non-zero to force icons to be resized to fit within a square, // while maintaining original proportions. @@ -88,8 +91,13 @@ class LauncherButton : public views::CustomButton { private: class BarView; - // Updates the parts of the button to reflect the current state_. This may - // add or remove views, layout and paint. + + // Returns true if the shelf is horizontal. If this returns false the shelf is + // vertical. + bool IsShelfHorizontal() const; + + // Updates the parts of the button to reflect the current |state_| and + // alignment. This may add or remove views, layout and paint. void UpdateState(); LauncherButtonHost* host_; diff --git a/ash/wm/shelf_layout_manager.cc b/ash/wm/shelf_layout_manager.cc index ad751a4..55bf5a2 100644 --- a/ash/wm/shelf_layout_manager.cc +++ b/ash/wm/shelf_layout_manager.cc @@ -212,8 +212,8 @@ gfx::Rect ShelfLayoutManager::GetIdealBounds() { case SHELF_ALIGNMENT_LEFT: return gfx::Rect(bounds.x(), bounds.y(), width, bounds.height()); case SHELF_ALIGNMENT_RIGHT: - return gfx::Rect(bounds.right() - width, bounds.bottom() - height, width, - height); + return gfx::Rect(bounds.right() - width, bounds.y(), width, + bounds.height()); } NOTREACHED(); return gfx::Rect(); |