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

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: Animate Container of the tray items 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;
flackr 2014/05/06 15:42:11 Does this need to match the status area widget dur
jonross 2014/05/07 13:52:36 They currently match in the spec. However the spec
47 const int kShowAnimationDelay = 100;
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 (!this->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();
flackr 2014/05/06 15:42:11 Given visible != this->visible(), if !this->visibl
jonross 2014/05/07 13:52:36 Done.
341 }
342
343 if (visible)
344 views::View::SetVisible(visible);
flackr 2014/05/06 15:42:11 Comment that SetVisible(false) is deferred until a
jonross 2014/05/07 13:52:36 Done.
345
346 layer()->GetAnimator()->StopAnimating();
347 ui::ScopedLayerAnimationSettings animation(layer()->GetAnimator());
348 animation.SetTransitionDuration(base::TimeDelta::FromMilliseconds(
349 kAnimationDurationForVisibility));
350 animation.SetPreemptionStrategy(
351 ui::LayerAnimator::IMMEDIATELY_ANIMATE_TO_NEW_TARGET);
352 animation.AddObserver(this);
353
354 if (visible) {
355 animation.SetTweenType(gfx::Tween::EASE_OUT);
356 layer()->GetAnimator()->SchedulePauseForProperties(
flackr 2014/05/06 15:42:11 Why is the show delayed? Add comment as to why.
jonross 2014/05/07 13:52:36 Done.
357 base::TimeDelta::FromMilliseconds(kShowAnimationDelay),
358 ui::LayerAnimationElement::OPACITY |
359 ui::LayerAnimationElement::TRANSFORM);
360 layer()->SetOpacity(1.0f);
361 gfx::Transform transform;
362 transform.Translate(0.0f, 0.0f);
363 layer()->SetTransform(transform);
364 } else {
365 animation.SetTweenType(gfx::Tween::EASE_IN);
366 layer()->SetOpacity(0.0f);
flackr 2014/05/06 15:42:11 Perhaps also layer()->SetVisible(false);
jonross 2014/05/07 13:52:36 Done.
367 HideTransformation();
368 }
369 }
370
322 const char* TrayBackgroundView::GetClassName() const { 371 const char* TrayBackgroundView::GetClassName() const {
323 return kViewClassName; 372 return kViewClassName;
324 } 373 }
325 374
326 void TrayBackgroundView::OnMouseEntered(const ui::MouseEvent& event) { 375 void TrayBackgroundView::OnMouseEntered(const ui::MouseEvent& event) {
327 hovered_ = true; 376 hovered_ = true;
328 } 377 }
329 378
330 void TrayBackgroundView::OnMouseExited(const ui::MouseEvent& event) { 379 void TrayBackgroundView::OnMouseExited(const ui::MouseEvent& event) {
331 hovered_ = false; 380 hovered_ = false;
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after
413 top_edge = 0; 462 top_edge = 0;
414 left_edge = ShelfLayoutManager::kShelfItemInset; 463 left_edge = ShelfLayoutManager::kShelfItemInset;
415 bottom_edge = on_edge ? kPaddingFromEdgeOfShelf : 0; 464 bottom_edge = on_edge ? kPaddingFromEdgeOfShelf : 0;
416 right_edge = kShelfSize - 465 right_edge = kShelfSize -
417 ShelfLayoutManager::kShelfItemInset - kShelfItemHeight; 466 ShelfLayoutManager::kShelfItemInset - kShelfItemHeight;
418 } 467 }
419 SetBorder(views::Border::CreateEmptyBorder( 468 SetBorder(views::Border::CreateEmptyBorder(
420 top_edge, left_edge, bottom_edge, right_edge)); 469 top_edge, left_edge, bottom_edge, right_edge));
421 } 470 }
422 471
472 void TrayBackgroundView::OnImplicitAnimationsCompleted() {
473 if (layer()->opacity() == 0.0f)
flackr 2014/05/06 15:42:11 It might be more robust to compare the layer's vis
jonross 2014/05/07 13:52:36 Moved the listener to only be added for the !visib
474 views::View::SetVisible(false);
475 }
476
477 void TrayBackgroundView::HideTransformation() {
478 gfx::Transform transform;
479 if (shelf_alignment_ == SHELF_ALIGNMENT_BOTTOM ||
480 shelf_alignment_ == SHELF_ALIGNMENT_TOP)
481 transform.Translate(width(), 0.0f);
482 else
483 transform.Translate(0.0f, height());
484 layer()->SetTransform(transform);
485 }
486
423 void TrayBackgroundView::InitializeBubbleAnimations( 487 void TrayBackgroundView::InitializeBubbleAnimations(
424 views::Widget* bubble_widget) { 488 views::Widget* bubble_widget) {
425 wm::SetWindowVisibilityAnimationType( 489 wm::SetWindowVisibilityAnimationType(
426 bubble_widget->GetNativeWindow(), 490 bubble_widget->GetNativeWindow(),
427 wm::WINDOW_VISIBILITY_ANIMATION_TYPE_FADE); 491 wm::WINDOW_VISIBILITY_ANIMATION_TYPE_FADE);
428 wm::SetWindowVisibilityAnimationTransition( 492 wm::SetWindowVisibilityAnimationTransition(
429 bubble_widget->GetNativeWindow(), 493 bubble_widget->GetNativeWindow(),
430 wm::ANIMATE_HIDE); 494 wm::ANIMATE_HIDE);
431 wm::SetWindowVisibilityAnimationDuration( 495 wm::SetWindowVisibilityAnimationDuration(
432 bubble_widget->GetNativeWindow(), 496 bubble_widget->GetNativeWindow(),
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after
519 background_->set_alpha(kTrayBackgroundAlpha); 583 background_->set_alpha(kTrayBackgroundAlpha);
520 SchedulePaint(); 584 SchedulePaint();
521 } 585 }
522 586
523 void TrayBackgroundView::UpdateBubbleViewArrow( 587 void TrayBackgroundView::UpdateBubbleViewArrow(
524 views::TrayBubbleView* bubble_view) { 588 views::TrayBubbleView* bubble_view) {
525 // Nothing to do here. 589 // Nothing to do here.
526 } 590 }
527 591
528 } // namespace ash 592 } // 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