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

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

Issue 2093283002: mash: Convert all of //ash/system to use WmShelf (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 6 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
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/system/toast/toast_overlay.h"
6 6
7 #include "ash/common/shelf/wm_shelf.h"
7 #include "ash/common/shell_window_ids.h" 8 #include "ash/common/shell_window_ids.h"
8 #include "ash/screen_util.h" 9 #include "ash/screen_util.h"
9 #include "ash/shelf/shelf.h"
10 #include "ash/shelf/shelf_layout_manager.h"
11 #include "ash/shell.h" 10 #include "ash/shell.h"
12 #include "ash/wm/window_animations.h" 11 #include "ash/wm/window_animations.h"
13 #include "base/strings/string_util.h" 12 #include "base/strings/string_util.h"
14 #include "base/strings/utf_string_conversions.h" 13 #include "base/strings/utf_string_conversions.h"
15 #include "base/threading/thread_task_runner_handle.h" 14 #include "base/threading/thread_task_runner_handle.h"
16 #include "grit/ash_strings.h" 15 #include "grit/ash_strings.h"
17 #include "third_party/skia/include/core/SkColor.h" 16 #include "third_party/skia/include/core/SkColor.h"
18 #include "ui/base/l10n/l10n_util.h" 17 #include "ui/base/l10n/l10n_util.h"
19 #include "ui/base/resource/resource_bundle.h" 18 #include "ui/base/resource/resource_bundle.h"
20 #include "ui/gfx/canvas.h" 19 #include "ui/gfx/canvas.h"
(...skipping 156 matching lines...) Expand 10 before | Expand all | Expand 10 after
177 paint.setColor(kButtonBackgroundColor); 176 paint.setColor(kButtonBackgroundColor);
178 canvas->DrawRoundRect(GetLocalBounds(), 2, paint); 177 canvas->DrawRoundRect(GetLocalBounds(), 2, paint);
179 views::View::OnPaint(canvas); 178 views::View::OnPaint(canvas);
180 } 179 }
181 180
182 gfx::Size ToastOverlayView::GetMinimumSize() const { 181 gfx::Size ToastOverlayView::GetMinimumSize() const {
183 return gfx::Size(kToastMinimumWidth, 0); 182 return gfx::Size(kToastMinimumWidth, 0);
184 } 183 }
185 184
186 gfx::Size ToastOverlayView::GetMaximumSize() const { 185 gfx::Size ToastOverlayView::GetMaximumSize() const {
187 ShelfLayoutManager* shelf_layout_manager = 186 gfx::Rect work_area_bounds =
188 Shelf::ForPrimaryDisplay()->shelf_layout_manager(); 187 WmShelf::ForPrimaryDisplay()->GetUserWorkAreaBounds();
msw 2016/06/25 00:18:29 aside: it seems like the shelf shouldn't be the so
James Cook 2016/06/25 01:20:58 Yeah, maybe it should be accessed via RootWindowCo
189 gfx::Rect work_area_bounds = shelf_layout_manager->user_work_area_bounds();
190
191 return gfx::Size(kToastMaximumWidth, work_area_bounds.height() - kOffset * 2); 188 return gfx::Size(kToastMaximumWidth, work_area_bounds.height() - kOffset * 2);
192 } 189 }
193 190
194 void ToastOverlayView::ButtonPressed(views::Button* sender, 191 void ToastOverlayView::ButtonPressed(views::Button* sender,
195 const ui::Event& event) { 192 const ui::Event& event) {
196 overlay_->Show(false); 193 overlay_->Show(false);
197 } 194 }
198 195
199 /////////////////////////////////////////////////////////////////////////////// 196 ///////////////////////////////////////////////////////////////////////////////
200 // ToastOverlay 197 // ToastOverlay
201 ToastOverlay::ToastOverlay(Delegate* delegate, 198 ToastOverlay::ToastOverlay(Delegate* delegate,
202 const std::string& text, 199 const std::string& text,
203 const std::string& dismiss_text) 200 const std::string& dismiss_text)
204 : delegate_(delegate), 201 : delegate_(delegate),
205 text_(text), 202 text_(text),
206 dismiss_text_(dismiss_text), 203 dismiss_text_(dismiss_text),
207 overlay_view_(new ToastOverlayView(this, text, dismiss_text)), 204 overlay_view_(new ToastOverlayView(this, text, dismiss_text)),
208 widget_size_(overlay_view_->GetPreferredSize()) { 205 widget_size_(overlay_view_->GetPreferredSize()) {
209 views::Widget::InitParams params; 206 views::Widget::InitParams params;
210 params.type = views::Widget::InitParams::TYPE_POPUP; 207 params.type = views::Widget::InitParams::TYPE_POPUP;
211 params.opacity = views::Widget::InitParams::TRANSLUCENT_WINDOW; 208 params.opacity = views::Widget::InitParams::TRANSLUCENT_WINDOW;
212 params.ownership = views::Widget::InitParams::WIDGET_OWNS_NATIVE_WIDGET; 209 params.ownership = views::Widget::InitParams::WIDGET_OWNS_NATIVE_WIDGET;
213 params.accept_events = true; 210 params.accept_events = true;
214 params.keep_on_top = true; 211 params.keep_on_top = true;
215 params.remove_standard_frame = true; 212 params.remove_standard_frame = true;
216 params.bounds = CalculateOverlayBounds(); 213 params.bounds = CalculateOverlayBounds();
217 // Show toasts above the app list and below the lock screen. 214 // Show toasts above the app list and below the lock screen.
215 // TODO(jamescook): Either this should be the primary root window, or the
216 // work area bounds computation should be for the target root window.
218 params.parent = Shell::GetContainer(Shell::GetTargetRootWindow(), 217 params.parent = Shell::GetContainer(Shell::GetTargetRootWindow(),
219 kShellWindowId_SystemModalContainer); 218 kShellWindowId_SystemModalContainer);
220 overlay_widget_.reset(new views::Widget); 219 overlay_widget_.reset(new views::Widget);
221 overlay_widget_->Init(params); 220 overlay_widget_->Init(params);
222 overlay_widget_->SetVisibilityChangedAnimationsEnabled(true); 221 overlay_widget_->SetVisibilityChangedAnimationsEnabled(true);
223 overlay_widget_->SetContentsView(overlay_view_.get()); 222 overlay_widget_->SetContentsView(overlay_view_.get());
224 overlay_widget_->SetBounds(CalculateOverlayBounds()); 223 overlay_widget_->SetBounds(CalculateOverlayBounds());
225 overlay_widget_->GetNativeView()->SetName("ToastOverlay"); 224 overlay_widget_->GetNativeView()->SetName("ToastOverlay");
226 225
227 gfx::NativeWindow native_view = overlay_widget_->GetNativeView(); 226 gfx::NativeWindow native_view = overlay_widget_->GetNativeView();
(...skipping 27 matching lines...) Expand all
255 overlay_widget_->Show(); 254 overlay_widget_->Show();
256 255
257 // Notify accessibility about the overlay. 256 // Notify accessibility about the overlay.
258 overlay_view_->NotifyAccessibilityEvent(ui::AX_EVENT_ALERT, false); 257 overlay_view_->NotifyAccessibilityEvent(ui::AX_EVENT_ALERT, false);
259 } else { 258 } else {
260 overlay_widget_->Hide(); 259 overlay_widget_->Hide();
261 } 260 }
262 } 261 }
263 262
264 gfx::Rect ToastOverlay::CalculateOverlayBounds() { 263 gfx::Rect ToastOverlay::CalculateOverlayBounds() {
265 ShelfLayoutManager* shelf_layout_manager = 264 gfx::Rect bounds = WmShelf::ForPrimaryDisplay()->GetUserWorkAreaBounds();
266 Shelf::ForPrimaryDisplay()->shelf_layout_manager();
267
268 gfx::Rect bounds = shelf_layout_manager->user_work_area_bounds();
269 int target_y = bounds.bottom() - widget_size_.height() - kOffset; 265 int target_y = bounds.bottom() - widget_size_.height() - kOffset;
270 bounds.ClampToCenteredSize(widget_size_); 266 bounds.ClampToCenteredSize(widget_size_);
271 bounds.set_y(target_y); 267 bounds.set_y(target_y);
272 return bounds; 268 return bounds;
273 } 269 }
274 270
275 void ToastOverlay::OnImplicitAnimationsScheduled() {} 271 void ToastOverlay::OnImplicitAnimationsScheduled() {}
276 272
277 void ToastOverlay::OnImplicitAnimationsCompleted() { 273 void ToastOverlay::OnImplicitAnimationsCompleted() {
278 if (!overlay_widget_->GetLayer()->GetTargetVisibility()) 274 if (!overlay_widget_->GetLayer()->GetTargetVisibility())
279 delegate_->OnClosed(); 275 delegate_->OnClosed();
280 } 276 }
281 277
282 views::Widget* ToastOverlay::widget_for_testing() { 278 views::Widget* ToastOverlay::widget_for_testing() {
283 return overlay_widget_.get(); 279 return overlay_widget_.get();
284 } 280 }
285 281
286 void ToastOverlay::ClickDismissButtonForTesting(const ui::Event& event) { 282 void ToastOverlay::ClickDismissButtonForTesting(const ui::Event& event) {
287 overlay_view_->button()->NotifyClick(event); 283 overlay_view_->button()->NotifyClick(event);
288 } 284 }
289 285
290 } // namespace ash 286 } // namespace ash
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698