| 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 "components/exo/notification_surface.h" | 7 #include "components/exo/notification_surface.h" |
| 8 #include "components/exo/surface.h" | 8 #include "components/exo/surface.h" |
| 9 #include "third_party/skia/include/core/SkColor.h" | 9 #include "third_party/skia/include/core/SkColor.h" |
| 10 #include "ui/base/l10n/l10n_util.h" | 10 #include "ui/base/l10n/l10n_util.h" |
| (...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 70 views::Widget* widget = GetWidget(); | 70 views::Widget* widget = GetWidget(); |
| 71 | 71 |
| 72 // Bail if native_view() has attached to a different widget. | 72 // Bail if native_view() has attached to a different widget. |
| 73 if (widget && native_view() && | 73 if (widget && native_view() && |
| 74 views::Widget::GetTopLevelWidgetForNativeView(native_view()) != widget) { | 74 views::Widget::GetTopLevelWidgetForNativeView(native_view()) != widget) { |
| 75 return; | 75 return; |
| 76 } | 76 } |
| 77 | 77 |
| 78 views::NativeViewHost::ViewHierarchyChanged(details); | 78 views::NativeViewHost::ViewHierarchyChanged(details); |
| 79 | 79 |
| 80 if (!widget || !details.is_add) | 80 if (!widget || !surface_ || !details.is_add) |
| 81 return; | 81 return; |
| 82 | 82 |
| 83 SetPreferredSize(surface_->GetSize()); | 83 SetPreferredSize(surface_->GetSize()); |
| 84 Attach(surface_->window()); | 84 Attach(surface_->window()); |
| 85 } | 85 } |
| 86 | 86 |
| 87 void ArcCustomNotificationView::Layout() { | 87 void ArcCustomNotificationView::Layout() { |
| 88 views::NativeViewHost::Layout(); | 88 views::NativeViewHost::Layout(); |
| 89 | 89 |
| 90 if (!floating_close_button_widget_ || !GetWidget()) | 90 if (!floating_close_button_widget_ || !surface_ || !GetWidget()) |
| 91 return; | 91 return; |
| 92 | 92 |
| 93 gfx::Rect surface_local_bounds(surface_->window()->bounds().size()); | 93 gfx::Rect surface_local_bounds(surface_->window()->bounds().size()); |
| 94 gfx::Rect close_button_bounds(floating_close_button_->GetPreferredSize()); | 94 gfx::Rect close_button_bounds(floating_close_button_->GetPreferredSize()); |
| 95 close_button_bounds.set_x(surface_local_bounds.right() - | 95 close_button_bounds.set_x(surface_local_bounds.right() - |
| 96 close_button_bounds.width()); | 96 close_button_bounds.width()); |
| 97 close_button_bounds.set_y(surface_local_bounds.y()); | 97 close_button_bounds.set_y(surface_local_bounds.y()); |
| 98 floating_close_button_widget_->SetBounds(close_button_bounds); | 98 floating_close_button_widget_->SetBounds(close_button_bounds); |
| 99 } | 99 } |
| 100 | 100 |
| 101 void ArcCustomNotificationView::ButtonPressed(views::Button* sender, | 101 void ArcCustomNotificationView::ButtonPressed(views::Button* sender, |
| 102 const ui::Event& event) { | 102 const ui::Event& event) { |
| 103 if (item_ && !item_->pinned() && sender == floating_close_button_) { | 103 if (item_ && !item_->pinned() && sender == floating_close_button_) { |
| 104 item_->CloseFromCloseButton(); | 104 item_->CloseFromCloseButton(); |
| 105 } | 105 } |
| 106 } | 106 } |
| 107 | 107 |
| 108 void ArcCustomNotificationView::OnItemDestroying() { | 108 void ArcCustomNotificationView::OnItemDestroying() { |
| 109 item_->RemoveObserver(this); | 109 item_->RemoveObserver(this); |
| 110 item_ = nullptr; | 110 item_ = nullptr; |
| 111 |
| 112 // Reset |surface_| with |item_| since no one is observing the |surface_| |
| 113 // after |item_| is gone and this view should be removed soon. |
| 114 surface_ = nullptr; |
| 111 } | 115 } |
| 112 | 116 |
| 113 void ArcCustomNotificationView::OnItemPinnedChanged() { | 117 void ArcCustomNotificationView::OnItemPinnedChanged() { |
| 114 if (item_->pinned() && floating_close_button_widget_) { | 118 if (item_->pinned() && floating_close_button_widget_) { |
| 115 floating_close_button_widget_.reset(); | 119 floating_close_button_widget_.reset(); |
| 116 } else if (!item_->pinned() && !floating_close_button_widget_) { | 120 } else if (!item_->pinned() && !floating_close_button_widget_) { |
| 117 CreateFloatingCloseButton(); | 121 CreateFloatingCloseButton(); |
| 118 } | 122 } |
| 119 } | 123 } |
| 120 | 124 |
| 125 void ArcCustomNotificationView::OnItemNotificationSurfaceRemoved() { |
| 126 surface_ = nullptr; |
| 127 } |
| 128 |
| 121 } // namespace arc | 129 } // namespace arc |
| OLD | NEW |