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 194 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
205 ArcCustomNotificationView* const owner_; | 205 ArcCustomNotificationView* const owner_; |
206 | 206 |
207 DISALLOW_COPY_AND_ASSIGN(ContentViewDelegate); | 207 DISALLOW_COPY_AND_ASSIGN(ContentViewDelegate); |
208 }; | 208 }; |
209 | 209 |
210 ArcCustomNotificationView::ControlButton::ControlButton( | 210 ArcCustomNotificationView::ControlButton::ControlButton( |
211 ArcCustomNotificationView* owner) | 211 ArcCustomNotificationView* owner) |
212 : message_center::PaddedButton(owner), owner_(owner) { | 212 : message_center::PaddedButton(owner), owner_(owner) { |
213 if (owner_->item_) { | 213 if (owner_->item_) { |
214 set_background(views::Background::CreateSolidBackground( | 214 set_background(views::Background::CreateSolidBackground( |
215 GetControlButtonBackgroundColor(owner_->item_->shown_contents()))); | 215 GetControlButtonBackgroundColor(owner_->item_->GetShownContents()))); |
216 } else { | 216 } else { |
217 set_background(views::Background::CreateSolidBackground( | 217 set_background(views::Background::CreateSolidBackground( |
218 message_center::kControlButtonBackgroundColor)); | 218 message_center::kControlButtonBackgroundColor)); |
219 } | 219 } |
220 } | 220 } |
221 | 221 |
222 void ArcCustomNotificationView::ControlButton::OnFocus() { | 222 void ArcCustomNotificationView::ControlButton::OnFocus() { |
223 message_center::PaddedButton::OnFocus(); | 223 message_center::PaddedButton::OnFocus(); |
224 owner_->UpdateControlButtonsVisibility(); | 224 owner_->UpdateControlButtonsVisibility(); |
225 } | 225 } |
226 | 226 |
227 void ArcCustomNotificationView::ControlButton::OnBlur() { | 227 void ArcCustomNotificationView::ControlButton::OnBlur() { |
228 message_center::PaddedButton::OnBlur(); | 228 message_center::PaddedButton::OnBlur(); |
229 owner_->UpdateControlButtonsVisibility(); | 229 owner_->UpdateControlButtonsVisibility(); |
230 } | 230 } |
231 | 231 |
232 ArcCustomNotificationView::ArcCustomNotificationView( | 232 ArcCustomNotificationView::ArcCustomNotificationView(ArcNotificationItem* item) |
233 ArcCustomNotificationItem* item) | |
234 : item_(item), | 233 : item_(item), |
235 notification_key_(item->notification_key()), | 234 notification_key_(item->GetNotificationKey()), |
236 event_forwarder_(new EventForwarder(this)) { | 235 event_forwarder_(new EventForwarder(this)) { |
237 SetFocusBehavior(FocusBehavior::ALWAYS); | 236 SetFocusBehavior(FocusBehavior::ALWAYS); |
238 | 237 |
239 item_->IncrementWindowRefCount(); | 238 item_->IncrementWindowRefCount(); |
240 item_->AddObserver(this); | 239 item_->AddObserver(this); |
241 | 240 |
242 ArcNotificationSurfaceManager::Get()->AddObserver(this); | 241 auto* surface_manager = ArcNotificationSurfaceManager::Get(); |
243 exo::NotificationSurface* surface = | 242 if (surface_manager) { |
244 ArcNotificationSurfaceManager::Get()->GetSurface(notification_key_); | 243 surface_manager->AddObserver(this); |
245 if (surface) | 244 exo::NotificationSurface* surface = |
246 OnNotificationSurfaceAdded(surface); | 245 surface_manager->GetSurface(notification_key_); |
| 246 if (surface) |
| 247 OnNotificationSurfaceAdded(surface); |
| 248 } |
247 | 249 |
248 // Create a layer as an anchor to insert surface copy during a slide. | 250 // Create a layer as an anchor to insert surface copy during a slide. |
249 SetPaintToLayer(); | 251 SetPaintToLayer(); |
250 UpdatePreferredSize(); | 252 UpdatePreferredSize(); |
251 } | 253 } |
252 | 254 |
253 ArcCustomNotificationView::~ArcCustomNotificationView() { | 255 ArcCustomNotificationView::~ArcCustomNotificationView() { |
254 SetSurface(nullptr); | 256 SetSurface(nullptr); |
| 257 |
| 258 auto* surface_manager = ArcNotificationSurfaceManager::Get(); |
| 259 if (surface_manager) |
| 260 surface_manager->RemoveObserver(this); |
255 if (item_) { | 261 if (item_) { |
| 262 item_->RemoveObserver(this); |
256 item_->DecrementWindowRefCount(); | 263 item_->DecrementWindowRefCount(); |
257 item_->RemoveObserver(this); | |
258 } | 264 } |
259 | |
260 if (ArcNotificationSurfaceManager::Get()) | |
261 ArcNotificationSurfaceManager::Get()->RemoveObserver(this); | |
262 } | 265 } |
263 | 266 |
264 std::unique_ptr<message_center::CustomNotificationContentViewDelegate> | 267 std::unique_ptr<message_center::CustomNotificationContentViewDelegate> |
265 ArcCustomNotificationView::CreateContentViewDelegate() { | 268 ArcCustomNotificationView::CreateContentViewDelegate() { |
266 return base::MakeUnique<ArcCustomNotificationView::ContentViewDelegate>(this); | 269 return base::MakeUnique<ArcCustomNotificationView::ContentViewDelegate>(this); |
267 } | 270 } |
268 | 271 |
269 void ArcCustomNotificationView::CreateCloseButton() { | 272 void ArcCustomNotificationView::CreateCloseButton() { |
270 DCHECK(control_buttons_view_); | 273 DCHECK(control_buttons_view_); |
271 DCHECK(item_); | 274 DCHECK(item_); |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
304 return; | 307 return; |
305 | 308 |
306 // Creates the control_buttons_view_, which collects all control buttons into | 309 // Creates the control_buttons_view_, which collects all control buttons into |
307 // a horizontal box. | 310 // a horizontal box. |
308 control_buttons_view_ = new views::View(); | 311 control_buttons_view_ = new views::View(); |
309 control_buttons_view_->SetLayoutManager( | 312 control_buttons_view_->SetLayoutManager( |
310 new views::BoxLayout(views::BoxLayout::kHorizontal, 0, 0, 0)); | 313 new views::BoxLayout(views::BoxLayout::kHorizontal, 0, 0, 0)); |
311 | 314 |
312 if (item_->IsOpeningSettingsSupported()) | 315 if (item_->IsOpeningSettingsSupported()) |
313 CreateSettingsButton(); | 316 CreateSettingsButton(); |
314 if (!item_->pinned()) | 317 if (!item_->GetPinned()) |
315 CreateCloseButton(); | 318 CreateCloseButton(); |
316 | 319 |
317 views::Widget::InitParams params(views::Widget::InitParams::TYPE_CONTROL); | 320 views::Widget::InitParams params(views::Widget::InitParams::TYPE_CONTROL); |
318 params.opacity = views::Widget::InitParams::TRANSLUCENT_WINDOW; | 321 params.opacity = views::Widget::InitParams::TRANSLUCENT_WINDOW; |
319 params.ownership = views::Widget::InitParams::WIDGET_OWNS_NATIVE_WIDGET; | 322 params.ownership = views::Widget::InitParams::WIDGET_OWNS_NATIVE_WIDGET; |
320 params.parent = surface_->window(); | 323 params.parent = surface_->window(); |
321 | 324 |
322 floating_control_buttons_widget_.reset(new views::Widget); | 325 floating_control_buttons_widget_.reset(new views::Widget); |
323 floating_control_buttons_widget_->Init(params); | 326 floating_control_buttons_widget_->Init(params); |
324 floating_control_buttons_widget_->SetContentsView(control_buttons_view_); | 327 floating_control_buttons_widget_->SetContentsView(control_buttons_view_); |
(...skipping 28 matching lines...) Expand all Loading... |
353 surface_->window()->AddPreTargetHandler(event_forwarder_.get()); | 356 surface_->window()->AddPreTargetHandler(event_forwarder_.get()); |
354 | 357 |
355 MaybeCreateFloatingControlButtons(); | 358 MaybeCreateFloatingControlButtons(); |
356 | 359 |
357 if (GetWidget()) | 360 if (GetWidget()) |
358 AttachSurface(); | 361 AttachSurface(); |
359 } | 362 } |
360 } | 363 } |
361 | 364 |
362 void ArcCustomNotificationView::UpdatePreferredSize() { | 365 void ArcCustomNotificationView::UpdatePreferredSize() { |
363 gfx::Size preferred_size = | 366 gfx::Size preferred_size; |
364 surface_ ? surface_->GetSize() : item_ ? item_->snapshot().size() | 367 if (surface_) |
365 : gfx::Size(); | 368 preferred_size = surface_->GetSize(); |
| 369 else if (item_) |
| 370 preferred_size = item_->GetSnapshot().size(); |
| 371 |
366 if (preferred_size.IsEmpty()) | 372 if (preferred_size.IsEmpty()) |
367 return; | 373 return; |
368 | 374 |
369 if (preferred_size.width() != message_center::kNotificationWidth) { | 375 if (preferred_size.width() != message_center::kNotificationWidth) { |
370 const float scale = static_cast<float>(message_center::kNotificationWidth) / | 376 const float scale = static_cast<float>(message_center::kNotificationWidth) / |
371 preferred_size.width(); | 377 preferred_size.width(); |
372 preferred_size.SetSize(message_center::kNotificationWidth, | 378 preferred_size.SetSize(message_center::kNotificationWidth, |
373 preferred_size.height() * scale); | 379 preferred_size.height() * scale); |
374 } | 380 } |
375 | 381 |
(...skipping 26 matching lines...) Expand all Loading... |
402 if (target_visiblity) | 408 if (target_visiblity) |
403 floating_control_buttons_widget_->Show(); | 409 floating_control_buttons_widget_->Show(); |
404 else | 410 else |
405 floating_control_buttons_widget_->Hide(); | 411 floating_control_buttons_widget_->Hide(); |
406 } | 412 } |
407 | 413 |
408 void ArcCustomNotificationView::UpdatePinnedState() { | 414 void ArcCustomNotificationView::UpdatePinnedState() { |
409 if (!item_) | 415 if (!item_) |
410 return; | 416 return; |
411 | 417 |
412 if (item_->pinned() && close_button_) { | 418 if (item_->GetPinned() && close_button_) { |
413 control_buttons_view_->RemoveChildView(close_button_.get()); | 419 control_buttons_view_->RemoveChildView(close_button_.get()); |
414 close_button_.reset(); | 420 close_button_.reset(); |
415 Layout(); | 421 Layout(); |
416 } else if (!item_->pinned() && !close_button_) { | 422 } else if (!item_->GetPinned() && !close_button_) { |
417 CreateCloseButton(); | 423 CreateCloseButton(); |
418 Layout(); | 424 Layout(); |
419 } | 425 } |
420 } | 426 } |
421 | 427 |
422 void ArcCustomNotificationView::UpdateSnapshot() { | 428 void ArcCustomNotificationView::UpdateSnapshot() { |
423 // Bail if we have a |surface_| because it controls the sizes and paints UI. | 429 // Bail if we have a |surface_| because it controls the sizes and paints UI. |
424 if (surface_) | 430 if (surface_) |
425 return; | 431 return; |
426 | 432 |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
460 control_button_color_animation_->Start(); | 466 control_button_color_animation_->Start(); |
461 } | 467 } |
462 | 468 |
463 bool ArcCustomNotificationView::ShouldUpdateControlButtonsColor() const { | 469 bool ArcCustomNotificationView::ShouldUpdateControlButtonsColor() const { |
464 // Don't update the control button color when we are about to be destroyed. | 470 // Don't update the control button color when we are about to be destroyed. |
465 if (!item_) | 471 if (!item_) |
466 return false; | 472 return false; |
467 | 473 |
468 if (settings_button_ && | 474 if (settings_button_ && |
469 settings_button_->background()->get_color() != | 475 settings_button_->background()->get_color() != |
470 GetControlButtonBackgroundColor(item_->shown_contents())) | 476 GetControlButtonBackgroundColor(item_->GetShownContents())) |
471 return true; | 477 return true; |
472 if (close_button_ && | 478 if (close_button_ && |
473 close_button_->background()->get_color() != | 479 close_button_->background()->get_color() != |
474 GetControlButtonBackgroundColor(item_->shown_contents())) | 480 GetControlButtonBackgroundColor(item_->GetShownContents())) |
475 return true; | 481 return true; |
476 return false; | 482 return false; |
477 } | 483 } |
478 | 484 |
479 void ArcCustomNotificationView::ViewHierarchyChanged( | 485 void ArcCustomNotificationView::ViewHierarchyChanged( |
480 const views::View::ViewHierarchyChangedDetails& details) { | 486 const views::View::ViewHierarchyChangedDetails& details) { |
481 views::Widget* widget = GetWidget(); | 487 views::Widget* widget = GetWidget(); |
482 | 488 |
483 if (!details.is_add) { | 489 if (!details.is_add) { |
484 // Resets slide helper when this view is removed from its parent. | 490 // Resets slide helper when this view is removed from its parent. |
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
549 | 555 |
550 UpdateControlButtonsVisibility(); | 556 UpdateControlButtonsVisibility(); |
551 | 557 |
552 ash::wm::SnapWindowToPixelBoundary(surface_->window()); | 558 ash::wm::SnapWindowToPixelBoundary(surface_->window()); |
553 } | 559 } |
554 | 560 |
555 void ArcCustomNotificationView::OnPaint(gfx::Canvas* canvas) { | 561 void ArcCustomNotificationView::OnPaint(gfx::Canvas* canvas) { |
556 views::NativeViewHost::OnPaint(canvas); | 562 views::NativeViewHost::OnPaint(canvas); |
557 | 563 |
558 // Bail if there is a |surface_| or no item or no snapshot image. | 564 // Bail if there is a |surface_| or no item or no snapshot image. |
559 if (surface_ || !item_ || item_->snapshot().isNull()) | 565 if (surface_ || !item_ || item_->GetSnapshot().isNull()) |
560 return; | 566 return; |
561 const gfx::Rect contents_bounds = GetContentsBounds(); | 567 const gfx::Rect contents_bounds = GetContentsBounds(); |
562 canvas->DrawImageInt(item_->snapshot(), 0, 0, item_->snapshot().width(), | 568 canvas->DrawImageInt(item_->GetSnapshot(), 0, 0, item_->GetSnapshot().width(), |
563 item_->snapshot().height(), contents_bounds.x(), | 569 item_->GetSnapshot().height(), contents_bounds.x(), |
564 contents_bounds.y(), contents_bounds.width(), | 570 contents_bounds.y(), contents_bounds.width(), |
565 contents_bounds.height(), false); | 571 contents_bounds.height(), false); |
566 } | 572 } |
567 | 573 |
568 void ArcCustomNotificationView::OnKeyEvent(ui::KeyEvent* event) { | 574 void ArcCustomNotificationView::OnKeyEvent(ui::KeyEvent* event) { |
569 // Forward to parent CustomNotificationView to handle keyboard dismissal. | 575 // Forward to parent CustomNotificationView to handle keyboard dismissal. |
570 parent()->OnKeyEvent(event); | 576 parent()->OnKeyEvent(event); |
571 } | 577 } |
572 | 578 |
573 void ArcCustomNotificationView::OnGestureEvent(ui::GestureEvent* event) { | 579 void ArcCustomNotificationView::OnGestureEvent(ui::GestureEvent* event) { |
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
629 const ui::AXActionData& action_data) { | 635 const ui::AXActionData& action_data) { |
630 if (item_ && action_data.action == ui::AX_ACTION_DO_DEFAULT) { | 636 if (item_ && action_data.action == ui::AX_ACTION_DO_DEFAULT) { |
631 item_->ToggleExpansion(); | 637 item_->ToggleExpansion(); |
632 return true; | 638 return true; |
633 } | 639 } |
634 return false; | 640 return false; |
635 } | 641 } |
636 | 642 |
637 void ArcCustomNotificationView::ButtonPressed(views::Button* sender, | 643 void ArcCustomNotificationView::ButtonPressed(views::Button* sender, |
638 const ui::Event& event) { | 644 const ui::Event& event) { |
639 if (item_ && !item_->pinned() && sender == close_button_.get()) { | 645 if (item_ && !item_->GetPinned() && sender == close_button_.get()) { |
640 CHECK_EQ(message_center::CustomNotificationView::kViewClassName, | 646 CHECK_EQ(message_center::CustomNotificationView::kViewClassName, |
641 parent()->GetClassName()); | 647 parent()->GetClassName()); |
642 static_cast<message_center::CustomNotificationView*>(parent()) | 648 static_cast<message_center::CustomNotificationView*>(parent()) |
643 ->OnCloseButtonPressed(); | 649 ->OnCloseButtonPressed(); |
644 } | 650 } |
645 if (item_ && settings_button_ && sender == settings_button_) { | 651 if (item_ && settings_button_ && sender == settings_button_) { |
646 item_->OpenSettings(); | 652 item_->OpenSettings(); |
647 } | 653 } |
648 } | 654 } |
649 | 655 |
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
699 DCHECK_EQ(animation, control_button_color_animation_.get()); | 705 DCHECK_EQ(animation, control_button_color_animation_.get()); |
700 control_button_color_animation_.reset(); | 706 control_button_color_animation_.reset(); |
701 } | 707 } |
702 | 708 |
703 void ArcCustomNotificationView::AnimationProgressed( | 709 void ArcCustomNotificationView::AnimationProgressed( |
704 const gfx::Animation* animation) { | 710 const gfx::Animation* animation) { |
705 DCHECK_EQ(animation, control_button_color_animation_.get()); | 711 DCHECK_EQ(animation, control_button_color_animation_.get()); |
706 | 712 |
707 if (item_) { | 713 if (item_) { |
708 const SkColor target = | 714 const SkColor target = |
709 GetControlButtonBackgroundColor(item_->shown_contents()); | 715 GetControlButtonBackgroundColor(item_->GetShownContents()); |
710 const SkColor start = | 716 const SkColor start = |
711 target == message_center::kControlButtonBackgroundColor | 717 target == message_center::kControlButtonBackgroundColor |
712 ? SK_ColorTRANSPARENT | 718 ? SK_ColorTRANSPARENT |
713 : message_center::kControlButtonBackgroundColor; | 719 : message_center::kControlButtonBackgroundColor; |
714 const SkColor current_color = gfx::Tween::ColorValueBetween( | 720 const SkColor current_color = gfx::Tween::ColorValueBetween( |
715 animation->GetCurrentValue(), start, target); | 721 animation->GetCurrentValue(), start, target); |
716 if (settings_button_) { | 722 if (settings_button_) { |
717 settings_button_->set_background( | 723 settings_button_->set_background( |
718 views::Background::CreateSolidBackground(current_color)); | 724 views::Background::CreateSolidBackground(current_color)); |
719 settings_button_->SchedulePaint(); | 725 settings_button_->SchedulePaint(); |
720 } | 726 } |
721 if (close_button_) { | 727 if (close_button_) { |
722 close_button_->set_background( | 728 close_button_->set_background( |
723 views::Background::CreateSolidBackground(current_color)); | 729 views::Background::CreateSolidBackground(current_color)); |
724 close_button_->SchedulePaint(); | 730 close_button_->SchedulePaint(); |
725 } | 731 } |
726 } | 732 } |
727 } | 733 } |
728 | 734 |
729 } // namespace arc | 735 } // namespace arc |
OLD | NEW |