Commit 7e846441 authored by xiyuan@chromium.org's avatar xiyuan@chromium.org

ash: Update launcher overflow chevron.

- Use new overflow chevron assets;
- Code drawing hover/pressed state and rotate image for left/right launcher;

BUG=132855
TEST=Verify launcher chevron uses new image and has hover effect similar to app menu and ubertray.

R=sky@chromium.org

Review URL: https://chromiumcodereview.appspot.com/10828184

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@150272 0039d316-1c4b-4281-b951-d872f2087c98
parent b4ddc7a0
...@@ -113,6 +113,8 @@ ...@@ -113,6 +113,8 @@
'launcher/launcher_view.h', 'launcher/launcher_view.h',
'launcher/overflow_bubble.cc', 'launcher/overflow_bubble.cc',
'launcher/overflow_bubble.h', 'launcher/overflow_bubble.h',
'launcher/overflow_button.cc',
'launcher/overflow_button.h',
'launcher/tabbed_launcher_button.cc', 'launcher/tabbed_launcher_button.cc',
'launcher/tabbed_launcher_button.h', 'launcher/tabbed_launcher_button.h',
'magnifier/magnification_controller.cc', 'magnifier/magnification_controller.cc',
......
...@@ -13,6 +13,7 @@ ...@@ -13,6 +13,7 @@
#include "ash/launcher/launcher_model.h" #include "ash/launcher/launcher_model.h"
#include "ash/launcher/launcher_tooltip_manager.h" #include "ash/launcher/launcher_tooltip_manager.h"
#include "ash/launcher/overflow_bubble.h" #include "ash/launcher/overflow_bubble.h"
#include "ash/launcher/overflow_button.h"
#include "ash/launcher/tabbed_launcher_button.h" #include "ash/launcher/tabbed_launcher_button.h"
#include "ash/shell.h" #include "ash/shell.h"
#include "ash/shell_delegate.h" #include "ash/shell_delegate.h"
...@@ -293,7 +294,6 @@ LauncherView::~LauncherView() { ...@@ -293,7 +294,6 @@ LauncherView::~LauncherView() {
} }
void LauncherView::Init() { void LauncherView::Init() {
ResourceBundle& rb = ResourceBundle::GetSharedInstance();
model_->AddObserver(this); model_->AddObserver(this);
const LauncherItems& items(model_->items()); const LauncherItems& items(model_->items());
...@@ -305,21 +305,7 @@ void LauncherView::Init() { ...@@ -305,21 +305,7 @@ void LauncherView::Init() {
} }
UpdateFirstButtonPadding(); UpdateFirstButtonPadding();
overflow_button_ = new views::ImageButton(this); overflow_button_ = new OverflowButton(this);
overflow_button_->set_accessibility_focusable(true);
overflow_button_->SetImageAlignment(views::ImageButton::ALIGN_CENTER,
views::ImageButton::ALIGN_MIDDLE);
overflow_button_->SetImage(
views::CustomButton::BS_NORMAL,
rb.GetImageNamed(IDR_AURA_LAUNCHER_OVERFLOW).ToImageSkia());
overflow_button_->SetImage(
views::CustomButton::BS_HOT,
rb.GetImageNamed(IDR_AURA_LAUNCHER_OVERFLOW_HOT).ToImageSkia());
overflow_button_->SetImage(
views::CustomButton::BS_PUSHED,
rb.GetImageNamed(IDR_AURA_LAUNCHER_OVERFLOW_PUSHED).ToImageSkia());
overflow_button_->SetAccessibleName(
l10n_util::GetStringUTF16(IDS_AURA_LAUNCHER_OVERFLOW_NAME));
overflow_button_->set_context_menu_controller(this); overflow_button_->set_context_menu_controller(this);
ConfigureChildView(overflow_button_); ConfigureChildView(overflow_button_);
AddChildView(overflow_button_); AddChildView(overflow_button_);
...@@ -332,6 +318,7 @@ void LauncherView::SetAlignment(ShelfAlignment alignment) { ...@@ -332,6 +318,7 @@ void LauncherView::SetAlignment(ShelfAlignment alignment) {
return; return;
alignment_ = alignment; alignment_ = alignment;
UpdateFirstButtonPadding(); UpdateFirstButtonPadding();
overflow_button_->SetShelfAlignment(alignment_);
LayoutToIdealBounds(); LayoutToIdealBounds();
tooltip_->SetArrowLocation(alignment_); tooltip_->SetArrowLocation(alignment_);
if (overflow_bubble_.get()) if (overflow_bubble_.get())
......
...@@ -20,7 +20,6 @@ ...@@ -20,7 +20,6 @@
namespace views { namespace views {
class BoundsAnimator; class BoundsAnimator;
class ImageButton;
class MenuRunner; class MenuRunner;
class ViewModel; class ViewModel;
} }
...@@ -42,6 +41,7 @@ class LauncherButton; ...@@ -42,6 +41,7 @@ class LauncherButton;
class LauncherTooltipManager; class LauncherTooltipManager;
class ShelfLayoutManager; class ShelfLayoutManager;
class OverflowBubble; class OverflowBubble;
class OverflowButton;
class ASH_EXPORT LauncherView : public views::View, class ASH_EXPORT LauncherView : public views::View,
public LauncherModelObserver, public LauncherModelObserver,
...@@ -238,7 +238,7 @@ class ASH_EXPORT LauncherView : public views::View, ...@@ -238,7 +238,7 @@ class ASH_EXPORT LauncherView : public views::View,
scoped_ptr<views::BoundsAnimator> bounds_animator_; scoped_ptr<views::BoundsAnimator> bounds_animator_;
views::ImageButton* overflow_button_; OverflowButton* overflow_button_;
scoped_ptr<OverflowBubble> overflow_bubble_; scoped_ptr<OverflowBubble> overflow_bubble_;
......
// Copyright (c) 2012 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "ash/launcher/overflow_button.h"
#include "grit/ash_strings.h"
#include "grit/ui_resources.h"
#include "third_party/skia/include/core/SkPaint.h"
#include "third_party/skia/include/core/SkPath.h"
#include "ui/base/animation/throb_animation.h"
#include "ui/base/l10n/l10n_util.h"
#include "ui/base/resource/resource_bundle.h"
#include "ui/gfx/canvas.h"
#include "ui/gfx/skia_util.h"
#include "ui/gfx/transform.h"
namespace ash {
namespace internal {
namespace {
const int kButtonHoverAlpha = 150;
const int kButtonCornerRadius = 2;
const int kButtonHoverSize = 28;
void RotateCounterclockwise(ui::Transform* transform) {
transform->matrix().set3x3(0, -1, 0,
1, 0, 0,
0, 0, 1);
}
void RotateClockwise(ui::Transform* transform) {
transform->matrix().set3x3( 0, 1, 0,
-1, 0, 0,
0, 0, 1);
}
} // namesapce
OverflowButton::OverflowButton(views::ButtonListener* listener)
: CustomButton(listener),
alignment_(SHELF_ALIGNMENT_BOTTOM),
image_(NULL) {
ResourceBundle& rb = ResourceBundle::GetSharedInstance();
image_ = rb.GetImageNamed(IDR_AURA_LAUNCHER_OVERFLOW).ToImageSkia();
set_accessibility_focusable(true);
SetAccessibleName(
l10n_util::GetStringUTF16(IDS_AURA_LAUNCHER_OVERFLOW_NAME));
}
OverflowButton::~OverflowButton() {
}
void OverflowButton::SetShelfAlignment(ShelfAlignment alignment) {
if (alignment_ == alignment)
return;
alignment_ = alignment;
SchedulePaint();
}
void OverflowButton::PaintBackground(gfx::Canvas* canvas, int alpha) {
gfx::Rect rect(GetContentsBounds());
rect = rect.Center(gfx::Size(kButtonHoverSize, kButtonHoverSize));
SkPaint paint;
paint.setAntiAlias(true);
paint.setStyle(SkPaint::kFill_Style);
paint.setColor(SkColorSetARGB(
kButtonHoverAlpha * hover_animation_->GetCurrentValue(),
0, 0, 0));
const SkScalar radius = SkIntToScalar(kButtonCornerRadius);
SkPath path;
path.addRoundRect(gfx::RectToSkRect(rect), radius, radius);
canvas->DrawPath(path, paint);
}
void OverflowButton::OnPaint(gfx::Canvas* canvas) {
if (hover_animation_->is_animating()) {
PaintBackground(
canvas,
kButtonHoverAlpha * hover_animation_->GetCurrentValue());
} else if (state() == BS_HOT || state() == BS_PUSHED) {
PaintBackground(canvas, kButtonHoverAlpha);
}
ui::Transform transform;
switch (alignment_) {
case SHELF_ALIGNMENT_BOTTOM:
// Shift 1 pixel left to align with overflow bubble tip.
transform.ConcatTranslate(-1, 0);
break;
case SHELF_ALIGNMENT_LEFT:
RotateClockwise(&transform);
transform.ConcatTranslate(width(), -1);
break;
case SHELF_ALIGNMENT_RIGHT:
RotateCounterclockwise(&transform);
transform.ConcatTranslate(0, height());
break;
}
canvas->Save();
canvas->Transform(transform);
gfx::Rect rect(GetContentsBounds());
canvas->DrawImageInt(*image_,
rect.x() + (rect.width() - image_->width()) / 2,
rect.y() + (rect.height() - image_->height()) / 2);
canvas->Restore();
}
} // namespace internal
} // namespace ash
// Copyright (c) 2012 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef ASH_LAUNCHER_OVERFLOW_BUTTON_H_
#define ASH_LAUNCHER_OVERFLOW_BUTTON_H_
#include "ash/wm/shelf_types.h"
#include "base/basictypes.h"
#include "base/compiler_specific.h"
#include "ui/views/controls/button/custom_button.h"
namespace gfx {
class ImageSkia;
}
namespace ash {
namespace internal {
// Launcher overflow chevron button.
class OverflowButton : public views::CustomButton {
public:
explicit OverflowButton(views::ButtonListener* listener);
virtual ~OverflowButton();
void SetShelfAlignment(ShelfAlignment alignment);
private:
void PaintBackground(gfx::Canvas* canvas, int alpha);
// views::View overrides:
virtual void OnPaint(gfx::Canvas* canvas) OVERRIDE;
ShelfAlignment alignment_;
const gfx::ImageSkia* image_;
DISALLOW_COPY_AND_ASSIGN(OverflowButton);
};
} // namespace internal
} // namespace ash
#endif // ASH_LAUNCHER_OVERFLOW_BUTTON_H_
...@@ -6,6 +6,7 @@ ...@@ -6,6 +6,7 @@
#include "ash/launcher/launcher_button.h" #include "ash/launcher/launcher_button.h"
#include "ash/launcher/launcher_view.h" #include "ash/launcher/launcher_view.h"
#include "ash/launcher/overflow_button.h"
#include "base/message_loop.h" #include "base/message_loop.h"
#include "ui/views/animation/bounds_animator.h" #include "ui/views/animation/bounds_animator.h"
#include "ui/views/controls/button/image_button.h" #include "ui/views/controls/button/image_button.h"
......
...@@ -66,8 +66,6 @@ ...@@ -66,8 +66,6 @@
<structure type="chrome_scaled_image" name="IDR_AURA_LAUNCHER_NEW_BROWSER_HOT" file="ash/new_browser_hover.png" /> <structure type="chrome_scaled_image" name="IDR_AURA_LAUNCHER_NEW_BROWSER_HOT" file="ash/new_browser_hover.png" />
<structure type="chrome_scaled_image" name="IDR_AURA_LAUNCHER_NEW_BROWSER_PUSHED" file="ash/new_browser_pressed.png" /> <structure type="chrome_scaled_image" name="IDR_AURA_LAUNCHER_NEW_BROWSER_PUSHED" file="ash/new_browser_pressed.png" />
<structure type="chrome_scaled_image" name="IDR_AURA_LAUNCHER_OVERFLOW" file="ash/launcher_overflow.png" /> <structure type="chrome_scaled_image" name="IDR_AURA_LAUNCHER_OVERFLOW" file="ash/launcher_overflow.png" />
<structure type="chrome_scaled_image" name="IDR_AURA_LAUNCHER_OVERFLOW_HOT" file="ash/launcher_overflow_hover.png" />
<structure type="chrome_scaled_image" name="IDR_AURA_LAUNCHER_OVERFLOW_PUSHED" file="ash/launcher_overflow_pressed.png" />
<structure type="chrome_scaled_image" name="IDR_AURA_LAUNCHER_UNDERLINE_ACTIVE" file="ash/launcher_underline_active.png" /> <structure type="chrome_scaled_image" name="IDR_AURA_LAUNCHER_UNDERLINE_ACTIVE" file="ash/launcher_underline_active.png" />
<structure type="chrome_scaled_image" name="IDR_AURA_LAUNCHER_UNDERLINE_HOVER" file="ash/launcher_underline_hover.png" /> <structure type="chrome_scaled_image" name="IDR_AURA_LAUNCHER_UNDERLINE_HOVER" file="ash/launcher_underline_hover.png" />
<structure type="chrome_scaled_image" name="IDR_AURA_LAUNCHER_UNDERLINE_RUNNING" file="ash/launcher_underline_running.png" /> <structure type="chrome_scaled_image" name="IDR_AURA_LAUNCHER_UNDERLINE_RUNNING" file="ash/launcher_underline_running.png" />
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment