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

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

Issue 11411344: Extract the code for supporing extended desktop from WorkspaceWindowResizer into DragWindowResizer. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 8 years 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 | Annotate | Revision Log
OLDNEW
(Empty)
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
3 // found in the LICENSE file.
4
5 #include "ash/wm/drag_window_resizer.h"
6
7 #include "ash/display/mouse_cursor_event_filter.h"
8 #include "ash/screen_ash.h"
9 #include "ash/shell.h"
10 #include "ash/wm/coordinate_conversion.h"
11 #include "ash/wm/cursor_manager.h"
12 #include "ash/wm/drag_window_controller.h"
13 #include "ash/wm/property_util.h"
14 #include "ui/aura/client/aura_constants.h"
15 #include "ui/aura/env.h"
16 #include "ui/aura/root_window.h"
17 #include "ui/aura/window.h"
18 #include "ui/aura/window_delegate.h"
19 #include "ui/base/hit_test.h"
20 #include "ui/base/ui_base_types.h"
21 #include "ui/gfx/screen.h"
22
23 namespace ash {
24 namespace internal {
25
26 namespace {
27
28 // The maximum opacity of the drag phantom window.
29 const float kMaxOpacity = 0.8f;
30
31 // Returns true if Ash has more than one root window.
32 bool HasSecondaryRootWindow() {
33 return Shell::GetAllRootWindows().size() > 1;
34 }
35
36 // When there are two root windows, returns one of the root windows which is not
37 // |root_window|. Returns NULL if only one root window exists.
38 aura::RootWindow* GetAnotherRootWindow(aura::RootWindow* root_window) {
39 Shell::RootWindowList root_windows = Shell::GetAllRootWindows();
40 if (root_windows.size() < 2)
41 return NULL;
42 DCHECK_EQ(2U, root_windows.size());
43 if (root_windows[0] == root_window)
44 return root_windows[1];
45 return root_windows[0];
46 }
47
48 }
49
50 DragWindowResizer::DragWindowResizer(WindowResizer* window_resizer,
51 const Details& details)
52 : window_resizer_(window_resizer),
53 details_(details),
54 destroyed_(NULL) {
55 // The pointer should be confined in one display during resizing a window
56 // because the window cannot span two displays at the same time anyway. The
57 // exception is window/tab dragging operation. During that operation,
58 // |mouse_warp_mode_| should be set to WARP_DRAG so that the user could move a
59 // window/tab to another display.
60 MouseCursorEventFilter* mouse_cursor_filter =
61 Shell::GetInstance()->mouse_cursor_filter();
62 mouse_cursor_filter->set_mouse_warp_mode(
63 ShouldAllowMouseWarp() ?
64 MouseCursorEventFilter::WARP_DRAG : MouseCursorEventFilter::WARP_NONE);
65 if (ShouldAllowMouseWarp()) {
66 mouse_cursor_filter->ShowSharedEdgeIndicator(
67 details.window->GetRootWindow());
68 }
69 }
70
71 DragWindowResizer::~DragWindowResizer() {
72 Shell* shell = Shell::GetInstance();
73 shell->mouse_cursor_filter()->set_mouse_warp_mode(
74 MouseCursorEventFilter::WARP_ALWAYS);
75 shell->mouse_cursor_filter()->HideSharedEdgeIndicator();
76
77 if (destroyed_)
78 *destroyed_ = true;
79 }
80
81 void DragWindowResizer::Drag(const gfx::Point& location, int event_flags) {
82 bool destroyed = false;
83 destroyed_ = &destroyed;
84 window_resizer_->Drag(location, event_flags);
85 if (destroyed)
86 return;
87 last_mouse_location_ = location;
88
89 // Show a phantom window for dragging in another root window.
90 if (HasSecondaryRootWindow()) {
91 gfx::Point location_in_screen = location;
92 wm::ConvertPointToScreen(GetTarget()->parent(), &location_in_screen);
93 const bool in_original_root =
94 wm::GetRootWindowAt(location_in_screen) == GetTarget()->GetRootWindow();
95 UpdateDragWindow(GetTarget()->bounds(), in_original_root);
96 } else {
97 drag_window_controller_.reset();
98 }
99 }
100
101 void DragWindowResizer::CompleteDrag(int event_flags) {
102 window_resizer_->CompleteDrag(event_flags);
103
104 GetTarget()->layer()->SetOpacity(details_.initial_opacity);
105 drag_window_controller_.reset();
106
107 // Check if the destination is another display.
108 gfx::Point last_mouse_location_in_screen = last_mouse_location_;
109 wm::ConvertPointToScreen(GetTarget()->parent(),
110 &last_mouse_location_in_screen);
111 gfx::Screen* screen = Shell::GetScreen();
112 const gfx::Display dst_display =
113 screen->GetDisplayNearestPoint(last_mouse_location_in_screen);
114
115 if (dst_display.id() !=
116 screen->GetDisplayNearestWindow(GetTarget()->GetRootWindow()).id()) {
117 const gfx::Rect dst_bounds =
118 ScreenAsh::ConvertRectToScreen(GetTarget()->parent(),
119 GetTarget()->bounds());
120 GetTarget()->SetBoundsInScreen(dst_bounds, dst_display);
121 }
122 }
123
124 void DragWindowResizer::RevertDrag() {
125 window_resizer_->RevertDrag();
126
127 drag_window_controller_.reset();
128 GetTarget()->layer()->SetOpacity(details_.initial_opacity);
129 }
130
131 aura::Window* DragWindowResizer::GetTarget() {
132 return window_resizer_->GetTarget();
133 }
134
135 void DragWindowResizer::UpdateDragWindow(const gfx::Rect& bounds,
136 bool in_original_root) {
137 if (details_.window_component != HTCAPTION || !ShouldAllowMouseWarp())
138 return;
139
140 // It's available. Show a phantom window on the display if needed.
141 aura::RootWindow* another_root =
142 GetAnotherRootWindow(GetTarget()->GetRootWindow());
143 const gfx::Rect root_bounds_in_screen(another_root->GetBoundsInScreen());
144 const gfx::Rect bounds_in_screen =
145 ScreenAsh::ConvertRectToScreen(GetTarget()->parent(), bounds);
146 gfx::Rect bounds_in_another_root =
147 gfx::IntersectRects(root_bounds_in_screen, bounds_in_screen);
148 const float fraction_in_another_window =
149 (bounds_in_another_root.width() * bounds_in_another_root.height()) /
150 static_cast<float>(bounds.width() * bounds.height());
151
152 if (fraction_in_another_window > 0) {
153 if (!drag_window_controller_.get()) {
154 drag_window_controller_.reset(
155 new DragWindowController(GetTarget()));
156 // Always show the drag phantom on the |another_root| window.
157 drag_window_controller_->SetDestinationDisplay(
158 Shell::GetScreen()->GetDisplayMatching(
159 another_root->GetBoundsInScreen()));
160 drag_window_controller_->Show();
161 } else {
162 // No animation.
163 drag_window_controller_->SetBounds(bounds_in_screen);
164 }
165 const float phantom_opacity =
166 !in_original_root ? 1 : (kMaxOpacity * fraction_in_another_window);
167 const float window_opacity =
168 in_original_root ? 1 : (kMaxOpacity * (1 - fraction_in_another_window));
169 drag_window_controller_->SetOpacity(phantom_opacity);
170 GetTarget()->layer()->SetOpacity(window_opacity);
171 } else {
172 drag_window_controller_.reset();
173 GetTarget()->layer()->SetOpacity(1.0f);
174 }
175 }
176
177 bool DragWindowResizer::ShouldAllowMouseWarp() {
178 return (details_.window_component == HTCAPTION) &&
179 (GetTarget()->GetProperty(aura::client::kModalKey) ==
180 ui::MODAL_TYPE_NONE) &&
181 (GetTarget()->type() == aura::client::WINDOW_TYPE_NORMAL);
182 }
183
184 } // namespace internal
185 } // namespace ash
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698