summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authoragl@chromium.org <agl@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2008-10-29 18:07:56 +0000
committeragl@chromium.org <agl@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2008-10-29 18:07:56 +0000
commitc09b65412f771fecbbe24c6f7e6232c9edbe5022 (patch)
tree7bebfa16d1b1fb280b952d122c1bccada8c916bd
parent87221b1b14635992cbdeb95b6680fcacf626dfb4 (diff)
downloadchromium_src-c09b65412f771fecbbe24c6f7e6232c9edbe5022.zip
chromium_src-c09b65412f771fecbbe24c6f7e6232c9edbe5022.tar.gz
chromium_src-c09b65412f771fecbbe24c6f7e6232c9edbe5022.tar.bz2
Start writing the GTK code for test_shell.
Review URL: http://codereview.chromium.org/8000 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@4136 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r--base/gfx/bitmap_platform_device_linux.cc38
-rw-r--r--base/gfx/bitmap_platform_device_linux.h23
-rw-r--r--base/gfx/platform_canvas_linux.cc1
-rw-r--r--webkit/glue/SConscript3
-rw-r--r--webkit/tools/test_shell/gtk/test_shell.cc15
-rw-r--r--webkit/tools/test_shell/gtk/webview_host.cc8
-rw-r--r--webkit/tools/test_shell/gtk/webwidget_host.cc173
-rw-r--r--webkit/tools/test_shell/webwidget_host.h7
8 files changed, 233 insertions, 35 deletions
diff --git a/base/gfx/bitmap_platform_device_linux.cc b/base/gfx/bitmap_platform_device_linux.cc
index 171f6b9..f86323e 100644
--- a/base/gfx/bitmap_platform_device_linux.cc
+++ b/base/gfx/bitmap_platform_device_linux.cc
@@ -4,9 +4,10 @@
#include "base/gfx/bitmap_platform_device_linux.h"
-#include "base/logging.h"
+#include <gdk/gdk.h>
+#include <gdk-pixbuf/gdk-pixbuf.h>
-#include <time.h>
+#include "base/logging.h"
namespace gfx {
@@ -16,26 +17,39 @@ namespace gfx {
// data.
BitmapPlatformDeviceLinux* BitmapPlatformDeviceLinux::Create(
int width, int height, bool is_opaque) {
+ GdkPixbuf* pixbuf = gdk_pixbuf_new(GDK_COLORSPACE_RGB, true, 8, width, height);
+ if (!pixbuf)
+ return NULL;
+
+ DCHECK_EQ(gdk_pixbuf_get_colorspace(pixbuf), GDK_COLORSPACE_RGB);
+ DCHECK_EQ(gdk_pixbuf_get_bits_per_sample(pixbuf), 8);
+ DCHECK(gdk_pixbuf_get_has_alpha(pixbuf));
+ DCHECK_EQ(gdk_pixbuf_get_n_channels(pixbuf), 4);
+ DCHECK_EQ(gdk_pixbuf_get_width(pixbuf), width);
+ DCHECK_EQ(gdk_pixbuf_get_height(pixbuf), height);
+
SkBitmap bitmap;
- bitmap.setConfig(SkBitmap::kARGB_8888_Config, width, height);
+ bitmap.setConfig(SkBitmap::kARGB_8888_Config, width, height,
+ gdk_pixbuf_get_rowstride(pixbuf));
+ bitmap.setPixels(gdk_pixbuf_get_pixels(pixbuf));
bitmap.setIsOpaque(is_opaque);
- if (is_opaque) {
#ifndef NDEBUG
- // To aid in finding bugs, we set the background color to something
- // obviously wrong so it will be noticable when it is not cleared
+ if (is_opaque) {
bitmap.eraseARGB(255, 0, 255, 128); // bright bluish green
-#endif
}
+#endif
// The device object will take ownership of the graphics context.
- return new BitmapPlatformDeviceLinux(bitmap);
+ return new BitmapPlatformDeviceLinux(bitmap, pixbuf);
}
// The device will own the bitmap, which corresponds to also owning the pixel
// data. Therefore, we do not transfer ownership to the SkDevice's bitmap.
-BitmapPlatformDeviceLinux::BitmapPlatformDeviceLinux(const SkBitmap& bitmap)
- : PlatformDeviceLinux(bitmap) {
+BitmapPlatformDeviceLinux::BitmapPlatformDeviceLinux(const SkBitmap& bitmap,
+ GdkPixbuf* pixbuf)
+ : PlatformDeviceLinux(bitmap),
+ pixbuf_(pixbuf) {
}
BitmapPlatformDeviceLinux::BitmapPlatformDeviceLinux(
@@ -45,6 +59,10 @@ BitmapPlatformDeviceLinux::BitmapPlatformDeviceLinux(
}
BitmapPlatformDeviceLinux::~BitmapPlatformDeviceLinux() {
+ if (pixbuf_) {
+ g_object_unref(pixbuf_);
+ pixbuf_ = NULL;
+ }
}
} // namespace gfx
diff --git a/base/gfx/bitmap_platform_device_linux.h b/base/gfx/bitmap_platform_device_linux.h
index 3059c2c..96a640c 100644
--- a/base/gfx/bitmap_platform_device_linux.h
+++ b/base/gfx/bitmap_platform_device_linux.h
@@ -8,10 +8,22 @@
#include "base/gfx/platform_device_linux.h"
#include "base/ref_counted.h"
+#include "gdk-pixbuf/gdk-pixbuf.h"
+
namespace gfx {
-// I'm trying to get away with defining as little as possible on this. Right
-// now, we don't do anything.
+// -----------------------------------------------------------------------------
+// This is the Linux bitmap backing for Skia. It's a GdkPixbuf of the correct
+// size and we implement a SkPixelRef in order that Skia can write directly to
+// the pixel memory backing the Pixbuf.
+//
+// We then provide an accessor for getting the pixbuf object and that can be
+// drawn to a GDK drawing area to display the rendering result.
+//
+// This is all quite ok for test_shell. In the future we will want to use
+// shared memory between the renderer and the main process at least. In this
+// case we'll probably create the pixbuf from a precreated region of memory.
+// -----------------------------------------------------------------------------
class BitmapPlatformDeviceLinux : public PlatformDeviceLinux {
public:
/// Static constructor. I don't understand this, it's just a copy of the mac
@@ -22,7 +34,7 @@ class BitmapPlatformDeviceLinux : public PlatformDeviceLinux {
/// you should probably be using Create(). This may become private later if
/// we ever have to share state between some native drawing UI and Skia, like
/// the Windows and Mac versions of this class do.
- BitmapPlatformDeviceLinux(const SkBitmap& other);
+ BitmapPlatformDeviceLinux(const SkBitmap& other, GdkPixbuf* pixbuf);
virtual ~BitmapPlatformDeviceLinux();
// A stub copy constructor. Needs to be properly implemented.
@@ -30,6 +42,11 @@ class BitmapPlatformDeviceLinux : public PlatformDeviceLinux {
// Bitmaps aren't vector graphics.
virtual bool IsVectorial() { return false; }
+
+ GdkPixbuf* pixbuf() const { return pixbuf_; }
+
+ private:
+ GdkPixbuf* pixbuf_;
};
} // namespace gfx
diff --git a/base/gfx/platform_canvas_linux.cc b/base/gfx/platform_canvas_linux.cc
index 71bc8f08..63ed3c2 100644
--- a/base/gfx/platform_canvas_linux.cc
+++ b/base/gfx/platform_canvas_linux.cc
@@ -4,6 +4,7 @@
#include "base/gfx/platform_canvas_linux.h"
+#include "base/gfx/platform_device_linux.h"
#include "base/gfx/bitmap_platform_device_linux.h"
#include "base/logging.h"
diff --git a/webkit/glue/SConscript b/webkit/glue/SConscript
index 65de5bf..e8275ef 100644
--- a/webkit/glue/SConscript
+++ b/webkit/glue/SConscript
@@ -70,7 +70,8 @@ input_files = [
]
if env['PLATFORM'] == 'posix':
- # TODO(port): until we have plugin support for Linux, these files aren't built.
+ # TODO(port): until we have plugin support for Linux, these files aren't
+ # built.
remove_files = [
'plugins/plugin_host.cc',
'plugins/plugin_instance.cc',
diff --git a/webkit/tools/test_shell/gtk/test_shell.cc b/webkit/tools/test_shell/gtk/test_shell.cc
index 8276220..97dc66c 100644
--- a/webkit/tools/test_shell/gtk/test_shell.cc
+++ b/webkit/tools/test_shell/gtk/test_shell.cc
@@ -20,9 +20,6 @@ WebPreferences* TestShell::web_prefs_ = NULL;
WindowList* TestShell::window_list_;
TestShell::TestShell() {
- // Uncomment this line to get a bunch of linker errors. This is what we need
- // to fix.
- m_webViewHost.reset(WebViewHost::Create(NULL, NULL, *TestShell::web_prefs_));
}
TestShell::~TestShell() {
@@ -79,17 +76,7 @@ bool TestShell::Initialize(const std::wstring& startingURL) {
-1 /* append */);
gtk_box_pack_start(GTK_BOX(vbox), toolbar, FALSE, FALSE, 0);
-
- // It's funny, ok?
- std::wstring path;
- PathService::Get(base::DIR_SOURCE_ROOT, &path);
- file_util::AppendToPath(&path, L"webkit");
- file_util::AppendToPath(&path, L"tools");
- file_util::AppendToPath(&path, L"test_shell");
- file_util::AppendToPath(&path, L"resources");
- file_util::AppendToPath(&path, L"acid3.png");
- GtkWidget* image = gtk_image_new_from_file(WideToUTF8(path).c_str());
- gtk_box_pack_start(GTK_BOX(vbox), image, FALSE, FALSE, 0);
+ m_webViewHost.reset(WebViewHost::Create(vbox, NULL, *TestShell::web_prefs_));
gtk_container_add(GTK_CONTAINER(m_mainWnd), vbox);
gtk_widget_show_all(m_mainWnd);
diff --git a/webkit/tools/test_shell/gtk/webview_host.cc b/webkit/tools/test_shell/gtk/webview_host.cc
index d84ea74..4eecae1 100644
--- a/webkit/tools/test_shell/gtk/webview_host.cc
+++ b/webkit/tools/test_shell/gtk/webview_host.cc
@@ -13,15 +13,19 @@
#include "webkit/glue/webview.h"
/*static*/
-WebViewHost* WebViewHost::Create(GtkWidget* parent_window,
+WebViewHost* WebViewHost::Create(GtkWidget* box,
WebViewDelegate* delegate,
const WebPreferences& prefs) {
- WebViewHost* host = new WebViewHost();
+ // TODO(agl):
+ // /usr/local/google/agl/src/chrome/src/webkit/tools/test_shell/gtk/webview_host.cc:19: error: no matching function for call to 'WebWidgetHost::Create(GtkWidget*&, WebViewDelegate*&)'
+ WebViewHost* host = reinterpret_cast<WebViewHost *>(WebWidgetHost::Create(box, NULL));
// TODO(erg):
// - Set "host->view_"
// - Call "host->webwidget_->Resize"
host->webwidget_ = WebView::Create(delegate, prefs);
+ host->webwidget_->Resize(gfx::Size(640, 480));
+ host->webwidget_->Layout();
return host;
}
diff --git a/webkit/tools/test_shell/gtk/webwidget_host.cc b/webkit/tools/test_shell/gtk/webwidget_host.cc
index 3b21839..46e3a83 100644
--- a/webkit/tools/test_shell/gtk/webwidget_host.cc
+++ b/webkit/tools/test_shell/gtk/webwidget_host.cc
@@ -4,12 +4,179 @@
#include "webkit/tools/test_shell/webwidget_host.h"
+#include <gtk/gtk.h>
+
#include "base/logging.h"
+#include "base/gfx/platform_canvas_linux.h"
+#include "base/gfx/platform_device_linux.h"
+#include "base/gfx/bitmap_platform_device_linux.h"
+#include "webkit/glue/webinputevent.h"
+#include "webkit/glue/webwidget.h"
+
+namespace {
+
+// -----------------------------------------------------------------------------
+// Callback functions to proxy to host...
+
+gboolean ConfigureEvent(GtkWidget* widget, GdkEventConfigure* config,
+ gpointer userdata) {
+ WebWidgetHost* host = (WebWidgetHost* ) userdata;
+ DLOG(INFO) << " -- Resize " << config->width << " " << config->height;
+ host->Resize(gfx::Size(config->width, config->height));
+ return FALSE;
+}
+
+gboolean ExposeEvent(GtkWidget* widget, GdkEventExpose* expose,
+ gpointer userdata) {
+ WebWidgetHost* host = (WebWidgetHost* ) userdata;
+ DLOG(INFO) << " -- Expose";
+ host->Paint();
+ return FALSE;
+}
+
+gboolean DestroyEvent(GtkWidget* widget, GdkEvent* event, gpointer userdata) {
+ WebWidgetHost* host = (WebWidgetHost* ) userdata;
+ DLOG(INFO) << " -- Destroy";
+ host->WindowDestroyed();
+ return FALSE;
+}
+
+gboolean KeyPressEvent(GtkWidget* widget, GdkEventKey* event,
+ gpointer userdata) {
+ WebWidgetHost* host = (WebWidgetHost* ) userdata;
+ DLOG(INFO) << " -- Key press";
+ WebKeyboardEvent wke(event);
+ host->webwidget()->HandleInputEvent(&wke);
+ return FALSE;
+}
+
+gboolean FocusIn(GtkWidget* widget, GdkEventFocus* focus, gpointer userdata) {
+ WebWidgetHost* host = (WebWidgetHost* ) userdata;
+ host->webwidget()->SetFocus(true);
+ return FALSE;
+}
+
+gboolean FocusOut(GtkWidget* widget, GdkEventFocus* focus, gpointer userdata) {
+ WebWidgetHost* host = (WebWidgetHost* ) userdata;
+ host->webwidget()->SetFocus(false);
+ return FALSE;
+}
+
+} // anonymous namespace
+
+// -----------------------------------------------------------------------------
+
+WebWidgetHost* WebWidgetHost::Create(gfx::WindowHandle box,
+ WebWidgetDelegate* delegate) {
+ WebWidgetHost* host = new WebWidgetHost();
+ host->view_ = gtk_drawing_area_new();
+ gtk_widget_add_events(host->view_, GDK_EXPOSURE_MASK |
+ GDK_POINTER_MOTION_MASK |
+ GDK_BUTTON_PRESS_MASK |
+ GDK_BUTTON_RELEASE_MASK |
+ GDK_KEY_PRESS_MASK |
+ GDK_KEY_RELEASE_MASK);
+ // TODO(agl): set GTK_CAN_FOCUS flag
+ host->webwidget_ = WebWidget::Create(delegate);
+ g_object_set_data(G_OBJECT(host->view_), "webwidgethost", host);
+
+ g_signal_connect(host->view_, "configure-event", G_CALLBACK(ConfigureEvent), host);
+ g_signal_connect(host->view_, "expose-event", G_CALLBACK(ExposeEvent), host);
+ g_signal_connect(host->view_, "destroy-event", G_CALLBACK(DestroyEvent), host);
+ g_signal_connect(host->view_, "key-press-event", G_CALLBACK(KeyPressEvent), host);
+ g_signal_connect(host->view_, "focus-in-event", G_CALLBACK(FocusIn), host);
+ g_signal_connect(host->view_, "focus-out-event", G_CALLBACK(FocusOut), host);
+
+ gtk_box_pack_start(GTK_BOX(box), host->view_, TRUE, TRUE, 0);
-WebWidgetHost::WebWidgetHost() {
- NOTIMPLEMENTED();
+ return host;
+}
+
+WebWidgetHost* FromWindow(gfx::WindowHandle view) {
+ const gpointer p = g_object_get_data(G_OBJECT(view), "webwidgethost");
+ return (WebWidgetHost* ) p;
+}
+
+WebWidgetHost::WebWidgetHost()
+ : view_(NULL),
+ webwidget_(NULL),
+ scroll_dx_(0),
+ scroll_dy_(0),
+ track_mouse_leave_(false) {
+ set_painting(false);
}
WebWidgetHost::~WebWidgetHost() {
- NOTIMPLEMENTED();
+ webwidget_->Close();
+ webwidget_->Release();
+}
+
+void WebWidgetHost::Resize(const gfx::Size &newsize) {
+ // The pixel buffer backing us is now the wrong size
+ canvas_.reset();
+
+ gtk_widget_set_size_request(GTK_WIDGET(view_), newsize.width(), newsize.height());
+ webwidget_->Resize(gfx::Size(newsize.width(), newsize.height()));
+}
+
+void WebWidgetHost::Paint() {
+ gint width, height;
+ gtk_widget_get_size_request(GTK_WIDGET(view_), &width, &height);
+
+ gfx::Rect client_rect(width, height);
+
+ if (!canvas_.get()) {
+ paint_rect_ = client_rect;
+ canvas_.reset(new gfx::PlatformCanvas(width, height, true));
+ if (!canvas_.get()) {
+ // memory allocation failed, we can't paint.
+ LOG(ERROR) << "Failed to allocate memory for " << width << "x" << height;
+ return;
+ }
+ }
+
+ // This may result in more invalidation
+ webwidget_->Layout();
+
+ // TODO(agl): scrolling code
+
+ // Paint the canvas if necessary. Allow painting to generate extra rects the
+ // first time we call it. This is necessary because some WebCore rendering
+ // objects update their layout only when painted.
+
+ for (int i = 0; i < 2; ++i) {
+ paint_rect_ = client_rect.Intersect(paint_rect_);
+ if (!paint_rect_.IsEmpty()) {
+ gfx::Rect rect(paint_rect_);
+ paint_rect_ = gfx::Rect();
+
+ DLOG_IF(WARNING, i == 1) << "painting caused additional invalidations";
+ PaintRect(rect);
+ }
+ }
+ DCHECK(paint_rect_.IsEmpty());
+
+ // BitBlit to the X server
+ gfx::PlatformDeviceLinux &platdev = canvas_->getTopPlatformDevice();
+ gfx::BitmapPlatformDeviceLinux* const bitdev =
+ static_cast<gfx::BitmapPlatformDeviceLinux* >(&platdev);
+ LOG(INFO) << "Using pixel data at " << (void *) gdk_pixbuf_get_pixels(bitdev->pixbuf());
+ gdk_draw_pixbuf(view_->window, NULL, bitdev->pixbuf(),
+ 0, 0, 0, 0, width, height, GDK_RGB_DITHER_NONE, 0, 0);
+ gdk_pixbuf_save(bitdev->pixbuf(), "output.png", "png", NULL, NULL);
+}
+
+void WebWidgetHost::PaintRect(const gfx::Rect& rect) {
+ set_painting(true);
+ webwidget_->Paint(canvas_.get(), rect);
+ set_painting(false);
+}
+
+// -----------------------------------------------------------------------------
+// This is called when the GTK window is destroyed. In the Windows code this
+// deletes this object. Since it's only test_shell it probably doesn't matter
+// that much.
+// -----------------------------------------------------------------------------
+void WebWidgetHost::WindowDestroyed() {
+ delete this;
}
diff --git a/webkit/tools/test_shell/webwidget_host.h b/webkit/tools/test_shell/webwidget_host.h
index c318c18..eb52bc0 100644
--- a/webkit/tools/test_shell/webwidget_host.h
+++ b/webkit/tools/test_shell/webwidget_host.h
@@ -42,6 +42,7 @@ class WebWidgetHost {
#endif
void DiscardBackingStore();
+ void Paint();
protected:
WebWidgetHost();
@@ -51,7 +52,6 @@ class WebWidgetHost {
// Per-class wndproc. Returns true if the event should be swallowed.
virtual bool WndProc(UINT message, WPARAM wparam, LPARAM lparam);
- void Paint();
void Resize(LPARAM lparam);
void MouseEvent(UINT message, WPARAM wparam, LPARAM lparam);
void WheelEvent(WPARAM wparam, LPARAM lparam);
@@ -63,13 +63,16 @@ class WebWidgetHost {
#elif defined(OS_MACOSX)
// These need to be called from a non-subclass, so they need to be public.
public:
- void Paint();
void Resize(const gfx::Rect& rect);
void MouseEvent(NSEvent *);
void WheelEvent(NSEvent *);
void KeyEvent(NSEvent *);
void SetFocus(bool enable);
protected:
+#elif defined(OS_LINUX)
+ public:
+ void WindowDestroyed();
+ void Resize(const gfx::Size& size);
#endif
void TrackMouseLeave(bool enable);