Commit 4a6bef33 authored by sadrul@chromium.org's avatar sadrul@chromium.org

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
parent ccb82434
...@@ -9,7 +9,7 @@ ...@@ -9,7 +9,7 @@
'targets': [ 'targets': [
{ {
'target_name': 'aura', 'target_name': 'aura',
'type': 'static_library', 'type': '<(component)',
'dependencies': [ 'dependencies': [
'../base/base.gyp:base', '../base/base.gyp:base',
'../base/base.gyp:base_i18n', '../base/base.gyp:base_i18n',
...@@ -19,6 +19,9 @@ ...@@ -19,6 +19,9 @@
'../ui/ui.gyp:ui', '../ui/ui.gyp:ui',
'../ui/ui.gyp:ui_resources', '../ui/ui.gyp:ui_resources',
], ],
'defines': [
'AURA_IMPLEMENTATION',
],
'sources': [ 'sources': [
'desktop_host.h', 'desktop_host.h',
'desktop_host_linux.cc', 'desktop_host_linux.cc',
...@@ -29,6 +32,7 @@ ...@@ -29,6 +32,7 @@
'event.cc', 'event.cc',
'event.h', 'event.h',
'event_win.cc', 'event_win.cc',
'event_x.cc',
'focus_manager.cc', 'focus_manager.cc',
'focus_manager.h', 'focus_manager.h',
'hit_test.h', 'hit_test.h',
......
// 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
...@@ -16,6 +16,11 @@ ...@@ -16,6 +16,11 @@
#include "ui/gfx/canvas_skia.h" #include "ui/gfx/canvas_skia.h"
#include "ui/gfx/rect.h" #include "ui/gfx/rect.h"
#if defined(USE_X11)
#include "aura/hit_test.h"
#include "base/message_pump_x.h"
#endif
namespace { namespace {
// Trivial WindowDelegate implementation that draws a colored background. // Trivial WindowDelegate implementation that draws a colored background.
......
...@@ -7,6 +7,7 @@ ...@@ -7,6 +7,7 @@
#pragma once #pragma once
#include "aura/root_window.h" #include "aura/root_window.h"
#include "aura/aura_export.h"
#include "base/basictypes.h" #include "base/basictypes.h"
#include "base/memory/ref_counted.h" #include "base/memory/ref_counted.h"
#include "ui/gfx/native_widget_types.h" #include "ui/gfx/native_widget_types.h"
...@@ -25,7 +26,7 @@ class DesktopHost; ...@@ -25,7 +26,7 @@ class DesktopHost;
class MouseEvent; class MouseEvent;
// Desktop is responsible for hosting a set of windows. // Desktop is responsible for hosting a set of windows.
class Desktop { class AURA_EXPORT Desktop {
public: public:
Desktop(); Desktop();
~Desktop(); ~Desktop();
......
...@@ -5,6 +5,7 @@ ...@@ -5,6 +5,7 @@
#include "aura/desktop_host.h" #include "aura/desktop_host.h"
#include "aura/desktop.h" #include "aura/desktop.h"
#include "aura/event.h"
#include "base/message_loop.h" #include "base/message_loop.h"
#include "base/message_pump_x.h" #include "base/message_pump_x.h"
...@@ -28,6 +29,7 @@ class DesktopHostLinux : public DesktopHost { ...@@ -28,6 +29,7 @@ class DesktopHostLinux : public DesktopHost {
virtual gfx::AcceleratedWidget GetAcceleratedWidget() OVERRIDE; virtual gfx::AcceleratedWidget GetAcceleratedWidget() OVERRIDE;
virtual void Show() OVERRIDE; virtual void Show() OVERRIDE;
virtual gfx::Size GetSize() OVERRIDE; virtual gfx::Size GetSize() OVERRIDE;
virtual void SetSize(const gfx::Size& size) OVERRIDE;
Desktop* desktop_; Desktop* desktop_;
...@@ -68,13 +70,27 @@ DesktopHostLinux::~DesktopHostLinux() { ...@@ -68,13 +70,27 @@ DesktopHostLinux::~DesktopHostLinux() {
base::MessagePumpDispatcher::DispatchStatus DesktopHostLinux::Dispatch( base::MessagePumpDispatcher::DispatchStatus DesktopHostLinux::Dispatch(
XEvent* xev) { XEvent* xev) {
// TODO(sad): Create events and dispatch to the appropriate window. bool handled = false;
switch (xev->type) { switch (xev->type) {
case Expose: case Expose:
desktop_->Draw(); desktop_->Draw();
handled = true;
break; 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) { void DesktopHostLinux::SetDesktop(Desktop* desktop) {
...@@ -92,6 +108,10 @@ gfx::Size DesktopHostLinux::GetSize() { ...@@ -92,6 +108,10 @@ gfx::Size DesktopHostLinux::GetSize() {
return bounds_.size(); return bounds_.size();
} }
void DesktopHostLinux::SetSize(const gfx::Size& size) {
XResizeWindow(xdisplay_, xwindow_, size.width(), size.height());
}
} // namespace } // namespace
// static // static
......
...@@ -12,12 +12,15 @@ ...@@ -12,12 +12,15 @@
#include "ui/base/keycodes/keyboard_codes.h" #include "ui/base/keycodes/keyboard_codes.h"
#include "ui/gfx/point.h" #include "ui/gfx/point.h"
#if defined(USE_X11)
typedef union _XEvent XEvent;
#endif
namespace aura { namespace aura {
#if defined(OS_WIN) #if defined(OS_WIN)
typedef MSG NativeEvent; typedef MSG NativeEvent;
#elif defined(USE_X11) #elif defined(USE_X11)
typedef union _XEvent XEvent;
typedef XEvent* NativeEvent; typedef XEvent* NativeEvent;
#endif #endif
......
// 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
...@@ -8,6 +8,7 @@ ...@@ -8,6 +8,7 @@
#include <vector> #include <vector>
#include "aura/aura_export.h"
#include "base/basictypes.h" #include "base/basictypes.h"
#include "base/memory/scoped_ptr.h" #include "base/memory/scoped_ptr.h"
#include "ui/gfx/compositor/layer_delegate.h" #include "ui/gfx/compositor/layer_delegate.h"
...@@ -35,7 +36,7 @@ class FocusManager; ...@@ -35,7 +36,7 @@ class FocusManager;
// Aura window implementation. Interesting events are sent to the // Aura window implementation. Interesting events are sent to the
// WindowDelegate. // WindowDelegate.
// TODO(beng): resolve ownership. // TODO(beng): resolve ownership.
class Window : public ui::LayerDelegate { class AURA_EXPORT Window : public ui::LayerDelegate {
public: public:
enum Visibility { enum Visibility {
// Don't display the window onscreen and don't let it receive mouse // Don't display the window onscreen and don't let it receive mouse
......
...@@ -383,7 +383,7 @@ ...@@ -383,7 +383,7 @@
'message_pump_x.cc', 'message_pump_x.cc',
], ],
}], }],
[ 'touchui==0', { [ 'touchui==0 and use_aura==0', {
'sources!' : [ 'message_pump_x.cc', ], 'sources!' : [ 'message_pump_x.cc', ],
}, { }, {
'sources!' : [ 'message_pump_gtk.cc', ], 'sources!' : [ 'message_pump_gtk.cc', ],
......
...@@ -151,7 +151,7 @@ MessageLoop::MessageLoop(Type type) ...@@ -151,7 +151,7 @@ MessageLoop::MessageLoop(Type type)
#elif defined(USE_WAYLAND) #elif defined(USE_WAYLAND)
#define MESSAGE_PUMP_UI new base::MessagePumpWayland() #define MESSAGE_PUMP_UI new base::MessagePumpWayland()
#define MESSAGE_PUMP_IO new base::MessagePumpLibevent() #define MESSAGE_PUMP_IO new base::MessagePumpLibevent()
#elif defined(TOUCH_UI) #elif defined(TOUCH_UI) || defined(USE_AURA)
#define MESSAGE_PUMP_UI new base::MessagePumpX() #define MESSAGE_PUMP_UI new base::MessagePumpX()
#define MESSAGE_PUMP_IO new base::MessagePumpLibevent() #define MESSAGE_PUMP_IO new base::MessagePumpLibevent()
#elif defined(OS_NACL) #elif defined(OS_NACL)
......
...@@ -31,7 +31,7 @@ ...@@ -31,7 +31,7 @@
#if defined(USE_WAYLAND) #if defined(USE_WAYLAND)
#include "base/message_pump_wayland.h" #include "base/message_pump_wayland.h"
#elif defined(TOUCH_UI) #elif defined(TOUCH_UI) || defined(USE_AURA)
#include "base/message_pump_x.h" #include "base/message_pump_x.h"
#else #else
#include "base/message_pump_gtk.h" #include "base/message_pump_gtk.h"
......
...@@ -55,34 +55,6 @@ void FreePixels(guchar* pixels, gpointer data) { ...@@ -55,34 +55,6 @@ void FreePixels(guchar* pixels, gpointer data) {
free(data); free(data);
} }
// Common implementation of ConvertAcceleratorsFromWindowsStyle() and
// RemoveWindowsStyleAccelerators().
// Replaces all ampersands (as used in our grd files to indicate mnemonics)
// to |target|. Similarly any underscores get replaced with two underscores as
// is needed by GTK.
std::string ConvertAmperstandsTo(const std::string& label,
const std::string& target) {
std::string ret;
ret.reserve(label.length() * 2);
for (size_t i = 0; i < label.length(); ++i) {
if ('_' == label[i]) {
ret.push_back('_');
ret.push_back('_');
} else if ('&' == label[i]) {
if (i + 1 < label.length() && '&' == label[i + 1]) {
ret.push_back('&');
++i;
} else {
ret.append(target);
}
} else {
ret.push_back(label[i]);
}
}
return ret;
}
} // namespace } // namespace
namespace gfx { namespace gfx {
...@@ -164,60 +136,16 @@ void SubtractRectanglesFromRegion(GdkRegion* region, ...@@ -164,60 +136,16 @@ void SubtractRectanglesFromRegion(GdkRegion* region,
} }
} }
PangoContext* GetPangoContext() {
#if defined(USE_WAYLAND)
PangoFontMap* font_map = pango_cairo_font_map_get_default();
PangoContext* default_context = pango_font_map_create_context(font_map);
#else
PangoContext* default_context = gdk_pango_context_get();
#endif
return default_context;
}
double GetPangoResolution() {
static double resolution;
static bool determined_resolution = false;
if (!determined_resolution) {
determined_resolution = true;
PangoContext* default_context = GetPangoContext();
resolution = pango_cairo_context_get_resolution(default_context);
g_object_unref(default_context);
}
return resolution;
}
GdkCursor* GetCursor(int type) { GdkCursor* GetCursor(int type) {
static GdkCursorCache impl; static GdkCursorCache impl;
return impl.GetCursorImpl(static_cast<GdkCursorType>(type)); return impl.GetCursorImpl(static_cast<GdkCursorType>(type));
} }
std::string ConvertAcceleratorsFromWindowsStyle(const std::string& label) { #if !defined(USE_WAYLAND) && !defined(USE_AURA)
return ConvertAmperstandsTo(label, "_"); PangoContext* GetPangoContext() {
} return gdk_pango_context_get();
std::string RemoveWindowsStyleAccelerators(const std::string& label) {
return ConvertAmperstandsTo(label, "");
}
uint8_t* BGRAToRGBA(const uint8_t* pixels, int width, int height, int stride) {
if (stride == 0)
stride = width * 4;
uint8_t* new_pixels = static_cast<uint8_t*>(malloc(height * stride));
// We have to copy the pixels and swap from BGRA to RGBA.
for (int i = 0; i < height; ++i) {
for (int j = 0; j < width; ++j) {
int idx = i * stride + j * 4;
new_pixels[idx] = pixels[idx + 2];
new_pixels[idx + 1] = pixels[idx + 1];
new_pixels[idx + 2] = pixels[idx];
new_pixels[idx + 3] = pixels[idx + 3];
}
}
return new_pixels;
} }
#endif
void InitRCStyles() { void InitRCStyles() {
static const char kRCText[] = static const char kRCText[] =
......
...@@ -14,13 +14,12 @@ ...@@ -14,13 +14,12 @@
#include "base/memory/scoped_ptr.h" #include "base/memory/scoped_ptr.h"
#include "ui/base/ui_export.h" #include "ui/base/ui_export.h"
#include "ui/gfx/linux_util.h"
typedef struct _GdkPixbuf GdkPixbuf; typedef struct _GdkPixbuf GdkPixbuf;
typedef struct _GdkRegion GdkRegion; typedef struct _GdkRegion GdkRegion;
typedef struct _GdkCursor GdkCursor; typedef struct _GdkCursor GdkCursor;
typedef struct _PangoContext PangoContext;
class CommandLine; class CommandLine;
class SkBitmap; class SkBitmap;
...@@ -42,54 +41,13 @@ UI_EXPORT GdkPixbuf* GdkPixbufFromSkBitmap(const SkBitmap* bitmap); ...@@ -42,54 +41,13 @@ UI_EXPORT GdkPixbuf* GdkPixbufFromSkBitmap(const SkBitmap* bitmap);
UI_EXPORT void SubtractRectanglesFromRegion(GdkRegion* region, UI_EXPORT void SubtractRectanglesFromRegion(GdkRegion* region,
const std::vector<Rect>& cutouts); const std::vector<Rect>& cutouts);
// Creates and returns a PangoContext. The caller owns the context.
PangoContext* GetPangoContext();
// Returns the resolution (DPI) used by pango. A negative values means the
// resolution hasn't been set.
double GetPangoResolution();
// Returns a static instance of a GdkCursor* object, sharable across the // Returns a static instance of a GdkCursor* object, sharable across the
// process. Caller must gdk_cursor_ref() it if they want to assume ownership. // process. Caller must gdk_cursor_ref() it if they want to assume ownership.
UI_EXPORT GdkCursor* GetCursor(int type); UI_EXPORT GdkCursor* GetCursor(int type);
// Change windows accelerator style to GTK style. (GTK uses _ for
// accelerators. Windows uses & with && as an escape for &.)
UI_EXPORT std::string ConvertAcceleratorsFromWindowsStyle(
const std::string& label);
// Removes the "&" accelerators from a Windows label.
UI_EXPORT std::string RemoveWindowsStyleAccelerators(const std::string& label);
// Makes a copy of |pixels| with the ordering changed from BGRA to RGBA.
// The caller is responsible for free()ing the data. If |stride| is 0, it's
// assumed to be 4 * |width|.
uint8_t* BGRAToRGBA(const uint8_t* pixels,
int width,
int height,
int stride);
// Initialize some GTK settings so that our dialogs are consistent. // Initialize some GTK settings so that our dialogs are consistent.
UI_EXPORT void InitRCStyles(); UI_EXPORT void InitRCStyles();
} // namespace gfx } // namespace gfx
// It's not legal C++ to have a templatized typedefs, so we wrap it in a
// struct. When using this, you need to include ::Type. E.g.,
// ScopedGObject<GdkPixbufLoader>::Type loader(gdk_pixbuf_loader_new());
template<class T>
struct ScopedGObject {
// A helper class that will g_object_unref |p| when it goes out of scope.
// This never adds a ref, it only unrefs.
template<class U>
struct GObjectUnrefer {
void operator()(U* ptr) const {
if (ptr)
g_object_unref(ptr);
}
};
typedef scoped_ptr_malloc<T, GObjectUnrefer<T> > Type;
};
#endif // UI_GFX_GTK_UTIL_H_ #endif // UI_GFX_GTK_UTIL_H_
...@@ -354,7 +354,10 @@ internal::ImageRep* Image::GetRepresentation( ...@@ -354,7 +354,10 @@ internal::ImageRep* Image::GetRepresentation(
if (default_rep->type() == Image::kImageRepSkia) { if (default_rep->type() == Image::kImageRepSkia) {
internal::ImageRepSkia* skia_rep = default_rep->AsImageRepSkia(); internal::ImageRepSkia* skia_rep = default_rep->AsImageRepSkia();
internal::ImageRep* native_rep = NULL; internal::ImageRep* native_rep = NULL;
#if defined(TOOLKIT_USES_GTK) #if defined(USE_AURA)
skia_rep = NULL;
NOTIMPLEMENTED();
#elif defined(TOOLKIT_USES_GTK)
if (rep_type == Image::kImageRepGdk) { if (rep_type == Image::kImageRepGdk) {
GdkPixbuf* pixbuf = gfx::GdkPixbufFromSkBitmap(skia_rep->bitmap()); GdkPixbuf* pixbuf = gfx::GdkPixbufFromSkBitmap(skia_rep->bitmap());
native_rep = new internal::ImageRepGdk(pixbuf); native_rep = new internal::ImageRepGdk(pixbuf);
......
// 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 "ui/gfx/linux_util.h"
#include <pango/pango.h>
#include <pango/pangocairo.h>
#include <stdlib.h>
#include "base/basictypes.h"
#include "base/command_line.h"
#include "base/linux_util.h"
#include "third_party/skia/include/core/SkBitmap.h"
#include "third_party/skia/include/core/SkUnPreMultiply.h"
#include "ui/gfx/rect.h"
namespace {
// Common implementation of ConvertAcceleratorsFromWindowsStyle() and
// RemoveWindowsStyleAccelerators().
// Replaces all ampersands (as used in our grd files to indicate mnemonics)
// to |target|. Similarly any underscores get replaced with two underscores as
// is needed by GTK.
std::string ConvertAmperstandsTo(const std::string& label,
const std::string& target) {
std::string ret;
ret.reserve(label.length() * 2);
for (size_t i = 0; i < label.length(); ++i) {
if ('_' == label[i]) {
ret.push_back('_');
ret.push_back('_');
} else if ('&' == label[i]) {
if (i + 1 < label.length() && '&' == label[i + 1]) {
ret.push_back('&');
++i;
} else {
ret.append(target);
}
} else {
ret.push_back(label[i]);
}
}
return ret;
}
} // namespace
namespace gfx {
#if defined(USE_WAYLAND) || defined(USE_AURA)
PangoContext* GetPangoContext() {
PangoFontMap* font_map = pango_cairo_font_map_get_default();
return pango_font_map_create_context(font_map);
}
#endif
double GetPangoResolution() {
static double resolution;
static bool determined_resolution = false;
if (!determined_resolution) {
determined_resolution = true;
PangoContext* default_context = GetPangoContext();
resolution = pango_cairo_context_get_resolution(default_context);
g_object_unref(default_context);
}
return resolution;
}
std::string ConvertAcceleratorsFromWindowsStyle(const std::string& label) {
return ConvertAmperstandsTo(label, "_");
}
std::string RemoveWindowsStyleAccelerators(const std::string& label) {
return ConvertAmperstandsTo(label, "");
}
uint8_t* BGRAToRGBA(const uint8_t* pixels, int width, int height, int stride) {
if (stride == 0)
stride = width * 4;
uint8_t* new_pixels = static_cast<uint8_t*>(malloc(height * stride));
// We have to copy the pixels and swap from BGRA to RGBA.
for (int i = 0; i < height; ++i) {
for (int j = 0; j < width; ++j) {
int idx = i * stride + j * 4;
new_pixels[idx] = pixels[idx + 2];
new_pixels[idx + 1] = pixels[idx + 1];
new_pixels[idx + 2] = pixels[idx];
new_pixels[idx + 3] = pixels[idx + 3];
}
}
return new_pixels;
}
} // namespace gfx
// 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 UI_GFX_LINUX_UTIL_H_
#define UI_GFX_LINUX_UTIL_H_
#pragma once
#include <glib-object.h>
#include <stdint.h>
#include <string>
#include <vector>
#include "base/memory/scoped_ptr.h"
#include "ui/base/ui_export.h"
typedef struct _PangoContext PangoContext;
class SkBitmap;
namespace gfx {
class Rect;
// Creates and returns a PangoContext. The caller owns the context.
PangoContext* GetPangoContext();
// Returns the resolution (DPI) used by pango. A negative values means the
// resolution hasn't been set.
double GetPangoResolution();
// Change windows accelerator style to GTK style. (GTK uses _ for
// accelerators. Windows uses & with && as an escape for &.)
UI_EXPORT std::string ConvertAcceleratorsFromWindowsStyle(
const std::string& label);
// Removes the "&" accelerators from a Windows label.
UI_EXPORT std::string RemoveWindowsStyleAccelerators(const std::string& label);
// Makes a copy of |pixels| with the ordering changed from BGRA to RGBA.
// The caller is responsible for free()ing the data. If |stride| is 0, it's
// assumed to be 4 * |width|.
uint8_t* BGRAToRGBA(const uint8_t* pixels, int width, int height, int stride);
} // namespace gfx
// It's not legal C++ to have a templatized typedefs, so we wrap it in a
// struct. When using this, you need to include ::Type. E.g.,
// ScopedGObject<GdkPixbufLoader>::Type loader(gdk_pixbuf_loader_new());
template<class T>
struct ScopedGObject {
// A helper class that will g_object_unref |p| when it goes out of scope.
// This never adds a ref, it only unrefs.
template<class U>
struct GObjectUnrefer {
void operator()(U* ptr) const {
if (ptr)
g_object_unref(ptr);
}
};
typedef scoped_ptr_malloc<T, GObjectUnrefer<T> > Type;
};
#endif // UI_GFX_LINUX_UTIL_H_
...@@ -17,7 +17,7 @@ ...@@ -17,7 +17,7 @@
#include "third_party/skia/include/core/SkPaint.h" #include "third_party/skia/include/core/SkPaint.h"
#include "ui/gfx/canvas_skia.h" #include "ui/gfx/canvas_skia.h"
#include "ui/gfx/font.h" #include "ui/gfx/font.h"
#include "ui/gfx/gtk_util.h" #include "ui/gfx/linux_util.h"
#if !defined(USE_WAYLAND) #if !defined(USE_WAYLAND)
#include <gdk/gdk.h> #include <gdk/gdk.h>
......
...@@ -4,7 +4,9 @@ ...@@ -4,7 +4,9 @@
#include "ui/gfx/screen.h" #include "ui/gfx/screen.h"
#if defined(OS_WIN)
#include <windows.h> #include <windows.h>
#endif
#include "base/logging.h" #include "base/logging.h"
...@@ -17,6 +19,8 @@ gfx::Point Screen::GetCursorScreenPoint() { ...@@ -17,6 +19,8 @@ gfx::Point Screen::GetCursorScreenPoint() {
GetCursorPos(&pt); GetCursorPos(&pt);
return gfx::Point(pt); return gfx::Point(pt);
#endif #endif
NOTIMPLEMENTED();
return gfx::Point();
} }
// static // static
......
...@@ -294,9 +294,11 @@ ...@@ -294,9 +294,11 @@
'conditions': [ 'conditions': [
['use_aura==1', { ['use_aura==1', {
'sources/': [ 'sources/': [
['exclude', 'gfx/gtk_'],
['exclude', 'gfx/screen_gtk.cc'],
['exclude', 'gfx/screen_win.cc'], ['exclude', 'gfx/screen_win.cc'],
['exclude', 'base/win/mouse_wheel_util.cc'], ['exclude', 'base/win/mouse_wheel_util.cc'],
['exclude', 'base/win/mouse_wheel_util.h'], ['exclude', 'base/win/mouse_wheel_util.h'],
], ],
}], }],
['toolkit_uses_gtk == 1', { ['toolkit_uses_gtk == 1', {
...@@ -315,6 +317,8 @@ ...@@ -315,6 +317,8 @@
'gfx/gtk_preserve_window.h', 'gfx/gtk_preserve_window.h',
'gfx/gtk_util.cc', 'gfx/gtk_util.cc',
'gfx/gtk_util.h', 'gfx/gtk_util.h',
'gfx/linux_util.cc',
'gfx/linux_util.h',
'gfx/native_theme_linux.cc', 'gfx/native_theme_linux.cc',
'gfx/native_theme_linux.h', 'gfx/native_theme_linux.h',
], ],
...@@ -360,6 +364,8 @@ ...@@ -360,6 +364,8 @@
['include', 'gfx/path_gtk.cc'], ['include', 'gfx/path_gtk.cc'],
['include', 'gfx/platform_font_gtk.cc'], ['include', 'gfx/platform_font_gtk.cc'],
['include', 'gfx/platform_font_gtk.h'], ['include', 'gfx/platform_font_gtk.h'],
['include', 'gfx/linux_util.cc'],
['include', 'gfx/linux_util.h'],
], ],
}], }],
['OS=="win"', { ['OS=="win"', {
......
...@@ -4,7 +4,9 @@ ...@@ -4,7 +4,9 @@
#include "views/metrics.h" #include "views/metrics.h"
#if defined(OS_WIN)
#include <windows.h> #include <windows.h>
#endif
namespace views { namespace views {
...@@ -24,7 +26,7 @@ int GetMenuShowDelay() { ...@@ -24,7 +26,7 @@ int GetMenuShowDelay() {
return delay; return delay;
#else #else
return 0; return 0;
#endif; #endif
} }
} // namespace views } // namespace views
...@@ -26,4 +26,4 @@ ...@@ -26,4 +26,4 @@
#define VIEWS_EXPORT #define VIEWS_EXPORT
#endif #endif
#endif // UI_UI_EXPORT_H_ #endif // VIEWS_VIEWS_EXPORT_H_
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment