Chromium Code Reviews| Index: ui/aura/window_tree_host_x11.cc |
| diff --git a/ui/aura/window_tree_host_x11.cc b/ui/aura/window_tree_host_x11.cc |
| index 1db7136a0d90ccf09976bacc7f600990a2dae4d3..50780de0af43fb48487e970a206a74ed0f7bdd59 100644 |
| --- a/ui/aura/window_tree_host_x11.cc |
| +++ b/ui/aura/window_tree_host_x11.cc |
| @@ -331,65 +331,13 @@ uint32_t WindowTreeHostX11::DispatchEvent(const ui::PlatformEvent& event) { |
| } |
| switch (xev->type) { |
| - case EnterNotify: { |
| - aura::Window* root_window = window(); |
| - client::CursorClient* cursor_client = |
| - client::GetCursorClient(root_window); |
| - if (cursor_client) { |
| - const gfx::Display display = gfx::Screen::GetScreenFor(root_window)-> |
| - GetDisplayNearestWindow(root_window); |
| - cursor_client->SetDisplay(display); |
| - } |
| - ui::MouseEvent mouse_event(xev); |
| - // EnterNotify creates ET_MOUSE_MOVE. Mark as synthesized as this is not |
| - // real mouse move event. |
| - mouse_event.set_flags(mouse_event.flags() | ui::EF_IS_SYNTHESIZED); |
| - TranslateAndDispatchLocatedEvent(&mouse_event); |
| - break; |
| - } |
| - case LeaveNotify: { |
| - ui::MouseEvent mouse_event(xev); |
| - TranslateAndDispatchLocatedEvent(&mouse_event); |
| - break; |
| - } |
| case Expose: { |
| gfx::Rect damage_rect(xev->xexpose.x, xev->xexpose.y, |
| xev->xexpose.width, xev->xexpose.height); |
| compositor()->ScheduleRedrawRect(damage_rect); |
| break; |
| } |
| - case KeyPress: { |
| - ui::KeyEvent keydown_event(xev, false); |
| - SendEventToProcessor(&keydown_event); |
| - break; |
| - } |
| - case KeyRelease: { |
| - ui::KeyEvent keyup_event(xev, false); |
| - SendEventToProcessor(&keyup_event); |
| - break; |
| - } |
| - case ButtonPress: |
| - case ButtonRelease: { |
| - switch (ui::EventTypeFromNative(xev)) { |
| - case ui::ET_MOUSEWHEEL: { |
| - ui::MouseWheelEvent mouseev(xev); |
| - TranslateAndDispatchLocatedEvent(&mouseev); |
| - break; |
| - } |
| - case ui::ET_MOUSE_PRESSED: |
| - case ui::ET_MOUSE_RELEASED: { |
| - ui::MouseEvent mouseev(xev); |
| - TranslateAndDispatchLocatedEvent(&mouseev); |
| - break; |
| - } |
| - case ui::ET_UNKNOWN: |
| - // No event is created for X11-release events for mouse-wheel buttons. |
| - break; |
| - default: |
| - NOTREACHED(); |
| - } |
| - break; |
| - } |
| + |
| case FocusOut: |
| if (xev->xfocus.mode != NotifyGrab) |
| OnHostLostWindowCapture(); |
| @@ -448,26 +396,74 @@ uint32_t WindowTreeHostX11::DispatchEvent(const ui::PlatformEvent& event) { |
| } |
| break; |
| } |
| + case EnterNotify: |
| + case LeaveNotify: |
| + case KeyPress: |
| + case KeyRelease: |
| + case ButtonPress: |
| + case ButtonRelease: |
| case MotionNotify: { |
| - // Discard all but the most recent motion event that targets the same |
| - // window with unchanged state. |
| - XEvent last_event; |
| - while (XPending(xev->xany.display)) { |
| - XEvent next_event; |
| - XPeekEvent(xev->xany.display, &next_event); |
| - if (next_event.type == MotionNotify && |
| - next_event.xmotion.window == xev->xmotion.window && |
| - next_event.xmotion.subwindow == xev->xmotion.subwindow && |
| - next_event.xmotion.state == xev->xmotion.state) { |
| - XNextEvent(xev->xany.display, &last_event); |
| - xev = &last_event; |
| - } else { |
| + if (xev->type == MotionNotify) { |
| + // Discard all but the most recent motion event that targets the same |
| + // window with unchanged state. |
| + XEvent last_event; |
| + while (XPending(xev->xany.display)) { |
| + XEvent next_event; |
| + XPeekEvent(xev->xany.display, &next_event); |
| + if (next_event.type == MotionNotify && |
| + next_event.xmotion.window == xev->xmotion.window && |
| + next_event.xmotion.subwindow == xev->xmotion.subwindow && |
| + next_event.xmotion.state == xev->xmotion.state) { |
| + XNextEvent(xev->xany.display, &last_event); |
| + xev = &last_event; |
| + } else { |
| + break; |
| + } |
| + } |
| + } |
|
sadrul
2014/06/12 21:02:27
Maybe this could move out of the switch/case (like
flackr
2014/06/18 05:28:31
Done.
|
| + switch (ui::EventTypeFromNative(xev)) { |
| + case ui::ET_MOUSE_ENTERED: { |
| + aura::Window* root_window = window(); |
| + client::CursorClient* cursor_client = |
| + client::GetCursorClient(root_window); |
| + if (cursor_client) { |
| + const gfx::Display display = gfx::Screen::GetScreenFor( |
| + root_window)->GetDisplayNearestWindow(root_window); |
| + cursor_client->SetDisplay(display); |
| + } |
| + ui::MouseEvent mouse_event(xev); |
| + // EnterNotify creates ET_MOUSE_MOVE. Mark as synthesized as this is |
| + // not a real mouse move event. |
| + mouse_event.set_flags(mouse_event.flags() | ui::EF_IS_SYNTHESIZED); |
| + TranslateAndDispatchLocatedEvent(&mouse_event); |
| + break; |
| + } |
| + case ui::ET_KEY_PRESSED: |
| + case ui::ET_KEY_RELEASED: { |
| + ui::KeyEvent keydown_event(xev, false); |
| + SendEventToProcessor(&keydown_event); |
| + break; |
| + } |
| + case ui::ET_MOUSE_MOVED: |
| + case ui::ET_MOUSE_DRAGGED: |
| + case ui::ET_MOUSE_EXITED: |
| + case ui::ET_MOUSE_PRESSED: |
| + case ui::ET_MOUSE_RELEASED: { |
| + ui::MouseEvent mouse_event(xev); |
| + TranslateAndDispatchLocatedEvent(&mouse_event); |
| break; |
| } |
| + case ui::ET_MOUSEWHEEL: { |
| + ui::MouseWheelEvent mouseev(xev); |
| + TranslateAndDispatchLocatedEvent(&mouseev); |
| + break; |
| + } |
| + case ui::ET_UNKNOWN: |
| + // No event is created for X11-release events for mouse-wheel buttons. |
| + break; |
| + default: |
| + NOTREACHED(); |
| } |
| - |
| - ui::MouseEvent mouseev(xev); |
| - TranslateAndDispatchLocatedEvent(&mouseev); |
| break; |
| } |
| } |
| @@ -639,9 +635,17 @@ void WindowTreeHostX11::DispatchXI2Event(const base::NativeEvent& event) { |
| (ui::EventTimeForNow() - ui::EventTimeFromNative(event)). |
| InMicroseconds()); |
| - ui::EventType type = ui::EventTypeFromNative(xev); |
| - XEvent last_event; |
| int num_coalesced = 0; |
| + XEvent last_event; |
| + if (xev->xgeneric.evtype == XI_Motion) { |
| + // If this is a motion event, we want to coalesce all pending motion |
| + // events that are at the top of the queue. Note, we don't coalesce |
| + // touch update events here. |
| + num_coalesced = ui::CoalescePendingMotionEvents(xev, &last_event); |
| + if (num_coalesced > 0) |
| + xev = &last_event; |
| + } |
| + ui::EventType type = ui::EventTypeFromNative(xev); |
| switch (type) { |
| case ui::ET_TOUCH_MOVED: |
| @@ -662,13 +666,6 @@ void WindowTreeHostX11::DispatchXI2Event(const base::NativeEvent& event) { |
| case ui::ET_MOUSE_RELEASED: |
| case ui::ET_MOUSE_ENTERED: |
| case ui::ET_MOUSE_EXITED: { |
| - if (type == ui::ET_MOUSE_MOVED || type == ui::ET_MOUSE_DRAGGED) { |
| - // If this is a motion event, we want to coalesce all pending motion |
| - // events that are at the top of the queue. |
| - num_coalesced = ui::CoalescePendingMotionEvents(xev, &last_event); |
| - if (num_coalesced > 0) |
| - xev = &last_event; |
| - } |
| ui::MouseEvent mouseev(xev); |
| TranslateAndDispatchLocatedEvent(&mouseev); |
| break; |