diff options
author | sadrul@chromium.org <sadrul@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-09-07 02:06:01 +0000 |
---|---|---|
committer | sadrul@chromium.org <sadrul@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-09-07 02:06:01 +0000 |
commit | 4a6bef33b6897ceff27eee304afe1a6da5fee4ff (patch) | |
tree | 64c7e2cb508ccbe6a9e50be1da7c99b016ea5b52 /aura | |
parent | ccb824344b58ae4acbc0b7b30ebcba048a032836 (diff) | |
download | chromium_src-4a6bef33b6897ceff27eee304afe1a6da5fee4ff.zip chromium_src-4a6bef33b6897ceff27eee304afe1a6da5fee4ff.tar.gz chromium_src-4a6bef33b6897ceff27eee304afe1a6da5fee4ff.tar.bz2 |
aura: A few changes to have aura_demo compile and run on linux.
* Make 'aura' a component, and export Desktop and Window.
* Events (Key and Mouse) from X Events.
* Rip non-gtk bits out of gfx/gtk_util into gfx/linux_util
BUG=93934,93933
TEST=none
Review URL: http://codereview.chromium.org/7833016
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@99898 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'aura')
-rw-r--r-- | aura/aura.gyp | 6 | ||||
-rw-r--r-- | aura/aura_export.h | 30 | ||||
-rw-r--r-- | aura/demo/demo_main.cc | 5 | ||||
-rw-r--r-- | aura/desktop.h | 3 | ||||
-rw-r--r-- | aura/desktop_host_linux.cc | 24 | ||||
-rw-r--r-- | aura/event.h | 5 | ||||
-rw-r--r-- | aura/event_x.cc | 193 | ||||
-rw-r--r-- | aura/window.h | 3 |
8 files changed, 263 insertions, 6 deletions
diff --git a/aura/aura.gyp b/aura/aura.gyp index de8586f..6b22ee4 100644 --- a/aura/aura.gyp +++ b/aura/aura.gyp @@ -9,7 +9,7 @@ 'targets': [ { 'target_name': 'aura', - 'type': 'static_library', + 'type': '<(component)', 'dependencies': [ '../base/base.gyp:base', '../base/base.gyp:base_i18n', @@ -19,6 +19,9 @@ '../ui/ui.gyp:ui', '../ui/ui.gyp:ui_resources', ], + 'defines': [ + 'AURA_IMPLEMENTATION', + ], 'sources': [ 'desktop_host.h', 'desktop_host_linux.cc', @@ -29,6 +32,7 @@ 'event.cc', 'event.h', 'event_win.cc', + 'event_x.cc', 'focus_manager.cc', 'focus_manager.h', 'hit_test.h', diff --git a/aura/aura_export.h b/aura/aura_export.h new file mode 100644 index 0000000..1ebab90 --- /dev/null +++ b/aura/aura_export.h @@ -0,0 +1,30 @@ +// Copyright (c) 2011 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#ifndef AURA_AURA_EXPORT_H +#define AURA_AURA_EXPORT_H +#pragma once + +// Defines AURA_EXPORT so that functionality implemented by the aura module +// can be exported to consumers. + +#if defined(COMPONENT_BUILD) +#if defined(WIN32) + +#if defined(AURA_IMPLEMENTATION) +#define AURA_EXPORT __declspec(dllexport) +#else +#define AURA_EXPORT __declspec(dllimport) +#endif // defined(AURA_IMPLEMENTATION) + +#else // defined(WIN32) +#define AURA_EXPORT __attribute__((visibility("default"))) +#endif + +#else // defined(COMPONENT_BUILD) +#define AURA_EXPORT +#endif + +#endif // AURA_AURA_EXPORT_H + diff --git a/aura/demo/demo_main.cc b/aura/demo/demo_main.cc index 7b87559..85a39cc 100644 --- a/aura/demo/demo_main.cc +++ b/aura/demo/demo_main.cc @@ -16,6 +16,11 @@ #include "ui/gfx/canvas_skia.h" #include "ui/gfx/rect.h" +#if defined(USE_X11) +#include "aura/hit_test.h" +#include "base/message_pump_x.h" +#endif + namespace { // Trivial WindowDelegate implementation that draws a colored background. diff --git a/aura/desktop.h b/aura/desktop.h index 88f02f3c..3d292af 100644 --- a/aura/desktop.h +++ b/aura/desktop.h @@ -7,6 +7,7 @@ #pragma once #include "aura/root_window.h" +#include "aura/aura_export.h" #include "base/basictypes.h" #include "base/memory/ref_counted.h" #include "ui/gfx/native_widget_types.h" @@ -25,7 +26,7 @@ class DesktopHost; class MouseEvent; // Desktop is responsible for hosting a set of windows. -class Desktop { +class AURA_EXPORT Desktop { public: Desktop(); ~Desktop(); diff --git a/aura/desktop_host_linux.cc b/aura/desktop_host_linux.cc index 746be03..723e571 100644 --- a/aura/desktop_host_linux.cc +++ b/aura/desktop_host_linux.cc @@ -5,6 +5,7 @@ #include "aura/desktop_host.h" #include "aura/desktop.h" +#include "aura/event.h" #include "base/message_loop.h" #include "base/message_pump_x.h" @@ -28,6 +29,7 @@ class DesktopHostLinux : public DesktopHost { virtual gfx::AcceleratedWidget GetAcceleratedWidget() OVERRIDE; virtual void Show() OVERRIDE; virtual gfx::Size GetSize() OVERRIDE; + virtual void SetSize(const gfx::Size& size) OVERRIDE; Desktop* desktop_; @@ -68,13 +70,27 @@ DesktopHostLinux::~DesktopHostLinux() { base::MessagePumpDispatcher::DispatchStatus DesktopHostLinux::Dispatch( XEvent* xev) { - // TODO(sad): Create events and dispatch to the appropriate window. + bool handled = false; switch (xev->type) { case Expose: desktop_->Draw(); + handled = true; break; + case KeyPress: + case KeyRelease: { + KeyEvent keyev(xev); + handled = desktop_->OnKeyEvent(keyev); + break; + } + case ButtonPress: + case ButtonRelease: + case MotionNotify: { + MouseEvent mouseev(xev); + handled = desktop_->OnMouseEvent(mouseev); + break; + } } - return EVENT_IGNORED; + return handled ? EVENT_PROCESSED : EVENT_IGNORED; } void DesktopHostLinux::SetDesktop(Desktop* desktop) { @@ -92,6 +108,10 @@ gfx::Size DesktopHostLinux::GetSize() { return bounds_.size(); } +void DesktopHostLinux::SetSize(const gfx::Size& size) { + XResizeWindow(xdisplay_, xwindow_, size.width(), size.height()); +} + } // namespace // static diff --git a/aura/event.h b/aura/event.h index 27a9843..884f9b0 100644 --- a/aura/event.h +++ b/aura/event.h @@ -12,12 +12,15 @@ #include "ui/base/keycodes/keyboard_codes.h" #include "ui/gfx/point.h" +#if defined(USE_X11) +typedef union _XEvent XEvent; +#endif + namespace aura { #if defined(OS_WIN) typedef MSG NativeEvent; #elif defined(USE_X11) -typedef union _XEvent XEvent; typedef XEvent* NativeEvent; #endif diff --git a/aura/event_x.cc b/aura/event_x.cc new file mode 100644 index 0000000..793be36 --- /dev/null +++ b/aura/event_x.cc @@ -0,0 +1,193 @@ +// Copyright (c) 2011 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#include "aura/event.h" + +#include <X11/Xlib.h> +#include <X11/extensions/XInput2.h> + +#include "base/logging.h" +#include "ui/base/keycodes/keyboard_code_conversion_x.h" + +namespace aura { + +namespace { + +int GetEventFlagsFromXState(unsigned int state) { + int flags = 0; + if (state & ControlMask) + flags |= ui::EF_CONTROL_DOWN; + if (state & ShiftMask) + flags |= ui::EF_SHIFT_DOWN; + if (state & Mod1Mask) + flags |= ui::EF_ALT_DOWN; + if (state & LockMask) + flags |= ui::EF_CAPS_LOCK_DOWN; + if (state & Button1Mask) + flags |= ui::EF_LEFT_BUTTON_DOWN; + if (state & Button2Mask) + flags |= ui::EF_MIDDLE_BUTTON_DOWN; + if (state & Button3Mask) + flags |= ui::EF_RIGHT_BUTTON_DOWN; + + return flags; +} + +// Get the event flag for the button in XButtonEvent. During a ButtonPress +// event, |state| in XButtonEvent does not include the button that has just been +// pressed. Instead |state| contains flags for the buttons (if any) that had +// already been pressed before the current button, and |button| stores the most +// current pressed button. So, if you press down left mouse button, and while +// pressing it down, press down the right mouse button, then for the latter +// event, |state| would have Button1Mask set but not Button3Mask, and |button| +// would be 3. +int GetEventFlagsForButton(int button) { + switch (button) { + case 1: + return ui::EF_LEFT_BUTTON_DOWN; + case 2: + return ui::EF_MIDDLE_BUTTON_DOWN; + case 3: + return ui::EF_RIGHT_BUTTON_DOWN; + } + + DLOG(WARNING) << "Unexpected button (" << button << ") received."; + return 0; +} + +int GetButtonMaskForX2Event(XIDeviceEvent* xievent) { + int buttonflags = 0; + + for (int i = 0; i < 8 * xievent->buttons.mask_len; i++) { + if (XIMaskIsSet(xievent->buttons.mask, i)) { + buttonflags |= GetEventFlagsForButton(i); + } + } + + return buttonflags; +} + +ui::EventType EventTypeFromNative(NativeEvent native_event) { + switch (native_event->type) { + case KeyPress: + return ui::ET_KEY_PRESSED; + case KeyRelease: + return ui::ET_KEY_RELEASED; + case ButtonPress: + if (native_event->xbutton.button == 4 || + native_event->xbutton.button == 5) + return ui::ET_MOUSEWHEEL; + return ui::ET_MOUSE_PRESSED; + case ButtonRelease: + if (native_event->xbutton.button == 4 || + native_event->xbutton.button == 5) + return ui::ET_MOUSEWHEEL; + return ui::ET_MOUSE_RELEASED; + case MotionNotify: + if (native_event->xmotion.state & + (Button1Mask | Button2Mask | Button3Mask)) + return ui::ET_MOUSE_DRAGGED; + return ui::ET_MOUSE_MOVED; + case GenericEvent: { + XIDeviceEvent* xievent = + static_cast<XIDeviceEvent*>(native_event->xcookie.data); + // TODO(sad): Determine if sourceid is a touch device. + switch (xievent->evtype) { + case XI_ButtonPress: + return (xievent->detail == 4 || xievent->detail == 5) ? + ui::ET_MOUSEWHEEL : ui::ET_MOUSE_PRESSED; + case XI_ButtonRelease: + return (xievent->detail == 4 || xievent->detail == 5) ? + ui::ET_MOUSEWHEEL : ui::ET_MOUSE_RELEASED; + case XI_Motion: + return GetButtonMaskForX2Event(xievent) ? ui::ET_MOUSE_DRAGGED : + ui::ET_MOUSE_MOVED; + } + } + default: + NOTREACHED(); + break; + } + return ui::ET_UNKNOWN; +} + +gfx::Point GetEventLocation(XEvent* xev) { + switch (xev->type) { + case ButtonPress: + case ButtonRelease: + return gfx::Point(xev->xbutton.x, xev->xbutton.y); + + case MotionNotify: + return gfx::Point(xev->xmotion.x, xev->xmotion.y); + + case GenericEvent: { + XIDeviceEvent* xievent = + static_cast<XIDeviceEvent*>(xev->xcookie.data); + return gfx::Point(static_cast<int>(xievent->event_x), + static_cast<int>(xievent->event_y)); + } + } + + return gfx::Point(); +} + +int GetLocatedEventFlags(XEvent* xev) { + switch (xev->type) { + case ButtonPress: + case ButtonRelease: + return GetEventFlagsFromXState(xev->xbutton.state) | + GetEventFlagsForButton(xev->xbutton.button); + + case MotionNotify: + return GetEventFlagsFromXState(xev->xmotion.state); + + case GenericEvent: { + XIDeviceEvent* xievent = static_cast<XIDeviceEvent*>(xev->xcookie.data); + bool touch = false; // TODO(sad): Determine if xievent->sourceid is a + // touch device. + switch (xievent->evtype) { + case XI_ButtonPress: + case XI_ButtonRelease: + return GetButtonMaskForX2Event(xievent) | + GetEventFlagsFromXState(xievent->mods.effective) | + (touch ? 0 : GetEventFlagsForButton(xievent->detail)); + + case XI_Motion: + return GetButtonMaskForX2Event(xievent) | + GetEventFlagsFromXState(xievent->mods.effective); + } + } + } + + return 0; +} + +} // namespace + +void Event::Init() { + memset(&native_event_, 0, sizeof(native_event_)); +} + +void Event::InitWithNativeEvent(NativeEvent native_event) { + native_event_ = native_event; +} + +LocatedEvent::LocatedEvent(NativeEvent native_event) + : Event(native_event, EventTypeFromNative(native_event), + GetLocatedEventFlags(native_event)), + location_(GetEventLocation(native_event)) { +} + +MouseEvent::MouseEvent(NativeEvent native_event) + : LocatedEvent(native_event) { +} + +KeyEvent::KeyEvent(NativeEvent native_event) + : Event(native_event, + EventTypeFromNative(native_event), + GetEventFlagsFromXState(native_event->xbutton.state)), + key_code_(ui::KeyboardCodeFromXKeyEvent(native_event)) { +} + +} // namespace aura diff --git a/aura/window.h b/aura/window.h index 5ebfb1a..d5d6e65 100644 --- a/aura/window.h +++ b/aura/window.h @@ -8,6 +8,7 @@ #include <vector> +#include "aura/aura_export.h" #include "base/basictypes.h" #include "base/memory/scoped_ptr.h" #include "ui/gfx/compositor/layer_delegate.h" @@ -35,7 +36,7 @@ class FocusManager; // Aura window implementation. Interesting events are sent to the // WindowDelegate. // TODO(beng): resolve ownership. -class Window : public ui::LayerDelegate { +class AURA_EXPORT Window : public ui::LayerDelegate { public: enum Visibility { // Don't display the window onscreen and don't let it receive mouse |