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

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;
46 const int kAnimationDurationForVisibility = 250;
47 const int kShowAnimationDelay = 100;
flackr 2014/05/07 21:32:26 It might be worth briefly describing these paramet
jonross 2014/05/08 16:44:17 Done.
41 48
42 } // namespace 49 } // namespace
43 50
44 using views::TrayBubbleView; 51 using views::TrayBubbleView;
45 52
46 namespace ash { 53 namespace ash {
47 54
48 // static 55 // static
49 const char TrayBackgroundView::kViewClassName[] = "tray/TrayBackgroundView"; 56 const char TrayBackgroundView::kViewClassName[] = "tray/TrayBackgroundView";
50 57
(...skipping 249 matching lines...) Expand 10 before | Expand all | Expand 10 after
300 307
301 // Initially we want to paint the background, but without the hover effect. 308 // Initially we want to paint the background, but without the hover effect.
302 hide_background_animator_.SetPaintsBackground( 309 hide_background_animator_.SetPaintsBackground(
303 true, BACKGROUND_CHANGE_IMMEDIATE); 310 true, BACKGROUND_CHANGE_IMMEDIATE);
304 hover_background_animator_.SetPaintsBackground( 311 hover_background_animator_.SetPaintsBackground(
305 false, BACKGROUND_CHANGE_IMMEDIATE); 312 false, BACKGROUND_CHANGE_IMMEDIATE);
306 313
307 tray_container_ = new TrayContainer(shelf_alignment_); 314 tray_container_ = new TrayContainer(shelf_alignment_);
308 SetContents(tray_container_); 315 SetContents(tray_container_);
309 tray_event_filter_.reset(new TrayEventFilter); 316 tray_event_filter_.reset(new TrayEventFilter);
317
318 SetPaintToLayer(true);
319 SetFillsBoundsOpaquely(false);
310 } 320 }
311 321
312 TrayBackgroundView::~TrayBackgroundView() { 322 TrayBackgroundView::~TrayBackgroundView() {
313 if (GetWidget()) 323 if (GetWidget())
314 GetWidget()->RemoveObserver(widget_observer_.get()); 324 GetWidget()->RemoveObserver(widget_observer_.get());
315 } 325 }
316 326
317 void TrayBackgroundView::Initialize() { 327 void TrayBackgroundView::Initialize() {
318 GetWidget()->AddObserver(widget_observer_.get()); 328 GetWidget()->AddObserver(widget_observer_.get());
319 SetTrayBorder(); 329 SetTrayBorder();
320 } 330 }
321 331
332 void TrayBackgroundView::SetVisible(bool visible) {
333 if (visible == this->visible())
334 return;
335
336 if (visible) {
337 // A translation transform was applied when becoming hidden. However the
338 // alignment of the shelf can change. Reset the offscreen transform so that
339 // the animation to becoming visible reflects the changed layout.
340 HideTransformation();
341 // SetVisible(false) is defered until the animation for hiding is done.
342 // Otherwise the view is immediately hidden and the animation does not
343 // render.
344 views::View::SetVisible(visible);
345 }
346
347 layer()->GetAnimator()->StopAnimating();
348 ui::ScopedLayerAnimationSettings animation(layer()->GetAnimator());
349 animation.SetTransitionDuration(base::TimeDelta::FromMilliseconds(
350 kAnimationDurationForVisibility));
351 animation.SetPreemptionStrategy(
352 ui::LayerAnimator::IMMEDIATELY_ANIMATE_TO_NEW_TARGET);
353
354 if (visible) {
355 animation.SetTweenType(gfx::Tween::EASE_OUT);
356 // Show is delayed so as to allow time for other children of
357 // StatusAreaWidget to begin animating to their new positions.
358 layer()->GetAnimator()->SchedulePauseForProperties(
359 base::TimeDelta::FromMilliseconds(kShowAnimationDelay),
360 ui::LayerAnimationElement::OPACITY |
361 ui::LayerAnimationElement::TRANSFORM);
362 layer()->SetOpacity(1.0f);
363 gfx::Transform transform;
364 transform.Translate(0.0f, 0.0f);
365 layer()->SetTransform(transform);
366 } else {
367 // Listen only to the hide animation. As we cannot turn off visibility
368 // until the animation is over.
369 animation.AddObserver(this);
370 animation.SetTweenType(gfx::Tween::EASE_IN);
371 layer()->SetOpacity(0.0f);
372 layer()->SetVisible(false);
373 HideTransformation();
374 }
375 }
376
322 const char* TrayBackgroundView::GetClassName() const { 377 const char* TrayBackgroundView::GetClassName() const {
323 return kViewClassName; 378 return kViewClassName;
324 } 379 }
325 380
326 void TrayBackgroundView::OnMouseEntered(const ui::MouseEvent& event) { 381 void TrayBackgroundView::OnMouseEntered(const ui::MouseEvent& event) {
327 hovered_ = true; 382 hovered_ = true;
328 } 383 }
329 384
330 void TrayBackgroundView::OnMouseExited(const ui::MouseEvent& event) { 385 void TrayBackgroundView::OnMouseExited(const ui::MouseEvent& event) {
331 hovered_ = false; 386 hovered_ = false;
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after
413 top_edge = 0; 468 top_edge = 0;
414 left_edge = ShelfLayoutManager::kShelfItemInset; 469 left_edge = ShelfLayoutManager::kShelfItemInset;
415 bottom_edge = on_edge ? kPaddingFromEdgeOfShelf : 0; 470 bottom_edge = on_edge ? kPaddingFromEdgeOfShelf : 0;
416 right_edge = kShelfSize - 471 right_edge = kShelfSize -
417 ShelfLayoutManager::kShelfItemInset - kShelfItemHeight; 472 ShelfLayoutManager::kShelfItemInset - kShelfItemHeight;
418 } 473 }
419 SetBorder(views::Border::CreateEmptyBorder( 474 SetBorder(views::Border::CreateEmptyBorder(
420 top_edge, left_edge, bottom_edge, right_edge)); 475 top_edge, left_edge, bottom_edge, right_edge));
421 } 476 }
422 477
478 void TrayBackgroundView::OnImplicitAnimationsCompleted() {
479 views::View::SetVisible(false);
480 }
481
482 void TrayBackgroundView::HideTransformation() {
483 gfx::Transform transform;
484 if (shelf_alignment_ == SHELF_ALIGNMENT_BOTTOM ||
485 shelf_alignment_ == SHELF_ALIGNMENT_TOP)
486 transform.Translate(width(), 0.0f);
487 else
488 transform.Translate(0.0f, height());
489 layer()->SetTransform(transform);
490 }
491
423 void TrayBackgroundView::InitializeBubbleAnimations( 492 void TrayBackgroundView::InitializeBubbleAnimations(
424 views::Widget* bubble_widget) { 493 views::Widget* bubble_widget) {
425 wm::SetWindowVisibilityAnimationType( 494 wm::SetWindowVisibilityAnimationType(
426 bubble_widget->GetNativeWindow(), 495 bubble_widget->GetNativeWindow(),
427 wm::WINDOW_VISIBILITY_ANIMATION_TYPE_FADE); 496 wm::WINDOW_VISIBILITY_ANIMATION_TYPE_FADE);
428 wm::SetWindowVisibilityAnimationTransition( 497 wm::SetWindowVisibilityAnimationTransition(
429 bubble_widget->GetNativeWindow(), 498 bubble_widget->GetNativeWindow(),
430 wm::ANIMATE_HIDE); 499 wm::ANIMATE_HIDE);
431 wm::SetWindowVisibilityAnimationDuration( 500 wm::SetWindowVisibilityAnimationDuration(
432 bubble_widget->GetNativeWindow(), 501 bubble_widget->GetNativeWindow(),
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after
519 background_->set_alpha(kTrayBackgroundAlpha); 588 background_->set_alpha(kTrayBackgroundAlpha);
520 SchedulePaint(); 589 SchedulePaint();
521 } 590 }
522 591
523 void TrayBackgroundView::UpdateBubbleViewArrow( 592 void TrayBackgroundView::UpdateBubbleViewArrow(
524 views::TrayBubbleView* bubble_view) { 593 views::TrayBubbleView* bubble_view) {
525 // Nothing to do here. 594 // Nothing to do here.
526 } 595 }
527 596
528 } // namespace ash 597 } // 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