OLD | NEW |
---|---|
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 "ash/system/tray/tray_background_view.h" | 5 #include "ash/system/tray/tray_background_view.h" |
6 | 6 |
7 #include "ash/ash_switches.h" | 7 #include "ash/ash_switches.h" |
8 #include "ash/root_window_controller.h" | 8 #include "ash/root_window_controller.h" |
9 #include "ash/screen_util.h" | 9 #include "ash/screen_util.h" |
10 #include "ash/shelf/shelf_layout_manager.h" | 10 #include "ash/shelf/shelf_layout_manager.h" |
11 #include "ash/shelf/shelf_widget.h" | 11 #include "ash/shelf/shelf_widget.h" |
12 #include "ash/shell.h" | 12 #include "ash/shell.h" |
13 #include "ash/shell_window_ids.h" | 13 #include "ash/shell_window_ids.h" |
14 #include "ash/system/status_area_widget.h" | 14 #include "ash/system/status_area_widget.h" |
15 #include "ash/system/status_area_widget_delegate.h" | 15 #include "ash/system/status_area_widget_delegate.h" |
16 #include "ash/system/tray/system_tray.h" | 16 #include "ash/system/tray/system_tray.h" |
17 #include "ash/system/tray/tray_constants.h" | 17 #include "ash/system/tray/tray_constants.h" |
18 #include "ash/system/tray/tray_event_filter.h" | 18 #include "ash/system/tray/tray_event_filter.h" |
19 #include "ash/wm/window_animations.h" | 19 #include "ash/wm/window_animations.h" |
20 #include "grit/ash_resources.h" | 20 #include "grit/ash_resources.h" |
21 #include "ui/accessibility/ax_view_state.h" | 21 #include "ui/accessibility/ax_view_state.h" |
22 #include "ui/aura/window.h" | 22 #include "ui/aura/window.h" |
23 #include "ui/aura/window_event_dispatcher.h" | 23 #include "ui/aura/window_event_dispatcher.h" |
24 #include "ui/base/resource/resource_bundle.h" | 24 #include "ui/base/resource/resource_bundle.h" |
25 #include "ui/compositor/layer.h" | |
26 #include "ui/compositor/layer_animation_element.h" | |
27 #include "ui/compositor/scoped_layer_animation_settings.h" | |
28 #include "ui/gfx/animation/tween.h" | |
25 #include "ui/gfx/canvas.h" | 29 #include "ui/gfx/canvas.h" |
26 #include "ui/gfx/image/image_skia.h" | 30 #include "ui/gfx/image/image_skia.h" |
27 #include "ui/gfx/image/image_skia_operations.h" | 31 #include "ui/gfx/image/image_skia_operations.h" |
28 #include "ui/gfx/rect.h" | 32 #include "ui/gfx/rect.h" |
29 #include "ui/gfx/screen.h" | 33 #include "ui/gfx/screen.h" |
30 #include "ui/gfx/skia_util.h" | 34 #include "ui/gfx/skia_util.h" |
35 #include "ui/gfx/transform.h" | |
31 #include "ui/views/background.h" | 36 #include "ui/views/background.h" |
32 #include "ui/views/layout/box_layout.h" | 37 #include "ui/views/layout/box_layout.h" |
33 | 38 |
34 namespace { | 39 namespace { |
35 | 40 |
36 const int kTrayBackgroundAlpha = 100; | 41 const int kTrayBackgroundAlpha = 100; |
37 const int kTrayBackgroundHoverAlpha = 150; | 42 const int kTrayBackgroundHoverAlpha = 150; |
38 const SkColor kTrayBackgroundPressedColor = SkColorSetRGB(66, 129, 244); | 43 const SkColor kTrayBackgroundPressedColor = SkColorSetRGB(66, 129, 244); |
39 | 44 |
40 const int kAnimationDurationForPopupMS = 200; | 45 const int kAnimationDurationForPopupMs = 200; |
46 | |
47 // Duration of opacity animation for visibility changes. | |
48 const int kAnimationDurationForVisibilityMs = 250; | |
49 | |
50 // When becoming visible delay the animation so that StatusAreaWidgetDelegate | |
51 // can animate sibling views out of the position to be occuped by the | |
52 // TrayBackgroundView. | |
53 const int kShowAnimationDelayMs = 100; | |
41 | 54 |
42 } // namespace | 55 } // namespace |
43 | 56 |
44 using views::TrayBubbleView; | 57 using views::TrayBubbleView; |
45 | 58 |
46 namespace ash { | 59 namespace ash { |
47 | 60 |
48 // static | 61 // static |
49 const char TrayBackgroundView::kViewClassName[] = "tray/TrayBackgroundView"; | 62 const char TrayBackgroundView::kViewClassName[] = "tray/TrayBackgroundView"; |
50 | 63 |
(...skipping 249 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
300 | 313 |
301 // Initially we want to paint the background, but without the hover effect. | 314 // Initially we want to paint the background, but without the hover effect. |
302 hide_background_animator_.SetPaintsBackground( | 315 hide_background_animator_.SetPaintsBackground( |
303 true, BACKGROUND_CHANGE_IMMEDIATE); | 316 true, BACKGROUND_CHANGE_IMMEDIATE); |
304 hover_background_animator_.SetPaintsBackground( | 317 hover_background_animator_.SetPaintsBackground( |
305 false, BACKGROUND_CHANGE_IMMEDIATE); | 318 false, BACKGROUND_CHANGE_IMMEDIATE); |
306 | 319 |
307 tray_container_ = new TrayContainer(shelf_alignment_); | 320 tray_container_ = new TrayContainer(shelf_alignment_); |
308 SetContents(tray_container_); | 321 SetContents(tray_container_); |
309 tray_event_filter_.reset(new TrayEventFilter); | 322 tray_event_filter_.reset(new TrayEventFilter); |
323 | |
324 SetPaintToLayer(true); | |
325 SetFillsBoundsOpaquely(false); | |
310 } | 326 } |
311 | 327 |
312 TrayBackgroundView::~TrayBackgroundView() { | 328 TrayBackgroundView::~TrayBackgroundView() { |
313 if (GetWidget()) | 329 if (GetWidget()) |
314 GetWidget()->RemoveObserver(widget_observer_.get()); | 330 GetWidget()->RemoveObserver(widget_observer_.get()); |
315 } | 331 } |
316 | 332 |
317 void TrayBackgroundView::Initialize() { | 333 void TrayBackgroundView::Initialize() { |
318 GetWidget()->AddObserver(widget_observer_.get()); | 334 GetWidget()->AddObserver(widget_observer_.get()); |
319 SetTrayBorder(); | 335 SetTrayBorder(); |
320 } | 336 } |
321 | 337 |
338 void TrayBackgroundView::SetVisible(bool visible) { | |
339 if (visible == layer()->GetTargetVisibility()) | |
340 return; | |
341 | |
342 if (visible) { | |
343 // The alignment of the shelf can change while the TrayBackgroundView is | |
344 // hidden. Reset the offscreen transform so that the animation to becoming | |
345 // visible reflects the current layout. | |
346 HideTransformation(); | |
347 // SetVisible(false) is defered until the animation for hiding is done. | |
348 // Otherwise the view is immediately hidden and the animation does not | |
349 // render. | |
350 views::View::SetVisible(visible); | |
351 } | |
352 | |
353 ui::ScopedLayerAnimationSettings animation(layer()->GetAnimator()); | |
354 animation.SetTransitionDuration(base::TimeDelta::FromMilliseconds( | |
355 kAnimationDurationForVisibilityMs)); | |
356 animation.SetPreemptionStrategy( | |
357 ui::LayerAnimator::IMMEDIATELY_ANIMATE_TO_NEW_TARGET); | |
358 | |
359 if (visible) { | |
360 animation.SetTweenType(gfx::Tween::EASE_OUT); | |
361 // Show is delayed so as to allow time for other children of | |
362 // StatusAreaWidget to begin animating to their new positions. | |
363 layer()->GetAnimator()->SchedulePauseForProperties( | |
364 base::TimeDelta::FromMilliseconds(kShowAnimationDelayMs), | |
365 ui::LayerAnimationElement::OPACITY | | |
366 ui::LayerAnimationElement::TRANSFORM); | |
367 layer()->SetOpacity(1.0f); | |
368 gfx::Transform transform; | |
369 transform.Translate(0.0f, 0.0f); | |
370 layer()->SetTransform(transform); | |
371 // If SetVisible(true) is called during an animation to not visible, then | |
372 // replacing that animation with the one to become visible ends the original | |
373 // animation. This could result to calls to views::View::SetVisible(false) | |
374 // after setting it to true. This will set the layer to not visibible, so it | |
375 // must be turned on again here. | |
376 layer()->SetVisible(true); | |
flackr
2014/05/16 18:07:17
This seems like a fail-safe for when we call views
jonross
2014/05/16 19:11:38
Done.
| |
377 } else { | |
378 // Listen only to the hide animation. As we cannot turn off visibility | |
379 // until the animation is over. | |
380 animation.AddObserver(this); | |
381 animation.SetTweenType(gfx::Tween::EASE_IN); | |
382 layer()->SetOpacity(0.0f); | |
383 layer()->SetVisible(false); | |
384 HideTransformation(); | |
385 } | |
386 } | |
387 | |
322 const char* TrayBackgroundView::GetClassName() const { | 388 const char* TrayBackgroundView::GetClassName() const { |
323 return kViewClassName; | 389 return kViewClassName; |
324 } | 390 } |
325 | 391 |
326 void TrayBackgroundView::OnMouseEntered(const ui::MouseEvent& event) { | 392 void TrayBackgroundView::OnMouseEntered(const ui::MouseEvent& event) { |
327 hovered_ = true; | 393 hovered_ = true; |
328 } | 394 } |
329 | 395 |
330 void TrayBackgroundView::OnMouseExited(const ui::MouseEvent& event) { | 396 void TrayBackgroundView::OnMouseExited(const ui::MouseEvent& event) { |
331 hovered_ = false; | 397 hovered_ = false; |
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
413 top_edge = 0; | 479 top_edge = 0; |
414 left_edge = ShelfLayoutManager::kShelfItemInset; | 480 left_edge = ShelfLayoutManager::kShelfItemInset; |
415 bottom_edge = on_edge ? kPaddingFromEdgeOfShelf : 0; | 481 bottom_edge = on_edge ? kPaddingFromEdgeOfShelf : 0; |
416 right_edge = kShelfSize - | 482 right_edge = kShelfSize - |
417 ShelfLayoutManager::kShelfItemInset - kShelfItemHeight; | 483 ShelfLayoutManager::kShelfItemInset - kShelfItemHeight; |
418 } | 484 } |
419 SetBorder(views::Border::CreateEmptyBorder( | 485 SetBorder(views::Border::CreateEmptyBorder( |
420 top_edge, left_edge, bottom_edge, right_edge)); | 486 top_edge, left_edge, bottom_edge, right_edge)); |
421 } | 487 } |
422 | 488 |
489 void TrayBackgroundView::OnImplicitAnimationsCompleted() { | |
490 // If there is another animation in the queue, the reverse animation was | |
491 // triggered before the completion of animating to invisible. Do not turn off | |
492 // the visibility so that the next animation may render. The value of | |
493 // layer()->GetTargetVisibility() can be incorrect if the hide animation was | |
494 // aborted to schedule an animation to become visible. As the new animation | |
495 // is not yet added to the queue. crbug.com/374236 | |
496 if(layer()->GetAnimator()->is_animating() || | |
497 layer()->GetTargetVisibility()) | |
498 return; | |
499 views::View::SetVisible(false); | |
500 } | |
501 | |
502 void TrayBackgroundView::HideTransformation() { | |
503 gfx::Transform transform; | |
504 if (shelf_alignment_ == SHELF_ALIGNMENT_BOTTOM || | |
505 shelf_alignment_ == SHELF_ALIGNMENT_TOP) | |
506 transform.Translate(width(), 0.0f); | |
507 else | |
508 transform.Translate(0.0f, height()); | |
509 layer()->SetTransform(transform); | |
510 } | |
511 | |
423 void TrayBackgroundView::InitializeBubbleAnimations( | 512 void TrayBackgroundView::InitializeBubbleAnimations( |
424 views::Widget* bubble_widget) { | 513 views::Widget* bubble_widget) { |
425 wm::SetWindowVisibilityAnimationType( | 514 wm::SetWindowVisibilityAnimationType( |
426 bubble_widget->GetNativeWindow(), | 515 bubble_widget->GetNativeWindow(), |
427 wm::WINDOW_VISIBILITY_ANIMATION_TYPE_FADE); | 516 wm::WINDOW_VISIBILITY_ANIMATION_TYPE_FADE); |
428 wm::SetWindowVisibilityAnimationTransition( | 517 wm::SetWindowVisibilityAnimationTransition( |
429 bubble_widget->GetNativeWindow(), | 518 bubble_widget->GetNativeWindow(), |
430 wm::ANIMATE_HIDE); | 519 wm::ANIMATE_HIDE); |
431 wm::SetWindowVisibilityAnimationDuration( | 520 wm::SetWindowVisibilityAnimationDuration( |
432 bubble_widget->GetNativeWindow(), | 521 bubble_widget->GetNativeWindow(), |
433 base::TimeDelta::FromMilliseconds(kAnimationDurationForPopupMS)); | 522 base::TimeDelta::FromMilliseconds(kAnimationDurationForPopupMs)); |
434 } | 523 } |
435 | 524 |
436 aura::Window* TrayBackgroundView::GetBubbleWindowContainer() const { | 525 aura::Window* TrayBackgroundView::GetBubbleWindowContainer() const { |
437 return ash::Shell::GetContainer( | 526 return ash::Shell::GetContainer( |
438 tray_container()->GetWidget()->GetNativeWindow()->GetRootWindow(), | 527 tray_container()->GetWidget()->GetNativeWindow()->GetRootWindow(), |
439 ash::kShellWindowId_SettingBubbleContainer); | 528 ash::kShellWindowId_SettingBubbleContainer); |
440 } | 529 } |
441 | 530 |
442 gfx::Rect TrayBackgroundView::GetBubbleAnchorRect( | 531 gfx::Rect TrayBackgroundView::GetBubbleAnchorRect( |
443 views::Widget* anchor_widget, | 532 views::Widget* anchor_widget, |
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
519 background_->set_alpha(kTrayBackgroundAlpha); | 608 background_->set_alpha(kTrayBackgroundAlpha); |
520 SchedulePaint(); | 609 SchedulePaint(); |
521 } | 610 } |
522 | 611 |
523 void TrayBackgroundView::UpdateBubbleViewArrow( | 612 void TrayBackgroundView::UpdateBubbleViewArrow( |
524 views::TrayBubbleView* bubble_view) { | 613 views::TrayBubbleView* bubble_view) { |
525 // Nothing to do here. | 614 // Nothing to do here. |
526 } | 615 } |
527 | 616 |
528 } // namespace ash | 617 } // namespace ash |
OLD | NEW |