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