| 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_x11.h" | 5 #include "ash/host/ash_window_tree_host_x11.h" |
| 6 | 6 |
| 7 #include <X11/extensions/Xfixes.h> | 7 #include <X11/extensions/Xfixes.h> |
| 8 #include <X11/extensions/XInput2.h> | 8 #include <X11/extensions/XInput2.h> |
| 9 #include <X11/Xatom.h> | 9 #include <X11/Xatom.h> |
| 10 #include <X11/Xlib.h> | 10 #include <X11/Xlib.h> |
| 11 | 11 |
| 12 #include <string> | 12 #include <string> |
| 13 #include <vector> | 13 #include <vector> |
| 14 | 14 |
| 15 #include "ash/host/ash_window_tree_host_init_params.h" | 15 #include "ash/host/ash_window_tree_host_init_params.h" |
| 16 #include "ash/host/root_window_transformer.h" | 16 #include "ash/host/root_window_transformer.h" |
| 17 #include "base/basictypes.h" | 17 #include "base/basictypes.h" |
| 18 #include "base/sys_info.h" | 18 #include "base/sys_info.h" |
| 19 #include "ui/aura/env.h" | 19 #include "ui/aura/env.h" |
| 20 #include "ui/aura/window.h" | 20 #include "ui/aura/window.h" |
| 21 #include "ui/aura/window_event_dispatcher.h" | 21 #include "ui/aura/window_event_dispatcher.h" |
| 22 #include "ui/base/x/x11_util.h" | 22 #include "ui/base/x/x11_util.h" |
| 23 #include "ui/events/devices/device_data_manager.h" | 23 #include "ui/events/devices/device_data_manager.h" |
| 24 #include "ui/events/devices/x11/device_list_cache_x11.h" | 24 #include "ui/events/devices/x11/device_list_cache_x11.h" |
| 25 #include "ui/events/devices/x11/touch_factory_x11.h" | 25 #include "ui/events/devices/x11/touch_factory_x11.h" |
| 26 #include "ui/events/event.h" | 26 #include "ui/events/event.h" |
| 27 #include "ui/events/event_utils.h" | 27 #include "ui/events/event_utils.h" |
| 28 #include "ui/events/null_event_targeter.h" | 28 #include "ui/events/null_event_targeter.h" |
| 29 #include "ui/events/platform/platform_event_source.h" | 29 #include "ui/events/platform/platform_event_source.h" |
| 30 #include "ui/gfx/display.h" |
| 30 #include "ui/gfx/geometry/rect.h" | 31 #include "ui/gfx/geometry/rect.h" |
| 31 #include "ui/gfx/screen.h" | 32 #include "ui/gfx/screen.h" |
| 32 | 33 |
| 33 namespace ash { | 34 namespace ash { |
| 34 | 35 |
| 35 AshWindowTreeHostX11::AshWindowTreeHostX11(const gfx::Rect& initial_bounds) | 36 AshWindowTreeHostX11::AshWindowTreeHostX11(const gfx::Rect& initial_bounds) |
| 36 : WindowTreeHostX11(initial_bounds), | 37 : WindowTreeHostX11(initial_bounds), transformer_helper_(this) { |
| 37 transformer_helper_(this), | |
| 38 display_ids_(std::make_pair(gfx::Display::kInvalidDisplayID, | |
| 39 gfx::Display::kInvalidDisplayID)) { | |
| 40 aura::Env::GetInstance()->AddObserver(this); | 38 aura::Env::GetInstance()->AddObserver(this); |
| 41 } | 39 } |
| 42 | 40 |
| 43 AshWindowTreeHostX11::~AshWindowTreeHostX11() { | 41 AshWindowTreeHostX11::~AshWindowTreeHostX11() { |
| 44 aura::Env::GetInstance()->RemoveObserver(this); | 42 aura::Env::GetInstance()->RemoveObserver(this); |
| 45 UnConfineCursor(); | 43 UnConfineCursor(); |
| 46 } | 44 } |
| 47 | 45 |
| 48 void AshWindowTreeHostX11::ToggleFullScreen() { NOTIMPLEMENTED(); } | 46 void AshWindowTreeHostX11::ToggleFullScreen() { NOTIMPLEMENTED(); } |
| 49 | 47 |
| (...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 119 ConfineCursorToRootWindow(); | 117 ConfineCursorToRootWindow(); |
| 120 } | 118 } |
| 121 } | 119 } |
| 122 | 120 |
| 123 gfx::Insets AshWindowTreeHostX11::GetHostInsets() const { | 121 gfx::Insets AshWindowTreeHostX11::GetHostInsets() const { |
| 124 return transformer_helper_.GetHostInsets(); | 122 return transformer_helper_.GetHostInsets(); |
| 125 } | 123 } |
| 126 | 124 |
| 127 aura::WindowTreeHost* AshWindowTreeHostX11::AsWindowTreeHost() { return this; } | 125 aura::WindowTreeHost* AshWindowTreeHostX11::AsWindowTreeHost() { return this; } |
| 128 | 126 |
| 129 void AshWindowTreeHostX11::UpdateDisplayID(int64 id1, int64 id2) { | |
| 130 display_ids_.first = id1; | |
| 131 display_ids_.second = id2; | |
| 132 } | |
| 133 | |
| 134 void AshWindowTreeHostX11::PrepareForShutdown() { | 127 void AshWindowTreeHostX11::PrepareForShutdown() { |
| 135 // Block the root window from dispatching events because it is weird for a | 128 // Block the root window from dispatching events because it is weird for a |
| 136 // ScreenPositionClient not to be attached to the root window and for | 129 // ScreenPositionClient not to be attached to the root window and for |
| 137 // ui::EventHandlers to be unable to convert the event's location to screen | 130 // ui::EventHandlers to be unable to convert the event's location to screen |
| 138 // coordinates. | 131 // coordinates. |
| 139 window()->SetEventTargeter( | 132 window()->SetEventTargeter( |
| 140 scoped_ptr<ui::EventTargeter>(new ui::NullEventTargeter)); | 133 scoped_ptr<ui::EventTargeter>(new ui::NullEventTargeter)); |
| 141 | 134 |
| 142 if (ui::PlatformEventSource::GetInstance()) { | 135 if (ui::PlatformEventSource::GetInstance()) { |
| 143 // Block X events which are not turned into ui::Events from getting | 136 // Block X events which are not turned into ui::Events from getting |
| (...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 205 ui::EventType type = ui::EventTypeFromNative(xev); | 198 ui::EventType type = ui::EventTypeFromNative(xev); |
| 206 // For touch event, check if the root window is residing on the according | 199 // For touch event, check if the root window is residing on the according |
| 207 // touch display. | 200 // touch display. |
| 208 switch (type) { | 201 switch (type) { |
| 209 case ui::ET_TOUCH_MOVED: | 202 case ui::ET_TOUCH_MOVED: |
| 210 case ui::ET_TOUCH_PRESSED: | 203 case ui::ET_TOUCH_PRESSED: |
| 211 case ui::ET_TOUCH_CANCELLED: | 204 case ui::ET_TOUCH_CANCELLED: |
| 212 case ui::ET_TOUCH_RELEASED: { | 205 case ui::ET_TOUCH_RELEASED: { |
| 213 #if defined(OS_CHROMEOS) | 206 #if defined(OS_CHROMEOS) |
| 214 XIDeviceEvent* xiev = static_cast<XIDeviceEvent*>(xev->xcookie.data); | 207 XIDeviceEvent* xiev = static_cast<XIDeviceEvent*>(xev->xcookie.data); |
| 215 int64 touch_display_id = | 208 gfx::Display touch_display = |
| 216 ui::DeviceDataManager::GetInstance()->GetDisplayForTouchDevice( | 209 ui::DeviceDataManager::GetInstance()->GetDisplayForTouchDevice( |
| 217 xiev->deviceid); | 210 xiev->deviceid); |
| 211 int64 touch_display_id = touch_display.id(); |
| 218 // If we don't have record of display id for this touch device, check | 212 // If we don't have record of display id for this touch device, check |
| 219 // that if the event is within the bound of the root window. Note | 213 // that if the event is within the bound of the root window. Note |
| 220 // that in multi-monitor case, the event position is in framebuffer | 214 // that in multi-monitor case, the event position is in framebuffer |
| 221 // space so the bounds check will not work so well. | 215 // space so the bounds check will not work so well. |
| 222 if (touch_display_id == gfx::Display::kInvalidDisplayID) { | 216 if (touch_display_id == gfx::Display::kInvalidDisplayID) { |
| 223 if (base::SysInfo::IsRunningOnChromeOS() && | 217 if (base::SysInfo::IsRunningOnChromeOS() && |
| 224 !bounds().Contains(ui::EventLocationFromNative(xev))) | 218 !bounds().Contains(ui::EventLocationFromNative(xev))) |
| 225 return false; | 219 return false; |
| 226 } else if (touch_display_id != display_ids_.first && | 220 } else { |
| 227 touch_display_id != display_ids_.second) { | 221 if (touch_display.mirrored_display_id() != |
| 228 return false; | 222 gfx::Display::kInvalidDisplayID) { |
| 223 touch_display_id = touch_display.mirrored_display_id(); |
| 224 } |
| 225 gfx::Screen* screen = gfx::Screen::GetScreenFor(window()); |
| 226 gfx::Display display = screen->GetDisplayNearestWindow(window()); |
| 227 return touch_display_id == display.id(); |
| 229 } | 228 } |
| 230 #endif // defined(OS_CHROMEOS) | 229 #endif // defined(OS_CHROMEOS) |
| 231 return true; | 230 return true; |
| 232 } | 231 } |
| 233 default: | 232 default: |
| 234 return true; | 233 return true; |
| 235 } | 234 } |
| 236 } | 235 } |
| 237 void AshWindowTreeHostX11::TranslateAndDispatchLocatedEvent( | 236 void AshWindowTreeHostX11::TranslateAndDispatchLocatedEvent( |
| 238 ui::LocatedEvent* event) { | 237 ui::LocatedEvent* event) { |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 284 } | 283 } |
| 285 } | 284 } |
| 286 #endif | 285 #endif |
| 287 | 286 |
| 288 AshWindowTreeHost* AshWindowTreeHost::Create( | 287 AshWindowTreeHost* AshWindowTreeHost::Create( |
| 289 const AshWindowTreeHostInitParams& init_params) { | 288 const AshWindowTreeHostInitParams& init_params) { |
| 290 return new AshWindowTreeHostX11(init_params.initial_bounds); | 289 return new AshWindowTreeHostX11(init_params.initial_bounds); |
| 291 } | 290 } |
| 292 | 291 |
| 293 } // namespace ash | 292 } // namespace ash |
| OLD | NEW |