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

Side by Side Diff: ash/system/tray/tray_background_view.cc

Issue 251193004: Animate the OverviewButtonTray (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 6 years, 7 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
OLDNEW
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;
41 46
47 // Animation constant based on visual design. During of opacity animation
flackr 2014/05/08 17:09:49 Did you mean duration of opacity ...? nit: "Anima
jonross 2014/05/08 17:24:25 Done.
48 // for visibility changes.
49 const int kAnimationDurationForVisibility = 250;
flackr 2014/05/08 17:09:49 nit: This should have units in the name, i.e. kAni
jonross 2014/05/08 17:24:25 Done.
50
51 // Animation constant based on visual design. When becoming visible delay
52 // the animation so that StatusAreaWidgetDelegate can animate sibling views
53 // out of the position to be occuped by the TrayBackgroundView.
54 const int kShowAnimationDelay = 100;
flackr 2014/05/08 17:09:49 Ditto.
jonross 2014/05/08 17:24:25 Done.
55
42 } // namespace 56 } // namespace
43 57
44 using views::TrayBubbleView; 58 using views::TrayBubbleView;
45 59
46 namespace ash { 60 namespace ash {
47 61
48 // static 62 // static
49 const char TrayBackgroundView::kViewClassName[] = "tray/TrayBackgroundView"; 63 const char TrayBackgroundView::kViewClassName[] = "tray/TrayBackgroundView";
50 64
51 // Used to track when the anchor widget changes position on screen so that the 65 // Used to track when the anchor widget changes position on screen so that the
(...skipping 248 matching lines...) Expand 10 before | Expand all | Expand 10 after
300 314
301 // Initially we want to paint the background, but without the hover effect. 315 // Initially we want to paint the background, but without the hover effect.
302 hide_background_animator_.SetPaintsBackground( 316 hide_background_animator_.SetPaintsBackground(
303 true, BACKGROUND_CHANGE_IMMEDIATE); 317 true, BACKGROUND_CHANGE_IMMEDIATE);
304 hover_background_animator_.SetPaintsBackground( 318 hover_background_animator_.SetPaintsBackground(
305 false, BACKGROUND_CHANGE_IMMEDIATE); 319 false, BACKGROUND_CHANGE_IMMEDIATE);
306 320
307 tray_container_ = new TrayContainer(shelf_alignment_); 321 tray_container_ = new TrayContainer(shelf_alignment_);
308 SetContents(tray_container_); 322 SetContents(tray_container_);
309 tray_event_filter_.reset(new TrayEventFilter); 323 tray_event_filter_.reset(new TrayEventFilter);
324
325 SetPaintToLayer(true);
326 SetFillsBoundsOpaquely(false);
310 } 327 }
311 328
312 TrayBackgroundView::~TrayBackgroundView() { 329 TrayBackgroundView::~TrayBackgroundView() {
313 if (GetWidget()) 330 if (GetWidget())
314 GetWidget()->RemoveObserver(widget_observer_.get()); 331 GetWidget()->RemoveObserver(widget_observer_.get());
315 } 332 }
316 333
317 void TrayBackgroundView::Initialize() { 334 void TrayBackgroundView::Initialize() {
318 GetWidget()->AddObserver(widget_observer_.get()); 335 GetWidget()->AddObserver(widget_observer_.get());
319 SetTrayBorder(); 336 SetTrayBorder();
320 } 337 }
321 338
339 void TrayBackgroundView::SetVisible(bool visible) {
340 if (visible == this->visible())
341 return;
342
343 if (visible) {
344 // A translation transform was applied when becoming hidden. However the
345 // alignment of the shelf can change. Reset the offscreen transform so that
346 // the animation to becoming visible reflects the changed layout.
347 HideTransformation();
348 // SetVisible(false) is defered until the animation for hiding is done.
349 // Otherwise the view is immediately hidden and the animation does not
350 // render.
351 views::View::SetVisible(visible);
352 }
353
354 layer()->GetAnimator()->StopAnimating();
355 ui::ScopedLayerAnimationSettings animation(layer()->GetAnimator());
356 animation.SetTransitionDuration(base::TimeDelta::FromMilliseconds(
357 kAnimationDurationForVisibility));
358 animation.SetPreemptionStrategy(
359 ui::LayerAnimator::IMMEDIATELY_ANIMATE_TO_NEW_TARGET);
360
361 if (visible) {
362 animation.SetTweenType(gfx::Tween::EASE_OUT);
363 // Show is delayed so as to allow time for other children of
364 // StatusAreaWidget to begin animating to their new positions.
365 layer()->GetAnimator()->SchedulePauseForProperties(
366 base::TimeDelta::FromMilliseconds(kShowAnimationDelay),
367 ui::LayerAnimationElement::OPACITY |
368 ui::LayerAnimationElement::TRANSFORM);
369 layer()->SetOpacity(1.0f);
370 gfx::Transform transform;
371 transform.Translate(0.0f, 0.0f);
372 layer()->SetTransform(transform);
373 } else {
374 // Listen only to the hide animation. As we cannot turn off visibility
375 // until the animation is over.
376 animation.AddObserver(this);
377 animation.SetTweenType(gfx::Tween::EASE_IN);
378 layer()->SetOpacity(0.0f);
379 layer()->SetVisible(false);
380 HideTransformation();
381 }
382 }
383
322 const char* TrayBackgroundView::GetClassName() const { 384 const char* TrayBackgroundView::GetClassName() const {
323 return kViewClassName; 385 return kViewClassName;
324 } 386 }
325 387
326 void TrayBackgroundView::OnMouseEntered(const ui::MouseEvent& event) { 388 void TrayBackgroundView::OnMouseEntered(const ui::MouseEvent& event) {
327 hovered_ = true; 389 hovered_ = true;
328 } 390 }
329 391
330 void TrayBackgroundView::OnMouseExited(const ui::MouseEvent& event) { 392 void TrayBackgroundView::OnMouseExited(const ui::MouseEvent& event) {
331 hovered_ = false; 393 hovered_ = false;
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after
413 top_edge = 0; 475 top_edge = 0;
414 left_edge = ShelfLayoutManager::kShelfItemInset; 476 left_edge = ShelfLayoutManager::kShelfItemInset;
415 bottom_edge = on_edge ? kPaddingFromEdgeOfShelf : 0; 477 bottom_edge = on_edge ? kPaddingFromEdgeOfShelf : 0;
416 right_edge = kShelfSize - 478 right_edge = kShelfSize -
417 ShelfLayoutManager::kShelfItemInset - kShelfItemHeight; 479 ShelfLayoutManager::kShelfItemInset - kShelfItemHeight;
418 } 480 }
419 SetBorder(views::Border::CreateEmptyBorder( 481 SetBorder(views::Border::CreateEmptyBorder(
420 top_edge, left_edge, bottom_edge, right_edge)); 482 top_edge, left_edge, bottom_edge, right_edge));
421 } 483 }
422 484
485 void TrayBackgroundView::OnImplicitAnimationsCompleted() {
486 views::View::SetVisible(false);
487 }
488
489 void TrayBackgroundView::HideTransformation() {
490 gfx::Transform transform;
491 if (shelf_alignment_ == SHELF_ALIGNMENT_BOTTOM ||
492 shelf_alignment_ == SHELF_ALIGNMENT_TOP)
493 transform.Translate(width(), 0.0f);
494 else
495 transform.Translate(0.0f, height());
496 layer()->SetTransform(transform);
497 }
498
423 void TrayBackgroundView::InitializeBubbleAnimations( 499 void TrayBackgroundView::InitializeBubbleAnimations(
424 views::Widget* bubble_widget) { 500 views::Widget* bubble_widget) {
425 wm::SetWindowVisibilityAnimationType( 501 wm::SetWindowVisibilityAnimationType(
426 bubble_widget->GetNativeWindow(), 502 bubble_widget->GetNativeWindow(),
427 wm::WINDOW_VISIBILITY_ANIMATION_TYPE_FADE); 503 wm::WINDOW_VISIBILITY_ANIMATION_TYPE_FADE);
428 wm::SetWindowVisibilityAnimationTransition( 504 wm::SetWindowVisibilityAnimationTransition(
429 bubble_widget->GetNativeWindow(), 505 bubble_widget->GetNativeWindow(),
430 wm::ANIMATE_HIDE); 506 wm::ANIMATE_HIDE);
431 wm::SetWindowVisibilityAnimationDuration( 507 wm::SetWindowVisibilityAnimationDuration(
432 bubble_widget->GetNativeWindow(), 508 bubble_widget->GetNativeWindow(),
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after
519 background_->set_alpha(kTrayBackgroundAlpha); 595 background_->set_alpha(kTrayBackgroundAlpha);
520 SchedulePaint(); 596 SchedulePaint();
521 } 597 }
522 598
523 void TrayBackgroundView::UpdateBubbleViewArrow( 599 void TrayBackgroundView::UpdateBubbleViewArrow(
524 views::TrayBubbleView* bubble_view) { 600 views::TrayBubbleView* bubble_view) {
525 // Nothing to do here. 601 // Nothing to do here.
526 } 602 }
527 603
528 } // namespace ash 604 } // namespace ash
OLDNEW
« ash/system/status_area_widget_delegate.cc ('K') | « ash/system/tray/tray_background_view.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698