Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(179)

Side by Side Diff: ash/wm/overview/overview_window_drag_controller.cc

Issue 2955203002: Cros Tablet Window management - Split Screen part II (Closed)
Patch Set: Rebase. Created 3 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(Empty)
1 // Copyright 2017 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include "ash/wm/overview/overview_window_drag_controller.h"
6
7 #include "ash/screen_util.h"
8 #include "ash/shell.h"
9 #include "ash/wm/overview/scoped_transform_overview_window.h"
10 #include "ash/wm/overview/window_selector.h"
11 #include "ash/wm/overview/window_selector_item.h"
12 #include "ash/wm/window_positioning_utils.h"
13 #include "ash/wm/window_state.h"
14 #include "ash/wm/wm_event.h"
15 #include "ash/wm/workspace/phantom_window_controller.h"
16 #include "ui/aura/window.h"
17 #include "ui/wm/core/coordinate_conversion.h"
18
19 namespace ash {
20
21 namespace {
22
23 // The minimum offset that will be considered as a drag event.
24 const int kMinimiumDragOffset = 5;
oshima 2017/07/14 18:43:11 nit: constexpr
xdai1 2017/07/18 17:36:44 Done.
25
26 // Snapping distance between the dragged window with the screen edge. It's
27 // useful especially for touch events.
28 const int kScreenEdgeInsetForDrag = 200;
oshima 2017/07/14 18:43:11 ditto
xdai1 2017/07/18 17:36:44 Done.
29
30 } // namespace
31
32 OverviewWindowDragController::OverviewWindowDragController(
33 WindowSelector* window_selector)
34 : window_selector_(window_selector),
35 split_view_controller_(Shell::Get()->split_view_controller()) {}
36
37 OverviewWindowDragController::~OverviewWindowDragController() {}
38
39 void OverviewWindowDragController::InitiateDrag(
40 WindowSelectorItem* item,
41 const gfx::Point& location_in_screen) {
42 previous_event_location_ = location_in_screen;
43 item_ = item;
44 }
45
46 void OverviewWindowDragController::Drag(const gfx::Point& location_in_screen) {
47 if (!did_move_ &&
48 (std::abs(location_in_screen.x() - previous_event_location_.x()) <
49 kMinimiumDragOffset ||
50 std::abs(location_in_screen.y() - previous_event_location_.y()) <
51 kMinimiumDragOffset)) {
52 return;
53 }
54 did_move_ = true;
55
56 // Update the dragged |item_|'s bounds accordingly.
57 gfx::Rect bounds(item_->target_bounds());
58 bounds.Offset(location_in_screen.x() - previous_event_location_.x(),
59 location_in_screen.y() - previous_event_location_.y());
60 item_->SetBounds(bounds, OverviewAnimationType::OVERVIEW_ANIMATION_NONE);
61 previous_event_location_ = location_in_screen;
62
63 UpdatePhantomWindow(location_in_screen);
64 }
65
66 void OverviewWindowDragController::CompleteDrag() {
67 phantom_window_controller_.reset();
68
69 if (!did_move_) {
70 // If no drag was initiated (e.g., a click/tap on the overview window),
71 // activate the window. If the split view is active and has a left window,
72 // snap the current window to right. If the split view is active and has a
73 // right window, snap the current window to left.
74 SplitViewController::State split_state = split_view_controller_->state();
75 if (split_state == SplitViewController::NO_SNAP) {
76 window_selector_->SelectWindow(item_);
77 } else {
78 SnapWindow(split_state == SplitViewController::LEFT_SNAPPED
79 ? SplitViewController::RIGHT
80 : SplitViewController::LEFT);
81 }
82 } else {
83 // If the window was dragged around but should not be snapped, move it back
84 // to overview window grid.
85 if (snap_position_ == SplitViewController::NONE)
86 window_selector_->PositionWindows(true /* animate */);
87 else
88 SnapWindow(snap_position_);
89 did_move_ = false;
90 }
91 }
92
93 void OverviewWindowDragController::UpdatePhantomWindow(
94 const gfx::Point& location_in_screen) {
95 SplitViewController::SnapPosition last_snap_position = snap_position_;
96 snap_position_ = GetSnapPosition(location_in_screen);
97 if (snap_position_ == SplitViewController::NONE ||
98 snap_position_ != last_snap_position) {
99 phantom_window_controller_.reset();
100 if (snap_position_ == SplitViewController::NONE)
101 return;
102 }
103
104 const bool can_snap = snap_position_ != SplitViewController::NONE &&
105 wm::GetWindowState(item_->GetWindow())->CanSnap();
106 if (!can_snap) {
107 snap_position_ = SplitViewController::NONE;
108 phantom_window_controller_.reset();
109 return;
110 }
111
112 aura::Window* target_window = item_->GetWindow();
113 gfx::Rect phantom_bounds_in_screen =
114 split_view_controller_->GetSnappedWindowBoundsInScreen(target_window,
115 snap_position_);
116
117 if (!phantom_window_controller_) {
118 phantom_window_controller_ =
119 base::MakeUnique<PhantomWindowController>(target_window);
120 }
121 phantom_window_controller_->Show(phantom_bounds_in_screen);
122 }
123
124 SplitViewController::SnapPosition OverviewWindowDragController::GetSnapPosition(
125 const gfx::Point& location_in_screen) {
126 gfx::Rect area(
127 ScreenUtil::GetDisplayWorkAreaBoundsInParent(item_->GetWindow()));
128 ::wm::ConvertRectToScreen(item_->GetWindow()->GetRootWindow(), &area);
129 area.Inset(kScreenEdgeInsetForDrag, 0);
130
131 if (location_in_screen.x() <= area.x())
132 return SplitViewController::LEFT;
133 if (location_in_screen.x() >= area.right() - 1)
134 return SplitViewController::RIGHT;
135 return SplitViewController::NONE;
136 }
137
138 void OverviewWindowDragController::SnapWindow(
139 SplitViewController::SnapPosition snap_position) {
140 DCHECK_NE(snap_position, SplitViewController::NONE);
141
142 item_->EnsureVisible();
143 item_->RestoreWindow();
144
145 // |item_| will be deleted after RemoveWindowSelectorItem().
146 aura::Window* window = item_->GetWindow();
147 window_selector_->RemoveWindowSelectorItem(item_);
148 split_view_controller_->SnapWindow(window, snap_position);
149 item_ = nullptr;
150 }
151
152 } // namespace ash
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698