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" |
11 #include "ui/base/resource/resource_bundle.h" | 11 #include "ui/base/resource/resource_bundle.h" |
| 12 #include "ui/message_center/message_center_style.h" |
12 #include "ui/resources/grit/ui_resources.h" | 13 #include "ui/resources/grit/ui_resources.h" |
13 #include "ui/strings/grit/ui_strings.h" | 14 #include "ui/strings/grit/ui_strings.h" |
14 #include "ui/views/background.h" | 15 #include "ui/views/background.h" |
15 #include "ui/views/border.h" | 16 #include "ui/views/border.h" |
16 #include "ui/views/controls/button/image_button.h" | 17 #include "ui/views/controls/button/image_button.h" |
17 #include "ui/views/widget/widget.h" | 18 #include "ui/views/widget/widget.h" |
18 | 19 |
19 namespace arc { | 20 namespace arc { |
20 | 21 |
21 ArcCustomNotificationView::ArcCustomNotificationView( | 22 ArcCustomNotificationView::ArcCustomNotificationView( |
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
73 if (widget && native_view() && | 74 if (widget && native_view() && |
74 views::Widget::GetTopLevelWidgetForNativeView(native_view()) != widget) { | 75 views::Widget::GetTopLevelWidgetForNativeView(native_view()) != widget) { |
75 return; | 76 return; |
76 } | 77 } |
77 | 78 |
78 views::NativeViewHost::ViewHierarchyChanged(details); | 79 views::NativeViewHost::ViewHierarchyChanged(details); |
79 | 80 |
80 if (!widget || !surface_ || !details.is_add) | 81 if (!widget || !surface_ || !details.is_add) |
81 return; | 82 return; |
82 | 83 |
83 SetPreferredSize(surface_->GetSize()); | 84 gfx::Size preferred_size = surface_->GetSize(); |
| 85 if (preferred_size.width() != message_center::kNotificationWidth) { |
| 86 const float scale = static_cast<float>(message_center::kNotificationWidth) / |
| 87 preferred_size.width(); |
| 88 preferred_size.SetSize(message_center::kNotificationWidth, |
| 89 preferred_size.height() * scale); |
| 90 } |
| 91 |
| 92 SetPreferredSize(preferred_size); |
84 Attach(surface_->window()); | 93 Attach(surface_->window()); |
85 } | 94 } |
86 | 95 |
87 void ArcCustomNotificationView::Layout() { | 96 void ArcCustomNotificationView::Layout() { |
88 views::NativeViewHost::Layout(); | 97 views::NativeViewHost::Layout(); |
89 | 98 |
90 if (!floating_close_button_widget_ || !surface_ || !GetWidget()) | 99 if (!surface_ || !GetWidget()) |
91 return; | 100 return; |
92 | 101 |
93 gfx::Rect surface_local_bounds(surface_->window()->bounds().size()); | 102 // Scale notification surface if necessary. |
| 103 gfx::Transform transform; |
| 104 const gfx::Size surface_size = surface_->GetSize(); |
| 105 const gfx::Size contents_size = GetContentsBounds().size(); |
| 106 if (!surface_size.IsEmpty() && !contents_size.IsEmpty()) { |
| 107 transform.Scale( |
| 108 static_cast<float>(contents_size.width()) / surface_size.width(), |
| 109 static_cast<float>(contents_size.height()) / surface_size.height()); |
| 110 } |
| 111 surface_->window()->SetTransform(transform); |
| 112 |
| 113 if (!floating_close_button_widget_) |
| 114 return; |
| 115 |
| 116 gfx::Rect surface_local_bounds(surface_->GetSize()); |
94 gfx::Rect close_button_bounds(floating_close_button_->GetPreferredSize()); | 117 gfx::Rect close_button_bounds(floating_close_button_->GetPreferredSize()); |
95 close_button_bounds.set_x(surface_local_bounds.right() - | 118 close_button_bounds.set_x(surface_local_bounds.right() - |
96 close_button_bounds.width()); | 119 close_button_bounds.width()); |
97 close_button_bounds.set_y(surface_local_bounds.y()); | 120 close_button_bounds.set_y(surface_local_bounds.y()); |
98 floating_close_button_widget_->SetBounds(close_button_bounds); | 121 floating_close_button_widget_->SetBounds(close_button_bounds); |
99 } | 122 } |
100 | 123 |
101 void ArcCustomNotificationView::ButtonPressed(views::Button* sender, | 124 void ArcCustomNotificationView::ButtonPressed(views::Button* sender, |
102 const ui::Event& event) { | 125 const ui::Event& event) { |
103 if (item_ && !item_->pinned() && sender == floating_close_button_) { | 126 if (item_ && !item_->pinned() && sender == floating_close_button_) { |
(...skipping 16 matching lines...) Expand all Loading... |
120 } else if (!item_->pinned() && !floating_close_button_widget_) { | 143 } else if (!item_->pinned() && !floating_close_button_widget_) { |
121 CreateFloatingCloseButton(); | 144 CreateFloatingCloseButton(); |
122 } | 145 } |
123 } | 146 } |
124 | 147 |
125 void ArcCustomNotificationView::OnItemNotificationSurfaceRemoved() { | 148 void ArcCustomNotificationView::OnItemNotificationSurfaceRemoved() { |
126 surface_ = nullptr; | 149 surface_ = nullptr; |
127 } | 150 } |
128 | 151 |
129 } // namespace arc | 152 } // namespace arc |
OLD | NEW |