| 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/common/ash_constants.h" | 8 #include "ash/common/ash_constants.h" |
| 9 #include "ash/common/material_design/material_design_controller.h" | 9 #include "ash/common/material_design/material_design_controller.h" |
| 10 #include "ash/common/shelf/shelf_constants.h" | 10 #include "ash/common/shelf/shelf_constants.h" |
| 11 #include "ash/common/system/tray/tray_constants.h" | 11 #include "ash/common/system/tray/tray_constants.h" |
| 12 #include "ash/shelf/ink_drop_button_listener.h" |
| 12 #include "ash/shelf/shelf.h" | 13 #include "ash/shelf/shelf.h" |
| 13 #include "ash/shelf/shelf_layout_manager.h" | 14 #include "ash/shelf/shelf_layout_manager.h" |
| 14 #include "ash/shelf/shelf_widget.h" | 15 #include "ash/shelf/shelf_widget.h" |
| 15 #include "grit/ash_resources.h" | 16 #include "grit/ash_resources.h" |
| 16 #include "grit/ash_strings.h" | 17 #include "grit/ash_strings.h" |
| 17 #include "third_party/skia/include/core/SkPaint.h" | 18 #include "third_party/skia/include/core/SkPaint.h" |
| 18 #include "third_party/skia/include/core/SkPath.h" | 19 #include "third_party/skia/include/core/SkPath.h" |
| 19 #include "ui/base/l10n/l10n_util.h" | 20 #include "ui/base/l10n/l10n_util.h" |
| 20 #include "ui/base/resource/resource_bundle.h" | 21 #include "ui/base/resource/resource_bundle.h" |
| 21 #include "ui/gfx/animation/throb_animation.h" | 22 #include "ui/gfx/animation/throb_animation.h" |
| 22 #include "ui/gfx/canvas.h" | 23 #include "ui/gfx/canvas.h" |
| 23 #include "ui/gfx/image/image_skia_operations.h" | 24 #include "ui/gfx/image/image_skia_operations.h" |
| 24 #include "ui/gfx/paint_vector_icon.h" | 25 #include "ui/gfx/paint_vector_icon.h" |
| 25 #include "ui/gfx/skbitmap_operations.h" | 26 #include "ui/gfx/skbitmap_operations.h" |
| 26 #include "ui/gfx/skia_util.h" | 27 #include "ui/gfx/skia_util.h" |
| 27 #include "ui/gfx/transform.h" | 28 #include "ui/gfx/transform.h" |
| 28 #include "ui/gfx/vector_icons_public.h" | 29 #include "ui/gfx/vector_icons_public.h" |
| 29 #include "ui/views/widget/widget.h" | 30 #include "ui/views/widget/widget.h" |
| 30 | 31 |
| 31 namespace ash { | 32 namespace ash { |
| 32 | 33 |
| 33 OverflowButton::OverflowButton(views::ButtonListener* listener, Shelf* shelf) | 34 OverflowButton::OverflowButton(InkDropButtonListener* listener, Shelf* shelf) |
| 34 : CustomButton(listener), bottom_image_(nullptr), shelf_(shelf) { | 35 : CustomButton(nullptr), |
| 36 bottom_image_(nullptr), |
| 37 listener_(listener), |
| 38 shelf_(shelf) { |
| 35 if (MaterialDesignController::IsShelfMaterial()) { | 39 if (MaterialDesignController::IsShelfMaterial()) { |
| 36 bottom_image_md_ = | 40 bottom_image_md_ = |
| 37 CreateVectorIcon(gfx::VectorIconId::SHELF_OVERFLOW, kShelfIconColor); | 41 CreateVectorIcon(gfx::VectorIconId::SHELF_OVERFLOW, kShelfIconColor); |
| 38 bottom_image_ = &bottom_image_md_; | 42 bottom_image_ = &bottom_image_md_; |
| 39 } else { | 43 } else { |
| 40 bottom_image_ = ui::ResourceBundle::GetSharedInstance().GetImageSkiaNamed( | 44 bottom_image_ = ui::ResourceBundle::GetSharedInstance().GetImageSkiaNamed( |
| 41 IDR_ASH_SHELF_OVERFLOW); | 45 IDR_ASH_SHELF_OVERFLOW); |
| 42 } | 46 } |
| 43 | 47 |
| 44 SetFocusBehavior(FocusBehavior::ACCESSIBLE_ONLY); | 48 SetFocusBehavior(FocusBehavior::ACCESSIBLE_ONLY); |
| 45 SetAccessibleName(l10n_util::GetStringUTF16(IDS_ASH_SHELF_OVERFLOW_NAME)); | 49 SetAccessibleName(l10n_util::GetStringUTF16(IDS_ASH_SHELF_OVERFLOW_NAME)); |
| 46 } | 50 } |
| 47 | 51 |
| 48 OverflowButton::~OverflowButton() {} | 52 OverflowButton::~OverflowButton() {} |
| 49 | 53 |
| 50 void OverflowButton::OnShelfAlignmentChanged() { | 54 void OverflowButton::OnShelfAlignmentChanged() { |
| 51 SchedulePaint(); | 55 SchedulePaint(); |
| 52 } | 56 } |
| 53 | 57 |
| 54 void OverflowButton::OnPaint(gfx::Canvas* canvas) { | 58 void OverflowButton::OnPaint(gfx::Canvas* canvas) { |
| 55 gfx::Rect bounds = CalculateButtonBounds(); | 59 gfx::Rect bounds = CalculateButtonBounds(); |
| 56 PaintBackground(canvas, bounds); | 60 PaintBackground(canvas, bounds); |
| 57 PaintForeground(canvas, bounds); | 61 PaintForeground(canvas, bounds); |
| 58 } | 62 } |
| 59 | 63 |
| 64 void OverflowButton::NotifyClick(const ui::Event& event) { |
| 65 CustomButton::NotifyClick(event); |
| 66 if (listener_) |
| 67 listener_->ButtonPressed(this, event, ink_drop()); |
| 68 } |
| 69 |
| 60 void OverflowButton::PaintBackground(gfx::Canvas* canvas, | 70 void OverflowButton::PaintBackground(gfx::Canvas* canvas, |
| 61 const gfx::Rect& bounds) { | 71 const gfx::Rect& bounds) { |
| 62 if (MaterialDesignController::IsShelfMaterial()) { | 72 if (MaterialDesignController::IsShelfMaterial()) { |
| 63 SkColor background_color = SK_ColorTRANSPARENT; | 73 SkColor background_color = SK_ColorTRANSPARENT; |
| 64 ShelfWidget* shelf_widget = shelf_->shelf_widget(); | 74 ShelfWidget* shelf_widget = shelf_->shelf_widget(); |
| 65 if (shelf_widget && | 75 if (shelf_widget && |
| 66 shelf_widget->GetBackgroundType() == | 76 shelf_widget->GetBackgroundType() == |
| 67 ShelfBackgroundType::SHELF_BACKGROUND_DEFAULT) { | 77 ShelfBackgroundType::SHELF_BACKGROUND_DEFAULT) { |
| 68 background_color = SkColorSetA(kShelfBaseColor, | 78 background_color = SkColorSetA(kShelfBaseColor, |
| 69 GetShelfConstant(SHELF_BACKGROUND_ALPHA)); | 79 GetShelfConstant(SHELF_BACKGROUND_ALPHA)); |
| (...skipping 19 matching lines...) Expand all Loading... |
| 89 const gfx::ImageSkia* background = | 99 const gfx::ImageSkia* background = |
| 90 rb.GetImageNamed(NonMaterialBackgroundImageId()).ToImageSkia(); | 100 rb.GetImageNamed(NonMaterialBackgroundImageId()).ToImageSkia(); |
| 91 canvas->DrawImageInt(*background, bounds.x(), bounds.y()); | 101 canvas->DrawImageInt(*background, bounds.x(), bounds.y()); |
| 92 } | 102 } |
| 93 } | 103 } |
| 94 | 104 |
| 95 void OverflowButton::PaintForeground(gfx::Canvas* canvas, | 105 void OverflowButton::PaintForeground(gfx::Canvas* canvas, |
| 96 const gfx::Rect& bounds) { | 106 const gfx::Rect& bounds) { |
| 97 const gfx::ImageSkia* image = nullptr; | 107 const gfx::ImageSkia* image = nullptr; |
| 98 | 108 |
| 99 switch(shelf_->alignment()) { | 109 switch (shelf_->alignment()) { |
| 100 case SHELF_ALIGNMENT_LEFT: | 110 case SHELF_ALIGNMENT_LEFT: |
| 101 if (left_image_.isNull()) { | 111 if (left_image_.isNull()) { |
| 102 left_image_ = gfx::ImageSkiaOperations::CreateRotatedImage( | 112 left_image_ = gfx::ImageSkiaOperations::CreateRotatedImage( |
| 103 *bottom_image_, SkBitmapOperations::ROTATION_90_CW); | 113 *bottom_image_, SkBitmapOperations::ROTATION_90_CW); |
| 104 } | 114 } |
| 105 image = &left_image_; | 115 image = &left_image_; |
| 106 break; | 116 break; |
| 107 case SHELF_ALIGNMENT_RIGHT: | 117 case SHELF_ALIGNMENT_RIGHT: |
| 108 if (right_image_.isNull()) { | 118 if (right_image_.isNull()) { |
| 109 right_image_ = gfx::ImageSkiaOperations::CreateRotatedImage( | 119 right_image_ = gfx::ImageSkiaOperations::CreateRotatedImage( |
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 161 bounds = | 171 bounds = |
| 162 gfx::Rect(bounds.x() + (bounds.width() - background->width()) / 2, | 172 gfx::Rect(bounds.x() + (bounds.width() - background->width()) / 2, |
| 163 bounds.y() + kShelfItemInset, background->width(), | 173 bounds.y() + kShelfItemInset, background->width(), |
| 164 background->height()); | 174 background->height()); |
| 165 } | 175 } |
| 166 } | 176 } |
| 167 return bounds; | 177 return bounds; |
| 168 } | 178 } |
| 169 | 179 |
| 170 } // namespace ash | 180 } // namespace ash |
| OLD | NEW |