| 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 182 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 193 | 193 |
| 194 void OnBlur() override { | 194 void OnBlur() override { |
| 195 message_center::PaddedButton::OnBlur(); | 195 message_center::PaddedButton::OnBlur(); |
| 196 owner_->UpdateControlButtonsVisiblity(); | 196 owner_->UpdateControlButtonsVisiblity(); |
| 197 } | 197 } |
| 198 | 198 |
| 199 private: | 199 private: |
| 200 ArcCustomNotificationView* const owner_; | 200 ArcCustomNotificationView* const owner_; |
| 201 }; | 201 }; |
| 202 | 202 |
| 203 ArcCustomNotificationView::ArcCustomNotificationView( | 203 // static |
| 204 ArcCustomNotificationItem* item) | 204 const char ArcCustomNotificationView::kViewClassName[] = |
| 205 "ArcCustomNotificationView"; |
| 206 |
| 207 ArcCustomNotificationView::ArcCustomNotificationView(ArcNotificationItem* item) |
| 205 : item_(item), | 208 : item_(item), |
| 206 notification_key_(item->notification_key()), | 209 notification_key_(item->notification_key()), |
| 207 event_forwarder_(new EventForwarder(this)) { | 210 event_forwarder_(new EventForwarder(this)) { |
| 208 SetFocusBehavior(FocusBehavior::ALWAYS); | 211 SetFocusBehavior(FocusBehavior::ALWAYS); |
| 209 | 212 |
| 210 item_->IncrementWindowRefCount(); | 213 item_->IncrementWindowRefCount(); |
| 211 item_->AddObserver(this); | 214 item_->AddObserver(this); |
| 212 | 215 |
| 213 ArcNotificationSurfaceManager::Get()->AddObserver(this); | 216 if (ArcNotificationSurfaceManager::Get()) { |
| 214 exo::NotificationSurface* surface = | 217 ArcNotificationSurfaceManager::Get()->AddObserver(this); |
| 215 ArcNotificationSurfaceManager::Get()->GetSurface(notification_key_); | 218 exo::NotificationSurface* surface = |
| 216 if (surface) | 219 ArcNotificationSurfaceManager::Get()->GetSurface(notification_key_); |
| 217 OnNotificationSurfaceAdded(surface); | 220 if (surface) |
| 221 OnNotificationSurfaceAdded(surface); |
| 222 } |
| 218 | 223 |
| 219 // Create a layer as an anchor to insert surface copy during a slide. | 224 // Create a layer as an anchor to insert surface copy during a slide. |
| 220 SetPaintToLayer(); | 225 SetPaintToLayer(); |
| 221 UpdatePreferredSize(); | 226 UpdatePreferredSize(); |
| 222 } | 227 } |
| 223 | 228 |
| 224 ArcCustomNotificationView::~ArcCustomNotificationView() { | 229 ArcCustomNotificationView::~ArcCustomNotificationView() { |
| 225 SetSurface(nullptr); | 230 SetSurface(nullptr); |
| 226 if (item_) { | 231 if (item_) { |
| 227 item_->DecrementWindowRefCount(); | 232 item_->DecrementWindowRefCount(); |
| 228 item_->RemoveObserver(this); | 233 item_->RemoveObserver(this); |
| 229 } | 234 } |
| 230 | 235 |
| 231 if (ArcNotificationSurfaceManager::Get()) | 236 if (ArcNotificationSurfaceManager::Get()) |
| 232 ArcNotificationSurfaceManager::Get()->RemoveObserver(this); | 237 ArcNotificationSurfaceManager::Get()->RemoveObserver(this); |
| 233 } | 238 } |
| 234 | 239 |
| 240 const char* ArcCustomNotificationView::GetClassName() const { |
| 241 return kViewClassName; |
| 242 } |
| 243 |
| 235 std::unique_ptr<message_center::CustomNotificationContentViewDelegate> | 244 std::unique_ptr<message_center::CustomNotificationContentViewDelegate> |
| 236 ArcCustomNotificationView::CreateContentViewDelegate() { | 245 ArcCustomNotificationView::CreateContentViewDelegate() { |
| 237 return base::MakeUnique<ArcCustomNotificationView::ContentViewDelegate>(this); | 246 return base::MakeUnique<ArcCustomNotificationView::ContentViewDelegate>(this); |
| 238 } | 247 } |
| 239 | 248 |
| 240 void ArcCustomNotificationView::CreateFloatingControlButtons() { | 249 void ArcCustomNotificationView::CreateFloatingControlButtons() { |
| 241 // Floating close button is a transient child of |surface_| and also part | 250 // Floating close button is a transient child of |surface_| and also part |
| 242 // of the hosting widget's focus chain. It could only be created when both | 251 // of the hosting widget's focus chain. It could only be created when both |
| 243 // are present. | 252 // are present. |
| 244 if (!surface_ || !GetWidget()) | 253 if (!surface_ || !GetWidget()) |
| (...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 359 | 368 |
| 360 UpdatePreferredSize(); | 369 UpdatePreferredSize(); |
| 361 SchedulePaint(); | 370 SchedulePaint(); |
| 362 } | 371 } |
| 363 | 372 |
| 364 void ArcCustomNotificationView::AttachSurface() { | 373 void ArcCustomNotificationView::AttachSurface() { |
| 365 if (!GetWidget()) | 374 if (!GetWidget()) |
| 366 return; | 375 return; |
| 367 | 376 |
| 368 UpdatePreferredSize(); | 377 UpdatePreferredSize(); |
| 369 Attach(surface_->window()); | 378 surface_->AttachWindow(this); |
| 370 | 379 |
| 371 // The texture for this window can be placed at subpixel position | 380 // The texture for this window can be placed at subpixel position |
| 372 // with fractional scale factor. Force to align it at the pixel | 381 // with fractional scale factor. Force to align it at the pixel |
| 373 // boundary here, and when layout is updated in Layout(). | 382 // boundary here, and when layout is updated in Layout(). |
| 374 ash::wm::SnapWindowToPixelBoundary(surface_->window()); | 383 ash::wm::SnapWindowToPixelBoundary(surface_->window()); |
| 375 | 384 |
| 376 // Creates slide helper after this view is added to its parent. | 385 // Creates slide helper after this view is added to its parent. |
| 377 slide_helper_.reset(new SlideHelper(this)); | 386 slide_helper_.reset(new SlideHelper(this)); |
| 378 | 387 |
| 379 // Invokes Update() in case surface is attached during a slide. | 388 // Invokes Update() in case surface is attached during a slide. |
| (...skipping 173 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 553 | 562 |
| 554 void ArcCustomNotificationView::OnNotificationSurfaceRemoved( | 563 void ArcCustomNotificationView::OnNotificationSurfaceRemoved( |
| 555 exo::NotificationSurface* surface) { | 564 exo::NotificationSurface* surface) { |
| 556 if (surface->notification_id() != notification_key_) | 565 if (surface->notification_id() != notification_key_) |
| 557 return; | 566 return; |
| 558 | 567 |
| 559 SetSurface(nullptr); | 568 SetSurface(nullptr); |
| 560 } | 569 } |
| 561 | 570 |
| 562 } // namespace arc | 571 } // namespace arc |
| OLD | NEW |