Skip to content

Commit

Permalink
splitview: Move some functions from split_view_controller to other cl…
Browse files Browse the repository at this point in the history
…ass.

Since they dont use class members move to split_view_utils or
screen_orientation_controller.

Test: builds
Bug: none
Change-Id: I11950bc60a60549609b72b7f187f992a6d92ee05
Reviewed-on: https://chromium-review.googlesource.com/c/1345431
Commit-Queue: Sammie Quon <sammiequon@chromium.org>
Reviewed-by: Robert Flack <flackr@chromium.org>
Reviewed-by: Xiyuan Xia <xiyuan@chromium.org>
Reviewed-by: Xiaoqian Dai <xdai@chromium.org>
Cr-Commit-Position: refs/heads/master@{#616845}
  • Loading branch information
sammiequon71 authored and Commit Bot committed Dec 14, 2018
1 parent 8f40b28 commit 17d0def
Show file tree
Hide file tree
Showing 21 changed files with 277 additions and 243 deletions.
17 changes: 17 additions & 0 deletions ash/display/screen_orientation_controller.cc
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,23 @@ bool IsPortraitOrientation(OrientationLockType type) {
type == OrientationLockType::kPortraitSecondary;
}

OrientationLockType GetCurrentScreenOrientation() {
// ScreenOrientationController might be nullptr during shutdown.
// TODO(xdai|sammiequon): See if we can reorder so that users of the function
// (split_view_controller) get shutddown before screen orientation controller.
if (!Shell::Get()->screen_orientation_controller())
return OrientationLockType::kAny;
return Shell::Get()->screen_orientation_controller()->GetCurrentOrientation();
}

bool IsCurrentScreenOrientationLandscape() {
return IsLandscapeOrientation(GetCurrentScreenOrientation());
}

bool IsCurrentScreenOrientationPrimary() {
return IsPrimaryOrientation(GetCurrentScreenOrientation());
}

std::ostream& operator<<(std::ostream& out, const OrientationLockType& lock) {
switch (lock) {
case OrientationLockType::kAny:
Expand Down
4 changes: 4 additions & 0 deletions ash/display/screen_orientation_controller.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,10 @@ bool IsPrimaryOrientation(OrientationLockType type);
bool IsLandscapeOrientation(OrientationLockType type);
bool IsPortraitOrientation(OrientationLockType type);

ASH_EXPORT OrientationLockType GetCurrentScreenOrientation();
ASH_EXPORT bool IsCurrentScreenOrientationLandscape();
ASH_EXPORT bool IsCurrentScreenOrientationPrimary();

ASH_EXPORT std::ostream& operator<<(std::ostream& out,
const OrientationLockType& lock);

Expand Down
16 changes: 16 additions & 0 deletions ash/screen_util.cc
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
#include "ash/display/display_configuration_controller.h"
#include "ash/display/mirror_window_controller.h"
#include "ash/display/window_tree_host_manager.h"
#include "ash/public/cpp/shell_window_ids.h"
#include "ash/root_window_controller.h"
#include "ash/shelf/shelf.h"
#include "ash/shell.h"
Expand Down Expand Up @@ -50,6 +51,21 @@ gfx::Rect GetDisplayWorkAreaBoundsInParentForLockScreen(aura::Window* window) {
return bounds;
}

gfx::Rect GetDisplayWorkAreaBoundsInParentForDefaultContainer(
aura::Window* window) {
aura::Window* root_window = window->GetRootWindow();
return GetDisplayWorkAreaBoundsInParent(
root_window->GetChildById(kShellWindowId_DefaultContainer));
}

gfx::Rect GetDisplayWorkAreaBoundsInScreenForDefaultContainer(
aura::Window* window) {
gfx::Rect bounds =
GetDisplayWorkAreaBoundsInParentForDefaultContainer(window);
::wm::ConvertRectToScreen(window->GetRootWindow(), &bounds);
return bounds;
}

gfx::Rect GetDisplayBoundsWithShelf(aura::Window* window) {
if (!Shell::Get()->display_manager()->IsInUnifiedMode())
return window->GetRootWindow()->bounds();
Expand Down
6 changes: 6 additions & 0 deletions ash/screen_util.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,12 @@ ASH_EXPORT gfx::Rect GetDisplayWorkAreaBoundsInParent(aura::Window* window);
ASH_EXPORT gfx::Rect GetDisplayWorkAreaBoundsInParentForLockScreen(
aura::Window* window);

// Returns the display's work area bounds on the default container.
ASH_EXPORT gfx::Rect GetDisplayWorkAreaBoundsInParentForDefaultContainer(
aura::Window* window);
ASH_EXPORT gfx::Rect GetDisplayWorkAreaBoundsInScreenForDefaultContainer(
aura::Window* window);

// Returns the bounds of the physical display containing the shelf for
// |window|. Physical displays can differ from logical displays in unified
// desktop mode.
Expand Down
3 changes: 2 additions & 1 deletion ash/wm/base_state.cc
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
#include "ash/screen_util.h"
#include "ash/shell.h"
#include "ash/wm/splitview/split_view_controller.h"
#include "ash/wm/splitview/split_view_utils.h"
#include "ash/wm/window_positioning_utils.h"
#include "ash/wm/wm_event.h"
#include "ui/aura/client/aura_constants.h"
Expand Down Expand Up @@ -180,7 +181,7 @@ gfx::Rect BaseState::GetSnappedWindowBoundsInParent(
aura::Window* window,
const mojom::WindowStateType state_type) {
gfx::Rect bounds_in_parent;
if (SplitViewController::ShouldAllowSplitView()) {
if (ShouldAllowSplitView()) {
bounds_in_parent =
Shell::Get()->split_view_controller()->GetSnappedWindowBoundsInParent(
window, (state_type == mojom::WindowStateType::LEFT_SNAPPED)
Expand Down
3 changes: 2 additions & 1 deletion ash/wm/overview/overview_utils.cc
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
#include "ash/wm/overview/start_animation_observer.h"
#include "ash/wm/overview/window_selector_controller.h"
#include "ash/wm/splitview/split_view_controller.h"
#include "ash/wm/splitview/split_view_utils.h"
#include "ash/wm/window_state.h"
#include "ash/wm/window_transient_descendant_iterator.h"
#include "base/no_destructor.h"
Expand Down Expand Up @@ -110,7 +111,7 @@ bool CanCoverAvailableWorkspace(aura::Window* window) {
SplitViewController* split_view_controller =
Shell::Get()->split_view_controller();
if (split_view_controller->IsSplitViewModeActive())
return split_view_controller->CanSnap(window);
return CanSnapInSplitview(window);
return wm::GetWindowState(window)->IsMaximizedOrFullscreenOrPinned();
}

Expand Down
53 changes: 24 additions & 29 deletions ash/wm/overview/overview_window_drag_controller.cc
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
#include "ash/wm/overview/window_selector_item.h"
#include "ash/wm/splitview/split_view_constants.h"
#include "ash/wm/splitview/split_view_drag_indicators.h"
#include "ash/wm/splitview/split_view_utils.h"
#include "ash/wm/window_positioning_utils.h"
#include "base/numerics/ranges.h"
#include "ui/aura/window.h"
Expand Down Expand Up @@ -58,7 +59,7 @@ void OverviewWindowDragController::InitiateDrag(
item_ = item;
previous_event_location_ = location_in_screen;
initial_event_location_ = location_in_screen;
if (SplitViewController::ShouldAllowSplitView()) {
if (ShouldAllowSplitView()) {
started_in_snap_region_ =
GetSnapPosition(location_in_screen) != SplitViewController::NONE;
}
Expand All @@ -81,7 +82,7 @@ void OverviewWindowDragController::Drag(const gfx::Point& location_in_screen) {
window_selector_->GetGridWithRootWindow(item_->root_window())
->StartNudge(item_);
did_move_ = true;
} else if (SplitViewController::ShouldAllowSplitView()) {
} else if (ShouldAllowSplitView()) {
StartSplitViewDragMode(location_in_screen);
}
}
Expand Down Expand Up @@ -109,7 +110,7 @@ void OverviewWindowDragController::Drag(const gfx::Point& location_in_screen) {
// Update the split view divider bar status if necessary. If splitview is
// active when dragging the overview window, the split divider bar should be
// placed below the dragged window during dragging.
if (SplitViewController::ShouldAllowSplitView())
if (ShouldAllowSplitView())
split_view_controller_->OnWindowDragStarted(item_->GetWindow());

// Update the dragged |item_|'s bounds accordingly.
Expand All @@ -126,7 +127,7 @@ void OverviewWindowDragController::CompleteDrag(
// should be placed above the dragged window after drag ends. Note here the
// passed paramters |snap_position_| and |location_in_screen| won't be used in
// this function for this case, but they are passed in as placeholders.
if (SplitViewController::ShouldAllowSplitView()) {
if (ShouldAllowSplitView()) {
split_view_controller_->OnWindowDragEnded(
item_->GetWindow(), snap_position_, location_in_screen);
}
Expand Down Expand Up @@ -172,17 +173,16 @@ void OverviewWindowDragController::CompleteDrag(

void OverviewWindowDragController::StartSplitViewDragMode(
const gfx::Point& location_in_screen) {
DCHECK(SplitViewController::ShouldAllowSplitView());
DCHECK(ShouldAllowSplitView());

item_->ScaleUpSelectedItem(
OVERVIEW_ANIMATION_LAY_OUT_SELECTOR_ITEMS_IN_OVERVIEW);

did_move_ = true;
current_drag_behavior_ = DragBehavior::kDragToSnap;
window_selector_->SetSplitViewDragIndicatorsIndicatorState(
split_view_controller_->CanSnap(item_->GetWindow())
? IndicatorState::kDragArea
: IndicatorState::kCannotSnap,
CanSnapInSplitview(item_->GetWindow()) ? IndicatorState::kDragArea
: IndicatorState::kCannotSnap,
location_in_screen);
}

Expand All @@ -192,7 +192,7 @@ void OverviewWindowDragController::Fling(const gfx::Point& location_in_screen,
if (current_drag_behavior_ == DragBehavior::kDragToClose ||
current_drag_behavior_ == DragBehavior::kUndefined) {
if (std::abs(velocity_y) > kFlingToCloseVelocityThreshold) {
if (SplitViewController::ShouldAllowSplitView()) {
if (ShouldAllowSplitView()) {
split_view_controller_->OnWindowDragEnded(
item_->GetWindow(), snap_position_, location_in_screen);
}
Expand All @@ -219,10 +219,9 @@ void OverviewWindowDragController::ActivateDraggedWindow() {
// and the selected window cannot be snapped, exit splitview and activate
// the selected window, and also exit the overview.
SplitViewController::State split_state = split_view_controller_->state();
if (!SplitViewController::ShouldAllowSplitView() ||
split_state == SplitViewController::NO_SNAP) {
if (!ShouldAllowSplitView() || split_state == SplitViewController::NO_SNAP) {
window_selector_->SelectWindow(item_);
} else if (split_view_controller_->CanSnap(item_->GetWindow())) {
} else if (CanSnapInSplitview(item_->GetWindow())) {
SnapWindow(split_state == SplitViewController::LEFT_SNAPPED
? SplitViewController::RIGHT
: SplitViewController::LEFT);
Expand All @@ -236,7 +235,7 @@ void OverviewWindowDragController::ActivateDraggedWindow() {

void OverviewWindowDragController::ResetGesture() {
window_selector_->PositionWindows(/*animate=*/true);
if (SplitViewController::ShouldAllowSplitView()) {
if (ShouldAllowSplitView()) {
window_selector_->SetSplitViewDragIndicatorsIndicatorState(
IndicatorState::kNone, gfx::Point());
}
Expand All @@ -252,13 +251,13 @@ void OverviewWindowDragController::ResetWindowSelector() {

void OverviewWindowDragController::UpdateDragIndicatorsAndWindowGrid(
const gfx::Point& location_in_screen) {
DCHECK(SplitViewController::ShouldAllowSplitView());
DCHECK(ShouldAllowSplitView());
if (!ShouldUpdateDragIndicatorsOrSnap(location_in_screen))
return;

// Attempt to update the drag indicators and move the window grid only if the
// window is snappable.
if (!split_view_controller_->CanSnap(item_->GetWindow())) {
if (!CanSnapInSplitview(item_->GetWindow())) {
snap_position_ = SplitViewController::NONE;
return;
}
Expand All @@ -279,9 +278,8 @@ void OverviewWindowDragController::UpdateDragIndicatorsAndWindowGrid(
// cannot be snapped, otherwise show the drag ui.
if (snap_position_ == SplitViewController::NONE) {
window_selector_->SetSplitViewDragIndicatorsIndicatorState(
split_view_controller_->CanSnap(item_->GetWindow())
? IndicatorState::kDragArea
: IndicatorState::kCannotSnap,
CanSnapInSplitview(item_->GetWindow()) ? IndicatorState::kDragArea
: IndicatorState::kCannotSnap,
gfx::Point());
return;
}
Expand All @@ -298,17 +296,15 @@ void OverviewWindowDragController::UpdateDragIndicatorsAndWindowGrid(
bool OverviewWindowDragController::ShouldUpdateDragIndicatorsOrSnap(
const gfx::Point& event_location) {
auto snap_position = GetSnapPosition(event_location);
const bool inverted =
!split_view_controller_->IsCurrentScreenOrientationPrimary();
const bool inverted = !IsCurrentScreenOrientationPrimary();
// Note: in some orientations SplitViewController::LEFT is not physically on
// the left/top.
const bool on_the_left_or_top =
(!inverted && snap_position == SplitViewController::LEFT) ||
(inverted && snap_position == SplitViewController::RIGHT);

// Snap the window if it is less than |kDistanceFromEdgeDp| from the edge.
const bool landscape =
split_view_controller_->IsCurrentScreenOrientationLandscape();
const bool landscape = IsCurrentScreenOrientationLandscape();
gfx::Rect area(
screen_util::GetDisplayWorkAreaBoundsInParent(item_->GetWindow()));
::wm::ConvertRectToScreen(item_->GetWindow()->GetRootWindow(), &area);
Expand Down Expand Up @@ -357,15 +353,13 @@ bool OverviewWindowDragController::ShouldUpdateDragIndicatorsOrSnap(
SplitViewController::SnapPosition OverviewWindowDragController::GetSnapPosition(
const gfx::Point& location_in_screen) const {
DCHECK(item_);
DCHECK(SplitViewController::ShouldAllowSplitView());
DCHECK(ShouldAllowSplitView());
gfx::Rect area(
screen_util::GetDisplayWorkAreaBoundsInParent(item_->GetWindow()));
::wm::ConvertRectToScreen(item_->GetWindow()->GetRootWindow(), &area);

const bool is_landscape =
split_view_controller_->IsCurrentScreenOrientationLandscape();
const bool is_primary =
split_view_controller_->IsCurrentScreenOrientationPrimary();
const bool is_landscape = IsCurrentScreenOrientationLandscape();
const bool is_primary = IsCurrentScreenOrientationPrimary();

// If split view mode is active at the moment, and dragging an overview window
// to snap it to a position that already has a snapped window in place, we
Expand Down Expand Up @@ -423,8 +417,9 @@ gfx::Rect OverviewWindowDragController::GetGridBounds(
aura::Window* pending_snapped_window = item_->GetWindow();
switch (snap_position) {
case SplitViewController::NONE:
return gfx::Rect(split_view_controller_->GetDisplayWorkAreaBoundsInParent(
pending_snapped_window));
return gfx::Rect(
screen_util::GetDisplayWorkAreaBoundsInParentForDefaultContainer(
pending_snapped_window));
case SplitViewController::LEFT:
return split_view_controller_->GetSnappedWindowBoundsInScreen(
pending_snapped_window, SplitViewController::RIGHT);
Expand Down
5 changes: 3 additions & 2 deletions ash/wm/overview/window_grid.cc
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
#include "ash/wm/overview/window_selector_controller.h"
#include "ash/wm/overview/window_selector_delegate.h"
#include "ash/wm/overview/window_selector_item.h"
#include "ash/wm/splitview/split_view_controller.h"
#include "ash/wm/splitview/split_view_drag_indicators.h"
#include "ash/wm/tablet_mode/tablet_mode_controller.h"
#include "ash/wm/tablet_mode/tablet_mode_window_state.h"
Expand Down Expand Up @@ -177,7 +178,7 @@ gfx::Rect GetGridBoundsInScreenDuringDragging(aura::Window* dragged_window,
return split_view_controller->GetSnappedWindowBoundsInScreen(
dragged_window, SplitViewController::LEFT);
default:
return split_view_controller->GetDisplayWorkAreaBoundsInScreen(
return screen_util::GetDisplayWorkAreaBoundsInScreenForDefaultContainer(
dragged_window);
}
}
Expand All @@ -194,7 +195,7 @@ gfx::Rect GetGridBoundsInScreenAfterDragging(aura::Window* dragged_window) {
return split_view_controller->GetSnappedWindowBoundsInScreen(
dragged_window, SplitViewController::LEFT);
default:
return split_view_controller->GetDisplayWorkAreaBoundsInScreen(
return screen_util::GetDisplayWorkAreaBoundsInScreenForDefaultContainer(
dragged_window);
}
}
Expand Down
20 changes: 9 additions & 11 deletions ash/wm/overview/window_selector.cc
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
#include "ash/wm/overview/window_selector_delegate.h"
#include "ash/wm/overview/window_selector_item.h"
#include "ash/wm/splitview/split_view_drag_indicators.h"
#include "ash/wm/splitview/split_view_utils.h"
#include "ash/wm/switchable_windows.h"
#include "ash/wm/window_state.h"
#include "ash/wm/window_util.h"
Expand Down Expand Up @@ -138,10 +139,9 @@ void UpdateShelfVisibility() {
// clamp the bounds to a minimum size and shift the bounds offscreen.
gfx::Rect GetGridBoundsInScreen(aura::Window* root_window,
bool divider_changed) {
SplitViewController* split_view_controller =
Shell::Get()->split_view_controller();
gfx::Rect work_area =
split_view_controller->GetDisplayWorkAreaBoundsInScreen(root_window);
screen_util::GetDisplayWorkAreaBoundsInScreenForDefaultContainer(
root_window);

// If the shelf is in auto hide, overview will force it to be in auto hide
// shown, but we want to place the thumbnails as if the shelf was shown, so
Expand All @@ -165,6 +165,8 @@ gfx::Rect GetGridBoundsInScreen(aura::Window* root_window,
}
}

SplitViewController* split_view_controller =
Shell::Get()->split_view_controller();
if (!split_view_controller->IsSplitViewModeActive())
return work_area;

Expand All @@ -178,8 +180,7 @@ gfx::Rect GetGridBoundsInScreen(aura::Window* root_window,
if (!divider_changed)
return bounds;

const bool landscape =
split_view_controller->IsCurrentScreenOrientationLandscape();
const bool landscape = IsCurrentScreenOrientationLandscape();
const int min_length =
(landscape ? work_area.width() : work_area.height()) / 3;
const int current_length = landscape ? bounds.width() : bounds.height();
Expand All @@ -198,8 +199,7 @@ gfx::Rect GetGridBoundsInScreen(aura::Window* root_window,
// respectively), if |opposite_position| is left AND current orientation is
// primary, OR |opposite_position| is right AND current orientation is not
// primary. This is an X-NOR condition.
const bool primary =
split_view_controller->IsCurrentScreenOrientationPrimary();
const bool primary = IsCurrentScreenOrientationPrimary();
const bool left_or_top =
(primary == (opposite_position == SplitViewController::LEFT));
if (left_or_top) {
Expand Down Expand Up @@ -320,7 +320,7 @@ void WindowSelector::Init(const WindowList& windows,
if (restore_focus_window_)
restore_focus_window_->AddObserver(this);

if (SplitViewController::ShouldAllowSplitView())
if (ShouldAllowSplitView())
split_view_drag_indicators_ = std::make_unique<SplitViewDragIndicators>();

aura::Window::Windows root_windows = Shell::GetAllRootWindows();
Expand Down Expand Up @@ -420,9 +420,7 @@ void WindowSelector::Shutdown() {
// Stop observing split view state changes before restoring window focus.
// Otherwise the activation of the window triggers OnSplitViewStateChanged()
// that will call into this function again.
SplitViewController* split_view_controller =
Shell::Get()->split_view_controller();
split_view_controller->RemoveObserver(this);
Shell::Get()->split_view_controller()->RemoveObserver(this);

size_t remaining_items = 0;
for (std::unique_ptr<WindowGrid>& window_grid : grid_list_) {
Expand Down
Loading

0 comments on commit 17d0def

Please sign in to comment.