| Index: ui/platform_window/x11/x11_window.cc
|
| diff --git a/ui/platform_window/x11/x11_window.cc b/ui/platform_window/x11/x11_window.cc
|
| index e86cf3c9a09cf6631f6ffd6f5672dd79190d4a21..ed22656b11c60c214545ceea302c554fd3f22b3b 100644
|
| --- a/ui/platform_window/x11/x11_window.cc
|
| +++ b/ui/platform_window/x11/x11_window.cc
|
| @@ -9,9 +9,11 @@
|
| #include <X11/Xlib.h>
|
| #include <X11/Xutil.h>
|
|
|
| +#include "base/bind.h"
|
| #include "ui/events/devices/x11/touch_factory_x11.h"
|
| #include "ui/events/event.h"
|
| #include "ui/events/event_utils.h"
|
| +#include "ui/events/ozone/events_ozone.h"
|
| #include "ui/events/platform/platform_event_dispatcher.h"
|
| #include "ui/events/platform/platform_event_source.h"
|
| #include "ui/events/platform/x11/x11_event_source.h"
|
| @@ -31,17 +33,41 @@ const char* kAtomsToCache[] = {
|
| NULL
|
| };
|
|
|
| -XID FindXEventTarget(XEvent* xevent) {
|
| - XID target = xevent->xany.window;
|
| - if (xevent->type == GenericEvent)
|
| - target = static_cast<XIDeviceEvent*>(xevent->xcookie.data)->event;
|
| - return target;
|
| +} // namespace
|
| +
|
| +X11WindowManager::X11WindowManager() {
|
| +}
|
| +X11WindowManager::~X11WindowManager() {
|
| }
|
|
|
| -} // namespace
|
| +scoped_ptr<X11Window> X11WindowManager::CreatePlatformWindow(
|
| + PlatformWindowDelegate* delegate) {
|
| + return scoped_ptr<X11Window>(new X11Window(
|
| + delegate, base::Bind(&X11WindowManager::OnWindowCreate, this),
|
| + base::Bind(&X11WindowManager::OnWindowDestroy, this)));
|
| +}
|
| +
|
| +X11Window* X11WindowManager::FindWindow(XID id) {
|
| + auto iter = window_map_.find(id);
|
| + if (iter == window_map_.end())
|
| + return nullptr;
|
| + return iter->second;
|
| +}
|
|
|
| -X11Window::X11Window(PlatformWindowDelegate* delegate)
|
| +void X11WindowManager::OnWindowCreate(XID id, X11Window* window) {
|
| + window_map_[id] = window;
|
| +}
|
| +
|
| +void X11WindowManager::OnWindowDestroy(XID id, X11Window* window) {
|
| + window_map_.erase(id);
|
| +}
|
| +
|
| +X11Window::X11Window(PlatformWindowDelegate* delegate,
|
| + WindowStatusCallback on_create_callback,
|
| + WindowStatusCallback on_destroy_callback)
|
| : delegate_(delegate),
|
| + on_create_callback_(on_create_callback),
|
| + on_destroy_callback_(on_destroy_callback),
|
| xdisplay_(gfx::GetXDisplay()),
|
| xwindow_(None),
|
| xroot_window_(DefaultRootWindow(xdisplay_)),
|
| @@ -61,59 +87,13 @@ void X11Window::Destroy() {
|
| return;
|
|
|
| // Stop processing events.
|
| + on_destroy_callback_.Run(xwindow_, this);
|
| PlatformEventSource::GetInstance()->RemovePlatformEventDispatcher(this);
|
| XDestroyWindow(xdisplay_, xwindow_);
|
| xwindow_ = None;
|
| }
|
|
|
| -void X11Window::ProcessXInput2Event(XEvent* xev) {
|
| - if (!TouchFactory::GetInstance()->ShouldProcessXI2Event(xev))
|
| - return;
|
| - EventType event_type = EventTypeFromNative(xev);
|
| - switch (event_type) {
|
| - case ET_KEY_PRESSED:
|
| - case ET_KEY_RELEASED: {
|
| - KeyEvent key_event(xev);
|
| - delegate_->DispatchEvent(&key_event);
|
| - break;
|
| - }
|
| - case ET_MOUSE_PRESSED:
|
| - case ET_MOUSE_MOVED:
|
| - case ET_MOUSE_DRAGGED:
|
| - case ET_MOUSE_RELEASED: {
|
| - MouseEvent mouse_event(xev);
|
| - delegate_->DispatchEvent(&mouse_event);
|
| - break;
|
| - }
|
| - case ET_MOUSEWHEEL: {
|
| - MouseWheelEvent wheel_event(xev);
|
| - delegate_->DispatchEvent(&wheel_event);
|
| - break;
|
| - }
|
| - case ET_SCROLL_FLING_START:
|
| - case ET_SCROLL_FLING_CANCEL:
|
| - case ET_SCROLL: {
|
| - ScrollEvent scroll_event(xev);
|
| - delegate_->DispatchEvent(&scroll_event);
|
| - break;
|
| - }
|
| - case ET_TOUCH_MOVED:
|
| - case ET_TOUCH_PRESSED:
|
| - case ET_TOUCH_CANCELLED:
|
| - case ET_TOUCH_RELEASED: {
|
| - TouchEvent touch_event(xev);
|
| - delegate_->DispatchEvent(&touch_event);
|
| - break;
|
| - }
|
| - default:
|
| - break;
|
| - }
|
| -}
|
| -
|
| -void X11Window::Show() {
|
| - if (window_mapped_)
|
| - return;
|
| -
|
| +void X11Window::Create() {
|
| CHECK(PlatformEventSource::GetInstance());
|
| PlatformEventSource::GetInstance()->AddPlatformEventDispatcher(this);
|
|
|
| @@ -133,6 +113,7 @@ void X11Window::Show() {
|
| CopyFromParent, // visual
|
| CWBackPixmap | CWOverrideRedirect,
|
| &swa);
|
| + on_create_callback_.Run(xwindow_, this);
|
|
|
| long event_mask = ButtonPressMask | ButtonReleaseMask | FocusChangeMask |
|
| KeyPressMask | KeyReleaseMask | EnterWindowMask |
|
| @@ -195,6 +176,13 @@ void X11Window::Show() {
|
| XSetWMNormalHints(xdisplay_, xwindow_, &size_hints);
|
|
|
| delegate_->OnAcceleratedWidgetAvailable(xwindow_);
|
| +}
|
| +
|
| +void X11Window::Show() {
|
| + if (window_mapped_)
|
| + return;
|
| + if (xwindow_ == None)
|
| + Create();
|
|
|
| XMapWindow(xdisplay_, xwindow_);
|
|
|
| @@ -219,7 +207,7 @@ void X11Window::Close() {
|
|
|
| void X11Window::SetBounds(const gfx::Rect& bounds) {
|
| requested_bounds_ = bounds;
|
| - if (!window_mapped_)
|
| + if (!window_mapped_ || bounds == confirmed_bounds_)
|
| return;
|
| XWindowChanges changes = {0};
|
| unsigned value_mask = CWX | CWY | CWWidth | CWHeight;
|
| @@ -251,27 +239,11 @@ void X11Window::SetCursor(PlatformCursor cursor) {}
|
| void X11Window::MoveCursorTo(const gfx::Point& location) {}
|
|
|
| bool X11Window::CanDispatchEvent(const PlatformEvent& event) {
|
| - return FindXEventTarget(event) == xwindow_;
|
| + return true;
|
| }
|
|
|
| -uint32_t X11Window::DispatchEvent(const PlatformEvent& event) {
|
| - XEvent* xev = event;
|
| +void X11Window::ProcessWindowEvent(XEvent* xev) {
|
| switch (xev->type) {
|
| - case EnterNotify: {
|
| - // EnterNotify creates ET_MOUSE_MOVED. Mark as synthesized as this is
|
| - // not real mouse move event.
|
| - MouseEvent mouse_event(xev);
|
| - CHECK_EQ(ET_MOUSE_MOVED, mouse_event.type());
|
| - mouse_event.set_flags(mouse_event.flags() | EF_IS_SYNTHESIZED);
|
| - delegate_->DispatchEvent(&mouse_event);
|
| - break;
|
| - }
|
| - case LeaveNotify: {
|
| - MouseEvent mouse_event(xev);
|
| - delegate_->DispatchEvent(&mouse_event);
|
| - break;
|
| - }
|
| -
|
| case Expose: {
|
| gfx::Rect damage_rect(xev->xexpose.x,
|
| xev->xexpose.y,
|
| @@ -281,37 +253,6 @@ uint32_t X11Window::DispatchEvent(const PlatformEvent& event) {
|
| break;
|
| }
|
|
|
| - case KeyPress:
|
| - case KeyRelease: {
|
| - KeyEvent key_event(xev);
|
| - delegate_->DispatchEvent(&key_event);
|
| - break;
|
| - }
|
| -
|
| - case ButtonPress:
|
| - case ButtonRelease: {
|
| - switch (EventTypeFromNative(xev)) {
|
| - case ET_MOUSEWHEEL: {
|
| - MouseWheelEvent mouseev(xev);
|
| - delegate_->DispatchEvent(&mouseev);
|
| - break;
|
| - }
|
| - case ET_MOUSE_PRESSED:
|
| - case ET_MOUSE_RELEASED: {
|
| - MouseEvent mouseev(xev);
|
| - delegate_->DispatchEvent(&mouseev);
|
| - break;
|
| - }
|
| - case 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)
|
| delegate_->OnLostCapture();
|
| @@ -348,12 +289,14 @@ uint32_t X11Window::DispatchEvent(const PlatformEvent& event) {
|
| }
|
| break;
|
| }
|
| -
|
| - case GenericEvent: {
|
| - ProcessXInput2Event(xev);
|
| - break;
|
| - }
|
| }
|
| +}
|
| +
|
| +uint32_t X11Window::DispatchEvent(const PlatformEvent& event) {
|
| + DispatchEventFromNativeUiEvent(
|
| + event, base::Bind(&PlatformWindowDelegate::DispatchEvent,
|
| + base::Unretained(delegate_)));
|
| +
|
| return POST_DISPATCH_STOP_PROPAGATION;
|
| }
|
|
|
|
|