From ced987b58feffea607cdf73fa3e8de774bafe6ce Mon Sep 17 00:00:00 2001 From: Robert O'Callahan Date: Fri, 10 Jul 2009 14:02:58 +1200 Subject: [PATCH] Bug 500910. GTK2 test plugin should take window shapes into account when computing the effective clip region. r=karlt --- modules/plugin/test/testplugin/Makefile.in | 2 +- .../plugin/test/testplugin/nptest_gtk2.cpp | 35 +++++++++++++++++-- 2 files changed, 34 insertions(+), 3 deletions(-) diff --git a/modules/plugin/test/testplugin/Makefile.in b/modules/plugin/test/testplugin/Makefile.in index 92ae9e30fec..47e50fff2ce 100644 --- a/modules/plugin/test/testplugin/Makefile.in +++ b/modules/plugin/test/testplugin/Makefile.in @@ -87,7 +87,7 @@ include $(topsrcdir)/config/rules.mk ifeq ($(MOZ_WIDGET_TOOLKIT),gtk2) CXXFLAGS += $(MOZ_GTK2_CFLAGS) CFLAGS += $(MOZ_GTK2_CFLAGS) -EXTRA_DSO_LDOPTS += $(MOZ_GTK2_LIBS) $(XLDFLAGS) $(XLIBS) +EXTRA_DSO_LDOPTS += $(MOZ_GTK2_LIBS) $(XLDFLAGS) $(XLIBS) $(XEXT_LIBS) endif install-plugin: $(SHARED_LIBRARY) diff --git a/modules/plugin/test/testplugin/nptest_gtk2.cpp b/modules/plugin/test/testplugin/nptest_gtk2.cpp index ab1dc55fe44..aed28cbc190 100644 --- a/modules/plugin/test/testplugin/nptest_gtk2.cpp +++ b/modules/plugin/test/testplugin/nptest_gtk2.cpp @@ -38,6 +38,7 @@ #include #ifdef MOZ_X11 #include +#include #endif #include @@ -334,6 +335,34 @@ int32_t pluginGetEdge(InstanceData* instanceData, RectEdge edge) return NPTEST_INT32_ERROR; } +#ifdef MOZ_X11 +static void intersectWithShapeRects(Display* display, Window window, + int kind, GdkRegion* region) +{ + int count, order; + XRectangle* shapeRects = + XShapeGetRectangles(display, window, kind, &count, &order); + if (!shapeRects) + return; + + GdkRegion* shapeRegion = gdk_region_new(); + if (!shapeRegion) { + XFree(shapeRects); + return; + } + + for (int i = 0; i < count; ++i) { + XRectangle* r = &shapeRects[i]; + GdkRectangle rect = { r->x, r->y, r->width, r->height }; + gdk_region_union_with_rect(shapeRegion, &rect); + } + XFree(shapeRects); + + gdk_region_intersect(region, shapeRegion); + gdk_region_destroy(shapeRegion); +} +#endif + static GdkRegion* computeClipRegion(InstanceData* instanceData) { if (!instanceData->hasWidget) @@ -374,13 +403,15 @@ static GdkRegion* computeClipRegion(InstanceData* instanceData) return 0; } - GdkRectangle windowRect = { -pluginX, -pluginY, width, height }; + GdkRectangle windowRect = { 0, 0, width, height }; GdkRegion* windowRgn = gdk_region_rectangle(&windowRect); if (!windowRgn) { gdk_region_destroy(region); return 0; } - gdk_region_intersect(region, windowRgn); + intersectWithShapeRects(display, window, ShapeBounding, windowRgn); + intersectWithShapeRects(display, window, ShapeClip, windowRgn); + gdk_region_offset(windowRgn, -pluginX, -pluginY); gdk_region_destroy(windowRgn); // Stop now if we've reached the toplevel. Stopping here means