Commit ca6c0161 authored by Avery Musbach's avatar Avery Musbach Committed by Commit Bot

split view: Change initial value of divider_closest_ratio_ from 0 to NaN

Before the present CL, SplitViewController::OnDisplayMetricsChanged
checks divider_closest_ratio_ against its initial value zero, which is
actually a "legitimate" value (it represents the divider position at the
extreme left or top). The present CL changes that initial value to NaN.

Test: ash_unittests SplitViewControllerTest.InternalDisplayConfigurationChangeDuringDividerSnapToLeft
Bug: 1006859
Change-Id: I1a89ea4b75d599251d77297449fd1d3a253eca26
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1815916Reviewed-by: default avatarXiaoqian Dai <xdai@chromium.org>
Commit-Queue: Avery Musbach <amusbach@chromium.org>
Cr-Commit-Position: refs/heads/master@{#699546}
parent d8839a96
...@@ -703,7 +703,7 @@ void SplitViewController::EndSplitView(EndReason end_reason) { ...@@ -703,7 +703,7 @@ void SplitViewController::EndSplitView(EndReason end_reason) {
black_scrim_layer_.reset(); black_scrim_layer_.reset();
default_snap_position_ = NONE; default_snap_position_ = NONE;
divider_position_ = -1; divider_position_ = -1;
divider_closest_ratio_ = 0.f; divider_closest_ratio_ = std::numeric_limits<float>::quiet_NaN();
snapping_window_transformed_bounds_map_.clear(); snapping_window_transformed_bounds_map_.clear();
UpdateSplitViewStateAndNotifyObservers(); UpdateSplitViewStateAndNotifyObservers();
...@@ -1111,7 +1111,7 @@ void SplitViewController::OnDisplayMetricsChanged( ...@@ -1111,7 +1111,7 @@ void SplitViewController::OnDisplayMetricsChanged(
const int divider_thickness = const int divider_thickness =
std::min(divider_size.width(), divider_size.height()); std::min(divider_size.width(), divider_size.height());
// Set default |divider_closest_ratio_| to kFixedPositionRatios[1]. // Set default |divider_closest_ratio_| to kFixedPositionRatios[1].
if (!divider_closest_ratio_) if (std::isnan(divider_closest_ratio_))
divider_closest_ratio_ = kFixedPositionRatios[1]; divider_closest_ratio_ = kFixedPositionRatios[1];
// Reverse the position ratio if top/left window changes. // Reverse the position ratio if top/left window changes.
......
...@@ -5,6 +5,7 @@ ...@@ -5,6 +5,7 @@
#ifndef ASH_WM_SPLITSVIEW_SPLIT_VIEW_CONTROLLER_H_ #ifndef ASH_WM_SPLITSVIEW_SPLIT_VIEW_CONTROLLER_H_
#define ASH_WM_SPLITSVIEW_SPLIT_VIEW_CONTROLLER_H_ #define ASH_WM_SPLITSVIEW_SPLIT_VIEW_CONTROLLER_H_
#include <limits>
#include <memory> #include <memory>
#include "ash/accessibility/accessibility_observer.h" #include "ash/accessibility/accessibility_observer.h"
...@@ -426,7 +427,7 @@ class ASH_EXPORT SplitViewController : public SplitViewNotifier, ...@@ -426,7 +427,7 @@ class ASH_EXPORT SplitViewController : public SplitViewNotifier,
// kOneThirdPositionRatio and kTwoThirdPositionRatio based on current // kOneThirdPositionRatio and kTwoThirdPositionRatio based on current
// |divider_position_|. Used to update |divider_position_| on work area // |divider_position_|. Used to update |divider_position_| on work area
// changes. // changes.
float divider_closest_ratio_ = 0.f; float divider_closest_ratio_ = std::numeric_limits<float>::quiet_NaN();
// The location of the previous mouse/gesture event in screen coordinates. // The location of the previous mouse/gesture event in screen coordinates.
gfx::Point previous_event_location_; gfx::Point previous_event_location_;
......
...@@ -863,10 +863,58 @@ TEST_F(SplitViewControllerTest, ...@@ -863,10 +863,58 @@ TEST_F(SplitViewControllerTest,
} }
// Test that if the internal screen display configuration changes during the // Test that if the internal screen display configuration changes during the
// divider snap animation, and if the adjusted divider bounds place it at an // divider snap animation, and if the adjusted divider bounds place it at the
// edge of the screen, then split view ends. // left edge of the screen, then split view ends.
TEST_F(SplitViewControllerTest, TEST_F(SplitViewControllerTest,
InternalDisplayConfigurationChangeDuringDividerSnapToEndSplitView) { InternalDisplayConfigurationChangeDuringDividerSnapToLeft) {
UpdateDisplay("407x400");
int64_t display_id = display::Screen::GetScreen()->GetPrimaryDisplay().id();
display::DisplayManager* display_manager = Shell::Get()->display_manager();
display::test::ScopedSetInternalDisplayId set_internal(display_manager,
display_id);
const gfx::Rect bounds(0, 0, 200, 200);
std::unique_ptr<aura::Window> window1(CreateWindow(bounds));
std::unique_ptr<aura::Window> window2(CreateWindow(bounds));
split_view_controller()->SnapWindow(window1.get(), SplitViewController::LEFT);
split_view_controller()->SnapWindow(window2.get(),
SplitViewController::RIGHT);
const gfx::Rect bounds_window1 = window1->GetBoundsInScreen();
const gfx::Rect bounds_window2 = window2->GetBoundsInScreen();
const gfx::Rect bounds_divider =
split_view_divider()->GetDividerBoundsInScreen(false /* is_dragging */);
// Test that |window1| and |window2| has the same width and height after snap.
EXPECT_NEAR(bounds_window1.width(), bounds_window2.width(), 1);
EXPECT_EQ(bounds_window1.height(), bounds_window2.height());
EXPECT_EQ(bounds_divider.height(), bounds_window1.height());
// Test that |window1|, divider, |window2| are aligned properly.
EXPECT_EQ(bounds_divider.x(), bounds_window1.x() + bounds_window1.width());
EXPECT_EQ(bounds_window2.x(), bounds_divider.x() + bounds_divider.width());
// Drag the divider to end split view pending the snap animation.
const gfx::Point divider_center =
split_view_divider()
->GetDividerBoundsInScreen(false /* is_dragging */)
.CenterPoint();
GetEventGenerator()->set_current_screen_location(divider_center);
GetEventGenerator()->DragMouseBy(20 - bounds_window1.width(), 0);
ASSERT_TRUE(split_view_controller()->InSplitViewMode());
ASSERT_TRUE(IsDividerAnimating());
// Change the display configuration and check that split view ends.
UpdateDisplay("507x500");
EXPECT_FALSE(split_view_controller()->InSplitViewMode());
}
// Test that if the internal screen display configuration changes during the
// divider snap animation, and if the adjusted divider bounds place it at the
// right edge of the screen, then split view ends.
TEST_F(SplitViewControllerTest,
InternalDisplayConfigurationChangeDuringDividerSnapToRight) {
UpdateDisplay("407x400"); UpdateDisplay("407x400");
int64_t display_id = display::Screen::GetScreen()->GetPrimaryDisplay().id(); int64_t display_id = display::Screen::GetScreen()->GetPrimaryDisplay().id();
display::DisplayManager* display_manager = Shell::Get()->display_manager(); display::DisplayManager* display_manager = Shell::Get()->display_manager();
......
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