Changeset 19979

Show
Ignore:
Timestamp:
03/06/07 01:05:42 (23 months ago)
Author:
andersca
Message:

LayoutTests:

Reviewed by Maciej.

<rdar://problem/5035045>
REGRESSION: WebKit browser doesn't display image at http://www.metoffice.gov.uk/weather/satellite/index.html


Add some tests where image elements have id _and_ name elements.


  • fast/dom/HTMLDocument/document-special-properties-expected.txt:
  • fast/dom/HTMLDocument/document-special-properties.html:

WebCore:

Reviewed by Maciej.

<rdar://problem/5035045>
REGRESSION: WebKit browser doesn't display image at http://www.metoffice.gov.uk/weather/satellite/index.html


It turns out WinIE does allow you to access images by their id as special document properties. However, this is only
allowed when the element also has a name attribute. The value of the name attribute is ignored and can even be empty!


  • bindings/js/kjs_html.cpp: (KJS::JSHTMLDocument::namedItemGetter): Return jsUndefined() if the collection is empty.


  • html/HTMLImageElement.cpp: (WebCore::HTMLImageElement::parseMappedAttribute): (WebCore::HTMLImageElement::insertedIntoDocument): (WebCore::HTMLImageElement::removedFromDocument):
  • html/HTMLImageElement.h: Add the id attribute value to the extra named item map.


  • html/HTMLNameCollection.cpp: (WebCore::HTMLNameCollection::traverseNextItem): Check for images with name attributes that match, as well as elements with id attributes that match where the element also has a name attribute.
Location:
trunk
Files:
8 modified

Legend:

Unmodified
Added
Removed
  • trunk/LayoutTests/ChangeLog

    r19977 r19979  
     12007-03-06  Anders Carlsson  <acarlsson@apple.com> 
     2 
     3        Reviewed by Maciej. 
     4 
     5        <rdar://problem/5035045> 
     6        REGRESSION: WebKit browser doesn't display image at http://www.metoffice.gov.uk/weather/satellite/index.html 
     7         
     8        Add some tests where image elements have id _and_ name elements. 
     9         
     10        * fast/dom/HTMLDocument/document-special-properties-expected.txt: 
     11        * fast/dom/HTMLDocument/document-special-properties.html: 
     12 
    1132007-03-05  Kevin McCullough  <kmccullough@apple.com> 
    214 
  • trunk/LayoutTests/fast/dom/HTMLDocument/document-special-properties-expected.txt

    r11962 r19979  
    1111Image by id (multiple): undefined 
    1212Image by id/name mixed: collection(2) IMG(name) IMG(name) 
     13Image by id, name present (unique): single IMG(id,name) 
     14Image by id, empty name present (unique): single IMG(id) 
     15Image by id, name present (multiple): collection(2) IMG(id,name) IMG(id,name) 
     16Image by name, id present (unique): single IMG(id,name) 
    1317 
    1418Nonexistent form name: undefined 
  • trunk/LayoutTests/fast/dom/HTMLDocument/document-special-properties.html

    r11995 r19979  
    3333<img name="image5" width="0" height="0"> 
    3434<img id="image5" width="0" height="0"> 
     35<img id="image6" name="image6name" width="0" height="0"> 
     36<img id="image7" name="" width="0" height="0"> 
     37<img id="image8" name="image8name" width="0" height="0"> 
     38<img id="image8" width="0" height="0"> 
     39<img id="image8" name="image7name" width="0" height="0"> 
     40<img id="image9" name="image9name" width="0" height="0"> 
    3541 
    3642<form name="form1" width="0" height="0"></form> 
     
    151157        print(" " + e.tagName); 
    152158 
    153         if (e.name && e.id) { 
    154             print("(id,name)"); 
    155         } else if (e.name) { 
    156             print("(name)"); 
     159    if (e.name && e.id) { 
     160        print("(id,name)"); 
     161    } else if (e.name) { 
     162        print("(name)"); 
    157163        } else if (e.id) { 
    158             print("(id)"); 
    159         } 
     164        print("(id)"); 
     165    } 
    160166    } else if (e.navigator) { 
    161167        print(" WINDOW"); 
     
    174180    } else if (propVal.length) { 
    175181        print(" collection(" + propVal.length + ")"); 
    176         for (var i = 0; i < propVal.length; i++) { 
    177             printElement(propVal[i]); 
    178         } 
     182    for (var i = 0; i < propVal.length; i++) { 
     183        printElement(propVal[i]); 
     184    } 
    179185    } else { 
    180186        print(" single"); 
    181         printElement(propVal); 
     187    printElement(propVal); 
    182188    } 
    183189     
     
    191197testProperty("Image by id (multiple)", "image4"); 
    192198testProperty("Image by id/name mixed", "image5"); 
     199testProperty("Image by id, name present (unique)", "image6"); 
     200testProperty("Image by id, empty name present (unique)", "image7"); 
     201testProperty("Image by id, name present (multiple)", "image8"); 
     202testProperty("Image by name, id present (unique)", "image9name"); 
     203 
    193204print("<br>"); 
    194205 
  • trunk/WebCore/ChangeLog

    r19978 r19979  
     12007-03-06  Anders Carlsson  <acarlsson@apple.com> 
     2 
     3        Reviewed by Maciej. 
     4 
     5        <rdar://problem/5035045> 
     6        REGRESSION: WebKit browser doesn't display image at http://www.metoffice.gov.uk/weather/satellite/index.html 
     7         
     8        It turns out WinIE does allow you to access images by their id as special document properties. However, this is only 
     9        allowed when the element also has a name attribute. The value of the name attribute is ignored and can even be empty! 
     10         
     11        * bindings/js/kjs_html.cpp: 
     12        (KJS::JSHTMLDocument::namedItemGetter): 
     13        Return jsUndefined() if the collection is empty. 
     14         
     15        * html/HTMLImageElement.cpp: 
     16        (WebCore::HTMLImageElement::parseMappedAttribute): 
     17        (WebCore::HTMLImageElement::insertedIntoDocument): 
     18        (WebCore::HTMLImageElement::removedFromDocument): 
     19        * html/HTMLImageElement.h: 
     20        Add the id attribute value to the extra named item map. 
     21         
     22        * html/HTMLNameCollection.cpp: 
     23        (WebCore::HTMLNameCollection::traverseNextItem): 
     24        Check for images with name attributes that match, as well as elements with id attributes that match where 
     25        the element also has a name attribute. 
     26 
    1272007-03-06  Anders Carlsson  <acarlsson@apple.com> 
    228 
  • trunk/WebCore/bindings/js/kjs_html.cpp

    r19971 r19979  
    208208      return Window::retrieve(frame); 
    209209    return toJS(exec, node); 
    210   } 
     210  } else if (collection->length() == 0) 
     211      return jsUndefined(); 
    211212 
    212213  return getHTMLCollection(exec, collection.get()); 
  • trunk/WebCore/html/HTMLImageElement.cpp

    r18940 r19979  
    140140        } 
    141141        oldNameAttr = newNameAttr; 
     142    } else if (attr->name() == idAttr) { 
     143        String newIdAttr = attr->value(); 
     144        if (inDocument() && document()->isHTMLDocument()) { 
     145            HTMLDocument *doc = static_cast<HTMLDocument *>(document()); 
     146            doc->removeDocExtraNamedItem(oldIdAttr); 
     147            doc->addDocExtraNamedItem(newIdAttr); 
     148        } 
     149        oldIdAttr = newIdAttr; 
     150        // also call superclass 
     151        HTMLElement::parseMappedAttribute(attr); 
    142152    } else 
    143153        HTMLElement::parseMappedAttribute(attr); 
     
    181191void HTMLImageElement::insertedIntoDocument() 
    182192{ 
    183     Document* doc = document(); 
    184     if (doc->isHTMLDocument()) 
    185         static_cast<HTMLDocument*>(doc)->addNamedItem(oldNameAttr); 
     193    if (document()->isHTMLDocument()) { 
     194        HTMLDocument* doc = static_cast<HTMLDocument*>(document()); 
     195 
     196        doc->addNamedItem(oldNameAttr); 
     197        doc->addDocExtraNamedItem(oldIdAttr); 
     198    } 
    186199 
    187200    HTMLElement::insertedIntoDocument(); 
     
    190203void HTMLImageElement::removedFromDocument() 
    191204{ 
    192     Document* doc = document(); 
    193     if (doc->isHTMLDocument()) 
    194         static_cast<HTMLDocument*>(doc)->removeNamedItem(oldNameAttr); 
     205    if (document()->isHTMLDocument()) { 
     206        HTMLDocument* doc = static_cast<HTMLDocument*>(document()); 
     207 
     208        doc->removeNamedItem(oldNameAttr); 
     209        doc->removeDocExtraNamedItem(oldIdAttr); 
     210    } 
    195211 
    196212    HTMLElement::removedFromDocument(); 
  • trunk/WebCore/html/HTMLImageElement.h

    r18940 r19979  
    117117    HTMLFormElement* m_form; 
    118118    String oldNameAttr; 
     119    String oldIdAttr; 
    119120    CompositeOperator m_compositeOperator; 
    120121}; 
  • trunk/WebCore/html/HTMLNameCollection.cpp

    r15006 r19979  
    6767            case DocumentNamedItems: 
    6868                // find images, forms, applets, embeds, objects and iframes by name,  
    69                 // but only applets and object by id (this strange rule matches IE) 
    70                 if (e->hasTagName(imgTag) || 
    71                     e->hasTagName(formTag) || 
     69                // applets and object by id, and images by id but only if they have 
     70                // a name attribute (this very strange rule matches IE) 
     71                if (e->hasTagName(formTag) || 
    7272                    e->hasTagName(embedTag) || 
    7373                    e->hasTagName(iframeTag)) 
     
    7979                    found = (e->getAttribute(nameAttr) == m_name || e->getAttribute(idAttr) == m_name) && 
    8080                        static_cast<HTMLObjectElement*>(e)->isDocNamedItem(); 
     81                else if (e->hasTagName(imgTag)) 
     82                    found = e->getAttribute(nameAttr) == m_name || (e->getAttribute(idAttr) == m_name && e->hasAttribute(nameAttr)); 
    8183                break; 
    8284            default: