Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(390)

Unified Diff: ui/platform_window/x11/x11_window.cc

Issue 1602173005: Add PlatformWindow/Event related code for Ozone X11. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: XEventDispatcher added. Created 4 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
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 6900a448915dfebde9e73ef2d7b1c5e07600f404..53e637e5b719222183dcc8ba534a92fc883b3875 100644
--- a/ui/platform_window/x11/x11_window.cc
+++ b/ui/platform_window/x11/x11_window.cc
@@ -9,13 +9,14 @@
#include <X11/Xlib.h>
#include <X11/Xutil.h>
+#include <string>
+
#include "base/strings/utf_string_conversions.h"
#include "ui/events/devices/x11/touch_factory_x11.h"
#include "ui/events/event.h"
#include "ui/events/event_utils.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"
#include "ui/gfx/geometry/rect.h"
#include "ui/gfx/x/x11_atom_cache.h"
#include "ui/gfx/x/x11_types.h"
@@ -34,13 +35,6 @@ 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;
-}
-
bool g_override_redirect = false;
} // namespace
@@ -50,8 +44,7 @@ X11Window::X11Window(PlatformWindowDelegate* delegate)
xdisplay_(gfx::GetXDisplay()),
xwindow_(None),
xroot_window_(DefaultRootWindow(xdisplay_)),
- atom_cache_(xdisplay_, kAtomsToCache),
- window_mapped_(false) {
+ atom_cache_(xdisplay_, kAtomsToCache) {
CHECK(delegate_);
TouchFactory::SetTouchDeviceListFromCommandLine();
}
@@ -75,57 +68,13 @@ void X11Window::Destroy() {
XDestroyWindow(xdisplay, xwindow);
}
-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;
-
- CHECK(PlatformEventSource::GetInstance());
+void X11Window::Create() {
+ DCHECK(PlatformEventSource::GetInstance());
PlatformEventSource::GetInstance()->AddPlatformEventDispatcher(this);
+ DCHECK(X11EventSource::GetInstance());
+ X11EventSource::GetInstance()->AddXEventDispatcher(this);
+
XSetWindowAttributes swa;
memset(&swa, 0, sizeof(swa));
swa.background_pixmap = None;
@@ -205,6 +154,16 @@ void X11Window::Show() {
size_hints.win_gravity = StaticGravity;
XSetWMNormalHints(xdisplay_, xwindow_, &size_hints);
+ // TODO(sky): provide real scale factor.
+ delegate_->OnAcceleratedWidgetAvailable(xwindow_, 1.f);
+}
+
+void X11Window::Show() {
+ if (window_mapped_)
+ return;
+ if (xwindow_ == None)
+ Create();
+
XMapWindow(xdisplay_, xwindow_);
// We now block until our window is mapped. Some X11 APIs will crash and
@@ -213,9 +172,6 @@ void X11Window::Show() {
if (X11EventSource::GetInstance())
X11EventSource::GetInstance()->BlockUntilWindowMapped(xwindow_);
window_mapped_ = true;
-
- // TODO(sky): provide real scale factor.
- delegate_->OnAcceleratedWidgetAvailable(xwindow_, 1.f);
}
void X11Window::Hide() {
@@ -231,7 +187,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;
@@ -260,7 +216,7 @@ void X11Window::SetTitle(const base::string16& title) {
reinterpret_cast<const unsigned char*>(utf8str.c_str()),
utf8str.size());
XTextProperty xtp;
- char *c_utf8_str = const_cast<char *>(utf8str.c_str());
+ char* c_utf8_str = const_cast<char*>(utf8str.c_str());
if (Xutf8TextListToTextProperty(xdisplay_, &c_utf8_str, 1,
XUTF8StringStyle, &xtp) == Success) {
XSetWMName(xdisplay_, xwindow_, &xtp);
@@ -280,10 +236,6 @@ void X11Window::Minimize() {}
void X11Window::Restore() {}
-void X11Window::SetCursor(PlatformCursor cursor) {
- XDefineCursor(xdisplay_, xwindow_, cursor);
-}
-
void X11Window::MoveCursorTo(const gfx::Point& location) {}
void X11Window::ConfineCursorToBounds(const gfx::Rect& bounds) {
@@ -293,80 +245,25 @@ PlatformImeController* X11Window::GetPlatformImeController() {
return nullptr;
}
-bool X11Window::CanDispatchEvent(const PlatformEvent& event) {
- return FindXEventTarget(event) == xwindow_;
-}
-
-uint32_t X11Window::DispatchEvent(const PlatformEvent& event) {
- XEvent* xev = event;
- 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;
- }
-
+void X11Window::ProcessXWindowEvent(const XEvent& xev) {
+ switch (xev.type) {
case Expose: {
- gfx::Rect damage_rect(xev->xexpose.x,
- xev->xexpose.y,
- xev->xexpose.width,
- xev->xexpose.height);
+ gfx::Rect damage_rect(xev.xexpose.x, xev.xexpose.y, xev.xexpose.width,
+ xev.xexpose.height);
delegate_->OnDamageRect(damage_rect);
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)
+ if (xev.xfocus.mode != NotifyGrab)
delegate_->OnLostCapture();
break;
case ConfigureNotify: {
- DCHECK_EQ(xwindow_, xev->xconfigure.event);
- DCHECK_EQ(xwindow_, xev->xconfigure.window);
- gfx::Rect bounds(xev->xconfigure.x,
- xev->xconfigure.y,
- xev->xconfigure.width,
- xev->xconfigure.height);
+ DCHECK_EQ(xwindow_, xev.xconfigure.event);
+ DCHECK_EQ(xwindow_, xev.xconfigure.window);
+ gfx::Rect bounds(xev.xconfigure.x, xev.xconfigure.y, xev.xconfigure.width,
+ xev.xconfigure.height);
if (confirmed_bounds_ != bounds) {
confirmed_bounds_ = bounds;
delegate_->OnBoundsChanged(confirmed_bounds_);
@@ -375,11 +272,11 @@ uint32_t X11Window::DispatchEvent(const PlatformEvent& event) {
}
case ClientMessage: {
- Atom message = static_cast<Atom>(xev->xclient.data.l[0]);
+ Atom message = static_cast<Atom>(xev.xclient.data.l[0]);
if (message == atom_cache_.GetAtom("WM_DELETE_WINDOW")) {
delegate_->OnCloseRequest();
} else if (message == atom_cache_.GetAtom("_NET_WM_PING")) {
- XEvent reply_event = *xev;
+ XEvent reply_event = xev;
reply_event.xclient.window = xroot_window_;
XSendEvent(xdisplay_,
@@ -391,13 +288,7 @@ uint32_t X11Window::DispatchEvent(const PlatformEvent& event) {
}
break;
}
-
- case GenericEvent: {
- ProcessXInput2Event(xev);
- break;
- }
}
- return POST_DISPATCH_STOP_PROPAGATION;
}
namespace test {

Powered by Google App Engine
This is Rietveld 408576698