Commit 0f1c56de authored by Eliot Courtney's avatar Eliot Courtney Committed by Commit Bot

Initiate smooth resize for both Android windows in split screen mode.

BUG=b/72806943

Change-Id: I6326cc8806984264011b807456fa45164f59d187
Reviewed-on: https://chromium-review.googlesource.com/956667
Commit-Queue: Eliot Courtney <edcourtney@chromium.org>
Reviewed-by: default avatarXiaoqian Dai <xdai@chromium.org>
Reviewed-by: default avatarMitsuru Oshima <oshima@chromium.org>
Cr-Commit-Position: refs/heads/master@{#549832}
parent 65fbaa47
...@@ -8,7 +8,6 @@ ...@@ -8,7 +8,6 @@
#include <memory> #include <memory>
#include "ash/display/screen_orientation_controller.h" #include "ash/display/screen_orientation_controller.h"
#include "ash/public/cpp/app_types.h"
#include "ash/public/cpp/ash_switches.h" #include "ash/public/cpp/ash_switches.h"
#include "ash/public/cpp/shell_window_ids.h" #include "ash/public/cpp/shell_window_ids.h"
#include "ash/screen_util.h" #include "ash/screen_util.h"
...@@ -34,7 +33,7 @@ ...@@ -34,7 +33,7 @@
#include "base/metrics/user_metrics.h" #include "base/metrics/user_metrics.h"
#include "base/optional.h" #include "base/optional.h"
#include "base/stl_util.h" #include "base/stl_util.h"
#include "ui/aura/client/aura_constants.h" #include "base/sys_info.h"
#include "ui/aura/window.h" #include "ui/aura/window.h"
#include "ui/aura/window_delegate.h" #include "ui/aura/window_delegate.h"
#include "ui/base/class_property.h" #include "ui/base/class_property.h"
...@@ -76,26 +75,6 @@ void TransposeRect(gfx::Rect* rect) { ...@@ -76,26 +75,6 @@ void TransposeRect(gfx::Rect* rect) {
rect->SetRect(rect->y(), rect->x(), rect->height(), rect->width()); rect->SetRect(rect->y(), rect->x(), rect->height(), rect->width());
} }
// Returns true if |window| is an Arc app window.
bool IsArcAppWindow(aura::Window* window) {
return window && window->GetProperty(aura::client::kAppType) ==
static_cast<int>(AppType::ARC_APP);
}
// Gets the window that is stacked above the other. The windows for comparison
// must have the same parent if they are both not nullptr.
aura::Window* GetWindowStackedAbove(aura::Window* window1,
aura::Window* window2) {
if (!window1 || !window2)
return window1 ? window1 : window2;
DCHECK(window1->parent() == window2->parent());
const aura::Window::Windows windows = window1->parent()->children();
auto window1_i = std::find(windows.begin(), windows.end(), window1);
auto window2_i = std::find(windows.begin(), windows.end(), window2);
return window1_i > window2_i ? window1 : window2;
}
mojom::SplitViewState ToMojomSplitViewState(SplitViewController::State state) { mojom::SplitViewState ToMojomSplitViewState(SplitViewController::State state) {
switch (state) { switch (state) {
case SplitViewController::NO_SNAP: case SplitViewController::NO_SNAP:
...@@ -365,16 +344,17 @@ void SplitViewController::StartResize(const gfx::Point& location_in_screen) { ...@@ -365,16 +344,17 @@ void SplitViewController::StartResize(const gfx::Point& location_in_screen) {
split_view_divider_->UpdateDividerBounds(); split_view_divider_->UpdateDividerBounds();
previous_event_location_ = location_in_screen; previous_event_location_ = location_in_screen;
smooth_resize_window_ = GetWindowForSmoothResize(); for (auto* window : {left_window_, right_window_}) {
DCHECK(smooth_resize_window_); if (window == nullptr)
wm::WindowState* window_state = wm::GetWindowState(smooth_resize_window_); continue;
gfx::Point location_in_parent(location_in_screen); wm::WindowState* window_state = wm::GetWindowState(window);
::wm::ConvertPointFromScreen(smooth_resize_window_->parent(), gfx::Point location_in_parent(location_in_screen);
&location_in_parent); ::wm::ConvertPointFromScreen(window->parent(), &location_in_parent);
int window_component = GetWindowComponentForResize(smooth_resize_window_); int window_component = GetWindowComponentForResize(window);
window_state->CreateDragDetails(location_in_parent, window_component, window_state->CreateDragDetails(location_in_parent, window_component,
::wm::WINDOW_MOVE_SOURCE_TOUCH); ::wm::WINDOW_MOVE_SOURCE_TOUCH);
window_state->OnDragStarted(window_component); window_state->OnDragStarted(window_component);
}
base::RecordAction(base::UserMetricsAction("SplitView_ResizeWindows")); base::RecordAction(base::UserMetricsAction("SplitView_ResizeWindows"));
} }
...@@ -421,13 +401,16 @@ void SplitViewController::EndResize(const gfx::Point& location_in_screen) { ...@@ -421,13 +401,16 @@ void SplitViewController::EndResize(const gfx::Point& location_in_screen) {
NotifyDividerPositionChanged(); NotifyDividerPositionChanged();
RestoreWindowsTransformAfterResizing(); RestoreWindowsTransformAfterResizing();
if (smooth_resize_window_) { // Update snapped window/windows bounds before sending OnCompleteDrag() for
// Update snapped window/windows bounds before sending OnCompleteDrag() for // smoother resizing visual result.
// smoother resizing visual result. UpdateSnappedWindowsAndDividerBounds();
UpdateSnappedWindowsAndDividerBounds();
wm::WindowState* window_state = wm::GetWindowState(smooth_resize_window_); for (auto* window : {left_window_, right_window_}) {
if (window == nullptr)
continue;
wm::WindowState* window_state = wm::GetWindowState(window);
window_state->OnCompleteDrag( window_state->OnCompleteDrag(
GetEndDragLocationInScreen(smooth_resize_window_, location_in_screen)); GetEndDragLocationInScreen(window, location_in_screen));
window_state->DeleteDragDetails(); window_state->DeleteDragDetails();
} }
...@@ -506,8 +489,6 @@ void SplitViewController::AddObserver(mojom::SplitViewObserverPtr observer) { ...@@ -506,8 +489,6 @@ void SplitViewController::AddObserver(mojom::SplitViewObserverPtr observer) {
void SplitViewController::OnWindowDestroying(aura::Window* window) { void SplitViewController::OnWindowDestroying(aura::Window* window) {
DCHECK(IsSplitViewModeActive()); DCHECK(IsSplitViewModeActive());
DCHECK(window == left_window_ || window == right_window_); DCHECK(window == left_window_ || window == right_window_);
if (smooth_resize_window_ == window)
smooth_resize_window_ = nullptr;
auto iter = overview_window_item_bounds_map_.find(window); auto iter = overview_window_item_bounds_map_.find(window);
if (iter != overview_window_item_bounds_map_.end()) if (iter != overview_window_item_bounds_map_.end())
overview_window_item_bounds_map_.erase(iter); overview_window_item_bounds_map_.erase(iter);
...@@ -1097,22 +1078,6 @@ void SplitViewController::GetDividerOptionalPositionRatios( ...@@ -1097,22 +1078,6 @@ void SplitViewController::GetDividerOptionalPositionRatios(
position_ratios->push_back(kTwoThirdPositionRatio); position_ratios->push_back(kTwoThirdPositionRatio);
} }
aura::Window* SplitViewController::GetWindowForSmoothResize() {
DCHECK(IsSplitViewModeActive());
// If there is only one snapped window, return it.
if (!left_window_ || !right_window_)
return left_window_ ? left_window_ : right_window_;
// If both of two snapped windows are Arc app windows or both are not Arc app
// windows, return the one who is stacked above the other. Otherwise return
// the one who is an Arc app window.
if (IsArcAppWindow(left_window_) == IsArcAppWindow(right_window_))
return GetWindowStackedAbove(left_window_, right_window_);
else
return IsArcAppWindow(left_window_) ? left_window_ : right_window_;
}
int SplitViewController::GetWindowComponentForResize(aura::Window* window) { int SplitViewController::GetWindowComponentForResize(aura::Window* window) {
if (window && (window == left_window_ || window == right_window_)) { if (window && (window == left_window_ || window == right_window_)) {
switch (GetCurrentScreenOrientation()) { switch (GetCurrentScreenOrientation()) {
......
...@@ -272,11 +272,6 @@ class ASH_EXPORT SplitViewController : public mojom::SplitViewController, ...@@ -272,11 +272,6 @@ class ASH_EXPORT SplitViewController : public mojom::SplitViewController,
// on the minimum size of current snapped windows. // on the minimum size of current snapped windows.
void GetDividerOptionalPositionRatios(std::vector<float>* positionRatios); void GetDividerOptionalPositionRatios(std::vector<float>* positionRatios);
// Selects the window that needs the quick/smooth resize. It's needed as
// Android only supports smooth resize for one app window at a time. If there
// are two snapped Arc app windows, always return the one who stacked above
// the other.
aura::Window* GetWindowForSmoothResize();
// Gets the expected window component depending on current screen orientation // Gets the expected window component depending on current screen orientation
// for resizing purpose. // for resizing purpose.
int GetWindowComponentForResize(aura::Window* window); int GetWindowComponentForResize(aura::Window* window);
...@@ -357,13 +352,6 @@ class ASH_EXPORT SplitViewController : public mojom::SplitViewController, ...@@ -357,13 +352,6 @@ class ASH_EXPORT SplitViewController : public mojom::SplitViewController,
// The time when splitview starts. Used for metric collection purpose. // The time when splitview starts. Used for metric collection purpose.
base::Time splitview_start_time_; base::Time splitview_start_time_;
// The window that needs smooth resize. It's needed as Android only supports
// smooth resize for one app window at a time. It's always the snapped Arc app
// window if there is one. And if there are two snapped Arc app windows, it's
// the one who stacked above the other, see GetWindowForSmoothResize() for
// details.
aura::Window* smooth_resize_window_ = nullptr;
// The map from a to-be-snapped window to its overview item's bounds if the // The map from a to-be-snapped window to its overview item's bounds if the
// window comes from the overview. // window comes from the overview.
base::flat_map<aura::Window*, gfx::Rect> overview_window_item_bounds_map_; base::flat_map<aura::Window*, gfx::Rect> overview_window_item_bounds_map_;
......
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