| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 "ash/launcher/overflow_button.h" | 5 #include "ash/launcher/overflow_button.h" |
| 6 | 6 |
| 7 #include "ash/ash_switches.h" |
| 7 #include "ash/shelf/shelf_layout_manager.h" | 8 #include "ash/shelf/shelf_layout_manager.h" |
| 9 #include "ash/shelf/shelf_widget.h" |
| 8 #include "grit/ash_resources.h" | 10 #include "grit/ash_resources.h" |
| 9 #include "grit/ash_strings.h" | 11 #include "grit/ash_strings.h" |
| 10 #include "third_party/skia/include/core/SkPaint.h" | 12 #include "third_party/skia/include/core/SkPaint.h" |
| 11 #include "third_party/skia/include/core/SkPath.h" | 13 #include "third_party/skia/include/core/SkPath.h" |
| 12 #include "ui/base/animation/throb_animation.h" | 14 #include "ui/base/animation/throb_animation.h" |
| 13 #include "ui/base/l10n/l10n_util.h" | 15 #include "ui/base/l10n/l10n_util.h" |
| 14 #include "ui/base/resource/resource_bundle.h" | 16 #include "ui/base/resource/resource_bundle.h" |
| 15 #include "ui/gfx/canvas.h" | 17 #include "ui/gfx/canvas.h" |
| 18 #include "ui/gfx/image/image_skia_operations.h" |
| 19 #include "ui/gfx/skbitmap_operations.h" |
| 16 #include "ui/gfx/skia_util.h" | 20 #include "ui/gfx/skia_util.h" |
| 17 #include "ui/gfx/transform.h" | 21 #include "ui/gfx/transform.h" |
| 18 #include "ui/views/widget/widget.h" | 22 #include "ui/views/widget/widget.h" |
| 19 | 23 |
| 20 namespace ash { | 24 namespace ash { |
| 21 namespace internal { | 25 namespace internal { |
| 22 | 26 |
| 23 namespace { | 27 namespace { |
| 24 | 28 |
| 25 const int kButtonHoverAlpha = 150; | 29 const int kButtonHoverAlpha = 150; |
| 26 | 30 |
| 27 const int kButtonCornerRadius = 2; | 31 const int kButtonCornerRadius = 2; |
| 28 | 32 |
| 29 const int kButtonHoverSize = 28; | 33 const int kButtonHoverSize = 28; |
| 30 | 34 |
| 31 const int kBackgroundOffset = (48 - kButtonHoverSize) / 2; | 35 const int kBackgroundOffset = (48 - kButtonHoverSize) / 2; |
| 32 | 36 |
| 33 void RotateCounterclockwise(gfx::Transform* transform) { | 37 // Padding from the inner edge of the shelf (towards center of display) to |
| 34 SkMatrix44 rotation; | 38 // the edge of the background image of the overflow button. |
| 35 rotation.set3x3(0, -1, 0, | 39 const int kImagePaddingFromShelf = 5; |
| 36 1, 0, 0, | |
| 37 0, 0, 1); | |
| 38 transform->matrix().preConcat(rotation); | |
| 39 } | |
| 40 | |
| 41 void RotateClockwise(gfx::Transform* transform) { | |
| 42 SkMatrix44 rotation; | |
| 43 rotation.set3x3( 0, 1, 0, | |
| 44 -1, 0, 0, | |
| 45 0, 0, 1); | |
| 46 transform->matrix().preConcat(rotation); | |
| 47 } | |
| 48 | 40 |
| 49 } // namesapce | 41 } // namesapce |
| 50 | 42 |
| 51 OverflowButton::OverflowButton(views::ButtonListener* listener) | 43 OverflowButton::OverflowButton(views::ButtonListener* listener) |
| 52 : CustomButton(listener), | 44 : CustomButton(listener), |
| 53 image_(NULL) { | 45 bottom_image_(NULL) { |
| 54 ResourceBundle& rb = ResourceBundle::GetSharedInstance(); | 46 ResourceBundle& rb = ResourceBundle::GetSharedInstance(); |
| 55 image_ = rb.GetImageNamed(IDR_AURA_LAUNCHER_OVERFLOW).ToImageSkia(); | 47 bottom_image_ = rb.GetImageNamed(IDR_AURA_LAUNCHER_OVERFLOW).ToImageSkia(); |
| 48 |
| 56 | 49 |
| 57 set_accessibility_focusable(true); | 50 set_accessibility_focusable(true); |
| 58 SetAccessibleName(l10n_util::GetStringUTF16(IDS_ASH_SHELF_OVERFLOW_NAME)); | 51 SetAccessibleName(l10n_util::GetStringUTF16(IDS_ASH_SHELF_OVERFLOW_NAME)); |
| 59 } | 52 } |
| 60 | 53 |
| 61 OverflowButton::~OverflowButton() {} | 54 OverflowButton::~OverflowButton() {} |
| 62 | 55 |
| 63 void OverflowButton::OnShelfAlignmentChanged() { | 56 void OverflowButton::OnShelfAlignmentChanged() { |
| 64 SchedulePaint(); | 57 SchedulePaint(); |
| 65 } | 58 } |
| (...skipping 23 matching lines...) Expand all Loading... |
| 89 kButtonHoverAlpha * hover_animation_->GetCurrentValue(), | 82 kButtonHoverAlpha * hover_animation_->GetCurrentValue(), |
| 90 0, 0, 0)); | 83 0, 0, 0)); |
| 91 | 84 |
| 92 const SkScalar radius = SkIntToScalar(kButtonCornerRadius); | 85 const SkScalar radius = SkIntToScalar(kButtonCornerRadius); |
| 93 SkPath path; | 86 SkPath path; |
| 94 path.addRoundRect(gfx::RectToSkRect(rect), radius, radius); | 87 path.addRoundRect(gfx::RectToSkRect(rect), radius, radius); |
| 95 canvas->DrawPath(path, paint); | 88 canvas->DrawPath(path, paint); |
| 96 } | 89 } |
| 97 | 90 |
| 98 void OverflowButton::OnPaint(gfx::Canvas* canvas) { | 91 void OverflowButton::OnPaint(gfx::Canvas* canvas) { |
| 99 ShelfAlignment alignment = ShelfLayoutManager::ForLauncher( | 92 ShelfLayoutManager* layout_manager = ShelfLayoutManager::ForLauncher( |
| 100 GetWidget()->GetNativeView())->GetAlignment(); | 93 GetWidget()->GetNativeView()); |
| 94 ShelfAlignment alignment = layout_manager->GetAlignment(); |
| 101 | 95 |
| 102 if (hover_animation_->is_animating()) { | 96 gfx::Rect bounds(GetContentsBounds()); |
| 103 PaintBackground( | 97 if (ash::switches::UseAlternateShelfLayout()) { |
| 104 canvas, | 98 ResourceBundle& rb = ResourceBundle::GetSharedInstance(); |
| 105 kButtonHoverAlpha * hover_animation_->GetCurrentValue()); | 99 int background_image_id = 0; |
| 106 } else if (state() == STATE_HOVERED || state() == STATE_PRESSED) { | 100 if (layout_manager->shelf_widget()->launcher()->IsShowingOverflowBubble()) |
| 107 PaintBackground(canvas, kButtonHoverAlpha); | 101 background_image_id = IDR_AURA_NOTIFICATION_BACKGROUND_PRESSED; |
| 102 else if(layout_manager->shelf_widget()->GetDimsShelf()) |
| 103 background_image_id = IDR_AURA_NOTIFICATION_BACKGROUND_ON_BLACK; |
| 104 else |
| 105 background_image_id = IDR_AURA_NOTIFICATION_BACKGROUND_NORMAL; |
| 106 |
| 107 const gfx::ImageSkia* background = |
| 108 rb.GetImageNamed(background_image_id).ToImageSkia(); |
| 109 if (alignment == SHELF_ALIGNMENT_LEFT) { |
| 110 bounds = gfx::Rect( |
| 111 bounds.right() - background->width() - kImagePaddingFromShelf, |
| 112 bounds.y() + (bounds.height() - background->height()) / 2, |
| 113 background->width(), background->height()); |
| 114 } else if (alignment == SHELF_ALIGNMENT_RIGHT) { |
| 115 bounds = gfx::Rect( |
| 116 bounds.x() + kImagePaddingFromShelf, |
| 117 bounds.y() + (bounds.height() - background->height()) / 2, |
| 118 background->width(), background->height()); |
| 119 } else { |
| 120 bounds = gfx::Rect( |
| 121 bounds.x() + (bounds.width() - background->width()) / 2, |
| 122 bounds.y() + kImagePaddingFromShelf, |
| 123 background->width(), background->height()); |
| 124 } |
| 125 canvas->DrawImageInt(*background, bounds.x(), bounds.y()); |
| 126 } else { |
| 127 if (alignment == SHELF_ALIGNMENT_BOTTOM) { |
| 128 bounds = gfx::Rect( |
| 129 bounds.x() + ((bounds.width() - kButtonHoverSize) / 2) - 1, |
| 130 bounds.y() + kBackgroundOffset - 1, |
| 131 kButtonHoverSize, kButtonHoverSize); |
| 132 } else { |
| 133 bounds = gfx::Rect( |
| 134 bounds.x() + kBackgroundOffset -1, |
| 135 bounds.y() + ((bounds.height() - kButtonHoverSize) / 2) -1, |
| 136 kButtonHoverSize, kButtonHoverSize); |
| 137 } |
| 138 if (hover_animation_->is_animating()) { |
| 139 PaintBackground( |
| 140 canvas, |
| 141 kButtonHoverAlpha * hover_animation_->GetCurrentValue()); |
| 142 } else if (state() == STATE_HOVERED || state() == STATE_PRESSED) { |
| 143 PaintBackground(canvas, kButtonHoverAlpha); |
| 144 } |
| 108 } | 145 } |
| 109 | 146 |
| 110 if (height() < kButtonHoverSize) | 147 if (height() < kButtonHoverSize) |
| 111 return; | 148 return; |
| 112 | 149 |
| 113 gfx::Transform transform; | 150 const gfx::ImageSkia* image = NULL; |
| 114 | 151 |
| 115 switch (alignment) { | 152 switch(alignment) { |
| 116 case SHELF_ALIGNMENT_BOTTOM: | |
| 117 // Shift 1 pixel left to align with overflow bubble tip. | |
| 118 transform.Translate(-1, kBackgroundOffset); | |
| 119 break; | |
| 120 case SHELF_ALIGNMENT_LEFT: | 153 case SHELF_ALIGNMENT_LEFT: |
| 121 transform.Translate(kBackgroundOffset, -1); | 154 if (left_image_.isNull()) { |
| 122 RotateClockwise(&transform); | 155 left_image_ = gfx::ImageSkiaOperations::CreateRotatedImage( |
| 156 *bottom_image_, SkBitmapOperations::ROTATION_90_CW); |
| 157 } |
| 158 image = &left_image_; |
| 123 break; | 159 break; |
| 124 case SHELF_ALIGNMENT_RIGHT: | 160 case SHELF_ALIGNMENT_RIGHT: |
| 125 transform.Translate(kBackgroundOffset, height()); | 161 if (right_image_.isNull()) { |
| 126 RotateCounterclockwise(&transform); | 162 right_image_ = gfx::ImageSkiaOperations::CreateRotatedImage( |
| 163 *bottom_image_, SkBitmapOperations::ROTATION_270_CW); |
| 164 } |
| 165 image = &right_image_; |
| 127 break; | 166 break; |
| 128 case SHELF_ALIGNMENT_TOP: | 167 default: |
| 129 transform.Translate(1, kBackgroundOffset); | 168 image = bottom_image_; |
| 130 break; | 169 break; |
| 131 } | 170 } |
| 132 | 171 |
| 133 canvas->Save(); | 172 canvas->DrawImageInt(*image, |
| 134 canvas->Transform(transform); | 173 bounds.x() + ((bounds.width() - image->width()) / 2), |
| 135 | 174 bounds.y() + ((bounds.height() - image->height()) / 2)); |
| 136 gfx::Rect rect(GetContentsBounds()); | |
| 137 if (alignment == SHELF_ALIGNMENT_BOTTOM || | |
| 138 alignment == SHELF_ALIGNMENT_TOP) { | |
| 139 canvas->DrawImageInt(*image_, | |
| 140 rect.x() + (rect.width() - image_->width()) / 2, | |
| 141 kButtonHoverSize - image_->height()); | |
| 142 } else { | |
| 143 canvas->DrawImageInt(*image_, | |
| 144 kButtonHoverSize - image_->width(), | |
| 145 rect.y() + (rect.height() - image_->height()) / 2); | |
| 146 } | |
| 147 canvas->Restore(); | |
| 148 } | 175 } |
| 149 | 176 |
| 150 } // namespace internal | 177 } // namespace internal |
| 151 } // namespace ash | 178 } // namespace ash |
| OLD | NEW |