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

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: address comments 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"
sky 2012/08/03 17:07:18 Can this file be moved to aura?
Yusuke Sato 2012/08/03 23:18:45 I think it's difficult right now since Aura does n
6
7 #include "ash/display/display_controller.h"
8 #include "ash/shell.h"
9 #include "ui/aura/root_window.h"
10 #include "ui/gfx/display.h"
11 #include "ui/gfx/point.h"
12 #include "ui/gfx/rect.h"
13 #include "ui/gfx/screen.h"
14
15 namespace ash {
16 namespace wm {
17
18 aura::RootWindow* GetRootWindowAt(const gfx::Point& point) {
19 const gfx::Display& display = gfx::Screen::GetDisplayNearestPoint(point);
20 return Shell::GetInstance()->display_controller()->
21 GetRootWindowForDisplayId(display.id());
22 }
23
24 aura::RootWindow* GetRootWindowMatching(const gfx::Rect& rect) {
25 const gfx::Display& display = gfx::Screen::GetDisplayMatching(rect);
26 return Shell::GetInstance()->display_controller()->
27 GetRootWindowForDisplayId(display.id());
28 }
29
30 std::pair<aura::RootWindow*, gfx::Point> GetRootWindowRelativeToWindow(
31 aura::Window* window, const gfx::Point& location) {
sky 2012/08/03 17:07:18 nit: wrap location to next line.
Yusuke Sato 2012/08/03 23:18:45 Done.
32 aura::RootWindow* root_window = window->GetRootWindow();
33 gfx::Point location_in_root(location);
34 aura::Window::ConvertPointToWindow(window, root_window, &location_in_root);
35
36 #if defined(USE_X11)
37 // This conversion is necessary for dealing with the "pointer warp" feature in
38 // ash/display/display_controller.cc. For example, if we have two displays,
39 // say 1000x1000 (primary) and 500x500 (extended one on the right), and start
40 // dragging a window at (999, 123), and then move the cursor to the right, the
41 // cursor suddenly warps to the extended display. The destination is (0, 123)
42 // in the secondary root window's coordinates, or (1000, 123) in the screen
43 // coordinates. However, since the mouse cursor is captured during drag, a
44 // weird LocatedEvent, something like (0, 1123) in the *primary* root window's
45 // coordinates, is sent to Chrome (Remember that in the native X11 world, the
46 // two root windows are always stacked vertically regardless of the display
47 // layout in Ash). We need to figure out that (0, 1123) in the primary root
48 // window's coordinates is actually (0, 123) in the extended root window's
49 // coordinates.
50 if (!root_window->ContainsPointInRoot(location_in_root)) {
51 gfx::Point location_in_native = location_in_root;
52 root_window->ConvertPointToNativeScreen(&location_in_native);
53
54 Shell::RootWindowList root_windows = Shell::GetAllRootWindows();
55 for (size_t i = 0; i < root_windows.size(); ++i) {
56 gfx::Point native_origin = root_windows[i]->bounds().origin();
57 root_windows[i]->ConvertPointToNativeScreen(&native_origin);
58 gfx::Rect native_bounds = root_windows[i]->bounds();
59 native_bounds.set_origin(native_origin);
60 if (native_bounds.Contains(location_in_native)) {
61 root_window = root_windows[i];
62 location_in_root = location_in_native;
63 location_in_root.Offset(-native_bounds.x(), -native_bounds.y());
64 break;
65 }
66 }
67 }
68 #else
69 // TODO(yusukes): Support non-X11 platforms if necessary.
70 #endif
71
72 return std::make_pair(root_window, location_in_root);
73 }
74
75 } // namespace wm
76 } // namespace ash
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698