Commit c6c4cb32 authored by xdai's avatar xdai Committed by Commit Bot

Cros splitscreen: Observe display change even though split view mode is not active.

Otherwise |screen_orientation_| might not have the correct screen
orientation. For example:
- In landscape mode, enter overview mode, drag a window around but do
not snap it. The phantom window should show on left/right side of the
screen.
- Rotate the device to portrait mode
- Drag the window around again. The phantom window should show on the
top/bottom side of the screen. But instead it still shows on left/right
side of the screen.

Bug: 725683
Change-Id: I3f4710648c5c8f988b8561af3fd6f46d62c6e429
Reviewed-on: https://chromium-review.googlesource.com/726273Reviewed-by: default avatarMitsuru Oshima <oshima@chromium.org>
Commit-Queue: Xiaoqian Dai <xdai@chromium.org>
Cr-Commit-Position: refs/heads/master@{#510126}
parent 00fe5149
...@@ -66,9 +66,14 @@ bool IsLeftWindowOnTopOrLeftOfScreen( ...@@ -66,9 +66,14 @@ bool IsLeftWindowOnTopOrLeftOfScreen(
} // namespace } // namespace
SplitViewController::SplitViewController() {} SplitViewController::SplitViewController() {
screen_orientation_ =
Shell::Get()->screen_orientation_controller()->GetCurrentOrientation();
display::Screen::GetScreen()->AddObserver(this);
}
SplitViewController::~SplitViewController() { SplitViewController::~SplitViewController() {
display::Screen::GetScreen()->RemoveObserver(this);
EndSplitView(); EndSplitView();
} }
...@@ -131,12 +136,9 @@ void SplitViewController::SnapWindow(aura::Window* window, ...@@ -131,12 +136,9 @@ void SplitViewController::SnapWindow(aura::Window* window,
// Add observers when the split view mode starts. // Add observers when the split view mode starts.
Shell::Get()->AddShellObserver(this); Shell::Get()->AddShellObserver(this);
Shell::Get()->activation_client()->AddObserver(this); Shell::Get()->activation_client()->AddObserver(this);
display::Screen::GetScreen()->AddObserver(this);
Shell::Get()->tablet_mode_controller()->AddObserver(this); Shell::Get()->tablet_mode_controller()->AddObserver(this);
Shell::Get()->NotifySplitViewModeStarting(); Shell::Get()->NotifySplitViewModeStarting();
screen_orientation_ =
Shell::Get()->screen_orientation_controller()->GetCurrentOrientation();
divider_position_ = GetDefaultDividerPosition(window); divider_position_ = GetDefaultDividerPosition(window);
default_snap_position_ = snap_position; default_snap_position_ = snap_position;
split_view_divider_ = split_view_divider_ =
...@@ -218,12 +220,7 @@ gfx::Rect SplitViewController::GetSnappedWindowBoundsInScreen( ...@@ -218,12 +220,7 @@ gfx::Rect SplitViewController::GetSnappedWindowBoundsInScreen(
if (snap_position == NONE) if (snap_position == NONE)
return work_area_bounds_in_screen; return work_area_bounds_in_screen;
// |screen_orientation_| and |divide_position_| might not be properly // |divide_position_| might not be properly initialized yet.
// initialized yet.
if (screen_orientation_ == blink::kWebScreenOrientationLockDefault) {
screen_orientation_ =
Shell::Get()->screen_orientation_controller()->GetCurrentOrientation();
}
divider_position_ = (divider_position_ < 0) divider_position_ = (divider_position_ < 0)
? GetDefaultDividerPosition(window) ? GetDefaultDividerPosition(window)
: divider_position_; : divider_position_;
...@@ -324,7 +321,6 @@ void SplitViewController::EndSplitView() { ...@@ -324,7 +321,6 @@ void SplitViewController::EndSplitView() {
// Remove observers when the split view mode ends. // Remove observers when the split view mode ends.
Shell::Get()->RemoveShellObserver(this); Shell::Get()->RemoveShellObserver(this);
Shell::Get()->activation_client()->RemoveObserver(this); Shell::Get()->activation_client()->RemoveObserver(this);
display::Screen::GetScreen()->RemoveObserver(this);
Shell::Get()->tablet_mode_controller()->RemoveObserver(this); Shell::Get()->tablet_mode_controller()->RemoveObserver(this);
StopObserving(left_window_); StopObserving(left_window_);
...@@ -334,7 +330,6 @@ void SplitViewController::EndSplitView() { ...@@ -334,7 +330,6 @@ void SplitViewController::EndSplitView() {
split_view_divider_.reset(); split_view_divider_.reset();
black_scrim_layer_.reset(); black_scrim_layer_.reset();
default_snap_position_ = NONE; default_snap_position_ = NONE;
screen_orientation_ = blink::kWebScreenOrientationLockDefault;
divider_position_ = -1; divider_position_ = -1;
State previous_state = state_; State previous_state = state_;
...@@ -447,7 +442,18 @@ void SplitViewController::OnOverviewModeEnded() { ...@@ -447,7 +442,18 @@ void SplitViewController::OnOverviewModeEnded() {
void SplitViewController::OnDisplayMetricsChanged( void SplitViewController::OnDisplayMetricsChanged(
const display::Display& display, const display::Display& display,
uint32_t metrics) { uint32_t metrics) {
DCHECK(IsSplitViewModeActive()); if (!display.IsInternal())
return;
// We need update |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();
if (!IsSplitViewModeActive())
return;
display::Display current_display = display::Display current_display =
display::Screen::GetScreen()->GetDisplayNearestWindow( display::Screen::GetScreen()->GetDisplayNearestWindow(
...@@ -463,11 +469,6 @@ void SplitViewController::OnDisplayMetricsChanged( ...@@ -463,11 +469,6 @@ void SplitViewController::OnDisplayMetricsChanged(
return; return;
} }
blink::WebScreenOrientationLockType previous_screen_orientation =
screen_orientation_;
screen_orientation_ =
Shell::Get()->screen_orientation_controller()->GetCurrentOrientation();
// Update |divider_position_| if the top/left window changes. // Update |divider_position_| if the top/left window changes.
if ((metrics & (display::DisplayObserver::DISPLAY_METRIC_ROTATION)) && if ((metrics & (display::DisplayObserver::DISPLAY_METRIC_ROTATION)) &&
(IsLeftWindowOnTopOrLeftOfScreen(previous_screen_orientation) != (IsLeftWindowOnTopOrLeftOfScreen(previous_screen_orientation) !=
......
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