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

Side by Side Diff: ash/wm/drag_window_resizer.cc

Issue 1838003002: Create drag windows on all displays (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 8 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
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "ash/wm/drag_window_resizer.h" 5 #include "ash/wm/drag_window_resizer.h"
6 6
7 #include "ash/display/mouse_cursor_event_filter.h" 7 #include "ash/display/mouse_cursor_event_filter.h"
8 #include "ash/screen_util.h" 8 #include "ash/screen_util.h"
9 #include "ash/shell.h" 9 #include "ash/shell.h"
10 #include "ash/wm/coordinate_conversion.h" 10 #include "ash/wm/coordinate_conversion.h"
11 #include "ash/wm/drag_window_controller.h" 11 #include "ash/wm/drag_window_controller.h"
12 #include "ash/wm/window_state.h" 12 #include "ash/wm/window_state.h"
13 #include "ash/wm/window_util.h" 13 #include "ash/wm/window_util.h"
14 #include "base/memory/weak_ptr.h" 14 #include "base/memory/weak_ptr.h"
15 #include "ui/aura/client/aura_constants.h" 15 #include "ui/aura/client/aura_constants.h"
16 #include "ui/aura/env.h" 16 #include "ui/aura/env.h"
17 #include "ui/aura/window.h" 17 #include "ui/aura/window.h"
18 #include "ui/aura/window_delegate.h" 18 #include "ui/aura/window_delegate.h"
19 #include "ui/aura/window_event_dispatcher.h" 19 #include "ui/aura/window_event_dispatcher.h"
20 #include "ui/base/hit_test.h" 20 #include "ui/base/hit_test.h"
21 #include "ui/base/ui_base_types.h" 21 #include "ui/base/ui_base_types.h"
22 #include "ui/gfx/screen.h" 22 #include "ui/gfx/screen.h"
23 #include "ui/wm/core/coordinate_conversion.h" 23 #include "ui/wm/core/coordinate_conversion.h"
24 #include "ui/wm/core/window_util.h" 24 #include "ui/wm/core/window_util.h"
25 25
26 namespace ash { 26 namespace ash {
27 namespace {
28
29 // The maximum opacity of the drag phantom window.
30 const float kMaxOpacity = 0.8f;
31
32 // Returns true if Ash has more than one root window.
33 bool HasSecondaryRootWindows() {
34 return Shell::GetAllRootWindows().size() > 1;
35 }
36
37 // When there are more than one root windows, returns all root windows which are
38 // not |root_window|. Returns an empty vector if only one root window exists.
39 aura::Window::Windows GetOtherRootWindows(aura::Window* root_window) {
40 aura::Window::Windows root_windows = Shell::GetAllRootWindows();
41 aura::Window::Windows other_root_windows;
42 if (root_windows.size() < 2)
43 return other_root_windows;
44 for (size_t i = 0; i < root_windows.size(); ++i) {
45 if (root_windows[i] != root_window)
46 other_root_windows.push_back(root_windows[i]);
47 }
48 return other_root_windows;
49 }
50
51 } // namespace
52 27
53 // static 28 // static
54 DragWindowResizer* DragWindowResizer::instance_ = NULL; 29 DragWindowResizer* DragWindowResizer::instance_ = NULL;
55 30
56 DragWindowResizer::~DragWindowResizer() { 31 DragWindowResizer::~DragWindowResizer() {
57 if (window_state_) 32 if (window_state_)
58 window_state_->DeleteDragDetails(); 33 window_state_->DeleteDragDetails();
59 Shell* shell = Shell::GetInstance(); 34 Shell* shell = Shell::GetInstance();
60 shell->mouse_cursor_filter()->set_mouse_warp_enabled(true); 35 shell->mouse_cursor_filter()->set_mouse_warp_enabled(true);
61 shell->mouse_cursor_filter()->HideSharedEdgeIndicator(); 36 shell->mouse_cursor_filter()->HideSharedEdgeIndicator();
(...skipping 10 matching lines...) Expand all
72 47
73 void DragWindowResizer::Drag(const gfx::Point& location, int event_flags) { 48 void DragWindowResizer::Drag(const gfx::Point& location, int event_flags) {
74 base::WeakPtr<DragWindowResizer> resizer(weak_ptr_factory_.GetWeakPtr()); 49 base::WeakPtr<DragWindowResizer> resizer(weak_ptr_factory_.GetWeakPtr());
75 next_window_resizer_->Drag(location, event_flags); 50 next_window_resizer_->Drag(location, event_flags);
76 51
77 if (!resizer) 52 if (!resizer)
78 return; 53 return;
79 54
80 last_mouse_location_ = location; 55 last_mouse_location_ = location;
81 // Show a phantom window for dragging in another root window. 56 // Show a phantom window for dragging in another root window.
82 if (HasSecondaryRootWindows()) { 57 if (gfx::Screen::GetScreen()->GetNumDisplays() > 1) {
83 gfx::Point location_in_screen = location; 58 gfx::Point location_in_screen = location;
84 ::wm::ConvertPointToScreen(GetTarget()->parent(), &location_in_screen); 59 ::wm::ConvertPointToScreen(GetTarget()->parent(), &location_in_screen);
85 const bool in_original_root = 60 UpdateDragWindow(GetTarget()->bounds(), location_in_screen);
86 wm::GetRootWindowAt(location_in_screen) == GetTarget()->GetRootWindow();
87 UpdateDragWindow(GetTarget()->bounds(), in_original_root);
88 } else { 61 } else {
89 drag_window_controllers_.clear(); 62 drag_window_controller_.reset();
90 } 63 }
91 } 64 }
92 65
93 void DragWindowResizer::CompleteDrag() { 66 void DragWindowResizer::CompleteDrag() {
94 next_window_resizer_->CompleteDrag(); 67 next_window_resizer_->CompleteDrag();
95 68
96 GetTarget()->layer()->SetOpacity(details().initial_opacity); 69 GetTarget()->layer()->SetOpacity(details().initial_opacity);
97 drag_window_controllers_.clear(); 70 drag_window_controller_.reset();
98 71
99 // Check if the destination is another display. 72 // Check if the destination is another display.
100 gfx::Point last_mouse_location_in_screen = last_mouse_location_; 73 gfx::Point last_mouse_location_in_screen = last_mouse_location_;
101 ::wm::ConvertPointToScreen(GetTarget()->parent(), 74 ::wm::ConvertPointToScreen(GetTarget()->parent(),
102 &last_mouse_location_in_screen); 75 &last_mouse_location_in_screen);
103 gfx::Screen* screen = gfx::Screen::GetScreen(); 76 gfx::Screen* screen = gfx::Screen::GetScreen();
104 const gfx::Display dst_display = 77 const gfx::Display dst_display =
105 screen->GetDisplayNearestPoint(last_mouse_location_in_screen); 78 screen->GetDisplayNearestPoint(last_mouse_location_in_screen);
106 79
107 if (dst_display.id() != 80 if (dst_display.id() !=
(...skipping 24 matching lines...) Expand all
132 ash::wm::AdjustBoundsToEnsureMinimumWindowVisibility( 105 ash::wm::AdjustBoundsToEnsureMinimumWindowVisibility(
133 dst_display.bounds(), &dst_bounds); 106 dst_display.bounds(), &dst_bounds);
134 107
135 GetTarget()->SetBoundsInScreen(dst_bounds, dst_display); 108 GetTarget()->SetBoundsInScreen(dst_bounds, dst_display);
136 } 109 }
137 } 110 }
138 111
139 void DragWindowResizer::RevertDrag() { 112 void DragWindowResizer::RevertDrag() {
140 next_window_resizer_->RevertDrag(); 113 next_window_resizer_->RevertDrag();
141 114
142 drag_window_controllers_.clear(); 115 drag_window_controller_.reset();
143 GetTarget()->layer()->SetOpacity(details().initial_opacity); 116 GetTarget()->layer()->SetOpacity(details().initial_opacity);
144 } 117 }
145 118
146 DragWindowResizer::DragWindowResizer(WindowResizer* next_window_resizer, 119 DragWindowResizer::DragWindowResizer(WindowResizer* next_window_resizer,
147 wm::WindowState* window_state) 120 wm::WindowState* window_state)
148 : WindowResizer(window_state), 121 : WindowResizer(window_state),
149 next_window_resizer_(next_window_resizer), 122 next_window_resizer_(next_window_resizer),
150 weak_ptr_factory_(this) { 123 weak_ptr_factory_(this) {
151 // The pointer should be confined in one display during resizing a window 124 // The pointer should be confined in one display during resizing a window
152 // because the window cannot span two displays at the same time anyway. The 125 // because the window cannot span two displays at the same time anyway. The
153 // exception is window/tab dragging operation. During that operation, 126 // exception is window/tab dragging operation. During that operation,
154 // |mouse_warp_mode_| should be set to WARP_DRAG so that the user could move a 127 // |mouse_warp_mode_| should be set to WARP_DRAG so that the user could move a
155 // window/tab to another display. 128 // window/tab to another display.
156 MouseCursorEventFilter* mouse_cursor_filter = 129 MouseCursorEventFilter* mouse_cursor_filter =
157 Shell::GetInstance()->mouse_cursor_filter(); 130 Shell::GetInstance()->mouse_cursor_filter();
158 mouse_cursor_filter->set_mouse_warp_enabled(ShouldAllowMouseWarp()); 131 mouse_cursor_filter->set_mouse_warp_enabled(ShouldAllowMouseWarp());
159 if (ShouldAllowMouseWarp()) 132 if (ShouldAllowMouseWarp())
160 mouse_cursor_filter->ShowSharedEdgeIndicator(GetTarget()->GetRootWindow()); 133 mouse_cursor_filter->ShowSharedEdgeIndicator(GetTarget()->GetRootWindow());
161 instance_ = this; 134 instance_ = this;
162 } 135 }
163 136
164 void DragWindowResizer::UpdateDragWindow(const gfx::Rect& bounds, 137 void DragWindowResizer::UpdateDragWindow(
165 bool in_original_root) { 138 const gfx::Rect& bounds_in_parent,
139 const gfx::Point& drag_location_in_screen) {
166 if (details().window_component != HTCAPTION || !ShouldAllowMouseWarp()) 140 if (details().window_component != HTCAPTION || !ShouldAllowMouseWarp())
167 return; 141 return;
168 142
169 // It's available. Show a phantom window on the display if needed. 143 if (!drag_window_controller_)
170 aura::Window::Windows other_roots = 144 drag_window_controller_.reset(new DragWindowController(GetTarget()));
171 GetOtherRootWindows(GetTarget()->GetRootWindow());
172 size_t drag_window_controller_count = 0;
173 for (size_t i = 0; i < other_roots.size(); ++i) {
174 aura::Window* another_root = other_roots[i];
175 const gfx::Rect root_bounds_in_screen(another_root->GetBoundsInScreen());
176 const gfx::Rect bounds_in_screen =
177 ScreenUtil::ConvertRectToScreen(GetTarget()->parent(), bounds);
178 gfx::Rect bounds_in_another_root =
179 gfx::IntersectRects(root_bounds_in_screen, bounds_in_screen);
180 const float fraction_in_another_window =
181 (bounds_in_another_root.width() * bounds_in_another_root.height()) /
182 static_cast<float>(bounds.width() * bounds.height());
183 145
184 if (fraction_in_another_window > 0) { 146 const gfx::Rect bounds_in_screen =
185 if (drag_window_controllers_.size() < ++drag_window_controller_count) 147 ScreenUtil::ConvertRectToScreen(GetTarget()->parent(), bounds_in_parent);
186 drag_window_controllers_.resize(drag_window_controller_count); 148
187 ScopedVector<DragWindowController>::reference drag_window_controller = 149 gfx::Rect root_bounds_in_screen =
188 drag_window_controllers_.back(); 150 GetTarget()->GetRootWindow()->GetBoundsInScreen();
189 if (!drag_window_controller) { 151 if (root_bounds_in_screen.Contains(drag_location_in_screen)) {
190 drag_window_controller = new DragWindowController(GetTarget()); 152 GetTarget()->layer()->SetOpacity(1.0f);
191 // Always show the drag phantom on the |another_root| window. 153 } else {
192 drag_window_controller->SetDestinationDisplay( 154 gfx::Rect visible_bounds = root_bounds_in_screen;
193 gfx::Screen::GetScreen()->GetDisplayNearestWindow(another_root)); 155 visible_bounds.Intersect(bounds_in_screen);
194 drag_window_controller->Show(); 156 float opacity = DragWindowController::GetDragWindowOpacity(bounds_in_screen,
195 } else { 157 visible_bounds);
196 // No animation. 158 GetTarget()->layer()->SetOpacity(opacity);
stevenjb 2016/03/29 18:56:13 nit: float opacity; if (root_bounds_in_screen.Cont
oshima 2016/03/30 21:21:02 Done, with slightly less code.
197 drag_window_controller->SetBounds(bounds_in_screen);
198 }
199 const float phantom_opacity =
200 !in_original_root ? 1 : (kMaxOpacity * fraction_in_another_window);
201 const float window_opacity =
202 in_original_root ? 1
203 : (kMaxOpacity * (1 - fraction_in_another_window));
204 drag_window_controller->SetOpacity(phantom_opacity);
205 GetTarget()->layer()->SetOpacity(window_opacity);
206 } else {
207 GetTarget()->layer()->SetOpacity(1.0f);
208 }
209 } 159 }
210 160
211 // If we have more drag window controllers allocated than needed, release the 161 drag_window_controller_->Update(bounds_in_screen, drag_location_in_screen);
212 // excess controllers by shrinking the vector |drag_window_controller_|.
213 DCHECK_GE(drag_window_controllers_.size(), drag_window_controller_count);
214 if (drag_window_controllers_.size() > drag_window_controller_count)
215 drag_window_controllers_.resize(drag_window_controller_count);
216 } 162 }
217 163
218 bool DragWindowResizer::ShouldAllowMouseWarp() { 164 bool DragWindowResizer::ShouldAllowMouseWarp() {
219 return details().window_component == HTCAPTION && 165 return details().window_component == HTCAPTION &&
220 !::wm::GetTransientParent(GetTarget()) && 166 !::wm::GetTransientParent(GetTarget()) &&
221 wm::IsWindowUserPositionable(GetTarget()); 167 wm::IsWindowUserPositionable(GetTarget());
222 } 168 }
223 169
224 } // namespace ash 170 } // namespace ash
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698