Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(268)

Side by Side Diff: ui/arc/notification/arc_notification_content_view.cc

Issue 2918763002: Fix crash on updating notification before attaching (Closed)
Patch Set: . Created 3 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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_notification_content_view.h" 5 #include "ui/arc/notification/arc_notification_content_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 342 matching lines...) Expand 10 before | Expand all | Expand 10 after
353 surface_->window()->RemoveObserver(this); 353 surface_->window()->RemoveObserver(this);
354 surface_->window()->RemovePreTargetHandler(event_forwarder_.get()); 354 surface_->window()->RemovePreTargetHandler(event_forwarder_.get());
355 } 355 }
356 356
357 surface_ = surface; 357 surface_ = surface;
358 358
359 if (surface_ && surface_->window()) { 359 if (surface_ && surface_->window()) {
360 surface_->window()->AddObserver(this); 360 surface_->window()->AddObserver(this);
361 surface_->window()->AddPreTargetHandler(event_forwarder_.get()); 361 surface_->window()->AddPreTargetHandler(event_forwarder_.get());
362 362
363 MaybeCreateFloatingControlButtons();
364
365 if (GetWidget()) 363 if (GetWidget())
366 AttachSurface(); 364 AttachSurface();
367 } 365 }
368 } 366 }
369 367
370 void ArcNotificationContentView::UpdatePreferredSize() { 368 void ArcNotificationContentView::UpdatePreferredSize() {
371 gfx::Size preferred_size; 369 gfx::Size preferred_size;
372 if (surface_) 370 if (surface_)
373 preferred_size = surface_->GetSize(); 371 preferred_size = surface_->GetSize();
374 else if (item_) 372 else if (item_)
375 preferred_size = item_->GetSnapshot().size(); 373 preferred_size = item_->GetSnapshot().size();
376 374
377 if (preferred_size.IsEmpty()) 375 if (preferred_size.IsEmpty())
378 return; 376 return;
379 377
380 if (preferred_size.width() != message_center::kNotificationWidth) { 378 if (preferred_size.width() != message_center::kNotificationWidth) {
381 const float scale = static_cast<float>(message_center::kNotificationWidth) / 379 const float scale = static_cast<float>(message_center::kNotificationWidth) /
382 preferred_size.width(); 380 preferred_size.width();
383 preferred_size.SetSize(message_center::kNotificationWidth, 381 preferred_size.SetSize(message_center::kNotificationWidth,
384 preferred_size.height() * scale); 382 preferred_size.height() * scale);
385 } 383 }
386 384
387 SetPreferredSize(preferred_size); 385 SetPreferredSize(preferred_size);
388 } 386 }
389 387
390 void ArcNotificationContentView::UpdateControlButtonsVisibility() { 388 void ArcNotificationContentView::UpdateControlButtonsVisibility() {
391 if (!surface_) 389 if (!floating_control_buttons_widget_)
392 return; 390 return;
393 391
394 // TODO(edcourtney, yhanada): Creating the floating control widget here is not
395 // correct. This function may be called during the destruction of
396 // |floating_control_buttons_widget_|. This can lead to memory corruption.
397 // Rather than creating it here, we should fix the behaviour of OnMouseExited
398 // and OnMouseEntered for ARC notifications in MessageCenterView. See
399 // crbug.com/714587 and crbug.com/709862.
400 if (!floating_control_buttons_widget_) {
Eliot Courtney 2017/06/01 07:37:39 I think removing this code will cause a regression
yoshiki 2017/06/05 04:59:31 As I checked, the regression is not happened. (alt
401 // This may update |floating_control_buttons_widget_|.
402 MaybeCreateFloatingControlButtons();
403 if (!floating_control_buttons_widget_)
404 return;
405 }
406
407 const bool target_visiblity = 392 const bool target_visiblity =
408 IsMouseHovered() || (close_button_ && close_button_->HasFocus()) || 393 IsMouseHovered() || (close_button_ && close_button_->HasFocus()) ||
409 (settings_button_ && settings_button_->HasFocus()); 394 (settings_button_ && settings_button_->HasFocus());
410 if (target_visiblity == floating_control_buttons_widget_->IsVisible()) 395 if (target_visiblity == floating_control_buttons_widget_->IsVisible())
411 return; 396 return;
412 397
413 if (target_visiblity) 398 if (target_visiblity)
414 floating_control_buttons_widget_->Show(); 399 floating_control_buttons_widget_->Show();
415 else 400 else
416 floating_control_buttons_widget_->Hide(); 401 floating_control_buttons_widget_->Hide();
417 } 402 }
418 403
419 void ArcNotificationContentView::UpdatePinnedState() { 404 void ArcNotificationContentView::UpdatePinnedState() {
420 if (!item_) 405 // Surface is not attached yet.
406 if (!control_buttons_view_)
Eliot Courtney 2017/06/01 07:37:39 After removing the call to UpdatePinnedState from
yoshiki 2017/06/05 04:59:31 Done.
421 return; 407 return;
422 408
423 if (item_->GetPinned() && close_button_) { 409 if (item_->GetPinned() && close_button_) {
424 control_buttons_view_->RemoveChildView(close_button_.get()); 410 control_buttons_view_->RemoveChildView(close_button_.get());
425 close_button_.reset(); 411 close_button_.reset();
426 Layout(); 412 Layout();
427 } else if (!item_->GetPinned() && !close_button_) { 413 } else if (!item_->GetPinned() && !close_button_) {
428 CreateCloseButton(); 414 CreateCloseButton();
429 Layout(); 415 Layout();
430 } 416 }
(...skipping 19 matching lines...) Expand all
450 // with fractional scale factor. Force to align it at the pixel 436 // with fractional scale factor. Force to align it at the pixel
451 // boundary here, and when layout is updated in Layout(). 437 // boundary here, and when layout is updated in Layout().
452 ash::wm::SnapWindowToPixelBoundary(surface_->window()); 438 ash::wm::SnapWindowToPixelBoundary(surface_->window());
453 439
454 // Creates slide helper after this view is added to its parent. 440 // Creates slide helper after this view is added to its parent.
455 slide_helper_.reset(new SlideHelper(this)); 441 slide_helper_.reset(new SlideHelper(this));
456 442
457 // Invokes Update() in case surface is attached during a slide. 443 // Invokes Update() in case surface is attached during a slide.
458 slide_helper_->Update(); 444 slide_helper_->Update();
459 445
460 // Updates pinned state to create or destroy the floating close button 446 // (Re-)create the floating buttons after |surface_| is attached to a widget.
461 // after |surface_| is attached to a widget.
462 if (item_) 447 if (item_)
Eliot Courtney 2017/06/01 07:37:39 I think item_ is checked inside MaybeCreateFloatin
yoshiki 2017/06/05 04:59:31 Done.
463 UpdatePinnedState(); 448 MaybeCreateFloatingControlButtons();
Eliot Courtney 2017/06/01 07:37:39 Doesn't this mean the pinned state potentially isn
yoshiki 2017/06/05 04:59:31 The pinned state is updated by this method because
464 } 449 }
465 450
466 void ArcNotificationContentView::StartControlButtonsColorAnimation() { 451 void ArcNotificationContentView::StartControlButtonsColorAnimation() {
467 if (control_button_color_animation_) 452 if (control_button_color_animation_)
468 control_button_color_animation_->End(); 453 control_button_color_animation_->End();
469 control_button_color_animation_.reset(new gfx::LinearAnimation(this)); 454 control_button_color_animation_.reset(new gfx::LinearAnimation(this));
470 control_button_color_animation_->SetDuration(kBackgroundColorChangeDuration); 455 control_button_color_animation_->SetDuration(kBackgroundColorChangeDuration);
471 control_button_color_animation_->Start(); 456 control_button_color_animation_->Start();
472 } 457 }
473 458
(...skipping 252 matching lines...) Expand 10 before | Expand all | Expand 10 after
726 } 711 }
727 if (close_button_) { 712 if (close_button_) {
728 close_button_->set_background( 713 close_button_->set_background(
729 views::Background::CreateSolidBackground(current_color)); 714 views::Background::CreateSolidBackground(current_color));
730 close_button_->SchedulePaint(); 715 close_button_->SchedulePaint();
731 } 716 }
732 } 717 }
733 } 718 }
734 719
735 } // namespace arc 720 } // namespace arc
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698