| OLD | NEW |
| (Empty) |
| 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 | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #include "ui/views/event_utils.h" | |
| 6 | |
| 7 #include "base/logging.h" | |
| 8 #include "base/memory/scoped_ptr.h" | |
| 9 #include "ui/aura/client/screen_position_client.h" | |
| 10 #include "ui/aura/window_event_dispatcher.h" | |
| 11 #include "ui/aura/window_tree_host.h" | |
| 12 #include "ui/events/event.h" | |
| 13 #include "ui/gfx/point.h" | |
| 14 #include "ui/views/views_delegate.h" | |
| 15 | |
| 16 using aura::client::ScreenPositionClient; | |
| 17 | |
| 18 namespace views { | |
| 19 | |
| 20 bool RepostLocatedEvent(gfx::NativeWindow window, | |
| 21 const ui::LocatedEvent& event) { | |
| 22 #if defined(OS_WIN) | |
| 23 // On Windows, if the |window| parameter is NULL, then we attempt to repost | |
| 24 // the event to the window at the current location, if it is on the current | |
| 25 // thread. | |
| 26 HWND target_window = NULL; | |
| 27 if (!window) { | |
| 28 target_window = ::WindowFromPoint(event.location().ToPOINT()); | |
| 29 if (::GetWindowThreadProcessId(target_window, NULL) != | |
| 30 ::GetCurrentThreadId()) | |
| 31 return false; | |
| 32 } else { | |
| 33 if (ViewsDelegate::views_delegate && | |
| 34 !ViewsDelegate::views_delegate->IsWindowInMetro(window)) | |
| 35 target_window = window->GetHost()->GetAcceleratedWidget(); | |
| 36 } | |
| 37 return RepostLocatedEventWin(target_window, event); | |
| 38 #else | |
| 39 if (!window) | |
| 40 return false; | |
| 41 | |
| 42 aura::Window* root_window = window->GetRootWindow(); | |
| 43 | |
| 44 gfx::Point root_loc(event.location()); | |
| 45 ScreenPositionClient* spc = | |
| 46 aura::client::GetScreenPositionClient(root_window); | |
| 47 if (!spc) | |
| 48 return false; | |
| 49 | |
| 50 spc->ConvertPointFromScreen(root_window, &root_loc); | |
| 51 | |
| 52 scoped_ptr<ui::LocatedEvent> relocated; | |
| 53 if (!event.IsMouseEvent()) { | |
| 54 // TODO(rbyers): Gesture event repost is tricky to get right | |
| 55 // crbug.com/170987. | |
| 56 DCHECK(event.IsGestureEvent()); | |
| 57 return false; | |
| 58 } | |
| 59 | |
| 60 const ui::MouseEvent& orig = static_cast<const ui::MouseEvent&>(event); | |
| 61 relocated.reset(new ui::MouseEvent(orig)); | |
| 62 relocated->set_location(root_loc); | |
| 63 relocated->set_root_location(root_loc); | |
| 64 | |
| 65 root_window->GetHost()->dispatcher()->RepostEvent(*relocated); | |
| 66 return true; | |
| 67 #endif | |
| 68 } | |
| 69 | |
| 70 } // namespace views | |
| OLD | NEW |