| 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_layout_manager.h" | 9 #include "ash/shelf/shelf_layout_manager.h" |
| 9 #include "ash/shelf/shelf_widget.h" | 10 #include "ash/shelf/shelf_widget.h" |
| 10 #include "grit/ash_resources.h" | 11 #include "grit/ash_resources.h" |
| 11 #include "grit/ash_strings.h" | 12 #include "grit/ash_strings.h" |
| 12 #include "third_party/skia/include/core/SkPaint.h" | 13 #include "third_party/skia/include/core/SkPaint.h" |
| 13 #include "third_party/skia/include/core/SkPath.h" | 14 #include "third_party/skia/include/core/SkPath.h" |
| 14 #include "ui/base/l10n/l10n_util.h" | 15 #include "ui/base/l10n/l10n_util.h" |
| 15 #include "ui/base/resource/resource_bundle.h" | 16 #include "ui/base/resource/resource_bundle.h" |
| 16 #include "ui/gfx/animation/throb_animation.h" | 17 #include "ui/gfx/animation/throb_animation.h" |
| 17 #include "ui/gfx/canvas.h" | 18 #include "ui/gfx/canvas.h" |
| 18 #include "ui/gfx/image/image_skia_operations.h" | 19 #include "ui/gfx/image/image_skia_operations.h" |
| 19 #include "ui/gfx/skbitmap_operations.h" | 20 #include "ui/gfx/skbitmap_operations.h" |
| 20 #include "ui/gfx/skia_util.h" | 21 #include "ui/gfx/skia_util.h" |
| 21 #include "ui/gfx/transform.h" | 22 #include "ui/gfx/transform.h" |
| 22 #include "ui/views/widget/widget.h" | 23 #include "ui/views/widget/widget.h" |
| 23 | 24 |
| 24 namespace ash { | 25 namespace ash { |
| 25 namespace { | 26 namespace { |
| 26 | 27 |
| 27 const int kButtonHoverAlpha = 150; | 28 const int kButtonHoverAlpha = 150; |
| 28 | 29 |
| 29 const int kButtonCornerRadius = 2; | 30 const int kButtonCornerRadius = 2; |
| 30 | 31 |
| 31 const int kButtonHoverSize = 28; | 32 const int kButtonHoverSize = 28; |
| 32 | 33 |
| 33 const int kBackgroundOffset = (48 - kButtonHoverSize) / 2; | 34 const int kBackgroundOffset = (48 - kButtonHoverSize) / 2; |
| 34 | 35 |
| 35 } // namesapce | 36 } // namesapce |
| 36 | 37 |
| 37 OverflowButton::OverflowButton(views::ButtonListener* listener, | 38 OverflowButton::OverflowButton(views::ButtonListener* listener, Shelf* shelf) |
| 38 ShelfLayoutManager* shelf) | |
| 39 : CustomButton(listener), bottom_image_(nullptr), shelf_(shelf) { | 39 : CustomButton(listener), bottom_image_(nullptr), shelf_(shelf) { |
| 40 ui::ResourceBundle* rb = &ui::ResourceBundle::GetSharedInstance(); | 40 ui::ResourceBundle* rb = &ui::ResourceBundle::GetSharedInstance(); |
| 41 bottom_image_ = rb->GetImageNamed(IDR_ASH_SHELF_OVERFLOW).ToImageSkia(); | 41 bottom_image_ = rb->GetImageNamed(IDR_ASH_SHELF_OVERFLOW).ToImageSkia(); |
| 42 | 42 |
| 43 SetAccessibilityFocusable(true); | 43 SetAccessibilityFocusable(true); |
| 44 SetAccessibleName(l10n_util::GetStringUTF16(IDS_ASH_SHELF_OVERFLOW_NAME)); | 44 SetAccessibleName(l10n_util::GetStringUTF16(IDS_ASH_SHELF_OVERFLOW_NAME)); |
| 45 } | 45 } |
| 46 | 46 |
| 47 OverflowButton::~OverflowButton() {} | 47 OverflowButton::~OverflowButton() {} |
| 48 | 48 |
| (...skipping 24 matching lines...) Expand all Loading... |
| 73 SkColorSetA(SK_ColorBLACK, | 73 SkColorSetA(SK_ColorBLACK, |
| 74 hover_animation().CurrentValueBetween(0, kButtonHoverAlpha))); | 74 hover_animation().CurrentValueBetween(0, kButtonHoverAlpha))); |
| 75 | 75 |
| 76 const SkScalar radius = SkIntToScalar(kButtonCornerRadius); | 76 const SkScalar radius = SkIntToScalar(kButtonCornerRadius); |
| 77 SkPath path; | 77 SkPath path; |
| 78 path.addRoundRect(gfx::RectToSkRect(rect), radius, radius); | 78 path.addRoundRect(gfx::RectToSkRect(rect), radius, radius); |
| 79 canvas->DrawPath(path, paint); | 79 canvas->DrawPath(path, paint); |
| 80 } | 80 } |
| 81 | 81 |
| 82 void OverflowButton::OnPaint(gfx::Canvas* canvas) { | 82 void OverflowButton::OnPaint(gfx::Canvas* canvas) { |
| 83 ShelfAlignment alignment = shelf_->GetAlignment(); | |
| 84 | |
| 85 gfx::Rect bounds(GetContentsBounds()); | 83 gfx::Rect bounds(GetContentsBounds()); |
| 86 ResourceBundle& rb = ResourceBundle::GetSharedInstance(); | 84 ResourceBundle& rb = ResourceBundle::GetSharedInstance(); |
| 87 int background_image_id = 0; | 85 int background_image_id = 0; |
| 88 if (shelf_->shelf_widget()->shelf()->IsShowingOverflowBubble()) | 86 if (shelf_->IsShowingOverflowBubble()) |
| 89 background_image_id = IDR_AURA_NOTIFICATION_BACKGROUND_PRESSED; | 87 background_image_id = IDR_AURA_NOTIFICATION_BACKGROUND_PRESSED; |
| 90 else if (shelf_->shelf_widget()->GetDimsShelf()) | 88 else if (shelf_->shelf_widget()->GetDimsShelf()) |
| 91 background_image_id = IDR_AURA_NOTIFICATION_BACKGROUND_ON_BLACK; | 89 background_image_id = IDR_AURA_NOTIFICATION_BACKGROUND_ON_BLACK; |
| 92 else | 90 else |
| 93 background_image_id = IDR_AURA_NOTIFICATION_BACKGROUND_NORMAL; | 91 background_image_id = IDR_AURA_NOTIFICATION_BACKGROUND_NORMAL; |
| 94 | 92 |
| 95 const gfx::ImageSkia* background = | 93 const gfx::ImageSkia* background = |
| 96 rb.GetImageNamed(background_image_id).ToImageSkia(); | 94 rb.GetImageNamed(background_image_id).ToImageSkia(); |
| 95 ShelfAlignment alignment = shelf_->alignment(); |
| 97 if (alignment == SHELF_ALIGNMENT_LEFT) { | 96 if (alignment == SHELF_ALIGNMENT_LEFT) { |
| 98 bounds = gfx::Rect( | 97 bounds = gfx::Rect( |
| 99 bounds.right() - background->width() - | 98 bounds.right() - background->width() - |
| 100 ShelfLayoutManager::kShelfItemInset, | 99 ShelfLayoutManager::kShelfItemInset, |
| 101 bounds.y() + (bounds.height() - background->height()) / 2, | 100 bounds.y() + (bounds.height() - background->height()) / 2, |
| 102 background->width(), background->height()); | 101 background->width(), background->height()); |
| 103 } else if (alignment == SHELF_ALIGNMENT_RIGHT) { | 102 } else if (alignment == SHELF_ALIGNMENT_RIGHT) { |
| 104 bounds = gfx::Rect( | 103 bounds = gfx::Rect( |
| 105 bounds.x() + ShelfLayoutManager::kShelfItemInset, | 104 bounds.x() + ShelfLayoutManager::kShelfItemInset, |
| 106 bounds.y() + (bounds.height() - background->height()) / 2, | 105 bounds.y() + (bounds.height() - background->height()) / 2, |
| (...skipping 30 matching lines...) Expand all Loading... |
| 137 image = bottom_image_; | 136 image = bottom_image_; |
| 138 break; | 137 break; |
| 139 } | 138 } |
| 140 | 139 |
| 141 canvas->DrawImageInt(*image, | 140 canvas->DrawImageInt(*image, |
| 142 bounds.x() + ((bounds.width() - image->width()) / 2), | 141 bounds.x() + ((bounds.width() - image->width()) / 2), |
| 143 bounds.y() + ((bounds.height() - image->height()) / 2)); | 142 bounds.y() + ((bounds.height() - image->height()) / 2)); |
| 144 } | 143 } |
| 145 | 144 |
| 146 } // namespace ash | 145 } // namespace ash |
| OLD | NEW |