OLD | NEW |
---|---|
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 "ash/host/ash_window_tree_host.h" | 5 #include "ash/host/ash_window_tree_host.h" |
6 | 6 |
7 #include "ash/host/ash_window_tree_host_init_params.h" | |
8 #include "ash/host/ash_window_tree_host_unified.h" | |
7 #include "ui/aura/client/screen_position_client.h" | 9 #include "ui/aura/client/screen_position_client.h" |
8 #include "ui/aura/window_tree_host.h" | 10 #include "ui/aura/window_tree_host.h" |
9 #include "ui/events/event.h" | 11 #include "ui/events/event.h" |
10 #include "ui/gfx/geometry/rect.h" | 12 #include "ui/gfx/geometry/rect.h" |
11 | 13 |
14 #if defined(USE_OZONE) | |
15 #include "ash/host/ash_window_tree_host_ozone.h" | |
16 #elif defined(USE_X11) | |
17 #include "ash/host/ash_window_tree_host_x11.h" | |
18 #elif defined(OS_WIN) | |
19 #include "ash/host/ash_window_tree_host_win.h" | |
20 #else | |
21 #error Unsupported platform. | |
22 #endif | |
23 | |
12 namespace ash { | 24 namespace ash { |
13 | 25 |
26 namespace { | |
27 | |
28 AshWindowTreeHost::Factory g_factory; | |
sky
2016/02/03 22:43:48
nit: g_factory is file local, so no 'g_'
sadrul
2016/02/04 00:03:42
Acknowledged.
| |
29 | |
30 } // namespace | |
31 | |
14 AshWindowTreeHost::AshWindowTreeHost() : input_method_handler_(nullptr) { | 32 AshWindowTreeHost::AshWindowTreeHost() : input_method_handler_(nullptr) { |
15 } | 33 } |
16 | 34 |
17 void AshWindowTreeHost::TranslateLocatedEvent(ui::LocatedEvent* event) { | 35 void AshWindowTreeHost::TranslateLocatedEvent(ui::LocatedEvent* event) { |
18 if (event->IsTouchEvent()) | 36 if (event->IsTouchEvent()) |
19 return; | 37 return; |
20 | 38 |
21 aura::WindowTreeHost* wth = AsWindowTreeHost(); | 39 aura::WindowTreeHost* wth = AsWindowTreeHost(); |
22 aura::Window* root_window = wth->window(); | 40 aura::Window* root_window = wth->window(); |
23 aura::client::ScreenPositionClient* screen_position_client = | 41 aura::client::ScreenPositionClient* screen_position_client = |
24 aura::client::GetScreenPositionClient(root_window); | 42 aura::client::GetScreenPositionClient(root_window); |
25 gfx::Rect local(wth->GetBounds().size()); | 43 gfx::Rect local(wth->GetBounds().size()); |
26 local.Inset(GetHostInsets()); | 44 local.Inset(GetHostInsets()); |
27 | 45 |
28 if (screen_position_client && !local.Contains(event->location())) { | 46 if (screen_position_client && !local.Contains(event->location())) { |
29 gfx::Point location(event->location()); | 47 gfx::Point location(event->location()); |
30 // In order to get the correct point in screen coordinates | 48 // In order to get the correct point in screen coordinates |
31 // during passive grab, we first need to find on which host window | 49 // during passive grab, we first need to find on which host window |
32 // the mouse is on, and find out the screen coordinates on that | 50 // the mouse is on, and find out the screen coordinates on that |
33 // host window, then convert it back to this host window's coordinate. | 51 // host window, then convert it back to this host window's coordinate. |
34 screen_position_client->ConvertHostPointToScreen(root_window, &location); | 52 screen_position_client->ConvertHostPointToScreen(root_window, &location); |
35 screen_position_client->ConvertPointFromScreen(root_window, &location); | 53 screen_position_client->ConvertPointFromScreen(root_window, &location); |
36 wth->ConvertPointToHost(&location); | 54 wth->ConvertPointToHost(&location); |
37 event->set_location(location); | 55 event->set_location(location); |
38 event->set_root_location(location); | 56 event->set_root_location(location); |
39 } | 57 } |
40 } | 58 } |
41 | 59 |
60 // static | |
61 AshWindowTreeHost* AshWindowTreeHost::Create( | |
62 const AshWindowTreeHostInitParams& init_params) { | |
63 if (!g_factory.is_null()) | |
64 return g_factory.Run(init_params); | |
65 if (init_params.offscreen) | |
66 return new AshWindowTreeHostUnified(init_params.initial_bounds); | |
67 #if defined(USE_OZONE) | |
68 return new AshWindowTreeHostOzone(init_params.initial_bounds); | |
69 #elif defined(USE_X11) | |
70 return new AshWindowTreeHostX11(init_params.initial_bounds); | |
71 #elif defined(OS_WIN) | |
72 return new AshWindowTreeHostWin(init_params.initial_bounds); | |
73 #endif | |
74 NOTREACHED(); | |
75 return nullptr; | |
76 } | |
77 | |
78 void AshWindowTreeHost::SetFactory(const Factory& factory) { | |
79 g_factory = factory; | |
80 } | |
81 | |
42 } // namespace ash | 82 } // namespace ash |
OLD | NEW |