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.
5 #include "ui/views/event_utils.h"
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/root_window.h"
11 #include "ui/events/event.h"
12 #include "ui/gfx/point.h"
14 using aura::client::ScreenPositionClient;
18 bool RepostLocatedEvent(gfx::NativeWindow window,
19 const ui::LocatedEvent& event) {
23 aura::Window* root_window = window->GetRootWindow();
25 gfx::Point root_loc(event.location());
26 ScreenPositionClient* spc =
27 aura::client::GetScreenPositionClient(root_window);
31 spc->ConvertPointFromScreen(root_window, &root_loc);
33 scoped_ptr<ui::LocatedEvent> relocated;
34 if (event.IsMouseEvent()) {
35 const ui::MouseEvent& orig = static_cast<const ui::MouseEvent&>(event);
36 relocated.reset(new ui::MouseEvent(orig));
37 } else if (event.IsGestureEvent()) {
38 // TODO(rbyers): Gesture event repost is tricky to get right
45 relocated->set_location(root_loc);
46 relocated->set_root_location(root_loc);
48 root_window->GetDispatcher()->RepostEvent(*relocated);