diff options
author | Lorry Tar Creator <lorry-tar-importer@lorry> | 2017-06-27 06:07:23 +0000 |
---|---|---|
committer | Lorry Tar Creator <lorry-tar-importer@lorry> | 2017-06-27 06:07:23 +0000 |
commit | 1bf1084f2b10c3b47fd1a588d85d21ed0eb41d0c (patch) | |
tree | 46dcd36c86e7fbc6e5df36deb463b33e9967a6f7 /Source/WebCore/xml/XMLErrors.cpp | |
parent | 32761a6cee1d0dee366b885b7b9c777e67885688 (diff) | |
download | WebKitGtk-tarball-master.tar.gz |
webkitgtk-2.16.5HEADwebkitgtk-2.16.5master
Diffstat (limited to 'Source/WebCore/xml/XMLErrors.cpp')
-rw-r--r-- | Source/WebCore/xml/XMLErrors.cpp | 92 |
1 files changed, 48 insertions, 44 deletions
diff --git a/Source/WebCore/xml/XMLErrors.cpp b/Source/WebCore/xml/XMLErrors.cpp index 6adfded72..d967f13ac 100644 --- a/Source/WebCore/xml/XMLErrors.cpp +++ b/Source/WebCore/xml/XMLErrors.cpp @@ -30,15 +30,17 @@ #include "XMLErrors.h" #include "Document.h" -#include "Element.h" #include "Frame.h" +#include "HTMLBodyElement.h" +#include "HTMLDivElement.h" +#include "HTMLHeadElement.h" +#include "HTMLHeadingElement.h" +#include "HTMLHtmlElement.h" #include "HTMLNames.h" -#include "Text.h" -#include <wtf/text/WTFString.h> - -#if ENABLE(SVG) +#include "HTMLParagraphElement.h" +#include "HTMLStyleElement.h" #include "SVGNames.h" -#endif +#include "Text.h" namespace WebCore { @@ -46,10 +48,8 @@ using namespace HTMLNames; const int maxErrors = 25; -XMLErrors::XMLErrors(Document* document) +XMLErrors::XMLErrors(Document& document) : m_document(document) - , m_errorCount(0) - , m_lastErrorPosition(TextPosition::belowRangePosition()) { } @@ -60,7 +60,7 @@ void XMLErrors::handleError(ErrorType type, const char* message, int lineNumber, void XMLErrors::handleError(ErrorType type, const char* message, TextPosition position) { - if (type == fatal || (m_errorCount < maxErrors && m_lastErrorPosition.m_line != position.m_line && m_lastErrorPosition.m_column != position.m_column)) { + if (type == fatal || (m_errorCount < maxErrors && (!m_lastErrorPosition || (m_lastErrorPosition->m_line != position.m_line && m_lastErrorPosition->m_column != position.m_column)))) { switch (type) { case warning: appendErrorMessage("warning", position, message); @@ -87,31 +87,31 @@ void XMLErrors::appendErrorMessage(const String& typeString, TextPosition positi m_errorMessages.append(message); } -static inline PassRefPtr<Element> createXHTMLParserErrorHeader(Document* doc, const String& errorMessages) +static inline Ref<Element> createXHTMLParserErrorHeader(Document& document, const String& errorMessages) { - RefPtr<Element> reportElement = doc->createElement(QualifiedName(nullAtom, "parsererror", xhtmlNamespaceURI), true); + Ref<Element> reportElement = document.createElement(QualifiedName(nullAtom, "parsererror", xhtmlNamespaceURI), true); Vector<Attribute> reportAttributes; reportAttributes.append(Attribute(styleAttr, "display: block; white-space: pre; border: 2px solid #c77; padding: 0 1em 0 1em; margin: 1em; background-color: #fdd; color: black")); reportElement->parserSetAttributes(reportAttributes); - RefPtr<Element> h3 = doc->createElement(h3Tag, true); - reportElement->parserAppendChild(h3.get()); - h3->parserAppendChild(doc->createTextNode("This page contains the following errors:")); + auto h3 = HTMLHeadingElement::create(h3Tag, document); + reportElement->parserAppendChild(h3); + h3->parserAppendChild(Text::create(document, ASCIILiteral("This page contains the following errors:"))); - RefPtr<Element> fixed = doc->createElement(divTag, true); + auto fixed = HTMLDivElement::create(document); Vector<Attribute> fixedAttributes; fixedAttributes.append(Attribute(styleAttr, "font-family:monospace;font-size:12px")); fixed->parserSetAttributes(fixedAttributes); - reportElement->parserAppendChild(fixed.get()); + reportElement->parserAppendChild(fixed); - fixed->parserAppendChild(doc->createTextNode(errorMessages)); + fixed->parserAppendChild(Text::create(document, errorMessages)); - h3 = doc->createElement(h3Tag, true); - reportElement->parserAppendChild(h3.get()); - h3->parserAppendChild(doc->createTextNode("Below is a rendering of the page up to the first error.")); + h3 = HTMLHeadingElement::create(h3Tag, document); + reportElement->parserAppendChild(h3); + h3->parserAppendChild(Text::create(document, ASCIILiteral("Below is a rendering of the page up to the first error."))); - return reportElement.release(); + return reportElement; } void XMLErrors::insertErrorMessageBlock() @@ -121,50 +121,54 @@ void XMLErrors::insertErrorMessageBlock() // where the errors are located) // Create elements for display - RefPtr<Element> documentElement = m_document->documentElement(); + RefPtr<Element> documentElement = m_document.documentElement(); if (!documentElement) { - RefPtr<Element> rootElement = m_document->createElement(htmlTag, true); - RefPtr<Element> body = m_document->createElement(bodyTag, true); + auto rootElement = HTMLHtmlElement::create(m_document); + auto body = HTMLBodyElement::create(m_document); rootElement->parserAppendChild(body); - m_document->parserAppendChild(rootElement); - documentElement = body.get(); - } -#if ENABLE(SVG) - else if (documentElement->namespaceURI() == SVGNames::svgNamespaceURI) { - RefPtr<Element> rootElement = m_document->createElement(htmlTag, true); - RefPtr<Element> body = m_document->createElement(bodyTag, true); + m_document.parserAppendChild(rootElement); + documentElement = WTFMove(body); + } else if (documentElement->namespaceURI() == SVGNames::svgNamespaceURI) { + auto rootElement = HTMLHtmlElement::create(m_document); + auto head = HTMLHeadElement::create(m_document); + auto style = HTMLStyleElement::create(m_document); + head->parserAppendChild(style); + style->parserAppendChild(m_document.createTextNode(ASCIILiteral("html, body { height: 100% } parsererror + svg { width: 100%; height: 100% }"))); + style->finishParsingChildren(); + rootElement->parserAppendChild(head); + auto body = HTMLBodyElement::create(m_document); rootElement->parserAppendChild(body); - documentElement->parentNode()->parserRemoveChild(*documentElement); + m_document.parserRemoveChild(*documentElement); + if (!documentElement->parentNode()) + body->parserAppendChild(*documentElement); - body->parserAppendChild(documentElement); - m_document->parserAppendChild(rootElement.get()); + m_document.parserAppendChild(rootElement); - documentElement = body.get(); + documentElement = WTFMove(body); } -#endif String errorMessages = m_errorMessages.toString(); - RefPtr<Element> reportElement = createXHTMLParserErrorHeader(m_document, errorMessages); + auto reportElement = createXHTMLParserErrorHeader(m_document, errorMessages); #if ENABLE(XSLT) - if (m_document->transformSourceDocument()) { + if (m_document.transformSourceDocument()) { Vector<Attribute> attributes; attributes.append(Attribute(styleAttr, "white-space: normal")); - RefPtr<Element> paragraph = m_document->createElement(pTag, true); + auto paragraph = HTMLParagraphElement::create(m_document); paragraph->parserSetAttributes(attributes); - paragraph->parserAppendChild(m_document->createTextNode("This document was created as the result of an XSL transformation. The line and column numbers given are from the transformed result.")); - reportElement->parserAppendChild(paragraph.release()); + paragraph->parserAppendChild(m_document.createTextNode(ASCIILiteral("This document was created as the result of an XSL transformation. The line and column numbers given are from the transformed result."))); + reportElement->parserAppendChild(paragraph); } #endif Node* firstChild = documentElement->firstChild(); if (firstChild) - documentElement->parserInsertBefore(reportElement, documentElement->firstChild()); + documentElement->parserInsertBefore(reportElement, *firstChild); else documentElement->parserAppendChild(reportElement); - m_document->updateStyleIfNeeded(); + m_document.updateStyleIfNeeded(); } } // namespace WebCore |