summaryrefslogtreecommitdiffstats
path: root/WebCore/dom
diff options
context:
space:
mode:
authorKristian Monsen <kristianm@google.com>2010-06-28 16:42:48 +0100
committerKristian Monsen <kristianm@google.com>2010-07-02 10:29:56 +0100
commit06ea8e899e48f1f2f396b70e63fae369f2f23232 (patch)
tree20c1428cd05c76f32394ab354ea35ed99acd86d8 /WebCore/dom
parent72aad67af14193199e29cdd5c4ddc095a8b9a8a8 (diff)
downloadexternal_webkit-06ea8e899e48f1f2f396b70e63fae369f2f23232.zip
external_webkit-06ea8e899e48f1f2f396b70e63fae369f2f23232.tar.gz
external_webkit-06ea8e899e48f1f2f396b70e63fae369f2f23232.tar.bz2
Merge WebKit at r61871: Initial merge by git.
Change-Id: I6cff43abca9cc4782e088a469ad4f03f166a65d5
Diffstat (limited to 'WebCore/dom')
-rw-r--r--WebCore/dom/DOMImplementation.cpp40
-rw-r--r--WebCore/dom/DOMImplementation.h3
-rw-r--r--WebCore/dom/Document.cpp75
-rw-r--r--WebCore/dom/Document.h17
-rw-r--r--WebCore/dom/DocumentFragment.cpp24
-rw-r--r--WebCore/dom/DocumentFragment.h6
-rw-r--r--WebCore/dom/DocumentParser.h133
-rw-r--r--WebCore/dom/Element.cpp55
-rw-r--r--WebCore/dom/Element.h12
-rw-r--r--WebCore/dom/ExceptionCode.cpp40
-rw-r--r--WebCore/dom/ExceptionCode.h7
-rw-r--r--WebCore/dom/FragmentScriptingPermission.h40
-rw-r--r--WebCore/dom/InputElement.h3
-rw-r--r--WebCore/dom/MappedAttributeEntry.h2
-rw-r--r--WebCore/dom/MessageChannel.idl10
-rw-r--r--WebCore/dom/Node.cpp15
-rw-r--r--WebCore/dom/Node.h5
-rw-r--r--WebCore/dom/NodeFilter.idl8
-rw-r--r--WebCore/dom/Position.cpp2
-rw-r--r--WebCore/dom/Position.h2
-rw-r--r--WebCore/dom/PositionIterator.cpp2
-rw-r--r--WebCore/dom/RawDataDocumentParser.h75
-rw-r--r--WebCore/dom/ScriptElement.cpp14
-rw-r--r--WebCore/dom/ScriptElement.h4
-rw-r--r--WebCore/dom/SelectElement.cpp9
-rw-r--r--WebCore/dom/StaticHashSetNodeList.cpp66
-rw-r--r--WebCore/dom/StaticHashSetNodeList.h70
-rw-r--r--WebCore/dom/Touch.h6
-rw-r--r--WebCore/dom/TouchList.h6
-rw-r--r--WebCore/dom/XMLDocumentParser.cpp26
-rw-r--r--WebCore/dom/XMLDocumentParser.h46
-rw-r--r--WebCore/dom/XMLDocumentParserLibxml2.cpp78
-rw-r--r--WebCore/dom/XMLDocumentParserQt.cpp60
-rw-r--r--WebCore/dom/XMLDocumentParserScope.h6
34 files changed, 729 insertions, 238 deletions
diff --git a/WebCore/dom/DOMImplementation.cpp b/WebCore/dom/DOMImplementation.cpp
index 4b7a743..3483b23 100644
--- a/WebCore/dom/DOMImplementation.cpp
+++ b/WebCore/dom/DOMImplementation.cpp
@@ -227,18 +227,18 @@ PassRefPtr<Document> DOMImplementation::createDocument(const String& namespaceUR
RefPtr<Document> doc;
#if ENABLE(SVG)
if (namespaceURI == SVGNames::svgNamespaceURI)
- doc = SVGDocument::create(0);
+ doc = SVGDocument::create(0, KURL());
else
#endif
#if ENABLE(WML)
if (namespaceURI == WMLNames::wmlNamespaceURI)
- doc = WMLDocument::create(0);
+ doc = WMLDocument::create(0, KURL());
else
#endif
if (namespaceURI == HTMLNames::xhtmlNamespaceURI)
- doc = Document::createXHTML(0);
+ doc = Document::createXHTML(0, KURL());
else
- doc = Document::create(0);
+ doc = Document::create(0, KURL());
RefPtr<Node> documentElement;
if (!qualifiedName.isEmpty()) {
@@ -295,63 +295,63 @@ bool DOMImplementation::isTextMIMEType(const String& mimeType)
PassRefPtr<HTMLDocument> DOMImplementation::createHTMLDocument(const String& title)
{
- RefPtr<HTMLDocument> d = HTMLDocument::create(0);
+ RefPtr<HTMLDocument> d = HTMLDocument::create(0, KURL());
d->open();
d->write("<!doctype html><html><body></body></html>");
d->setTitle(title);
return d.release();
}
-PassRefPtr<Document> DOMImplementation::createDocument(const String& type, Frame* frame, bool inViewSourceMode)
+PassRefPtr<Document> DOMImplementation::createDocument(const String& type, Frame* frame, const KURL& url, bool inViewSourceMode)
{
if (inViewSourceMode)
- return HTMLViewSourceDocument::create(frame, type);
+ return HTMLViewSourceDocument::create(frame, url, type);
// Plugins cannot take HTML and XHTML from us, and we don't even need to initialize the plugin database for those.
if (type == "text/html")
- return HTMLDocument::create(frame);
+ return HTMLDocument::create(frame, url);
if (type == "application/xhtml+xml"
#if ENABLE(XHTMLMP)
|| type == "application/vnd.wap.xhtml+xml"
#endif
)
- return Document::createXHTML(frame);
+ return Document::createXHTML(frame, url);
#if ENABLE(WML)
if (type == "text/vnd.wap.wml" || type == "application/vnd.wap.wmlc")
- return WMLDocument::create(frame);
+ return WMLDocument::create(frame, url);
#endif
#if ENABLE(FTPDIR)
// Plugins cannot take FTP from us either
if (type == "application/x-ftp-directory")
- return FTPDirectoryDocument::create(frame);
+ return FTPDirectoryDocument::create(frame, url);
#endif
PluginData* pluginData = 0;
- if (frame && frame->page() && frame->loader()->allowPlugins(NotAboutToInstantiatePlugin))
+ if (frame && frame->page() && frame->loader()->subframeLoader()->allowPlugins(NotAboutToInstantiatePlugin))
pluginData = frame->page()->pluginData();
// PDF is one image type for which a plugin can override built-in support.
// We do not want QuickTime to take over all image types, obviously.
if ((type == "application/pdf" || type == "text/pdf") && pluginData && pluginData->supportsMimeType(type))
- return PluginDocument::create(frame);
+ return PluginDocument::create(frame, url);
if (Image::supportsType(type))
- return ImageDocument::create(frame);
+ return ImageDocument::create(frame, url);
#if ENABLE(VIDEO)
// Check to see if the type can be played by our MediaPlayer, if so create a MediaDocument
if (MediaPlayer::supportsType(ContentType(type)))
- return MediaDocument::create(frame);
+ return MediaDocument::create(frame, url);
#endif
// Everything else except text/plain can be overridden by plugins. In particular, Adobe SVG Viewer should be used for SVG, if installed.
// Disallowing plug-ins to use text/plain prevents plug-ins from hijacking a fundamental type that the browser is expected to handle,
// and also serves as an optimization to prevent loading the plug-in database in the common case.
if (type != "text/plain" && pluginData && pluginData->supportsMimeType(type))
- return PluginDocument::create(frame);
+ return PluginDocument::create(frame, url);
if (isTextMIMEType(type))
- return TextDocument::create(frame);
+ return TextDocument::create(frame, url);
#if ENABLE(SVG)
if (type == "image/svg+xml") {
@@ -359,13 +359,13 @@ PassRefPtr<Document> DOMImplementation::createDocument(const String& type, Frame
Settings* settings = frame ? frame->settings() : 0;
if (!settings || !settings->usesDashboardBackwardCompatibilityMode())
#endif
- return SVGDocument::create(frame);
+ return SVGDocument::create(frame, url);
}
#endif
if (isXMLMIMEType(type))
- return Document::create(frame);
+ return Document::create(frame, url);
- return HTMLDocument::create(frame);
+ return HTMLDocument::create(frame, url);
}
}
diff --git a/WebCore/dom/DOMImplementation.h b/WebCore/dom/DOMImplementation.h
index b776d22..c3d5658 100644
--- a/WebCore/dom/DOMImplementation.h
+++ b/WebCore/dom/DOMImplementation.h
@@ -34,6 +34,7 @@ class Document;
class DocumentType;
class Frame;
class HTMLDocument;
+class KURL;
class String;
typedef int ExceptionCode;
@@ -56,7 +57,7 @@ public:
static PassRefPtr<HTMLDocument> createHTMLDocument(const String& title);
// Other methods (not part of DOM)
- static PassRefPtr<Document> createDocument(const String& MIMEType, Frame*, bool inViewSourceMode);
+ static PassRefPtr<Document> createDocument(const String& MIMEType, Frame*, const KURL&, bool inViewSourceMode);
static bool isXMLMIMEType(const String& MIMEType);
static bool isTextMIMEType(const String& MIMEType);
diff --git a/WebCore/dom/Document.cpp b/WebCore/dom/Document.cpp
index c41b87e..c9a2182 100644
--- a/WebCore/dom/Document.cpp
+++ b/WebCore/dom/Document.cpp
@@ -76,10 +76,10 @@
#include "HTMLMapElement.h"
#include "HTMLNameCollection.h"
#include "HTMLNames.h"
-#include "LegacyHTMLTreeConstructor.h"
+#include "LegacyHTMLTreeBuilder.h"
#include "HTMLStyleElement.h"
#include "HTMLTitleElement.h"
-#include "HTMLDocumentParser.h"
+#include "LegacyHTMLDocumentParser.h"
#include "HTTPParsers.h"
#include "HistoryItem.h"
#include "HitTestRequest.h"
@@ -372,7 +372,7 @@ private:
Document* m_document;
};
-Document::Document(Frame* frame, bool isXHTML, bool isHTML)
+Document::Document(Frame* frame, const KURL& url, bool isXHTML, bool isHTML)
: ContainerNode(0)
, m_domtree_version(0)
, m_styleSheets(StyleSheetList::create(this))
@@ -431,7 +431,13 @@ Document::Document(Frame* frame, bool isXHTML, bool isHTML)
m_frame = frame;
+<<<<<<< HEAD
#if !PLATFORM(ANDROID)
+=======
+ if (frame || !url.isEmpty())
+ setURL(url);
+
+>>>>>>> webkit.org at r61871
m_axObjectCache = 0;
#endif
@@ -1534,6 +1540,43 @@ PassRefPtr<RenderStyle> Document::styleForElementIgnoringPendingStylesheets(Elem
return style.release();
}
+PassRefPtr<RenderStyle> Document::styleForPage(int pageIndex)
+{
+ RefPtr<RenderStyle> style = styleSelector()->styleForPage(pageIndex);
+ return style.release();
+}
+
+bool Document::isPageBoxVisible(int pageIndex)
+{
+ RefPtr<RenderStyle> style = styleForPage(pageIndex);
+ return style->visibility() != HIDDEN; // display property doesn't apply to @page.
+}
+
+IntRect Document::pageAreaRectInPixels(int pageIndex)
+{
+ RefPtr<RenderStyle> style = styleForPage(pageIndex);
+ IntSize pageSize = preferredPageSizeInPixels(pageIndex);
+ // 100% value for margin-{left,right,top,bottom}. This is used also for top and bottom. http://www.w3.org/TR/CSS2/box.html#value-def-margin-width
+ int maxValue = pageSize.width();
+ int surroundLeft = style->marginLeft().calcValue(maxValue) + style->borderLeft().width() + style->paddingLeft().calcValue(maxValue);
+ int surroundRight = style->marginRight().calcValue(maxValue) + style->borderRight().width() + style->paddingRight().calcValue(maxValue);
+ int surroundTop = style->marginTop().calcValue(maxValue) + style->borderTop().width() + style->paddingTop().calcValue(maxValue);
+ int surroundBottom = style->marginBottom().calcValue(maxValue) + style->borderBottom().width() + style->paddingBottom().calcValue(maxValue);
+ int width = pageSize.width() - surroundLeft - surroundRight;
+ int height = pageSize.height() - surroundTop - surroundBottom;
+
+ return IntRect(surroundLeft, surroundTop, width, height);
+}
+
+IntSize Document::preferredPageSizeInPixels(int pageIndex)
+{
+ RefPtr<RenderStyle> style = styleForPage(pageIndex);
+ LengthSize size = style->pageSize();
+ ASSERT(size.width().isFixed());
+ ASSERT(size.height().isFixed());
+ return IntSize(size.width().calcValue(0), size.height().calcValue(0));
+}
+
void Document::createStyleSelector()
{
bool matchAuthorAndUserStyles = true;
@@ -1723,7 +1766,7 @@ void Document::open(Document* ownerDocument)
}
if (m_frame) {
- if (m_frame->loader()->isLoadingMainResource() || (parser() && parser()->executingScript()))
+ if (m_frame->loader()->isLoadingMainResource() || (parser() && parser()->isExecutingScript()))
return;
if (m_frame->loader()->state() == FrameStateProvisional)
@@ -2000,12 +2043,16 @@ void Document::write(const SegmentedString& text, Document* ownerDocument)
printf("Beginning a document.write at %d\n", elapsedTime());
#endif
- if (!m_parser)
+ if (!m_parser || m_parser->finishWasCalled())
open(ownerDocument);
ASSERT(m_parser);
+ // FIXME: forceSynchronous should always be the same as the bool passed to
+ // write(). However LegacyHTMLDocumentParser uses write("", false) to pump
+ // the parser (after running external scripts, etc.) thus necessitating a
+ // separate state for forceSynchronous.
bool wasForcedSynchronous = false;
- HTMLDocumentParser* parser = m_parser->asHTMLDocumentParser();
+ LegacyHTMLDocumentParser* parser = m_parser->asHTMLDocumentParser();
if (parser) {
wasForcedSynchronous = parser->forceSynchronous();
parser->setForceSynchronous(true);
@@ -4630,9 +4677,8 @@ void Document::initSecurityContext()
// In the common case, create the security context from the currently
// loading URL.
- const KURL& url = m_frame->loader()->url();
- m_cookieURL = url;
- ScriptExecutionContext::setSecurityOrigin(SecurityOrigin::create(url, m_frame->loader()->sandboxFlags()));
+ m_cookieURL = m_url;
+ ScriptExecutionContext::setSecurityOrigin(SecurityOrigin::create(m_url, m_frame->loader()->sandboxFlags()));
if (SecurityOrigin::allowSubstituteDataAccessToLocal()) {
// If this document was loaded with substituteData, then the document can
@@ -4790,6 +4836,17 @@ void Document::executeScriptSoon(ScriptElementData* data, CachedResourceHandle<C
m_executeScriptSoonTimer.startOneShot(0);
}
+void Document::suspendExecuteScriptSoonTimer()
+{
+ m_executeScriptSoonTimer.stop();
+}
+
+void Document::resumeExecuteScriptSoonTimer()
+{
+ if (!m_scriptsToExecuteSoon.isEmpty())
+ m_executeScriptSoonTimer.startOneShot(0);
+}
+
// FF method for accessing the selection added for compatibility.
DOMSelection* Document::getSelection() const
{
diff --git a/WebCore/dom/Document.h b/WebCore/dom/Document.h
index 0e86df4..dc4b6ba 100644
--- a/WebCore/dom/Document.h
+++ b/WebCore/dom/Document.h
@@ -185,13 +185,13 @@ enum PageshowEventPersistence {
class Document : public ContainerNode, public ScriptExecutionContext {
public:
- static PassRefPtr<Document> create(Frame* frame)
+ static PassRefPtr<Document> create(Frame* frame, const KURL& url)
{
- return adoptRef(new Document(frame, false, false));
+ return adoptRef(new Document(frame, url, false, false));
}
- static PassRefPtr<Document> createXHTML(Frame* frame)
+ static PassRefPtr<Document> createXHTML(Frame* frame, const KURL& url)
{
- return adoptRef(new Document(frame, true, false));
+ return adoptRef(new Document(frame, url, true, false));
}
virtual ~Document();
@@ -482,6 +482,10 @@ public:
void updateLayout();
void updateLayoutIgnorePendingStylesheets();
PassRefPtr<RenderStyle> styleForElementIgnoringPendingStylesheets(Element*);
+ PassRefPtr<RenderStyle> styleForPage(int pageIndex);
+ bool isPageBoxVisible(int pageIndex);
+ IntRect pageAreaRectInPixels(int pageIndex);
+ IntSize preferredPageSizeInPixels(int pageIndex);
static void updateStyleForAllDocuments(); // FIXME: Try to reduce the # of calls to this function.
DocLoader* docLoader() { return m_docLoader.get(); }
@@ -823,6 +827,9 @@ public:
void executeScriptSoon(ScriptElementData*, CachedResourceHandle<CachedScript>);
+ void suspendExecuteScriptSoonTimer();
+ void resumeExecuteScriptSoonTimer();
+
#if ENABLE(XSLT)
void applyXSLTransform(ProcessingInstruction* pi);
PassRefPtr<Document> transformSourceDocument() { return m_transformSourceDocument; }
@@ -992,7 +999,7 @@ public:
const QualifiedName& idAttributeName() const { return m_idAttributeName; }
protected:
- Document(Frame*, bool isXHTML, bool isHTML);
+ Document(Frame*, const KURL&, bool isXHTML, bool isHTML);
void clearXMLVersion() { m_xmlVersion = String(); }
diff --git a/WebCore/dom/DocumentFragment.cpp b/WebCore/dom/DocumentFragment.cpp
index f7df8f6..7287439 100644
--- a/WebCore/dom/DocumentFragment.cpp
+++ b/WebCore/dom/DocumentFragment.cpp
@@ -24,12 +24,18 @@
#include "DocumentFragment.h"
#include "Document.h"
+#include "HTMLDocumentParser.h"
+#include "LegacyHTMLDocumentParser.h"
+#include "Page.h"
+#include "Settings.h"
+#include "XMLDocumentParser.h"
namespace WebCore {
inline DocumentFragment::DocumentFragment(Document* document)
: ContainerNode(document)
{
+ ASSERT(document);
}
PassRefPtr<DocumentFragment> DocumentFragment::create(Document* document)
@@ -70,4 +76,22 @@ PassRefPtr<Node> DocumentFragment::cloneNode(bool deep)
return clone.release();
}
+bool DocumentFragment::shouldUseLegacyHTMLParser() const
+{
+ return document()->page() && document()->page()->settings()
+ && !document()->page()->settings()->html5ParserEnabled();
+}
+
+void DocumentFragment::parseHTML(const String& source, FragmentScriptingPermission scriptingPermission)
+{
+ if (shouldUseLegacyHTMLParser())
+ return LegacyHTMLDocumentParser::parseDocumentFragment(source, this, scriptingPermission);
+ HTMLDocumentParser::parseDocumentFragment(source, this, scriptingPermission);
+}
+
+bool DocumentFragment::parseXML(const String& source, Element* parent, FragmentScriptingPermission scriptingPermission)
+{
+ return parseXMLDocumentFragment(source, this, parent, scriptingPermission);
+}
+
}
diff --git a/WebCore/dom/DocumentFragment.h b/WebCore/dom/DocumentFragment.h
index e624ee4..5eff17f 100644
--- a/WebCore/dom/DocumentFragment.h
+++ b/WebCore/dom/DocumentFragment.h
@@ -25,6 +25,7 @@
#define DocumentFragment_h
#include "ContainerNode.h"
+#include "FragmentScriptingPermission.h"
namespace WebCore {
@@ -32,9 +33,14 @@ class DocumentFragment : public ContainerNode {
public:
static PassRefPtr<DocumentFragment> create(Document*);
+ void parseHTML(const String&, FragmentScriptingPermission = FragmentScriptingAllowed);
+ bool parseXML(const String&, Element* parent, FragmentScriptingPermission = FragmentScriptingAllowed);
+
private:
DocumentFragment(Document*);
+ bool shouldUseLegacyHTMLParser() const;
+
virtual String nodeName() const;
virtual NodeType nodeType() const;
virtual PassRefPtr<Node> cloneNode(bool deep);
diff --git a/WebCore/dom/DocumentParser.h b/WebCore/dom/DocumentParser.h
index c7eea06..881136c 100644
--- a/WebCore/dom/DocumentParser.h
+++ b/WebCore/dom/DocumentParser.h
@@ -2,6 +2,7 @@
* Copyright (C) 2000 Peter Kelly (pmk@post.com)
* Copyright (C) 2005, 2006 Apple Computer, Inc.
* Copyright (C) 2007 Samuel Weinig (sam@webkit.org)
+ * Copyright (C) 2010 Google, Inc.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public
@@ -23,64 +24,84 @@
#ifndef DocumentParser_h
#define DocumentParser_h
+#include <wtf/Assertions.h>
+
namespace WebCore {
- class LegacyHTMLTreeConstructor;
- class HTMLDocumentParser;
- class SegmentedString;
- class XSSAuditor;
-
- class DocumentParser : public Noncopyable {
- public:
- virtual ~DocumentParser() { }
-
- // Script output must be prepended, while new data
- // received during executing a script must be appended, hence the
- // extra bool to be able to distinguish between both cases.
- // document.write() always uses false, while the loader uses true.
- virtual void write(const SegmentedString&, bool appendData) = 0;
- virtual void finish() = 0;
- virtual bool isWaitingForScripts() const = 0;
- virtual void stopParsing() { m_parserStopped = true; }
- virtual bool processingData() const { return false; }
- virtual int executingScript() const { return 0; }
-
- virtual bool wantsRawData() const { return false; }
- virtual bool writeRawData(const char* /*data*/, int /*length*/) { return false; }
-
- bool inViewSourceMode() const { return m_inViewSourceMode; }
- void setInViewSourceMode(bool mode) { m_inViewSourceMode = mode; }
-
- virtual bool wellFormed() const { return true; }
-
- virtual int lineNumber() const { return -1; }
- virtual int columnNumber() const { return -1; }
-
- virtual void executeScriptsWaitingForStylesheets() {}
-
- virtual LegacyHTMLTreeConstructor* htmlTreeConstructor() const { return 0; }
- virtual HTMLDocumentParser* asHTMLDocumentParser() { return 0; }
-
- XSSAuditor* xssAuditor() const { return m_XSSAuditor; }
- void setXSSAuditor(XSSAuditor* auditor) { m_XSSAuditor = auditor; }
-
- protected:
- DocumentParser(bool viewSourceMode = false)
- : m_parserStopped(false)
- , m_inViewSourceMode(viewSourceMode)
- , m_XSSAuditor(0)
- {
- }
-
- // The parser has buffers, so parsing may continue even after
- // it stops receiving data. We use m_parserStopped to stop the parser
- // even when it has buffered data.
- bool m_parserStopped;
- bool m_inViewSourceMode;
-
- // The XSSAuditor associated with this document parser.
- XSSAuditor* m_XSSAuditor;
- };
+class Document;
+class LegacyHTMLTreeBuilder;
+class LegacyHTMLDocumentParser;
+class SegmentedString;
+class XSSAuditor;
+
+class DocumentParser : public Noncopyable {
+public:
+ virtual ~DocumentParser() { }
+
+ // Script output must be prepended, while new data
+ // received during executing a script must be appended, hence the
+ // extra bool to be able to distinguish between both cases.
+ // document.write() always uses false, while the loader uses true.
+ virtual void write(const SegmentedString&, bool isFromNetwork) = 0;
+ virtual void finish() = 0;
+ virtual bool finishWasCalled() = 0;
+ virtual bool isWaitingForScripts() const = 0;
+ virtual bool isExecutingScript() const { return false; }
+
+ virtual void stopParsing() { m_parserStopped = true; }
+ // FIXME: processingData() is only used by DocumentLoader::isLoadingInAPISense
+ // and is very unclear as to what it actually means. Only LegacyHTMLDocumentParser
+ // actually implements it.
+ virtual bool processingData() const { return false; }
+
+ virtual bool wantsRawData() const { return false; }
+ virtual bool writeRawData(const char* /*data*/, int /*length*/)
+ {
+ ASSERT_NOT_REACHED();
+ return false;
+ }
+
+ virtual bool wellFormed() const { return true; }
+
+ virtual int lineNumber() const { return -1; }
+ virtual int columnNumber() const { return -1; }
+
+ virtual void executeScriptsWaitingForStylesheets() {}
+
+ virtual LegacyHTMLTreeBuilder* htmlTreeBuilder() const { return 0; }
+ virtual LegacyHTMLDocumentParser* asHTMLDocumentParser() { return 0; }
+
+ // FIXME: view source mode is only used by the HTML and Text
+ // DocumentParsers and may not belong on the base-class.
+ bool inViewSourceMode() const { return m_inViewSourceMode; }
+ void setInViewSourceMode(bool mode) { m_inViewSourceMode = mode; }
+
+ Document* document() const { return m_document; }
+
+ XSSAuditor* xssAuditor() const { return m_XSSAuditor; }
+ void setXSSAuditor(XSSAuditor* auditor) { m_XSSAuditor = auditor; }
+
+protected:
+ DocumentParser(Document* document, bool viewSourceMode = false)
+ : m_parserStopped(false)
+ , m_inViewSourceMode(viewSourceMode)
+ , m_document(document)
+ , m_XSSAuditor(0)
+ {
+ ASSERT(document);
+ }
+
+ // The parser has buffers, so parsing may continue even after
+ // it stops receiving data. We use m_parserStopped to stop the parser
+ // even when it has buffered data.
+ bool m_parserStopped;
+ bool m_inViewSourceMode;
+
+ // Every DocumentParser needs a pointer back to the document.
+ Document* m_document;
+ // The XSSAuditor associated with this document parser.
+ XSSAuditor* m_XSSAuditor;
+};
} // namespace WebCore
diff --git a/WebCore/dom/Element.cpp b/WebCore/dom/Element.cpp
index c1c798b..adbb720 100644
--- a/WebCore/dom/Element.cpp
+++ b/WebCore/dom/Element.cpp
@@ -4,7 +4,7 @@
* (C) 2001 Peter Kelly (pmk@post.com)
* (C) 2001 Dirk Mueller (mueller@kde.org)
* (C) 2007 David Smith (catfish.man@gmail.com)
- * Copyright (C) 2004, 2005, 2006, 2007, 2008, 2009 Apple Inc. All rights reserved.
+ * Copyright (C) 2004, 2005, 2006, 2007, 2008, 2009, 2010 Apple Inc. All rights reserved.
* (C) 2007 Eric Seidel (eric@webkit.org)
*
* This library is free software; you can redistribute it and/or
@@ -42,7 +42,6 @@
#include "FrameView.h"
#include "HTMLElement.h"
#include "HTMLNames.h"
-#include "HTMLDocumentParser.h"
#include "InspectorController.h"
#include "NodeList.h"
#include "NodeRenderStyle.h"
@@ -52,7 +51,6 @@
#include "RenderWidget.h"
#include "TextIterator.h"
#include "XMLNames.h"
-#include "XMLDocumentParser.h"
#include <wtf/text/CString.h>
#if ENABLE(SVG)
@@ -93,12 +91,12 @@ NodeRareData* Element::createRareData()
PassRefPtr<DocumentFragment> Element::createContextualFragment(const String& markup, FragmentScriptingPermission scriptingPermission)
{
- RefPtr<DocumentFragment> fragment = DocumentFragment::create(document());
-
+ RefPtr<DocumentFragment> fragment = document()->createDocumentFragment();
+
if (document()->isHTMLDocument())
- parseHTMLDocumentFragment(markup, fragment.get(), scriptingPermission);
+ fragment->parseHTML(markup, scriptingPermission);
else {
- if (!parseXMLDocumentFragment(markup, fragment.get(), this, scriptingPermission))
+ if (!fragment->parseXML(markup, this, scriptingPermission))
// FIXME: We should propagate a syntax error exception out here.
return 0;
}
@@ -189,7 +187,7 @@ void Element::setCStringAttribute(const QualifiedName& name, const char* cString
void Element::setBooleanAttribute(const QualifiedName& name, bool b)
{
if (b)
- setAttribute(name, name.localName());
+ setAttribute(name, emptyAtom);
else {
ExceptionCode ex;
removeAttribute(name, ex);
@@ -639,6 +637,8 @@ void Element::updateAfterAttributeChanged(Attribute* attr)
document()->axObjectCache()->contentChanged(renderer());
} else if (attrName == aria_selectedAttr)
document()->axObjectCache()->selectedChildrenChanged(renderer());
+ else if (attrName == aria_expandedAttr)
+ document()->axObjectCache()->handleAriaExpandedChange(renderer());
}
void Element::recalcStyleIfNeededAfterAttributeChanged(Attribute* attr)
@@ -1098,7 +1098,7 @@ void Element::dispatchAttrRemovalEvent(Attribute*)
if (!document()->hasListenerType(Document::DOMATTRMODIFIED_LISTENER))
return;
ExceptionCode ec = 0;
- dispatchEvent(new MutationEvent(DOMAttrModifiedEvent, true, false, attr, attr->value(),
+ dispatchEvent(MutationEvent::create(DOMAttrModifiedEvent, true, attr, attr->value(),
attr->value(), document()->attrName(attr->id()), MutationEvent::REMOVAL), ec);
#endif
}
@@ -1111,7 +1111,7 @@ void Element::dispatchAttrAdditionEvent(Attribute*)
if (!document()->hasListenerType(Document::DOMATTRMODIFIED_LISTENER))
return;
ExceptionCode ec = 0;
- dispatchEvent(new MutationEvent(DOMAttrModifiedEvent, true, false, attr, attr->value(),
+ dispatchEvent(MutationEvent::create(DOMAttrModifiedEvent, true, attr, attr->value(),
attr->value(), document()->attrName(attr->id()), MutationEvent::ADDITION), ec);
#endif
}
@@ -1531,4 +1531,39 @@ KURL Element::getURLAttribute(const QualifiedName& name) const
return document()->completeURL(deprecatedParseURL(getAttribute(name)));
}
+int Element::getIntegralAttribute(const QualifiedName& attributeName) const
+{
+ return getAttribute(attributeName).string().toInt();
+}
+
+void Element::setIntegralAttribute(const QualifiedName& attributeName, int value)
+{
+ // FIXME: Need an AtomicString version of String::number.
+ ExceptionCode ec;
+ setAttribute(attributeName, String::number(value), ec);
+}
+
+unsigned Element::getUnsignedIntegralAttribute(const QualifiedName& attributeName) const
+{
+ return getAttribute(attributeName).string().toUInt();
+}
+
+void Element::setUnsignedIntegralAttribute(const QualifiedName& attributeName, unsigned value)
+{
+ // FIXME: Need an AtomicString version of String::number.
+ ExceptionCode ec;
+ setAttribute(attributeName, String::number(value), ec);
+}
+
+#if ENABLE(SVG)
+bool Element::childShouldCreateRenderer(Node* child) const
+{
+ // Only create renderers for SVG elements whose parents are SVG elements, or for proper <svg xmlns="svgNS"> subdocuments.
+ if (child->isSVGElement())
+ return child->hasTagName(SVGNames::svgTag) || isSVGElement();
+
+ return Node::childShouldCreateRenderer(child);
+}
+#endif
+
} // namespace WebCore
diff --git a/WebCore/dom/Element.h b/WebCore/dom/Element.h
index c6eebcb..a0cf7b1 100644
--- a/WebCore/dom/Element.h
+++ b/WebCore/dom/Element.h
@@ -26,7 +26,7 @@
#define Element_h
#include "Document.h"
-#include "MappedAttributeEntry.h"
+#include "FragmentScriptingPermission.h"
#include "NamedNodeMap.h"
#include "ScrollTypes.h"
@@ -101,6 +101,12 @@ public:
void setAttribute(const QualifiedName&, const AtomicString& value, ExceptionCode&);
void removeAttribute(const QualifiedName&, ExceptionCode&);
+ // Typed getters and setters for language bindings.
+ int getIntegralAttribute(const QualifiedName& attributeName) const;
+ void setIntegralAttribute(const QualifiedName& attributeName, int value);
+ unsigned getUnsignedIntegralAttribute(const QualifiedName& attributeName) const;
+ void setUnsignedIntegralAttribute(const QualifiedName& attributeName, unsigned value);
+
// Call this to get the value of an attribute that is known not to be the style
// attribute or one of the SVG animatable attributes.
bool fastHasAttribute(const QualifiedName&) const;
@@ -279,6 +285,10 @@ public:
virtual void dispatchFormControlChangeEvent() { }
+#if ENABLE(SVG)
+ virtual bool childShouldCreateRenderer(Node*) const;
+#endif
+
protected:
Element(const QualifiedName& tagName, Document* document, ConstructionType type)
: ContainerNode(document, type)
diff --git a/WebCore/dom/ExceptionCode.cpp b/WebCore/dom/ExceptionCode.cpp
index 7bb8a50..9303f9e 100644
--- a/WebCore/dom/ExceptionCode.cpp
+++ b/WebCore/dom/ExceptionCode.cpp
@@ -38,6 +38,10 @@
#include "XPathException.h"
#endif
+#if ENABLE(DATABASE)
+#include "SQLException.h"
+#endif
+
namespace WebCore {
static const char* const exceptionNames[] = {
@@ -145,6 +149,30 @@ static const char* const svgExceptionDescriptions[] = {
};
#endif
+#if ENABLE(DATABASE)
+static const char* const sqlExceptionNames[] = {
+ "UNKNOWN_ERR",
+ "DATABASE_ERR",
+ "VERSION_ERR",
+ "TOO_LARGE_ERR",
+ "QUOTA_ERR",
+ "SYNTAX_ERR",
+ "CONSTRAINT_ERR",
+ "TIMEOUT_ERR"
+};
+
+static const char* const sqlExceptionDescriptions[] = {
+ "The operation failed for reasons unrelated to the database.",
+ "The operation failed for some reason related to the database.",
+ "The actual database version did not match the expected version.",
+ "Data returned from the database is too large.",
+ "Quota was exceeded.",
+ "Invalid or unauthorized statement; or the number of arguments did not match the number of ? placeholders.",
+ "A constraint was violated.",
+ "A transaction lock could not be acquired in a reasonable time."
+};
+#endif
+
void getExceptionCodeDescription(ExceptionCode ec, ExceptionCodeDescription& description)
{
ASSERT(ec);
@@ -156,7 +184,7 @@ void getExceptionCodeDescription(ExceptionCode ec, ExceptionCodeDescription& des
int nameTableSize;
int nameTableOffset;
ExceptionType type;
-
+
if (code >= RangeException::RangeExceptionOffset && code <= RangeException::RangeExceptionMax) {
type = RangeExceptionType;
typeName = "DOM Range";
@@ -203,6 +231,16 @@ void getExceptionCodeDescription(ExceptionCode ec, ExceptionCodeDescription& des
nameTableSize = sizeof(svgExceptionNames) / sizeof(svgExceptionNames[0]);
nameTableOffset = SVGException::SVG_WRONG_TYPE_ERR;
#endif
+#if ENABLE(DATABASE)
+ } else if (code >= SQLException::SQLExceptionOffset && code <= SQLException::SQLExceptionMax) {
+ type = SQLExceptionType;
+ typeName = "DOM SQL";
+ code -= SQLException::SQLExceptionOffset;
+ nameTable = sqlExceptionNames;
+ descriptionTable = sqlExceptionDescriptions;
+ nameTableSize = sizeof(sqlExceptionNames) / sizeof(sqlExceptionNames[0]);
+ nameTableOffset = SQLException::UNKNOWN_ERR;
+#endif
} else {
type = DOMExceptionType;
typeName = "DOM";
diff --git a/WebCore/dom/ExceptionCode.h b/WebCore/dom/ExceptionCode.h
index a5618f8..ef73052 100644
--- a/WebCore/dom/ExceptionCode.h
+++ b/WebCore/dom/ExceptionCode.h
@@ -78,8 +78,11 @@ namespace WebCore {
#if ENABLE(SVG)
, SVGExceptionType
#endif
- };
-
+#if ENABLE(DATABASE)
+ , SQLExceptionType
+#endif
+ };
+
struct ExceptionCodeDescription {
const char* typeName; // has spaces and is suitable for use in exception description strings; maximum length is 10 characters
diff --git a/WebCore/dom/FragmentScriptingPermission.h b/WebCore/dom/FragmentScriptingPermission.h
new file mode 100644
index 0000000..6371011
--- /dev/null
+++ b/WebCore/dom/FragmentScriptingPermission.h
@@ -0,0 +1,40 @@
+/*
+ * Copyright (C) 2010 Google, Inc. All Rights Reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY
+ * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR
+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+ * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+ * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
+ * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
+ * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#ifndef FragmentScriptingPermission_h
+#define FragmentScriptingPermission_h
+
+namespace WebCore {
+
+// FIXME: This enum is poorly named. It is used to remove script contents when
+// generating DocumentFragments for paste in platform/*/Pasteboard.*.
+enum FragmentScriptingPermission {
+ FragmentScriptingAllowed,
+ FragmentScriptingNotAllowed,
+};
+
+};
+
+#endif // FragmentScriptingPermission_h
diff --git a/WebCore/dom/InputElement.h b/WebCore/dom/InputElement.h
index d477046..1d6c356 100644
--- a/WebCore/dom/InputElement.h
+++ b/WebCore/dom/InputElement.h
@@ -44,6 +44,9 @@ public:
virtual bool isSearchField() const = 0;
virtual bool isTextField() const = 0;
virtual bool hasSpinButton() const { return false; }
+#if ENABLE(INPUT_SPEECH)
+ virtual bool isSpeechEnabled() const = 0;
+#endif
virtual bool searchEventsShouldBeDispatched() const = 0;
diff --git a/WebCore/dom/MappedAttributeEntry.h b/WebCore/dom/MappedAttributeEntry.h
index ce2464e..f28f182 100644
--- a/WebCore/dom/MappedAttributeEntry.h
+++ b/WebCore/dom/MappedAttributeEntry.h
@@ -48,8 +48,6 @@ enum MappedAttributeEntry {
, eLastEntry
};
-enum FragmentScriptingPermission { FragmentScriptingAllowed, FragmentScriptingNotAllowed };
-
}
#endif
diff --git a/WebCore/dom/MessageChannel.idl b/WebCore/dom/MessageChannel.idl
index bae5b18..a3f3c94 100644
--- a/WebCore/dom/MessageChannel.idl
+++ b/WebCore/dom/MessageChannel.idl
@@ -1,5 +1,5 @@
/*
- * Copyright (C) 2008 Apple Inc. All Rights Reserved.
+ * Copyright (C) 2008, 2010 Apple Inc. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
@@ -26,7 +26,13 @@
module events {
- interface [CustomConstructor, CustomMarkFunction, NoStaticTables] MessageChannel {
+ interface [
+ CanBeConstructed,
+ CustomConstructFunction,
+ V8CustomConstructor,
+ CustomMarkFunction,
+ NoStaticTables
+ ] MessageChannel {
readonly attribute MessagePort port1;
readonly attribute MessagePort port2;
diff --git a/WebCore/dom/Node.cpp b/WebCore/dom/Node.cpp
index 840b967..4b25d9a 100644
--- a/WebCore/dom/Node.cpp
+++ b/WebCore/dom/Node.cpp
@@ -681,6 +681,21 @@ IntRect Node::getRect() const
return renderer()->absoluteBoundingBoxRect();
return IntRect();
}
+
+IntRect Node::renderRect(bool* isReplaced)
+{
+ RenderObject* hitRenderer = this->renderer();
+ ASSERT(hitRenderer);
+ RenderObject* renderer = hitRenderer;
+ while (renderer && !renderer->isBody() && !renderer->isRoot()) {
+ if (renderer->isRenderBlock() || renderer->isInlineBlockOrInlineTable() || renderer->isReplaced()) {
+ *isReplaced = renderer->isReplaced();
+ return renderer->absoluteBoundingBoxRect(true);
+ }
+ renderer = renderer->parent();
+ }
+ return IntRect();
+}
bool Node::hasNonEmptyBoundingBox() const
{
diff --git a/WebCore/dom/Node.h b/WebCore/dom/Node.h
index 8bf89cc..6e99cd7 100644
--- a/WebCore/dom/Node.h
+++ b/WebCore/dom/Node.h
@@ -332,6 +332,7 @@ public:
virtual bool isContentRichlyEditable() const;
virtual bool shouldUseInputMethod() const;
virtual IntRect getRect() const;
+ IntRect renderRect(bool* isReplaced);
// Returns true if the node has a non-empty bounding box in layout.
// This does not 100% guarantee the user can see it, but is pretty close.
@@ -666,7 +667,7 @@ private:
void clearFlag(NodeFlags mask) const { m_nodeFlags &= ~mask; }
protected:
- // CreateElementZeroRefCount is deprecated and can be removed once we convert all element
+ // CreateWithZeroRefCountFlag is deprecated and can be removed once we convert all element
// classes to start with a reference count of 1.
enum ConstructionType {
CreateOther = DefaultNodeFlags,
@@ -674,11 +675,9 @@ protected:
CreateComment = DefaultNodeFlags | IsCommentFlag,
CreateContainer = DefaultNodeFlags | IsContainerFlag,
CreateElement = CreateContainer | IsElementFlag,
- CreateElementZeroRefCount = IsElementFlag | CreateWithZeroRefCountFlag,
CreateStyledElement = CreateElement | IsStyledElementFlag,
CreateStyledElementZeroRefCount = CreateStyledElement | CreateWithZeroRefCountFlag,
CreateHTMLElement = CreateStyledElement | IsHTMLFlag,
- CreateHTMLElementZeroRefCount = CreateHTMLElement | CreateWithZeroRefCountFlag,
CreateSVGElement = CreateStyledElement | IsSVGFlag,
CreateSVGElementZeroRefCount = CreateSVGElement | CreateWithZeroRefCountFlag,
};
diff --git a/WebCore/dom/NodeFilter.idl b/WebCore/dom/NodeFilter.idl
index 16f3f26..40c5bad 100644
--- a/WebCore/dom/NodeFilter.idl
+++ b/WebCore/dom/NodeFilter.idl
@@ -21,8 +21,12 @@
module traversal {
// Introduced in DOM Level 2:
- interface [CustomMarkFunction, CustomNativeConverter, ObjCProtocol] NodeFilter {
-
+ interface [
+ CustomMarkFunction,
+ CustomNativeConverter,
+ ObjCProtocol,
+ PureInterface
+ ] NodeFilter {
// Constants returned by acceptNode
const short FILTER_ACCEPT = 1;
const short FILTER_REJECT = 2;
diff --git a/WebCore/dom/Position.cpp b/WebCore/dom/Position.cpp
index 7861fbe..65b7261 100644
--- a/WebCore/dom/Position.cpp
+++ b/WebCore/dom/Position.cpp
@@ -739,7 +739,7 @@ bool Position::isCandidate() const
return m_offset == 0 && !nodeIsUserSelectNone(node()->parent());
if (renderer->isText())
- return inRenderedText() && !nodeIsUserSelectNone(node());
+ return !nodeIsUserSelectNone(node()) && inRenderedText();
if (isTableElement(node()) || editingIgnoresContent(node()))
return (atFirstEditingPositionForNode() || atLastEditingPositionForNode()) && !nodeIsUserSelectNone(node()->parent());
diff --git a/WebCore/dom/Position.h b/WebCore/dom/Position.h
index ce06f48..f606c29 100644
--- a/WebCore/dom/Position.h
+++ b/WebCore/dom/Position.h
@@ -234,7 +234,7 @@ inline Position positionAfterNode(Node* anchorNode)
inline int lastOffsetInNode(Node* node)
{
- return node->offsetInCharacters() ? node->maxCharacterOffset() : node->childNodeCount();
+ return node->offsetInCharacters() ? node->maxCharacterOffset() : static_cast<int>(node->childNodeCount());
}
// firstPositionInNode and lastPositionInNode return parent-anchored positions, lastPositionInNode construction is O(n) due to childNodeCount()
diff --git a/WebCore/dom/PositionIterator.cpp b/WebCore/dom/PositionIterator.cpp
index 619e376..d2c3a3f 100644
--- a/WebCore/dom/PositionIterator.cpp
+++ b/WebCore/dom/PositionIterator.cpp
@@ -150,7 +150,7 @@ bool PositionIterator::isCandidate() const
return !m_offsetInAnchor && !Position::nodeIsUserSelectNone(m_anchorNode->parent());
if (renderer->isText())
- return Position(*this).inRenderedText() && !Position::nodeIsUserSelectNone(m_anchorNode);
+ return !Position::nodeIsUserSelectNone(m_anchorNode) && Position(*this).inRenderedText();
if (isTableElement(m_anchorNode) || editingIgnoresContent(m_anchorNode))
return (atStartOfNode() || atEndOfNode()) && !Position::nodeIsUserSelectNone(m_anchorNode->parent());
diff --git a/WebCore/dom/RawDataDocumentParser.h b/WebCore/dom/RawDataDocumentParser.h
new file mode 100644
index 0000000..77d148d
--- /dev/null
+++ b/WebCore/dom/RawDataDocumentParser.h
@@ -0,0 +1,75 @@
+/*
+ * Copyright (C) 2010 Google, Inc. All Rights Reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY
+ * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR
+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+ * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+ * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
+ * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
+ * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#ifndef RawDataDocumentParser_h
+#define RawDataDocumentParser_h
+
+#include "DocumentParser.h"
+
+namespace WebCore {
+
+// FIXME: It seems wrong that RawDataDocumentParser is a subclass of
+// DocumentParser. RawDataDocumentParser, just wants to override an earlier
+// version of write() before the data is decoded. Seems the decoding could
+// move into the base-class DocumentParser, and then RawDataDocumentParser
+// would just be short-circuting. That could simplify some of the
+// DocumentWriter logic.
+class RawDataDocumentParser : public DocumentParser {
+public:
+ RawDataDocumentParser(Document* document)
+ : DocumentParser(document)
+ {
+ }
+
+protected:
+ virtual void finish()
+ {
+ if (!m_parserStopped)
+ m_document->finishedParsing();
+ }
+
+private:
+ virtual void write(const SegmentedString&, bool)
+ {
+ // <https://bugs.webkit.org/show_bug.cgi?id=25397>: JS code can always call document.write, we need to handle it.
+ ASSERT_NOT_REACHED();
+ }
+
+ virtual bool finishWasCalled()
+ {
+ // finish() always calls document()->finishedParsing() so we will be
+ // deleted after finish().
+ return false;
+ }
+
+ virtual bool isWaitingForScripts() const { return false; }
+
+ virtual bool wantsRawData() const { return true; }
+ virtual bool writeRawData(const char*, int) { return false; }
+};
+
+};
+
+#endif // RawDataDocumentParser_h
diff --git a/WebCore/dom/ScriptElement.cpp b/WebCore/dom/ScriptElement.cpp
index 0ac0846..518aead 100644
--- a/WebCore/dom/ScriptElement.cpp
+++ b/WebCore/dom/ScriptElement.cpp
@@ -305,6 +305,20 @@ String ScriptElementData::scriptContent() const
return String::adopt(val);
}
+bool ScriptElementData::isAsynchronous() const
+{
+ // Only external scripts may be asynchronous.
+ // See: http://dev.w3.org/html5/spec/Overview.html#attr-script-async
+ return !m_scriptElement->sourceAttributeValue().isEmpty() && m_scriptElement->asyncAttributeValue();
+}
+
+bool ScriptElementData::isDeferred() const
+{
+ // Only external scripts may be deferred and async trumps defer to allow for backward compatibility.
+ // See: http://dev.w3.org/html5/spec/Overview.html#attr-script-defer
+ return !m_scriptElement->sourceAttributeValue().isEmpty() && !m_scriptElement->asyncAttributeValue() && m_scriptElement->deferAttributeValue();
+}
+
ScriptElement* toScriptElement(Element* element)
{
if (element->isHTMLElement() && element->hasTagName(HTMLNames::scriptTag))
diff --git a/WebCore/dom/ScriptElement.h b/WebCore/dom/ScriptElement.h
index 8cc84fc..c663e43 100644
--- a/WebCore/dom/ScriptElement.h
+++ b/WebCore/dom/ScriptElement.h
@@ -44,6 +44,8 @@ public:
virtual String languageAttributeValue() const = 0;
virtual String forAttributeValue() const = 0;
virtual String eventAttributeValue() const = 0;
+ virtual bool asyncAttributeValue() const = 0;
+ virtual bool deferAttributeValue() const = 0;
virtual void dispatchLoadEvent() = 0;
virtual void dispatchErrorEvent() = 0;
@@ -74,6 +76,8 @@ public:
String scriptContent() const;
String scriptCharset() const;
+ bool isAsynchronous() const;
+ bool isDeferred() const;
Element* element() const { return m_element; }
bool createdByParser() const { return m_createdByParser; }
diff --git a/WebCore/dom/SelectElement.cpp b/WebCore/dom/SelectElement.cpp
index c7052b3..43e6e28 100644
--- a/WebCore/dom/SelectElement.cpp
+++ b/WebCore/dom/SelectElement.cpp
@@ -342,8 +342,13 @@ void SelectElement::setSelectedIndex(SelectElementData& data, Element* element,
data.setUserDrivenChange(userDrivenChange);
if (fireOnChangeNow)
menuListOnChange(data, element);
- if (RenderMenuList* menuList = toRenderMenuList(element->renderer()))
- menuList->didSetSelectedIndex();
+ RenderObject* renderer = element->renderer();
+ if (renderer) {
+ if (data.usesMenuList())
+ toRenderMenuList(renderer)->didSetSelectedIndex();
+ else if (renderer->isListBox())
+ toRenderListBox(renderer)->selectionChanged();
+ }
}
if (Frame* frame = element->document()->frame())
diff --git a/WebCore/dom/StaticHashSetNodeList.cpp b/WebCore/dom/StaticHashSetNodeList.cpp
new file mode 100644
index 0000000..d641cb5
--- /dev/null
+++ b/WebCore/dom/StaticHashSetNodeList.cpp
@@ -0,0 +1,66 @@
+/*
+ * Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies)
+ * Copyright (C) 2010 Antonio Gomes <tonikitoo@webkit.org>
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. Neither the name of Apple Computer, Inc. ("Apple") nor the names of
+ * its contributors may be used to endorse or promote products derived
+ * from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE AND ITS CONTRIBUTORS "AS IS" AND ANY
+ * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL APPLE OR ITS CONTRIBUTORS BE LIABLE FOR ANY
+ * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include "config.h"
+#include "StaticHashSetNodeList.h"
+
+#include "Element.h"
+
+namespace WebCore {
+
+unsigned StaticHashSetNodeList::length() const
+{
+ return m_nodes.size();
+}
+
+Node* StaticHashSetNodeList::item(unsigned index) const
+{
+ if (index < (unsigned) m_nodes.size()) {
+ ListHashSet<RefPtr<Node> >::const_iterator it = m_nodes.begin();
+ for (unsigned count = 0; count < index; ++it, ++count) { }
+ return (*it).get();
+ }
+
+ return 0;
+}
+
+Node* StaticHashSetNodeList::itemWithName(const AtomicString& elementId) const
+{
+ ListHashSet<RefPtr<Node> >::const_iterator it = m_nodes.begin();
+ ListHashSet<RefPtr<Node> >::const_iterator end = m_nodes.end();
+ for ( ; it != end ; ++it) {
+ Node* node = (*it).get();
+ if (node->hasID() && static_cast<Element*>(node)->getIdAttribute() == elementId)
+ return node;
+ }
+
+ return 0;
+}
+
+} // namespace WebCore
diff --git a/WebCore/dom/StaticHashSetNodeList.h b/WebCore/dom/StaticHashSetNodeList.h
new file mode 100644
index 0000000..e954493
--- /dev/null
+++ b/WebCore/dom/StaticHashSetNodeList.h
@@ -0,0 +1,70 @@
+/*
+ * Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies)
+ * Copyright (C) 2010 Antonio Gomes <tonikitoo@webkit.org>
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. Neither the name of Apple Computer, Inc. ("Apple") nor the names of
+ * its contributors may be used to endorse or promote products derived
+ * from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE AND ITS CONTRIBUTORS "AS IS" AND ANY
+ * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL APPLE OR ITS CONTRIBUTORS BE LIABLE FOR ANY
+ * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#ifndef StaticHashSetNodeList_h
+#define StaticHashSetNodeList_h
+
+#include "NodeList.h"
+#include <wtf/ListHashSet.h>
+#include <wtf/PassRefPtr.h>
+#include <wtf/RefPtr.h>
+
+namespace WebCore {
+
+class Node;
+
+class StaticHashSetNodeList : public NodeList {
+public:
+ // Adopts the contents of the nodes ListHashSet.
+ static PassRefPtr<StaticHashSetNodeList> adopt(const ListHashSet<RefPtr<Node> >& nodes)
+ {
+ return adopt(const_cast<ListHashSet<RefPtr<Node> >&>(nodes));
+ }
+
+ static PassRefPtr<StaticHashSetNodeList> adopt(ListHashSet<RefPtr<Node> >& nodes)
+ {
+ return adoptRef(new StaticHashSetNodeList(nodes));
+ }
+
+ virtual unsigned length() const;
+ virtual Node* item(unsigned index) const;
+ virtual Node* itemWithName(const AtomicString&) const;
+
+private:
+ StaticHashSetNodeList(ListHashSet<RefPtr<Node> >& nodes)
+ {
+ m_nodes.swap(nodes);
+ }
+
+ ListHashSet<RefPtr<Node> > m_nodes;
+};
+
+} // namespace WebCore
+
+#endif // StaticHashSetNodeList_h
diff --git a/WebCore/dom/Touch.h b/WebCore/dom/Touch.h
index ceb8ae7..54e85a5 100644
--- a/WebCore/dom/Touch.h
+++ b/WebCore/dom/Touch.h
@@ -23,8 +23,8 @@
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
-#ifndef TOUCH_H_
-#define TOUCH_H_
+#ifndef Touch_h
+#define Touch_h
#if ENABLE(TOUCH_EVENTS)
@@ -72,4 +72,4 @@ private:
#endif // ENABLE(TOUCH_EVENTS)
-#endif /* TOUCH_H_ */
+#endif /* Touch_h */
diff --git a/WebCore/dom/TouchList.h b/WebCore/dom/TouchList.h
index 61350b0..2546955 100644
--- a/WebCore/dom/TouchList.h
+++ b/WebCore/dom/TouchList.h
@@ -23,8 +23,8 @@
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
-#ifndef TOUCHLIST_H_
-#define TOUCHLIST_H_
+#ifndef TouchList_h
+#define TouchList_h
#if ENABLE(TOUCH_EVENTS)
@@ -57,4 +57,4 @@ private:
#endif // ENABLE(TOUCH_EVENTS)
-#endif /* TOUCHLIST_H_ */
+#endif /* TouchList_h */
diff --git a/WebCore/dom/XMLDocumentParser.cpp b/WebCore/dom/XMLDocumentParser.cpp
index 987e9b1..ab02bb3 100644
--- a/WebCore/dom/XMLDocumentParser.cpp
+++ b/WebCore/dom/XMLDocumentParser.cpp
@@ -72,10 +72,7 @@ const int maxErrors = 25;
#if ENABLE(WML)
bool XMLDocumentParser::isWMLDocument() const
{
- if (m_doc)
- return m_doc->isWMLDocument();
-
- return false;
+ return document()->isWMLDocument();
}
#endif
@@ -83,7 +80,7 @@ void XMLDocumentParser::pushCurrentNode(Node* n)
{
ASSERT(n);
ASSERT(m_currentNode);
- if (n != m_doc)
+ if (n != document())
n->ref();
m_currentNodeStack.append(m_currentNode);
m_currentNode = n;
@@ -97,7 +94,7 @@ void XMLDocumentParser::popCurrentNode()
return;
ASSERT(m_currentNodeStack.size());
- if (m_currentNode != m_doc)
+ if (m_currentNode != document())
m_currentNode->deref();
m_currentNode = m_currentNodeStack.last();
@@ -106,14 +103,14 @@ void XMLDocumentParser::popCurrentNode()
void XMLDocumentParser::clearCurrentNodeStack()
{
- if (m_currentNode && m_currentNode != m_doc)
+ if (m_currentNode && m_currentNode != document())
m_currentNode->deref();
m_currentNode = 0;
if (m_currentNodeStack.size()) { // Aborted parsing.
for (size_t i = m_currentNodeStack.size() - 1; i != 0; --i)
m_currentNodeStack[i]->deref();
- if (m_currentNodeStack[0] && m_currentNodeStack[0] != m_doc)
+ if (m_currentNodeStack[0] && m_currentNodeStack[0] != document())
m_currentNodeStack[0]->deref();
m_currentNodeStack.clear();
}
@@ -169,7 +166,7 @@ bool XMLDocumentParser::enterText()
#if !USE(QXMLSTREAM)
ASSERT(m_bufferedText.size() == 0);
#endif
- RefPtr<Node> newNode = Text::create(m_doc, "");
+ RefPtr<Node> newNode = Text::create(document(), "");
if (!m_currentNode->addChild(newNode.get()))
return false;
pushCurrentNode(newNode.get());
@@ -217,12 +214,12 @@ void XMLDocumentParser::end()
insertErrorMessageBlock();
else {
exitText();
- m_doc->updateStyleSelector();
+ document()->updateStyleSelector();
}
clearCurrentNodeStack();
if (!m_parsingFragment)
- m_doc->finishedParsing();
+ document()->finishedParsing();
}
void XMLDocumentParser::finish()
@@ -233,6 +230,11 @@ void XMLDocumentParser::finish()
end();
}
+bool XMLDocumentParser::finishWasCalled()
+{
+ return m_finishCalled;
+}
+
static inline RefPtr<Element> createXHTMLParserErrorHeader(Document* doc, const String& errorMessages)
{
RefPtr<Element> reportElement = doc->createElement(QualifiedName(nullAtom, "parsererror", xhtmlNamespaceURI), false);
@@ -267,7 +269,7 @@ void XMLDocumentParser::insertErrorMessageBlock()
// Create elements for display
ExceptionCode ec = 0;
- Document* doc = m_doc;
+ Document* doc = document();
Node* documentElement = doc->documentElement();
if (!documentElement) {
RefPtr<Node> rootElement = doc->createElement(htmlTag, false);
diff --git a/WebCore/dom/XMLDocumentParser.h b/WebCore/dom/XMLDocumentParser.h
index bc10415..9915409 100644
--- a/WebCore/dom/XMLDocumentParser.h
+++ b/WebCore/dom/XMLDocumentParser.h
@@ -22,8 +22,8 @@
*
*/
-#ifndef XMLTokenizer_h
-#define XMLTokenizer_h
+#ifndef XMLDocumentParser_h
+#define XMLDocumentParser_h
#if USE(EXPAT)
@@ -136,10 +136,10 @@ bool parseXMLDocumentFragment(const String&, DocumentFragment*, Element* parent
#include "CachedResourceClient.h"
#include "CachedResourceHandle.h"
-#include "MappedAttributeEntry.h"
#include "SegmentedString.h"
#include "StringHash.h"
#include "DocumentParser.h"
+#include "FragmentScriptingPermission.h"
#include <wtf/HashMap.h>
#include <wtf/OwnPtr.h>
@@ -185,18 +185,9 @@ namespace WebCore {
XMLDocumentParser(DocumentFragment*, Element*, FragmentScriptingPermission);
~XMLDocumentParser();
+ // Exposed for callbacks:
enum ErrorType { warning, nonFatal, fatal };
-
- // from DocumentParser
- virtual void write(const SegmentedString&, bool appendData);
- virtual void finish();
- virtual bool isWaitingForScripts() const;
- virtual void stopParsing();
-
- void end();
-
- void pauseParsing();
- void resumeParsing();
+ void handleError(ErrorType, const char* message, int lineNumber, int columnNumber);
void setIsXHTMLDocument(bool isXHTML) { m_isXHTMLDocument = isXHTML; }
bool isXHTMLDocument() const { return m_isXHTMLDocument; }
@@ -208,16 +199,24 @@ namespace WebCore {
bool isWMLDocument() const;
#endif
- // from CachedResourceClient
- virtual void notifyFinished(CachedResource* finishedObj);
-
+ private:
+ // From DocumentParser
+ virtual void write(const SegmentedString&, bool appendData);
+ virtual void finish();
+ virtual bool finishWasCalled();
+ virtual bool isWaitingForScripts() const;
+ virtual void stopParsing();
+ virtual bool wellFormed() const { return !m_sawError; }
+ virtual int lineNumber() const;
+ virtual int columnNumber() const;
- void handleError(ErrorType type, const char* m, int lineNumber, int columnNumber);
+ // from CachedResourceClient
+ virtual void notifyFinished(CachedResource*);
- virtual bool wellFormed() const { return !m_sawError; }
+ void end();
- int lineNumber() const;
- int columnNumber() const;
+ void pauseParsing();
+ void resumeParsing();
#if USE(QXMLSTREAM)
private:
@@ -264,7 +263,6 @@ public:
void doWrite(const String&);
void doEnd();
- Document* m_doc;
FrameView* m_view;
String m_originalSourceForTransform;
@@ -321,6 +319,10 @@ bool parseXMLDocumentFragment(const String&, DocumentFragment*, Element* parent
} // namespace WebCore
+<<<<<<< HEAD
#endif // USE(EXPAT)
#endif // XMLTokenizer_h
+=======
+#endif // XMLDocumentParser_h
+>>>>>>> webkit.org at r61871
diff --git a/WebCore/dom/XMLDocumentParserLibxml2.cpp b/WebCore/dom/XMLDocumentParserLibxml2.cpp
index 2a1bac6..33b0a09 100644
--- a/WebCore/dom/XMLDocumentParserLibxml2.cpp
+++ b/WebCore/dom/XMLDocumentParserLibxml2.cpp
@@ -38,13 +38,12 @@
#include "FrameView.h"
#include "HTMLLinkElement.h"
#include "HTMLStyleElement.h"
-#include "HTMLDocumentParser.h" // for decodeNamedEntity
+#include "LegacyHTMLDocumentParser.h" // for decodeNamedEntity
#include "ProcessingInstruction.h"
#include "ResourceError.h"
#include "ResourceHandle.h"
#include "ResourceRequest.h"
#include "ResourceResponse.h"
-#include "ScriptController.h"
#include "ScriptElement.h"
#include "ScriptSourceCode.h"
#include "ScriptValue.h"
@@ -523,12 +522,12 @@ PassRefPtr<XMLParserContext> XMLParserContext::createMemoryParser(xmlSAXHandlerP
// --------------------------------
-XMLDocumentParser::XMLDocumentParser(Document* _doc, FrameView* _view)
- : m_doc(_doc)
- , m_view(_view)
+XMLDocumentParser::XMLDocumentParser(Document* document, FrameView* frameView)
+ : DocumentParser(document)
+ , m_view(frameView)
, m_context(0)
, m_pendingCallbacks(new PendingCallbacks)
- , m_currentNode(_doc)
+ , m_currentNode(document)
, m_sawError(false)
, m_sawXSLTransform(false)
, m_sawFirstElement(false)
@@ -551,7 +550,7 @@ XMLDocumentParser::XMLDocumentParser(Document* _doc, FrameView* _view)
}
XMLDocumentParser::XMLDocumentParser(DocumentFragment* fragment, Element* parentElement, FragmentScriptingPermission scriptingPermission)
- : m_doc(fragment->document())
+ : DocumentParser(fragment->document())
, m_view(0)
, m_context(0)
, m_pendingCallbacks(new PendingCallbacks)
@@ -576,8 +575,6 @@ XMLDocumentParser::XMLDocumentParser(DocumentFragment* fragment, Element* parent
, m_scriptingPermission(scriptingPermission)
{
fragment->ref();
- if (m_doc)
- m_doc->ref();
// Add namespaces based on the parent node
Vector<Element*> elemStack;
@@ -620,8 +617,6 @@ XMLParserContext::~XMLParserContext()
XMLDocumentParser::~XMLDocumentParser()
{
clearCurrentNodeStack();
- if (m_parsingFragment && m_doc)
- m_doc->deref();
if (m_pendingScript)
m_pendingScript->removeClient(this);
}
@@ -644,11 +639,11 @@ void XMLDocumentParser::doWrite(const String& parseString)
const unsigned char BOMHighByte = *reinterpret_cast<const unsigned char*>(&BOM);
xmlSwitchEncoding(context->context(), BOMHighByte == 0xFF ? XML_CHAR_ENCODING_UTF16LE : XML_CHAR_ENCODING_UTF16BE);
- XMLDocumentParserScope scope(m_doc->docLoader());
+ XMLDocumentParserScope scope(document()->docLoader());
xmlParseChunk(context->context(), reinterpret_cast<const char*>(parseString.characters()), sizeof(UChar) * parseString.length(), 0);
}
- if (m_doc->decoder() && m_doc->decoder()->sawError()) {
+ if (document()->decoder() && document()->decoder()->sawError()) {
// If the decoder saw an error, report it as fatal (stops parsing)
handleError(fatal, "Encoding error", context->context()->input->line, context->context()->input->col);
}
@@ -729,7 +724,7 @@ void XMLDocumentParser::startElementNs(const xmlChar* xmlLocalName, const xmlCha
#if ENABLE(XHTMLMP)
// check if the DOCTYPE Declaration of XHTMLMP document exists
- if (!m_hasDocTypeDeclaration && m_doc->isXHTMLMPDocument()) {
+ if (!m_hasDocTypeDeclaration && document()->isXHTMLMPDocument()) {
handleError(fatal, "DOCTYPE declaration lost.", lineNumber(), columnNumber());
return;
}
@@ -770,7 +765,7 @@ void XMLDocumentParser::startElementNs(const xmlChar* xmlLocalName, const xmlCha
m_sawFirstElement = true;
QualifiedName qName(prefix, localName, uri);
- RefPtr<Element> newElement = m_doc->createElement(qName, true);
+ RefPtr<Element> newElement = document()->createElement(qName, true);
if (!newElement) {
stopParsing();
return;
@@ -783,19 +778,12 @@ void XMLDocumentParser::startElementNs(const xmlChar* xmlLocalName, const xmlCha
return;
}
- ScriptController* jsProxy = m_doc->frame() ? m_doc->frame()->script() : 0;
- if (jsProxy && m_doc->frame()->script()->canExecuteScripts(NotAboutToExecuteScript))
- jsProxy->setEventHandlerLineNumber(lineNumber());
-
handleElementAttributes(newElement.get(), libxmlAttributes, nb_attributes, ec, m_scriptingPermission);
if (ec) {
stopParsing();
return;
}
- if (jsProxy)
- jsProxy->setEventHandlerLineNumber(0);
-
newElement->beginParsingChildren();
ScriptElement* scriptElement = toScriptElement(newElement.get());
@@ -811,8 +799,8 @@ void XMLDocumentParser::startElementNs(const xmlChar* xmlLocalName, const xmlCha
if (m_view && !newElement->attached())
newElement->attach();
- if (!m_parsingFragment && isFirstElement && m_doc->frame())
- m_doc->frame()->loader()->dispatchDocumentElementAvailable();
+ if (!m_parsingFragment && isFirstElement && document()->frame())
+ document()->frame()->loader()->dispatchDocumentElementAvailable();
}
void XMLDocumentParser::endElementNs()
@@ -863,7 +851,7 @@ void XMLDocumentParser::endElementNs()
#if ENABLE(XHTMLMP)
if (!scriptElement->shouldExecuteAsJavaScript())
- m_doc->setShouldProcessNoscriptElement(true);
+ document()->setShouldProcessNoscriptElement(true);
else
#endif
{
@@ -872,7 +860,7 @@ void XMLDocumentParser::endElementNs()
// we have a src attribute
String scriptCharset = scriptElement->scriptCharset();
if (element->dispatchBeforeLoadEvent(scriptHref) &&
- (m_pendingScript = m_doc->docLoader()->requestScript(scriptHref, scriptCharset))) {
+ (m_pendingScript = document()->docLoader()->requestScript(scriptHref, scriptCharset))) {
m_scriptElement = element;
m_pendingScript->addClient(this);
@@ -882,7 +870,7 @@ void XMLDocumentParser::endElementNs()
} else
m_scriptElement = 0;
} else
- m_view->frame()->script()->executeScript(ScriptSourceCode(scriptElement->scriptContent(), m_doc->url(), m_scriptStartLine));
+ m_view->frame()->script()->executeScript(ScriptSourceCode(scriptElement->scriptContent(), document()->url(), m_scriptStartLine));
}
m_requestingScript = false;
popCurrentNode();
@@ -940,7 +928,7 @@ void XMLDocumentParser::processingInstruction(const xmlChar* target, const xmlCh
// ### handle exceptions
int exception = 0;
- RefPtr<ProcessingInstruction> pi = m_doc->createProcessingInstruction(
+ RefPtr<ProcessingInstruction> pi = document()->createProcessingInstruction(
toString(target), toString(data), exception);
if (exception)
return;
@@ -956,7 +944,7 @@ void XMLDocumentParser::processingInstruction(const xmlChar* target, const xmlCh
#if ENABLE(XSLT)
m_sawXSLTransform = !m_sawFirstElement && pi->isXSL();
- if (m_sawXSLTransform && !m_doc->transformSourceDocument())
+ if (m_sawXSLTransform && !document()->transformSourceDocument())
stopParsing();
#endif
}
@@ -973,7 +961,7 @@ void XMLDocumentParser::cdataBlock(const xmlChar* s, int len)
exitText();
- RefPtr<Node> newNode = CDATASection::create(m_doc, toString(s, len));
+ RefPtr<Node> newNode = CDATASection::create(document(), toString(s, len));
if (!m_currentNode->addChild(newNode.get()))
return;
if (m_view && !newNode->attached())
@@ -992,7 +980,7 @@ void XMLDocumentParser::comment(const xmlChar* s)
exitText();
- RefPtr<Node> newNode = Comment::create(m_doc, toString(s));
+ RefPtr<Node> newNode = Comment::create(document(), toString(s));
m_currentNode->addChild(newNode.get());
if (m_view && !newNode->attached())
newNode->attach();
@@ -1003,10 +991,10 @@ void XMLDocumentParser::startDocument(const xmlChar* version, const xmlChar* enc
ExceptionCode ec = 0;
if (version)
- m_doc->setXMLVersion(toString(version), ec);
- m_doc->setXMLStandalone(standalone == 1, ec); // possible values are 0, 1, and -1
+ document()->setXMLVersion(toString(version), ec);
+ document()->setXMLStandalone(standalone == 1, ec); // possible values are 0, 1, and -1
if (encoding)
- m_doc->setXMLEncoding(toString(encoding));
+ document()->setXMLEncoding(toString(encoding));
}
void XMLDocumentParser::endDocument()
@@ -1027,7 +1015,7 @@ void XMLDocumentParser::internalSubset(const xmlChar* name, const xmlChar* exter
return;
}
- if (m_doc) {
+ if (document()) {
#if ENABLE(WML) || ENABLE(XHTMLMP)
String extId = toString(externalID);
#endif
@@ -1048,7 +1036,7 @@ void XMLDocumentParser::internalSubset(const xmlChar* name, const xmlChar* exter
return;
}
- if (m_doc->isXHTMLMPDocument())
+ if (document()->isXHTMLMPDocument())
setIsXHTMLMPDocument(true);
else
setIsXHTMLDocument(true);
@@ -1057,7 +1045,7 @@ void XMLDocumentParser::internalSubset(const xmlChar* name, const xmlChar* exter
}
#endif
- m_doc->addChild(DocumentType::create(m_doc, toString(name), toString(externalID), toString(systemID)));
+ document()->addChild(DocumentType::create(document(), toString(name), toString(externalID), toString(systemID)));
}
}
@@ -1283,7 +1271,7 @@ void XMLDocumentParser::initializeParserContext(const char* chunk)
m_sawXSLTransform = false;
m_sawFirstElement = false;
- XMLDocumentParserScope scope(m_doc->docLoader());
+ XMLDocumentParserScope scope(document()->docLoader());
if (m_parsingFragment)
m_context = XMLParserContext::createMemoryParser(&sax, this, chunk);
else
@@ -1294,12 +1282,12 @@ void XMLDocumentParser::doEnd()
{
#if ENABLE(XSLT)
if (m_sawXSLTransform) {
- void* doc = xmlDocPtrForString(m_doc->docLoader(), m_originalSourceForTransform, m_doc->url().string());
- m_doc->setTransformSource(new TransformSource(doc));
+ void* doc = xmlDocPtrForString(document()->docLoader(), m_originalSourceForTransform, document()->url().string());
+ document()->setTransformSource(new TransformSource(doc));
- m_doc->setParsing(false); // Make the doc think it's done, so it will apply xsl sheets.
- m_doc->updateStyleSelector();
- m_doc->setParsing(true);
+ document()->setParsing(false); // Make the doc think it's done, so it will apply xsl sheets.
+ document()->updateStyleSelector();
+ document()->setParsing(true);
m_parserStopped = true;
}
#endif
@@ -1310,7 +1298,7 @@ void XMLDocumentParser::doEnd()
if (m_context) {
// Tell libxml we're done.
{
- XMLDocumentParserScope scope(m_doc->docLoader());
+ XMLDocumentParserScope scope(document()->docLoader());
xmlParseChunk(context(), 0, 0, 1);
}
@@ -1383,6 +1371,8 @@ void XMLDocumentParser::resumeParsing()
end();
}
+// FIXME: This method should be possible to implement using the DocumentParser
+// API, instead of needing to grab at libxml2 state directly.
bool parseXMLDocumentFragment(const String& chunk, DocumentFragment* fragment, Element* parent, FragmentScriptingPermission scriptingPermission)
{
if (!chunk.length())
diff --git a/WebCore/dom/XMLDocumentParserQt.cpp b/WebCore/dom/XMLDocumentParserQt.cpp
index 89f542f..3b657f1 100644
--- a/WebCore/dom/XMLDocumentParserQt.cpp
+++ b/WebCore/dom/XMLDocumentParserQt.cpp
@@ -38,7 +38,7 @@
#include "FrameView.h"
#include "HTMLLinkElement.h"
#include "HTMLStyleElement.h"
-#include "HTMLDocumentParser.h"
+#include "LegacyHTMLDocumentParser.h"
#include "ProcessingInstruction.h"
#include "ResourceError.h"
#include "ResourceHandle.h"
@@ -77,11 +77,11 @@ QString EntityResolver::resolveUndeclaredEntity(const QString &name)
// --------------------------------
-XMLDocumentParser::XMLDocumentParser(Document* _doc, FrameView* _view)
- : m_doc(_doc)
- , m_view(_view)
+XMLDocumentParser::XMLDocumentParser(Document* document, FrameView* frameView)
+ : DocumentParser(document)
+ , m_view(frameView)
, m_wroteText(false)
- , m_currentNode(_doc)
+ , m_currentNode(document)
, m_sawError(false)
, m_sawXSLTransform(false)
, m_sawFirstElement(false)
@@ -105,7 +105,7 @@ XMLDocumentParser::XMLDocumentParser(Document* _doc, FrameView* _view)
}
XMLDocumentParser::XMLDocumentParser(DocumentFragment* fragment, Element* parentElement, FragmentScriptingPermission permission)
- : m_doc(fragment->document())
+ : DocumentParser(fragment->document())
, m_view(0)
, m_wroteText(false)
, m_currentNode(fragment)
@@ -129,8 +129,6 @@ XMLDocumentParser::XMLDocumentParser(DocumentFragment* fragment, Element* parent
, m_scriptingPermission(permission)
{
fragment->ref();
- if (m_doc)
- m_doc->ref();
// Add namespaces based on the parent node
Vector<Element*> elemStack;
@@ -169,8 +167,6 @@ XMLDocumentParser::XMLDocumentParser(DocumentFragment* fragment, Element* parent
XMLDocumentParser::~XMLDocumentParser()
{
clearCurrentNodeStack();
- if (m_parsingFragment && m_doc)
- m_doc->deref();
if (m_pendingScript)
m_pendingScript->removeClient(this);
delete m_stream.entityResolver();
@@ -180,7 +176,7 @@ void XMLDocumentParser::doWrite(const String& parseString)
{
m_wroteText = true;
- if (m_doc->decoder() && m_doc->decoder()->sawError()) {
+ if (document()->decoder() && document()->decoder()->sawError()) {
// If the decoder saw an error, report it as fatal (stops parsing)
handleError(fatal, "Encoding error", lineNumber(), columnNumber());
return;
@@ -207,10 +203,10 @@ void XMLDocumentParser::doEnd()
{
#if ENABLE(XSLT)
if (m_sawXSLTransform) {
- m_doc->setTransformSource(new TransformSource(m_originalSourceForTransform));
- m_doc->setParsing(false); // Make the doc think it's done, so it will apply xsl sheets.
- m_doc->updateStyleSelector();
- m_doc->setParsing(true);
+ document()->setTransformSource(new TransformSource(m_originalSourceForTransform));
+ document()->setParsing(false); // Make the doc think it's done, so it will apply xsl sheets.
+ document()->updateStyleSelector();
+ document()->setParsing(true);
m_parserStopped = true;
}
#endif
@@ -365,7 +361,7 @@ void XMLDocumentParser::parse()
break;
case QXmlStreamReader::StartElement: {
#if ENABLE(XHTMLMP)
- if (m_doc->isXHTMLMPDocument() && !m_hasDocTypeDeclaration) {
+ if (document()->isXHTMLMPDocument() && !m_hasDocTypeDeclaration) {
handleError(fatal, "DOCTYPE declaration lost.", lineNumber(), columnNumber());
break;
}
@@ -444,14 +440,14 @@ void XMLDocumentParser::startDocument()
ExceptionCode ec = 0;
if (!m_parsingFragment) {
- m_doc->setXMLStandalone(m_stream.isStandaloneDocument(), ec);
+ document()->setXMLStandalone(m_stream.isStandaloneDocument(), ec);
QStringRef version = m_stream.documentVersion();
if (!version.isEmpty())
- m_doc->setXMLVersion(version, ec);
+ document()->setXMLVersion(version, ec);
QStringRef encoding = m_stream.documentEncoding();
if (!encoding.isEmpty())
- m_doc->setXMLEncoding(encoding);
+ document()->setXMLEncoding(encoding);
}
}
@@ -475,7 +471,7 @@ void XMLDocumentParser::parseStartElement()
}
QualifiedName qName(prefix, localName, uri);
- RefPtr<Element> newElement = m_doc->createElement(qName, true);
+ RefPtr<Element> newElement = document()->createElement(qName, true);
if (!newElement) {
stopParsing();
return;
@@ -529,8 +525,8 @@ void XMLDocumentParser::parseStartElement()
if (m_view && !newElement->attached())
newElement->attach();
- if (isFirstElement && m_doc->frame())
- m_doc->frame()->loader()->dispatchDocumentElementAvailable();
+ if (isFirstElement && document()->frame())
+ document()->frame()->loader()->dispatchDocumentElementAvailable();
}
void XMLDocumentParser::parseEndElement()
@@ -574,7 +570,7 @@ void XMLDocumentParser::parseEndElement()
#if ENABLE(XHTMLMP)
if (!scriptElement->shouldExecuteAsJavaScript())
- m_doc->setShouldProcessNoscriptElement(true);
+ document()->setShouldProcessNoscriptElement(true);
else
#endif
{
@@ -583,7 +579,7 @@ void XMLDocumentParser::parseEndElement()
// we have a src attribute
String scriptCharset = scriptElement->scriptCharset();
if (element->dispatchBeforeLoadEvent(scriptHref) &&
- (m_pendingScript = m_doc->docLoader()->requestScript(scriptHref, scriptCharset))) {
+ (m_pendingScript = document()->docLoader()->requestScript(scriptHref, scriptCharset))) {
m_scriptElement = element;
m_pendingScript->addClient(this);
@@ -593,7 +589,7 @@ void XMLDocumentParser::parseEndElement()
} else
m_scriptElement = 0;
} else
- m_view->frame()->script()->executeScript(ScriptSourceCode(scriptElement->scriptContent(), m_doc->url(), m_scriptStartLine));
+ m_view->frame()->script()->executeScript(ScriptSourceCode(scriptElement->scriptContent(), document()->url(), m_scriptStartLine));
}
m_requestingScript = false;
popCurrentNode();
@@ -613,7 +609,7 @@ void XMLDocumentParser::parseProcessingInstruction()
// ### handle exceptions
int exception = 0;
- RefPtr<ProcessingInstruction> pi = m_doc->createProcessingInstruction(
+ RefPtr<ProcessingInstruction> pi = document()->createProcessingInstruction(
m_stream.processingInstructionTarget(),
m_stream.processingInstructionData(), exception);
if (exception)
@@ -630,7 +626,7 @@ void XMLDocumentParser::parseProcessingInstruction()
#if ENABLE(XSLT)
m_sawXSLTransform = !m_sawFirstElement && pi->isXSL();
- if (m_sawXSLTransform && !m_doc->transformSourceDocument())
+ if (m_sawXSLTransform && !document()->transformSourceDocument())
stopParsing();
#endif
}
@@ -639,7 +635,7 @@ void XMLDocumentParser::parseCdata()
{
exitText();
- RefPtr<Node> newNode = CDATASection::create(m_doc, m_stream.text());
+ RefPtr<Node> newNode = CDATASection::create(document(), m_stream.text());
if (!m_currentNode->addChild(newNode.get()))
return;
if (m_view && !newNode->attached())
@@ -650,7 +646,7 @@ void XMLDocumentParser::parseComment()
{
exitText();
- RefPtr<Node> newNode = Comment::create(m_doc, m_stream.text());
+ RefPtr<Node> newNode = Comment::create(document(), m_stream.text());
m_currentNode->addChild(newNode.get());
if (m_view && !newNode->attached())
newNode->attach();
@@ -695,14 +691,14 @@ void XMLDocumentParser::parseDtd()
return;
}
- if (m_doc->isXHTMLMPDocument()) // check if the MIME type is correct with this method
+ if (document()->isXHTMLMPDocument()) // check if the MIME type is correct with this method
setIsXHTMLMPDocument(true);
else
setIsXHTMLDocument(true);
}
#endif
#if ENABLE(WML)
- else if (m_doc->isWMLDocument()
+ else if (document()->isWMLDocument()
&& publicId != QLatin1String("-//WAPFORUM//DTD WML 1.3//EN")
&& publicId != QLatin1String("-//WAPFORUM//DTD WML 1.2//EN")
&& publicId != QLatin1String("-//WAPFORUM//DTD WML 1.1//EN")
@@ -710,7 +706,7 @@ void XMLDocumentParser::parseDtd()
handleError(fatal, "Invalid DTD Public ID", lineNumber(), columnNumber());
#endif
if (!m_parsingFragment)
- m_doc->addChild(DocumentType::create(m_doc, name, publicId, systemId));
+ document()->addChild(DocumentType::create(document(), name, publicId, systemId));
}
}
diff --git a/WebCore/dom/XMLDocumentParserScope.h b/WebCore/dom/XMLDocumentParserScope.h
index 89740d2..bdf629d 100644
--- a/WebCore/dom/XMLDocumentParserScope.h
+++ b/WebCore/dom/XMLDocumentParserScope.h
@@ -23,8 +23,8 @@
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
-#ifndef XMLTokenizerScope_h
-#define XMLTokenizerScope_h
+#ifndef XMLDocumentParserScope_h
+#define XMLDocumentParserScope_h
#include <wtf/Noncopyable.h>
@@ -59,4 +59,4 @@ namespace WebCore {
} // namespace WebCore
-#endif // XMLTokenizerScope_h
+#endif // XMLDocumentParserScope_h