| 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 "ash/wm/window_util.h" | 7 #include "ash/wm/window_util.h" |
| 8 #include "base/auto_reset.h" | 8 #include "base/auto_reset.h" |
| 9 #include "base/memory/ptr_util.h" | 9 #include "base/memory/ptr_util.h" |
| 10 #include "components/exo/notification_surface.h" | 10 #include "components/exo/notification_surface.h" |
| (...skipping 241 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 252 if (ArcNotificationSurfaceManager::Get()) | 252 if (ArcNotificationSurfaceManager::Get()) |
| 253 ArcNotificationSurfaceManager::Get()->RemoveObserver(this); | 253 ArcNotificationSurfaceManager::Get()->RemoveObserver(this); |
| 254 } | 254 } |
| 255 | 255 |
| 256 std::unique_ptr<message_center::CustomNotificationContentViewDelegate> | 256 std::unique_ptr<message_center::CustomNotificationContentViewDelegate> |
| 257 ArcCustomNotificationView::CreateContentViewDelegate() { | 257 ArcCustomNotificationView::CreateContentViewDelegate() { |
| 258 return base::MakeUnique<ArcCustomNotificationView::ContentViewDelegate>(this); | 258 return base::MakeUnique<ArcCustomNotificationView::ContentViewDelegate>(this); |
| 259 } | 259 } |
| 260 | 260 |
| 261 void ArcCustomNotificationView::CreateFloatingCloseButton() { | 261 void ArcCustomNotificationView::CreateFloatingCloseButton() { |
| 262 if (!surface_) | 262 // Floating close button is a transient child of |surface_| and also part |
| 263 // of the hosting widget's focus chain. It could only be created when both |
| 264 // are present. |
| 265 if (!surface_ || !GetWidget()) |
| 263 return; | 266 return; |
| 264 | 267 |
| 265 floating_close_button_ = new CloseButton(this); | 268 floating_close_button_ = new CloseButton(this); |
| 266 | 269 |
| 267 views::Widget::InitParams params(views::Widget::InitParams::TYPE_CONTROL); | 270 views::Widget::InitParams params(views::Widget::InitParams::TYPE_CONTROL); |
| 268 params.opacity = views::Widget::InitParams::TRANSLUCENT_WINDOW; | 271 params.opacity = views::Widget::InitParams::TRANSLUCENT_WINDOW; |
| 269 params.ownership = views::Widget::InitParams::WIDGET_OWNS_NATIVE_WIDGET; | 272 params.ownership = views::Widget::InitParams::WIDGET_OWNS_NATIVE_WIDGET; |
| 270 params.parent = surface_->window(); | 273 params.parent = surface_->window(); |
| 271 | 274 |
| 272 floating_close_button_widget_.reset(new views::Widget); | 275 floating_close_button_widget_.reset(new views::Widget); |
| (...skipping 21 matching lines...) Expand all Loading... |
| 294 } | 297 } |
| 295 | 298 |
| 296 surface_ = surface; | 299 surface_ = surface; |
| 297 | 300 |
| 298 if (surface_ && surface_->window()) { | 301 if (surface_ && surface_->window()) { |
| 299 surface_->window()->AddObserver(this); | 302 surface_->window()->AddObserver(this); |
| 300 surface_->window()->AddPreTargetHandler(event_forwarder_.get()); | 303 surface_->window()->AddPreTargetHandler(event_forwarder_.get()); |
| 301 | 304 |
| 302 if (GetWidget()) | 305 if (GetWidget()) |
| 303 AttachSurface(); | 306 AttachSurface(); |
| 304 | |
| 305 if (item_) | |
| 306 UpdatePinnedState(); | |
| 307 } | 307 } |
| 308 } | 308 } |
| 309 | 309 |
| 310 void ArcCustomNotificationView::UpdatePreferredSize() { | 310 void ArcCustomNotificationView::UpdatePreferredSize() { |
| 311 gfx::Size preferred_size = | 311 gfx::Size preferred_size = |
| 312 surface_ ? surface_->GetSize() : item_ ? item_->snapshot().size() | 312 surface_ ? surface_->GetSize() : item_ ? item_->snapshot().size() |
| 313 : gfx::Size(); | 313 : gfx::Size(); |
| 314 if (preferred_size.IsEmpty()) | 314 if (preferred_size.IsEmpty()) |
| 315 return; | 315 return; |
| 316 | 316 |
| (...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 370 // The texture for this window can be placed at subpixel position | 370 // The texture for this window can be placed at subpixel position |
| 371 // with fractional scale factor. Force to align it at the pixel | 371 // with fractional scale factor. Force to align it at the pixel |
| 372 // boundary here, and when layout is updated in Layout(). | 372 // boundary here, and when layout is updated in Layout(). |
| 373 ash::wm::SnapWindowToPixelBoundary(surface_->window()); | 373 ash::wm::SnapWindowToPixelBoundary(surface_->window()); |
| 374 | 374 |
| 375 // Creates slide helper after this view is added to its parent. | 375 // Creates slide helper after this view is added to its parent. |
| 376 slide_helper_.reset(new SlideHelper(this)); | 376 slide_helper_.reset(new SlideHelper(this)); |
| 377 | 377 |
| 378 // Invokes Update() in case surface is attached during a slide. | 378 // Invokes Update() in case surface is attached during a slide. |
| 379 slide_helper_->Update(); | 379 slide_helper_->Update(); |
| 380 |
| 381 // Updates pinned state to create or destroy the floating close button |
| 382 // after |surface_| is attached to a widget. |
| 383 if (item_) |
| 384 UpdatePinnedState(); |
| 380 } | 385 } |
| 381 | 386 |
| 382 void ArcCustomNotificationView::ViewHierarchyChanged( | 387 void ArcCustomNotificationView::ViewHierarchyChanged( |
| 383 const views::View::ViewHierarchyChangedDetails& details) { | 388 const views::View::ViewHierarchyChangedDetails& details) { |
| 384 views::Widget* widget = GetWidget(); | 389 views::Widget* widget = GetWidget(); |
| 385 | 390 |
| 386 if (!details.is_add) { | 391 if (!details.is_add) { |
| 387 // Resets slide helper when this view is removed from its parent. | 392 // Resets slide helper when this view is removed from its parent. |
| 388 slide_helper_.reset(); | 393 slide_helper_.reset(); |
| 389 | 394 |
| (...skipping 152 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 542 | 547 |
| 543 void ArcCustomNotificationView::OnNotificationSurfaceRemoved( | 548 void ArcCustomNotificationView::OnNotificationSurfaceRemoved( |
| 544 exo::NotificationSurface* surface) { | 549 exo::NotificationSurface* surface) { |
| 545 if (surface->notification_id() != notification_key_) | 550 if (surface->notification_id() != notification_key_) |
| 546 return; | 551 return; |
| 547 | 552 |
| 548 SetSurface(nullptr); | 553 SetSurface(nullptr); |
| 549 } | 554 } |
| 550 | 555 |
| 551 } // namespace arc | 556 } // namespace arc |
| OLD | NEW |