Reland "Add quick app barebones UI implementation"
This is a reland of commit 78f47a099ad0260751a4ac28f844d8c12d71f72c
The ASAN failure was caused by QuickAppAccessModel getting destroyed
before the HomeButton which is observing it. Resetting
quick_app_model_observation_ in OnShellDestroying() ensures that the
QuickAppAccessModel still exists when removing the homebutton as
observer.
Original change's description:
> Add quick app barebones UI implementation
>
> Add quick app button to be shown next to the home button. Quick app can
> be set by passing an app_id to the app list controller function
> SetHomeButtonQuickApp(). The home button will observe the new
> QuickAppAccessModel for the quick app to be changed and will then show
> the quick app button.
>
> Animations, icon loading, and additional metric to be added in follow
> ups.
>
> Bug=b:266734005
>
> Change-Id: I2840998e5860ab33a1607022417a55277e06d660
> Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/4380277
> Commit-Queue: Matthew Mourgos <mmourgos@chromium.org>
> Reviewed-by: Toni Barzic <tbarzic@chromium.org>
> Cr-Commit-Position: refs/heads/main@{#1126186}
Change-Id: I87c713c91b1b098ea21b99a57bf9612129754c55
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/4401631
Reviewed-by: Toni Barzic <tbarzic@chromium.org>
Commit-Queue: Matthew Mourgos <mmourgos@chromium.org>
Cr-Commit-Position: refs/heads/main@{#1126712}
diff --git a/ash/shelf/home_button.h b/ash/shelf/home_button.h
index 90d088a..1ce809f1 100644
--- a/ash/shelf/home_button.h
+++ b/ash/shelf/home_button.h
@@ -8,16 +8,22 @@
#include <memory>
#include "ash/app_list/app_list_metrics.h"
+#include "ash/app_list/app_list_model_provider.h"
+#include "ash/app_list/quick_app_access_model.h"
#include "ash/ash_export.h"
+#include "ash/public/cpp/app_list/app_list_controller_observer.h"
#include "ash/shelf/home_button_controller.h"
#include "ash/shelf/shelf_button_delegate.h"
#include "ash/shelf/shelf_control_button.h"
+#include "ash/shell_observer.h"
+#include "base/scoped_observation.h"
#include "ui/gfx/geometry/rect.h"
#include "ui/views/view_targeter_delegate.h"
namespace views {
class AnimationBuilder;
class CircleLayerDelegate;
+class ImageButton;
class Label;
} // namespace views
@@ -30,6 +36,7 @@
class Shelf;
class ShelfButtonDelegate;
class ShelfNavigationWidget;
+class Shell;
// 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
@@ -40,7 +47,10 @@
// launch Assistant.
class ASH_EXPORT HomeButton : public ShelfControlButton,
public ShelfButtonDelegate,
- public views::ViewTargeterDelegate {
+ public views::ViewTargeterDelegate,
+ public ShellObserver,
+ public AppListModelProvider::Observer,
+ public QuickAppAccessModel::Observer {
public:
class ScopedNoClipRect {
public:
@@ -126,7 +136,15 @@
void AddNudgeAnimationObserverForTest(NudgeAnimationObserver* observer);
void RemoveNudgeAnimationObserverForTest(NudgeAnimationObserver* observer);
- views::View* label_container_for_test() const { return label_container_; }
+ views::View* expandable_container_for_test() const {
+ return expandable_container_;
+ }
+
+ views::Label* nudge_label_for_test() const { return nudge_label_; }
+
+ views::ImageButton* quick_app_button_for_test() const {
+ return quick_app_button_;
+ }
protected:
// views::Button:
@@ -137,6 +155,16 @@
// Creates `nudge_label_` for launcher nudge.
void CreateNudgeLabel();
+ // Creates the `expandable_container_` which holds either the `nudge_label_`
+ // or the `quick_app_button_`.
+ void CreateExpandableContainer();
+
+ // Creates the `quick_app_button_` to be shown next to the home button.
+ void CreateQuickAppButton();
+
+ // Called when the quick app button is pressed.
+ void QuickAppButtonPressed();
+
// Animation functions for launcher nudge.
void AnimateNudgeRipple(views::AnimationBuilder& builder);
void AnimateNudgeBounce(views::AnimationBuilder& builder);
@@ -157,6 +185,24 @@
bool DoesIntersectRect(const views::View* target,
const gfx::Rect& rect) const override;
+ // ShellObserver:
+ void OnShellDestroying() override;
+
+ // AppListModelProvider::Observer:
+ void OnActiveAppListModelsChanged(AppListModel* model,
+ SearchModel* search_model) override;
+
+ // QuickAppAccessModel::Observer:
+ void OnQuickAppChanged() override;
+
+ base::ScopedObservation<QuickAppAccessModel, QuickAppAccessModel::Observer>
+ quick_app_model_observation_{this};
+
+ base::ScopedObservation<Shell, ShellObserver> shell_observation_{this};
+
+ base::ScopedObservation<AppListModelProvider, AppListModelProvider::Observer>
+ app_list_model_observation_{this};
+
Shelf* const shelf_;
// The controller used to determine the button's behavior.
@@ -169,9 +215,10 @@
// The label view and for launcher nudge animation.
views::Label* nudge_label_ = nullptr;
- // The container of `nudge_label_`. This is also responsible for painting the
- // background of the label.
- views::View* label_container_ = nullptr;
+ // The container of `nudge_label_` or `quick_app_button_`. This is also
+ // responsible for painting the background of the contents. This container can
+ // expand visually by animation.
+ views::View* expandable_container_ = nullptr;
// The timer that counts down to hide the nudge_label_ from showing state.
base::OneShotTimer label_nudge_timer_;
@@ -182,6 +229,13 @@
std::unique_ptr<ScopedNoClipRect> scoped_no_clip_rect_;
+ // The app button which is shown next to the home button. Only shown when
+ // set by SetQuickApp().
+ views::ImageButton* quick_app_button_ = nullptr;
+
+ // The app_id of the quick app button.
+ std::string quick_app_id_;
+
base::ObserverList<NudgeAnimationObserver> observers_;
base::WeakPtrFactory<HomeButton> weak_ptr_factory_{this};