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/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/ash_switches.h" | |
9 #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" |
10 #include "ash/common/shelf/shelf_constants.h" | 10 #include "ash/common/shelf/shelf_constants.h" |
11 #include "ash/shelf/ink_drop_button_listener.h" | 11 #include "ash/common/shelf/wm_shelf.h" |
12 #include "ash/shelf/shelf.h" | 12 #include "ash/common/shelf/wm_shelf_util.h" |
13 #include "ash/shelf/shelf_layout_manager.h" | |
14 #include "ash/shelf/shelf_widget.h" | |
15 #include "grit/ash_resources.h" | 13 #include "grit/ash_resources.h" |
16 #include "grit/ash_strings.h" | 14 #include "grit/ash_strings.h" |
17 #include "third_party/skia/include/core/SkPaint.h" | 15 #include "third_party/skia/include/core/SkPaint.h" |
18 #include "third_party/skia/include/core/SkPath.h" | 16 #include "third_party/skia/include/core/SkPath.h" |
19 #include "ui/base/l10n/l10n_util.h" | 17 #include "ui/base/l10n/l10n_util.h" |
20 #include "ui/base/resource/resource_bundle.h" | 18 #include "ui/base/resource/resource_bundle.h" |
21 #include "ui/gfx/animation/throb_animation.h" | |
22 #include "ui/gfx/canvas.h" | 19 #include "ui/gfx/canvas.h" |
23 #include "ui/gfx/image/image_skia_operations.h" | 20 #include "ui/gfx/image/image_skia_operations.h" |
24 #include "ui/gfx/paint_vector_icon.h" | 21 #include "ui/gfx/paint_vector_icon.h" |
25 #include "ui/gfx/skbitmap_operations.h" | 22 #include "ui/gfx/skbitmap_operations.h" |
26 #include "ui/gfx/skia_util.h" | 23 #include "ui/gfx/skia_util.h" |
27 #include "ui/gfx/transform.h" | 24 #include "ui/gfx/transform.h" |
28 #include "ui/gfx/vector_icons_public.h" | 25 #include "ui/gfx/vector_icons_public.h" |
29 #include "ui/views/widget/widget.h" | |
30 | 26 |
31 namespace ash { | 27 namespace ash { |
32 | 28 |
33 OverflowButton::OverflowButton(InkDropButtonListener* listener, Shelf* shelf) | 29 OverflowButton::OverflowButton(InkDropButtonListener* listener, |
| 30 WmShelf* wm_shelf) |
34 : CustomButton(nullptr), | 31 : CustomButton(nullptr), |
35 bottom_image_(nullptr), | 32 bottom_image_(nullptr), |
36 listener_(listener), | 33 listener_(listener), |
37 shelf_(shelf) { | 34 wm_shelf_(wm_shelf) { |
38 if (MaterialDesignController::IsShelfMaterial()) { | 35 if (MaterialDesignController::IsShelfMaterial()) { |
39 bottom_image_md_ = | 36 bottom_image_md_ = |
40 CreateVectorIcon(gfx::VectorIconId::SHELF_OVERFLOW, kShelfIconColor); | 37 CreateVectorIcon(gfx::VectorIconId::SHELF_OVERFLOW, kShelfIconColor); |
41 bottom_image_ = &bottom_image_md_; | 38 bottom_image_ = &bottom_image_md_; |
42 } else { | 39 } else { |
43 bottom_image_ = ui::ResourceBundle::GetSharedInstance().GetImageSkiaNamed( | 40 bottom_image_ = ui::ResourceBundle::GetSharedInstance().GetImageSkiaNamed( |
44 IDR_ASH_SHELF_OVERFLOW); | 41 IDR_ASH_SHELF_OVERFLOW); |
45 } | 42 } |
46 | 43 |
47 SetFocusBehavior(FocusBehavior::ACCESSIBLE_ONLY); | 44 SetFocusBehavior(FocusBehavior::ACCESSIBLE_ONLY); |
(...skipping 15 matching lines...) Expand all Loading... |
63 void OverflowButton::NotifyClick(const ui::Event& event) { | 60 void OverflowButton::NotifyClick(const ui::Event& event) { |
64 CustomButton::NotifyClick(event); | 61 CustomButton::NotifyClick(event); |
65 if (listener_) | 62 if (listener_) |
66 listener_->ButtonPressed(this, event, ink_drop()); | 63 listener_->ButtonPressed(this, event, ink_drop()); |
67 } | 64 } |
68 | 65 |
69 void OverflowButton::PaintBackground(gfx::Canvas* canvas, | 66 void OverflowButton::PaintBackground(gfx::Canvas* canvas, |
70 const gfx::Rect& bounds) { | 67 const gfx::Rect& bounds) { |
71 if (MaterialDesignController::IsShelfMaterial()) { | 68 if (MaterialDesignController::IsShelfMaterial()) { |
72 SkColor background_color = SK_ColorTRANSPARENT; | 69 SkColor background_color = SK_ColorTRANSPARENT; |
73 ShelfWidget* shelf_widget = shelf_->shelf_widget(); | 70 if (wm_shelf_->GetBackgroundType() == |
74 if (shelf_widget && | 71 ShelfBackgroundType::SHELF_BACKGROUND_DEFAULT) { |
75 shelf_widget->GetBackgroundType() == | |
76 ShelfBackgroundType::SHELF_BACKGROUND_DEFAULT) { | |
77 background_color = SkColorSetA(kShelfBaseColor, | 72 background_color = SkColorSetA(kShelfBaseColor, |
78 GetShelfConstant(SHELF_BACKGROUND_ALPHA)); | 73 GetShelfConstant(SHELF_BACKGROUND_ALPHA)); |
79 } | 74 } |
80 | 75 |
81 // TODO(bruthig|tdanderson): The background should be changed using a | 76 // TODO(bruthig|tdanderson): The background should be changed using a |
82 // fade in/out animation. | 77 // fade in/out animation. |
83 SkPaint background_paint; | 78 SkPaint background_paint; |
84 background_paint.setFlags(SkPaint::kAntiAlias_Flag); | 79 background_paint.setFlags(SkPaint::kAntiAlias_Flag); |
85 background_paint.setColor(background_color); | 80 background_paint.setColor(background_color); |
86 canvas->DrawRoundRect(bounds, kOverflowButtonCornerRadius, | 81 canvas->DrawRoundRect(bounds, kOverflowButtonCornerRadius, |
87 background_paint); | 82 background_paint); |
88 | 83 |
89 if (shelf_->IsShowingOverflowBubble()) { | 84 if (wm_shelf_->IsShowingOverflowBubble()) { |
90 SkPaint highlight_paint; | 85 SkPaint highlight_paint; |
91 highlight_paint.setFlags(SkPaint::kAntiAlias_Flag); | 86 highlight_paint.setFlags(SkPaint::kAntiAlias_Flag); |
92 highlight_paint.setColor(kShelfButtonActivatedHighlightColor); | 87 highlight_paint.setColor(kShelfButtonActivatedHighlightColor); |
93 canvas->DrawRoundRect(bounds, kOverflowButtonCornerRadius, | 88 canvas->DrawRoundRect(bounds, kOverflowButtonCornerRadius, |
94 highlight_paint); | 89 highlight_paint); |
95 } | 90 } |
96 } else { | 91 } else { |
97 ResourceBundle& rb = ResourceBundle::GetSharedInstance(); | 92 ResourceBundle& rb = ResourceBundle::GetSharedInstance(); |
98 const gfx::ImageSkia* background = | 93 const gfx::ImageSkia* background = |
99 rb.GetImageNamed(NonMaterialBackgroundImageId()).ToImageSkia(); | 94 rb.GetImageNamed(NonMaterialBackgroundImageId()).ToImageSkia(); |
100 canvas->DrawImageInt(*background, bounds.x(), bounds.y()); | 95 canvas->DrawImageInt(*background, bounds.x(), bounds.y()); |
101 } | 96 } |
102 } | 97 } |
103 | 98 |
104 void OverflowButton::PaintForeground(gfx::Canvas* canvas, | 99 void OverflowButton::PaintForeground(gfx::Canvas* canvas, |
105 const gfx::Rect& bounds) { | 100 const gfx::Rect& bounds) { |
106 const gfx::ImageSkia* image = nullptr; | 101 const gfx::ImageSkia* image = nullptr; |
107 | 102 |
108 switch (shelf_->alignment()) { | 103 switch (wm_shelf_->GetAlignment()) { |
109 case SHELF_ALIGNMENT_LEFT: | 104 case SHELF_ALIGNMENT_LEFT: |
110 if (left_image_.isNull()) { | 105 if (left_image_.isNull()) { |
111 left_image_ = gfx::ImageSkiaOperations::CreateRotatedImage( | 106 left_image_ = gfx::ImageSkiaOperations::CreateRotatedImage( |
112 *bottom_image_, SkBitmapOperations::ROTATION_90_CW); | 107 *bottom_image_, SkBitmapOperations::ROTATION_90_CW); |
113 } | 108 } |
114 image = &left_image_; | 109 image = &left_image_; |
115 break; | 110 break; |
116 case SHELF_ALIGNMENT_RIGHT: | 111 case SHELF_ALIGNMENT_RIGHT: |
117 if (right_image_.isNull()) { | 112 if (right_image_.isNull()) { |
118 right_image_ = gfx::ImageSkiaOperations::CreateRotatedImage( | 113 right_image_ = gfx::ImageSkiaOperations::CreateRotatedImage( |
119 *bottom_image_, SkBitmapOperations::ROTATION_270_CW); | 114 *bottom_image_, SkBitmapOperations::ROTATION_270_CW); |
120 } | 115 } |
121 image = &right_image_; | 116 image = &right_image_; |
122 break; | 117 break; |
123 default: | 118 default: |
124 image = bottom_image_; | 119 image = bottom_image_; |
125 break; | 120 break; |
126 } | 121 } |
127 | 122 |
128 canvas->DrawImageInt(*image, | 123 canvas->DrawImageInt(*image, |
129 bounds.x() + ((bounds.width() - image->width()) / 2), | 124 bounds.x() + ((bounds.width() - image->width()) / 2), |
130 bounds.y() + ((bounds.height() - image->height()) / 2)); | 125 bounds.y() + ((bounds.height() - image->height()) / 2)); |
131 } | 126 } |
132 | 127 |
133 int OverflowButton::NonMaterialBackgroundImageId() { | 128 int OverflowButton::NonMaterialBackgroundImageId() { |
134 if (shelf_->IsShowingOverflowBubble()) | 129 if (wm_shelf_->IsShowingOverflowBubble()) |
135 return IDR_AURA_NOTIFICATION_BACKGROUND_PRESSED; | 130 return IDR_AURA_NOTIFICATION_BACKGROUND_PRESSED; |
136 else if (shelf_->shelf_widget()->GetDimsShelf()) | 131 else if (wm_shelf_->IsDimmed()) |
137 return IDR_AURA_NOTIFICATION_BACKGROUND_ON_BLACK; | 132 return IDR_AURA_NOTIFICATION_BACKGROUND_ON_BLACK; |
138 return IDR_AURA_NOTIFICATION_BACKGROUND_NORMAL; | 133 return IDR_AURA_NOTIFICATION_BACKGROUND_NORMAL; |
139 } | 134 } |
140 | 135 |
141 gfx::Rect OverflowButton::CalculateButtonBounds() { | 136 gfx::Rect OverflowButton::CalculateButtonBounds() { |
142 ShelfAlignment alignment = shelf_->alignment(); | 137 ShelfAlignment alignment = wm_shelf_->GetAlignment(); |
143 gfx::Rect bounds(GetContentsBounds()); | 138 gfx::Rect bounds(GetContentsBounds()); |
144 ResourceBundle& rb = ResourceBundle::GetSharedInstance(); | 139 ResourceBundle& rb = ResourceBundle::GetSharedInstance(); |
145 if (MaterialDesignController::IsShelfMaterial()) { | 140 if (MaterialDesignController::IsShelfMaterial()) { |
146 const int width_offset = (bounds.width() - kOverflowButtonSize) / 2; | 141 const int width_offset = (bounds.width() - kOverflowButtonSize) / 2; |
147 const int height_offset = (bounds.height() - kOverflowButtonSize) / 2; | 142 const int height_offset = (bounds.height() - kOverflowButtonSize) / 2; |
148 if (shelf_->IsHorizontalAlignment()) { | 143 if (IsHorizontalAlignment(alignment)) { |
149 bounds = gfx::Rect(bounds.x() + width_offset, bounds.y() + height_offset, | 144 bounds = gfx::Rect(bounds.x() + width_offset, bounds.y() + height_offset, |
150 kOverflowButtonSize, kOverflowButtonSize); | 145 kOverflowButtonSize, kOverflowButtonSize); |
151 } else { | 146 } else { |
152 bounds = gfx::Rect(bounds.x() + height_offset, bounds.y() + width_offset, | 147 bounds = gfx::Rect(bounds.x() + height_offset, bounds.y() + width_offset, |
153 kOverflowButtonSize, kOverflowButtonSize); | 148 kOverflowButtonSize, kOverflowButtonSize); |
154 } | 149 } |
155 } else { | 150 } else { |
156 const gfx::ImageSkia* background = | 151 const gfx::ImageSkia* background = |
157 rb.GetImageNamed(NonMaterialBackgroundImageId()).ToImageSkia(); | 152 rb.GetImageNamed(NonMaterialBackgroundImageId()).ToImageSkia(); |
158 if (alignment == SHELF_ALIGNMENT_LEFT) { | 153 if (alignment == SHELF_ALIGNMENT_LEFT) { |
(...skipping 10 matching lines...) Expand all Loading... |
169 bounds = | 164 bounds = |
170 gfx::Rect(bounds.x() + (bounds.width() - background->width()) / 2, | 165 gfx::Rect(bounds.x() + (bounds.width() - background->width()) / 2, |
171 bounds.y() + kShelfItemInset, background->width(), | 166 bounds.y() + kShelfItemInset, background->width(), |
172 background->height()); | 167 background->height()); |
173 } | 168 } |
174 } | 169 } |
175 return bounds; | 170 return bounds; |
176 } | 171 } |
177 | 172 |
178 } // namespace ash | 173 } // namespace ash |
OLD | NEW |