Skip to content

Commit

Permalink
[merge to 124] splitview: Suspected fix for SetWindowsTransformDuring…
Browse files Browse the repository at this point in the history
…Resizing crash

This clamps the values of `GetClosestFixedDividerPosition()` and
`CalculateDividerPosition()` to be between 0 and the work area length.

Test: compiles
Bug: b/327685487
Change-Id: Ifba1dad1b79208292094844eb2a6ab86941dc637
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/5414873
Commit-Queue: Sophie Wen <sophiewen@chromium.org>
Reviewed-by: Ahmed Fakhry <afakhry@chromium.org>
Cr-Original-Commit-Position: refs/heads/main@{#1282845}
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/5449870
Cr-Commit-Position: refs/branch-heads/6367@{#798}
Cr-Branched-From: d158c6d-refs/heads/main@{#1274542}
  • Loading branch information
Sophie Wen authored and Chromium LUCI CQ committed Apr 12, 2024
1 parent 676f2d8 commit 8771130
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 6 deletions.
2 changes: 1 addition & 1 deletion ash/wm/splitview/split_view_controller.cc
Expand Up @@ -2093,7 +2093,7 @@ int SplitViewController::GetClosestFixedDividerPosition(int divider_position) {
if (divider_closest_ratio_ > 0.f && divider_closest_ratio_ < 1.f) {
fixed_position -= kSplitviewDividerShortSideLength / 2;
}
return fixed_position;
return std::clamp(fixed_position, 0, divider_upper_limit);
}

void SplitViewController::StopAndShoveAnimatedDivider() {
Expand Down
8 changes: 5 additions & 3 deletions ash/wm/splitview/split_view_utils.cc
Expand Up @@ -764,9 +764,11 @@ int CalculateDividerPosition(aura::Window* root_window,
// 1-DIP gap between snapped windows precludes multiresizing. See b/262011280.
const float snap_length = (divider_upper_limit - divider_delta) * snap_ratio;

return snap_position == SnapPosition::kPrimary
? snap_length
: divider_upper_limit - snap_length - divider_delta;
return std::clamp(
static_cast<int>(snap_position == SnapPosition::kPrimary
? snap_length
: divider_upper_limit - snap_length - divider_delta),
0, divider_upper_limit);
}

int GetEquivalentDividerPosition(aura::Window* window,
Expand Down
5 changes: 3 additions & 2 deletions ash/wm/splitview/split_view_utils.h
Expand Up @@ -221,8 +221,9 @@ int GetDividerPositionUpperLimit(aura::Window* root_window);
int GetMinimumWindowLength(aura::Window* window, bool horizontal);

// Returns the target divider position for `root_window` for `snap_ratio` at
// `snap_position`. `account_for_divider_width` will decide whether the divider
// shorter side width will be subtracted or not.
// `snap_position`, clamped between 0 and the upper limit of `root_window`.
// `account_for_divider_width` will decide whether the divider shorter side
// width will be subtracted or not.
int CalculateDividerPosition(aura::Window* root_window,
SnapPosition snap_position,
float snap_ratio,
Expand Down

0 comments on commit 8771130

Please sign in to comment.