Commit 983ff12f authored by Manu Cornet's avatar Manu Cornet Committed by Commit Bot

CrOS Shelf: Skip layout of tray containers and hotseat when not needed

Also calculate the new hotseat state as part of calculating new target
bounds instead of passing it in.

Bug: 1042911, 1040177
Change-Id: Ie3471df435ba9ce49130e528811c17da0e249b0c
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2025428
Commit-Queue: Manu Cornet <manucornet@chromium.org>
Reviewed-by: default avatarXiyuan Xia <xiyuan@chromium.org>
Cr-Commit-Position: refs/heads/master@{#736118}
parent 5e5133d0
......@@ -335,7 +335,7 @@ void HotseatWidget::OnTabletModeChanged() {
delegate_view_->OnTabletModeChanged();
}
float HotseatWidget::CalculateOpacity() {
float HotseatWidget::CalculateOpacity() const {
const float target_opacity =
GetShelfView()->shelf()->shelf_layout_manager()->GetOpacity();
return (state() == HotseatState::kExtended) ? 1.0f // fully opaque
......@@ -348,6 +348,9 @@ void HotseatWidget::SetOpaqueBackground(
}
void HotseatWidget::UpdateLayout(bool animate) {
const LayoutInputs new_layout_inputs = GetLayoutInputs();
if (layout_inputs_.has_value() && *layout_inputs_ == new_layout_inputs)
return;
ui::Layer* layer = GetNativeView()->layer();
ui::ScopedLayerAnimationSettings animation_setter(layer->GetAnimator());
animation_setter.SetTransitionDuration(
......@@ -357,9 +360,9 @@ void HotseatWidget::UpdateLayout(bool animate) {
animation_setter.SetPreemptionStrategy(
ui::LayerAnimator::IMMEDIATELY_ANIMATE_TO_NEW_TARGET);
layer->SetOpacity(CalculateOpacity());
SetBounds(
GetShelfView()->shelf()->shelf_layout_manager()->GetHotseatBounds());
layer->SetOpacity(new_layout_inputs.opacity);
SetBounds(new_layout_inputs.bounds);
layout_inputs_ = new_layout_inputs;
}
gfx::Size HotseatWidget::GetOpaqueBackgroundSize() const {
......@@ -411,4 +414,9 @@ void HotseatWidget::SetState(HotseatState state) {
}
}
HotseatWidget::LayoutInputs HotseatWidget::GetLayoutInputs() const {
return {GetShelfView()->shelf()->shelf_layout_manager()->GetHotseatBounds(),
CalculateOpacity()};
}
} // namespace ash
......@@ -8,6 +8,7 @@
#include "ash/ash_export.h"
#include "ash/public/cpp/shelf_config.h"
#include "ash/public/cpp/shelf_types.h"
#include "base/optional.h"
#include "ui/views/widget/widget.h"
namespace aura {
......@@ -58,7 +59,7 @@ class ASH_EXPORT HotseatWidget : public views::Widget,
void OnTabletModeChanged();
// Returns the target opacity (between 0 and 1) given current conditions.
float CalculateOpacity();
float CalculateOpacity() const;
// Sets the bounds of the opaque background which functions as the hotseat
// background.
......@@ -99,6 +100,23 @@ class ASH_EXPORT HotseatWidget : public views::Widget,
private:
class DelegateView;
struct LayoutInputs {
gfx::Rect bounds;
float opacity = 0.0f;
bool operator==(const LayoutInputs& other) const {
return bounds == other.bounds && opacity == other.opacity;
}
};
// Collects the inputs for layout.
LayoutInputs GetLayoutInputs() const;
// The set of inputs that impact this widget's layout. The assumption is that
// this widget needs a relayout if, and only if, one or more of these has
// changed.
base::Optional<LayoutInputs> layout_inputs_;
HotseatState state_ = HotseatState::kShown;
// View containing the shelf items within an active user session. Owned by
......
......@@ -489,7 +489,7 @@ void ShelfLayoutManager::LayoutShelf(bool animate) {
if (in_shutdown_)
return;
CalculateTargetBoundsAndUpdateWorkArea(hotseat_state());
CalculateTargetBoundsAndUpdateWorkArea();
UpdateBoundsAndOpacity(animate);
// Update insets in ShelfWindowTargeter when shelf bounds change.
......@@ -1031,7 +1031,7 @@ void ShelfLayoutManager::OnSessionStateChanged(
if (was_locked != state_.IsScreenLocked())
UpdateShelfVisibilityAfterLoginUIChange();
CalculateTargetBoundsAndUpdateWorkArea(hotseat_state());
CalculateTargetBoundsAndUpdateWorkArea();
UpdateBoundsAndOpacity(true /* animate */);
UpdateVisibilityState();
}
......@@ -1055,7 +1055,7 @@ void ShelfLayoutManager::OnDisplayMetricsChanged(
return;
// Update |user_work_area_bounds_| for the new display arrangement.
CalculateTargetBoundsAndUpdateWorkArea(hotseat_state());
CalculateTargetBoundsAndUpdateWorkArea();
}
void ShelfLayoutManager::OnLocaleChanged() {
......@@ -1167,7 +1167,7 @@ void ShelfLayoutManager::ResumeWorkAreaUpdate() {
UpdateVisibilityState();
CalculateTargetBoundsAndUpdateWorkArea(hotseat_state());
CalculateTargetBoundsAndUpdateWorkArea();
UpdateBoundsAndOpacity(/*animate=*/true);
MaybeUpdateShelfBackground(AnimationChangeType::ANIMATE);
}
......@@ -1175,7 +1175,6 @@ void ShelfLayoutManager::ResumeWorkAreaUpdate() {
void ShelfLayoutManager::SetState(ShelfVisibilityState visibility_state) {
if (suspend_visibility_update_)
return;
State state;
const HotseatState previous_hotseat_state = hotseat_state();
state.visibility_state = visibility_state;
......@@ -1183,7 +1182,8 @@ void ShelfLayoutManager::SetState(ShelfVisibilityState visibility_state) {
state.window_state =
GetShelfWorkspaceWindowState(shelf_widget_->GetNativeWindow());
HotseatState new_hotseat_state =
CalculateHotseatState(state.visibility_state, state.auto_hide_state);
CalculateHotseatState(visibility_state, state.auto_hide_state);
// Preserve the log in screen states.
state.session_state = state_.session_state;
state.pre_lock_screen_animation_active =
......@@ -1234,7 +1234,7 @@ void ShelfLayoutManager::SetState(ShelfVisibilityState visibility_state) {
if (!delay_background_change)
MaybeUpdateShelfBackground(change_type);
CalculateTargetBoundsAndUpdateWorkArea(new_hotseat_state);
CalculateTargetBoundsAndUpdateWorkArea();
UpdateBoundsAndOpacity(true /* animate */);
// OnAutoHideStateChanged Should be emitted when:
......@@ -1427,7 +1427,7 @@ void ShelfLayoutManager::SetDimmed(bool dimmed) {
return;
dimmed_for_inactivity_ = dimmed;
CalculateTargetBoundsAndUpdateWorkArea(hotseat_state());
CalculateTargetBoundsAndUpdateWorkArea();
AnimateOpacity(shelf_widget_->navigation_widget(), target_bounds_.opacity,
kDimAnimationDuration, gfx::Tween::LINEAR);
......@@ -1727,8 +1727,9 @@ void ShelfLayoutManager::CalculateTargetBounds(
}
}
void ShelfLayoutManager::CalculateTargetBoundsAndUpdateWorkArea(
HotseatState hotseat_target_state) {
void ShelfLayoutManager::CalculateTargetBoundsAndUpdateWorkArea() {
HotseatState hotseat_target_state =
CalculateHotseatState(visibility_state(), auto_hide_state());
CalculateTargetBounds(state_, hotseat_target_state);
gfx::Rect shelf_bounds_for_workarea_calculation = target_bounds_.shelf_bounds;
// When the hotseat is enabled, only use the in-app shelf bounds when
......
......@@ -408,10 +408,9 @@ class ASH_EXPORT ShelfLayoutManager
void CalculateTargetBounds(const State& state,
HotseatState hotseat_target_state);
// Calculates the target bounds using |state_|, |hotseat_target_state|, and
// updates the |user_work_area_bounds_|.
void CalculateTargetBoundsAndUpdateWorkArea(
HotseatState hotseat_target_state);
// Calculates the target bounds using |state_| and updates the
// |user_work_area_bounds_|.
void CalculateTargetBoundsAndUpdateWorkArea();
// Updates the target bounds if a gesture-drag is in progress. This is only
// used by |CalculateTargetBounds()|.
......
......@@ -68,8 +68,17 @@ const char* TrayContainer::GetClassName() const {
return "TrayContainer";
}
TrayContainer::LayoutInputs TrayContainer::GetLayoutInputs() const {
return {shelf_->IsHorizontalAlignment(),
ShelfConfig::Get()->status_area_hit_region_padding(),
GetAnchorBoundsInScreen(), main_axis_margin_, cross_axis_margin_};
}
void TrayContainer::UpdateLayout() {
const bool is_horizontal = shelf_->IsHorizontalAlignment();
const LayoutInputs new_layout_inputs = GetLayoutInputs();
if (layout_inputs_.has_value() && *layout_inputs_ == new_layout_inputs)
return;
const bool is_horizontal = new_layout_inputs.shelf_alignment_is_horizontal;
// Adjust the size of status tray dark background by adding additional
// empty border.
......@@ -79,13 +88,12 @@ void TrayContainer::UpdateLayout() {
gfx::Insets insets(
is_horizontal
? gfx::Insets(0, ShelfConfig::Get()->status_area_hit_region_padding())
: gfx::Insets(ShelfConfig::Get()->status_area_hit_region_padding(),
0));
? gfx::Insets(0, new_layout_inputs.status_area_hit_region_padding)
: gfx::Insets(new_layout_inputs.status_area_hit_region_padding, 0));
SetBorder(views::CreateEmptyBorder(insets));
int horizontal_margin = main_axis_margin_;
int vertical_margin = cross_axis_margin_;
int horizontal_margin = new_layout_inputs.main_axis_margin;
int vertical_margin = new_layout_inputs.cross_axis_margin;
if (!is_horizontal)
std::swap(horizontal_margin, vertical_margin);
......@@ -96,6 +104,7 @@ void TrayContainer::UpdateLayout() {
views::View::SetLayoutManager(std::move(layout));
PreferredSizeChanged();
layout_inputs_ = new_layout_inputs;
}
} // namespace ash
......@@ -6,6 +6,7 @@
#define ASH_SYSTEM_TRAY_TRAY_CONTAINER_H_
#include "base/macros.h"
#include "base/optional.h"
#include "ui/views/view.h"
namespace ash {
......@@ -32,8 +33,34 @@ class TrayContainer : public views::View {
const char* GetClassName() const override;
private:
struct LayoutInputs {
bool shelf_alignment_is_horizontal = true;
int status_area_hit_region_padding = 0;
gfx::Rect anchor_bounds_in_screen;
int main_axis_margin = 0;
int cross_axis_margin = 0;
bool operator==(const LayoutInputs& other) const {
return shelf_alignment_is_horizontal ==
other.shelf_alignment_is_horizontal &&
status_area_hit_region_padding ==
other.status_area_hit_region_padding &&
anchor_bounds_in_screen == other.anchor_bounds_in_screen &&
main_axis_margin == other.main_axis_margin &&
cross_axis_margin == other.cross_axis_margin;
}
};
// Collects the inputs for layout.
LayoutInputs GetLayoutInputs() const;
void UpdateLayout();
// The set of inputs that impact this widget's layout. The assumption is that
// this widget needs a relayout if, and only if, one or more of these has
// changed.
base::Optional<LayoutInputs> layout_inputs_;
Shelf* const shelf_;
int main_axis_margin_ = 0;
......
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