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

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: Moved ash/test/material_design_controller_test_api.(h|cc) to ash/common/material_design/test/. Created 4 years, 6 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..eebc8f3305af5f67bf414bee9ee0ccbcfac3d47f
--- /dev/null
+++ b/ash/common/shelf/shelf_background_animator.h
@@ -0,0 +1,128 @@
+// 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.
+
+#include <vector>
+
+#include "ash/ash_export.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 currently 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.
James Cook 2016/06/14 17:50:01 So for material design, we don't have the overlap
bruthig 2016/07/26 19:50:02 Attempted to clarify in comment. WDYT?
+// Material Design:
+// 1. Shelf button backgrounds
+// 2. Opaque overlay for THE SHELF_BACKGROUND_MAXIMIZED state.
James Cook 2016/06/14 17:50:01 nit: THE -> the
bruthig 2016/07/26 19:50:02 Done.
+class ASH_EXPORT ShelfBackgroundAnimator : public WmShelfObserver,
+ public BackgroundAnimatorDelegate {
+ public:
+ ShelfBackgroundAnimator();
+ ~ShelfBackgroundAnimator() override;
+
+ ShelfBackgroundType target_background_type() const {
James Cook 2016/06/14 17:50:01 #include "ash/common/shelf/shelf_types.h" for Shel
bruthig 2016/07/26 19:50:02 Done.
+ return target_background_type_;
+ }
+
+ void AddObserver(ShelfBackgroundAnimatorObserver* observer);
+ void RemoveObserver(ShelfBackgroundAnimatorObserver* observer);
+
+ // Sets the |background_type| and notifies all the attached 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.
+ void PaintBackground(ShelfBackgroundType background_type,
+ BackgroundAnimatorChangeType change_type);
+
+ protected:
+ // WmShelfObserver:
+ void OnBackgroundUpdated(ShelfBackgroundType background_type,
+ BackgroundAnimatorChangeType change_type) override;
+
+ // BackgroundAnimatorDelegate:
+ void UpdateBackground(BackgroundAnimator* animator, int alpha) override;
+ void BackgroundAnimationEnded(BackgroundAnimator* animator,
+ bool successful) override;
+
+ private:
+ friend class test::ShelfBackgroundAnimatorTestApi;
+
+ // Creates new BackgroundAnimators configured with the correct initial/target
+ // alpha values. If any BackgroundAnimator's are currently animating they
+ // will be stopped.
+ void CreateAnimators(ShelfBackgroundType background_type,
+ BackgroundAnimatorChangeType change_type);
+
+ // Stops all existing animators owned by this.
+ void StopAnimators();
+
+ // Configures all the BackgroundAnimators owned by this with the correct
+ // durations.
+ void ConfigureAnimators(ShelfBackgroundType background_type,
+ BackgroundAnimatorChangeType change_type);
+
+ // The background type that this is animating towards or has reached.
+ ShelfBackgroundType target_background_type_;
+
+ // The last background type this is animating away from.
+ ShelfBackgroundType previous_background_type_;
+
+ // The last opaque background alpha value updated by the
+ // |opaque_background_animator_|.
+ int previous_opaque_background_alpha_;
James Cook 2016/06/14 17:50:01 For my edification: Do we prefer ints for alpha or
bruthig 2016/07/26 19:50:02 I haven't dealt much in the opacity/alpha space bu
+
+ // The last opaque background alpha value updated by the
+ // |asset_background_animator_|.
+ int previous_asset_background_alpha_;
+
+ // The last opaque background alpha value updated by the
+ // |item_background_animator_|.
+ int previous_item_background_alpha_;
+
+ // TODO(bruthig): Replace all BackgroundAnimators with a single
+ // gfx::SlideAnimation.
+ std::unique_ptr<BackgroundAnimator> opaque_background_animator_;
James Cook 2016/06/14 17:50:01 nit: Comment which things are animated with this a
bruthig 2016/07/26 19:50:02 Done.
+
+ // TODO(bruthig): Remove when non-md is no longer needed (crbug.com/614453).
+ std::unique_ptr<BackgroundAnimator> asset_background_animator_;
+
+ std::unique_ptr<BackgroundAnimator> item_background_animator_;
+
+ base::ObserverList<ShelfBackgroundAnimatorObserver> observers_;
+
+ // true if the existing BackgroundAnimators can be re-used to animate to the
James Cook 2016/06/14 17:50:01 nit: true -> True and false -> False below
bruthig 2016/07/26 19:50:02 Done.
+ // |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_;
+
+ // Tracks how many animators complete successfully since the last
+ // CreateAnimators() call. Used to properly set |can_reuse_animators_|.
+ int successful_animator_count_;
+
+ // false until an animation is triggered for the first time.
+ bool has_animated_once_;
+
+ DISALLOW_COPY_AND_ASSIGN(ShelfBackgroundAnimator);
+};
James Cook 2016/06/14 17:50:01 Thanks for nice documentation through this class.
bruthig 2016/07/26 19:50:02 :)
+
+} // namespace ash

Powered by Google App Engine
This is Rietveld 408576698