Skip to content

Commit

Permalink
[Merge to M66] Cros splitscreen: Use current screen orientation inste…
Browse files Browse the repository at this point in the history
…ad of cached screen orientation when calculating snapped window bounds.

It's possible that there is a dismatch between the current screen
orientation and the cached screen orientation in SplitViewController.

Bug: 799609
[email protected]

(cherry picked from commit 57903fc)

Change-Id: I484324e4716b51239c40a9d482f9b7f85ced0627
Reviewed-on: https://chromium-review.googlesource.com/947665
Commit-Queue: Xiaoqian Dai <[email protected]>
Reviewed-by: Mitsuru Oshima <[email protected]>
Cr-Original-Commit-Position: refs/heads/master@{#541001}
Reviewed-on: https://chromium-review.googlesource.com/953136
Reviewed-by: Xiaoqian Dai <[email protected]>
Cr-Commit-Position: refs/branch-heads/3359@{#67}
Cr-Branched-From: 66afc5e-refs/heads/master@{#540276}
  • Loading branch information
Xiaoqian Dai committed Mar 7, 2018
1 parent 58b43c8 commit 5dd5b5f
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 28 deletions.
2 changes: 1 addition & 1 deletion ash/wm/overview/overview_window_drag_controller.cc
Original file line number Diff line number Diff line change
Expand Up @@ -229,7 +229,7 @@ SplitViewController::SnapPosition OverviewWindowDragController::GetSnapPosition(
screen_util::GetDisplayWorkAreaBoundsInParent(item_->GetWindow()));
::wm::ConvertRectToScreen(item_->GetWindow()->GetRootWindow(), &area);

switch (split_view_controller_->screen_orientation()) {
switch (split_view_controller_->GetCurrentScreenOrientation()) {
case blink::kWebScreenOrientationLockLandscapePrimary:
case blink::kWebScreenOrientationLockLandscapeSecondary: {
// The window can be snapped if it reaches close enough to the screen
Expand Down
50 changes: 30 additions & 20 deletions ash/wm/splitview/split_view_controller.cc
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,14 @@ bool IsPrimaryScreenOrientation(
screen_orientation == blink::kWebScreenOrientationLockPortraitPrimary;
}

bool IsLandscapeOrientation(
blink::WebScreenOrientationLockType screen_orientation) {
return screen_orientation ==
blink::kWebScreenOrientationLockLandscapePrimary ||
screen_orientation ==
blink::kWebScreenOrientationLockLandscapeSecondary;
}

// Returns the minimum size of the window according to the screen orientation.
int GetMinimumWindowSize(aura::Window* window, bool is_landscape) {
int minimum_width = 0;
Expand All @@ -141,8 +149,6 @@ int GetMinimumWindowSize(aura::Window* window, bool is_landscape) {
} // namespace

SplitViewController::SplitViewController() {
screen_orientation_ =
Shell::Get()->screen_orientation_controller()->GetCurrentOrientation();
display::Screen::GetScreen()->AddObserver(this);
}

Expand Down Expand Up @@ -193,15 +199,17 @@ bool SplitViewController::IsSplitViewModeActive() const {
return state_ != NO_SNAP;
}

blink::WebScreenOrientationLockType
SplitViewController::GetCurrentScreenOrientation() const {
return Shell::Get()->screen_orientation_controller()->GetCurrentOrientation();
}

bool SplitViewController::IsCurrentScreenOrientationLandscape() const {
return screen_orientation_ ==
blink::kWebScreenOrientationLockLandscapePrimary ||
screen_orientation_ ==
blink::kWebScreenOrientationLockLandscapeSecondary;
return IsLandscapeOrientation(GetCurrentScreenOrientation());
}

bool SplitViewController::IsCurrentScreenOrientationPrimary() const {
return IsPrimaryScreenOrientation(screen_orientation_);
return IsPrimaryScreenOrientation(GetCurrentScreenOrientation());
}

void SplitViewController::SnapWindow(aura::Window* window,
Expand Down Expand Up @@ -608,12 +616,11 @@ void SplitViewController::OnDisplayMetricsChanged(
if (!display.IsInternal())
return;

// We need update |screen_orientation_| even though split view mode is not
// active at the moment.
// We need update |previous_screen_orientation_| even though split view mode
// is not active at the moment.
blink::WebScreenOrientationLockType previous_screen_orientation =
screen_orientation_;
screen_orientation_ =
Shell::Get()->screen_orientation_controller()->GetCurrentOrientation();
previous_screen_orientation_;
previous_screen_orientation_ = GetCurrentScreenOrientation();

if (!IsSplitViewModeActive())
return;
Expand All @@ -635,10 +642,11 @@ void SplitViewController::OnDisplayMetricsChanged(
// Update |divider_position_| if the top/left window changes.
if ((metrics & (display::DisplayObserver::DISPLAY_METRIC_ROTATION)) &&
(IsPrimaryScreenOrientation(previous_screen_orientation) !=
IsPrimaryScreenOrientation(screen_orientation_))) {
IsCurrentScreenOrientationPrimary())) {
const int work_area_long_length = GetDividerEndPosition();
const gfx::Size divider_size = SplitViewDivider::GetDividerSize(
display.work_area(), screen_orientation_, false /* is_dragging */);
display.work_area(), GetCurrentScreenOrientation(),
false /* is_dragging */);
const int divider_short_length =
std::min(divider_size.width(), divider_size.height());
divider_position_ =
Expand Down Expand Up @@ -696,7 +704,8 @@ int SplitViewController::GetDefaultDividerPosition(aura::Window* window) const {
const gfx::Rect work_area_bounds_in_screen =
GetDisplayWorkAreaBoundsInScreen(window);
const gfx::Size divider_size = SplitViewDivider::GetDividerSize(
work_area_bounds_in_screen, screen_orientation_, false /* is_dragging */);
work_area_bounds_in_screen, GetCurrentScreenOrientation(),
false /* is_dragging */);
if (IsCurrentScreenOrientationLandscape())
return (work_area_bounds_in_screen.width() - divider_size.width()) * 0.5f;
else
Expand Down Expand Up @@ -835,8 +844,8 @@ void SplitViewController::GetSnappedWindowBoundsInScreenInternal(
? GetDefaultDividerPosition(window)
: divider_position_;
const gfx::Rect divider_bounds = SplitViewDivider::GetDividerBoundsInScreen(
work_area_bounds_in_screen, screen_orientation_, divider_position_,
false /* is_dragging */);
work_area_bounds_in_screen, GetCurrentScreenOrientation(),
divider_position_, false /* is_dragging */);

SplitRect(work_area_bounds_in_screen, divider_bounds,
IsCurrentScreenOrientationLandscape(), left_or_top_rect,
Expand Down Expand Up @@ -874,7 +883,8 @@ void SplitViewController::MoveDividerToClosestFixedPosition() {
const gfx::Rect work_area_bounds_in_screen =
GetDisplayWorkAreaBoundsInScreen(GetDefaultSnappedWindow());
const gfx::Size divider_size = SplitViewDivider::GetDividerSize(
work_area_bounds_in_screen, screen_orientation_, false /* is_dragging */);
work_area_bounds_in_screen, GetCurrentScreenOrientation(),
false /* is_dragging */);
const int divider_thickness =
std::min(divider_size.width(), divider_size.height());

Expand Down Expand Up @@ -1045,7 +1055,7 @@ aura::Window* SplitViewController::GetWindowForSmoothResize() {

int SplitViewController::GetWindowComponentForResize(aura::Window* window) {
if (window && (window == left_window_ || window == right_window_)) {
switch (screen_orientation_) {
switch (GetCurrentScreenOrientation()) {
case blink::kWebScreenOrientationLockLandscapePrimary:
return (window == left_window_) ? HTRIGHT : HTLEFT;
case blink::kWebScreenOrientationLockLandscapeSecondary:
Expand All @@ -1071,7 +1081,7 @@ gfx::Point SplitViewController::GetEndDragLocationInScreen(
const gfx::Rect bounds = (window == left_window_)
? GetSnappedWindowBoundsInScreen(window, LEFT)
: GetSnappedWindowBoundsInScreen(window, RIGHT);
switch (screen_orientation_) {
switch (GetCurrentScreenOrientation()) {
case blink::kWebScreenOrientationLockLandscapePrimary:
end_location.set_x(window == left_window_ ? bounds.right() : bounds.x());
break;
Expand Down
9 changes: 4 additions & 5 deletions ash/wm/splitview/split_view_controller.h
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,8 @@ class ASH_EXPORT SplitViewController : public mojom::SplitViewController,
// Returns true if split view mode is active.
bool IsSplitViewModeActive() const;

blink::WebScreenOrientationLockType GetCurrentScreenOrientation() const;

// Returns true if |screen_orientation_| is a landscape orientation.
bool IsCurrentScreenOrientationLandscape() const;

Expand Down Expand Up @@ -158,9 +160,6 @@ class ASH_EXPORT SplitViewController : public mojom::SplitViewController,
SnapPosition default_snap_position() const { return default_snap_position_; }
SplitViewDivider* split_view_divider() { return split_view_divider_.get(); }
bool is_resizing() const { return is_resizing_; }
blink::WebScreenOrientationLockType screen_orientation() const {
return screen_orientation_;
}

private:
friend class SplitViewControllerTest;
Expand Down Expand Up @@ -324,8 +323,8 @@ class ASH_EXPORT SplitViewController : public mojom::SplitViewController,
// versa.
SnapPosition default_snap_position_ = NONE;

// The current orientation of the screen.
blink::WebScreenOrientationLockType screen_orientation_ =
// The previous orientation of the screen.
blink::WebScreenOrientationLockType previous_screen_orientation_ =
blink::kWebScreenOrientationLockDefault;

// If the divider is currently being dragging.
Expand Down
2 changes: 1 addition & 1 deletion ash/wm/splitview/split_view_controller_unittest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ class SplitViewControllerTest : public AshTestBase {
}

blink::WebScreenOrientationLockType screen_orientation() {
return split_view_controller()->screen_orientation();
return split_view_controller()->GetCurrentScreenOrientation();
}

int divider_position() { return split_view_controller()->divider_position(); }
Expand Down
2 changes: 1 addition & 1 deletion ash/wm/splitview/split_view_divider.cc
Original file line number Diff line number Diff line change
Expand Up @@ -260,7 +260,7 @@ gfx::Rect SplitViewDivider::GetDividerBoundsInScreen(bool is_dragging) {
controller_->GetDisplayWorkAreaBoundsInScreen(root_window);
const int divider_position = controller_->divider_position();
const blink::WebScreenOrientationLockType screen_orientation =
controller_->screen_orientation();
controller_->GetCurrentScreenOrientation();
return GetDividerBoundsInScreen(work_area_bounds_in_screen,
screen_orientation, divider_position,
is_dragging);
Expand Down

0 comments on commit 5dd5b5f

Please sign in to comment.