Commit 1a6a0bd5 authored by Angus L. M. McLean IV's avatar Angus L. M. McLean IV Committed by Commit Bot

Move volume/mic/brightness slider when auto-hidden shelf is shown

This prevents the slider views from awkwardly overlapping with the
shelf.

Bug: 1136564
Change-Id: I83551c6c5c2efb244d245a1055238ba6841d96c6
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2499641
Commit-Queue: Angus McLean <angusmclean@chromium.org>
Reviewed-by: default avatarToni Baržić <tbarzic@chromium.org>
Reviewed-by: default avatarTim Song <tengs@chromium.org>
Cr-Commit-Position: refs/heads/master@{#823297}
parent ae840aee
...@@ -304,6 +304,7 @@ class ASH_EXPORT ShelfLayoutManager ...@@ -304,6 +304,7 @@ class ASH_EXPORT ShelfLayoutManager
friend class ShelfLayoutManagerTestBase; friend class ShelfLayoutManagerTestBase;
friend class ShelfLayoutManagerWindowDraggingTest; friend class ShelfLayoutManagerWindowDraggingTest;
friend class NotificationTrayTest; friend class NotificationTrayTest;
friend class UnifiedSystemTrayTest;
friend class Shelf; friend class Shelf;
struct State { struct State {
......
...@@ -44,11 +44,13 @@ UnifiedSliderBubbleController::UnifiedSliderBubbleController( ...@@ -44,11 +44,13 @@ UnifiedSliderBubbleController::UnifiedSliderBubbleController(
: tray_(tray) { : tray_(tray) {
CrasAudioHandler::Get()->AddAudioObserver(this); CrasAudioHandler::Get()->AddAudioObserver(this);
tray_->model()->AddObserver(this); tray_->model()->AddObserver(this);
tray_->shelf()->AddObserver(this);
} }
UnifiedSliderBubbleController::~UnifiedSliderBubbleController() { UnifiedSliderBubbleController::~UnifiedSliderBubbleController() {
CrasAudioHandler::Get()->RemoveAudioObserver(this); CrasAudioHandler::Get()->RemoveAudioObserver(this);
tray_->model()->RemoveObserver(this); tray_->model()->RemoveObserver(this);
tray_->shelf()->RemoveObserver(this);
autoclose_.Stop(); autoclose_.Stop();
slider_controller_.reset(); slider_controller_.reset();
if (bubble_widget_) if (bubble_widget_)
...@@ -111,6 +113,11 @@ void UnifiedSliderBubbleController::OnAudioSettingsButtonClicked() { ...@@ -111,6 +113,11 @@ void UnifiedSliderBubbleController::OnAudioSettingsButtonClicked() {
tray_->ShowAudioDetailedViewBubble(); tray_->ShowAudioDetailedViewBubble();
} }
void UnifiedSliderBubbleController::OnShelfWorkAreaInsetsChanged() {
if (bubble_view_)
bubble_view_->ChangeAnchorRect(tray_->shelf()->GetSystemTrayAnchorRect());
}
void UnifiedSliderBubbleController::ShowBubble(SliderType slider_type) { void UnifiedSliderBubbleController::ShowBubble(SliderType slider_type) {
// Never show slider bubble in kiosk app mode. // Never show slider bubble in kiosk app mode.
if (Shell::Get()->session_controller()->IsRunningInAppMode()) if (Shell::Get()->session_controller()->IsRunningInAppMode())
......
...@@ -6,6 +6,7 @@ ...@@ -6,6 +6,7 @@
#define ASH_SYSTEM_UNIFIED_UNIFIED_SLIDER_BUBBLE_CONTROLLER_H_ #define ASH_SYSTEM_UNIFIED_UNIFIED_SLIDER_BUBBLE_CONTROLLER_H_
#include "ash/ash_export.h" #include "ash/ash_export.h"
#include "ash/shelf/shelf_observer.h"
#include "ash/system/audio/unified_volume_slider_controller.h" #include "ash/system/audio/unified_volume_slider_controller.h"
#include "ash/system/tray/tray_bubble_view.h" #include "ash/system/tray/tray_bubble_view.h"
#include "ash/system/unified/unified_system_tray_model.h" #include "ash/system/unified/unified_system_tray_model.h"
...@@ -23,7 +24,8 @@ class ASH_EXPORT UnifiedSliderBubbleController ...@@ -23,7 +24,8 @@ class ASH_EXPORT UnifiedSliderBubbleController
: public TrayBubbleView::Delegate, : public TrayBubbleView::Delegate,
public chromeos::CrasAudioHandler::AudioObserver, public chromeos::CrasAudioHandler::AudioObserver,
public UnifiedSystemTrayModel::Observer, public UnifiedSystemTrayModel::Observer,
public UnifiedVolumeSliderController::Delegate { public UnifiedVolumeSliderController::Delegate,
public ShelfObserver {
public: public:
enum SliderType { enum SliderType {
SLIDER_TYPE_VOLUME = 0, SLIDER_TYPE_VOLUME = 0,
...@@ -59,6 +61,9 @@ class ASH_EXPORT UnifiedSliderBubbleController ...@@ -59,6 +61,9 @@ class ASH_EXPORT UnifiedSliderBubbleController
// UnifiedVolumeSliderController::Delegate: // UnifiedVolumeSliderController::Delegate:
void OnAudioSettingsButtonClicked() override; void OnAudioSettingsButtonClicked() override;
// ShelfObserver:
void OnShelfWorkAreaInsetsChanged() override;
private: private:
friend class UnifiedSystemTrayTest; friend class UnifiedSystemTrayTest;
......
...@@ -4,6 +4,8 @@ ...@@ -4,6 +4,8 @@
#include "ash/system/unified/unified_system_tray.h" #include "ash/system/unified/unified_system_tray.h"
#include "ash/shelf/shelf.h"
#include "ash/shelf/shelf_layout_manager.h"
#include "ash/system/status_area_widget.h" #include "ash/system/status_area_widget.h"
#include "ash/system/status_area_widget_test_helper.h" #include "ash/system/status_area_widget_test_helper.h"
#include "ash/system/unified/unified_slider_bubble_controller.h" #include "ash/system/unified/unified_slider_bubble_controller.h"
...@@ -34,6 +36,16 @@ class UnifiedSystemTrayTest : public AshTestBase { ...@@ -34,6 +36,16 @@ class UnifiedSystemTrayTest : public AshTestBase {
return GetPrimaryUnifiedSystemTray()->bubble_.get(); return GetPrimaryUnifiedSystemTray()->bubble_.get();
} }
void UpdateAutoHideStateNow() {
GetPrimaryShelf()->shelf_layout_manager()->UpdateAutoHideStateNow();
}
gfx::Rect GetBubbleViewBounds() {
auto* bubble =
GetPrimaryUnifiedSystemTray()->slider_bubble_controller_->bubble_view_;
return bubble ? bubble->GetBoundsInScreen() : gfx::Rect();
}
private: private:
DISALLOW_COPY_AND_ASSIGN(UnifiedSystemTrayTest); DISALLOW_COPY_AND_ASSIGN(UnifiedSystemTrayTest);
}; };
...@@ -59,6 +71,78 @@ TEST_F(UnifiedSystemTrayTest, ShowVolumeSliderBubble) { ...@@ -59,6 +71,78 @@ TEST_F(UnifiedSystemTrayTest, ShowVolumeSliderBubble) {
EXPECT_FALSE(status->ShouldShowShelf()); EXPECT_FALSE(status->ShouldShowShelf());
} }
TEST_F(UnifiedSystemTrayTest, SliderBubbleMovesOnShelfAutohide) {
// The slider button should be moved when the autohidden shelf is shown, so
// as to not overlap. Regression test for crbug.com/1136564
auto* shelf = GetPrimaryShelf();
shelf->SetAlignment(ShelfAlignment::kBottom);
shelf->SetAutoHideBehavior(ShelfAutoHideBehavior::kAlways);
// Create a test widget to make auto-hiding work. Auto-hidden shelf will
// remain visible if no windows are shown, making it impossible to properly
// test.
views::Widget::InitParams params(views::Widget::InitParams::TYPE_WINDOW);
params.bounds = gfx::Rect(0, 0, 200, 200);
params.context = GetContext();
views::Widget* widget = new views::Widget;
widget->Init(std::move(params));
widget->Show();
// Start off the mouse nowhere near the shelf; the shelf should be hidden.
display::Display display = display::Screen::GetScreen()->GetPrimaryDisplay();
auto center = display.bounds().CenterPoint();
auto bottom_center = display.bounds().bottom_center();
bottom_center.set_y(bottom_center.y() - 1);
ui::test::EventGenerator* generator = GetEventGenerator();
generator->MoveMouseTo(center);
UpdateAutoHideStateNow();
GetPrimaryUnifiedSystemTray()->ShowVolumeSliderBubble();
gfx::Rect before_bounds = GetBubbleViewBounds();
// Now move the mouse close to the edge, so that the shelf shows, and verify
// that the volume slider adjusts accordingly.
generator->MoveMouseTo(bottom_center);
UpdateAutoHideStateNow();
gfx::Rect after_bounds = GetBubbleViewBounds();
EXPECT_NE(after_bounds, before_bounds);
// Also verify that the shelf and slider bubble would have overlapped, but do
// not now that we've moved the slider bubble.
gfx::Rect shelf_bounds = shelf->GetShelfBoundsInScreen();
EXPECT_TRUE(before_bounds.Intersects(shelf_bounds));
EXPECT_FALSE(after_bounds.Intersects(shelf_bounds));
// Move the mouse away and verify that it adjusts back to its original
// position.
generator->MoveMouseTo(center);
UpdateAutoHideStateNow();
after_bounds = GetBubbleViewBounds();
EXPECT_EQ(after_bounds, before_bounds);
// Now fullscreen and restore our window with autohide disabled and verify
// that the bubble moves down as the shelf disappears and reappears. Disable
// autohide so that the shelf is initially showing.
shelf->SetAlignment(ShelfAlignment::kRight);
after_bounds = GetBubbleViewBounds();
EXPECT_NE(after_bounds, before_bounds);
shelf->SetAlignment(ShelfAlignment::kBottom);
after_bounds = GetBubbleViewBounds();
EXPECT_EQ(after_bounds, before_bounds);
// Adjust the alignment of the shelf, and verify that the bubble moves along
// with it.
shelf->SetAutoHideBehavior(ShelfAutoHideBehavior::kNever);
before_bounds = GetBubbleViewBounds();
widget->SetFullscreen(true);
after_bounds = GetBubbleViewBounds();
EXPECT_NE(after_bounds, before_bounds);
widget->SetFullscreen(false);
after_bounds = GetBubbleViewBounds();
EXPECT_EQ(after_bounds, before_bounds);
}
TEST_F(UnifiedSystemTrayTest, ShowBubble_MultipleDisplays_OpenedOnSameDisplay) { TEST_F(UnifiedSystemTrayTest, ShowBubble_MultipleDisplays_OpenedOnSameDisplay) {
// Initialize two displays with 800x800 resolution. // Initialize two displays with 800x800 resolution.
UpdateDisplay("400+400-800x600,1220+400-800x600"); UpdateDisplay("400+400-800x600,1220+400-800x600");
......
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