Commit 23c075e9 authored by Sammie Quon's avatar Sammie Quon Committed by Commit Bot

overview: Use 'target_bounds_' to place drop target and item widget.

Instead of doing extra step to transform the window and then find the
bounds of these objects by reverse transform.

Test: manual
Bug: 1011973
Change-Id: I00e7432d4c02c6d8f08dd7ddaa195a5d7de2591b
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1864169Reviewed-by: default avatarXiaoqian Dai <xdai@chromium.org>
Commit-Queue: Sammie Quon <sammiequon@chromium.org>
Cr-Commit-Position: refs/heads/master@{#706735}
parent 583d19c9
...@@ -299,9 +299,10 @@ void CaptionContainerView::Layout() { ...@@ -299,9 +299,10 @@ void CaptionContainerView::Layout() {
preview_view_->SetBoundsRect(preview_bounds); preview_view_->SetBoundsRect(preview_bounds);
} }
// Position the header at the top. // Position the header at the top. The close button should be right aligned so
// that the edge of its icon, not the button itself lines up with the margins.
const gfx::Rect header_bounds(kOverviewMargin, kOverviewMargin, const gfx::Rect header_bounds(kOverviewMargin, kOverviewMargin,
GetLocalBounds().width() - kOverviewMargin, GetLocalBounds().width() - kWindowMargin,
kHeaderHeightDp); kHeaderHeightDp);
header_view_->SetBoundsRect(header_bounds); header_view_->SetBoundsRect(header_bounds);
} }
......
...@@ -408,9 +408,6 @@ void OverviewItem::SetBounds(const gfx::RectF& target_bounds, ...@@ -408,9 +408,6 @@ void OverviewItem::SetBounds(const gfx::RectF& target_bounds,
const bool is_first_update = target_bounds_.IsEmpty(); const bool is_first_update = target_bounds_.IsEmpty();
target_bounds_ = target_bounds; target_bounds_ = target_bounds;
gfx::RectF inset_bounds(target_bounds);
inset_bounds.Inset(kWindowMargin, kWindowMargin);
// If the window is minimized we can avoid applying transforms on the original // If the window is minimized we can avoid applying transforms on the original
// window. // window.
if (transform_window_.IsMinimized()) { if (transform_window_.IsMinimized()) {
...@@ -454,8 +451,8 @@ void OverviewItem::SetBounds(const gfx::RectF& target_bounds, ...@@ -454,8 +451,8 @@ void OverviewItem::SetBounds(const gfx::RectF& target_bounds,
} }
} }
} else { } else {
// SetItemBounds is called before UpdateHeaderLayout so the header can gfx::RectF inset_bounds(target_bounds);
// properly use the updated windows bounds. inset_bounds.Inset(kWindowMargin, kWindowMargin);
SetItemBounds(inset_bounds, new_animation_type, is_first_update); SetItemBounds(inset_bounds, new_animation_type, is_first_update);
UpdateHeaderLayout(is_first_update ? OVERVIEW_ANIMATION_NONE UpdateHeaderLayout(is_first_update ? OVERVIEW_ANIMATION_NONE
: new_animation_type); : new_animation_type);
...@@ -469,12 +466,10 @@ void OverviewItem::SetBounds(const gfx::RectF& target_bounds, ...@@ -469,12 +466,10 @@ void OverviewItem::SetBounds(const gfx::RectF& target_bounds,
UpdateRoundedCornersAndShadow(); UpdateRoundedCornersAndShadow();
if (cannot_snap_widget_) { if (cannot_snap_widget_) {
inset_bounds.Inset(
gfx::Insets(static_cast<float>(kHeaderHeightDp), 0.f, 0.f, 0.f));
SetWidgetBoundsAndMaybeAnimateTransform( SetWidgetBoundsAndMaybeAnimateTransform(
cannot_snap_widget_.get(), cannot_snap_widget_.get(),
cannot_snap_widget_->GetBoundsCenteredIn( cannot_snap_widget_->GetBoundsCenteredIn(
gfx::ToEnclosingRect(inset_bounds)), gfx::ToEnclosingRect(GetWindowTargetBoundsWithInsets())),
new_animation_type, nullptr); new_animation_type, nullptr);
} }
...@@ -580,9 +575,8 @@ void OverviewItem::UpdateCannotSnapWarningVisibility() { ...@@ -580,9 +575,8 @@ void OverviewItem::UpdateCannotSnapWarningVisibility() {
visible visible
? SPLITVIEW_ANIMATION_OVERVIEW_ITEM_FADE_IN ? SPLITVIEW_ANIMATION_OVERVIEW_ITEM_FADE_IN
: SPLITVIEW_ANIMATION_OVERVIEW_ITEM_FADE_OUT); : SPLITVIEW_ANIMATION_OVERVIEW_ITEM_FADE_OUT);
gfx::Rect bounds = gfx::ToEnclosingRect(target_bounds()); const gfx::Rect bounds =
bounds.Inset(kWindowMargin, kWindowMargin); gfx::ToEnclosingRect(GetWindowTargetBoundsWithInsets());
bounds.Inset(gfx::Insets(kHeaderHeightDp, 0, 0, 0));
cannot_snap_widget_->SetBoundsCenteredIn(bounds, /*animate=*/false); cannot_snap_widget_->SetBoundsCenteredIn(bounds, /*animate=*/false);
} }
...@@ -1086,6 +1080,13 @@ gfx::Rect OverviewItem::GetShadowBoundsForTesting() { ...@@ -1086,6 +1080,13 @@ gfx::Rect OverviewItem::GetShadowBoundsForTesting() {
return shadow_->content_bounds(); return shadow_->content_bounds();
} }
gfx::RectF OverviewItem::GetWindowTargetBoundsWithInsets() const {
gfx::RectF window_target_bounds = target_bounds_;
window_target_bounds.Inset(kWindowMargin, kWindowMargin);
window_target_bounds.Inset(0, kHeaderHeightDp, 0, 0);
return window_target_bounds;
}
void OverviewItem::OnWindowCloseAnimationCompleted() { void OverviewItem::OnWindowCloseAnimationCompleted() {
transform_window_.Close(); transform_window_.Close();
} }
...@@ -1155,6 +1156,15 @@ void OverviewItem::SetItemBounds(const gfx::RectF& target_bounds, ...@@ -1155,6 +1156,15 @@ void OverviewItem::SetItemBounds(const gfx::RectF& target_bounds,
bool is_first_update) { bool is_first_update) {
aura::Window* window = GetWindow(); aura::Window* window = GetWindow();
DCHECK(root_window_ == window->GetRootWindow()); DCHECK(root_window_ == window->GetRootWindow());
// Do not set transform for drop target, set bounds instead.
if (overview_grid_->IsDropTargetWindow(window)) {
window->SetBoundsInScreen(
gfx::ToEnclosedRect(GetWindowTargetBoundsWithInsets()),
WindowState::Get(window)->GetDisplay());
window->SetTransform(gfx::Transform());
return;
}
gfx::RectF screen_rect = gfx::RectF(GetTargetBoundsInScreen()); gfx::RectF screen_rect = gfx::RectF(GetTargetBoundsInScreen());
// Avoid division by zero by ensuring screen bounds is not empty. // Avoid division by zero by ensuring screen bounds is not empty.
...@@ -1166,13 +1176,6 @@ void OverviewItem::SetItemBounds(const gfx::RectF& target_bounds, ...@@ -1166,13 +1176,6 @@ void OverviewItem::SetItemBounds(const gfx::RectF& target_bounds,
gfx::RectF overview_item_bounds = gfx::RectF overview_item_bounds =
transform_window_.ShrinkRectToFitPreservingAspectRatio( transform_window_.ShrinkRectToFitPreservingAspectRatio(
screen_rect, target_bounds, top_view_inset, kHeaderHeightDp); screen_rect, target_bounds, top_view_inset, kHeaderHeightDp);
// Do not set transform for drop target, set bounds instead.
if (overview_grid_->IsDropTargetWindow(window)) {
window->SetBoundsInScreen(gfx::ToEnclosedRect(overview_item_bounds),
WindowState::Get(window)->GetDisplay());
window->SetTransform(gfx::Transform());
return;
}
const gfx::Transform transform = const gfx::Transform transform =
gfx::TransformBetweenRects(screen_rect, overview_item_bounds); gfx::TransformBetweenRects(screen_rect, overview_item_bounds);
...@@ -1230,11 +1233,6 @@ void OverviewItem::CreateWindowLabel() { ...@@ -1230,11 +1233,6 @@ void OverviewItem::CreateWindowLabel() {
} }
void OverviewItem::UpdateHeaderLayout(OverviewAnimationType animation_type) { void OverviewItem::UpdateHeaderLayout(OverviewAnimationType animation_type) {
gfx::RectF transformed_window_bounds =
transform_window_.overview_bounds().value_or(
transform_window_.GetTransformedBounds());
::wm::TranslateRectFromScreen(root_window_, &transformed_window_bounds);
aura::Window* widget_window = item_widget_->GetNativeWindow(); aura::Window* widget_window = item_widget_->GetNativeWindow();
ScopedOverviewAnimationSettings animation_settings(animation_type, ScopedOverviewAnimationSettings animation_settings(animation_type,
widget_window); widget_window);
...@@ -1247,16 +1245,15 @@ void OverviewItem::UpdateHeaderLayout(OverviewAnimationType animation_type) { ...@@ -1247,16 +1245,15 @@ void OverviewItem::UpdateHeaderLayout(OverviewAnimationType animation_type) {
std::move(enter_observer)); std::move(enter_observer));
} }
// |widget_window| is sized to the same bounds as the original window plus gfx::RectF item_bounds = target_bounds_;
// some space for the header and a little padding. ::wm::TranslateRectFromScreen(root_window_, &item_bounds);
gfx::Rect label_rect(0, -kHeaderHeightDp, transformed_window_bounds.width(), const gfx::Point origin = gfx::ToRoundedPoint(item_bounds.origin());
kHeaderHeightDp + transformed_window_bounds.height()); item_bounds.set_origin(gfx::PointF());
label_rect.Inset(-kOverviewMargin, -kOverviewMargin); item_bounds.Inset(-kWindowMargin, -kWindowMargin);
widget_window->SetBounds(label_rect); widget_window->SetBounds(gfx::ToEnclosedRect(item_bounds));
gfx::Transform label_transform; gfx::Transform label_transform;
label_transform.Translate(gfx::ToRoundedInt(transformed_window_bounds.x()), label_transform.Translate(origin.x(), origin.y());
gfx::ToRoundedInt(transformed_window_bounds.y()));
widget_window->SetTransform(label_transform); widget_window->SetTransform(label_transform);
} }
......
...@@ -277,6 +277,10 @@ class ASH_EXPORT OverviewItem : public CaptionContainerView::EventDelegate, ...@@ -277,6 +277,10 @@ class ASH_EXPORT OverviewItem : public CaptionContainerView::EventDelegate,
FRIEND_TEST_ALL_PREFIXES(SplitViewOverviewSessionTest, FRIEND_TEST_ALL_PREFIXES(SplitViewOverviewSessionTest,
OverviewUnsnappableIndicatorVisibility); OverviewUnsnappableIndicatorVisibility);
// Returns the target bounds of |window_|. Same as |target_bounds_|, with some
// insets.
gfx::RectF GetWindowTargetBoundsWithInsets() const;
// Functions to be called back when their associated animations complete. // Functions to be called back when their associated animations complete.
void OnWindowCloseAnimationCompleted(); void OnWindowCloseAnimationCompleted();
void OnItemSpawnedAnimationCompleted(); void OnItemSpawnedAnimationCompleted();
......
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