OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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 "ui/views/event_utils.h" | 5 #include "ui/views/event_utils.h" |
6 | 6 |
7 #include "base/logging.h" | 7 #include "base/logging.h" |
8 #include "base/memory/scoped_ptr.h" | 8 #include "base/memory/scoped_ptr.h" |
9 #include "ui/aura/client/screen_position_client.h" | 9 #include "ui/aura/client/screen_position_client.h" |
10 #include "ui/aura/root_window.h" | 10 #include "ui/aura/root_window.h" |
11 #include "ui/events/event.h" | 11 #include "ui/events/event.h" |
12 #include "ui/gfx/point.h" | 12 #include "ui/gfx/point.h" |
13 #include "ui/views/views_delegate.h" | 13 #include "ui/views/views_delegate.h" |
14 | 14 |
15 using aura::client::ScreenPositionClient; | 15 using aura::client::ScreenPositionClient; |
16 | 16 |
17 namespace views { | 17 namespace views { |
18 | 18 |
19 bool RepostLocatedEvent(gfx::NativeWindow window, | 19 bool RepostLocatedEvent(gfx::NativeWindow window, |
20 const ui::LocatedEvent& event) { | 20 const ui::LocatedEvent& event) { |
| 21 #if defined(OS_WIN) |
| 22 // On Windows, if the |window| parameter is NULL, then we attempt to repost |
| 23 // the event to the window at the current location, if it is on the current |
| 24 // thread. |
| 25 HWND target_window = NULL; |
| 26 if (!window) { |
| 27 target_window = ::WindowFromPoint(event.location().ToPOINT()); |
| 28 if (::GetWindowThreadProcessId(target_window, NULL) != |
| 29 ::GetCurrentThreadId()) |
| 30 return false; |
| 31 } else { |
| 32 if (ViewsDelegate::views_delegate && |
| 33 !ViewsDelegate::views_delegate->IsWindowInMetro(window)) |
| 34 target_window = window->GetDispatcher()->host()->GetAcceleratedWidget(); |
| 35 } |
| 36 return RepostLocatedEventWin(target_window, event); |
| 37 #endif |
21 if (!window) | 38 if (!window) |
22 return false; | 39 return false; |
23 | 40 |
24 #if defined(OS_WIN) | |
25 if (ViewsDelegate::views_delegate && | |
26 !ViewsDelegate::views_delegate->IsWindowInMetro(window)) { | |
27 return RepostLocatedEventWin( | |
28 window->GetDispatcher()->host()->GetAcceleratedWidget(), event); | |
29 } | |
30 #endif | |
31 aura::Window* root_window = window->GetRootWindow(); | 41 aura::Window* root_window = window->GetRootWindow(); |
32 | 42 |
33 gfx::Point root_loc(event.location()); | 43 gfx::Point root_loc(event.location()); |
34 ScreenPositionClient* spc = | 44 ScreenPositionClient* spc = |
35 aura::client::GetScreenPositionClient(root_window); | 45 aura::client::GetScreenPositionClient(root_window); |
36 if (!spc) | 46 if (!spc) |
37 return false; | 47 return false; |
38 | 48 |
39 spc->ConvertPointFromScreen(root_window, &root_loc); | 49 spc->ConvertPointFromScreen(root_window, &root_loc); |
40 | 50 |
(...skipping 10 matching lines...) Expand all Loading... |
51 return false; | 61 return false; |
52 } | 62 } |
53 relocated->set_location(root_loc); | 63 relocated->set_location(root_loc); |
54 relocated->set_root_location(root_loc); | 64 relocated->set_root_location(root_loc); |
55 | 65 |
56 root_window->GetDispatcher()->RepostEvent(*relocated); | 66 root_window->GetDispatcher()->RepostEvent(*relocated); |
57 return true; | 67 return true; |
58 } | 68 } |
59 | 69 |
60 } // namespace views | 70 } // namespace views |
OLD | NEW |