| 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/common/shelf/overflow_button.h" | 5 #include "ash/common/shelf/overflow_button.h" |
| 6 | 6 |
| 7 #include "ash/common/ash_constants.h" | |
| 8 #include "ash/common/material_design/material_design_controller.h" | |
| 9 #include "ash/common/shelf/ink_drop_button_listener.h" | |
| 10 #include "ash/common/shelf/shelf_constants.h" | 7 #include "ash/common/shelf/shelf_constants.h" |
| 11 #include "ash/common/shelf/shelf_view.h" | 8 #include "ash/common/shelf/shelf_view.h" |
| 12 #include "ash/common/shelf/wm_shelf.h" | 9 #include "ash/common/shelf/wm_shelf.h" |
| 13 #include "ash/common/shelf/wm_shelf_util.h" | |
| 14 #include "ash/common/strings/grit/ash_strings.h" | 10 #include "ash/common/strings/grit/ash_strings.h" |
| 15 #include "ash/resources/grit/ash_resources.h" | |
| 16 #include "ash/resources/vector_icons/vector_icons.h" | 11 #include "ash/resources/vector_icons/vector_icons.h" |
| 17 #include "base/memory/ptr_util.h" | 12 #include "base/memory/ptr_util.h" |
| 18 #include "third_party/skia/include/core/SkPath.h" | |
| 19 #include "ui/base/l10n/l10n_util.h" | 13 #include "ui/base/l10n/l10n_util.h" |
| 20 #include "ui/base/resource/resource_bundle.h" | |
| 21 #include "ui/gfx/canvas.h" | 14 #include "ui/gfx/canvas.h" |
| 22 #include "ui/gfx/image/image_skia_operations.h" | 15 #include "ui/gfx/image/image_skia_operations.h" |
| 23 #include "ui/gfx/paint_vector_icon.h" | 16 #include "ui/gfx/paint_vector_icon.h" |
| 24 #include "ui/gfx/skbitmap_operations.h" | 17 #include "ui/gfx/skbitmap_operations.h" |
| 25 #include "ui/gfx/skia_util.h" | |
| 26 #include "ui/gfx/transform.h" | |
| 27 #include "ui/views/animation/flood_fill_ink_drop_ripple.h" | 18 #include "ui/views/animation/flood_fill_ink_drop_ripple.h" |
| 28 #include "ui/views/animation/ink_drop_impl.h" | 19 #include "ui/views/animation/ink_drop_impl.h" |
| 29 #include "ui/views/animation/ink_drop_mask.h" | 20 #include "ui/views/animation/ink_drop_mask.h" |
| 30 | 21 |
| 31 namespace ash { | 22 namespace ash { |
| 32 | 23 |
| 33 OverflowButton::OverflowButton(ShelfView* shelf_view, WmShelf* wm_shelf) | 24 OverflowButton::OverflowButton(ShelfView* shelf_view, WmShelf* wm_shelf) |
| 34 : CustomButton(nullptr), | 25 : CustomButton(nullptr), |
| 35 bottom_image_(nullptr), | |
| 36 shelf_view_(shelf_view), | 26 shelf_view_(shelf_view), |
| 37 wm_shelf_(wm_shelf), | 27 wm_shelf_(wm_shelf), |
| 38 background_color_(kShelfDefaultBaseColor) { | 28 background_color_(kShelfDefaultBaseColor) { |
| 39 DCHECK(shelf_view_); | 29 DCHECK(shelf_view_); |
| 40 if (MaterialDesignController::IsShelfMaterial()) { | 30 |
| 41 SetInkDropMode(InkDropMode::ON); | 31 SetInkDropMode(InkDropMode::ON); |
| 42 set_ink_drop_base_color(kShelfInkDropBaseColor); | 32 set_ink_drop_base_color(kShelfInkDropBaseColor); |
| 43 set_ink_drop_visible_opacity(kShelfInkDropVisibleOpacity); | 33 set_ink_drop_visible_opacity(kShelfInkDropVisibleOpacity); |
| 44 set_hide_ink_drop_when_showing_context_menu(false); | 34 set_hide_ink_drop_when_showing_context_menu(false); |
| 45 bottom_image_md_ = CreateVectorIcon(kShelfOverflowIcon, kShelfIconColor); | 35 bottom_image_ = gfx::CreateVectorIcon(kShelfOverflowIcon, kShelfIconColor); |
| 46 bottom_image_ = &bottom_image_md_; | |
| 47 } else { | |
| 48 bottom_image_ = ui::ResourceBundle::GetSharedInstance().GetImageSkiaNamed( | |
| 49 IDR_ASH_SHELF_OVERFLOW); | |
| 50 } | |
| 51 | 36 |
| 52 SetFocusBehavior(FocusBehavior::ACCESSIBLE_ONLY); | 37 SetFocusBehavior(FocusBehavior::ACCESSIBLE_ONLY); |
| 53 SetAccessibleName(l10n_util::GetStringUTF16(IDS_ASH_SHELF_OVERFLOW_NAME)); | 38 SetAccessibleName(l10n_util::GetStringUTF16(IDS_ASH_SHELF_OVERFLOW_NAME)); |
| 54 } | 39 } |
| 55 | 40 |
| 56 OverflowButton::~OverflowButton() {} | 41 OverflowButton::~OverflowButton() {} |
| 57 | 42 |
| 58 void OverflowButton::OnShelfAlignmentChanged() { | 43 void OverflowButton::OnShelfAlignmentChanged() { |
| 59 SchedulePaint(); | 44 SchedulePaint(); |
| 60 } | 45 } |
| 61 | 46 |
| 62 void OverflowButton::OnOverflowBubbleShown() { | 47 void OverflowButton::OnOverflowBubbleShown() { |
| 63 AnimateInkDrop(views::InkDropState::ACTIVATED, nullptr); | 48 AnimateInkDrop(views::InkDropState::ACTIVATED, nullptr); |
| 64 if (!ash::MaterialDesignController::IsShelfMaterial()) | |
| 65 SchedulePaint(); | |
| 66 } | 49 } |
| 67 | 50 |
| 68 void OverflowButton::OnOverflowBubbleHidden() { | 51 void OverflowButton::OnOverflowBubbleHidden() { |
| 69 AnimateInkDrop(views::InkDropState::DEACTIVATED, nullptr); | 52 AnimateInkDrop(views::InkDropState::DEACTIVATED, nullptr); |
| 70 if (!ash::MaterialDesignController::IsShelfMaterial()) | |
| 71 SchedulePaint(); | |
| 72 } | 53 } |
| 73 | 54 |
| 74 void OverflowButton::UpdateShelfItemBackground(SkColor color) { | 55 void OverflowButton::UpdateShelfItemBackground(SkColor color) { |
| 75 background_color_ = color; | 56 background_color_ = color; |
| 76 SchedulePaint(); | 57 SchedulePaint(); |
| 77 } | 58 } |
| 78 | 59 |
| 79 void OverflowButton::OnPaint(gfx::Canvas* canvas) { | 60 void OverflowButton::OnPaint(gfx::Canvas* canvas) { |
| 80 gfx::Rect bounds = CalculateButtonBounds(); | 61 gfx::Rect bounds = CalculateButtonBounds(); |
| 81 PaintBackground(canvas, bounds); | 62 PaintBackground(canvas, bounds); |
| (...skipping 29 matching lines...) Expand all Loading... |
| 111 } | 92 } |
| 112 | 93 |
| 113 std::unique_ptr<views::InkDropMask> OverflowButton::CreateInkDropMask() const { | 94 std::unique_ptr<views::InkDropMask> OverflowButton::CreateInkDropMask() const { |
| 114 gfx::Insets insets = GetLocalBounds().InsetsFrom(CalculateButtonBounds()); | 95 gfx::Insets insets = GetLocalBounds().InsetsFrom(CalculateButtonBounds()); |
| 115 return base::MakeUnique<views::RoundRectInkDropMask>( | 96 return base::MakeUnique<views::RoundRectInkDropMask>( |
| 116 size(), insets, kOverflowButtonCornerRadius); | 97 size(), insets, kOverflowButtonCornerRadius); |
| 117 } | 98 } |
| 118 | 99 |
| 119 void OverflowButton::PaintBackground(gfx::Canvas* canvas, | 100 void OverflowButton::PaintBackground(gfx::Canvas* canvas, |
| 120 const gfx::Rect& bounds) { | 101 const gfx::Rect& bounds) { |
| 121 if (MaterialDesignController::IsShelfMaterial()) { | 102 cc::PaintFlags flags; |
| 122 cc::PaintFlags flags; | 103 flags.setFlags(cc::PaintFlags::kAntiAlias_Flag); |
| 123 flags.setFlags(cc::PaintFlags::kAntiAlias_Flag); | 104 flags.setColor(background_color_); |
| 124 flags.setColor(background_color_); | 105 canvas->DrawRoundRect(bounds, kOverflowButtonCornerRadius, flags); |
| 125 canvas->DrawRoundRect(bounds, kOverflowButtonCornerRadius, flags); | |
| 126 } else { | |
| 127 ResourceBundle& rb = ResourceBundle::GetSharedInstance(); | |
| 128 const gfx::ImageSkia* background = | |
| 129 rb.GetImageNamed(NonMaterialBackgroundImageId()).ToImageSkia(); | |
| 130 canvas->DrawImageInt(*background, bounds.x(), bounds.y()); | |
| 131 } | |
| 132 } | 106 } |
| 133 | 107 |
| 134 void OverflowButton::PaintForeground(gfx::Canvas* canvas, | 108 void OverflowButton::PaintForeground(gfx::Canvas* canvas, |
| 135 const gfx::Rect& bounds) { | 109 const gfx::Rect& bounds) { |
| 136 const gfx::ImageSkia* image = nullptr; | 110 const gfx::ImageSkia* image = nullptr; |
| 137 | 111 |
| 138 switch (wm_shelf_->GetAlignment()) { | 112 switch (wm_shelf_->GetAlignment()) { |
| 139 case SHELF_ALIGNMENT_LEFT: | 113 case SHELF_ALIGNMENT_LEFT: |
| 140 if (left_image_.isNull()) { | 114 if (left_image_.isNull()) { |
| 141 left_image_ = gfx::ImageSkiaOperations::CreateRotatedImage( | 115 left_image_ = gfx::ImageSkiaOperations::CreateRotatedImage( |
| 142 *bottom_image_, SkBitmapOperations::ROTATION_90_CW); | 116 bottom_image_, SkBitmapOperations::ROTATION_90_CW); |
| 143 } | 117 } |
| 144 image = &left_image_; | 118 image = &left_image_; |
| 145 break; | 119 break; |
| 146 case SHELF_ALIGNMENT_RIGHT: | 120 case SHELF_ALIGNMENT_RIGHT: |
| 147 if (right_image_.isNull()) { | 121 if (right_image_.isNull()) { |
| 148 right_image_ = gfx::ImageSkiaOperations::CreateRotatedImage( | 122 right_image_ = gfx::ImageSkiaOperations::CreateRotatedImage( |
| 149 *bottom_image_, SkBitmapOperations::ROTATION_270_CW); | 123 bottom_image_, SkBitmapOperations::ROTATION_270_CW); |
| 150 } | 124 } |
| 151 image = &right_image_; | 125 image = &right_image_; |
| 152 break; | 126 break; |
| 153 default: | 127 default: |
| 154 image = bottom_image_; | 128 image = &bottom_image_; |
| 155 break; | 129 break; |
| 156 } | 130 } |
| 157 | 131 |
| 158 canvas->DrawImageInt(*image, | 132 canvas->DrawImageInt(*image, |
| 159 bounds.x() + ((bounds.width() - image->width()) / 2), | 133 bounds.x() + ((bounds.width() - image->width()) / 2), |
| 160 bounds.y() + ((bounds.height() - image->height()) / 2)); | 134 bounds.y() + ((bounds.height() - image->height()) / 2)); |
| 161 } | 135 } |
| 162 | 136 |
| 163 int OverflowButton::NonMaterialBackgroundImageId() const { | |
| 164 if (shelf_view_->IsShowingOverflowBubble()) | |
| 165 return IDR_AURA_NOTIFICATION_BACKGROUND_PRESSED; | |
| 166 return IDR_AURA_NOTIFICATION_BACKGROUND_NORMAL; | |
| 167 } | |
| 168 | |
| 169 gfx::Rect OverflowButton::CalculateButtonBounds() const { | 137 gfx::Rect OverflowButton::CalculateButtonBounds() const { |
| 170 ShelfAlignment alignment = wm_shelf_->GetAlignment(); | 138 ShelfAlignment alignment = wm_shelf_->GetAlignment(); |
| 171 gfx::Rect bounds(GetContentsBounds()); | 139 gfx::Rect content_bounds = GetContentsBounds(); |
| 172 if (MaterialDesignController::IsShelfMaterial()) { | 140 // Align the button to the top of a bottom-aligned shelf, to the right edge |
| 173 // Align the button to the top of a bottom-aligned shelf, to the right edge | 141 // a left-aligned shelf, and to the left edge of a right-aligned shelf. |
| 174 // a left-aligned shelf, and to the left edge of a right-aligned shelf. | 142 const int inset = (GetShelfConstant(SHELF_SIZE) - kOverflowButtonSize) / 2; |
| 175 const int inset = (GetShelfConstant(SHELF_SIZE) - kOverflowButtonSize) / 2; | 143 const int x = alignment == SHELF_ALIGNMENT_LEFT |
| 176 const int x = alignment == SHELF_ALIGNMENT_LEFT | 144 ? content_bounds.right() - inset - kOverflowButtonSize |
| 177 ? bounds.right() - inset - kOverflowButtonSize | 145 : content_bounds.x() + inset; |
| 178 : bounds.x() + inset; | 146 return gfx::Rect(x, content_bounds.y() + inset, kOverflowButtonSize, |
| 179 bounds = gfx::Rect(x, bounds.y() + inset, kOverflowButtonSize, | 147 kOverflowButtonSize); |
| 180 kOverflowButtonSize); | |
| 181 } else { | |
| 182 ResourceBundle& rb = ResourceBundle::GetSharedInstance(); | |
| 183 const gfx::ImageSkia* background = | |
| 184 rb.GetImageNamed(NonMaterialBackgroundImageId()).ToImageSkia(); | |
| 185 if (alignment == SHELF_ALIGNMENT_LEFT) { | |
| 186 bounds = | |
| 187 gfx::Rect(bounds.right() - background->width() - kShelfItemInset, | |
| 188 bounds.y() + (bounds.height() - background->height()) / 2, | |
| 189 background->width(), background->height()); | |
| 190 } else if (alignment == SHELF_ALIGNMENT_RIGHT) { | |
| 191 bounds = | |
| 192 gfx::Rect(bounds.x() + kShelfItemInset, | |
| 193 bounds.y() + (bounds.height() - background->height()) / 2, | |
| 194 background->width(), background->height()); | |
| 195 } else { | |
| 196 bounds = | |
| 197 gfx::Rect(bounds.x() + (bounds.width() - background->width()) / 2, | |
| 198 bounds.y() + kShelfItemInset, background->width(), | |
| 199 background->height()); | |
| 200 } | |
| 201 } | |
| 202 return bounds; | |
| 203 } | 148 } |
| 204 | 149 |
| 205 } // namespace ash | 150 } // namespace ash |
| OLD | NEW |