diff options
Diffstat (limited to 'ui')
-rw-r--r-- | ui/aura/desktop.cc | 5 | ||||
-rw-r--r-- | ui/aura/desktop.h | 3 | ||||
-rw-r--r-- | ui/aura/desktop_host.h | 3 | ||||
-rw-r--r-- | ui/aura/desktop_host_linux.cc | 59 | ||||
-rw-r--r-- | ui/aura/desktop_host_win.cc | 7 | ||||
-rw-r--r-- | ui/aura/desktop_host_win.h | 1 | ||||
-rw-r--r-- | ui/base/x/events_x.cc | 30 | ||||
-rw-r--r-- | ui/ui.gyp | 1 | ||||
-rw-r--r-- | ui/ui_unittests.gypi | 2 |
9 files changed, 89 insertions, 22 deletions
diff --git a/ui/aura/desktop.cc b/ui/aura/desktop.cc index a4aa58e..b3a8b8a 100644 --- a/ui/aura/desktop.cc +++ b/ui/aura/desktop.cc @@ -377,6 +377,11 @@ void Desktop::PostNativeEvent(const base::NativeEvent& native_event) { host_->PostNativeEvent(native_event); } +void Desktop::ConvertPointToNativeScreen(gfx::Point* point) const { + gfx::Point location = host_->GetLocationOnNativeScreen(); + point->Offset(location.x(), location.y()); +} + void Desktop::SetCapture(Window* window) { if (capture_window_ == window) return; diff --git a/ui/aura/desktop.h b/ui/aura/desktop.h index 7e8d0dc..40963f4 100644 --- a/ui/aura/desktop.h +++ b/ui/aura/desktop.h @@ -131,6 +131,9 @@ class AURA_EXPORT Desktop : public ui::CompositorDelegate, // Posts |native_event| to the platform's event queue. void PostNativeEvent(const base::NativeEvent& native_event); + // Converts |point| from the desktop's coordinate system to native screen's. + void ConvertPointToNativeScreen(gfx::Point* point) const; + // Capture ------------------------------------------------------------------- // Sets capture to the specified window. diff --git a/ui/aura/desktop_host.h b/ui/aura/desktop_host.h index b276dea..0ac7be1 100644 --- a/ui/aura/desktop_host.h +++ b/ui/aura/desktop_host.h @@ -50,6 +50,9 @@ class DesktopHost : public MessageLoop::Dispatcher { virtual gfx::Size GetSize() const = 0; virtual void SetSize(const gfx::Size& size) = 0; + // Returns the location of the desktop on native screen. + virtual gfx::Point GetLocationOnNativeScreen() const = 0; + // Sets the currently displayed cursor. virtual void SetCursor(gfx::NativeCursor cursor) = 0; diff --git a/ui/aura/desktop_host_linux.cc b/ui/aura/desktop_host_linux.cc index 2de31e6..7e9a5b1 100644 --- a/ui/aura/desktop_host_linux.cc +++ b/ui/aura/desktop_host_linux.cc @@ -238,6 +238,7 @@ class DesktopHostLinux : public DesktopHost { virtual void ToggleFullScreen() OVERRIDE; virtual gfx::Size GetSize() const OVERRIDE; virtual void SetSize(const gfx::Size& size) OVERRIDE; + virtual gfx::Point GetLocationOnNativeScreen() const OVERRIDE; virtual void SetCursor(gfx::NativeCursor cursor_type) OVERRIDE; virtual gfx::Point QueryMouseLocation() OVERRIDE; virtual void PostNativeEvent(const base::NativeEvent& event) OVERRIDE; @@ -256,8 +257,8 @@ class DesktopHostLinux : public DesktopHost { // Current Aura cursor. gfx::NativeCursor current_cursor_; - // The size of |xwindow_|. - gfx::Size size_; + // The bounds of |xwindow_|. + gfx::Rect bounds_; DISALLOW_COPY_AND_ASSIGN(DesktopHostLinux); }; @@ -267,7 +268,7 @@ DesktopHostLinux::DesktopHostLinux(const gfx::Rect& bounds) xdisplay_(base::MessagePumpX::GetDefaultXDisplay()), xwindow_(0), current_cursor_(aura::kCursorNull), - size_(bounds.size()) { + bounds_(bounds) { xwindow_ = XCreateSimpleWindow(xdisplay_, DefaultRootWindow(xdisplay_), bounds.x(), bounds.y(), bounds.width(), bounds.height(), @@ -331,11 +332,12 @@ base::MessagePumpDispatcher::DispatchStatus DesktopHostLinux::Dispatch( // It's possible that the X window may be resized by some other means than // from within aura (e.g. the X window manager can change the size). Make // sure the desktop size is maintained properly. - gfx::Size size(xev->xconfigure.width, xev->xconfigure.height); - if (size_ != size) { - size_ = size; - desktop_->OnHostResized(size); - } + gfx::Rect bounds(xev->xconfigure.x, xev->xconfigure.y, + xev->xconfigure.width, xev->xconfigure.height); + bool size_changed = bounds_.size() != bounds.size(); + bounds_ = bounds; + if (size_changed) + desktop_->OnHostResized(bounds.size()); handled = true; break; } @@ -437,11 +439,11 @@ void DesktopHostLinux::ToggleFullScreen() { } gfx::Size DesktopHostLinux::GetSize() const { - return size_; + return bounds_.size(); } void DesktopHostLinux::SetSize(const gfx::Size& size) { - if (size == size_) + if (size == bounds_.size()) return; XResizeWindow(xdisplay_, xwindow_, size.width(), size.height()); @@ -450,11 +452,15 @@ void DesktopHostLinux::SetSize(const gfx::Size& size) { // case if we're running without a window manager. If there's a window // manager, it can modify or ignore the request, but (per ICCCM) we'll get a // (possibly synthetic) ConfigureNotify about the actual size and correct - // |size_| later. - size_ = size; + // |bounds_| later. + bounds_.set_size(size); desktop_->OnHostResized(size); } +gfx::Point DesktopHostLinux::GetLocationOnNativeScreen() const { + return bounds_.origin(); +} + void DesktopHostLinux::SetCursor(gfx::NativeCursor cursor) { if (current_cursor_ == cursor) return; @@ -478,8 +484,8 @@ gfx::Point DesktopHostLinux::QueryMouseLocation() { &root_x_return, &root_y_return, &win_x_return, &win_y_return, &mask_return); - return gfx::Point(max(0, min(size_.width(), win_x_return)), - max(0, min(size_.height(), win_y_return))); + return gfx::Point(max(0, min(bounds_.width(), win_x_return)), + max(0, min(bounds_.height(), win_y_return))); } void DesktopHostLinux::PostNativeEvent(const base::NativeEvent& native_event) { @@ -488,7 +494,30 @@ void DesktopHostLinux::PostNativeEvent(const base::NativeEvent& native_event) { XEvent xevent = *native_event; xevent.xany.display = xdisplay_; xevent.xany.window = xwindow_; - ::XPutBackEvent(xdisplay_, &xevent); + + switch (xevent.type) { + case EnterNotify: + case LeaveNotify: + case MotionNotify: + case KeyPress: + case KeyRelease: + case ButtonPress: + case ButtonRelease: { + // The fields used below are in the same place for all of events + // above. Using xmotion from XEvent's unions to avoid repeating + // the code. + xevent.xmotion.root = DefaultRootWindow(xdisplay_); + xevent.xmotion.time = CurrentTime; + + gfx::Point point(xevent.xmotion.x, xevent.xmotion.y); + desktop_->ConvertPointToNativeScreen(&point); + xevent.xmotion.x_root = point.x(); + xevent.xmotion.y_root = point.y(); + } + default: + break; + } + XSendEvent(xdisplay_, xwindow_, False, 0, &xevent); } bool DesktopHostLinux::IsWindowManagerPresent() { diff --git a/ui/aura/desktop_host_win.cc b/ui/aura/desktop_host_win.cc index 36399e2..3ad4f66 100644 --- a/ui/aura/desktop_host_win.cc +++ b/ui/aura/desktop_host_win.cc @@ -206,6 +206,13 @@ void DesktopHostWin::SetSize(const gfx::Size& size) { SWP_NOMOVE | SWP_NOOWNERZORDER | SWP_NOREDRAW | SWP_NOREPOSITION); } +gfx::Point DesktopHostWin::GetLocationOnNativeScreen() const { + RECT r; + GetClientRect(hwnd(), &r); + return gfx::Point(r.left, r.top); +} + + void DesktopHostWin::SetCursor(gfx::NativeCursor native_cursor) { // Custom web cursors are handled directly. if (native_cursor == kCursorCustom) diff --git a/ui/aura/desktop_host_win.h b/ui/aura/desktop_host_win.h index 9309d2b..cd9c136 100644 --- a/ui/aura/desktop_host_win.h +++ b/ui/aura/desktop_host_win.h @@ -27,6 +27,7 @@ class DesktopHostWin : public DesktopHost, public ui::WindowImpl { virtual void ToggleFullScreen() OVERRIDE; virtual gfx::Size GetSize() const OVERRIDE; virtual void SetSize(const gfx::Size& size) OVERRIDE; + virtual gfx::Point GetLocationOnNativeScreen() const OVERRIDE; virtual void SetCursor(gfx::NativeCursor cursor) OVERRIDE; virtual gfx::Point QueryMouseLocation() OVERRIDE; virtual void PostNativeEvent(const base::NativeEvent& native_event) OVERRIDE; diff --git a/ui/base/x/events_x.cc b/ui/base/x/events_x.cc index 966fec2..765aed3 100644 --- a/ui/base/x/events_x.cc +++ b/ui/base/x/events_x.cc @@ -6,12 +6,17 @@ #include <X11/Xlib.h> #include <X11/extensions/XInput2.h> +#include <string.h> #include "base/logging.h" #include "ui/base/keycodes/keyboard_code_conversion_x.h" #include "ui/base/touch/touch_factory.h" #include "ui/gfx/point.h" +#if !defined(TOOLKIT_USES_GTK) +#include "base/message_pump_x.h" +#endif + namespace { // Scroll amount for each wheelscroll event. 53 is also the value used for GTK+. @@ -356,12 +361,25 @@ float GetTouchForce(const base::NativeEvent& native_event) { } base::NativeEvent CreateNoopEvent() { - static XEvent* noop = new XEvent(); - noop->xclient.type = ClientMessage; - noop->xclient.display = NULL; - noop->xclient.window = None; - noop->xclient.message_type = 0; - noop->xclient.format = 0; + static XEvent* noop = NULL; + if (!noop) { + noop = new XEvent(); + memset(noop, 0, sizeof(XEvent)); + noop->xclient.type = ClientMessage; + noop->xclient.window = None; + noop->xclient.format = 8; + DCHECK(!noop->xclient.display); + } + // TODO(oshima): Remove ifdef once gtk is removed from views. +#if defined(TOOLKIT_USES_GTK) + NOTREACHED(); +#else + // Make sure we use atom from current xdisplay, which may + // change during the test. + noop->xclient.message_type = XInternAtom( + base::MessagePumpX::GetDefaultXDisplay(), + "noop", False); +#endif return noop; } @@ -572,6 +572,7 @@ 'gfx/render_text_linux.h', 'gfx/render_text_win.cc', 'gfx/render_text_win.h', + 'base/x/events_x.cc', ], }], ['OS=="android"', { diff --git a/ui/ui_unittests.gypi b/ui/ui_unittests.gypi index 5a4a8c4..cab407c 100644 --- a/ui/ui_unittests.gypi +++ b/ui/ui_unittests.gypi @@ -121,7 +121,7 @@ ], }, }], - ['OS == "linux"', { + ['OS == "linux" and toolkit_views==1', { 'sources': [ 'base/x/events_x_unittest.cc', ], |