Commit 99f4e7a3 authored by Xiaoqian Dai's avatar Xiaoqian Dai Committed by Commit Bot

Cros splitscreen: do not show black backdrop on the non-snapped side of the...

Cros splitscreen: do not show black backdrop on the non-snapped side of the screen if there is only one snapped window.

Bug: 818310
Change-Id: I08ced2fcf88da0d65c01253880e7cd49c0d0913c
Reviewed-on: https://chromium-review.googlesource.com/953337Reviewed-by: default avatarMitsuru Oshima <oshima@chromium.org>
Commit-Queue: Xiaoqian Dai <xdai@chromium.org>
Cr-Commit-Position: refs/heads/master@{#543421}
parent 6fcdfef8
...@@ -350,6 +350,24 @@ gfx::Rect SplitViewController::GetDisplayWorkAreaBoundsInScreen( ...@@ -350,6 +350,24 @@ gfx::Rect SplitViewController::GetDisplayWorkAreaBoundsInScreen(
return bounds; return bounds;
} }
gfx::Rect SplitViewController::GetSnappedWindowBoundsInScreenUnadjusted(
aura::Window* window,
SnapPosition snap_position) {
const gfx::Rect work_area_bounds_in_screen =
GetDisplayWorkAreaBoundsInScreen(window);
if (snap_position == NONE)
return work_area_bounds_in_screen;
gfx::Rect left_or_top_rect, right_or_bottom_rect;
GetSnappedWindowBoundsInScreenInternal(window, &left_or_top_rect,
&right_or_bottom_rect);
if (IsCurrentScreenOrientationPrimary())
return (snap_position == LEFT) ? left_or_top_rect : right_or_bottom_rect;
else
return (snap_position == LEFT) ? right_or_bottom_rect : left_or_top_rect;
}
void SplitViewController::StartResize(const gfx::Point& location_in_screen) { void SplitViewController::StartResize(const gfx::Point& location_in_screen) {
DCHECK(IsSplitViewModeActive()); DCHECK(IsSplitViewModeActive());
is_resizing_ = true; is_resizing_ = true;
......
...@@ -104,7 +104,10 @@ class ASH_EXPORT SplitViewController : public mojom::SplitViewController, ...@@ -104,7 +104,10 @@ class ASH_EXPORT SplitViewController : public mojom::SplitViewController,
aura::Window* GetDefaultSnappedWindow(); aura::Window* GetDefaultSnappedWindow();
// Gets the window bounds according to the snap state |snap_state| and the // Gets the window bounds according to the snap state |snap_state| and the
// separator position |separator_position_|. // divider position |divider_position_|. The returned snapped window bounds
// are adjusted to its minimum size if the desired bounds are smaller than
// its minumum bounds. Note: the snapped window bounds can't be pushed
// outside of the workspace area.
gfx::Rect GetSnappedWindowBoundsInParent(aura::Window* window, gfx::Rect GetSnappedWindowBoundsInParent(aura::Window* window,
SnapPosition snap_position); SnapPosition snap_position);
gfx::Rect GetSnappedWindowBoundsInScreen(aura::Window* window, gfx::Rect GetSnappedWindowBoundsInScreen(aura::Window* window,
...@@ -112,6 +115,11 @@ class ASH_EXPORT SplitViewController : public mojom::SplitViewController, ...@@ -112,6 +115,11 @@ class ASH_EXPORT SplitViewController : public mojom::SplitViewController,
gfx::Rect GetDisplayWorkAreaBoundsInParent(aura::Window* window) const; gfx::Rect GetDisplayWorkAreaBoundsInParent(aura::Window* window) const;
gfx::Rect GetDisplayWorkAreaBoundsInScreen(aura::Window* window) const; gfx::Rect GetDisplayWorkAreaBoundsInScreen(aura::Window* window) const;
// Gets the desired snapped window bounds accoridng to the snap state
// |snap_state| and the divider pistion |divider_position_|.
gfx::Rect GetSnappedWindowBoundsInScreenUnadjusted(aura::Window* window,
SnapPosition snap_postion);
void StartResize(const gfx::Point& location_in_screen); void StartResize(const gfx::Point& location_in_screen);
void Resize(const gfx::Point& location_in_screen); void Resize(const gfx::Point& location_in_screen);
void EndResize(const gfx::Point& location_in_screen); void EndResize(const gfx::Point& location_in_screen);
......
...@@ -127,7 +127,6 @@ void BackdropController::UpdateBackdrop() { ...@@ -127,7 +127,6 @@ void BackdropController::UpdateBackdrop() {
if (window->GetRootWindow() != backdrop_window_->GetRootWindow()) if (window->GetRootWindow() != backdrop_window_->GetRootWindow())
return; return;
if (!backdrop_->IsVisible())
Show(); Show();
// Since the backdrop needs to be immediately behind the window and the // Since the backdrop needs to be immediately behind the window and the
...@@ -157,11 +156,29 @@ void BackdropController::OnAppListVisibilityChanged(bool shown, ...@@ -157,11 +156,29 @@ void BackdropController::OnAppListVisibilityChanged(bool shown,
RemoveForceHidden(); RemoveForceHidden();
} }
void BackdropController::OnSplitViewModeStarting() {
Shell::Get()->split_view_controller()->AddObserver(this);
}
void BackdropController::OnSplitViewModeEnded() {
Shell::Get()->split_view_controller()->RemoveObserver(this);
}
void BackdropController::OnAccessibilityStatusChanged( void BackdropController::OnAccessibilityStatusChanged(
AccessibilityNotificationVisibility notify) { AccessibilityNotificationVisibility notify) {
UpdateBackdrop(); UpdateBackdrop();
} }
void BackdropController::OnSplitViewStateChanged(
SplitViewController::State previous_state,
SplitViewController::State state) {
UpdateBackdrop();
}
void BackdropController::OnSplitViewDividerPositionChanged() {
UpdateBackdrop();
}
void BackdropController::EnsureBackdropWidget() { void BackdropController::EnsureBackdropWidget() {
if (backdrop_) if (backdrop_)
return; return;
...@@ -236,8 +253,12 @@ bool BackdropController::WindowShouldHaveBackdrop(aura::Window* window) { ...@@ -236,8 +253,12 @@ bool BackdropController::WindowShouldHaveBackdrop(aura::Window* window) {
} }
void BackdropController::Show() { void BackdropController::Show() {
// Makes sure that the backdrop has the correct bounds if it should not be
// fullscreen size.
backdrop_->SetFullscreen(BackdropShouldFullscreen());
if (!BackdropShouldFullscreen())
backdrop_->SetBounds(GetBackdropBounds());
backdrop_->Show(); backdrop_->Show();
backdrop_->SetFullscreen(true);
} }
void BackdropController::Hide() { void BackdropController::Hide() {
...@@ -268,4 +289,36 @@ void BackdropController::RemoveForceHidden() { ...@@ -268,4 +289,36 @@ void BackdropController::RemoveForceHidden() {
UpdateBackdrop(); UpdateBackdrop();
} }
bool BackdropController::BackdropShouldFullscreen() {
aura::Window* window = GetTopmostWindowWithBackdrop();
SplitViewController* split_view_controller =
Shell::Get()->split_view_controller();
SplitViewController::State state = split_view_controller->state();
if ((state == SplitViewController::LEFT_SNAPPED &&
window == split_view_controller->left_window()) ||
(state == SplitViewController::RIGHT_SNAPPED &&
window == split_view_controller->right_window())) {
return false;
}
return true;
}
gfx::Rect BackdropController::GetBackdropBounds() {
DCHECK(!BackdropShouldFullscreen());
SplitViewController* split_view_controller =
Shell::Get()->split_view_controller();
SplitViewController::State state = split_view_controller->state();
DCHECK(state == SplitViewController::LEFT_SNAPPED ||
state == SplitViewController::RIGHT_SNAPPED);
aura::Window* snapped_window =
split_view_controller->GetDefaultSnappedWindow();
SplitViewController::SnapPosition snap_position =
(state == SplitViewController::LEFT_SNAPPED) ? SplitViewController::LEFT
: SplitViewController::RIGHT;
return split_view_controller->GetSnappedWindowBoundsInScreenUnadjusted(
snapped_window, snap_position);
}
} // namespace ash } // namespace ash
...@@ -9,6 +9,7 @@ ...@@ -9,6 +9,7 @@
#include "ash/accessibility/accessibility_observer.h" #include "ash/accessibility/accessibility_observer.h"
#include "ash/shell_observer.h" #include "ash/shell_observer.h"
#include "ash/wm/splitview/split_view_controller.h"
#include "base/macros.h" #include "base/macros.h"
namespace aura { namespace aura {
...@@ -41,7 +42,9 @@ class BackdropDelegate; ...@@ -41,7 +42,9 @@ class BackdropDelegate;
// 1) Has a aura::client::kHasBackdrop property = true. // 1) Has a aura::client::kHasBackdrop property = true.
// 2) BackdropDelegate::HasBackdrop(aura::Window* window) returns true. // 2) BackdropDelegate::HasBackdrop(aura::Window* window) returns true.
// 3) Active ARC window when the spoken feedback is enabled. // 3) Active ARC window when the spoken feedback is enabled.
class BackdropController : public ShellObserver, public AccessibilityObserver { class BackdropController : public ShellObserver,
public AccessibilityObserver,
public SplitViewController::Observer {
public: public:
explicit BackdropController(aura::Window* container); explicit BackdropController(aura::Window* container);
~BackdropController() override; ~BackdropController() override;
...@@ -64,11 +67,18 @@ class BackdropController : public ShellObserver, public AccessibilityObserver { ...@@ -64,11 +67,18 @@ class BackdropController : public ShellObserver, public AccessibilityObserver {
void OnOverviewModeEnded() override; void OnOverviewModeEnded() override;
void OnAppListVisibilityChanged(bool shown, void OnAppListVisibilityChanged(bool shown,
aura::Window* root_window) override; aura::Window* root_window) override;
void OnSplitViewModeStarting() override;
void OnSplitViewModeEnded() override;
// AccessibilityObserver: // AccessibilityObserver:
void OnAccessibilityStatusChanged( void OnAccessibilityStatusChanged(
AccessibilityNotificationVisibility notify) override; AccessibilityNotificationVisibility notify) override;
// SplitViewController::Observer:
void OnSplitViewStateChanged(SplitViewController::State previous_state,
SplitViewController::State state) override;
void OnSplitViewDividerPositionChanged() override;
private: private:
friend class WorkspaceControllerTestApi; friend class WorkspaceControllerTestApi;
...@@ -93,6 +103,18 @@ class BackdropController : public ShellObserver, public AccessibilityObserver { ...@@ -93,6 +103,18 @@ class BackdropController : public ShellObserver, public AccessibilityObserver {
// Decrement |force_hidden_counter_| and then update backdrop state. // Decrement |force_hidden_counter_| and then update backdrop state.
void RemoveForceHidden(); void RemoveForceHidden();
// Returns true if the backdrop window should be fullscreen. It should not be
// fullscreen only if 1) split view is active and 2) there is only one snapped
// window and 3) the snapped window is the topmost window which should have
// the backdrop.
bool BackdropShouldFullscreen();
// Gets the bounds for the backdrop window if it should not be fullscreen.
// It's the case for splitview mode, if there is only one snapped window, the
// backdrop should not cover the non-snapped side of the screen, thus the
// backdrop bounds should be the bounds of the snapped window.
gfx::Rect GetBackdropBounds();
// The backdrop which covers the rest of the screen. // The backdrop which covers the rest of the screen.
views::Widget* backdrop_ = nullptr; views::Widget* backdrop_ = nullptr;
......
...@@ -1755,15 +1755,14 @@ TEST_F(WorkspaceLayoutManagerBackdropTest, BackdropForSplitScreenTest) { ...@@ -1755,15 +1755,14 @@ TEST_F(WorkspaceLayoutManagerBackdropTest, BackdropForSplitScreenTest) {
default_container()->children()[0]->bounds()); default_container()->children()[0]->bounds());
// Snap the window to left. Test that the backdrop window is still visible // Snap the window to left. Test that the backdrop window is still visible
// and is the second child in the container. Its bounds should still be the // and is the second child in the container. Its bounds should be the same
// same as the container bounds. // as the snapped window's bounds.
split_view_controller->SnapWindow(window1.get(), SplitViewController::LEFT); split_view_controller->SnapWindow(window1.get(), SplitViewController::LEFT);
EXPECT_EQ(2U, default_container()->children().size()); EXPECT_EQ(2U, default_container()->children().size());
for (auto* child : default_container()->children()) for (auto* child : default_container()->children())
EXPECT_TRUE(child->IsVisible()); EXPECT_TRUE(child->IsVisible());
EXPECT_EQ(window1.get(), default_container()->children()[1]); EXPECT_EQ(window1.get(), default_container()->children()[1]);
EXPECT_EQ(default_container()->bounds(), EXPECT_EQ(window1->bounds(), default_container()->children()[0]->bounds());
default_container()->children()[0]->bounds());
// Now snap another window to right. Test that the backdrop window is still // Now snap another window to right. Test that the backdrop window is still
// visible but is now the third window in the container. Its bounds should // visible but is now the third window in the container. Its bounds should
......
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