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

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

Issue 10835047: Allow the cursor to warp even when a window is dragged (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: don't check mouse lock status in display controller Created 8 years, 4 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 | 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/coordinate_conversion.h"
6
7 #include "ash/display/display_controller.h"
8 #include "ash/shell.h"
9 #include "ui/aura/client/screen_position_client.h"
10 #include "ui/aura/root_window.h"
11 #include "ui/gfx/display.h"
12 #include "ui/gfx/point.h"
13 #include "ui/gfx/rect.h"
14 #include "ui/gfx/screen.h"
15
16 namespace ash {
17 namespace wm {
18
19 aura::RootWindow* GetRootWindowAt(const gfx::Point& point) {
20 const gfx::Display& display = gfx::Screen::GetDisplayNearestPoint(point);
21 // TODO(yusukes): Move coordinate_conversion.cc and .h to ui/aura/ once
22 // GetRootWindowForDisplayId() is moved to aura::Env.
23 return Shell::GetInstance()->display_controller()->
24 GetRootWindowForDisplayId(display.id());
25 }
26
27 aura::RootWindow* GetRootWindowMatching(const gfx::Rect& rect) {
28 const gfx::Display& display = gfx::Screen::GetDisplayMatching(rect);
29 return Shell::GetInstance()->display_controller()->
30 GetRootWindowForDisplayId(display.id());
31 }
32
33 std::pair<aura::RootWindow*, gfx::Point> GetRootWindowRelativeToWindow(
34 aura::Window* window,
35 const gfx::Point& location) {
36 aura::RootWindow* root_window = window->GetRootWindow();
37 gfx::Point location_in_root(location);
38 aura::Window::ConvertPointToWindow(window, root_window, &location_in_root);
39
40 #if defined(USE_X11)
41 // This conversion is necessary for dealing with the "pointer warp" feature in
42 // ash/display/display_controller.cc. For example, if we have two displays,
43 // say 1000x1000 (primary) and 500x500 (extended one on the right), and start
44 // dragging a window at (999, 123), and then move the pointer to the right,
45 // the pointer suddenly warps to the extended display. The destination is
46 // (0, 123) in the secondary root window's coordinates, or (1000, 123) in the
47 // screen coordinates. However, since the mouse is captured during drag, a
48 // weird LocatedEvent, something like (0, 1123) in the *primary* root window's
49 // coordinates, is sent to Chrome (Remember that in the native X11 world, the
50 // two root windows are always stacked vertically regardless of the display
51 // layout in Ash). We need to figure out that (0, 1123) in the primary root
52 // window's coordinates is actually (0, 123) in the extended root window's
53 // coordinates.
54 if (!root_window->ContainsPointInRoot(location_in_root)) {
55 gfx::Point location_in_native = location_in_root;
56 root_window->ConvertPointToNativeScreen(&location_in_native);
57
58 Shell::RootWindowList root_windows = Shell::GetAllRootWindows();
59 for (size_t i = 0; i < root_windows.size(); ++i) {
60 gfx::Point native_origin = root_windows[i]->bounds().origin();
61 root_windows[i]->ConvertPointToNativeScreen(&native_origin);
62 gfx::Rect native_bounds = root_windows[i]->bounds();
63 native_bounds.set_origin(native_origin);
64 if (native_bounds.Contains(location_in_native)) {
65 root_window = root_windows[i];
66 location_in_root = location_in_native;
67 location_in_root.Offset(-native_bounds.x(), -native_bounds.y());
68 break;
69 }
70 }
71 }
72 #else
73 // TODO(yusukes): Support non-X11 platforms if necessary.
74 #endif
75
76 return std::make_pair(root_window, location_in_root);
77 }
78
79 void ConvertPointToScreen(aura::Window* window, gfx::Point* point) {
80 aura::client::GetScreenPositionClient(window->GetRootWindow())->
81 ConvertPointToScreen(window, point);
82 }
83
84 void ConvertPointFromScreen(aura::Window* window,
85 gfx::Point* point_in_screen) {
86 aura::client::GetScreenPositionClient(window->GetRootWindow())->
87 ConvertPointFromScreen(window, point_in_screen);
88 }
89
90 } // namespace wm
91 } // namespace ash
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698