OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 "ui/aura/root_window_host.h" | 5 #include "ui/aura/root_window_host.h" |
6 | 6 |
7 #include <X11/cursorfont.h> | 7 #include <X11/cursorfont.h> |
8 #include <X11/Xlib.h> | 8 #include <X11/Xlib.h> |
9 | 9 |
10 // Get rid of a macro from Xlib.h that conflicts with Aura's RootWindow class. | 10 // Get rid of a macro from Xlib.h that conflicts with Aura's RootWindow class. |
11 #undef RootWindow | 11 #undef RootWindow |
12 | 12 |
13 #include <algorithm> | 13 #include <algorithm> |
14 | 14 |
15 #include "base/message_loop.h" | 15 #include "base/message_loop.h" |
16 #include "base/message_pump_x.h" | 16 #include "base/message_pump_x.h" |
17 #include "ui/aura/cursor.h" | 17 #include "ui/aura/cursor.h" |
18 #include "ui/aura/event.h" | 18 #include "ui/aura/event.h" |
19 #include "ui/aura/root_window.h" | 19 #include "ui/aura/root_window.h" |
20 #include "ui/base/keycodes/keyboard_codes.h" | 20 #include "ui/base/keycodes/keyboard_codes.h" |
21 #include "ui/base/touch/touch_factory.h" | 21 #include "ui/base/touch/touch_factory.h" |
| 22 #include "ui/base/x/scroll_factory.h" |
22 #include "ui/base/x/x11_util.h" | 23 #include "ui/base/x/x11_util.h" |
23 #include "ui/gfx/compositor/layer.h" | 24 #include "ui/gfx/compositor/layer.h" |
24 | 25 |
25 #include <X11/cursorfont.h> | 26 #include <X11/cursorfont.h> |
26 #include <X11/extensions/XInput2.h> | 27 #include <X11/extensions/XInput2.h> |
27 #include <X11/Xlib.h> | 28 #include <X11/Xlib.h> |
28 | 29 |
29 using std::max; | 30 using std::max; |
30 using std::min; | 31 using std::min; |
31 | 32 |
(...skipping 158 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
190 // with one from the master and one from the slave so there will | 191 // with one from the master and one from the slave so there will |
191 // always be at least one pending. | 192 // always be at least one pending. |
192 if (!ui::TouchFactory::GetInstance()->ShouldProcessXI2Event(&next_event)) { | 193 if (!ui::TouchFactory::GetInstance()->ShouldProcessXI2Event(&next_event)) { |
193 CheckXEventForConsistency(&next_event); | 194 CheckXEventForConsistency(&next_event); |
194 XFreeEventData(display, &next_event.xcookie); | 195 XFreeEventData(display, &next_event.xcookie); |
195 XNextEvent(display, &next_event); | 196 XNextEvent(display, &next_event); |
196 continue; | 197 continue; |
197 } | 198 } |
198 | 199 |
199 if (next_event.type == GenericEvent && | 200 if (next_event.type == GenericEvent && |
200 next_event.xgeneric.evtype == XI_Motion) { | 201 next_event.xgeneric.evtype == XI_Motion && |
| 202 !ui::ScrollFactory::GetInstance()->GetScrollOffsets( |
| 203 next_event, NULL, NULL)) { |
201 XIDeviceEvent* next_xievent = | 204 XIDeviceEvent* next_xievent = |
202 static_cast<XIDeviceEvent*>(next_event.xcookie.data); | 205 static_cast<XIDeviceEvent*>(next_event.xcookie.data); |
203 // Confirm that the motion event is targeted at the same window | 206 // Confirm that the motion event is targeted at the same window |
204 // and that no buttons or modifiers have changed. | 207 // and that no buttons or modifiers have changed. |
205 if (xievent->event == next_xievent->event && | 208 if (xievent->event == next_xievent->event && |
206 xievent->child == next_xievent->child && | 209 xievent->child == next_xievent->child && |
207 xievent->buttons.mask_len == next_xievent->buttons.mask_len && | 210 xievent->buttons.mask_len == next_xievent->buttons.mask_len && |
208 (memcmp(xievent->buttons.mask, | 211 (memcmp(xievent->buttons.mask, |
209 next_xievent->buttons.mask, | 212 next_xievent->buttons.mask, |
210 xievent->buttons.mask_len) == 0) && | 213 xievent->buttons.mask_len) == 0) && |
(...skipping 204 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
415 if (size_changed) | 418 if (size_changed) |
416 root_window_->OnHostResized(bounds.size()); | 419 root_window_->OnHostResized(bounds.size()); |
417 handled = true; | 420 handled = true; |
418 break; | 421 break; |
419 } | 422 } |
420 case GenericEvent: { | 423 case GenericEvent: { |
421 ui::TouchFactory* factory = ui::TouchFactory::GetInstance(); | 424 ui::TouchFactory* factory = ui::TouchFactory::GetInstance(); |
422 if (!factory->ShouldProcessXI2Event(xev)) | 425 if (!factory->ShouldProcessXI2Event(xev)) |
423 break; | 426 break; |
424 | 427 |
| 428 // Update the device list if necessary. |
| 429 if (xev->xgeneric.evtype == XI_HierarchyChanged) { |
| 430 ui::ScrollFactory::GetInstance()->UpdateDeviceList(xdisplay_); |
| 431 factory->UpdateDeviceList(xdisplay_); |
| 432 handled = true; |
| 433 break; |
| 434 } |
| 435 |
| 436 ui::EventType type = ui::EventTypeFromNative(xev); |
425 // If this is a motion event we want to coalesce all pending motion | 437 // If this is a motion event we want to coalesce all pending motion |
426 // events that are at the top of the queue. | 438 // events that are at the top of the queue. |
427 XEvent last_event; | 439 XEvent last_event; |
428 int num_coalesced = 0; | 440 int num_coalesced = 0; |
429 if (xev->xgeneric.evtype == XI_Motion) { | |
430 num_coalesced = CoalescePendingXIMotionEvents(xev, &last_event); | |
431 if (num_coalesced > 0) | |
432 xev = &last_event; | |
433 } | |
434 | 441 |
435 ui::EventType type = ui::EventTypeFromNative(xev); | |
436 switch (type) { | 442 switch (type) { |
437 case ui::ET_TOUCH_PRESSED: | 443 case ui::ET_TOUCH_PRESSED: |
438 case ui::ET_TOUCH_RELEASED: | 444 case ui::ET_TOUCH_RELEASED: |
439 case ui::ET_TOUCH_MOVED: { | 445 case ui::ET_TOUCH_MOVED: { |
440 TouchEvent touchev(xev); | 446 TouchEvent touchev(xev); |
441 handled = root_window_->DispatchTouchEvent(&touchev); | 447 handled = root_window_->DispatchTouchEvent(&touchev); |
442 break; | 448 break; |
443 } | 449 } |
| 450 case ui::ET_MOUSE_MOVED: |
| 451 case ui::ET_MOUSE_DRAGGED: { |
| 452 // If this is a motion event we want to coalesce all pending motion |
| 453 // events that are at the top of the queue. |
| 454 num_coalesced = CoalescePendingXIMotionEvents(xev, &last_event); |
| 455 if (num_coalesced > 0) |
| 456 xev = &last_event; |
| 457 } |
444 case ui::ET_MOUSE_PRESSED: | 458 case ui::ET_MOUSE_PRESSED: |
445 case ui::ET_MOUSE_RELEASED: | 459 case ui::ET_MOUSE_RELEASED: |
446 case ui::ET_MOUSE_MOVED: | |
447 case ui::ET_MOUSE_DRAGGED: | |
448 case ui::ET_MOUSEWHEEL: | 460 case ui::ET_MOUSEWHEEL: |
449 case ui::ET_MOUSE_ENTERED: | 461 case ui::ET_MOUSE_ENTERED: |
450 case ui::ET_MOUSE_EXITED: { | 462 case ui::ET_MOUSE_EXITED: { |
451 MouseEvent mouseev(xev); | 463 MouseEvent mouseev(xev); |
452 handled = root_window_->DispatchMouseEvent(&mouseev); | 464 handled = root_window_->DispatchMouseEvent(&mouseev); |
453 break; | 465 break; |
454 } | 466 } |
| 467 case ui::ET_SCROLL: { |
| 468 ScrollEvent scrollev(xev); |
| 469 handled = root_window_->DispatchScrollEvent(&scrollev); |
| 470 break; |
| 471 } |
455 case ui::ET_UNKNOWN: | 472 case ui::ET_UNKNOWN: |
456 handled = false; | 473 handled = false; |
457 break; | 474 break; |
458 default: | 475 default: |
459 NOTREACHED(); | 476 NOTREACHED(); |
460 } | 477 } |
461 | 478 |
462 // If we coalesced an event we need to free its cookie. | 479 // If we coalesced an event we need to free its cookie. |
463 if (num_coalesced > 0) | 480 if (num_coalesced > 0) |
464 XFreeEventData(xev->xgeneric.display, &last_event.xcookie); | 481 XFreeEventData(xev->xgeneric.display, &last_event.xcookie); |
(...skipping 165 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
630 return new RootWindowHostLinux(bounds); | 647 return new RootWindowHostLinux(bounds); |
631 } | 648 } |
632 | 649 |
633 // static | 650 // static |
634 gfx::Size RootWindowHost::GetNativeScreenSize() { | 651 gfx::Size RootWindowHost::GetNativeScreenSize() { |
635 ::Display* xdisplay = base::MessagePumpX::GetDefaultXDisplay(); | 652 ::Display* xdisplay = base::MessagePumpX::GetDefaultXDisplay(); |
636 return gfx::Size(DisplayWidth(xdisplay, 0), DisplayHeight(xdisplay, 0)); | 653 return gfx::Size(DisplayWidth(xdisplay, 0), DisplayHeight(xdisplay, 0)); |
637 } | 654 } |
638 | 655 |
639 } // namespace aura | 656 } // namespace aura |
OLD | NEW |