Commit 7b514edc authored by Manu Cornet's avatar Manu Cornet Committed by Commit Bot

CrOS Shelf: Introduce a common |ShelfComponent| interface

Bug: 1044306, 1042491, 1040177, 1042911
Change-Id: I37021bfce8f2d6a9b7bcd39df0a3d23eae0b6707
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2028858
Commit-Queue: Manu Cornet <manucornet@chromium.org>
Reviewed-by: default avatarAlex Newcomer <newcomer@chromium.org>
Cr-Commit-Position: refs/heads/master@{#736622}
parent 42987aa5
......@@ -613,6 +613,7 @@ component("ash") {
"shelf/shelf_button_delegate.h",
"shelf/shelf_button_pressed_metric_tracker.cc",
"shelf/shelf_button_pressed_metric_tracker.h",
"shelf/shelf_component.h",
"shelf/shelf_config.cc",
"shelf/shelf_container_view.cc",
"shelf/shelf_container_view.h",
......
......@@ -349,6 +349,11 @@ void HotseatWidget::SetTranslucentBackground(
delegate_view_->SetTranslucentBackground(translucent_background_bounds);
}
void HotseatWidget::CalculateTargetBounds() {
// TODO(manucornet): Move target bounds calculations from the shelf layout
// manager.
}
void HotseatWidget::UpdateLayout(bool animate) {
const LayoutInputs new_layout_inputs = GetLayoutInputs();
if (layout_inputs_.has_value() && *layout_inputs_ == new_layout_inputs)
......
......@@ -8,6 +8,7 @@
#include "ash/ash_export.h"
#include "ash/public/cpp/shelf_config.h"
#include "ash/public/cpp/shelf_types.h"
#include "ash/shelf/shelf_component.h"
#include "base/optional.h"
#include "ui/views/widget/widget.h"
......@@ -22,8 +23,9 @@ class Shelf;
class ShelfView;
// The hotseat widget is part of the shelf and hosts app shortcuts.
class ASH_EXPORT HotseatWidget : public views::Widget,
public ShelfConfig::Observer {
class ASH_EXPORT HotseatWidget : public ShelfComponent,
public ShelfConfig::Observer,
public views::Widget {
public:
HotseatWidget();
~HotseatWidget() override;
......@@ -39,7 +41,7 @@ class ASH_EXPORT HotseatWidget : public views::Widget,
void OnGestureEvent(ui::GestureEvent* event) override;
bool OnNativeWidgetActivationChanged(bool active) override;
// ShelfConfig::Observer
// ShelfConfig::Observer:
void OnShelfConfigUpdated() override;
// Whether the overflow menu/bubble is currently being shown.
......@@ -65,8 +67,9 @@ class ASH_EXPORT HotseatWidget : public views::Widget,
// hotseat background.
void SetTranslucentBackground(const gfx::Rect& background_bounds);
// Updates this widget's layout according to current conditions.
void UpdateLayout(bool animate);
// ShelfComponent:
void CalculateTargetBounds() override;
void UpdateLayout(bool animate) override;
gfx::Size GetTranslucentBackgroundSize() const;
......
// Copyright 2020 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_SHELF_SHELF_COMPONENT_H_
#define ASH_SHELF_SHELF_COMPONENT_H_
#include "ash/ash_export.h"
// An interface describing any shelf component such as the navigation widget,
// the hotseat widget or the status area widget, to make it easier to
// coordinate animations for all of them.
class ASH_EXPORT ShelfComponent {
// Makes the component calculate its new target bounds given the current
// target conditions. It is the component's responsibility to store the
// calculated bounds.
virtual void CalculateTargetBounds() = 0;
// Updates the component's layout and bounds to match the most recently
// calculated target bounds. The change should be animated if |animate| is
// true.
virtual void UpdateLayout(bool animate) = 0;
};
#endif // ASH_SHELF_SHELF_COMPONENT_H_
......@@ -404,6 +404,11 @@ void ShelfNavigationWidget::OnShelfConfigUpdated() {
UpdateLayout(/*animate=*/true);
}
void ShelfNavigationWidget::CalculateTargetBounds() {
// TODO(manucornet): Move target bounds calculations from the shelf layout
// manager.
}
void ShelfNavigationWidget::UpdateLayout(bool animate) {
const bool back_button_shown = IsBackButtonShown();
const bool home_button_shown = IsHomeButtonShown();
......
......@@ -8,6 +8,7 @@
#include "ash/ash_export.h"
#include "ash/public/cpp/shelf_config.h"
#include "ash/public/cpp/tablet_mode_observer.h"
#include "ash/shelf/shelf_component.h"
#include "ash/shell_observer.h"
#include "ui/views/accessible_pane_view.h"
#include "ui/views/widget/widget.h"
......@@ -29,10 +30,11 @@ class ShelfView;
// The shelf navigation widget holds the home button and (when in tablet mode)
// the back button.
class ASH_EXPORT ShelfNavigationWidget : public views::Widget,
public TabletModeObserver,
class ASH_EXPORT ShelfNavigationWidget : public TabletModeObserver,
public ShelfComponent,
public ShelfConfig::Observer,
public ShellObserver,
public ShelfConfig::Observer {
public views::Widget {
public:
class TestApi {
public:
......@@ -89,9 +91,9 @@ class ASH_EXPORT ShelfNavigationWidget : public views::Widget,
// ShelfConfig::Observer:
void OnShelfConfigUpdated() override;
// Updates this widget's layout according to current constraints: tablet
// mode and shelf orientation.
void UpdateLayout(bool animate);
// ShelfComponent:
void CalculateTargetBounds() override;
void UpdateLayout(bool animate) override;
private:
class Delegate;
......
......@@ -702,6 +702,15 @@ void ShelfWidget::OnBackgroundTypeChanged(ShelfBackgroundType background_type,
delegate_view_->UpdateOpaqueBackground();
}
void ShelfWidget::CalculateTargetBounds() {
// TODO(manucornet): Move target bounds calculations from the shelf layout
// manager.
}
void ShelfWidget::UpdateLayout(bool animate) {
// TODO(manucornet): Refactor layout update logic into this method.
}
void ShelfWidget::OnSessionStateChanged(session_manager::SessionState state) {
// Do not show shelf widget:
// * when views based shelf is disabled
......
......@@ -14,6 +14,7 @@
#include "ash/shelf/hotseat_transition_animator.h"
#include "ash/shelf/hotseat_widget.h"
#include "ash/shelf/shelf_background_animator.h"
#include "ash/shelf/shelf_component.h"
#include "ash/shelf/shelf_layout_manager_observer.h"
#include "ash/shelf/shelf_observer.h"
#include "base/macros.h"
......@@ -34,11 +35,12 @@ class StatusAreaWidget;
// The ShelfWidget manages the shelf view (which contains the shelf icons) and
// the status area widget. There is one ShelfWidget per display. It is created
// early during RootWindowController initialization.
class ASH_EXPORT ShelfWidget : public views::Widget,
class ASH_EXPORT ShelfWidget : public AccessibilityObserver,
public SessionObserver,
public ShelfComponent,
public ShelfLayoutManagerObserver,
public ShelfObserver,
public SessionObserver,
public AccessibilityObserver {
public views::Widget {
public:
explicit ShelfWidget(Shelf* shelf);
~ShelfWidget() override;
......@@ -106,6 +108,10 @@ class ASH_EXPORT ShelfWidget : public views::Widget,
void OnGestureEvent(ui::GestureEvent* event) override;
bool OnNativeWidgetActivationChanged(bool active) override;
// ShelfComponent:
void CalculateTargetBounds() override;
void UpdateLayout(bool animate) override;
// ShelfLayoutManagerObserver:
void WillDeleteShelfLayoutManager() override;
void OnHotseatStateChanged(HotseatState old_state,
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment