| 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> |
| (...skipping 129 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 140 gfx::Transform AshWindowTreeHostX11::GetInverseRootTransform() const { | 140 gfx::Transform AshWindowTreeHostX11::GetInverseRootTransform() const { |
| 141 return transformer_helper_.GetInverseTransform(); | 141 return transformer_helper_.GetInverseTransform(); |
| 142 } | 142 } |
| 143 | 143 |
| 144 void AshWindowTreeHostX11::UpdateRootWindowSizeInPixels( | 144 void AshWindowTreeHostX11::UpdateRootWindowSizeInPixels( |
| 145 const gfx::Size& host_size_in_pixels) { | 145 const gfx::Size& host_size_in_pixels) { |
| 146 transformer_helper_.UpdateWindowSize(host_size_in_pixels); | 146 transformer_helper_.UpdateWindowSize(host_size_in_pixels); |
| 147 } | 147 } |
| 148 | 148 |
| 149 void AshWindowTreeHostX11::OnCursorVisibilityChangedNative(bool show) { | 149 void AshWindowTreeHostX11::OnCursorVisibilityChangedNative(bool show) { |
| 150 #if defined(OS_CHROMEOS) | |
| 151 SetCrOSTapPaused(!show); | 150 SetCrOSTapPaused(!show); |
| 152 #endif | |
| 153 } | 151 } |
| 154 | 152 |
| 155 void AshWindowTreeHostX11::OnWindowInitialized(aura::Window* window) {} | 153 void AshWindowTreeHostX11::OnWindowInitialized(aura::Window* window) {} |
| 156 | 154 |
| 157 void AshWindowTreeHostX11::OnHostInitialized(aura::WindowTreeHost* host) { | 155 void AshWindowTreeHostX11::OnHostInitialized(aura::WindowTreeHost* host) { |
| 158 if (host != AsWindowTreeHost()) | 156 if (host != AsWindowTreeHost()) |
| 159 return; | 157 return; |
| 160 | 158 |
| 161 #if defined(OS_CHROMEOS) | |
| 162 // We have to enable Tap-to-click by default because the cursor is set to | 159 // We have to enable Tap-to-click by default because the cursor is set to |
| 163 // visible in Shell::InitRootWindowController. | 160 // visible in Shell::InitRootWindowController. |
| 164 SetCrOSTapPaused(false); | 161 SetCrOSTapPaused(false); |
| 165 #endif | |
| 166 } | 162 } |
| 167 | 163 |
| 168 void AshWindowTreeHostX11::OnConfigureNotify() { | 164 void AshWindowTreeHostX11::OnConfigureNotify() { |
| 169 // Always update barrier and mouse location because |bounds_| might | 165 // Always update barrier and mouse location because |bounds_| might |
| 170 // have already been updated in |SetBounds|. | 166 // have already been updated in |SetBounds|. |
| 171 if (pointer_barriers_) { | 167 if (pointer_barriers_) { |
| 172 UnConfineCursor(); | 168 UnConfineCursor(); |
| 173 ConfineCursorToRootWindow(); | 169 ConfineCursorToRootWindow(); |
| 174 } | 170 } |
| 175 } | 171 } |
| 176 | 172 |
| 177 bool AshWindowTreeHostX11::CanDispatchEvent(const ui::PlatformEvent& event) { | 173 bool AshWindowTreeHostX11::CanDispatchEvent(const ui::PlatformEvent& event) { |
| 178 if (!WindowTreeHostX11::CanDispatchEvent(event)) | 174 if (!WindowTreeHostX11::CanDispatchEvent(event)) |
| 179 return false; | 175 return false; |
| 180 XEvent* xev = event; | 176 XEvent* xev = event; |
| 181 ui::EventType type = ui::EventTypeFromNative(xev); | 177 ui::EventType type = ui::EventTypeFromNative(xev); |
| 182 // For touch event, check if the root window is residing on the according | 178 // For touch event, check if the root window is residing on the according |
| 183 // touch display. | 179 // touch display. |
| 184 switch (type) { | 180 switch (type) { |
| 185 case ui::ET_TOUCH_MOVED: | 181 case ui::ET_TOUCH_MOVED: |
| 186 case ui::ET_TOUCH_PRESSED: | 182 case ui::ET_TOUCH_PRESSED: |
| 187 case ui::ET_TOUCH_CANCELLED: | 183 case ui::ET_TOUCH_CANCELLED: |
| 188 case ui::ET_TOUCH_RELEASED: { | 184 case ui::ET_TOUCH_RELEASED: { |
| 189 #if defined(OS_CHROMEOS) | |
| 190 XIDeviceEvent* xiev = static_cast<XIDeviceEvent*>(xev->xcookie.data); | 185 XIDeviceEvent* xiev = static_cast<XIDeviceEvent*>(xev->xcookie.data); |
| 191 int64_t touch_display_id = | 186 int64_t touch_display_id = |
| 192 ui::DeviceDataManager::GetInstance()->GetTargetDisplayForTouchDevice( | 187 ui::DeviceDataManager::GetInstance()->GetTargetDisplayForTouchDevice( |
| 193 xiev->deviceid); | 188 xiev->deviceid); |
| 194 // If we don't have record of display id for this touch device, check | 189 // If we don't have record of display id for this touch device, check |
| 195 // that if the event is within the bound of the root window. Note | 190 // that if the event is within the bound of the root window. Note |
| 196 // that in multi-monitor case, the event position is in framebuffer | 191 // that in multi-monitor case, the event position is in framebuffer |
| 197 // space so the bounds check will not work so well. | 192 // space so the bounds check will not work so well. |
| 198 if (touch_display_id == display::kInvalidDisplayId) { | 193 if (touch_display_id == display::kInvalidDisplayId) { |
| 199 if (base::SysInfo::IsRunningOnChromeOS() && | 194 if (base::SysInfo::IsRunningOnChromeOS() && |
| 200 !bounds().Contains( | 195 !bounds().Contains( |
| 201 gfx::ToFlooredPoint(ui::EventLocationFromNative(xev)))) | 196 gfx::ToFlooredPoint(ui::EventLocationFromNative(xev)))) |
| 202 return false; | 197 return false; |
| 203 } else { | 198 } else { |
| 204 display::Screen* screen = display::Screen::GetScreen(); | 199 display::Screen* screen = display::Screen::GetScreen(); |
| 205 display::Display display = screen->GetDisplayNearestWindow(window()); | 200 display::Display display = screen->GetDisplayNearestWindow(window()); |
| 206 return touch_display_id == display.id(); | 201 return touch_display_id == display.id(); |
| 207 } | 202 } |
| 208 #endif // defined(OS_CHROMEOS) | |
| 209 return true; | 203 return true; |
| 210 } | 204 } |
| 211 default: | 205 default: |
| 212 return true; | 206 return true; |
| 213 } | 207 } |
| 214 } | 208 } |
| 209 |
| 215 void AshWindowTreeHostX11::TranslateAndDispatchLocatedEvent( | 210 void AshWindowTreeHostX11::TranslateAndDispatchLocatedEvent( |
| 216 ui::LocatedEvent* event) { | 211 ui::LocatedEvent* event) { |
| 217 TranslateLocatedEvent(event); | 212 TranslateLocatedEvent(event); |
| 218 SendEventToProcessor(event); | 213 SendEventToProcessor(event); |
| 219 } | 214 } |
| 220 | 215 |
| 221 ui::EventDispatchDetails AshWindowTreeHostX11::DispatchKeyEventPostIME( | 216 ui::EventDispatchDetails AshWindowTreeHostX11::DispatchKeyEventPostIME( |
| 222 ui::KeyEvent* event) { | 217 ui::KeyEvent* event) { |
| 223 input_method_handler()->SetPostIME(true); | 218 input_method_handler()->SetPostIME(true); |
| 224 ui::EventDispatchDetails details = | 219 ui::EventDispatchDetails details = |
| 225 event_processor()->OnEventFromSource(event); | 220 event_processor()->OnEventFromSource(event); |
| 226 if (!details.dispatcher_destroyed) | 221 if (!details.dispatcher_destroyed) |
| 227 input_method_handler()->SetPostIME(false); | 222 input_method_handler()->SetPostIME(false); |
| 228 return details; | 223 return details; |
| 229 } | 224 } |
| 230 | 225 |
| 231 #if defined(OS_CHROMEOS) | |
| 232 void AshWindowTreeHostX11::SetCrOSTapPaused(bool state) { | 226 void AshWindowTreeHostX11::SetCrOSTapPaused(bool state) { |
| 233 if (!ui::IsXInput2Available()) | 227 if (!ui::IsXInput2Available()) |
| 234 return; | 228 return; |
| 235 // Temporarily pause tap-to-click when the cursor is hidden. | 229 // Temporarily pause tap-to-click when the cursor is hidden. |
| 236 Atom prop = atom_cache()->GetAtom("Tap Paused"); | 230 Atom prop = atom_cache()->GetAtom("Tap Paused"); |
| 237 unsigned char value = state; | 231 unsigned char value = state; |
| 238 const XIDeviceList& dev_list = | 232 const XIDeviceList& dev_list = |
| 239 ui::DeviceListCacheX11::GetInstance()->GetXI2DeviceList(xdisplay()); | 233 ui::DeviceListCacheX11::GetInstance()->GetXI2DeviceList(xdisplay()); |
| 240 | 234 |
| 241 // Only slave pointer devices could possibly have tap-paused property. | 235 // Only slave pointer devices could possibly have tap-paused property. |
| 242 for (int i = 0; i < dev_list.count; i++) { | 236 for (int i = 0; i < dev_list.count; i++) { |
| 243 if (dev_list[i].use == XISlavePointer) { | 237 if (dev_list[i].use == XISlavePointer) { |
| 244 Atom old_type; | 238 Atom old_type; |
| 245 int old_format; | 239 int old_format; |
| 246 unsigned long old_nvalues, bytes; | 240 unsigned long old_nvalues, bytes; |
| 247 unsigned char* data; | 241 unsigned char* data; |
| 248 int result = XIGetProperty(xdisplay(), dev_list[i].deviceid, prop, 0, 0, | 242 int result = XIGetProperty(xdisplay(), dev_list[i].deviceid, prop, 0, 0, |
| 249 False, AnyPropertyType, &old_type, &old_format, | 243 False, AnyPropertyType, &old_type, &old_format, |
| 250 &old_nvalues, &bytes, &data); | 244 &old_nvalues, &bytes, &data); |
| 251 if (result != Success) | 245 if (result != Success) |
| 252 continue; | 246 continue; |
| 253 XFree(data); | 247 XFree(data); |
| 254 XIChangeProperty(xdisplay(), dev_list[i].deviceid, prop, XA_INTEGER, 8, | 248 XIChangeProperty(xdisplay(), dev_list[i].deviceid, prop, XA_INTEGER, 8, |
| 255 PropModeReplace, &value, 1); | 249 PropModeReplace, &value, 1); |
| 256 } | 250 } |
| 257 } | 251 } |
| 258 } | 252 } |
| 259 #endif // defined(OS_CHROMEOS) | |
| 260 | 253 |
| 261 } // namespace ash | 254 } // namespace ash |
| OLD | NEW |