summaryrefslogtreecommitdiffstats
path: root/ui/gfx
diff options
context:
space:
mode:
authorsadrul@chromium.org <sadrul@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-09-07 02:06:01 +0000
committersadrul@chromium.org <sadrul@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-09-07 02:06:01 +0000
commit4a6bef33b6897ceff27eee304afe1a6da5fee4ff (patch)
tree64c7e2cb508ccbe6a9e50be1da7c99b016ea5b52 /ui/gfx
parentccb824344b58ae4acbc0b7b30ebcba048a032836 (diff)
downloadchromium_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 'ui/gfx')
-rw-r--r--ui/gfx/gtk_util.cc80
-rw-r--r--ui/gfx/gtk_util.h44
-rw-r--r--ui/gfx/image/image.cc5
-rw-r--r--ui/gfx/linux_util.cc99
-rw-r--r--ui/gfx/linux_util.h66
-rw-r--r--ui/gfx/platform_font_gtk.cc2
-rw-r--r--ui/gfx/screen_aura.cc4
7 files changed, 179 insertions, 121 deletions
diff --git a/ui/gfx/gtk_util.cc b/ui/gfx/gtk_util.cc
index 45ae56a..aa336e8 100644
--- a/ui/gfx/gtk_util.cc
+++ b/ui/gfx/gtk_util.cc
@@ -55,34 +55,6 @@ void FreePixels(guchar* pixels, gpointer 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 gfx {
@@ -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) {
static GdkCursorCache impl;
return impl.GetCursorImpl(static_cast<GdkCursorType>(type));
}
-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;
+#if !defined(USE_WAYLAND) && !defined(USE_AURA)
+PangoContext* GetPangoContext() {
+ return gdk_pango_context_get();
}
+#endif
void InitRCStyles() {
static const char kRCText[] =
diff --git a/ui/gfx/gtk_util.h b/ui/gfx/gtk_util.h
index 62f9064..c519942 100644
--- a/ui/gfx/gtk_util.h
+++ b/ui/gfx/gtk_util.h
@@ -14,13 +14,12 @@
#include "base/memory/scoped_ptr.h"
#include "ui/base/ui_export.h"
+#include "ui/gfx/linux_util.h"
typedef struct _GdkPixbuf GdkPixbuf;
typedef struct _GdkRegion GdkRegion;
typedef struct _GdkCursor GdkCursor;
-typedef struct _PangoContext PangoContext;
-
class CommandLine;
class SkBitmap;
@@ -42,54 +41,13 @@ UI_EXPORT GdkPixbuf* GdkPixbufFromSkBitmap(const SkBitmap* bitmap);
UI_EXPORT void SubtractRectanglesFromRegion(GdkRegion* region,
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
// process. Caller must gdk_cursor_ref() it if they want to assume ownership.
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.
UI_EXPORT void InitRCStyles();
} // 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_
diff --git a/ui/gfx/image/image.cc b/ui/gfx/image/image.cc
index 9bd6842..7dc6e62 100644
--- a/ui/gfx/image/image.cc
+++ b/ui/gfx/image/image.cc
@@ -354,7 +354,10 @@ internal::ImageRep* Image::GetRepresentation(
if (default_rep->type() == Image::kImageRepSkia) {
internal::ImageRepSkia* skia_rep = default_rep->AsImageRepSkia();
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) {
GdkPixbuf* pixbuf = gfx::GdkPixbufFromSkBitmap(skia_rep->bitmap());
native_rep = new internal::ImageRepGdk(pixbuf);
diff --git a/ui/gfx/linux_util.cc b/ui/gfx/linux_util.cc
new file mode 100644
index 0000000..a189233
--- /dev/null
+++ b/ui/gfx/linux_util.cc
@@ -0,0 +1,99 @@
+// 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
diff --git a/ui/gfx/linux_util.h b/ui/gfx/linux_util.h
new file mode 100644
index 0000000..1c1f3ff
--- /dev/null
+++ b/ui/gfx/linux_util.h
@@ -0,0 +1,66 @@
+// 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_
diff --git a/ui/gfx/platform_font_gtk.cc b/ui/gfx/platform_font_gtk.cc
index e743638..05e43fe 100644
--- a/ui/gfx/platform_font_gtk.cc
+++ b/ui/gfx/platform_font_gtk.cc
@@ -17,7 +17,7 @@
#include "third_party/skia/include/core/SkPaint.h"
#include "ui/gfx/canvas_skia.h"
#include "ui/gfx/font.h"
-#include "ui/gfx/gtk_util.h"
+#include "ui/gfx/linux_util.h"
#if !defined(USE_WAYLAND)
#include <gdk/gdk.h>
diff --git a/ui/gfx/screen_aura.cc b/ui/gfx/screen_aura.cc
index 75b0afc..b47a832 100644
--- a/ui/gfx/screen_aura.cc
+++ b/ui/gfx/screen_aura.cc
@@ -4,7 +4,9 @@
#include "ui/gfx/screen.h"
+#if defined(OS_WIN)
#include <windows.h>
+#endif
#include "base/logging.h"
@@ -17,6 +19,8 @@ gfx::Point Screen::GetCursorScreenPoint() {
GetCursorPos(&pt);
return gfx::Point(pt);
#endif
+ NOTIMPLEMENTED();
+ return gfx::Point();
}
// static