Chromium Code Reviews| 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_layout_manager.h" | 8 #include "ash/shelf/shelf_layout_manager.h" |
| 9 #include "ash/shelf/shelf_widget.h" | 9 #include "ash/shelf/shelf_widget.h" |
| 10 #include "grit/ash_resources.h" | 10 #include "grit/ash_resources.h" |
| (...skipping 16 matching lines...) Expand all Loading... | |
| 27 const int kButtonHoverAlpha = 150; | 27 const int kButtonHoverAlpha = 150; |
| 28 | 28 |
| 29 const int kButtonCornerRadius = 2; | 29 const int kButtonCornerRadius = 2; |
| 30 | 30 |
| 31 const int kButtonHoverSize = 28; | 31 const int kButtonHoverSize = 28; |
| 32 | 32 |
| 33 const int kBackgroundOffset = (48 - kButtonHoverSize) / 2; | 33 const int kBackgroundOffset = (48 - kButtonHoverSize) / 2; |
| 34 | 34 |
| 35 } // namesapce | 35 } // namesapce |
| 36 | 36 |
| 37 OverflowButton::OverflowButton(views::ButtonListener* listener) | 37 OverflowButton::OverflowButton(views::ButtonListener* listener, |
| 38 : CustomButton(listener), | 38 ShelfLayoutManager* shelf) |
| 39 bottom_image_(NULL) { | 39 : CustomButton(listener), bottom_image_(NULL), shelf_(shelf) { |
|
sky
2016/02/03 00:01:42
nit: nullptr
sadrul
2016/02/03 02:07:58
Done.
| |
| 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 |
| 49 void OverflowButton::OnShelfAlignmentChanged() { | 49 void OverflowButton::OnShelfAlignmentChanged() { |
| 50 SchedulePaint(); | 50 SchedulePaint(); |
| 51 } | 51 } |
| 52 | 52 |
| 53 void OverflowButton::PaintBackground(gfx::Canvas* canvas, int alpha) { | 53 void OverflowButton::PaintBackground(gfx::Canvas* canvas, int alpha) { |
| 54 gfx::Rect bounds(GetContentsBounds()); | 54 gfx::Rect bounds(GetContentsBounds()); |
| 55 gfx::Rect rect(0, 0, kButtonHoverSize, kButtonHoverSize); | 55 gfx::Rect rect(0, 0, kButtonHoverSize, kButtonHoverSize); |
| 56 ShelfLayoutManager* shelf = | |
| 57 ShelfLayoutManager::ForShelf(GetWidget()->GetNativeView()); | |
| 58 | 56 |
| 59 // Nudge the background a little to line up right. | 57 // Nudge the background a little to line up right. |
| 60 if (shelf->IsHorizontalAlignment()) { | 58 if (shelf_->IsHorizontalAlignment()) { |
| 61 rect.set_origin(gfx::Point( | 59 rect.set_origin(gfx::Point( |
| 62 bounds.x() + ((bounds.width() - kButtonHoverSize) / 2) - 1, | 60 bounds.x() + ((bounds.width() - kButtonHoverSize) / 2) - 1, |
| 63 bounds.y() + kBackgroundOffset - 1)); | 61 bounds.y() + kBackgroundOffset - 1)); |
| 64 | 62 |
| 65 } else { | 63 } else { |
| 66 rect.set_origin(gfx::Point( | 64 rect.set_origin(gfx::Point( |
| 67 bounds.x() + kBackgroundOffset - 1, | 65 bounds.x() + kBackgroundOffset - 1, |
| 68 bounds.y() + ((bounds.height() - kButtonHoverSize) / 2) - 1)); | 66 bounds.y() + ((bounds.height() - kButtonHoverSize) / 2) - 1)); |
| 69 } | 67 } |
| 70 | 68 |
| 71 SkPaint paint; | 69 SkPaint paint; |
| 72 paint.setAntiAlias(true); | 70 paint.setAntiAlias(true); |
| 73 paint.setStyle(SkPaint::kFill_Style); | 71 paint.setStyle(SkPaint::kFill_Style); |
| 74 paint.setColor( | 72 paint.setColor( |
| 75 SkColorSetA(SK_ColorBLACK, | 73 SkColorSetA(SK_ColorBLACK, |
| 76 hover_animation().CurrentValueBetween(0, kButtonHoverAlpha))); | 74 hover_animation().CurrentValueBetween(0, kButtonHoverAlpha))); |
| 77 | 75 |
| 78 const SkScalar radius = SkIntToScalar(kButtonCornerRadius); | 76 const SkScalar radius = SkIntToScalar(kButtonCornerRadius); |
| 79 SkPath path; | 77 SkPath path; |
| 80 path.addRoundRect(gfx::RectToSkRect(rect), radius, radius); | 78 path.addRoundRect(gfx::RectToSkRect(rect), radius, radius); |
| 81 canvas->DrawPath(path, paint); | 79 canvas->DrawPath(path, paint); |
| 82 } | 80 } |
| 83 | 81 |
| 84 void OverflowButton::OnPaint(gfx::Canvas* canvas) { | 82 void OverflowButton::OnPaint(gfx::Canvas* canvas) { |
| 85 ShelfLayoutManager* layout_manager = | 83 ShelfAlignment alignment = shelf_->GetAlignment(); |
| 86 ShelfLayoutManager::ForShelf(GetWidget()->GetNativeView()); | |
| 87 ShelfAlignment alignment = layout_manager->GetAlignment(); | |
| 88 | 84 |
| 89 gfx::Rect bounds(GetContentsBounds()); | 85 gfx::Rect bounds(GetContentsBounds()); |
| 90 ResourceBundle& rb = ResourceBundle::GetSharedInstance(); | 86 ResourceBundle& rb = ResourceBundle::GetSharedInstance(); |
| 91 int background_image_id = 0; | 87 int background_image_id = 0; |
| 92 if (layout_manager->shelf_widget()->shelf()->IsShowingOverflowBubble()) | 88 if (shelf_->shelf_widget()->shelf()->IsShowingOverflowBubble()) |
| 93 background_image_id = IDR_AURA_NOTIFICATION_BACKGROUND_PRESSED; | 89 background_image_id = IDR_AURA_NOTIFICATION_BACKGROUND_PRESSED; |
| 94 else if(layout_manager->shelf_widget()->GetDimsShelf()) | 90 else if (shelf_->shelf_widget()->GetDimsShelf()) |
| 95 background_image_id = IDR_AURA_NOTIFICATION_BACKGROUND_ON_BLACK; | 91 background_image_id = IDR_AURA_NOTIFICATION_BACKGROUND_ON_BLACK; |
| 96 else | 92 else |
| 97 background_image_id = IDR_AURA_NOTIFICATION_BACKGROUND_NORMAL; | 93 background_image_id = IDR_AURA_NOTIFICATION_BACKGROUND_NORMAL; |
| 98 | 94 |
| 99 const gfx::ImageSkia* background = | 95 const gfx::ImageSkia* background = |
| 100 rb.GetImageNamed(background_image_id).ToImageSkia(); | 96 rb.GetImageNamed(background_image_id).ToImageSkia(); |
| 101 if (alignment == SHELF_ALIGNMENT_LEFT) { | 97 if (alignment == SHELF_ALIGNMENT_LEFT) { |
| 102 bounds = gfx::Rect( | 98 bounds = gfx::Rect( |
| 103 bounds.right() - background->width() - | 99 bounds.right() - background->width() - |
| 104 ShelfLayoutManager::kShelfItemInset, | 100 ShelfLayoutManager::kShelfItemInset, |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 141 image = bottom_image_; | 137 image = bottom_image_; |
| 142 break; | 138 break; |
| 143 } | 139 } |
| 144 | 140 |
| 145 canvas->DrawImageInt(*image, | 141 canvas->DrawImageInt(*image, |
| 146 bounds.x() + ((bounds.width() - image->width()) / 2), | 142 bounds.x() + ((bounds.width() - image->width()) / 2), |
| 147 bounds.y() + ((bounds.height() - image->height()) / 2)); | 143 bounds.y() + ((bounds.height() - image->height()) / 2)); |
| 148 } | 144 } |
| 149 | 145 |
| 150 } // namespace ash | 146 } // namespace ash |
| OLD | NEW |