Changeset 41120 in webkit


Ignore:
Timestamp:
Feb 20, 2009 4:15:33 PM (15 years ago)
Author:
jchaffraix@webkit.org
Message:

2009-02-20 Julien Chaffraix <jchaffraix@webkit.org>

Reviewed by Alexey Proskuryakov.

Bug 23940: Use Document::createElement(const QualifiedName&, bool) when creating a known element inside WebCore

Document::createElement(const QualifiedName&, bool) does not check for the prefix as opposed the the one taking an AtomicString
or Document::createElementNS. This is perfectly fine internally because we know the type of element created and the check is
unneeded.

It also removes the use of an ExceptionCode argument which was here only to check that the prefix check was fine. Finally it
enables us to use some generated QualifiedName.

  • bindings/js/JSOptionConstructor.cpp: (WebCore::constructHTMLOptionElement):
  • dom/Document.cpp: (WebCore::Document::setTitle):
  • dom/XMLTokenizer.cpp: (WebCore::createXHTMLParserErrorHeader): (WebCore::XMLTokenizer::insertErrorMessageBlock):
  • editing/CompositeEditCommand.cpp: (WebCore::createBlockPlaceholderElement):
  • editing/htmlediting.cpp: (WebCore::createTabSpanElement):
  • html/HTMLSelectElement.cpp: (WebCore::HTMLSelectElement::setLength):
  • loader/FTPDirectoryDocument.cpp: (WebCore::FTPDirectoryTokenizer::appendEntry): (WebCore::FTPDirectoryTokenizer::createTDForFilename): (WebCore::FTPDirectoryTokenizer::loadDocumentTemplate): (WebCore::FTPDirectoryTokenizer::createBasicDocument):
  • loader/ImageDocument.cpp: (WebCore::ImageDocument::createDocumentStructure):
  • loader/MediaDocument.cpp: (WebCore::MediaTokenizer::createDocumentStructure):
  • loader/PluginDocument.cpp: (WebCore::PluginTokenizer::createDocumentStructure):
  • loader/TextDocument.cpp: (WebCore::TextTokenizer::write):
  • page/Frame.cpp: (WebCore::Frame::selectionComputedStyle): (WebCore::Frame::styleForSelectionStart): Document::createElement(const AtomicString&, ...) to Document::createElement(const QualifiedName&, ...) switch.
  • xml/XPathFunctions.cpp: (WebCore::XPath::FunLang::evaluate): Re-use langAttr instead of creating a new attribute.
  • page/DragController.cpp: (WebCore::documentFragmentFromDragData): Use the HTMLAnchorElement directly to get rid of the static cast.
Location:
trunk/WebCore
Files:
15 edited

Legend:

Unmodified
Added
Removed
  • trunk/WebCore/ChangeLog

    r41119 r41120  
     12009-02-20  Julien Chaffraix  <jchaffraix@webkit.org>
     2
     3        Reviewed by Alexey Proskuryakov.
     4
     5        Bug 23940: Use Document::createElement(const QualifiedName&, bool) when creating a known element inside WebCore
     6
     7        Document::createElement(const QualifiedName&, bool) does not check for the prefix as opposed the the one taking an AtomicString
     8        or Document::createElementNS. This is perfectly fine internally because we know the type of element created and the check is
     9        unneeded.
     10
     11        It also removes the use of an ExceptionCode argument which was here only to check that the prefix check was fine. Finally it
     12        enables us to use some generated QualifiedName.
     13
     14        * bindings/js/JSOptionConstructor.cpp:
     15        (WebCore::constructHTMLOptionElement):
     16        * dom/Document.cpp:
     17        (WebCore::Document::setTitle):
     18        * dom/XMLTokenizer.cpp:
     19        (WebCore::createXHTMLParserErrorHeader):
     20        (WebCore::XMLTokenizer::insertErrorMessageBlock):
     21        * editing/CompositeEditCommand.cpp:
     22        (WebCore::createBlockPlaceholderElement):
     23        * editing/htmlediting.cpp:
     24        (WebCore::createTabSpanElement):
     25        * html/HTMLSelectElement.cpp:
     26        (WebCore::HTMLSelectElement::setLength):
     27        * loader/FTPDirectoryDocument.cpp:
     28        (WebCore::FTPDirectoryTokenizer::appendEntry):
     29        (WebCore::FTPDirectoryTokenizer::createTDForFilename):
     30        (WebCore::FTPDirectoryTokenizer::loadDocumentTemplate):
     31        (WebCore::FTPDirectoryTokenizer::createBasicDocument):
     32        * loader/ImageDocument.cpp:
     33        (WebCore::ImageDocument::createDocumentStructure):
     34        * loader/MediaDocument.cpp:
     35        (WebCore::MediaTokenizer::createDocumentStructure):
     36        * loader/PluginDocument.cpp:
     37        (WebCore::PluginTokenizer::createDocumentStructure):
     38        * loader/TextDocument.cpp:
     39        (WebCore::TextTokenizer::write):
     40        * page/Frame.cpp:
     41        (WebCore::Frame::selectionComputedStyle):
     42        (WebCore::Frame::styleForSelectionStart):
     43        Document::createElement(const AtomicString&, ...) to Document::createElement(const QualifiedName&, ...) switch.
     44
     45        * xml/XPathFunctions.cpp:
     46        (WebCore::XPath::FunLang::evaluate): Re-use langAttr instead of creating a new attribute.
     47        * page/DragController.cpp:
     48        (WebCore::documentFragmentFromDragData): Use the HTMLAnchorElement directly to get rid of the static cast.
     49
    1502009-02-19  Dimitri Glazkov  <dglazkov@chromium.org>
    251
  • trunk/WebCore/bindings/js/JSOptionConstructor.cpp

    r40046 r41120  
    2121#include "JSOptionConstructor.h"
    2222
     23#include "HTMLNames.h"
    2324#include "HTMLOptionElement.h"
    2425#include "JSHTMLOptionElement.h"
     
    4748    Document* document = static_cast<JSOptionConstructor*>(constructor)->document();
    4849
     50    RefPtr<HTMLOptionElement> element = static_pointer_cast<HTMLOptionElement>(document->createElement(HTMLNames::optionTag, false));
     51
    4952    ExceptionCode ec = 0;
    50 
    51     RefPtr<HTMLOptionElement> element = static_pointer_cast<HTMLOptionElement>(document->createElement("option", ec));
    52     RefPtr<Text> text;
    53     if (ec == 0)
    54         text = document->createTextNode("");
    55     if (ec == 0 && !args.at(exec, 0).isUndefined())
     53    RefPtr<Text> text = document->createTextNode("");
     54    if (!args.at(exec, 0).isUndefined())
    5655        text->setData(args.at(exec, 0).toString(exec), ec);
    5756    if (ec == 0)
  • trunk/WebCore/dom/Document.cpp

    r41102 r41120  
    970970        else if (!m_titleElement) {
    971971            if (HTMLElement* headElement = head()) {
     972                m_titleElement = createElement(titleTag, false);
    972973                ExceptionCode ec = 0;
    973                 m_titleElement = createElement("title", ec);
    974                 ASSERT(!ec);
    975974                headElement->appendChild(m_titleElement, ec);
    976975                ASSERT(!ec);
  • trunk/WebCore/dom/XMLTokenizer.cpp

    r40087 r41120  
    6565namespace WebCore {
    6666
     67using namespace HTMLNames;
     68
    6769const int maxErrors = 25;
    6870
     
    201203static inline RefPtr<Element> createXHTMLParserErrorHeader(Document* doc, const String& errorMessages)
    202204{
     205    RefPtr<Element> reportElement = doc->createElement(QualifiedName(nullAtom, "parsererror", xhtmlNamespaceURI), false);
     206    reportElement->setAttribute(styleAttr, "display: block; white-space: pre; border: 2px solid #c77; padding: 0 1em 0 1em; margin: 1em; background-color: #fdd; color: black");
     207   
    203208    ExceptionCode ec = 0;
    204     RefPtr<Element> reportElement = doc->createElementNS(HTMLNames::xhtmlNamespaceURI, "parsererror", ec);
    205     reportElement->setAttribute(HTMLNames::styleAttr, "display: block; white-space: pre; border: 2px solid #c77; padding: 0 1em 0 1em; margin: 1em; background-color: #fdd; color: black");
    206    
    207     RefPtr<Element> h3 = doc->createElementNS(HTMLNames::xhtmlNamespaceURI, "h3", ec);
     209    RefPtr<Element> h3 = doc->createElement(h3Tag, false);
    208210    reportElement->appendChild(h3.get(), ec);
    209211    h3->appendChild(doc->createTextNode("This page contains the following errors:"), ec);
    210    
    211     RefPtr<Element> fixed = doc->createElementNS(HTMLNames::xhtmlNamespaceURI, "div", ec);
     212
     213    RefPtr<Element> fixed = doc->createElement(divTag, false);
    212214    reportElement->appendChild(fixed.get(), ec);
    213     fixed->setAttribute(HTMLNames::styleAttr, "font-family:monospace;font-size:12px");
     215    fixed->setAttribute(styleAttr, "font-family:monospace;font-size:12px");
    214216    fixed->appendChild(doc->createTextNode(errorMessages), ec);
    215    
    216     h3 = doc->createElementNS(HTMLNames::xhtmlNamespaceURI, "h3", ec);
     217
     218    h3 = doc->createElement(h3Tag, false);
    217219    reportElement->appendChild(h3.get(), ec);
    218220    h3->appendChild(doc->createTextNode("Below is a rendering of the page up to the first error."), ec);
     
    236238    Node* documentElement = doc->documentElement();
    237239    if (!documentElement) {
    238         RefPtr<Node> rootElement = doc->createElementNS(HTMLNames::xhtmlNamespaceURI, "html", ec);
     240        RefPtr<Node> rootElement = doc->createElement(htmlTag, false);
    239241        doc->appendChild(rootElement, ec);
    240         RefPtr<Node> body = doc->createElementNS(HTMLNames::xhtmlNamespaceURI, "body", ec);
     242        RefPtr<Node> body = doc->createElement(bodyTag, false);
    241243        rootElement->appendChild(body, ec);
    242244        documentElement = body.get();
     
    244246#if ENABLE(SVG)
    245247    else if (documentElement->namespaceURI() == SVGNames::svgNamespaceURI) {
    246         RefPtr<Node> rootElement = doc->createElementNS(HTMLNames::xhtmlNamespaceURI, "html", ec);
    247         RefPtr<Node> body = doc->createElementNS(HTMLNames::xhtmlNamespaceURI, "body", ec);
     248        RefPtr<Node> rootElement = doc->createElement(htmlTag, false);
     249        RefPtr<Node> body = doc->createElement(bodyTag, false);
    248250        rootElement->appendChild(body, ec);
    249251        body->appendChild(documentElement, ec);
     
    254256#if ENABLE(WML)
    255257    else if (isWMLDocument()) {
    256         RefPtr<Node> rootElement = doc->createElementNS(HTMLNames::xhtmlNamespaceURI, "html", ec);
    257         RefPtr<Node> body = doc->createElementNS(HTMLNames::xhtmlNamespaceURI, "body", ec);
     258        RefPtr<Node> rootElement = doc->createElement(htmlTag, false);
     259        RefPtr<Node> body = doc->createElement(bodyTag, false);
    258260        rootElement->appendChild(body, ec);
    259261        body->appendChild(documentElement, ec);
     
    267269#if ENABLE(XSLT)
    268270    if (doc->transformSourceDocument()) {
    269         RefPtr<Element> par = doc->createElementNS(HTMLNames::xhtmlNamespaceURI, "p", ec);
     271        RefPtr<Element> par = doc->createElement(pTag, false);
    270272        reportElement->appendChild(par, ec);
    271         par->setAttribute(HTMLNames::styleAttr, "white-space: normal");
     273        par->setAttribute(styleAttr, "white-space: normal");
    272274        par->appendChild(doc->createTextNode("This document was created as the result of an XSL transformation. The line and column numbers given are from the transformed result."), ec);
    273275    }
  • trunk/WebCore/editing/CompositeEditCommand.cpp

    r41026 r41120  
    10341034PassRefPtr<Element> createBlockPlaceholderElement(Document* document)
    10351035{
    1036     ExceptionCode ec = 0;
    1037     RefPtr<Element> breakNode = document->createElementNS(xhtmlNamespaceURI, "br", ec);
    1038     ASSERT(ec == 0);
     1036    RefPtr<Element> breakNode = document->createElement(brTag, false);
    10391037    return breakNode.release();
    10401038}
  • trunk/WebCore/editing/htmlediting.cpp

    r40793 r41120  
    820820PassRefPtr<Element> createTabSpanElement(Document* document, PassRefPtr<Node> tabTextNode)
    821821{
    822     // make the span to hold the tab
    823     ExceptionCode ec = 0;
    824     RefPtr<Element> spanElement = document->createElementNS(xhtmlNamespaceURI, "span", ec);
    825     ASSERT(ec == 0);
     822    // Make the span to hold the tab.
     823    RefPtr<Element> spanElement = document->createElement(spanTag, false);
    826824    spanElement->setAttribute(classAttr, AppleTabSpanClass);
    827825    spanElement->setAttribute(styleAttr, "white-space:pre");
    828826
    829     // add tab text to that span
     827    // Add tab text to that span.
    830828    if (!tabTextNode)
    831829        tabTextNode = document->createEditingTextNode("\t");
     830
     831    ExceptionCode ec = 0;
    832832    spanElement->appendChild(tabTextNode, ec);
    833833    ASSERT(ec == 0);
  • trunk/WebCore/html/HTMLSelectElement.cpp

    r40804 r41120  
    11041104    if (diff < 0) { // add dummy elements
    11051105        do {
    1106             RefPtr<Element> option = document()->createElement("option", ec);
    1107             if (!option)
    1108                 break;
     1106            RefPtr<Element> option = document()->createElement(optionTag, false);
     1107            ASSERT(option);
    11091108            add(static_cast<HTMLElement*>(option.get()), 0, ec);
    11101109            if (ec)
  • trunk/WebCore/loader/FTPDirectoryDocument.cpp

    r39601 r41120  
    118118    rowElement->setAttribute("class", "ftpDirectoryEntryRow", ec);
    119119   
    120     RefPtr<Element> element = m_doc->createElementNS(xhtmlNamespaceURI, "td", ec);
     120    RefPtr<Element> element = m_doc->createElement(tdTag, false);
    121121    element->appendChild(new Text(m_doc, String(&noBreakSpace, 1)), ec);
    122122    if (isDirectory)
     
    130130    rowElement->appendChild(element, ec);
    131131   
    132     element = m_doc->createElementNS(xhtmlNamespaceURI, "td", ec);
     132    element = m_doc->createElement(tdTag, false);
    133133    element->appendChild(new Text(m_doc, date), ec);
    134134    element->setAttribute("class", "ftpDirectoryFileDate", ec);
    135135    rowElement->appendChild(element, ec);
    136136   
    137     element = m_doc->createElementNS(xhtmlNamespaceURI, "td", ec);
     137    element = m_doc->createElement(tdTag, false);
    138138    element->appendChild(new Text(m_doc, size), ec);
    139139    element->setAttribute("class", "ftpDirectoryFileSize", ec);
     
    151151        fullURL.append("/" + filename);
    152152
    153     RefPtr<Element> anchorElement = m_doc->createElementNS(xhtmlNamespaceURI, "a", ec);
     153    RefPtr<Element> anchorElement = m_doc->createElement(aTag, false);
    154154    anchorElement->setAttribute("href", fullURL, ec);
    155155    anchorElement->appendChild(new Text(m_doc, filename), ec);
    156156   
    157     RefPtr<Element> tdElement = m_doc->createElementNS(xhtmlNamespaceURI, "td", ec);
     157    RefPtr<Element> tdElement = m_doc->createElement(tdTag, false);
    158158    tdElement->appendChild(anchorElement, ec);
    159159   
     
    365365
    366366    // Otherwise create one manually
     367    tableElement = m_doc->createElement(tableTag, false);
     368    m_tableElement = static_cast<HTMLTableElement*>(tableElement.get());
    367369    ExceptionCode ec;       
    368     tableElement = m_doc->createElementNS(xhtmlNamespaceURI, "table", ec);
    369     m_tableElement = static_cast<HTMLTableElement*>(tableElement.get());
    370370    m_tableElement->setAttribute("id", "ftpDirectoryTable", ec);
    371371
     
    387387    // FIXME: Make this "basic document" more acceptable
    388388
     389   
     390    RefPtr<Element> bodyElement = m_doc->createElement(bodyTag, false);
     391                           
    389392    ExceptionCode ec;
    390    
    391     RefPtr<Element> bodyElement = m_doc->createElementNS(xhtmlNamespaceURI, "body", ec);
    392                            
    393393    m_doc->appendChild(bodyElement, ec);
    394394   
    395     RefPtr<Element> tableElement = m_doc->createElementNS(xhtmlNamespaceURI, "table", ec);
     395    RefPtr<Element> tableElement = m_doc->createElement(tableTag, false);
    396396    m_tableElement = static_cast<HTMLTableElement*>(tableElement.get());
    397397    m_tableElement->setAttribute("id", "ftpDirectoryTable", ec);
  • trunk/WebCore/loader/ImageDocument.cpp

    r39601 r41120  
    167167    ExceptionCode ec;
    168168   
    169     RefPtr<Element> rootElement = createElementNS(xhtmlNamespaceURI, "html", ec);
     169    RefPtr<Element> rootElement = Document::createElement(htmlTag, false);
    170170    appendChild(rootElement, ec);
    171171   
    172     RefPtr<Element> body = createElementNS(xhtmlNamespaceURI, "body", ec);
     172    RefPtr<Element> body = Document::createElement(bodyTag, false);
    173173    body->setAttribute(styleAttr, "margin: 0px;");
    174174   
  • trunk/WebCore/loader/MediaDocument.cpp

    r40675 r41120  
    7878{
    7979    ExceptionCode ec;
    80     RefPtr<Element> rootElement = m_doc->createElementNS(xhtmlNamespaceURI, "html", ec);
     80    RefPtr<Element> rootElement = m_doc->createElement(htmlTag, false);
    8181    m_doc->appendChild(rootElement, ec);
    8282       
    83     RefPtr<Element> body = m_doc->createElementNS(xhtmlNamespaceURI, "body", ec);
     83    RefPtr<Element> body = m_doc->createElement(bodyTag, false);
    8484    body->setAttribute(styleAttr, "background-color: rgb(38,38,38);");
    8585
    8686    rootElement->appendChild(body, ec);
    8787       
    88     RefPtr<Element> mediaElement = m_doc->createElementNS(xhtmlNamespaceURI, "video", ec);
     88    RefPtr<Element> mediaElement = m_doc->createElement(videoTag, false);
    8989       
    9090    m_mediaElement = static_cast<HTMLVideoElement*>(mediaElement.get());
  • trunk/WebCore/loader/PluginDocument.cpp

    r39601 r41120  
    7373{
    7474    ExceptionCode ec;
    75     RefPtr<Element> rootElement = m_doc->createElementNS(xhtmlNamespaceURI, "html", ec);
     75    RefPtr<Element> rootElement = m_doc->createElement(htmlTag, false);
    7676    m_doc->appendChild(rootElement, ec);
    77        
    78     RefPtr<Element> body = m_doc->createElementNS(xhtmlNamespaceURI, "body", ec);
     77
     78    RefPtr<Element> body = m_doc->createElement(bodyTag, false);
    7979    body->setAttribute(marginwidthAttr, "0");
    8080    body->setAttribute(marginheightAttr, "0");
     
    8383    rootElement->appendChild(body, ec);
    8484       
    85     RefPtr<Element> embedElement = m_doc->createElementNS(xhtmlNamespaceURI, "embed", ec);
     85    RefPtr<Element> embedElement = m_doc->createElement(embedTag, false);
    8686       
    8787    m_embedElement = static_cast<HTMLEmbedElement*>(embedElement.get());
  • trunk/WebCore/loader/TextDocument.cpp

    r39601 r41120  
    126126
    127127    if (!m_preElement && !inViewSourceMode()) {
    128         RefPtr<Element> rootElement = m_doc->createElementNS(xhtmlNamespaceURI, "html", ec);
     128        RefPtr<Element> rootElement = m_doc->createElement(htmlTag, false);
    129129        m_doc->appendChild(rootElement, ec);
    130130
    131         RefPtr<Element> body = m_doc->createElementNS(xhtmlNamespaceURI, "body", ec);
     131        RefPtr<Element> body = m_doc->createElement(bodyTag, false);
    132132        rootElement->appendChild(body, ec);
    133133
    134         RefPtr<Element> preElement = m_doc->createElementNS(xhtmlNamespaceURI, "pre", ec);
     134        RefPtr<Element> preElement = m_doc->createElement(preTag, false);
    135135        preElement->setAttribute("style", "word-wrap: break-word; white-space: pre-wrap;", ec);
    136136
  • trunk/WebCore/page/DragController.cpp

    r40793 r41120  
    108108            String url = dragData->asURL(&title);
    109109            if (!url.isEmpty()) {
     110                RefPtr<HTMLAnchorElement> anchor = new HTMLAnchorElement(document);
     111                anchor->setHref(url);
    110112                ExceptionCode ec;
    111                 RefPtr<HTMLAnchorElement> anchor = static_cast<HTMLAnchorElement*>(document->createElement("a", ec).get());
    112                 anchor->setHref(url);
    113113                RefPtr<Node> anchorText = document->createTextNode(title);
    114114                anchor->appendChild(anchorText, ec);
  • trunk/WebCore/page/Frame.cpp

    r41066 r41120  
    953953
    954954    if (m_typingStyle) {
    955         styleElement = document()->createElementNS(xhtmlNamespaceURI, "span", ec);
    956         ASSERT(ec == 0);
     955        styleElement = document()->createElement(spanTag, false);
    957956
    958957        styleElement->setAttribute(styleAttr, m_typingStyle->cssText().impl(), ec);
     
    13231322        return node->renderer()->style();
    13241323   
     1324    RefPtr<Element> styleElement = document()->createElement(spanTag, false);
     1325   
    13251326    ExceptionCode ec = 0;
    1326     RefPtr<Element> styleElement = document()->createElementNS(xhtmlNamespaceURI, "span", ec);
    1327     ASSERT(ec == 0);
    1328    
    13291327    String styleText = m_typingStyle->cssText() + " display: inline";
    13301328    styleElement->setAttribute(styleAttr, styleText.impl(), ec);
  • trunk/WebCore/xml/XPathFunctions.cpp

    r40484 r41120  
    540540        NamedAttrMap* attrs = node->attributes();
    541541        if (attrs)
    542             languageAttribute = attrs->getAttributeItem(QualifiedName(nullAtom, "lang", XMLNames::xmlNamespaceURI));
     542            languageAttribute = attrs->getAttributeItem(XMLNames::langAttr);
    543543        if (languageAttribute)
    544544            break;
Note: See TracChangeset for help on using the changeset viewer.