OLD | NEW |
(Empty) | |
| 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 |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #ifndef ASH_COMMON_SHELF_SHELF_BACKGROUND_ANIMATOR_H_ |
| 6 #define ASH_COMMON_SHELF_SHELF_BACKGROUND_ANIMATOR_H_ |
| 7 |
| 8 #include <vector> |
| 9 |
| 10 #include "ash/ash_export.h" |
| 11 #include "ash/common/shelf/shelf_types.h" |
| 12 #include "ash/common/shelf/wm_shelf_observer.h" |
| 13 #include "ash/common/wm/background_animator.h" |
| 14 #include "base/macros.h" |
| 15 #include "base/observer_list.h" |
| 16 |
| 17 namespace ash { |
| 18 |
| 19 class ShelfBackgroundAnimatorObserver; |
| 20 class ShelfBackgroundAnimatorTestApi; |
| 21 class WmShelf; |
| 22 |
| 23 // Central controller for the Shelf and Dock opacity animations. |
| 24 // |
| 25 // The ShelfBackgroundAnimator is capable of observing a WmShelf instance for |
| 26 // background type changes or clients can call PaintBackground() directly. |
| 27 // |
| 28 // The Shelf uses 3 surfaces for the animations: |
| 29 // |
| 30 // Non-Material Design: |
| 31 // 1. Shelf button backgrounds |
| 32 // 2. Opaque overlay for the SHELF_BACKGROUND_MAXIMIZED state. |
| 33 // 3. Shelf and Dock assets for the SHELF_BACKGROUND_OVERLAP state. |
| 34 // Material Design: |
| 35 // 1. Shelf button backgrounds |
| 36 // 2. Opaque overlay for the SHELF_BACKGROUND_OVERLAP and |
| 37 // SHELF_BACKGROUND_MAXIMIZED states. |
| 38 class ASH_EXPORT ShelfBackgroundAnimator : public WmShelfObserver, |
| 39 public BackgroundAnimatorDelegate { |
| 40 public: |
| 41 // Initializes this with the given |background_type|. This will observe the |
| 42 // |wm_shelf| for background type changes if |wm_shelf| is not null. |
| 43 ShelfBackgroundAnimator(ShelfBackgroundType background_type, |
| 44 WmShelf* wm_shelf); |
| 45 ~ShelfBackgroundAnimator() override; |
| 46 |
| 47 ShelfBackgroundType target_background_type() const { |
| 48 return target_background_type_; |
| 49 } |
| 50 |
| 51 // |observer| will be notified of the current values when being added. |
| 52 void AddObserver(ShelfBackgroundAnimatorObserver* observer); |
| 53 void RemoveObserver(ShelfBackgroundAnimatorObserver* observer); |
| 54 |
| 55 // Conditionally animates the background to the specified |background_type| |
| 56 // and notifies observers of the new background parameters (e.g. alpha). |
| 57 // If |change_type| is BACKGROUND_CHANGE_IMMEDIATE then the |
| 58 // observers will only receive one notification with the final background |
| 59 // state, otherwise the observers will be notified multiple times in order to |
| 60 // animate the changes to the backgrounds. |
| 61 // |
| 62 // NOTE: If a second request to paint the same |background_type| using the |
| 63 // BACKGROUND_CHANGE_ANIMATE change type is received it will be ignored and |
| 64 // observers will NOT be notified. |
| 65 void PaintBackground(ShelfBackgroundType background_type, |
| 66 BackgroundAnimatorChangeType change_type); |
| 67 |
| 68 protected: |
| 69 // WmShelfObserver: |
| 70 void OnBackgroundTypeChanged( |
| 71 ShelfBackgroundType background_type, |
| 72 BackgroundAnimatorChangeType change_type) override; |
| 73 |
| 74 // BackgroundAnimatorDelegate: |
| 75 void UpdateBackground(BackgroundAnimator* animator, int alpha) override; |
| 76 void BackgroundAnimationEnded(BackgroundAnimator* animator) override; |
| 77 |
| 78 private: |
| 79 friend class ShelfBackgroundAnimatorTestApi; |
| 80 |
| 81 // Helper function used by PaintBackground() to animate the background. |
| 82 void AnimateBackground(ShelfBackgroundType background_type, |
| 83 BackgroundAnimatorChangeType change_type); |
| 84 |
| 85 // Creates new BackgroundAnimators configured with the correct durations and |
| 86 // initial/target alpha values. If any BackgroundAnimators are currently |
| 87 // animating they will be stopped. |
| 88 void CreateAnimators(ShelfBackgroundType background_type, |
| 89 BackgroundAnimatorChangeType change_type); |
| 90 |
| 91 // Stops all existing animators owned by this. |
| 92 void StopAnimators(); |
| 93 |
| 94 // Called when an alpha value changes and observers need to be notified. |
| 95 void OnAlphaChanged(BackgroundAnimator* animator, int alpha); |
| 96 |
| 97 // The background type that this is animating towards or has reached. |
| 98 ShelfBackgroundType target_background_type_ = SHELF_BACKGROUND_DEFAULT; |
| 99 |
| 100 // The last background type this is animating away from. |
| 101 ShelfBackgroundType previous_background_type_ = SHELF_BACKGROUND_MAXIMIZED; |
| 102 |
| 103 // Animates the solid color background of the Shelf. |
| 104 // TODO(bruthig): Replace all BackgroundAnimators with a single |
| 105 // gfx::SlideAnimation. |
| 106 std::unique_ptr<BackgroundAnimator> opaque_background_animator_; |
| 107 |
| 108 // Animates the asset/image based background of the Shelf. |
| 109 // TODO(bruthig): Remove when non-md is no longer needed (crbug.com/614453). |
| 110 std::unique_ptr<BackgroundAnimator> asset_background_animator_; |
| 111 |
| 112 // Animates the backgrounds of Shelf child Views. |
| 113 std::unique_ptr<BackgroundAnimator> item_background_animator_; |
| 114 |
| 115 base::ObserverList<ShelfBackgroundAnimatorObserver> observers_; |
| 116 |
| 117 // True if the existing BackgroundAnimators can be re-used to animate to the |
| 118 // |previous_background_type_|. This allows for pre-empted animations to take |
| 119 // the same amount of time to reverse to the |previous_background_type_|. |
| 120 bool can_reuse_animators_ = false; |
| 121 |
| 122 // Tracks how many animators completed successfully since the last |
| 123 // CreateAnimators() call. Used to properly set |can_reuse_animators_|. |
| 124 int successful_animator_count_ = 0; |
| 125 |
| 126 // The shelf to observe for changes to the shelf background type, can be null. |
| 127 WmShelf* wm_shelf_; |
| 128 |
| 129 DISALLOW_COPY_AND_ASSIGN(ShelfBackgroundAnimator); |
| 130 }; |
| 131 |
| 132 } // namespace ash |
| 133 |
| 134 #endif // ASH_COMMON_SHELF_SHELF_BACKGROUND_ANIMATOR_H_ |
OLD | NEW |