Changeset 55617 in webkit


Ignore:
Timestamp:
Mar 6, 2010 4:26:08 AM (14 years ago)
Author:
eric@webkit.org
Message:

2010-03-06 Yuta Kitamura <yutak@chromium.org>

Reviewed by Eric Seidel.

Fix decoration position in search input field.

This patch fixes rendering of input field of "search" type, whose decoration
(loupe icon and close button) was wrongly positioned when the input field was
contained in a block with -webkit-transform property.

Chromium bug: http://crbug.com/20439

[Chromium] Decoration of "search" input field is wrongly rendered
https://bugs.webkit.org/show_bug.cgi?id=30245

No new tests, since this patch fixes an existing test
(fast/forms/search-transformed.html) in Chromium layout tests.

  • rendering/RenderThemeChromiumSkia.cpp: (WebCore::RenderThemeChromiumSkia::convertToPaintingRect): Added. This method does almost the same thing as RenderThemeMac::convertToPaintingRect. (WebCore::RenderThemeChromiumSkia::paintSearchFieldCancelButton): The position of the icon should not depend on its absolute position. (WebCore::RenderThemeChromiumSkia::paintSearchFieldResultsDecoration): Ditto. (WebCore::RenderThemeChromiumSkia::paintSearchFieldResultsButton): Ditto.
  • rendering/RenderThemeChromiumSkia.h: Added new method.
Location:
trunk/WebCore
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/WebCore/ChangeLog

    r55614 r55617  
     12010-03-06  Yuta Kitamura  <yutak@chromium.org>
     2
     3        Reviewed by Eric Seidel.
     4
     5        Fix decoration position in search input field.
     6
     7        This patch fixes rendering of input field of "search" type, whose decoration
     8        (loupe icon and close button) was wrongly positioned when the input field was
     9        contained in a block with -webkit-transform property.
     10
     11        Chromium bug: http://crbug.com/20439
     12
     13        [Chromium] Decoration of "search" input field is wrongly rendered
     14        https://bugs.webkit.org/show_bug.cgi?id=30245
     15
     16        No new tests, since this patch fixes an existing test
     17        (fast/forms/search-transformed.html) in Chromium layout tests.
     18
     19        * rendering/RenderThemeChromiumSkia.cpp:
     20        (WebCore::RenderThemeChromiumSkia::convertToPaintingRect): Added. This method
     21        does almost the same thing as RenderThemeMac::convertToPaintingRect.
     22        (WebCore::RenderThemeChromiumSkia::paintSearchFieldCancelButton): The position
     23        of the icon should not depend on its absolute position.
     24        (WebCore::RenderThemeChromiumSkia::paintSearchFieldResultsDecoration): Ditto.
     25        (WebCore::RenderThemeChromiumSkia::paintSearchFieldResultsButton): Ditto.
     26        * rendering/RenderThemeChromiumSkia.h: Added new method.
     27
    1282010-03-06  Ilya Tikhonovsky  <loislo@chromium.org>
    229
  • trunk/WebCore/rendering/RenderThemeChromiumSkia.cpp

    r53289 r55617  
    404404}
    405405
    406 bool RenderThemeChromiumSkia::paintSearchFieldCancelButton(RenderObject* o, const RenderObject::PaintInfo& i, const IntRect& r)
    407 {
    408     IntRect bounds = r;
    409     ASSERT(o->parent());
    410     if (!o->parent() || !o->parent()->isBox())
     406IntRect RenderThemeChromiumSkia::convertToPaintingRect(RenderObject* inputRenderer, const RenderObject* partRenderer, IntRect partRect, const IntRect& localOffset) const
     407{
     408    // Compute an offset between the part renderer and the input renderer.
     409    IntSize offsetFromInputRenderer = -(partRenderer->offsetFromAncestorContainer(inputRenderer));
     410    // Move the rect into partRenderer's coords.
     411    partRect.move(offsetFromInputRenderer);
     412    // Account for the local drawing offset.
     413    partRect.move(localOffset.x(), localOffset.y());
     414
     415    return partRect;
     416}
     417
     418bool RenderThemeChromiumSkia::paintSearchFieldCancelButton(RenderObject* cancelButtonObject, const RenderObject::PaintInfo& paintInfo, const IntRect& r)
     419{
     420    // Get the renderer of <input> element.
     421    Node* input = cancelButtonObject->node()->shadowAncestorNode();
     422    if (!input->renderer()->isBox())
    411423        return false;
    412 
    413     RenderBox* parentRenderBox = toRenderBox(o->parent());
    414 
    415     IntRect parentBox = parentRenderBox->absoluteContentBox();
    416 
    417     // Make sure the scaled button stays square and will fit in its parent's box
    418     bounds.setHeight(std::min(parentBox.width(), std::min(parentBox.height(), bounds.height())));
    419     bounds.setWidth(bounds.height());
    420 
     424    RenderBox* inputRenderBox = toRenderBox(input->renderer());
     425    IntRect inputContentBox = inputRenderBox->contentBoxRect();
     426
     427    // Make sure the scaled button stays square and will fit in its parent's box.
     428    int cancelButtonSize = std::min(inputContentBox.width(), std::min(inputContentBox.height(), r.height()));
     429    // Calculate cancel button's coordinates relative to the input element.
    421430    // Center the button vertically.  Round up though, so if it has to be one pixel off-center, it will
    422431    // be one pixel closer to the bottom of the field.  This tends to look better with the text.
    423     bounds.setY(parentBox.y() + (parentBox.height() - bounds.height() + 1) / 2);
     432    IntRect cancelButtonRect(cancelButtonObject->offsetFromAncestorContainer(inputRenderBox).width(),
     433                             inputContentBox.y() + (inputContentBox.height() - cancelButtonSize + 1) / 2,
     434                             cancelButtonSize, cancelButtonSize);
     435    IntRect paintingRect = convertToPaintingRect(inputRenderBox, cancelButtonObject, cancelButtonRect, r);
    424436
    425437    static Image* cancelImage = Image::loadPlatformResource("searchCancel").releaseRef();
    426438    static Image* cancelPressedImage = Image::loadPlatformResource("searchCancelPressed").releaseRef();
    427     i.context->drawImage(isPressed(o) ? cancelPressedImage : cancelImage, o->style()->colorSpace(), bounds);
     439    paintInfo.context->drawImage(isPressed(cancelButtonObject) ? cancelPressedImage : cancelImage,
     440                                 cancelButtonObject->style()->colorSpace(), paintingRect);
    428441    return false;
    429442}
     
    446459}
    447460
    448 bool RenderThemeChromiumSkia::paintSearchFieldResultsDecoration(RenderObject* o, const RenderObject::PaintInfo& i, const IntRect& r)
    449 {
    450     IntRect bounds = r;
    451     ASSERT(o->parent());
    452     if (!o->parent() || !o->parent()->isBox())
     461bool RenderThemeChromiumSkia::paintSearchFieldResultsDecoration(RenderObject* magnifierObject, const RenderObject::PaintInfo& paintInfo, const IntRect& r)
     462{
     463    // Get the renderer of <input> element.
     464    Node* input = magnifierObject->node()->shadowAncestorNode();
     465    if (!input->renderer()->isBox())
    453466        return false;
    454 
    455     RenderBox* parentRenderBox = toRenderBox(o->parent());
    456     IntRect parentBox = parentRenderBox->absoluteContentBox();
    457 
    458     // Make sure the scaled decoration stays square and will fit in its parent's box
    459     bounds.setHeight(std::min(parentBox.width(), std::min(parentBox.height(), bounds.height())));
    460     bounds.setWidth(bounds.height());
    461 
     467    RenderBox* inputRenderBox = toRenderBox(input->renderer());
     468    IntRect inputContentBox = inputRenderBox->contentBoxRect();
     469
     470    // Make sure the scaled decoration stays square and will fit in its parent's box.
     471    int magnifierSize = std::min(inputContentBox.width(), std::min(inputContentBox.height(), r.height()));
     472    // Calculate decoration's coordinates relative to the input element.
    462473    // Center the decoration vertically.  Round up though, so if it has to be one pixel off-center, it will
    463474    // be one pixel closer to the bottom of the field.  This tends to look better with the text.
    464     bounds.setY(parentBox.y() + (parentBox.height() - bounds.height() + 1) / 2);
     475    IntRect magnifierRect(magnifierObject->offsetFromAncestorContainer(inputRenderBox).width(),
     476                          inputContentBox.y() + (inputContentBox.height() - magnifierSize + 1) / 2,
     477                          magnifierSize, magnifierSize);
     478    IntRect paintingRect = convertToPaintingRect(inputRenderBox, magnifierObject, magnifierRect, r);
    465479
    466480    static Image* magnifierImage = Image::loadPlatformResource("searchMagnifier").releaseRef();
    467     i.context->drawImage(magnifierImage, o->style()->colorSpace(), bounds);
     481    paintInfo.context->drawImage(magnifierImage, magnifierObject->style()->colorSpace(), paintingRect);
    468482    return false;
    469483}
     
    480494}
    481495
    482 bool RenderThemeChromiumSkia::paintSearchFieldResultsButton(RenderObject* o, const RenderObject::PaintInfo& i, const IntRect& r)
    483 {
    484     IntRect bounds = r;
    485     ASSERT(o->parent());
    486     if (!o->parent())
     496bool RenderThemeChromiumSkia::paintSearchFieldResultsButton(RenderObject* magnifierObject, const RenderObject::PaintInfo& paintInfo, const IntRect& r)
     497{
     498    // Get the renderer of <input> element.
     499    Node* input = magnifierObject->node()->shadowAncestorNode();
     500    if (!input->renderer()->isBox())
    487501        return false;
    488     if (!o->parent() || !o->parent()->isBox())
    489         return false;
    490 
    491     RenderBox* parentRenderBox = toRenderBox(o->parent());
    492     IntRect parentBox = parentRenderBox->absoluteContentBox();
    493 
    494     // Make sure the scaled decoration will fit in its parent's box
    495     bounds.setHeight(std::min(parentBox.height(), bounds.height()));
    496     bounds.setWidth(std::min(parentBox.width(), static_cast<int>(bounds.height() * defaultSearchFieldResultsButtonWidth / defaultSearchFieldResultsDecorationSize)));
    497 
    498     // Center the button vertically.  Round up though, so if it has to be one pixel off-center, it will
    499     // be one pixel closer to the bottom of the field.  This tends to look better with the text.
    500     bounds.setY(parentBox.y() + (parentBox.height() - bounds.height() + 1) / 2);
     502    RenderBox* inputRenderBox = toRenderBox(input->renderer());
     503    IntRect inputContentBox = inputRenderBox->contentBoxRect();
     504
     505    // Make sure the scaled decoration will fit in its parent's box.
     506    int magnifierHeight = std::min(inputContentBox.height(), r.height());
     507    int magnifierWidth = std::min(inputContentBox.width(), static_cast<int>(magnifierHeight * defaultSearchFieldResultsButtonWidth / defaultSearchFieldResultsDecorationSize));
     508    IntRect magnifierRect(magnifierObject->offsetFromAncestorContainer(inputRenderBox).width(),
     509                          inputContentBox.y() + (inputContentBox.height() - magnifierHeight + 1) / 2,
     510                          magnifierWidth, magnifierHeight);
     511    IntRect paintingRect = convertToPaintingRect(inputRenderBox, magnifierObject, magnifierRect, r);
    501512
    502513    static Image* magnifierImage = Image::loadPlatformResource("searchMagnifierResults").releaseRef();
    503     i.context->drawImage(magnifierImage, o->style()->colorSpace(), bounds);
     514    paintInfo.context->drawImage(magnifierImage, magnifierObject->style()->colorSpace(), paintingRect);
    504515    return false;
    505516}
  • trunk/WebCore/rendering/RenderThemeChromiumSkia.h

    r51428 r55617  
    154154        int menuListInternalPadding(RenderStyle*, int paddingType) const;
    155155        bool paintMediaButtonInternal(GraphicsContext*, const IntRect&, Image*);
     156        IntRect convertToPaintingRect(RenderObject* inputRenderer, const RenderObject* partRenderer, IntRect partRect, const IntRect& localOffset) const;
    156157    };
    157158
Note: See TracChangeset for help on using the changeset viewer.