Changeset 66650 in webkit


Ignore:
Timestamp:
Sep 2, 2010 2:10:21 AM (14 years ago)
Author:
eric@webkit.org
Message:

2010-09-02 Eric Seidel <eric@webkit.org>

Reviewed by Dimitri Glazkov.

Share more code between HTMLObjectElement and HTMLEmbedElement
https://bugs.webkit.org/show_bug.cgi?id=45054

This pushes more of HTMLObjectElement code down into
HTMLPlugInImageElement so that it can be shared with HTMLEmbedElement.

I also moved a little code from HTMLPluginElement to HTMLPlugInImageElement
since HTMLAppletElement does not need to share this same widget update logic.
This is a small correction from the previous change.

This patch was originally written in one piece and reviewed by Dimitri.
I'm landing it as two separate changes for easier readability and less
chance of regression.

No functional change, thus no tests.

  • html/HTMLEmbedElement.cpp: (WebCore::HTMLEmbedElement::HTMLEmbedElement): (WebCore::HTMLEmbedElement::mapToEntry): (WebCore::HTMLEmbedElement::parseMappedAttribute): (WebCore::HTMLEmbedElement::rendererIsNeeded): (WebCore::HTMLEmbedElement::attach): (WebCore::HTMLEmbedElement::updateWidget): (WebCore::HTMLEmbedElement::insertedIntoDocument): (WebCore::HTMLEmbedElement::removedFromDocument): (WebCore::HTMLEmbedElement::attributeChanged):
  • html/HTMLEmbedElement.h:
  • html/HTMLObjectElement.cpp: (WebCore::HTMLObjectElement::HTMLObjectElement): (WebCore::HTMLObjectElement::parseMappedAttribute): (WebCore::HTMLObjectElement::rendererIsNeeded): (WebCore::HTMLObjectElement::attach): (WebCore::HTMLObjectElement::updateWidget): (WebCore::HTMLObjectElement::finishParsingChildren): (WebCore::HTMLObjectElement::detach): (WebCore::HTMLObjectElement::insertedIntoDocument): (WebCore::HTMLObjectElement::removedFromDocument): (WebCore::HTMLObjectElement::recalcStyle): (WebCore::HTMLObjectElement::childrenChanged): (WebCore::HTMLObjectElement::renderFallbackContent):
  • html/HTMLObjectElement.h:
  • html/HTMLPlugInElement.cpp:
  • html/HTMLPlugInElement.h:
  • html/HTMLPlugInImageElement.cpp: (WebCore::HTMLPlugInImageElement::HTMLPlugInImageElement): (WebCore::HTMLPlugInImageElement::renderEmbeddedObject):
  • html/HTMLPlugInImageElement.h: (WebCore::HTMLPlugInImageElement::needsWidgetUpdate): (WebCore::HTMLPlugInImageElement::setNeedsWidgetUpdate):
  • loader/SubframeLoader.cpp: (WebCore::SubframeLoader::requestObject): (WebCore::SubframeLoader::loadPlugin):
  • loader/SubframeLoader.h:
  • rendering/RenderEmbeddedObject.cpp: (WebCore::updateWidgetForObjectElement): (WebCore::updateWidgetForEmbedElement):
Location:
trunk/WebCore
Files:
12 edited

Legend:

Unmodified
Added
Removed
  • trunk/WebCore/ChangeLog

    r66649 r66650  
     12010-09-02  Eric Seidel  <eric@webkit.org>
     2
     3        Reviewed by Dimitri Glazkov.
     4
     5        Share more code between HTMLObjectElement and HTMLEmbedElement
     6        https://bugs.webkit.org/show_bug.cgi?id=45054
     7
     8        This pushes more of HTMLObjectElement code down into
     9        HTMLPlugInImageElement so that it can be shared with HTMLEmbedElement.
     10
     11        I also moved a little code from HTMLPluginElement to HTMLPlugInImageElement
     12        since HTMLAppletElement does not need to share this same widget update logic.
     13        This is a small correction from the previous change.
     14
     15        This patch was originally written in one piece and reviewed by Dimitri.
     16        I'm landing it as two separate changes for easier readability and less
     17        chance of regression.
     18
     19        No functional change, thus no tests.
     20
     21        * html/HTMLEmbedElement.cpp:
     22        (WebCore::HTMLEmbedElement::HTMLEmbedElement):
     23        (WebCore::HTMLEmbedElement::mapToEntry):
     24        (WebCore::HTMLEmbedElement::parseMappedAttribute):
     25        (WebCore::HTMLEmbedElement::rendererIsNeeded):
     26        (WebCore::HTMLEmbedElement::attach):
     27        (WebCore::HTMLEmbedElement::updateWidget):
     28        (WebCore::HTMLEmbedElement::insertedIntoDocument):
     29        (WebCore::HTMLEmbedElement::removedFromDocument):
     30        (WebCore::HTMLEmbedElement::attributeChanged):
     31        * html/HTMLEmbedElement.h:
     32        * html/HTMLObjectElement.cpp:
     33        (WebCore::HTMLObjectElement::HTMLObjectElement):
     34        (WebCore::HTMLObjectElement::parseMappedAttribute):
     35        (WebCore::HTMLObjectElement::rendererIsNeeded):
     36        (WebCore::HTMLObjectElement::attach):
     37        (WebCore::HTMLObjectElement::updateWidget):
     38        (WebCore::HTMLObjectElement::finishParsingChildren):
     39        (WebCore::HTMLObjectElement::detach):
     40        (WebCore::HTMLObjectElement::insertedIntoDocument):
     41        (WebCore::HTMLObjectElement::removedFromDocument):
     42        (WebCore::HTMLObjectElement::recalcStyle):
     43        (WebCore::HTMLObjectElement::childrenChanged):
     44        (WebCore::HTMLObjectElement::renderFallbackContent):
     45        * html/HTMLObjectElement.h:
     46        * html/HTMLPlugInElement.cpp:
     47        * html/HTMLPlugInElement.h:
     48        * html/HTMLPlugInImageElement.cpp:
     49        (WebCore::HTMLPlugInImageElement::HTMLPlugInImageElement):
     50        (WebCore::HTMLPlugInImageElement::renderEmbeddedObject):
     51        * html/HTMLPlugInImageElement.h:
     52        (WebCore::HTMLPlugInImageElement::needsWidgetUpdate):
     53        (WebCore::HTMLPlugInImageElement::setNeedsWidgetUpdate):
     54        * loader/SubframeLoader.cpp:
     55        (WebCore::SubframeLoader::requestObject):
     56        (WebCore::SubframeLoader::loadPlugin):
     57        * loader/SubframeLoader.h:
     58        * rendering/RenderEmbeddedObject.cpp:
     59        (WebCore::updateWidgetForObjectElement):
     60        (WebCore::updateWidgetForEmbedElement):
     61
    1622010-09-02  Tony Gentilcore  <tonyg@chromium.org>
    263
  • trunk/WebCore/html/HTMLEmbedElement.cpp

    r66631 r66650  
    4545inline HTMLEmbedElement::HTMLEmbedElement(const QualifiedName& tagName, Document* document)
    4646    : HTMLPlugInImageElement(tagName, document)
    47     , m_needWidgetUpdate(false)
    4847{
    4948    ASSERT(hasTagName(embedTag));
     
    8180    }
    8281       
    83     return HTMLPlugInElement::mapToEntry(attrName, result);
     82    return HTMLPlugInImageElement::mapToEntry(attrName, result);
    8483}
    8584
     
    119118        m_name = value;
    120119    } else
    121         HTMLPlugInElement::parseMappedAttribute(attr);
     120        HTMLPlugInImageElement::parseMappedAttribute(attr);
    122121}
    123122
     
    125124{
    126125    if (isImageType())
    127         return HTMLPlugInElement::rendererIsNeeded(style);
     126        return HTMLPlugInImageElement::rendererIsNeeded(style);
    128127
    129128    Frame* frame = document()->frame();
     
    150149#endif
    151150
    152     return HTMLPlugInElement::rendererIsNeeded(style);
     151    return HTMLPlugInImageElement::rendererIsNeeded(style);
    153152}
    154153
     
    165164void HTMLEmbedElement::attach()
    166165{
    167     m_needWidgetUpdate = true;
     166    setNeedsWidgetUpdate(true);
    168167
    169168    bool isImage = isImageType();
    170169
    171170    if (!isImage)
    172         queuePostAttachCallback(&HTMLPlugInElement::updateWidgetCallback, this);
    173 
    174     HTMLPlugInElement::attach();
     171        queuePostAttachCallback(&HTMLPlugInImageElement::updateWidgetCallback, this);
     172
     173    HTMLPlugInImageElement::attach();
    175174
    176175    if (isImage && renderer()) {
     
    187186{
    188187    document()->updateStyleIfNeeded();
    189     if (m_needWidgetUpdate && renderEmbeddedObject() && !isImageType())
     188    if (needsWidgetUpdate() && renderEmbeddedObject() && !isImageType())
    190189        renderEmbeddedObject()->updateWidget(true);
    191190}
     
    210209    }
    211210
    212     HTMLPlugInElement::insertedIntoDocument();
     211    HTMLPlugInImageElement::insertedIntoDocument();
    213212}
    214213
     
    218217        static_cast<HTMLDocument*>(document())->removeNamedItem(m_name);
    219218
    220     HTMLPlugInElement::removedFromDocument();
     219    HTMLPlugInImageElement::removedFromDocument();
    221220}
    222221
    223222void HTMLEmbedElement::attributeChanged(Attribute* attr, bool preserveDecls)
    224223{
    225     HTMLPlugInElement::attributeChanged(attr, preserveDecls);
     224    HTMLPlugInImageElement::attributeChanged(attr, preserveDecls);
    226225
    227226    if ((attr->name() == widthAttr || attr->name() == heightAttr) && !attr->isEmpty()) {
  • trunk/WebCore/html/HTMLEmbedElement.h

    r66057 r66650  
    3232    static PassRefPtr<HTMLEmbedElement> create(const QualifiedName&, Document*);
    3333
    34     void setNeedWidgetUpdate(bool needWidgetUpdate) { m_needWidgetUpdate = needWidgetUpdate; }
    35 
    3634private:
    3735    HTMLEmbedElement(const QualifiedName&, Document*);
     
    5654
    5755    virtual void addSubresourceAttributeURLs(ListHashSet<KURL>&) const;
    58 
    59     bool m_needWidgetUpdate;
    6056};
    6157
  • trunk/WebCore/html/HTMLObjectElement.cpp

    r66631 r66650  
    4949    : HTMLPlugInImageElement(tagName, document)
    5050    , m_docNamedItem(true)
    51     , m_needWidgetUpdate(!createdByParser)
    5251    , m_useFallbackContent(false)
    5352{
     53    // HTMLObjectElement tries to delay updating its widget while parsing until
     54    // after all of its children are parsed.
     55    setNeedsWidgetUpdate(!createdByParser);
    5456    ASSERT(hasTagName(objectTag));
    5557}
     
    6870void HTMLObjectElement::parseMappedAttribute(Attribute* attr)
    6971{
    70     String val = attr->value();
    71     size_t pos;
    7272    if (attr->name() == typeAttr) {
    73         m_serviceType = val.lower();
    74         pos = m_serviceType.find(";");
     73        m_serviceType = attr->value().lower();
     74        size_t pos = m_serviceType.find(";");
    7575        if (pos != notFound)
    76           m_serviceType = m_serviceType.left(pos);
     76            m_serviceType = m_serviceType.left(pos);
    7777        if (renderer())
    78           m_needWidgetUpdate = true;
     78            setNeedsWidgetUpdate(true);
    7979        if (!isImageType() && m_imageLoader)
    80           m_imageLoader.clear();
     80            m_imageLoader.clear();
    8181    } else if (attr->name() == dataAttr) {
    82         m_url = deprecatedParseURL(val);
     82        m_url = deprecatedParseURL(attr->value());
     83        if (renderer()) {
     84            setNeedsWidgetUpdate(true);
     85            if (isImageType()) {
     86                if (!m_imageLoader)
     87                    m_imageLoader = adoptPtr(new HTMLImageLoader(this));
     88                m_imageLoader->updateFromElementIgnoringPreviousError();
     89            }
     90        }
     91    } else if (attr->name() == classidAttr) {
     92        m_classId = attr->value();
    8393        if (renderer())
    84           m_needWidgetUpdate = true;
    85         if (renderer() && isImageType()) {
    86           if (!m_imageLoader)
    87               m_imageLoader = adoptPtr(new HTMLImageLoader(this));
    88           m_imageLoader->updateFromElementIgnoringPreviousError();
    89         }
    90     } else if (attr->name() == classidAttr) {
    91         m_classId = val;
    92         if (renderer())
    93           m_needWidgetUpdate = true;
     94            setNeedsWidgetUpdate(true);
    9495    } else if (attr->name() == onloadAttr)
    9596        setAttributeEventListener(eventNames().loadEvent, createAttributeEventListener(this, attr));
     
    113114        m_id = newId;
    114115        // also call superclass
    115         HTMLPlugInElement::parseMappedAttribute(attr);
     116        HTMLPlugInImageElement::parseMappedAttribute(attr);
    116117    } else
    117         HTMLPlugInElement::parseMappedAttribute(attr);
     118        HTMLPlugInImageElement::parseMappedAttribute(attr);
    118119}
    119120
     
    128129    // for the object element.
    129130    bool isGearsPlugin = equalIgnoringCase(getAttribute(typeAttr), "application/x-googlegears");
    130     return isGearsPlugin || HTMLPlugInElement::rendererIsNeeded(style);
     131    return isGearsPlugin || HTMLPlugInImageElement::rendererIsNeeded(style);
    131132}
    132133
     
    151152
    152153    if (!isImage)
    153         queuePostAttachCallback(&HTMLPlugInElement::updateWidgetCallback, this);
    154 
    155     HTMLPlugInElement::attach();
     154        queuePostAttachCallback(&HTMLPlugInImageElement::updateWidgetCallback, this);
     155
     156    HTMLPlugInImageElement::attach();
    156157
    157158    if (isImage && renderer() && !m_useFallbackContent) {
     
    165166{
    166167    document()->updateStyleIfNeeded();
    167     if (m_needWidgetUpdate && renderEmbeddedObject() && !m_useFallbackContent && !isImageType())
     168    if (needsWidgetUpdate() && renderEmbeddedObject() && !m_useFallbackContent && !isImageType())
    168169        renderEmbeddedObject()->updateWidget(true);
    169170}
     
    171172void HTMLObjectElement::finishParsingChildren()
    172173{
    173     HTMLPlugInElement::finishParsingChildren();
     174    HTMLPlugInImageElement::finishParsingChildren();
    174175    if (!m_useFallbackContent) {
    175         m_needWidgetUpdate = true;
     176        setNeedsWidgetUpdate(true);
    176177        if (inDocument())
    177178            setNeedsStyleRecalc();
     
    183184    if (attached() && renderer() && !m_useFallbackContent)
    184185        // Update the widget the next time we attach (detaching destroys the plugin).
    185         m_needWidgetUpdate = true;
    186     HTMLPlugInElement::detach();
     186        setNeedsWidgetUpdate(true);
     187    HTMLPlugInImageElement::detach();
    187188}
    188189
     
    195196    }
    196197
    197     HTMLPlugInElement::insertedIntoDocument();
     198    HTMLPlugInImageElement::insertedIntoDocument();
    198199}
    199200
     
    206207    }
    207208
    208     HTMLPlugInElement::removedFromDocument();
     209    HTMLPlugInImageElement::removedFromDocument();
    209210}
    210211
    211212void HTMLObjectElement::recalcStyle(StyleChange ch)
    212213{
    213     if (!m_useFallbackContent && m_needWidgetUpdate && renderer() && !isImageType()) {
     214    if (!m_useFallbackContent && needsWidgetUpdate() && renderer() && !isImageType()) {
    214215        detach();
    215216        attach();
    216217    }
    217     HTMLPlugInElement::recalcStyle(ch);
     218    HTMLPlugInImageElement::recalcStyle(ch);
    218219}
    219220
     
    222223    updateDocNamedItem();
    223224    if (inDocument() && !m_useFallbackContent) {
    224         m_needWidgetUpdate = true;
     225        setNeedsWidgetUpdate(true);
    225226        setNeedsStyleRecalc();
    226227    }
    227     HTMLPlugInElement::childrenChanged(changedByParser, beforeChange, afterChange, childCountDelta);
     228    HTMLPlugInImageElement::childrenChanged(changedByParser, beforeChange, afterChange, childCountDelta);
    228229}
    229230
     
    258259    }
    259260
    260     // Mark ourselves as using the fallback content.
    261261    m_useFallbackContent = true;
    262262
    263     // Now do a detach and reattach.   
    264263    // FIXME: Style gets recalculated which is suboptimal.
    265264    detach();
  • trunk/WebCore/html/HTMLObjectElement.h

    r66156 r66650  
    3131public:
    3232    static PassRefPtr<HTMLObjectElement> create(const QualifiedName&, Document*, bool createdByParser);
    33 
    34     void setNeedWidgetUpdate(bool needWidgetUpdate) { m_needWidgetUpdate = needWidgetUpdate; }
    3533
    3634    void renderFallbackContent();
     
    7573    String m_classId;
    7674    bool m_docNamedItem : 1;
    77     bool m_needWidgetUpdate : 1;
    7875    bool m_useFallbackContent : 1;
    7976};
  • trunk/WebCore/html/HTMLPlugInElement.cpp

    r66631 r66650  
    8080
    8181    HTMLFrameOwnerElement::detach();
    82 }
    83 
    84 RenderEmbeddedObject* HTMLPlugInElement::renderEmbeddedObject() const
    85 {
    86     // HTMLObjectElement and HTMLEmbedElement may return arbitrary renderers
    87     // when using fallback content.
    88     if (!renderer() || !renderer()->isEmbeddedObject())
    89         return 0;
    90     return toRenderEmbeddedObject(renderer());
    9182}
    9283
  • trunk/WebCore/html/HTMLPlugInElement.h

    r66631 r66650  
    5252    void setIsCapturingMouseEvents(bool capturing) { m_isCapturingMouseEvents = capturing; }
    5353
    54     RenderEmbeddedObject* renderEmbeddedObject() const;
    55 
    5654protected:
    5755    HTMLPlugInElement(const QualifiedName& tagName, Document*);
  • trunk/WebCore/html/HTMLPlugInImageElement.cpp

    r57109 r66650  
    2727#include "HTMLImageLoader.h"
    2828#include "Image.h"
     29#include "RenderEmbeddedObject.h"
    2930
    3031namespace WebCore {
     
    3233HTMLPlugInImageElement::HTMLPlugInImageElement(const QualifiedName& tagName, Document* document)
    3334    : HTMLPlugInElement(tagName, document)
     35    , m_needsWidgetUpdate(false)
    3436{
     37}
     38
     39RenderEmbeddedObject* HTMLPlugInImageElement::renderEmbeddedObject() const
     40{
     41    // HTMLObjectElement and HTMLEmbedElement may return arbitrary renderers
     42    // when using fallback content.
     43    if (!renderer() || !renderer()->isEmbeddedObject())
     44        return 0;
     45    return toRenderEmbeddedObject(renderer());
    3546}
    3647
  • trunk/WebCore/html/HTMLPlugInImageElement.h

    r57109 r66650  
    2929class HTMLImageLoader;
    3030
     31// Base class for HTMLObjectElement and HTMLEmbedElement
    3132class HTMLPlugInImageElement : public HTMLPlugInElement {
    3233public:
     
    3435    const String& url() const { return m_url; }
    3536
     37    bool needsWidgetUpdate() const { return m_needsWidgetUpdate; }
     38    void setNeedsWidgetUpdate(bool needsWidgetUpdate) { m_needsWidgetUpdate = needsWidgetUpdate; }
     39
     40    RenderEmbeddedObject* renderEmbeddedObject() const;
     41   
    3642protected:
    3743    HTMLPlugInImageElement(const QualifiedName& tagName, Document*);
     
    4551private:
    4652    virtual void willMoveToNewOwnerDocument();
     53
     54    bool m_needsWidgetUpdate;
    4755};
    4856
  • trunk/WebCore/loader/SubframeLoader.cpp

    r66631 r66650  
    3939#include "HTMLFrameElementBase.h"
    4040#include "HTMLNames.h"
    41 #include "HTMLPlugInElement.h"
     41#include "HTMLPlugInImageElement.h"
    4242#include "MIMETypeRegistry.h"
    4343#include "Node.h"
     
    9090}
    9191
    92 bool SubframeLoader::requestObject(HTMLPlugInElement* ownerElement, const String& url, const AtomicString& frameName,
     92bool SubframeLoader::requestObject(HTMLPlugInImageElement* ownerElement, const String& url, const AtomicString& frameName,
    9393    const String& mimeType, const Vector<String>& paramNames, const Vector<String>& paramValues)
    9494{
     
    125125
    126126        ASSERT(ownerElement->hasTagName(objectTag) || ownerElement->hasTagName(embedTag));
    127         HTMLPlugInElement* pluginElement = static_cast<HTMLPlugInElement*>(ownerElement);
     127        HTMLPlugInImageElement* pluginElement = static_cast<HTMLPlugInImageElement*>(ownerElement);
    128128
    129129        return loadPlugin(pluginElement, completedURL, mimeType, paramNames, paramValues, useFallback);
     
    329329}
    330330
    331 bool SubframeLoader::loadPlugin(HTMLPlugInElement* pluginElement, const KURL& url, const String& mimeType,
     331bool SubframeLoader::loadPlugin(HTMLPlugInImageElement* pluginElement, const KURL& url, const String& mimeType,
    332332    const Vector<String>& paramNames, const Vector<String>& paramValues, bool useFallback)
    333333{
  • trunk/WebCore/loader/SubframeLoader.h

    r66631 r66650  
    4646class HTMLAppletElement;
    4747class HTMLFrameOwnerElement;
    48 class HTMLPlugInElement;
     48class HTMLPlugInImageElement;
    4949class IntSize;
    5050class KURL;
     
    6262
    6363    bool requestFrame(HTMLFrameOwnerElement*, const String& url, const AtomicString& frameName, bool lockHistory = true, bool lockBackForwardList = true);   
    64     bool requestObject(HTMLPlugInElement*, const String& url, const AtomicString& frameName,
     64    bool requestObject(HTMLPlugInImageElement*, const String& url, const AtomicString& frameName,
    6565        const String& serviceType, const Vector<String>& paramNames, const Vector<String>& paramValues);
    6666
     
    8080    Frame* loadOrRedirectSubframe(HTMLFrameOwnerElement*, const KURL&, const AtomicString& frameName, bool lockHistory, bool lockBackForwardList);
    8181    Frame* loadSubframe(HTMLFrameOwnerElement*, const KURL&, const String& name, const String& referrer);
    82     bool loadPlugin(HTMLPlugInElement*, const KURL&, const String& mimeType,
     82    bool loadPlugin(HTMLPlugInImageElement*, const KURL&, const String& mimeType,
    8383        const Vector<String>& paramNames, const Vector<String>& paramValues, bool useFallback);
    8484
  • trunk/WebCore/rendering/RenderEmbeddedObject.cpp

    r66631 r66650  
    256256static void updateWidgetForObjectElement(HTMLObjectElement* objectElement, bool onlyCreateNonNetscapePlugins)
    257257{
    258     objectElement->setNeedWidgetUpdate(false);
     258    objectElement->setNeedsWidgetUpdate(false);
    259259    if (!objectElement->isFinishedParsingChildren())
    260260        return;
     
    312312    String serviceType = embedElement->serviceType();
    313313
    314     embedElement->setNeedWidgetUpdate(false);
     314    embedElement->setNeedsWidgetUpdate(false);
    315315
    316316    if (url.isEmpty() && serviceType.isEmpty())
Note: See TracChangeset for help on using the changeset viewer.