| Index: ash/launcher/overflow_button.cc
|
| diff --git a/ash/launcher/overflow_button.cc b/ash/launcher/overflow_button.cc
|
| index 884746892f982c4b96b8c71ae32cdf87c40a68a4..c3d5a6891d055d154ff5433af6a1660c51d1df4d 100644
|
| --- a/ash/launcher/overflow_button.cc
|
| +++ b/ash/launcher/overflow_button.cc
|
| @@ -4,7 +4,9 @@
|
|
|
| #include "ash/launcher/overflow_button.h"
|
|
|
| +#include "ash/ash_switches.h"
|
| #include "ash/shelf/shelf_layout_manager.h"
|
| +#include "ash/shelf/shelf_widget.h"
|
| #include "grit/ash_resources.h"
|
| #include "grit/ash_strings.h"
|
| #include "third_party/skia/include/core/SkPaint.h"
|
| @@ -13,6 +15,8 @@
|
| #include "ui/base/l10n/l10n_util.h"
|
| #include "ui/base/resource/resource_bundle.h"
|
| #include "ui/gfx/canvas.h"
|
| +#include "ui/gfx/image/image_skia_operations.h"
|
| +#include "ui/gfx/skbitmap_operations.h"
|
| #include "ui/gfx/skia_util.h"
|
| #include "ui/gfx/transform.h"
|
| #include "ui/views/widget/widget.h"
|
| @@ -30,29 +34,18 @@ const int kButtonHoverSize = 28;
|
|
|
| const int kBackgroundOffset = (48 - kButtonHoverSize) / 2;
|
|
|
| -void RotateCounterclockwise(gfx::Transform* transform) {
|
| - SkMatrix44 rotation;
|
| - rotation.set3x3(0, -1, 0,
|
| - 1, 0, 0,
|
| - 0, 0, 1);
|
| - transform->matrix().preConcat(rotation);
|
| -}
|
| -
|
| -void RotateClockwise(gfx::Transform* transform) {
|
| - SkMatrix44 rotation;
|
| - rotation.set3x3( 0, 1, 0,
|
| - -1, 0, 0,
|
| - 0, 0, 1);
|
| - transform->matrix().preConcat(rotation);
|
| -}
|
| +// Padding from the inner edge of the shelf (towards center of display) to
|
| +// the edge of the background image of the overflow button.
|
| +const int kImagePaddingFromShelf = 5;
|
|
|
| } // namesapce
|
|
|
| OverflowButton::OverflowButton(views::ButtonListener* listener)
|
| : CustomButton(listener),
|
| - image_(NULL) {
|
| + bottom_image_(NULL) {
|
| ResourceBundle& rb = ResourceBundle::GetSharedInstance();
|
| - image_ = rb.GetImageNamed(IDR_AURA_LAUNCHER_OVERFLOW).ToImageSkia();
|
| + bottom_image_ = rb.GetImageNamed(IDR_AURA_LAUNCHER_OVERFLOW).ToImageSkia();
|
| +
|
|
|
| set_accessibility_focusable(true);
|
| SetAccessibleName(l10n_util::GetStringUTF16(IDS_ASH_SHELF_OVERFLOW_NAME));
|
| @@ -96,55 +89,89 @@ void OverflowButton::PaintBackground(gfx::Canvas* canvas, int alpha) {
|
| }
|
|
|
| void OverflowButton::OnPaint(gfx::Canvas* canvas) {
|
| - ShelfAlignment alignment = ShelfLayoutManager::ForLauncher(
|
| - GetWidget()->GetNativeView())->GetAlignment();
|
| -
|
| - if (hover_animation_->is_animating()) {
|
| - PaintBackground(
|
| - canvas,
|
| - kButtonHoverAlpha * hover_animation_->GetCurrentValue());
|
| - } else if (state() == STATE_HOVERED || state() == STATE_PRESSED) {
|
| - PaintBackground(canvas, kButtonHoverAlpha);
|
| + ShelfLayoutManager* layout_manager = ShelfLayoutManager::ForLauncher(
|
| + GetWidget()->GetNativeView());
|
| + ShelfAlignment alignment = layout_manager->GetAlignment();
|
| +
|
| + gfx::Rect bounds(GetContentsBounds());
|
| + if (ash::switches::UseAlternateShelfLayout()) {
|
| + ResourceBundle& rb = ResourceBundle::GetSharedInstance();
|
| + int background_image_id = 0;
|
| + if (layout_manager->shelf_widget()->launcher()->IsShowingOverflowBubble())
|
| + background_image_id = IDR_AURA_NOTIFICATION_BACKGROUND_PRESSED;
|
| + else if(layout_manager->shelf_widget()->GetDimsShelf())
|
| + background_image_id = IDR_AURA_NOTIFICATION_BACKGROUND_ON_BLACK;
|
| + else
|
| + background_image_id = IDR_AURA_NOTIFICATION_BACKGROUND_NORMAL;
|
| +
|
| + const gfx::ImageSkia* background =
|
| + rb.GetImageNamed(background_image_id).ToImageSkia();
|
| + if (alignment == SHELF_ALIGNMENT_LEFT) {
|
| + bounds = gfx::Rect(
|
| + bounds.right() - background->width() - kImagePaddingFromShelf,
|
| + bounds.y() + (bounds.height() - background->height()) / 2,
|
| + background->width(), background->height());
|
| + } else if (alignment == SHELF_ALIGNMENT_RIGHT) {
|
| + bounds = gfx::Rect(
|
| + bounds.x() + kImagePaddingFromShelf,
|
| + bounds.y() + (bounds.height() - background->height()) / 2,
|
| + background->width(), background->height());
|
| + } else {
|
| + bounds = gfx::Rect(
|
| + bounds.x() + (bounds.width() - background->width()) / 2,
|
| + bounds.y() + kImagePaddingFromShelf,
|
| + background->width(), background->height());
|
| + }
|
| + canvas->DrawImageInt(*background, bounds.x(), bounds.y());
|
| + } else {
|
| + if (alignment == SHELF_ALIGNMENT_BOTTOM) {
|
| + bounds = gfx::Rect(
|
| + bounds.x() + ((bounds.width() - kButtonHoverSize) / 2) - 1,
|
| + bounds.y() + kBackgroundOffset - 1,
|
| + kButtonHoverSize, kButtonHoverSize);
|
| + } else {
|
| + bounds = gfx::Rect(
|
| + bounds.x() + kBackgroundOffset -1,
|
| + bounds.y() + ((bounds.height() - kButtonHoverSize) / 2) -1,
|
| + kButtonHoverSize, kButtonHoverSize);
|
| + }
|
| + if (hover_animation_->is_animating()) {
|
| + PaintBackground(
|
| + canvas,
|
| + kButtonHoverAlpha * hover_animation_->GetCurrentValue());
|
| + } else if (state() == STATE_HOVERED || state() == STATE_PRESSED) {
|
| + PaintBackground(canvas, kButtonHoverAlpha);
|
| + }
|
| }
|
|
|
| if (height() < kButtonHoverSize)
|
| return;
|
|
|
| - gfx::Transform transform;
|
| + const gfx::ImageSkia* image = NULL;
|
|
|
| - switch (alignment) {
|
| - case SHELF_ALIGNMENT_BOTTOM:
|
| - // Shift 1 pixel left to align with overflow bubble tip.
|
| - transform.Translate(-1, kBackgroundOffset);
|
| - break;
|
| + switch(alignment) {
|
| case SHELF_ALIGNMENT_LEFT:
|
| - transform.Translate(kBackgroundOffset, -1);
|
| - RotateClockwise(&transform);
|
| + if (left_image_.isNull()) {
|
| + left_image_ = gfx::ImageSkiaOperations::CreateRotatedImage(
|
| + *bottom_image_, SkBitmapOperations::ROTATION_90_CW);
|
| + }
|
| + image = &left_image_;
|
| break;
|
| case SHELF_ALIGNMENT_RIGHT:
|
| - transform.Translate(kBackgroundOffset, height());
|
| - RotateCounterclockwise(&transform);
|
| + if (right_image_.isNull()) {
|
| + right_image_ = gfx::ImageSkiaOperations::CreateRotatedImage(
|
| + *bottom_image_, SkBitmapOperations::ROTATION_270_CW);
|
| + }
|
| + image = &right_image_;
|
| break;
|
| - case SHELF_ALIGNMENT_TOP:
|
| - transform.Translate(1, kBackgroundOffset);
|
| + default:
|
| + image = bottom_image_;
|
| break;
|
| }
|
|
|
| - canvas->Save();
|
| - canvas->Transform(transform);
|
| -
|
| - gfx::Rect rect(GetContentsBounds());
|
| - if (alignment == SHELF_ALIGNMENT_BOTTOM ||
|
| - alignment == SHELF_ALIGNMENT_TOP) {
|
| - canvas->DrawImageInt(*image_,
|
| - rect.x() + (rect.width() - image_->width()) / 2,
|
| - kButtonHoverSize - image_->height());
|
| - } else {
|
| - canvas->DrawImageInt(*image_,
|
| - kButtonHoverSize - image_->width(),
|
| - rect.y() + (rect.height() - image_->height()) / 2);
|
| - }
|
| - canvas->Restore();
|
| + canvas->DrawImageInt(*image,
|
| + bounds.x() + ((bounds.width() - image->width()) / 2),
|
| + bounds.y() + ((bounds.height() - image->height()) / 2));
|
| }
|
|
|
| } // namespace internal
|
|
|