Changeset 18755 in webkit


Ignore:
Timestamp:
Jan 10, 2007 6:24:30 PM (17 years ago)
Author:
bdash
Message:

2007-01-10 Kirby White <KWhiteRight@gmail.com>

Reviewed by Darin.

Fixes for http://bugs.webkit.org/show_bug.cgi?id=11841

Set image size to fit alt text when image or input-image element
has no src attribute, so that those images show their alt text instead
of showing nothing at all.

  • html/HTMLImageElement.cpp: (WebCore::HTMLImageElement::attach):
  • html/HTMLInputElement.cpp: (WebCore::HTMLInputElement::attach):
  • rendering/RenderImage.cpp: (WebCore::RenderImage::setImageSizeForAltText): (WebCore::RenderImage::imageChanged):
  • rendering/RenderImage.h:

2007-01-10 Kirby White <KWhiteRight@gmail.com>

Reviewed by Darin.

New and adjusted test cases for
http://bugs.webkit.org/show_bug.cgi?id=11841

  • fast/dom/HTMLImageElement/image-alt-text-expected.checksum: Added.
  • fast/dom/HTMLImageElement/image-alt-text-expected.png: Added.
  • fast/dom/HTMLImageElement/image-alt-text-expected.txt: Added.
  • fast/dom/HTMLImageElement/image-alt-text.html: Added.
  • fast/dom/HTMLImageElement/resources/blue_rect.jpg: Added.
  • fast/dom/HTMLInputElement/input-image-alt-text-expected.checksum: Added.
  • fast/dom/HTMLInputElement/input-image-alt-text-expected.png: Added.
  • fast/dom/HTMLInputElement/input-image-alt-text-expected.txt: Added.
  • fast/dom/HTMLInputElement/input-image-alt-text.html: Added.
  • fast/dom/HTMLInputElement/resources/blue_rect.jpg: Added.
  • fast/forms/focus2-expected.txt:
  • fast/forms/focus2.html:
  • fast/forms/input-value-expected.checksum:
  • fast/forms/input-value-expected.png:
  • fast/forms/input-value-expected.txt:
Location:
trunk
Files:
12 added
11 edited

Legend:

Unmodified
Added
Removed
  • trunk/LayoutTests/ChangeLog

    r18753 r18755  
     12007-01-10  Kirby White  <KWhiteRight@gmail.com>
     2
     3        Reviewed by Darin.
     4
     5        New and adjusted test cases for
     6        http://bugs.webkit.org/show_bug.cgi?id=11841
     7
     8        * fast/dom/HTMLImageElement/image-alt-text-expected.checksum: Added.
     9        * fast/dom/HTMLImageElement/image-alt-text-expected.png: Added.
     10        * fast/dom/HTMLImageElement/image-alt-text-expected.txt: Added.
     11        * fast/dom/HTMLImageElement/image-alt-text.html: Added.
     12        * fast/dom/HTMLImageElement/resources/blue_rect.jpg: Added.
     13        * fast/dom/HTMLInputElement/input-image-alt-text-expected.checksum: Added.
     14        * fast/dom/HTMLInputElement/input-image-alt-text-expected.png: Added.
     15        * fast/dom/HTMLInputElement/input-image-alt-text-expected.txt: Added.
     16        * fast/dom/HTMLInputElement/input-image-alt-text.html: Added.
     17        * fast/dom/HTMLInputElement/resources/blue_rect.jpg: Added.
     18        * fast/forms/focus2-expected.txt:
     19        * fast/forms/focus2.html:
     20        * fast/forms/input-value-expected.checksum:
     21        * fast/forms/input-value-expected.png:
     22        * fast/forms/input-value-expected.txt:
     23
    1242007-01-10  Mitz Pettel  <mitz@webkit.org>
    225
  • trunk/LayoutTests/fast/forms/focus2-expected.txt

    r18610 r18755  
    1414keypress event: [to] FILE
    1515blur event: [to] FILE
     16focus event: [to] IMAGE
     17keypress event: [to] IMAGE
     18blur event: [to] IMAGE
    1619focus event: [to] ISINDEX
    1720keypress event: [to] ISINDEX
     
    5659keypress event: [to] FILE
    5760blur event: [to] FILE
     61focus event: [to] IMAGE
     62keypress event: [to] IMAGE
     63blur event: [to] IMAGE
    5864focus event: [to] ISINDEX
    5965keypress event: [to] ISINDEX
  • trunk/LayoutTests/fast/forms/focus2.html

    r18610 r18755  
    128128log('PARENT DOCUMENT:\n');
    129129document.getElementsByTagName('input')[0].focus();
    130 for (var i = 0; i < 12; ++i) //>
     130for (var i = 0; i < 13; ++i) //>
    131131    dispatchOptionTab(lastFocusedElement, false);
    132132
     
    135135log('\nIFRAME DOCUMENT:\n');
    136136document.getElementById('testIframe').contentDocument.getElementsByTagName('input')[0].focus();
    137 for (var i = 0; i < 12; ++i) //>
     137for (var i = 0; i < 13; ++i) //>
    138138    dispatchOptionTab(lastFocusedElement, false);
    139139</script>
  • trunk/LayoutTests/fast/forms/input-value-expected.checksum

    r16290 r18755  
    1 46aacae774651d7db7e097624470e413
     1117a32ed4debd2d2ba5d14641f9004cb
  • trunk/LayoutTests/fast/forms/input-value-expected.txt

    r18292 r18755  
    9595                RenderText {#text} at (1,1) size 222x18
    9696                  text run at (1,1) width 222: "image with value property changed"
    97               RenderTableCell {TD} at (389,135) size 243x2 [r=5 c=1 rs=1 cs=1]
    98                 RenderImage {INPUT} at (1,1) size 0x0
     97              RenderTableCell {TD} at (389,128) size 243x15 [r=5 c=1 rs=1 cs=1]
     98                RenderImage {INPUT} at (1,1) size 35x13
    9999              RenderTableCell {TD} at (634,126) size 62x20 [r=5 c=2 rs=1 cs=1]
    100100                RenderText {#text} at (1,1) size 28x18
  • trunk/WebCore/ChangeLog

    r18754 r18755  
     12007-01-10  Kirby White  <KWhiteRight@gmail.com>
     2
     3        Reviewed by Darin.
     4
     5        Fixes for http://bugs.webkit.org/show_bug.cgi?id=11841
     6
     7        Set image size to fit alt text when image or input-image element
     8        has no src attribute, so that those images show their alt text instead
     9        of showing nothing at all.
     10
     11        * html/HTMLImageElement.cpp:
     12        (WebCore::HTMLImageElement::attach):
     13        * html/HTMLInputElement.cpp:
     14        (WebCore::HTMLInputElement::attach):
     15        * rendering/RenderImage.cpp:
     16        (WebCore::RenderImage::setImageSizeForAltText):
     17        (WebCore::RenderImage::imageChanged):
     18        * rendering/RenderImage.h:
     19
    1202007-01-11  Mark Rowe  <mrowe@apple.com>
    221
  • trunk/WebCore/html/HTMLImageElement.cpp

    r15653 r18755  
    167167    HTMLElement::attach();
    168168
    169     if (RenderImage* imageObj = static_cast<RenderImage*>(renderer()))
     169    if (renderer()) {
     170        RenderImage* imageObj = static_cast<RenderImage*>(renderer());
    170171        imageObj->setCachedImage(m_imageLoader.image());
     172       
     173        // If we have no image at all because we have no src attribute, set
     174        // image height and width for the alt text instead.
     175        if (!m_imageLoader.image() && !imageObj->cachedImage())
     176            imageObj->setImageSizeForAltText();
     177    }
    171178}
    172179
  • trunk/WebCore/html/HTMLInputElement.cpp

    r18523 r18755  
    850850        if (renderer()) {
    851851            RenderImage* imageObj = static_cast<RenderImage*>(renderer());
    852             imageObj->setCachedImage(m_imageLoader->image());   
     852            imageObj->setCachedImage(m_imageLoader->image());
     853           
     854            // If we have no image at all because we have no src attribute, set
     855            // image height and width for the alt text instead.
     856            if (!m_imageLoader->image() && !imageObj->cachedImage())
     857                imageObj->setImageSizeForAltText();
    853858        }
    854859    }
  • trunk/WebCore/rendering/RenderImage.cpp

    r18654 r18755  
    7676}
    7777
     78// If we'll be displaying either alt text or an image, add some padding.
     79static const unsigned short paddingWidth = 4;
     80static const unsigned short paddingHeight = 4;
     81
     82// Alt text is restricted to this maximum size, in pixels.  These are
     83// signed integers because they are compared with other signed values.
     84static const int maxAltTextWidth = 1024;
     85static const int maxAltTextHeight = 256;
     86
     87// Sets the image height and width to fit the alt text.  Returns true if the
     88// image size changed.
     89bool RenderImage::setImageSizeForAltText(CachedImage* newImage /* = 0 */)
     90{
     91    int imageWidth = 0;
     92    int imageHeight = 0;
     93 
     94    // If we'll be displaying either text or an image, add a little padding.
     95    if (!m_altText.isEmpty() || newImage) {
     96        imageWidth = paddingWidth;
     97        imageHeight = paddingHeight;
     98    }
     99 
     100    if (newImage) {
     101        imageWidth += newImage->image()->width();
     102        imageHeight += newImage->image()->height();
     103    }
     104 
     105    // we have an alt and the user meant it (its not a text we invented)
     106    if (!m_altText.isEmpty()) {
     107        const Font& font = style()->font();
     108        imageWidth = max(imageWidth, min(font.width(TextRun(m_altText.characters(), m_altText.length())), maxAltTextWidth));
     109        imageHeight = max(imageHeight, min(font.height(), maxAltTextHeight));
     110    }
     111 
     112    bool imageSizeChanged = false;
     113 
     114    if (imageWidth != intrinsicWidth()) {
     115        setIntrinsicWidth(imageWidth);
     116        imageSizeChanged = true;
     117    }
     118    if (imageHeight != intrinsicHeight()) {
     119        setIntrinsicHeight(imageHeight);
     120        imageSizeChanged = true;
     121    }
     122 
     123    return imageSizeChanged;
     124}
     125
    78126void RenderImage::imageChanged(CachedImage* newImage)
    79127{
     
    88136    bool imageSizeChanged = false;
    89137
    90     if (newImage->isErrorImage()) {
    91         int imageWidth = newImage->image()->width() + 4;
    92         int imageHeight = newImage->image()->height() + 4;
    93 
    94         // we have an alt and the user meant it (its not a text we invented)
    95         if (!m_altText.isEmpty()) {
    96             const Font& font = style()->font();
    97             imageWidth = max(imageWidth, min(font.width(TextRun(m_altText.characters(), m_altText.length())), 1024));
    98             imageHeight = max(imageHeight, min(font.height(), 256));
    99         }
    100 
    101         if (imageWidth != intrinsicWidth()) {
    102             setIntrinsicWidth(imageWidth);
    103             imageSizeChanged = true;
    104         }
    105         if (imageHeight != intrinsicHeight()) {
    106             setIntrinsicHeight(imageHeight);
    107             imageSizeChanged = true;
    108         }
    109     }
    110 
     138    // Set image dimensions, taking into account the size of the alt text.
     139    if (newImage->isErrorImage())
     140        imageSizeChanged = setImageSizeForAltText(newImage);
     141   
    111142    bool ensureLayout = false;
    112143
  • trunk/WebCore/rendering/RenderImage.h

    r18724 r18755  
    4747
    4848    virtual void imageChanged(CachedImage*);
     49   
     50    bool setImageSizeForAltText(CachedImage* newImage = 0);
    4951
    5052    void updateAltText();
Note: See TracChangeset for help on using the changeset viewer.