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 175 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
186 | 186 |
187 void RequestFocusOnCloseButton() override { | 187 void RequestFocusOnCloseButton() override { |
188 if (owner_->close_button_) | 188 if (owner_->close_button_) |
189 owner_->close_button_->RequestFocus(); | 189 owner_->close_button_->RequestFocus(); |
190 owner_->UpdateControlButtonsVisibility(); | 190 owner_->UpdateControlButtonsVisibility(); |
191 } | 191 } |
192 | 192 |
193 bool IsPinned() const override { | 193 bool IsPinned() const override { |
194 if (!owner_->item_) | 194 if (!owner_->item_) |
195 return false; | 195 return false; |
196 return owner_->item_->pinned(); | 196 return owner_->item_->GetPinned(); |
197 } | 197 } |
198 | 198 |
199 void UpdateControlButtonsVisibility() override { | 199 void UpdateControlButtonsVisibility() override { |
200 owner_->UpdateControlButtonsVisibility(); | 200 owner_->UpdateControlButtonsVisibility(); |
201 } | 201 } |
202 | 202 |
203 private: | 203 private: |
204 ArcCustomNotificationView* const owner_; | 204 ArcCustomNotificationView* const owner_; |
205 | 205 |
206 DISALLOW_COPY_AND_ASSIGN(ContentViewDelegate); | 206 DISALLOW_COPY_AND_ASSIGN(ContentViewDelegate); |
207 }; | 207 }; |
208 | 208 |
209 ArcCustomNotificationView::ControlButton::ControlButton( | 209 ArcCustomNotificationView::ControlButton::ControlButton( |
210 ArcCustomNotificationView* owner) | 210 ArcCustomNotificationView* owner) |
211 : message_center::PaddedButton(owner), owner_(owner) { | 211 : message_center::PaddedButton(owner), owner_(owner) { |
212 if (owner_->item_) { | 212 if (owner_->item_) { |
213 set_background(views::Background::CreateSolidBackground( | 213 set_background(views::Background::CreateSolidBackground( |
214 GetControlButtonBackgroundColor(owner_->item_->shown_contents()))); | 214 GetControlButtonBackgroundColor(owner_->item_->GetShownContents()))); |
215 } else { | 215 } else { |
216 set_background(views::Background::CreateSolidBackground( | 216 set_background(views::Background::CreateSolidBackground( |
217 message_center::kControlButtonBackgroundColor)); | 217 message_center::kControlButtonBackgroundColor)); |
218 } | 218 } |
219 } | 219 } |
220 | 220 |
221 void ArcCustomNotificationView::ControlButton::OnFocus() { | 221 void ArcCustomNotificationView::ControlButton::OnFocus() { |
222 message_center::PaddedButton::OnFocus(); | 222 message_center::PaddedButton::OnFocus(); |
223 owner_->UpdateControlButtonsVisibility(); | 223 owner_->UpdateControlButtonsVisibility(); |
224 } | 224 } |
225 | 225 |
226 void ArcCustomNotificationView::ControlButton::OnBlur() { | 226 void ArcCustomNotificationView::ControlButton::OnBlur() { |
227 message_center::PaddedButton::OnBlur(); | 227 message_center::PaddedButton::OnBlur(); |
228 owner_->UpdateControlButtonsVisibility(); | 228 owner_->UpdateControlButtonsVisibility(); |
229 } | 229 } |
230 | 230 |
231 ArcCustomNotificationView::ArcCustomNotificationView( | 231 ArcCustomNotificationView::ArcCustomNotificationView(ArcNotificationItem* item) |
232 ArcCustomNotificationItem* item) | |
233 : item_(item), | 232 : item_(item), |
234 notification_key_(item->notification_key()), | 233 notification_key_(item->GetNotificationKey()), |
235 event_forwarder_(new EventForwarder(this)) { | 234 event_forwarder_(new EventForwarder(this)) { |
236 SetFocusBehavior(FocusBehavior::ALWAYS); | 235 SetFocusBehavior(FocusBehavior::ALWAYS); |
237 | 236 |
238 item_->IncrementWindowRefCount(); | 237 item_->IncrementWindowRefCount(); |
239 item_->AddObserver(this); | 238 item_->AddObserver(this); |
240 | 239 |
241 ArcNotificationSurfaceManager::Get()->AddObserver(this); | 240 if (ArcNotificationSurfaceManager::Get()) { |
hidehiko
2017/05/01 12:29:17
Optional/nit:
auto* surface_manager = ArcNotifica
yoshiki
2017/05/08 06:24:52
Done.
| |
242 exo::NotificationSurface* surface = | 241 ArcNotificationSurfaceManager::Get()->AddObserver(this); |
243 ArcNotificationSurfaceManager::Get()->GetSurface(notification_key_); | 242 exo::NotificationSurface* surface = |
244 if (surface) | 243 ArcNotificationSurfaceManager::Get()->GetSurface(notification_key_); |
245 OnNotificationSurfaceAdded(surface); | 244 if (surface) |
245 OnNotificationSurfaceAdded(surface); | |
246 } | |
246 | 247 |
247 // Create a layer as an anchor to insert surface copy during a slide. | 248 // Create a layer as an anchor to insert surface copy during a slide. |
248 SetPaintToLayer(); | 249 SetPaintToLayer(); |
249 UpdatePreferredSize(); | 250 UpdatePreferredSize(); |
250 } | 251 } |
251 | 252 |
252 ArcCustomNotificationView::~ArcCustomNotificationView() { | 253 ArcCustomNotificationView::~ArcCustomNotificationView() { |
253 SetSurface(nullptr); | 254 SetSurface(nullptr); |
254 if (item_) { | 255 if (item_) { |
255 item_->DecrementWindowRefCount(); | 256 item_->DecrementWindowRefCount(); |
hidehiko
2017/05/01 12:29:17
Please call clean up functions in the reverse orde
yoshiki
2017/05/08 06:24:52
Done.
| |
256 item_->RemoveObserver(this); | 257 item_->RemoveObserver(this); |
257 } | 258 } |
258 | 259 |
259 if (ArcNotificationSurfaceManager::Get()) | 260 if (ArcNotificationSurfaceManager::Get()) |
260 ArcNotificationSurfaceManager::Get()->RemoveObserver(this); | 261 ArcNotificationSurfaceManager::Get()->RemoveObserver(this); |
261 } | 262 } |
262 | 263 |
263 std::unique_ptr<message_center::CustomNotificationContentViewDelegate> | 264 std::unique_ptr<message_center::CustomNotificationContentViewDelegate> |
264 ArcCustomNotificationView::CreateContentViewDelegate() { | 265 ArcCustomNotificationView::CreateContentViewDelegate() { |
265 return base::MakeUnique<ArcCustomNotificationView::ContentViewDelegate>(this); | 266 return base::MakeUnique<ArcCustomNotificationView::ContentViewDelegate>(this); |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
303 return; | 304 return; |
304 | 305 |
305 // Creates the control_buttons_view_, which collects all control buttons into | 306 // Creates the control_buttons_view_, which collects all control buttons into |
306 // a horizontal box. | 307 // a horizontal box. |
307 control_buttons_view_ = new views::View(); | 308 control_buttons_view_ = new views::View(); |
308 control_buttons_view_->SetLayoutManager( | 309 control_buttons_view_->SetLayoutManager( |
309 new views::BoxLayout(views::BoxLayout::kHorizontal, 0, 0, 0)); | 310 new views::BoxLayout(views::BoxLayout::kHorizontal, 0, 0, 0)); |
310 | 311 |
311 if (item_->IsOpeningSettingsSupported()) | 312 if (item_->IsOpeningSettingsSupported()) |
312 CreateSettingsButton(); | 313 CreateSettingsButton(); |
313 if (!item_->pinned()) | 314 if (!item_->GetPinned()) |
314 CreateCloseButton(); | 315 CreateCloseButton(); |
315 | 316 |
316 views::Widget::InitParams params(views::Widget::InitParams::TYPE_CONTROL); | 317 views::Widget::InitParams params(views::Widget::InitParams::TYPE_CONTROL); |
317 params.opacity = views::Widget::InitParams::TRANSLUCENT_WINDOW; | 318 params.opacity = views::Widget::InitParams::TRANSLUCENT_WINDOW; |
318 params.ownership = views::Widget::InitParams::WIDGET_OWNS_NATIVE_WIDGET; | 319 params.ownership = views::Widget::InitParams::WIDGET_OWNS_NATIVE_WIDGET; |
319 params.parent = surface_->window(); | 320 params.parent = surface_->window(); |
320 | 321 |
321 floating_control_buttons_widget_.reset(new views::Widget); | 322 floating_control_buttons_widget_.reset(new views::Widget); |
322 floating_control_buttons_widget_->Init(params); | 323 floating_control_buttons_widget_->Init(params); |
323 floating_control_buttons_widget_->SetContentsView(control_buttons_view_); | 324 floating_control_buttons_widget_->SetContentsView(control_buttons_view_); |
(...skipping 29 matching lines...) Expand all Loading... | |
353 | 354 |
354 MaybeCreateFloatingControlButtons(); | 355 MaybeCreateFloatingControlButtons(); |
355 | 356 |
356 if (GetWidget()) | 357 if (GetWidget()) |
357 AttachSurface(); | 358 AttachSurface(); |
358 } | 359 } |
359 } | 360 } |
360 | 361 |
361 void ArcCustomNotificationView::UpdatePreferredSize() { | 362 void ArcCustomNotificationView::UpdatePreferredSize() { |
362 gfx::Size preferred_size = | 363 gfx::Size preferred_size = |
363 surface_ ? surface_->GetSize() : item_ ? item_->snapshot().size() | 364 surface_ ? surface_->GetSize() |
hidehiko
2017/05/01 12:29:17
Optional/nit:
Maybe better to avoid nested "?:" o
yoshiki
2017/05/08 06:24:52
Done.
| |
364 : gfx::Size(); | 365 : item_ ? item_->GetSnapshot().size() : gfx::Size(); |
365 if (preferred_size.IsEmpty()) | 366 if (preferred_size.IsEmpty()) |
366 return; | 367 return; |
367 | 368 |
368 if (preferred_size.width() != message_center::kNotificationWidth) { | 369 if (preferred_size.width() != message_center::kNotificationWidth) { |
369 const float scale = static_cast<float>(message_center::kNotificationWidth) / | 370 const float scale = static_cast<float>(message_center::kNotificationWidth) / |
370 preferred_size.width(); | 371 preferred_size.width(); |
371 preferred_size.SetSize(message_center::kNotificationWidth, | 372 preferred_size.SetSize(message_center::kNotificationWidth, |
372 preferred_size.height() * scale); | 373 preferred_size.height() * scale); |
373 } | 374 } |
374 | 375 |
(...skipping 26 matching lines...) Expand all Loading... | |
401 if (target_visiblity) | 402 if (target_visiblity) |
402 floating_control_buttons_widget_->Show(); | 403 floating_control_buttons_widget_->Show(); |
403 else | 404 else |
404 floating_control_buttons_widget_->Hide(); | 405 floating_control_buttons_widget_->Hide(); |
405 } | 406 } |
406 | 407 |
407 void ArcCustomNotificationView::UpdatePinnedState() { | 408 void ArcCustomNotificationView::UpdatePinnedState() { |
408 if (!item_) | 409 if (!item_) |
409 return; | 410 return; |
410 | 411 |
411 if (item_->pinned() && close_button_) { | 412 if (item_->GetPinned() && close_button_) { |
412 control_buttons_view_->RemoveChildView(close_button_.get()); | 413 control_buttons_view_->RemoveChildView(close_button_.get()); |
413 close_button_.reset(); | 414 close_button_.reset(); |
414 Layout(); | 415 Layout(); |
415 } else if (!item_->pinned() && !close_button_) { | 416 } else if (!item_->GetPinned() && !close_button_) { |
416 CreateCloseButton(); | 417 CreateCloseButton(); |
417 Layout(); | 418 Layout(); |
418 } | 419 } |
419 } | 420 } |
420 | 421 |
421 void ArcCustomNotificationView::UpdateSnapshot() { | 422 void ArcCustomNotificationView::UpdateSnapshot() { |
422 // Bail if we have a |surface_| because it controls the sizes and paints UI. | 423 // Bail if we have a |surface_| because it controls the sizes and paints UI. |
423 if (surface_) | 424 if (surface_) |
424 return; | 425 return; |
425 | 426 |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
459 control_button_color_animation_->Start(); | 460 control_button_color_animation_->Start(); |
460 } | 461 } |
461 | 462 |
462 bool ArcCustomNotificationView::ShouldUpdateControlButtonsColor() const { | 463 bool ArcCustomNotificationView::ShouldUpdateControlButtonsColor() const { |
463 // Don't update the control button color when we are about to be destroyed. | 464 // Don't update the control button color when we are about to be destroyed. |
464 if (!item_) | 465 if (!item_) |
465 return false; | 466 return false; |
466 | 467 |
467 if (settings_button_ && | 468 if (settings_button_ && |
468 settings_button_->background()->get_color() != | 469 settings_button_->background()->get_color() != |
469 GetControlButtonBackgroundColor(item_->shown_contents())) | 470 GetControlButtonBackgroundColor(item_->GetShownContents())) |
470 return true; | 471 return true; |
471 if (close_button_ && | 472 if (close_button_ && |
472 close_button_->background()->get_color() != | 473 close_button_->background()->get_color() != |
473 GetControlButtonBackgroundColor(item_->shown_contents())) | 474 GetControlButtonBackgroundColor(item_->GetShownContents())) |
474 return true; | 475 return true; |
475 return false; | 476 return false; |
476 } | 477 } |
477 | 478 |
478 void ArcCustomNotificationView::ViewHierarchyChanged( | 479 void ArcCustomNotificationView::ViewHierarchyChanged( |
479 const views::View::ViewHierarchyChangedDetails& details) { | 480 const views::View::ViewHierarchyChangedDetails& details) { |
480 views::Widget* widget = GetWidget(); | 481 views::Widget* widget = GetWidget(); |
481 | 482 |
482 if (!details.is_add) { | 483 if (!details.is_add) { |
483 // Resets slide helper when this view is removed from its parent. | 484 // Resets slide helper when this view is removed from its parent. |
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
548 | 549 |
549 UpdateControlButtonsVisibility(); | 550 UpdateControlButtonsVisibility(); |
550 | 551 |
551 ash::wm::SnapWindowToPixelBoundary(surface_->window()); | 552 ash::wm::SnapWindowToPixelBoundary(surface_->window()); |
552 } | 553 } |
553 | 554 |
554 void ArcCustomNotificationView::OnPaint(gfx::Canvas* canvas) { | 555 void ArcCustomNotificationView::OnPaint(gfx::Canvas* canvas) { |
555 views::NativeViewHost::OnPaint(canvas); | 556 views::NativeViewHost::OnPaint(canvas); |
556 | 557 |
557 // Bail if there is a |surface_| or no item or no snapshot image. | 558 // Bail if there is a |surface_| or no item or no snapshot image. |
558 if (surface_ || !item_ || item_->snapshot().isNull()) | 559 if (surface_ || !item_ || item_->GetSnapshot().isNull()) |
559 return; | 560 return; |
560 const gfx::Rect contents_bounds = GetContentsBounds(); | 561 const gfx::Rect contents_bounds = GetContentsBounds(); |
561 canvas->DrawImageInt(item_->snapshot(), 0, 0, item_->snapshot().width(), | 562 canvas->DrawImageInt(item_->GetSnapshot(), 0, 0, item_->GetSnapshot().width(), |
562 item_->snapshot().height(), contents_bounds.x(), | 563 item_->GetSnapshot().height(), contents_bounds.x(), |
563 contents_bounds.y(), contents_bounds.width(), | 564 contents_bounds.y(), contents_bounds.width(), |
564 contents_bounds.height(), false); | 565 contents_bounds.height(), false); |
565 } | 566 } |
566 | 567 |
567 void ArcCustomNotificationView::OnKeyEvent(ui::KeyEvent* event) { | 568 void ArcCustomNotificationView::OnKeyEvent(ui::KeyEvent* event) { |
568 // Forward to parent CustomNotificationView to handle keyboard dismissal. | 569 // Forward to parent CustomNotificationView to handle keyboard dismissal. |
569 parent()->OnKeyEvent(event); | 570 parent()->OnKeyEvent(event); |
570 } | 571 } |
571 | 572 |
572 void ArcCustomNotificationView::OnGestureEvent(ui::GestureEvent* event) { | 573 void ArcCustomNotificationView::OnGestureEvent(ui::GestureEvent* event) { |
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
627 bool ArcCustomNotificationView::OnMousePressed(const ui::MouseEvent& event) { | 628 bool ArcCustomNotificationView::OnMousePressed(const ui::MouseEvent& event) { |
628 // TODO(yhanada): Remove this hack as soon as possible after letting | 629 // TODO(yhanada): Remove this hack as soon as possible after letting |
629 // accessible actions be delivered to this view. | 630 // accessible actions be delivered to this view. |
630 // All mouse clicks or touches should be sent to corresponding Android view | 631 // All mouse clicks or touches should be sent to corresponding Android view |
631 // because the surface is on this view, so receiving a mouse pressed event | 632 // because the surface is on this view, so receiving a mouse pressed event |
632 // means the event is generated by automation API. | 633 // means the event is generated by automation API. |
633 // We can distinguish events from automation API by checking the target of the | 634 // We can distinguish events from automation API by checking the target of the |
634 // event because the target of all events generated by automation API is set | 635 // event because the target of all events generated by automation API is set |
635 // to nullptr. | 636 // to nullptr. |
636 if (event.IsOnlyLeftMouseButton() && item_ && | 637 if (event.IsOnlyLeftMouseButton() && item_ && |
637 item_->expand_state() != mojom::ArcNotificationExpandState::FIXED_SIZE && | 638 item_->GetExpandState() != |
639 mojom::ArcNotificationExpandState::FIXED_SIZE && | |
638 event.target() == nullptr) { | 640 event.target() == nullptr) { |
639 item_->ToggleExpansion(); | 641 item_->ToggleExpansion(); |
640 return true; | 642 return true; |
641 } | 643 } |
642 return false; | 644 return false; |
643 } | 645 } |
644 | 646 |
645 void ArcCustomNotificationView::ButtonPressed(views::Button* sender, | 647 void ArcCustomNotificationView::ButtonPressed(views::Button* sender, |
646 const ui::Event& event) { | 648 const ui::Event& event) { |
647 if (item_ && !item_->pinned() && sender == close_button_.get()) { | 649 if (item_ && !item_->GetPinned() && sender == close_button_.get()) { |
648 CHECK_EQ(message_center::CustomNotificationView::kViewClassName, | 650 CHECK_EQ(message_center::CustomNotificationView::kViewClassName, |
649 parent()->GetClassName()); | 651 parent()->GetClassName()); |
650 static_cast<message_center::CustomNotificationView*>(parent()) | 652 static_cast<message_center::CustomNotificationView*>(parent()) |
651 ->OnCloseButtonPressed(); | 653 ->OnCloseButtonPressed(); |
652 } | 654 } |
653 if (item_ && settings_button_ && sender == settings_button_) { | 655 if (item_ && settings_button_ && sender == settings_button_) { |
654 item_->OpenSettings(); | 656 item_->OpenSettings(); |
655 } | 657 } |
656 } | 658 } |
657 | 659 |
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
707 DCHECK_EQ(animation, control_button_color_animation_.get()); | 709 DCHECK_EQ(animation, control_button_color_animation_.get()); |
708 control_button_color_animation_.reset(); | 710 control_button_color_animation_.reset(); |
709 } | 711 } |
710 | 712 |
711 void ArcCustomNotificationView::AnimationProgressed( | 713 void ArcCustomNotificationView::AnimationProgressed( |
712 const gfx::Animation* animation) { | 714 const gfx::Animation* animation) { |
713 DCHECK_EQ(animation, control_button_color_animation_.get()); | 715 DCHECK_EQ(animation, control_button_color_animation_.get()); |
714 | 716 |
715 if (item_) { | 717 if (item_) { |
716 const SkColor target = | 718 const SkColor target = |
717 GetControlButtonBackgroundColor(item_->shown_contents()); | 719 GetControlButtonBackgroundColor(item_->GetShownContents()); |
718 const SkColor start = | 720 const SkColor start = |
719 target == message_center::kControlButtonBackgroundColor | 721 target == message_center::kControlButtonBackgroundColor |
720 ? SK_ColorTRANSPARENT | 722 ? SK_ColorTRANSPARENT |
721 : message_center::kControlButtonBackgroundColor; | 723 : message_center::kControlButtonBackgroundColor; |
722 const SkColor current_color = gfx::Tween::ColorValueBetween( | 724 const SkColor current_color = gfx::Tween::ColorValueBetween( |
723 animation->GetCurrentValue(), start, target); | 725 animation->GetCurrentValue(), start, target); |
724 if (settings_button_) { | 726 if (settings_button_) { |
725 settings_button_->set_background( | 727 settings_button_->set_background( |
726 views::Background::CreateSolidBackground(current_color)); | 728 views::Background::CreateSolidBackground(current_color)); |
727 settings_button_->SchedulePaint(); | 729 settings_button_->SchedulePaint(); |
728 } | 730 } |
729 if (close_button_) { | 731 if (close_button_) { |
730 close_button_->set_background( | 732 close_button_->set_background( |
731 views::Background::CreateSolidBackground(current_color)); | 733 views::Background::CreateSolidBackground(current_color)); |
732 close_button_->SchedulePaint(); | 734 close_button_->SchedulePaint(); |
733 } | 735 } |
734 } | 736 } |
735 } | 737 } |
736 | 738 |
737 } // namespace arc | 739 } // namespace arc |
OLD | NEW |