OLD | NEW |
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 "ui/arc/notification/arc_custom_notification_view.h" | 5 #include "ui/arc/notification/arc_custom_notification_view.h" |
6 | 6 |
7 #include "base/auto_reset.h" | 7 #include "base/auto_reset.h" |
8 #include "base/memory/ptr_util.h" | 8 #include "base/memory/ptr_util.h" |
9 #include "components/exo/notification_surface.h" | 9 #include "components/exo/notification_surface.h" |
10 #include "components/exo/surface.h" | 10 #include "components/exo/surface.h" |
(...skipping 240 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
251 if (ArcNotificationSurfaceManager::Get()) | 251 if (ArcNotificationSurfaceManager::Get()) |
252 ArcNotificationSurfaceManager::Get()->RemoveObserver(this); | 252 ArcNotificationSurfaceManager::Get()->RemoveObserver(this); |
253 } | 253 } |
254 | 254 |
255 std::unique_ptr<message_center::CustomNotificationContentViewDelegate> | 255 std::unique_ptr<message_center::CustomNotificationContentViewDelegate> |
256 ArcCustomNotificationView::CreateContentViewDelegate() { | 256 ArcCustomNotificationView::CreateContentViewDelegate() { |
257 return base::MakeUnique<ArcCustomNotificationView::ContentViewDelegate>(this); | 257 return base::MakeUnique<ArcCustomNotificationView::ContentViewDelegate>(this); |
258 } | 258 } |
259 | 259 |
260 void ArcCustomNotificationView::CreateFloatingCloseButton() { | 260 void ArcCustomNotificationView::CreateFloatingCloseButton() { |
261 if (!surface_) | 261 // Floating close button is a transient child of |surface_| and also part |
| 262 // of the hosting widget's focus chain. It could only be created when both |
| 263 // are present. |
| 264 if (!surface_ || !GetWidget()) |
262 return; | 265 return; |
263 | 266 |
264 floating_close_button_ = new CloseButton(this); | 267 floating_close_button_ = new CloseButton(this); |
265 | 268 |
266 views::Widget::InitParams params(views::Widget::InitParams::TYPE_CONTROL); | 269 views::Widget::InitParams params(views::Widget::InitParams::TYPE_CONTROL); |
267 params.opacity = views::Widget::InitParams::TRANSLUCENT_WINDOW; | 270 params.opacity = views::Widget::InitParams::TRANSLUCENT_WINDOW; |
268 params.ownership = views::Widget::InitParams::WIDGET_OWNS_NATIVE_WIDGET; | 271 params.ownership = views::Widget::InitParams::WIDGET_OWNS_NATIVE_WIDGET; |
269 params.parent = surface_->window(); | 272 params.parent = surface_->window(); |
270 | 273 |
271 floating_close_button_widget_.reset(new views::Widget); | 274 floating_close_button_widget_.reset(new views::Widget); |
(...skipping 21 matching lines...) Expand all Loading... |
293 } | 296 } |
294 | 297 |
295 surface_ = surface; | 298 surface_ = surface; |
296 | 299 |
297 if (surface_ && surface_->window()) { | 300 if (surface_ && surface_->window()) { |
298 surface_->window()->AddObserver(this); | 301 surface_->window()->AddObserver(this); |
299 surface_->window()->AddPreTargetHandler(event_forwarder_.get()); | 302 surface_->window()->AddPreTargetHandler(event_forwarder_.get()); |
300 | 303 |
301 if (GetWidget()) | 304 if (GetWidget()) |
302 AttachSurface(); | 305 AttachSurface(); |
303 | |
304 if (item_) | |
305 UpdatePinnedState(); | |
306 } | 306 } |
307 } | 307 } |
308 | 308 |
309 void ArcCustomNotificationView::UpdatePreferredSize() { | 309 void ArcCustomNotificationView::UpdatePreferredSize() { |
310 gfx::Size preferred_size = | 310 gfx::Size preferred_size = |
311 surface_ ? surface_->GetSize() : item_ ? item_->snapshot().size() | 311 surface_ ? surface_->GetSize() : item_ ? item_->snapshot().size() |
312 : gfx::Size(); | 312 : gfx::Size(); |
313 if (preferred_size.IsEmpty()) | 313 if (preferred_size.IsEmpty()) |
314 return; | 314 return; |
315 | 315 |
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
364 return; | 364 return; |
365 | 365 |
366 UpdatePreferredSize(); | 366 UpdatePreferredSize(); |
367 Attach(surface_->window()); | 367 Attach(surface_->window()); |
368 | 368 |
369 // Creates slide helper after this view is added to its parent. | 369 // Creates slide helper after this view is added to its parent. |
370 slide_helper_.reset(new SlideHelper(this)); | 370 slide_helper_.reset(new SlideHelper(this)); |
371 | 371 |
372 // Invokes Update() in case surface is attached during a slide. | 372 // Invokes Update() in case surface is attached during a slide. |
373 slide_helper_->Update(); | 373 slide_helper_->Update(); |
| 374 |
| 375 // Updates pinned state to create or destroy the floating close button |
| 376 // after |surface_| is attached to a widget. |
| 377 if (item_) |
| 378 UpdatePinnedState(); |
374 } | 379 } |
375 | 380 |
376 void ArcCustomNotificationView::ViewHierarchyChanged( | 381 void ArcCustomNotificationView::ViewHierarchyChanged( |
377 const views::View::ViewHierarchyChangedDetails& details) { | 382 const views::View::ViewHierarchyChangedDetails& details) { |
378 views::Widget* widget = GetWidget(); | 383 views::Widget* widget = GetWidget(); |
379 | 384 |
380 if (!details.is_add) { | 385 if (!details.is_add) { |
381 // Resets slide helper when this view is removed from its parent. | 386 // Resets slide helper when this view is removed from its parent. |
382 slide_helper_.reset(); | 387 slide_helper_.reset(); |
383 | 388 |
(...skipping 150 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
534 | 539 |
535 void ArcCustomNotificationView::OnNotificationSurfaceRemoved( | 540 void ArcCustomNotificationView::OnNotificationSurfaceRemoved( |
536 exo::NotificationSurface* surface) { | 541 exo::NotificationSurface* surface) { |
537 if (surface->notification_id() != notification_key_) | 542 if (surface->notification_id() != notification_key_) |
538 return; | 543 return; |
539 | 544 |
540 SetSurface(nullptr); | 545 SetSurface(nullptr); |
541 } | 546 } |
542 | 547 |
543 } // namespace arc | 548 } // namespace arc |
OLD | NEW |