diff options
Diffstat (limited to 'WebCore/html')
121 files changed, 2692 insertions, 650 deletions
diff --git a/WebCore/html/FileReader.cpp b/WebCore/html/FileReader.cpp index 69e01ce..3442342 100644 --- a/WebCore/html/FileReader.cpp +++ b/WebCore/html/FileReader.cpp @@ -41,6 +41,7 @@ #include "Logging.h" #include "ProgressEvent.h" #include "ScriptExecutionContext.h" +#include "TextResourceDecoder.h" #include <wtf/CurrentTime.h> namespace WebCore { @@ -50,14 +51,13 @@ const double progressNotificationIntervalMS = 50; FileReader::FileReader(ScriptExecutionContext* context) : ActiveDOMObject(context, this) - , m_state(Empty) + , m_state(None) , m_readType(ReadFileAsBinaryString) , m_result("") , m_isRawDataConverted(false) , m_bytesLoaded(0) , m_totalBytes(0) , m_lastProgressNotificationTimeMS(0) - , m_alreadyStarted(false) { m_buffer.resize(bufferSize); } @@ -69,7 +69,7 @@ FileReader::~FileReader() bool FileReader::hasPendingActivity() const { - return m_state == Loading || ActiveDOMObject::hasPendingActivity(); + return (m_state != None && m_state != Completed) || ActiveDOMObject::hasPendingActivity(); } bool FileReader::canSuspend() const @@ -110,11 +110,12 @@ void FileReader::readAsDataURL(File* file) void FileReader::readInternal(Blob* fileBlob, ReadType type) { // readAs*** methods() can be called multiple times. Only the last call before the actual reading happens is processed. - if (m_alreadyStarted) + if (m_state != None && m_state != Starting) return; m_fileBlob = fileBlob; m_readType = type; + m_state = Starting; // When FileStreamProxy is created, FileReader::didStart() will get notified on the File thread and we will start // opening and reading the file since then. @@ -142,18 +143,18 @@ void FileReader::terminate() m_streamProxy->stop(); m_streamProxy = 0; } - m_state = Done; + m_state = Completed; } void FileReader::didStart() { - m_alreadyStarted = true; + m_state = Opening; m_streamProxy->openForRead(m_fileBlob.get()); } void FileReader::didGetSize(long long size) { - m_state = Loading; + m_state = Reading; fireEvent(eventNames().loadstartEvent); m_totalBytes = size; @@ -165,7 +166,7 @@ void FileReader::didRead(const char* data, int bytesRead) ASSERT(data && bytesRead); // Bail out if we have aborted the reading. - if (m_state == Done) + if (m_state == Completed) return; switch (m_readType) { @@ -198,7 +199,7 @@ void FileReader::didRead(const char* data, int bytesRead) void FileReader::didFinish() { - m_state = Done; + m_state = Completed; m_streamProxy->close(); @@ -208,7 +209,7 @@ void FileReader::didFinish() void FileReader::didFail(ExceptionCode ec) { - m_state = Done; + m_state = Completed; m_error = FileError::create(ec); m_streamProxy->close(); @@ -223,6 +224,22 @@ void FileReader::fireEvent(const AtomicString& type) dispatchEvent(ProgressEvent::create(type, true, static_cast<unsigned>(m_bytesLoaded), static_cast<unsigned>(m_totalBytes))); } +FileReader::ReadyState FileReader::readyState() const +{ + switch (m_state) { + case None: + case Starting: + return Empty; + case Opening: + case Reading: + return Loading; + case Completed: + return Done; + } + ASSERT_NOT_REACHED(); + return Empty; +} + const ScriptString& FileReader::result() { // If reading as binary string, we can return the result immediately. @@ -237,7 +254,7 @@ const ScriptString& FileReader::result() if (m_readType == ReadFileAsText) convertToText(); // For data URL, we only do the coversion until we receive all the raw data. - else if (m_readType == ReadFileAsDataURL && m_state == Done) + else if (m_readType == ReadFileAsDataURL && m_state == Completed) convertToDataURL(); return m_result; @@ -250,26 +267,17 @@ void FileReader::convertToText() return; } - // Try to determine the encoding if it is not provided. - // FIXME: move the following logic to a more generic place. - int offset = 0; - if (!m_encoding.isValid()) { - if (m_rawData.size() >= 2 && m_rawData[0] == '\xFE' && m_rawData[1] == '\xFF') { - offset = 2; - m_encoding = UTF16BigEndianEncoding(); - } else if (m_rawData.size() >= 2 && m_rawData[0] == '\xFF' && m_rawData[1] == '\xFE') { - offset = 2; - m_encoding = UTF16LittleEndianEncoding(); - } else if (m_rawData.size() >= 2 && m_rawData[0] == '\xEF' && m_rawData[1] == '\xBB' && m_rawData[2] == '\xBF') { - offset = 3; - m_encoding = UTF8Encoding(); - } else - m_encoding = UTF8Encoding(); - } - // Decode the data. + // The File API spec says that we should use the supplied encoding if it is valid. However, we choose to ignore this + // requirement in order to be consistent with how WebKit decodes the web content: always has the BOM override the + // provided encoding. // FIXME: consider supporting incremental decoding to improve the perf. - m_result = m_encoding.decode(&m_rawData.at(0) + offset, m_rawData.size() - offset); + if (!m_decoder) + m_decoder = TextResourceDecoder::create("text/plain", m_encoding.isValid() ? m_encoding : UTF8Encoding()); + m_result = m_decoder->decode(&m_rawData.at(0), m_rawData.size()); + + if (m_state == Completed && !m_error) + m_result += m_decoder->flush(); } void FileReader::convertToDataURL() diff --git a/WebCore/html/FileReader.h b/WebCore/html/FileReader.h index b30fad7..80d425c 100644 --- a/WebCore/html/FileReader.h +++ b/WebCore/html/FileReader.h @@ -51,6 +51,7 @@ class Blob; class File; class FileStreamProxy; class ScriptExecutionContext; +class TextResourceDecoder; class FileReader : public RefCounted<FileReader>, public ActiveDOMObject, public EventTarget, public FileStreamClient { public: @@ -72,7 +73,7 @@ public: void readAsDataURL(File*); void abort(); - ReadyState readyState() const { return m_state; } + ReadyState readyState() const; PassRefPtr<FileError> error() { return m_error; } const ScriptString& result(); @@ -108,6 +109,13 @@ private: ReadFileAsText, ReadFileAsDataURL }; + enum InternalState { + None, + Starting, + Opening, + Reading, + Completed + }; FileReader(ScriptExecutionContext*); @@ -123,11 +131,12 @@ private: void convertToText(); void convertToDataURL(); - ReadyState m_state; + InternalState m_state; EventTargetData m_eventTargetData; RefPtr<Blob> m_fileBlob; ReadType m_readType; + TextEncoding m_encoding; // Like XMLHttpRequest.m_responseText, we keep this as a ScriptString, not a WebCore::String. // That's because these strings can easily get huge (they are filled from the file) and @@ -141,8 +150,8 @@ private: Vector<char> m_rawData; bool m_isRawDataConverted; - // Encoding scheme used to decode the data. - TextEncoding m_encoding; + // The decoder used to decode the text data. + RefPtr<TextResourceDecoder> m_decoder; // Needed to create data URL. String m_fileType; @@ -153,7 +162,6 @@ private: long long m_bytesLoaded; long long m_totalBytes; double m_lastProgressNotificationTimeMS; - bool m_alreadyStarted; }; } // namespace WebCore diff --git a/WebCore/html/FileStreamProxy.cpp b/WebCore/html/FileStreamProxy.cpp index 6b41f32..eb99cf3 100644 --- a/WebCore/html/FileStreamProxy.cpp +++ b/WebCore/html/FileStreamProxy.cpp @@ -35,10 +35,10 @@ #include "FileStreamProxy.h" #include "Blob.h" +#include "CrossThreadTask.h" #include "FileStream.h" #include "FileThread.h" #include "FileThreadTask.h" -#include "GenericWorkerTask.h" #include "PlatformString.h" #include "ScriptExecutionContext.h" diff --git a/WebCore/html/HTML5Lexer.cpp b/WebCore/html/HTML5Lexer.cpp new file mode 100644 index 0000000..44eae83 --- /dev/null +++ b/WebCore/html/HTML5Lexer.cpp @@ -0,0 +1,1319 @@ +/* + * Copyright (C) 2008 Apple Inc. All Rights Reserved. + * Copyright (C) 2009 Torch Mobile, Inc. http://www.torchmobile.com/ + * 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. + */ + +#include "config.h" +#include "HTML5Lexer.h" + +#include "AtomicString.h" +#include "HTML5Token.h" +#include "HTMLNames.h" +#include "NotImplemented.h" +#include <wtf/CurrentTime.h> +#include <wtf/UnusedParam.h> +#include <wtf/text/CString.h> +#include <wtf/unicode/Unicode.h> + + +// Use __GNUC__ instead of PLATFORM(GCC) to stay consistent with the gperf generated c file +#ifdef __GNUC__ +// The main tokenizer includes this too so we are getting two copies of the data. However, this way the code gets inlined. +#include "HTMLEntityNames.c" +#else +// Not inlined for non-GCC compilers +struct Entity { + const char* name; + int code; +}; +const struct Entity* findEntity(register const char* str, register unsigned int len); +#endif + +using namespace WTF; + +namespace WebCore { + +using namespace HTMLNames; + +inline UChar toLowerCase(UChar cc) +{ + ASSERT(cc >= 'A' && cc <= 'Z'); + const int lowerCaseOffset = 0x20; + return cc + lowerCaseOffset; +} + +HTML5Lexer::HTML5Lexer() +{ + reset(); +} + +HTML5Lexer::~HTML5Lexer() +{ +} + +void HTML5Lexer::reset() +{ + m_state = DataState; + m_token = 0; + m_emitPending = false; + m_additionalAllowedCharacter = '\0'; +} + +static inline bool isWhitespace(UChar c) +{ + return c == ' ' || c == '\n' || c == '\r' || c == '\t'; +} + +static inline unsigned legalEntityFor(unsigned value) +{ + // FIXME There is a table for more exceptions in the HTML5 specification. + if (value == 0 || value > 0x10FFFF || (value >= 0xD800 && value <= 0xDFFF)) + return 0xFFFD; + return value; +} + +unsigned HTML5Lexer::consumeEntity(SegmentedString& source, bool& notEnoughCharacters) +{ + enum EntityState { + Initial, + NumberType, + MaybeHex, + Hex, + Decimal, + Named + }; + EntityState entityState = Initial; + unsigned result = 0; + Vector<UChar, 10> seenChars; + Vector<char, 10> entityName; + + while (!source.isEmpty()) { + UChar cc = *source; + seenChars.append(cc); + switch (entityState) { + case Initial: + if (isWhitespace(cc) || cc == '<' || cc == '&') + return 0; + else if (cc == '#') + entityState = NumberType; + else if ((cc >= 'a' && cc <= 'z') || (cc >= 'A' && cc <= 'Z')) { + entityName.append(cc); + entityState = Named; + } else + return 0; + break; + case NumberType: + if (cc == 'x' || cc == 'X') + entityState = MaybeHex; + else if (cc >= '0' && cc <= '9') { + entityState = Decimal; + result = cc - '0'; + } else { + source.push('#'); + return 0; + } + break; + case MaybeHex: + if (cc >= '0' && cc <= '9') + result = cc - '0'; + else if (cc >= 'a' && cc <= 'f') + result = 10 + cc - 'a'; + else if (cc >= 'A' && cc <= 'F') + result = 10 + cc - 'A'; + else { + source.push('#'); + source.push(seenChars[1]); + return 0; + } + entityState = Hex; + break; + case Hex: + if (cc >= '0' && cc <= '9') + result = result * 16 + cc - '0'; + else if (cc >= 'a' && cc <= 'f') + result = result * 16 + 10 + cc - 'a'; + else if (cc >= 'A' && cc <= 'F') + result = result * 16 + 10 + cc - 'A'; + else if (cc == ';') { + source.advance(); + return legalEntityFor(result); + } else + return legalEntityFor(result); + break; + case Decimal: + if (cc >= '0' && cc <= '9') + result = result * 10 + cc - '0'; + else if (cc == ';') { + source.advance(); + return legalEntityFor(result); + } else + return legalEntityFor(result); + break; + case Named: + // This is the attribute only version, generic version matches somewhat differently + while (entityName.size() <= 8) { + if (cc == ';') { + const Entity* entity = findEntity(entityName.data(), entityName.size()); + if (entity) { + source.advance(); + return entity->code; + } + break; + } + if (!(cc >= 'a' && cc <= 'z') && !(cc >= 'A' && cc <= 'Z') && !(cc >= '0' && cc <= '9')) { + const Entity* entity = findEntity(entityName.data(), entityName.size()); + if (entity) + return entity->code; + break; + } + entityName.append(cc); + source.advance(); + if (source.isEmpty()) + goto outOfCharacters; + cc = *source; + seenChars.append(cc); + } + if (seenChars.size() == 2) + source.push(seenChars[0]); + else if (seenChars.size() == 3) { + source.push(seenChars[0]); + source.push(seenChars[1]); + } else + source.prepend(SegmentedString(String(seenChars.data(), seenChars.size() - 1))); + return 0; + } + source.advance(); + } +outOfCharacters: + notEnoughCharacters = true; + source.prepend(SegmentedString(String(seenChars.data(), seenChars.size()))); + return 0; +} + +bool HTML5Lexer::nextToken(SegmentedString& source, HTML5Token& token) +{ + // If we have a token in progress, then we're supposed to be called back + // with the same token so we can finish it. + ASSERT(!m_token || m_token == &token || token.type() == HTML5Token::Uninitialized); + m_token = &token; + + if (!m_bufferedEndTagName.isEmpty()) { + // We started an end tag during our last iteration. + m_token->beginEndTag(m_bufferedEndTagName); + m_bufferedEndTagName.clear(); + if (m_state == DataState) { + // We're back in the data state, so we must be done with the tag. + return true; + } + } + + // Source: http://www.whatwg.org/specs/web-apps/current-work/#tokenisation0 + // FIXME: This while should stop as soon as we have a token to return. + while (!source.isEmpty()) { + UChar cc = *source; + switch (m_state) { + case DataState: { + if (cc == '&') + m_state = CharacterReferenceInDataState; + else if (cc == '<') { + if (m_token->type() == HTML5Token::Character) { + // We have a bunch of character tokens queued up that we + // are emitting lazily here. + return true; + } + m_state = TagOpenState; + } else + emitCharacter(cc); + break; + } + case CharacterReferenceInDataState: { + notImplemented(); + break; + } + case RCDATAState: { + if (cc == '&') + m_state = CharacterReferenceInRCDATAState; + else if (cc == '<') + m_state = RCDATALessThanSignState; + else + emitCharacter(cc); + break; + } + case CharacterReferenceInRCDATAState: { + notImplemented(); + break; + } + case RAWTEXTState: { + if (cc == '<') + m_state = RAWTEXTLessThanSignState; + else + emitCharacter(cc); + break; + } + case ScriptDataState: { + if (cc == '<') + m_state = ScriptDataLessThanSignState; + else + emitCharacter(cc); + break; + } + case PLAINTEXTState: { + emitCharacter(cc); + break; + } + case TagOpenState: { + if (cc == '!') + m_state = MarkupDeclarationOpenState; + else if (cc == '/') + m_state = EndTagOpenState; + else if (cc >= 'A' && cc <= 'Z') { + m_token->beginStartTag(toLowerCase(cc)); + m_state = TagNameState; + } else if (cc >= 'a' && cc <= 'z') { + m_token->beginStartTag(cc); + m_state = TagNameState; + } else if (cc == '?') { + emitParseError(); + m_state = BogusCommentState; + } else { + emitParseError(); + m_state = DataState; + emitCharacter('<'); + continue; + } + break; + } + case EndTagOpenState: { + if (cc >= 'A' && cc <= 'Z') { + m_token->beginEndTag(toLowerCase(cc)); + m_state = TagNameState; + } else if (cc >= 'a' && cc <= 'z') { + m_token->beginEndTag(cc); + m_state = TagNameState; + } else if (cc == '>') { + emitParseError(); + m_state = DataState; + } else { + emitParseError(); + m_state = DataState; + } + // FIXME: Handle EOF properly. + break; + } + case TagNameState: { + if (cc == '\x09' || cc == '\x0A' || cc == '\x0C' || cc == ' ') + m_state = BeforeAttributeNameState; + else if (cc == '/') + m_state = SelfClosingStartTagState; + else if (cc == '>') { + emitCurrentToken(); + m_state = DataState; + } else if (cc >= 'A' && cc <= 'Z') + m_token->appendToName(toLowerCase(cc)); + else + m_token->appendToName(cc); + // FIXME: Handle EOF properly. + break; + } + case RCDATALessThanSignState: { + if (cc == '/') { + m_temporaryBuffer.clear(); + m_state = RCDATAEndTagOpenState; + } else { + emitCharacter('<'); + m_state = RCDATAState; + continue; + } + break; + } + case RCDATAEndTagOpenState: { + if (cc >= 'A' && cc <= 'Z') { + notImplemented(); + m_state = RCDATAEndTagNameState; + } else if (cc >= 'a' && cc <= 'z') { + notImplemented(); + m_state = RCDATAEndTagNameState; + emitCharacter('<'); + emitCharacter('/'); + m_state = RCDATAState; + continue; + } + break; + } + case RCDATAEndTagNameState: { + if (cc == '\x09' || cc == '\x0A' || cc == '\x0C' || cc == ' ') { + notImplemented(); + m_state = BeforeAttributeNameState; + } else if (cc == '/') { + notImplemented(); + m_state = SelfClosingStartTagState; + } else if (cc == '>') { + notImplemented(); + m_state = DataState; + } else if (cc >= 'A' && cc <= 'Z') + notImplemented(); + else if (cc >= 'a' && cc <= 'z') + notImplemented(); + else { + emitCharacter('<'); + emitCharacter('/'); + notImplemented(); + m_state = RCDATAState; + continue; + } + break; + } + case RAWTEXTLessThanSignState: { + if (cc == '/') { + m_temporaryBuffer.clear(); + m_state = RAWTEXTEndTagOpenState; + } else { + emitCharacter('<'); + m_state = RAWTEXTState; + continue; + } + break; + } + case RAWTEXTEndTagOpenState: { + if (cc >= 'A' && cc <= 'Z') { + notImplemented(); + m_state = RAWTEXTEndTagNameState; + } else if (cc >= 'a' && cc <= 'z') { + notImplemented(); + m_state = RAWTEXTEndTagNameState; + } else { + emitCharacter('<'); + emitCharacter('/'); + m_state = RAWTEXTState; + continue; + } + break; + } + case RAWTEXTEndTagNameState: { + if (cc == '\x09' || cc == '\x0A' || cc == '\x0C' || cc == ' ') { + notImplemented(); + m_state = BeforeAttributeNameState; + } else if (cc == '/') { + notImplemented(); + m_state = SelfClosingStartTagState; + } else if (cc == '>') { + notImplemented(); + m_state = DataState; + } else if (cc >= 'A' && cc <= 'Z') + notImplemented(); + else if (cc >= 'a' && cc <= 'z') + notImplemented(); + else { + emitCharacter('<'); + emitCharacter('/'); + notImplemented(); + m_state = RAWTEXTState; + continue; + } + } + case ScriptDataLessThanSignState: { + if (cc == '/') { + m_temporaryBuffer.clear(); + ASSERT(m_bufferedEndTagName.isEmpty()); + m_state = ScriptDataEndTagOpenState; + } else if (cc == '!') { + emitCharacter('<'); + emitCharacter('!'); + m_state = ScriptDataEscapeStartState; + } else { + emitCharacter('<'); + m_state = ScriptDataState; + continue; + } + break; + } + case ScriptDataEndTagOpenState: { + if (cc >= 'A' && cc <= 'Z') { + m_temporaryBuffer.append(cc); + m_bufferedEndTagName.append(toLowerCase(cc)); + m_state = ScriptDataEndTagNameState; + } else if (cc >= 'a' && cc <= 'z') { + m_temporaryBuffer.append(cc); + m_bufferedEndTagName.append(cc); + m_state = ScriptDataEndTagNameState; + } else { + emitCharacter('<'); + emitCharacter('/'); + m_state = ScriptDataState; + continue; + } + break; + } + case ScriptDataEndTagNameState: { + if (cc >= 'A' && cc <= 'Z') { + m_temporaryBuffer.append(cc); + m_bufferedEndTagName.append(toLowerCase(cc)); + } else if (cc >= 'a' && cc <= 'z') { + m_temporaryBuffer.append(cc); + m_bufferedEndTagName.append(cc); + } else { + if (cc == '\x09' || cc == '\x0A' || cc == '\x0C' || cc == ' ') { + if (isAppropriateEndTag()) { + m_state = BeforeAttributeNameState; + ASSERT(m_token->type() == HTML5Token::Character); + emitCurrentToken(); + break; + } + } else if (cc == '/') { + if (isAppropriateEndTag()) { + m_state = SelfClosingStartTagState; + ASSERT(m_token->type() == HTML5Token::Character); + emitCurrentToken(); + break; + } + } else if (cc == '>') { + if (isAppropriateEndTag()) { + m_state = DataState; + ASSERT(m_token->type() == HTML5Token::Character); + emitCurrentToken(); + break; + } + } + emitCharacter('<'); + emitCharacter('/'); + m_token->appendToCharacter(m_temporaryBuffer); + m_bufferedEndTagName.clear(); + m_state = ScriptDataState; + continue; + } + break; + } + case ScriptDataEscapeStartState: { + if (cc == '-') { + emitCharacter(cc); + m_state = ScriptDataEscapeStartDashState; + } else { + m_state = ScriptDataState; + continue; + } + break; + } + case ScriptDataEscapeStartDashState: { + if (cc == '-') { + emitCharacter(cc); + m_state = ScriptDataEscapedDashDashState; + } else { + m_state = ScriptDataState; + continue; + } + break; + } + case ScriptDataEscapedState: { + if (cc == '-') { + emitCharacter(cc); + m_state = ScriptDataEscapedDashState; + } else if (cc == '<') + m_state = ScriptDataEscapedLessThanSignState; + else + emitCharacter(cc); + // FIXME: Handle EOF properly. + break; + } + case ScriptDataEscapedDashState: { + if (cc == '-') { + emitCharacter(cc); + m_state = ScriptDataEscapedDashDashState; + } else if (cc == '<') + m_state = ScriptDataEscapedLessThanSignState; + else { + emitCharacter(cc); + m_state = ScriptDataEscapedState; + } + // FIXME: Handle EOF properly. + break; + } + case ScriptDataEscapedDashDashState: { + if (cc == '-') + emitCharacter(cc); + else if (cc == '<') + m_state = ScriptDataEscapedLessThanSignState; + else if (cc == '>') { + emitCharacter(cc); + m_state = ScriptDataState; + } else { + emitCharacter(cc); + m_state = ScriptDataEscapedState; + } + // FIXME: Handle EOF properly. + break; + } + case ScriptDataEscapedLessThanSignState: { + if (cc == '/') { + m_temporaryBuffer.clear(); + m_state = ScriptDataEscapedEndTagOpenState; + } else if (cc >= 'A' && cc <= 'Z') { + notImplemented(); + m_state = ScriptDataDoubleEscapeStartState; + } else if (cc >= 'a' && cc <= 'z') { + notImplemented(); + m_state = ScriptDataDoubleEscapeStartState; + } else { + emitCharacter('<'); + m_state = ScriptDataEscapedState; + continue; + } + break; + } + case ScriptDataEscapedEndTagOpenState: { + if (cc >= 'A' && cc <= 'Z') { + notImplemented(); + m_state = ScriptDataEscapedEndTagNameState; + } else if (cc >= 'a' && cc <= 'z') { + notImplemented(); + m_state = ScriptDataEscapedEndTagNameState; + } else { + emitCharacter('<'); + emitCharacter('/'); + m_state = ScriptDataEscapedState; + continue; + } + break; + } + case ScriptDataEscapedEndTagNameState: { + if (cc == '\x09' || cc == '\x0A' || cc == '\x0C' || cc == ' ') { + notImplemented(); + m_state = BeforeAttributeNameState; + } else if (cc == '/') { + notImplemented(); + m_state = SelfClosingStartTagState; + } else if (cc == '>') { + notImplemented(); + m_state = DataState; + } else if (cc >= 'A' && cc <= 'Z') + notImplemented(); + else if (cc >= 'a' && cc <= 'z') + notImplemented(); + else { + emitCharacter('<'); + emitCharacter('/'); + notImplemented(); + m_state = ScriptDataEscapedState; + continue; + } + break; + } + case ScriptDataDoubleEscapeStartState: { + if (cc == '\x09' || cc == '\x0A' || cc == '\x0C' || cc == ' ' || cc == '/' || cc == '>') { + emitCharacter(cc); + if (temporaryBufferIs("string")) + m_state = ScriptDataDoubleEscapedState; + else + m_state = ScriptDataEscapedState; + } else if (cc >= 'A' && cc <= 'Z') + notImplemented(); + else if (cc >= 'a' && cc <= 'z') + notImplemented(); + else { + m_state = ScriptDataEscapedState; + continue; + } + break; + } + case ScriptDataDoubleEscapedState: { + if (cc == '-') { + emitCharacter(cc); + m_state = ScriptDataDoubleEscapedDashState; + } else if (cc == '<') { + emitCharacter(cc); + m_state = ScriptDataDoubleEscapedLessThanSignState; + } else + emitCharacter(cc); + // FIXME: Handle EOF properly. + break; + } + case ScriptDataDoubleEscapedDashState: { + if (cc == '-') { + emitCharacter(cc); + m_state = ScriptDataDoubleEscapedDashDashState; + } else if (cc == '<') { + emitCharacter(cc); + m_state = ScriptDataDoubleEscapedLessThanSignState; + } else { + emitCharacter(cc); + m_state = ScriptDataDoubleEscapedState; + } + // FIXME: Handle EOF properly. + break; + } + case ScriptDataDoubleEscapedDashDashState: { + if (cc == '-') + emitCharacter(cc); + else if (cc == '<') { + emitCharacter(cc); + m_state = ScriptDataDoubleEscapedLessThanSignState; + } else if (cc == '>') { + emitCharacter(cc); + m_state = ScriptDataState; + } else { + emitCharacter(cc); + m_state = ScriptDataDoubleEscapedState; + } + // FIXME: Handle EOF properly. + break; + } + case ScriptDataDoubleEscapedLessThanSignState: { + if (cc == '/') { + emitCharacter(cc); + m_temporaryBuffer.clear(); + m_state = ScriptDataDoubleEscapeEndState; + } else { + m_state = ScriptDataDoubleEscapedState; + continue; + } + break; + } + case ScriptDataDoubleEscapeEndState: { + if (cc == '\x09' || cc == '\x0A' || cc == '\x0C' || cc == ' ' || cc == '/' || cc == '>') { + emitCharacter(cc); + if (temporaryBufferIs("string")) + m_state = ScriptDataEscapedState; + else + m_state = ScriptDataDoubleEscapedState; + } else if (cc >= 'A' && cc <= 'Z') + notImplemented(); + else if (cc >= 'a' && cc <= 'z') + notImplemented(); + else { + m_state = ScriptDataDoubleEscapedState; + continue; + } + break; + } + case BeforeAttributeNameState: { + if (cc == '\x09' || cc == '\x0A' || cc == '\x0C' || cc == ' ') + break; + else if (cc == '/') + m_state = SelfClosingStartTagState; + else if (cc == '>') { + emitCurrentToken(); + m_state = DataState; + } else if (cc >= 'A' && cc <= 'Z') { + m_token->addNewAttribute(); + m_token->appendToAttributeName(toLowerCase(cc)); + m_state = AttributeNameState; + } else { + if (cc == '"' || cc == '\'' || cc == '<' || cc == '=') + emitParseError(); + m_token->addNewAttribute(); + m_token->appendToAttributeName(cc); + m_state = AttributeNameState; + } + // FIXME: Handle EOF properly. + break; + } + case AttributeNameState: { + if (cc == '\x09' || cc == '\x0A' || cc == '\x0C' || cc == ' ') + m_state = AfterAttributeNameState; + else if (cc == '/') + m_state = SelfClosingStartTagState; + else if (cc == '=') + m_state = BeforeAttributeValueState; + else if (cc == '>') { + emitCurrentToken(); + m_state = DataState; + } else if (cc >= 'A' && cc <= 'Z') + m_token->appendToAttributeName(toLowerCase(cc)); + else { + if (cc == '"' || cc == '\'' || cc == '<' || cc == '=') + emitParseError(); + m_token->appendToAttributeName(cc); + m_state = AttributeNameState; + } + // FIXME: Handle EOF properly. + break; + } + case AfterAttributeNameState: { + if (cc == '\x09' || cc == '\x0A' || cc == '\x0C' || cc == ' ') + break; + else if (cc == '/') + m_state = SelfClosingStartTagState; + else if (cc == '=') + m_state = BeforeAttributeValueState; + else if (cc == '=') { + emitCurrentToken(); + m_state = DataState; + } else if (cc >= 'A' && cc <= 'Z') { + m_token->addNewAttribute(); + m_token->appendToAttributeName(toLowerCase(cc)); + m_state = AttributeNameState; + } else { + if (cc == '"' || cc == '\'' || cc == '<') + emitParseError(); + m_token->addNewAttribute(); + m_token->appendToAttributeName(cc); + m_state = AttributeNameState; + } + // FIXME: Handle EOF properly. + break; + } + case BeforeAttributeValueState: { + if (cc == '\x09' || cc == '\x0A' || cc == '\x0C' || cc == ' ') + break; + else if (cc == '"') + m_state = AttributeValueDoubleQuotedState; + else if (cc == '&') { + m_state = AttributeValueUnquotedState; + continue; + } else if (cc == '\'') + m_state = AttributeValueSingleQuotedState; + else if (cc == '>') { + emitParseError(); + emitCurrentToken(); + m_state = DataState; + } else { + if (cc == '<' || cc == '=' || cc == '`') + emitParseError(); + m_token->appendToAttributeValue(cc); + m_state = AttributeValueUnquotedState; + } + break; + } + case AttributeValueDoubleQuotedState: { + if (cc == '"') + m_state = AfterAttributeValueQuotedState; + else if (cc == '&') { + m_state = CharacterReferenceInAttributeValueState; + m_additionalAllowedCharacter = '"'; + } else + m_token->appendToAttributeValue(cc); + // FIXME: Handle EOF properly. + break; + } + case AttributeValueSingleQuotedState: { + if (cc == '\'') + m_state = AfterAttributeValueQuotedState; + else if (cc == '&') { + m_state = CharacterReferenceInAttributeValueState; + m_additionalAllowedCharacter = '\''; + } else + m_token->appendToAttributeValue(cc); + // FIXME: Handle EOF properly. + break; + } + case AttributeValueUnquotedState: { + if (cc == '\x09' || cc == '\x0A' || cc == '\x0C' || cc == ' ') + m_state = BeforeAttributeNameState; + else if (cc == '&') { + m_state = CharacterReferenceInAttributeValueState; + m_additionalAllowedCharacter = '>'; + } else if (cc == '>') { + emitCurrentToken(); + m_state = DataState; + } else { + if (cc == '"' || cc == '\'' || cc == '<' || cc == '=' || cc == '`') + emitParseError(); + m_token->appendToAttributeValue(cc); + } + // FIXME: Handle EOF properly. + break; + } + case CharacterReferenceInAttributeValueState: { + notImplemented(); + break; + } + case AfterAttributeValueQuotedState: { + if (cc == '\x09' || cc == '\x0A' || cc == '\x0C' || cc == ' ') + m_state = BeforeAttributeNameState; + else if (cc == '/') + m_state = SelfClosingStartTagState; + else if (cc == '>') { + emitCurrentToken(); + m_state = DataState; + } else { + emitParseError(); + m_state = BeforeAttributeNameState; + continue; + } + // FIXME: Handle EOF properly. + break; + } + case SelfClosingStartTagState: { + if (cc == '>') { + notImplemented(); + emitCurrentToken(); + m_state = DataState; + } else { + emitParseError(); + m_state = BeforeAttributeNameState; + continue; + } + // FIXME: Handle EOF properly. + break; + } + case BogusCommentState: { + notImplemented(); + m_state = DataState; + break; + } + case MarkupDeclarationOpenState: { + DEFINE_STATIC_LOCAL(String, dashDashString, ("--")); + if (cc == '-') { + SegmentedString::LookAheadResult result = source.lookAhead(dashDashString); + if (result == SegmentedString::DidMatch) { + source.advanceAndASSERT('-'); + source.advanceAndASSERT('-'); + m_token->beginComment(); + m_state = CommentStartState; + continue; + } else if (result == SegmentedString::NotEnoughCharacters) + return false; // We need to wait for more characters to arrive. + } + notImplemented(); + break; + } + case CommentStartState: { + if (cc == '-') + m_state = CommentStartDashState; + else if (cc == '>') { + emitParseError(); + emitCurrentToken(); + m_state = DataState; + } else { + m_token->appendToComment(cc); + m_state = CommentState; + } + // FIXME: Handle EOF properly. + break; + } + case CommentStartDashState: { + if (cc == '-') + m_state = CommentEndState; + else if (cc == '>') { + emitParseError(); + emitCurrentToken(); + m_state = DataState; + } else { + m_token->appendToComment('-'); + m_token->appendToComment(cc); + m_state = CommentState; + } + // FIXME: Handle EOF properly. + break; + } + case CommentState: { + if (cc == '-') + m_state = CommentEndDashState; + else + m_token->appendToComment(cc); + // FIXME: Handle EOF properly. + break; + } + case CommentEndDashState: { + if (cc == '-') + m_state = CommentEndState; + else { + m_token->appendToComment('-'); + m_token->appendToComment(cc); + m_state = CommentState; + } + // FIXME: Handle EOF properly. + break; + } + case CommentEndState: { + if (cc == '>') { + emitCurrentToken(); + m_state = DataState; + } else if (cc == '\x09' || cc == '\x0A' || cc == '\x0C' || cc == ' ') { + emitParseError(); + m_token->appendToComment('-'); + m_token->appendToComment('-'); + m_token->appendToComment(cc); + m_state = CommentEndSpaceState; + } else if (cc == '!') { + emitParseError(); + m_state = CommentEndBangState; + } else if (cc == '-') { + emitParseError(); + m_token->appendToComment('-'); + m_token->appendToComment(cc); + } else { + emitParseError(); + m_token->appendToComment('-'); + m_token->appendToComment('-'); + m_token->appendToComment(cc); + m_state = CommentState; + } + // FIXME: Handle EOF properly. + break; + } + case CommentEndBangState: { + if (cc == '-') { + m_token->appendToComment('-'); + m_token->appendToComment('-'); + m_token->appendToComment('!'); + m_state = CommentEndDashState; + } else if (cc == '>') { + emitCurrentToken(); + m_state = DataState; + } else { + m_token->appendToComment('-'); + m_token->appendToComment('-'); + m_token->appendToComment('!'); + m_token->appendToComment(cc); + m_state = CommentState; + } + // FIXME: Handle EOF properly. + break; + } + case CommentEndSpaceState: { + if (cc == '\x09' || cc == '\x0A' || cc == '\x0C' || cc == ' ') + m_token->appendToComment(cc); + else if (cc == '-') + m_state = CommentEndDashState; + else if (cc == '>') { + emitCurrentToken(); + m_state = DataState; + } else { + m_token->appendToComment(cc); + m_state = CommentState; + } + // FIXME: Handle EOF properly. + break; + } + case DOCTYPEState: { + if (cc == '\x09' || cc == '\x0A' || cc == '\x0C' || cc == ' ') + m_state = BeforeDOCTYPENameState; + else { + emitParseError(); + m_state = BeforeDOCTYPENameState; + continue; + } + // FIXME: Handle EOF properly. + break; + } + case BeforeDOCTYPENameState: { + if (cc == '\x09' || cc == '\x0A' || cc == '\x0C' || cc == ' ') + break; + else if (cc >= 'A' && cc <= 'Z') { + notImplemented(); + m_state = DOCTYPENameState; + } else if (cc == '>') { + emitParseError(); + notImplemented(); + emitCurrentDoctypeToken(); + m_state = DataState; + } else { + notImplemented(); + m_state = DOCTYPENameState; + } + // FIXME: Handle EOF properly. + break; + } + case DOCTYPENameState: { + if (cc == '\x09' || cc == '\x0A' || cc == '\x0C' || cc == ' ') + m_state = AfterDOCTYPENameState; + else if (cc == '>') { + emitCurrentDoctypeToken(); + m_state = DataState; + } else if (cc >= 'A' && cc <= 'Z') + notImplemented(); + else + notImplemented(); + // FIXME: Handle EOF properly. + break; + } + case AfterDOCTYPENameState: { + if (cc == '\x09' || cc == '\x0A' || cc == '\x0C' || cc == ' ') + break; + else if (cc == '>') { + emitCurrentDoctypeToken(); + m_state = DataState; + } else + notImplemented(); + // FIXME: Handle EOF properly. + break; + } + case AfterDOCTYPEPublicKeywordState: { + if (cc == '\x09' || cc == '\x0A' || cc == '\x0C' || cc == ' ') + m_state = BeforeDOCTYPEPublicIdentifierState; + else if (cc == '"') { + emitParseError(); + notImplemented(); + m_state = DOCTYPEPublicIdentifierDoubleQuotedState; + } else if (cc == '\'') { + emitParseError(); + notImplemented(); + m_state = DOCTYPEPublicIdentifierSingleQuotedState; + } else if (cc == '>') { + emitParseError(); + notImplemented(); + emitCurrentDoctypeToken(); + m_state = DataState; + } else { + emitParseError(); + notImplemented(); + m_state = BogusDOCTYPEState; + } + // FIXME: Handle EOF properly. + break; + } + case BeforeDOCTYPEPublicIdentifierState: { + if (cc == '\x09' || cc == '\x0A' || cc == '\x0C' || cc == ' ') + break; + else if (cc == '"') { + notImplemented(); + m_state = DOCTYPEPublicIdentifierDoubleQuotedState; + } else if (cc == '\'') { + notImplemented(); + m_state = DOCTYPEPublicIdentifierSingleQuotedState; + } else if (cc == '>') { + emitParseError(); + notImplemented(); + emitCurrentDoctypeToken(); + m_state = DataState; + } else { + emitParseError(); + notImplemented(); + m_state = BogusDOCTYPEState; + } + // FIXME: Handle EOF properly. + break; + } + case DOCTYPEPublicIdentifierDoubleQuotedState: { + if (cc == '"') + m_state = AfterDOCTYPEPublicIdentifierState; + else if (cc == '>') { + emitParseError(); + notImplemented(); + emitCurrentDoctypeToken(); + m_state = DataState; + } else + notImplemented(); + // FIXME: Handle EOF properly. + break; + } + case DOCTYPEPublicIdentifierSingleQuotedState: { + if (cc == '\'') + m_state = AfterDOCTYPEPublicIdentifierState; + else if (cc == '>') { + emitParseError(); + notImplemented(); + emitCurrentDoctypeToken(); + m_state = DataState; + } else + notImplemented(); + // FIXME: Handle EOF properly. + break; + } + case AfterDOCTYPEPublicIdentifierState: { + if (cc == '\x09' || cc == '\x0A' || cc == '\x0C' || cc == ' ') + m_state = BetweenDOCTYPEPublicAndSystemIdentifiersState; + else if (cc == '>') { + emitCurrentDoctypeToken(); + m_state = DataState; + } else if (cc == '"') { + emitParseError(); + notImplemented(); + m_state = DOCTYPESystemIdentifierDoubleQuotedState; + } else if (cc == '\'') { + emitParseError(); + notImplemented(); + m_state = DOCTYPESystemIdentifierSingleQuotedState; + } else { + emitParseError(); + notImplemented(); + m_state = BogusDOCTYPEState; + } + // FIXME: Handle EOF properly. + break; + } + case BetweenDOCTYPEPublicAndSystemIdentifiersState: { + if (cc == '\x09' || cc == '\x0A' || cc == '\x0C' || cc == ' ') + m_state = BetweenDOCTYPEPublicAndSystemIdentifiersState; + else if (cc == '>') { + emitCurrentDoctypeToken(); + m_state = DataState; + } else if (cc == '"') { + notImplemented(); + m_state = DOCTYPESystemIdentifierDoubleQuotedState; + } else if (cc == '\'') { + notImplemented(); + m_state = DOCTYPESystemIdentifierSingleQuotedState; + } else { + emitParseError(); + notImplemented(); + m_state = BogusDOCTYPEState; + } + // FIXME: Handle EOF properly. + break; + } + case AfterDOCTYPESystemKeywordState: { + if (cc == '\x09' || cc == '\x0A' || cc == '\x0C' || cc == ' ') + m_state = BeforeDOCTYPESystemIdentifierState; + else if (cc == '"') { + emitParseError(); + notImplemented(); + m_state = DOCTYPESystemIdentifierDoubleQuotedState; + } else if (cc == '\'') { + emitParseError(); + notImplemented(); + m_state = DOCTYPESystemIdentifierSingleQuotedState; + } else if (cc == '>') { + emitParseError(); + notImplemented(); + emitCurrentDoctypeToken(); + m_state = DataState; + } else { + emitParseError(); + notImplemented(); + m_state = BogusDOCTYPEState; + } + // FIXME: Handle EOF properly. + break; + } + case BeforeDOCTYPESystemIdentifierState: { + if (cc == '\x09' || cc == '\x0A' || cc == '\x0C' || cc == ' ') + break; + else if (cc == '"') { + notImplemented(); + m_state = DOCTYPESystemIdentifierDoubleQuotedState; + } else if (cc == '\'') { + notImplemented(); + m_state = DOCTYPESystemIdentifierSingleQuotedState; + } else if (cc == '>') { + emitParseError(); + notImplemented(); + emitCurrentDoctypeToken(); + m_state = DataState; + } else { + emitParseError(); + notImplemented(); + m_state = BogusDOCTYPEState; + } + // FIXME: Handle EOF properly. + break; + } + case DOCTYPESystemIdentifierDoubleQuotedState: { + if (cc == '"') + m_state = AfterDOCTYPESystemIdentifierState; + else if (cc == '>') { + emitParseError(); + notImplemented(); + emitCurrentDoctypeToken(); + m_state = DataState; + } else + notImplemented(); + // FIXME: Handle EOF properly. + break; + } + case DOCTYPESystemIdentifierSingleQuotedState: { + if (cc == '\'') + m_state = AfterDOCTYPESystemIdentifierState; + else if (cc == '>') { + emitParseError(); + notImplemented(); + emitCurrentDoctypeToken(); + m_state = DataState; + } else + notImplemented(); + // FIXME: Handle EOF properly. + break; + } + case AfterDOCTYPESystemIdentifierState: { + if (cc == '\x09' || cc == '\x0A' || cc == '\x0C' || cc == ' ') + break; + else if (cc == '>') { + emitCurrentDoctypeToken(); + m_state = DataState; + } else { + emitParseError(); + m_state = BogusDOCTYPEState; + } + // FIXME: Handle EOF properly. + break; + } + case BogusDOCTYPEState: { + if (cc == '>') + emitCurrentDoctypeToken(); + // FIXME: Handle EOF properly. + break; + } + case CDATASectionState: { + notImplemented(); + break; + } + case TokenizingCharacterReferencesState: { + notImplemented(); + break; + } + } + source.advance(); + if (m_emitPending) { + m_emitPending = false; + return true; + } + } + // We've reached the end of the input stream. If we have a character + // token buffered, we should emit it. + return m_token->type() == HTML5Token::Character; +} + +inline bool HTML5Lexer::temporaryBufferIs(const char*) +{ + notImplemented(); + return true; +} + +inline bool HTML5Lexer::isAppropriateEndTag() +{ + if (m_bufferedEndTagName.size() != m_appropriateEndTagName.length()) + return false; + const UChar* appropriate = m_appropriateEndTagName.characters(); + const UChar* actual = m_bufferedEndTagName.data(); + // FIXME: Is there a higher-level function we should be calling here? + return !memcmp(appropriate, actual, m_bufferedEndTagName.size() * sizeof(UChar)); +} + +inline void HTML5Lexer::emitCharacter(UChar character) +{ + if (m_token->type() != HTML5Token::Character) { + m_token->beginCharacter(character); + return; + } + m_token->appendToCharacter(character); +} + +inline void HTML5Lexer::emitParseError() +{ + notImplemented(); +} + +inline void HTML5Lexer::emitCurrentToken() +{ + m_emitPending = true; + if (m_token->type() == HTML5Token::StartTag) + m_appropriateEndTagName = m_token->name(); +} + +inline void HTML5Lexer::emitCurrentDoctypeToken() +{ +} + +} diff --git a/WebCore/html/HTML5Lexer.h b/WebCore/html/HTML5Lexer.h new file mode 100644 index 0000000..6d61cc2 --- /dev/null +++ b/WebCore/html/HTML5Lexer.h @@ -0,0 +1,162 @@ +/* + * Copyright (C) 2008 Apple Inc. All Rights Reserved. + * 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 HTML5Lexer_h +#define HTML5Lexer_h + +#include "AtomicString.h" +#include "SegmentedString.h" +#include <wtf/Noncopyable.h> +#include <wtf/Vector.h> + +namespace WebCore { + + class HTML5Token; + + class HTML5Lexer : public Noncopyable { + public: + enum State { + DataState, + CharacterReferenceInDataState, + RCDATAState, + CharacterReferenceInRCDATAState, + RAWTEXTState, + ScriptDataState, + PLAINTEXTState, + TagOpenState, + EndTagOpenState, + TagNameState, + RCDATALessThanSignState, + RCDATAEndTagOpenState, + RCDATAEndTagNameState, + RAWTEXTLessThanSignState, + RAWTEXTEndTagOpenState, + RAWTEXTEndTagNameState, + ScriptDataLessThanSignState, + ScriptDataEndTagOpenState, + ScriptDataEndTagNameState, + ScriptDataEscapeStartState, + ScriptDataEscapeStartDashState, + ScriptDataEscapedState, + ScriptDataEscapedDashState, + ScriptDataEscapedDashDashState, + ScriptDataEscapedLessThanSignState, + ScriptDataEscapedEndTagOpenState, + ScriptDataEscapedEndTagNameState, + ScriptDataDoubleEscapeStartState, + ScriptDataDoubleEscapedState, + ScriptDataDoubleEscapedDashState, + ScriptDataDoubleEscapedDashDashState, + ScriptDataDoubleEscapedLessThanSignState, + ScriptDataDoubleEscapeEndState, + BeforeAttributeNameState, + AttributeNameState, + AfterAttributeNameState, + BeforeAttributeValueState, + AttributeValueDoubleQuotedState, + AttributeValueSingleQuotedState, + AttributeValueUnquotedState, + CharacterReferenceInAttributeValueState, + AfterAttributeValueQuotedState, + SelfClosingStartTagState, + BogusCommentState, + MarkupDeclarationOpenState, + CommentStartState, + CommentStartDashState, + CommentState, + CommentEndDashState, + CommentEndState, + CommentEndBangState, + CommentEndSpaceState, + DOCTYPEState, + BeforeDOCTYPENameState, + DOCTYPENameState, + AfterDOCTYPENameState, + AfterDOCTYPEPublicKeywordState, + BeforeDOCTYPEPublicIdentifierState, + DOCTYPEPublicIdentifierDoubleQuotedState, + DOCTYPEPublicIdentifierSingleQuotedState, + AfterDOCTYPEPublicIdentifierState, + BetweenDOCTYPEPublicAndSystemIdentifiersState, + AfterDOCTYPESystemKeywordState, + BeforeDOCTYPESystemIdentifierState, + DOCTYPESystemIdentifierDoubleQuotedState, + DOCTYPESystemIdentifierSingleQuotedState, + AfterDOCTYPESystemIdentifierState, + BogusDOCTYPEState, + CDATASectionState, + TokenizingCharacterReferencesState, + }; + + HTML5Lexer(); + ~HTML5Lexer(); + + void reset(); + + // This function returns true if it emits a token. Otherwise, callers + // must provide the same (in progress) token on the next call (unless + // they call reset() first). + bool nextToken(SegmentedString&, HTML5Token&); + + void setState(State state) { m_state = state; } + + static unsigned consumeEntity(SegmentedString&, bool& notEnoughCharacters); + + private: + inline void emitCharacter(UChar); + inline void emitParseError(); + inline void emitCurrentToken(); + inline void emitCurrentDoctypeToken(); + + inline bool temporaryBufferIs(const char*); + + inline bool isAppropriateEndTag(); + + State m_state; + + AtomicString m_appropriateEndTagName; + + // m_token is owned by the caller. If nextToken is not on the stack, + // this member might be pointing to unallocated memory. + HTML5Token* m_token; + + bool m_emitPending; + + // http://www.whatwg.org/specs/web-apps/current-work/#temporary-buffer + Vector<UChar, 32> m_temporaryBuffer; + + // We occationally want to emit both a character token and an end tag + // token (e.g., when lexing script). We buffer the name of the end tag + // token here so we remember it next time we re-enter the lexer. + Vector<UChar, 32> m_bufferedEndTagName; + + // http://www.whatwg.org/specs/web-apps/current-work/#additional-allowed-character + UChar m_additionalAllowedCharacter; + }; + +} + +#endif diff --git a/WebCore/html/HTML5Token.h b/WebCore/html/HTML5Token.h new file mode 100644 index 0000000..1918589 --- /dev/null +++ b/WebCore/html/HTML5Token.h @@ -0,0 +1,206 @@ +/* + * 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 HTML5Token_h +#define HTML5Token_h + +#include "NamedNodeMap.h" +#include <wtf/Noncopyable.h> +#include <wtf/Vector.h> + +namespace WebCore { + +class HTML5Token : public Noncopyable { +public: + enum Type { + Uninitialized, + DOCTYPE, + StartTag, + EndTag, + Comment, + Character, + EndOfFile, + }; + + class Attribute { + public: + WTF::Vector<UChar, 32> m_name; + WTF::Vector<UChar, 32> m_value; + }; + + typedef WTF::Vector<Attribute> AttributeList; + + HTML5Token() { clear(); } + + void clear() + { + m_type = Uninitialized; + } + + void beginStartTag(UChar character) + { + ASSERT(m_type == Uninitialized); + m_type = StartTag; + m_data.clear(); + m_dataString = AtomicString(); + m_selfClosing = false; + m_currentAttribute = 0; + + m_data.append(character); + } + + template<typename T> + void beginEndTag(T characters) + { + ASSERT(m_type == Uninitialized); + m_type = EndTag; + m_data.clear(); + m_dataString = AtomicString(); + m_selfClosing = false; + m_currentAttribute = 0; + + m_data.append(characters); + } + + void beginCharacter(UChar character) + { + ASSERT(m_type == Uninitialized); + m_type = Character; + m_data.clear(); + m_dataString = AtomicString(); + m_data.append(character); + } + + void beginComment() + { + ASSERT(m_type == Uninitialized); + m_type = Comment; + m_data.clear(); + m_dataString = AtomicString(); + } + + void appendToName(UChar character) + { + ASSERT(m_type == StartTag || m_type == EndTag || m_type == DOCTYPE); + m_data.append(character); + } + + template<typename T> + void appendToCharacter(T characters) + { + ASSERT(m_type == Character); + m_data.append(characters); + } + + void appendToComment(UChar character) + { + ASSERT(m_type == Comment); + m_data.append(character); + } + + void addNewAttribute() + { + ASSERT(m_type == StartTag || m_type == EndTag); + m_attributes.grow(m_attributes.size() + 1); + m_currentAttribute = &m_attributes.last(); + } + + void appendToAttributeName(UChar character) + { + ASSERT(m_type == StartTag || m_type == EndTag); + m_currentAttribute->m_name.append(character); + } + + void appendToAttributeValue(UChar character) + { + ASSERT(m_type == StartTag || m_type == EndTag); + m_currentAttribute->m_value.append(character); + } + + Type type() const { return m_type; } + + bool selfClosing() const + { + ASSERT(m_type == StartTag || m_type == EndTag); + return m_selfClosing; + } + + AttributeList& attributes() + { + ASSERT(m_type == StartTag || m_type == EndTag); + return m_attributes; + } + + AtomicString name() + { + ASSERT(m_type == StartTag || m_type == EndTag || m_type == DOCTYPE); + return dataString(); + } + + AtomicString characters() + { + ASSERT(m_type == Character); + return dataString(); + } + + AtomicString data() + { + ASSERT(m_type == Comment); + return dataString(); + } + +private: + AtomicString dataString() + { + if (!m_data.isEmpty() && m_dataString.isEmpty()) + m_dataString = AtomicString(StringImpl::adopt(m_data)); + return m_dataString; + } + + Type m_type; + + // "name" for DOCTYPE, StartTag, and EndTag + // "characters" for Character + // "data" for Comment + WTF::Vector<UChar, 1024> m_data; + + // For DOCTYPE + String m_publicIdentifier; + String m_systemIdentifier; + bool m_forceQuirks; + + // For StartTag and EndTag + bool m_selfClosing; + AttributeList m_attributes; // Old tokenizer reserves 10. + + // A pointer into m_attributes used during lexing. + Attribute* m_currentAttribute; + + AtomicString m_dataString; +}; + +} + +#endif diff --git a/WebCore/html/HTML5Tokenizer.cpp b/WebCore/html/HTML5Tokenizer.cpp new file mode 100644 index 0000000..c531c7e --- /dev/null +++ b/WebCore/html/HTML5Tokenizer.cpp @@ -0,0 +1,82 @@ +/* + * 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. + */ + +#include "config.h" +#include "HTML5Tokenizer.h" + +#include "HTML5Lexer.h" +#include "HTML5Token.h" +#include "HTML5TreeBuilder.h" +#include "Node.h" +#include "NotImplemented.h" + +namespace WebCore { + +HTML5Tokenizer::HTML5Tokenizer(HTMLDocument* document, bool reportErrors) + : Tokenizer() + , m_lexer(new HTML5Lexer) + , m_treeBuilder(new HTML5TreeBuilder(m_lexer.get(), document, reportErrors)) +{ + begin(); +} + +HTML5Tokenizer::~HTML5Tokenizer() +{ +} + +void HTML5Tokenizer::begin() +{ +} + +void HTML5Tokenizer::write(const SegmentedString& source, bool) +{ + m_source.append(source); + + HTML5Token token; + while (!m_source.isEmpty()) { + if (m_lexer->nextToken(m_source, token)) { + m_treeBuilder->constructTreeFromToken(token); + token.clear(); + } + } +} + +void HTML5Tokenizer::end() +{ + m_treeBuilder->finished(); +} + +void HTML5Tokenizer::finish() +{ + end(); +} + +bool HTML5Tokenizer::isWaitingForScripts() const +{ + notImplemented(); + return false; +} + +} diff --git a/WebCore/html/HTML5Tokenizer.h b/WebCore/html/HTML5Tokenizer.h new file mode 100644 index 0000000..7d503aa --- /dev/null +++ b/WebCore/html/HTML5Tokenizer.h @@ -0,0 +1,67 @@ +/* + * 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 HTML5Tokenizer_h +#define HTML5Tokenizer_h + +#include "CachedResourceClient.h" +#include "SegmentedString.h" +#include "Tokenizer.h" +#include <wtf/OwnPtr.h> + +namespace WebCore { + +class HTMLDocument; +class HTML5TreeBuilder; +class HTML5Lexer; + +// FIXME: This is the wrong layer to hook in the new HTML 5 Lexer, +// however HTMLTokenizer is too large and too fragile of a class to hack into. +// Eventually we should split all of the HTML lexer logic out from HTMLTokenizer +// and then share non-lexer-specific tokenizer logic between HTML5 and the +// legacy WebKit HTML lexer. + +// FIXME: This class is far from complete. +class HTML5Tokenizer : public Tokenizer, public CachedResourceClient { +public: + HTML5Tokenizer(HTMLDocument*, bool reportErrors); + virtual ~HTML5Tokenizer(); + + virtual void begin(); + virtual void write(const SegmentedString&, bool appendData); + virtual void end(); + virtual void finish(); + virtual bool isWaitingForScripts() const; + +private: + SegmentedString m_source; + + OwnPtr<HTML5Lexer> m_lexer; + OwnPtr<HTML5TreeBuilder> m_treeBuilder; +}; + +} + +#endif diff --git a/WebCore/html/HTML5TreeBuilder.cpp b/WebCore/html/HTML5TreeBuilder.cpp new file mode 100644 index 0000000..af53ac6 --- /dev/null +++ b/WebCore/html/HTML5TreeBuilder.cpp @@ -0,0 +1,117 @@ +/* + * 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 GOOGLE 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 GOOGLE 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. + */ + +#include "config.h" +#include "HTML5TreeBuilder.h" + +#include "Attribute.h" +#include "HTML5Lexer.h" +#include "HTML5Token.h" +#include "HTMLDocument.h" +#include "HTMLParser.h" +#include "HTMLTokenizer.h" +#include "NotImplemented.h" + +namespace WebCore { + +HTML5TreeBuilder::HTML5TreeBuilder(HTML5Lexer* lexer, HTMLDocument* document, bool reportErrors) + : m_document(document) + , m_reportErrors(reportErrors) + , m_lexer(lexer) + , m_legacyHTMLParser(new HTMLParser(document, reportErrors)) +{ +} + +HTML5TreeBuilder::~HTML5TreeBuilder() +{ +} + +static void convertToOldStyle(HTML5Token& token, Token& oldStyleToken) +{ + switch (token.type()) { + case HTML5Token::Uninitialized: + ASSERT_NOT_REACHED(); + break; + case HTML5Token::DOCTYPE: + case HTML5Token::EndOfFile: + ASSERT_NOT_REACHED(); + notImplemented(); + break; + case HTML5Token::StartTag: + case HTML5Token::EndTag: { + oldStyleToken.beginTag = (token.type() == HTML5Token::StartTag); + oldStyleToken.selfClosingTag = token.selfClosing(); + oldStyleToken.tagName = token.name(); + HTML5Token::AttributeList& attributes = token.attributes(); + for (HTML5Token::AttributeList::iterator iter = attributes.begin(); + iter != attributes.end(); ++iter) { + if (!iter->m_name.isEmpty()) { + String name = String(StringImpl::adopt(iter->m_name)); + String value = String(StringImpl::adopt(iter->m_value)); + RefPtr<Attribute> mappedAttribute = Attribute::createMapped(name, value); + if (!oldStyleToken.attrs) + oldStyleToken.attrs = NamedNodeMap::create(); + oldStyleToken.attrs->insertAttribute(mappedAttribute.release(), false); + } + } + break; + } + case HTML5Token::Comment: + oldStyleToken.tagName = commentAtom; + oldStyleToken.text = token.data().impl(); + break; + case HTML5Token::Character: + oldStyleToken.tagName = textAtom; + oldStyleToken.text = token.characters().impl(); + break; + } +} + +PassRefPtr<Node> HTML5TreeBuilder::passTokenToLegacyParser(HTML5Token& token) +{ + if (token.type() == HTML5Token::StartTag && token.name() == "script") { + // This work is supposed to be done by the parser, but + // when using the old parser for we have to do this manually. + m_lexer->setState(HTML5Lexer::ScriptDataState); + } + // For now, we translate into an old-style token for testing. + Token oldStyleToken; + convertToOldStyle(token, oldStyleToken); + + return m_legacyHTMLParser->parseToken(&oldStyleToken); +} + +PassRefPtr<Node> HTML5TreeBuilder::constructTreeFromToken(HTML5Token& token) +{ + return passTokenToLegacyParser(token); + // Our HTML5 parser implementation will go here in a separate patch. +} + +void HTML5TreeBuilder::finished() +{ + m_legacyHTMLParser->finished(); +} + +} diff --git a/WebCore/html/HTML5TreeBuilder.h b/WebCore/html/HTML5TreeBuilder.h new file mode 100644 index 0000000..466fd6e --- /dev/null +++ b/WebCore/html/HTML5TreeBuilder.h @@ -0,0 +1,66 @@ +/* + * 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 GOOGLE 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 GOOGLE 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 HTML5TreeBuilder_h +#define HTML5TreeBuilder_h + +#include <wtf/Noncopyable.h> +#include <wtf/OwnPtr.h> +#include <wtf/PassRefPtr.h> + +namespace WebCore { +class Document; +class HTML5Lexer; +class HTML5Token; +class HTMLDocument; +class HTMLParser; +class Node; + +class HTML5TreeBuilder : public Noncopyable { +public: + HTML5TreeBuilder(HTML5Lexer*, HTMLDocument*, bool reportErrors); + ~HTML5TreeBuilder(); + + // The token really should be passed as a const& since it's never modified. + PassRefPtr<Node> constructTreeFromToken(HTML5Token&); + void finished(); + +private: + PassRefPtr<Node> passTokenToLegacyParser(HTML5Token&); + + // We could grab m_document off the lexer if we wanted to save space. + Document* m_document; + bool m_reportErrors; + // HTML5 spec requires that we be able to change the state of the lexer + // from within parser actions. + HTML5Lexer* m_lexer; + + // We're re-using logic from the old HTMLParser while this class is being written. + OwnPtr<HTMLParser> m_legacyHTMLParser; +}; + +} + +#endif diff --git a/WebCore/html/HTMLAnchorElement.cpp b/WebCore/html/HTMLAnchorElement.cpp index e3752c3..d5faf8f 100644 --- a/WebCore/html/HTMLAnchorElement.cpp +++ b/WebCore/html/HTMLAnchorElement.cpp @@ -24,13 +24,13 @@ #include "config.h" #include "HTMLAnchorElement.h" +#include "Attribute.h" #include "EventNames.h" #include "Frame.h" #include "FrameLoaderTypes.h" #include "HTMLImageElement.h" #include "HTMLNames.h" #include "KeyboardEvent.h" -#include "MappedAttribute.h" #include "MouseEvent.h" #include "Page.h" #include "RenderImage.h" @@ -78,7 +78,7 @@ bool HTMLAnchorElement::supportsFocus() const bool HTMLAnchorElement::isMouseFocusable() const { // Anchor elements should be mouse focusable, https://bugs.webkit.org/show_bug.cgi?id=26856 -#if !PLATFORM(GTK) && !PLATFORM(QT) +#if !PLATFORM(GTK) && !PLATFORM(QT) && !PLATFORM(EFL) if (isLink()) // Only allow links with tabIndex or contentEditable to be mouse focusable. return HTMLElement::supportsFocus(); @@ -251,7 +251,7 @@ void HTMLAnchorElement::setActive(bool down, bool pause) ContainerNode::setActive(down, pause); } -void HTMLAnchorElement::parseMappedAttribute(MappedAttribute *attr) +void HTMLAnchorElement::parseMappedAttribute(Attribute* attr) { if (attr->name() == hrefAttr) { bool wasLink = isLink(); diff --git a/WebCore/html/HTMLAnchorElement.h b/WebCore/html/HTMLAnchorElement.h index 03d3529..4f7b4fd 100644 --- a/WebCore/html/HTMLAnchorElement.h +++ b/WebCore/html/HTMLAnchorElement.h @@ -94,7 +94,7 @@ public: protected: HTMLAnchorElement(const QualifiedName&, Document*); - virtual void parseMappedAttribute(MappedAttribute*); + virtual void parseMappedAttribute(Attribute*); private: virtual HTMLTagStatus endTagRequirement() const { return TagStatusRequired; } diff --git a/WebCore/html/HTMLAppletElement.cpp b/WebCore/html/HTMLAppletElement.cpp index fb23b5c..79fcfba 100644 --- a/WebCore/html/HTMLAppletElement.cpp +++ b/WebCore/html/HTMLAppletElement.cpp @@ -24,9 +24,9 @@ #include "config.h" #include "HTMLAppletElement.h" +#include "Attribute.h" #include "HTMLDocument.h" #include "HTMLNames.h" -#include "MappedAttribute.h" #include "RenderApplet.h" #include "SecurityOrigin.h" #include "Settings.h" @@ -46,7 +46,7 @@ PassRefPtr<HTMLAppletElement> HTMLAppletElement::create(const QualifiedName& tag return adoptRef(new HTMLAppletElement(tagName, document)); } -void HTMLAppletElement::parseMappedAttribute(MappedAttribute* attr) +void HTMLAppletElement::parseMappedAttribute(Attribute* attr) { if (attr->name() == altAttr || attr->name() == archiveAttr || diff --git a/WebCore/html/HTMLAppletElement.h b/WebCore/html/HTMLAppletElement.h index a53bd5c..1e11b44 100644 --- a/WebCore/html/HTMLAppletElement.h +++ b/WebCore/html/HTMLAppletElement.h @@ -42,7 +42,7 @@ private: virtual int tagPriority() const { return 1; } - virtual void parseMappedAttribute(MappedAttribute*); + virtual void parseMappedAttribute(Attribute*); virtual bool rendererIsNeeded(RenderStyle*); virtual RenderObject* createRenderer(RenderArena*, RenderStyle*); diff --git a/WebCore/html/HTMLAreaElement.cpp b/WebCore/html/HTMLAreaElement.cpp index b862f69..c907f83 100644 --- a/WebCore/html/HTMLAreaElement.cpp +++ b/WebCore/html/HTMLAreaElement.cpp @@ -22,11 +22,11 @@ #include "config.h" #include "HTMLAreaElement.h" +#include "Attribute.h" #include "HTMLImageElement.h" #include "HTMLMapElement.h" #include "HTMLNames.h" #include "HitTestResult.h" -#include "MappedAttribute.h" #include "Path.h" #include "RenderObject.h" @@ -50,7 +50,7 @@ PassRefPtr<HTMLAreaElement> HTMLAreaElement::create(const QualifiedName& tagName return adoptRef(new HTMLAreaElement(tagName, document)); } -void HTMLAreaElement::parseMappedAttribute(MappedAttribute* attr) +void HTMLAreaElement::parseMappedAttribute(Attribute* attr) { if (attr->name() == shapeAttr) { if (equalIgnoringCase(attr->value(), "default")) diff --git a/WebCore/html/HTMLAreaElement.h b/WebCore/html/HTMLAreaElement.h index f8e2564..e6e087f 100644 --- a/WebCore/html/HTMLAreaElement.h +++ b/WebCore/html/HTMLAreaElement.h @@ -57,7 +57,7 @@ private: virtual HTMLTagStatus endTagRequirement() const { return TagStatusForbidden; } virtual int tagPriority() const { return 0; } - virtual void parseMappedAttribute(MappedAttribute*); + virtual void parseMappedAttribute(Attribute*); virtual bool supportsFocus() const; virtual String target() const; virtual bool isKeyboardFocusable(KeyboardEvent*) const; diff --git a/WebCore/html/HTMLBRElement.cpp b/WebCore/html/HTMLBRElement.cpp index dbd8eba..57dc011 100644 --- a/WebCore/html/HTMLBRElement.cpp +++ b/WebCore/html/HTMLBRElement.cpp @@ -23,9 +23,9 @@ #include "config.h" #include "HTMLBRElement.h" +#include "Attribute.h" #include "CSSPropertyNames.h" #include "HTMLNames.h" -#include "MappedAttribute.h" #include "RenderBR.h" namespace WebCore { @@ -48,7 +48,7 @@ bool HTMLBRElement::mapToEntry(const QualifiedName& attrName, MappedAttributeEnt return HTMLElement::mapToEntry(attrName, result); } -void HTMLBRElement::parseMappedAttribute(MappedAttribute* attr) +void HTMLBRElement::parseMappedAttribute(Attribute* attr) { if (attr->name() == clearAttr) { // If the string is empty, then don't add the clear property. diff --git a/WebCore/html/HTMLBRElement.h b/WebCore/html/HTMLBRElement.h index 6b20b37..5ae33c8 100644 --- a/WebCore/html/HTMLBRElement.h +++ b/WebCore/html/HTMLBRElement.h @@ -39,7 +39,7 @@ private: virtual int tagPriority() const { return 0; } virtual bool mapToEntry(const QualifiedName&, MappedAttributeEntry&) const; - virtual void parseMappedAttribute(MappedAttribute*); + virtual void parseMappedAttribute(Attribute*); virtual RenderObject* createRenderer(RenderArena*, RenderStyle*); }; diff --git a/WebCore/html/HTMLBaseElement.cpp b/WebCore/html/HTMLBaseElement.cpp index 613a0f7..862f072 100644 --- a/WebCore/html/HTMLBaseElement.cpp +++ b/WebCore/html/HTMLBaseElement.cpp @@ -23,11 +23,11 @@ #include "config.h" #include "HTMLBaseElement.h" +#include "Attribute.h" #include "CSSHelper.h" #include "Document.h" #include "Frame.h" #include "HTMLNames.h" -#include "MappedAttribute.h" #include "XSSAuditor.h" namespace WebCore { @@ -40,7 +40,7 @@ HTMLBaseElement::HTMLBaseElement(const QualifiedName& qName, Document* document) ASSERT(hasTagName(baseTag)); } -void HTMLBaseElement::parseMappedAttribute(MappedAttribute* attr) +void HTMLBaseElement::parseMappedAttribute(Attribute* attr) { if (attr->name() == hrefAttr) { m_hrefAttrValue = attr->value(); diff --git a/WebCore/html/HTMLBaseElement.h b/WebCore/html/HTMLBaseElement.h index d413bec..993a56f 100644 --- a/WebCore/html/HTMLBaseElement.h +++ b/WebCore/html/HTMLBaseElement.h @@ -37,7 +37,7 @@ private: virtual String target() const { return m_target; } - virtual void parseMappedAttribute(MappedAttribute*); + virtual void parseMappedAttribute(Attribute*); virtual void insertedIntoDocument(); virtual void removedFromDocument(); diff --git a/WebCore/html/HTMLBodyElement.cpp b/WebCore/html/HTMLBodyElement.cpp index e5a16cb..9e39cb3 100644 --- a/WebCore/html/HTMLBodyElement.cpp +++ b/WebCore/html/HTMLBodyElement.cpp @@ -24,6 +24,7 @@ #include "config.h" #include "HTMLBodyElement.h" +#include "Attribute.h" #include "CSSStyleSelector.h" #include "CSSStyleSheet.h" #include "CSSValueKeywords.h" @@ -32,7 +33,6 @@ #include "FrameView.h" #include "HTMLFrameElementBase.h" #include "HTMLNames.h" -#include "MappedAttribute.h" #include "ScriptEventListener.h" #ifdef ANDROID_META_SUPPORT @@ -87,7 +87,7 @@ bool HTMLBodyElement::mapToEntry(const QualifiedName& attrName, MappedAttributeE return HTMLElement::mapToEntry(attrName, result); } -void HTMLBodyElement::parseMappedAttribute(MappedAttribute *attr) +void HTMLBodyElement::parseMappedAttribute(Attribute* attr) { if (attr->name() == backgroundAttr) { String url = deprecatedParseURL(attr->value()); diff --git a/WebCore/html/HTMLBodyElement.h b/WebCore/html/HTMLBodyElement.h index 76b49a1..f2c1f98 100644 --- a/WebCore/html/HTMLBodyElement.h +++ b/WebCore/html/HTMLBodyElement.h @@ -70,7 +70,7 @@ private: virtual int tagPriority() const { return 10; } virtual bool mapToEntry(const QualifiedName&, MappedAttributeEntry&) const; - virtual void parseMappedAttribute(MappedAttribute*); + virtual void parseMappedAttribute(Attribute*); virtual void insertedIntoDocument(); diff --git a/WebCore/html/HTMLButtonElement.cpp b/WebCore/html/HTMLButtonElement.cpp index b3d358d..2ef932b 100644 --- a/WebCore/html/HTMLButtonElement.cpp +++ b/WebCore/html/HTMLButtonElement.cpp @@ -26,14 +26,14 @@ #include "config.h" #include "HTMLButtonElement.h" +#include "Attribute.h" #include "EventNames.h" #include "FormDataList.h" #include "HTMLFormElement.h" #include "HTMLNames.h" -#include "ScriptEventListener.h" #include "KeyboardEvent.h" -#include "MappedAttribute.h" #include "RenderButton.h" +#include "ScriptEventListener.h" #include <wtf/StdLibExtras.h> namespace WebCore { @@ -78,7 +78,7 @@ const AtomicString& HTMLButtonElement::formControlType() const return emptyAtom; } -void HTMLButtonElement::parseMappedAttribute(MappedAttribute* attr) +void HTMLButtonElement::parseMappedAttribute(Attribute* attr) { if (attr->name() == typeAttr) { if (equalIgnoringCase(attr->value(), "reset")) diff --git a/WebCore/html/HTMLButtonElement.h b/WebCore/html/HTMLButtonElement.h index f4df571..92951c3 100644 --- a/WebCore/html/HTMLButtonElement.h +++ b/WebCore/html/HTMLButtonElement.h @@ -37,7 +37,7 @@ public: virtual RenderObject* createRenderer(RenderArena*, RenderStyle*); - virtual void parseMappedAttribute(MappedAttribute*); + virtual void parseMappedAttribute(Attribute*); virtual void defaultEventHandler(Event*); virtual bool appendFormData(FormDataList&, bool); diff --git a/WebCore/html/HTMLCanvasElement.cpp b/WebCore/html/HTMLCanvasElement.cpp index ef85323..205cf28 100644 --- a/WebCore/html/HTMLCanvasElement.cpp +++ b/WebCore/html/HTMLCanvasElement.cpp @@ -27,14 +27,11 @@ #include "config.h" #include "HTMLCanvasElement.h" +#include "Attribute.h" #include "CanvasContextAttributes.h" -#include "CanvasRenderingContext2D.h" -#if ENABLE(3D_CANVAS) -#include "WebGLContextAttributes.h" -#include "WebGLRenderingContext.h" -#endif #include "CanvasGradient.h" #include "CanvasPattern.h" +#include "CanvasRenderingContext2D.h" #include "CanvasStyle.h" #include "Chrome.h" #include "Document.h" @@ -42,13 +39,17 @@ #include "GraphicsContext.h" #include "HTMLNames.h" #include "ImageBuffer.h" -#include "MappedAttribute.h" #include "Page.h" #include "RenderHTMLCanvas.h" #include "Settings.h" #include <math.h> #include <stdio.h> +#if ENABLE(3D_CANVAS) +#include "WebGLContextAttributes.h" +#include "WebGLRenderingContext.h" +#endif + namespace WebCore { using namespace HTMLNames; @@ -90,7 +91,7 @@ int HTMLCanvasElement::tagPriority() const #endif -void HTMLCanvasElement::parseMappedAttribute(MappedAttribute* attr) +void HTMLCanvasElement::parseMappedAttribute(Attribute* attr) { const QualifiedName& attrName = attr->name(); if (attrName == widthAttr || attrName == heightAttr) diff --git a/WebCore/html/HTMLCanvasElement.h b/WebCore/html/HTMLCanvasElement.h index 4ee4b3e..a7f42ce 100644 --- a/WebCore/html/HTMLCanvasElement.h +++ b/WebCore/html/HTMLCanvasElement.h @@ -110,7 +110,7 @@ private: virtual int tagPriority() const; #endif - virtual void parseMappedAttribute(MappedAttribute*); + virtual void parseMappedAttribute(Attribute*); virtual RenderObject* createRenderer(RenderArena*, RenderStyle*); void reset(); diff --git a/WebCore/html/HTMLDataGridColElement.cpp b/WebCore/html/HTMLDataGridColElement.cpp index 935375e..7f02aa5 100644 --- a/WebCore/html/HTMLDataGridColElement.cpp +++ b/WebCore/html/HTMLDataGridColElement.cpp @@ -27,11 +27,11 @@ #if ENABLE(DATAGRID) +#include "Attribute.h" #include "DataGridColumn.h" -#include "HTMLDataGridElement.h" #include "HTMLDataGridColElement.h" +#include "HTMLDataGridElement.h" #include "HTMLNames.h" -#include "MappedAttribute.h" #include "Text.h" namespace WebCore { @@ -145,7 +145,7 @@ void HTMLDataGridColElement::setPrimary(bool primary) setAttribute(primaryAttr, primary ? "" : 0); } -void HTMLDataGridColElement::parseMappedAttribute(MappedAttribute* attr) +void HTMLDataGridColElement::parseMappedAttribute(Attribute* attr) { HTMLElement::parseMappedAttribute(attr); diff --git a/WebCore/html/HTMLDataGridColElement.h b/WebCore/html/HTMLDataGridColElement.h index d91ec51..2ee284b 100644 --- a/WebCore/html/HTMLDataGridColElement.h +++ b/WebCore/html/HTMLDataGridColElement.h @@ -43,7 +43,7 @@ public: virtual int tagPriority() const { return 0; } virtual void insertedIntoTree(bool /*deep*/); virtual void removedFromTree(bool /*deep*/); - virtual void parseMappedAttribute(MappedAttribute*); + virtual void parseMappedAttribute(Attribute*); String label() const; void setLabel(const String&); diff --git a/WebCore/html/HTMLDivElement.cpp b/WebCore/html/HTMLDivElement.cpp index bd7195e..4482946 100644 --- a/WebCore/html/HTMLDivElement.cpp +++ b/WebCore/html/HTMLDivElement.cpp @@ -23,10 +23,10 @@ #include "config.h" #include "HTMLDivElement.h" +#include "Attribute.h" #include "CSSPropertyNames.h" #include "CSSValueKeywords.h" #include "HTMLNames.h" -#include "MappedAttribute.h" namespace WebCore { @@ -51,7 +51,7 @@ bool HTMLDivElement::mapToEntry(const QualifiedName& attrName, MappedAttributeEn return HTMLElement::mapToEntry(attrName, result); } -void HTMLDivElement::parseMappedAttribute(MappedAttribute *attr) +void HTMLDivElement::parseMappedAttribute(Attribute* attr) { if (attr->name() == alignAttr) { String v = attr->value(); diff --git a/WebCore/html/HTMLDivElement.h b/WebCore/html/HTMLDivElement.h index 49cbc38..8359b96 100644 --- a/WebCore/html/HTMLDivElement.h +++ b/WebCore/html/HTMLDivElement.h @@ -35,7 +35,7 @@ public: virtual int tagPriority() const { return 5; } virtual bool mapToEntry(const QualifiedName&, MappedAttributeEntry&) const; - virtual void parseMappedAttribute(MappedAttribute*); + virtual void parseMappedAttribute(Attribute*); String align() const; void setAlign(const String&); diff --git a/WebCore/html/HTMLDocument.cpp b/WebCore/html/HTMLDocument.cpp index c0e9eb7..5e08a99 100644 --- a/WebCore/html/HTMLDocument.cpp +++ b/WebCore/html/HTMLDocument.cpp @@ -64,6 +64,7 @@ #include "FrameLoader.h" #include "FrameTree.h" #include "FrameView.h" +#include "HTML5Tokenizer.h" #include "HTMLBodyElement.h" #include "HTMLElementFactory.h" #include "HTMLNames.h" @@ -71,6 +72,7 @@ #include "InspectorController.h" #include "KURL.h" #include "Page.h" +#include "Settings.h" #include <wtf/text/CString.h> #include "DocTypeStrings.cpp" @@ -281,7 +283,7 @@ void HTMLDocument::releaseEvents() { } -Tokenizer *HTMLDocument::createTokenizer() +Tokenizer* HTMLDocument::createTokenizer() { bool reportErrors = false; #if ENABLE(INSPECTOR) @@ -289,6 +291,9 @@ Tokenizer *HTMLDocument::createTokenizer() reportErrors = page->inspectorController()->windowVisible(); #endif + if (settings() && settings()->html5ParserEnabled()) + return new HTML5Tokenizer(this, reportErrors); + return new HTMLTokenizer(this, reportErrors); } diff --git a/WebCore/html/HTMLElement.cpp b/WebCore/html/HTMLElement.cpp index 77aa93b..a623f24 100644 --- a/WebCore/html/HTMLElement.cpp +++ b/WebCore/html/HTMLElement.cpp @@ -24,6 +24,7 @@ #include "config.h" #include "HTMLElement.h" +#include "Attribute.h" #include "CSSPropertyNames.h" #include "CSSValueKeywords.h" #include "DocumentFragment.h" @@ -39,7 +40,6 @@ #include "HTMLFormElement.h" #include "HTMLNames.h" #include "HTMLTokenizer.h" -#include "MappedAttribute.h" #include "RenderWordBreak.h" #include "ScriptEventListener.h" #include "Settings.h" @@ -142,7 +142,7 @@ bool HTMLElement::mapToEntry(const QualifiedName& attrName, MappedAttributeEntry return StyledElement::mapToEntry(attrName, result); } -void HTMLElement::parseMappedAttribute(MappedAttribute *attr) +void HTMLElement::parseMappedAttribute(Attribute* attr) { if (attr->name() == idAttributeName() || attr->name() == classAttr || attr->name() == styleAttr) return StyledElement::parseMappedAttribute(attr); @@ -569,12 +569,12 @@ void HTMLElement::insertAdjacentText(const String& where, const String& text, Ex insertAdjacent(where, textNode.get(), ec); } -void HTMLElement::addHTMLAlignment(MappedAttribute* attr) +void HTMLElement::addHTMLAlignment(Attribute* attr) { addHTMLAlignmentToStyledElement(this, attr); } -void HTMLElement::addHTMLAlignmentToStyledElement(StyledElement* element, MappedAttribute* attr) +void HTMLElement::addHTMLAlignmentToStyledElement(StyledElement* element, Attribute* attr) { // Vertical alignment with respect to the current baseline of the text // right or left means floating images. @@ -670,7 +670,7 @@ String HTMLElement::contentEditable() const } } -void HTMLElement::setContentEditable(MappedAttribute* attr) +void HTMLElement::setContentEditable(Attribute* attr) { const AtomicString& enabled = attr->value(); if (enabled.isEmpty() || equalIgnoringCase(enabled, "true")) { @@ -858,9 +858,7 @@ static HashSet<AtomicStringImpl*>* inlineTagList() tagList.add(rpTag.localName().impl()); tagList.add(rtTag.localName().impl()); tagList.add(rubyTag.localName().impl()); -#if ENABLE(PROGRESS_TAG) tagList.add(progressTag.localName().impl()); -#endif tagList.add(meterTag.localName().impl()); } return &tagList; diff --git a/WebCore/html/HTMLElement.h b/WebCore/html/HTMLElement.h index b51dba4..db9cb98 100644 --- a/WebCore/html/HTMLElement.h +++ b/WebCore/html/HTMLElement.h @@ -79,15 +79,15 @@ public: HTMLFormElement* form() const { return virtualForm(); } - static void addHTMLAlignmentToStyledElement(StyledElement*, MappedAttribute*); + static void addHTMLAlignmentToStyledElement(StyledElement*, Attribute*); protected: HTMLElement(const QualifiedName& tagName, Document*, ConstructionType = CreateHTMLElementZeroRefCount); - void addHTMLAlignment(MappedAttribute*); + void addHTMLAlignment(Attribute*); virtual bool mapToEntry(const QualifiedName& attrName, MappedAttributeEntry& result) const; - virtual void parseMappedAttribute(MappedAttribute*); + virtual void parseMappedAttribute(Attribute*); virtual bool childAllowed(Node* newChild); // Error-checking during parsing that checks the DTD @@ -104,7 +104,7 @@ protected: private: virtual String nodeName() const; - void setContentEditable(MappedAttribute*); + void setContentEditable(Attribute*); virtual HTMLFormElement* virtualForm() const; diff --git a/WebCore/html/HTMLEmbedElement.cpp b/WebCore/html/HTMLEmbedElement.cpp index eba980c..3f700ef 100644 --- a/WebCore/html/HTMLEmbedElement.cpp +++ b/WebCore/html/HTMLEmbedElement.cpp @@ -24,6 +24,7 @@ #include "config.h" #include "HTMLEmbedElement.h" +#include "Attribute.h" #include "CSSHelper.h" #include "CSSPropertyNames.h" #include "Frame.h" @@ -31,7 +32,6 @@ #include "HTMLImageLoader.h" #include "HTMLNames.h" #include "HTMLObjectElement.h" -#include "MappedAttribute.h" #include "RenderEmbeddedObject.h" #include "RenderImage.h" #include "RenderWidget.h" @@ -83,7 +83,7 @@ bool HTMLEmbedElement::mapToEntry(const QualifiedName& attrName, MappedAttribute return HTMLPlugInElement::mapToEntry(attrName, result); } -void HTMLEmbedElement::parseMappedAttribute(MappedAttribute* attr) +void HTMLEmbedElement::parseMappedAttribute(Attribute* attr) { const AtomicString& value = attr->value(); diff --git a/WebCore/html/HTMLEmbedElement.h b/WebCore/html/HTMLEmbedElement.h index 16f0893..53da011 100644 --- a/WebCore/html/HTMLEmbedElement.h +++ b/WebCore/html/HTMLEmbedElement.h @@ -40,7 +40,7 @@ private: virtual int tagPriority() const { return 0; } virtual bool mapToEntry(const QualifiedName& attrName, MappedAttributeEntry& result) const; - virtual void parseMappedAttribute(MappedAttribute*); + virtual void parseMappedAttribute(Attribute*); virtual void attach(); virtual bool canLazyAttach() { return false; } diff --git a/WebCore/html/HTMLFontElement.cpp b/WebCore/html/HTMLFontElement.cpp index d19032a..b6de0b8 100644 --- a/WebCore/html/HTMLFontElement.cpp +++ b/WebCore/html/HTMLFontElement.cpp @@ -23,10 +23,10 @@ #include "config.h" #include "HTMLFontElement.h" +#include "Attribute.h" #include "CSSPropertyNames.h" #include "CSSValueKeywords.h" #include "HTMLNames.h" -#include "MappedAttribute.h" using namespace WTF; @@ -130,7 +130,7 @@ bool HTMLFontElement::cssValueFromFontSizeNumber(const String& s, int& size) return true; } -void HTMLFontElement::parseMappedAttribute(MappedAttribute *attr) +void HTMLFontElement::parseMappedAttribute(Attribute* attr) { if (attr->name() == sizeAttr) { int size; diff --git a/WebCore/html/HTMLFontElement.h b/WebCore/html/HTMLFontElement.h index 029a23e..b3439b7 100644 --- a/WebCore/html/HTMLFontElement.h +++ b/WebCore/html/HTMLFontElement.h @@ -34,7 +34,7 @@ public: virtual int tagPriority() const { return 1; } virtual bool mapToEntry(const QualifiedName&, MappedAttributeEntry&) const; - virtual void parseMappedAttribute(MappedAttribute*); + virtual void parseMappedAttribute(Attribute*); String color() const; void setColor(const String&); diff --git a/WebCore/html/HTMLFormControlElement.cpp b/WebCore/html/HTMLFormControlElement.cpp index 5512236..5894999 100644 --- a/WebCore/html/HTMLFormControlElement.cpp +++ b/WebCore/html/HTMLFormControlElement.cpp @@ -25,6 +25,7 @@ #include "config.h" #include "HTMLFormControlElement.h" +#include "Attribute.h" #include "CharacterNames.h" #include "Chrome.h" #include "ChromeClient.h" @@ -38,7 +39,6 @@ #include "HTMLNames.h" #include "HTMLParser.h" #include "HTMLTokenizer.h" -#include "MappedAttribute.h" #include "Page.h" #include "RenderBox.h" #include "RenderTextControl.h" @@ -92,7 +92,7 @@ ValidityState* HTMLFormControlElement::validity() return m_validityState.get(); } -void HTMLFormControlElement::parseMappedAttribute(MappedAttribute *attr) +void HTMLFormControlElement::parseMappedAttribute(Attribute* attr) { if (attr->name() == disabledAttr) { bool oldDisabled = m_disabled; @@ -604,7 +604,7 @@ VisibleSelection HTMLTextFormControlElement::selection() const return toRenderTextControl(renderer())->selection(cachedSelectionStart(), cachedSelectionEnd()); } -void HTMLTextFormControlElement::parseMappedAttribute(MappedAttribute* attr) +void HTMLTextFormControlElement::parseMappedAttribute(Attribute* attr) { if (attr->name() == placeholderAttr) updatePlaceholderVisibility(true); diff --git a/WebCore/html/HTMLFormControlElement.h b/WebCore/html/HTMLFormControlElement.h index 5c13d24..befa67b 100644 --- a/WebCore/html/HTMLFormControlElement.h +++ b/WebCore/html/HTMLFormControlElement.h @@ -51,7 +51,7 @@ public: virtual bool isTextFormControl() const { return false; } virtual bool isEnabledFormControl() const { return !disabled(); } - virtual void parseMappedAttribute(MappedAttribute*); + virtual void parseMappedAttribute(Attribute*); virtual void attach(); virtual void insertedIntoTree(bool deep); virtual void removedFromTree(bool deep); @@ -189,7 +189,7 @@ protected: void updatePlaceholderVisibility(bool); virtual int cachedSelectionStart() const = 0; virtual int cachedSelectionEnd() const = 0; - virtual void parseMappedAttribute(MappedAttribute*); + virtual void parseMappedAttribute(Attribute*); private: // A subclass should return true if placeholder processing is needed. diff --git a/WebCore/html/HTMLFormElement.cpp b/WebCore/html/HTMLFormElement.cpp index 7c58364..c84454d 100644 --- a/WebCore/html/HTMLFormElement.cpp +++ b/WebCore/html/HTMLFormElement.cpp @@ -25,6 +25,7 @@ #include "config.h" #include "HTMLFormElement.h" +#include "Attribute.h" #include "CSSHelper.h" #include "DOMFormData.h" #include "DOMWindow.h" @@ -44,10 +45,9 @@ #include "HTMLImageElement.h" #include "HTMLInputElement.h" #include "HTMLNames.h" -#include "ScriptEventListener.h" #include "MIMETypeRegistry.h" -#include "MappedAttribute.h" #include "RenderTextControl.h" +#include "ScriptEventListener.h" #include "ValidityState.h" #include <limits> #include <wtf/CurrentTime.h> @@ -431,7 +431,7 @@ void HTMLFormElement::reset() m_inreset = false; } -void HTMLFormElement::parseMappedAttribute(MappedAttribute* attr) +void HTMLFormElement::parseMappedAttribute(Attribute* attr) { if (attr->name() == actionAttr) m_url = deprecatedParseURL(attr->value()); diff --git a/WebCore/html/HTMLFormElement.h b/WebCore/html/HTMLFormElement.h index 68aebdf..e3de222 100644 --- a/WebCore/html/HTMLFormElement.h +++ b/WebCore/html/HTMLFormElement.h @@ -71,7 +71,7 @@ public: bool autoComplete() const { return m_autocomplete; } - virtual void parseMappedAttribute(MappedAttribute*); + virtual void parseMappedAttribute(Attribute*); void registerFormElement(HTMLFormControlElement*); void removeFormElement(HTMLFormControlElement*); diff --git a/WebCore/html/HTMLFrameElement.cpp b/WebCore/html/HTMLFrameElement.cpp index b456ac3..3ccc87f 100644 --- a/WebCore/html/HTMLFrameElement.cpp +++ b/WebCore/html/HTMLFrameElement.cpp @@ -24,10 +24,10 @@ #include "config.h" #include "HTMLFrameElement.h" +#include "Attribute.h" #include "Frame.h" #include "HTMLFrameSetElement.h" #include "HTMLNames.h" -#include "MappedAttribute.h" #include "RenderFrame.h" namespace WebCore { @@ -80,7 +80,7 @@ void HTMLFrameElement::attach() } } -void HTMLFrameElement::parseMappedAttribute(MappedAttribute* attr) +void HTMLFrameElement::parseMappedAttribute(Attribute* attr) { if (attr->name() == frameborderAttr) { m_frameBorder = attr->value().toInt(); diff --git a/WebCore/html/HTMLFrameElement.h b/WebCore/html/HTMLFrameElement.h index 4a8e16c..20f298e 100644 --- a/WebCore/html/HTMLFrameElement.h +++ b/WebCore/html/HTMLFrameElement.h @@ -48,7 +48,7 @@ private: virtual bool rendererIsNeeded(RenderStyle*); virtual RenderObject* createRenderer(RenderArena*, RenderStyle*); - virtual void parseMappedAttribute(MappedAttribute*); + virtual void parseMappedAttribute(Attribute*); bool m_frameBorder; bool m_frameBorderSet; diff --git a/WebCore/html/HTMLFrameElementBase.cpp b/WebCore/html/HTMLFrameElementBase.cpp index c30b74f..756dd84 100644 --- a/WebCore/html/HTMLFrameElementBase.cpp +++ b/WebCore/html/HTMLFrameElementBase.cpp @@ -24,6 +24,7 @@ #include "config.h" #include "HTMLFrameElementBase.h" +#include "Attribute.h" #include "CSSHelper.h" #include "Document.h" #include "EventNames.h" @@ -34,11 +35,11 @@ #include "FrameView.h" #include "HTMLFrameSetElement.h" #include "HTMLNames.h" -#include "ScriptEventListener.h" #include "KURL.h" -#include "MappedAttribute.h" #include "Page.h" #include "RenderFrame.h" +#include "ScriptController.h" +#include "ScriptEventListener.h" #include "Settings.h" namespace WebCore { @@ -64,6 +65,12 @@ bool HTMLFrameElementBase::isURLAllowed() const const KURL& completeURL = document()->completeURL(m_URL); + if (protocolIsJavaScript(completeURL)) { + Document* contentDoc = this->contentDocument(); + if (contentDoc && !ScriptController::canAccessFromCurrentOrigin(contentDoc->frame())) + return false; + } + // Don't allow more than 200 total frames in a set. This seems // like a reasonable upper bound, and otherwise mutually recursive // frameset pages can quickly bring the program to its knees with @@ -109,7 +116,7 @@ void HTMLFrameElementBase::openURL(bool lockHistory, bool lockBackForwardList) contentFrame()->setInViewSourceMode(viewSourceMode()); } -void HTMLFrameElementBase::parseMappedAttribute(MappedAttribute *attr) +void HTMLFrameElementBase::parseMappedAttribute(Attribute* attr) { if (attr->name() == srcAttr) setLocation(deprecatedParseURL(attr->value())); diff --git a/WebCore/html/HTMLFrameElementBase.h b/WebCore/html/HTMLFrameElementBase.h index 6424ba7..1b6e2a3 100644 --- a/WebCore/html/HTMLFrameElementBase.h +++ b/WebCore/html/HTMLFrameElementBase.h @@ -49,7 +49,7 @@ protected: bool isURLAllowed() const; - virtual void parseMappedAttribute(MappedAttribute*); + virtual void parseMappedAttribute(Attribute*); virtual void insertedIntoDocument(); virtual void removedFromDocument(); diff --git a/WebCore/html/HTMLFrameSetElement.cpp b/WebCore/html/HTMLFrameSetElement.cpp index a669e59..b97c498 100644 --- a/WebCore/html/HTMLFrameSetElement.cpp +++ b/WebCore/html/HTMLFrameSetElement.cpp @@ -24,16 +24,16 @@ #include "config.h" #include "HTMLFrameSetElement.h" +#include "Attribute.h" #include "CSSPropertyNames.h" #include "Document.h" #include "Event.h" #include "EventNames.h" #include "HTMLNames.h" -#include "ScriptEventListener.h" #include "Length.h" -#include "MappedAttribute.h" #include "MouseEvent.h" #include "RenderFrameSet.h" +#include "ScriptEventListener.h" #include "Text.h" namespace WebCore { @@ -83,7 +83,7 @@ bool HTMLFrameSetElement::mapToEntry(const QualifiedName& attrName, MappedAttrib return HTMLElement::mapToEntry(attrName, result); } -void HTMLFrameSetElement::parseMappedAttribute(MappedAttribute *attr) +void HTMLFrameSetElement::parseMappedAttribute(Attribute* attr) { if (attr->name() == rowsAttr) { if (!attr->isNull()) { diff --git a/WebCore/html/HTMLFrameSetElement.h b/WebCore/html/HTMLFrameSetElement.h index 0c75efe..faf800d 100644 --- a/WebCore/html/HTMLFrameSetElement.h +++ b/WebCore/html/HTMLFrameSetElement.h @@ -40,7 +40,7 @@ public: virtual bool checkDTD(const Node* newChild); virtual bool mapToEntry(const QualifiedName& attrName, MappedAttributeEntry& result) const; - virtual void parseMappedAttribute(MappedAttribute*); + virtual void parseMappedAttribute(Attribute*); virtual void attach(); virtual bool rendererIsNeeded(RenderStyle*); diff --git a/WebCore/html/HTMLHRElement.cpp b/WebCore/html/HTMLHRElement.cpp index 6858f56..92fb3b2 100644 --- a/WebCore/html/HTMLHRElement.cpp +++ b/WebCore/html/HTMLHRElement.cpp @@ -23,10 +23,10 @@ #include "config.h" #include "HTMLHRElement.h" +#include "Attribute.h" #include "CSSPropertyNames.h" #include "CSSValueKeywords.h" #include "HTMLNames.h" -#include "MappedAttribute.h" namespace WebCore { @@ -55,7 +55,7 @@ bool HTMLHRElement::mapToEntry(const QualifiedName& attrName, MappedAttributeEnt return HTMLElement::mapToEntry(attrName, result); } -void HTMLHRElement::parseMappedAttribute(MappedAttribute *attr) +void HTMLHRElement::parseMappedAttribute(Attribute* attr) { if (attr->name() == alignAttr) { if (equalIgnoringCase(attr->value(), "left")) { diff --git a/WebCore/html/HTMLHRElement.h b/WebCore/html/HTMLHRElement.h index 7a9f498..8763082 100644 --- a/WebCore/html/HTMLHRElement.h +++ b/WebCore/html/HTMLHRElement.h @@ -35,7 +35,7 @@ public: virtual int tagPriority() const { return 0; } virtual bool mapToEntry(const QualifiedName&, MappedAttributeEntry&) const; - virtual void parseMappedAttribute(MappedAttribute*); + virtual void parseMappedAttribute(Attribute*); String align() const; void setAlign(const String&); diff --git a/WebCore/html/HTMLIFrameElement.cpp b/WebCore/html/HTMLIFrameElement.cpp index cce39df..b3fffe3 100644 --- a/WebCore/html/HTMLIFrameElement.cpp +++ b/WebCore/html/HTMLIFrameElement.cpp @@ -25,11 +25,11 @@ #include "config.h" #include "HTMLIFrameElement.h" +#include "Attribute.h" #include "CSSPropertyNames.h" #include "Frame.h" #include "HTMLDocument.h" #include "HTMLNames.h" -#include "MappedAttribute.h" #include "RenderIFrame.h" namespace WebCore { @@ -68,7 +68,7 @@ bool HTMLIFrameElement::mapToEntry(const QualifiedName& attrName, MappedAttribut } #if ENABLE(SANDBOX) -static SandboxFlags parseSandboxAttribute(MappedAttribute* attribute) +static SandboxFlags parseSandboxAttribute(Attribute* attribute) { if (attribute->isNull()) return SandboxNone; @@ -105,7 +105,7 @@ static SandboxFlags parseSandboxAttribute(MappedAttribute* attribute) } #endif -void HTMLIFrameElement::parseMappedAttribute(MappedAttribute* attr) +void HTMLIFrameElement::parseMappedAttribute(Attribute* attr) { if (attr->name() == widthAttr) addCSSLength(attr, CSSPropertyWidth, attr->value()); diff --git a/WebCore/html/HTMLIFrameElement.h b/WebCore/html/HTMLIFrameElement.h index c708456..1d01c66 100644 --- a/WebCore/html/HTMLIFrameElement.h +++ b/WebCore/html/HTMLIFrameElement.h @@ -39,7 +39,7 @@ private: virtual int tagPriority() const { return 1; } virtual bool mapToEntry(const QualifiedName&, MappedAttributeEntry&) const; - virtual void parseMappedAttribute(MappedAttribute*); + virtual void parseMappedAttribute(Attribute*); virtual void insertedIntoDocument(); virtual void removedFromDocument(); diff --git a/WebCore/html/HTMLImageElement.cpp b/WebCore/html/HTMLImageElement.cpp index db66533..5256e6d 100644 --- a/WebCore/html/HTMLImageElement.cpp +++ b/WebCore/html/HTMLImageElement.cpp @@ -23,6 +23,7 @@ #include "config.h" #include "HTMLImageElement.h" +#include "Attribute.h" #include "CSSHelper.h" #include "CSSPropertyNames.h" #include "CSSValueKeywords.h" @@ -31,7 +32,6 @@ #include "HTMLDocument.h" #include "HTMLFormElement.h" #include "HTMLNames.h" -#include "MappedAttribute.h" #include "RenderImage.h" #include "ScriptEventListener.h" @@ -88,7 +88,7 @@ bool HTMLImageElement::mapToEntry(const QualifiedName& attrName, MappedAttribute return HTMLElement::mapToEntry(attrName, result); } -void HTMLImageElement::parseMappedAttribute(MappedAttribute* attr) +void HTMLImageElement::parseMappedAttribute(Attribute* attr) { const QualifiedName& attrName = attr->name(); if (attrName == altAttr) { diff --git a/WebCore/html/HTMLImageElement.h b/WebCore/html/HTMLImageElement.h index e9b813c..61faa39 100644 --- a/WebCore/html/HTMLImageElement.h +++ b/WebCore/html/HTMLImageElement.h @@ -44,7 +44,7 @@ public: virtual int tagPriority() const { return 0; } virtual bool mapToEntry(const QualifiedName& attrName, MappedAttributeEntry& result) const; - virtual void parseMappedAttribute(MappedAttribute*); + virtual void parseMappedAttribute(Attribute*); virtual void attach(); virtual RenderObject* createRenderer(RenderArena*, RenderStyle*); diff --git a/WebCore/html/HTMLInputElement.cpp b/WebCore/html/HTMLInputElement.cpp index 31d2cc2..7994472 100644 --- a/WebCore/html/HTMLInputElement.cpp +++ b/WebCore/html/HTMLInputElement.cpp @@ -27,6 +27,7 @@ #include "HTMLInputElement.h" #include "AXObjectCache.h" +#include "Attribute.h" #include "CSSPropertyNames.h" #include "ChromeClient.h" #include "DateComponents.h" @@ -49,7 +50,6 @@ #include "HTMLParser.h" #include "KeyboardEvent.h" #include "LocalizedStrings.h" -#include "MappedAttribute.h" #include "MouseEvent.h" #include "Page.h" #include "RegularExpression.h" @@ -849,7 +849,7 @@ void HTMLInputElement::setInputType(const String& t) registerForActivationCallbackIfNeeded(); if (didRespectHeightAndWidth != willRespectHeightAndWidth) { - NamedMappedAttrMap* map = mappedAttributes(); + NamedNodeMap* map = mappedAttributes(); ASSERT(map); if (Attribute* height = map->getAttributeItem(heightAttr)) attributeChanged(height, false); @@ -1063,7 +1063,7 @@ bool HTMLInputElement::mapToEntry(const QualifiedName& attrName, MappedAttribute return HTMLElement::mapToEntry(attrName, result); } -void HTMLInputElement::parseMappedAttribute(MappedAttribute *attr) +void HTMLInputElement::parseMappedAttribute(Attribute* attr) { if (attr->name() == nameAttr) { checkedRadioButtons(this).removeButton(this); @@ -2646,8 +2646,36 @@ void HTMLInputElement::addSubresourceAttributeURLs(ListHashSet<KURL>& urls) cons bool HTMLInputElement::recalcWillValidate() const { - return HTMLFormControlElementWithState::recalcWillValidate() - && inputType() != HIDDEN && inputType() != BUTTON && inputType() != RESET; + switch (inputType()) { + case CHECKBOX: + case COLOR: + case DATE: + case DATETIME: + case DATETIMELOCAL: + case EMAIL: + case FILE: + case ISINDEX: + case MONTH: + case NUMBER: + case PASSWORD: + case RADIO: + case RANGE: + case SEARCH: + case TELEPHONE: + case TEXT: + case TIME: + case URL: + case WEEK: + return HTMLFormControlElementWithState::recalcWillValidate(); + case BUTTON: + case HIDDEN: + case IMAGE: + case RESET: + case SUBMIT: + return false; + } + ASSERT_NOT_REACHED(); + return false; } bool HTMLInputElement::parseToDateComponents(InputType type, const String& formString, DateComponents* out) diff --git a/WebCore/html/HTMLInputElement.h b/WebCore/html/HTMLInputElement.h index 96fb492..da9cee7 100644 --- a/WebCore/html/HTMLInputElement.h +++ b/WebCore/html/HTMLInputElement.h @@ -179,7 +179,7 @@ public: virtual void accessKeyAction(bool sendToAnyElement); virtual bool mapToEntry(const QualifiedName& attrName, MappedAttributeEntry& result) const; - virtual void parseMappedAttribute(MappedAttribute*); + virtual void parseMappedAttribute(Attribute*); virtual void copyNonAttributeProperties(const Element* source); diff --git a/WebCore/html/HTMLIsIndexElement.cpp b/WebCore/html/HTMLIsIndexElement.cpp index 31fafa6..5cc73de 100644 --- a/WebCore/html/HTMLIsIndexElement.cpp +++ b/WebCore/html/HTMLIsIndexElement.cpp @@ -25,8 +25,8 @@ #include "config.h" #include "HTMLIsIndexElement.h" +#include "Attribute.h" #include "HTMLNames.h" -#include "MappedAttribute.h" namespace WebCore { @@ -39,7 +39,7 @@ HTMLIsIndexElement::HTMLIsIndexElement(const QualifiedName& tagName, Document *d setDefaultName(isindexTag.localName()); } -void HTMLIsIndexElement::parseMappedAttribute(MappedAttribute* attr) +void HTMLIsIndexElement::parseMappedAttribute(Attribute* attr) { if (attr->name() == promptAttr) setValue(attr->value()); diff --git a/WebCore/html/HTMLIsIndexElement.h b/WebCore/html/HTMLIsIndexElement.h index ad56079..f8124f6 100644 --- a/WebCore/html/HTMLIsIndexElement.h +++ b/WebCore/html/HTMLIsIndexElement.h @@ -35,7 +35,7 @@ public: virtual int tagPriority() const { return 0; } virtual bool canTriggerImplicitSubmission() const { return true; } - virtual void parseMappedAttribute(MappedAttribute *attr); + virtual void parseMappedAttribute(Attribute* attr); String prompt() const; void setPrompt(const String &); diff --git a/WebCore/html/HTMLKeygenElement.cpp b/WebCore/html/HTMLKeygenElement.cpp index 6af088f..dbcc2b2 100644 --- a/WebCore/html/HTMLKeygenElement.cpp +++ b/WebCore/html/HTMLKeygenElement.cpp @@ -25,11 +25,11 @@ #include "config.h" #include "HTMLKeygenElement.h" +#include "Attribute.h" #include "Document.h" #include "FormDataList.h" #include "HTMLNames.h" #include "HTMLOptionElement.h" -#include "MappedAttribute.h" #include "SSLKeyGenerator.h" #include "Text.h" #include <wtf/StdLibExtras.h> @@ -61,7 +61,7 @@ const AtomicString& HTMLKeygenElement::formControlType() const return keygen; } -void HTMLKeygenElement::parseMappedAttribute(MappedAttribute* attr) +void HTMLKeygenElement::parseMappedAttribute(Attribute* attr) { if (attr->name() == challengeAttr) m_challenge = attr->value(); diff --git a/WebCore/html/HTMLKeygenElement.h b/WebCore/html/HTMLKeygenElement.h index b2a0c26..8b6b198 100644 --- a/WebCore/html/HTMLKeygenElement.h +++ b/WebCore/html/HTMLKeygenElement.h @@ -35,10 +35,12 @@ public: virtual int tagPriority() const { return 0; } virtual const AtomicString& formControlType() const; virtual bool isEnumeratable() const { return false; } - virtual void parseMappedAttribute(MappedAttribute*); + virtual void parseMappedAttribute(Attribute*); virtual bool appendFormData(FormDataList&, bool); private: + virtual bool isOptionalFormControl() const { return false; } + AtomicString m_challenge; AtomicString m_keyType; }; diff --git a/WebCore/html/HTMLLIElement.cpp b/WebCore/html/HTMLLIElement.cpp index a8a327a..1bfb6f5 100644 --- a/WebCore/html/HTMLLIElement.cpp +++ b/WebCore/html/HTMLLIElement.cpp @@ -23,10 +23,10 @@ #include "config.h" #include "HTMLLIElement.h" +#include "Attribute.h" #include "CSSPropertyNames.h" #include "CSSValueKeywords.h" #include "HTMLNames.h" -#include "MappedAttribute.h" #include "RenderListItem.h" namespace WebCore { @@ -50,7 +50,7 @@ bool HTMLLIElement::mapToEntry(const QualifiedName& attrName, MappedAttributeEnt return HTMLElement::mapToEntry(attrName, result); } -void HTMLLIElement::parseMappedAttribute(MappedAttribute* attr) +void HTMLLIElement::parseMappedAttribute(Attribute* attr) { if (attr->name() == valueAttr) { m_requestedValue = attr->value().toInt(); diff --git a/WebCore/html/HTMLLIElement.h b/WebCore/html/HTMLLIElement.h index e3afaf5..6b46b41 100644 --- a/WebCore/html/HTMLLIElement.h +++ b/WebCore/html/HTMLLIElement.h @@ -34,7 +34,7 @@ public: virtual int tagPriority() const { return 3; } virtual bool mapToEntry(const QualifiedName&, MappedAttributeEntry&) const; - virtual void parseMappedAttribute(MappedAttribute*); + virtual void parseMappedAttribute(Attribute*); virtual void attach(); diff --git a/WebCore/html/HTMLLinkElement.cpp b/WebCore/html/HTMLLinkElement.cpp index 4afccde..c02c4fe 100644 --- a/WebCore/html/HTMLLinkElement.cpp +++ b/WebCore/html/HTMLLinkElement.cpp @@ -24,6 +24,7 @@ #include "config.h" #include "HTMLLinkElement.h" +#include "Attribute.h" #include "CSSHelper.h" #include "CachedCSSStyleSheet.h" #include "DocLoader.h" @@ -33,7 +34,6 @@ #include "FrameLoaderClient.h" #include "FrameTree.h" #include "HTMLNames.h" -#include "MappedAttribute.h" #include "MediaList.h" #include "MediaQueryEvaluator.h" #include "Page.h" @@ -112,7 +112,7 @@ StyleSheet* HTMLLinkElement::sheet() const return m_sheet.get(); } -void HTMLLinkElement::parseMappedAttribute(MappedAttribute *attr) +void HTMLLinkElement::parseMappedAttribute(Attribute* attr) { if (attr->name() == relAttr) { tokenizeRelAttribute(attr->value(), m_relAttribute); diff --git a/WebCore/html/HTMLLinkElement.h b/WebCore/html/HTMLLinkElement.h index 4ca921f..8da4494 100644 --- a/WebCore/html/HTMLLinkElement.h +++ b/WebCore/html/HTMLLinkElement.h @@ -96,7 +96,7 @@ public: StyleSheet* sheet() const; // overload from HTMLElement - virtual void parseMappedAttribute(MappedAttribute*); + virtual void parseMappedAttribute(Attribute*); void process(); diff --git a/WebCore/html/HTMLMapElement.cpp b/WebCore/html/HTMLMapElement.cpp index 10a05d6..cc709a0 100644 --- a/WebCore/html/HTMLMapElement.cpp +++ b/WebCore/html/HTMLMapElement.cpp @@ -22,6 +22,7 @@ #include "config.h" #include "HTMLMapElement.h" +#include "Attribute.h" #include "Document.h" #include "HTMLAreaElement.h" #include "HTMLCollection.h" @@ -29,7 +30,6 @@ #include "HTMLNames.h" #include "HitTestResult.h" #include "IntSize.h" -#include "MappedAttribute.h" #include "RenderObject.h" using namespace std; @@ -95,7 +95,7 @@ HTMLImageElement* HTMLMapElement::imageElement() const return 0; } -void HTMLMapElement::parseMappedAttribute(MappedAttribute* attr) +void HTMLMapElement::parseMappedAttribute(Attribute* attr) { const QualifiedName& attrName = attr->name(); if (attrName == idAttributeName() || attrName == nameAttr) { diff --git a/WebCore/html/HTMLMapElement.h b/WebCore/html/HTMLMapElement.h index f40e78e..8dc9edf 100644 --- a/WebCore/html/HTMLMapElement.h +++ b/WebCore/html/HTMLMapElement.h @@ -42,7 +42,7 @@ public: const AtomicString& getName() const { return m_name; } - virtual void parseMappedAttribute(MappedAttribute*); + virtual void parseMappedAttribute(Attribute*); bool mapMouseEvent(int x, int y, const IntSize&, HitTestResult&); diff --git a/WebCore/html/HTMLMarqueeElement.cpp b/WebCore/html/HTMLMarqueeElement.cpp index 7c16f16..23122dc 100644 --- a/WebCore/html/HTMLMarqueeElement.cpp +++ b/WebCore/html/HTMLMarqueeElement.cpp @@ -23,10 +23,10 @@ #include "config.h" #include "HTMLMarqueeElement.h" +#include "Attribute.h" #include "CSSPropertyNames.h" #include "CSSValueKeywords.h" #include "HTMLNames.h" -#include "MappedAttribute.h" #include "RenderLayer.h" #include "RenderMarquee.h" @@ -64,7 +64,7 @@ bool HTMLMarqueeElement::mapToEntry(const QualifiedName& attrName, MappedAttribu return HTMLElement::mapToEntry(attrName, result); } -void HTMLMarqueeElement::parseMappedAttribute(MappedAttribute *attr) +void HTMLMarqueeElement::parseMappedAttribute(Attribute* attr) { if (attr->name() == widthAttr) { if (!attr->value().isEmpty()) diff --git a/WebCore/html/HTMLMarqueeElement.h b/WebCore/html/HTMLMarqueeElement.h index 9100e8f..871edc8 100644 --- a/WebCore/html/HTMLMarqueeElement.h +++ b/WebCore/html/HTMLMarqueeElement.h @@ -38,7 +38,7 @@ public: virtual int tagPriority() const { return 3; } virtual bool mapToEntry(const QualifiedName&, MappedAttributeEntry&) const; - virtual void parseMappedAttribute(MappedAttribute*); + virtual void parseMappedAttribute(Attribute*); int minimumDelay() const { return m_minimumDelay; } diff --git a/WebCore/html/HTMLMediaElement.cpp b/WebCore/html/HTMLMediaElement.cpp index a08ff45..efef1d2 100644 --- a/WebCore/html/HTMLMediaElement.cpp +++ b/WebCore/html/HTMLMediaElement.cpp @@ -28,13 +28,14 @@ #if ENABLE(VIDEO) #include "HTMLMediaElement.h" +#include "Attribute.h" +#include "CSSHelper.h" +#include "CSSPropertyNames.h" +#include "CSSValueKeywords.h" #include "Chrome.h" #include "ChromeClient.h" #include "ClientRect.h" #include "ClientRectList.h" -#include "CSSHelper.h" -#include "CSSPropertyNames.h" -#include "CSSValueKeywords.h" #include "ContentType.h" #include "DocLoader.h" #include "Event.h" @@ -49,7 +50,6 @@ #include "HTMLSourceElement.h" #include "HTMLVideoElement.h" #include "MIMETypeRegistry.h" -#include "MappedAttribute.h" #include "MediaDocument.h" #include "MediaError.h" #include "MediaList.h" @@ -129,6 +129,7 @@ HTMLMediaElement::HTMLMediaElement(const QualifiedName& tagName, Document* doc) , m_needWidgetUpdate(false) #endif , m_dispatchingCanPlayEvent(false) + , m_loadInitiatedByUserGesture(false) { document()->registerForDocumentActivationCallbacks(this); document()->registerForMediaVolumeCallbacks(this); @@ -188,7 +189,7 @@ void HTMLMediaElement::attributeChanged(Attribute* attr, bool preserveDecls) #endif } -void HTMLMediaElement::parseMappedAttribute(MappedAttribute* attr) +void HTMLMediaElement::parseMappedAttribute(Attribute* attr) { const QualifiedName& attrName = attr->name(); @@ -468,6 +469,7 @@ void HTMLMediaElement::load(bool isUserGesture, ExceptionCode& ec) if (m_restrictions & RequireUserGestureForLoadRestriction && !isUserGesture) ec = INVALID_STATE_ERR; else { + m_loadInitiatedByUserGesture = isUserGesture; prepareForLoad(); loadInternal(); } @@ -1206,7 +1208,7 @@ void HTMLMediaElement::play(bool isUserGesture) Document* doc = document(); Settings* settings = doc->settings(); - if (settings && settings->needsSiteSpecificQuirks() && m_dispatchingCanPlayEvent) { + if (settings && settings->needsSiteSpecificQuirks() && m_dispatchingCanPlayEvent && !m_loadInitiatedByUserGesture) { // It should be impossible to be processing the canplay event while handling a user gesture // since it is dispatched asynchronously. ASSERT(!isUserGesture); diff --git a/WebCore/html/HTMLMediaElement.h b/WebCore/html/HTMLMediaElement.h index 9c36438..35c2235 100644 --- a/WebCore/html/HTMLMediaElement.h +++ b/WebCore/html/HTMLMediaElement.h @@ -173,7 +173,7 @@ protected: HTMLMediaElement(const QualifiedName&, Document*); virtual ~HTMLMediaElement(); - virtual void parseMappedAttribute(MappedAttribute*); + virtual void parseMappedAttribute(Attribute*); virtual void attach(); virtual void willMoveToNewOwnerDocument(); @@ -364,6 +364,7 @@ private: #endif bool m_dispatchingCanPlayEvent : 1; + bool m_loadInitiatedByUserGesture : 1; }; } //namespace diff --git a/WebCore/html/HTMLMetaElement.cpp b/WebCore/html/HTMLMetaElement.cpp index 51bfac3..70129b1 100644 --- a/WebCore/html/HTMLMetaElement.cpp +++ b/WebCore/html/HTMLMetaElement.cpp @@ -23,9 +23,9 @@ #include "config.h" #include "HTMLMetaElement.h" +#include "Attribute.h" #include "Document.h" #include "HTMLNames.h" -#include "MappedAttribute.h" #ifdef ANDROID_META_SUPPORT #include "Settings.h" @@ -46,7 +46,7 @@ HTMLMetaElement::~HTMLMetaElement() { } -void HTMLMetaElement::parseMappedAttribute(MappedAttribute* attr) +void HTMLMetaElement::parseMappedAttribute(Attribute* attr) { if (attr->name() == http_equivAttr) { m_equiv = attr->value(); diff --git a/WebCore/html/HTMLMetaElement.h b/WebCore/html/HTMLMetaElement.h index 19e8ecd..61d6a86 100644 --- a/WebCore/html/HTMLMetaElement.h +++ b/WebCore/html/HTMLMetaElement.h @@ -34,7 +34,7 @@ public: virtual HTMLTagStatus endTagRequirement() const { return TagStatusForbidden; } virtual int tagPriority() const { return 0; } - virtual void parseMappedAttribute(MappedAttribute*); + virtual void parseMappedAttribute(Attribute*); virtual void insertedIntoDocument(); void process(); diff --git a/WebCore/html/HTMLMeterElement.cpp b/WebCore/html/HTMLMeterElement.cpp index 2c1f8a5..a1b74b2 100644 --- a/WebCore/html/HTMLMeterElement.cpp +++ b/WebCore/html/HTMLMeterElement.cpp @@ -22,12 +22,12 @@ #if ENABLE(METER_TAG) #include "HTMLMeterElement.h" +#include "Attribute.h" #include "EventNames.h" #include "FormDataList.h" #include "HTMLFormElement.h" #include "HTMLNames.h" #include "HTMLParser.h" -#include "MappedAttribute.h" #include "RenderMeter.h" #include <wtf/StdLibExtras.h> @@ -57,7 +57,7 @@ const AtomicString& HTMLMeterElement::formControlType() const return meter; } -void HTMLMeterElement::parseMappedAttribute(MappedAttribute* attribute) +void HTMLMeterElement::parseMappedAttribute(Attribute* attribute) { if (attribute->name() == valueAttr || attribute->name() == minAttr || attribute->name() == maxAttr || attribute->name() == lowAttr || attribute->name() == highAttr || attribute->name() == optimumAttr) { if (renderer()) diff --git a/WebCore/html/HTMLMeterElement.h b/WebCore/html/HTMLMeterElement.h index 0808b9f..a218584 100644 --- a/WebCore/html/HTMLMeterElement.h +++ b/WebCore/html/HTMLMeterElement.h @@ -57,7 +57,7 @@ private: virtual RenderObject* createRenderer(RenderArena*, RenderStyle*); - virtual void parseMappedAttribute(MappedAttribute*); + virtual void parseMappedAttribute(Attribute*); }; } // namespace diff --git a/WebCore/html/HTMLOListElement.cpp b/WebCore/html/HTMLOListElement.cpp index 344a069..82c4526 100644 --- a/WebCore/html/HTMLOListElement.cpp +++ b/WebCore/html/HTMLOListElement.cpp @@ -22,10 +22,10 @@ #include "config.h" #include "HTMLOListElement.h" +#include "Attribute.h" #include "CSSPropertyNames.h" #include "CSSValueKeywords.h" #include "HTMLNames.h" -#include "MappedAttribute.h" #include "RenderListItem.h" namespace WebCore { @@ -49,7 +49,7 @@ bool HTMLOListElement::mapToEntry(const QualifiedName& attrName, MappedAttribute return HTMLElement::mapToEntry(attrName, result); } -void HTMLOListElement::parseMappedAttribute(MappedAttribute* attr) +void HTMLOListElement::parseMappedAttribute(Attribute* attr) { if (attr->name() == typeAttr) { if (attr->value() == "a") diff --git a/WebCore/html/HTMLOListElement.h b/WebCore/html/HTMLOListElement.h index b7a13ee..3d76abf 100644 --- a/WebCore/html/HTMLOListElement.h +++ b/WebCore/html/HTMLOListElement.h @@ -34,7 +34,7 @@ public: virtual int tagPriority() const { return 5; } virtual bool mapToEntry(const QualifiedName&, MappedAttributeEntry&) const; - virtual void parseMappedAttribute(MappedAttribute*); + virtual void parseMappedAttribute(Attribute*); bool compact() const; void setCompact(bool); diff --git a/WebCore/html/HTMLObjectElement.cpp b/WebCore/html/HTMLObjectElement.cpp index 74fbf21..ea130b9 100644 --- a/WebCore/html/HTMLObjectElement.cpp +++ b/WebCore/html/HTMLObjectElement.cpp @@ -24,6 +24,7 @@ #include "config.h" #include "HTMLObjectElement.h" +#include "Attribute.h" #include "CSSHelper.h" #include "EventNames.h" #include "ExceptionCode.h" @@ -32,13 +33,12 @@ #include "HTMLFormElement.h" #include "HTMLImageLoader.h" #include "HTMLNames.h" -#include "ScriptEventListener.h" #include "MIMETypeRegistry.h" -#include "MappedAttribute.h" #include "RenderEmbeddedObject.h" #include "RenderImage.h" #include "RenderWidget.h" #include "ScriptController.h" +#include "ScriptEventListener.h" #include "Text.h" namespace WebCore { @@ -67,7 +67,7 @@ RenderWidget* HTMLObjectElement::renderWidgetForJSBindings() const return toRenderWidget(renderer()); } -void HTMLObjectElement::parseMappedAttribute(MappedAttribute *attr) +void HTMLObjectElement::parseMappedAttribute(Attribute* attr) { String val = attr->value(); int pos; diff --git a/WebCore/html/HTMLObjectElement.h b/WebCore/html/HTMLObjectElement.h index ec1132f..4a22ea3 100644 --- a/WebCore/html/HTMLObjectElement.h +++ b/WebCore/html/HTMLObjectElement.h @@ -55,7 +55,7 @@ private: virtual int tagPriority() const { return 5; } - virtual void parseMappedAttribute(MappedAttribute*); + virtual void parseMappedAttribute(Attribute*); virtual void attach(); virtual bool canLazyAttach() { return false; } diff --git a/WebCore/html/HTMLOptGroupElement.cpp b/WebCore/html/HTMLOptGroupElement.cpp index 90156da..5c5faac 100644 --- a/WebCore/html/HTMLOptGroupElement.cpp +++ b/WebCore/html/HTMLOptGroupElement.cpp @@ -97,7 +97,7 @@ void HTMLOptGroupElement::childrenChanged(bool changedByParser, Node* beforeChan HTMLFormControlElement::childrenChanged(changedByParser, beforeChange, afterChange, childCountDelta); } -void HTMLOptGroupElement::parseMappedAttribute(MappedAttribute* attr) +void HTMLOptGroupElement::parseMappedAttribute(Attribute* attr) { HTMLFormControlElement::parseMappedAttribute(attr); recalcSelectOptions(); diff --git a/WebCore/html/HTMLOptGroupElement.h b/WebCore/html/HTMLOptGroupElement.h index 6e5b043..cdd1d37 100644 --- a/WebCore/html/HTMLOptGroupElement.h +++ b/WebCore/html/HTMLOptGroupElement.h @@ -39,7 +39,7 @@ public: virtual const AtomicString& formControlType() const; virtual bool supportsFocus() const; virtual bool isFocusable() const; - virtual void parseMappedAttribute(MappedAttribute*); + virtual void parseMappedAttribute(Attribute*); virtual bool rendererIsNeeded(RenderStyle*) { return false; } virtual void attach(); virtual void detach(); diff --git a/WebCore/html/HTMLOptionElement.cpp b/WebCore/html/HTMLOptionElement.cpp index 1e07221..fa430d3 100644 --- a/WebCore/html/HTMLOptionElement.cpp +++ b/WebCore/html/HTMLOptionElement.cpp @@ -26,12 +26,12 @@ #include "config.h" #include "HTMLOptionElement.h" +#include "Attribute.h" #include "CSSStyleSelector.h" #include "Document.h" #include "ExceptionCode.h" #include "HTMLNames.h" #include "HTMLSelectElement.h" -#include "MappedAttribute.h" #include "NodeRenderStyle.h" #include "RenderMenuList.h" #include "Text.h" @@ -134,7 +134,7 @@ int HTMLOptionElement::index() const return OptionElement::optionIndex(ownerSelectElement(), this); } -void HTMLOptionElement::parseMappedAttribute(MappedAttribute *attr) +void HTMLOptionElement::parseMappedAttribute(Attribute* attr) { if (attr->name() == selectedAttr) m_data.setSelected(!attr->isNull()); diff --git a/WebCore/html/HTMLOptionElement.h b/WebCore/html/HTMLOptionElement.h index 4255f25..4692119 100644 --- a/WebCore/html/HTMLOptionElement.h +++ b/WebCore/html/HTMLOptionElement.h @@ -29,9 +29,9 @@ namespace WebCore { -class HTMLSelectElement; +class Attribute; class HTMLFormElement; -class MappedAttribute; +class HTMLSelectElement; class HTMLOptionElement : public HTMLFormControlElement, public OptionElement { friend class HTMLSelectElement; @@ -59,7 +59,7 @@ public: void setText(const String&, ExceptionCode&); int index() const; - virtual void parseMappedAttribute(MappedAttribute*); + virtual void parseMappedAttribute(Attribute*); virtual String value() const; void setValue(const String&); diff --git a/WebCore/html/HTMLParagraphElement.cpp b/WebCore/html/HTMLParagraphElement.cpp index a8deb10..f39e3ff 100644 --- a/WebCore/html/HTMLParagraphElement.cpp +++ b/WebCore/html/HTMLParagraphElement.cpp @@ -23,11 +23,11 @@ #include "config.h" #include "HTMLParagraphElement.h" +#include "Attribute.h" #include "CSSPropertyNames.h" #include "CSSValueKeywords.h" #include "Document.h" #include "HTMLNames.h" -#include "MappedAttribute.h" namespace WebCore { @@ -53,7 +53,7 @@ bool HTMLParagraphElement::mapToEntry(const QualifiedName& attrName, MappedAttri return HTMLElement::mapToEntry(attrName, result); } -void HTMLParagraphElement::parseMappedAttribute(MappedAttribute *attr) +void HTMLParagraphElement::parseMappedAttribute(Attribute* attr) { if (attr->name() == alignAttr) { String v = attr->value(); diff --git a/WebCore/html/HTMLParagraphElement.h b/WebCore/html/HTMLParagraphElement.h index 8e1646f..496951a 100644 --- a/WebCore/html/HTMLParagraphElement.h +++ b/WebCore/html/HTMLParagraphElement.h @@ -35,7 +35,7 @@ public: virtual bool checkDTD(const Node* newChild); virtual bool mapToEntry(const QualifiedName&, MappedAttributeEntry&) const; - virtual void parseMappedAttribute(MappedAttribute*); + virtual void parseMappedAttribute(Attribute*); String align() const; void setAlign(const String&); diff --git a/WebCore/html/HTMLParamElement.cpp b/WebCore/html/HTMLParamElement.cpp index 2b0637a..61a5a65 100644 --- a/WebCore/html/HTMLParamElement.cpp +++ b/WebCore/html/HTMLParamElement.cpp @@ -23,9 +23,9 @@ #include "config.h" #include "HTMLParamElement.h" +#include "Attribute.h" #include "Document.h" #include "HTMLNames.h" -#include "MappedAttribute.h" namespace WebCore { @@ -41,7 +41,7 @@ HTMLParamElement::~HTMLParamElement() { } -void HTMLParamElement::parseMappedAttribute(MappedAttribute* attr) +void HTMLParamElement::parseMappedAttribute(Attribute* attr) { if (attr->name() == idAttributeName()) { // Must call base class so that hasID bit gets set. diff --git a/WebCore/html/HTMLParamElement.h b/WebCore/html/HTMLParamElement.h index 1867ccf..84152c6 100644 --- a/WebCore/html/HTMLParamElement.h +++ b/WebCore/html/HTMLParamElement.h @@ -36,7 +36,7 @@ public: virtual HTMLTagStatus endTagRequirement() const { return TagStatusForbidden; } virtual int tagPriority() const { return 0; } - virtual void parseMappedAttribute(MappedAttribute*); + virtual void parseMappedAttribute(Attribute*); virtual bool isURLAttribute(Attribute*) const; diff --git a/WebCore/html/HTMLParser.cpp b/WebCore/html/HTMLParser.cpp index 428e8d5..0f0a0fc 100644 --- a/WebCore/html/HTMLParser.cpp +++ b/WebCore/html/HTMLParser.cpp @@ -55,6 +55,7 @@ #include "HTMLTokenizer.h" #include "LocalizedStrings.h" #include "Page.h" +#include "QualifiedName.h" #include "Settings.h" #include "Text.h" #include "TreeDepthLimit.h" @@ -77,6 +78,18 @@ static const int minBlockLevelTagPriority = 3; // siblings instead of children once it is reached. static const size_t cMaxBlockDepth = 4096; + +typedef HashSet<AtomicStringImpl*> TagNameSet; + +template< size_t ArraySize > +static void addTags(TagNameSet& set, QualifiedName (&names)[ArraySize]) +{ + for (size_t x = 0; x < ArraySize; x++) { + const QualifiedName& name = names[x]; + set.add(name.localName().impl()); + } +} + struct HTMLStackElem : Noncopyable { HTMLStackElem(const AtomicString& t, int lvl, Node* n, bool r, HTMLStackElem* nx) : tagName(t) @@ -342,8 +355,8 @@ static bool isTableSection(const Node* n) static bool isTablePart(const Node* n) { - return n->hasTagName(trTag) || n->hasTagName(tdTag) || n->hasTagName(thTag) || - isTableSection(n); + return n->hasTagName(trTag) || n->hasTagName(tdTag) || n->hasTagName(thTag) + || isTableSection(n); } static bool isTableRelated(const Node* n) @@ -353,7 +366,9 @@ static bool isTableRelated(const Node* n) static bool isScopingTag(const AtomicString& tagName) { - return tagName == appletTag || tagName == captionTag || tagName == tdTag || tagName == thTag || tagName == buttonTag || tagName == marqueeTag || tagName == objectTag || tagName == tableTag || tagName == htmlTag; + return tagName == appletTag || tagName == captionTag || tagName == tdTag + || tagName == thTag || tagName == buttonTag || tagName == marqueeTag + || tagName == objectTag || tagName == tableTag || tagName == htmlTag; } bool HTMLParser::insertNode(Node* n, bool flat) @@ -912,74 +927,62 @@ bool HTMLParser::mapCreateErrorCheck(Token*, RefPtr<Node>& result) return false; } +static void mapTagToFunc(FunctionMap& map, const QualifiedName& tag, CreateErrorCheckFunc func) +{ + map.set(tag.localName().impl(), func); +} + +template< size_t ArraySize > +static void mapTagsToFunc(FunctionMap& map, QualifiedName (&names)[ArraySize], CreateErrorCheckFunc func) +{ + for (size_t x = 0; x < ArraySize; x++) { + const QualifiedName& name = names[x]; + mapTagToFunc(map, name, func); + } +} + PassRefPtr<Node> HTMLParser::getNode(Token* t) { // Init our error handling table. DEFINE_STATIC_LOCAL(FunctionMap, gFunctionMap, ()); if (gFunctionMap.isEmpty()) { - gFunctionMap.set(aTag.localName().impl(), &HTMLParser::nestedCreateErrorCheck); - gFunctionMap.set(addressTag.localName().impl(), &HTMLParser::pCloserCreateErrorCheck); - gFunctionMap.set(articleTag.localName().impl(), &HTMLParser::pCloserCreateErrorCheck); - gFunctionMap.set(asideTag.localName().impl(), &HTMLParser::pCloserCreateErrorCheck); - gFunctionMap.set(bTag.localName().impl(), &HTMLParser::nestedStyleCreateErrorCheck); - gFunctionMap.set(bigTag.localName().impl(), &HTMLParser::nestedStyleCreateErrorCheck); - gFunctionMap.set(blockquoteTag.localName().impl(), &HTMLParser::pCloserCreateErrorCheck); - gFunctionMap.set(bodyTag.localName().impl(), &HTMLParser::bodyCreateErrorCheck); - gFunctionMap.set(buttonTag.localName().impl(), &HTMLParser::nestedCreateErrorCheck); - gFunctionMap.set(centerTag.localName().impl(), &HTMLParser::pCloserCreateErrorCheck); + QualifiedName nestedCreateErrorTags[] = { aTag, buttonTag, nobrTag, trTag }; + mapTagsToFunc(gFunctionMap, nestedCreateErrorTags, &HTMLParser::nestedCreateErrorCheck); + + QualifiedName nestedStyleCreateErrorTags[] = { bTag, bigTag, iTag, sTag, smallTag, strikeTag, ttTag, uTag }; + mapTagsToFunc(gFunctionMap, nestedStyleCreateErrorTags, &HTMLParser::nestedStyleCreateErrorCheck); + + QualifiedName pCloserCreateErrorTags[] = { addressTag, articleTag, + asideTag, blockquoteTag, centerTag, dirTag, divTag, dlTag, + fieldsetTag, footerTag, h1Tag, h2Tag, h3Tag, h4Tag, h5Tag, h6Tag, + headerTag, hgroupTag, hrTag, listingTag, menuTag, navTag, olTag, + pTag, plaintextTag, preTag, sectionTag, ulTag }; + mapTagsToFunc(gFunctionMap, pCloserCreateErrorTags, &HTMLParser::pCloserCreateErrorCheck); + + mapTagToFunc(gFunctionMap, bodyTag, &HTMLParser::bodyCreateErrorCheck); + mapTagToFunc(gFunctionMap, ddTag, &HTMLParser::ddCreateErrorCheck); + mapTagToFunc(gFunctionMap, dtTag, &HTMLParser::dtCreateErrorCheck); + mapTagToFunc(gFunctionMap, formTag, &HTMLParser::formCreateErrorCheck); + mapTagToFunc(gFunctionMap, framesetTag, &HTMLParser::framesetCreateErrorCheck); + mapTagToFunc(gFunctionMap, headTag, &HTMLParser::headCreateErrorCheck); + mapTagToFunc(gFunctionMap, isindexTag, &HTMLParser::isindexCreateErrorCheck); + mapTagToFunc(gFunctionMap, mapTag, &HTMLParser::mapCreateErrorCheck); + mapTagToFunc(gFunctionMap, liTag, &HTMLParser::nestedPCloserCreateErrorCheck); + mapTagToFunc(gFunctionMap, noembedTag, &HTMLParser::noembedCreateErrorCheck); + mapTagToFunc(gFunctionMap, noframesTag, &HTMLParser::noframesCreateErrorCheck); + mapTagToFunc(gFunctionMap, noscriptTag, &HTMLParser::noscriptCreateErrorCheck); + mapTagToFunc(gFunctionMap, tableTag, &HTMLParser::pCloserStrictCreateErrorCheck); + mapTagToFunc(gFunctionMap, rpTag, &HTMLParser::rpCreateErrorCheck); + mapTagToFunc(gFunctionMap, rtTag, &HTMLParser::rtCreateErrorCheck); + mapTagToFunc(gFunctionMap, selectTag, &HTMLParser::selectCreateErrorCheck); + mapTagToFunc(gFunctionMap, tdTag, &HTMLParser::tableCellCreateErrorCheck); + mapTagToFunc(gFunctionMap, thTag, &HTMLParser::tableCellCreateErrorCheck); + mapTagToFunc(gFunctionMap, tbodyTag, &HTMLParser::tableSectionCreateErrorCheck); + mapTagToFunc(gFunctionMap, tfootTag, &HTMLParser::tableSectionCreateErrorCheck); + mapTagToFunc(gFunctionMap, theadTag, &HTMLParser::tableSectionCreateErrorCheck); + gFunctionMap.set(commentAtom.impl(), &HTMLParser::commentCreateErrorCheck); - gFunctionMap.set(ddTag.localName().impl(), &HTMLParser::ddCreateErrorCheck); - gFunctionMap.set(dirTag.localName().impl(), &HTMLParser::pCloserCreateErrorCheck); - gFunctionMap.set(divTag.localName().impl(), &HTMLParser::pCloserCreateErrorCheck); - gFunctionMap.set(dlTag.localName().impl(), &HTMLParser::pCloserCreateErrorCheck); - gFunctionMap.set(dtTag.localName().impl(), &HTMLParser::dtCreateErrorCheck); - gFunctionMap.set(formTag.localName().impl(), &HTMLParser::formCreateErrorCheck); - gFunctionMap.set(fieldsetTag.localName().impl(), &HTMLParser::pCloserCreateErrorCheck); - gFunctionMap.set(footerTag.localName().impl(), &HTMLParser::pCloserCreateErrorCheck); - gFunctionMap.set(framesetTag.localName().impl(), &HTMLParser::framesetCreateErrorCheck); - gFunctionMap.set(h1Tag.localName().impl(), &HTMLParser::pCloserCreateErrorCheck); - gFunctionMap.set(h2Tag.localName().impl(), &HTMLParser::pCloserCreateErrorCheck); - gFunctionMap.set(h3Tag.localName().impl(), &HTMLParser::pCloserCreateErrorCheck); - gFunctionMap.set(h4Tag.localName().impl(), &HTMLParser::pCloserCreateErrorCheck); - gFunctionMap.set(h5Tag.localName().impl(), &HTMLParser::pCloserCreateErrorCheck); - gFunctionMap.set(h6Tag.localName().impl(), &HTMLParser::pCloserCreateErrorCheck); - gFunctionMap.set(headTag.localName().impl(), &HTMLParser::headCreateErrorCheck); - gFunctionMap.set(headerTag.localName().impl(), &HTMLParser::pCloserCreateErrorCheck); - gFunctionMap.set(hgroupTag.localName().impl(), &HTMLParser::pCloserCreateErrorCheck); - gFunctionMap.set(hrTag.localName().impl(), &HTMLParser::pCloserCreateErrorCheck); - gFunctionMap.set(iTag.localName().impl(), &HTMLParser::nestedStyleCreateErrorCheck); - gFunctionMap.set(isindexTag.localName().impl(), &HTMLParser::isindexCreateErrorCheck); - gFunctionMap.set(liTag.localName().impl(), &HTMLParser::nestedPCloserCreateErrorCheck); - gFunctionMap.set(listingTag.localName().impl(), &HTMLParser::pCloserCreateErrorCheck); - gFunctionMap.set(mapTag.localName().impl(), &HTMLParser::mapCreateErrorCheck); - gFunctionMap.set(menuTag.localName().impl(), &HTMLParser::pCloserCreateErrorCheck); - gFunctionMap.set(navTag.localName().impl(), &HTMLParser::pCloserCreateErrorCheck); - gFunctionMap.set(nobrTag.localName().impl(), &HTMLParser::nestedCreateErrorCheck); - gFunctionMap.set(noembedTag.localName().impl(), &HTMLParser::noembedCreateErrorCheck); - gFunctionMap.set(noframesTag.localName().impl(), &HTMLParser::noframesCreateErrorCheck); - gFunctionMap.set(noscriptTag.localName().impl(), &HTMLParser::noscriptCreateErrorCheck); - gFunctionMap.set(olTag.localName().impl(), &HTMLParser::pCloserCreateErrorCheck); - gFunctionMap.set(pTag.localName().impl(), &HTMLParser::pCloserCreateErrorCheck); - gFunctionMap.set(plaintextTag.localName().impl(), &HTMLParser::pCloserCreateErrorCheck); - gFunctionMap.set(preTag.localName().impl(), &HTMLParser::pCloserCreateErrorCheck); - gFunctionMap.set(rpTag.localName().impl(), &HTMLParser::rpCreateErrorCheck); - gFunctionMap.set(rtTag.localName().impl(), &HTMLParser::rtCreateErrorCheck); - gFunctionMap.set(sTag.localName().impl(), &HTMLParser::nestedStyleCreateErrorCheck); - gFunctionMap.set(sectionTag.localName().impl(), &HTMLParser::pCloserCreateErrorCheck); - gFunctionMap.set(selectTag.localName().impl(), &HTMLParser::selectCreateErrorCheck); - gFunctionMap.set(smallTag.localName().impl(), &HTMLParser::nestedStyleCreateErrorCheck); - gFunctionMap.set(strikeTag.localName().impl(), &HTMLParser::nestedStyleCreateErrorCheck); - gFunctionMap.set(tableTag.localName().impl(), &HTMLParser::pCloserStrictCreateErrorCheck); - gFunctionMap.set(tbodyTag.localName().impl(), &HTMLParser::tableSectionCreateErrorCheck); - gFunctionMap.set(tdTag.localName().impl(), &HTMLParser::tableCellCreateErrorCheck); gFunctionMap.set(textAtom.impl(), &HTMLParser::textCreateErrorCheck); - gFunctionMap.set(tfootTag.localName().impl(), &HTMLParser::tableSectionCreateErrorCheck); - gFunctionMap.set(thTag.localName().impl(), &HTMLParser::tableCellCreateErrorCheck); - gFunctionMap.set(theadTag.localName().impl(), &HTMLParser::tableSectionCreateErrorCheck); - gFunctionMap.set(trTag.localName().impl(), &HTMLParser::nestedCreateErrorCheck); - gFunctionMap.set(ttTag.localName().impl(), &HTMLParser::nestedStyleCreateErrorCheck); - gFunctionMap.set(uTag.localName().impl(), &HTMLParser::nestedStyleCreateErrorCheck); - gFunctionMap.set(ulTag.localName().impl(), &HTMLParser::pCloserCreateErrorCheck); } bool proceed = true; @@ -1035,16 +1038,11 @@ void HTMLParser::processCloseTag(Token* t) bool HTMLParser::isHeadingTag(const AtomicString& tagName) { - DEFINE_STATIC_LOCAL(HashSet<AtomicStringImpl*>, headingTags, ()); + DEFINE_STATIC_LOCAL(TagNameSet, headingTags, ()); if (headingTags.isEmpty()) { - headingTags.add(h1Tag.localName().impl()); - headingTags.add(h2Tag.localName().impl()); - headingTags.add(h3Tag.localName().impl()); - headingTags.add(h4Tag.localName().impl()); - headingTags.add(h5Tag.localName().impl()); - headingTags.add(h6Tag.localName().impl()); + QualifiedName tagNames[] = { h1Tag, h2Tag, h3Tag, h4Tag, h5Tag, h6Tag }; + addTags(headingTags, tagNames); } - return headingTags.contains(tagName.impl()); } @@ -1082,26 +1080,11 @@ bool HTMLParser::isResidualStyleTag(const AtomicString& tagName) { DEFINE_STATIC_LOCAL(HashSet<AtomicStringImpl*>, residualStyleTags, ()); if (residualStyleTags.isEmpty()) { - residualStyleTags.add(aTag.localName().impl()); - residualStyleTags.add(fontTag.localName().impl()); - residualStyleTags.add(ttTag.localName().impl()); - residualStyleTags.add(uTag.localName().impl()); - residualStyleTags.add(bTag.localName().impl()); - residualStyleTags.add(iTag.localName().impl()); - residualStyleTags.add(sTag.localName().impl()); - residualStyleTags.add(strikeTag.localName().impl()); - residualStyleTags.add(bigTag.localName().impl()); - residualStyleTags.add(smallTag.localName().impl()); - residualStyleTags.add(emTag.localName().impl()); - residualStyleTags.add(strongTag.localName().impl()); - residualStyleTags.add(dfnTag.localName().impl()); - residualStyleTags.add(codeTag.localName().impl()); - residualStyleTags.add(sampTag.localName().impl()); - residualStyleTags.add(kbdTag.localName().impl()); - residualStyleTags.add(varTag.localName().impl()); - residualStyleTags.add(nobrTag.localName().impl()); + QualifiedName tagNames[] = { aTag, fontTag, ttTag, uTag, bTag, iTag, + sTag, strikeTag, bigTag, smallTag, emTag, strongTag, dfnTag, + codeTag, sampTag, kbdTag, varTag, nobrTag }; + addTags(residualStyleTags, tagNames); } - return residualStyleTags.contains(tagName.impl()); } @@ -1109,25 +1092,11 @@ bool HTMLParser::isAffectedByResidualStyle(const AtomicString& tagName) { DEFINE_STATIC_LOCAL(HashSet<AtomicStringImpl*>, unaffectedTags, ()); if (unaffectedTags.isEmpty()) { - unaffectedTags.add(bodyTag.localName().impl()); - unaffectedTags.add(tableTag.localName().impl()); - unaffectedTags.add(theadTag.localName().impl()); - unaffectedTags.add(tbodyTag.localName().impl()); - unaffectedTags.add(tfootTag.localName().impl()); - unaffectedTags.add(trTag.localName().impl()); - unaffectedTags.add(thTag.localName().impl()); - unaffectedTags.add(tdTag.localName().impl()); - unaffectedTags.add(captionTag.localName().impl()); - unaffectedTags.add(colgroupTag.localName().impl()); - unaffectedTags.add(colTag.localName().impl()); - unaffectedTags.add(optionTag.localName().impl()); - unaffectedTags.add(optgroupTag.localName().impl()); - unaffectedTags.add(selectTag.localName().impl()); - unaffectedTags.add(objectTag.localName().impl()); - unaffectedTags.add(datagridTag.localName().impl()); - unaffectedTags.add(datalistTag.localName().impl()); + QualifiedName tagNames[] = { bodyTag, tableTag, theadTag, tbodyTag, + tfootTag, trTag, thTag, tdTag, captionTag, colgroupTag, colTag, + optionTag, optgroupTag, selectTag, objectTag, datagridTag, datalistTag }; + addTags(unaffectedTags, tagNames); } - return !unaffectedTags.contains(tagName.impl()); } @@ -1629,7 +1598,7 @@ PassRefPtr<Node> HTMLParser::handleIsindex(Token* t) { RefPtr<Node> n = new HTMLDivElement(divTag, m_document); - NamedMappedAttrMap* attrs = t->attrs.get(); + NamedNodeMap* attrs = t->attrs.get(); RefPtr<HTMLIsIndexElement> isIndex = new HTMLIsIndexElement(isindexTag, m_document, m_currentFormElement.get()); isIndex->setAttributeMap(attrs); diff --git a/WebCore/html/HTMLPlugInElement.cpp b/WebCore/html/HTMLPlugInElement.cpp index 51db115..18b1c6a 100644 --- a/WebCore/html/HTMLPlugInElement.cpp +++ b/WebCore/html/HTMLPlugInElement.cpp @@ -23,13 +23,13 @@ #include "config.h" #include "HTMLPlugInElement.h" +#include "Attribute.h" #include "CSSPropertyNames.h" #include "Document.h" #include "Frame.h" #include "FrameLoader.h" #include "FrameTree.h" #include "HTMLNames.h" -#include "MappedAttribute.h" #include "Page.h" #include "RenderWidget.h" #include "ScriptController.h" @@ -126,7 +126,7 @@ bool HTMLPlugInElement::mapToEntry(const QualifiedName& attrName, MappedAttribut return HTMLFrameOwnerElement::mapToEntry(attrName, result); } -void HTMLPlugInElement::parseMappedAttribute(MappedAttribute* attr) +void HTMLPlugInElement::parseMappedAttribute(Attribute* attr) { if (attr->name() == widthAttr) addCSSLength(attr, CSSPropertyWidth, attr->value()); diff --git a/WebCore/html/HTMLPlugInElement.h b/WebCore/html/HTMLPlugInElement.h index cf18e27..e9cd9d0 100644 --- a/WebCore/html/HTMLPlugInElement.h +++ b/WebCore/html/HTMLPlugInElement.h @@ -58,7 +58,7 @@ protected: static void updateWidgetCallback(Node*); virtual bool mapToEntry(const QualifiedName& attrName, MappedAttributeEntry& result) const; - virtual void parseMappedAttribute(MappedAttribute*); + virtual void parseMappedAttribute(Attribute*); #if PLATFORM(ANDROID) // in Android, plugin has a focused mode where it accepts all the touch events. diff --git a/WebCore/html/HTMLPreElement.cpp b/WebCore/html/HTMLPreElement.cpp index 030660f..0108ff3 100644 --- a/WebCore/html/HTMLPreElement.cpp +++ b/WebCore/html/HTMLPreElement.cpp @@ -23,10 +23,10 @@ #include "config.h" #include "HTMLPreElement.h" +#include "Attribute.h" #include "CSSPropertyNames.h" #include "CSSValueKeywords.h" #include "HTMLNames.h" -#include "MappedAttribute.h" namespace WebCore { @@ -46,7 +46,7 @@ bool HTMLPreElement::mapToEntry(const QualifiedName& attrName, MappedAttributeEn return HTMLElement::mapToEntry(attrName, result); } -void HTMLPreElement::parseMappedAttribute(MappedAttribute *attr) +void HTMLPreElement::parseMappedAttribute(Attribute* attr) { if (attr->name() == widthAttr) { // FIXME: Implement this some day. Width on a <pre> is the # of characters that diff --git a/WebCore/html/HTMLPreElement.h b/WebCore/html/HTMLPreElement.h index e84f4b3..17b945e 100644 --- a/WebCore/html/HTMLPreElement.h +++ b/WebCore/html/HTMLPreElement.h @@ -34,7 +34,7 @@ public: virtual int tagPriority() const { return 5; } bool mapToEntry(const QualifiedName&, MappedAttributeEntry&) const; - void parseMappedAttribute(MappedAttribute*); + void parseMappedAttribute(Attribute*); int width() const; void setWidth(int w); diff --git a/WebCore/html/HTMLProgressElement.cpp b/WebCore/html/HTMLProgressElement.cpp index 84a9794..d275ebf 100644 --- a/WebCore/html/HTMLProgressElement.cpp +++ b/WebCore/html/HTMLProgressElement.cpp @@ -22,12 +22,12 @@ #if ENABLE(PROGRESS_TAG) #include "HTMLProgressElement.h" +#include "Attribute.h" #include "EventNames.h" #include "FormDataList.h" #include "HTMLFormElement.h" #include "HTMLNames.h" #include "HTMLParser.h" -#include "MappedAttribute.h" #include "RenderProgress.h" #include <wtf/StdLibExtras.h> @@ -57,7 +57,7 @@ const AtomicString& HTMLProgressElement::formControlType() const return progress; } -void HTMLProgressElement::parseMappedAttribute(MappedAttribute* attribute) +void HTMLProgressElement::parseMappedAttribute(Attribute* attribute) { if (attribute->name() == valueAttr) { if (renderer()) diff --git a/WebCore/html/HTMLProgressElement.h b/WebCore/html/HTMLProgressElement.h index eaf4ce9..7900063 100644 --- a/WebCore/html/HTMLProgressElement.h +++ b/WebCore/html/HTMLProgressElement.h @@ -41,13 +41,13 @@ public: private: HTMLProgressElement(const QualifiedName&, Document*, HTMLFormElement*); - virtual bool isOptionalFormControl() const { return true; } + virtual bool recalcWillValidate() const { return false; } virtual const AtomicString& formControlType() const; virtual RenderObject* createRenderer(RenderArena*, RenderStyle*); - virtual void parseMappedAttribute(MappedAttribute*); + virtual void parseMappedAttribute(Attribute*); }; } // namespace diff --git a/WebCore/html/HTMLScriptElement.cpp b/WebCore/html/HTMLScriptElement.cpp index 58c3b03..83af32e 100644 --- a/WebCore/html/HTMLScriptElement.cpp +++ b/WebCore/html/HTMLScriptElement.cpp @@ -23,11 +23,11 @@ #include "config.h" #include "HTMLScriptElement.h" +#include "Attribute.h" #include "Document.h" #include "Event.h" #include "EventNames.h" #include "HTMLNames.h" -#include "MappedAttribute.h" #include "ScriptEventListener.h" #include "Text.h" @@ -63,7 +63,7 @@ void HTMLScriptElement::childrenChanged(bool changedByParser, Node* beforeChange HTMLElement::childrenChanged(changedByParser, beforeChange, afterChange, childCountDelta); } -void HTMLScriptElement::parseMappedAttribute(MappedAttribute* attr) +void HTMLScriptElement::parseMappedAttribute(Attribute* attr) { const QualifiedName& attrName = attr->name(); diff --git a/WebCore/html/HTMLScriptElement.h b/WebCore/html/HTMLScriptElement.h index b6d683f..f5c3acb 100644 --- a/WebCore/html/HTMLScriptElement.h +++ b/WebCore/html/HTMLScriptElement.h @@ -42,7 +42,7 @@ public: virtual int tagPriority() const { return 1; } virtual bool checkDTD(const Node* newChild) { return newChild->isTextNode(); } - virtual void parseMappedAttribute(MappedAttribute*); + virtual void parseMappedAttribute(Attribute*); virtual void insertedIntoDocument(); virtual void removedFromDocument(); virtual void childrenChanged(bool changedByParser = false, Node* beforeChange = 0, Node* afterChange = 0, int childCountDelta = 0); diff --git a/WebCore/html/HTMLSelectElement.cpp b/WebCore/html/HTMLSelectElement.cpp index 12ec26f..c053a84 100644 --- a/WebCore/html/HTMLSelectElement.cpp +++ b/WebCore/html/HTMLSelectElement.cpp @@ -28,11 +28,11 @@ #include "HTMLSelectElement.h" #include "AXObjectCache.h" +#include "Attribute.h" #include "EventNames.h" #include "HTMLNames.h" #include "HTMLOptionElement.h" #include "HTMLOptionsCollection.h" -#include "MappedAttribute.h" #include "RenderListBox.h" #include "RenderMenuList.h" #include "ScriptEventListener.h" @@ -189,7 +189,7 @@ void HTMLSelectElement::restoreFormControlState(const String& state) SelectElement::restoreFormControlState(m_data, this, state); } -void HTMLSelectElement::parseMappedAttribute(MappedAttribute* attr) +void HTMLSelectElement::parseMappedAttribute(Attribute* attr) { bool oldUsesMenuList = m_data.usesMenuList(); if (attr->name() == sizeAttr) { diff --git a/WebCore/html/HTMLSelectElement.h b/WebCore/html/HTMLSelectElement.h index 8a31efc..c31e7f6 100644 --- a/WebCore/html/HTMLSelectElement.h +++ b/WebCore/html/HTMLSelectElement.h @@ -106,7 +106,7 @@ private: virtual bool saveFormControlState(String& value) const; virtual void restoreFormControlState(const String&); - virtual void parseMappedAttribute(MappedAttribute*); + virtual void parseMappedAttribute(Attribute*); virtual RenderObject* createRenderer(RenderArena*, RenderStyle *); virtual bool appendFormData(FormDataList&, bool); diff --git a/WebCore/html/HTMLStyleElement.cpp b/WebCore/html/HTMLStyleElement.cpp index 206aec4..1cdfed2 100644 --- a/WebCore/html/HTMLStyleElement.cpp +++ b/WebCore/html/HTMLStyleElement.cpp @@ -24,9 +24,9 @@ #include "config.h" #include "HTMLStyleElement.h" +#include "Attribute.h" #include "Document.h" #include "HTMLNames.h" -#include "MappedAttribute.h" namespace WebCore { @@ -41,7 +41,7 @@ HTMLStyleElement::HTMLStyleElement(const QualifiedName& tagName, Document* doc, } // other stuff... -void HTMLStyleElement::parseMappedAttribute(MappedAttribute *attr) +void HTMLStyleElement::parseMappedAttribute(Attribute* attr) { if (attr->name() == mediaAttr) m_media = attr->value().string().lower(); diff --git a/WebCore/html/HTMLStyleElement.h b/WebCore/html/HTMLStyleElement.h index 03b4c66..ba8ed3e 100644 --- a/WebCore/html/HTMLStyleElement.h +++ b/WebCore/html/HTMLStyleElement.h @@ -37,7 +37,7 @@ public: virtual bool checkDTD(const Node* newChild) { return newChild->isTextNode(); } // overload from HTMLElement - virtual void parseMappedAttribute(MappedAttribute*); + virtual void parseMappedAttribute(Attribute*); virtual void insertedIntoDocument(); virtual void removedFromDocument(); virtual void childrenChanged(bool changedByParser = false, Node* beforeChange = 0, Node* afterChange = 0, int childCountDelta = 0); diff --git a/WebCore/html/HTMLTableCaptionElement.cpp b/WebCore/html/HTMLTableCaptionElement.cpp index 2c94727..828a4e9 100644 --- a/WebCore/html/HTMLTableCaptionElement.cpp +++ b/WebCore/html/HTMLTableCaptionElement.cpp @@ -25,9 +25,9 @@ #include "config.h" #include "HTMLTableCaptionElement.h" +#include "Attribute.h" #include "CSSPropertyNames.h" #include "HTMLNames.h" -#include "MappedAttribute.h" namespace WebCore { @@ -49,7 +49,7 @@ bool HTMLTableCaptionElement::mapToEntry(const QualifiedName& attrName, MappedAt return HTMLElement::mapToEntry(attrName, result); } -void HTMLTableCaptionElement::parseMappedAttribute(MappedAttribute *attr) +void HTMLTableCaptionElement::parseMappedAttribute(Attribute* attr) { if (attr->name() == alignAttr) { if (!attr->value().isEmpty()) diff --git a/WebCore/html/HTMLTableCaptionElement.h b/WebCore/html/HTMLTableCaptionElement.h index 3c2aaa1..cf9d4d9 100644 --- a/WebCore/html/HTMLTableCaptionElement.h +++ b/WebCore/html/HTMLTableCaptionElement.h @@ -38,7 +38,7 @@ public: virtual int tagPriority() const { return 5; } virtual bool mapToEntry(const QualifiedName&, MappedAttributeEntry&) const; - virtual void parseMappedAttribute(MappedAttribute*); + virtual void parseMappedAttribute(Attribute*); String align() const; void setAlign(const String&); diff --git a/WebCore/html/HTMLTableCellElement.cpp b/WebCore/html/HTMLTableCellElement.cpp index 94bf82e..7d71ff4 100644 --- a/WebCore/html/HTMLTableCellElement.cpp +++ b/WebCore/html/HTMLTableCellElement.cpp @@ -25,11 +25,11 @@ #include "config.h" #include "HTMLTableCellElement.h" +#include "Attribute.h" #include "CSSPropertyNames.h" #include "CSSValueKeywords.h" #include "HTMLNames.h" #include "HTMLTableElement.h" -#include "MappedAttribute.h" #include "RenderTableCell.h" #ifdef ANDROID_LAYOUT #include "Document.h" @@ -89,7 +89,7 @@ bool HTMLTableCellElement::mapToEntry(const QualifiedName& attrName, MappedAttri return HTMLTablePartElement::mapToEntry(attrName, result); } -void HTMLTableCellElement::parseMappedAttribute(MappedAttribute *attr) +void HTMLTableCellElement::parseMappedAttribute(Attribute* attr) { if (attr->name() == rowspanAttr) { rSpan = !attr->isNull() ? attr->value().toInt() : 1; diff --git a/WebCore/html/HTMLTableCellElement.h b/WebCore/html/HTMLTableCellElement.h index 9cb7cf5..b598ce8 100644 --- a/WebCore/html/HTMLTableCellElement.h +++ b/WebCore/html/HTMLTableCellElement.h @@ -49,7 +49,7 @@ public: int rowSpan() const { return rSpan; } virtual bool mapToEntry(const QualifiedName&, MappedAttributeEntry&) const; - virtual void parseMappedAttribute(MappedAttribute*); + virtual void parseMappedAttribute(Attribute*); // used by table cells to share style decls created by the enclosing table. virtual bool canHaveAdditionalAttributeStyleDecls() const { return true; } diff --git a/WebCore/html/HTMLTableColElement.cpp b/WebCore/html/HTMLTableColElement.cpp index 27ff6f7..7a40be2 100644 --- a/WebCore/html/HTMLTableColElement.cpp +++ b/WebCore/html/HTMLTableColElement.cpp @@ -25,10 +25,10 @@ #include "config.h" #include "HTMLTableColElement.h" +#include "Attribute.h" #include "CSSPropertyNames.h" #include "HTMLNames.h" #include "HTMLTableElement.h" -#include "MappedAttribute.h" #include "RenderTableCol.h" #include "Text.h" @@ -72,7 +72,7 @@ bool HTMLTableColElement::mapToEntry(const QualifiedName& attrName, MappedAttrib return HTMLTablePartElement::mapToEntry(attrName, result); } -void HTMLTableColElement::parseMappedAttribute(MappedAttribute *attr) +void HTMLTableColElement::parseMappedAttribute(Attribute* attr) { if (attr->name() == spanAttr) { _span = !attr->isNull() ? attr->value().toInt() : 1; diff --git a/WebCore/html/HTMLTableColElement.h b/WebCore/html/HTMLTableColElement.h index af785f3..3710c11 100644 --- a/WebCore/html/HTMLTableColElement.h +++ b/WebCore/html/HTMLTableColElement.h @@ -42,7 +42,7 @@ public: // overrides virtual bool mapToEntry(const QualifiedName&, MappedAttributeEntry&) const; - virtual void parseMappedAttribute(MappedAttribute*); + virtual void parseMappedAttribute(Attribute*); virtual bool canHaveAdditionalAttributeStyleDecls() const { return true; } virtual void additionalAttributeStyleDecls(Vector<CSSMutableStyleDeclaration*>&); diff --git a/WebCore/html/HTMLTableElement.cpp b/WebCore/html/HTMLTableElement.cpp index af35740..338f505 100644 --- a/WebCore/html/HTMLTableElement.cpp +++ b/WebCore/html/HTMLTableElement.cpp @@ -25,6 +25,7 @@ #include "config.h" #include "HTMLTableElement.h" +#include "Attribute.h" #include "CSSPropertyNames.h" #include "CSSStyleSheet.h" #include "CSSValueKeywords.h" @@ -34,7 +35,6 @@ #include "HTMLTableRowElement.h" #include "HTMLTableRowsCollection.h" #include "HTMLTableSectionElement.h" -#include "MappedAttribute.h" #include "RenderTable.h" #include "Text.h" @@ -316,7 +316,7 @@ static bool setTableCellsChanged(Node* n) return cellChanged; } -void HTMLTableElement::parseMappedAttribute(MappedAttribute* attr) +void HTMLTableElement::parseMappedAttribute(Attribute* attr) { CellBorders bordersBefore = cellBorders(); unsigned short oldPadding = m_padding; diff --git a/WebCore/html/HTMLTableElement.h b/WebCore/html/HTMLTableElement.h index 3c6589a..7f1e747 100644 --- a/WebCore/html/HTMLTableElement.h +++ b/WebCore/html/HTMLTableElement.h @@ -92,7 +92,7 @@ public: virtual ContainerNode* addChild(PassRefPtr<Node>); virtual bool mapToEntry(const QualifiedName&, MappedAttributeEntry&) const; - virtual void parseMappedAttribute(MappedAttribute*); + virtual void parseMappedAttribute(Attribute*); virtual void attach(); virtual bool isURLAttribute(Attribute*) const; diff --git a/WebCore/html/HTMLTablePartElement.cpp b/WebCore/html/HTMLTablePartElement.cpp index f060dce..316ace4 100644 --- a/WebCore/html/HTMLTablePartElement.cpp +++ b/WebCore/html/HTMLTablePartElement.cpp @@ -25,12 +25,12 @@ #include "config.h" #include "HTMLTablePartElement.h" +#include "Attribute.h" #include "CSSHelper.h" #include "CSSPropertyNames.h" #include "CSSValueKeywords.h" #include "Document.h" #include "HTMLNames.h" -#include "MappedAttribute.h" namespace WebCore { @@ -59,7 +59,7 @@ bool HTMLTablePartElement::mapToEntry(const QualifiedName& attrName, MappedAttri return HTMLElement::mapToEntry(attrName, result); } -void HTMLTablePartElement::parseMappedAttribute(MappedAttribute *attr) +void HTMLTablePartElement::parseMappedAttribute(Attribute* attr) { if (attr->name() == bgcolorAttr) addCSSColor(attr, CSSPropertyBackgroundColor, attr->value()); diff --git a/WebCore/html/HTMLTablePartElement.h b/WebCore/html/HTMLTablePartElement.h index 1fd5218..cd8b590 100644 --- a/WebCore/html/HTMLTablePartElement.h +++ b/WebCore/html/HTMLTablePartElement.h @@ -37,7 +37,7 @@ public: { } virtual bool mapToEntry(const QualifiedName&, MappedAttributeEntry&) const; - virtual void parseMappedAttribute(MappedAttribute*); + virtual void parseMappedAttribute(Attribute*); }; } //namespace diff --git a/WebCore/html/HTMLTextAreaElement.cpp b/WebCore/html/HTMLTextAreaElement.cpp index cdb7cdb..bb88b1c 100644 --- a/WebCore/html/HTMLTextAreaElement.cpp +++ b/WebCore/html/HTMLTextAreaElement.cpp @@ -26,10 +26,11 @@ #include "config.h" #include "HTMLTextAreaElement.h" +#include "Attribute.h" #include "BeforeTextInsertedEvent.h" +#include "CSSValueKeywords.h" #include "Chrome.h" #include "ChromeClient.h" -#include "CSSValueKeywords.h" #include "Document.h" #include "Event.h" #include "EventNames.h" @@ -39,7 +40,6 @@ #include "Frame.h" #include "HTMLNames.h" #include "InputElement.h" -#include "MappedAttribute.h" #include "Page.h" #include "RenderStyle.h" #include "RenderTextControlMultiLine.h" @@ -108,7 +108,7 @@ void HTMLTextAreaElement::childrenChanged(bool changedByParser, Node* beforeChan HTMLElement::childrenChanged(changedByParser, beforeChange, afterChange, childCountDelta); } -void HTMLTextAreaElement::parseMappedAttribute(MappedAttribute* attr) +void HTMLTextAreaElement::parseMappedAttribute(Attribute* attr) { if (attr->name() == rowsAttr) { int rows = attr->value().toInt(); diff --git a/WebCore/html/HTMLTextAreaElement.h b/WebCore/html/HTMLTextAreaElement.h index f75f076..d38f613 100644 --- a/WebCore/html/HTMLTextAreaElement.h +++ b/WebCore/html/HTMLTextAreaElement.h @@ -56,7 +56,7 @@ public: virtual bool valueMissing() const { return isRequiredFormControl() && !disabled() && !readOnly() && value().isEmpty(); } virtual void childrenChanged(bool changedByParser = false, Node* beforeChange = 0, Node* afterChange = 0, int childCountDelta = 0); - virtual void parseMappedAttribute(MappedAttribute*); + virtual void parseMappedAttribute(Attribute*); virtual RenderObject* createRenderer(RenderArena*, RenderStyle*); virtual bool appendFormData(FormDataList&, bool); virtual void reset(); diff --git a/WebCore/html/HTMLTokenizer.cpp b/WebCore/html/HTMLTokenizer.cpp index 390d332..620913f 100644 --- a/WebCore/html/HTMLTokenizer.cpp +++ b/WebCore/html/HTMLTokenizer.cpp @@ -28,6 +28,7 @@ #include "config.h" #include "HTMLTokenizer.h" +#include "Attribute.h" #include "CSSHelper.h" #include "Cache.h" #include "CachedScript.h" @@ -45,7 +46,6 @@ #include "HTMLViewSourceDocument.h" #include "ImageLoader.h" #include "InspectorTimelineAgent.h" -#include "MappedAttribute.h" #include "Page.h" #include "PreloadScanner.h" #include "ScriptController.h" @@ -139,9 +139,9 @@ inline void Token::addAttribute(AtomicString& attrName, const AtomicString& attr { if (!attrName.isEmpty()) { ASSERT(!attrName.contains('/')); - RefPtr<MappedAttribute> a = MappedAttribute::create(attrName, attributeValue); + RefPtr<Attribute> a = Attribute::createMapped(attrName, attributeValue); if (!attrs) { - attrs = NamedMappedAttrMap::create(); + attrs = NamedNodeMap::create(); attrs->reserveInitialCapacity(10); } attrs->insertAttribute(a.release(), viewSourceMode); @@ -1632,7 +1632,143 @@ inline bool HTMLTokenizer::continueProcessing(int& processedCount, double startT processedCount++; return true; } - + +// Turns the statemachine one crank using the passed in State object. +// FIXME: Eventually this should modify m_state directly. +ALWAYS_INLINE void HTMLTokenizer::advance(State& state) +{ + // do we need to enlarge the buffer? + checkBuffer(); + + UChar cc = *m_src; + + bool wasSkipLF = state.skipLF(); + if (wasSkipLF) + state.setSkipLF(false); + + if (wasSkipLF && (cc == '\n')) + m_src.advance(); + else if (state.needsSpecialWriteHandling()) { + // it's important to keep needsSpecialWriteHandling with the flags this block tests + if (state.hasEntityState()) + state = parseEntity(m_src, m_dest, state, m_cBufferPos, false, state.hasTagState()); + else if (state.inPlainText()) + state = parseText(m_src, state); + else if (state.inAnyNonHTMLText()) + state = parseNonHTMLText(m_src, state); + else if (state.inComment()) + state = parseComment(m_src, state); + else if (state.inDoctype()) + state = parseDoctype(m_src, state); + else if (state.inServer()) + state = parseServer(m_src, state); + else if (state.inProcessingInstruction()) + state = parseProcessingInstruction(m_src, state); + else if (state.hasTagState()) + state = parseTag(m_src, state); + else if (state.startTag()) { + state.setStartTag(false); + + switch (cc) { + case '/': + break; + case '!': { + // <!-- comment --> or <!DOCTYPE ...> + searchCount = 1; // Look for '<!--' sequence to start comment or '<!DOCTYPE' sequence to start doctype + m_doctypeSearchCount = 1; + break; + } + case '?': { + // xml processing instruction + state.setInProcessingInstruction(true); + tquote = NoQuote; + state = parseProcessingInstruction(m_src, state); + return; + } + case '%': + if (!m_brokenServer) { + // <% server stuff, handle as comment %> + state.setInServer(true); + tquote = NoQuote; + state = parseServer(m_src, state); + return; + } + // else fall through + default: { + if (((cc >= 'a') && (cc <= 'z')) || ((cc >= 'A') && (cc <= 'Z'))) { + // Start of a Start-Tag + } else { + // Invalid tag + // Add as is + *m_dest = '<'; + m_dest++; + return; + } + } + }; // end case + + processToken(); + + m_cBufferPos = 0; + state.setTagState(TagName); + state = parseTag(m_src, state); + } + } else if (cc == '&' && !m_src.escaped()) { + m_src.advancePastNonNewline(); + state = parseEntity(m_src, m_dest, state, m_cBufferPos, true, state.hasTagState()); + } else if (cc == '<' && !m_src.escaped()) { + m_currentTagStartLineNumber = m_lineNumber; + m_src.advancePastNonNewline(); + state.setStartTag(true); + state.setDiscardLF(false); + } else if (cc == '\n' || cc == '\r') { + if (state.discardLF()) + // Ignore this LF + state.setDiscardLF(false); // We have discarded 1 LF + else { + // Process this LF + *m_dest++ = '\n'; + if (cc == '\r' && !m_src.excludeLineNumbers()) + m_lineNumber++; + } + + /* Check for MS-DOS CRLF sequence */ + if (cc == '\r') + state.setSkipLF(true); + m_src.advance(m_lineNumber); + } else { + state.setDiscardLF(false); + *m_dest++ = cc; + m_src.advancePastNonNewline(); + } +} + +void HTMLTokenizer::willWriteHTML(const SegmentedString& source) +{ + #ifdef INSTRUMENT_LAYOUT_SCHEDULING + if (!m_doc->ownerElement()) + printf("Beginning write at time %d\n", m_doc->elapsedTime()); + #endif + + #if ENABLE(INSPECTOR) + if (InspectorTimelineAgent* timelineAgent = m_doc->inspectorTimelineAgent()) + timelineAgent->willWriteHTML(source.length(), m_lineNumber); + #endif +} + +void HTMLTokenizer::didWriteHTML() +{ + #ifdef INSTRUMENT_LAYOUT_SCHEDULING + if (!m_doc->ownerElement()) + printf("Ending write at time %d\n", m_doc->elapsedTime()); + #endif + + #if ENABLE(INSPECTOR) + if (InspectorTimelineAgent* timelineAgent = m_doc->inspectorTimelineAgent()) + timelineAgent->didWriteHTML(m_lineNumber); + #endif +} + void HTMLTokenizer::write(const SegmentedString& str, bool appendData) { if (!m_buffer) @@ -1675,151 +1811,31 @@ void HTMLTokenizer::write(const SegmentedString& str, bool appendData) bool wasInWrite = m_inWrite; m_inWrite = true; - -#ifdef INSTRUMENT_LAYOUT_SCHEDULING - if (!m_doc->ownerElement()) - printf("Beginning write at time %d\n", m_doc->elapsedTime()); -#endif +<<<<<<< HEAD int processedCount = 0; double startTime = currentTime(); #ifdef ANDROID_INSTRUMENT android::TimeCounter::start(android::TimeCounter::ParsingTimeCounter); #endif +======= + willWriteHTML(source); +>>>>>>> webkit.org at r60074 -#if ENABLE(INSPECTOR) - if (InspectorTimelineAgent* timelineAgent = m_doc->inspectorTimelineAgent()) - timelineAgent->willWriteHTML(source.length(), m_lineNumber); -#endif - Frame* frame = m_doc->frame(); - State state = m_state; + int processedCount = 0; + double startTime = currentTime(); while (!m_src.isEmpty() && (!frame || !frame->redirectScheduler()->locationChangePending())) { if (!continueProcessing(processedCount, startTime, state)) break; - - // do we need to enlarge the buffer? - checkBuffer(); - - UChar cc = *m_src; - - bool wasSkipLF = state.skipLF(); - if (wasSkipLF) - state.setSkipLF(false); - - if (wasSkipLF && (cc == '\n')) - m_src.advance(); - else if (state.needsSpecialWriteHandling()) { - // it's important to keep needsSpecialWriteHandling with the flags this block tests - if (state.hasEntityState()) - state = parseEntity(m_src, m_dest, state, m_cBufferPos, false, state.hasTagState()); - else if (state.inPlainText()) - state = parseText(m_src, state); - else if (state.inAnyNonHTMLText()) - state = parseNonHTMLText(m_src, state); - else if (state.inComment()) - state = parseComment(m_src, state); - else if (state.inDoctype()) - state = parseDoctype(m_src, state); - else if (state.inServer()) - state = parseServer(m_src, state); - else if (state.inProcessingInstruction()) - state = parseProcessingInstruction(m_src, state); - else if (state.hasTagState()) - state = parseTag(m_src, state); - else if (state.startTag()) { - state.setStartTag(false); - - switch (cc) { - case '/': - break; - case '!': { - // <!-- comment --> or <!DOCTYPE ...> - searchCount = 1; // Look for '<!--' sequence to start comment or '<!DOCTYPE' sequence to start doctype - m_doctypeSearchCount = 1; - break; - } - case '?': { - // xml processing instruction - state.setInProcessingInstruction(true); - tquote = NoQuote; - state = parseProcessingInstruction(m_src, state); - continue; - - break; - } - case '%': - if (!m_brokenServer) { - // <% server stuff, handle as comment %> - state.setInServer(true); - tquote = NoQuote; - state = parseServer(m_src, state); - continue; - } - // else fall through - default: { - if ( ((cc >= 'a') && (cc <= 'z')) || ((cc >= 'A') && (cc <= 'Z'))) { - // Start of a Start-Tag - } else { - // Invalid tag - // Add as is - *m_dest = '<'; - m_dest++; - continue; - } - } - }; // end case - - processToken(); - - m_cBufferPos = 0; - state.setTagState(TagName); - state = parseTag(m_src, state); - } - } else if (cc == '&' && !m_src.escaped()) { - m_src.advancePastNonNewline(); - state = parseEntity(m_src, m_dest, state, m_cBufferPos, true, state.hasTagState()); - } else if (cc == '<' && !m_src.escaped()) { - m_currentTagStartLineNumber = m_lineNumber; - m_src.advancePastNonNewline(); - state.setStartTag(true); - state.setDiscardLF(false); - } else if (cc == '\n' || cc == '\r') { - if (state.discardLF()) - // Ignore this LF - state.setDiscardLF(false); // We have discarded 1 LF - else { - // Process this LF - *m_dest++ = '\n'; - if (cc == '\r' && !m_src.excludeLineNumbers()) - m_lineNumber++; - } - - /* Check for MS-DOS CRLF sequence */ - if (cc == '\r') - state.setSkipLF(true); - m_src.advance(m_lineNumber); - } else { - state.setDiscardLF(false); - *m_dest++ = cc; - m_src.advancePastNonNewline(); - } + advance(state); } - -#ifdef INSTRUMENT_LAYOUT_SCHEDULING - if (!m_doc->ownerElement()) - printf("Ending write at time %d\n", m_doc->elapsedTime()); -#endif -#if ENABLE(INSPECTOR) - if (InspectorTimelineAgent* timelineAgent = m_doc->inspectorTimelineAgent()) - timelineAgent->didWriteHTML(m_lineNumber); -#endif + didWriteHTML(); m_inWrite = wasInWrite; - m_state = state; #ifdef ANDROID_INSTRUMENT @@ -1951,7 +1967,7 @@ PassRefPtr<Node> HTMLTokenizer::processToken() RefPtr<Node> n; if (!m_parserStopped) { - if (NamedMappedAttrMap* map = m_currentToken.attrs.get()) + if (NamedNodeMap* map = m_currentToken.attrs.get()) map->shrinkToLength(); if (inViewSourceMode()) static_cast<HTMLViewSourceDocument*>(m_doc)->addViewSourceToken(&m_currentToken); diff --git a/WebCore/html/HTMLTokenizer.h b/WebCore/html/HTMLTokenizer.h index 290fc5c..dc03cf2 100644 --- a/WebCore/html/HTMLTokenizer.h +++ b/WebCore/html/HTMLTokenizer.h @@ -26,8 +26,8 @@ #include "CachedResourceClient.h" #include "CachedResourceHandle.h" -#include "NamedMappedAttrMap.h" #include "MappedAttributeEntry.h" +#include "NamedNodeMap.h" #include "SegmentedString.h" #include "Timer.h" #include "Tokenizer.h" @@ -83,7 +83,7 @@ struct Token { void addViewSourceChar(UChar c) { if (!m_sourceInfo.get()) m_sourceInfo.set(new Vector<UChar>); m_sourceInfo->append(c); } - RefPtr<NamedMappedAttrMap> attrs; + RefPtr<NamedNodeMap> attrs; RefPtr<StringImpl> text; AtomicString tagName; bool beginTag; @@ -132,6 +132,11 @@ public: //----------------------------------------------------------------------------- +// FIXME: This class does too much. Right now it is both an HTML lexer as well +// as handling all of the non-lexer-specific junk related to tokenizing HTML +// (like dealing with <script> tags). The HTML lexer bits should be pushed +// down into a separate HTML lexer class. + class HTMLTokenizer : public Tokenizer, public CachedResourceClient { public: HTMLTokenizer(HTMLDocument*, bool reportErrors); @@ -168,6 +173,10 @@ private: void reset(); + void willWriteHTML(const SegmentedString&); + ALWAYS_INLINE void advance(State&); + void didWriteHTML(); + PassRefPtr<Node> processToken(); void processDoctypeToken(); diff --git a/WebCore/html/HTMLUListElement.cpp b/WebCore/html/HTMLUListElement.cpp index f36cb57..d4ae714 100644 --- a/WebCore/html/HTMLUListElement.cpp +++ b/WebCore/html/HTMLUListElement.cpp @@ -22,9 +22,9 @@ #include "config.h" #include "HTMLUListElement.h" +#include "Attribute.h" #include "CSSPropertyNames.h" #include "HTMLNames.h" -#include "MappedAttribute.h" namespace WebCore { @@ -46,7 +46,7 @@ bool HTMLUListElement::mapToEntry(const QualifiedName& attrName, MappedAttribute return HTMLElement::mapToEntry(attrName, result); } -void HTMLUListElement::parseMappedAttribute(MappedAttribute *attr) +void HTMLUListElement::parseMappedAttribute(Attribute* attr) { if (attr->name() == typeAttr) addCSSProperty(attr, CSSPropertyListStyleType, attr->value()); diff --git a/WebCore/html/HTMLUListElement.h b/WebCore/html/HTMLUListElement.h index 1eda5f3..ee161d0 100644 --- a/WebCore/html/HTMLUListElement.h +++ b/WebCore/html/HTMLUListElement.h @@ -34,7 +34,7 @@ public: virtual int tagPriority() const { return 5; } virtual bool mapToEntry(const QualifiedName&, MappedAttributeEntry&) const; - virtual void parseMappedAttribute(MappedAttribute*); + virtual void parseMappedAttribute(Attribute*); bool compact() const; void setCompact(bool); diff --git a/WebCore/html/HTMLVideoElement.cpp b/WebCore/html/HTMLVideoElement.cpp index 3db48f1..dd37b69 100644 --- a/WebCore/html/HTMLVideoElement.cpp +++ b/WebCore/html/HTMLVideoElement.cpp @@ -28,15 +28,15 @@ #if ENABLE(VIDEO) #include "HTMLVideoElement.h" -#include "Chrome.h" -#include "ChromeClient.h" +#include "Attribute.h" #include "CSSHelper.h" #include "CSSPropertyNames.h" +#include "Chrome.h" +#include "ChromeClient.h" #include "Document.h" #include "ExceptionCode.h" #include "HTMLImageLoader.h" #include "HTMLNames.h" -#include "MappedAttribute.h" #include "Page.h" #include "RenderImage.h" #include "RenderVideo.h" @@ -91,7 +91,7 @@ void HTMLVideoElement::detach() m_imageLoader.clear(); } -void HTMLVideoElement::parseMappedAttribute(MappedAttribute* attr) +void HTMLVideoElement::parseMappedAttribute(Attribute* attr) { const QualifiedName& attrName = attr->name(); diff --git a/WebCore/html/HTMLVideoElement.h b/WebCore/html/HTMLVideoElement.h index 4dad3db..5480448 100644 --- a/WebCore/html/HTMLVideoElement.h +++ b/WebCore/html/HTMLVideoElement.h @@ -73,7 +73,7 @@ private: #endif virtual void attach(); virtual void detach(); - virtual void parseMappedAttribute(MappedAttribute*); + virtual void parseMappedAttribute(Attribute*); virtual bool isVideo() const { return true; } virtual bool hasVideo() const { return player() && player()->hasVideo(); } virtual bool supportsFullscreen() const; diff --git a/WebCore/html/HTMLViewSourceDocument.cpp b/WebCore/html/HTMLViewSourceDocument.cpp index 2d800b4..0173715 100644 --- a/WebCore/html/HTMLViewSourceDocument.cpp +++ b/WebCore/html/HTMLViewSourceDocument.cpp @@ -25,6 +25,7 @@ #include "config.h" #include "HTMLViewSourceDocument.h" +#include "Attribute.h" #include "DOMImplementation.h" #include "HTMLAnchorElement.h" #include "HTMLBodyElement.h" @@ -36,7 +37,6 @@ #include "HTMLTableRowElement.h" #include "HTMLTableSectionElement.h" #include "HTMLTokenizer.h" -#include "MappedAttribute.h" #include "Text.h" #include "TextDocument.h" @@ -59,6 +59,7 @@ Tokenizer* HTMLViewSourceDocument::createTokenizer() || m_type == "application/vnd.wap.xhtml+xml" #endif ) { + // FIXME: Should respect Settings::html5ParserEnabled() return new HTMLTokenizer(this); } @@ -77,8 +78,8 @@ void HTMLViewSourceDocument::createContainingTable() // Create a line gutter div that can be used to make sure the gutter extends down the height of the whole // document. RefPtr<HTMLDivElement> div = new HTMLDivElement(divTag, this); - RefPtr<NamedMappedAttrMap> attrs = NamedMappedAttrMap::create(); - attrs->addAttribute(MappedAttribute::create(classAttr, "webkit-line-gutter-backdrop")); + RefPtr<NamedNodeMap> attrs = NamedNodeMap::create(); + attrs->addAttribute(Attribute::createMapped(classAttr, "webkit-line-gutter-backdrop")); div->setAttributeMap(attrs.release()); body->addChild(div); div->attach(); @@ -210,8 +211,8 @@ PassRefPtr<Element> HTMLViewSourceDocument::addSpanWithClassName(const String& c } RefPtr<HTMLElement> span = HTMLElement::create(spanTag, this); - RefPtr<NamedMappedAttrMap> attrs = NamedMappedAttrMap::create(); - attrs->addAttribute(MappedAttribute::create(classAttr, className)); + RefPtr<NamedNodeMap> attrs = NamedNodeMap::create(); + attrs->addAttribute(Attribute::createMapped(classAttr, className)); span->setAttributeMap(attrs.release()); m_current->addChild(span); span->attach(); @@ -227,16 +228,16 @@ void HTMLViewSourceDocument::addLine(const String& className) // Create a cell that will hold the line number (it is generated in the stylesheet using counters). RefPtr<HTMLTableCellElement> td = new HTMLTableCellElement(tdTag, this); - RefPtr<NamedMappedAttrMap> attrs = NamedMappedAttrMap::create(); - attrs->addAttribute(MappedAttribute::create(classAttr, "webkit-line-number")); + RefPtr<NamedNodeMap> attrs = NamedNodeMap::create(); + attrs->addAttribute(Attribute::createMapped(classAttr, "webkit-line-number")); td->setAttributeMap(attrs.release()); trow->addChild(td); td->attach(); // Create a second cell for the line contents td = new HTMLTableCellElement(tdTag, this); - attrs = NamedMappedAttrMap::create(); - attrs->addAttribute(MappedAttribute::create(classAttr, "webkit-line-content")); + attrs = NamedNodeMap::create(); + attrs->addAttribute(Attribute::createMapped(classAttr, "webkit-line-content")); td->setAttributeMap(attrs.release()); trow->addChild(td); td->attach(); @@ -293,15 +294,15 @@ PassRefPtr<Element> HTMLViewSourceDocument::addLink(const String& url, bool isAn // Now create a link for the attribute value instead of a span. RefPtr<HTMLAnchorElement> anchor = HTMLAnchorElement::create(this); - RefPtr<NamedMappedAttrMap> attrs = NamedMappedAttrMap::create(); + RefPtr<NamedNodeMap> attrs = NamedNodeMap::create(); const char* classValue; if (isAnchor) classValue = "webkit-html-attribute-value webkit-html-external-link"; else classValue = "webkit-html-attribute-value webkit-html-resource-link"; - attrs->addAttribute(MappedAttribute::create(classAttr, classValue)); - attrs->addAttribute(MappedAttribute::create(targetAttr, "_blank")); - attrs->addAttribute(MappedAttribute::create(hrefAttr, url)); + attrs->addAttribute(Attribute::createMapped(classAttr, classValue)); + attrs->addAttribute(Attribute::createMapped(targetAttr, "_blank")); + attrs->addAttribute(Attribute::createMapped(hrefAttr, url)); anchor->setAttributeMap(attrs.release()); m_current->addChild(anchor); anchor->attach(); diff --git a/WebCore/html/canvas/CanvasRenderingContext2D.cpp b/WebCore/html/canvas/CanvasRenderingContext2D.cpp index 7cdf5d6..184cc14 100644 --- a/WebCore/html/canvas/CanvasRenderingContext2D.cpp +++ b/WebCore/html/canvas/CanvasRenderingContext2D.cpp @@ -1,6 +1,6 @@ /* * Copyright (C) 2004, 2005, 2006, 2007, 2008, 2009 Apple Inc. All rights reserved. - * Copyright (C) 2008 Nokia Corporation and/or its subsidiary(-ies) + * Copyright (C) 2008, 2010 Nokia Corporation and/or its subsidiary(-ies) * Copyright (C) 2007 Alp Toker <alp@atoker.com> * Copyright (C) 2008 Eric Seidel <eric@webkit.org> * Copyright (C) 2008 Dirk Schulze <krit@webkit.org> @@ -118,14 +118,14 @@ void CanvasRenderingContext2D::reset() } CanvasRenderingContext2D::State::State() - : m_strokeStyle(CanvasStyle::create("#000000")) - , m_fillStyle(CanvasStyle::create("#000000")) + : m_strokeStyle(CanvasStyle::create(Color::black)) + , m_fillStyle(CanvasStyle::create(Color::black)) , m_lineWidth(1) , m_lineCap(ButtCap) , m_lineJoin(MiterJoin) , m_miterLimit(10) , m_shadowBlur(0) - , m_shadowColor("black") + , m_shadowColor(Color::transparent) , m_globalAlpha(1) , m_globalComposite(CompositeSourceOver) , m_invertibleCTM(true) @@ -315,13 +315,14 @@ void CanvasRenderingContext2D::setShadowBlur(float blur) String CanvasRenderingContext2D::shadowColor() const { - // FIXME: What should this return if you called setShadow with a non-string color? - return state().m_shadowColor; + return Color(state().m_shadowColor).serialized(); } void CanvasRenderingContext2D::setShadowColor(const String& color) { - state().m_shadowColor = color; + if (!CSSParser::parseColor(state().m_shadowColor, color)) + return; + applyShadow(); } @@ -814,15 +815,17 @@ void CanvasRenderingContext2D::setShadow(float width, float height, float blur) { state().m_shadowOffset = FloatSize(width, height); state().m_shadowBlur = blur; - state().m_shadowColor = ""; + state().m_shadowColor = Color::transparent; applyShadow(); } void CanvasRenderingContext2D::setShadow(float width, float height, float blur, const String& color) { + if (!CSSParser::parseColor(state().m_shadowColor, color)) + return; + state().m_shadowOffset = FloatSize(width, height); state().m_shadowBlur = blur; - state().m_shadowColor = color; applyShadow(); } @@ -830,65 +833,64 @@ void CanvasRenderingContext2D::setShadow(float width, float height, float blur, { state().m_shadowOffset = FloatSize(width, height); state().m_shadowBlur = blur; - state().m_shadowColor = ""; + state().m_shadowColor = makeRGBA32FromFloats(grayLevel, grayLevel, grayLevel, 1.0f); GraphicsContext* c = drawingContext(); if (!c) return; - RGBA32 rgba = makeRGBA32FromFloats(grayLevel, grayLevel, grayLevel, 1.0f); - c->setShadow(IntSize(width, -height), state().m_shadowBlur, Color(rgba), DeviceColorSpace); + c->setShadow(IntSize(width, -height), state().m_shadowBlur, state().m_shadowColor, DeviceColorSpace); } void CanvasRenderingContext2D::setShadow(float width, float height, float blur, const String& color, float alpha) { + RGBA32 rgba; + + if (!CSSParser::parseColor(rgba, color)) + return; + + state().m_shadowColor = colorWithOverrideAlpha(rgba, alpha); state().m_shadowOffset = FloatSize(width, height); state().m_shadowBlur = blur; - state().m_shadowColor = color; GraphicsContext* c = drawingContext(); if (!c) return; - RGBA32 rgba = 0; // default is transparent black - if (!state().m_shadowColor.isEmpty()) - CSSParser::parseColor(rgba, state().m_shadowColor); - c->setShadow(IntSize(width, -height), state().m_shadowBlur, Color(colorWithOverrideAlpha(rgba, alpha)), DeviceColorSpace); + c->setShadow(IntSize(width, -height), state().m_shadowBlur, state().m_shadowColor, DeviceColorSpace); } void CanvasRenderingContext2D::setShadow(float width, float height, float blur, float grayLevel, float alpha) { state().m_shadowOffset = FloatSize(width, height); state().m_shadowBlur = blur; - state().m_shadowColor = ""; + state().m_shadowColor = makeRGBA32FromFloats(grayLevel, grayLevel, grayLevel, alpha); GraphicsContext* c = drawingContext(); if (!c) return; - RGBA32 rgba = makeRGBA32FromFloats(grayLevel, grayLevel, grayLevel, alpha); - c->setShadow(IntSize(width, -height), state().m_shadowBlur, Color(rgba), DeviceColorSpace); + c->setShadow(IntSize(width, -height), state().m_shadowBlur, state().m_shadowColor, DeviceColorSpace); } void CanvasRenderingContext2D::setShadow(float width, float height, float blur, float r, float g, float b, float a) { state().m_shadowOffset = FloatSize(width, height); state().m_shadowBlur = blur; - state().m_shadowColor = ""; + state().m_shadowColor = makeRGBA32FromFloats(r, g, b, a); GraphicsContext* c = drawingContext(); if (!c) return; - RGBA32 rgba = makeRGBA32FromFloats(r, g, b, a); // default is transparent black - c->setShadow(IntSize(width, -height), state().m_shadowBlur, Color(rgba), DeviceColorSpace); + c->setShadow(IntSize(width, -height), state().m_shadowBlur, state().m_shadowColor, DeviceColorSpace); } void CanvasRenderingContext2D::setShadow(float width, float height, float blur, float c, float m, float y, float k, float a) { state().m_shadowOffset = FloatSize(width, height); state().m_shadowBlur = blur; - state().m_shadowColor = ""; + state().m_shadowColor = makeRGBAFromCMYKA(c, m, y, k, a); GraphicsContext* dc = drawingContext(); if (!dc) @@ -901,7 +903,7 @@ void CanvasRenderingContext2D::setShadow(float width, float height, float blur, CGContextSetShadowWithColor(dc->platformContext(), adjustedShadowSize(width, -height), blur, shadowColor); CGColorRelease(shadowColor); #else - dc->setShadow(IntSize(width, -height), blur, Color(c, m, y, k, a), DeviceColorSpace); + dc->setShadow(IntSize(width, -height), blur, state().m_shadowColor, DeviceColorSpace); #endif } @@ -909,7 +911,7 @@ void CanvasRenderingContext2D::clearShadow() { state().m_shadowOffset = FloatSize(); state().m_shadowBlur = 0; - state().m_shadowColor = ""; + state().m_shadowColor = Color::transparent; applyShadow(); } @@ -919,12 +921,9 @@ void CanvasRenderingContext2D::applyShadow() if (!c) return; - RGBA32 rgba = 0; // default is transparent black - if (!state().m_shadowColor.isEmpty()) - CSSParser::parseColor(rgba, state().m_shadowColor); float width = state().m_shadowOffset.width(); float height = state().m_shadowOffset.height(); - c->setShadow(IntSize(width, -height), state().m_shadowBlur, Color(rgba), DeviceColorSpace); + c->setShadow(IntSize(width, -height), state().m_shadowBlur, state().m_shadowColor, DeviceColorSpace); } static IntSize size(HTMLImageElement* image) diff --git a/WebCore/html/canvas/CanvasRenderingContext2D.h b/WebCore/html/canvas/CanvasRenderingContext2D.h index a49ff81..d6b0c8a 100644 --- a/WebCore/html/canvas/CanvasRenderingContext2D.h +++ b/WebCore/html/canvas/CanvasRenderingContext2D.h @@ -28,6 +28,7 @@ #include "AffineTransform.h" #include "CanvasRenderingContext.h" +#include "Color.h" #include "FloatSize.h" #include "Font.h" #include "GraphicsTypes.h" @@ -219,7 +220,7 @@ namespace WebCore { float m_miterLimit; FloatSize m_shadowOffset; float m_shadowBlur; - String m_shadowColor; + RGBA32 m_shadowColor; float m_globalAlpha; CompositeOperator m_globalComposite; AffineTransform m_transform; diff --git a/WebCore/html/canvas/CanvasStyle.cpp b/WebCore/html/canvas/CanvasStyle.cpp index 3515e03..67e8201 100644 --- a/WebCore/html/canvas/CanvasStyle.cpp +++ b/WebCore/html/canvas/CanvasStyle.cpp @@ -1,6 +1,6 @@ /* * Copyright (C) 2006, 2008 Apple Inc. All rights reserved. - * Copyright (C) 2008 Nokia Corporation and/or its subsidiary(-ies) + * Copyright (C) 2008, 2010 Nokia Corporation and/or its subsidiary(-ies) * Copyright (C) 2007 Alp Toker <alp@atoker.com> * Copyright (C) 2008 Eric Seidel <eric@webkit.org> * @@ -48,122 +48,108 @@ namespace WebCore { -CanvasStyle::CanvasStyle(const String& color) - : m_type(ColorString) - , m_color(color) +CanvasStyle::CanvasStyle(RGBA32 rgba) + : m_type(RGBA) + , m_rgba(rgba) { } CanvasStyle::CanvasStyle(float grayLevel) - : m_type(GrayLevel) - , m_alpha(1) - , m_grayLevel(grayLevel) -{ -} - -CanvasStyle::CanvasStyle(const String& color, float alpha) - : m_type(ColorStringWithAlpha) - , m_color(color) - , m_alpha(alpha) + : m_type(RGBA) + , m_rgba(makeRGBA32FromFloats(grayLevel, grayLevel, grayLevel, 1.0f)) { } CanvasStyle::CanvasStyle(float grayLevel, float alpha) - : m_type(GrayLevel) - , m_alpha(alpha) - , m_grayLevel(grayLevel) + : m_type(RGBA) + , m_rgba(makeRGBA32FromFloats(grayLevel, grayLevel, grayLevel, alpha)) { } CanvasStyle::CanvasStyle(float r, float g, float b, float a) : m_type(RGBA) - , m_alpha(a) - , m_red(r) - , m_green(g) - , m_blue(b) + , m_rgba(makeRGBA32FromFloats(r, g, b, a)) { } CanvasStyle::CanvasStyle(float c, float m, float y, float k, float a) : m_type(CMYKA) - , m_alpha(a) - , m_cyan(c) - , m_magenta(m) - , m_yellow(y) - , m_black(k) + , m_rgba(makeRGBAFromCMYKA(c, m, y, k, a)) + , m_cmyka(c, m, y, k, a) { } CanvasStyle::CanvasStyle(PassRefPtr<CanvasGradient> gradient) - : m_type(gradient ? Gradient : ColorString) + : m_type(Gradient) , m_gradient(gradient) { } CanvasStyle::CanvasStyle(PassRefPtr<CanvasPattern> pattern) - : m_type(pattern ? ImagePattern : ColorString) + : m_type(ImagePattern) , m_pattern(pattern) { } +PassRefPtr<CanvasStyle> CanvasStyle::create(const String& color) +{ + RGBA32 rgba; + if (!CSSParser::parseColor(rgba, color)) + return 0; + return adoptRef(new CanvasStyle(rgba)); +} + +PassRefPtr<CanvasStyle> CanvasStyle::create(const String& color, float alpha) +{ + RGBA32 rgba; + if (!CSSParser::parseColor(rgba, color)) + return 0; + return adoptRef(new CanvasStyle(colorWithOverrideAlpha(rgba, alpha))); +} + +PassRefPtr<CanvasStyle> CanvasStyle::create(PassRefPtr<CanvasGradient> gradient) +{ + if (!gradient) + return 0; + return adoptRef(new CanvasStyle(gradient)); +} +PassRefPtr<CanvasStyle> CanvasStyle::create(PassRefPtr<CanvasPattern> pattern) +{ + if (!pattern) + return 0; + return adoptRef(new CanvasStyle(pattern)); +} + void CanvasStyle::applyStrokeColor(GraphicsContext* context) { if (!context) return; switch (m_type) { - case ColorString: { - Color c = Color(m_color); - if (c.isValid()) { - context->setStrokeColor(c.rgb(), DeviceColorSpace); - break; - } - RGBA32 color = 0; // default is transparent black - if (CSSParser::parseColor(color, m_color)) - context->setStrokeColor(color, DeviceColorSpace); - break; - } - case ColorStringWithAlpha: { - Color c = Color(m_color); - if (c.isValid()) { - context->setStrokeColor(colorWithOverrideAlpha(c.rgb(), m_alpha), DeviceColorSpace); - break; - } - RGBA32 color = 0; // default is transparent black - if (CSSParser::parseColor(color, m_color)) - context->setStrokeColor(colorWithOverrideAlpha(color, m_alpha), DeviceColorSpace); - break; - } - case GrayLevel: - // We're only supporting 255 levels of gray here. Since this isn't - // even part of HTML5, I don't expect anyone will care. If they do - // we'll make a fancier Color abstraction. - context->setStrokeColor(Color(m_grayLevel, m_grayLevel, m_grayLevel, m_alpha), DeviceColorSpace); - break; - case RGBA: - context->setStrokeColor(Color(m_red, m_green, m_blue, m_alpha), DeviceColorSpace); - break; - case CMYKA: { - // FIXME: Do this through platform-independent GraphicsContext API. - // We'll need a fancier Color abstraction to support CYMKA correctly + case RGBA: + context->setStrokeColor(m_rgba, DeviceColorSpace); + break; + case CMYKA: { + // FIXME: Do this through platform-independent GraphicsContext API. + // We'll need a fancier Color abstraction to support CMYKA correctly #if PLATFORM(CG) - CGContextSetCMYKStrokeColor(context->platformContext(), m_cyan, m_magenta, m_yellow, m_black, m_alpha); + CGContextSetCMYKStrokeColor(context->platformContext(), m_cmyka.c, m_cmyka.m, m_cmyka.y, m_cmyka.k, m_cmyka.a); #elif PLATFORM(QT) - QPen currentPen = context->platformContext()->pen(); - QColor clr; - clr.setCmykF(m_cyan, m_magenta, m_yellow, m_black, m_alpha); - currentPen.setColor(clr); - context->platformContext()->setPen(currentPen); + QPen currentPen = context->platformContext()->pen(); + QColor clr; + clr.setCmykF(m_cmyka.c, m_cmyka.m, m_cmyka.y, m_cmyka.k, m_cmyka.a); + currentPen.setColor(clr); + context->platformContext()->setPen(currentPen); #else - context->setStrokeColor(Color(m_cyan, m_magenta, m_yellow, m_black, m_alpha), DeviceColorSpace); + context->setStrokeColor(m_rgba, DeviceColorSpace); #endif - break; - } - case Gradient: - context->setStrokeGradient(canvasGradient()->gradient()); - break; - case ImagePattern: - context->setStrokePattern(canvasPattern()->pattern()); - break; + break; + } + case Gradient: + context->setStrokeGradient(canvasGradient()->gradient()); + break; + case ImagePattern: + context->setStrokePattern(canvasPattern()->pattern()); + break; } } @@ -172,49 +158,31 @@ void CanvasStyle::applyFillColor(GraphicsContext* context) if (!context) return; switch (m_type) { - case ColorString: { - RGBA32 rgba = 0; // default is transparent black - if (CSSParser::parseColor(rgba, m_color)) - context->setFillColor(rgba, DeviceColorSpace); - break; - } - case ColorStringWithAlpha: { - RGBA32 color = 0; // default is transparent black - if (CSSParser::parseColor(color, m_color)) - context->setFillColor(colorWithOverrideAlpha(color, m_alpha), DeviceColorSpace); - break; - } - case GrayLevel: - // We're only supporting 255 levels of gray here. Since this isn't - // even part of HTML5, I don't expect anyone will care. If they do - // we'll make a fancier Color abstraction. - context->setFillColor(Color(m_grayLevel, m_grayLevel, m_grayLevel, m_alpha), DeviceColorSpace); - break; - case RGBA: - context->setFillColor(Color(m_red, m_green, m_blue, m_alpha), DeviceColorSpace); - break; - case CMYKA: { - // FIXME: Do this through platform-independent GraphicsContext API. - // We'll need a fancier Color abstraction to support CYMKA correctly + case RGBA: + context->setFillColor(m_rgba, DeviceColorSpace); + break; + case CMYKA: { + // FIXME: Do this through platform-independent GraphicsContext API. + // We'll need a fancier Color abstraction to support CMYKA correctly #if PLATFORM(CG) - CGContextSetCMYKFillColor(context->platformContext(), m_cyan, m_magenta, m_yellow, m_black, m_alpha); + CGContextSetCMYKFillColor(context->platformContext(), m_cmyka.c, m_cmyka.m, m_cmyka.y, m_cmyka.k, m_cmyka.a); #elif PLATFORM(QT) - QBrush currentBrush = context->platformContext()->brush(); - QColor clr; - clr.setCmykF(m_cyan, m_magenta, m_yellow, m_black, m_alpha); - currentBrush.setColor(clr); - context->platformContext()->setBrush(currentBrush); + QBrush currentBrush = context->platformContext()->brush(); + QColor clr; + clr.setCmykF(m_cmyka.c, m_cmyka.m, m_cmyka.y, m_cmyka.k, m_cmyka.a); + currentBrush.setColor(clr); + context->platformContext()->setBrush(currentBrush); #else - context->setFillColor(Color(m_cyan, m_magenta, m_yellow, m_black, m_alpha), DeviceColorSpace); + context->setFillColor(m_rgba, DeviceColorSpace); #endif - break; - } - case Gradient: - context->setFillGradient(canvasGradient()->gradient()); - break; - case ImagePattern: - context->setFillPattern(canvasPattern()->pattern()); - break; + break; + } + case Gradient: + context->setFillGradient(canvasGradient()->gradient()); + break; + case ImagePattern: + context->setFillPattern(canvasPattern()->pattern()); + break; } } diff --git a/WebCore/html/canvas/CanvasStyle.h b/WebCore/html/canvas/CanvasStyle.h index fe01bd1..18e55cf 100644 --- a/WebCore/html/canvas/CanvasStyle.h +++ b/WebCore/html/canvas/CanvasStyle.h @@ -1,5 +1,6 @@ /* * Copyright (C) 2006, 2008 Apple Inc. All rights reserved. + * Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies) * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions @@ -26,6 +27,7 @@ #ifndef CanvasStyle_h #define CanvasStyle_h +#include "Color.h" #include "PlatformString.h" namespace WebCore { @@ -36,16 +38,17 @@ namespace WebCore { class CanvasStyle : public RefCounted<CanvasStyle> { public: - static PassRefPtr<CanvasStyle> create(const String& color) { return adoptRef(new CanvasStyle(color)); } + static PassRefPtr<CanvasStyle> create(RGBA32 rgba) { return adoptRef(new CanvasStyle(rgba)); } + static PassRefPtr<CanvasStyle> create(const String& color); + static PassRefPtr<CanvasStyle> create(const String& color, float alpha); static PassRefPtr<CanvasStyle> create(float grayLevel) { return adoptRef(new CanvasStyle(grayLevel)); } - static PassRefPtr<CanvasStyle> create(const String& color, float alpha) { return adoptRef(new CanvasStyle(color, alpha)); } static PassRefPtr<CanvasStyle> create(float grayLevel, float alpha) { return adoptRef(new CanvasStyle(grayLevel, alpha)); } static PassRefPtr<CanvasStyle> create(float r, float g, float b, float a) { return adoptRef(new CanvasStyle(r, g, b, a)); } static PassRefPtr<CanvasStyle> create(float c, float m, float y, float k, float a) { return adoptRef(new CanvasStyle(c, m, y, k, a)); } - static PassRefPtr<CanvasStyle> create(PassRefPtr<CanvasGradient> gradient) { return adoptRef(new CanvasStyle(gradient)); } - static PassRefPtr<CanvasStyle> create(PassRefPtr<CanvasPattern> pattern) { return adoptRef(new CanvasStyle(pattern)); } + static PassRefPtr<CanvasStyle> create(PassRefPtr<CanvasGradient> gradient); + static PassRefPtr<CanvasStyle> create(PassRefPtr<CanvasPattern> pattern); - String color() const { return m_color; } + String color() const { return Color(m_rgba).serialized(); } CanvasGradient* canvasGradient() const { return m_gradient.get(); } CanvasPattern* canvasPattern() const { return m_pattern.get(); } @@ -53,35 +56,32 @@ namespace WebCore { void applyStrokeColor(GraphicsContext*); private: - CanvasStyle(const String& color); + CanvasStyle(RGBA32 rgba); CanvasStyle(float grayLevel); - CanvasStyle(const String& color, float alpha); CanvasStyle(float grayLevel, float alpha); CanvasStyle(float r, float g, float b, float a); CanvasStyle(float c, float m, float y, float k, float a); CanvasStyle(PassRefPtr<CanvasGradient>); CanvasStyle(PassRefPtr<CanvasPattern>); - enum Type { ColorString, ColorStringWithAlpha, GrayLevel, RGBA, CMYKA, Gradient, ImagePattern }; + enum Type { RGBA, CMYKA, Gradient, ImagePattern }; Type m_type; - String m_color; + RGBA32 m_rgba; + RefPtr<CanvasGradient> m_gradient; RefPtr<CanvasPattern> m_pattern; - float m_alpha; - - float m_grayLevel; - - float m_red; - float m_green; - float m_blue; - - float m_cyan; - float m_magenta; - float m_yellow; - float m_black; + struct CMYKAValues { + CMYKAValues() {} + CMYKAValues(float cyan, float magenta, float yellow, float black, float alpha) : c(cyan), m(magenta), y(yellow), k(black), a(alpha) {} + float c; + float m; + float y; + float k; + float a; + } m_cmyka; }; } // namespace WebCore |