Title: [129041] trunk/Source/WebCore
Revision
129041
Author
[email protected]
Date
2012-09-19 13:52:43 -0700 (Wed, 19 Sep 2012)

Log Message

[BlackBerry] Fix vertical positioning problem for 'X' in search field
https://bugs.webkit.org/show_bug.cgi?id=97126

Reviewed by Antonio Gomes.

We have the same problem as described in bug 30245, so integrate that code.

* platform/blackberry/RenderThemeBlackBerry.cpp:
(WebCore::RenderThemeBlackBerry::convertToPaintingRect):
(WebCore):
(WebCore::RenderThemeBlackBerry::paintSearchFieldCancelButton):

Modified Paths

Diff

Modified: trunk/Source/WebCore/ChangeLog (129040 => 129041)


--- trunk/Source/WebCore/ChangeLog	2012-09-19 20:43:54 UTC (rev 129040)
+++ trunk/Source/WebCore/ChangeLog	2012-09-19 20:52:43 UTC (rev 129041)
@@ -146,6 +146,20 @@
 
 2012-09-19  Rob Buis  <[email protected]>
 
+        [BlackBerry] Fix vertical positioning problem for 'X' in search field
+        https://bugs.webkit.org/show_bug.cgi?id=97126
+
+        Reviewed by Antonio Gomes.
+
+        We have the same problem as described in bug 30245, so integrate that code.
+
+        * platform/blackberry/RenderThemeBlackBerry.cpp:
+        (WebCore::RenderThemeBlackBerry::convertToPaintingRect):
+        (WebCore):
+        (WebCore::RenderThemeBlackBerry::paintSearchFieldCancelButton):
+
+2012-09-19  Rob Buis  <[email protected]>
+
         [BlackBerry] Remove custom painting code for searchCancel
         https://bugs.webkit.org/show_bug.cgi?id=97119
 

Modified: trunk/Source/WebCore/platform/blackberry/RenderThemeBlackBerry.cpp (129040 => 129041)


--- trunk/Source/WebCore/platform/blackberry/RenderThemeBlackBerry.cpp	2012-09-19 20:43:54 UTC (rev 129040)
+++ trunk/Source/WebCore/platform/blackberry/RenderThemeBlackBerry.cpp	2012-09-19 20:52:43 UTC (rev 129041)
@@ -332,28 +332,42 @@
     return paintTextFieldOrTextAreaOrSearchField(object, info, rect);
 }
 
-bool RenderThemeBlackBerry::paintSearchFieldCancelButton(RenderObject* object, const PaintInfo& paintInfo, const IntRect& rect)
+IntRect RenderThemeBlackBerry::convertToPaintingRect(RenderObject* inputRenderer, const RenderObject* partRenderer, LayoutRect partRect, const IntRect& localOffset) const
 {
-    ASSERT(object->parent());
-    if (!object->parent() || !object->parent()->isBox())
+    // Compute an offset between the part renderer and the input renderer.
+    LayoutSize offsetFromInputRenderer = -partRenderer->offsetFromAncestorContainer(inputRenderer);
+    // Move the rect into partRenderer's coords.
+    partRect.move(offsetFromInputRenderer);
+    // Account for the local drawing offset.
+    partRect.move(localOffset.x(), localOffset.y());
+
+    return pixelSnappedIntRect(partRect);
+}
+
+
+bool RenderThemeBlackBerry::paintSearchFieldCancelButton(RenderObject* cancelButtonObject, const PaintInfo& paintInfo, const IntRect& r)
+{
+    Node* input = cancelButtonObject->node()->shadowAncestorNode();
+    if (!input->renderer()->isBox())
         return false;
 
-    RenderBox* parentRenderBox = toRenderBox(object->parent());
+    RenderBox* inputRenderBox = toRenderBox(input->renderer());
+    LayoutRect inputContentBox = inputRenderBox->contentBoxRect();
 
-    IntRect parentBox = parentRenderBox->absoluteContentBox();
-    IntRect bounds = rect;
-    // Make sure the scaled button stays square and fits in its parent's box.
-    bounds.setHeight(std::min(parentBox.width(), std::min(parentBox.height(), bounds.height())));
-    bounds.setWidth(bounds.height());
+    // Make sure the scaled button stays square and will fit in its parent's box.
+    LayoutUnit cancelButtonSize = std::min(inputContentBox.width(), std::min<LayoutUnit>(inputContentBox.height(), r.height()));
+    // Calculate cancel button's coordinates relative to the input element.
+    // Center the button vertically. Round up though, so if it has to be one pixel off-center, it will
+    // be one pixel closer to the bottom of the field. This tends to look better with the text.
+    LayoutRect cancelButtonRect(cancelButtonObject->offsetFromAncestorContainer(inputRenderBox).width(),
+                                inputContentBox.y() + (inputContentBox.height() - cancelButtonSize + 1) / 2,
+                                cancelButtonSize, cancelButtonSize);
+    IntRect paintingRect = convertToPaintingRect(inputRenderBox, cancelButtonObject, cancelButtonRect, r);
 
-    // Put the button in the middle vertically, and round up the value.
-    // So if it has to be one pixel off-center, it would be one pixel closer
-    // to the bottom of the field. This would look better with the text.
-    bounds.setY(parentBox.y() + (parentBox.height() - bounds.height() + 1) / 2);
-
     static Image* cancelImage = Image::loadPlatformResource("searchCancel").leakRef();
     static Image* cancelPressedImage = Image::loadPlatformResource("searchCancelPressed").leakRef();
-    paintInfo.context->drawImage(isPressed(object) ? cancelPressedImage : cancelImage, object->style()->colorSpace(), bounds);
+    paintInfo.context->drawImage(isPressed(cancelButtonObject) ? cancelPressedImage : cancelImage,
+                                 cancelButtonObject->style()->colorSpace(), paintingRect);
     return false;
 }
 
_______________________________________________
webkit-changes mailing list
[email protected]
http://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to