summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authortc@google.com <tc@google.com@0039d316-1c4b-4281-b951-d872f2087c98>2008-11-05 00:05:44 +0000
committertc@google.com <tc@google.com@0039d316-1c4b-4281-b951-d872f2087c98>2008-11-05 00:05:44 +0000
commit0ebb5701c641d30980d82bf638b19ff1b9b5f61a (patch)
tree7fe592f0236c2fe50889c6974119ebb960ca2c40
parent0e097dbc1b1638d95c6f5b13482472e7233a5a1c (diff)
downloadchromium_src-0ebb5701c641d30980d82bf638b19ff1b9b5f61a.zip
chromium_src-0ebb5701c641d30980d82bf638b19ff1b9b5f61a.tar.gz
chromium_src-0ebb5701c641d30980d82bf638b19ff1b9b5f61a.tar.bz2
Paint regions properly on linux test_shell.
The key was to update paint_rect_ during the DidInvalidateRect. I also added some code for bookkeeping needed for optimized scrolling, but haven't actually hooked it up yet. Most of the other changes were to get more inline with the Windows code. Review URL: http://codereview.chromium.org/9151 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@4711 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r--webkit/tools/test_shell/gtk/webwidget_host.cc53
1 files changed, 39 insertions, 14 deletions
diff --git a/webkit/tools/test_shell/gtk/webwidget_host.cc b/webkit/tools/test_shell/gtk/webwidget_host.cc
index 78d5c67..79e39f58 100644
--- a/webkit/tools/test_shell/gtk/webwidget_host.cc
+++ b/webkit/tools/test_shell/gtk/webwidget_host.cc
@@ -27,7 +27,6 @@ gboolean ConfigureEvent(GtkWidget* widget, GdkEventConfigure* config,
gboolean ExposeEvent(GtkWidget* widget, GdkEventExpose* expose,
WebWidgetHost* host) {
- DLOG(INFO) << " -- Expose";
host->Paint();
return FALSE;
}
@@ -77,7 +76,6 @@ gboolean MouseMoveEvent(GtkWidget* widget, GdkEventMotion* event,
gboolean MouseScrollEvent(GtkWidget* widget, GdkEventScroll* event,
WebWidgetHost* host) {
WebMouseWheelEvent wmwe(event);
- DLOG(INFO) << " -- mouse wheel scroll event";
host->webwidget()->HandleInputEvent(&wmwe);
return FALSE;
}
@@ -130,18 +128,39 @@ WebWidgetHost* WebWidgetHost::Create(gfx::WindowHandle box,
return host;
}
-void WebWidgetHost::DidInvalidateRect(const gfx::Rect& rect) {
- LOG(INFO) << " -- Invalidate " << rect.x() << " "
- << rect.y() << " "
- << rect.width() << " "
- << rect.height() << " ";
+void WebWidgetHost::DidInvalidateRect(const gfx::Rect& damaged_rect) {
+ DLOG_IF(WARNING, painting_) << "unexpected invalidation while painting";
- gtk_widget_queue_draw_area(GTK_WIDGET(view_), rect.x(), rect.y(), rect.width(),
- rect.height());
+ // If this invalidate overlaps with a pending scroll, then we have to
+ // downgrade to invalidating the scroll rect.
+ if (damaged_rect.Intersects(scroll_rect_)) {
+ paint_rect_ = paint_rect_.Union(scroll_rect_);
+ ResetScrollRect();
+ }
+ paint_rect_ = paint_rect_.Union(damaged_rect);
+
+ gtk_widget_queue_draw_area(GTK_WIDGET(view_), damaged_rect.x(),
+ damaged_rect.y(), damaged_rect.width(), damaged_rect.height());
}
void WebWidgetHost::DidScrollRect(int dx, int dy, const gfx::Rect& clip_rect) {
- NOTIMPLEMENTED();
+ DCHECK(dx || dy);
+
+ // If we already have a pending scroll operation or if this scroll operation
+ // intersects the existing paint region, then just failover to invalidating.
+ if (!scroll_rect_.IsEmpty() || paint_rect_.Intersects(clip_rect)) {
+ paint_rect_ = paint_rect_.Union(scroll_rect_);
+ ResetScrollRect();
+ paint_rect_ = paint_rect_.Union(clip_rect);
+ }
+
+ // We will perform scrolling lazily, when requested to actually paint.
+ scroll_rect_ = clip_rect;
+ scroll_dx_ = dx;
+ scroll_dy_ = dy;
+
+ gtk_widget_queue_draw_area(GTK_WIDGET(view_), clip_rect.x(), clip_rect.y(),
+ clip_rect.width(), clip_rect.height());
}
WebWidgetHost* FromWindow(gfx::WindowHandle view) {
@@ -174,10 +193,11 @@ void WebWidgetHost::Resize(const gfx::Size &newsize) {
void WebWidgetHost::Paint() {
gint width, height;
gtk_widget_get_size_request(GTK_WIDGET(view_), &width, &height);
-
gfx::Rect client_rect(width, height);
+ // Allocate a canvas if necessary
if (!canvas_.get()) {
+ ResetScrollRect();
paint_rect_ = client_rect;
canvas_.reset(new gfx::PlatformCanvas(width, height, true));
if (!canvas_.get()) {
@@ -190,12 +210,12 @@ void WebWidgetHost::Paint() {
// This may result in more invalidation
webwidget_->Layout();
- // TODO(agl): scrolling code
+ // TODO(agl): Optimized scrolling code would go here.
+ ResetScrollRect();
// 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()) {
@@ -212,11 +232,16 @@ void WebWidgetHost::Paint() {
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);
}
+void WebWidgetHost::ResetScrollRect() {
+ scroll_rect_ = gfx::Rect();
+ scroll_dx_ = 0;
+ scroll_dy_ = 0;
+}
+
void WebWidgetHost::PaintRect(const gfx::Rect& rect) {
set_painting(true);
webwidget_->Paint(canvas_.get(), rect);