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

Side by Side Diff: ash/common/system/toast/toast_overlay.cc

Issue 2139183003: mash: Migrate //ash/system/toast to WM common types (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: move test back 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/common/system/toast/toast_overlay.h ('k') | ash/shell.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2016 The Chromium Authors. All rights reserved. 1 // Copyright 2016 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/system/toast/toast_overlay.h" 5 #include "ash/common/system/toast/toast_overlay.h"
6 6
7 #include "ash/common/shelf/wm_shelf.h" 7 #include "ash/common/shelf/wm_shelf.h"
8 #include "ash/common/shell_window_ids.h" 8 #include "ash/common/shell_window_ids.h"
9 #include "ash/common/wm_lookup.h"
9 #include "ash/common/wm_root_window_controller.h" 10 #include "ash/common/wm_root_window_controller.h"
10 #include "ash/common/wm_shell.h" 11 #include "ash/common/wm_shell.h"
11 #include "ash/common/wm_window.h" 12 #include "ash/common/wm_window.h"
12 #include "ash/screen_util.h"
13 #include "ash/shell.h"
14 #include "ash/wm/window_animations.h"
15 #include "base/strings/string_util.h" 13 #include "base/strings/string_util.h"
16 #include "base/strings/utf_string_conversions.h" 14 #include "base/strings/utf_string_conversions.h"
17 #include "base/threading/thread_task_runner_handle.h" 15 #include "base/threading/thread_task_runner_handle.h"
18 #include "grit/ash_strings.h" 16 #include "grit/ash_strings.h"
19 #include "third_party/skia/include/core/SkColor.h" 17 #include "third_party/skia/include/core/SkColor.h"
20 #include "ui/base/l10n/l10n_util.h" 18 #include "ui/base/l10n/l10n_util.h"
21 #include "ui/base/resource/resource_bundle.h" 19 #include "ui/base/resource/resource_bundle.h"
22 #include "ui/gfx/canvas.h" 20 #include "ui/gfx/canvas.h"
23 #include "ui/gfx/font_list.h" 21 #include "ui/gfx/font_list.h"
24 #include "ui/views/border.h" 22 #include "ui/views/border.h"
25 #include "ui/views/controls/button/label_button.h" 23 #include "ui/views/controls/button/label_button.h"
26 #include "ui/views/controls/label.h" 24 #include "ui/views/controls/label.h"
27 #include "ui/views/layout/box_layout.h" 25 #include "ui/views/layout/box_layout.h"
28 #include "ui/views/view.h" 26 #include "ui/views/view.h"
29 #include "ui/views/widget/widget.h" 27 #include "ui/views/widget/widget.h"
30 #include "ui/views/widget/widget_delegate.h" 28 #include "ui/views/widget/widget_delegate.h"
29 #include "ui/wm/core/window_animations.h"
31 30
32 namespace ash { 31 namespace ash {
33 32
34 namespace { 33 namespace {
35 34
36 // Offset of the overlay from the edge of the work area. 35 // Offset of the overlay from the edge of the work area.
37 const int kOffset = 5; 36 const int kOffset = 5;
38 37
39 // Font style used for modifier key labels. 38 // Font style used for modifier key labels.
40 const ui::ResourceBundle::FontStyle kTextFontStyle = 39 const ui::ResourceBundle::FontStyle kTextFontStyle =
41 ui::ResourceBundle::MediumFont; 40 ui::ResourceBundle::MediumFont;
42 41
43 // Duration of slide animation when overlay is shown or hidden. 42 // Duration of slide animation when overlay is shown or hidden.
44 const int kSlideAnimationDurationMs = 100; 43 const int kSlideAnimationDurationMs = 100;
45 44
46 // Colors for the dismiss button. 45 // Colors for the dismiss button.
47 const SkColor kButtonBackgroundColor = SkColorSetARGB(0xFF, 0x32, 0x32, 0x32); 46 const SkColor kButtonBackgroundColor = SkColorSetARGB(0xFF, 0x32, 0x32, 0x32);
48 const SkColor kButtonTextColor = SkColorSetARGB(0xFF, 0x7B, 0xAA, 0xF7); 47 const SkColor kButtonTextColor = SkColorSetARGB(0xFF, 0x7B, 0xAA, 0xF7);
49 48
50 // These values are in DIP. 49 // These values are in DIP.
51 const int kToastHorizontalSpacing = 16; 50 const int kToastHorizontalSpacing = 16;
52 const int kToastVerticalSpacing = 16; 51 const int kToastVerticalSpacing = 16;
53 const int kToastMaximumWidth = 568; 52 const int kToastMaximumWidth = 568;
54 const int kToastMinimumWidth = 288; 53 const int kToastMinimumWidth = 288;
55 54
56 // Returns the shelf for the primary display. 55 // Returns the work area bounds for the root window where new windows are added
57 WmShelf* GetPrimaryShelf() { 56 // (including new toasts).
57 gfx::Rect GetUserWorkAreaBounds() {
58 return WmShell::Get() 58 return WmShell::Get()
59 ->GetPrimaryRootWindow() 59 ->GetRootWindowForNewWindows()
60 ->GetRootWindowController() 60 ->GetRootWindowController()
61 ->GetShelf(); 61 ->GetShelf()
62 ->GetUserWorkAreaBounds();
62 } 63 }
63 64
64 } // anonymous namespace 65 } // anonymous namespace
65 66
66 /////////////////////////////////////////////////////////////////////////////// 67 ///////////////////////////////////////////////////////////////////////////////
67 // ToastOverlayLabel 68 // ToastOverlayLabel
68 class ToastOverlayLabel : public views::Label { 69 class ToastOverlayLabel : public views::Label {
69 public: 70 public:
70 explicit ToastOverlayLabel(const std::string& label); 71 explicit ToastOverlayLabel(const std::string& label);
71 ~ToastOverlayLabel() override; 72 ~ToastOverlayLabel() override;
(...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after
187 paint.setColor(kButtonBackgroundColor); 188 paint.setColor(kButtonBackgroundColor);
188 canvas->DrawRoundRect(GetLocalBounds(), 2, paint); 189 canvas->DrawRoundRect(GetLocalBounds(), 2, paint);
189 views::View::OnPaint(canvas); 190 views::View::OnPaint(canvas);
190 } 191 }
191 192
192 gfx::Size ToastOverlayView::GetMinimumSize() const { 193 gfx::Size ToastOverlayView::GetMinimumSize() const {
193 return gfx::Size(kToastMinimumWidth, 0); 194 return gfx::Size(kToastMinimumWidth, 0);
194 } 195 }
195 196
196 gfx::Size ToastOverlayView::GetMaximumSize() const { 197 gfx::Size ToastOverlayView::GetMaximumSize() const {
197 gfx::Rect work_area_bounds = GetPrimaryShelf()->GetUserWorkAreaBounds(); 198 gfx::Rect work_area_bounds = GetUserWorkAreaBounds();
198 return gfx::Size(kToastMaximumWidth, work_area_bounds.height() - kOffset * 2); 199 return gfx::Size(kToastMaximumWidth, work_area_bounds.height() - kOffset * 2);
199 } 200 }
200 201
201 void ToastOverlayView::ButtonPressed(views::Button* sender, 202 void ToastOverlayView::ButtonPressed(views::Button* sender,
202 const ui::Event& event) { 203 const ui::Event& event) {
203 overlay_->Show(false); 204 overlay_->Show(false);
204 } 205 }
205 206
206 /////////////////////////////////////////////////////////////////////////////// 207 ///////////////////////////////////////////////////////////////////////////////
207 // ToastOverlay 208 // ToastOverlay
208 ToastOverlay::ToastOverlay(Delegate* delegate, 209 ToastOverlay::ToastOverlay(Delegate* delegate,
209 const std::string& text, 210 const std::string& text,
210 const std::string& dismiss_text) 211 const std::string& dismiss_text)
211 : delegate_(delegate), 212 : delegate_(delegate),
212 text_(text), 213 text_(text),
213 dismiss_text_(dismiss_text), 214 dismiss_text_(dismiss_text),
215 overlay_widget_(new views::Widget),
214 overlay_view_(new ToastOverlayView(this, text, dismiss_text)), 216 overlay_view_(new ToastOverlayView(this, text, dismiss_text)),
215 widget_size_(overlay_view_->GetPreferredSize()) { 217 widget_size_(overlay_view_->GetPreferredSize()) {
216 views::Widget::InitParams params; 218 views::Widget::InitParams params;
217 params.type = views::Widget::InitParams::TYPE_POPUP; 219 params.type = views::Widget::InitParams::TYPE_POPUP;
220 params.name = "ToastOverlay";
218 params.opacity = views::Widget::InitParams::TRANSLUCENT_WINDOW; 221 params.opacity = views::Widget::InitParams::TRANSLUCENT_WINDOW;
219 params.ownership = views::Widget::InitParams::WIDGET_OWNS_NATIVE_WIDGET; 222 params.ownership = views::Widget::InitParams::WIDGET_OWNS_NATIVE_WIDGET;
220 params.accept_events = true; 223 params.accept_events = true;
221 params.keep_on_top = true; 224 params.keep_on_top = true;
222 params.remove_standard_frame = true; 225 params.remove_standard_frame = true;
223 params.bounds = CalculateOverlayBounds(); 226 params.bounds = CalculateOverlayBounds();
224 // Show toasts above the app list and below the lock screen. 227 // Show toasts above the app list and below the lock screen.
225 // TODO(jamescook): Either this should be the primary root window, or the 228 WmShell::Get()
226 // work area bounds computation should be for the target root window. 229 ->GetRootWindowForNewWindows()
227 params.parent = Shell::GetContainer(Shell::GetTargetRootWindow(), 230 ->GetRootWindowController()
228 kShellWindowId_SystemModalContainer); 231 ->ConfigureWidgetInitParamsForContainer(
229 overlay_widget_.reset(new views::Widget); 232 overlay_widget_.get(), kShellWindowId_SystemModalContainer, &params);
230 overlay_widget_->Init(params); 233 overlay_widget_->Init(params);
231 overlay_widget_->SetVisibilityChangedAnimationsEnabled(true); 234 overlay_widget_->SetVisibilityChangedAnimationsEnabled(true);
232 overlay_widget_->SetContentsView(overlay_view_.get()); 235 overlay_widget_->SetContentsView(overlay_view_.get());
233 overlay_widget_->SetBounds(CalculateOverlayBounds()); 236 overlay_widget_->SetBounds(CalculateOverlayBounds());
234 overlay_widget_->GetNativeView()->SetName("ToastOverlay");
235 237
236 gfx::NativeWindow native_view = overlay_widget_->GetNativeView(); 238 WmWindow* overlay_window =
237 ::wm::SetWindowVisibilityAnimationType( 239 WmLookup::Get()->GetWindowForWidget(overlay_widget_.get());
238 native_view, ::wm::WINDOW_VISIBILITY_ANIMATION_TYPE_VERTICAL); 240 overlay_window->SetVisibilityAnimationType(
239 ::wm::SetWindowVisibilityAnimationDuration( 241 ::wm::WINDOW_VISIBILITY_ANIMATION_TYPE_VERTICAL);
240 native_view, 242 overlay_window->SetVisibilityAnimationDuration(
241 base::TimeDelta::FromMilliseconds(kSlideAnimationDurationMs)); 243 base::TimeDelta::FromMilliseconds(kSlideAnimationDurationMs));
242 } 244 }
243 245
244 ToastOverlay::~ToastOverlay() { 246 ToastOverlay::~ToastOverlay() {
245 overlay_widget_->Close(); 247 overlay_widget_->Close();
246 } 248 }
247 249
248 void ToastOverlay::Show(bool visible) { 250 void ToastOverlay::Show(bool visible) {
249 if (overlay_widget_->GetLayer()->GetTargetVisibility() == visible) 251 if (overlay_widget_->GetLayer()->GetTargetVisibility() == visible)
250 return; 252 return;
(...skipping 13 matching lines...) Expand all
264 overlay_widget_->Show(); 266 overlay_widget_->Show();
265 267
266 // Notify accessibility about the overlay. 268 // Notify accessibility about the overlay.
267 overlay_view_->NotifyAccessibilityEvent(ui::AX_EVENT_ALERT, false); 269 overlay_view_->NotifyAccessibilityEvent(ui::AX_EVENT_ALERT, false);
268 } else { 270 } else {
269 overlay_widget_->Hide(); 271 overlay_widget_->Hide();
270 } 272 }
271 } 273 }
272 274
273 gfx::Rect ToastOverlay::CalculateOverlayBounds() { 275 gfx::Rect ToastOverlay::CalculateOverlayBounds() {
274 gfx::Rect bounds = GetPrimaryShelf()->GetUserWorkAreaBounds(); 276 gfx::Rect bounds = GetUserWorkAreaBounds();
275 int target_y = bounds.bottom() - widget_size_.height() - kOffset; 277 int target_y = bounds.bottom() - widget_size_.height() - kOffset;
276 bounds.ClampToCenteredSize(widget_size_); 278 bounds.ClampToCenteredSize(widget_size_);
277 bounds.set_y(target_y); 279 bounds.set_y(target_y);
278 return bounds; 280 return bounds;
279 } 281 }
280 282
281 void ToastOverlay::OnImplicitAnimationsScheduled() {} 283 void ToastOverlay::OnImplicitAnimationsScheduled() {}
282 284
283 void ToastOverlay::OnImplicitAnimationsCompleted() { 285 void ToastOverlay::OnImplicitAnimationsCompleted() {
284 if (!overlay_widget_->GetLayer()->GetTargetVisibility()) 286 if (!overlay_widget_->GetLayer()->GetTargetVisibility())
285 delegate_->OnClosed(); 287 delegate_->OnClosed();
286 } 288 }
287 289
288 views::Widget* ToastOverlay::widget_for_testing() { 290 views::Widget* ToastOverlay::widget_for_testing() {
289 return overlay_widget_.get(); 291 return overlay_widget_.get();
290 } 292 }
291 293
292 void ToastOverlay::ClickDismissButtonForTesting(const ui::Event& event) { 294 void ToastOverlay::ClickDismissButtonForTesting(const ui::Event& event) {
293 overlay_view_->button()->NotifyClick(event); 295 overlay_view_->button()->NotifyClick(event);
294 } 296 }
295 297
296 } // namespace ash 298 } // namespace ash
OLDNEW
« no previous file with comments | « ash/common/system/toast/toast_overlay.h ('k') | ash/shell.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698