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_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" |
11 #include "components/exo/surface.h" | 11 #include "components/exo/surface.h" |
12 #include "ui/accessibility/ax_action_data.h" | 12 #include "ui/accessibility/ax_action_data.h" |
13 #include "ui/accessibility/ax_node_data.h" | 13 #include "ui/accessibility/ax_node_data.h" |
14 #include "ui/arc/notification/arc_notification_view.h" | 14 #include "ui/arc/notification/arc_notification_view.h" |
15 #include "ui/base/l10n/l10n_util.h" | 15 #include "ui/base/l10n/l10n_util.h" |
(...skipping 26 matching lines...) Expand all Loading... |
42 SkColor GetControlButtonBackgroundColor( | 42 SkColor GetControlButtonBackgroundColor( |
43 const mojom::ArcNotificationShownContents& shown_contents) { | 43 const mojom::ArcNotificationShownContents& shown_contents) { |
44 if (shown_contents == mojom::ArcNotificationShownContents::CONTENTS_SHOWN) | 44 if (shown_contents == mojom::ArcNotificationShownContents::CONTENTS_SHOWN) |
45 return message_center::kControlButtonBackgroundColor; | 45 return message_center::kControlButtonBackgroundColor; |
46 else | 46 else |
47 return SK_ColorTRANSPARENT; | 47 return SK_ColorTRANSPARENT; |
48 } | 48 } |
49 | 49 |
50 } // namespace | 50 } // namespace |
51 | 51 |
52 class ArcCustomNotificationView::EventForwarder : public ui::EventHandler { | 52 class ArcNotificationContentView::EventForwarder : public ui::EventHandler { |
53 public: | 53 public: |
54 explicit EventForwarder(ArcCustomNotificationView* owner) : owner_(owner) {} | 54 explicit EventForwarder(ArcNotificationContentView* owner) : owner_(owner) {} |
55 ~EventForwarder() override = default; | 55 ~EventForwarder() override = default; |
56 | 56 |
57 private: | 57 private: |
58 // ui::EventHandler | 58 // ui::EventHandler |
59 void OnEvent(ui::Event* event) override { | 59 void OnEvent(ui::Event* event) override { |
60 // Do not forward event targeted to the floating close button so that | 60 // Do not forward event targeted to the floating close button so that |
61 // keyboard press and tap are handled properly. | 61 // keyboard press and tap are handled properly. |
62 if (owner_->floating_control_buttons_widget_ && event->target() && | 62 if (owner_->floating_control_buttons_widget_ && event->target() && |
63 owner_->floating_control_buttons_widget_->GetNativeWindow() == | 63 owner_->floating_control_buttons_widget_->GetNativeWindow() == |
64 event->target()) { | 64 event->target()) { |
(...skipping 25 matching lines...) Expand all Loading... |
90 widget->OnMouseEvent(located_event->AsMouseEvent()); | 90 widget->OnMouseEvent(located_event->AsMouseEvent()); |
91 } else if (located_event->IsScrollEvent()) { | 91 } else if (located_event->IsScrollEvent()) { |
92 widget->OnScrollEvent(located_event->AsScrollEvent()); | 92 widget->OnScrollEvent(located_event->AsScrollEvent()); |
93 } else if (located_event->IsGestureEvent() && | 93 } else if (located_event->IsGestureEvent() && |
94 event->type() != ui::ET_GESTURE_TAP) { | 94 event->type() != ui::ET_GESTURE_TAP) { |
95 widget->OnGestureEvent(located_event->AsGestureEvent()); | 95 widget->OnGestureEvent(located_event->AsGestureEvent()); |
96 } | 96 } |
97 } | 97 } |
98 } | 98 } |
99 | 99 |
100 ArcCustomNotificationView* const owner_; | 100 ArcNotificationContentView* const owner_; |
101 | 101 |
102 DISALLOW_COPY_AND_ASSIGN(EventForwarder); | 102 DISALLOW_COPY_AND_ASSIGN(EventForwarder); |
103 }; | 103 }; |
104 | 104 |
105 class ArcCustomNotificationView::SlideHelper | 105 class ArcNotificationContentView::SlideHelper |
106 : public ui::LayerAnimationObserver { | 106 : public ui::LayerAnimationObserver { |
107 public: | 107 public: |
108 explicit SlideHelper(ArcCustomNotificationView* owner) : owner_(owner) { | 108 explicit SlideHelper(ArcNotificationContentView* owner) : owner_(owner) { |
109 GetSlideOutLayer()->GetAnimator()->AddObserver(this); | 109 GetSlideOutLayer()->GetAnimator()->AddObserver(this); |
110 | 110 |
111 // Reset opacity to 1 to handle to case when the surface is sliding before | 111 // Reset opacity to 1 to handle to case when the surface is sliding before |
112 // getting managed by this class, e.g. sliding in a popup before showing | 112 // getting managed by this class, e.g. sliding in a popup before showing |
113 // in a message center view. | 113 // in a message center view. |
114 if (owner_->surface_ && owner_->surface_->window()) | 114 if (owner_->surface_ && owner_->surface_->window()) |
115 owner_->surface_->window()->layer()->SetOpacity(1.0f); | 115 owner_->surface_->window()->layer()->SetOpacity(1.0f); |
116 } | 116 } |
117 ~SlideHelper() override { | 117 ~SlideHelper() override { |
118 if (GetSlideOutLayer()) | 118 if (GetSlideOutLayer()) |
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
162 | 162 |
163 // ui::LayerAnimationObserver | 163 // ui::LayerAnimationObserver |
164 void OnLayerAnimationEnded(ui::LayerAnimationSequence* seq) override { | 164 void OnLayerAnimationEnded(ui::LayerAnimationSequence* seq) override { |
165 Update(); | 165 Update(); |
166 } | 166 } |
167 void OnLayerAnimationAborted(ui::LayerAnimationSequence* seq) override { | 167 void OnLayerAnimationAborted(ui::LayerAnimationSequence* seq) override { |
168 Update(); | 168 Update(); |
169 } | 169 } |
170 void OnLayerAnimationScheduled(ui::LayerAnimationSequence* seq) override {} | 170 void OnLayerAnimationScheduled(ui::LayerAnimationSequence* seq) override {} |
171 | 171 |
172 ArcCustomNotificationView* const owner_; | 172 ArcNotificationContentView* const owner_; |
173 bool sliding_ = false; | 173 bool sliding_ = false; |
174 std::unique_ptr<ui::LayerTreeOwner> surface_copy_; | 174 std::unique_ptr<ui::LayerTreeOwner> surface_copy_; |
175 | 175 |
176 DISALLOW_COPY_AND_ASSIGN(SlideHelper); | 176 DISALLOW_COPY_AND_ASSIGN(SlideHelper); |
177 }; | 177 }; |
178 | 178 |
179 class ArcCustomNotificationView::ContentViewDelegate | 179 class ArcNotificationContentView::ContentViewDelegate |
180 : public ArcNotificationContentViewDelegate { | 180 : public ArcNotificationContentViewDelegate { |
181 public: | 181 public: |
182 explicit ContentViewDelegate(ArcCustomNotificationView* owner) | 182 explicit ContentViewDelegate(ArcNotificationContentView* owner) |
183 : owner_(owner) {} | 183 : owner_(owner) {} |
184 | 184 |
185 bool IsCloseButtonFocused() const override { | 185 bool IsCloseButtonFocused() const override { |
186 if (!owner_->close_button_) | 186 if (!owner_->close_button_) |
187 return false; | 187 return false; |
188 return owner_->close_button_->HasFocus(); | 188 return owner_->close_button_->HasFocus(); |
189 } | 189 } |
190 | 190 |
191 void RequestFocusOnCloseButton() override { | 191 void RequestFocusOnCloseButton() override { |
192 if (owner_->close_button_) | 192 if (owner_->close_button_) |
193 owner_->close_button_->RequestFocus(); | 193 owner_->close_button_->RequestFocus(); |
194 owner_->UpdateControlButtonsVisibility(); | 194 owner_->UpdateControlButtonsVisibility(); |
195 } | 195 } |
196 | 196 |
197 void UpdateControlButtonsVisibility() override { | 197 void UpdateControlButtonsVisibility() override { |
198 owner_->UpdateControlButtonsVisibility(); | 198 owner_->UpdateControlButtonsVisibility(); |
199 } | 199 } |
200 | 200 |
201 void OnSlideChanged() override { | 201 void OnSlideChanged() override { |
202 if (owner_->slide_helper_) | 202 if (owner_->slide_helper_) |
203 owner_->slide_helper_->Update(); | 203 owner_->slide_helper_->Update(); |
204 } | 204 } |
205 | 205 |
206 private: | 206 private: |
207 ArcCustomNotificationView* const owner_; | 207 ArcNotificationContentView* const owner_; |
208 | 208 |
209 DISALLOW_COPY_AND_ASSIGN(ContentViewDelegate); | 209 DISALLOW_COPY_AND_ASSIGN(ContentViewDelegate); |
210 }; | 210 }; |
211 | 211 |
212 ArcCustomNotificationView::ControlButton::ControlButton( | 212 ArcNotificationContentView::ControlButton::ControlButton( |
213 ArcCustomNotificationView* owner) | 213 ArcNotificationContentView* owner) |
214 : message_center::PaddedButton(owner), owner_(owner) { | 214 : message_center::PaddedButton(owner), owner_(owner) { |
215 if (owner_->item_) { | 215 if (owner_->item_) { |
216 set_background(views::Background::CreateSolidBackground( | 216 set_background(views::Background::CreateSolidBackground( |
217 GetControlButtonBackgroundColor(owner_->item_->GetShownContents()))); | 217 GetControlButtonBackgroundColor(owner_->item_->GetShownContents()))); |
218 } else { | 218 } else { |
219 set_background(views::Background::CreateSolidBackground( | 219 set_background(views::Background::CreateSolidBackground( |
220 message_center::kControlButtonBackgroundColor)); | 220 message_center::kControlButtonBackgroundColor)); |
221 } | 221 } |
222 } | 222 } |
223 | 223 |
224 void ArcCustomNotificationView::ControlButton::OnFocus() { | 224 void ArcNotificationContentView::ControlButton::OnFocus() { |
225 message_center::PaddedButton::OnFocus(); | 225 message_center::PaddedButton::OnFocus(); |
226 owner_->UpdateControlButtonsVisibility(); | 226 owner_->UpdateControlButtonsVisibility(); |
227 } | 227 } |
228 | 228 |
229 void ArcCustomNotificationView::ControlButton::OnBlur() { | 229 void ArcNotificationContentView::ControlButton::OnBlur() { |
230 message_center::PaddedButton::OnBlur(); | 230 message_center::PaddedButton::OnBlur(); |
231 owner_->UpdateControlButtonsVisibility(); | 231 owner_->UpdateControlButtonsVisibility(); |
232 } | 232 } |
233 | 233 |
234 ArcCustomNotificationView::ArcCustomNotificationView(ArcNotificationItem* item) | 234 ArcNotificationContentView::ArcNotificationContentView( |
| 235 ArcNotificationItem* item) |
235 : item_(item), | 236 : item_(item), |
236 notification_key_(item->GetNotificationKey()), | 237 notification_key_(item->GetNotificationKey()), |
237 event_forwarder_(new EventForwarder(this)) { | 238 event_forwarder_(new EventForwarder(this)) { |
238 SetFocusBehavior(FocusBehavior::ALWAYS); | 239 SetFocusBehavior(FocusBehavior::ALWAYS); |
239 | 240 |
240 item_->IncrementWindowRefCount(); | 241 item_->IncrementWindowRefCount(); |
241 item_->AddObserver(this); | 242 item_->AddObserver(this); |
242 | 243 |
243 auto* surface_manager = ArcNotificationSurfaceManager::Get(); | 244 auto* surface_manager = ArcNotificationSurfaceManager::Get(); |
244 if (surface_manager) { | 245 if (surface_manager) { |
245 surface_manager->AddObserver(this); | 246 surface_manager->AddObserver(this); |
246 exo::NotificationSurface* surface = | 247 exo::NotificationSurface* surface = |
247 surface_manager->GetSurface(notification_key_); | 248 surface_manager->GetSurface(notification_key_); |
248 if (surface) | 249 if (surface) |
249 OnNotificationSurfaceAdded(surface); | 250 OnNotificationSurfaceAdded(surface); |
250 } | 251 } |
251 | 252 |
252 // Create a layer as an anchor to insert surface copy during a slide. | 253 // Create a layer as an anchor to insert surface copy during a slide. |
253 SetPaintToLayer(); | 254 SetPaintToLayer(); |
254 UpdatePreferredSize(); | 255 UpdatePreferredSize(); |
255 UpdateAccessibleName(); | 256 UpdateAccessibleName(); |
256 } | 257 } |
257 | 258 |
258 ArcCustomNotificationView::~ArcCustomNotificationView() { | 259 ArcNotificationContentView::~ArcNotificationContentView() { |
259 SetSurface(nullptr); | 260 SetSurface(nullptr); |
260 | 261 |
261 auto* surface_manager = ArcNotificationSurfaceManager::Get(); | 262 auto* surface_manager = ArcNotificationSurfaceManager::Get(); |
262 if (surface_manager) | 263 if (surface_manager) |
263 surface_manager->RemoveObserver(this); | 264 surface_manager->RemoveObserver(this); |
264 if (item_) { | 265 if (item_) { |
265 item_->RemoveObserver(this); | 266 item_->RemoveObserver(this); |
266 item_->DecrementWindowRefCount(); | 267 item_->DecrementWindowRefCount(); |
267 } | 268 } |
268 } | 269 } |
269 | 270 |
270 std::unique_ptr<ArcNotificationContentViewDelegate> | 271 std::unique_ptr<ArcNotificationContentViewDelegate> |
271 ArcCustomNotificationView::CreateContentViewDelegate() { | 272 ArcNotificationContentView::CreateContentViewDelegate() { |
272 return base::MakeUnique<ArcCustomNotificationView::ContentViewDelegate>(this); | 273 return base::MakeUnique<ArcNotificationContentView::ContentViewDelegate>( |
| 274 this); |
273 } | 275 } |
274 | 276 |
275 void ArcCustomNotificationView::CreateCloseButton() { | 277 void ArcNotificationContentView::CreateCloseButton() { |
276 DCHECK(control_buttons_view_); | 278 DCHECK(control_buttons_view_); |
277 DCHECK(item_); | 279 DCHECK(item_); |
278 | 280 |
279 close_button_ = base::MakeUnique<ControlButton>(this); | 281 close_button_ = base::MakeUnique<ControlButton>(this); |
280 close_button_->SetImage(views::CustomButton::STATE_NORMAL, | 282 close_button_->SetImage(views::CustomButton::STATE_NORMAL, |
281 message_center::GetCloseIcon()); | 283 message_center::GetCloseIcon()); |
282 close_button_->SetAccessibleName(l10n_util::GetStringUTF16( | 284 close_button_->SetAccessibleName(l10n_util::GetStringUTF16( |
283 IDS_MESSAGE_CENTER_CLOSE_NOTIFICATION_BUTTON_ACCESSIBLE_NAME)); | 285 IDS_MESSAGE_CENTER_CLOSE_NOTIFICATION_BUTTON_ACCESSIBLE_NAME)); |
284 close_button_->SetTooltipText(l10n_util::GetStringUTF16( | 286 close_button_->SetTooltipText(l10n_util::GetStringUTF16( |
285 IDS_MESSAGE_CENTER_CLOSE_NOTIFICATION_BUTTON_TOOLTIP)); | 287 IDS_MESSAGE_CENTER_CLOSE_NOTIFICATION_BUTTON_TOOLTIP)); |
286 close_button_->set_owned_by_client(); | 288 close_button_->set_owned_by_client(); |
287 control_buttons_view_->AddChildView(close_button_.get()); | 289 control_buttons_view_->AddChildView(close_button_.get()); |
288 } | 290 } |
289 | 291 |
290 void ArcCustomNotificationView::CreateSettingsButton() { | 292 void ArcNotificationContentView::CreateSettingsButton() { |
291 DCHECK(control_buttons_view_); | 293 DCHECK(control_buttons_view_); |
292 DCHECK(item_); | 294 DCHECK(item_); |
293 | 295 |
294 settings_button_ = new ControlButton(this); | 296 settings_button_ = new ControlButton(this); |
295 settings_button_->SetImage(views::CustomButton::STATE_NORMAL, | 297 settings_button_->SetImage(views::CustomButton::STATE_NORMAL, |
296 message_center::GetSettingsIcon()); | 298 message_center::GetSettingsIcon()); |
297 settings_button_->SetAccessibleName(l10n_util::GetStringUTF16( | 299 settings_button_->SetAccessibleName(l10n_util::GetStringUTF16( |
298 IDS_MESSAGE_NOTIFICATION_SETTINGS_BUTTON_ACCESSIBLE_NAME)); | 300 IDS_MESSAGE_NOTIFICATION_SETTINGS_BUTTON_ACCESSIBLE_NAME)); |
299 settings_button_->SetTooltipText(l10n_util::GetStringUTF16( | 301 settings_button_->SetTooltipText(l10n_util::GetStringUTF16( |
300 IDS_MESSAGE_NOTIFICATION_SETTINGS_BUTTON_ACCESSIBLE_NAME)); | 302 IDS_MESSAGE_NOTIFICATION_SETTINGS_BUTTON_ACCESSIBLE_NAME)); |
301 control_buttons_view_->AddChildView(settings_button_); | 303 control_buttons_view_->AddChildView(settings_button_); |
302 } | 304 } |
303 | 305 |
304 void ArcCustomNotificationView::MaybeCreateFloatingControlButtons() { | 306 void ArcNotificationContentView::MaybeCreateFloatingControlButtons() { |
305 // Floating close button is a transient child of |surface_| and also part | 307 // Floating close button is a transient child of |surface_| and also part |
306 // of the hosting widget's focus chain. It could only be created when both | 308 // of the hosting widget's focus chain. It could only be created when both |
307 // are present. Further, if we are being destroyed (|item_| is null), don't | 309 // are present. Further, if we are being destroyed (|item_| is null), don't |
308 // create the control buttons. | 310 // create the control buttons. |
309 if (!surface_ || !GetWidget() || !item_) | 311 if (!surface_ || !GetWidget() || !item_) |
310 return; | 312 return; |
311 | 313 |
312 // Creates the control_buttons_view_, which collects all control buttons into | 314 // Creates the control_buttons_view_, which collects all control buttons into |
313 // a horizontal box. | 315 // a horizontal box. |
314 control_buttons_view_ = new views::View(); | 316 control_buttons_view_ = new views::View(); |
(...skipping 15 matching lines...) Expand all Loading... |
330 floating_control_buttons_widget_->SetContentsView(control_buttons_view_); | 332 floating_control_buttons_widget_->SetContentsView(control_buttons_view_); |
331 | 333 |
332 // Put the close button into the focus chain. | 334 // Put the close button into the focus chain. |
333 floating_control_buttons_widget_->SetFocusTraversableParent( | 335 floating_control_buttons_widget_->SetFocusTraversableParent( |
334 GetWidget()->GetFocusTraversable()); | 336 GetWidget()->GetFocusTraversable()); |
335 floating_control_buttons_widget_->SetFocusTraversableParentView(this); | 337 floating_control_buttons_widget_->SetFocusTraversableParentView(this); |
336 | 338 |
337 Layout(); | 339 Layout(); |
338 } | 340 } |
339 | 341 |
340 void ArcCustomNotificationView::SetSurface(exo::NotificationSurface* surface) { | 342 void ArcNotificationContentView::SetSurface(exo::NotificationSurface* surface) { |
341 if (surface_ == surface) | 343 if (surface_ == surface) |
342 return; | 344 return; |
343 | 345 |
344 // Reset |floating_control_buttons_widget_| when |surface_| is changed. | 346 // Reset |floating_control_buttons_widget_| when |surface_| is changed. |
345 floating_control_buttons_widget_.reset(); | 347 floating_control_buttons_widget_.reset(); |
346 control_buttons_view_ = nullptr; | 348 control_buttons_view_ = nullptr; |
347 settings_button_ = nullptr; | 349 settings_button_ = nullptr; |
348 close_button_.reset(); | 350 close_button_.reset(); |
349 | 351 |
350 if (surface_ && surface_->window()) { | 352 if (surface_ && surface_->window()) { |
351 surface_->window()->RemoveObserver(this); | 353 surface_->window()->RemoveObserver(this); |
352 surface_->window()->RemovePreTargetHandler(event_forwarder_.get()); | 354 surface_->window()->RemovePreTargetHandler(event_forwarder_.get()); |
353 } | 355 } |
354 | 356 |
355 surface_ = surface; | 357 surface_ = surface; |
356 | 358 |
357 if (surface_ && surface_->window()) { | 359 if (surface_ && surface_->window()) { |
358 surface_->window()->AddObserver(this); | 360 surface_->window()->AddObserver(this); |
359 surface_->window()->AddPreTargetHandler(event_forwarder_.get()); | 361 surface_->window()->AddPreTargetHandler(event_forwarder_.get()); |
360 | 362 |
361 MaybeCreateFloatingControlButtons(); | 363 MaybeCreateFloatingControlButtons(); |
362 | 364 |
363 if (GetWidget()) | 365 if (GetWidget()) |
364 AttachSurface(); | 366 AttachSurface(); |
365 } | 367 } |
366 } | 368 } |
367 | 369 |
368 void ArcCustomNotificationView::UpdatePreferredSize() { | 370 void ArcNotificationContentView::UpdatePreferredSize() { |
369 gfx::Size preferred_size; | 371 gfx::Size preferred_size; |
370 if (surface_) | 372 if (surface_) |
371 preferred_size = surface_->GetSize(); | 373 preferred_size = surface_->GetSize(); |
372 else if (item_) | 374 else if (item_) |
373 preferred_size = item_->GetSnapshot().size(); | 375 preferred_size = item_->GetSnapshot().size(); |
374 | 376 |
375 if (preferred_size.IsEmpty()) | 377 if (preferred_size.IsEmpty()) |
376 return; | 378 return; |
377 | 379 |
378 if (preferred_size.width() != message_center::kNotificationWidth) { | 380 if (preferred_size.width() != message_center::kNotificationWidth) { |
379 const float scale = static_cast<float>(message_center::kNotificationWidth) / | 381 const float scale = static_cast<float>(message_center::kNotificationWidth) / |
380 preferred_size.width(); | 382 preferred_size.width(); |
381 preferred_size.SetSize(message_center::kNotificationWidth, | 383 preferred_size.SetSize(message_center::kNotificationWidth, |
382 preferred_size.height() * scale); | 384 preferred_size.height() * scale); |
383 } | 385 } |
384 | 386 |
385 SetPreferredSize(preferred_size); | 387 SetPreferredSize(preferred_size); |
386 } | 388 } |
387 | 389 |
388 void ArcCustomNotificationView::UpdateControlButtonsVisibility() { | 390 void ArcNotificationContentView::UpdateControlButtonsVisibility() { |
389 if (!surface_) | 391 if (!surface_) |
390 return; | 392 return; |
391 | 393 |
392 // TODO(edcourtney, yhanada): Creating the floating control widget here is not | 394 // TODO(edcourtney, yhanada): Creating the floating control widget here is not |
393 // correct. This function may be called during the destruction of | 395 // correct. This function may be called during the destruction of |
394 // |floating_control_buttons_widget_|. This can lead to memory corruption. | 396 // |floating_control_buttons_widget_|. This can lead to memory corruption. |
395 // Rather than creating it here, we should fix the behaviour of OnMouseExited | 397 // Rather than creating it here, we should fix the behaviour of OnMouseExited |
396 // and OnMouseEntered for ARC notifications in MessageCenterView. See | 398 // and OnMouseEntered for ARC notifications in MessageCenterView. See |
397 // crbug.com/714587 and crbug.com/709862. | 399 // crbug.com/714587 and crbug.com/709862. |
398 if (!floating_control_buttons_widget_) { | 400 if (!floating_control_buttons_widget_) { |
399 // This may update |floating_control_buttons_widget_|. | 401 // This may update |floating_control_buttons_widget_|. |
400 MaybeCreateFloatingControlButtons(); | 402 MaybeCreateFloatingControlButtons(); |
401 if (!floating_control_buttons_widget_) | 403 if (!floating_control_buttons_widget_) |
402 return; | 404 return; |
403 } | 405 } |
404 | 406 |
405 const bool target_visiblity = | 407 const bool target_visiblity = |
406 IsMouseHovered() || (close_button_ && close_button_->HasFocus()) || | 408 IsMouseHovered() || (close_button_ && close_button_->HasFocus()) || |
407 (settings_button_ && settings_button_->HasFocus()); | 409 (settings_button_ && settings_button_->HasFocus()); |
408 if (target_visiblity == floating_control_buttons_widget_->IsVisible()) | 410 if (target_visiblity == floating_control_buttons_widget_->IsVisible()) |
409 return; | 411 return; |
410 | 412 |
411 if (target_visiblity) | 413 if (target_visiblity) |
412 floating_control_buttons_widget_->Show(); | 414 floating_control_buttons_widget_->Show(); |
413 else | 415 else |
414 floating_control_buttons_widget_->Hide(); | 416 floating_control_buttons_widget_->Hide(); |
415 } | 417 } |
416 | 418 |
417 void ArcCustomNotificationView::UpdatePinnedState() { | 419 void ArcNotificationContentView::UpdatePinnedState() { |
418 if (!item_) | 420 if (!item_) |
419 return; | 421 return; |
420 | 422 |
421 if (item_->GetPinned() && close_button_) { | 423 if (item_->GetPinned() && close_button_) { |
422 control_buttons_view_->RemoveChildView(close_button_.get()); | 424 control_buttons_view_->RemoveChildView(close_button_.get()); |
423 close_button_.reset(); | 425 close_button_.reset(); |
424 Layout(); | 426 Layout(); |
425 } else if (!item_->GetPinned() && !close_button_) { | 427 } else if (!item_->GetPinned() && !close_button_) { |
426 CreateCloseButton(); | 428 CreateCloseButton(); |
427 Layout(); | 429 Layout(); |
428 } | 430 } |
429 } | 431 } |
430 | 432 |
431 void ArcCustomNotificationView::UpdateSnapshot() { | 433 void ArcNotificationContentView::UpdateSnapshot() { |
432 // Bail if we have a |surface_| because it controls the sizes and paints UI. | 434 // Bail if we have a |surface_| because it controls the sizes and paints UI. |
433 if (surface_) | 435 if (surface_) |
434 return; | 436 return; |
435 | 437 |
436 UpdatePreferredSize(); | 438 UpdatePreferredSize(); |
437 SchedulePaint(); | 439 SchedulePaint(); |
438 } | 440 } |
439 | 441 |
440 void ArcCustomNotificationView::AttachSurface() { | 442 void ArcNotificationContentView::AttachSurface() { |
441 if (!GetWidget()) | 443 if (!GetWidget()) |
442 return; | 444 return; |
443 | 445 |
444 UpdatePreferredSize(); | 446 UpdatePreferredSize(); |
445 Attach(surface_->window()); | 447 Attach(surface_->window()); |
446 | 448 |
447 // The texture for this window can be placed at subpixel position | 449 // The texture for this window can be placed at subpixel position |
448 // with fractional scale factor. Force to align it at the pixel | 450 // with fractional scale factor. Force to align it at the pixel |
449 // boundary here, and when layout is updated in Layout(). | 451 // boundary here, and when layout is updated in Layout(). |
450 ash::wm::SnapWindowToPixelBoundary(surface_->window()); | 452 ash::wm::SnapWindowToPixelBoundary(surface_->window()); |
451 | 453 |
452 // Creates slide helper after this view is added to its parent. | 454 // Creates slide helper after this view is added to its parent. |
453 slide_helper_.reset(new SlideHelper(this)); | 455 slide_helper_.reset(new SlideHelper(this)); |
454 | 456 |
455 // Invokes Update() in case surface is attached during a slide. | 457 // Invokes Update() in case surface is attached during a slide. |
456 slide_helper_->Update(); | 458 slide_helper_->Update(); |
457 | 459 |
458 // Updates pinned state to create or destroy the floating close button | 460 // Updates pinned state to create or destroy the floating close button |
459 // after |surface_| is attached to a widget. | 461 // after |surface_| is attached to a widget. |
460 if (item_) | 462 if (item_) |
461 UpdatePinnedState(); | 463 UpdatePinnedState(); |
462 } | 464 } |
463 | 465 |
464 void ArcCustomNotificationView::StartControlButtonsColorAnimation() { | 466 void ArcNotificationContentView::StartControlButtonsColorAnimation() { |
465 if (control_button_color_animation_) | 467 if (control_button_color_animation_) |
466 control_button_color_animation_->End(); | 468 control_button_color_animation_->End(); |
467 control_button_color_animation_.reset(new gfx::LinearAnimation(this)); | 469 control_button_color_animation_.reset(new gfx::LinearAnimation(this)); |
468 control_button_color_animation_->SetDuration(kBackgroundColorChangeDuration); | 470 control_button_color_animation_->SetDuration(kBackgroundColorChangeDuration); |
469 control_button_color_animation_->Start(); | 471 control_button_color_animation_->Start(); |
470 } | 472 } |
471 | 473 |
472 bool ArcCustomNotificationView::ShouldUpdateControlButtonsColor() const { | 474 bool ArcNotificationContentView::ShouldUpdateControlButtonsColor() const { |
473 // Don't update the control button color when we are about to be destroyed. | 475 // Don't update the control button color when we are about to be destroyed. |
474 if (!item_) | 476 if (!item_) |
475 return false; | 477 return false; |
476 | 478 |
477 if (settings_button_ && | 479 if (settings_button_ && |
478 settings_button_->background()->get_color() != | 480 settings_button_->background()->get_color() != |
479 GetControlButtonBackgroundColor(item_->GetShownContents())) | 481 GetControlButtonBackgroundColor(item_->GetShownContents())) |
480 return true; | 482 return true; |
481 if (close_button_ && | 483 if (close_button_ && |
482 close_button_->background()->get_color() != | 484 close_button_->background()->get_color() != |
483 GetControlButtonBackgroundColor(item_->GetShownContents())) | 485 GetControlButtonBackgroundColor(item_->GetShownContents())) |
484 return true; | 486 return true; |
485 return false; | 487 return false; |
486 } | 488 } |
487 | 489 |
488 void ArcCustomNotificationView::UpdateAccessibleName() { | 490 void ArcNotificationContentView::UpdateAccessibleName() { |
489 // Don't update the accessible name when we are about to be destroyed. | 491 // Don't update the accessible name when we are about to be destroyed. |
490 if (!item_) | 492 if (!item_) |
491 return; | 493 return; |
492 | 494 |
493 accessible_name_ = item_->GetAccessibleName(); | 495 accessible_name_ = item_->GetAccessibleName(); |
494 } | 496 } |
495 | 497 |
496 void ArcCustomNotificationView::ViewHierarchyChanged( | 498 void ArcNotificationContentView::ViewHierarchyChanged( |
497 const views::View::ViewHierarchyChangedDetails& details) { | 499 const views::View::ViewHierarchyChangedDetails& details) { |
498 views::Widget* widget = GetWidget(); | 500 views::Widget* widget = GetWidget(); |
499 | 501 |
500 if (!details.is_add) { | 502 if (!details.is_add) { |
501 // Resets slide helper when this view is removed from its parent. | 503 // Resets slide helper when this view is removed from its parent. |
502 slide_helper_.reset(); | 504 slide_helper_.reset(); |
503 | 505 |
504 // Bail if this view is no longer attached to a widget or native_view() has | 506 // Bail if this view is no longer attached to a widget or native_view() has |
505 // attached to a different widget. | 507 // attached to a different widget. |
506 if (!widget || (native_view() && | 508 if (!widget || |
507 views::Widget::GetTopLevelWidgetForNativeView( | 509 (native_view() && views::Widget::GetTopLevelWidgetForNativeView( |
508 native_view()) != widget)) { | 510 native_view()) != widget)) { |
509 return; | 511 return; |
510 } | 512 } |
511 } | 513 } |
512 | 514 |
513 views::NativeViewHost::ViewHierarchyChanged(details); | 515 views::NativeViewHost::ViewHierarchyChanged(details); |
514 | 516 |
515 if (!widget || !surface_ || !details.is_add) | 517 if (!widget || !surface_ || !details.is_add) |
516 return; | 518 return; |
517 | 519 |
518 AttachSurface(); | 520 AttachSurface(); |
519 } | 521 } |
520 | 522 |
521 void ArcCustomNotificationView::Layout() { | 523 void ArcNotificationContentView::Layout() { |
522 base::AutoReset<bool> auto_reset_in_layout(&in_layout_, true); | 524 base::AutoReset<bool> auto_reset_in_layout(&in_layout_, true); |
523 | 525 |
524 views::NativeViewHost::Layout(); | 526 views::NativeViewHost::Layout(); |
525 | 527 |
526 if (!surface_ || !GetWidget()) | 528 if (!surface_ || !GetWidget()) |
527 return; | 529 return; |
528 | 530 |
529 const gfx::Rect contents_bounds = GetContentsBounds(); | 531 const gfx::Rect contents_bounds = GetContentsBounds(); |
530 | 532 |
531 // Scale notification surface if necessary. | 533 // Scale notification surface if necessary. |
(...skipping 30 matching lines...) Expand all Loading... |
562 message_center::kControlButtonPadding); | 564 message_center::kControlButtonPadding); |
563 control_buttons_bounds.set_width(buttons_width); | 565 control_buttons_bounds.set_width(buttons_width); |
564 control_buttons_bounds.set_height(buttons_height); | 566 control_buttons_bounds.set_height(buttons_height); |
565 floating_control_buttons_widget_->SetBounds(control_buttons_bounds); | 567 floating_control_buttons_widget_->SetBounds(control_buttons_bounds); |
566 | 568 |
567 UpdateControlButtonsVisibility(); | 569 UpdateControlButtonsVisibility(); |
568 | 570 |
569 ash::wm::SnapWindowToPixelBoundary(surface_->window()); | 571 ash::wm::SnapWindowToPixelBoundary(surface_->window()); |
570 } | 572 } |
571 | 573 |
572 void ArcCustomNotificationView::OnPaint(gfx::Canvas* canvas) { | 574 void ArcNotificationContentView::OnPaint(gfx::Canvas* canvas) { |
573 views::NativeViewHost::OnPaint(canvas); | 575 views::NativeViewHost::OnPaint(canvas); |
574 | 576 |
575 // Bail if there is a |surface_| or no item or no snapshot image. | 577 // Bail if there is a |surface_| or no item or no snapshot image. |
576 if (surface_ || !item_ || item_->GetSnapshot().isNull()) | 578 if (surface_ || !item_ || item_->GetSnapshot().isNull()) |
577 return; | 579 return; |
578 const gfx::Rect contents_bounds = GetContentsBounds(); | 580 const gfx::Rect contents_bounds = GetContentsBounds(); |
579 canvas->DrawImageInt(item_->GetSnapshot(), 0, 0, item_->GetSnapshot().width(), | 581 canvas->DrawImageInt(item_->GetSnapshot(), 0, 0, item_->GetSnapshot().width(), |
580 item_->GetSnapshot().height(), contents_bounds.x(), | 582 item_->GetSnapshot().height(), contents_bounds.x(), |
581 contents_bounds.y(), contents_bounds.width(), | 583 contents_bounds.y(), contents_bounds.width(), |
582 contents_bounds.height(), false); | 584 contents_bounds.height(), false); |
583 } | 585 } |
584 | 586 |
585 void ArcCustomNotificationView::OnMouseEntered(const ui::MouseEvent&) { | 587 void ArcNotificationContentView::OnMouseEntered(const ui::MouseEvent&) { |
586 UpdateControlButtonsVisibility(); | 588 UpdateControlButtonsVisibility(); |
587 } | 589 } |
588 | 590 |
589 void ArcCustomNotificationView::OnMouseExited(const ui::MouseEvent&) { | 591 void ArcNotificationContentView::OnMouseExited(const ui::MouseEvent&) { |
590 UpdateControlButtonsVisibility(); | 592 UpdateControlButtonsVisibility(); |
591 } | 593 } |
592 | 594 |
593 void ArcCustomNotificationView::OnFocus() { | 595 void ArcNotificationContentView::OnFocus() { |
594 CHECK_EQ(ArcNotificationView::kViewClassName, parent()->GetClassName()); | 596 CHECK_EQ(ArcNotificationView::kViewClassName, parent()->GetClassName()); |
595 | 597 |
596 NativeViewHost::OnFocus(); | 598 NativeViewHost::OnFocus(); |
597 static_cast<ArcNotificationView*>(parent())->OnContentFocused(); | 599 static_cast<ArcNotificationView*>(parent())->OnContentFocused(); |
598 } | 600 } |
599 | 601 |
600 void ArcCustomNotificationView::OnBlur() { | 602 void ArcNotificationContentView::OnBlur() { |
601 if (!parent()) { | 603 if (!parent()) { |
602 // OnBlur may be called when this view is being removed. | 604 // OnBlur may be called when this view is being removed. |
603 return; | 605 return; |
604 } | 606 } |
605 | 607 |
606 CHECK_EQ(ArcNotificationView::kViewClassName, parent()->GetClassName()); | 608 CHECK_EQ(ArcNotificationView::kViewClassName, parent()->GetClassName()); |
607 | 609 |
608 NativeViewHost::OnBlur(); | 610 NativeViewHost::OnBlur(); |
609 static_cast<ArcNotificationView*>(parent())->OnContentBlured(); | 611 static_cast<ArcNotificationView*>(parent())->OnContentBlured(); |
610 } | 612 } |
611 | 613 |
612 void ArcCustomNotificationView::ActivateToast() { | 614 void ArcNotificationContentView::ActivateToast() { |
613 if (message_center::ToastContentsView::kViewClassName == | 615 if (message_center::ToastContentsView::kViewClassName == |
614 parent()->parent()->GetClassName()) { | 616 parent()->parent()->GetClassName()) { |
615 static_cast<message_center::ToastContentsView*>(parent()->parent()) | 617 static_cast<message_center::ToastContentsView*>(parent()->parent()) |
616 ->ActivateToast(); | 618 ->ActivateToast(); |
617 } | 619 } |
618 } | 620 } |
619 | 621 |
620 views::FocusTraversable* ArcCustomNotificationView::GetFocusTraversable() { | 622 views::FocusTraversable* ArcNotificationContentView::GetFocusTraversable() { |
621 if (floating_control_buttons_widget_) | 623 if (floating_control_buttons_widget_) |
622 return static_cast<views::internal::RootView*>( | 624 return static_cast<views::internal::RootView*>( |
623 floating_control_buttons_widget_->GetRootView()); | 625 floating_control_buttons_widget_->GetRootView()); |
624 return nullptr; | 626 return nullptr; |
625 } | 627 } |
626 | 628 |
627 bool ArcCustomNotificationView::HandleAccessibleAction( | 629 bool ArcNotificationContentView::HandleAccessibleAction( |
628 const ui::AXActionData& action_data) { | 630 const ui::AXActionData& action_data) { |
629 if (item_ && action_data.action == ui::AX_ACTION_DO_DEFAULT) { | 631 if (item_ && action_data.action == ui::AX_ACTION_DO_DEFAULT) { |
630 item_->ToggleExpansion(); | 632 item_->ToggleExpansion(); |
631 return true; | 633 return true; |
632 } | 634 } |
633 return false; | 635 return false; |
634 } | 636 } |
635 | 637 |
636 void ArcCustomNotificationView::GetAccessibleNodeData( | 638 void ArcNotificationContentView::GetAccessibleNodeData( |
637 ui::AXNodeData* node_data) { | 639 ui::AXNodeData* node_data) { |
638 node_data->role = ui::AX_ROLE_BUTTON; | 640 node_data->role = ui::AX_ROLE_BUTTON; |
639 node_data->SetName(accessible_name_); | 641 node_data->SetName(accessible_name_); |
640 } | 642 } |
641 | 643 |
642 void ArcCustomNotificationView::ButtonPressed(views::Button* sender, | 644 void ArcNotificationContentView::ButtonPressed(views::Button* sender, |
643 const ui::Event& event) { | 645 const ui::Event& event) { |
644 if (item_ && !item_->GetPinned() && sender == close_button_.get()) { | 646 if (item_ && !item_->GetPinned() && sender == close_button_.get()) { |
645 CHECK_EQ(ArcNotificationView::kViewClassName, parent()->GetClassName()); | 647 CHECK_EQ(ArcNotificationView::kViewClassName, parent()->GetClassName()); |
646 static_cast<ArcNotificationView*>(parent())->OnCloseButtonPressed(); | 648 static_cast<ArcNotificationView*>(parent())->OnCloseButtonPressed(); |
647 } | 649 } |
648 if (item_ && settings_button_ && sender == settings_button_) { | 650 if (item_ && settings_button_ && sender == settings_button_) { |
649 item_->OpenSettings(); | 651 item_->OpenSettings(); |
650 } | 652 } |
651 } | 653 } |
652 | 654 |
653 void ArcCustomNotificationView::OnWindowBoundsChanged( | 655 void ArcNotificationContentView::OnWindowBoundsChanged( |
654 aura::Window* window, | 656 aura::Window* window, |
655 const gfx::Rect& old_bounds, | 657 const gfx::Rect& old_bounds, |
656 const gfx::Rect& new_bounds) { | 658 const gfx::Rect& new_bounds) { |
657 if (in_layout_) | 659 if (in_layout_) |
658 return; | 660 return; |
659 | 661 |
660 UpdatePreferredSize(); | 662 UpdatePreferredSize(); |
661 Layout(); | 663 Layout(); |
662 } | 664 } |
663 | 665 |
664 void ArcCustomNotificationView::OnWindowDestroying(aura::Window* window) { | 666 void ArcNotificationContentView::OnWindowDestroying(aura::Window* window) { |
665 SetSurface(nullptr); | 667 SetSurface(nullptr); |
666 } | 668 } |
667 | 669 |
668 void ArcCustomNotificationView::OnItemDestroying() { | 670 void ArcNotificationContentView::OnItemDestroying() { |
669 item_->RemoveObserver(this); | 671 item_->RemoveObserver(this); |
670 item_ = nullptr; | 672 item_ = nullptr; |
671 | 673 |
672 // Reset |surface_| with |item_| since no one is observing the |surface_| | 674 // Reset |surface_| with |item_| since no one is observing the |surface_| |
673 // after |item_| is gone and this view should be removed soon. | 675 // after |item_| is gone and this view should be removed soon. |
674 SetSurface(nullptr); | 676 SetSurface(nullptr); |
675 } | 677 } |
676 | 678 |
677 void ArcCustomNotificationView::OnItemUpdated() { | 679 void ArcNotificationContentView::OnItemUpdated() { |
678 UpdateAccessibleName(); | 680 UpdateAccessibleName(); |
679 UpdatePinnedState(); | 681 UpdatePinnedState(); |
680 UpdateSnapshot(); | 682 UpdateSnapshot(); |
681 if (ShouldUpdateControlButtonsColor()) | 683 if (ShouldUpdateControlButtonsColor()) |
682 StartControlButtonsColorAnimation(); | 684 StartControlButtonsColorAnimation(); |
683 } | 685 } |
684 | 686 |
685 void ArcCustomNotificationView::OnNotificationSurfaceAdded( | 687 void ArcNotificationContentView::OnNotificationSurfaceAdded( |
686 exo::NotificationSurface* surface) { | 688 exo::NotificationSurface* surface) { |
687 if (surface->notification_id() != notification_key_) | 689 if (surface->notification_id() != notification_key_) |
688 return; | 690 return; |
689 | 691 |
690 SetSurface(surface); | 692 SetSurface(surface); |
691 } | 693 } |
692 | 694 |
693 void ArcCustomNotificationView::OnNotificationSurfaceRemoved( | 695 void ArcNotificationContentView::OnNotificationSurfaceRemoved( |
694 exo::NotificationSurface* surface) { | 696 exo::NotificationSurface* surface) { |
695 if (surface->notification_id() != notification_key_) | 697 if (surface->notification_id() != notification_key_) |
696 return; | 698 return; |
697 | 699 |
698 SetSurface(nullptr); | 700 SetSurface(nullptr); |
699 } | 701 } |
700 | 702 |
701 void ArcCustomNotificationView::AnimationEnded( | 703 void ArcNotificationContentView::AnimationEnded( |
702 const gfx::Animation* animation) { | 704 const gfx::Animation* animation) { |
703 DCHECK_EQ(animation, control_button_color_animation_.get()); | 705 DCHECK_EQ(animation, control_button_color_animation_.get()); |
704 control_button_color_animation_.reset(); | 706 control_button_color_animation_.reset(); |
705 } | 707 } |
706 | 708 |
707 void ArcCustomNotificationView::AnimationProgressed( | 709 void ArcNotificationContentView::AnimationProgressed( |
708 const gfx::Animation* animation) { | 710 const gfx::Animation* animation) { |
709 DCHECK_EQ(animation, control_button_color_animation_.get()); | 711 DCHECK_EQ(animation, control_button_color_animation_.get()); |
710 | 712 |
711 if (item_) { | 713 if (item_) { |
712 const SkColor target = | 714 const SkColor target = |
713 GetControlButtonBackgroundColor(item_->GetShownContents()); | 715 GetControlButtonBackgroundColor(item_->GetShownContents()); |
714 const SkColor start = | 716 const SkColor start = |
715 target == message_center::kControlButtonBackgroundColor | 717 target == message_center::kControlButtonBackgroundColor |
716 ? SK_ColorTRANSPARENT | 718 ? SK_ColorTRANSPARENT |
717 : message_center::kControlButtonBackgroundColor; | 719 : message_center::kControlButtonBackgroundColor; |
718 const SkColor current_color = gfx::Tween::ColorValueBetween( | 720 const SkColor current_color = gfx::Tween::ColorValueBetween( |
719 animation->GetCurrentValue(), start, target); | 721 animation->GetCurrentValue(), start, target); |
720 if (settings_button_) { | 722 if (settings_button_) { |
721 settings_button_->set_background( | 723 settings_button_->set_background( |
722 views::Background::CreateSolidBackground(current_color)); | 724 views::Background::CreateSolidBackground(current_color)); |
723 settings_button_->SchedulePaint(); | 725 settings_button_->SchedulePaint(); |
724 } | 726 } |
725 if (close_button_) { | 727 if (close_button_) { |
726 close_button_->set_background( | 728 close_button_->set_background( |
727 views::Background::CreateSolidBackground(current_color)); | 729 views::Background::CreateSolidBackground(current_color)); |
728 close_button_->SchedulePaint(); | 730 close_button_->SchedulePaint(); |
729 } | 731 } |
730 } | 732 } |
731 } | 733 } |
732 | 734 |
733 } // namespace arc | 735 } // namespace arc |
OLD | NEW |