| OLD | NEW |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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/shelf/overflow_button.h" | 5 #include "ash/shelf/overflow_button.h" |
| 6 | 6 |
| 7 #include "ash/ash_switches.h" | 7 #include "ash/ash_switches.h" |
| 8 #include "ash/shelf/shelf.h" | 8 #include "ash/shelf/shelf.h" |
| 9 #include "ash/shelf/shelf_layout_manager.h" | 9 #include "ash/shelf/shelf_layout_manager.h" |
| 10 #include "ash/shelf/shelf_view.h" |
| 10 #include "ash/shelf/shelf_widget.h" | 11 #include "ash/shelf/shelf_widget.h" |
| 11 #include "grit/ash_resources.h" | 12 #include "grit/ash_resources.h" |
| 12 #include "grit/ash_strings.h" | 13 #include "grit/ash_strings.h" |
| 13 #include "third_party/skia/include/core/SkPaint.h" | 14 #include "third_party/skia/include/core/SkPaint.h" |
| 14 #include "third_party/skia/include/core/SkPath.h" | 15 #include "third_party/skia/include/core/SkPath.h" |
| 15 #include "ui/base/l10n/l10n_util.h" | 16 #include "ui/base/l10n/l10n_util.h" |
| 16 #include "ui/base/resource/resource_bundle.h" | 17 #include "ui/base/resource/resource_bundle.h" |
| 17 #include "ui/gfx/animation/throb_animation.h" | 18 #include "ui/gfx/animation/throb_animation.h" |
| 18 #include "ui/gfx/canvas.h" | 19 #include "ui/gfx/canvas.h" |
| 19 #include "ui/gfx/image/image_skia_operations.h" | 20 #include "ui/gfx/image/image_skia_operations.h" |
| 20 #include "ui/gfx/skbitmap_operations.h" | 21 #include "ui/gfx/skbitmap_operations.h" |
| 21 #include "ui/gfx/skia_util.h" | 22 #include "ui/gfx/skia_util.h" |
| 22 #include "ui/gfx/transform.h" | 23 #include "ui/gfx/transform.h" |
| 23 #include "ui/views/widget/widget.h" | 24 #include "ui/views/widget/widget.h" |
| 24 | 25 |
| 25 namespace ash { | 26 namespace ash { |
| 26 namespace { | 27 namespace { |
| 27 | 28 |
| 28 const int kButtonHoverAlpha = 150; | 29 const int kButtonHoverAlpha = 150; |
| 29 | 30 |
| 30 const int kButtonCornerRadius = 2; | 31 const int kButtonCornerRadius = 2; |
| 31 | 32 |
| 32 const int kButtonHoverSize = 28; | 33 const int kButtonHoverSize = 28; |
| 33 | 34 |
| 34 const int kBackgroundOffset = (48 - kButtonHoverSize) / 2; | 35 const int kBackgroundOffset = (48 - kButtonHoverSize) / 2; |
| 35 | 36 |
| 36 } // namesapce | 37 } // namesapce |
| 37 | 38 |
| 38 OverflowButton::OverflowButton(views::ButtonListener* listener, Shelf* shelf) | 39 OverflowButton::OverflowButton(ShelfView* shelf_view) |
| 39 : CustomButton(listener), bottom_image_(nullptr), shelf_(shelf) { | 40 : CustomButton(nullptr), bottom_image_(nullptr), shelf_view_(shelf_view) { |
| 40 ui::ResourceBundle* rb = &ui::ResourceBundle::GetSharedInstance(); | 41 ui::ResourceBundle* rb = &ui::ResourceBundle::GetSharedInstance(); |
| 41 bottom_image_ = rb->GetImageNamed(IDR_ASH_SHELF_OVERFLOW).ToImageSkia(); | 42 bottom_image_ = rb->GetImageNamed(IDR_ASH_SHELF_OVERFLOW).ToImageSkia(); |
| 42 | 43 |
| 43 SetFocusBehavior(FocusBehavior::ACCESSIBLE_ONLY); | 44 SetFocusBehavior(FocusBehavior::ACCESSIBLE_ONLY); |
| 44 SetAccessibleName(l10n_util::GetStringUTF16(IDS_ASH_SHELF_OVERFLOW_NAME)); | 45 SetAccessibleName(l10n_util::GetStringUTF16(IDS_ASH_SHELF_OVERFLOW_NAME)); |
| 45 } | 46 } |
| 46 | 47 |
| 47 OverflowButton::~OverflowButton() {} | 48 OverflowButton::~OverflowButton() {} |
| 48 | 49 |
| 49 void OverflowButton::OnShelfAlignmentChanged() { | 50 void OverflowButton::OnShelfAlignmentChanged() { |
| 50 SchedulePaint(); | 51 SchedulePaint(); |
| 51 } | 52 } |
| 52 | 53 |
| 53 void OverflowButton::PaintBackground(gfx::Canvas* canvas, int alpha) { | 54 void OverflowButton::PaintBackground(gfx::Canvas* canvas, int alpha) { |
| 54 gfx::Rect bounds(GetContentsBounds()); | 55 gfx::Rect bounds(GetContentsBounds()); |
| 55 gfx::Rect rect(0, 0, kButtonHoverSize, kButtonHoverSize); | 56 gfx::Rect rect(0, 0, kButtonHoverSize, kButtonHoverSize); |
| 56 | 57 |
| 57 // Nudge the background a little to line up right. | 58 // Nudge the background a little to line up right. |
| 58 if (shelf_->IsHorizontalAlignment()) { | 59 if (shelf_view_->shelf()->IsHorizontalAlignment()) { |
| 59 rect.set_origin(gfx::Point( | 60 rect.set_origin(gfx::Point( |
| 60 bounds.x() + ((bounds.width() - kButtonHoverSize) / 2) - 1, | 61 bounds.x() + ((bounds.width() - kButtonHoverSize) / 2) - 1, |
| 61 bounds.y() + kBackgroundOffset - 1)); | 62 bounds.y() + kBackgroundOffset - 1)); |
| 62 | 63 |
| 63 } else { | 64 } else { |
| 64 rect.set_origin(gfx::Point( | 65 rect.set_origin(gfx::Point( |
| 65 bounds.x() + kBackgroundOffset - 1, | 66 bounds.x() + kBackgroundOffset - 1, |
| 66 bounds.y() + ((bounds.height() - kButtonHoverSize) / 2) - 1)); | 67 bounds.y() + ((bounds.height() - kButtonHoverSize) / 2) - 1)); |
| 67 } | 68 } |
| 68 | 69 |
| 69 SkPaint paint; | 70 SkPaint paint; |
| 70 paint.setAntiAlias(true); | 71 paint.setAntiAlias(true); |
| 71 paint.setStyle(SkPaint::kFill_Style); | 72 paint.setStyle(SkPaint::kFill_Style); |
| 72 paint.setColor( | 73 paint.setColor( |
| 73 SkColorSetA(SK_ColorBLACK, | 74 SkColorSetA(SK_ColorBLACK, |
| 74 hover_animation().CurrentValueBetween(0, kButtonHoverAlpha))); | 75 hover_animation().CurrentValueBetween(0, kButtonHoverAlpha))); |
| 75 | 76 |
| 76 const SkScalar radius = SkIntToScalar(kButtonCornerRadius); | 77 const SkScalar radius = SkIntToScalar(kButtonCornerRadius); |
| 77 SkPath path; | 78 SkPath path; |
| 78 path.addRoundRect(gfx::RectToSkRect(rect), radius, radius); | 79 path.addRoundRect(gfx::RectToSkRect(rect), radius, radius); |
| 79 canvas->DrawPath(path, paint); | 80 canvas->DrawPath(path, paint); |
| 80 } | 81 } |
| 81 | 82 |
| 82 void OverflowButton::OnPaint(gfx::Canvas* canvas) { | 83 void OverflowButton::OnPaint(gfx::Canvas* canvas) { |
| 83 gfx::Rect bounds(GetContentsBounds()); | 84 gfx::Rect bounds(GetContentsBounds()); |
| 84 ResourceBundle& rb = ResourceBundle::GetSharedInstance(); | 85 ResourceBundle& rb = ResourceBundle::GetSharedInstance(); |
| 85 int background_image_id = 0; | 86 int background_image_id = 0; |
| 86 if (shelf_->IsShowingOverflowBubble()) | 87 if (shelf_view_->shelf()->IsShowingOverflowBubble()) |
| 87 background_image_id = IDR_AURA_NOTIFICATION_BACKGROUND_PRESSED; | 88 background_image_id = IDR_AURA_NOTIFICATION_BACKGROUND_PRESSED; |
| 88 else if (shelf_->shelf_widget()->GetDimsShelf()) | 89 else if (shelf_view_->shelf()->shelf_widget()->GetDimsShelf()) |
| 89 background_image_id = IDR_AURA_NOTIFICATION_BACKGROUND_ON_BLACK; | 90 background_image_id = IDR_AURA_NOTIFICATION_BACKGROUND_ON_BLACK; |
| 90 else | 91 else |
| 91 background_image_id = IDR_AURA_NOTIFICATION_BACKGROUND_NORMAL; | 92 background_image_id = IDR_AURA_NOTIFICATION_BACKGROUND_NORMAL; |
| 92 | 93 |
| 93 const gfx::ImageSkia* background = | 94 const gfx::ImageSkia* background = |
| 94 rb.GetImageNamed(background_image_id).ToImageSkia(); | 95 rb.GetImageNamed(background_image_id).ToImageSkia(); |
| 95 ShelfAlignment alignment = shelf_->alignment(); | 96 ShelfAlignment alignment = shelf_view_->shelf()->alignment(); |
| 96 if (alignment == SHELF_ALIGNMENT_LEFT) { | 97 if (alignment == SHELF_ALIGNMENT_LEFT) { |
| 97 bounds = gfx::Rect( | 98 bounds = gfx::Rect( |
| 98 bounds.right() - background->width() - | 99 bounds.right() - background->width() - |
| 99 ShelfLayoutManager::kShelfItemInset, | 100 ShelfLayoutManager::kShelfItemInset, |
| 100 bounds.y() + (bounds.height() - background->height()) / 2, | 101 bounds.y() + (bounds.height() - background->height()) / 2, |
| 101 background->width(), background->height()); | 102 background->width(), background->height()); |
| 102 } else if (alignment == SHELF_ALIGNMENT_RIGHT) { | 103 } else if (alignment == SHELF_ALIGNMENT_RIGHT) { |
| 103 bounds = gfx::Rect( | 104 bounds = gfx::Rect( |
| 104 bounds.x() + ShelfLayoutManager::kShelfItemInset, | 105 bounds.x() + ShelfLayoutManager::kShelfItemInset, |
| 105 bounds.y() + (bounds.height() - background->height()) / 2, | 106 bounds.y() + (bounds.height() - background->height()) / 2, |
| (...skipping 29 matching lines...) Expand all Loading... |
| 135 default: | 136 default: |
| 136 image = bottom_image_; | 137 image = bottom_image_; |
| 137 break; | 138 break; |
| 138 } | 139 } |
| 139 | 140 |
| 140 canvas->DrawImageInt(*image, | 141 canvas->DrawImageInt(*image, |
| 141 bounds.x() + ((bounds.width() - image->width()) / 2), | 142 bounds.x() + ((bounds.width() - image->width()) / 2), |
| 142 bounds.y() + ((bounds.height() - image->height()) / 2)); | 143 bounds.y() + ((bounds.height() - image->height()) / 2)); |
| 143 } | 144 } |
| 144 | 145 |
| 146 void OverflowButton::NotifyClick(const ui::Event& event) { |
| 147 CustomButton::NotifyClick(event); |
| 148 shelf_view_->ButtonPressed(this, event, ink_drop()); |
| 149 } |
| 150 |
| 145 } // namespace ash | 151 } // namespace ash |
| OLD | NEW |