Diff
Modified: trunk/Source/WebCore/ChangeLog (132554 => 132555)
--- trunk/Source/WebCore/ChangeLog 2012-10-26 01:57:07 UTC (rev 132554)
+++ trunk/Source/WebCore/ChangeLog 2012-10-26 02:18:16 UTC (rev 132555)
@@ -1,3 +1,31 @@
+2012-10-25 Nico Weber <[email protected]>
+
+ Flip ImageOrientation coordinate system from lefthanded to righthanded
+ https://bugs.webkit.org/show_bug.cgi?id=100414
+
+ Reviewed by Eric Seidel.
+
+ platform/graphics, noteably GraphicsContext uses a right-handed
+ coordinate system (origin in the top left corner, x growing to the
+ right, y to the bottom). ImageOrientation was an outlier from
+ and used a left-handed coordinate system. This patch makes
+ ImageOrientation match the rest of platform/graphics.
+
+ This is a pure refactoring and has no observable effects.
+
+ * platform/chromium/DragImageChromiumSkia.cpp:
+ (WebCore::createDragImageFromImage):
+ * platform/graphics/ImageOrientation.cpp:
+ (WebCore::ImageOrientation::transformFromDefault):
+ * platform/graphics/cg/GraphicsContextCG.cpp:
+ (WebCore::GraphicsContext::drawNativeImage):
+ * platform/graphics/skia/ImageSkia.cpp:
+ (WebCore::BitmapImage::draw):
+ * platform/mac/DragImageMac.mm:
+ (WebCore::createDragImageFromImage):
+ * rendering/RenderObject.cpp:
+ (WebCore::RenderObject::shouldRespectImageOrientation):
+
2012-10-25 Keishi Hattori <[email protected]>
Hide popup while transitioning from the suggestion picker to the calendar picker
Modified: trunk/Source/WebCore/platform/chromium/DragImageChromiumSkia.cpp (132554 => 132555)
--- trunk/Source/WebCore/platform/chromium/DragImageChromiumSkia.cpp 2012-10-26 01:57:07 UTC (rev 132554)
+++ trunk/Source/WebCore/platform/chromium/DragImageChromiumSkia.cpp 2012-10-26 02:18:16 UTC (rev 132555)
@@ -130,18 +130,11 @@
FloatRect destRect(FloatPoint(), sizeRespectingOrientation);
SkCanvas canvas(*dragImageChromium->bitmap);
- // ImageOrientation expects the origin in the lower left corner, so flip, transform, and then...
- canvas.translate(0, destRect.height());
- canvas.scale(1, -1);
canvas.concat(orientation.transformFromDefault(sizeRespectingOrientation));
if (orientation.usesWidthAsHeight())
destRect = FloatRect(destRect.x(), destRect.y(), destRect.height(), destRect.width());
- // ...flip back.
- canvas.translate(0, destRect.height());
- canvas.scale(1, -1);
-
canvas.drawBitmapRect(bitmap->bitmap(), 0, destRect);
return dragImageChromium;
}
Modified: trunk/Source/WebCore/platform/graphics/ImageOrientation.cpp (132554 => 132555)
--- trunk/Source/WebCore/platform/graphics/ImageOrientation.cpp 2012-10-26 01:57:07 UTC (rev 132554)
+++ trunk/Source/WebCore/platform/graphics/ImageOrientation.cpp 2012-10-26 02:18:16 UTC (rev 132555)
@@ -41,17 +41,17 @@
case OriginBottomRight:
return AffineTransform(-1, 0, 0, -1, w, h);
case OriginLeftBottom:
+ return AffineTransform( 0, -1, 1, 0, 0, h);
+ case OriginRightTop:
return AffineTransform( 0, 1, -1, 0, w, 0);
- case OriginRightTop:
- return AffineTransform( 0, -1, 1, 0, 0, h);
case OriginTopRight:
return AffineTransform(-1, 0, 0, 1, w, 0);
case OriginBottomLeft:
return AffineTransform( 1, 0, 0, -1, 0, h);
case OriginLeftTop:
+ return AffineTransform( 0, 1, 1, 0, 0, 0);
+ case OriginRightBottom:
return AffineTransform( 0, -1, -1, 0, w, h);
- case OriginRightBottom:
- return AffineTransform( 0, 1, 1, 0, 0, 0);
}
ASSERT_NOT_REACHED();
return AffineTransform();
Modified: trunk/Source/WebCore/platform/graphics/ImageOrientation.h (132554 => 132555)
--- trunk/Source/WebCore/platform/graphics/ImageOrientation.h 2012-10-26 01:57:07 UTC (rev 132554)
+++ trunk/Source/WebCore/platform/graphics/ImageOrientation.h 2012-10-26 02:18:16 UTC (rev 132555)
@@ -76,7 +76,7 @@
}
// This transform can be used for drawing an image according to the orientation.
- // It should be used in a left-handed coordinate system.
+ // It should be used in a right-handed coordinate system.
AffineTransform transformFromDefault(const FloatSize& drawnSize) const;
inline bool operator==(const ImageOrientation& other) const { return other.m_orientation == m_orientation; }
Modified: trunk/Source/WebCore/platform/graphics/cg/GraphicsContextCG.cpp (132554 => 132555)
--- trunk/Source/WebCore/platform/graphics/cg/GraphicsContextCG.cpp 2012-10-26 01:57:07 UTC (rev 132554)
+++ trunk/Source/WebCore/platform/graphics/cg/GraphicsContextCG.cpp 2012-10-26 02:18:16 UTC (rev 132555)
@@ -326,9 +326,8 @@
setPlatformCompositeOperation(op);
- // Flip the coords.
- CGContextTranslateCTM(context, adjustedDestRect.x(), adjustedDestRect.maxY());
- CGContextScaleCTM(context, 1, -1);
+ // ImageOrientation expects the origin to be at (0, 0)
+ CGContextTranslateCTM(context, adjustedDestRect.x(), adjustedDestRect.y());
adjustedDestRect.setLocation(FloatPoint());
if (orientation != DefaultImageOrientation) {
@@ -340,6 +339,10 @@
}
}
+ // Flip the coords.
+ CGContextTranslateCTM(context, 0, adjustedDestRect.height());
+ CGContextScaleCTM(context, 1, -1);
+
// Adjust the color space.
image = Image::imageWithColorSpace(image.get(), styleColorSpace);
Modified: trunk/Source/WebCore/platform/graphics/skia/ImageSkia.cpp (132554 => 132555)
--- trunk/Source/WebCore/platform/graphics/skia/ImageSkia.cpp 2012-10-26 01:57:07 UTC (rev 132554)
+++ trunk/Source/WebCore/platform/graphics/skia/ImageSkia.cpp 2012-10-26 02:18:16 UTC (rev 132555)
@@ -619,9 +619,6 @@
ctxt->translate(normDstRect.x(), normDstRect.y());
normDstRect.setLocation(FloatPoint());
- // ImageOrientation also expects the origin in the lower left corner, so flip, transform, and then...
- ctxt->translate(0, normDstRect.height());
- ctxt->scale(FloatSize(1, -1));
ctxt->concatCTM(orientation.transformFromDefault(normDstRect.size()));
if (orientation.usesWidthAsHeight()) {
@@ -629,10 +626,6 @@
// the image, as it was needed for page layout, so we need to reverse it back here.
normDstRect = FloatRect(normDstRect.x(), normDstRect.y(), normDstRect.height(), normDstRect.width());
}
-
- // ...flip back.
- ctxt->translate(0, normDstRect.height());
- ctxt->scale(FloatSize(1, -1));
}
paintSkBitmap(ctxt->platformContext(),
Modified: trunk/Source/WebCore/platform/mac/DragImageMac.mm (132554 => 132555)
--- trunk/Source/WebCore/platform/mac/DragImageMac.mm 2012-10-26 01:57:07 UTC (rev 132554)
+++ trunk/Source/WebCore/platform/mac/DragImageMac.mm 2012-10-26 02:18:16 UTC (rev 132555)
@@ -99,17 +99,27 @@
if (orientation != DefaultImageOrientation) {
// Construct a correctly-rotated copy of the image to use as the drag image.
- RetainPtr<NSAffineTransform> cocoaTransform(AdoptNS, [[NSAffineTransform alloc] init]);
- CGAffineTransform transform = orientation.transformFromDefault(sizeRespectingOrientation);
- [cocoaTransform.get() setTransformStruct:*(NSAffineTransformStruct*)&transform];
-
FloatRect destRect(FloatPoint(), sizeRespectingOrientation);
RetainPtr<NSImage> rotatedDragImage(AdoptNS, [[NSImage alloc] initWithSize:(NSSize)(sizeRespectingOrientation)]);
[rotatedDragImage.get() lockFocus];
- [cocoaTransform.get() concat];
+
+ // ImageOrientation uses top-left coordinates, need to flip to bottom-left, apply...
+ CGAffineTransform transform = CGAffineTransformMakeTranslation(0, destRect.height());
+ transform = CGAffineTransformScale(transform, 1, -1);
+ transform = CGAffineTransformConcat(orientation.transformFromDefault(sizeRespectingOrientation), transform);
+
if (orientation.usesWidthAsHeight())
destRect = FloatRect(destRect.x(), destRect.y(), destRect.height(), destRect.width());
+
+ // ...and flip back.
+ transform = CGAffineTransformTranslate(transform, 0, destRect.height());
+ transform = CGAffineTransformScale(transform, 1, -1);
+
+ RetainPtr<NSAffineTransform> cocoaTransform(AdoptNS, [[NSAffineTransform alloc] init]);
+ [cocoaTransform.get() setTransformStruct:*(NSAffineTransformStruct*)&transform];
+ [cocoaTransform.get() concat];
+
[image->getNSImage() drawInRect:destRect fromRect:NSMakeRect(0, 0, size.width(), size.height()) operation:NSCompositeSourceOver fraction:1.0];
[rotatedDragImage.get() unlockFocus];