Commit 9273c976 authored by Xiyuan Xia's avatar Xiyuan Xia Committed by Commit Bot

ash: Add ShelfObserver::OnShelfWorkAreaInsetsChanged

- Add ShelfLayoutManager::OnWorkAreaInsetsChanged that notifies
  Shelf when it updates the Shelf insets in WorkAreaInsets;
- Add ShelfObserver::OnShelfWorkAreaInsetsChanged that gets called
  when Shelf gets a OnWorkAreaInsetsChanged call;
- AshPopupAlignmentDelegate observes OnShelfWorkAreaInsetsChanged
  and update its work area instead Shelf visibility or autohide
  state change;

Bug: 1002003
Change-Id: I1239713a1d1dd7c27d84cfe4f81621f4ab638ecf
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1795907
Commit-Queue: Xiyuan Xia <xiyuan@chromium.org>
Reviewed-by: default avatarManu Cornet <manucornet@chromium.org>
Reviewed-by: default avatarEvan Stade <estade@chromium.org>
Cr-Commit-Position: refs/heads/master@{#695332}
parent b955580a
...@@ -391,6 +391,11 @@ void Shelf::OnBackgroundUpdated(ShelfBackgroundType background_type, ...@@ -391,6 +391,11 @@ void Shelf::OnBackgroundUpdated(ShelfBackgroundType background_type,
observer.OnBackgroundTypeChanged(background_type, change_type); observer.OnBackgroundTypeChanged(background_type, change_type);
} }
void Shelf::OnWorkAreaInsetsChanged() {
for (auto& observer : observers_)
observer.OnShelfWorkAreaInsetsChanged();
}
WorkAreaInsets* Shelf::GetWorkAreaInsets() const { WorkAreaInsets* Shelf::GetWorkAreaInsets() const {
const aura::Window* window = GetWindow(); const aura::Window* window = GetWindow();
DCHECK(window); DCHECK(window);
......
...@@ -189,6 +189,7 @@ class ASH_EXPORT Shelf : public ShelfLayoutManagerObserver { ...@@ -189,6 +189,7 @@ class ASH_EXPORT Shelf : public ShelfLayoutManagerObserver {
void OnAutoHideStateChanged(ShelfAutoHideState new_state) override; void OnAutoHideStateChanged(ShelfAutoHideState new_state) override;
void OnBackgroundUpdated(ShelfBackgroundType background_type, void OnBackgroundUpdated(ShelfBackgroundType background_type,
AnimationChangeType change_type) override; AnimationChangeType change_type) override;
void OnWorkAreaInsetsChanged() override;
private: private:
class AutoHideEventHandler; class AutoHideEventHandler;
......
...@@ -1452,6 +1452,8 @@ void ShelfLayoutManager::CalculateTargetBoundsAndUpdateWorkArea( ...@@ -1452,6 +1452,8 @@ void ShelfLayoutManager::CalculateTargetBoundsAndUpdateWorkArea(
WorkAreaInsets::ForWindow(shelf_widget_->GetNativeWindow()) WorkAreaInsets::ForWindow(shelf_widget_->GetNativeWindow())
->SetShelfBoundsAndInsets(target_bounds->shelf_bounds, ->SetShelfBoundsAndInsets(target_bounds->shelf_bounds,
target_bounds->shelf_insets); target_bounds->shelf_insets);
for (auto& observer : observers_)
observer.OnWorkAreaInsetsChanged();
} }
void ShelfLayoutManager::UpdateTargetBoundsForGesture( void ShelfLayoutManager::UpdateTargetBoundsForGesture(
......
...@@ -32,6 +32,10 @@ class ASH_EXPORT ShelfLayoutManagerObserver { ...@@ -32,6 +32,10 @@ class ASH_EXPORT ShelfLayoutManagerObserver {
// Called when the hotseat state changes. // Called when the hotseat state changes.
virtual void OnHotseatStateChanged(HotseatState state) {} virtual void OnHotseatStateChanged(HotseatState state) {}
// Called when ShelfLayoutManager has updated Shelf insets in work area
// insets.
virtual void OnWorkAreaInsetsChanged() {}
}; };
} // namespace ash } // namespace ash
......
...@@ -15,12 +15,22 @@ enum class AnimationChangeType; ...@@ -15,12 +15,22 @@ enum class AnimationChangeType;
// Used to observe changes to the shelf. // Used to observe changes to the shelf.
class ASH_EXPORT ShelfObserver { class ASH_EXPORT ShelfObserver {
public: public:
// Invoked when background type is changed.
virtual void OnBackgroundTypeChanged(ShelfBackgroundType background_type, virtual void OnBackgroundTypeChanged(ShelfBackgroundType background_type,
AnimationChangeType change_type) {} AnimationChangeType change_type) {}
// Invoked when Shelf's visibility state will be changed to |new_state|.
virtual void WillChangeVisibilityState(ShelfVisibilityState new_state) {} virtual void WillChangeVisibilityState(ShelfVisibilityState new_state) {}
// Invoked when Shelf's auto hide state is changed to |new_state|.
virtual void OnAutoHideStateChanged(ShelfAutoHideState new_state) {} virtual void OnAutoHideStateChanged(ShelfAutoHideState new_state) {}
// Invoked when the positions of Shelf Icons are changed.
virtual void OnShelfIconPositionsChanged() {} virtual void OnShelfIconPositionsChanged() {}
// Invoked when the Shelf has updated its insets in work area insets.
virtual void OnShelfWorkAreaInsetsChanged() {}
protected: protected:
virtual ~ShelfObserver() {} virtual ~ShelfObserver() {}
}; };
......
...@@ -147,13 +147,7 @@ void AshPopupAlignmentDelegate::UpdateWorkArea() { ...@@ -147,13 +147,7 @@ void AshPopupAlignmentDelegate::UpdateWorkArea() {
/////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////
// ShelfObserver: // ShelfObserver:
void AshPopupAlignmentDelegate::WillChangeVisibilityState( void AshPopupAlignmentDelegate::OnShelfWorkAreaInsetsChanged() {
ShelfVisibilityState new_state) {
UpdateWorkArea();
}
void AshPopupAlignmentDelegate::OnAutoHideStateChanged(
ShelfAutoHideState new_state) {
UpdateWorkArea(); UpdateWorkArea();
} }
......
...@@ -73,8 +73,7 @@ class ASH_EXPORT AshPopupAlignmentDelegate ...@@ -73,8 +73,7 @@ class ASH_EXPORT AshPopupAlignmentDelegate
void UpdateWorkArea(); void UpdateWorkArea();
// ShelfObserver: // ShelfObserver:
void WillChangeVisibilityState(ShelfVisibilityState new_state) override; void OnShelfWorkAreaInsetsChanged() override;
void OnAutoHideStateChanged(ShelfAutoHideState new_state) override;
// Overridden from display::DisplayObserver: // Overridden from display::DisplayObserver:
void OnDisplayMetricsChanged(const display::Display& display, void OnDisplayMetricsChanged(const display::Display& display,
......
...@@ -18,6 +18,7 @@ ...@@ -18,6 +18,7 @@
#include "ash/shell.h" #include "ash/shell.h"
#include "ash/test/ash_test_base.h" #include "ash/test/ash_test_base.h"
#include "ash/wm/desks/desks_util.h" #include "ash/wm/desks/desks_util.h"
#include "ash/wm/overview/overview_controller.h"
#include "base/command_line.h" #include "base/command_line.h"
#include "ui/display/manager/display_manager.h" #include "ui/display/manager/display_manager.h"
#include "ui/display/screen.h" #include "ui/display/screen.h"
...@@ -252,4 +253,31 @@ TEST_F(AshPopupAlignmentDelegateTest, KeyboardShowing) { ...@@ -252,4 +253,31 @@ TEST_F(AshPopupAlignmentDelegateTest, KeyboardShowing) {
EXPECT_EQ(baseline, alignment_delegate()->GetBaseline()); EXPECT_EQ(baseline, alignment_delegate()->GetBaseline());
} }
// Tests that notification bubble baseline is correct when entering and exiting
// overview with a full screen window.
TEST_F(AshPopupAlignmentDelegateTest, BaselineInOverview) {
UpdateDisplay("800x600");
ASSERT_TRUE(GetPrimaryShelf()->IsHorizontalAlignment());
ASSERT_EQ(SHELF_VISIBLE, GetPrimaryShelf()->GetVisibilityState());
const int baseline_with_visible_shelf = alignment_delegate()->GetBaseline();
std::unique_ptr<views::Widget> widget = CreateTestWidget();
widget->SetFullscreen(true);
ASSERT_EQ(SHELF_HIDDEN, GetPrimaryShelf()->GetVisibilityState());
const int baseline_with_hidden_shelf = alignment_delegate()->GetBaseline();
EXPECT_NE(baseline_with_visible_shelf, baseline_with_hidden_shelf);
auto* overview_controller = Shell::Get()->overview_controller();
overview_controller->StartOverview();
EXPECT_TRUE(overview_controller->InOverviewSession());
const int baseline_in_overview = alignment_delegate()->GetBaseline();
EXPECT_EQ(baseline_in_overview, baseline_with_visible_shelf);
overview_controller->EndOverview();
EXPECT_FALSE(overview_controller->InOverviewSession());
const int baseline_no_overview = alignment_delegate()->GetBaseline();
EXPECT_EQ(baseline_no_overview, baseline_with_hidden_shelf);
}
} // namespace ash } // namespace ash
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