From 1deabc22a79236001955f6f6082cac2249776ac2 Mon Sep 17 00:00:00 2001 From: Xan Lopez Date: Thu, 1 Jul 2010 16:18:26 +0200 Subject: [PATCH] WebCore: 2010-07-01 Xan Lopez Reviewed by NOBODY (OOPS!). [GTK] Stop using GdkRegion in 3.x mode https://bugs.webkit.org/show_bug.cgi?id=41463 Make us compile without using GdkRegion, since it's gone from GTK+ 3.x. * platform/graphics/IntRect.h: * platform/graphics/cairo/GraphicsContextCairo.cpp: (WebCore::GraphicsContext::drawFocusRing): * platform/graphics/gtk/FontGtk.cpp: (WebCore::cairo_region_shrink): (WebCore::Font::drawComplexText): * platform/gtk/GtkPluginWidget.cpp: (WebCore::GtkPluginWidget::paint): * platform/gtk/RenderThemeGtk.h: * platform/gtk/ScrollbarGtk.cpp: (ScrollbarGtk::paint): WebKit/gtk: 2010-07-01 Xan Lopez Reviewed by NOBODY (OOPS!). [GTK] Stop using GdkRegion in 3.x mode https://bugs.webkit.org/show_bug.cgi?id=41463 Make us compile without using GdkRegion, since it's gone from GTK+ 3.x. * WebCoreSupport/ChromeClientGtk.cpp: (WebKit::ChromeClient::scroll): * webkit/webkitwebview.cpp: (webkit_web_view_expose_event): --- WebCore/ChangeLog | 22 ++++++++++++ WebCore/platform/graphics/IntRect.h | 5 +++ .../graphics/cairo/GraphicsContextCairo.cpp | 14 +++++++ WebCore/platform/graphics/gtk/FontGtk.cpp | 37 +++++++++++++++++++- WebCore/platform/gtk/GtkPluginWidget.cpp | 8 ++++ WebCore/platform/gtk/RenderThemeGtk.h | 5 +++ WebCore/platform/gtk/ScrollbarGtk.cpp | 8 ++++ WebKit/gtk/ChangeLog | 15 ++++++++ WebKit/gtk/WebCoreSupport/ChromeClientGtk.cpp | 16 ++++++++ WebKit/gtk/webkit/webkitwebview.cpp | 10 ++++- 10 files changed, 137 insertions(+), 3 deletions(-) diff --git a/WebCore/platform/graphics/IntRect.h b/WebCore/platform/graphics/IntRect.h index ad90dd9..c5990ef 100644 --- WebCore/platform/graphics/IntRect.h +++ WebCore/platform/graphics/IntRect.h @@ -48,7 +48,12 @@ QT_BEGIN_NAMESPACE class QRect; QT_END_NAMESPACE #elif PLATFORM(GTK) +#ifdef GTK_API_VERSION_2 typedef struct _GdkRectangle GdkRectangle; +#else +typedef struct _cairo_rectangle_int cairo_rectangle_int_t; +typedef cairo_rectangle_int_t GdkRectangle; +#endif #elif PLATFORM(HAIKU) class BRect; #endif diff --git a/WebCore/platform/graphics/cairo/GraphicsContextCairo.cpp b/WebCore/platform/graphics/cairo/GraphicsContextCairo.cpp index dc32317..5521a6f 100644 --- WebCore/platform/graphics/cairo/GraphicsContextCairo.cpp +++ WebCore/platform/graphics/cairo/GraphicsContextCairo.cpp @@ -643,13 +643,27 @@ void GraphicsContext::drawFocusRing(const Vector& rects, int width, int cairo_new_path(cr); #if PLATFORM(GTK) +#ifdef GTK_API_VERSION_2 GdkRegion* reg = gdk_region_new(); +#else + cairo_region_t* reg = cairo_region_create(); +#endif + for (unsigned i = 0; i < rectCount; i++) { +#ifdef GTK_API_VERSION_2 GdkRectangle rect = rects[i]; gdk_region_union_with_rect(reg, &rect); +#else + cairo_rectangle_int_t rect = rects[i]; + cairo_region_union_rectangle(reg, &rect); +#endif } gdk_cairo_region(cr, reg); +#ifdef GTK_API_VERSION_2 gdk_region_destroy(reg); +#else + cairo_region_destroy(reg); +#endif setColor(cr, color); cairo_set_line_width(cr, 2.0f); diff --git a/WebCore/platform/graphics/gtk/FontGtk.cpp b/WebCore/platform/graphics/gtk/FontGtk.cpp index fae84cb..e451b76 100644 --- WebCore/platform/graphics/gtk/FontGtk.cpp +++ WebCore/platform/graphics/gtk/FontGtk.cpp @@ -181,6 +181,29 @@ bool Font::canReturnFallbackFontsForComplexText() return false; } +#ifndef GTK_API_VERSION_2 +static void cairo_region_shrink(cairo_region_t* region, int dx, int dy) +{ + int nRects = cairo_region_num_rectangles(region); + /* clear region */ + cairo_region_subtract(region, region); + + for (int i = 0; i < nRects; i++) { + cairo_rectangle_int_t rect; + cairo_region_get_rectangle(region, i, &rect); + + if (rect.width <= 2 * dx || rect.height <= 2 * dy) + continue; + + rect.x += dx; + rect.y += dy; + rect.width -= 2 * dx; + rect.height -= 2 * dy; + cairo_region_union_rectangle(region, &rect); + } +} +#endif + void Font::drawComplexText(GraphicsContext* context, const TextRun& run, const FloatPoint& point, int from, int to) const { cairo_t* cr = context->platformContext(); @@ -196,14 +219,22 @@ void Font::drawComplexText(GraphicsContext* context, const TextRun& run, const F // Our layouts are single line PangoLayoutLine* layoutLine = pango_layout_get_line_readonly(layout, 0); - GdkRegion* partialRegion = NULL; +#ifdef GTK_API_VERSION_2 + GdkRegion* partialRegion = 0; +#else + cairo_region_t* partialRegion = 0; +#endif if (to - from != run.length()) { // Clip the region of the run to be rendered char* start = g_utf8_offset_to_pointer(utf8, from); char* end = g_utf8_offset_to_pointer(start, to - from); int ranges[] = {start - utf8, end - utf8}; partialRegion = gdk_pango_layout_line_get_clip_region(layoutLine, 0, 0, ranges, 1); +#ifdef GTK_API_VERSION_2 gdk_region_shrink(partialRegion, 0, -pixelSize()); +#else + cairo_region_shrink(partialRegion, 0, -pixelSize()); +#endif } Color fillColor = context->fillColor(); @@ -265,7 +296,11 @@ void Font::drawComplexText(GraphicsContext* context, const TextRun& run, const F cairo_new_path(cr); if (partialRegion) +#ifdef GTK_API_VERSION_2 gdk_region_destroy(partialRegion); +#else + cairo_region_destroy(partialRegion); +#endif g_free(utf8); g_object_unref(layout); diff --git a/WebCore/platform/gtk/GtkPluginWidget.cpp b/WebCore/platform/gtk/GtkPluginWidget.cpp index 94382f1..331f60f 100644 --- WebCore/platform/gtk/GtkPluginWidget.cpp +++ WebCore/platform/gtk/GtkPluginWidget.cpp @@ -87,7 +87,11 @@ void GtkPluginWidget::paint(GraphicsContext* context, const IntRect& rect) event->expose.area.x = loc.x(); event->expose.area.y = loc.y(); +#ifdef GTK_API_VERSION_2 event->expose.region = gdk_region_rectangle(&event->expose.area); +#else + event->expose.region = cairo_region_create_rectangle(&event->expose.area); +#endif /* * This will be unref'ed by gdk_event_free. @@ -97,7 +101,11 @@ void GtkPluginWidget::paint(GraphicsContext* context, const IntRect& rect) /* * If we are going to paint do the translation and GtkAllocation manipulation. */ +#ifdef GTK_API_VERSION_2 if (!gdk_region_empty(event->expose.region)) +#else + if (!cairo_region_is_empty(event->expose.region)) +#endif gtk_widget_send_expose(widget, event); gdk_event_free(event); diff --git a/WebCore/platform/gtk/RenderThemeGtk.h b/WebCore/platform/gtk/RenderThemeGtk.h index 3f02f0e..71338d4 100644 --- WebCore/platform/gtk/RenderThemeGtk.h +++ WebCore/platform/gtk/RenderThemeGtk.h @@ -34,7 +34,12 @@ typedef struct _GtkWidget GtkWidget; typedef struct _GtkStyle GtkStyle; typedef struct _GtkContainer GtkContainer; +#ifdef GTK_API_VERSION_2 typedef struct _GdkRectangle GdkRectangle; +#else +typedef struct _cairo_rectangle_int cairo_rectangle_int_t; +typedef cairo_rectangle_int_t GdkRectangle; +#endif typedef struct _GdkDrawable GdkDrawable; typedef struct _GtkBorder GtkBorder; typedef struct _GtkThemeParts GtkThemeParts; diff --git a/WebCore/platform/gtk/ScrollbarGtk.cpp b/WebCore/platform/gtk/ScrollbarGtk.cpp index 5dc4dd6..8081fb8 100644 --- WebCore/platform/gtk/ScrollbarGtk.cpp +++ WebCore/platform/gtk/ScrollbarGtk.cpp @@ -238,7 +238,11 @@ void ScrollbarGtk::paint(GraphicsContext* context, const IntRect& rect) event->expose.area.x = loc.x(); event->expose.area.y = loc.y(); +#ifdef GTK_API_VERSION_2 event->expose.region = gdk_region_rectangle(&event->expose.area); +#else + event->expose.region = cairo_region_create_rectangle(&event->expose.area); +#endif /* * This will be unref'ed by gdk_event_free. @@ -248,7 +252,11 @@ void ScrollbarGtk::paint(GraphicsContext* context, const IntRect& rect) /* * If we are going to paint do the translation and GtkAllocation manipulation. */ +#ifdef GTK_API_VERSION_2 if (!gdk_region_empty(event->expose.region)) +#else + if (!cairo_region_is_empty(event->expose.region)) +#endif gtk_widget_send_expose(widget, event); gdk_event_free(event); diff --git a/WebKit/gtk/WebCoreSupport/ChromeClientGtk.cpp b/WebKit/gtk/WebCoreSupport/ChromeClientGtk.cpp index fe5d9eb..bb469c5 100644 --- WebKit/gtk/WebCoreSupport/ChromeClientGtk.cpp +++ WebKit/gtk/WebCoreSupport/ChromeClientGtk.cpp @@ -372,6 +372,7 @@ void ChromeClient::scroll(const IntSize& delta, const IntRect& rectToScroll, con sourceRect.x -= delta.width(); sourceRect.y -= delta.height(); +#ifdef GTK_API_VERSION_2 GdkRegion* invalidRegion = gdk_region_rectangle(&area); if (gdk_rectangle_intersect(&area, &sourceRect, &moveRect)) { @@ -384,6 +385,21 @@ void ChromeClient::scroll(const IntSize& delta, const IntRect& rectToScroll, con gdk_window_invalidate_region(window, invalidRegion, FALSE); gdk_region_destroy(invalidRegion); +#else + cairo_region_t* invalidRegion = cairo_region_create_rectangle(&area); + + if (gdk_rectangle_intersect(&area, &sourceRect, &moveRect)) { + cairo_region_t* moveRegion = cairo_region_create_rectangle(&moveRect); + gdk_window_move_region(window, moveRegion, delta.width(), delta.height()); + cairo_region_translate(moveRegion, delta.width(), delta.height()); + cairo_region_subtract(invalidRegion, moveRegion); + cairo_region_destroy(moveRegion); + } + + gdk_window_invalidate_region(window, invalidRegion, FALSE); + cairo_region_destroy(invalidRegion); +#endif + } // FIXME: this does not take into account the WM decorations diff --git a/WebKit/gtk/webkit/webkitwebview.cpp b/WebKit/gtk/webkit/webkitwebview.cpp index ff4aa8a..62997c5 100644 --- WebKit/gtk/webkit/webkitwebview.cpp +++ WebKit/gtk/webkit/webkitwebview.cpp @@ -517,10 +517,16 @@ static gboolean webkit_web_view_expose_event(GtkWidget* widget, GdkEventExpose* cairo_destroy(cr); ctx.setGdkExposeEvent(event); - GOwnPtr rects; int rectCount; +#ifdef GTK_API_VERSION_2 + GOwnPtr rects; gdk_region_get_rectangles(event->region, &rects.outPtr(), &rectCount); - +#else + rectCount = cairo_region_num_rectangles(event->region); + GOwnPtr rects(g_new(GdkRectangle, rectCount)); + for (int i = 0; i < rectCount; i++) + cairo_region_get_rectangle(event->region, i, rects.get()+i); +#endif // Avoid recursing into the render tree excessively bool coalesce = shouldCoalesce(event->area, rects.get(), rectCount); -- 1.6.6.1