[go: nahoru, domu]

Separate AppListButton view from business logic

AppListButton observes several global states to change how it draws
itself, based on Tablet Mode, App List visibility, etc. It also has
complex Assistant-related logic.

This CL moves this business logic to AppListButtonController, so that
AppListButton only has to know how to paint. The controller observes
global state and directs AppListButton to animate itself to different
states as needed.

This will allow changing the controller logic without affecting the
button, and changing the button style (and how different states are
represented) without affecting the controller logic.

Bug: 937549
Change-Id: I8bededc22e06675da46e6fa8b91f7eea46ed87cb
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1529078
Commit-Queue: Michael Giuffrida <michaelpg@chromium.org>
Reviewed-by: James Cook <jamescook@chromium.org>
Cr-Commit-Position: refs/heads/master@{#643148}
diff --git a/ash/shelf/app_list_button.h b/ash/shelf/app_list_button.h
index c698120..86c6bfc 100644
--- a/ash/shelf/app_list_button.h
+++ b/ash/shelf/app_list_button.h
@@ -7,87 +7,48 @@
 
 #include <memory>
 
-#include "ash/app_list/app_list_controller_observer.h"
 #include "ash/ash_export.h"
-#include "ash/public/cpp/assistant/default_voice_interaction_observer.h"
-#include "ash/public/interfaces/voice_interaction_controller.mojom.h"
-#include "ash/session/session_observer.h"
+#include "ash/shelf/app_list_button_controller.h"
 #include "ash/shelf/shelf_control_button.h"
-#include "ash/wm/tablet_mode/tablet_mode_observer.h"
 #include "base/macros.h"
-#include "third_party/skia/include/core/SkColor.h"
-
-namespace base {
-class OneShotTimer;
-}  // namespace base
 
 namespace ash {
 
-class AssistantOverlay;
 class Shelf;
 class ShelfView;
 
-// Button used for the AppList icon on the shelf.
-class ASH_EXPORT AppListButton : public ShelfControlButton,
-                                 public AppListControllerObserver,
-                                 public SessionObserver,
-                                 public TabletModeObserver,
-                                 public DefaultVoiceInteractionObserver {
+// Button used for the AppList icon on the shelf. It opens the app list (in
+// clamshell mode) or home screen (in tablet mode). Because the clamshell-mode
+// app list appears like a dismissable overlay, the button is highlighted while
+// the app list is open in clamshell mode.
+//
+// If Assistant is enabled, the button is filled in; long-pressing it will
+// launch Assistant.
+class ASH_EXPORT AppListButton : public ShelfControlButton {
  public:
   static const char kViewClassName[];
 
   AppListButton(ShelfView* shelf_view, Shelf* shelf);
   ~AppListButton() override;
 
-  void OnAppListShown();
-  void OnAppListDismissed();
-
-  bool is_showing_app_list() const { return is_showing_app_list_; }
-
   // views::Button:
   void OnGestureEvent(ui::GestureEvent* event) override;
   const char* GetClassName() const override;
 
+  // Called when the availability of a long-press gesture may have changed, e.g.
+  // when Assistant becomes enabled.
+  void OnVoiceInteractionAvailabilityChanged();
+
+  // True if the app list is shown for the display containing this button.
+  bool IsShowingAppList() const;
+
  protected:
   // views::Button:
   void PaintButtonContents(gfx::Canvas* canvas) override;
 
  private:
-  // AppListControllerObserver:
-  void OnAppListVisibilityChanged(bool shown, int64_t display_id) override;
-
-  // mojom::VoiceInteractionObserver:
-  void OnVoiceInteractionStatusChanged(
-      mojom::VoiceInteractionState state) override;
-  void OnVoiceInteractionSettingsEnabled(bool enabled) override;
-  void OnVoiceInteractionConsentStatusUpdated(
-      mojom::ConsentStatus consent_status) override;
-
-  // SessionObserver:
-  void OnActiveUserSessionChanged(const AccountId& account_id) override;
-
-  // TabletModeObserver:
-  void OnTabletModeStarted() override;
-
-  void StartVoiceInteractionAnimation();
-
-  // Whether the voice interaction style should be used.
-  bool UseVoiceInteractionStyle();
-
-  // Initialize the voice interaction overlay.
-  void InitializeVoiceInteractionOverlay();
-
-  // True if the app list is currently showing for this display.
-  // This is useful because other app_list_visible functions aren't per-display.
-  bool is_showing_app_list_ = false;
-
-  Shelf* shelf_;
-
-  // Owned by the view hierarchy. Null if the voice interaction is not enabled.
-  AssistantOverlay* assistant_overlay_ = nullptr;
-  std::unique_ptr<base::OneShotTimer> assistant_animation_delay_timer_;
-  std::unique_ptr<base::OneShotTimer> assistant_animation_hide_delay_timer_;
-  base::TimeTicks voice_interaction_start_timestamp_;
+  // The controller used to determine the button's behavior.
+  AppListButtonController controller_;
 
   DISALLOW_COPY_AND_ASSIGN(AppListButton);
 };