Commit 9ed68bfb authored by Sammie Quon's avatar Sammie Quon Committed by Commit Bot

overview: Clipping for windows using new grid layout.

Extracts parts of the regular grid layout function into a helper, which
is then used by the new grid layout function.

Test: manual
Bug: 1011973
Change-Id: I7bdf40227bbd1df467ea9d56bc84e58b01c12f33
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1867271
Commit-Queue: Sammie Quon <sammiequon@chromium.org>
Reviewed-by: default avatarXiaoqian Dai <xdai@chromium.org>
Cr-Commit-Position: refs/heads/master@{#707460}
parent 65cc1c1a
......@@ -1660,13 +1660,9 @@ std::vector<gfx::RectF> OverviewGrid::GetWindowRectsForTabletModeLayout(
continue;
}
// Maintains the aspect ratio from the original window. The window's
// original height will be shrunk to fit into |height|, minus the margin and
// overview header.
const float ratio = float{height - kHeaderHeightDp - kOverviewMargin} /
item->GetWindow()->bounds().height();
// Calculate the width and y position of the item.
const int width =
item->GetWindow()->bounds().width() * ratio + kOverviewMargin;
CalculateWidthAndMaybeSetUnclippedBounds(window_list_[i].get(), height);
const int y =
height * (window_position % kTabletLayoutRow) + total_bounds.y();
......@@ -1711,85 +1707,14 @@ bool OverviewGrid::FitWindowRectsInBounds(
// All elements are of same height and only the height is necessary to
// determine each item's scale.
const gfx::Size item_size(0, height);
for (size_t i = 0u; i < window_count; ++i) {
if (window_list_[i]->animating_to_close() ||
ignored_items.contains(window_list_[i].get())) {
continue;
}
gfx::RectF target_bounds = window_list_[i]->GetTargetBoundsInScreen();
float scale = window_list_[i]->GetItemScale(item_size);
// The drop target, unlike the other windows has its bounds set directly, so
// |GetTargetBoundsInScreen()| won't return the value we want. Instead, get
// the scale from the window it was meant to be a placeholder for.
if (IsDropTargetWindow(window_list_[i]->GetWindow())) {
aura::Window* dragged_window = nullptr;
OverviewItem* item =
overview_session_->window_drag_controller()
? overview_session_->window_drag_controller()->item()
: nullptr;
if (item)
dragged_window = item->GetWindow();
else if (dragged_window_)
dragged_window = dragged_window_;
if (dragged_window && dragged_window->parent()) {
target_bounds = ::ash::GetTargetBoundsInScreen(dragged_window);
const gfx::SizeF inset_size(item_size.width(),
item_size.height() - 2 * kWindowMargin);
scale = ScopedOverviewTransformWindow::GetItemScale(
target_bounds.size(), inset_size,
dragged_window->GetProperty(aura::client::kTopViewInset),
kHeaderHeightDp);
}
}
int width = std::max(1, gfx::ToFlooredInt(target_bounds.width() * scale) +
2 * kWindowMargin);
switch (window_list_[i]->GetWindowDimensionsType()) {
case ScopedOverviewTransformWindow::GridWindowFillMode::kLetterBoxed:
width = ScopedOverviewTransformWindow::kExtremeWindowRatioThreshold *
height;
break;
case ScopedOverviewTransformWindow::GridWindowFillMode::kPillarBoxed:
width = height /
ScopedOverviewTransformWindow::kExtremeWindowRatioThreshold;
break;
default:
break;
}
const bool is_landscape = IsCurrentScreenOrientationLandscape();
// Get the bounds of the window if there is a snapped window or a window
// about to be snapped.
base::Optional<gfx::RectF> split_view_bounds =
GetSplitviewBoundsMaintainingAspectRatio(window_list_[i]->GetWindow());
gfx::Size unclipped_size;
if (split_view_bounds) {
if (is_landscape) {
unclipped_size.set_width(width - 2 * kWindowMargin);
unclipped_size.set_height(height - 2 * kWindowMargin);
// For landscape mode, shrink |width| so that the aspect ratio matches
// that of |split_view_bounds|.
width =
std::max(1, gfx::ToFlooredInt(split_view_bounds->width() * scale) +
2 * kWindowMargin);
} else {
// For portrait mode, we want |height| to stay the same, so calculate
// what the unclipped height would be based on |split_view_bounds|.
width =
split_view_bounds->width() * height / split_view_bounds->height();
int unclipped_height =
(target_bounds.height() * width) / target_bounds.width();
unclipped_size.set_width(width);
unclipped_size.set_height(unclipped_height);
}
}
window_list_[i]->set_unclipped_size(
unclipped_size.IsEmpty() ? base::nullopt
: base::make_optional(unclipped_size));
int width =
CalculateWidthAndMaybeSetUnclippedBounds(window_list_[i].get(), height);
if (left + width > bounds.right()) {
// Move to the next row if possible.
......@@ -1873,4 +1798,82 @@ void OverviewGrid::AddDraggedWindowIntoOverviewOnDragEnd(
/*animate=*/false);
}
int OverviewGrid::CalculateWidthAndMaybeSetUnclippedBounds(OverviewItem* item,
int height) {
const gfx::Size item_size(0, height);
gfx::RectF target_bounds = item->GetTargetBoundsInScreen();
float scale = item->GetItemScale(item_size);
// The drop target, unlike the other windows has its bounds set directly, so
// |GetTargetBoundsInScreen()| won't return the value we want. Instead, get
// the scale from the window it was meant to be a placeholder for.
if (IsDropTargetWindow(item->GetWindow())) {
aura::Window* dragged_window = nullptr;
OverviewItem* item =
overview_session_->window_drag_controller()
? overview_session_->window_drag_controller()->item()
: nullptr;
if (item)
dragged_window = item->GetWindow();
else if (dragged_window_)
dragged_window = dragged_window_;
if (dragged_window && dragged_window->parent()) {
target_bounds = ::ash::GetTargetBoundsInScreen(dragged_window);
const gfx::SizeF inset_size(0, height - 2 * kWindowMargin);
scale = ScopedOverviewTransformWindow::GetItemScale(
target_bounds.size(), inset_size,
dragged_window->GetProperty(aura::client::kTopViewInset),
kHeaderHeightDp);
}
}
int width = std::max(
1, gfx::ToFlooredInt(target_bounds.width() * scale) + 2 * kWindowMargin);
switch (item->GetWindowDimensionsType()) {
case ScopedOverviewTransformWindow::GridWindowFillMode::kLetterBoxed:
width =
ScopedOverviewTransformWindow::kExtremeWindowRatioThreshold * height;
break;
case ScopedOverviewTransformWindow::GridWindowFillMode::kPillarBoxed:
width =
height / ScopedOverviewTransformWindow::kExtremeWindowRatioThreshold;
break;
default:
break;
}
// Get the bounds of the window if there is a snapped window or a window
// about to be snapped.
base::Optional<gfx::RectF> split_view_bounds =
GetSplitviewBoundsMaintainingAspectRatio(item->GetWindow());
if (!split_view_bounds) {
item->set_unclipped_size(base::nullopt);
return width;
}
const bool is_landscape = IsCurrentScreenOrientationLandscape();
gfx::Size unclipped_size;
if (is_landscape) {
unclipped_size.set_width(width - 2 * kWindowMargin);
unclipped_size.set_height(height - 2 * kWindowMargin);
// For landscape mode, shrink |width| so that the aspect ratio matches
// that of |split_view_bounds|.
width = std::max(1, gfx::ToFlooredInt(split_view_bounds->width() * scale) +
2 * kWindowMargin);
} else {
// For portrait mode, we want |height| to stay the same, so calculate
// what the unclipped height would be based on |split_view_bounds|.
width = split_view_bounds->width() * height / split_view_bounds->height();
int unclipped_height =
(target_bounds.height() * width) / target_bounds.width();
unclipped_size.set_width(width);
unclipped_size.set_height(unclipped_height);
}
DCHECK(!unclipped_size.IsEmpty());
item->set_unclipped_size(base::make_optional(unclipped_size));
return width;
}
} // namespace ash
......@@ -396,6 +396,12 @@ class ASH_EXPORT OverviewGrid : public SplitViewObserver,
// the window's bounds if it has been resized.
void AddDraggedWindowIntoOverviewOnDragEnd(aura::Window* dragged_window);
// Calculate the width of an item based on |height|. The width tries to keep
// the same aspect ratio as the original window, but may be modified if the
// bounds of the window are considered extreme, or if the window is in
// splitview or entering splitview.
int CalculateWidthAndMaybeSetUnclippedBounds(OverviewItem* item, int height);
// Root window the grid is in.
aura::Window* root_window_;
......
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