[Qt] Broken controls rendering when transform is applied.
authorcommit-queue@webkit.org <commit-queue@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Fri, 25 May 2012 12:18:04 +0000 (12:18 +0000)
committercommit-queue@webkit.org <commit-queue@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Fri, 25 May 2012 12:18:04 +0000 (12:18 +0000)
https://bugs.webkit.org/show_bug.cgi?id=87483

Patch by Zalan Bujtas <zbujtas@gmail.com> on 2012-05-25
Reviewed by Simon Hausmann.

.:

* ManualTests/qt/control_paiting_with_transforms.html: Added.

Source/WebCore:

Use only the scaling transform value to determine the size of
the control to be drawn. When other transforms present such as
rotate or skew, ignore them, unless scaling also involved. In
that case, calculate the scaling value out of the transformation.

* ManualTests/qt/control_paiting_with_transforms.html: Added.

* platform/qt/RenderThemeQtMobile.cpp:
(WebCore::painterScale):
(WebCore):
(WebCore::StylePainterMobile::sizeForPainterScale):

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@118514 268f45cc-cd09-0410-ab3c-d52691b4dbfc

ChangeLog
ManualTests/qt/control_paiting_with_transforms.html [new file with mode: 0644]
Source/WebCore/ChangeLog
Source/WebCore/platform/qt/RenderThemeQtMobile.cpp

index ea6736a..213720d 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,12 @@
+2012-05-25  Zalan Bujtas  <zbujtas@gmail.com>
+
+        [Qt] Broken controls rendering when transform is applied.
+        https://bugs.webkit.org/show_bug.cgi?id=87483
+
+        Reviewed by Simon Hausmann.
+
+        * ManualTests/qt/control_paiting_with_transforms.html: Added.
+
 2012-05-24  Tim Horton  <timothy_horton@apple.com>
 
         Add feature defines for web-facing parts of CSS Regions and Exclusions
diff --git a/ManualTests/qt/control_paiting_with_transforms.html b/ManualTests/qt/control_paiting_with_transforms.html
new file mode 100644 (file)
index 0000000..0600474
--- /dev/null
@@ -0,0 +1,23 @@
+<html>
+<head>
+  <script>
+    var d = 0;
+
+    function rotate() {
+      d+=1;
+      document.getElementById('text_rotate').style.webkitTransform = "rotate(" + d + "deg)";
+      document.getElementById('button_rotate').style.webkitTransform = "rotate(" + (360 - d) + "deg)";
+      setTimeout('rotate()', 10);
+    }
+  </script>
+</head>
+<body>
+  <p>This tests the quality of the control drawing, while transform is applied.<br>
+     Click on the button and check for quality regression, while rotating.</p>
+  <input type='button' value='rotate' onclick='rotate();'>
+  <input id='text_rotate'; style='position:absolute; left:300px; top:100px; -webkit-transform: rotate(0deg);' type='text' value=''>
+  <input id='button_rotate'; style='position:absolute; left:300px; top:300px; -webkit-transform: rotate(0deg);' type='button' value='                            '>
+</body>
+</html>
+
+
index f5f2a57..f6549bd 100644 (file)
@@ -1,3 +1,22 @@
+2012-05-25  Zalan Bujtas  <zbujtas@gmail.com>
+
+        [Qt] Broken controls rendering when transform is applied.
+        https://bugs.webkit.org/show_bug.cgi?id=87483
+
+        Reviewed by Simon Hausmann.
+
+        Use only the scaling transform value to determine the size of
+        the control to be drawn. When other transforms present such as
+        rotate or skew, ignore them, unless scaling also involved. In
+        that case, calculate the scaling value out of the transformation.
+
+        * ManualTests/qt/control_paiting_with_transforms.html: Added.
+
+        * platform/qt/RenderThemeQtMobile.cpp:
+        (WebCore::painterScale):
+        (WebCore):
+        (WebCore::StylePainterMobile::sizeForPainterScale):
+
 2012-05-17  Andrey Kosyakov  <caseq@chromium.org>
 
         [chromium] add instrumentation for compositing
index 9155cd4..7d5713e 100644 (file)
@@ -80,6 +80,24 @@ static const QColor shadowColor(80, 80, 80, 160);
 
 static QHash<KeyIdentifier, CacheKey> cacheKeys;
 
+static qreal painterScale(QPainter* painter)
+{
+    if (!painter)
+        return 1;
+
+    const QTransform& transform = painter->transform();
+    qreal scale = 1;
+
+    if (transform.type() == QTransform::TxScale)
+        scale = qAbs(transform.m11());
+    else if (transform.type() >= QTransform::TxRotate) {
+        const QLineF l1(0, 0, 1, 0);
+        const QLineF l2 = transform.map(l1);
+        scale = qAbs(l2.length() / l1.length());
+    }
+    return scale;
+}
+
 uint qHash(const KeyIdentifier& id)
 {
     const quint32 value = id.trait1 + (id.trait2 << 1) + (uint(id.type) << 2) + (id.height << 5) + (id.width << 14) + (id.trait3 << 25);
@@ -132,11 +150,6 @@ static inline QRect shrinkRectToSquare(const QRect& rect)
     return QRect(rect.topLeft(), QSize(side, side));
 }
 
-static inline qreal painterScale(QPainter* painter)
-{
-    return painter ? painter->transform().m11() : 1;
-}
-
 static inline QPen borderPen(QPainter* painter = 0)
 {
     return QPen(darkColor, 0.4 * painterScale(painter), Qt::SolidLine, Qt::RoundCap, Qt::RoundJoin);
@@ -201,8 +214,10 @@ void StylePainterMobile::drawCheckableBackground(QPainter* painter, const QRect&
 
 QSize StylePainterMobile::sizeForPainterScale(const QRect& rect) const
 {
-    const QRect mappedRect = painter->transform().mapRect(rect);
-    return mappedRect.size();
+    qreal scale = painterScale(painter);
+    QTransform scaleTransform = QTransform::fromScale(scale, scale);
+
+    return scaleTransform.mapRect(rect).size();
 }
 
 void StylePainterMobile::drawChecker(QPainter* painter, const QRect& rect, const QColor& color) const