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/common/shelf/overflow_button.h" | 5 #include "ash/common/shelf/overflow_button.h" |
| 6 | 6 |
| 7 #include "ash/common/ash_constants.h" | 7 #include "ash/common/ash_constants.h" |
| 8 #include "ash/common/material_design/material_design_controller.h" | 8 #include "ash/common/material_design/material_design_controller.h" |
| 9 #include "ash/common/shelf/ink_drop_button_listener.h" | 9 #include "ash/common/shelf/ink_drop_button_listener.h" |
| 10 #include "ash/common/shelf/shelf_constants.h" | 10 #include "ash/common/shelf/shelf_constants.h" |
| 11 #include "ash/common/shelf/wm_shelf.h" | 11 #include "ash/common/shelf/wm_shelf.h" |
| 12 #include "ash/common/shelf/wm_shelf_util.h" | 12 #include "ash/common/shelf/wm_shelf_util.h" |
| 13 #include "grit/ash_resources.h" | 13 #include "grit/ash_resources.h" |
| 14 #include "grit/ash_strings.h" | 14 #include "grit/ash_strings.h" |
| 15 #include "third_party/skia/include/core/SkPaint.h" | 15 #include "third_party/skia/include/core/SkPaint.h" |
| 16 #include "third_party/skia/include/core/SkPath.h" | 16 #include "third_party/skia/include/core/SkPath.h" |
| 17 #include "ui/base/l10n/l10n_util.h" | 17 #include "ui/base/l10n/l10n_util.h" |
| 18 #include "ui/base/resource/resource_bundle.h" | 18 #include "ui/base/resource/resource_bundle.h" |
| 19 #include "ui/gfx/canvas.h" | 19 #include "ui/gfx/canvas.h" |
| 20 #include "ui/gfx/image/image_skia_operations.h" | 20 #include "ui/gfx/image/image_skia_operations.h" |
| 21 #include "ui/gfx/paint_vector_icon.h" | 21 #include "ui/gfx/paint_vector_icon.h" |
| 22 #include "ui/gfx/skbitmap_operations.h" | 22 #include "ui/gfx/skbitmap_operations.h" |
| 23 #include "ui/gfx/skia_util.h" | 23 #include "ui/gfx/skia_util.h" |
| 24 #include "ui/gfx/transform.h" | 24 #include "ui/gfx/transform.h" |
| 25 #include "ui/gfx/vector_icons_public.h" | 25 #include "ui/gfx/vector_icons_public.h" |
| 26 #include "ui/views/animation/flood_fill_ink_drop_ripple.h" | |
| 26 | 27 |
| 27 namespace ash { | 28 namespace ash { |
| 28 | 29 |
| 29 OverflowButton::OverflowButton(InkDropButtonListener* listener, | 30 OverflowButton::OverflowButton(InkDropButtonListener* listener, |
| 30 WmShelf* wm_shelf) | 31 WmShelf* wm_shelf) |
| 31 : CustomButton(nullptr), | 32 : CustomButton(nullptr), |
| 32 bottom_image_(nullptr), | 33 bottom_image_(nullptr), |
| 33 listener_(listener), | 34 listener_(listener), |
| 34 wm_shelf_(wm_shelf) { | 35 wm_shelf_(wm_shelf) { |
| 35 if (MaterialDesignController::IsShelfMaterial()) { | 36 if (MaterialDesignController::IsShelfMaterial()) { |
| 37 SetInkDropMode(InkDropMode::ON); | |
| 38 set_ink_drop_base_color(kShelfInkDropBaseColor); | |
| 39 set_ink_drop_visible_opacity(kShelfInkDropVisibleOpacity); | |
| 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 |
| 58 void OverflowButton::OnOverflowBubbleShown() { | |
| 59 AnimateInkDrop(views::InkDropState::ACTIVATED, nullptr); | |
| 60 // While overflow bubble is active, showing context menu should not hide ink | |
| 61 // drop. | |
| 62 set_hide_ink_drop_when_showing_context_menu(false); | |
|
bruthig
2016/07/26 13:57:15
Does this need to be toggled or can it just be ini
mohsen
2016/07/26 20:00:58
My OverflowButton::ShouldEnterPushedState() was wr
| |
| 63 if (!ash::MaterialDesignController::IsShelfMaterial()) | |
| 64 SchedulePaint(); | |
| 65 } | |
| 66 | |
| 67 void OverflowButton::OnOverflowBubbleHidden() { | |
| 68 AnimateInkDrop(views::InkDropState::DEACTIVATED, nullptr); | |
| 69 set_hide_ink_drop_when_showing_context_menu(true); | |
| 70 if (!ash::MaterialDesignController::IsShelfMaterial()) | |
| 71 SchedulePaint(); | |
| 72 } | |
| 73 | |
| 54 void OverflowButton::OnPaint(gfx::Canvas* canvas) { | 74 void OverflowButton::OnPaint(gfx::Canvas* canvas) { |
| 55 gfx::Rect bounds = CalculateButtonBounds(); | 75 gfx::Rect bounds = CalculateButtonBounds(); |
| 56 PaintBackground(canvas, bounds); | 76 PaintBackground(canvas, bounds); |
| 57 PaintForeground(canvas, bounds); | 77 PaintForeground(canvas, bounds); |
| 58 } | 78 } |
| 59 | 79 |
| 80 std::unique_ptr<views::InkDropRipple> OverflowButton::CreateInkDropRipple() | |
| 81 const { | |
| 82 return base::WrapUnique(new views::FloodFillInkDropRipple( | |
| 83 CalculateButtonBounds(), GetInkDropCenterBasedOnLastEvent(), | |
| 84 GetInkDropBaseColor(), ink_drop_visible_opacity())); | |
| 85 } | |
| 86 | |
| 87 bool OverflowButton::ShouldEnterPushedState(const ui::Event& event) { | |
| 88 return !wm_shelf_->IsShowingOverflowBubble(); | |
| 89 } | |
| 90 | |
| 91 bool OverflowButton::ShouldShowInkDropHighlight() const { | |
| 92 return false; | |
| 93 } | |
| 94 | |
| 60 void OverflowButton::NotifyClick(const ui::Event& event) { | 95 void OverflowButton::NotifyClick(const ui::Event& event) { |
| 61 CustomButton::NotifyClick(event); | 96 CustomButton::NotifyClick(event); |
| 62 if (listener_) | 97 if (listener_) |
| 63 listener_->ButtonPressed(this, event, ink_drop()); | 98 listener_->ButtonPressed(this, event, ink_drop()); |
| 64 } | 99 } |
| 65 | 100 |
| 66 void OverflowButton::PaintBackground(gfx::Canvas* canvas, | 101 void OverflowButton::PaintBackground(gfx::Canvas* canvas, |
| 67 const gfx::Rect& bounds) { | 102 const gfx::Rect& bounds) { |
| 68 if (MaterialDesignController::IsShelfMaterial()) { | 103 if (MaterialDesignController::IsShelfMaterial()) { |
| 69 SkColor background_color = SK_ColorTRANSPARENT; | 104 SkColor background_color = SK_ColorTRANSPARENT; |
| 70 if (wm_shelf_->GetBackgroundType() == | 105 if (wm_shelf_->GetBackgroundType() == |
| 71 ShelfBackgroundType::SHELF_BACKGROUND_DEFAULT) { | 106 ShelfBackgroundType::SHELF_BACKGROUND_DEFAULT) { |
| 72 background_color = SkColorSetA(kShelfBaseColor, | 107 background_color = SkColorSetA(kShelfBaseColor, |
| 73 GetShelfConstant(SHELF_BACKGROUND_ALPHA)); | 108 GetShelfConstant(SHELF_BACKGROUND_ALPHA)); |
| 74 } | 109 } |
| 75 | 110 |
| 76 // TODO(bruthig|tdanderson): The background should be changed using a | 111 // TODO(bruthig|tdanderson): The background should be changed using a |
| 77 // fade in/out animation. | 112 // fade in/out animation. |
| 78 SkPaint background_paint; | 113 SkPaint background_paint; |
| 79 background_paint.setFlags(SkPaint::kAntiAlias_Flag); | 114 background_paint.setFlags(SkPaint::kAntiAlias_Flag); |
| 80 background_paint.setColor(background_color); | 115 background_paint.setColor(background_color); |
| 81 canvas->DrawRoundRect(bounds, kOverflowButtonCornerRadius, | 116 canvas->DrawRoundRect(bounds, kOverflowButtonCornerRadius, |
| 82 background_paint); | 117 background_paint); |
| 83 | |
| 84 if (wm_shelf_->IsShowingOverflowBubble()) { | |
| 85 SkPaint highlight_paint; | |
| 86 highlight_paint.setFlags(SkPaint::kAntiAlias_Flag); | |
| 87 highlight_paint.setColor(kShelfButtonActivatedHighlightColor); | |
| 88 canvas->DrawRoundRect(bounds, kOverflowButtonCornerRadius, | |
| 89 highlight_paint); | |
| 90 } | |
| 91 } else { | 118 } else { |
| 92 ResourceBundle& rb = ResourceBundle::GetSharedInstance(); | 119 ResourceBundle& rb = ResourceBundle::GetSharedInstance(); |
| 93 const gfx::ImageSkia* background = | 120 const gfx::ImageSkia* background = |
| 94 rb.GetImageNamed(NonMaterialBackgroundImageId()).ToImageSkia(); | 121 rb.GetImageNamed(NonMaterialBackgroundImageId()).ToImageSkia(); |
| 95 canvas->DrawImageInt(*background, bounds.x(), bounds.y()); | 122 canvas->DrawImageInt(*background, bounds.x(), bounds.y()); |
| 96 } | 123 } |
| 97 } | 124 } |
| 98 | 125 |
| 99 void OverflowButton::PaintForeground(gfx::Canvas* canvas, | 126 void OverflowButton::PaintForeground(gfx::Canvas* canvas, |
| 100 const gfx::Rect& bounds) { | 127 const gfx::Rect& bounds) { |
| (...skipping 17 matching lines...) Expand all Loading... | |
| 118 default: | 145 default: |
| 119 image = bottom_image_; | 146 image = bottom_image_; |
| 120 break; | 147 break; |
| 121 } | 148 } |
| 122 | 149 |
| 123 canvas->DrawImageInt(*image, | 150 canvas->DrawImageInt(*image, |
| 124 bounds.x() + ((bounds.width() - image->width()) / 2), | 151 bounds.x() + ((bounds.width() - image->width()) / 2), |
| 125 bounds.y() + ((bounds.height() - image->height()) / 2)); | 152 bounds.y() + ((bounds.height() - image->height()) / 2)); |
| 126 } | 153 } |
| 127 | 154 |
| 128 int OverflowButton::NonMaterialBackgroundImageId() { | 155 int OverflowButton::NonMaterialBackgroundImageId() const { |
| 129 if (wm_shelf_->IsShowingOverflowBubble()) | 156 if (wm_shelf_->IsShowingOverflowBubble()) |
| 130 return IDR_AURA_NOTIFICATION_BACKGROUND_PRESSED; | 157 return IDR_AURA_NOTIFICATION_BACKGROUND_PRESSED; |
| 131 else if (wm_shelf_->IsDimmed()) | 158 else if (wm_shelf_->IsDimmed()) |
| 132 return IDR_AURA_NOTIFICATION_BACKGROUND_ON_BLACK; | 159 return IDR_AURA_NOTIFICATION_BACKGROUND_ON_BLACK; |
| 133 return IDR_AURA_NOTIFICATION_BACKGROUND_NORMAL; | 160 return IDR_AURA_NOTIFICATION_BACKGROUND_NORMAL; |
| 134 } | 161 } |
| 135 | 162 |
| 136 gfx::Rect OverflowButton::CalculateButtonBounds() { | 163 gfx::Rect OverflowButton::CalculateButtonBounds() const { |
| 137 ShelfAlignment alignment = wm_shelf_->GetAlignment(); | 164 ShelfAlignment alignment = wm_shelf_->GetAlignment(); |
| 138 gfx::Rect bounds(GetContentsBounds()); | 165 gfx::Rect bounds(GetContentsBounds()); |
| 139 ResourceBundle& rb = ResourceBundle::GetSharedInstance(); | 166 ResourceBundle& rb = ResourceBundle::GetSharedInstance(); |
| 140 if (MaterialDesignController::IsShelfMaterial()) { | 167 if (MaterialDesignController::IsShelfMaterial()) { |
| 141 const int width_offset = (bounds.width() - kOverflowButtonSize) / 2; | 168 const int width_offset = (bounds.width() - kOverflowButtonSize) / 2; |
| 142 const int height_offset = (bounds.height() - kOverflowButtonSize) / 2; | 169 const int height_offset = (bounds.height() - kOverflowButtonSize) / 2; |
| 143 if (IsHorizontalAlignment(alignment)) { | 170 if (IsHorizontalAlignment(alignment)) { |
| 144 bounds = gfx::Rect(bounds.x() + width_offset, bounds.y() + height_offset, | 171 bounds = gfx::Rect(bounds.x() + width_offset, bounds.y() + height_offset, |
| 145 kOverflowButtonSize, kOverflowButtonSize); | 172 kOverflowButtonSize, kOverflowButtonSize); |
| 146 } else { | 173 } else { |
| (...skipping 17 matching lines...) Expand all Loading... | |
| 164 bounds = | 191 bounds = |
| 165 gfx::Rect(bounds.x() + (bounds.width() - background->width()) / 2, | 192 gfx::Rect(bounds.x() + (bounds.width() - background->width()) / 2, |
| 166 bounds.y() + kShelfItemInset, background->width(), | 193 bounds.y() + kShelfItemInset, background->width(), |
| 167 background->height()); | 194 background->height()); |
| 168 } | 195 } |
| 169 } | 196 } |
| 170 return bounds; | 197 return bounds; |
| 171 } | 198 } |
| 172 | 199 |
| 173 } // namespace ash | 200 } // namespace ash |
| OLD | NEW |