Commit 4d051191 authored by Avery Musbach's avatar Avery Musbach Committed by Commit Bot

split view: Clean up some overly complicated code

Change-Id: I56ee473cd6e317f19d76dbbb17dc66473aaca987
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1822865
Commit-Queue: Avery Musbach <amusbach@chromium.org>
Reviewed-by: default avatarXiaoqian Dai <xdai@chromium.org>
Cr-Commit-Position: refs/heads/master@{#699572}
parent d2e07530
......@@ -8,6 +8,7 @@
#include <functional>
#include <utility>
#include "ash/display/screen_orientation_controller.h"
#include "ash/metrics/histogram_macros.h"
#include "ash/public/cpp/ash_features.h"
#include "ash/public/cpp/fps_counter.h"
......
......@@ -4,6 +4,7 @@
#include "ash/wm/overview/overview_window_drag_controller.h"
#include "ash/display/screen_orientation_controller.h"
#include "ash/display/screen_orientation_controller_test_api.h"
#include "ash/public/cpp/ash_features.h"
#include "ash/shell.h"
......
......@@ -517,10 +517,8 @@ gfx::Rect SplitViewController::GetSnappedWindowBoundsInScreen(
// desired bound is smaller than the minimum bounds of the window.
AdjustSnappedWindowBounds(&left_or_top_rect, &right_or_bottom_rect);
if (IsCurrentScreenOrientationPrimary())
return (snap_position == LEFT) ? left_or_top_rect : right_or_bottom_rect;
else
return (snap_position == LEFT) ? right_or_bottom_rect : left_or_top_rect;
return IsPhysicalLeftOrTop(snap_position) ? left_or_top_rect
: right_or_bottom_rect;
}
gfx::Rect SplitViewController::GetSnappedWindowBoundsInScreenUnadjusted(
......@@ -536,27 +534,21 @@ gfx::Rect SplitViewController::GetSnappedWindowBoundsInScreenUnadjusted(
GetSnappedWindowBoundsInScreenInternal(window, &left_or_top_rect,
&right_or_bottom_rect);
if (IsCurrentScreenOrientationPrimary())
return (snap_position == LEFT) ? left_or_top_rect : right_or_bottom_rect;
else
return (snap_position == LEFT) ? right_or_bottom_rect : left_or_top_rect;
return IsPhysicalLeftOrTop(snap_position) ? left_or_top_rect
: right_or_bottom_rect;
}
int SplitViewController::GetDefaultDividerPosition(aura::Window* window) const {
const gfx::Rect work_area_bounds_in_screen =
screen_util::GetDisplayWorkAreaBoundsInScreenForActiveDeskContainer(
window);
gfx::Size divider_size;
// In clamshell mode, there is no divider bar, thus divider_size is empty.
if (split_view_type_ == SplitViewType::kTabletType) {
divider_size = SplitViewDivider::GetDividerSize(
work_area_bounds_in_screen, GetCurrentScreenOrientation(),
false /* is_dragging */);
}
if (IsCurrentScreenOrientationLandscape())
return (work_area_bounds_in_screen.width() - divider_size.width()) * 0.5f;
else
return (work_area_bounds_in_screen.height() - divider_size.height()) * 0.5f;
int default_divider_position = (IsCurrentScreenOrientationLandscape()
? work_area_bounds_in_screen.width()
: work_area_bounds_in_screen.height()) /
2;
if (split_view_type_ == SplitViewType::kTabletType)
default_divider_position -= kSplitviewDividerShortSideLength / 2;
return default_divider_position;
}
bool SplitViewController::IsDividerAnimating() const {
......@@ -806,16 +798,12 @@ void SplitViewController::OnWindowBoundsChanged(
const gfx::Rect work_area =
screen_util::GetDisplayWorkAreaBoundsInScreenForActiveDeskContainer(
window);
const bool is_left_or_top_window =
IsCurrentScreenOrientationPrimary()
? (window == left_window_ ? true : false)
: (window == left_window_ ? false : true);
if (IsCurrentScreenOrientationLandscape()) {
divider_position_ = is_left_or_top_window
divider_position_ = window == GetPhysicalLeftOrTopWindow()
? new_bounds.width()
: work_area.width() - new_bounds.width();
} else {
divider_position_ = is_left_or_top_window
divider_position_ = window == GetPhysicalLeftOrTopWindow()
? new_bounds.height()
: work_area.height() - new_bounds.height();
}
......@@ -1070,11 +1058,11 @@ void SplitViewController::OnDisplayMetricsChanged(
if (!display.IsInternal())
return;
// We need update |previous_screen_orientation_| even though split view mode
// is not active at the moment.
OrientationLockType previous_screen_orientation =
previous_screen_orientation_;
previous_screen_orientation_ = GetCurrentScreenOrientation();
// We need to update |is_previous_screen_orientation_primary_| even if split
// view mode is not active.
const bool is_previous_screen_orientation_primary =
is_previous_screen_orientation_primary_;
is_previous_screen_orientation_primary_ = IsCurrentScreenOrientationPrimary();
if (!InSplitViewMode())
return;
......@@ -1106,22 +1094,18 @@ void SplitViewController::OnDisplayMetricsChanged(
if ((metrics & display::DisplayObserver::DISPLAY_METRIC_ROTATION) ||
(metrics & display::DisplayObserver::DISPLAY_METRIC_WORK_AREA)) {
const gfx::Size divider_size = SplitViewDivider::GetDividerSize(
display.work_area(), GetCurrentScreenOrientation(), false);
const int divider_thickness =
std::min(divider_size.width(), divider_size.height());
// Set default |divider_closest_ratio_| to kFixedPositionRatios[1].
if (std::isnan(divider_closest_ratio_))
divider_closest_ratio_ = kFixedPositionRatios[1];
// Reverse the position ratio if top/left window changes.
if (IsPrimaryOrientation(previous_screen_orientation) !=
if (is_previous_screen_orientation_primary !=
IsCurrentScreenOrientationPrimary()) {
divider_closest_ratio_ = 1.f - divider_closest_ratio_;
}
divider_position_ =
std::floor(divider_closest_ratio_ * GetDividerEndPosition()) -
std::floor(divider_thickness / 2.f);
static_cast<int>(divider_closest_ratio_ * GetDividerEndPosition()) -
kSplitviewDividerShortSideLength / 2;
}
// For other display configuration changes, we only move the divider to the
......@@ -1188,6 +1172,14 @@ void SplitViewController::OnAccessibilityControllerShutdown() {
Shell::Get()->accessibility_controller()->RemoveObserver(this);
}
aura::Window* SplitViewController::GetPhysicalLeftOrTopWindow() {
return IsCurrentScreenOrientationPrimary() ? left_window_ : right_window_;
}
aura::Window* SplitViewController::GetPhysicalRightOrBottomWindow() {
return IsCurrentScreenOrientationPrimary() ? right_window_ : left_window_;
}
void SplitViewController::StartObserving(aura::Window* window) {
if (window && !window->HasObserver(this)) {
Shell::Get()->shadow_controller()->UpdateShadowForWindow(window);
......@@ -1391,7 +1383,7 @@ void SplitViewController::GetSnappedWindowBoundsInScreenInternal(
gfx::Rect divider_bounds;
if (split_view_type_ == SplitViewType::kTabletType) {
divider_bounds = SplitViewDivider::GetDividerBoundsInScreen(
work_area_bounds_in_screen, GetCurrentScreenOrientation(),
work_area_bounds_in_screen, IsCurrentScreenOrientationLandscape(),
divider_position, false /* is_dragging */);
} else {
if (IsCurrentScreenOrientationLandscape())
......@@ -1433,15 +1425,6 @@ void SplitViewController::SplitRect(const gfx::Rect& work_area_rect,
int SplitViewController::GetClosestFixedDividerPosition() {
DCHECK(InSplitViewMode());
const gfx::Rect work_area_bounds_in_screen =
screen_util::GetDisplayWorkAreaBoundsInScreenForActiveDeskContainer(
GetDefaultSnappedWindow());
const gfx::Size divider_size = SplitViewDivider::GetDividerSize(
work_area_bounds_in_screen, GetCurrentScreenOrientation(),
false /* is_dragging */);
const int divider_thickness =
std::min(divider_size.width(), divider_size.height());
// The values in |kFixedPositionRatios| represent the fixed position of the
// center of the divider while |divider_position_| represent the origin of the
// divider rectangle. So, before calling FindClosestFixedPositionRatio,
......@@ -1450,11 +1433,11 @@ int SplitViewController::GetClosestFixedDividerPosition() {
// the endpoints.
int divider_end_position = GetDividerEndPosition();
divider_closest_ratio_ = FindClosestPositionRatio(
divider_position_ + std::floor(divider_thickness / 2.f),
divider_position_ + kSplitviewDividerShortSideLength / 2,
divider_end_position);
int fix_position = std::floor(divider_end_position * divider_closest_ratio_);
int fix_position = divider_end_position * divider_closest_ratio_;
if (divider_closest_ratio_ > 0.f && divider_closest_ratio_ < 1.f)
fix_position -= std::floor(divider_thickness / 2.f);
fix_position -= kSplitviewDividerShortSideLength / 2;
return fix_position;
}
......@@ -1561,16 +1544,11 @@ void SplitViewController::OnSnappedWindowDetached(aura::Window* window,
void SplitViewController::AdjustSnappedWindowBounds(
gfx::Rect* left_or_top_rect,
gfx::Rect* right_or_bottom_rect) {
aura::Window* left_or_top_window =
IsCurrentScreenOrientationPrimary() ? left_window_ : right_window_;
aura::Window* right_or_bottom_window =
IsCurrentScreenOrientationPrimary() ? right_window_ : left_window_;
const bool is_landscape = IsCurrentScreenOrientationLandscape();
const int left_minimum_width =
GetMinimumWindowSize(left_or_top_window, is_landscape);
GetMinimumWindowSize(GetPhysicalLeftOrTopWindow(), is_landscape);
const int right_minimum_width =
GetMinimumWindowSize(right_or_bottom_window, is_landscape);
GetMinimumWindowSize(GetPhysicalRightOrBottomWindow(), is_landscape);
if (!is_landscape) {
left_or_top_rect->Transpose();
......
......@@ -10,7 +10,6 @@
#include "ash/accessibility/accessibility_observer.h"
#include "ash/ash_export.h"
#include "ash/display/screen_orientation_controller.h"
#include "ash/public/cpp/split_view.h"
#include "ash/public/cpp/tablet_mode_observer.h"
#include "ash/shell_observer.h"
......@@ -230,6 +229,11 @@ class ASH_EXPORT SplitViewController : public SplitViewNotifier,
class TabDraggedWindowObserver;
class DividerSnapAnimation;
// These functions return |left_window_| and |right_window_|, swapped in
// nonprimary screen orientations. Note that they may return null.
aura::Window* GetPhysicalLeftOrTopWindow();
aura::Window* GetPhysicalRightOrBottomWindow();
// Start observing |window|.
void StartObserving(aura::Window* window);
// Stop observing the window at associated with |snap_position|. Also updates
......@@ -444,8 +448,8 @@ class ASH_EXPORT SplitViewController : public SplitViewNotifier,
// versa.
SnapPosition default_snap_position_ = NONE;
// The previous orientation of the screen.
OrientationLockType previous_screen_orientation_ = OrientationLockType::kAny;
// Whether the previous screen orientation is a primary orientation.
bool is_previous_screen_orientation_primary_ = true;
// True when the divider is being dragged (not during its snap animation).
bool is_resizing_ = false;
......
......@@ -252,61 +252,37 @@ SplitViewDivider::~SplitViewDivider() {
observed_windows_.clear();
}
// static
gfx::Size SplitViewDivider::GetDividerSize(
const gfx::Rect& work_area_bounds,
OrientationLockType screen_orientation,
bool is_dragging) {
if (IsLandscapeOrientation(screen_orientation)) {
return is_dragging ? gfx::Size(kSplitviewDividerEnlargedShortSideLength,
work_area_bounds.height())
: gfx::Size(kSplitviewDividerShortSideLength,
work_area_bounds.height());
} else {
return is_dragging ? gfx::Size(work_area_bounds.width(),
kSplitviewDividerEnlargedShortSideLength)
: gfx::Size(work_area_bounds.width(),
kSplitviewDividerShortSideLength);
}
}
// static
gfx::Rect SplitViewDivider::GetDividerBoundsInScreen(
const gfx::Rect& work_area_bounds_in_screen,
OrientationLockType screen_orientation,
bool landscape,
int divider_position,
bool is_dragging) {
const gfx::Size divider_size = GetDividerSize(
work_area_bounds_in_screen, screen_orientation, is_dragging);
int dragging_diff = (kSplitviewDividerEnlargedShortSideLength -
kSplitviewDividerShortSideLength) /
2;
switch (screen_orientation) {
case OrientationLockType::kLandscapePrimary:
case OrientationLockType::kLandscapeSecondary:
return is_dragging
? gfx::Rect(work_area_bounds_in_screen.x() + divider_position -
dragging_diff,
work_area_bounds_in_screen.y(),
divider_size.width(), divider_size.height())
: gfx::Rect(work_area_bounds_in_screen.x() + divider_position,
work_area_bounds_in_screen.y(),
divider_size.width(), divider_size.height());
case OrientationLockType::kPortraitPrimary:
case OrientationLockType::kPortraitSecondary:
return is_dragging
? gfx::Rect(work_area_bounds_in_screen.x(),
work_area_bounds_in_screen.y() + divider_position -
(kSplitviewDividerEnlargedShortSideLength -
kSplitviewDividerShortSideLength) /
2,
divider_size.width(), divider_size.height())
: gfx::Rect(work_area_bounds_in_screen.x(),
work_area_bounds_in_screen.y() + divider_position,
divider_size.width(), divider_size.height());
default:
NOTREACHED();
return gfx::Rect();
const int dragging_diff = (kSplitviewDividerEnlargedShortSideLength -
kSplitviewDividerShortSideLength) /
2;
if (landscape) {
return is_dragging
? gfx::Rect(work_area_bounds_in_screen.x() + divider_position -
dragging_diff,
work_area_bounds_in_screen.y(),
kSplitviewDividerEnlargedShortSideLength,
work_area_bounds_in_screen.height())
: gfx::Rect(work_area_bounds_in_screen.x() + divider_position,
work_area_bounds_in_screen.y(),
kSplitviewDividerShortSideLength,
work_area_bounds_in_screen.height());
} else {
return is_dragging
? gfx::Rect(work_area_bounds_in_screen.x(),
work_area_bounds_in_screen.y() + divider_position -
dragging_diff,
work_area_bounds_in_screen.width(),
kSplitviewDividerEnlargedShortSideLength)
: gfx::Rect(work_area_bounds_in_screen.x(),
work_area_bounds_in_screen.y() + divider_position,
work_area_bounds_in_screen.width(),
kSplitviewDividerShortSideLength);
}
}
......@@ -325,10 +301,9 @@ gfx::Rect SplitViewDivider::GetDividerBoundsInScreen(bool is_dragging) {
Shell::GetPrimaryRootWindow()->GetChildById(
desks_util::GetActiveDeskContainerId()));
const int divider_position = controller_->divider_position();
const OrientationLockType screen_orientation = GetCurrentScreenOrientation();
return GetDividerBoundsInScreen(work_area_bounds_in_screen,
screen_orientation, divider_position,
is_dragging);
const bool landscape = IsCurrentScreenOrientationLandscape();
return GetDividerBoundsInScreen(work_area_bounds_in_screen, landscape,
divider_position, is_dragging);
}
void SplitViewDivider::SetAlwaysOnTop(bool on_top) {
......
......@@ -29,8 +29,6 @@ class ScopedWindowTargeter;
namespace ash {
enum class OrientationLockType;
class SplitViewController;
// Split view divider. It passes the mouse/gesture events to SplitViewController
......@@ -43,16 +41,10 @@ class ASH_EXPORT SplitViewDivider : public aura::WindowObserver,
SplitViewDivider(SplitViewController* controller, aura::Window* root_window);
~SplitViewDivider() override;
// Gets the size of the divider widget. The divider widget is enlarged during
// dragging. For now, it's a vertical rectangle.
static gfx::Size GetDividerSize(const gfx::Rect& work_area_bounds,
OrientationLockType screen_orientation,
bool is_dragging);
// static version of GetDividerBoundsInScreen(bool is_dragging) function.
static gfx::Rect GetDividerBoundsInScreen(
const gfx::Rect& work_area_bounds_in_screen,
OrientationLockType screen_orientation,
bool landscape,
int divider_position,
bool is_dragging);
......
......@@ -6,6 +6,7 @@
#include <vector>
#include "ash/display/screen_orientation_controller.h"
#include "ash/home_screen/home_screen_controller.h"
#include "ash/public/cpp/wallpaper_types.h"
#include "ash/root_window_controller.h"
......
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