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

Unified Diff: ash/common/shelf/shelf_background_animator.h

Issue 2053113002: Replaced BackgroundAnimator with ShelfBackgroundAnimator. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Added PaletteTray to the Shelf background animations. Created 4 years, 5 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 side-by-side diff with in-line comments
Download patch
Index: ash/common/shelf/shelf_background_animator.h
diff --git a/ash/common/shelf/shelf_background_animator.h b/ash/common/shelf/shelf_background_animator.h
new file mode 100644
index 0000000000000000000000000000000000000000..4a937cef58afa510c9f7ab5b7d6962f6613bb056
--- /dev/null
+++ b/ash/common/shelf/shelf_background_animator.h
@@ -0,0 +1,129 @@
+// Copyright 2016 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#ifndef ASH_COMMON_SHELF_SHELF_BACKGROUND_ANIMATOR_H_
+#define ASH_COMMON_SHELF_SHELF_BACKGROUND_ANIMATOR_H_
+
+#include <vector>
+
+#include "ash/ash_export.h"
+#include "ash/common/shelf/shelf_types.h"
+#include "ash/common/shelf/wm_shelf_observer.h"
+#include "ash/common/wm/background_animator.h"
+#include "base/macros.h"
+#include "base/observer_list.h"
+
+namespace ash {
+
+namespace test {
+class ShelfBackgroundAnimatorTestApi;
+} // namespace test
+
+class ShelfBackgroundAnimatorObserver;
+
+// Central controller for the Shelf and Dock opacity animations.
+//
+// The ShelfBackgroundAnimator is capable of observing a WmShelf instance but it
+// needs to be explicitly added as an observer.
+//
+// The Shelf uses 3 surfaces for the animations:
+//
+// Non-Material Design:
+// 1. Shelf button backgrounds
+// 2. Opaque overlay for the SHELF_BACKGROUND_MAXIMIZED state.
+// 3. Shelf and Dock assets for the SHELF_BACKGROUND_OVERLAP state.
+// Material Design:
+// 1. Shelf button backgrounds
+// 2. Opaque overlay for the SHELF_BACKGROUND_OVERLAP and
+// SHELF_BACKGROUND_MAXIMIZED states.
+class ASH_EXPORT ShelfBackgroundAnimator : public WmShelfObserver,
+ public BackgroundAnimatorDelegate {
+ public:
+ explicit ShelfBackgroundAnimator(ShelfBackgroundType background_type);
+ ~ShelfBackgroundAnimator() override;
+
+ ShelfBackgroundType target_background_type() const {
+ return target_background_type_;
+ }
+
+ // |observer| will be notified of the current values when being added.
+ void AddObserver(ShelfBackgroundAnimatorObserver* observer);
+ void RemoveObserver(ShelfBackgroundAnimatorObserver* observer);
+
+ // Conditionally animates the background to the specified |background_type|
+ // and notifies observers of the new background parameters (e.g. alpha).
+ // If |change_type| is BACKGROUND_CHANGE_IMMEDIATE then the
+ // observers will only receive one notification with the final background
+ // state, otherwise the observers will be notified multiple times in order to
+ // animate the changes to the backgrounds.
+ //
+ // NOTE: If a second request to paint the same |background_type| using the
+ // BACKGROUND_CHANGE_ANIMATE change type is received it will be ignored and
+ // observers will NOT be notified.
+ void PaintBackground(ShelfBackgroundType background_type,
+ BackgroundAnimatorChangeType change_type);
+
+ protected:
+ // WmShelfObserver:
+ void OnBackgroundChanged(ShelfBackgroundType background_type,
+ BackgroundAnimatorChangeType change_type) override;
+
+ // BackgroundAnimatorDelegate:
+ void UpdateBackground(BackgroundAnimator* animator, int alpha) override;
+ void BackgroundAnimationEnded(BackgroundAnimator* animator) override;
+
+ private:
+ friend class test::ShelfBackgroundAnimatorTestApi;
+
+ // Helper function used by PaintBackground() to animate the background.
+ void AnimateBackground(ShelfBackgroundType background_type,
+ BackgroundAnimatorChangeType change_type);
+
+ // Creates new BackgroundAnimators configured with the correct durations and
+ // initial/target alpha values. If any BackgroundAnimators are currently
+ // animating they will be stopped.
+ void CreateAnimators(ShelfBackgroundType background_type,
+ BackgroundAnimatorChangeType change_type);
+
+ // Stops all existing animators owned by this.
+ void StopAnimators();
+
+ // Called when an alpha value changes and observers need to be notified.
+ void OnAlphaChanged(BackgroundAnimator* animator, int alpha);
+
+ // The background type that this is animating towards or has reached.
+ ShelfBackgroundType target_background_type_ = SHELF_BACKGROUND_DEFAULT;
+
+ // The last background type this is animating away from.
+ ShelfBackgroundType previous_background_type_ = SHELF_BACKGROUND_MAXIMIZED;
+
+ // TODO(bruthig): Replace all BackgroundAnimators with a single
James Cook 2016/07/27 00:30:38 super-nit: Put the TODO under the other comment, h
bruthig 2016/07/27 17:05:44 Done.
+ // gfx::SlideAnimation.
+ // Animates the solid color background of the Shelf.
+ std::unique_ptr<BackgroundAnimator> opaque_background_animator_;
+
+ // TODO(bruthig): Remove when non-md is no longer needed (crbug.com/614453).
+ // Animates the asset/image based background of the Shelf.
+ std::unique_ptr<BackgroundAnimator> asset_background_animator_;
+
+ // Animates the backgrounds of Shelf child Views.
+ std::unique_ptr<BackgroundAnimator> item_background_animator_;
+
+ base::ObserverList<ShelfBackgroundAnimatorObserver> observers_;
+
+ // True if the existing BackgroundAnimators can be re-used to animate to the
+ // |previous_background_type_|. This allows for pre-empted animations to take
+ // the same amount of time to reverse to the |previous_background_type_|.
+ bool can_reuse_animators_ = false;
+
+ // Tracks how many animators complete successfully since the last
James Cook 2016/07/27 00:30:38 nit: complete -> completed?
bruthig 2016/07/27 17:05:44 Done.
+ // CreateAnimators() call. Used to properly set |can_reuse_animators_|.
+ int successful_animator_count_ = 0;
+
+ DISALLOW_COPY_AND_ASSIGN(ShelfBackgroundAnimator);
+};
+
+} // namespace ash
+
+#endif // ASH_COMMON_SHELF_SHELF_BACKGROUND_ANIMATOR_H_

Powered by Google App Engine
This is Rietveld 408576698