Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(168)

Side by Side Diff: ash/shelf/overflow_button.cc

Issue 2164733002: mash: Convert ash shelf overflow bubble to wm common types (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: review comments Created 4 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « ash/shelf/overflow_button.h ('k') | ash/shelf/shelf_button.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
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
3 // found in the LICENSE file.
4
5 #include "ash/shelf/overflow_button.h"
6
7 #include "ash/common/ash_constants.h"
8 #include "ash/common/ash_switches.h"
9 #include "ash/common/material_design/material_design_controller.h"
10 #include "ash/common/shelf/shelf_constants.h"
11 #include "ash/shelf/ink_drop_button_listener.h"
12 #include "ash/shelf/shelf.h"
13 #include "ash/shelf/shelf_layout_manager.h"
14 #include "ash/shelf/shelf_widget.h"
15 #include "grit/ash_resources.h"
16 #include "grit/ash_strings.h"
17 #include "third_party/skia/include/core/SkPaint.h"
18 #include "third_party/skia/include/core/SkPath.h"
19 #include "ui/base/l10n/l10n_util.h"
20 #include "ui/base/resource/resource_bundle.h"
21 #include "ui/gfx/animation/throb_animation.h"
22 #include "ui/gfx/canvas.h"
23 #include "ui/gfx/image/image_skia_operations.h"
24 #include "ui/gfx/paint_vector_icon.h"
25 #include "ui/gfx/skbitmap_operations.h"
26 #include "ui/gfx/skia_util.h"
27 #include "ui/gfx/transform.h"
28 #include "ui/gfx/vector_icons_public.h"
29 #include "ui/views/widget/widget.h"
30
31 namespace ash {
32
33 OverflowButton::OverflowButton(InkDropButtonListener* listener, Shelf* shelf)
34 : CustomButton(nullptr),
35 bottom_image_(nullptr),
36 listener_(listener),
37 shelf_(shelf) {
38 if (MaterialDesignController::IsShelfMaterial()) {
39 bottom_image_md_ =
40 CreateVectorIcon(gfx::VectorIconId::SHELF_OVERFLOW, kShelfIconColor);
41 bottom_image_ = &bottom_image_md_;
42 } else {
43 bottom_image_ = ui::ResourceBundle::GetSharedInstance().GetImageSkiaNamed(
44 IDR_ASH_SHELF_OVERFLOW);
45 }
46
47 SetFocusBehavior(FocusBehavior::ACCESSIBLE_ONLY);
48 SetAccessibleName(l10n_util::GetStringUTF16(IDS_ASH_SHELF_OVERFLOW_NAME));
49 }
50
51 OverflowButton::~OverflowButton() {}
52
53 void OverflowButton::OnShelfAlignmentChanged() {
54 SchedulePaint();
55 }
56
57 void OverflowButton::OnPaint(gfx::Canvas* canvas) {
58 gfx::Rect bounds = CalculateButtonBounds();
59 PaintBackground(canvas, bounds);
60 PaintForeground(canvas, bounds);
61 }
62
63 void OverflowButton::NotifyClick(const ui::Event& event) {
64 CustomButton::NotifyClick(event);
65 if (listener_)
66 listener_->ButtonPressed(this, event, ink_drop());
67 }
68
69 void OverflowButton::PaintBackground(gfx::Canvas* canvas,
70 const gfx::Rect& bounds) {
71 if (MaterialDesignController::IsShelfMaterial()) {
72 SkColor background_color = SK_ColorTRANSPARENT;
73 ShelfWidget* shelf_widget = shelf_->shelf_widget();
74 if (shelf_widget &&
75 shelf_widget->GetBackgroundType() ==
76 ShelfBackgroundType::SHELF_BACKGROUND_DEFAULT) {
77 background_color = SkColorSetA(kShelfBaseColor,
78 GetShelfConstant(SHELF_BACKGROUND_ALPHA));
79 }
80
81 // TODO(bruthig|tdanderson): The background should be changed using a
82 // fade in/out animation.
83 SkPaint background_paint;
84 background_paint.setFlags(SkPaint::kAntiAlias_Flag);
85 background_paint.setColor(background_color);
86 canvas->DrawRoundRect(bounds, kOverflowButtonCornerRadius,
87 background_paint);
88
89 if (shelf_->IsShowingOverflowBubble()) {
90 SkPaint highlight_paint;
91 highlight_paint.setFlags(SkPaint::kAntiAlias_Flag);
92 highlight_paint.setColor(kShelfButtonActivatedHighlightColor);
93 canvas->DrawRoundRect(bounds, kOverflowButtonCornerRadius,
94 highlight_paint);
95 }
96 } else {
97 ResourceBundle& rb = ResourceBundle::GetSharedInstance();
98 const gfx::ImageSkia* background =
99 rb.GetImageNamed(NonMaterialBackgroundImageId()).ToImageSkia();
100 canvas->DrawImageInt(*background, bounds.x(), bounds.y());
101 }
102 }
103
104 void OverflowButton::PaintForeground(gfx::Canvas* canvas,
105 const gfx::Rect& bounds) {
106 const gfx::ImageSkia* image = nullptr;
107
108 switch (shelf_->alignment()) {
109 case SHELF_ALIGNMENT_LEFT:
110 if (left_image_.isNull()) {
111 left_image_ = gfx::ImageSkiaOperations::CreateRotatedImage(
112 *bottom_image_, SkBitmapOperations::ROTATION_90_CW);
113 }
114 image = &left_image_;
115 break;
116 case SHELF_ALIGNMENT_RIGHT:
117 if (right_image_.isNull()) {
118 right_image_ = gfx::ImageSkiaOperations::CreateRotatedImage(
119 *bottom_image_, SkBitmapOperations::ROTATION_270_CW);
120 }
121 image = &right_image_;
122 break;
123 default:
124 image = bottom_image_;
125 break;
126 }
127
128 canvas->DrawImageInt(*image,
129 bounds.x() + ((bounds.width() - image->width()) / 2),
130 bounds.y() + ((bounds.height() - image->height()) / 2));
131 }
132
133 int OverflowButton::NonMaterialBackgroundImageId() {
134 if (shelf_->IsShowingOverflowBubble())
135 return IDR_AURA_NOTIFICATION_BACKGROUND_PRESSED;
136 else if (shelf_->shelf_widget()->GetDimsShelf())
137 return IDR_AURA_NOTIFICATION_BACKGROUND_ON_BLACK;
138 return IDR_AURA_NOTIFICATION_BACKGROUND_NORMAL;
139 }
140
141 gfx::Rect OverflowButton::CalculateButtonBounds() {
142 ShelfAlignment alignment = shelf_->alignment();
143 gfx::Rect bounds(GetContentsBounds());
144 ResourceBundle& rb = ResourceBundle::GetSharedInstance();
145 if (MaterialDesignController::IsShelfMaterial()) {
146 const int width_offset = (bounds.width() - kOverflowButtonSize) / 2;
147 const int height_offset = (bounds.height() - kOverflowButtonSize) / 2;
148 if (shelf_->IsHorizontalAlignment()) {
149 bounds = gfx::Rect(bounds.x() + width_offset, bounds.y() + height_offset,
150 kOverflowButtonSize, kOverflowButtonSize);
151 } else {
152 bounds = gfx::Rect(bounds.x() + height_offset, bounds.y() + width_offset,
153 kOverflowButtonSize, kOverflowButtonSize);
154 }
155 } else {
156 const gfx::ImageSkia* background =
157 rb.GetImageNamed(NonMaterialBackgroundImageId()).ToImageSkia();
158 if (alignment == SHELF_ALIGNMENT_LEFT) {
159 bounds =
160 gfx::Rect(bounds.right() - background->width() - kShelfItemInset,
161 bounds.y() + (bounds.height() - background->height()) / 2,
162 background->width(), background->height());
163 } else if (alignment == SHELF_ALIGNMENT_RIGHT) {
164 bounds =
165 gfx::Rect(bounds.x() + kShelfItemInset,
166 bounds.y() + (bounds.height() - background->height()) / 2,
167 background->width(), background->height());
168 } else {
169 bounds =
170 gfx::Rect(bounds.x() + (bounds.width() - background->width()) / 2,
171 bounds.y() + kShelfItemInset, background->width(),
172 background->height());
173 }
174 }
175 return bounds;
176 }
177
178 } // namespace ash
OLDNEW
« no previous file with comments | « ash/shelf/overflow_button.h ('k') | ash/shelf/shelf_button.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698