diff options
Diffstat (limited to 'WebCore/html')
154 files changed, 3228 insertions, 1514 deletions
diff --git a/WebCore/html/DateComponents.h b/WebCore/html/DateComponents.h index aff8855..a15d558 100644 --- a/WebCore/html/DateComponents.h +++ b/WebCore/html/DateComponents.h @@ -136,6 +136,20 @@ public: double monthsSinceEpoch() const; static inline double invalidMilliseconds() { return std::numeric_limits<double>::quiet_NaN(); } + // Minimum and maxmimum limits for setMillisecondsSince*(), + // setMonthsSinceEpoch(), millisecondsSinceEpoch(), and monthsSinceEpoch(). + static inline double minimumDate() { return -12219292800000.0; } // This means 1582-10-15T00:00Z. + static inline double minimumDateTime() { return -12219292800000.0; } // ditto. + static inline double minimumMonth() { return (1582.0 - 1970) * 12 + 10 - 1; } // 1582-10 + static inline double minimumTime() { return 0; } // 00:00:00.000 + static inline double minimumWeek() { return -12212380800000.0; } // 1583-01-03, the first Monday of 1583. + static inline double maximumDate() { return std::numeric_limits<double>::max(); } + static inline double maximumDateTime() { return std::numeric_limits<double>::max(); } + // DateComponents::m_year can't represent a year greater than INT_MAX. + static inline double maximumMonth() { return (std::numeric_limits<int>::max() - 1970) * 12.0 + 12 - 1; } + static inline double maximumTime() { return 86399999; } // 23:59:59.999 + static inline double maximumWeek() { return std::numeric_limits<double>::max(); } + private: // Returns the maximum week number in this DateComponents's year. // The result is either of 52 and 53. diff --git a/WebCore/html/HTML5Lexer.cpp b/WebCore/html/HTML5Lexer.cpp index 44eae83..6c23bb0 100644 --- a/WebCore/html/HTML5Lexer.cpp +++ b/WebCore/html/HTML5Lexer.cpp @@ -57,6 +57,15 @@ namespace WebCore { using namespace HTMLNames; +namespace { + +static const UChar windowsLatin1ExtensionArray[32] = { + 0x20AC, 0x0081, 0x201A, 0x0192, 0x201E, 0x2026, 0x2020, 0x2021, // 80-87 + 0x02C6, 0x2030, 0x0160, 0x2039, 0x0152, 0x008D, 0x017D, 0x008F, // 88-8F + 0x0090, 0x2018, 0x2019, 0x201C, 0x201D, 0x2022, 0x2013, 0x2014, // 90-97 + 0x02DC, 0x2122, 0x0161, 0x203A, 0x0153, 0x009D, 0x017E, 0x0178, // 98-9F +}; + inline UChar toLowerCase(UChar cc) { ASSERT(cc >= 'A' && cc <= 'Z'); @@ -64,6 +73,74 @@ inline UChar toLowerCase(UChar cc) return cc + lowerCaseOffset; } +inline void advanceStringAndASSERTIgnoringCase(SegmentedString& source, const char* expectedCharacters) +{ + while (*expectedCharacters) + source.advanceAndASSERTIgnoringCase(*expectedCharacters++); +} + +inline bool vectorEqualsString(const Vector<UChar, 32>& vector, const String& string) +{ + if (vector.size() != string.length()) + return false; + const UChar* stringData = string.characters(); + const UChar* vectorData = vector.data(); + // FIXME: Is there a higher-level function we should be calling here? + return !memcmp(stringData, vectorData, vector.size() * sizeof(UChar)); +} + +inline UChar adjustEntity(unsigned value) +{ + if ((value & ~0x1F) != 0x0080) + return value; + return windowsLatin1ExtensionArray[value - 0x80]; +} + +inline unsigned legalEntityFor(unsigned value) +{ + // FIXME: A number of specific entity values generate parse errors. + if (value == 0 || value > 0x10FFFF || (value >= 0xD800 && value <= 0xDFFF)) + return 0xFFFD; + if (value < 0xFFFF) + return adjustEntity(value); + return value; +} + +inline bool isHexDigit(UChar cc) +{ + return (cc >= '0' && cc <= '9') || (cc >= 'a' && cc <= 'f') || (cc >= 'A' && cc <= 'F'); +} + +inline bool isAlphaNumeric(UChar cc) +{ + return (cc >= '0' && cc <= '9') || (cc >= 'a' && cc <= 'z') || (cc >= 'A' && cc <= 'Z'); +} + +void unconsumeCharacters(SegmentedString& source, const Vector<UChar, 10>& consumedCharacters) +{ + if (consumedCharacters.size() == 1) + source.push(consumedCharacters[0]); + else if (consumedCharacters.size() == 2) { + source.push(consumedCharacters[0]); + source.push(consumedCharacters[1]); + } else + source.prepend(SegmentedString(String(consumedCharacters.data(), consumedCharacters.size()))); +} + +inline bool isEndTagBufferingState(HTML5Lexer::State state) +{ + return state == HTML5Lexer::RCDATAEndTagOpenState + || state == HTML5Lexer::RCDATAEndTagNameState + || state == HTML5Lexer::RAWTEXTEndTagOpenState + || state == HTML5Lexer::RAWTEXTEndTagNameState + || state == HTML5Lexer::ScriptDataEndTagOpenState + || state == HTML5Lexer::ScriptDataEndTagNameState + || state == HTML5Lexer::ScriptDataEscapedEndTagOpenState + || state == HTML5Lexer::ScriptDataEscapedEndTagNameState; +} + +} + HTML5Lexer::HTML5Lexer() { reset(); @@ -77,79 +154,83 @@ void HTML5Lexer::reset() { m_state = DataState; m_token = 0; + m_skipLeadingNewLineForListing = false; 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) { + ASSERT(m_state != CharacterReferenceInAttributeValueState || m_additionalAllowedCharacter == '"' || m_additionalAllowedCharacter == '\'' || m_additionalAllowedCharacter == '>'); + ASSERT(!notEnoughCharacters); + enum EntityState { Initial, NumberType, - MaybeHex, + MaybeHexLowerCaseX, + MaybeHexUpperCaseX, Hex, Decimal, Named }; EntityState entityState = Initial; unsigned result = 0; - Vector<UChar, 10> seenChars; + Vector<UChar, 10> consumedCharacters; Vector<char, 10> entityName; while (!source.isEmpty()) { UChar cc = *source; - seenChars.append(cc); switch (entityState) { - case Initial: - if (isWhitespace(cc) || cc == '<' || cc == '&') + case Initial: { + if (cc == '\x09' || cc == '\x0A' || cc == '\x0C' || cc == ' ' || cc == '<' || cc == '&') return 0; - else if (cc == '#') + if (m_state == CharacterReferenceInAttributeValueState && cc == m_additionalAllowedCharacter) + return 0; + if (cc == '#') { entityState = NumberType; - else if ((cc >= 'a' && cc <= 'z') || (cc >= 'A' && cc <= 'Z')) { - entityName.append(cc); + break; + } + if ((cc >= 'a' && cc <= 'z') || (cc >= 'A' && cc <= 'Z')) { entityState = Named; - } else - return 0; - break; - case NumberType: - if (cc == 'x' || cc == 'X') - entityState = MaybeHex; - else if (cc >= '0' && cc <= '9') { + continue; + } + return 0; + } + case NumberType: { + if (cc == 'x') { + entityState = MaybeHexLowerCaseX; + break; + } + if (cc == 'X') { + entityState = MaybeHexUpperCaseX; + break; + } + if (cc >= '0' && cc <= '9') { entityState = Decimal; - result = cc - '0'; - } else { - source.push('#'); - return 0; + continue; } - 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; + source.push('#'); + return 0; + } + case MaybeHexLowerCaseX: { + if (isHexDigit(cc)) { + entityState = Hex; + continue; } - entityState = Hex; - break; - case Hex: + source.push('#'); + source.push('x'); + return 0; + } + case MaybeHexUpperCaseX: { + if (isHexDigit(cc)) { + entityState = Hex; + continue; + } + source.push('#'); + source.push('X'); + return 0; + } + case Hex: { if (cc >= '0' && cc <= '9') result = result * 16 + cc - '0'; else if (cc >= 'a' && cc <= 'f') @@ -162,7 +243,8 @@ unsigned HTML5Lexer::consumeEntity(SegmentedString& source, bool& notEnoughChara } else return legalEntityFor(result); break; - case Decimal: + } + case Decimal: { if (cc >= '0' && cc <= '9') result = result * 10 + cc - '0'; else if (cc == ';') { @@ -170,48 +252,71 @@ unsigned HTML5Lexer::consumeEntity(SegmentedString& source, bool& notEnoughChara 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) { + break; + } + case Named: { + // FIXME: This code is wrong. We need to find the longest matching entity. + // The examples from the spec are: + // I'm ¬it; I tell you + // I'm ∉ I tell you + // In the first case, "¬" is the entity. In the second + // case, "∉" is the entity. + // FIXME: Our list of HTML entities is incomplete. + // FIXME: The number 8 below is bogus. + while (!source.isEmpty() && entityName.size() <= 8) { + cc = *source; if (cc == ';') { const Entity* entity = findEntity(entityName.data(), entityName.size()); if (entity) { - source.advance(); + source.advanceAndASSERT(';'); return entity->code; } + emitParseError(); break; } - if (!(cc >= 'a' && cc <= 'z') && !(cc >= 'A' && cc <= 'Z') && !(cc >= '0' && cc <= '9')) { + if (!isAlphaNumeric(cc)) { const Entity* entity = findEntity(entityName.data(), entityName.size()); - if (entity) + if (entity) { + // HTML5 tells us to ignore this entity, for historical reasons, + // if the lookhead character is '='. + if (m_state == CharacterReferenceInAttributeValueState && cc == '=') + break; + emitParseError(); return entity->code; + } break; } entityName.append(cc); - source.advance(); - if (source.isEmpty()) - goto outOfCharacters; - cc = *source; - seenChars.append(cc); + consumedCharacters.append(cc); + source.advanceAndASSERT(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))); + notEnoughCharacters = source.isEmpty(); + unconsumeCharacters(source, consumedCharacters); return 0; } - source.advance(); + } + consumedCharacters.append(cc); + source.advanceAndASSERT(cc); } -outOfCharacters: + ASSERT(source.isEmpty()); notEnoughCharacters = true; - source.prepend(SegmentedString(String(seenChars.data(), seenChars.size()))); + unconsumeCharacters(source, consumedCharacters); return 0; } +inline bool HTML5Lexer::processEntity(SegmentedString& source) +{ + bool notEnoughCharacters = false; + unsigned value = consumeEntity(source, notEnoughCharacters); + if (notEnoughCharacters) + return false; + if (!value) + emitCharacter('&'); + else + emitCodePoint(value); + return true; +} + bool HTML5Lexer::nextToken(SegmentedString& source, HTML5Token& token) { // If we have a token in progress, then we're supposed to be called back @@ -219,7 +324,8 @@ bool HTML5Lexer::nextToken(SegmentedString& source, HTML5Token& token) ASSERT(!m_token || m_token == &token || token.type() == HTML5Token::Uninitialized); m_token = &token; - if (!m_bufferedEndTagName.isEmpty()) { + if (!m_bufferedEndTagName.isEmpty() && !isEndTagBufferingState(m_state)) { + // FIXME: This should call flushBufferedEndTag(). // We started an end tag during our last iteration. m_token->beginEndTag(m_bufferedEndTagName); m_bufferedEndTagName.clear(); @@ -229,6 +335,11 @@ bool HTML5Lexer::nextToken(SegmentedString& source, HTML5Token& token) } } + // http://www.whatwg.org/specs/web-apps/current-work/multipage/tokenization.html#parsing-main-inbody + if (m_skipLeadingNewLineForListing && m_state == DataState && !source.isEmpty() && *source == '\x0A') + source.advanceAndASSERT('\x0A'); + m_skipLeadingNewLineForListing = false; + // 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()) { @@ -249,8 +360,10 @@ bool HTML5Lexer::nextToken(SegmentedString& source, HTML5Token& token) break; } case CharacterReferenceInDataState: { - notImplemented(); - break; + if (!processEntity(source)) + return shouldEmitBufferedCharacterToken(source); + m_state = DataState; + continue; } case RCDATAState: { if (cc == '&') @@ -262,8 +375,10 @@ bool HTML5Lexer::nextToken(SegmentedString& source, HTML5Token& token) break; } case CharacterReferenceInRCDATAState: { - notImplemented(); - break; + if (!processEntity(source)) + return shouldEmitBufferedCharacterToken(source); + m_state = RCDATAState; + continue; } case RAWTEXTState: { if (cc == '<') @@ -297,6 +412,10 @@ bool HTML5Lexer::nextToken(SegmentedString& source, HTML5Token& token) } else if (cc == '?') { emitParseError(); m_state = BogusCommentState; + // The spec consumes the current character before switching + // to the bogus comment state, but it's easier to implement + // if we reconsume the current character. + continue; } else { emitParseError(); m_state = DataState; @@ -317,7 +436,8 @@ bool HTML5Lexer::nextToken(SegmentedString& source, HTML5Token& token) m_state = DataState; } else { emitParseError(); - m_state = DataState; + m_state = BogusCommentState; + continue; } // FIXME: Handle EOF properly. break; @@ -340,6 +460,7 @@ bool HTML5Lexer::nextToken(SegmentedString& source, HTML5Token& token) case RCDATALessThanSignState: { if (cc == '/') { m_temporaryBuffer.clear(); + ASSERT(m_bufferedEndTagName.isEmpty()); m_state = RCDATAEndTagOpenState; } else { emitCharacter('<'); @@ -350,11 +471,14 @@ bool HTML5Lexer::nextToken(SegmentedString& source, HTML5Token& token) } case RCDATAEndTagOpenState: { if (cc >= 'A' && cc <= 'Z') { - notImplemented(); + m_temporaryBuffer.append(cc); + addToPossibleEndTag(toLowerCase(cc)); m_state = RCDATAEndTagNameState; } else if (cc >= 'a' && cc <= 'z') { - notImplemented(); + m_temporaryBuffer.append(cc); + addToPossibleEndTag(cc); m_state = RCDATAEndTagNameState; + } else { emitCharacter('<'); emitCharacter('/'); m_state = RCDATAState; @@ -363,23 +487,36 @@ bool HTML5Lexer::nextToken(SegmentedString& source, HTML5Token& token) 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 { + if (cc >= 'A' && cc <= 'Z') { + m_temporaryBuffer.append(cc); + addToPossibleEndTag(toLowerCase(cc)); + } else if (cc >= 'a' && cc <= 'z') { + m_temporaryBuffer.append(cc); + addToPossibleEndTag(cc); + } else { + if (cc == '\x09' || cc == '\x0A' || cc == '\x0C' || cc == ' ') { + if (isAppropriateEndTag()) { + m_state = BeforeAttributeNameState; + maybeFlushBufferedEndTag(); + break; + } + } else if (cc == '/') { + if (isAppropriateEndTag()) { + m_state = SelfClosingStartTagState; + maybeFlushBufferedEndTag(); + break; + } + } else if (cc == '>') { + if (isAppropriateEndTag()) { + m_state = DataState; + maybeFlushBufferedEndTag(); + break; + } + } emitCharacter('<'); emitCharacter('/'); - notImplemented(); + m_token->appendToCharacter(m_temporaryBuffer); + m_bufferedEndTagName.clear(); m_state = RCDATAState; continue; } @@ -388,6 +525,7 @@ bool HTML5Lexer::nextToken(SegmentedString& source, HTML5Token& token) case RAWTEXTLessThanSignState: { if (cc == '/') { m_temporaryBuffer.clear(); + ASSERT(m_bufferedEndTagName.isEmpty()); m_state = RAWTEXTEndTagOpenState; } else { emitCharacter('<'); @@ -398,10 +536,12 @@ bool HTML5Lexer::nextToken(SegmentedString& source, HTML5Token& token) } case RAWTEXTEndTagOpenState: { if (cc >= 'A' && cc <= 'Z') { - notImplemented(); + m_temporaryBuffer.append(cc); + addToPossibleEndTag(toLowerCase(cc)); m_state = RAWTEXTEndTagNameState; } else if (cc >= 'a' && cc <= 'z') { - notImplemented(); + m_temporaryBuffer.append(cc); + addToPossibleEndTag(cc); m_state = RAWTEXTEndTagNameState; } else { emitCharacter('<'); @@ -412,26 +552,40 @@ bool HTML5Lexer::nextToken(SegmentedString& source, HTML5Token& token) 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 { + if (cc >= 'A' && cc <= 'Z') { + m_temporaryBuffer.append(cc); + addToPossibleEndTag(toLowerCase(cc)); + } else if (cc >= 'a' && cc <= 'z') { + m_temporaryBuffer.append(cc); + addToPossibleEndTag(cc); + } else { + if (cc == '\x09' || cc == '\x0A' || cc == '\x0C' || cc == ' ') { + if (isAppropriateEndTag()) { + m_state = BeforeAttributeNameState; + maybeFlushBufferedEndTag(); + break; + } + } else if (cc == '/') { + if (isAppropriateEndTag()) { + m_state = SelfClosingStartTagState; + maybeFlushBufferedEndTag(); + break; + } + } else if (cc == '>') { + if (isAppropriateEndTag()) { + m_state = DataState; + maybeFlushBufferedEndTag(); + break; + } + } emitCharacter('<'); emitCharacter('/'); - notImplemented(); + m_token->appendToCharacter(m_temporaryBuffer); + m_bufferedEndTagName.clear(); m_state = RAWTEXTState; continue; } + break; } case ScriptDataLessThanSignState: { if (cc == '/') { @@ -452,11 +606,11 @@ bool HTML5Lexer::nextToken(SegmentedString& source, HTML5Token& token) case ScriptDataEndTagOpenState: { if (cc >= 'A' && cc <= 'Z') { m_temporaryBuffer.append(cc); - m_bufferedEndTagName.append(toLowerCase(cc)); + addToPossibleEndTag(toLowerCase(cc)); m_state = ScriptDataEndTagNameState; } else if (cc >= 'a' && cc <= 'z') { m_temporaryBuffer.append(cc); - m_bufferedEndTagName.append(cc); + addToPossibleEndTag(cc); m_state = ScriptDataEndTagNameState; } else { emitCharacter('<'); @@ -469,30 +623,27 @@ bool HTML5Lexer::nextToken(SegmentedString& source, HTML5Token& token) case ScriptDataEndTagNameState: { if (cc >= 'A' && cc <= 'Z') { m_temporaryBuffer.append(cc); - m_bufferedEndTagName.append(toLowerCase(cc)); + addToPossibleEndTag(toLowerCase(cc)); } else if (cc >= 'a' && cc <= 'z') { m_temporaryBuffer.append(cc); - m_bufferedEndTagName.append(cc); + addToPossibleEndTag(cc); } else { if (cc == '\x09' || cc == '\x0A' || cc == '\x0C' || cc == ' ') { if (isAppropriateEndTag()) { m_state = BeforeAttributeNameState; - ASSERT(m_token->type() == HTML5Token::Character); - emitCurrentToken(); + maybeFlushBufferedEndTag(); break; } } else if (cc == '/') { if (isAppropriateEndTag()) { m_state = SelfClosingStartTagState; - ASSERT(m_token->type() == HTML5Token::Character); - emitCurrentToken(); + maybeFlushBufferedEndTag(); break; } } else if (cc == '>') { if (isAppropriateEndTag()) { m_state = DataState; - ASSERT(m_token->type() == HTML5Token::Character); - emitCurrentToken(); + maybeFlushBufferedEndTag(); break; } } @@ -567,12 +718,19 @@ bool HTML5Lexer::nextToken(SegmentedString& source, HTML5Token& token) case ScriptDataEscapedLessThanSignState: { if (cc == '/') { m_temporaryBuffer.clear(); + ASSERT(m_bufferedEndTagName.isEmpty()); m_state = ScriptDataEscapedEndTagOpenState; } else if (cc >= 'A' && cc <= 'Z') { - notImplemented(); + emitCharacter('<'); + emitCharacter(cc); + m_temporaryBuffer.clear(); + m_temporaryBuffer.append(toLowerCase(cc)); m_state = ScriptDataDoubleEscapeStartState; } else if (cc >= 'a' && cc <= 'z') { - notImplemented(); + emitCharacter('<'); + emitCharacter(cc); + m_temporaryBuffer.clear(); + m_temporaryBuffer.append(cc); m_state = ScriptDataDoubleEscapeStartState; } else { emitCharacter('<'); @@ -583,10 +741,12 @@ bool HTML5Lexer::nextToken(SegmentedString& source, HTML5Token& token) } case ScriptDataEscapedEndTagOpenState: { if (cc >= 'A' && cc <= 'Z') { - notImplemented(); + m_temporaryBuffer.append(cc); + addToPossibleEndTag(toLowerCase(cc)); m_state = ScriptDataEscapedEndTagNameState; } else if (cc >= 'a' && cc <= 'z') { - notImplemented(); + m_temporaryBuffer.append(cc); + addToPossibleEndTag(cc); m_state = ScriptDataEscapedEndTagNameState; } else { emitCharacter('<'); @@ -597,23 +757,36 @@ bool HTML5Lexer::nextToken(SegmentedString& source, HTML5Token& token) 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 { + if (cc >= 'A' && cc <= 'Z') { + m_temporaryBuffer.append(cc); + addToPossibleEndTag(toLowerCase(cc)); + } else if (cc >= 'a' && cc <= 'z') { + m_temporaryBuffer.append(cc); + addToPossibleEndTag(cc); + } else { + if (cc == '\x09' || cc == '\x0A' || cc == '\x0C' || cc == ' ') { + if (isAppropriateEndTag()) { + m_state = BeforeAttributeNameState; + maybeFlushBufferedEndTag(); + break; + } + } else if (cc == '/') { + if (isAppropriateEndTag()) { + m_state = SelfClosingStartTagState; + maybeFlushBufferedEndTag(); + break; + } + } else if (cc == '>') { + if (isAppropriateEndTag()) { + m_state = DataState; + maybeFlushBufferedEndTag(); + break; + } + } emitCharacter('<'); emitCharacter('/'); - notImplemented(); + m_token->appendToCharacter(m_temporaryBuffer); + m_bufferedEndTagName.clear(); m_state = ScriptDataEscapedState; continue; } @@ -622,15 +795,17 @@ bool HTML5Lexer::nextToken(SegmentedString& source, HTML5Token& token) case ScriptDataDoubleEscapeStartState: { if (cc == '\x09' || cc == '\x0A' || cc == '\x0C' || cc == ' ' || cc == '/' || cc == '>') { emitCharacter(cc); - if (temporaryBufferIs("string")) + if (temporaryBufferIs(scriptTag.localName())) m_state = ScriptDataDoubleEscapedState; else m_state = ScriptDataEscapedState; - } else if (cc >= 'A' && cc <= 'Z') - notImplemented(); - else if (cc >= 'a' && cc <= 'z') - notImplemented(); - else { + } else if (cc >= 'A' && cc <= 'Z') { + emitCharacter(cc); + m_temporaryBuffer.append(toLowerCase(cc)); + } else if (cc >= 'a' && cc <= 'z') { + emitCharacter(cc); + m_temporaryBuffer.append(cc); + } else { m_state = ScriptDataEscapedState; continue; } @@ -692,15 +867,17 @@ bool HTML5Lexer::nextToken(SegmentedString& source, HTML5Token& token) case ScriptDataDoubleEscapeEndState: { if (cc == '\x09' || cc == '\x0A' || cc == '\x0C' || cc == ' ' || cc == '/' || cc == '>') { emitCharacter(cc); - if (temporaryBufferIs("string")) + if (temporaryBufferIs(scriptTag.localName())) m_state = ScriptDataEscapedState; else m_state = ScriptDataDoubleEscapedState; - } else if (cc >= 'A' && cc <= 'Z') - notImplemented(); - else if (cc >= 'a' && cc <= 'z') - notImplemented(); - else { + } else if (cc >= 'A' && cc <= 'Z') { + emitCharacter(cc); + m_temporaryBuffer.append(toLowerCase(cc)); + } else if (cc >= 'a' && cc <= 'z') { + emitCharacter(cc); + m_temporaryBuffer.append(cc); + } else { m_state = ScriptDataDoubleEscapedState; continue; } @@ -835,8 +1012,31 @@ bool HTML5Lexer::nextToken(SegmentedString& source, HTML5Token& token) break; } case CharacterReferenceInAttributeValueState: { - notImplemented(); - break; + bool notEnoughCharacters = false; + unsigned value = consumeEntity(source, notEnoughCharacters); + if (notEnoughCharacters) + return shouldEmitBufferedCharacterToken(source); + if (!value) + m_token->appendToAttributeValue('&'); + else if (value < 0xFFFF) + m_token->appendToAttributeValue(value); + else { + m_token->appendToAttributeValue(U16_LEAD(value)); + m_token->appendToAttributeValue(U16_TRAIL(value)); + } + // We're supposed to switch back to the attribute value state that + // we were in when we were switched into this state. Rather than + // keeping track of this explictly, we observe that the previous + // state can be determined by m_additionalAllowedCharacter. + if (m_additionalAllowedCharacter == '"') + m_state = AttributeValueDoubleQuotedState; + else if (m_additionalAllowedCharacter == '\'') + m_state = AttributeValueSingleQuotedState; + else if (m_additionalAllowedCharacter == '>') + m_state = AttributeValueUnquotedState; + else + ASSERT_NOT_REACHED(); + continue; } case AfterAttributeValueQuotedState: { if (cc == '\x09' || cc == '\x0A' || cc == '\x0C' || cc == ' ') @@ -868,12 +1068,24 @@ bool HTML5Lexer::nextToken(SegmentedString& source, HTML5Token& token) break; } case BogusCommentState: { - notImplemented(); + m_token->beginComment(); + while (!source.isEmpty()) { + cc = *source; + if (cc == '>') + break; + m_token->appendToComment(cc); + source.advance(); + } + emitCurrentToken(); m_state = DataState; + if (source.isEmpty()) + return true; + // FIXME: Handle EOF properly. break; } case MarkupDeclarationOpenState: { DEFINE_STATIC_LOCAL(String, dashDashString, ("--")); + DEFINE_STATIC_LOCAL(String, doctypeString, ("doctype")); if (cc == '-') { SegmentedString::LookAheadResult result = source.lookAhead(dashDashString); if (result == SegmentedString::DidMatch) { @@ -883,10 +1095,22 @@ bool HTML5Lexer::nextToken(SegmentedString& source, HTML5Token& token) m_state = CommentStartState; continue; } else if (result == SegmentedString::NotEnoughCharacters) - return false; // We need to wait for more characters to arrive. + return shouldEmitBufferedCharacterToken(source); + } else if (cc == 'D' || cc == 'd') { + SegmentedString::LookAheadResult result = source.lookAheadIgnoringCase(doctypeString); + if (result == SegmentedString::DidMatch) { + advanceStringAndASSERTIgnoringCase(source, "doctype"); + m_state = DOCTYPEState; + continue; + } else if (result == SegmentedString::NotEnoughCharacters) + return shouldEmitBufferedCharacterToken(source); } notImplemented(); - break; + // FIXME: We're still missing the bits about the insertion mode being in foreign content: + // http://www.whatwg.org/specs/web-apps/current-work/multipage/tokenization.html#markup-declaration-open-state + emitParseError(); + m_state = BogusCommentState; + continue; } case CommentStartState: { if (cc == '-') @@ -1012,15 +1236,16 @@ bool HTML5Lexer::nextToken(SegmentedString& source, HTML5Token& token) if (cc == '\x09' || cc == '\x0A' || cc == '\x0C' || cc == ' ') break; else if (cc >= 'A' && cc <= 'Z') { - notImplemented(); + m_token->beginDOCTYPE(toLowerCase(cc)); m_state = DOCTYPENameState; } else if (cc == '>') { emitParseError(); + m_token->beginDOCTYPE(); notImplemented(); - emitCurrentDoctypeToken(); + emitCurrentToken(); m_state = DataState; } else { - notImplemented(); + m_token->beginDOCTYPE(cc); m_state = DOCTYPENameState; } // FIXME: Handle EOF properly. @@ -1030,23 +1255,45 @@ bool HTML5Lexer::nextToken(SegmentedString& source, HTML5Token& token) if (cc == '\x09' || cc == '\x0A' || cc == '\x0C' || cc == ' ') m_state = AfterDOCTYPENameState; else if (cc == '>') { - emitCurrentDoctypeToken(); + emitCurrentToken(); m_state = DataState; } else if (cc >= 'A' && cc <= 'Z') - notImplemented(); + m_token->appendToName(toLowerCase(cc)); else - notImplemented(); + m_token->appendToName(cc); // FIXME: Handle EOF properly. break; } case AfterDOCTYPENameState: { if (cc == '\x09' || cc == '\x0A' || cc == '\x0C' || cc == ' ') break; - else if (cc == '>') { - emitCurrentDoctypeToken(); + if (cc == '>') { + emitCurrentToken(); m_state = DataState; - } else + } else { + DEFINE_STATIC_LOCAL(String, publicString, ("public")); + DEFINE_STATIC_LOCAL(String, systemString, ("system")); + if (cc == 'P' || cc == 'p') { + SegmentedString::LookAheadResult result = source.lookAheadIgnoringCase(publicString); + if (result == SegmentedString::DidMatch) { + advanceStringAndASSERTIgnoringCase(source, "public"); + m_state = AfterDOCTYPEPublicKeywordState; + continue; + } else if (result == SegmentedString::NotEnoughCharacters) + return shouldEmitBufferedCharacterToken(source); + } else if (cc == 'S' || cc == 's') { + SegmentedString::LookAheadResult result = source.lookAheadIgnoringCase(systemString); + if (result == SegmentedString::DidMatch) { + advanceStringAndASSERTIgnoringCase(source, "system"); + m_state = AfterDOCTYPESystemKeywordState; + continue; + } else if (result == SegmentedString::NotEnoughCharacters) + return shouldEmitBufferedCharacterToken(source); + } + emitParseError(); notImplemented(); + m_state = BogusDOCTYPEState; + } // FIXME: Handle EOF properly. break; } @@ -1055,16 +1302,16 @@ bool HTML5Lexer::nextToken(SegmentedString& source, HTML5Token& token) m_state = BeforeDOCTYPEPublicIdentifierState; else if (cc == '"') { emitParseError(); - notImplemented(); + m_token->setPublicIdentifierToEmptyString(); m_state = DOCTYPEPublicIdentifierDoubleQuotedState; } else if (cc == '\'') { emitParseError(); - notImplemented(); + m_token->setPublicIdentifierToEmptyString(); m_state = DOCTYPEPublicIdentifierSingleQuotedState; } else if (cc == '>') { emitParseError(); notImplemented(); - emitCurrentDoctypeToken(); + emitCurrentToken(); m_state = DataState; } else { emitParseError(); @@ -1078,15 +1325,15 @@ bool HTML5Lexer::nextToken(SegmentedString& source, HTML5Token& token) if (cc == '\x09' || cc == '\x0A' || cc == '\x0C' || cc == ' ') break; else if (cc == '"') { - notImplemented(); + m_token->setPublicIdentifierToEmptyString(); m_state = DOCTYPEPublicIdentifierDoubleQuotedState; } else if (cc == '\'') { - notImplemented(); + m_token->setPublicIdentifierToEmptyString(); m_state = DOCTYPEPublicIdentifierSingleQuotedState; } else if (cc == '>') { emitParseError(); notImplemented(); - emitCurrentDoctypeToken(); + emitCurrentToken(); m_state = DataState; } else { emitParseError(); @@ -1102,10 +1349,10 @@ bool HTML5Lexer::nextToken(SegmentedString& source, HTML5Token& token) else if (cc == '>') { emitParseError(); notImplemented(); - emitCurrentDoctypeToken(); + emitCurrentToken(); m_state = DataState; } else - notImplemented(); + m_token->appendToPublicIdentifier(cc); // FIXME: Handle EOF properly. break; } @@ -1115,10 +1362,10 @@ bool HTML5Lexer::nextToken(SegmentedString& source, HTML5Token& token) else if (cc == '>') { emitParseError(); notImplemented(); - emitCurrentDoctypeToken(); + emitCurrentToken(); m_state = DataState; } else - notImplemented(); + m_token->appendToPublicIdentifier(cc); // FIXME: Handle EOF properly. break; } @@ -1126,15 +1373,15 @@ bool HTML5Lexer::nextToken(SegmentedString& source, HTML5Token& token) if (cc == '\x09' || cc == '\x0A' || cc == '\x0C' || cc == ' ') m_state = BetweenDOCTYPEPublicAndSystemIdentifiersState; else if (cc == '>') { - emitCurrentDoctypeToken(); + emitCurrentToken(); m_state = DataState; } else if (cc == '"') { emitParseError(); - notImplemented(); + m_token->setPublicIdentifierToEmptyString(); m_state = DOCTYPESystemIdentifierDoubleQuotedState; } else if (cc == '\'') { emitParseError(); - notImplemented(); + m_token->setPublicIdentifierToEmptyString(); m_state = DOCTYPESystemIdentifierSingleQuotedState; } else { emitParseError(); @@ -1148,13 +1395,13 @@ bool HTML5Lexer::nextToken(SegmentedString& source, HTML5Token& token) if (cc == '\x09' || cc == '\x0A' || cc == '\x0C' || cc == ' ') m_state = BetweenDOCTYPEPublicAndSystemIdentifiersState; else if (cc == '>') { - emitCurrentDoctypeToken(); + emitCurrentToken(); m_state = DataState; } else if (cc == '"') { - notImplemented(); + m_token->setSystemIdentifierToEmptyString(); m_state = DOCTYPESystemIdentifierDoubleQuotedState; } else if (cc == '\'') { - notImplemented(); + m_token->setSystemIdentifierToEmptyString(); m_state = DOCTYPESystemIdentifierSingleQuotedState; } else { emitParseError(); @@ -1169,16 +1416,16 @@ bool HTML5Lexer::nextToken(SegmentedString& source, HTML5Token& token) m_state = BeforeDOCTYPESystemIdentifierState; else if (cc == '"') { emitParseError(); - notImplemented(); + m_token->setSystemIdentifierToEmptyString(); m_state = DOCTYPESystemIdentifierDoubleQuotedState; } else if (cc == '\'') { emitParseError(); - notImplemented(); + m_token->setSystemIdentifierToEmptyString(); m_state = DOCTYPESystemIdentifierSingleQuotedState; } else if (cc == '>') { emitParseError(); notImplemented(); - emitCurrentDoctypeToken(); + emitCurrentToken(); m_state = DataState; } else { emitParseError(); @@ -1191,16 +1438,16 @@ bool HTML5Lexer::nextToken(SegmentedString& source, HTML5Token& token) case BeforeDOCTYPESystemIdentifierState: { if (cc == '\x09' || cc == '\x0A' || cc == '\x0C' || cc == ' ') break; - else if (cc == '"') { - notImplemented(); + if (cc == '"') { + m_token->setSystemIdentifierToEmptyString(); m_state = DOCTYPESystemIdentifierDoubleQuotedState; } else if (cc == '\'') { - notImplemented(); + m_token->setSystemIdentifierToEmptyString(); m_state = DOCTYPESystemIdentifierSingleQuotedState; } else if (cc == '>') { emitParseError(); notImplemented(); - emitCurrentDoctypeToken(); + emitCurrentToken(); m_state = DataState; } else { emitParseError(); @@ -1216,10 +1463,10 @@ bool HTML5Lexer::nextToken(SegmentedString& source, HTML5Token& token) else if (cc == '>') { emitParseError(); notImplemented(); - emitCurrentDoctypeToken(); + emitCurrentToken(); m_state = DataState; } else - notImplemented(); + m_token->appendToSystemIdentifier(cc); // FIXME: Handle EOF properly. break; } @@ -1229,10 +1476,10 @@ bool HTML5Lexer::nextToken(SegmentedString& source, HTML5Token& token) else if (cc == '>') { emitParseError(); notImplemented(); - emitCurrentDoctypeToken(); + emitCurrentToken(); m_state = DataState; } else - notImplemented(); + m_token->appendToSystemIdentifier(cc); // FIXME: Handle EOF properly. break; } @@ -1240,7 +1487,7 @@ bool HTML5Lexer::nextToken(SegmentedString& source, HTML5Token& token) if (cc == '\x09' || cc == '\x0A' || cc == '\x0C' || cc == ' ') break; else if (cc == '>') { - emitCurrentDoctypeToken(); + emitCurrentToken(); m_state = DataState; } else { emitParseError(); @@ -1250,8 +1497,10 @@ bool HTML5Lexer::nextToken(SegmentedString& source, HTML5Token& token) break; } case BogusDOCTYPEState: { - if (cc == '>') - emitCurrentDoctypeToken(); + if (cc == '>') { + emitCurrentToken(); + m_state = DataState; + } // FIXME: Handle EOF properly. break; } @@ -1259,10 +1508,6 @@ bool HTML5Lexer::nextToken(SegmentedString& source, HTML5Token& token) notImplemented(); break; } - case TokenizingCharacterReferencesState: { - notImplemented(); - break; - } } source.advance(); if (m_emitPending) { @@ -1272,23 +1517,23 @@ bool HTML5Lexer::nextToken(SegmentedString& source, HTML5Token& token) } // 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; + return shouldEmitBufferedCharacterToken(source); } -inline bool HTML5Lexer::temporaryBufferIs(const char*) +inline bool HTML5Lexer::temporaryBufferIs(const String& expectedString) { - notImplemented(); - return true; + return vectorEqualsString(m_temporaryBuffer, expectedString); +} + +inline void HTML5Lexer::addToPossibleEndTag(UChar cc) +{ + ASSERT(isEndTagBufferingState(m_state)); + m_bufferedEndTagName.append(cc); } 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)); + return vectorEqualsString(m_bufferedEndTagName, m_appropriateEndTagName); } inline void HTML5Lexer::emitCharacter(UChar character) @@ -1300,20 +1545,52 @@ inline void HTML5Lexer::emitCharacter(UChar character) m_token->appendToCharacter(character); } +inline void HTML5Lexer::emitCodePoint(unsigned value) +{ + if (value < 0xFFFF) { + emitCharacter(value); + return; + } + emitCharacter(U16_LEAD(value)); + emitCharacter(U16_TRAIL(value)); +} + inline void HTML5Lexer::emitParseError() { notImplemented(); } +inline void HTML5Lexer::maybeFlushBufferedEndTag() +{ + ASSERT(m_token->type() == HTML5Token::Character || m_token->type() == HTML5Token::Uninitialized); + if (m_token->type() == HTML5Token::Character) { + // We have a character token queued up. We need to emit it before we + // can start begin the buffered end tag token. + emitCurrentToken(); + return; + } + flushBufferedEndTag(); +} + +inline void HTML5Lexer::flushBufferedEndTag() +{ + m_token->beginEndTag(m_bufferedEndTagName); + m_bufferedEndTagName.clear(); + if (m_state == DataState) + emitCurrentToken(); +} + inline void HTML5Lexer::emitCurrentToken() { + ASSERT(m_token->type() != HTML5Token::Uninitialized); m_emitPending = true; if (m_token->type() == HTML5Token::StartTag) m_appropriateEndTagName = m_token->name(); } -inline void HTML5Lexer::emitCurrentDoctypeToken() +inline bool HTML5Lexer::shouldEmitBufferedCharacterToken(const SegmentedString& source) { + return source.isClosed() && m_token->type() == HTML5Token::Character; } } diff --git a/WebCore/html/HTML5Lexer.h b/WebCore/html/HTML5Lexer.h index 6d61cc2..08612e6 100644 --- a/WebCore/html/HTML5Lexer.h +++ b/WebCore/html/HTML5Lexer.h @@ -108,7 +108,6 @@ namespace WebCore { AfterDOCTYPESystemIdentifierState, BogusDOCTYPEState, CDATASectionState, - TokenizingCharacterReferencesState, }; HTML5Lexer(); @@ -123,17 +122,30 @@ namespace WebCore { void setState(State state) { m_state = state; } - static unsigned consumeEntity(SegmentedString&, bool& notEnoughCharacters); + // Hack to skip leading newline in <pre>/<listing> for authoring ease. + // http://www.whatwg.org/specs/web-apps/current-work/multipage/tokenization.html#parsing-main-inbody + void skipLeadingNewLineForListing() { m_skipLeadingNewLineForListing = true; } private: inline void emitCharacter(UChar); inline void emitParseError(); inline void emitCurrentToken(); - inline void emitCurrentDoctypeToken(); + inline void emitCodePoint(unsigned); - inline bool temporaryBufferIs(const char*); + unsigned consumeEntity(SegmentedString&, bool& notEnoughCharacters); + inline bool processEntity(SegmentedString& source); + inline bool temporaryBufferIs(const String&); + + // Sometimes we speculatively consume input characters and we don't + // know whether they represent end tags or RCDATA, etc. These + // functions help manage these state. + inline void addToPossibleEndTag(UChar cc); inline bool isAppropriateEndTag(); + inline void maybeFlushBufferedEndTag(); + inline void flushBufferedEndTag(); + + inline bool shouldEmitBufferedCharacterToken(const SegmentedString&); State m_state; @@ -143,6 +155,7 @@ namespace WebCore { // this member might be pointing to unallocated memory. HTML5Token* m_token; + bool m_skipLeadingNewLineForListing; bool m_emitPending; // http://www.whatwg.org/specs/web-apps/current-work/#temporary-buffer diff --git a/WebCore/html/HTML5ScriptRunner.cpp b/WebCore/html/HTML5ScriptRunner.cpp new file mode 100644 index 0000000..3e0cd7f --- /dev/null +++ b/WebCore/html/HTML5ScriptRunner.cpp @@ -0,0 +1,247 @@ +/* + * 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 "HTML5ScriptRunner.h" + +#include "Attribute.h" +#include "CachedScript.h" +#include "DocLoader.h" +#include "Element.h" +#include "Event.h" +#include "Frame.h" +#include "HTML5ScriptRunnerHost.h" +#include "HTMLNames.h" +#include "NotImplemented.h" +#include "ScriptElement.h" +#include "ScriptSourceCode.h" + +namespace WebCore { + +using namespace HTMLNames; + +HTML5ScriptRunner::HTML5ScriptRunner(Document* document, HTML5ScriptRunnerHost* host) + : m_document(document) + , m_host(host) + , m_scriptNestingLevel(0) + , m_hasScriptsWaitingForStylesheets(false) +{ +} + +HTML5ScriptRunner::~HTML5ScriptRunner() +{ + // FIXME: Should we be passed a "done loading/parsing" callback sooner than destruction? + if (m_parsingBlockingScript.cachedScript && m_parsingBlockingScript.watchingForLoad) + stopWatchingForLoad(m_parsingBlockingScript); +} + +static KURL documentURLForScriptExecution(Document* document) +{ + if (!document || !document->frame()) + return KURL(); + + // Use the URL of the currently active document for this frame. + return document->frame()->document()->url(); +} + +inline PassRefPtr<Event> createScriptLoadEvent() +{ + return Event::create(eventNames().loadEvent, false, false); +} + +inline PassRefPtr<Event> createScriptErrorEvent() +{ + return Event::create(eventNames().errorEvent, true, false); +} + +ScriptSourceCode HTML5ScriptRunner::sourceFromPendingScript(const PendingScript& script, bool& errorOccurred) +{ + if (script.cachedScript) { + errorOccurred = script.cachedScript->errorOccurred(); + ASSERT(script.cachedScript->isLoaded()); + return ScriptSourceCode(script.cachedScript.get()); + } + errorOccurred = false; + // FIXME: Line numbers are wrong. + return ScriptSourceCode(script.element->textContent(), documentURLForScriptExecution(m_document)); +} + +bool HTML5ScriptRunner::isPendingScriptReady(const PendingScript& script) +{ + m_hasScriptsWaitingForStylesheets = !m_document->haveStylesheetsLoaded(); + if (m_hasScriptsWaitingForStylesheets) + return false; + if (script.cachedScript && !script.cachedScript->isLoaded()) + return false; + return true; +} + +void HTML5ScriptRunner::executePendingScript() +{ + ASSERT(!m_scriptNestingLevel); + ASSERT(m_document->haveStylesheetsLoaded()); + bool errorOccurred = false; + ASSERT(isPendingScriptReady(m_parsingBlockingScript)); + ScriptSourceCode sourceCode = sourceFromPendingScript(m_parsingBlockingScript, errorOccurred); + + // Stop watching loads before executeScript to prevent recursion if the script reloads itself. + if (m_parsingBlockingScript.cachedScript && m_parsingBlockingScript.watchingForLoad) + stopWatchingForLoad(m_parsingBlockingScript); + + // Clear the pending script before possible rentrancy from executeScript() + RefPtr<Element> scriptElement = m_parsingBlockingScript.element.release(); + m_parsingBlockingScript = PendingScript(); + + m_scriptNestingLevel++; + if (errorOccurred) + scriptElement->dispatchEvent(createScriptErrorEvent()); + else { + executeScript(scriptElement.get(), sourceCode); + scriptElement->dispatchEvent(createScriptLoadEvent()); + } + m_scriptNestingLevel--; + ASSERT(!m_scriptNestingLevel); +} + +void HTML5ScriptRunner::executeScript(Element* element, const ScriptSourceCode& sourceCode) +{ + ScriptElement* scriptElement = toScriptElement(element); + ASSERT(scriptElement); + if (!scriptElement->shouldExecuteAsJavaScript()) + return; + + // Always use the delegate to execute the script so that it can save any + // necessary state to prepare for rentrancy. + m_host->executeScript(sourceCode); +} + +void HTML5ScriptRunner::watchForLoad(PendingScript& pendingScript) +{ + ASSERT(!pendingScript.watchingForLoad); + m_host->watchForLoad(pendingScript.cachedScript.get()); + pendingScript.watchingForLoad = true; +} + +void HTML5ScriptRunner::stopWatchingForLoad(PendingScript& pendingScript) +{ + ASSERT(pendingScript.watchingForLoad); + m_host->stopWatchingForLoad(pendingScript.cachedScript.get()); + pendingScript.watchingForLoad = false; +} + +// This function should match 10.2.5.11 "An end tag whose tag name is 'script'" +// Script handling lives outside the tree builder to keep the each class simple. +bool HTML5ScriptRunner::execute(PassRefPtr<Element> scriptElement) +{ + ASSERT(scriptElement); + // FIXME: If scripting is disabled, always just return true; + + // Try to execute the script given to us. + runScript(scriptElement.get()); + if (m_scriptNestingLevel) + return false; // Don't continue parsing. + if (!executeParsingBlockingScripts()) + return false; + + notImplemented(); // Restore insertion point? + // FIXME: Handle re-entrant scripts and m_pendingParsingBlockinScript. + return true; +} + +bool HTML5ScriptRunner::executeParsingBlockingScripts() +{ + while (m_parsingBlockingScript.element) { + // We only really need to check once. + if (!isPendingScriptReady(m_parsingBlockingScript)) + return false; + executePendingScript(); + } + return true; +} + +bool HTML5ScriptRunner::executeScriptsWaitingForLoad(CachedResource*) +{ + ASSERT(!m_scriptNestingLevel); + ASSERT(m_parsingBlockingScript.element); + ASSERT(m_parsingBlockingScript.cachedScript->isLoaded()); + return executeParsingBlockingScripts(); +} + +bool HTML5ScriptRunner::executeScriptsWaitingForStylesheets() +{ + // Callers should check hasScriptsWaitingForStylesheets() before calling + // to prevent parser or script re-entry during </style> parsing. + ASSERT(m_hasScriptsWaitingForStylesheets); + ASSERT(!m_scriptNestingLevel); + ASSERT(m_document->haveStylesheetsLoaded()); + return executeParsingBlockingScripts(); +} + +void HTML5ScriptRunner::requestScript(Element* script) +{ + ASSERT(!m_parsingBlockingScript.element); + AtomicString srcValue = script->getAttribute(srcAttr); + // FIXME: We need to resolve the url relative to the element. + m_parsingBlockingScript.element = script; + if (!script->dispatchBeforeLoadEvent(srcValue)) // Part of HTML5? + return; + // This should correctly return 0 for empty or invalid srcValues. + CachedScript* cachedScript = m_document->docLoader()->requestScript(srcValue, toScriptElement(script)->scriptCharset()); + if (!cachedScript) { + notImplemented(); // Dispatch error event. + return; + } + m_parsingBlockingScript.cachedScript = cachedScript; + + // We only care about a load callback if cachedScript is not already + // in the cache. Callers will attempt to run the m_parsingBlockingScript + // if possible before returning control to the parser. + if (!m_parsingBlockingScript.cachedScript->isLoaded()) + watchForLoad(m_parsingBlockingScript); +} + +// This method is meant to match the HTML5 definition of "running a script" +// http://www.whatwg.org/specs/web-apps/current-work/multipage/scripting-1.html#running-a-script +void HTML5ScriptRunner::runScript(Element* script) +{ + ASSERT(!m_parsingBlockingScript.element); + m_scriptNestingLevel++; + // Check script type and language, current code uses ScriptElement::shouldExecuteAsJavaScript(), but that may not be HTML5 compliant. + notImplemented(); // event for support + + if (script->hasAttribute(srcAttr)) { + // FIXME: Handle defer and async + requestScript(script); + } else if (!m_document->haveStylesheetsLoaded()) { + m_parsingBlockingScript.element = script; + } else { + // FIXME: Need a line numbers implemenation. + ScriptSourceCode sourceCode(script->textContent(), documentURLForScriptExecution(m_document), 0); + executeScript(script, sourceCode); + } + m_scriptNestingLevel--; +} + +} diff --git a/WebCore/html/HTML5ScriptRunner.h b/WebCore/html/HTML5ScriptRunner.h new file mode 100644 index 0000000..c6a03fb --- /dev/null +++ b/WebCore/html/HTML5ScriptRunner.h @@ -0,0 +1,102 @@ +/* + * 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 HTML5ScriptRunner_h +#define HTML5ScriptRunner_h + +#include "CachedResourceClient.h" +#include "CachedResourceHandle.h" +#include <wtf/Noncopyable.h> +#include <wtf/PassRefPtr.h> + +namespace WebCore { + +class CachedResourceClient; +class CachedScript; +class Document; +class Element; +class Frame; +class HTML5ScriptRunnerHost; +class ScriptSourceCode; + +class HTML5ScriptRunner : public Noncopyable { +public: + HTML5ScriptRunner(Document*, HTML5ScriptRunnerHost*); + ~HTML5ScriptRunner(); + + // Processes the passed in script and any pending scripts if possible. + bool execute(PassRefPtr<Element> scriptToProcess); + // Processes any pending scripts. + bool executeScriptsWaitingForLoad(CachedResource*); + bool hasScriptsWaitingForStylesheets() const { return m_hasScriptsWaitingForStylesheets; } + bool executeScriptsWaitingForStylesheets(); + + bool inScriptExecution() { return !!m_scriptNestingLevel; } + +private: + struct PendingScript { + PendingScript() + : watchingForLoad(false) + { + } + + RefPtr<Element> element; + CachedResourceHandle<CachedScript> cachedScript; + bool watchingForLoad; // Did we pass the cachedScript to the HTML5ScriptRunnerHost. + // HTML5 has an isReady parameter, however isReady ends up equivalent to + // m_document->haveStylesheetsLoaded() && cachedScript->isLoaded() + }; + + Frame* frame() const; + + bool executeParsingBlockingScripts(); + void executePendingScript(); + + void requestScript(Element*); + void runScript(Element*); + + // Helpers for dealing with HTML5ScriptRunnerHost + void watchForLoad(PendingScript&); + void stopWatchingForLoad(PendingScript&); + void executeScript(Element*, const ScriptSourceCode&); + + bool isPendingScriptReady(const PendingScript&); + ScriptSourceCode sourceFromPendingScript(const PendingScript&, bool& errorOccurred); + + Document* m_document; + HTML5ScriptRunnerHost* m_host; + PendingScript m_parsingBlockingScript; + unsigned m_scriptNestingLevel; + + // We only want stylesheet loads to trigger script execution if script + // execution is currently stopped due to stylesheet loads, otherwise we'd + // cause nested sript execution when parsing <style> tags since </style> + // tags can cause Document to call executeScriptsWaitingForStylesheets. + bool m_hasScriptsWaitingForStylesheets; +}; + +} + +#endif diff --git a/WebCore/html/HTML5ScriptRunnerHost.h b/WebCore/html/HTML5ScriptRunnerHost.h new file mode 100644 index 0000000..730e0fc --- /dev/null +++ b/WebCore/html/HTML5ScriptRunnerHost.h @@ -0,0 +1,49 @@ +/* + * 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 HTML5ScriptRunnerHost_h +#define HTML5ScriptRunnerHost_h + +namespace WebCore { + +class CachedResource; +class ScriptSourceCode; + +class HTML5ScriptRunnerHost { +public: + virtual ~HTML5ScriptRunnerHost() { } + + // Implementors should call cachedResource->addClient() here or soon after. + virtual void watchForLoad(CachedResource*) = 0; + // Implementors must call cachedResource->removeClient() immediately. + virtual void stopWatchingForLoad(CachedResource*) = 0; + + // Implementors should handle possible rentry before/after calling ScriptController::executeScript + virtual void executeScript(const ScriptSourceCode&) = 0; +}; + +} + +#endif diff --git a/WebCore/html/HTML5Token.h b/WebCore/html/HTML5Token.h index 1918589..b4188d3 100644 --- a/WebCore/html/HTML5Token.h +++ b/WebCore/html/HTML5Token.h @@ -51,6 +51,7 @@ public: }; typedef WTF::Vector<Attribute> AttributeList; + typedef WTF::Vector<UChar, 1024> DataVector; HTML5Token() { clear(); } @@ -63,10 +64,10 @@ public: { ASSERT(m_type == Uninitialized); m_type = StartTag; - m_data.clear(); - m_dataString = AtomicString(); + clearData(); m_selfClosing = false; m_currentAttribute = 0; + m_attributes.clear(); m_data.append(character); } @@ -76,10 +77,10 @@ public: { ASSERT(m_type == Uninitialized); m_type = EndTag; - m_data.clear(); - m_dataString = AtomicString(); + clearData(); m_selfClosing = false; m_currentAttribute = 0; + m_attributes.clear(); m_data.append(characters); } @@ -88,8 +89,7 @@ public: { ASSERT(m_type == Uninitialized); m_type = Character; - m_data.clear(); - m_dataString = AtomicString(); + clearData(); m_data.append(character); } @@ -97,8 +97,21 @@ public: { ASSERT(m_type == Uninitialized); m_type = Comment; - m_data.clear(); - m_dataString = AtomicString(); + clearData(); + } + + void beginDOCTYPE() + { + ASSERT(m_type == Uninitialized); + m_type = DOCTYPE; + clearData(); + m_doctypeData.set(new DoctypeData()); + } + + void beginDOCTYPE(UChar character) + { + beginDOCTYPE(); + m_data.append(character); } void appendToName(UChar character) @@ -156,27 +169,108 @@ public: AtomicString name() { ASSERT(m_type == StartTag || m_type == EndTag || m_type == DOCTYPE); - return dataString(); + if (!m_data.isEmpty() && m_dataAsNameAtom.isEmpty()) + m_dataAsNameAtom = AtomicString(adoptDataAsStringImpl()); + return m_dataAsNameAtom; + } + + PassRefPtr<StringImpl> adoptDataAsStringImpl() + { + ASSERT(!m_dataAsNameAtom); // An attempt to make sure this isn't called twice. + return StringImpl::adopt(m_data); + } + + const DataVector& characters() + { + ASSERT(m_type == Character); + ASSERT(!m_dataAsNameAtom); + return m_data; + } + + const DataVector& comment() + { + ASSERT(m_type == Comment); + ASSERT(!m_dataAsNameAtom); + return m_data; } - AtomicString characters() + // FIXME: Should be removed once we stop using the old parser. + String takeCharacters() { ASSERT(m_type == Character); - return dataString(); + return String(adoptDataAsStringImpl()); } - AtomicString data() + // FIXME: Should be removed once we stop using the old parser. + String takeComment() { ASSERT(m_type == Comment); - return dataString(); + return String(adoptDataAsStringImpl()); + } + + // FIXME: Distinguish between a missing public identifer and an empty one. + const WTF::Vector<UChar>& publicIdentifier() + { + ASSERT(m_type == DOCTYPE); + return m_doctypeData->m_publicIdentifier; + } + + // FIXME: Distinguish between a missing system identifer and an empty one. + const WTF::Vector<UChar>& systemIdentifier() + { + ASSERT(m_type == DOCTYPE); + return m_doctypeData->m_systemIdentifier; + } + + void setPublicIdentifierToEmptyString() + { + ASSERT(m_type == DOCTYPE); + m_doctypeData->m_hasPublicIdentifier = true; + m_doctypeData->m_publicIdentifier.clear(); + } + + void setSystemIdentifierToEmptyString() + { + ASSERT(m_type == DOCTYPE); + m_doctypeData->m_hasSystemIdentifier = true; + m_doctypeData->m_systemIdentifier.clear(); + } + + void appendToPublicIdentifier(UChar character) + { + ASSERT(m_type == DOCTYPE); + ASSERT(m_doctypeData->m_hasPublicIdentifier); + m_doctypeData->m_publicIdentifier.append(character); + } + + void appendToSystemIdentifier(UChar character) + { + ASSERT(m_type == DOCTYPE); + ASSERT(m_doctypeData->m_hasSystemIdentifier); + m_doctypeData->m_systemIdentifier.append(character); } private: - AtomicString dataString() + class DoctypeData { + public: + DoctypeData() + : m_hasPublicIdentifier(false) + , m_hasSystemIdentifier(false) + , m_forceQuirks(false) + { + } + + bool m_hasPublicIdentifier; + bool m_hasSystemIdentifier; + bool m_forceQuirks; + WTF::Vector<UChar> m_publicIdentifier; + WTF::Vector<UChar> m_systemIdentifier; + }; + + void clearData() { - if (!m_data.isEmpty() && m_dataString.isEmpty()) - m_dataString = AtomicString(StringImpl::adopt(m_data)); - return m_dataString; + m_data.clear(); + m_dataAsNameAtom = AtomicString(); } Type m_type; @@ -184,12 +278,11 @@ private: // "name" for DOCTYPE, StartTag, and EndTag // "characters" for Character // "data" for Comment - WTF::Vector<UChar, 1024> m_data; + DataVector m_data; + AtomicString m_dataAsNameAtom; // For DOCTYPE - String m_publicIdentifier; - String m_systemIdentifier; - bool m_forceQuirks; + OwnPtr<DoctypeData> m_doctypeData; // For StartTag and EndTag bool m_selfClosing; @@ -197,8 +290,6 @@ private: // A pointer into m_attributes used during lexing. Attribute* m_currentAttribute; - - AtomicString m_dataString; }; } diff --git a/WebCore/html/HTML5Tokenizer.cpp b/WebCore/html/HTML5Tokenizer.cpp index c531c7e..0feace5 100644 --- a/WebCore/html/HTML5Tokenizer.cpp +++ b/WebCore/html/HTML5Tokenizer.cpp @@ -26,9 +26,12 @@ #include "config.h" #include "HTML5Tokenizer.h" +#include "Element.h" +#include "Frame.h" #include "HTML5Lexer.h" -#include "HTML5Token.h" +#include "HTML5ScriptRunner.h" #include "HTML5TreeBuilder.h" +#include "HTMLDocument.h" #include "Node.h" #include "NotImplemented.h" @@ -36,8 +39,11 @@ namespace WebCore { HTML5Tokenizer::HTML5Tokenizer(HTMLDocument* document, bool reportErrors) : Tokenizer() + , m_document(document) , m_lexer(new HTML5Lexer) + , m_scriptRunner(new HTML5ScriptRunner(document, this)) , m_treeBuilder(new HTML5TreeBuilder(m_lexer.get(), document, reportErrors)) + , m_wasWaitingOnScriptsDuringFinish(false) { begin(); } @@ -50,33 +56,127 @@ void HTML5Tokenizer::begin() { } -void HTML5Tokenizer::write(const SegmentedString& source, bool) +void HTML5Tokenizer::pumpLexer() { - m_source.append(source); + ASSERT(!m_treeBuilder->isPaused()); + while (m_lexer->nextToken(m_source, m_token)) { + m_treeBuilder->constructTreeFromToken(m_token); + m_token.clear(); - HTML5Token token; - while (!m_source.isEmpty()) { - if (m_lexer->nextToken(m_source, token)) { - m_treeBuilder->constructTreeFromToken(token); - token.clear(); - } + if (!m_treeBuilder->isPaused()) + continue; + + // The parser will pause itself when waiting on a script to load or run. + // ScriptRunner executes scripts at the right times and handles reentrancy. + bool shouldContinueParsing = m_scriptRunner->execute(m_treeBuilder->takeScriptToProcess()); + m_treeBuilder->setPaused(!shouldContinueParsing); + if (!shouldContinueParsing) + return; } } +void HTML5Tokenizer::write(const SegmentedString& source, bool) +{ + // HTML5Tokenizer::executeScript is responsible for handling saving m_source before re-entry. + m_source.append(source); + if (!m_treeBuilder->isPaused()) + pumpLexer(); +} + void HTML5Tokenizer::end() { + m_source.close(); + if (!m_treeBuilder->isPaused()) + pumpLexer(); m_treeBuilder->finished(); } void HTML5Tokenizer::finish() { + // finish() indicates we will not receive any more data. If we are waiting on + // an external script to load, we can't finish parsing quite yet. + if (isWaitingForScripts()) { + // FIXME: We might want to use real state enum instead of a bool here. + m_wasWaitingOnScriptsDuringFinish = true; + return; + } + // We can't call m_source.close() yet as we may have a <script> execution + // pending which will call document.write(). No more data off the network though. end(); } +int HTML5Tokenizer::executingScript() const +{ + return m_scriptRunner->inScriptExecution(); +} + bool HTML5Tokenizer::isWaitingForScripts() const { - notImplemented(); - return false; + return m_treeBuilder->isPaused(); +} + +void HTML5Tokenizer::resumeParsingAfterScriptExecution() +{ + ASSERT(!m_scriptRunner->inScriptExecution()); + ASSERT(!m_treeBuilder->isPaused()); + pumpLexer(); + ASSERT(m_treeBuilder->isPaused() || m_source.isEmpty()); + if (m_source.isEmpty() && m_wasWaitingOnScriptsDuringFinish) + end(); // The document already finished parsing we were just waiting on scripts when finished() was called. +} + +void HTML5Tokenizer::watchForLoad(CachedResource* cachedScript) +{ + ASSERT(!cachedScript->isLoaded()); + // addClient would call notifyFinished if the load were complete. + // Callers do not expect to be re-entered from this call, so they should + // not an already-loaded CachedResource. + cachedScript->addClient(this); +} + +void HTML5Tokenizer::stopWatchingForLoad(CachedResource* cachedScript) +{ + cachedScript->removeClient(this); +} + +void HTML5Tokenizer::executeScript(const ScriptSourceCode& sourceCode) +{ + ASSERT(m_scriptRunner->inScriptExecution()); + if (!m_document->frame()) + return; + + SegmentedString oldInsertionPoint = m_source; + m_source = SegmentedString(); + m_document->frame()->script()->executeScript(sourceCode); + // Append oldInsertionPoint onto the new (likely empty) m_source instead of + // oldInsertionPoint.prepent(m_source) as that would ASSERT if + // m_source.escaped() (it had characters pushed back onto it). + m_source.append(oldInsertionPoint); +} + +void HTML5Tokenizer::notifyFinished(CachedResource* cachedResource) +{ + ASSERT(!m_scriptRunner->inScriptExecution()); + ASSERT(m_treeBuilder->isPaused()); + bool shouldContinueParsing = m_scriptRunner->executeScriptsWaitingForLoad(cachedResource); + m_treeBuilder->setPaused(!shouldContinueParsing); + if (shouldContinueParsing) + resumeParsingAfterScriptExecution(); +} + +void HTML5Tokenizer::executeScriptsWaitingForStylesheets() +{ + // Ignore calls unless we have a script blocking the parser waiting on a + // stylesheet load. Otherwise we are currently parsing and this + // is a re-entrant call from encountering a </ style> tag. + if (!m_scriptRunner->hasScriptsWaitingForStylesheets()) + return; + ASSERT(!m_scriptRunner->inScriptExecution()); + ASSERT(m_treeBuilder->isPaused()); + bool shouldContinueParsing = m_scriptRunner->executeScriptsWaitingForStylesheets(); + m_treeBuilder->setPaused(!shouldContinueParsing); + if (shouldContinueParsing) + resumeParsingAfterScriptExecution(); } } diff --git a/WebCore/html/HTML5Tokenizer.h b/WebCore/html/HTML5Tokenizer.h index 7d503aa..b96866d 100644 --- a/WebCore/html/HTML5Tokenizer.h +++ b/WebCore/html/HTML5Tokenizer.h @@ -27,39 +27,59 @@ #define HTML5Tokenizer_h #include "CachedResourceClient.h" +#include "HTML5ScriptRunnerHost.h" +#include "HTML5Token.h" #include "SegmentedString.h" #include "Tokenizer.h" #include <wtf/OwnPtr.h> namespace WebCore { -class HTMLDocument; -class HTML5TreeBuilder; class HTML5Lexer; +class HTML5ScriptRunner; +class HTML5TreeBuilder; +class HTMLDocument; +class ScriptSourceCode; -// 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 { +// FIXME: The whole Tokenizer class system should be renamed "Parser" +// or "ParserController" as the job of this class is to drive parsing process +// but it does not itself Tokenize. +class HTML5Tokenizer : public Tokenizer, HTML5ScriptRunnerHost, CachedResourceClient { public: HTML5Tokenizer(HTMLDocument*, bool reportErrors); virtual ~HTML5Tokenizer(); + // Tokenizer virtual void begin(); virtual void write(const SegmentedString&, bool appendData); virtual void end(); virtual void finish(); + virtual int executingScript() const; virtual bool isWaitingForScripts() const; + virtual void executeScriptsWaitingForStylesheets(); + + // HTML5ScriptRunnerHost + virtual void watchForLoad(CachedResource*); + virtual void stopWatchingForLoad(CachedResource*); + virtual void executeScript(const ScriptSourceCode&); + + // CachedResourceClient + virtual void notifyFinished(CachedResource*); private: + void pumpLexer(); + void resumeParsingAfterScriptExecution(); + SegmentedString m_source; + // We hold m_token here because it might be partially complete. + HTML5Token m_token; + + HTMLDocument* m_document; OwnPtr<HTML5Lexer> m_lexer; + OwnPtr<HTML5ScriptRunner> m_scriptRunner; OwnPtr<HTML5TreeBuilder> m_treeBuilder; + bool m_wasWaitingOnScriptsDuringFinish; }; } diff --git a/WebCore/html/HTML5TreeBuilder.cpp b/WebCore/html/HTML5TreeBuilder.cpp index af53ac6..0153e94 100644 --- a/WebCore/html/HTML5TreeBuilder.cpp +++ b/WebCore/html/HTML5TreeBuilder.cpp @@ -26,19 +26,24 @@ #include "config.h" #include "HTML5TreeBuilder.h" -#include "Attribute.h" +#include "Element.h" #include "HTML5Lexer.h" #include "HTML5Token.h" #include "HTMLDocument.h" +#include "HTMLNames.h" #include "HTMLParser.h" #include "HTMLTokenizer.h" #include "NotImplemented.h" +#include <wtf/UnusedParam.h> namespace WebCore { +using namespace HTMLNames; + HTML5TreeBuilder::HTML5TreeBuilder(HTML5Lexer* lexer, HTMLDocument* document, bool reportErrors) : m_document(document) , m_reportErrors(reportErrors) + , m_isPaused(false) , m_lexer(lexer) , m_legacyHTMLParser(new HTMLParser(document, reportErrors)) { @@ -52,9 +57,9 @@ static void convertToOldStyle(HTML5Token& token, Token& oldStyleToken) { switch (token.type()) { case HTML5Token::Uninitialized: + case HTML5Token::DOCTYPE: ASSERT_NOT_REACHED(); break; - case HTML5Token::DOCTYPE: case HTML5Token::EndOfFile: ASSERT_NOT_REACHED(); notImplemented(); @@ -80,37 +85,119 @@ static void convertToOldStyle(HTML5Token& token, Token& oldStyleToken) } case HTML5Token::Comment: oldStyleToken.tagName = commentAtom; - oldStyleToken.text = token.data().impl(); + oldStyleToken.text = token.takeComment().impl(); break; case HTML5Token::Character: oldStyleToken.tagName = textAtom; - oldStyleToken.text = token.characters().impl(); + oldStyleToken.text = token.takeCharacters().impl(); break; } } +void HTML5TreeBuilder::handleScriptStartTag() +{ + notImplemented(); // The HTML frgment case? + m_lexer->setState(HTML5Lexer::ScriptDataState); + notImplemented(); // Save insertion mode. +} + +void HTML5TreeBuilder::handleScriptEndTag(Element* scriptElement) +{ + ASSERT(!m_scriptToProcess); // Caller never called takeScriptToProcess! + notImplemented(); // Save insertion mode and insertion point? + + // Pause ourselves so that parsing stops until the script can be processed by the caller. + m_isPaused = true; + m_scriptToProcess = scriptElement; +} + +PassRefPtr<Element> HTML5TreeBuilder::takeScriptToProcess() +{ + // Unpause ourselves, callers may pause us again when processing the script. + // The HTML5 spec is written as though scripts are executed inside the tree + // builder. We pause the parser to exit the tree builder, and then resume + // before running scripts. + m_isPaused = false; + return m_scriptToProcess.release(); +} + 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); + if (token.type() == HTML5Token::DOCTYPE) { + DoctypeToken doctypeToken; + doctypeToken.m_name.append(token.name().characters(), token.name().length()); + doctypeToken.m_publicID = token.publicIdentifier(); + doctypeToken.m_systemID = token.systemIdentifier(); + + m_legacyHTMLParser->parseDoctypeToken(&doctypeToken); + return 0; } + // For now, we translate into an old-style token for testing. Token oldStyleToken; convertToOldStyle(token, oldStyleToken); - return m_legacyHTMLParser->parseToken(&oldStyleToken); + RefPtr<Node> result = m_legacyHTMLParser->parseToken(&oldStyleToken); + if (token.type() == HTML5Token::StartTag) { + // This work is supposed to be done by the parser, but + // when using the old parser for we have to do this manually. + if (token.name() == scriptTag) { + handleScriptStartTag(); + m_lastScriptElement = static_pointer_cast<Element>(result); + } else if (token.name() == textareaTag || token.name() == titleTag) + m_lexer->setState(HTML5Lexer::RCDATAState); + else if (token.name() == styleTag || token.name() == iframeTag + || token.name() == xmpTag || token.name() == noembedTag) { + // FIXME: noscript and noframes may conditionally enter this state as well. + m_lexer->setState(HTML5Lexer::RAWTEXTState); + } else if (token.name() == plaintextTag) + m_lexer->setState(HTML5Lexer::PLAINTEXTState); + else if (token.name() == preTag || token.name() == listingTag) + m_lexer->skipLeadingNewLineForListing(); + } + if (token.type() == HTML5Token::EndTag) { + if (token.name() == scriptTag) { + if (m_lastScriptElement) { + handleScriptEndTag(m_lastScriptElement.get()); + m_lastScriptElement = 0; + } + } + } + return result.release(); } PassRefPtr<Node> HTML5TreeBuilder::constructTreeFromToken(HTML5Token& token) { - return passTokenToLegacyParser(token); - // Our HTML5 parser implementation will go here in a separate patch. + // Make MSVC ignore our unreachable code for now. + if (true) + return passTokenToLegacyParser(token); + + // HTML5 expects the tokenizer to call the parser every time a character is + // emitted. We instead collect characters and call the parser with a batch. + // In order to make our first-pass parser code simple, processToken matches + // the spec in only handling one character at a time. + if (token.type() == HTML5Token::Character) { + HTML5Token::DataVector characters = token.characters(); + HTML5Token::DataVector::const_iterator itr = characters.begin(); + for (;itr; ++itr) + processToken(token, *itr); + return 0; // FIXME: Should we be returning the Text node? + } + return processToken(token); +} + +PassRefPtr<Node> HTML5TreeBuilder::processToken(HTML5Token& token, UChar currentCharacter) +{ + UNUSED_PARAM(token); + UNUSED_PARAM(currentCharacter); + // Implementation coming in the next patch. + return 0; } void HTML5TreeBuilder::finished() { + // We should call m_document->finishedParsing() here, except + // m_legacyHTMLParser->finished() does it for us. m_legacyHTMLParser->finished(); } diff --git a/WebCore/html/HTML5TreeBuilder.h b/WebCore/html/HTML5TreeBuilder.h index 466fd6e..ee5ba47 100644 --- a/WebCore/html/HTML5TreeBuilder.h +++ b/WebCore/html/HTML5TreeBuilder.h @@ -29,9 +29,13 @@ #include <wtf/Noncopyable.h> #include <wtf/OwnPtr.h> #include <wtf/PassRefPtr.h> +#include <wtf/RefPtr.h> +#include <wtf/unicode/Unicode.h> namespace WebCore { class Document; +class Element; +class Frame; class HTML5Lexer; class HTML5Token; class HTMLDocument; @@ -43,22 +47,35 @@ public: HTML5TreeBuilder(HTML5Lexer*, HTMLDocument*, bool reportErrors); ~HTML5TreeBuilder(); + void setPaused(bool paused) { m_isPaused = paused; } + bool isPaused() { return m_isPaused; } + // The token really should be passed as a const& since it's never modified. PassRefPtr<Node> constructTreeFromToken(HTML5Token&); + // Must be called when parser is paused before calling the parser again. + PassRefPtr<Element> takeScriptToProcess(); + + // Done, close any open tags, etc. void finished(); private: PassRefPtr<Node> passTokenToLegacyParser(HTML5Token&); + PassRefPtr<Node> processToken(HTML5Token&, UChar currentCharacter = 0); + + void handleScriptStartTag(); + void handleScriptEndTag(Element*); - // We could grab m_document off the lexer if we wanted to save space. - Document* m_document; + Document* m_document; // This is only used by the m_legacyParser for now. bool m_reportErrors; + bool m_isPaused; // 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; + RefPtr<Element> m_lastScriptElement; // FIXME: This is a hack for <script> support. + RefPtr<Element> m_scriptToProcess; // Set to a <script> tag which needs processing. }; } diff --git a/WebCore/html/HTMLAudioElement.cpp b/WebCore/html/HTMLAudioElement.cpp index 6018b52..0b229ff 100644 --- a/WebCore/html/HTMLAudioElement.cpp +++ b/WebCore/html/HTMLAudioElement.cpp @@ -41,6 +41,11 @@ HTMLAudioElement::HTMLAudioElement(const QualifiedName& tagName, Document* docum ASSERT(hasTagName(audioTag)); } +PassRefPtr<HTMLAudioElement> HTMLAudioElement::create(const QualifiedName& tagName, Document* document) +{ + return new HTMLAudioElement(tagName, document); +} + PassRefPtr<HTMLAudioElement> HTMLAudioElement::createForJSConstructor(Document* document, const String& src) { RefPtr<HTMLAudioElement> audio = new HTMLAudioElement(audioTag, document); diff --git a/WebCore/html/HTMLAudioElement.h b/WebCore/html/HTMLAudioElement.h index 2f06f1a..e453486 100644 --- a/WebCore/html/HTMLAudioElement.h +++ b/WebCore/html/HTMLAudioElement.h @@ -36,9 +36,12 @@ namespace WebCore { class HTMLAudioElement : public HTMLMediaElement { public: + static PassRefPtr<HTMLAudioElement> create(const QualifiedName&, Document*); static PassRefPtr<HTMLAudioElement> createForJSConstructor(Document*, const String& src); - HTMLAudioElement(const QualifiedName&, Document*); + private: + HTMLAudioElement(const QualifiedName&, Document*); + virtual bool isVideo() const { return false; } virtual int tagPriority() const { return 5; } }; diff --git a/WebCore/html/HTMLBRElement.cpp b/WebCore/html/HTMLBRElement.cpp index 57dc011..88ddf3b 100644 --- a/WebCore/html/HTMLBRElement.cpp +++ b/WebCore/html/HTMLBRElement.cpp @@ -2,7 +2,7 @@ * Copyright (C) 1999 Lars Knoll (knoll@kde.org) * (C) 1999 Antti Koivisto (koivisto@kde.org) * (C) 2000 Simon Hausmann <hausmann@kde.org> - * Copyright (C) 2003, 2006, 2009 Apple Inc. All rights reserved. + * Copyright (C) 2003, 2006, 2009, 2010 Apple Inc. All rights reserved. * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Library General Public @@ -32,12 +32,22 @@ namespace WebCore { using namespace HTMLNames; -HTMLBRElement::HTMLBRElement(const QualifiedName& tagName, Document *doc) - : HTMLElement(tagName, doc) +HTMLBRElement::HTMLBRElement(const QualifiedName& tagName, Document* document) + : HTMLElement(tagName, document) { ASSERT(hasTagName(brTag)); } +PassRefPtr<HTMLBRElement> HTMLBRElement::create(Document* document) +{ + return new HTMLBRElement(brTag, document); +} + +PassRefPtr<HTMLBRElement> HTMLBRElement::create(const QualifiedName& tagName, Document* document) +{ + return new HTMLBRElement(tagName, document); +} + bool HTMLBRElement::mapToEntry(const QualifiedName& attrName, MappedAttributeEntry& result) const { if (attrName == clearAttr) { diff --git a/WebCore/html/HTMLBRElement.h b/WebCore/html/HTMLBRElement.h index 5ae33c8..3bb5af1 100644 --- a/WebCore/html/HTMLBRElement.h +++ b/WebCore/html/HTMLBRElement.h @@ -2,7 +2,7 @@ * Copyright (C) 1999 Lars Knoll (knoll@kde.org) * (C) 1999 Antti Koivisto (koivisto@kde.org) * (C) 2000 Simon Hausmann <hausmann@kde.org> - * Copyright (C) 2003, 2006, 2009 Apple Inc. All rights reserved. + * Copyright (C) 2003, 2006, 2009, 2010 Apple Inc. All rights reserved. * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Library General Public @@ -28,13 +28,14 @@ namespace WebCore { -class String; - class HTMLBRElement : public HTMLElement { public: - HTMLBRElement(const QualifiedName&, Document*); + static PassRefPtr<HTMLBRElement> create(Document*); + static PassRefPtr<HTMLBRElement> create(const QualifiedName&, Document*); private: + HTMLBRElement(const QualifiedName&, Document*); + virtual HTMLTagStatus endTagRequirement() const { return TagStatusForbidden; } virtual int tagPriority() const { return 0; } @@ -44,6 +45,6 @@ private: virtual RenderObject* createRenderer(RenderArena*, RenderStyle*); }; -} //namespace +} // namespace #endif diff --git a/WebCore/html/HTMLBaseElement.cpp b/WebCore/html/HTMLBaseElement.cpp index 862f072..184b9fc 100644 --- a/WebCore/html/HTMLBaseElement.cpp +++ b/WebCore/html/HTMLBaseElement.cpp @@ -2,7 +2,7 @@ * Copyright (C) 1999 Lars Knoll (knoll@kde.org) * (C) 1999 Antti Koivisto (koivisto@kde.org) * (C) 2001 Dirk Mueller (mueller@kde.org) - * Copyright (C) 2003, 2008, 2009 Apple Inc. All rights reserved. + * Copyright (C) 2003, 2008, 2009, 2010 Apple Inc. All rights reserved. * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Library General Public @@ -34,12 +34,17 @@ namespace WebCore { using namespace HTMLNames; -HTMLBaseElement::HTMLBaseElement(const QualifiedName& qName, Document* document) - : HTMLElement(qName, document) +inline HTMLBaseElement::HTMLBaseElement(const QualifiedName& tagName, Document* document) + : HTMLElement(tagName, document) { ASSERT(hasTagName(baseTag)); } +PassRefPtr<HTMLBaseElement> HTMLBaseElement::create(const QualifiedName& tagName, Document* document) +{ + return new HTMLBaseElement(tagName, document); +} + void HTMLBaseElement::parseMappedAttribute(Attribute* attr) { if (attr->name() == hrefAttr) { diff --git a/WebCore/html/HTMLBaseElement.h b/WebCore/html/HTMLBaseElement.h index 993a56f..6c2d2d8 100644 --- a/WebCore/html/HTMLBaseElement.h +++ b/WebCore/html/HTMLBaseElement.h @@ -1,7 +1,7 @@ /* * Copyright (C) 1999 Lars Knoll (knoll@kde.org) * (C) 1999 Antti Koivisto (koivisto@kde.org) - * Copyright (C) 2003, 2009 Apple Inc. All rights reserved. + * Copyright (C) 2003, 2009, 2010 Apple Inc. All rights reserved. * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Library General Public @@ -29,9 +29,11 @@ namespace WebCore { class HTMLBaseElement : public HTMLElement { public: - HTMLBaseElement(const QualifiedName&, Document*); + static PassRefPtr<HTMLBaseElement> create(const QualifiedName&, Document*); private: + HTMLBaseElement(const QualifiedName&, Document*); + virtual HTMLTagStatus endTagRequirement() const { return TagStatusForbidden; } virtual int tagPriority() const { return 0; } @@ -51,6 +53,6 @@ private: String m_target; }; -} //namespace +} // namespace #endif diff --git a/WebCore/html/HTMLBaseFontElement.cpp b/WebCore/html/HTMLBaseFontElement.cpp index 9acbf73..1ac9ce6 100644 --- a/WebCore/html/HTMLBaseFontElement.cpp +++ b/WebCore/html/HTMLBaseFontElement.cpp @@ -1,7 +1,7 @@ /* * Copyright (C) 1999 Lars Knoll (knoll@kde.org) * (C) 1999 Antti Koivisto (koivisto@kde.org) - * Copyright (C) 2003, 2004, 2005, 2006, 2009 Apple Inc. All rights reserved. + * Copyright (C) 2003, 2004, 2005, 2006, 2009, 2010 Apple Inc. All rights reserved. * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Library General Public @@ -29,12 +29,17 @@ namespace WebCore { using namespace HTMLNames; -HTMLBaseFontElement::HTMLBaseFontElement(const QualifiedName& tagName, Document* document) +inline HTMLBaseFontElement::HTMLBaseFontElement(const QualifiedName& tagName, Document* document) : HTMLElement(tagName, document) { ASSERT(hasTagName(basefontTag)); } +PassRefPtr<HTMLBaseFontElement> HTMLBaseFontElement::create(const QualifiedName& tagName, Document* document) +{ + return new HTMLBaseFontElement(tagName, document); +} + int HTMLBaseFontElement::size() const { return getAttribute(sizeAttr).toInt(); diff --git a/WebCore/html/HTMLBaseFontElement.h b/WebCore/html/HTMLBaseFontElement.h index e76d07f..82f9a32 100644 --- a/WebCore/html/HTMLBaseFontElement.h +++ b/WebCore/html/HTMLBaseFontElement.h @@ -1,7 +1,7 @@ /* * Copyright (C) 1999 Lars Knoll (knoll@kde.org) * (C) 1999 Antti Koivisto (koivisto@kde.org) - * Copyright (C) 2003, 2004, 2005, 2006, 2009 Apple Inc. All rights reserved. + * Copyright (C) 2003, 2004, 2005, 2006, 2009, 2010 Apple Inc. All rights reserved. * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Library General Public @@ -29,12 +29,14 @@ namespace WebCore { class HTMLBaseFontElement : public HTMLElement { public: - HTMLBaseFontElement(const QualifiedName&, Document*); + static PassRefPtr<HTMLBaseFontElement> create(const QualifiedName&, Document*); int size() const; void setSize(int); private: + HTMLBaseFontElement(const QualifiedName&, Document*); + virtual HTMLTagStatus endTagRequirement() const { return TagStatusForbidden; } virtual int tagPriority() const { return 0; } }; diff --git a/WebCore/html/HTMLBlockquoteElement.cpp b/WebCore/html/HTMLBlockquoteElement.cpp index c064ad3..88437d8 100644 --- a/WebCore/html/HTMLBlockquoteElement.cpp +++ b/WebCore/html/HTMLBlockquoteElement.cpp @@ -1,7 +1,7 @@ /* * Copyright (C) 1999 Lars Knoll (knoll@kde.org) * (C) 1999 Antti Koivisto (koivisto@kde.org) - * Copyright (C) 2003, 2009 Apple Inc. All rights reserved. + * Copyright (C) 2003, 2009, 2010 Apple Inc. All rights reserved. * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Library General Public @@ -35,4 +35,14 @@ HTMLBlockquoteElement::HTMLBlockquoteElement(const QualifiedName& tagName, Docum ASSERT(hasTagName(blockquoteTag)); } +PassRefPtr<HTMLBlockquoteElement> HTMLBlockquoteElement::create(Document* document) +{ + return new HTMLBlockquoteElement(blockquoteTag, document); +} + +PassRefPtr<HTMLBlockquoteElement> HTMLBlockquoteElement::create(const QualifiedName& tagName, Document* document) +{ + return new HTMLBlockquoteElement(tagName, document); +} + } diff --git a/WebCore/html/HTMLBlockquoteElement.h b/WebCore/html/HTMLBlockquoteElement.h index f27d258..3f46d63 100644 --- a/WebCore/html/HTMLBlockquoteElement.h +++ b/WebCore/html/HTMLBlockquoteElement.h @@ -1,7 +1,7 @@ /* * Copyright (C) 1999 Lars Knoll (knoll@kde.org) * (C) 1999 Antti Koivisto (koivisto@kde.org) - * Copyright (C) 2009 Apple Inc. + * Copyright (C) 2009, 2010 Apple Inc. All rights reserved. * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Library General Public @@ -29,9 +29,12 @@ namespace WebCore { class HTMLBlockquoteElement : public HTMLElement { public: - HTMLBlockquoteElement(const QualifiedName&, Document*); + static PassRefPtr<HTMLBlockquoteElement> create(Document*); + static PassRefPtr<HTMLBlockquoteElement> create(const QualifiedName&, Document*); private: + HTMLBlockquoteElement(const QualifiedName&, Document*); + virtual HTMLTagStatus endTagRequirement() const { return TagStatusRequired; } virtual int tagPriority() const { return 5; } }; diff --git a/WebCore/html/HTMLBodyElement.cpp b/WebCore/html/HTMLBodyElement.cpp index 9e39cb3..d52ab6e 100644 --- a/WebCore/html/HTMLBodyElement.cpp +++ b/WebCore/html/HTMLBodyElement.cpp @@ -3,7 +3,7 @@ * (C) 1999 Antti Koivisto (koivisto@kde.org) * (C) 2000 Simon Hausmann (hausmann@kde.org) * (C) 2001 Dirk Mueller (mueller@kde.org) - * Copyright (C) 2004, 2006, 2007, 2008, 2009 Apple Inc. All rights reserved. + * Copyright (C) 2004, 2006, 2007, 2008, 2009, 2010 Apple Inc. All rights reserved. * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Library General Public @@ -50,6 +50,16 @@ HTMLBodyElement::HTMLBodyElement(const QualifiedName& tagName, Document* documen ASSERT(hasTagName(bodyTag)); } +PassRefPtr<HTMLBodyElement> HTMLBodyElement::create(Document* document) +{ + return new HTMLBodyElement(bodyTag, document); +} + +PassRefPtr<HTMLBodyElement> HTMLBodyElement::create(const QualifiedName& tagName, Document* document) +{ + return new HTMLBodyElement(tagName, document); +} + HTMLBodyElement::~HTMLBodyElement() { if (m_linkDecl) { @@ -267,7 +277,7 @@ void HTMLBodyElement::setVLink(const String& value) static int adjustForZoom(int value, FrameView* frameView) { - float zoomFactor = frameView->frame()->zoomFactor(); + float zoomFactor = frameView->zoomFactor(); if (zoomFactor == 1) return value; // Needed because of truncation (rather than rounding) when scaling up. @@ -287,12 +297,12 @@ int HTMLBodyElement::scrollLeft() const void HTMLBodyElement::setScrollLeft(int scrollLeft) { - FrameView* sview = ownerDocument()->view(); - if (sview) { - // Update the document's layout - document()->updateLayoutIgnorePendingStylesheets(); - sview->setScrollPosition(IntPoint(static_cast<int>(scrollLeft * sview->frame()->zoomFactor()), sview->scrollY())); - } + Document* document = this->document(); + document->updateLayoutIgnorePendingStylesheets(); + FrameView* view = document->view(); + if (!view) + return; + view->setScrollPosition(IntPoint(static_cast<int>(scrollLeft * view->zoomFactor()), view->scrollY())); } int HTMLBodyElement::scrollTop() const @@ -306,12 +316,12 @@ int HTMLBodyElement::scrollTop() const void HTMLBodyElement::setScrollTop(int scrollTop) { - FrameView* sview = ownerDocument()->view(); - if (sview) { - // Update the document's layout - document()->updateLayoutIgnorePendingStylesheets(); - sview->setScrollPosition(IntPoint(sview->scrollX(), static_cast<int>(scrollTop * sview->frame()->zoomFactor()))); - } + Document* document = this->document(); + document->updateLayoutIgnorePendingStylesheets(); + FrameView* view = document->view(); + if (!view) + return; + view->setScrollPosition(IntPoint(view->scrollX(), static_cast<int>(scrollTop * view->zoomFactor()))); } int HTMLBodyElement::scrollHeight() const diff --git a/WebCore/html/HTMLBodyElement.h b/WebCore/html/HTMLBodyElement.h index f2c1f98..7b32549 100644 --- a/WebCore/html/HTMLBodyElement.h +++ b/WebCore/html/HTMLBodyElement.h @@ -2,7 +2,7 @@ * Copyright (C) 1999 Lars Knoll (knoll@kde.org) * (C) 1999 Antti Koivisto (koivisto@kde.org) * (C) 2000 Simon Hausmann <hausmann@kde.org> - * Copyright (C) 2004, 2006, 2009 Apple Inc. All rights reserved. + * Copyright (C) 2004, 2006, 2009, 2010 Apple Inc. All rights reserved. * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Library General Public @@ -31,7 +31,8 @@ namespace WebCore { class HTMLBodyElement : public HTMLElement { public: - HTMLBodyElement(const QualifiedName&, Document*); + static PassRefPtr<HTMLBodyElement> create(Document*); + static PassRefPtr<HTMLBodyElement> create(const QualifiedName&, Document*); virtual ~HTMLBodyElement(); String aLink() const; @@ -66,6 +67,8 @@ public: #endif private: + HTMLBodyElement(const QualifiedName&, Document*); + virtual HTMLTagStatus endTagRequirement() const { return TagStatusRequired; } virtual int tagPriority() const { return 10; } diff --git a/WebCore/html/HTMLButtonElement.cpp b/WebCore/html/HTMLButtonElement.cpp index 2ef932b..2775b82 100644 --- a/WebCore/html/HTMLButtonElement.cpp +++ b/WebCore/html/HTMLButtonElement.cpp @@ -40,16 +40,17 @@ namespace WebCore { using namespace HTMLNames; -HTMLButtonElement::HTMLButtonElement(const QualifiedName& tagName, Document* doc, HTMLFormElement* form) - : HTMLFormControlElement(tagName, doc, form) +inline HTMLButtonElement::HTMLButtonElement(const QualifiedName& tagName, Document* document, HTMLFormElement* form) + : HTMLFormControlElement(tagName, document, form) , m_type(SUBMIT) , m_activeSubmit(false) { ASSERT(hasTagName(buttonTag)); } -HTMLButtonElement::~HTMLButtonElement() +PassRefPtr<HTMLButtonElement> HTMLButtonElement::create(const QualifiedName& tagName, Document* document, HTMLFormElement* form) { + return new HTMLButtonElement(tagName, document, form); } RenderObject* HTMLButtonElement::createRenderer(RenderArena* arena, RenderStyle*) diff --git a/WebCore/html/HTMLButtonElement.h b/WebCore/html/HTMLButtonElement.h index 92951c3..aefb27a 100644 --- a/WebCore/html/HTMLButtonElement.h +++ b/WebCore/html/HTMLButtonElement.h @@ -2,7 +2,7 @@ * Copyright (C) 1999 Lars Knoll (knoll@kde.org) * (C) 1999 Antti Koivisto (koivisto@kde.org) * (C) 2000 Dirk Mueller (mueller@kde.org) - * Copyright (C) 2004, 2005, 2006, 2007 Apple Inc. All rights reserved. + * Copyright (C) 2004, 2005, 2006, 2007, 2010 Apple Inc. All rights reserved. * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Library General Public @@ -30,8 +30,18 @@ namespace WebCore { class HTMLButtonElement : public HTMLFormControlElement { public: - HTMLButtonElement(const QualifiedName&, Document*, HTMLFormElement* = 0); - virtual ~HTMLButtonElement(); + static PassRefPtr<HTMLButtonElement> create(const QualifiedName&, Document*, HTMLFormElement*); + + String accessKey() const; + void setAccessKey(const String&); + + String value() const; + void setValue(const String&); + +private: + HTMLButtonElement(const QualifiedName& tagName, Document*, HTMLFormElement*); + + enum Type { SUBMIT, RESET, BUTTON }; virtual const AtomicString& formControlType() const; @@ -51,14 +61,6 @@ public: virtual bool canStartSelection() const { return false; } - String accessKey() const; - void setAccessKey(const String&); - - String value() const; - void setValue(const String&); - -private: - enum Type { SUBMIT, RESET, BUTTON }; virtual bool isOptionalFormControl() const { return true; } virtual bool recalcWillValidate() const { return false; } diff --git a/WebCore/html/HTMLButtonElement.idl b/WebCore/html/HTMLButtonElement.idl index 73098fe..cf9f648 100644 --- a/WebCore/html/HTMLButtonElement.idl +++ b/WebCore/html/HTMLButtonElement.idl @@ -35,6 +35,7 @@ module html { boolean checkValidity(); void setCustomValidity(in [ConvertUndefinedOrNullToNullString] DOMString error); void click(); + readonly attribute NodeList labels; }; } diff --git a/WebCore/html/HTMLCanvasElement.cpp b/WebCore/html/HTMLCanvasElement.cpp index 205cf28..c9e4620 100644 --- a/WebCore/html/HTMLCanvasElement.cpp +++ b/WebCore/html/HTMLCanvasElement.cpp @@ -54,15 +54,25 @@ namespace WebCore { using namespace HTMLNames; -HTMLCanvasElement::HTMLCanvasElement(const QualifiedName& tagName, Document* doc) - : HTMLElement(tagName, doc) - , CanvasSurface(doc->frame() ? doc->frame()->page()->chrome()->scaleFactor() : 1) +HTMLCanvasElement::HTMLCanvasElement(const QualifiedName& tagName, Document* document) + : HTMLElement(tagName, document) + , CanvasSurface(document->frame() ? document->frame()->page()->chrome()->scaleFactor() : 1) , m_observer(0) , m_ignoreReset(false) { ASSERT(hasTagName(canvasTag)); } +PassRefPtr<HTMLCanvasElement> HTMLCanvasElement::create(Document* document) +{ + return new HTMLCanvasElement(canvasTag, document); +} + +PassRefPtr<HTMLCanvasElement> HTMLCanvasElement::create(const QualifiedName& tagName, Document* document) +{ + return new HTMLCanvasElement(tagName, document); +} + HTMLCanvasElement::~HTMLCanvasElement() { if (m_observer) diff --git a/WebCore/html/HTMLCanvasElement.h b/WebCore/html/HTMLCanvasElement.h index a7f42ce..ebd9378 100644 --- a/WebCore/html/HTMLCanvasElement.h +++ b/WebCore/html/HTMLCanvasElement.h @@ -1,5 +1,5 @@ /* - * Copyright (C) 2004, 2006, 2009 Apple Inc. All rights reserved. + * Copyright (C) 2004, 2006, 2009, 2010 Apple Inc. All rights reserved. * Copyright (C) 2007 Alp Toker <alp@atoker.com> * * Redistribution and use in source and binary forms, with or without @@ -30,10 +30,11 @@ #include "CanvasSurface.h" #include "FloatRect.h" #include "HTMLElement.h" +#include "IntSize.h" + #if ENABLE(3D_CANVAS) #include "GraphicsContext3D.h" #endif -#include "IntSize.h" namespace WebCore { @@ -54,7 +55,8 @@ public: class HTMLCanvasElement : public HTMLElement, public CanvasSurface { public: - HTMLCanvasElement(const QualifiedName&, Document*); + static PassRefPtr<HTMLCanvasElement> create(Document*); + static PassRefPtr<HTMLCanvasElement> create(const QualifiedName&, Document*); virtual ~HTMLCanvasElement(); void setWidth(int); @@ -105,6 +107,8 @@ public: #endif private: + HTMLCanvasElement(const QualifiedName&, Document*); + #if ENABLE(DASHBOARD_SUPPORT) virtual HTMLTagStatus endTagRequirement() const; virtual int tagPriority() const; diff --git a/WebCore/html/HTMLCanvasElement.idl b/WebCore/html/HTMLCanvasElement.idl index ea7f982..656d6ae 100644 --- a/WebCore/html/HTMLCanvasElement.idl +++ b/WebCore/html/HTMLCanvasElement.idl @@ -1,5 +1,6 @@ /* * Copyright (C) 2006, 2008, 2009 Apple Inc. All rights reserved. + * Copyright (C) 2010 Torch Mobile (Beijing) Co. Ltd. All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions @@ -32,7 +33,7 @@ module html { attribute long width; attribute long height; - DOMString toDataURL(in [ConvertUndefinedOrNullToNullString] DOMString type) + [Custom] DOMString toDataURL(in [ConvertUndefinedOrNullToNullString] DOMString type) raises(DOMException); #if !defined(LANGUAGE_OBJECTIVE_C) || !LANGUAGE_OBJECTIVE_C diff --git a/WebCore/html/HTMLDListElement.cpp b/WebCore/html/HTMLDListElement.cpp index 8681332..e3720e0 100644 --- a/WebCore/html/HTMLDListElement.cpp +++ b/WebCore/html/HTMLDListElement.cpp @@ -1,6 +1,7 @@ -/** +/* * Copyright (C) 1999 Lars Knoll (knoll@kde.org) * (C) 1999 Antti Koivisto (koivisto@kde.org) + * Copyright (C) 2010 Apple Inc. All rights reserved. * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Library General Public @@ -18,6 +19,7 @@ * Boston, MA 02110-1301, USA. * */ + #include "config.h" #include "HTMLDListElement.h" @@ -27,12 +29,17 @@ namespace WebCore { using namespace HTMLNames; -HTMLDListElement::HTMLDListElement(const QualifiedName& tagName, Document* doc) - : HTMLElement(tagName, doc) +inline HTMLDListElement::HTMLDListElement(const QualifiedName& tagName, Document* document) + : HTMLElement(tagName, document) { ASSERT(hasTagName(dlTag)); } +PassRefPtr<HTMLDListElement> HTMLDListElement::create(const QualifiedName& tagName, Document* document) +{ + return new HTMLDListElement(tagName, document); +} + bool HTMLDListElement::compact() const { return !getAttribute(compactAttr).isNull(); diff --git a/WebCore/html/HTMLDListElement.h b/WebCore/html/HTMLDListElement.h index 49c944b..906109e 100644 --- a/WebCore/html/HTMLDListElement.h +++ b/WebCore/html/HTMLDListElement.h @@ -1,6 +1,7 @@ /* * Copyright (C) 1999 Lars Knoll (knoll@kde.org) * (C) 1999 Antti Koivisto (koivisto@kde.org) + * Copyright (C) 2010 Apple Inc. All rights reserved. * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Library General Public @@ -28,13 +29,16 @@ namespace WebCore { class HTMLDListElement : public HTMLElement { public: + static PassRefPtr<HTMLDListElement> create(const QualifiedName&, Document*); + + bool compact() const; + void setCompact(bool); + +private: HTMLDListElement(const QualifiedName&, Document*); virtual HTMLTagStatus endTagRequirement() const { return TagStatusRequired; } virtual int tagPriority() const { return 5; } - - bool compact() const; - void setCompact(bool); }; } //namespace diff --git a/WebCore/html/HTMLDataGridCellElement.cpp b/WebCore/html/HTMLDataGridCellElement.cpp index bad8929..3085680 100644 --- a/WebCore/html/HTMLDataGridCellElement.cpp +++ b/WebCore/html/HTMLDataGridCellElement.cpp @@ -1,5 +1,5 @@ /* - * Copyright (C) 2009 Apple Inc. All rights reserved. + * Copyright (C) 2009, 2010 Apple Inc. All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions @@ -30,17 +30,21 @@ #include "HTMLDataGridCellElement.h" #include "HTMLNames.h" -#include "Text.h" namespace WebCore { using namespace HTMLNames; -HTMLDataGridCellElement::HTMLDataGridCellElement(const QualifiedName& name, Document* doc) - : HTMLElement(name, doc) +inline HTMLDataGridCellElement::HTMLDataGridCellElement(const QualifiedName& name, Document* document) + : HTMLElement(name, document) { } +PassRefPtr<HTMLDataGridCellElement> HTMLDataGridCellElement::create(const QualifiedName& name, Document* document) +{ + return new HTMLDataGridCellElement(name, document); +} + String HTMLDataGridCellElement::label() const { return getAttribute(labelAttr); diff --git a/WebCore/html/HTMLDataGridCellElement.h b/WebCore/html/HTMLDataGridCellElement.h index 270835c..567ec23 100644 --- a/WebCore/html/HTMLDataGridCellElement.h +++ b/WebCore/html/HTMLDataGridCellElement.h @@ -1,5 +1,5 @@ /* - * Copyright (C) 2009 Apple Inc. All rights reserved. + * Copyright (C) 2009, 2010 Apple Inc. All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions @@ -34,11 +34,8 @@ namespace WebCore { class HTMLDataGridCellElement : public HTMLElement { public: - HTMLDataGridCellElement(const QualifiedName&, Document*); + static PassRefPtr<HTMLDataGridCellElement> create(const QualifiedName&, Document*); - virtual HTMLTagStatus endTagRequirement() const { return TagStatusForbidden; } - virtual int tagPriority() const { return 0; } - String label() const; void setLabel(const String&); @@ -53,6 +50,13 @@ public: float progress() const; void setProgress(float); + +private: + HTMLDataGridCellElement(const QualifiedName&, Document*); + + virtual HTMLTagStatus endTagRequirement() const { return TagStatusForbidden; } + virtual int tagPriority() const { return 0; } + }; } // namespace WebCore diff --git a/WebCore/html/HTMLDataGridColElement.cpp b/WebCore/html/HTMLDataGridColElement.cpp index 7f02aa5..be2b7f2 100644 --- a/WebCore/html/HTMLDataGridColElement.cpp +++ b/WebCore/html/HTMLDataGridColElement.cpp @@ -1,5 +1,5 @@ /* - * Copyright (C) 2009 Apple Inc. All rights reserved. + * Copyright (C) 2009, 2010 Apple Inc. All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions @@ -38,12 +38,17 @@ namespace WebCore { using namespace HTMLNames; -HTMLDataGridColElement::HTMLDataGridColElement(const QualifiedName& name, Document* doc) - : HTMLElement(name, doc) +inline HTMLDataGridColElement::HTMLDataGridColElement(const QualifiedName& name, Document* document) + : HTMLElement(name, document) , m_dataGrid(0) { } +PassRefPtr<HTMLDataGridColElement> HTMLDataGridColElement::create(const QualifiedName& name, Document* document) +{ + return new HTMLDataGridColElement(name, document); +} + HTMLDataGridElement* HTMLDataGridColElement::findDataGridAncestor() const { if (parent() && parent()->hasTagName(datagridTag)) diff --git a/WebCore/html/HTMLDataGridColElement.h b/WebCore/html/HTMLDataGridColElement.h index 2ee284b..701bc42 100644 --- a/WebCore/html/HTMLDataGridColElement.h +++ b/WebCore/html/HTMLDataGridColElement.h @@ -1,5 +1,5 @@ /* - * Copyright (C) 2009 Apple Inc. All rights reserved. + * Copyright (C) 2009, 2010 Apple Inc. All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions @@ -37,13 +37,7 @@ class HTMLDataGridElement; class HTMLDataGridColElement : public HTMLElement { public: - HTMLDataGridColElement(const QualifiedName&, Document*); - - virtual HTMLTagStatus endTagRequirement() const { return TagStatusForbidden; } - virtual int tagPriority() const { return 0; } - virtual void insertedIntoTree(bool /*deep*/); - virtual void removedFromTree(bool /*deep*/); - virtual void parseMappedAttribute(Attribute*); + static PassRefPtr<HTMLDataGridColElement> create(const QualifiedName&, Document*); String label() const; void setLabel(const String&); @@ -64,6 +58,14 @@ public: void setColumn(PassRefPtr<DataGridColumn> col) { m_column = col; } private: + HTMLDataGridColElement(const QualifiedName&, Document*); + + virtual HTMLTagStatus endTagRequirement() const { return TagStatusForbidden; } + virtual int tagPriority() const { return 0; } + virtual void insertedIntoTree(bool /*deep*/); + virtual void removedFromTree(bool /*deep*/); + virtual void parseMappedAttribute(Attribute*); + HTMLDataGridElement* dataGrid() const { return m_dataGrid; } HTMLDataGridElement* findDataGridAncestor() const; void ensureColumn(); diff --git a/WebCore/html/HTMLDataGridElement.cpp b/WebCore/html/HTMLDataGridElement.cpp index bb1f4a6..5753748 100644 --- a/WebCore/html/HTMLDataGridElement.cpp +++ b/WebCore/html/HTMLDataGridElement.cpp @@ -1,5 +1,5 @@ /* - * Copyright (C) 2009 Apple Inc. All rights reserved. + * Copyright (C) 2009, 2010 Apple Inc. All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions @@ -38,13 +38,18 @@ namespace WebCore { using namespace HTMLNames; -HTMLDataGridElement::HTMLDataGridElement(const QualifiedName& tagName, Document* document) +inline HTMLDataGridElement::HTMLDataGridElement(const QualifiedName& tagName, Document* document) : HTMLElement(tagName, document) , m_columns(DataGridColumnList::create(this)) { setDataSource(DOMDataGridDataSource::create()); } +PassRefPtr<HTMLDataGridElement> HTMLDataGridElement::create(const QualifiedName& tagName, Document* document) +{ + return new HTMLDataGridElement(tagName, document); +} + HTMLDataGridElement::~HTMLDataGridElement() { m_columns->clearDataGrid(); diff --git a/WebCore/html/HTMLDataGridElement.h b/WebCore/html/HTMLDataGridElement.h index 94672c1..e29bf98 100644 --- a/WebCore/html/HTMLDataGridElement.h +++ b/WebCore/html/HTMLDataGridElement.h @@ -1,5 +1,5 @@ /* - * Copyright (C) 2009 Apple Inc. All rights reserved. + * Copyright (C) 2009, 2010 Apple Inc. All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions @@ -31,20 +31,14 @@ #include "DataGridColumnList.h" #include "DataGridDataSource.h" #include "HTMLElement.h" -#include "Timer.h" namespace WebCore { class HTMLDataGridElement : public HTMLElement { public: - HTMLDataGridElement(const QualifiedName&, Document*); + static PassRefPtr<HTMLDataGridElement> create(const QualifiedName&, Document*); virtual ~HTMLDataGridElement(); - virtual int tagPriority() const { return 6; } // Same as <select>s - virtual bool checkDTD(const Node*); - - virtual RenderObject* createRenderer(RenderArena*, RenderStyle*); - bool autofocus() const; void setAutofocus(bool); @@ -60,6 +54,13 @@ public: DataGridColumnList* columns() const { return m_columns.get(); } private: + HTMLDataGridElement(const QualifiedName&, Document*); + + virtual int tagPriority() const { return 6; } // Same as <select>s + virtual bool checkDTD(const Node*); + + virtual RenderObject* createRenderer(RenderArena*, RenderStyle*); + RefPtr<DataGridDataSource> m_dataSource; RefPtr<DataGridColumnList> m_columns; }; diff --git a/WebCore/html/HTMLDataGridRowElement.cpp b/WebCore/html/HTMLDataGridRowElement.cpp index c958cbd..bab2a92 100644 --- a/WebCore/html/HTMLDataGridRowElement.cpp +++ b/WebCore/html/HTMLDataGridRowElement.cpp @@ -1,5 +1,5 @@ /* - * Copyright (C) 2009 Apple Inc. All rights reserved. + * Copyright (C) 2009, 2010 Apple Inc. All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions @@ -30,17 +30,21 @@ #include "HTMLDataGridRowElement.h" #include "HTMLNames.h" -#include "Text.h" namespace WebCore { using namespace HTMLNames; -HTMLDataGridRowElement::HTMLDataGridRowElement(const QualifiedName& name, Document* doc) - : HTMLElement(name, doc) +inline HTMLDataGridRowElement::HTMLDataGridRowElement(const QualifiedName& name, Document* document) + : HTMLElement(name, document) { } +PassRefPtr<HTMLDataGridRowElement> HTMLDataGridRowElement::create(const QualifiedName& name, Document* document) +{ + return new HTMLDataGridRowElement(name, document); +} + bool HTMLDataGridRowElement::checkDTD(const Node* newChild) { if (newChild->isTextNode()) diff --git a/WebCore/html/HTMLDataGridRowElement.h b/WebCore/html/HTMLDataGridRowElement.h index eac33e6..81be914 100644 --- a/WebCore/html/HTMLDataGridRowElement.h +++ b/WebCore/html/HTMLDataGridRowElement.h @@ -1,5 +1,5 @@ /* - * Copyright (C) 2009 Apple Inc. All rights reserved. + * Copyright (C) 2009, 2010 Apple Inc. All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions @@ -34,10 +34,7 @@ namespace WebCore { class HTMLDataGridRowElement : public HTMLElement { public: - HTMLDataGridRowElement(const QualifiedName&, Document*); - - virtual int tagPriority() const { return 2; } // Same as <option>s. - virtual bool checkDTD(const Node*); + static PassRefPtr<HTMLDataGridRowElement> create(const QualifiedName&, Document*); bool selected() const; void setSelected(bool); @@ -47,6 +44,12 @@ public: bool expanded() const; void setExpanded(bool); + +private: + HTMLDataGridRowElement(const QualifiedName&, Document*); + + virtual int tagPriority() const { return 2; } // Same as <option>s. + virtual bool checkDTD(const Node*); }; } // namespace WebCore diff --git a/WebCore/html/HTMLDataListElement.cpp b/WebCore/html/HTMLDataListElement.cpp index a6ca525..a9a60a1 100644 --- a/WebCore/html/HTMLDataListElement.cpp +++ b/WebCore/html/HTMLDataListElement.cpp @@ -1,5 +1,6 @@ /* - * Copyright (c) 2009, Google Inc. All rights reserved. + * Copyright (C) 2009 Google Inc. All rights reserved. + * Copyright (C) 2010 Apple Inc. All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are @@ -36,13 +37,14 @@ namespace WebCore { -HTMLDataListElement::HTMLDataListElement(const QualifiedName& tagName, Document *doc) - : HTMLElement(tagName, doc) +inline HTMLDataListElement::HTMLDataListElement(const QualifiedName& tagName, Document* document) + : HTMLElement(tagName, document) { } -HTMLDataListElement::~HTMLDataListElement() +PassRefPtr<HTMLDataListElement> HTMLDataListElement::create(const QualifiedName& tagName, Document* document) { + return new HTMLDataListElement(tagName, document); } bool HTMLDataListElement::checkDTD(const Node* newChild) diff --git a/WebCore/html/HTMLDataListElement.h b/WebCore/html/HTMLDataListElement.h index 8c4cfbc..3587234 100644 --- a/WebCore/html/HTMLDataListElement.h +++ b/WebCore/html/HTMLDataListElement.h @@ -1,5 +1,6 @@ /* * Copyright (c) 2009, Google Inc. All rights reserved. + * Copyright (C) 2010 Apple Inc. All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are @@ -38,15 +39,17 @@ namespace WebCore { - class HTMLDataListElement : public HTMLElement { - public: - HTMLDataListElement(const QualifiedName&, Document*); - virtual ~HTMLDataListElement(); - PassRefPtr<HTMLCollection> options(); +class HTMLDataListElement : public HTMLElement { +public: + static PassRefPtr<HTMLDataListElement> create(const QualifiedName&, Document*); - private: - virtual bool checkDTD(const Node*); - }; + PassRefPtr<HTMLCollection> options(); + +private: + HTMLDataListElement(const QualifiedName&, Document*); + + virtual bool checkDTD(const Node*); +}; } // namespace WebCore diff --git a/WebCore/html/HTMLDivElement.cpp b/WebCore/html/HTMLDivElement.cpp index 4482946..72f532f 100644 --- a/WebCore/html/HTMLDivElement.cpp +++ b/WebCore/html/HTMLDivElement.cpp @@ -1,7 +1,7 @@ -/** +/* * Copyright (C) 1999 Lars Knoll (knoll@kde.org) * (C) 1999 Antti Koivisto (koivisto@kde.org) - * Copyright (C) 2003 Apple Computer, Inc. + * Copyright (C) 2003, 2010 Apple Inc. All rights reserved. * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Library General Public @@ -32,14 +32,20 @@ namespace WebCore { using namespace HTMLNames; -HTMLDivElement::HTMLDivElement(const QualifiedName& tagName, Document *doc) - : HTMLElement(tagName, doc) +HTMLDivElement::HTMLDivElement(const QualifiedName& tagName, Document* document) + : HTMLElement(tagName, document) { ASSERT(hasTagName(divTag)); } -HTMLDivElement::~HTMLDivElement() +PassRefPtr<HTMLDivElement> HTMLDivElement::create(Document* document) { + return new HTMLDivElement(divTag, document); +} + +PassRefPtr<HTMLDivElement> HTMLDivElement::create(const QualifiedName& tagName, Document* document) +{ + return new HTMLDivElement(tagName, document); } bool HTMLDivElement::mapToEntry(const QualifiedName& attrName, MappedAttributeEntry& result) const diff --git a/WebCore/html/HTMLDivElement.h b/WebCore/html/HTMLDivElement.h index 8359b96..aa60275 100644 --- a/WebCore/html/HTMLDivElement.h +++ b/WebCore/html/HTMLDivElement.h @@ -1,6 +1,7 @@ /* * Copyright (C) 1999 Lars Knoll (knoll@kde.org) * (C) 1999 Antti Koivisto (koivisto@kde.org) + * Copyright (C) 2010 Apple Inc. All rights reserved. * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Library General Public @@ -28,17 +29,21 @@ namespace WebCore { class HTMLDivElement : public HTMLElement { public: + static PassRefPtr<HTMLDivElement> create(Document*); + static PassRefPtr<HTMLDivElement> create(const QualifiedName&, Document*); + + String align() const; + void setAlign(const String&); + +protected: HTMLDivElement(const QualifiedName&, Document*); - ~HTMLDivElement(); +private: virtual HTMLTagStatus endTagRequirement() const { return TagStatusRequired; } virtual int tagPriority() const { return 5; } virtual bool mapToEntry(const QualifiedName&, MappedAttributeEntry&) const; virtual void parseMappedAttribute(Attribute*); - - String align() const; - void setAlign(const String&); }; } // namespace WebCore diff --git a/WebCore/html/HTMLDocument.cpp b/WebCore/html/HTMLDocument.cpp index 5e08a99..f060adb 100644 --- a/WebCore/html/HTMLDocument.cpp +++ b/WebCore/html/HTMLDocument.cpp @@ -315,17 +315,21 @@ PassRefPtr<Element> HTMLDocument::createElement(const AtomicString& name, Except return HTMLElementFactory::createHTMLElement(QualifiedName(nullAtom, name.lower(), xhtmlNamespaceURI), this, 0, false); } -static void addItemToMap(HashCountedSet<AtomicStringImpl*>& map, const AtomicString& name) +void HTMLDocument::addItemToMap(HashCountedSet<AtomicStringImpl*>& map, const AtomicString& name) { if (name.isEmpty()) return; map.add(name.impl()); + if (Frame* f = frame()) + f->script()->namedItemAdded(this, name); } -static void removeItemFromMap(HashCountedSet<AtomicStringImpl*>& map, const AtomicString& name) +void HTMLDocument::removeItemFromMap(HashCountedSet<AtomicStringImpl*>& map, const AtomicString& name) { if (name.isEmpty()) return; + if (Frame* f = frame()) + f->script()->namedItemRemoved(this, name); map.remove(name.impl()); } diff --git a/WebCore/html/HTMLDocument.h b/WebCore/html/HTMLDocument.h index 4a8dd8b..55cf8ad 100644 --- a/WebCore/html/HTMLDocument.h +++ b/WebCore/html/HTMLDocument.h @@ -99,6 +99,9 @@ private: virtual Tokenizer* createTokenizer(); virtual void determineParseMode(); + void addItemToMap(HashCountedSet<AtomicStringImpl*>&, const AtomicString&); + void removeItemFromMap(HashCountedSet<AtomicStringImpl*>&, const AtomicString&); + HashCountedSet<AtomicStringImpl*> m_namedItemCounts; HashCountedSet<AtomicStringImpl*> m_extraNamedItemCounts; }; diff --git a/WebCore/html/HTMLElement.cpp b/WebCore/html/HTMLElement.cpp index a623f24..d95a236 100644 --- a/WebCore/html/HTMLElement.cpp +++ b/WebCore/html/HTMLElement.cpp @@ -435,7 +435,7 @@ void HTMLElement::setInnerText(const String& text, ExceptionCode& ec) return; } if (!(c == '\n' && i != 0 && prev == '\r')) { - fragment->appendChild(new HTMLBRElement(brTag, document()), ec); + fragment->appendChild(HTMLBRElement::create(document()), ec); if (ec) return; } diff --git a/WebCore/html/HTMLFieldSetElement.cpp b/WebCore/html/HTMLFieldSetElement.cpp index b792075..5e27786 100644 --- a/WebCore/html/HTMLFieldSetElement.cpp +++ b/WebCore/html/HTMLFieldSetElement.cpp @@ -2,7 +2,7 @@ * Copyright (C) 1999 Lars Knoll (knoll@kde.org) * (C) 1999 Antti Koivisto (koivisto@kde.org) * (C) 2001 Dirk Mueller (mueller@kde.org) - * Copyright (C) 2004, 2005, 2006 Apple Computer, Inc. + * Copyright (C) 2004, 2005, 2006, 2010 Apple Inc. All rights reserved. * (C) 2006 Alexey Proskuryakov (ap@nypop.com) * * This library is free software; you can redistribute it and/or @@ -33,14 +33,15 @@ namespace WebCore { using namespace HTMLNames; -HTMLFieldSetElement::HTMLFieldSetElement(const QualifiedName& tagName, Document *doc, HTMLFormElement *f) - : HTMLFormControlElement(tagName, doc, f) +inline HTMLFieldSetElement::HTMLFieldSetElement(const QualifiedName& tagName, Document* document, HTMLFormElement* form) + : HTMLFormControlElement(tagName, document, form) { ASSERT(hasTagName(fieldsetTag)); } -HTMLFieldSetElement::~HTMLFieldSetElement() +PassRefPtr<HTMLFieldSetElement> HTMLFieldSetElement::create(const QualifiedName& tagName, Document* document, HTMLFormElement* form) { + return new HTMLFieldSetElement(tagName, document, form); } bool HTMLFieldSetElement::checkDTD(const Node* newChild) diff --git a/WebCore/html/HTMLFieldSetElement.h b/WebCore/html/HTMLFieldSetElement.h index 457fe93..58c3ec4 100644 --- a/WebCore/html/HTMLFieldSetElement.h +++ b/WebCore/html/HTMLFieldSetElement.h @@ -2,7 +2,7 @@ * Copyright (C) 1999 Lars Knoll (knoll@kde.org) * (C) 1999 Antti Koivisto (koivisto@kde.org) * (C) 2000 Dirk Mueller (mueller@kde.org) - * Copyright (C) 2004, 2005, 2006 Apple Computer, Inc. + * Copyright (C) 2004, 2005, 2006, 2010 Apple Inc. All rights reserved. * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Library General Public @@ -27,30 +27,23 @@ #include "HTMLFormControlElement.h" namespace WebCore { - class RenderStyle; -} - -namespace WebCore { - -class HTMLFormElement; -class Document; -class Node; class HTMLFieldSetElement : public HTMLFormControlElement { public: - HTMLFieldSetElement(const QualifiedName&, Document*, HTMLFormElement* = 0); - virtual ~HTMLFieldSetElement(); - + static PassRefPtr<HTMLFieldSetElement> create(const QualifiedName&, Document*, HTMLFormElement*); + +private: + HTMLFieldSetElement(const QualifiedName&, Document*, HTMLFormElement*); + virtual int tagPriority() const { return 3; } virtual bool checkDTD(const Node* newChild); virtual bool supportsFocus() const; virtual RenderObject* createRenderer(RenderArena*, RenderStyle*); virtual const AtomicString& formControlType() const; -private: virtual bool recalcWillValidate() const { return false; } }; -} //namespace +} // namespace #endif diff --git a/WebCore/html/HTMLFontElement.cpp b/WebCore/html/HTMLFontElement.cpp index b6de0b8..ab103b1 100644 --- a/WebCore/html/HTMLFontElement.cpp +++ b/WebCore/html/HTMLFontElement.cpp @@ -2,7 +2,7 @@ * Copyright (C) 1999 Lars Knoll (knoll@kde.org) * (C) 1999 Antti Koivisto (koivisto@kde.org) * (C) 2000 Simon Hausmann <hausmann@kde.org> - * Copyright (C) 2003, 2006, 2008 Apple Inc. All rights reserved. + * Copyright (C) 2003, 2006, 2008, 2010 Apple Inc. All rights reserved. * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Library General Public @@ -40,6 +40,11 @@ HTMLFontElement::HTMLFontElement(const QualifiedName& tagName, Document* documen ASSERT(hasTagName(fontTag)); } +PassRefPtr<HTMLFontElement> HTMLFontElement::create(const QualifiedName& tagName, Document* document) +{ + return new HTMLFontElement(tagName, document); +} + // Allows leading spaces. // Allows trailing nonnumeric characters. // Returns 10 for any size greater than 9. diff --git a/WebCore/html/HTMLFontElement.h b/WebCore/html/HTMLFontElement.h index b3439b7..cdf7143 100644 --- a/WebCore/html/HTMLFontElement.h +++ b/WebCore/html/HTMLFontElement.h @@ -2,6 +2,7 @@ * Copyright (C) 1999 Lars Knoll (knoll@kde.org) * (C) 1999 Antti Koivisto (koivisto@kde.org) * (C) 2000 Simon Hausmann <hausmann@kde.org> + * Copyright (C) 2010 Apple Inc. All rights reserved. * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Library General Public @@ -19,6 +20,7 @@ * Boston, MA 02110-1301, USA. * */ + #ifndef HTMLFontElement_h #define HTMLFontElement_h @@ -28,14 +30,8 @@ namespace WebCore { class HTMLFontElement : public HTMLElement { public: - HTMLFontElement(const QualifiedName&, Document*); + static PassRefPtr<HTMLFontElement> create(const QualifiedName&, Document*); - virtual HTMLTagStatus endTagRequirement() const { return TagStatusRequired; } - virtual int tagPriority() const { return 1; } - - virtual bool mapToEntry(const QualifiedName&, MappedAttributeEntry&) const; - virtual void parseMappedAttribute(Attribute*); - String color() const; void setColor(const String&); @@ -46,8 +42,17 @@ public: void setSize(const String&); static bool cssValueFromFontSizeNumber(const String&, int&); + +private: + HTMLFontElement(const QualifiedName&, Document*); + + virtual HTMLTagStatus endTagRequirement() const { return TagStatusRequired; } + virtual int tagPriority() const { return 1; } + + virtual bool mapToEntry(const QualifiedName&, MappedAttributeEntry&) const; + virtual void parseMappedAttribute(Attribute*); }; -} //namespace +} // namespace #endif diff --git a/WebCore/html/HTMLFormCollection.cpp b/WebCore/html/HTMLFormCollection.cpp index 65c48fe..e140a03 100644 --- a/WebCore/html/HTMLFormCollection.cpp +++ b/WebCore/html/HTMLFormCollection.cpp @@ -1,7 +1,7 @@ /* * Copyright (C) 1999 Lars Knoll (knoll@kde.org) * (C) 1999 Antti Koivisto (koivisto@kde.org) - * Copyright (C) 2003, 2004, 2005, 2006, 2007 Apple Inc. All rights reserved. + * Copyright (C) 2003, 2004, 2005, 2006, 2007, 2010 Apple Inc. All rights reserved. * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Library General Public @@ -38,9 +38,9 @@ using namespace HTMLNames; inline CollectionCache* HTMLFormCollection::formCollectionInfo(HTMLFormElement* form) { - if (!form->collectionInfo) - form->collectionInfo = new CollectionCache; - return form->collectionInfo; + if (!form->m_collectionCache) + form->m_collectionCache.set(new CollectionCache); + return form->m_collectionCache.get(); } HTMLFormCollection::HTMLFormCollection(PassRefPtr<HTMLFormElement> form) @@ -78,16 +78,17 @@ Node* HTMLFormCollection::item(unsigned index) const info()->elementsArrayPosition = 0; } - Vector<HTMLFormControlElement*>& l = static_cast<HTMLFormElement*>(base())->formElements; + Vector<HTMLFormControlElement*>& elementsArray = static_cast<HTMLFormElement*>(base())->m_associatedElements; unsigned currentIndex = info()->position; - for (unsigned i = info()->elementsArrayPosition; i < l.size(); i++) { - if (l[i]->isEnumeratable() ) { + for (unsigned i = info()->elementsArrayPosition; i < elementsArray.size(); i++) { + HTMLFormControlElement* element = elementsArray[i]; + if (element->isEnumeratable()) { if (index == currentIndex) { info()->position = index; - info()->current = l[i]; + info()->current = element; info()->elementsArrayPosition = i; - return l[i]; + return element; } currentIndex++; @@ -108,8 +109,8 @@ Element* HTMLFormCollection::getNamedFormItem(const QualifiedName& attrName, con HTMLFormElement* form = static_cast<HTMLFormElement*>(base()); bool foundInputElements = false; - for (unsigned i = 0; i < form->formElements.size(); ++i) { - HTMLFormControlElement* e = form->formElements[i]; + for (unsigned i = 0; i < form->m_associatedElements.size(); ++i) { + HTMLFormControlElement* e = form->m_associatedElements[i]; const QualifiedName& attributeName = (attrName == idAttr) ? e->idAttributeName() : attrName; if (e->isEnumeratable() && e->getAttribute(attributeName) == name) { foundInputElements = true; @@ -120,8 +121,8 @@ Element* HTMLFormCollection::getNamedFormItem(const QualifiedName& attrName, con } if (!foundInputElements) { - for (unsigned i = 0; i < form->imgElements.size(); ++i) { - HTMLImageElement* e = form->imgElements[i]; + for (unsigned i = 0; i < form->m_imageElements.size(); ++i) { + HTMLImageElement* e = form->m_imageElements[i]; const QualifiedName& attributeName = (attrName == idAttr) ? e->idAttributeName() : attrName; if (e->getAttribute(attributeName) == name) { if (!duplicateNumber) @@ -190,8 +191,8 @@ void HTMLFormCollection::updateNameCache() const HTMLFormElement* f = static_cast<HTMLFormElement*>(base()); - for (unsigned i = 0; i < f->formElements.size(); ++i) { - HTMLFormControlElement* e = f->formElements[i]; + for (unsigned i = 0; i < f->m_associatedElements.size(); ++i) { + HTMLFormControlElement* e = f->m_associatedElements[i]; if (e->isEnumeratable()) { const AtomicString& idAttrVal = e->getAttribute(e->idAttributeName()); const AtomicString& nameAttrVal = e->getAttribute(nameAttr); @@ -218,8 +219,8 @@ void HTMLFormCollection::updateNameCache() const } } - for (unsigned i = 0; i < f->imgElements.size(); ++i) { - HTMLImageElement* e = f->imgElements[i]; + for (unsigned i = 0; i < f->m_imageElements.size(); ++i) { + HTMLImageElement* e = f->m_imageElements[i]; const AtomicString& idAttrVal = e->getAttribute(e->idAttributeName()); const AtomicString& nameAttrVal = e->getAttribute(nameAttr); if (!idAttrVal.isEmpty() && !foundInputElements.contains(idAttrVal.impl())) { diff --git a/WebCore/html/HTMLFormControlElement.cpp b/WebCore/html/HTMLFormControlElement.cpp index 5894999..fa5d957 100644 --- a/WebCore/html/HTMLFormControlElement.cpp +++ b/WebCore/html/HTMLFormControlElement.cpp @@ -30,6 +30,7 @@ #include "Chrome.h" #include "ChromeClient.h" #include "Document.h" +#include "ElementRareData.h" #include "Event.h" #include "EventHandler.h" #include "EventNames.h" @@ -39,6 +40,7 @@ #include "HTMLNames.h" #include "HTMLParser.h" #include "HTMLTokenizer.h" +#include "LabelsNodeList.h" #include "Page.h" #include "RenderBox.h" #include "RenderTextControl.h" @@ -406,11 +408,30 @@ bool HTMLFormControlElement::isLabelable() const { // FIXME: Add meterTag and outputTag to the list once we support them. return hasTagName(buttonTag) || hasTagName(inputTag) || hasTagName(keygenTag) +#if ENABLE(METER_TAG) + || hasTagName(meterTag) +#endif #if ENABLE(PROGRESS_TAG) || hasTagName(progressTag) #endif || hasTagName(selectTag) || hasTagName(textareaTag); } + +PassRefPtr<NodeList> HTMLFormControlElement::labels() +{ + if (!isLabelable()) + return 0; + if (!document()) + return 0; + + NodeRareData* data = Node::ensureRareData(); + if (!data->nodeLists()) { + data->setNodeLists(NodeListsNodeData::create()); + document()->addNodeListCache(); + } + + return LabelsNodeList::create(this); +} HTMLFormControlElementWithState::HTMLFormControlElementWithState(const QualifiedName& tagName, Document* doc, HTMLFormElement* f) : HTMLFormControlElement(tagName, doc, f) diff --git a/WebCore/html/HTMLFormControlElement.h b/WebCore/html/HTMLFormControlElement.h index befa67b..b960381 100644 --- a/WebCore/html/HTMLFormControlElement.h +++ b/WebCore/html/HTMLFormControlElement.h @@ -2,7 +2,7 @@ * Copyright (C) 1999 Lars Knoll (knoll@kde.org) * (C) 1999 Antti Koivisto (koivisto@kde.org) * (C) 2000 Dirk Mueller (mueller@kde.org) - * Copyright (C) 2004, 2005, 2006, 2007 Apple Inc. All rights reserved. + * Copyright (C) 2004, 2005, 2006, 2007, 2008, 2009, 2010 Apple Inc. All rights reserved. * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Library General Public @@ -36,26 +36,14 @@ class VisibleSelection; class HTMLFormControlElement : public HTMLElement { public: - HTMLFormControlElement(const QualifiedName& tagName, Document*, HTMLFormElement*, ConstructionType = CreateHTMLElementZeroRefCount); virtual ~HTMLFormControlElement(); - virtual HTMLTagStatus endTagRequirement() const { return TagStatusRequired; } - virtual int tagPriority() const { return 1; } - HTMLFormElement* form() const { return m_form; } ValidityState* validity(); bool formNoValidate() const; void setFormNoValidate(bool); - virtual bool isTextFormControl() const { return false; } - virtual bool isEnabledFormControl() const { return !disabled(); } - - virtual void parseMappedAttribute(Attribute*); - virtual void attach(); - virtual void insertedIntoTree(bool deep); - virtual void removedFromTree(bool deep); - virtual void reset() {} virtual bool formControlValueMatchesRenderer() const { return m_valueMatchesRenderer; } @@ -66,13 +54,9 @@ public: bool disabled() const { return m_disabled; } void setDisabled(bool); - virtual bool supportsFocus() const; virtual bool isFocusable() const; - virtual bool isKeyboardFocusable(KeyboardEvent*) const; - virtual bool isMouseFocusable() const; virtual bool isEnumeratable() const { return false; } - virtual bool isReadOnlyFormControl() const { return m_readOnly; } void setReadOnly(bool); // Determines whether or not a control will be automatically focused @@ -82,17 +66,14 @@ public: bool required() const; void setRequired(bool); - virtual void recalcStyle(StyleChange); - - virtual const AtomicString& formControlName() const; - virtual const AtomicString& formControlType() const = 0; - const AtomicString& type() const { return formControlType(); } const AtomicString& name() const { return formControlName(); } void setName(const AtomicString& name); - virtual bool isFormControlElement() const { return true; } + virtual bool isEnabledFormControl() const { return !disabled(); } + virtual bool isReadOnlyFormControl() const { return readOnly(); } + virtual bool isRadioButton() const { return false; } virtual bool canTriggerImplicitSubmission() const { return false; } @@ -105,8 +86,6 @@ public: virtual bool isActivatedSubmit() const { return false; } virtual void setActivatedSubmit(bool) { } - virtual short tabIndex() const; - virtual bool willValidate() const; String validationMessage(); bool checkValidity(Vector<RefPtr<HTMLFormControlElement> >* unhandledInvalidControls = 0); @@ -119,18 +98,45 @@ public: void formDestroyed() { m_form = 0; } - virtual void dispatchFocusEvent(); - virtual void dispatchBlurEvent(); - bool isLabelable() const; + PassRefPtr<NodeList> labels(); + bool readOnly() const { return m_readOnly; } + protected: + HTMLFormControlElement(const QualifiedName& tagName, Document*, HTMLFormElement*, ConstructionType = CreateHTMLElementZeroRefCount); + + virtual void parseMappedAttribute(Attribute*); + virtual void attach(); + virtual void insertedIntoTree(bool deep); + virtual void removedFromTree(bool deep); + + virtual bool isKeyboardFocusable(KeyboardEvent*) const; + virtual bool isMouseFocusable() const; + + virtual void recalcStyle(StyleChange); + + virtual void dispatchFocusEvent(); + virtual void dispatchBlurEvent(); + void removeFromForm(); // This must be called any time the result of willValidate() has changed. void setNeedsWillValidateCheck(); virtual bool recalcWillValidate() const; private: + virtual HTMLTagStatus endTagRequirement() const { return TagStatusRequired; } + virtual int tagPriority() const { return 1; } + + virtual const AtomicString& formControlName() const; + virtual const AtomicString& formControlType() const = 0; + + virtual bool isFormControlElement() const { return true; } + + virtual bool supportsFocus() const; + + virtual short tabIndex() const; + virtual HTMLFormElement* virtualForm() const; virtual bool isDefaultButtonForForm() const; virtual bool isValidFormControlElement(); @@ -153,25 +159,25 @@ private: class HTMLFormControlElementWithState : public HTMLFormControlElement { public: - HTMLFormControlElementWithState(const QualifiedName& tagName, Document*, HTMLFormElement*); virtual ~HTMLFormControlElementWithState(); +protected: + HTMLFormControlElementWithState(const QualifiedName& tagName, Document*, HTMLFormElement*); + virtual bool autoComplete() const; - virtual bool shouldSaveAndRestoreFormControlState() const; - virtual void finishParsingChildren(); -protected: virtual void willMoveToNewOwnerDocument(); virtual void didMoveToNewOwnerDocument(); virtual void defaultEventHandler(Event*); + +private: + virtual bool shouldSaveAndRestoreFormControlState() const; + virtual void finishParsingChildren(); }; class HTMLTextFormControlElement : public HTMLFormControlElementWithState { public: - HTMLTextFormControlElement(const QualifiedName&, Document*, HTMLFormElement*); virtual ~HTMLTextFormControlElement(); - virtual void dispatchFocusEvent(); - virtual void dispatchBlurEvent(); String strippedPlaceholder() const; @@ -184,14 +190,22 @@ public: VisibleSelection selection() const; protected: - bool isPlaceholderEmpty() const; + HTMLTextFormControlElement(const QualifiedName&, Document*, HTMLFormElement*); + bool placeholderShouldBeVisible() const; void updatePlaceholderVisibility(bool); - virtual int cachedSelectionStart() const = 0; - virtual int cachedSelectionEnd() const = 0; + virtual void parseMappedAttribute(Attribute*); private: + virtual void dispatchFocusEvent(); + virtual void dispatchBlurEvent(); + + bool isPlaceholderEmpty() const; + + virtual int cachedSelectionStart() const = 0; + virtual int cachedSelectionEnd() const = 0; + // A subclass should return true if placeholder processing is needed. virtual bool supportsPlaceholder() const = 0; // Returns true if user-editable value is empty. This is used to check placeholder visibility. @@ -203,6 +217,6 @@ private: RenderTextControl* textRendererAfterUpdateLayout(); }; -} //namespace +} // namespace #endif diff --git a/WebCore/html/HTMLFormElement.cpp b/WebCore/html/HTMLFormElement.cpp index c84454d..c19933a 100644 --- a/WebCore/html/HTMLFormElement.cpp +++ b/WebCore/html/HTMLFormElement.cpp @@ -72,10 +72,8 @@ static int64_t generateFormDataIdentifier() return ++nextIdentifier; } -HTMLFormElement::HTMLFormElement(const QualifiedName& tagName, Document* doc) - : HTMLElement(tagName, doc) - , m_elementAliases(0) - , collectionInfo(0) +HTMLFormElement::HTMLFormElement(const QualifiedName& tagName, Document* document) + : HTMLElement(tagName, document) , m_autocomplete(true) , m_insubmit(false) , m_doingsubmit(false) @@ -86,18 +84,25 @@ HTMLFormElement::HTMLFormElement(const QualifiedName& tagName, Document* doc) ASSERT(hasTagName(formTag)); } +PassRefPtr<HTMLFormElement> HTMLFormElement::create(Document* document) +{ + return new HTMLFormElement(formTag, document); +} + +PassRefPtr<HTMLFormElement> HTMLFormElement::create(const QualifiedName& tagName, Document* document) +{ + return new HTMLFormElement(tagName, document); +} + HTMLFormElement::~HTMLFormElement() { if (!m_autocomplete) document()->unregisterForDocumentActivationCallbacks(this); - delete m_elementAliases; - delete collectionInfo; - - for (unsigned i = 0; i < formElements.size(); ++i) - formElements[i]->formDestroyed(); - for (unsigned i = 0; i < imgElements.size(); ++i) - imgElements[i]->m_form = 0; + for (unsigned i = 0; i < m_associatedElements.size(); ++i) + m_associatedElements[i]->formDestroyed(); + for (unsigned i = 0; i < m_imageElements.size(); ++i) + m_imageElements[i]->m_form = 0; } bool HTMLFormElement::formWouldHaveSecureSubmission(const String& url) @@ -105,11 +110,6 @@ bool HTMLFormElement::formWouldHaveSecureSubmission(const String& url) return document()->completeURL(url).protocolIs("https"); } -void HTMLFormElement::attach() -{ - HTMLElement::attach(); -} - bool HTMLFormElement::rendererIsNeeded(RenderStyle* style) { if (!isDemoted()) @@ -163,11 +163,10 @@ void HTMLFormElement::handleLocalEvents(Event* event) unsigned HTMLFormElement::length() const { - int len = 0; - for (unsigned i = 0; i < formElements.size(); ++i) - if (formElements[i]->isEnumeratable()) + unsigned len = 0; + for (unsigned i = 0; i < m_associatedElements.size(); ++i) + if (m_associatedElements[i]->isEnumeratable()) ++len; - return len; } @@ -179,8 +178,8 @@ Node* HTMLFormElement::item(unsigned index) void HTMLFormElement::submitImplicitly(Event* event, bool fromImplicitSubmissionTrigger) { int submissionTriggerCount = 0; - for (unsigned i = 0; i < formElements.size(); ++i) { - HTMLFormControlElement* formElement = formElements[i]; + for (unsigned i = 0; i < m_associatedElements.size(); ++i) { + HTMLFormControlElement* formElement = m_associatedElements[i]; if (formElement->isSuccessfulSubmitButton()) { if (formElement->renderer()) { formElement->dispatchSimulatedClick(event); @@ -204,8 +203,8 @@ TextEncoding HTMLFormElement::dataEncoding() const PassRefPtr<FormData> HTMLFormElement::createFormData() { RefPtr<DOMFormData> domFormData = DOMFormData::create(dataEncoding().encodingForFormSubmission()); - for (unsigned i = 0; i < formElements.size(); ++i) { - HTMLFormControlElement* control = formElements[i]; + for (unsigned i = 0; i < m_associatedElements.size(); ++i) { + HTMLFormControlElement* control = m_associatedElements[i]; if (!control->disabled()) control->appendFormData(*domFormData, m_formDataBuilder.isMultiPartForm()); } @@ -354,8 +353,8 @@ void HTMLFormElement::submit(Event* event, bool activateSubmitButton, bool lockH Vector<pair<String, String> > formValues; - for (unsigned i = 0; i < formElements.size(); ++i) { - HTMLFormControlElement* control = formElements[i]; + for (unsigned i = 0; i < m_associatedElements.size(); ++i) { + HTMLFormControlElement* control = m_associatedElements[i]; if (control->hasLocalName(inputTag)) { HTMLInputElement* input = static_cast<HTMLInputElement*>(control); if (input->isTextField()) { @@ -425,8 +424,8 @@ void HTMLFormElement::reset() return; } - for (unsigned i = 0; i < formElements.size(); ++i) - formElements[i]->reset(); + for (unsigned i = 0; i < m_associatedElements.size(); ++i) + m_associatedElements[i]->reset(); m_inreset = false; } @@ -496,20 +495,20 @@ unsigned HTMLFormElement::formElementIndex(HTMLFormControlElement* e) ++i; } } - return formElements.size(); + return m_associatedElements.size(); } void HTMLFormElement::registerFormElement(HTMLFormControlElement* e) { document()->checkedRadioButtons().removeButton(e); m_checkedRadioButtons.addButton(e); - formElements.insert(formElementIndex(e), e); + m_associatedElements.insert(formElementIndex(e), e); } void HTMLFormElement::removeFormElement(HTMLFormControlElement* e) { m_checkedRadioButtons.removeButton(e); - removeFromVector(formElements, e); + removeFromVector(m_associatedElements, e); } bool HTMLFormElement::isURLAttribute(Attribute* attr) const @@ -519,14 +518,14 @@ bool HTMLFormElement::isURLAttribute(Attribute* attr) const void HTMLFormElement::registerImgElement(HTMLImageElement* e) { - ASSERT(imgElements.find(e) == notFound); - imgElements.append(e); + ASSERT(m_imageElements.find(e) == notFound); + m_imageElements.append(e); } void HTMLFormElement::removeImgElement(HTMLImageElement* e) { - ASSERT(imgElements.find(e) != notFound); - removeFromVector(imgElements, e); + ASSERT(m_imageElements.find(e) != notFound); + removeFromVector(m_imageElements, e); } PassRefPtr<HTMLCollection> HTMLFormElement::elements() @@ -596,8 +595,8 @@ void HTMLFormElement::setTarget(const String &value) HTMLFormControlElement* HTMLFormElement::defaultButton() const { - for (unsigned i = 0; i < formElements.size(); ++i) { - HTMLFormControlElement* control = formElements[i]; + for (unsigned i = 0; i < m_associatedElements.size(); ++i) { + HTMLFormControlElement* control = m_associatedElements[i]; if (control->isSuccessfulSubmitButton()) return control; } @@ -615,12 +614,12 @@ bool HTMLFormElement::checkValidity() void HTMLFormElement::collectUnhandledInvalidControls(Vector<RefPtr<HTMLFormControlElement> >& unhandledInvalidControls) { RefPtr<HTMLFormElement> protector(this); - // Copy formElements because event handlers called from - // HTMLFormControlElement::checkValidity() might change formElements. + // Copy m_associatedElements because event handlers called from + // HTMLFormControlElement::checkValidity() might change m_associatedElements. Vector<RefPtr<HTMLFormControlElement> > elements; - elements.reserveCapacity(formElements.size()); - for (unsigned i = 0; i < formElements.size(); ++i) - elements.append(formElements[i]); + elements.reserveCapacity(m_associatedElements.size()); + for (unsigned i = 0; i < m_associatedElements.size(); ++i) + elements.append(m_associatedElements[i]); for (unsigned i = 0; i < elements.size(); ++i) { if (elements[i]->form() == this) elements[i]->checkValidity(&unhandledInvalidControls); @@ -639,7 +638,7 @@ void HTMLFormElement::addElementAlias(HTMLFormControlElement* element, const Ato if (alias.isEmpty()) return; if (!m_elementAliases) - m_elementAliases = new AliasMap; + m_elementAliases.set(new AliasMap); m_elementAliases->set(alias.impl(), element); } @@ -670,8 +669,8 @@ void HTMLFormElement::documentDidBecomeActive() { ASSERT(!m_autocomplete); - for (unsigned i = 0; i < formElements.size(); ++i) - formElements[i]->reset(); + for (unsigned i = 0; i < m_associatedElements.size(); ++i) + m_associatedElements[i]->reset(); } void HTMLFormElement::willMoveToNewOwnerDocument() diff --git a/WebCore/html/HTMLFormElement.h b/WebCore/html/HTMLFormElement.h index e3de222..a49f443 100644 --- a/WebCore/html/HTMLFormElement.h +++ b/WebCore/html/HTMLFormElement.h @@ -2,7 +2,7 @@ * Copyright (C) 1999 Lars Knoll (knoll@kde.org) * (C) 1999 Antti Koivisto (koivisto@kde.org) * (C) 2000 Dirk Mueller (mueller@kde.org) - * Copyright (C) 2004, 2005, 2006, 2007, 2008, 2009 Apple Inc. All rights reserved. + * Copyright (C) 2004, 2005, 2006, 2007, 2008, 2009, 2010 Apple Inc. All rights reserved. * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Library General Public @@ -44,22 +44,13 @@ struct CollectionCache; class HTMLFormElement : public HTMLElement { public: - HTMLFormElement(const QualifiedName&, Document*); + static PassRefPtr<HTMLFormElement> create(Document*); + static PassRefPtr<HTMLFormElement> create(const QualifiedName&, Document*); virtual ~HTMLFormElement(); - virtual HTMLTagStatus endTagRequirement() const { return TagStatusRequired; } - virtual int tagPriority() const { return 3; } - - virtual void attach(); - virtual bool rendererIsNeeded(RenderStyle*); - virtual void insertedIntoDocument(); - virtual void removedFromDocument(); - - virtual void handleLocalEvents(Event*); - PassRefPtr<HTMLCollection> elements(); void getNamedElements(const AtomicString&, Vector<RefPtr<Node> >&); - + unsigned length() const; Node* item(unsigned index); @@ -71,8 +62,8 @@ public: bool autoComplete() const { return m_autocomplete; } - virtual void parseMappedAttribute(Attribute*); - + // FIXME: Should rename these two functions to say "form control" + // or "form-associated element" instead of "form element". void registerFormElement(HTMLFormControlElement*); void removeFormElement(HTMLFormControlElement*); void registerImgElement(HTMLImageElement*); @@ -89,8 +80,6 @@ public: void setDemoted(bool demoted) { m_demoted = demoted; } bool isDemoted() const { return m_demoted; } - virtual bool isURLAttribute(Attribute*) const; - void submitImplicitly(Event*, bool fromImplicitSubmissionTrigger); bool formWouldHaveSecureSubmission(const String& url); @@ -119,18 +108,31 @@ public: PassRefPtr<HTMLFormControlElement> elementForAlias(const AtomicString&); void addElementAlias(HTMLFormControlElement*, const AtomicString& alias); - // FIXME: Change this to be private after getting rid of all the clients. - Vector<HTMLFormControlElement*> formElements; - CheckedRadioButtons& checkedRadioButtons() { return m_checkedRadioButtons; } - + + const Vector<HTMLFormControlElement*>& associatedElements() const { return m_associatedElements; } + +private: + HTMLFormElement(const QualifiedName&, Document*); + + virtual HTMLTagStatus endTagRequirement() const { return TagStatusRequired; } + virtual int tagPriority() const { return 3; } + + virtual bool rendererIsNeeded(RenderStyle*); + virtual void insertedIntoDocument(); + virtual void removedFromDocument(); + + virtual void handleLocalEvents(Event*); + + virtual void parseMappedAttribute(Attribute*); + + virtual bool isURLAttribute(Attribute*) const; + virtual void documentDidBecomeActive(); -protected: virtual void willMoveToNewOwnerDocument(); virtual void didMoveToNewOwnerDocument(); -private: void submit(Event*, bool activateSubmitButton, bool lockHistory, FormSubmissionTrigger); bool isMailtoForm() const; @@ -148,12 +150,14 @@ private: typedef HashMap<RefPtr<AtomicStringImpl>, RefPtr<HTMLFormControlElement> > AliasMap; FormDataBuilder m_formDataBuilder; - AliasMap* m_elementAliases; - CollectionCache* collectionInfo; + OwnPtr<AliasMap> m_elementAliases; + OwnPtr<CollectionCache> m_collectionCache; CheckedRadioButtons m_checkedRadioButtons; - Vector<HTMLImageElement*> imgElements; + Vector<HTMLFormControlElement*> m_associatedElements; + Vector<HTMLImageElement*> m_imageElements; + String m_url; String m_target; bool m_autocomplete : 1; diff --git a/WebCore/html/HTMLFrameElementBase.cpp b/WebCore/html/HTMLFrameElementBase.cpp index 756dd84..fb05e91 100644 --- a/WebCore/html/HTMLFrameElementBase.cpp +++ b/WebCore/html/HTMLFrameElementBase.cpp @@ -71,15 +71,8 @@ bool HTMLFrameElementBase::isURLAllowed() const 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 - // exponential growth in the number of frames. - // FIXME: This limit could be higher, but because WebKit has some - // algorithms that happen while loading which appear to be N^2 or - // worse in the number of frames, we'll keep it at 200 for now. if (Frame* parentFrame = document()->frame()) { - if (parentFrame->page()->frameCount() > 200) + if (parentFrame->page()->frameCount() >= Page::maxNumberOfFrames) return false; } diff --git a/WebCore/html/HTMLFrameSetElement.cpp b/WebCore/html/HTMLFrameSetElement.cpp index b97c498..0181cc9 100644 --- a/WebCore/html/HTMLFrameSetElement.cpp +++ b/WebCore/html/HTMLFrameSetElement.cpp @@ -1,9 +1,9 @@ -/** +/* * Copyright (C) 1999 Lars Knoll (knoll@kde.org) * (C) 1999 Antti Koivisto (koivisto@kde.org) * (C) 2000 Simon Hausmann (hausmann@kde.org) * (C) 2001 Dirk Mueller (mueller@kde.org) - * Copyright (C) 2004, 2006, 2009 Apple Inc. All rights reserved. + * Copyright (C) 2004, 2006, 2009, 2010 Apple Inc. All rights reserved. * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Library General Public @@ -40,10 +40,8 @@ namespace WebCore { using namespace HTMLNames; -HTMLFrameSetElement::HTMLFrameSetElement(const QualifiedName& tagName, Document *doc) - : HTMLElement(tagName, doc) - , m_rows(0) - , m_cols(0) +HTMLFrameSetElement::HTMLFrameSetElement(const QualifiedName& tagName, Document* document) + : HTMLElement(tagName, document) , m_totalRows(1) , m_totalCols(1) , m_border(6) @@ -56,12 +54,9 @@ HTMLFrameSetElement::HTMLFrameSetElement(const QualifiedName& tagName, Document ASSERT(hasTagName(framesetTag)); } -HTMLFrameSetElement::~HTMLFrameSetElement() +PassRefPtr<HTMLFrameSetElement> HTMLFrameSetElement::create(const QualifiedName& tagName, Document* document) { - if (m_rows) - delete [] m_rows; - if (m_cols) - delete [] m_cols; + return new HTMLFrameSetElement(tagName, document); } bool HTMLFrameSetElement::checkDTD(const Node* newChild) @@ -87,14 +82,12 @@ void HTMLFrameSetElement::parseMappedAttribute(Attribute* attr) { if (attr->name() == rowsAttr) { if (!attr->isNull()) { - if (m_rows) delete [] m_rows; - m_rows = newLengthArray(attr->value().string(), m_totalRows); + m_rowLengths.set(newLengthArray(attr->value().string(), m_totalRows)); setNeedsStyleRecalc(); } } else if (attr->name() == colsAttr) { if (!attr->isNull()) { - delete [] m_cols; - m_cols = newLengthArray(attr->value().string(), m_totalCols); + m_colLengths.set(newLengthArray(attr->value().string(), m_totalCols)); setNeedsStyleRecalc(); } } else if (attr->name() == frameborderAttr) { diff --git a/WebCore/html/HTMLFrameSetElement.h b/WebCore/html/HTMLFrameSetElement.h index faf800d..accfbf8 100644 --- a/WebCore/html/HTMLFrameSetElement.h +++ b/WebCore/html/HTMLFrameSetElement.h @@ -2,7 +2,7 @@ * Copyright (C) 1999 Lars Knoll (knoll@kde.org) * (C) 1999 Antti Koivisto (koivisto@kde.org) * (C) 2000 Simon Hausmann <hausmann@kde.org> - * Copyright (C) 2004, 2006, 2009 Apple Inc. All rights reserved. + * Copyright (C) 2004, 2006, 2009, 2010 Apple Inc. All rights reserved. * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Library General Public @@ -24,29 +24,14 @@ #ifndef HTMLFrameSetElement_h #define HTMLFrameSetElement_h -#include "Color.h" -#include "Document.h" +#include <wtf/OwnArrayPtr.h> #include "HTMLElement.h" namespace WebCore { class HTMLFrameSetElement : public HTMLElement { public: - HTMLFrameSetElement(const QualifiedName&, Document*); - ~HTMLFrameSetElement(); - - virtual HTMLTagStatus endTagRequirement() const { return TagStatusRequired; } - virtual int tagPriority() const { return 10; } - virtual bool checkDTD(const Node* newChild); - - virtual bool mapToEntry(const QualifiedName& attrName, MappedAttributeEntry& result) const; - virtual void parseMappedAttribute(Attribute*); - - virtual void attach(); - virtual bool rendererIsNeeded(RenderStyle*); - virtual RenderObject* createRenderer(RenderArena*, RenderStyle*); - - virtual void defaultEventHandler(Event*); + static PassRefPtr<HTMLFrameSetElement> create(const QualifiedName&, Document*); bool hasFrameBorder() const { return frameborder; } bool noResize() const { return noresize; } @@ -57,16 +42,14 @@ public: bool hasBorderColor() const { return m_borderColorSet; } - virtual void recalcStyle(StyleChange); - String cols() const; void setCols(const String&); String rows() const; void setRows(const String&); - const Length* rowLengths() const { return m_rows; } - const Length* colLengths() const { return m_cols; } + const Length* rowLengths() const { return m_rowLengths.get(); } + const Length* colLengths() const { return m_colLengths.get(); } // Declared virtual in Element DEFINE_WINDOW_ATTRIBUTE_EVENT_LISTENER(blur); @@ -88,8 +71,25 @@ public: #endif private: - Length* m_rows; - Length* m_cols; + HTMLFrameSetElement(const QualifiedName&, Document*); + + virtual HTMLTagStatus endTagRequirement() const { return TagStatusRequired; } + virtual int tagPriority() const { return 10; } + virtual bool checkDTD(const Node* newChild); + + virtual bool mapToEntry(const QualifiedName& attrName, MappedAttributeEntry& result) const; + virtual void parseMappedAttribute(Attribute*); + + virtual void attach(); + virtual bool rendererIsNeeded(RenderStyle*); + virtual RenderObject* createRenderer(RenderArena*, RenderStyle*); + + virtual void defaultEventHandler(Event*); + + virtual void recalcStyle(StyleChange); + + OwnArrayPtr<Length> m_rowLengths; + OwnArrayPtr<Length> m_colLengths; int m_totalRows; int m_totalCols; diff --git a/WebCore/html/HTMLHRElement.cpp b/WebCore/html/HTMLHRElement.cpp index 92fb3b2..b0fc6ff 100644 --- a/WebCore/html/HTMLHRElement.cpp +++ b/WebCore/html/HTMLHRElement.cpp @@ -1,7 +1,7 @@ -/** +/* * Copyright (C) 1999 Lars Knoll (knoll@kde.org) * (C) 1999 Antti Koivisto (koivisto@kde.org) - * Copyright (C) 2003 Apple Computer, Inc. + * Copyright (C) 2003, 2010 Apple Inc. All rights reserved. * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Library General Public @@ -32,14 +32,20 @@ namespace WebCore { using namespace HTMLNames; -HTMLHRElement::HTMLHRElement(const QualifiedName& tagName, Document* doc) - : HTMLElement(tagName, doc) +HTMLHRElement::HTMLHRElement(const QualifiedName& tagName, Document* document) + : HTMLElement(tagName, document) { ASSERT(hasTagName(hrTag)); } -HTMLHRElement::~HTMLHRElement() +PassRefPtr<HTMLHRElement> HTMLHRElement::create(Document* document) { + return new HTMLHRElement(hrTag, document); +} + +PassRefPtr<HTMLHRElement> HTMLHRElement::create(const QualifiedName& tagName, Document* document) +{ + return new HTMLHRElement(tagName, document); } bool HTMLHRElement::mapToEntry(const QualifiedName& attrName, MappedAttributeEntry& result) const diff --git a/WebCore/html/HTMLHRElement.h b/WebCore/html/HTMLHRElement.h index 8763082..ea10c88 100644 --- a/WebCore/html/HTMLHRElement.h +++ b/WebCore/html/HTMLHRElement.h @@ -1,6 +1,7 @@ /* * Copyright (C) 1999 Lars Knoll (knoll@kde.org) * (C) 1999 Antti Koivisto (koivisto@kde.org) + * Copyright (C) 2010 Apple Inc. All rights reserved. * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Library General Public @@ -28,15 +29,9 @@ namespace WebCore { class HTMLHRElement : public HTMLElement { public: - HTMLHRElement(const QualifiedName&, Document*); - ~HTMLHRElement(); - - virtual HTMLTagStatus endTagRequirement() const { return TagStatusForbidden; } - virtual int tagPriority() const { return 0; } + static PassRefPtr<HTMLHRElement> create(Document*); + static PassRefPtr<HTMLHRElement> create(const QualifiedName&, Document*); - virtual bool mapToEntry(const QualifiedName&, MappedAttributeEntry&) const; - virtual void parseMappedAttribute(Attribute*); - String align() const; void setAlign(const String&); @@ -48,6 +43,15 @@ public: String width() const; void setWidth(const String&); + +private: + HTMLHRElement(const QualifiedName&, Document*); + + virtual HTMLTagStatus endTagRequirement() const { return TagStatusForbidden; } + virtual int tagPriority() const { return 0; } + + virtual bool mapToEntry(const QualifiedName&, MappedAttributeEntry&) const; + virtual void parseMappedAttribute(Attribute*); }; } // namespace WebCore diff --git a/WebCore/html/HTMLHeadElement.cpp b/WebCore/html/HTMLHeadElement.cpp index 5e3c509..df5acb4 100644 --- a/WebCore/html/HTMLHeadElement.cpp +++ b/WebCore/html/HTMLHeadElement.cpp @@ -1,9 +1,9 @@ -/** +/* * Copyright (C) 1999 Lars Knoll (knoll@kde.org) * (C) 1999 Antti Koivisto (koivisto@kde.org) * (C) 2000 Simon Hausmann (hausmann@kde.org) * (C) 2001 Dirk Mueller (mueller@kde.org) - * Copyright (C) 2004, 2006 Apple Computer, Inc. + * Copyright (C) 2004, 2006, 2010 Apple Inc. All rights reserved. * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Library General Public @@ -20,6 +20,7 @@ * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, * Boston, MA 02110-1301, USA. */ + #include "config.h" #include "HTMLHeadElement.h" @@ -30,14 +31,20 @@ namespace WebCore { using namespace HTMLNames; -HTMLHeadElement::HTMLHeadElement(const QualifiedName& qName, Document* doc) - : HTMLElement(qName, doc) +HTMLHeadElement::HTMLHeadElement(const QualifiedName& tagName, Document* document) + : HTMLElement(tagName, document) { ASSERT(hasTagName(headTag)); } -HTMLHeadElement::~HTMLHeadElement() +PassRefPtr<HTMLHeadElement> HTMLHeadElement::create(Document* document) +{ + return new HTMLHeadElement(headTag, document); +} + +PassRefPtr<HTMLHeadElement> HTMLHeadElement::create(const QualifiedName& tagName, Document* document) { + return new HTMLHeadElement(tagName, document); } String HTMLHeadElement::profile() const diff --git a/WebCore/html/HTMLHeadElement.h b/WebCore/html/HTMLHeadElement.h index 14a4409..a91f5f8 100644 --- a/WebCore/html/HTMLHeadElement.h +++ b/WebCore/html/HTMLHeadElement.h @@ -2,7 +2,7 @@ * Copyright (C) 1999 Lars Knoll (knoll@kde.org) * (C) 1999 Antti Koivisto (koivisto@kde.org) * (C) 2000 Simon Hausmann <hausmann@kde.org> - * Copyright (C) 2004, 2006 Apple Computer, Inc. + * Copyright (C) 2004, 2006, 2010 Apple Inc. All rights reserved. * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Library General Public @@ -30,18 +30,22 @@ namespace WebCore { class HTMLHeadElement : public HTMLElement { public: + static PassRefPtr<HTMLHeadElement> create(Document*); + static PassRefPtr<HTMLHeadElement> create(const QualifiedName&, Document*); + + String profile() const; + void setProfile(const String&); + + virtual int tagPriority() const { return 10; } + +private: HTMLHeadElement(const QualifiedName&, Document*); - ~HTMLHeadElement(); virtual HTMLTagStatus endTagRequirement() const { return TagStatusOptional; } - virtual int tagPriority() const { return 10; } virtual bool childAllowed(Node* newChild); virtual bool checkDTD(const Node* newChild); - - String profile() const; - void setProfile(const String&); }; -} //namespace +} // namespace #endif diff --git a/WebCore/html/HTMLHeadingElement.cpp b/WebCore/html/HTMLHeadingElement.cpp index 95c82d1..dd5ae66 100644 --- a/WebCore/html/HTMLHeadingElement.cpp +++ b/WebCore/html/HTMLHeadingElement.cpp @@ -1,7 +1,7 @@ -/** +/* * Copyright (C) 1999 Lars Knoll (knoll@kde.org) * (C) 1999 Antti Koivisto (koivisto@kde.org) - * Copyright (C) 2003 Apple Computer, Inc. + * Copyright (C) 2003, 2010 Apple Inc. All rights reserved. * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Library General Public @@ -19,6 +19,7 @@ * Boston, MA 02110-1301, USA. * */ + #include "config.h" #include "HTMLHeadingElement.h" @@ -28,9 +29,14 @@ namespace WebCore { using namespace HTMLNames; -HTMLHeadingElement::HTMLHeadingElement(const QualifiedName& tagName, Document *doc) - : HTMLElement(tagName, doc) +inline HTMLHeadingElement::HTMLHeadingElement(const QualifiedName& tagName, Document* document) + : HTMLElement(tagName, document) +{ +} + +PassRefPtr<HTMLHeadingElement> HTMLHeadingElement::create(const QualifiedName& tagName, Document* document) { + return new HTMLHeadingElement(tagName, document); } bool HTMLHeadingElement::checkDTD(const Node* newChild) diff --git a/WebCore/html/HTMLHeadingElement.h b/WebCore/html/HTMLHeadingElement.h index 765bede..e783360 100644 --- a/WebCore/html/HTMLHeadingElement.h +++ b/WebCore/html/HTMLHeadingElement.h @@ -1,6 +1,7 @@ /* * Copyright (C) 1999 Lars Knoll (knoll@kde.org) * (C) 1999 Antti Koivisto (koivisto@kde.org) + * Copyright (C) 2010 Apple Inc. All rights reserved. * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Library General Public @@ -28,14 +29,17 @@ namespace WebCore { class HTMLHeadingElement : public HTMLElement { public: + static PassRefPtr<HTMLHeadingElement> create(const QualifiedName&, Document*); + + String align() const; + void setAlign(const String&); + +private: HTMLHeadingElement(const QualifiedName&, Document*); virtual HTMLTagStatus endTagRequirement() const { return TagStatusRequired; } virtual int tagPriority() const { return 5; } virtual bool checkDTD(const Node* newChild); - - String align() const; - void setAlign(const String&); }; } // namespace WebCore diff --git a/WebCore/html/HTMLHtmlElement.cpp b/WebCore/html/HTMLHtmlElement.cpp index 8382e60..1949b59 100644 --- a/WebCore/html/HTMLHtmlElement.cpp +++ b/WebCore/html/HTMLHtmlElement.cpp @@ -1,9 +1,9 @@ -/** +/* * Copyright (C) 1999 Lars Knoll (knoll@kde.org) * (C) 1999 Antti Koivisto (koivisto@kde.org) * (C) 2000 Simon Hausmann (hausmann@kde.org) * (C) 2001 Dirk Mueller (mueller@kde.org) - * Copyright (C) 2004, 2006 Apple Computer, Inc. + * Copyright (C) 2004, 2006, 2010 Apple Inc. All rights reserved. * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Library General Public @@ -20,6 +20,7 @@ * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, * Boston, MA 02110-1301, USA. */ + #include "config.h" #include "HTMLHtmlElement.h" @@ -33,14 +34,20 @@ namespace WebCore { using namespace HTMLNames; -HTMLHtmlElement::HTMLHtmlElement(const QualifiedName& tagName, Document* doc) - : HTMLElement(tagName, doc) +HTMLHtmlElement::HTMLHtmlElement(const QualifiedName& tagName, Document* document) + : HTMLElement(tagName, document) { ASSERT(hasTagName(htmlTag)); } -HTMLHtmlElement::~HTMLHtmlElement() +PassRefPtr<HTMLHtmlElement> HTMLHtmlElement::create(Document* document) +{ + return new HTMLHtmlElement(htmlTag, document); +} + +PassRefPtr<HTMLHtmlElement> HTMLHtmlElement::create(const QualifiedName& tagName, Document* document) { + return new HTMLHtmlElement(tagName, document); } String HTMLHtmlElement::version() const diff --git a/WebCore/html/HTMLHtmlElement.h b/WebCore/html/HTMLHtmlElement.h index de80ba8..ed04703 100644 --- a/WebCore/html/HTMLHtmlElement.h +++ b/WebCore/html/HTMLHtmlElement.h @@ -2,7 +2,7 @@ * Copyright (C) 1999 Lars Knoll (knoll@kde.org) * (C) 1999 Antti Koivisto (koivisto@kde.org) * (C) 2000 Simon Hausmann <hausmann@kde.org> - * Copyright (C) 2004, 2006 Apple Computer, Inc. + * Copyright (C) 2004, 2006, 2010 Apple Inc. All rights reserved. * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Library General Public @@ -30,8 +30,14 @@ namespace WebCore { class HTMLHtmlElement : public HTMLElement { public: + static PassRefPtr<HTMLHtmlElement> create(Document*); + static PassRefPtr<HTMLHtmlElement> create(const QualifiedName&, Document*); + + String version() const; + void setVersion(const String&); + +private: HTMLHtmlElement(const QualifiedName&, Document*); - ~HTMLHtmlElement(); virtual HTMLTagStatus endTagRequirement() const { return TagStatusRequired; } virtual int tagPriority() const { return 11; } @@ -40,11 +46,8 @@ public: #if ENABLE(OFFLINE_WEB_APPLICATIONS) virtual void insertedIntoDocument(); #endif - - String version() const; - void setVersion(const String&); }; -} //namespace +} // namespace #endif diff --git a/WebCore/html/HTMLImageElement.cpp b/WebCore/html/HTMLImageElement.cpp index 5256e6d..5dd036e 100644 --- a/WebCore/html/HTMLImageElement.cpp +++ b/WebCore/html/HTMLImageElement.cpp @@ -28,7 +28,7 @@ #include "CSSPropertyNames.h" #include "CSSValueKeywords.h" #include "EventNames.h" -#include "Frame.h" +#include "FrameView.h" #include "HTMLDocument.h" #include "HTMLFormElement.h" #include "HTMLNames.h" @@ -41,8 +41,8 @@ namespace WebCore { using namespace HTMLNames; -HTMLImageElement::HTMLImageElement(const QualifiedName& tagName, Document* doc, HTMLFormElement* form) - : HTMLElement(tagName, doc) +HTMLImageElement::HTMLImageElement(const QualifiedName& tagName, Document* document, HTMLFormElement* form) + : HTMLElement(tagName, document) , m_imageLoader(this) , ismap(false) , m_form(form) @@ -53,6 +53,16 @@ HTMLImageElement::HTMLImageElement(const QualifiedName& tagName, Document* doc, form->registerImgElement(this); } +PassRefPtr<HTMLImageElement> HTMLImageElement::create(Document* document) +{ + return new HTMLImageElement(imgTag, document); +} + +PassRefPtr<HTMLImageElement> HTMLImageElement::create(const QualifiedName& tagName, Document* document, HTMLFormElement* form) +{ + return new HTMLImageElement(tagName, document, form); +} + HTMLImageElement::~HTMLImageElement() { if (m_form) @@ -255,7 +265,7 @@ int HTMLImageElement::width(bool ignorePendingStylesheets) const // if the image is available, use its width if (m_imageLoader.image()) { - float zoomFactor = document()->frame() ? document()->frame()->pageZoomFactor() : 1.0f; + float zoomFactor = document()->view() ? document()->view()->pageZoomFactor() : 1.0f; return m_imageLoader.image()->imageSize(zoomFactor).width(); } } @@ -279,7 +289,7 @@ int HTMLImageElement::height(bool ignorePendingStylesheets) const // if the image is available, use its height if (m_imageLoader.image()) { - float zoomFactor = document()->frame() ? document()->frame()->pageZoomFactor() : 1.0f; + float zoomFactor = document()->view() ? document()->view()->pageZoomFactor() : 1.0f; return m_imageLoader.image()->imageSize(zoomFactor).height(); } } diff --git a/WebCore/html/HTMLImageElement.h b/WebCore/html/HTMLImageElement.h index 61faa39..62d315c 100644 --- a/WebCore/html/HTMLImageElement.h +++ b/WebCore/html/HTMLImageElement.h @@ -35,21 +35,11 @@ class HTMLFormElement; class HTMLImageElement : public HTMLElement { friend class HTMLFormElement; public: + static PassRefPtr<HTMLImageElement> create(Document*); + static PassRefPtr<HTMLImageElement> create(const QualifiedName&, Document*, HTMLFormElement*); static PassRefPtr<HTMLImageElement> createForJSConstructor(Document*, const int* optionalWidth, const int* optionalHeight); - HTMLImageElement(const QualifiedName&, Document*, HTMLFormElement* = 0); - ~HTMLImageElement(); - - virtual HTMLTagStatus endTagRequirement() const { return TagStatusForbidden; } - virtual int tagPriority() const { return 0; } - - virtual bool mapToEntry(const QualifiedName& attrName, MappedAttributeEntry& result) const; - virtual void parseMappedAttribute(Attribute*); - - virtual void attach(); - virtual RenderObject* createRenderer(RenderArena*, RenderStyle*); - - virtual bool canStartSelection() const { return false; } + virtual ~HTMLImageElement(); int width(bool ignorePendingStylesheets = false) const; int height(bool ignorePendingStylesheets = false) const; @@ -61,8 +51,6 @@ public: String altText() const; - virtual bool isURLAttribute(Attribute*) const; - CompositeOperator compositeOperator() const { return m_compositeOperator; } CachedImage* cachedImage() const { return m_imageLoader.image(); } @@ -72,8 +60,6 @@ public: const AtomicString& alt() const; - virtual bool draggable() const; - void setHeight(int); int hspace() const; @@ -103,12 +89,29 @@ public: bool haveFiredLoadEvent() const { return m_imageLoader.haveFiredLoadEvent(); } - virtual void addSubresourceAttributeURLs(ListHashSet<KURL>&) const; - protected: + HTMLImageElement(const QualifiedName&, Document*, HTMLFormElement* = 0); + virtual void willMoveToNewOwnerDocument(); private: + virtual HTMLTagStatus endTagRequirement() const { return TagStatusForbidden; } + virtual int tagPriority() const { return 0; } + + virtual bool mapToEntry(const QualifiedName& attrName, MappedAttributeEntry& result) const; + virtual void parseMappedAttribute(Attribute*); + + virtual void attach(); + virtual RenderObject* createRenderer(RenderArena*, RenderStyle*); + + virtual bool canStartSelection() const { return false; } + + virtual bool isURLAttribute(Attribute*) const; + + virtual bool draggable() const; + + virtual void addSubresourceAttributeURLs(ListHashSet<KURL>&) const; + virtual void insertedIntoDocument(); virtual void removedFromDocument(); virtual void insertedIntoTree(bool deep); diff --git a/WebCore/html/HTMLImageLoader.cpp b/WebCore/html/HTMLImageLoader.cpp index c6f49aa..6e31d9b 100644 --- a/WebCore/html/HTMLImageLoader.cpp +++ b/WebCore/html/HTMLImageLoader.cpp @@ -1,7 +1,7 @@ /* * Copyright (C) 1999 Lars Knoll (knoll@kde.org) * (C) 1999 Antti Koivisto (koivisto@kde.org) - * Copyright (C) 2004, 2005, 2006, 2007 Apple Inc. All rights reserved. + * Copyright (C) 2004, 2005, 2006, 2007, 2010 Apple Inc. All rights reserved. * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Library General Public @@ -30,6 +30,10 @@ #include "HTMLNames.h" #include "HTMLObjectElement.h" +#if USE(JSC) +#include "JSDOMWindowBase.h" +#endif + namespace WebCore { HTMLImageLoader::HTMLImageLoader(Element* node) @@ -55,12 +59,21 @@ String HTMLImageLoader::sourceURI(const AtomicString& attr) const } void HTMLImageLoader::notifyFinished(CachedResource*) -{ +{ CachedImage* cachedImage = image(); Element* elem = element(); ImageLoader::notifyFinished(cachedImage); +#if USE(JSC) + if (!cachedImage->errorOccurred() && !cachedImage->httpStatusCodeErrorOccurred()) { + if (!elem->inDocument()) { + JSC::JSGlobalData* globalData = JSDOMWindowBase::commonJSGlobalData(); + globalData->heap.reportExtraMemoryCost(cachedImage->encodedSize()); + } + } +#endif + if ((cachedImage->errorOccurred() || cachedImage->httpStatusCodeErrorOccurred()) && elem->hasTagName(HTMLNames::objectTag)) static_cast<HTMLObjectElement*>(elem)->renderFallbackContent(); } diff --git a/WebCore/html/HTMLInputElement.cpp b/WebCore/html/HTMLInputElement.cpp index 7994472..9f91277 100644 --- a/WebCore/html/HTMLInputElement.cpp +++ b/WebCore/html/HTMLInputElement.cpp @@ -94,23 +94,12 @@ static const double weekDefaultStep = 1.0; static const double weekStepScaleFactor = 604800000.0; // Constant values for minimum(). -static const double dateDefaultMinimum = -12219292800000.0; // This means 1582-10-15T00:00Z. -static const double dateTimeDefaultMinimum = -12219292800000.0; // ditto. -static const double monthDefaultMinimum = (1582.0 - 1970) * 12 + 10 - 1; // 1582-10 static const double numberDefaultMinimum = -DBL_MAX; static const double rangeDefaultMinimum = 0.0; -static const double timeDefaultMinimum = 0.0; // 00:00:00.000 -static const double weekDefaultMinimum = -12212380800000.0; // 1583-01-03, the first Monday of 1583. // Constant values for maximum(). -static const double dateDefaultMaximum = DBL_MAX; -static const double dateTimeDefaultMaximum = DBL_MAX; -// DateComponents::m_year can't represent a year greater than INT_MAX. -static const double monthDefaultMaximum = (INT_MAX - 1970) * 12.0 + 12 - 1; static const double numberDefaultMaximum = DBL_MAX; static const double rangeDefaultMaximum = 100.0; -static const double timeDefaultMaximum = 86399999.0; // 23:59:59.999 -static const double weekDefaultMaximum = DBL_MAX; static const double defaultStepBase = 0.0; static const double weekDefaultStepBase = -259200000.0; // The first day of 1970-W01. @@ -118,8 +107,8 @@ static const double weekDefaultStepBase = -259200000.0; // The first day of 1970 static const double msecPerMinute = 60 * 1000; static const double msecPerSecond = 1000; -HTMLInputElement::HTMLInputElement(const QualifiedName& tagName, Document* doc, HTMLFormElement* f) - : HTMLTextFormControlElement(tagName, doc, f) +HTMLInputElement::HTMLInputElement(const QualifiedName& tagName, Document* document, HTMLFormElement* form) + : HTMLTextFormControlElement(tagName, document, form) , m_xPos(0) , m_yPos(0) , m_maxResults(-1) @@ -137,6 +126,11 @@ HTMLInputElement::HTMLInputElement(const QualifiedName& tagName, Document* doc, ASSERT(hasTagName(inputTag) || hasTagName(isindexTag)); } +PassRefPtr<HTMLInputElement> HTMLInputElement::create(const QualifiedName& tagName, Document* document, HTMLFormElement* form) +{ + return new HTMLInputElement(tagName, document, form); +} + HTMLInputElement::~HTMLInputElement() { if (needsActivationCallback()) @@ -381,20 +375,20 @@ double HTMLInputElement::minimum() const { switch (inputType()) { case DATE: - return parseToDouble(getAttribute(minAttr), dateDefaultMinimum); + return parseToDouble(getAttribute(minAttr), DateComponents::minimumDate()); case DATETIME: case DATETIMELOCAL: - return parseToDouble(getAttribute(minAttr), dateTimeDefaultMinimum); + return parseToDouble(getAttribute(minAttr), DateComponents::minimumDateTime()); case MONTH: - return parseToDouble(getAttribute(minAttr), monthDefaultMinimum); + return parseToDouble(getAttribute(minAttr), DateComponents::minimumMonth()); case NUMBER: return parseToDouble(getAttribute(minAttr), numberDefaultMinimum); case RANGE: return parseToDouble(getAttribute(minAttr), rangeDefaultMinimum); case TIME: - return parseToDouble(getAttribute(minAttr), timeDefaultMinimum); + return parseToDouble(getAttribute(minAttr), DateComponents::minimumTime()); case WEEK: - return parseToDouble(getAttribute(minAttr), weekDefaultMinimum); + return parseToDouble(getAttribute(minAttr), DateComponents::minimumWeek()); case BUTTON: case CHECKBOX: case COLOR: @@ -421,12 +415,12 @@ double HTMLInputElement::maximum() const { switch (inputType()) { case DATE: - return parseToDouble(getAttribute(maxAttr), dateDefaultMaximum); + return parseToDouble(getAttribute(maxAttr), DateComponents::maximumDate()); case DATETIME: case DATETIMELOCAL: - return parseToDouble(getAttribute(maxAttr), dateTimeDefaultMaximum); + return parseToDouble(getAttribute(maxAttr), DateComponents::maximumDateTime()); case MONTH: - return parseToDouble(getAttribute(maxAttr), monthDefaultMaximum); + return parseToDouble(getAttribute(maxAttr), DateComponents::maximumMonth()); case NUMBER: return parseToDouble(getAttribute(maxAttr), numberDefaultMaximum); case RANGE: { @@ -439,9 +433,9 @@ double HTMLInputElement::maximum() const return max; } case TIME: - return parseToDouble(getAttribute(maxAttr), timeDefaultMaximum); + return parseToDouble(getAttribute(maxAttr), DateComponents::maximumTime()); case WEEK: - return parseToDouble(getAttribute(maxAttr), weekDefaultMaximum); + return parseToDouble(getAttribute(maxAttr), DateComponents::maximumWeek()); case BUTTON: case CHECKBOX: case COLOR: @@ -2375,7 +2369,7 @@ void HTMLInputElement::defaultEventHandler(Event* evt) PassRefPtr<HTMLFormElement> HTMLInputElement::createTemporaryFormForIsIndex() { - RefPtr<HTMLFormElement> form = new HTMLFormElement(formTag, document()); + RefPtr<HTMLFormElement> form = HTMLFormElement::create(document()); form->registerFormElement(this); form->setMethod("GET"); if (!document()->baseURL().isEmpty()) { diff --git a/WebCore/html/HTMLInputElement.h b/WebCore/html/HTMLInputElement.h index da9cee7..363a25f 100644 --- a/WebCore/html/HTMLInputElement.h +++ b/WebCore/html/HTMLInputElement.h @@ -2,7 +2,7 @@ * Copyright (C) 1999 Lars Knoll (knoll@kde.org) * (C) 1999 Antti Koivisto (koivisto@kde.org) * (C) 2000 Dirk Mueller (mueller@kde.org) - * Copyright (C) 2004, 2005, 2006, 2007 Apple Inc. All rights reserved. + * Copyright (C) 2004, 2005, 2006, 2007, 2010 Apple Inc. All rights reserved. * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Library General Public @@ -69,40 +69,11 @@ public: }; static const int numberOfTypes = WEEK + 1; - enum AutoCompleteSetting { - Uninitialized, - On, - Off - }; - - HTMLInputElement(const QualifiedName&, Document*, HTMLFormElement* = 0); + static PassRefPtr<HTMLInputElement> create(const QualifiedName&, Document*, HTMLFormElement*); virtual ~HTMLInputElement(); - virtual HTMLTagStatus endTagRequirement() const { return TagStatusForbidden; } - virtual int tagPriority() const { return 0; } - - virtual bool isKeyboardFocusable(KeyboardEvent*) const; - virtual bool isMouseFocusable() const; - virtual bool isEnumeratable() const { return inputType() != IMAGE; } - virtual void updateFocusAppearance(bool restorePreviousSelection); - virtual void aboutToUnload(); - virtual bool shouldUseInputMethod() const; - - virtual const AtomicString& formControlName() const; - bool autoComplete() const; - // isChecked is used by the rendering tree/CSS while checked() is used by JS to determine checked state - virtual bool isChecked() const { return checked() && (inputType() == CHECKBOX || inputType() == RADIO); } - virtual bool isIndeterminate() const { return indeterminate(); } - - bool readOnly() const { return isReadOnlyFormControl(); } - - virtual bool isTextFormControl() const { return isTextField(); } - - virtual bool valueMissing() const; - virtual bool patternMismatch() const; - virtual bool tooLong() const; // For ValidityState bool rangeUnderflow() const; bool rangeOverflow() const; @@ -130,23 +101,17 @@ public: virtual bool isSearchField() const { return m_type == SEARCH; } virtual bool isInputTypeHidden() const { return m_type == HIDDEN; } virtual bool isPasswordField() const { return m_type == PASSWORD; } - virtual bool hasSpinButton() const { return m_type == NUMBER || m_type == DATE || m_type == DATETIME || m_type == DATETIMELOCAL || m_type == MONTH || m_type == TIME || m_type == WEEK; } - virtual bool canTriggerImplicitSubmission() const { return isTextField(); } bool checked() const { return m_checked; } void setChecked(bool, bool sendChangeEvent = false); // 'indeterminate' is a state independent of the checked state that causes the control to draw in a way that hides the actual state. - bool allowsIndeterminate() const { return inputType() == CHECKBOX || inputType() == RADIO; } bool indeterminate() const { return m_indeterminate; } void setIndeterminate(bool); virtual int size() const; - virtual const AtomicString& formControlType() const; - void setType(const String&); - virtual const String& suggestedValue() const; - void setSuggestedValue(const String&); + void setType(const String&); virtual String value() const; virtual void setValue(const String&, bool sendChangeEvent = false); @@ -161,52 +126,28 @@ public: virtual String placeholder() const; virtual void setPlaceholder(const String&); - virtual bool searchEventsShouldBeDispatched() const; - String valueWithDefault() const; virtual void setValueFromRenderer(const String&); void setFileListFromRenderer(const Vector<String>&); - virtual bool saveFormControlState(String& value) const; - virtual void restoreFormControlState(const String&); - - virtual bool canStartSelection() const; - bool canHaveSelection() const; virtual void select() { HTMLTextFormControlElement::select(); } - virtual void accessKeyAction(bool sendToAnyElement); - - virtual bool mapToEntry(const QualifiedName& attrName, MappedAttributeEntry& result) const; - virtual void parseMappedAttribute(Attribute*); - - virtual void copyNonAttributeProperties(const Element* source); - - virtual void attach(); virtual bool rendererIsNeeded(RenderStyle*); virtual RenderObject* createRenderer(RenderArena*, RenderStyle*); virtual void detach(); - virtual bool appendFormData(FormDataList&, bool); - virtual bool isSuccessfulSubmitButton() const; + // FIXME: For isActivatedSubmit and setActivatedSubmit, we should use the NVI-idiom here by making + // it private virtual in all classes and expose a public method in HTMLFormControlElement to call + // the private virtual method. virtual bool isActivatedSubmit() const; virtual void setActivatedSubmit(bool flag); InputType inputType() const { return static_cast<InputType>(m_type); } void setInputType(const String&); - - // Report if this input type uses height & width attributes - bool respectHeightAndWidthAttrs() const { return inputType() == IMAGE || inputType() == HIDDEN; } - - virtual void reset(); - - virtual void* preDispatchEventHandler(Event*); - virtual void postDispatchEventHandler(Event*, void* dataFromPreDispatch); String altText() const; - - virtual bool isURLAttribute(Attribute*) const; int maxResults() const { return m_maxResults; } @@ -235,11 +176,6 @@ public: KURL src() const; void setSrc(const String&); -#if ENABLE(DATALIST) - HTMLElement* list() const; - HTMLOptionElement* selectedOption() const; -#endif - int maxLength() const; void setMaxLength(int, ExceptionCode&); @@ -254,32 +190,100 @@ public: FileList* files(); - virtual void cacheSelection(int start, int end); void addSearchResult(); void onSearch(); - virtual String sanitizeValue(const String&) const; - - virtual void documentDidBecomeActive(); - - virtual void addSubresourceAttributeURLs(ListHashSet<KURL>&) const; - // Parses the specified string as the InputType, and returns true if it is successfully parsed. // An instance pointed by the DateComponents* parameter will have parsed values and be // modified even if the parsing fails. The DateComponents* parameter may be 0. static bool parseToDateComponents(InputType, const String&, DateComponents*); -#if ENABLE(WCSS) - void setWapInputFormat(String& mask); - virtual InputElementData data() const { return m_data; } +#if ENABLE(DATALIST) + HTMLElement* list() const; + HTMLOptionElement* selectedOption() const; #endif - + protected: - virtual void willMoveToNewOwnerDocument(); - virtual void didMoveToNewOwnerDocument(); + HTMLInputElement(const QualifiedName&, Document*, HTMLFormElement* = 0); + virtual void defaultEventHandler(Event*); private: + enum AutoCompleteSetting { Uninitialized, On, Off }; + + virtual void willMoveToNewOwnerDocument(); + virtual void didMoveToNewOwnerDocument(); + + virtual HTMLTagStatus endTagRequirement() const { return TagStatusForbidden; } + virtual int tagPriority() const { return 0; } + + virtual bool isKeyboardFocusable(KeyboardEvent*) const; + virtual bool isMouseFocusable() const; + virtual bool isEnumeratable() const { return inputType() != IMAGE; } + virtual void updateFocusAppearance(bool restorePreviousSelection); + virtual void aboutToUnload(); + virtual bool shouldUseInputMethod() const; + + virtual const AtomicString& formControlName() const; + + // isChecked is used by the rendering tree/CSS while checked() is used by JS to determine checked state + virtual bool isChecked() const { return checked() && (inputType() == CHECKBOX || inputType() == RADIO); } + virtual bool isIndeterminate() const { return indeterminate(); } + + virtual bool isTextFormControl() const { return isTextField(); } + + virtual bool valueMissing() const; + virtual bool patternMismatch() const; + virtual bool tooLong() const; + + virtual bool hasSpinButton() const { return m_type == NUMBER || m_type == DATE || m_type == DATETIME || m_type == DATETIMELOCAL || m_type == MONTH || m_type == TIME || m_type == WEEK; } + virtual bool canTriggerImplicitSubmission() const { return isTextField(); } + + bool allowsIndeterminate() const { return inputType() == CHECKBOX || inputType() == RADIO; } + + virtual const AtomicString& formControlType() const; + + virtual const String& suggestedValue() const; + void setSuggestedValue(const String&); + + virtual bool searchEventsShouldBeDispatched() const; + + virtual bool saveFormControlState(String& value) const; + virtual void restoreFormControlState(const String&); + + virtual bool canStartSelection() const; + + virtual void accessKeyAction(bool sendToAnyElement); + + virtual bool mapToEntry(const QualifiedName& attrName, MappedAttributeEntry& result) const; + virtual void parseMappedAttribute(Attribute*); + + virtual void copyNonAttributeProperties(const Element* source); + + virtual void attach(); + + virtual bool appendFormData(FormDataList&, bool); + + virtual bool isSuccessfulSubmitButton() const; + + // Report if this input type uses height & width attributes + bool respectHeightAndWidthAttrs() const { return inputType() == IMAGE || inputType() == HIDDEN; } + + virtual void reset(); + + virtual void* preDispatchEventHandler(Event*); + virtual void postDispatchEventHandler(Event*, void* dataFromPreDispatch); + + virtual bool isURLAttribute(Attribute*) const; + + virtual void cacheSelection(int start, int end); + + virtual String sanitizeValue(const String&) const; + + virtual void documentDidBecomeActive(); + + virtual void addSubresourceAttributeURLs(ListHashSet<KURL>&) const; + bool storesValueSeparateFromAttribute() const; bool needsActivationCallback(); @@ -325,6 +329,11 @@ private: HTMLDataListElement* dataList() const; #endif +#if ENABLE(WCSS) + void setWapInputFormat(String& mask); + virtual InputElementData data() const { return m_data; } +#endif + InputElementData m_data; int m_xPos; int m_yPos; diff --git a/WebCore/html/HTMLInputElement.idl b/WebCore/html/HTMLInputElement.idl index 4563120..83b04e7 100644 --- a/WebCore/html/HTMLInputElement.idl +++ b/WebCore/html/HTMLInputElement.idl @@ -95,6 +95,7 @@ module html { #endif readonly attribute FileList files; + readonly attribute NodeList labels; }; } diff --git a/WebCore/html/HTMLIsIndexElement.cpp b/WebCore/html/HTMLIsIndexElement.cpp index 5cc73de..d382af5 100644 --- a/WebCore/html/HTMLIsIndexElement.cpp +++ b/WebCore/html/HTMLIsIndexElement.cpp @@ -2,7 +2,7 @@ * Copyright (C) 1999 Lars Knoll (knoll@kde.org) * (C) 1999 Antti Koivisto (koivisto@kde.org) * (C) 2001 Dirk Mueller (mueller@kde.org) - * Copyright (C) 2004, 2005, 2006 Apple Computer, Inc. + * Copyright (C) 2004, 2005, 2006, 2010 Apple Inc. All rights reserved. * (C) 2006 Alexey Proskuryakov (ap@nypop.com) * * This library is free software; you can redistribute it and/or @@ -32,13 +32,23 @@ namespace WebCore { using namespace HTMLNames; -HTMLIsIndexElement::HTMLIsIndexElement(const QualifiedName& tagName, Document *doc, HTMLFormElement *f) - : HTMLInputElement(tagName, doc, f) +HTMLIsIndexElement::HTMLIsIndexElement(const QualifiedName& tagName, Document* document, HTMLFormElement* form) + : HTMLInputElement(tagName, document, form) { ASSERT(hasTagName(isindexTag)); setDefaultName(isindexTag.localName()); } +PassRefPtr<HTMLIsIndexElement> HTMLIsIndexElement::create(Document* document, HTMLFormElement* form) +{ + return new HTMLIsIndexElement(isindexTag, document, form); +} + +PassRefPtr<HTMLIsIndexElement> HTMLIsIndexElement::create(const QualifiedName& tagName, Document* document, HTMLFormElement* form) +{ + return new HTMLIsIndexElement(tagName, document, form); +} + void HTMLIsIndexElement::parseMappedAttribute(Attribute* attr) { if (attr->name() == promptAttr) diff --git a/WebCore/html/HTMLIsIndexElement.h b/WebCore/html/HTMLIsIndexElement.h index f8124f6..528f3e2 100644 --- a/WebCore/html/HTMLIsIndexElement.h +++ b/WebCore/html/HTMLIsIndexElement.h @@ -2,7 +2,7 @@ * Copyright (C) 1999 Lars Knoll (knoll@kde.org) * (C) 1999 Antti Koivisto (koivisto@kde.org) * (C) 2000 Dirk Mueller (mueller@kde.org) - * Copyright (C) 2004, 2005, 2006 Apple Computer, Inc. + * Copyright (C) 2004, 2005, 2006, 2010 Apple Inc. All rights reserved. * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Library General Public @@ -20,6 +20,7 @@ * Boston, MA 02110-1301, USA. * */ + #ifndef HTMLIsIndexElement_h #define HTMLIsIndexElement_h @@ -29,21 +30,22 @@ namespace WebCore { class HTMLIsIndexElement : public HTMLInputElement { public: - HTMLIsIndexElement(const QualifiedName&, Document *doc, HTMLFormElement *f = 0); + static PassRefPtr<HTMLIsIndexElement> create(Document*, HTMLFormElement*); + static PassRefPtr<HTMLIsIndexElement> create(const QualifiedName&, Document*, HTMLFormElement*); + + String prompt() const; + void setPrompt(const String&); + +private: + HTMLIsIndexElement(const QualifiedName&, Document*, HTMLFormElement*); virtual HTMLTagStatus endTagRequirement() const { return TagStatusForbidden; } virtual int tagPriority() const { return 0; } virtual bool canTriggerImplicitSubmission() const { return true; } - virtual void parseMappedAttribute(Attribute* attr); - - String prompt() const; - void setPrompt(const String &); - -protected: - String m_prompt; + virtual void parseMappedAttribute(Attribute*); }; -} //namespace +} // namespace #endif diff --git a/WebCore/html/HTMLKeygenElement.cpp b/WebCore/html/HTMLKeygenElement.cpp index dbcc2b2..4318c65 100644 --- a/WebCore/html/HTMLKeygenElement.cpp +++ b/WebCore/html/HTMLKeygenElement.cpp @@ -2,7 +2,7 @@ * Copyright (C) 1999 Lars Knoll (knoll@kde.org) * (C) 1999 Antti Koivisto (koivisto@kde.org) * (C) 2001 Dirk Mueller (mueller@kde.org) - * Copyright (C) 2004, 2005, 2006 Apple Computer, Inc. + * Copyright (C) 2004, 2005, 2006, 2010 Apple Inc. All rights reserved. * (C) 2006 Alexey Proskuryakov (ap@nypop.com) * * This library is free software; you can redistribute it and/or @@ -40,21 +40,26 @@ namespace WebCore { using namespace HTMLNames; -HTMLKeygenElement::HTMLKeygenElement(const QualifiedName& tagName, Document* doc, HTMLFormElement* f) - : HTMLSelectElement(tagName, doc, f) +inline HTMLKeygenElement::HTMLKeygenElement(const QualifiedName& tagName, Document* document, HTMLFormElement* form) + : HTMLSelectElement(tagName, document, form) { ASSERT(hasTagName(keygenTag)); + + // Add one option element for each key size. Vector<String> keys; getSupportedKeySizes(keys); - - Vector<String>::const_iterator end = keys.end(); - for (Vector<String>::const_iterator it = keys.begin(); it != end; ++it) { - HTMLOptionElement* o = new HTMLOptionElement(optionTag, doc, form()); - addChild(o); - o->addChild(Text::create(doc, *it)); + for (size_t i = 0; i < keys.size(); ++i) { + RefPtr<HTMLOptionElement> option = HTMLOptionElement::create(document, this->form()); + addChild(option); + option->addChild(Text::create(document, keys[i])); } } +PassRefPtr<HTMLKeygenElement> HTMLKeygenElement::create(const QualifiedName& tagName, Document* document, HTMLFormElement* form) +{ + return new HTMLKeygenElement(tagName, document, form); +} + const AtomicString& HTMLKeygenElement::formControlType() const { DEFINE_STATIC_LOCAL(const AtomicString, keygen, ("keygen")); @@ -67,9 +72,10 @@ void HTMLKeygenElement::parseMappedAttribute(Attribute* attr) m_challenge = attr->value(); else if (attr->name() == keytypeAttr) m_keyType = attr->value(); - else - // skip HTMLSelectElement parsing! + else { + // Skip HTMLSelectElement parsing. HTMLFormControlElement::parseMappedAttribute(attr); + } } bool HTMLKeygenElement::appendFormData(FormDataList& encoded_values, bool) diff --git a/WebCore/html/HTMLKeygenElement.h b/WebCore/html/HTMLKeygenElement.h index 8b6b198..baa9a17 100644 --- a/WebCore/html/HTMLKeygenElement.h +++ b/WebCore/html/HTMLKeygenElement.h @@ -2,7 +2,7 @@ * Copyright (C) 1999 Lars Knoll (knoll@kde.org) * (C) 1999 Antti Koivisto (koivisto@kde.org) * (C) 2000 Dirk Mueller (mueller@kde.org) - * Copyright (C) 2004, 2005, 2006 Apple Computer, Inc. + * Copyright (C) 2004, 2005, 2006, 2010 Apple Inc. All rights reserved. * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Library General Public @@ -30,7 +30,10 @@ namespace WebCore { class HTMLKeygenElement : public HTMLSelectElement { public: - HTMLKeygenElement(const QualifiedName&, Document*, HTMLFormElement* = 0); + static PassRefPtr<HTMLKeygenElement> create(const QualifiedName&, Document*, HTMLFormElement*); + +private: + HTMLKeygenElement(const QualifiedName&, Document*, HTMLFormElement*); virtual int tagPriority() const { return 0; } virtual const AtomicString& formControlType() const; @@ -38,7 +41,6 @@ public: virtual void parseMappedAttribute(Attribute*); virtual bool appendFormData(FormDataList&, bool); -private: virtual bool isOptionalFormControl() const { return false; } AtomicString m_challenge; diff --git a/WebCore/html/HTMLLIElement.cpp b/WebCore/html/HTMLLIElement.cpp index 1bfb6f5..74c3468 100644 --- a/WebCore/html/HTMLLIElement.cpp +++ b/WebCore/html/HTMLLIElement.cpp @@ -1,7 +1,7 @@ -/** +/* * Copyright (C) 1999 Lars Knoll (knoll@kde.org) * (C) 1999 Antti Koivisto (koivisto@kde.org) - * Copyright (C) 2006, 2007 Apple Inc. All rights reserved. + * Copyright (C) 2006, 2007, 2010 Apple Inc. All rights reserved. * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Library General Public @@ -33,13 +33,23 @@ namespace WebCore { using namespace HTMLNames; -HTMLLIElement::HTMLLIElement(const QualifiedName& tagName, Document* doc) - : HTMLElement(tagName, doc) +HTMLLIElement::HTMLLIElement(const QualifiedName& tagName, Document* document) + : HTMLElement(tagName, document) , m_requestedValue(0) { ASSERT(hasTagName(liTag)); } +PassRefPtr<HTMLLIElement> HTMLLIElement::create(Document* document) +{ + return new HTMLLIElement(liTag, document); +} + +PassRefPtr<HTMLLIElement> HTMLLIElement::create(const QualifiedName& tagName, Document* document) +{ + return new HTMLLIElement(tagName, document); +} + bool HTMLLIElement::mapToEntry(const QualifiedName& attrName, MappedAttributeEntry& result) const { if (attrName == typeAttr) { diff --git a/WebCore/html/HTMLLIElement.h b/WebCore/html/HTMLLIElement.h index 6b46b41..5ce00f2 100644 --- a/WebCore/html/HTMLLIElement.h +++ b/WebCore/html/HTMLLIElement.h @@ -1,6 +1,7 @@ /* * Copyright (C) 1999 Lars Knoll (knoll@kde.org) * (C) 1999 Antti Koivisto (koivisto@kde.org) + * Copyright (C) 2010 Apple Inc. All rights reserved. * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Library General Public @@ -28,6 +29,16 @@ namespace WebCore { class HTMLLIElement : public HTMLElement { public: + static PassRefPtr<HTMLLIElement> create(Document*); + static PassRefPtr<HTMLLIElement> create(const QualifiedName&, Document*); + + String type() const; + void setType(const String&); + + int value() const; + void setValue(int); + +private: HTMLLIElement(const QualifiedName&, Document*); virtual HTMLTagStatus endTagRequirement() const { return TagStatusOptional; } @@ -38,13 +49,6 @@ public: virtual void attach(); - String type() const; - void setType(const String&); - - int value() const; - void setValue(int); - -private: int m_requestedValue; }; diff --git a/WebCore/html/HTMLLabelElement.cpp b/WebCore/html/HTMLLabelElement.cpp index 893106c..ed0fab6 100644 --- a/WebCore/html/HTMLLabelElement.cpp +++ b/WebCore/html/HTMLLabelElement.cpp @@ -2,7 +2,7 @@ * Copyright (C) 1999 Lars Knoll (knoll@kde.org) * (C) 1999 Antti Koivisto (koivisto@kde.org) * (C) 2001 Dirk Mueller (mueller@kde.org) - * Copyright (C) 2004, 2005, 2006, 2007 Apple Inc. ALl rights reserved. + * Copyright (C) 2004, 2005, 2006, 2007, 2010 Apple Inc. All rights reserved. * (C) 2006 Alexey Proskuryakov (ap@nypop.com) * * This library is free software; you can redistribute it and/or @@ -38,7 +38,7 @@ using namespace HTMLNames; static HTMLFormControlElement* nodeAsLabelableFormControl(Node* node) { - if (!node || !node->isHTMLElement() || !static_cast<HTMLElement*>(node)->isFormControlElement()) + if (!node || !node->isElementNode() || !static_cast<Element*>(node)->isFormControlElement()) return 0; HTMLFormControlElement* formControlElement = static_cast<HTMLFormControlElement*>(node); @@ -48,14 +48,15 @@ static HTMLFormControlElement* nodeAsLabelableFormControl(Node* node) return formControlElement; } -HTMLLabelElement::HTMLLabelElement(const QualifiedName& tagName, Document *doc) - : HTMLElement(tagName, doc) +inline HTMLLabelElement::HTMLLabelElement(const QualifiedName& tagName, Document* document) + : HTMLElement(tagName, document) { ASSERT(hasTagName(labelTag)); } -HTMLLabelElement::~HTMLLabelElement() +PassRefPtr<HTMLLabelElement> HTMLLabelElement::create(const QualifiedName& tagName, Document* document) { + return new HTMLLabelElement(tagName, document); } bool HTMLLabelElement::isFocusable() const @@ -173,4 +174,15 @@ void HTMLLabelElement::setHtmlFor(const String &value) setAttribute(forAttr, value); } +void HTMLLabelElement::parseMappedAttribute(Attribute* attribute) +{ + if (attribute->name() == forAttr) { + // htmlFor attribute change affects other nodes than this. + // Clear the caches to ensure that the labels caches are cleared. + if (document()) + document()->notifyLocalNodeListsLabelChanged(); + } else + HTMLElement::parseMappedAttribute(attribute); +} + } // namespace diff --git a/WebCore/html/HTMLLabelElement.h b/WebCore/html/HTMLLabelElement.h index 48622f9..759ffcd 100644 --- a/WebCore/html/HTMLLabelElement.h +++ b/WebCore/html/HTMLLabelElement.h @@ -2,7 +2,7 @@ * Copyright (C) 1999 Lars Knoll (knoll@kde.org) * (C) 1999 Antti Koivisto (koivisto@kde.org) * (C) 2000 Dirk Mueller (mueller@kde.org) - * Copyright (C) 2004, 2005, 2006, 2007 Apple Inc. All rights reserved. + * Copyright (C) 2004, 2005, 2006, 2007, 2010 Apple Inc. All rights reserved. * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Library General Public @@ -31,8 +31,18 @@ namespace WebCore { class HTMLLabelElement : public HTMLElement { public: + static PassRefPtr<HTMLLabelElement> create(const QualifiedName&, Document*); + + HTMLFormControlElement* control(); + + String accessKey() const; + void setAccessKey(const String&); + + String htmlFor() const; + void setHtmlFor(const String&); + +private: HTMLLabelElement(const QualifiedName&, Document*); - virtual ~HTMLLabelElement(); virtual int tagPriority() const { return 5; } @@ -47,18 +57,9 @@ public: // Overridden to either click() or focus() the corresponding control. virtual void defaultEventHandler(Event*); - HTMLFormControlElement* control(); - - String accessKey() const; - void setAccessKey(const String&); - - String htmlFor() const; - void setHtmlFor(const String&); - void focus(bool restorePreviousSelection = true); - private: - String m_formElementID; + virtual void parseMappedAttribute(Attribute*); }; } //namespace diff --git a/WebCore/html/HTMLLegendElement.cpp b/WebCore/html/HTMLLegendElement.cpp index 516ca54..0aa4142 100644 --- a/WebCore/html/HTMLLegendElement.cpp +++ b/WebCore/html/HTMLLegendElement.cpp @@ -2,7 +2,7 @@ * Copyright (C) 1999 Lars Knoll (knoll@kde.org) * (C) 1999 Antti Koivisto (koivisto@kde.org) * (C) 2001 Dirk Mueller (mueller@kde.org) - * Copyright (C) 2004, 2005, 2006 Apple Computer, Inc. + * Copyright (C) 2004, 2005, 2006, 2010 Apple Inc. All rights reserved. * (C) 2006 Alexey Proskuryakov (ap@nypop.com) * * This library is free software; you can redistribute it and/or @@ -32,14 +32,15 @@ namespace WebCore { using namespace HTMLNames; -HTMLLegendElement::HTMLLegendElement(const QualifiedName& tagName, Document *doc, HTMLFormElement *f) - : HTMLFormControlElement(tagName, doc, f) +inline HTMLLegendElement::HTMLLegendElement(const QualifiedName& tagName, Document* document, HTMLFormElement* form) + : HTMLFormControlElement(tagName, document, form) { ASSERT(hasTagName(legendTag)); } -HTMLLegendElement::~HTMLLegendElement() +PassRefPtr<HTMLLegendElement> HTMLLegendElement::create(const QualifiedName& tagName, Document* document, HTMLFormElement* form) { + return new HTMLLegendElement(tagName, document, form); } bool HTMLLegendElement::supportsFocus() const @@ -73,23 +74,23 @@ void HTMLLegendElement::setAlign(const String &value) setAttribute(alignAttr, value); } -Element *HTMLLegendElement::formElement() +HTMLFormControlElement* HTMLLegendElement::associatedControl() { // Check if there's a fieldset belonging to this legend. - Node *fieldset = parentNode(); + Node* fieldset = parentNode(); while (fieldset && !fieldset->hasTagName(fieldsetTag)) fieldset = fieldset->parentNode(); if (!fieldset) return 0; - // Find first form element inside the fieldset. - // FIXME: Should we care about tabindex? - Node *node = fieldset; + // Find first form element inside the fieldset that is not a legend element. + // FIXME: Should we consider tabindex? + Node* node = fieldset; while ((node = node->traverseNextNode(fieldset))) { - if (node->isHTMLElement()) { - HTMLElement *element = static_cast<HTMLElement *>(node); + if (node->isElementNode()) { + Element* element = static_cast<Element*>(node); if (!element->hasLocalName(legendTag) && element->isFormControlElement()) - return element; + return static_cast<HTMLFormControlElement*>(element); } } @@ -101,15 +102,15 @@ void HTMLLegendElement::focus(bool) if (isFocusable()) Element::focus(); - // to match other browsers, never restore previous selection - if (Element *element = formElement()) - element->focus(false); + // To match other browsers' behavior, never restore previous selection. + if (HTMLFormControlElement* control = associatedControl()) + control->focus(false); } void HTMLLegendElement::accessKeyAction(bool sendToAnyElement) { - if (Element *element = formElement()) - element->accessKeyAction(sendToAnyElement); + if (HTMLFormControlElement* control = associatedControl()) + control->accessKeyAction(sendToAnyElement); } } // namespace diff --git a/WebCore/html/HTMLLegendElement.h b/WebCore/html/HTMLLegendElement.h index 1b394e4..fa2aa2b 100644 --- a/WebCore/html/HTMLLegendElement.h +++ b/WebCore/html/HTMLLegendElement.h @@ -2,7 +2,7 @@ * Copyright (C) 1999 Lars Knoll (knoll@kde.org) * (C) 1999 Antti Koivisto (koivisto@kde.org) * (C) 2000 Dirk Mueller (mueller@kde.org) - * Copyright (C) 2004, 2005, 2006 Apple Computer, Inc. + * Copyright (C) 2004, 2005, 2006, 2010 Apple Inc. All rights reserved. * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Library General Public @@ -30,25 +30,24 @@ namespace WebCore { class HTMLLegendElement : public HTMLFormControlElement { public: - HTMLLegendElement(const QualifiedName&, Document*, HTMLFormElement* = 0); - virtual ~HTMLLegendElement(); - - virtual bool supportsFocus() const; - virtual const AtomicString& formControlType() const; - virtual void accessKeyAction(bool sendToAnyElement); - - /** - * The first form element in the legend's fieldset - */ - Element* formElement(); + static PassRefPtr<HTMLLegendElement> create(const QualifiedName&, Document*, HTMLFormElement*); String accessKey() const; - void setAccessKey(const String &); + void setAccessKey(const String&); String align() const; - void setAlign(const String &); + void setAlign(const String&); - void focus(bool restorePreviousSelection = true); +private: + HTMLLegendElement(const QualifiedName&, Document*, HTMLFormElement*); + + // Control in the legend's fieldset that gets focus and access key. + HTMLFormControlElement* associatedControl(); + + virtual bool supportsFocus() const; + virtual const AtomicString& formControlType() const; + virtual void accessKeyAction(bool sendToAnyElement); + virtual void focus(bool restorePreviousSelection = true); }; } //namespace diff --git a/WebCore/html/HTMLLinkElement.cpp b/WebCore/html/HTMLLinkElement.cpp index c02c4fe..e5f7b26 100644 --- a/WebCore/html/HTMLLinkElement.cpp +++ b/WebCore/html/HTMLLinkElement.cpp @@ -49,9 +49,8 @@ namespace WebCore { using namespace HTMLNames; -HTMLLinkElement::HTMLLinkElement(const QualifiedName& qName, Document *doc, bool createdByParser) - : HTMLElement(qName, doc) - , m_cachedSheet(0) +inline HTMLLinkElement::HTMLLinkElement(const QualifiedName& tagName, Document* document, bool createdByParser) + : HTMLElement(tagName, document) , m_disabledState(Unset) , m_loading(false) , m_createdByParser(createdByParser) @@ -60,6 +59,11 @@ HTMLLinkElement::HTMLLinkElement(const QualifiedName& qName, Document *doc, bool ASSERT(hasTagName(linkTag)); } +PassRefPtr<HTMLLinkElement> HTMLLinkElement::create(const QualifiedName& tagName, Document* document, bool createdByParser) +{ + return new HTMLLinkElement(tagName, document, createdByParser); +} + HTMLLinkElement::~HTMLLinkElement() { if (m_cachedSheet) { diff --git a/WebCore/html/HTMLLinkElement.h b/WebCore/html/HTMLLinkElement.h index 8da4494..ae88c44 100644 --- a/WebCore/html/HTMLLinkElement.h +++ b/WebCore/html/HTMLLinkElement.h @@ -60,11 +60,8 @@ public: { }; }; - HTMLLinkElement(const QualifiedName&, Document*, bool createdByParser); - ~HTMLLinkElement(); - - virtual HTMLTagStatus endTagRequirement() const { return TagStatusForbidden; } - virtual int tagPriority() const { return 0; } + static PassRefPtr<HTMLLinkElement> create(const QualifiedName&, Document*, bool createdByParser); + virtual ~HTMLLinkElement(); bool disabled() const; void setDisabled(bool); @@ -95,7 +92,16 @@ public: StyleSheet* sheet() const; - // overload from HTMLElement + bool isLoading() const; + + bool isDisabled() const { return m_disabledState == Disabled; } + bool isEnabledViaScript() const { return m_disabledState == EnabledViaScript; } + bool isIcon() const { return m_relAttribute.m_isIcon; } + +private: + virtual HTMLTagStatus endTagRequirement() const { return TagStatusForbidden; } + virtual int tagPriority() const { return 0; } + virtual void parseMappedAttribute(Attribute*); void process(); @@ -105,26 +111,29 @@ public: // from CachedResourceClient virtual void setCSSStyleSheet(const String& href, const KURL& baseURL, const String& charset, const CachedCSSStyleSheet* sheet); +<<<<<<< HEAD virtual void notifyFinished(CachedResource*); bool isLoading() const; +======= +>>>>>>> webkit.org at r60469 virtual bool sheetLoaded(); bool isAlternate() const { return m_disabledState == Unset && m_relAttribute.m_isAlternate; } - bool isDisabled() const { return m_disabledState == Disabled; } - bool isEnabledViaScript() const { return m_disabledState == EnabledViaScript; } - bool isIcon() const { return m_relAttribute.m_isIcon; } void setDisabledState(bool _disabled); virtual bool isURLAttribute(Attribute*) const; +public: static void tokenizeRelAttribute(const AtomicString& value, RelAttribute&); +private: virtual void addSubresourceAttributeURLs(ListHashSet<KURL>&) const; virtual void finishParsingChildren(); +<<<<<<< HEAD #ifdef ANDROID_INSTRUMENT // Overridden to resolve the ambiguous void* operator new(size_t size); @@ -135,6 +144,10 @@ public: protected: void timerFired(Timer<HTMLLinkElement>*); +======= +private: + HTMLLinkElement(const QualifiedName&, Document*, bool createdByParser); +>>>>>>> webkit.org at r60469 enum DisabledState { Unset, diff --git a/WebCore/html/HTMLMapElement.cpp b/WebCore/html/HTMLMapElement.cpp index cc709a0..1395cbb 100644 --- a/WebCore/html/HTMLMapElement.cpp +++ b/WebCore/html/HTMLMapElement.cpp @@ -1,7 +1,7 @@ /* * Copyright (C) 1999 Lars Knoll (knoll@kde.org) * (C) 1999 Antti Koivisto (koivisto@kde.org) - * Copyright (C) 2004, 2005, 2006, 2007 Apple Inc. All rights reserved. + * Copyright (C) 2004, 2005, 2006, 2007, 2010 Apple Inc. All rights reserved. * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Library General Public @@ -38,12 +38,22 @@ namespace WebCore { using namespace HTMLNames; -HTMLMapElement::HTMLMapElement(const QualifiedName& tagName, Document* doc) - : HTMLElement(tagName, doc) +HTMLMapElement::HTMLMapElement(const QualifiedName& tagName, Document* document) + : HTMLElement(tagName, document) { ASSERT(hasTagName(mapTag)); } +PassRefPtr<HTMLMapElement> HTMLMapElement::create(Document* document) +{ + return new HTMLMapElement(mapTag, document); +} + +PassRefPtr<HTMLMapElement> HTMLMapElement::create(const QualifiedName& tagName, Document* document) +{ + return new HTMLMapElement(tagName, document); +} + HTMLMapElement::~HTMLMapElement() { document()->removeImageMap(this); diff --git a/WebCore/html/HTMLMapElement.h b/WebCore/html/HTMLMapElement.h index 8dc9edf..9c8ab79 100644 --- a/WebCore/html/HTMLMapElement.h +++ b/WebCore/html/HTMLMapElement.h @@ -1,7 +1,7 @@ /* * Copyright (C) 1999 Lars Knoll (knoll@kde.org) * (C) 1999 Antti Koivisto (koivisto@kde.org) - * Copyright (C) 2004 Apple Computer, Inc. + * Copyright (C) 2004, 2010 Apple Inc. All rights reserved. * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Library General Public @@ -33,17 +33,12 @@ class HTMLImageElement; class HTMLMapElement : public HTMLElement { public: - HTMLMapElement(const QualifiedName&, Document*); - ~HTMLMapElement(); - - virtual HTMLTagStatus endTagRequirement() const { return TagStatusRequired; } - virtual int tagPriority() const { return 1; } - virtual bool checkDTD(const Node*); + static PassRefPtr<HTMLMapElement> create(Document*); + static PassRefPtr<HTMLMapElement> create(const QualifiedName&, Document*); + virtual ~HTMLMapElement(); const AtomicString& getName() const { return m_name; } - virtual void parseMappedAttribute(Attribute*); - bool mapMouseEvent(int x, int y, const IntSize&, HitTestResult&); HTMLImageElement* imageElement() const; @@ -53,6 +48,14 @@ public: void setName(const String&); private: + HTMLMapElement(const QualifiedName&, Document*); + + virtual HTMLTagStatus endTagRequirement() const { return TagStatusRequired; } + virtual int tagPriority() const { return 1; } + virtual bool checkDTD(const Node*); + + virtual void parseMappedAttribute(Attribute*); + AtomicString m_name; }; diff --git a/WebCore/html/HTMLMarqueeElement.cpp b/WebCore/html/HTMLMarqueeElement.cpp index 23122dc..c16b069 100644 --- a/WebCore/html/HTMLMarqueeElement.cpp +++ b/WebCore/html/HTMLMarqueeElement.cpp @@ -1,7 +1,7 @@ -/** +/* * Copyright (C) 1999 Lars Knoll (knoll@kde.org) * (C) 1999 Antti Koivisto (koivisto@kde.org) - * Copyright (C) 2003, 2007 Apple Inc. All rights reserved. + * Copyright (C) 2003, 2007, 2010 Apple Inc. All rights reserved. * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Library General Public @@ -37,14 +37,19 @@ using namespace HTMLNames; // WinIE uses 60ms as the minimum delay by default. const int defaultMinimumDelay = 60; -HTMLMarqueeElement::HTMLMarqueeElement(const QualifiedName& tagName, Document* doc) - : HTMLElement(tagName, doc) - , ActiveDOMObject(doc, this) +inline HTMLMarqueeElement::HTMLMarqueeElement(const QualifiedName& tagName, Document* document) + : HTMLElement(tagName, document) + , ActiveDOMObject(document, this) , m_minimumDelay(defaultMinimumDelay) { ASSERT(hasTagName(marqueeTag)); } +PassRefPtr<HTMLMarqueeElement> HTMLMarqueeElement::create(const QualifiedName& tagName, Document* document) +{ + return new HTMLMarqueeElement(tagName, document); +} + bool HTMLMarqueeElement::mapToEntry(const QualifiedName& attrName, MappedAttributeEntry& result) const { if (attrName == widthAttr || diff --git a/WebCore/html/HTMLMarqueeElement.h b/WebCore/html/HTMLMarqueeElement.h index 871edc8..4932d46 100644 --- a/WebCore/html/HTMLMarqueeElement.h +++ b/WebCore/html/HTMLMarqueeElement.h @@ -1,7 +1,7 @@ /* * Copyright (C) 1999 Lars Knoll (knoll@kde.org) * (C) 1999 Antti Koivisto (koivisto@kde.org) - * Copyright (C) 2007 Apple Inc. All rights reserved. + * Copyright (C) 2007, 2010 Apple Inc. All rights reserved. * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Library General Public @@ -32,13 +32,7 @@ class RenderMarquee; class HTMLMarqueeElement : public HTMLElement, private ActiveDOMObject { public: - HTMLMarqueeElement(const QualifiedName&, Document*); - - virtual HTMLTagStatus endTagRequirement() const { return TagStatusRequired; } - virtual int tagPriority() const { return 3; } - - virtual bool mapToEntry(const QualifiedName&, MappedAttributeEntry&) const; - virtual void parseMappedAttribute(Attribute*); + static PassRefPtr<HTMLMarqueeElement> create(const QualifiedName&, Document*); int minimumDelay() const { return m_minimumDelay; } @@ -48,6 +42,14 @@ public: void stop(); private: + HTMLMarqueeElement(const QualifiedName&, Document*); + + virtual HTMLTagStatus endTagRequirement() const { return TagStatusRequired; } + virtual int tagPriority() const { return 3; } + + virtual bool mapToEntry(const QualifiedName&, MappedAttributeEntry&) const; + virtual void parseMappedAttribute(Attribute*); + // ActiveDOMObject virtual bool canSuspend() const; virtual void suspend(); diff --git a/WebCore/html/HTMLMenuElement.cpp b/WebCore/html/HTMLMenuElement.cpp index 69497ef..92030b5 100644 --- a/WebCore/html/HTMLMenuElement.cpp +++ b/WebCore/html/HTMLMenuElement.cpp @@ -1,6 +1,7 @@ -/** +/* * Copyright (C) 1999 Lars Knoll (knoll@kde.org) * (C) 1999 Antti Koivisto (koivisto@kde.org) + * Copyright (C) 2010 Apple Inc. All rights reserved. * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Library General Public @@ -18,6 +19,7 @@ * Boston, MA 02110-1301, USA. * */ + #include "config.h" #include "HTMLMenuElement.h" @@ -27,12 +29,17 @@ namespace WebCore { using namespace HTMLNames; -HTMLMenuElement::HTMLMenuElement(const QualifiedName& tagName, Document* doc) - : HTMLElement(tagName, doc) +inline HTMLMenuElement::HTMLMenuElement(const QualifiedName& tagName, Document* document) + : HTMLElement(tagName, document) { ASSERT(hasTagName(menuTag)); } +PassRefPtr<HTMLMenuElement> HTMLMenuElement::create(const QualifiedName& tagName, Document* document) +{ + return new HTMLMenuElement(tagName, document); +} + bool HTMLMenuElement::compact() const { return !getAttribute(compactAttr).isNull(); diff --git a/WebCore/html/HTMLMenuElement.h b/WebCore/html/HTMLMenuElement.h index 68b5b8f..7534e81 100644 --- a/WebCore/html/HTMLMenuElement.h +++ b/WebCore/html/HTMLMenuElement.h @@ -1,6 +1,7 @@ /* * Copyright (C) 1999 Lars Knoll (knoll@kde.org) * (C) 1999 Antti Koivisto (koivisto@kde.org) + * Copyright (C) 2010 Apple Inc. All rights reserved. * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Library General Public @@ -28,13 +29,16 @@ namespace WebCore { class HTMLMenuElement : public HTMLElement { public: + static PassRefPtr<HTMLMenuElement> create(const QualifiedName&, Document*); + + bool compact() const; + void setCompact(bool); + +private: HTMLMenuElement(const QualifiedName&, Document*); virtual HTMLTagStatus endTagRequirement() const { return TagStatusRequired; } virtual int tagPriority() const { return 5; } - - bool compact() const; - void setCompact(bool); }; } //namespace diff --git a/WebCore/html/HTMLMetaElement.cpp b/WebCore/html/HTMLMetaElement.cpp index 70129b1..b4610e0 100644 --- a/WebCore/html/HTMLMetaElement.cpp +++ b/WebCore/html/HTMLMetaElement.cpp @@ -1,8 +1,8 @@ -/** +/* * Copyright (C) 1999 Lars Knoll (knoll@kde.org) * (C) 1999 Antti Koivisto (koivisto@kde.org) * (C) 2001 Dirk Mueller (mueller@kde.org) - * Copyright (C) 2003 Apple Computer, Inc. + * Copyright (C) 2003, 2010 Apple Inc. All rights reserved. * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Library General Public @@ -36,14 +36,15 @@ namespace WebCore { using namespace HTMLNames; -HTMLMetaElement::HTMLMetaElement(const QualifiedName& tagName, Document* doc) - : HTMLElement(tagName, doc) +inline HTMLMetaElement::HTMLMetaElement(const QualifiedName& tagName, Document* document) + : HTMLElement(tagName, document) { ASSERT(hasTagName(metaTag)); } -HTMLMetaElement::~HTMLMetaElement() +PassRefPtr<HTMLMetaElement> HTMLMetaElement::create(const QualifiedName& tagName, Document* document) { + return new HTMLMetaElement(tagName, document); } void HTMLMetaElement::parseMappedAttribute(Attribute* attr) diff --git a/WebCore/html/HTMLMetaElement.h b/WebCore/html/HTMLMetaElement.h index 61d6a86..7708a50 100644 --- a/WebCore/html/HTMLMetaElement.h +++ b/WebCore/html/HTMLMetaElement.h @@ -1,7 +1,7 @@ /* * Copyright (C) 1999 Lars Knoll (knoll@kde.org) * (C) 1999 Antti Koivisto (koivisto@kde.org) - * Copyright (C) 2003 Apple Computer, Inc. + * Copyright (C) 2003, 2010 Apple Inc. All rights reserved. * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Library General Public @@ -19,6 +19,7 @@ * Boston, MA 02110-1301, USA. * */ + #ifndef HTMLMetaElement_h #define HTMLMetaElement_h @@ -28,16 +29,7 @@ namespace WebCore { class HTMLMetaElement : public HTMLElement { public: - HTMLMetaElement(const QualifiedName&, Document*); - ~HTMLMetaElement(); - - virtual HTMLTagStatus endTagRequirement() const { return TagStatusForbidden; } - virtual int tagPriority() const { return 0; } - - virtual void parseMappedAttribute(Attribute*); - virtual void insertedIntoDocument(); - - void process(); + static PassRefPtr<HTMLMetaElement> create(const QualifiedName&, Document*); String content() const; void setContent(const String&); @@ -51,7 +43,17 @@ public: String scheme() const; void setScheme(const String&); -protected: +private: + HTMLMetaElement(const QualifiedName&, Document*); + + virtual HTMLTagStatus endTagRequirement() const { return TagStatusForbidden; } + virtual int tagPriority() const { return 0; } + + virtual void parseMappedAttribute(Attribute*); + virtual void insertedIntoDocument(); + + void process(); + String m_equiv; String m_content; }; diff --git a/WebCore/html/HTMLMeterElement.idl b/WebCore/html/HTMLMeterElement.idl index e061764..2b0e03f 100644 --- a/WebCore/html/HTMLMeterElement.idl +++ b/WebCore/html/HTMLMeterElement.idl @@ -34,5 +34,6 @@ module html { attribute double optimum setter raises(DOMException); readonly attribute HTMLFormElement form; + readonly attribute NodeList labels; }; } diff --git a/WebCore/html/HTMLModElement.cpp b/WebCore/html/HTMLModElement.cpp index 19b3403..a745e44 100644 --- a/WebCore/html/HTMLModElement.cpp +++ b/WebCore/html/HTMLModElement.cpp @@ -1,8 +1,8 @@ -/** +/* * Copyright (C) 1999 Lars Knoll (knoll@kde.org) * (C) 1999 Antti Koivisto (koivisto@kde.org) * (C) 2000 Simon Hausmann <hausmann@kde.org> - * Copyright (C) 2003, 2006 Apple Computer, Inc. + * Copyright (C) 2003, 2006, 2010 Apple Inc. All rights reserved. * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Library General Public @@ -19,6 +19,7 @@ * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, * Boston, MA 02110-1301, USA. */ + #include "config.h" #include "HTMLModElement.h" @@ -28,9 +29,14 @@ namespace WebCore { using namespace HTMLNames; -HTMLModElement::HTMLModElement(const QualifiedName& tagName, Document *doc) - : HTMLElement(tagName, doc) +inline HTMLModElement::HTMLModElement(const QualifiedName& tagName, Document* document) + : HTMLElement(tagName, document) +{ +} + +PassRefPtr<HTMLModElement> HTMLModElement::create(const QualifiedName& tagName, Document* document) { + return new HTMLModElement(tagName, document); } String HTMLModElement::cite() const diff --git a/WebCore/html/HTMLModElement.h b/WebCore/html/HTMLModElement.h index 9d9e6c1..af003d7 100644 --- a/WebCore/html/HTMLModElement.h +++ b/WebCore/html/HTMLModElement.h @@ -2,6 +2,7 @@ * Copyright (C) 1999 Lars Knoll (knoll@kde.org) * (C) 1999 Antti Koivisto (koivisto@kde.org) * (C) 2000 Simon Hausmann <hausmann@kde.org> + * Copyright (C) 2010 Apple Inc. All rights reserved. * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Library General Public @@ -19,6 +20,7 @@ * Boston, MA 02110-1301, USA. * */ + #ifndef HTMLModElement_h #define HTMLModElement_h @@ -26,20 +28,21 @@ namespace WebCore { -class String; - class HTMLModElement : public HTMLElement { public: - HTMLModElement(const QualifiedName&, Document*); - - virtual HTMLTagStatus endTagRequirement() const { return TagStatusRequired; } - virtual int tagPriority() const { return 1; } + static PassRefPtr<HTMLModElement> create(const QualifiedName&, Document*); String cite() const; void setCite(const String&); String dateTime() const; void setDateTime(const String&); + +private: + HTMLModElement(const QualifiedName&, Document*); + + virtual HTMLTagStatus endTagRequirement() const { return TagStatusRequired; } + virtual int tagPriority() const { return 1; } }; } //namespace diff --git a/WebCore/html/HTMLNoScriptElement.cpp b/WebCore/html/HTMLNoScriptElement.cpp index 3bbfbe6..eda2110 100644 --- a/WebCore/html/HTMLNoScriptElement.cpp +++ b/WebCore/html/HTMLNoScriptElement.cpp @@ -1,5 +1,6 @@ /* * Copyright (C) 2009 Torch Mobile Inc. All rights reserved. (http://www.torchmobile.com/) + * Copyright (C) 2010 Apple Inc. All rights reserved. * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Library General Public @@ -30,14 +31,15 @@ namespace WebCore { using namespace HTMLNames; -HTMLNoScriptElement::HTMLNoScriptElement(const QualifiedName& tagName, Document* doc) - : HTMLElement(tagName, doc) +inline HTMLNoScriptElement::HTMLNoScriptElement(const QualifiedName& tagName, Document* document) + : HTMLElement(tagName, document) { ASSERT(hasTagName(noscriptTag)); } -HTMLNoScriptElement::~HTMLNoScriptElement() +PassRefPtr<HTMLNoScriptElement> HTMLNoScriptElement::create(const QualifiedName& tagName, Document* document) { + return new HTMLNoScriptElement(tagName, document); } bool HTMLNoScriptElement::checkDTD(const Node* newChild) @@ -76,10 +78,11 @@ void HTMLNoScriptElement::recalcStyle(StyleChange change) } } -bool HTMLNoScriptElement::childShouldCreateRenderer(Node* child) const +bool HTMLNoScriptElement::childShouldCreateRenderer(Node*) const { return document()->shouldProcessNoscriptElement(); } } + #endif diff --git a/WebCore/html/HTMLNoScriptElement.h b/WebCore/html/HTMLNoScriptElement.h index 2cc5a3c..8b98205 100644 --- a/WebCore/html/HTMLNoScriptElement.h +++ b/WebCore/html/HTMLNoScriptElement.h @@ -1,5 +1,6 @@ /* * Copyright (C) 2009 Torch Mobile Inc. All rights reserved. (http://www.torchmobile.com/) + * Copyright (C) 2010 Apple Inc. All rights reserved. * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Library General Public @@ -28,10 +29,10 @@ namespace WebCore { class HTMLNoScriptElement : public HTMLElement { public: - HTMLNoScriptElement(const QualifiedName&, Document*); + static PassRefPtr<HTMLNoScriptElement> create(const QualifiedName&, Document*); private: - virtual ~HTMLNoScriptElement(); + HTMLNoScriptElement(const QualifiedName&, Document*); virtual bool checkDTD(const Node*); virtual void attach(); diff --git a/WebCore/html/HTMLOListElement.cpp b/WebCore/html/HTMLOListElement.cpp index 82c4526..277b809 100644 --- a/WebCore/html/HTMLOListElement.cpp +++ b/WebCore/html/HTMLOListElement.cpp @@ -1,6 +1,7 @@ /* * Copyright (C) 1999 Lars Knoll (knoll@kde.org) * (C) 1999 Antti Koivisto (koivisto@kde.org) + * Copyright (C) 2010 Apple Inc. All rights reserved. * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Library General Public @@ -32,13 +33,23 @@ namespace WebCore { using namespace HTMLNames; -HTMLOListElement::HTMLOListElement(const QualifiedName& tagName, Document* doc) - : HTMLElement(tagName, doc) +HTMLOListElement::HTMLOListElement(const QualifiedName& tagName, Document* document) + : HTMLElement(tagName, document) , m_start(1) { ASSERT(hasTagName(olTag)); } +PassRefPtr<HTMLOListElement> HTMLOListElement::create(Document* document) +{ + return new HTMLOListElement(olTag, document); +} + +PassRefPtr<HTMLOListElement> HTMLOListElement::create(const QualifiedName& tagName, Document* document) +{ + return new HTMLOListElement(tagName, document); +} + bool HTMLOListElement::mapToEntry(const QualifiedName& attrName, MappedAttributeEntry& result) const { if (attrName == typeAttr) { @@ -102,4 +113,5 @@ void HTMLOListElement::setType(const String& value) { setAttribute(typeAttr, value); } + } diff --git a/WebCore/html/HTMLOListElement.h b/WebCore/html/HTMLOListElement.h index 3d76abf..871c34c 100644 --- a/WebCore/html/HTMLOListElement.h +++ b/WebCore/html/HTMLOListElement.h @@ -1,6 +1,7 @@ /* * Copyright (C) 1999 Lars Knoll (knoll@kde.org) * (C) 1999 Antti Koivisto (koivisto@kde.org) + * Copyright (C) 2010 Apple Inc. All rights reserved. * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Library General Public @@ -28,13 +29,8 @@ namespace WebCore { class HTMLOListElement : public HTMLElement { public: - HTMLOListElement(const QualifiedName&, Document*); - - virtual HTMLTagStatus endTagRequirement() const { return TagStatusRequired; } - virtual int tagPriority() const { return 5; } - - virtual bool mapToEntry(const QualifiedName&, MappedAttributeEntry&) const; - virtual void parseMappedAttribute(Attribute*); + static PassRefPtr<HTMLOListElement> create(Document*); + static PassRefPtr<HTMLOListElement> create(const QualifiedName&, Document*); bool compact() const; void setCompact(bool); @@ -46,6 +42,14 @@ public: void setType(const String&); private: + HTMLOListElement(const QualifiedName&, Document*); + + virtual HTMLTagStatus endTagRequirement() const { return TagStatusRequired; } + virtual int tagPriority() const { return 5; } + + virtual bool mapToEntry(const QualifiedName&, MappedAttributeEntry&) const; + virtual void parseMappedAttribute(Attribute*); + int m_start; }; diff --git a/WebCore/html/HTMLOptGroupElement.cpp b/WebCore/html/HTMLOptGroupElement.cpp index 5c5faac..b98b668 100644 --- a/WebCore/html/HTMLOptGroupElement.cpp +++ b/WebCore/html/HTMLOptGroupElement.cpp @@ -2,7 +2,7 @@ * Copyright (C) 1999 Lars Knoll (knoll@kde.org) * (C) 1999 Antti Koivisto (koivisto@kde.org) * (C) 2001 Dirk Mueller (mueller@kde.org) - * Copyright (C) 2004, 2005, 2006, 2007, 2008 Apple Inc. All rights reserved. + * Copyright (C) 2004, 2005, 2006, 2007, 2008, 2010 Apple Inc. All rights reserved. * (C) 2006 Alexey Proskuryakov (ap@nypop.com) * * This library is free software; you can redistribute it and/or @@ -37,13 +37,17 @@ namespace WebCore { using namespace HTMLNames; -HTMLOptGroupElement::HTMLOptGroupElement(const QualifiedName& tagName, Document* doc, HTMLFormElement* f) - : HTMLFormControlElement(tagName, doc, f) - , m_style(0) +inline HTMLOptGroupElement::HTMLOptGroupElement(const QualifiedName& tagName, Document* document, HTMLFormElement* form) + : HTMLFormControlElement(tagName, document, form) { ASSERT(hasTagName(optgroupTag)); } +PassRefPtr<HTMLOptGroupElement> HTMLOptGroupElement::create(const QualifiedName& tagName, Document* document, HTMLFormElement* form) +{ + return new HTMLOptGroupElement(tagName, document, form); +} + bool HTMLOptGroupElement::supportsFocus() const { return HTMLElement::supportsFocus(); @@ -61,36 +65,6 @@ const AtomicString& HTMLOptGroupElement::formControlType() const return optgroup; } -bool HTMLOptGroupElement::insertBefore(PassRefPtr<Node> newChild, Node* refChild, ExceptionCode& ec, bool shouldLazyAttach) -{ - bool result = HTMLFormControlElement::insertBefore(newChild, refChild, ec, shouldLazyAttach); - return result; -} - -bool HTMLOptGroupElement::replaceChild(PassRefPtr<Node> newChild, Node* oldChild, ExceptionCode& ec, bool shouldLazyAttach) -{ - bool result = HTMLFormControlElement::replaceChild(newChild, oldChild, ec, shouldLazyAttach); - return result; -} - -bool HTMLOptGroupElement::removeChild(Node* oldChild, ExceptionCode& ec) -{ - bool result = HTMLFormControlElement::removeChild(oldChild, ec); - return result; -} - -bool HTMLOptGroupElement::appendChild(PassRefPtr<Node> newChild, ExceptionCode& ec, bool shouldLazyAttach) -{ - bool result = HTMLFormControlElement::appendChild(newChild, ec, shouldLazyAttach); - return result; -} - -bool HTMLOptGroupElement::removeChildren() -{ - bool result = HTMLFormControlElement::removeChildren(); - return result; -} - void HTMLOptGroupElement::childrenChanged(bool changedByParser, Node* beforeChange, Node* afterChange, int childCountDelta) { recalcSelectOptions(); diff --git a/WebCore/html/HTMLOptGroupElement.h b/WebCore/html/HTMLOptGroupElement.h index cdd1d37..394fdca 100644 --- a/WebCore/html/HTMLOptGroupElement.h +++ b/WebCore/html/HTMLOptGroupElement.h @@ -2,7 +2,7 @@ * Copyright (C) 1999 Lars Knoll (knoll@kde.org) * (C) 1999 Antti Koivisto (koivisto@kde.org) * (C) 2000 Dirk Mueller (mueller@kde.org) - * Copyright (C) 2004, 2005, 2006, 2007 Apple Inc. All rights reserved. + * Copyright (C) 2004, 2005, 2006, 2007, 2010 Apple Inc. All rights reserved. * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Library General Public @@ -33,7 +33,17 @@ class HTMLSelectElement; class HTMLOptGroupElement : public HTMLFormControlElement, public OptionGroupElement { public: - HTMLOptGroupElement(const QualifiedName&, Document*, HTMLFormElement* = 0); + static PassRefPtr<HTMLOptGroupElement> create(const QualifiedName&, Document*, HTMLFormElement*); + + String label() const; + void setLabel(const String&); + + HTMLSelectElement* ownerSelectElement() const; + + virtual String groupLabelText() const; + +private: + HTMLOptGroupElement(const QualifiedName&, Document*, HTMLFormElement*); virtual bool checkDTD(const Node*); virtual const AtomicString& formControlType() const; @@ -45,21 +55,10 @@ public: virtual void detach(); virtual void setRenderStyle(PassRefPtr<RenderStyle>); - virtual bool insertBefore(PassRefPtr<Node> newChild, Node* refChild, ExceptionCode&, bool shouldLazyAttach = false); - virtual bool replaceChild(PassRefPtr<Node> newChild, Node* oldChild, ExceptionCode&, bool shouldLazyAttach = false); - virtual bool removeChild(Node* child, ExceptionCode&); - virtual bool appendChild(PassRefPtr<Node> newChild, ExceptionCode&, bool shouldLazyAttach = false); - virtual bool removeChildren(); virtual void childrenChanged(bool changedByParser = false, Node* beforeChange = 0, Node* afterChange = 0, int childCountDelta = 0); - String label() const; - void setLabel(const String&); - - virtual String groupLabelText() const; - HTMLSelectElement* ownerSelectElement() const; virtual void accessKeyAction(bool sendToAnyElement); -private: virtual RenderStyle* nonRendererRenderStyle() const; void recalcSelectOptions(); diff --git a/WebCore/html/HTMLOptionElement.cpp b/WebCore/html/HTMLOptionElement.cpp index fa430d3..1be0746 100644 --- a/WebCore/html/HTMLOptionElement.cpp +++ b/WebCore/html/HTMLOptionElement.cpp @@ -44,11 +44,20 @@ using namespace HTMLNames; HTMLOptionElement::HTMLOptionElement(const QualifiedName& tagName, Document* document, HTMLFormElement* form) : HTMLFormControlElement(tagName, document, form) - , m_style(0) { ASSERT(hasTagName(optionTag)); } +PassRefPtr<HTMLOptionElement> HTMLOptionElement::create(Document* document, HTMLFormElement* form) +{ + return new HTMLOptionElement(optionTag, document, form); +} + +PassRefPtr<HTMLOptionElement> HTMLOptionElement::create(const QualifiedName& tagName, Document* document, HTMLFormElement* form) +{ + return new HTMLOptionElement(tagName, document, form); +} + PassRefPtr<HTMLOptionElement> HTMLOptionElement::createForJSConstructor(Document* document, const String& data, const String& value, bool defaultSelected, bool selected, ExceptionCode& ec) { diff --git a/WebCore/html/HTMLOptionElement.h b/WebCore/html/HTMLOptionElement.h index 4692119..35f7fae 100644 --- a/WebCore/html/HTMLOptionElement.h +++ b/WebCore/html/HTMLOptionElement.h @@ -2,7 +2,7 @@ * Copyright (C) 1999 Lars Knoll (knoll@kde.org) * (C) 1999 Antti Koivisto (koivisto@kde.org) * (C) 2000 Dirk Mueller (mueller@kde.org) - * Copyright (C) 2004, 2005, 2006 Apple Computer, Inc. + * Copyright (C) 2004, 2005, 2006, 2010 Apple Inc. All rights reserved. * Copyright (C) 2010 Google Inc. All rights reserved. * * This library is free software; you can redistribute it and/or @@ -29,8 +29,6 @@ namespace WebCore { -class Attribute; -class HTMLFormElement; class HTMLSelectElement; class HTMLOptionElement : public HTMLFormControlElement, public OptionElement { @@ -38,55 +36,60 @@ class HTMLOptionElement : public HTMLFormControlElement, public OptionElement { friend class RenderMenuList; public: - HTMLOptionElement(const QualifiedName&, Document*, HTMLFormElement* = 0); - + static PassRefPtr<HTMLOptionElement> create(Document*, HTMLFormElement*); + static PassRefPtr<HTMLOptionElement> create(const QualifiedName&, Document*, HTMLFormElement*); static PassRefPtr<HTMLOptionElement> createForJSConstructor(Document*, const String& data, const String& value, bool defaultSelected, bool selected, ExceptionCode&); - virtual HTMLTagStatus endTagRequirement() const { return TagStatusOptional; } - virtual int tagPriority() const { return 2; } - virtual bool checkDTD(const Node* newChild); - virtual bool supportsFocus() const; - virtual bool isFocusable() const; - virtual bool rendererIsNeeded(RenderStyle*) { return false; } - virtual void attach(); - virtual void detach(); - virtual void setRenderStyle(PassRefPtr<RenderStyle>); - - virtual const AtomicString& formControlType() const; - virtual String text() const; void setText(const String&, ExceptionCode&); int index() const; - virtual void parseMappedAttribute(Attribute*); virtual String value() const; void setValue(const String&); virtual bool selected() const; void setSelected(bool); - virtual void setSelectedState(bool); HTMLSelectElement* ownerSelectElement() const; - virtual void childrenChanged(bool changedByParser = false, Node* beforeChange = 0, Node* afterChange = 0, int childCountDelta = 0); - bool defaultSelected() const; void setDefaultSelected(bool); String label() const; void setLabel(const String&); - virtual String textIndentedToRespectGroupLabel() const; - bool ownElementDisabled() const { return HTMLFormControlElement::disabled(); } + virtual bool disabled() const; +private: + HTMLOptionElement(const QualifiedName&, Document*, HTMLFormElement* = 0); + + virtual HTMLTagStatus endTagRequirement() const { return TagStatusOptional; } + virtual int tagPriority() const { return 2; } + virtual bool checkDTD(const Node* newChild); + virtual bool supportsFocus() const; + virtual bool isFocusable() const; + virtual bool rendererIsNeeded(RenderStyle*) { return false; } + virtual void attach(); + virtual void detach(); + virtual void setRenderStyle(PassRefPtr<RenderStyle>); + + virtual const AtomicString& formControlType() const; + + virtual void parseMappedAttribute(Attribute*); + + virtual void setSelectedState(bool); + + virtual String textIndentedToRespectGroupLabel() const; + virtual void insertedIntoTree(bool); virtual void accessKeyAction(bool); -private: + virtual void childrenChanged(bool changedByParser = false, Node* beforeChange = 0, Node* afterChange = 0, int childCountDelta = 0); + virtual RenderStyle* nonRendererRenderStyle() const; OptionElementData m_data; diff --git a/WebCore/html/HTMLParagraphElement.cpp b/WebCore/html/HTMLParagraphElement.cpp index f39e3ff..fd04a30 100644 --- a/WebCore/html/HTMLParagraphElement.cpp +++ b/WebCore/html/HTMLParagraphElement.cpp @@ -1,7 +1,7 @@ -/** +/* * Copyright (C) 1999 Lars Knoll (knoll@kde.org) * (C) 1999 Antti Koivisto (koivisto@kde.org) - * Copyright (C) 2003 Apple Computer, Inc. + * Copyright (C) 2003, 2010 Apple Inc. All rights reserved. * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Library General Public @@ -33,12 +33,17 @@ namespace WebCore { using namespace HTMLNames; -HTMLParagraphElement::HTMLParagraphElement(const QualifiedName& tagName, Document *doc) - : HTMLElement(tagName, doc) +inline HTMLParagraphElement::HTMLParagraphElement(const QualifiedName& tagName, Document* document) + : HTMLElement(tagName, document) { ASSERT(hasTagName(pTag)); } +PassRefPtr<HTMLParagraphElement> HTMLParagraphElement::create(const QualifiedName& tagName, Document* document) +{ + return new HTMLParagraphElement(tagName, document); +} + bool HTMLParagraphElement::checkDTD(const Node* newChild) { return inInlineTagList(newChild) || (document()->inCompatMode() && newChild->hasTagName(tableTag)); diff --git a/WebCore/html/HTMLParagraphElement.h b/WebCore/html/HTMLParagraphElement.h index 496951a..26e34a7 100644 --- a/WebCore/html/HTMLParagraphElement.h +++ b/WebCore/html/HTMLParagraphElement.h @@ -1,6 +1,7 @@ /* * Copyright (C) 1999 Lars Knoll (knoll@kde.org) * (C) 1999 Antti Koivisto (koivisto@kde.org) + * Copyright (C) 2010 Apple Inc. All rights reserved. * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Library General Public @@ -28,6 +29,12 @@ namespace WebCore { class HTMLParagraphElement : public HTMLElement { public: + static PassRefPtr<HTMLParagraphElement> create(const QualifiedName&, Document*); + + String align() const; + void setAlign(const String&); + +private: HTMLParagraphElement(const QualifiedName&, Document*); virtual HTMLTagStatus endTagRequirement() const { return TagStatusRequired; } @@ -36,9 +43,6 @@ public: virtual bool mapToEntry(const QualifiedName&, MappedAttributeEntry&) const; virtual void parseMappedAttribute(Attribute*); - - String align() const; - void setAlign(const String&); }; } // namespace WebCore diff --git a/WebCore/html/HTMLParamElement.cpp b/WebCore/html/HTMLParamElement.cpp index 61a5a65..ca28383 100644 --- a/WebCore/html/HTMLParamElement.cpp +++ b/WebCore/html/HTMLParamElement.cpp @@ -2,7 +2,7 @@ * Copyright (C) 1999 Lars Knoll (knoll@kde.org) * (C) 1999 Antti Koivisto (koivisto@kde.org) * (C) 2000 Stefan Schimanski (1Stein@gmx.de) - * Copyright (C) 2004, 2005, 2006, 2008 Apple Inc. All rights reserved. + * Copyright (C) 2004, 2005, 2006, 2008, 2010 Apple Inc. All rights reserved. * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Library General Public @@ -31,14 +31,15 @@ namespace WebCore { using namespace HTMLNames; -HTMLParamElement::HTMLParamElement(const QualifiedName& tagName, Document* doc) - : HTMLElement(tagName, doc) +inline HTMLParamElement::HTMLParamElement(const QualifiedName& tagName, Document* document) + : HTMLElement(tagName, document) { ASSERT(hasTagName(paramTag)); } -HTMLParamElement::~HTMLParamElement() +PassRefPtr<HTMLParamElement> HTMLParamElement::create(const QualifiedName& tagName, Document* document) { + return new HTMLParamElement(tagName, document); } void HTMLParamElement::parseMappedAttribute(Attribute* attr) diff --git a/WebCore/html/HTMLParamElement.h b/WebCore/html/HTMLParamElement.h index 84152c6..a782353 100644 --- a/WebCore/html/HTMLParamElement.h +++ b/WebCore/html/HTMLParamElement.h @@ -1,7 +1,7 @@ /* * Copyright (C) 1999 Lars Knoll (knoll@kde.org) * (C) 1999 Antti Koivisto (koivisto@kde.org) - * Copyright (C) 2004, 2006 Apple Computer, Inc. + * Copyright (C) 2004, 2006, 2010 Apple Inc. All rights reserved. * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Library General Public @@ -28,17 +28,8 @@ namespace WebCore { class HTMLParamElement : public HTMLElement { - friend class HTMLAppletElement; public: - HTMLParamElement(const QualifiedName&, Document*); - ~HTMLParamElement(); - - virtual HTMLTagStatus endTagRequirement() const { return TagStatusForbidden; } - virtual int tagPriority() const { return 0; } - - virtual void parseMappedAttribute(Attribute*); - - virtual bool isURLAttribute(Attribute*) const; + static PassRefPtr<HTMLParamElement> create(const QualifiedName&, Document*); String name() const { return m_name; } void setName(const String&); @@ -52,9 +43,18 @@ public: String valueType() const; void setValueType(const String&); +private: + HTMLParamElement(const QualifiedName&, Document*); + + virtual HTMLTagStatus endTagRequirement() const { return TagStatusForbidden; } + virtual int tagPriority() const { return 0; } + + virtual void parseMappedAttribute(Attribute*); + + virtual bool isURLAttribute(Attribute*) const; + virtual void addSubresourceAttributeURLs(ListHashSet<KURL>&) const; - protected: AtomicString m_name; AtomicString m_value; }; diff --git a/WebCore/html/HTMLParser.cpp b/WebCore/html/HTMLParser.cpp index 0f0a0fc..dd822cf 100644 --- a/WebCore/html/HTMLParser.cpp +++ b/WebCore/html/HTMLParser.cpp @@ -431,7 +431,6 @@ bool HTMLParser::insertNode(Node* n, bool flat) bool HTMLParser::handleError(Node* n, bool flat, const AtomicString& localName, int tagPriority) { // Error handling code. This is just ad hoc handling of specific parent/child combinations. - HTMLElement* e; bool handled = false; // 1. Check out the element's tag name to decide how to deal with errors. @@ -559,7 +558,7 @@ bool HTMLParser::handleError(Node* n, bool flat, const AtomicString& localName, elt->hasLocalName(titleTag) || elt->hasLocalName(isindexTag) || elt->hasLocalName(baseTag))) { if (!m_head) { - m_head = new HTMLHeadElement(headTag, m_document); + m_head = HTMLHeadElement::create(m_document); insertNode(m_head.get()); handled = true; } @@ -576,9 +575,8 @@ bool HTMLParser::handleError(Node* n, bool flat, const AtomicString& localName, createHead(); popBlock(headTag); - e = new HTMLBodyElement(bodyTag, m_document); startBody(); - insertNode(e); + insertNode(HTMLBodyElement::create(m_document).get()); handled = true; } else reportError(MisplacedFramesetContentError, &localName); @@ -591,9 +589,8 @@ bool HTMLParser::handleError(Node* n, bool flat, const AtomicString& localName, if (!m_haveFrameSet) { ASSERT(currentTagName == headTag); popBlock(currentTagName); - e = new HTMLBodyElement(bodyTag, m_document); startBody(); - insertNode(e); + insertNode(HTMLBodyElement::create(m_document).get()); handled = true; } else reportError(MisplacedFramesetContentError, &localName); @@ -661,17 +658,15 @@ bool HTMLParser::handleError(Node* n, bool flat, const AtomicString& localName, if (!ec) { if (m_current->hasTagName(trTag)) { reportError(TablePartRequiredError, &localName, &tdTag.localName()); - e = new HTMLTableCellElement(tdTag, m_document); + insertNode(HTMLTableCellElement::create(tdTag, m_document).get()); } else if (m_current->hasTagName(tableTag)) { // Don't report an error in this case, since making a <tbody> happens all the time when you have <table><tr>, // and it isn't really a parse error per se. - e = new HTMLTableSectionElement(tbodyTag, m_document); + insertNode(HTMLTableSectionElement::create(tbodyTag, m_document).get()); } else { reportError(TablePartRequiredError, &localName, &trTag.localName()); - e = new HTMLTableRowElement(trTag, m_document); + insertNode(HTMLTableRowElement::create(m_document).get()); } - - insertNode(e); handled = true; } } @@ -715,8 +710,7 @@ bool HTMLParser::handleError(Node* n, bool flat, const AtomicString& localName, } if (!m_document->documentElement()) { - e = new HTMLHtmlElement(htmlTag, m_document); - insertNode(e); + insertNode(HTMLHtmlElement::create(m_document).get()); handled = true; } } @@ -747,7 +741,7 @@ bool HTMLParser::commentCreateErrorCheck(Token* t, RefPtr<Node>& result) bool HTMLParser::headCreateErrorCheck(Token*, RefPtr<Node>& result) { if (!m_head || m_current->localName() == htmlTag) { - m_head = new HTMLHeadElement(headTag, m_document); + m_head = HTMLHeadElement::create(m_document); result = m_head; } else reportError(MisplacedHeadError); @@ -795,7 +789,7 @@ bool HTMLParser::formCreateErrorCheck(Token* t, RefPtr<Node>& result) // Only create a new form if we're not already inside one. // This is consistent with other browsers' behavior. if (!m_currentFormElement) { - m_currentFormElement = new HTMLFormElement(formTag, m_document); + m_currentFormElement = HTMLFormElement::create(m_document); result = m_currentFormElement; pCloserCreateErrorCheck(t, result); } @@ -922,7 +916,7 @@ bool HTMLParser::pCloserStrictCreateErrorCheck(Token*, RefPtr<Node>&) bool HTMLParser::mapCreateErrorCheck(Token*, RefPtr<Node>& result) { - m_currentMapElement = new HTMLMapElement(mapTag, m_document); + m_currentMapElement = HTMLMapElement::create(m_document); result = m_currentMapElement; return false; } @@ -1572,11 +1566,11 @@ void HTMLParser::createHead() return; if (!m_document->documentElement() && !m_isParsingFragment) { - insertNode(new HTMLHtmlElement(htmlTag, m_document)); + insertNode(HTMLHtmlElement::create(m_document).get()); ASSERT(m_document->documentElement() || m_isParsingFragment); } - m_head = new HTMLHeadElement(headTag, m_document); + m_head = HTMLHeadElement::create(m_document); if (m_isParsingFragment) return; @@ -1596,11 +1590,11 @@ void HTMLParser::createHead() PassRefPtr<Node> HTMLParser::handleIsindex(Token* t) { - RefPtr<Node> n = new HTMLDivElement(divTag, m_document); + RefPtr<Node> n = HTMLDivElement::create(m_document); NamedNodeMap* attrs = t->attrs.get(); - RefPtr<HTMLIsIndexElement> isIndex = new HTMLIsIndexElement(isindexTag, m_document, m_currentFormElement.get()); + RefPtr<HTMLIsIndexElement> isIndex = HTMLIsIndexElement::create(m_document, m_currentFormElement.get()); isIndex->setAttributeMap(attrs); isIndex->setAttribute(typeAttr, "khtml_isindex"); @@ -1611,10 +1605,10 @@ PassRefPtr<Node> HTMLParser::handleIsindex(Token* t) t->attrs = 0; } - n->addChild(new HTMLHRElement(hrTag, m_document)); + n->addChild(HTMLHRElement::create(m_document)); n->addChild(Text::create(m_document, text)); n->addChild(isIndex.release()); - n->addChild(new HTMLHRElement(hrTag, m_document)); + n->addChild(HTMLHRElement::create(m_document)); return n.release(); } @@ -1636,7 +1630,7 @@ void HTMLParser::finished() { // In the case of a completely empty document, here's the place to create the HTML element. if (m_current && m_current->isDocumentNode() && !m_document->documentElement()) - insertNode(new HTMLHtmlElement(htmlTag, m_document)); + insertNode(HTMLHtmlElement::create(m_document).get()); // This ensures that "current" is not left pointing to a node when the document is destroyed. freeBlock(); diff --git a/WebCore/html/HTMLPreElement.cpp b/WebCore/html/HTMLPreElement.cpp index 0108ff3..68522e5 100644 --- a/WebCore/html/HTMLPreElement.cpp +++ b/WebCore/html/HTMLPreElement.cpp @@ -1,7 +1,7 @@ -/** +/* * Copyright (C) 1999 Lars Knoll (knoll@kde.org) * (C) 1999 Antti Koivisto (koivisto@kde.org) - * Copyright (C) 2003 Apple Computer, Inc. + * Copyright (C) 2003, 2010 Apple Inc. All rights reserved. * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Library General Public @@ -32,11 +32,16 @@ namespace WebCore { using namespace HTMLNames; -HTMLPreElement::HTMLPreElement(const QualifiedName& tagName, Document* doc) - : HTMLElement(tagName, doc) +inline HTMLPreElement::HTMLPreElement(const QualifiedName& tagName, Document* document) + : HTMLElement(tagName, document) { } +PassRefPtr<HTMLPreElement> HTMLPreElement::create(const QualifiedName& tagName, Document* document) +{ + return new HTMLPreElement(tagName, document); +} + bool HTMLPreElement::mapToEntry(const QualifiedName& attrName, MappedAttributeEntry& result) const { if (attrName == widthAttr || attrName == wrapAttr) { diff --git a/WebCore/html/HTMLPreElement.h b/WebCore/html/HTMLPreElement.h index 17b945e..0975c0f 100644 --- a/WebCore/html/HTMLPreElement.h +++ b/WebCore/html/HTMLPreElement.h @@ -1,6 +1,7 @@ /* * Copyright (C) 1999 Lars Knoll (knoll@kde.org) * (C) 1999 Antti Koivisto (koivisto@kde.org) + * Copyright (C) 2010 Apple Inc. All rights reserved. * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Library General Public @@ -28,19 +29,22 @@ namespace WebCore { class HTMLPreElement : public HTMLElement { public: + static PassRefPtr<HTMLPreElement> create(const QualifiedName&, Document*); + + int width() const; + void setWidth(int); + + bool wrap() const; + void setWrap(bool); + +private: HTMLPreElement(const QualifiedName&, Document*); virtual HTMLTagStatus endTagRequirement() const { return TagStatusRequired; } virtual int tagPriority() const { return 5; } - bool mapToEntry(const QualifiedName&, MappedAttributeEntry&) const; - void parseMappedAttribute(Attribute*); - - int width() const; - void setWidth(int w); - - bool wrap() const; - void setWrap(bool b); + virtual bool mapToEntry(const QualifiedName&, MappedAttributeEntry&) const; + virtual void parseMappedAttribute(Attribute*); }; } // namespace WebCore diff --git a/WebCore/html/HTMLProgressElement.idl b/WebCore/html/HTMLProgressElement.idl index 935bd95..b49252c 100644 --- a/WebCore/html/HTMLProgressElement.idl +++ b/WebCore/html/HTMLProgressElement.idl @@ -27,6 +27,7 @@ module html { setter raises(DOMException); readonly attribute double position; readonly attribute HTMLFormElement form; + readonly attribute NodeList labels; }; } diff --git a/WebCore/html/HTMLQuoteElement.cpp b/WebCore/html/HTMLQuoteElement.cpp index e548215..b646fc0 100644 --- a/WebCore/html/HTMLQuoteElement.cpp +++ b/WebCore/html/HTMLQuoteElement.cpp @@ -1,8 +1,8 @@ -/** +/* * Copyright (C) 1999 Lars Knoll (knoll@kde.org) * (C) 1999 Antti Koivisto (koivisto@kde.org) * (C) 2000 Simon Hausmann <hausmann@kde.org> - * Copyright (C) 2003, 2006 Apple Computer, Inc. + * Copyright (C) 2003, 2006, 2010 Apple Inc. All rights reserved. * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Library General Public @@ -19,6 +19,7 @@ * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, * Boston, MA 02110-1301, USA. */ + #include "config.h" #include "HTMLQuoteElement.h" @@ -29,12 +30,17 @@ namespace WebCore { using namespace HTMLNames; -HTMLQuoteElement::HTMLQuoteElement(const QualifiedName& tagName, Document* doc) - : HTMLElement(tagName, doc) +inline HTMLQuoteElement::HTMLQuoteElement(const QualifiedName& tagName, Document* document) + : HTMLElement(tagName, document) { ASSERT(hasTagName(qTag)); } +PassRefPtr<HTMLQuoteElement> HTMLQuoteElement::create(const QualifiedName& tagName, Document* document) +{ + return new HTMLQuoteElement(tagName, document); +} + void HTMLQuoteElement::insertedIntoDocument() { document()->setUsesBeforeAfterRules(true); diff --git a/WebCore/html/HTMLQuoteElement.h b/WebCore/html/HTMLQuoteElement.h index addbfb4..fa21d2d 100644 --- a/WebCore/html/HTMLQuoteElement.h +++ b/WebCore/html/HTMLQuoteElement.h @@ -2,6 +2,7 @@ * Copyright (C) 1999 Lars Knoll (knoll@kde.org) * (C) 1999 Antti Koivisto (koivisto@kde.org) * (C) 2000 Simon Hausmann <hausmann@kde.org> + * Copyright (C) 2010 Apple Inc. All rights reserved. * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Library General Public @@ -19,6 +20,7 @@ * Boston, MA 02110-1301, USA. * */ + #ifndef HTMLQuoteElement_h #define HTMLQuoteElement_h @@ -30,15 +32,18 @@ class String; class HTMLQuoteElement : public HTMLElement { public: + static PassRefPtr<HTMLQuoteElement> create(const QualifiedName&, Document*); + + String cite() const; + void setCite(const String&); + +private: HTMLQuoteElement(const QualifiedName&, Document*); virtual HTMLTagStatus endTagRequirement() const { return TagStatusRequired; } virtual int tagPriority() const { return 1; } virtual void insertedIntoDocument(); - - String cite() const; - void setCite(const String&); }; } //namespace diff --git a/WebCore/html/HTMLScriptElement.cpp b/WebCore/html/HTMLScriptElement.cpp index 83af32e..f4c3ae8 100644 --- a/WebCore/html/HTMLScriptElement.cpp +++ b/WebCore/html/HTMLScriptElement.cpp @@ -35,16 +35,17 @@ namespace WebCore { using namespace HTMLNames; -HTMLScriptElement::HTMLScriptElement(const QualifiedName& tagName, Document* doc, bool createdByParser) - : HTMLElement(tagName, doc) +inline HTMLScriptElement::HTMLScriptElement(const QualifiedName& tagName, Document* document, bool createdByParser) + : HTMLElement(tagName, document) , m_data(this, this) { ASSERT(hasTagName(scriptTag)); m_data.setCreatedByParser(createdByParser); } -HTMLScriptElement::~HTMLScriptElement() +PassRefPtr<HTMLScriptElement> HTMLScriptElement::create(const QualifiedName& tagName, Document* document, bool createdByParser) { + return new HTMLScriptElement(tagName, document, createdByParser); } bool HTMLScriptElement::isURLAttribute(Attribute* attr) const diff --git a/WebCore/html/HTMLScriptElement.h b/WebCore/html/HTMLScriptElement.h index f5c3acb..14a1264 100644 --- a/WebCore/html/HTMLScriptElement.h +++ b/WebCore/html/HTMLScriptElement.h @@ -29,26 +29,11 @@ namespace WebCore { -class HTMLScriptElement : public HTMLElement - , public ScriptElement { +class HTMLScriptElement : public HTMLElement, public ScriptElement { public: - HTMLScriptElement(const QualifiedName&, Document*, bool createdByParser); - ~HTMLScriptElement(); + static PassRefPtr<HTMLScriptElement> create(const QualifiedName&, Document*, bool createdByParser); virtual bool shouldExecuteAsJavaScript() const; - virtual String scriptContent() const; - - virtual HTMLTagStatus endTagRequirement() const { return TagStatusRequired; } - virtual int tagPriority() const { return 1; } - virtual bool checkDTD(const Node* newChild) { return newChild->isTextNode(); } - - 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); - - virtual bool isURLAttribute(Attribute*) const; - virtual void finishParsingChildren(); String text() const; void setText(const String&); @@ -73,11 +58,27 @@ public: virtual String scriptCharset() const; - virtual void addSubresourceAttributeURLs(ListHashSet<KURL>&) const; - bool haveFiredLoadEvent() const { return m_data.haveFiredLoadEvent(); } -protected: +private: + HTMLScriptElement(const QualifiedName&, Document*, bool createdByParser); + + virtual String scriptContent() const; + + virtual HTMLTagStatus endTagRequirement() const { return TagStatusRequired; } + virtual int tagPriority() const { return 1; } + virtual bool checkDTD(const Node* newChild) { return newChild->isTextNode(); } + + 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); + + virtual bool isURLAttribute(Attribute*) const; + virtual void finishParsingChildren(); + + virtual void addSubresourceAttributeURLs(ListHashSet<KURL>&) const; + virtual String sourceAttributeValue() const; virtual String charsetAttributeValue() const; virtual String typeAttributeValue() const; @@ -88,7 +89,6 @@ protected: virtual void dispatchLoadEvent(); virtual void dispatchErrorEvent(); -private: ScriptElementData m_data; }; diff --git a/WebCore/html/HTMLSelectElement.cpp b/WebCore/html/HTMLSelectElement.cpp index c053a84..4c124e0 100644 --- a/WebCore/html/HTMLSelectElement.cpp +++ b/WebCore/html/HTMLSelectElement.cpp @@ -3,7 +3,7 @@ * Copyright (C) 1999 Lars Knoll (knoll@kde.org) * (C) 1999 Antti Koivisto (koivisto@kde.org) * (C) 2001 Dirk Mueller (mueller@kde.org) - * Copyright (C) 2004, 2005, 2006, 2007, 2009 Apple Inc. All rights reserved. + * Copyright (C) 2004, 2005, 2006, 2007, 2009, 2010 Apple Inc. All rights reserved. * (C) 2006 Alexey Proskuryakov (ap@nypop.com) * Copyright (C) 2010 Google Inc. All rights reserved. * @@ -52,6 +52,12 @@ HTMLSelectElement::HTMLSelectElement(const QualifiedName& tagName, Document* doc ASSERT(hasTagName(selectTag) || hasTagName(keygenTag)); } +PassRefPtr<HTMLSelectElement> HTMLSelectElement::create(const QualifiedName& tagName, Document* document, HTMLFormElement* form) +{ + ASSERT(tagName.matches(selectTag)); + return new HTMLSelectElement(tagName, document, form); +} + bool HTMLSelectElement::checkDTD(const Node* newChild) { // Make sure to keep <optgroup> in sync with this. diff --git a/WebCore/html/HTMLSelectElement.h b/WebCore/html/HTMLSelectElement.h index c31e7f6..59c943a 100644 --- a/WebCore/html/HTMLSelectElement.h +++ b/WebCore/html/HTMLSelectElement.h @@ -3,7 +3,7 @@ * Copyright (C) 1999 Lars Knoll (knoll@kde.org) * (C) 1999 Antti Koivisto (koivisto@kde.org) * (C) 2000 Dirk Mueller (mueller@kde.org) - * Copyright (C) 2004, 2005, 2006, 2007, 2009 Apple Inc. All rights reserved. + * Copyright (C) 2004, 2005, 2006, 2007, 2009, 2010 Apple Inc. All rights reserved. * Copyright (C) 2010 Google Inc. All rights reserved. * * This library is free software; you can redistribute it and/or @@ -34,11 +34,10 @@ namespace WebCore { class HTMLOptionElement; class HTMLOptionsCollection; -class KeyboardEvent; class HTMLSelectElement : public HTMLFormControlElementWithState, public SelectElement { public: - HTMLSelectElement(const QualifiedName&, Document*, HTMLFormElement* = 0); + static PassRefPtr<HTMLSelectElement> create(const QualifiedName&, Document*, HTMLFormElement*); virtual int selectedIndex() const; virtual void setSelectedIndex(int index, bool deselect = true); @@ -83,6 +82,9 @@ public: void listBoxSelectItem(int listIndex, bool allowMultiplySelections, bool shift, bool fireOnChangeNow = true); +protected: + HTMLSelectElement(const QualifiedName&, Document*, HTMLFormElement*); + private: virtual int tagPriority() const { return 6; } virtual bool checkDTD(const Node* newChild); diff --git a/WebCore/html/HTMLSelectElement.idl b/WebCore/html/HTMLSelectElement.idl index d260fad..3303272 100644 --- a/WebCore/html/HTMLSelectElement.idl +++ b/WebCore/html/HTMLSelectElement.idl @@ -68,6 +68,7 @@ module html { // "The contained options can be directly accessed through the select element as a collection." Node item(in [IsIndex] unsigned long index); Node namedItem(in DOMString name); + readonly attribute NodeList labels; }; } diff --git a/WebCore/html/HTMLSourceElement.cpp b/WebCore/html/HTMLSourceElement.cpp index 4b9401d..8378bc8 100644 --- a/WebCore/html/HTMLSourceElement.cpp +++ b/WebCore/html/HTMLSourceElement.cpp @@ -1,5 +1,5 @@ /* - * Copyright (C) 2007, 2008 Apple Inc. All rights reserved. + * Copyright (C) 2007, 2008, 2010 Apple Inc. All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions @@ -40,15 +40,16 @@ namespace WebCore { using namespace HTMLNames; -HTMLSourceElement::HTMLSourceElement(const QualifiedName& tagName, Document* doc) - : HTMLElement(tagName, doc) +inline HTMLSourceElement::HTMLSourceElement(const QualifiedName& tagName, Document* document) + : HTMLElement(tagName, document) , m_errorEventTimer(this, &HTMLSourceElement::errorEventTimerFired) { ASSERT(hasTagName(sourceTag)); } -HTMLSourceElement::~HTMLSourceElement() +PassRefPtr<HTMLSourceElement> HTMLSourceElement::create(const QualifiedName& tagName, Document* document) { + return new HTMLSourceElement(tagName, document); } void HTMLSourceElement::insertedIntoDocument() diff --git a/WebCore/html/HTMLSourceElement.h b/WebCore/html/HTMLSourceElement.h index 50d6687..e11c9d0 100644 --- a/WebCore/html/HTMLSourceElement.h +++ b/WebCore/html/HTMLSourceElement.h @@ -1,5 +1,5 @@ /* - * Copyright (C) 2007, 2008 Apple Inc. All rights reserved. + * Copyright (C) 2007, 2008, 2010 Apple Inc. All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions @@ -30,22 +30,13 @@ #include "HTMLElement.h" #include "Timer.h" -#include <limits> namespace WebCore { -class KURL; - class HTMLSourceElement : public HTMLElement { public: - HTMLSourceElement(const QualifiedName&, Document*); - virtual ~HTMLSourceElement(); + static PassRefPtr<HTMLSourceElement> create(const QualifiedName&, Document*); - virtual HTMLTagStatus endTagRequirement() const { return TagStatusForbidden; } - virtual int tagPriority() const { return 0; } - - virtual void insertedIntoDocument(); - KURL src() const; String media() const; String type() const; @@ -57,6 +48,13 @@ public: void cancelPendingErrorEvent(); private: + HTMLSourceElement(const QualifiedName&, Document*); + + virtual HTMLTagStatus endTagRequirement() const { return TagStatusForbidden; } + virtual int tagPriority() const { return 0; } + + virtual void insertedIntoDocument(); + void errorEventTimerFired(Timer<HTMLSourceElement>*); Timer<HTMLSourceElement> m_errorEventTimer; diff --git a/WebCore/html/HTMLStyleElement.cpp b/WebCore/html/HTMLStyleElement.cpp index 1cdfed2..b67bfa3 100644 --- a/WebCore/html/HTMLStyleElement.cpp +++ b/WebCore/html/HTMLStyleElement.cpp @@ -1,8 +1,8 @@ -/** +/* * Copyright (C) 1999 Lars Knoll (knoll@kde.org) * (C) 1999 Antti Koivisto (koivisto@kde.org) * (C) 2001 Dirk Mueller (mueller@kde.org) - * Copyright (C) 2003 Apple Computer, Inc. + * Copyright (C) 2003, 2010 Apple Inc. All rights reserved. * (C) 2007 Rob Buis (buis@kde.org) * * This library is free software; you can redistribute it and/or @@ -32,14 +32,19 @@ namespace WebCore { using namespace HTMLNames; -HTMLStyleElement::HTMLStyleElement(const QualifiedName& tagName, Document* doc, bool createdByParser) - : HTMLElement(tagName, doc) +inline HTMLStyleElement::HTMLStyleElement(const QualifiedName& tagName, Document* document, bool createdByParser) + : HTMLElement(tagName, document) , m_loading(false) , m_createdByParser(createdByParser) { ASSERT(hasTagName(styleTag)); } +PassRefPtr<HTMLStyleElement> HTMLStyleElement::create(const QualifiedName& tagName, Document* document, bool createdByParser) +{ + return new HTMLStyleElement(tagName, document, createdByParser); +} + // other stuff... void HTMLStyleElement::parseMappedAttribute(Attribute* attr) { diff --git a/WebCore/html/HTMLStyleElement.h b/WebCore/html/HTMLStyleElement.h index ba8ed3e..58dce14 100644 --- a/WebCore/html/HTMLStyleElement.h +++ b/WebCore/html/HTMLStyleElement.h @@ -1,7 +1,7 @@ /* * Copyright (C) 1999 Lars Knoll (knoll@kde.org) * (C) 1999 Antti Koivisto (koivisto@kde.org) - * Copyright (C) 2003 Apple Computer, Inc. + * Copyright (C) 2003, 2010 Apple Inc. ALl rights reserved. * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Library General Public @@ -22,14 +22,29 @@ #ifndef HTMLStyleElement_h #define HTMLStyleElement_h -#include "CSSStyleSheet.h" #include "HTMLElement.h" #include "StyleElement.h" namespace WebCore { +class StyleSheet; + class HTMLStyleElement : public HTMLElement, public StyleElement { public: + static PassRefPtr<HTMLStyleElement> create(const QualifiedName&, Document*, bool createdByParser); + + bool disabled() const; + void setDisabled(bool); + + virtual const AtomicString& media() const; + void setMedia(const AtomicString&); + + virtual const AtomicString& type() const; + void setType(const AtomicString&); + + StyleSheet* sheet(); + +private: HTMLStyleElement(const QualifiedName&, Document*, bool createdByParser); virtual HTMLTagStatus endTagRequirement() const { return TagStatusRequired; } @@ -47,22 +62,10 @@ public: virtual bool isLoading() const; virtual bool sheetLoaded(); - bool disabled() const; - void setDisabled(bool); - - virtual const AtomicString& media() const; - void setMedia(const AtomicString&); - - virtual const AtomicString& type() const; - void setType(const AtomicString&); - - StyleSheet* sheet(); - virtual void setLoading(bool loading) { m_loading = loading; } virtual void addSubresourceAttributeURLs(ListHashSet<KURL>&) const; -protected: String m_media; bool m_loading; bool m_createdByParser; diff --git a/WebCore/html/HTMLTableCaptionElement.cpp b/WebCore/html/HTMLTableCaptionElement.cpp index 828a4e9..3713ca1 100644 --- a/WebCore/html/HTMLTableCaptionElement.cpp +++ b/WebCore/html/HTMLTableCaptionElement.cpp @@ -1,10 +1,10 @@ -/** +/* * Copyright (C) 1997 Martin Jones (mjones@kde.org) * (C) 1997 Torben Weis (weis@kde.org) * (C) 1998 Waldo Bastian (bastian@kde.org) * (C) 1999 Lars Knoll (knoll@kde.org) * (C) 1999 Antti Koivisto (koivisto@kde.org) - * Copyright (C) 2003, 2004, 2005, 2006 Apple Computer, Inc. + * Copyright (C) 2003, 2004, 2005, 2006, 2010 Apple Inc. All rights reserved. * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Library General Public @@ -33,12 +33,17 @@ namespace WebCore { using namespace HTMLNames; -HTMLTableCaptionElement::HTMLTableCaptionElement(const QualifiedName& tagName, Document *doc) - : HTMLTablePartElement(tagName, doc) +inline HTMLTableCaptionElement::HTMLTableCaptionElement(const QualifiedName& tagName, Document* document) + : HTMLTablePartElement(tagName, document) { ASSERT(hasTagName(captionTag)); } +PassRefPtr<HTMLTableCaptionElement> HTMLTableCaptionElement::create(const QualifiedName& tagName, Document* document) +{ + return new HTMLTableCaptionElement(tagName, document); +} + bool HTMLTableCaptionElement::mapToEntry(const QualifiedName& attrName, MappedAttributeEntry& result) const { if (attrName == alignAttr) { diff --git a/WebCore/html/HTMLTableCaptionElement.h b/WebCore/html/HTMLTableCaptionElement.h index cf9d4d9..e97b03f 100644 --- a/WebCore/html/HTMLTableCaptionElement.h +++ b/WebCore/html/HTMLTableCaptionElement.h @@ -4,7 +4,7 @@ * (C) 1998 Waldo Bastian (bastian@kde.org) * (C) 1999 Lars Knoll (knoll@kde.org) * (C) 1999 Antti Koivisto (koivisto@kde.org) - * Copyright (C) 2003, 2004, 2005, 2006 Apple Computer, Inc. + * Copyright (C) 2003, 2004, 2005, 2006, 2010 Apple Inc. All rights reserved. * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Library General Public @@ -32,6 +32,12 @@ namespace WebCore { class HTMLTableCaptionElement : public HTMLTablePartElement { public: + static PassRefPtr<HTMLTableCaptionElement> create(const QualifiedName&, Document*); + + String align() const; + void setAlign(const String&); + +private: HTMLTableCaptionElement(const QualifiedName&, Document*); virtual HTMLTagStatus endTagRequirement() const { return TagStatusRequired; } @@ -39,11 +45,8 @@ public: virtual bool mapToEntry(const QualifiedName&, MappedAttributeEntry&) const; virtual void parseMappedAttribute(Attribute*); - - String align() const; - void setAlign(const String&); }; -} //namespace +} // namespace #endif diff --git a/WebCore/html/HTMLTableCellElement.cpp b/WebCore/html/HTMLTableCellElement.cpp index 7d71ff4..92ccdf1 100644 --- a/WebCore/html/HTMLTableCellElement.cpp +++ b/WebCore/html/HTMLTableCellElement.cpp @@ -1,10 +1,10 @@ -/** +/* * Copyright (C) 1997 Martin Jones (mjones@kde.org) * (C) 1997 Torben Weis (weis@kde.org) * (C) 1998 Waldo Bastian (bastian@kde.org) * (C) 1999 Lars Knoll (knoll@kde.org) * (C) 1999 Antti Koivisto (koivisto@kde.org) - * Copyright (C) 2003, 2004, 2005, 2006 Apple Computer, Inc. + * Copyright (C) 2003, 2004, 2005, 2006, 2010 Apple Inc. All rights reserved. * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Library General Public @@ -47,19 +47,18 @@ static const int maxRowspan = 8190; using namespace HTMLNames; -HTMLTableCellElement::HTMLTableCellElement(const QualifiedName& tagName, Document *doc) - : HTMLTablePartElement(tagName, doc) - , _row(-1) - , _col(-1) - , rSpan(1) - , cSpan(1) - , rowHeight(0) - , m_solid(false) +inline HTMLTableCellElement::HTMLTableCellElement(const QualifiedName& tagName, Document* document) + : HTMLTablePartElement(tagName, document) + , m_row(-1) + , m_col(-1) + , m_rowSpan(1) + , m_colSpan(1) { } -HTMLTableCellElement::~HTMLTableCellElement() +PassRefPtr<HTMLTableCellElement> HTMLTableCellElement::create(const QualifiedName& tagName, Document* document) { + return new HTMLTableCellElement(tagName, document); } int HTMLTableCellElement::cellIndex() const @@ -92,28 +91,32 @@ bool HTMLTableCellElement::mapToEntry(const QualifiedName& attrName, MappedAttri void HTMLTableCellElement::parseMappedAttribute(Attribute* attr) { if (attr->name() == rowspanAttr) { - rSpan = !attr->isNull() ? attr->value().toInt() : 1; - rSpan = max(1, min(rSpan, maxRowspan)); + m_rowSpan = max(1, min(attr->value().toInt(), maxRowspan)); if (renderer() && renderer()->isTableCell()) toRenderTableCell(renderer())->updateFromElement(); } else if (attr->name() == colspanAttr) { - cSpan = !attr->isNull() ? attr->value().toInt() : 1; - cSpan = max(1, cSpan); + m_colSpan = max(1, attr->value().toInt()); if (renderer() && renderer()->isTableCell()) toRenderTableCell(renderer())->updateFromElement(); } else if (attr->name() == nowrapAttr) { +<<<<<<< HEAD #ifdef ANDROID_LAYOUT if (!(document()->frame()) || document()->frame()->settings()->layoutAlgorithm() != Settings::kLayoutSSR) #endif +======= + // FIXME: What about removing the property when the attribute becomes null? +>>>>>>> webkit.org at r60469 if (!attr->isNull()) addCSSProperty(attr, CSSPropertyWhiteSpace, CSSValueWebkitNowrap); } else if (attr->name() == widthAttr) { + // FIXME: What about removing the property when the attribute becomes empty, zero or negative? if (!attr->value().isEmpty()) { int widthInt = attr->value().toInt(); if (widthInt > 0) // width="0" is ignored for compatibility with WinIE. addCSSLength(attr, CSSPropertyWidth, attr->value()); } } else if (attr->name() == heightAttr) { + // FIXME: What about removing the property when the attribute becomes empty, zero or negative? if (!attr->value().isEmpty()) { int heightInt = attr->value().toInt(); if (heightInt > 0) // height="0" is ignored for compatibility with WinIE. diff --git a/WebCore/html/HTMLTableCellElement.h b/WebCore/html/HTMLTableCellElement.h index b598ce8..6a514ec 100644 --- a/WebCore/html/HTMLTableCellElement.h +++ b/WebCore/html/HTMLTableCellElement.h @@ -4,7 +4,7 @@ * (C) 1998 Waldo Bastian (bastian@kde.org) * (C) 1999 Lars Knoll (knoll@kde.org) * (C) 1999 Antti Koivisto (koivisto@kde.org) - * Copyright (C) 2003, 2004, 2005, 2006 Apple Computer, Inc. + * Copyright (C) 2003, 2004, 2005, 2006, 2010 Apple Inc. All rights reserved. * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Library General Public @@ -32,30 +32,17 @@ namespace WebCore { class HTMLTableCellElement : public HTMLTablePartElement { public: - HTMLTableCellElement(const QualifiedName&, Document*); - ~HTMLTableCellElement(); - - virtual HTMLTagStatus endTagRequirement() const { return TagStatusOptional; } - virtual int tagPriority() const { return 6; } + static PassRefPtr<HTMLTableCellElement> create(const QualifiedName&, Document*); int cellIndex() const; - int col() const { return _col; } - void setCol(int col) { _col = col; } - int row() const { return _row; } - void setRow(int r) { _row = r; } - - int colSpan() const { return cSpan; } - int rowSpan() const { return rSpan; } - - virtual bool mapToEntry(const QualifiedName&, MappedAttributeEntry&) const; - virtual void parseMappedAttribute(Attribute*); + int col() const { return m_col; } + void setCol(int col) { m_col = col; } + int row() const { return m_row; } + void setRow(int row) { m_row = row; } - // used by table cells to share style decls created by the enclosing table. - virtual bool canHaveAdditionalAttributeStyleDecls() const { return true; } - virtual void additionalAttributeStyleDecls(Vector<CSSMutableStyleDeclaration*>&); - - virtual bool isURLAttribute(Attribute*) const; + int colSpan() const { return m_colSpan; } + int rowSpan() const { return m_rowSpan; } void setCellIndex(int); @@ -99,17 +86,29 @@ public: String width() const; void setWidth(const String&); +private: + HTMLTableCellElement(const QualifiedName&, Document*); + + virtual HTMLTagStatus endTagRequirement() const { return TagStatusOptional; } + virtual int tagPriority() const { return 6; } + + virtual bool mapToEntry(const QualifiedName&, MappedAttributeEntry&) const; + virtual void parseMappedAttribute(Attribute*); + + // used by table cells to share style decls created by the enclosing table. + virtual bool canHaveAdditionalAttributeStyleDecls() const { return true; } + virtual void additionalAttributeStyleDecls(Vector<CSSMutableStyleDeclaration*>&); + + virtual bool isURLAttribute(Attribute*) const; + virtual void addSubresourceAttributeURLs(ListHashSet<KURL>&) const; -protected: - int _row; - int _col; - int rSpan; - int cSpan; - int rowHeight; - bool m_solid; + int m_row; + int m_col; + int m_rowSpan; + int m_colSpan; }; -} //namespace +} // namespace #endif diff --git a/WebCore/html/HTMLTableColElement.cpp b/WebCore/html/HTMLTableColElement.cpp index 7a40be2..d21b307 100644 --- a/WebCore/html/HTMLTableColElement.cpp +++ b/WebCore/html/HTMLTableColElement.cpp @@ -1,10 +1,10 @@ -/** +/* * Copyright (C) 1997 Martin Jones (mjones@kde.org) * (C) 1997 Torben Weis (weis@kde.org) * (C) 1998 Waldo Bastian (bastian@kde.org) * (C) 1999 Lars Knoll (knoll@kde.org) * (C) 1999 Antti Koivisto (koivisto@kde.org) - * Copyright (C) 2003, 2004, 2005, 2006 Apple Computer, Inc. + * Copyright (C) 2003, 2004, 2005, 2006, 2010 Apple Inc. All rights reserved. * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Library General Public @@ -36,10 +36,15 @@ namespace WebCore { using namespace HTMLNames; -HTMLTableColElement::HTMLTableColElement(const QualifiedName& tagName, Document *doc) - : HTMLTablePartElement(tagName, doc) +inline HTMLTableColElement::HTMLTableColElement(const QualifiedName& tagName, Document* document) + : HTMLTablePartElement(tagName, document) + , m_span(1) { - _span = 1; +} + +PassRefPtr<HTMLTableColElement> HTMLTableColElement::create(const QualifiedName& tagName, Document* document) +{ + return new HTMLTableColElement(tagName, document); } HTMLTagStatus HTMLTableColElement::endTagRequirement() const @@ -75,7 +80,7 @@ bool HTMLTableColElement::mapToEntry(const QualifiedName& attrName, MappedAttrib void HTMLTableColElement::parseMappedAttribute(Attribute* attr) { if (attr->name() == spanAttr) { - _span = !attr->isNull() ? attr->value().toInt() : 1; + m_span = !attr->isNull() ? attr->value().toInt() : 1; if (renderer() && renderer()->isTableCol()) renderer()->updateFromElement(); } else if (attr->name() == widthAttr) { diff --git a/WebCore/html/HTMLTableColElement.h b/WebCore/html/HTMLTableColElement.h index 3710c11..07b0ae8 100644 --- a/WebCore/html/HTMLTableColElement.h +++ b/WebCore/html/HTMLTableColElement.h @@ -4,7 +4,7 @@ * (C) 1998 Waldo Bastian (bastian@kde.org) * (C) 1999 Lars Knoll (knoll@kde.org) * (C) 1999 Antti Koivisto (koivisto@kde.org) - * Copyright (C) 2003, 2004, 2005, 2006 Apple Computer, Inc. + * Copyright (C) 2003, 2004, 2005, 2006, 2010 Apple Inc. All rights reserved. * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Library General Public @@ -30,23 +30,11 @@ namespace WebCore { -class HTMLTableElement; - class HTMLTableColElement : public HTMLTablePartElement { public: - HTMLTableColElement(const QualifiedName& tagName, Document*); - - virtual HTMLTagStatus endTagRequirement() const; - virtual int tagPriority() const; - virtual bool checkDTD(const Node*); + static PassRefPtr<HTMLTableColElement> create(const QualifiedName& tagName, Document*); - // overrides - virtual bool mapToEntry(const QualifiedName&, MappedAttributeEntry&) const; - virtual void parseMappedAttribute(Attribute*); - virtual bool canHaveAdditionalAttributeStyleDecls() const { return true; } - virtual void additionalAttributeStyleDecls(Vector<CSSMutableStyleDeclaration*>&); - - int span() const { return _span; } + int span() const { return m_span; } String align() const; void setAlign(const String&); @@ -65,8 +53,18 @@ public: String width() const; void setWidth(const String&); -protected: - int _span; +private: + HTMLTableColElement(const QualifiedName& tagName, Document*); + + virtual HTMLTagStatus endTagRequirement() const; + virtual int tagPriority() const; + virtual bool checkDTD(const Node*); + virtual bool mapToEntry(const QualifiedName&, MappedAttributeEntry&) const; + virtual void parseMappedAttribute(Attribute*); + virtual bool canHaveAdditionalAttributeStyleDecls() const { return true; } + virtual void additionalAttributeStyleDecls(Vector<CSSMutableStyleDeclaration*>&); + + int m_span; }; } //namespace diff --git a/WebCore/html/HTMLTableElement.cpp b/WebCore/html/HTMLTableElement.cpp index 338f505..7532b35 100644 --- a/WebCore/html/HTMLTableElement.cpp +++ b/WebCore/html/HTMLTableElement.cpp @@ -4,7 +4,7 @@ * (C) 1998 Waldo Bastian (bastian@kde.org) * (C) 1999 Lars Knoll (knoll@kde.org) * (C) 1999 Antti Koivisto (koivisto@kde.org) - * Copyright (C) 2003, 2004, 2005, 2006, 2008 Apple Inc. All rights reserved. + * Copyright (C) 2003, 2004, 2005, 2006, 2008, 2010 Apple Inc. All rights reserved. * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Library General Public @@ -42,8 +42,8 @@ namespace WebCore { using namespace HTMLNames; -HTMLTableElement::HTMLTableElement(const QualifiedName& tagName, Document* doc) - : HTMLElement(tagName, doc) +HTMLTableElement::HTMLTableElement(const QualifiedName& tagName, Document* document) + : HTMLElement(tagName, document) , m_borderAttr(false) , m_borderColorAttr(false) , m_frameAttr(false) @@ -53,6 +53,16 @@ HTMLTableElement::HTMLTableElement(const QualifiedName& tagName, Document* doc) ASSERT(hasTagName(tableTag)); } +PassRefPtr<HTMLTableElement> HTMLTableElement::create(Document* document) +{ + return new HTMLTableElement(tableTag, document); +} + +PassRefPtr<HTMLTableElement> HTMLTableElement::create(const QualifiedName& tagName, Document* document) +{ + return new HTMLTableElement(tagName, document); +} + bool HTMLTableElement::checkDTD(const Node* newChild) { if (newChild->isTextNode()) @@ -125,7 +135,7 @@ PassRefPtr<HTMLElement> HTMLTableElement::createTHead() { if (HTMLTableSectionElement* existingHead = tHead()) return existingHead; - RefPtr<HTMLTableSectionElement> head = new HTMLTableSectionElement(theadTag, document()); + RefPtr<HTMLTableSectionElement> head = HTMLTableSectionElement::create(theadTag, document()); ExceptionCode ec; setTHead(head, ec); return head.release(); @@ -141,7 +151,7 @@ PassRefPtr<HTMLElement> HTMLTableElement::createTFoot() { if (HTMLTableSectionElement* existingFoot = tFoot()) return existingFoot; - RefPtr<HTMLTableSectionElement> foot = new HTMLTableSectionElement(tfootTag, document()); + RefPtr<HTMLTableSectionElement> foot = HTMLTableSectionElement::create(tfootTag, document()); ExceptionCode ec; setTFoot(foot, ec); return foot.release(); @@ -157,7 +167,7 @@ PassRefPtr<HTMLElement> HTMLTableElement::createCaption() { if (HTMLTableCaptionElement* existingCaption = caption()) return existingCaption; - RefPtr<HTMLTableCaptionElement> caption = new HTMLTableCaptionElement(captionTag, document()); + RefPtr<HTMLTableCaptionElement> caption = HTMLTableCaptionElement::create(captionTag, document()); ExceptionCode ec; setCaption(caption, ec); return caption.release(); @@ -209,15 +219,15 @@ PassRefPtr<HTMLElement> HTMLTableElement::insertRow(int index, ExceptionCode& ec else { parent = lastBody(); if (!parent) { - RefPtr<HTMLTableSectionElement> newBody = new HTMLTableSectionElement(tbodyTag, document()); - RefPtr<HTMLTableRowElement> newRow = new HTMLTableRowElement(trTag, document()); + RefPtr<HTMLTableSectionElement> newBody = HTMLTableSectionElement::create(tbodyTag, document()); + RefPtr<HTMLTableRowElement> newRow = HTMLTableRowElement::create(document()); newBody->appendChild(newRow, ec); appendChild(newBody.release(), ec); return newRow.release(); } } - RefPtr<HTMLTableRowElement> newRow = new HTMLTableRowElement(trTag, document()); + RefPtr<HTMLTableRowElement> newRow = HTMLTableRowElement::create(document()); parent->insertBefore(newRow, row, ec); return newRow.release(); } diff --git a/WebCore/html/HTMLTableElement.h b/WebCore/html/HTMLTableElement.h index 7f1e747..0189ce4 100644 --- a/WebCore/html/HTMLTableElement.h +++ b/WebCore/html/HTMLTableElement.h @@ -36,11 +36,8 @@ class HTMLTableSectionElement; class HTMLTableElement : public HTMLElement { public: - HTMLTableElement(const QualifiedName&, Document*); - - virtual HTMLTagStatus endTagRequirement() const { return TagStatusRequired; } - virtual int tagPriority() const { return 9; } - virtual bool checkDTD(const Node*); + static PassRefPtr<HTMLTableElement> create(Document*); + static PassRefPtr<HTMLTableElement> create(const QualifiedName&, Document*); HTMLTableCaptionElement* caption() const; void setCaption(PassRefPtr<HTMLTableCaptionElement>, ExceptionCode&); @@ -91,21 +88,30 @@ public: void setWidth(const String&); virtual ContainerNode* addChild(PassRefPtr<Node>); + + virtual void attach(); + + void addSharedCellDecls(Vector<CSSMutableStyleDeclaration*>&); + void addSharedGroupDecls(bool rows, Vector<CSSMutableStyleDeclaration*>&); + +private: + HTMLTableElement(const QualifiedName&, Document*); + + virtual HTMLTagStatus endTagRequirement() const { return TagStatusRequired; } + virtual int tagPriority() const { return 9; } + virtual bool checkDTD(const Node*); + virtual bool mapToEntry(const QualifiedName&, MappedAttributeEntry&) const; virtual void parseMappedAttribute(Attribute*); - virtual void attach(); virtual bool isURLAttribute(Attribute*) const; // Used to obtain either a solid or outset border decl and to deal with the frame // and rules attributes. virtual bool canHaveAdditionalAttributeStyleDecls() const { return true; } virtual void additionalAttributeStyleDecls(Vector<CSSMutableStyleDeclaration*>&); - void addSharedCellDecls(Vector<CSSMutableStyleDeclaration*>&); - void addSharedGroupDecls(bool rows, Vector<CSSMutableStyleDeclaration*>&); virtual void addSubresourceAttributeURLs(ListHashSet<KURL>&) const; -private: void addSharedCellBordersDecl(Vector<CSSMutableStyleDeclaration*>&); void addSharedCellPaddingDecl(Vector<CSSMutableStyleDeclaration*>&); @@ -121,7 +127,7 @@ private: bool m_frameAttr; // Implies a thin border width if no border is set and then a certain set of solid/hidden borders based off the value. TableRules m_rulesAttr; // Implies a thin border width, a collapsing border model, and all borders on the table becoming set to hidden (if frame/border // are present, to none otherwise). - + unsigned short m_padding; RefPtr<CSSMappedAttributeDeclaration> m_paddingDecl; }; diff --git a/WebCore/html/HTMLTablePartElement.h b/WebCore/html/HTMLTablePartElement.h index cd8b590..9df2f91 100644 --- a/WebCore/html/HTMLTablePartElement.h +++ b/WebCore/html/HTMLTablePartElement.h @@ -4,7 +4,7 @@ * (C) 1998 Waldo Bastian (bastian@kde.org) * (C) 1999 Lars Knoll (knoll@kde.org) * (C) 1999 Antti Koivisto (koivisto@kde.org) - * Copyright (C) 2003, 2004, 2005, 2006 Apple Computer, Inc. + * Copyright (C) 2003, 2004, 2005, 2006, 2010 Apple Inc. All rights reserved. * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Library General Public @@ -31,10 +31,11 @@ namespace WebCore { class HTMLTablePartElement : public HTMLElement { -public: - HTMLTablePartElement(const QualifiedName& tagName, Document* doc) - : HTMLElement(tagName, doc) - { } +protected: + HTMLTablePartElement(const QualifiedName& tagName, Document* document) + : HTMLElement(tagName, document) + { + } virtual bool mapToEntry(const QualifiedName&, MappedAttributeEntry&) const; virtual void parseMappedAttribute(Attribute*); diff --git a/WebCore/html/HTMLTableRowElement.cpp b/WebCore/html/HTMLTableRowElement.cpp index 94be02e..49f85ce 100644 --- a/WebCore/html/HTMLTableRowElement.cpp +++ b/WebCore/html/HTMLTableRowElement.cpp @@ -4,7 +4,7 @@ * (C) 1998 Waldo Bastian (bastian@kde.org) * (C) 1999 Lars Knoll (knoll@kde.org) * (C) 1999 Antti Koivisto (koivisto@kde.org) - * Copyright (C) 2003, 2004, 2005, 2006, 2007 Apple Inc. All rights reserved. + * Copyright (C) 2003, 2004, 2005, 2006, 2007, 2010 Apple Inc. All rights reserved. * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Library General Public @@ -38,12 +38,22 @@ namespace WebCore { using namespace HTMLNames; -HTMLTableRowElement::HTMLTableRowElement(const QualifiedName& tagName, Document* doc) - : HTMLTablePartElement(tagName, doc) +HTMLTableRowElement::HTMLTableRowElement(const QualifiedName& tagName, Document* document) + : HTMLTablePartElement(tagName, document) { ASSERT(hasTagName(trTag)); } +PassRefPtr<HTMLTableRowElement> HTMLTableRowElement::create(Document* document) +{ + return new HTMLTableRowElement(trTag, document); +} + +PassRefPtr<HTMLTableRowElement> HTMLTableRowElement::create(const QualifiedName& tagName, Document* document) +{ + return new HTMLTableRowElement(tagName, document); +} + bool HTMLTableRowElement::checkDTD(const Node* newChild) { if (newChild->isTextNode()) @@ -139,18 +149,18 @@ PassRefPtr<HTMLElement> HTMLTableRowElement::insertCell(int index, ExceptionCode return 0; } - RefPtr<HTMLTableCellElement> c = new HTMLTableCellElement(tdTag, document()); + RefPtr<HTMLTableCellElement> cell = HTMLTableCellElement::create(tdTag, document()); if (index < 0 || index >= numCells) - appendChild(c, ec); + appendChild(cell, ec); else { Node* n; if (index < 1) n = firstChild(); else n = children->item(index); - insertBefore(c, n, ec); + insertBefore(cell, n, ec); } - return c.release(); + return cell.release(); } void HTMLTableRowElement::deleteCell(int index, ExceptionCode& ec) diff --git a/WebCore/html/HTMLTableRowElement.h b/WebCore/html/HTMLTableRowElement.h index 6d35551..b47edc2 100644 --- a/WebCore/html/HTMLTableRowElement.h +++ b/WebCore/html/HTMLTableRowElement.h @@ -4,7 +4,7 @@ * (C) 1998 Waldo Bastian (bastian@kde.org) * (C) 1999 Lars Knoll (knoll@kde.org) * (C) 1999 Antti Koivisto (koivisto@kde.org) - * Copyright (C) 2003, 2004, 2005, 2006, 2007 Apple Inc. All rights reserved. + * Copyright (C) 2003, 2004, 2005, 2006, 2007, 2010 Apple Inc. All rights reserved. * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Library General Public @@ -32,11 +32,9 @@ namespace WebCore { class HTMLTableRowElement : public HTMLTablePartElement { public: - HTMLTableRowElement(const QualifiedName&, Document*); + static PassRefPtr<HTMLTableRowElement> create(Document*); + static PassRefPtr<HTMLTableRowElement> create(const QualifiedName&, Document*); - virtual HTMLTagStatus endTagRequirement() const { return TagStatusOptional; } - virtual int tagPriority() const { return 7; } - virtual bool checkDTD(const Node*); virtual ContainerNode* addChild(PassRefPtr<Node>); int rowIndex() const; @@ -65,6 +63,13 @@ public: String vAlign() const; void setVAlign(const String&); + +private: + HTMLTableRowElement(const QualifiedName&, Document*); + + virtual HTMLTagStatus endTagRequirement() const { return TagStatusOptional; } + virtual int tagPriority() const { return 7; } + virtual bool checkDTD(const Node*); }; } // namespace diff --git a/WebCore/html/HTMLTableSectionElement.cpp b/WebCore/html/HTMLTableSectionElement.cpp index 15fa97e..96a0d9e 100644 --- a/WebCore/html/HTMLTableSectionElement.cpp +++ b/WebCore/html/HTMLTableSectionElement.cpp @@ -1,10 +1,10 @@ -/** +/* * Copyright (C) 1997 Martin Jones (mjones@kde.org) * (C) 1997 Torben Weis (weis@kde.org) * (C) 1998 Waldo Bastian (bastian@kde.org) * (C) 1999 Lars Knoll (knoll@kde.org) * (C) 1999 Antti Koivisto (koivisto@kde.org) - * Copyright (C) 2003, 2004, 2005, 2006 Apple Computer, Inc. + * Copyright (C) 2003, 2004, 2005, 2006, 2010 Apple Inc. All rights reserved. * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Library General Public @@ -21,6 +21,7 @@ * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, * Boston, MA 02110-1301, USA. */ + #include "config.h" #include "HTMLTableSectionElement.h" @@ -36,11 +37,16 @@ namespace WebCore { using namespace HTMLNames; -HTMLTableSectionElement::HTMLTableSectionElement(const QualifiedName& tagName, Document* document) +inline HTMLTableSectionElement::HTMLTableSectionElement(const QualifiedName& tagName, Document* document) : HTMLTablePartElement(tagName, document) { } +PassRefPtr<HTMLTableSectionElement> HTMLTableSectionElement::create(const QualifiedName& tagName, Document* document) +{ + return new HTMLTableSectionElement(tagName, document); +} + bool HTMLTableSectionElement::checkDTD(const Node* newChild) { if (newChild->isTextNode()) @@ -78,25 +84,25 @@ void HTMLTableSectionElement::additionalAttributeStyleDecls(Vector<CSSMutableSty // the index... but they aren't used during usual HTML parsing anyway PassRefPtr<HTMLElement> HTMLTableSectionElement::insertRow(int index, ExceptionCode& ec) { - RefPtr<HTMLTableRowElement> r; + RefPtr<HTMLTableRowElement> row; RefPtr<HTMLCollection> children = rows(); int numRows = children ? (int)children->length() : 0; if (index < -1 || index > numRows) ec = INDEX_SIZE_ERR; // per the DOM else { - r = new HTMLTableRowElement(trTag, document()); + row = HTMLTableRowElement::create(trTag, document()); if (numRows == index || index == -1) - appendChild(r, ec); + appendChild(row, ec); else { Node* n; if (index < 1) n = firstChild(); else n = children->item(index); - insertBefore(r, n, ec); + insertBefore(row, n, ec); } } - return r.release(); + return row.release(); } void HTMLTableSectionElement::deleteRow(int index, ExceptionCode& ec) diff --git a/WebCore/html/HTMLTableSectionElement.h b/WebCore/html/HTMLTableSectionElement.h index 819b369..f7c1d8a 100644 --- a/WebCore/html/HTMLTableSectionElement.h +++ b/WebCore/html/HTMLTableSectionElement.h @@ -32,14 +32,9 @@ namespace WebCore { class HTMLTableSectionElement : public HTMLTablePartElement { public: - HTMLTableSectionElement(const QualifiedName& tagName, Document*); + static PassRefPtr<HTMLTableSectionElement> create(const QualifiedName&, Document*); - virtual HTMLTagStatus endTagRequirement() const { return TagStatusOptional; } - virtual int tagPriority() const { return 8; } - virtual bool checkDTD(const Node*); virtual ContainerNode* addChild(PassRefPtr<Node>); - virtual bool canHaveAdditionalAttributeStyleDecls() const { return true; } - virtual void additionalAttributeStyleDecls(Vector<CSSMutableStyleDeclaration*>&); PassRefPtr<HTMLElement> insertRow(int index, ExceptionCode&); void deleteRow(int index, ExceptionCode&); @@ -59,6 +54,15 @@ public: void setVAlign(const String&); PassRefPtr<HTMLCollection> rows(); + +private: + HTMLTableSectionElement(const QualifiedName& tagName, Document*); + + virtual HTMLTagStatus endTagRequirement() const { return TagStatusOptional; } + virtual int tagPriority() const { return 8; } + virtual bool checkDTD(const Node*); + virtual bool canHaveAdditionalAttributeStyleDecls() const { return true; } + virtual void additionalAttributeStyleDecls(Vector<CSSMutableStyleDeclaration*>&); }; } //namespace diff --git a/WebCore/html/HTMLTagNames.in b/WebCore/html/HTMLTagNames.in index 6374b4d..8e67cba 100644 --- a/WebCore/html/HTMLTagNames.in +++ b/WebCore/html/HTMLTagNames.in @@ -10,73 +10,73 @@ applet area article interfaceName=HTMLElement aside interfaceName=HTMLElement -audio wrapperOnlyIfMediaIsAvailable, conditional=VIDEO, createWithNew +audio wrapperOnlyIfMediaIsAvailable, conditional=VIDEO b interfaceName=HTMLElement -base createWithNew -basefont interfaceName=HTMLBaseFontElement, createWithNew +base +basefont interfaceName=HTMLBaseFontElement bdo interfaceName=HTMLElement big interfaceName=HTMLElement -blockquote createWithNew -body createWithNew -br interfaceName=HTMLBRElement, createWithNew -button constructorNeedsFormElement, createWithNew -canvas createWithNew -caption interfaceName=HTMLTableCaptionElement, createWithNew +blockquote +body +br interfaceName=HTMLBRElement +button constructorNeedsFormElement +canvas +caption interfaceName=HTMLTableCaptionElement center interfaceName=HTMLElement cite interfaceName=HTMLElement code interfaceName=HTMLElement -col interfaceName=HTMLTableColElement, createWithNew -colgroup interfaceName=HTMLTableColElement, createWithNew -datagrid interfaceName=HTMLDataGridElement, conditional=DATAGRID, createWithNew -datalist interfaceName=HTMLDataListElement, conditional=DATALIST, createWithNew -dcell interfaceName=HTMLDataGridCellElement, conditional=DATAGRID, createWithNew -dcol interfaceName=HTMLDataGridColElement, conditional=DATAGRID, createWithNew -drow interfaceName=HTMLDataGridRowElement, conditional=DATAGRID, createWithNew +col interfaceName=HTMLTableColElement +colgroup interfaceName=HTMLTableColElement +datagrid interfaceName=HTMLDataGridElement, conditional=DATAGRID +datalist interfaceName=HTMLDataListElement, conditional=DATALIST +dcell interfaceName=HTMLDataGridCellElement, conditional=DATAGRID +dcol interfaceName=HTMLDataGridColElement, conditional=DATAGRID +drow interfaceName=HTMLDataGridRowElement, conditional=DATAGRID dd interfaceName=HTMLElement -del interfaceName=HTMLModElement, createWithNew +del interfaceName=HTMLModElement dfn interfaceName=HTMLElement -dir interfaceName=HTMLDirectoryElement, createWithNew -div createWithNew -dl interfaceName=HTMLDListElement, createWithNew, createWithNew +dir interfaceName=HTMLDirectoryElement +div +dl interfaceName=HTMLDListElement dt interfaceName=HTMLElement em interfaceName=HTMLElement embed -fieldset interfaceName=HTMLFieldSetElement, constructorNeedsFormElement, createWithNew -font createWithNew +fieldset interfaceName=HTMLFieldSetElement, constructorNeedsFormElement +font footer interfaceName=HTMLElement -form createWithNew +form frame -frameset interfaceName=HTMLFrameSetElement, createWithNew -h1 interfaceName=HTMLHeadingElement, createWithNew -h2 interfaceName=HTMLHeadingElement, createWithNew -h3 interfaceName=HTMLHeadingElement, createWithNew -h4 interfaceName=HTMLHeadingElement, createWithNew -h5 interfaceName=HTMLHeadingElement, createWithNew -h6 interfaceName=HTMLHeadingElement, createWithNew -head createWithNew +frameset interfaceName=HTMLFrameSetElement +h1 interfaceName=HTMLHeadingElement +h2 interfaceName=HTMLHeadingElement +h3 interfaceName=HTMLHeadingElement +h4 interfaceName=HTMLHeadingElement +h5 interfaceName=HTMLHeadingElement +h6 interfaceName=HTMLHeadingElement +head header interfaceName=HTMLElement hgroup interfaceName=HTMLElement -hr interfaceName=HTMLHRElement, createWithNew -html createWithNew +hr interfaceName=HTMLHRElement +html i interfaceName=HTMLElement iframe interfaceName=HTMLIFrameElement -image mapToTagName=img, createWithNew -img interfaceName=HTMLImageElement, constructorNeedsFormElement, createWithNew -input constructorNeedsFormElement, createWithNew -ins interfaceName=HTMLModElement, createWithNew -isindex interfaceName=HTMLIsIndexElement, constructorNeedsFormElement, createWithNew +image mapToTagName=img +img interfaceName=HTMLImageElement, constructorNeedsFormElement +input constructorNeedsFormElement +ins interfaceName=HTMLModElement +isindex interfaceName=HTMLIsIndexElement, constructorNeedsFormElement kbd interfaceName=HTMLElement -keygen JSInterfaceName=HTMLSelectElement, constructorNeedsFormElement, createWithNew -label createWithNew +keygen JSInterfaceName=HTMLSelectElement, constructorNeedsFormElement +label layer interfaceName=HTMLElement -legend constructorNeedsFormElement, createWithNew -li interfaceName=HTMLLIElement, createWithNew -link constructorNeedsCreatedByParser, createWithNew -listing interfaceName=HTMLPreElement, createWithNew -map createWithNew -marquee createWithNew -menu createWithNew -meta createWithNew +legend constructorNeedsFormElement +li interfaceName=HTMLLIElement +link constructorNeedsCreatedByParser +listing interfaceName=HTMLPreElement +map +marquee +menu +meta meter interfaceName=HTMLMeterElement, conditional=METER_TAG nav interfaceName=HTMLElement nobr interfaceName=HTMLElement @@ -84,50 +84,50 @@ noembed interfaceName=HTMLElement noframes interfaceName=HTMLElement nolayer interfaceName=HTMLElement object constructorNeedsCreatedByParser -ol interfaceName=HTMLOListElement, createWithNew -optgroup interfaceName=HTMLOptGroupElement, constructorNeedsFormElement, createWithNew -option constructorNeedsFormElement, createWithNew -p interfaceName=HTMLParagraphElement, createWithNew -param createWithNew +ol interfaceName=HTMLOListElement +optgroup interfaceName=HTMLOptGroupElement, constructorNeedsFormElement +option constructorNeedsFormElement +p interfaceName=HTMLParagraphElement +param plaintext interfaceName=HTMLElement -pre createWithNew +pre progress interfaceName=HTMLProgressElement, conditional=PROGRESS_TAG -q interfaceName=HTMLQuoteElement, createWithNew +q interfaceName=HTMLQuoteElement rp interfaceName=HTMLElement, conditional=RUBY rt interfaceName=HTMLElement, conditional=RUBY ruby interfaceName=HTMLElement, conditional=RUBY s interfaceName=HTMLElement samp interfaceName=HTMLElement -script constructorNeedsCreatedByParser, createWithNew +script constructorNeedsCreatedByParser section interfaceName=HTMLElement -select constructorNeedsFormElement, createWithNew +select constructorNeedsFormElement small interfaceName=HTMLElement -source wrapperOnlyIfMediaIsAvailable, conditional=VIDEO, createWithNew +source wrapperOnlyIfMediaIsAvailable, conditional=VIDEO span interfaceName=HTMLElement strike interfaceName=HTMLElement strong interfaceName=HTMLElement -style constructorNeedsCreatedByParser, createWithNew +style constructorNeedsCreatedByParser sub interfaceName=HTMLElement sup interfaceName=HTMLElement -table createWithNew -tbody interfaceName=HTMLTableSectionElement, createWithNew -td interfaceName=HTMLTableCellElement, createWithNew -textarea interfaceName=HTMLTextAreaElement, constructorNeedsFormElement, createWithNew -tfoot interfaceName=HTMLTableSectionElement, createWithNew -th interfaceName=HTMLTableCellElement, createWithNew -thead interfaceName=HTMLTableSectionElement, createWithNew -title createWithNew -tr interfaceName=HTMLTableRowElement, createWithNew +table +tbody interfaceName=HTMLTableSectionElement +td interfaceName=HTMLTableCellElement +textarea interfaceName=HTMLTextAreaElement, constructorNeedsFormElement +tfoot interfaceName=HTMLTableSectionElement +th interfaceName=HTMLTableCellElement +thead interfaceName=HTMLTableSectionElement +title +tr interfaceName=HTMLTableRowElement tt interfaceName=HTMLElement u interfaceName=HTMLElement -ul interfaceName=HTMLUListElement, createWithNew +ul interfaceName=HTMLUListElement var interfaceName=HTMLElement -video wrapperOnlyIfMediaIsAvailable, conditional=VIDEO, createWithNew +video wrapperOnlyIfMediaIsAvailable, conditional=VIDEO wbr interfaceName=HTMLElement -xmp interfaceName=HTMLPreElement, createWithNew +xmp interfaceName=HTMLPreElement #if ENABLE_XHTMLMP -noscript interfaceName=HTMLNoScriptElement, createWithNew +noscript interfaceName=HTMLNoScriptElement #else noscript interfaceName=HTMLElement #endif diff --git a/WebCore/html/HTMLTextAreaElement.cpp b/WebCore/html/HTMLTextAreaElement.cpp index bb88b1c..dd82aea 100644 --- a/WebCore/html/HTMLTextAreaElement.cpp +++ b/WebCore/html/HTMLTextAreaElement.cpp @@ -2,7 +2,7 @@ * Copyright (C) 1999 Lars Knoll (knoll@kde.org) * (C) 1999 Antti Koivisto (koivisto@kde.org) * (C) 2001 Dirk Mueller (mueller@kde.org) - * Copyright (C) 2004, 2005, 2006, 2007, 2008 Apple Inc. All rights reserved. + * Copyright (C) 2004, 2005, 2006, 2007, 2008, 2010 Apple Inc. All rights reserved. * (C) 2006 Alexey Proskuryakov (ap@nypop.com) * Copyright (C) 2007 Samuel Weinig (sam@webkit.org) * @@ -79,7 +79,11 @@ HTMLTextAreaElement::HTMLTextAreaElement(const QualifiedName& tagName, Document* { ASSERT(hasTagName(textareaTag)); setFormControlValueMatchesRenderer(true); - notifyFormStateChanged(this); +} + +PassRefPtr<HTMLTextAreaElement> HTMLTextAreaElement::create(const QualifiedName& tagName, Document* document, HTMLFormElement* form) +{ + return new HTMLTextAreaElement(tagName, document, form); } const AtomicString& HTMLTextAreaElement::formControlType() const diff --git a/WebCore/html/HTMLTextAreaElement.h b/WebCore/html/HTMLTextAreaElement.h index d38f613..af233ae 100644 --- a/WebCore/html/HTMLTextAreaElement.h +++ b/WebCore/html/HTMLTextAreaElement.h @@ -2,7 +2,7 @@ * Copyright (C) 1999 Lars Knoll (knoll@kde.org) * (C) 1999 Antti Koivisto (koivisto@kde.org) * (C) 2000 Dirk Mueller (mueller@kde.org) - * Copyright (C) 2004, 2005, 2006, 2007 Apple Inc. All rights reserved. + * Copyright (C) 2004, 2005, 2006, 2007, 2010 Apple Inc. All rights reserved. * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Library General Public @@ -33,37 +33,13 @@ class VisibleSelection; class HTMLTextAreaElement : public HTMLTextFormControlElement { public: - HTMLTextAreaElement(const QualifiedName&, Document*, HTMLFormElement* = 0); - - virtual bool checkDTD(const Node* newChild) { return newChild->isTextNode(); } + static PassRefPtr<HTMLTextAreaElement> create(const QualifiedName&, Document*, HTMLFormElement*); int cols() const { return m_cols; } int rows() const { return m_rows; } bool shouldWrapText() const { return m_wrap != NoWrap; } - virtual bool isEnumeratable() const { return true; } - - virtual const AtomicString& formControlType() const; - - virtual bool saveFormControlState(String& value) const; - virtual void restoreFormControlState(const String&); - - bool readOnly() const { return isReadOnlyFormControl(); } - - virtual bool isTextFormControl() const { return true; } - - 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(Attribute*); - virtual RenderObject* createRenderer(RenderArena*, RenderStyle*); - virtual bool appendFormData(FormDataList&, bool); - virtual void reset(); - virtual bool isMouseFocusable() const; - virtual bool isKeyboardFocusable(KeyboardEvent*) const; - virtual void updateFocusAppearance(bool restorePreviousSelection); - String value() const; void setValue(const String&); String defaultValue() const; @@ -75,8 +51,6 @@ public: void rendererWillBeDestroyed(); - virtual void accessKeyAction(bool sendToAnyElement); - const AtomicString& accessKey() const; void setAccessKey(const String&); @@ -85,9 +59,9 @@ public: void cacheSelection(int s, int e) { m_cachedSelectionStart = s; m_cachedSelectionEnd = e; }; - virtual bool shouldUseInputMethod() const; - private: + HTMLTextAreaElement(const QualifiedName&, Document*, HTMLFormElement*); + enum WrapMethod { NoWrap, SoftWrap, HardWrap }; void handleBeforeTextInsertedEvent(BeforeTextInsertedEvent*) const; @@ -105,6 +79,32 @@ private: virtual void defaultEventHandler(Event*); + virtual bool checkDTD(const Node* newChild) { return newChild->isTextNode(); } + + virtual bool isEnumeratable() const { return true; } + + virtual const AtomicString& formControlType() const; + + virtual bool saveFormControlState(String& value) const; + virtual void restoreFormControlState(const String&); + + virtual bool isTextFormControl() const { return true; } + + 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(Attribute*); + virtual RenderObject* createRenderer(RenderArena*, RenderStyle*); + virtual bool appendFormData(FormDataList&, bool); + virtual void reset(); + virtual bool isMouseFocusable() const; + virtual bool isKeyboardFocusable(KeyboardEvent*) const; + virtual void updateFocusAppearance(bool restorePreviousSelection); + + virtual void accessKeyAction(bool sendToAnyElement); + + virtual bool shouldUseInputMethod() const; + int m_rows; int m_cols; WrapMethod m_wrap; diff --git a/WebCore/html/HTMLTextAreaElement.idl b/WebCore/html/HTMLTextAreaElement.idl index 2d82eed..a17f2ec 100644 --- a/WebCore/html/HTMLTextAreaElement.idl +++ b/WebCore/html/HTMLTextAreaElement.idl @@ -50,6 +50,7 @@ module html { attribute long selectionStart; attribute long selectionEnd; void setSelectionRange(in long start, in long end); + readonly attribute NodeList labels; }; } diff --git a/WebCore/html/HTMLTitleElement.cpp b/WebCore/html/HTMLTitleElement.cpp index 81ecd10..40c9f8b 100644 --- a/WebCore/html/HTMLTitleElement.cpp +++ b/WebCore/html/HTMLTitleElement.cpp @@ -1,8 +1,8 @@ -/** +/* * Copyright (C) 1999 Lars Knoll (knoll@kde.org) * (C) 1999 Antti Koivisto (koivisto@kde.org) * (C) 2001 Dirk Mueller (mueller@kde.org) - * Copyright (C) 2003 Apple Computer, Inc. + * Copyright (C) 2003, 2010 Apple Inc. All rights reserved. * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Library General Public @@ -19,6 +19,7 @@ * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, * Boston, MA 02110-1301, USA. */ + #include "config.h" #include "HTMLTitleElement.h" @@ -30,15 +31,16 @@ namespace WebCore { using namespace HTMLNames; -HTMLTitleElement::HTMLTitleElement(const QualifiedName& tagName, Document* doc) - : HTMLElement(tagName, doc) +inline HTMLTitleElement::HTMLTitleElement(const QualifiedName& tagName, Document* document) + : HTMLElement(tagName, document) , m_title("") { ASSERT(hasTagName(titleTag)); } -HTMLTitleElement::~HTMLTitleElement() +PassRefPtr<HTMLTitleElement> HTMLTitleElement::create(const QualifiedName& tagName, Document* document) { + return new HTMLTitleElement(tagName, document); } void HTMLTitleElement::insertedIntoDocument() diff --git a/WebCore/html/HTMLTitleElement.h b/WebCore/html/HTMLTitleElement.h index 677bffd..bcd4283 100644 --- a/WebCore/html/HTMLTitleElement.h +++ b/WebCore/html/HTMLTitleElement.h @@ -1,7 +1,7 @@ /* * Copyright (C) 1999 Lars Knoll (knoll@kde.org) * (C) 1999 Antti Koivisto (koivisto@kde.org) - * Copyright (C) 2003 Apple Computer, Inc. + * Copyright (C) 2003, 2010 Apple Inc. All rights reserved. * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Library General Public @@ -28,8 +28,13 @@ namespace WebCore { class HTMLTitleElement : public HTMLElement { public: + static PassRefPtr<HTMLTitleElement> create(const QualifiedName&, Document*); + + String text() const; + void setText(const String&); + +private: HTMLTitleElement(const QualifiedName&, Document*); - ~HTMLTitleElement(); virtual bool checkDTD(const Node* newChild) { return newChild->isTextNode(); } @@ -37,10 +42,6 @@ public: virtual void removedFromDocument(); virtual void childrenChanged(bool changedByParser = false, Node* beforeChange = 0, Node* afterChange = 0, int childCountDelta = 0); - String text() const; - void setText(const String&); - -protected: String m_title; }; diff --git a/WebCore/html/HTMLTokenizer.cpp b/WebCore/html/HTMLTokenizer.cpp index a0877ff..e3d3ce6 100644 --- a/WebCore/html/HTMLTokenizer.cpp +++ b/WebCore/html/HTMLTokenizer.cpp @@ -62,7 +62,6 @@ #endif #define PRELOAD_SCANNER_ENABLED 1 -// #define INSTRUMENT_LAYOUT_SCHEDULING 1 using namespace WTF; using namespace std; @@ -440,10 +439,6 @@ HTMLTokenizer::State HTMLTokenizer::scriptHandler(State state) if (!m_scriptTagSrcAttrValue.isEmpty() && m_doc->frame()) { // forget what we just got; load from src url instead if (!m_parser->skipMode() && !followingFrameset) { -#ifdef INSTRUMENT_LAYOUT_SCHEDULING - if (!m_doc->ownerElement()) - printf("Requesting script at time %d\n", m_doc->elapsedTime()); -#endif // The parser might have been stopped by for example a window.close call in an earlier script. // If so, we don't want to load scripts. if (!m_parserStopped && m_scriptNode->dispatchBeforeLoadEvent(m_scriptTagSrcAttrValue) && @@ -575,22 +570,12 @@ HTMLTokenizer::State HTMLTokenizer::scriptExecution(const ScriptSourceCode& sour SegmentedString prependingSrc; m_currentPrependingSrc = &prependingSrc; -#ifdef INSTRUMENT_LAYOUT_SCHEDULING - if (!m_doc->ownerElement()) - printf("beginning script execution at %d\n", m_doc->elapsedTime()); -#endif - m_state = state; m_doc->frame()->script()->executeScript(sourceCode); state = m_state; state.setAllowYield(true); -#ifdef INSTRUMENT_LAYOUT_SCHEDULING - if (!m_doc->ownerElement()) - printf("ending script execution at %d\n", m_doc->elapsedTime()); -#endif - m_executingScript--; if (!m_executingScript && !state.loadingExtScript()) { @@ -1621,10 +1606,6 @@ inline bool HTMLTokenizer::continueProcessing(int& processedCount, double startT (m_doc->documentElement()->id() != ID_HTML || m_doc->body()))) {*/ // Schedule the timer to keep processing as soon as possible. m_timer.startOneShot(0); -#ifdef INSTRUMENT_LAYOUT_SCHEDULING - if (currentTime() - startTime > m_tokenizerTimeDelay) - printf("Deferring processing of data because 500ms elapsed away from event loop.\n"); -#endif return false; } } @@ -1634,7 +1615,7 @@ inline bool HTMLTokenizer::continueProcessing(int& processedCount, double startT } // Turns the statemachine one crank using the passed in State object. -// FIXME: Eventually this should modify m_state directly. +// This does not modify m_state directly in order to be reentrant. ALWAYS_INLINE void HTMLTokenizer::advance(State& state) { // do we need to enlarge the buffer? @@ -1745,11 +1726,6 @@ ALWAYS_INLINE void HTMLTokenizer::advance(State& state) 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); @@ -1758,11 +1734,6 @@ void HTMLTokenizer::willWriteHTML(const SegmentedString& source) 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); @@ -1863,11 +1834,6 @@ bool HTMLTokenizer::processingData() const void HTMLTokenizer::timerFired(Timer<HTMLTokenizer>*) { -#ifdef INSTRUMENT_LAYOUT_SCHEDULING - if (!m_doc->ownerElement()) - printf("Beginning timer write at time %d\n", m_doc->elapsedTime()); -#endif - if (m_doc->view() && m_doc->view()->layoutPending() && !m_doc->minimumLayoutDelay()) { // Restart the timer and let layout win. This is basically a way of ensuring that the layout // timer has higher priority than our timer. @@ -2050,11 +2016,6 @@ void HTMLTokenizer::notifyFinished(CachedResource*) void HTMLTokenizer::executeExternalScriptsIfReady() { -#ifdef INSTRUMENT_LAYOUT_SCHEDULING - if (!m_doc->ownerElement()) - printf("script loaded at %d\n", m_doc->elapsedTime()); -#endif - ASSERT(!m_pendingScripts.isEmpty()); // Make external scripts wait for external stylesheets. @@ -2084,11 +2045,6 @@ void HTMLTokenizer::executeExternalScriptsIfReady() RefPtr<Node> n = m_scriptNode.release(); -#ifdef INSTRUMENT_LAYOUT_SCHEDULING - if (!m_doc->ownerElement()) - printf("external script beginning execution at %d\n", m_doc->elapsedTime()); -#endif - if (errorOccurred) n->dispatchEvent(Event::create(eventNames().errorEvent, true, false)); else { @@ -2107,10 +2063,6 @@ void HTMLTokenizer::executeExternalScriptsIfReady() if (finished) { ASSERT(!m_hasScriptsWaitingForStylesheets); m_state.setLoadingExtScript(false); -#ifdef INSTRUMENT_LAYOUT_SCHEDULING - if (!m_doc->ownerElement()) - printf("external script finished execution at %d\n", m_doc->elapsedTime()); -#endif } else if (m_hasScriptsWaitingForStylesheets) { // m_hasScriptsWaitingForStylesheets flag might have changed during the script execution. // If it did we are now blocked waiting for stylesheets and should not execute more scripts until they arrive. diff --git a/WebCore/html/HTMLUListElement.cpp b/WebCore/html/HTMLUListElement.cpp index d4ae714..fcc20bc 100644 --- a/WebCore/html/HTMLUListElement.cpp +++ b/WebCore/html/HTMLUListElement.cpp @@ -1,6 +1,7 @@ -/** +/* * Copyright (C) 1999 Lars Knoll (knoll@kde.org) * (C) 1999 Antti Koivisto (koivisto@kde.org) + * Copyright (C) 2010 Apple Inc. All rights reserved. * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Library General Public @@ -30,12 +31,22 @@ namespace WebCore { using namespace HTMLNames; -HTMLUListElement::HTMLUListElement(const QualifiedName& tagName, Document* doc) - : HTMLElement(tagName, doc) +HTMLUListElement::HTMLUListElement(const QualifiedName& tagName, Document* document) + : HTMLElement(tagName, document) { ASSERT(hasTagName(ulTag)); } +PassRefPtr<HTMLUListElement> HTMLUListElement::create(Document* document) +{ + return new HTMLUListElement(ulTag, document); +} + +PassRefPtr<HTMLUListElement> HTMLUListElement::create(const QualifiedName& tagName, Document* document) +{ + return new HTMLUListElement(tagName, document); +} + bool HTMLUListElement::mapToEntry(const QualifiedName& attrName, MappedAttributeEntry& result) const { if (attrName == typeAttr) { diff --git a/WebCore/html/HTMLUListElement.h b/WebCore/html/HTMLUListElement.h index ee161d0..0b74c43 100644 --- a/WebCore/html/HTMLUListElement.h +++ b/WebCore/html/HTMLUListElement.h @@ -1,6 +1,7 @@ /* * Copyright (C) 1999 Lars Knoll (knoll@kde.org) * (C) 1999 Antti Koivisto (koivisto@kde.org) + * Copyright (C) 2010 Apple Inc. All rights reserved. * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Library General Public @@ -28,6 +29,16 @@ namespace WebCore { class HTMLUListElement : public HTMLElement { public: + static PassRefPtr<HTMLUListElement> create(Document*); + static PassRefPtr<HTMLUListElement> create(const QualifiedName&, Document*); + + bool compact() const; + void setCompact(bool); + + String type() const; + void setType(const String&); + +private: HTMLUListElement(const QualifiedName&, Document*); virtual HTMLTagStatus endTagRequirement() const { return TagStatusRequired; } @@ -35,12 +46,6 @@ public: virtual bool mapToEntry(const QualifiedName&, MappedAttributeEntry&) const; virtual void parseMappedAttribute(Attribute*); - - bool compact() const; - void setCompact(bool); - - String type() const; - void setType(const String&); }; } //namespace diff --git a/WebCore/html/HTMLVideoElement.cpp b/WebCore/html/HTMLVideoElement.cpp index dd37b69..0389b54 100644 --- a/WebCore/html/HTMLVideoElement.cpp +++ b/WebCore/html/HTMLVideoElement.cpp @@ -45,13 +45,18 @@ namespace WebCore { using namespace HTMLNames; -HTMLVideoElement::HTMLVideoElement(const QualifiedName& tagName, Document* doc) - : HTMLMediaElement(tagName, doc) +inline HTMLVideoElement::HTMLVideoElement(const QualifiedName& tagName, Document* document) + : HTMLMediaElement(tagName, document) , m_shouldDisplayPosterImage(false) { ASSERT(hasTagName(videoTag)); } +PassRefPtr<HTMLVideoElement> HTMLVideoElement::create(const QualifiedName& tagName, Document* document) +{ + return new HTMLVideoElement(tagName, document); +} + bool HTMLVideoElement::rendererIsNeeded(RenderStyle* style) { return HTMLElement::rendererIsNeeded(style); diff --git a/WebCore/html/HTMLVideoElement.h b/WebCore/html/HTMLVideoElement.h index 5480448..4b8acbb 100644 --- a/WebCore/html/HTMLVideoElement.h +++ b/WebCore/html/HTMLVideoElement.h @@ -36,7 +36,7 @@ class HTMLImageLoader; class HTMLVideoElement : public HTMLMediaElement { public: - HTMLVideoElement(const QualifiedName&, Document*); + static PassRefPtr<HTMLVideoElement> create(const QualifiedName&, Document*); unsigned width() const; void setWidth(unsigned); @@ -66,6 +66,8 @@ public: void paintCurrentFrameInContext(GraphicsContext*, const IntRect&); private: + HTMLVideoElement(const QualifiedName&, Document*); + virtual int tagPriority() const { return 5; } virtual bool rendererIsNeeded(RenderStyle*); #if !ENABLE(PLUGIN_PROXY_FOR_VIDEO) diff --git a/WebCore/html/HTMLViewSourceDocument.cpp b/WebCore/html/HTMLViewSourceDocument.cpp index 0173715..196c67e 100644 --- a/WebCore/html/HTMLViewSourceDocument.cpp +++ b/WebCore/html/HTMLViewSourceDocument.cpp @@ -1,5 +1,5 @@ /* - * Copyright (C) 2006, 2008, 2009 Apple Inc. All rights reserved. + * Copyright (C) 2006, 2008, 2009, 2010 Apple Inc. All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions @@ -68,26 +68,26 @@ Tokenizer* HTMLViewSourceDocument::createTokenizer() void HTMLViewSourceDocument::createContainingTable() { - RefPtr<HTMLHtmlElement> html = new HTMLHtmlElement(htmlTag, this); + RefPtr<HTMLHtmlElement> html = HTMLHtmlElement::create(this); addChild(html); html->attach(); - RefPtr<HTMLBodyElement> body = new HTMLBodyElement(bodyTag, this); + RefPtr<HTMLBodyElement> body = HTMLBodyElement::create(this); html->addChild(body); body->attach(); // 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<HTMLDivElement> div = HTMLDivElement::create(this); RefPtr<NamedNodeMap> attrs = NamedNodeMap::create(); attrs->addAttribute(Attribute::createMapped(classAttr, "webkit-line-gutter-backdrop")); div->setAttributeMap(attrs.release()); body->addChild(div); div->attach(); - RefPtr<HTMLTableElement> table = new HTMLTableElement(tableTag, this); + RefPtr<HTMLTableElement> table = HTMLTableElement::create(this); body->addChild(table); table->attach(); - m_tbody = new HTMLTableSectionElement(tbodyTag, this); + m_tbody = HTMLTableSectionElement::create(tbodyTag, this); table->addChild(m_tbody); m_tbody->attach(); m_current = m_tbody; @@ -222,12 +222,12 @@ PassRefPtr<Element> HTMLViewSourceDocument::addSpanWithClassName(const String& c void HTMLViewSourceDocument::addLine(const String& className) { // Create a table row. - RefPtr<HTMLTableRowElement> trow = new HTMLTableRowElement(trTag, this); + RefPtr<HTMLTableRowElement> trow = HTMLTableRowElement::create(this); m_tbody->addChild(trow); trow->attach(); // 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<HTMLTableCellElement> td = HTMLTableCellElement::create(tdTag, this); RefPtr<NamedNodeMap> attrs = NamedNodeMap::create(); attrs->addAttribute(Attribute::createMapped(classAttr, "webkit-line-number")); td->setAttributeMap(attrs.release()); @@ -235,7 +235,7 @@ void HTMLViewSourceDocument::addLine(const String& className) td->attach(); // Create a second cell for the line contents - td = new HTMLTableCellElement(tdTag, this); + td = HTMLTableCellElement::create(tdTag, this); attrs = NamedNodeMap::create(); attrs->addAttribute(Attribute::createMapped(classAttr, "webkit-line-content")); td->setAttributeMap(attrs.release()); diff --git a/WebCore/html/LabelsNodeList.cpp b/WebCore/html/LabelsNodeList.cpp new file mode 100644 index 0000000..f2bda17 --- /dev/null +++ b/WebCore/html/LabelsNodeList.cpp @@ -0,0 +1,50 @@ +/** + * Copyright (C) 1999 Lars Knoll (knoll@kde.org) + * (C) 1999 Antti Koivisto (koivisto@kde.org) + * (C) 2001 Dirk Mueller (mueller@kde.org) + * Copyright (C) 2004, 2007, 2008 Apple Inc. All rights reserved. + * Copyright (C) 2010 Nokia Inc. All rights reserved. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public License + * along with this library; see the file COPYING.LIB. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA. + */ + +#include "config.h" +#include "LabelsNodeList.h" + +#include "Element.h" +#include "HTMLLabelElement.h" +#include "HTMLNames.h" + +namespace WebCore { + +using namespace HTMLNames; + +LabelsNodeList::LabelsNodeList(PassRefPtr<Node> forNode ) + : DynamicNodeList(forNode->document()) , m_forNode(forNode) +{ +} + +LabelsNodeList::~LabelsNodeList() +{ + m_forNode->removeCachedLabelsNodeList(this); +} + +bool LabelsNodeList::nodeMatches(Element* testNode) const +{ + return testNode->hasTagName(labelTag) && static_cast<HTMLLabelElement*>(testNode)->control() == m_forNode; +} + +} // namespace WebCore diff --git a/WebCore/html/LabelsNodeList.h b/WebCore/html/LabelsNodeList.h new file mode 100644 index 0000000..c22a532 --- /dev/null +++ b/WebCore/html/LabelsNodeList.h @@ -0,0 +1,52 @@ +/* + * Copyright (C) 1999 Lars Knoll (knoll@kde.org) + * (C) 1999 Antti Koivisto (koivisto@kde.org) + * (C) 2001 Dirk Mueller (mueller@kde.org) + * Copyright (C) 2004, 2007 Apple Inc. All rights reserved. + * Copyright (C) 2010 Nokia Inc. All rights reserved. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public License + * along with this library; see the file COPYING.LIB. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA. + * + */ + +#ifndef LabelsNodeList_h +#define LabelsNodeList_h + +#include "DynamicNodeList.h" +#include <wtf/PassRefPtr.h> + +namespace WebCore { + +class LabelsNodeList : public DynamicNodeList { +public: + static PassRefPtr<LabelsNodeList> create(PassRefPtr<Node> forNode) + { + return adoptRef(new LabelsNodeList(forNode)); + } + ~LabelsNodeList(); + +protected: + LabelsNodeList(PassRefPtr<Node> forNode); + + virtual bool nodeMatches(Element*) const; + +private: + RefPtr<Node> m_forNode; +}; + +} // namespace WebCore + +#endif // LabelsNodeList_h diff --git a/WebCore/html/canvas/WebGLFramebuffer.cpp b/WebCore/html/canvas/WebGLFramebuffer.cpp index 614437b..c783553 100644 --- a/WebCore/html/canvas/WebGLFramebuffer.cpp +++ b/WebCore/html/canvas/WebGLFramebuffer.cpp @@ -39,26 +39,52 @@ PassRefPtr<WebGLFramebuffer> WebGLFramebuffer::create(WebGLRenderingContext* ctx WebGLFramebuffer::WebGLFramebuffer(WebGLRenderingContext* ctx) : CanvasObject(ctx) - , m_isDepthAttached(false) - , m_isStencilAttached(false) - , m_isDepthStencilAttached(false) + , m_colorAttachment(0) + , m_depthAttachment(0) + , m_stencilAttachment(0) + , m_depthStencilAttachment(0) { setObject(context()->graphicsContext3D()->createFramebuffer()); } -void WebGLFramebuffer::setIsAttached(unsigned long attachment, bool isAttached) +void WebGLFramebuffer::setAttachment(unsigned long attachment, CanvasObject* attachedObject) { + if (!object()) + return; + if (attachedObject && !attachedObject->object()) + attachedObject = 0; switch (attachment) { + case GraphicsContext3D::COLOR_ATTACHMENT0: + m_colorAttachment = attachedObject; + break; case GraphicsContext3D::DEPTH_ATTACHMENT: - m_isDepthAttached = isAttached; + m_depthAttachment = attachedObject; break; case GraphicsContext3D::STENCIL_ATTACHMENT: - m_isStencilAttached = isAttached; + m_stencilAttachment = attachedObject; break; case GraphicsContext3D::DEPTH_STENCIL_ATTACHMENT: - m_isDepthStencilAttached = isAttached; + m_depthStencilAttachment = attachedObject; break; + default: + return; } + initializeRenderbuffers(); +} + +void WebGLFramebuffer::onBind() +{ + initializeRenderbuffers(); +} + +void WebGLFramebuffer::onAttachedObjectChange(CanvasObject* object) +{ + // Currently object == 0 is not considered, but this might change if the + // lifespan of CanvasObject changes. + if (object + && (object == m_colorAttachment || object == m_depthAttachment + || object == m_stencilAttachment || object == m_depthStencilAttachment)) + initializeRenderbuffers(); } void WebGLFramebuffer::_deleteObject(Platform3DObject object) @@ -66,6 +92,115 @@ void WebGLFramebuffer::_deleteObject(Platform3DObject object) context()->graphicsContext3D()->deleteFramebuffer(object); } +bool WebGLFramebuffer::isUninitialized(CanvasObject* attachedObject) +{ + if (attachedObject && attachedObject->object() && attachedObject->isRenderbuffer() + && !(reinterpret_cast<WebGLRenderbuffer*>(attachedObject))->isInitialized()) + return true; + return false; +} + +void WebGLFramebuffer::setInitialized(CanvasObject* attachedObject) +{ + if (attachedObject && attachedObject->object() && attachedObject->isRenderbuffer()) + (reinterpret_cast<WebGLRenderbuffer*>(attachedObject))->setInitialized(); +} + +void WebGLFramebuffer::initializeRenderbuffers() +{ + if (!object()) + return; + bool initColor = false, initDepth = false, initStencil = false; + unsigned long mask = 0; + if (isUninitialized(m_colorAttachment)) { + initColor = true; + mask |= GraphicsContext3D::COLOR_BUFFER_BIT; + } + if (isUninitialized(m_depthAttachment)) { + initDepth = true; + mask |= GraphicsContext3D::DEPTH_BUFFER_BIT; + } + if (isUninitialized(m_stencilAttachment)) { + initStencil = true; + mask |= GraphicsContext3D::STENCIL_BUFFER_BIT; + } + if (isUninitialized(m_depthStencilAttachment)) { + initDepth = true; + initStencil = true; + mask |= (GraphicsContext3D::DEPTH_BUFFER_BIT | GraphicsContext3D::STENCIL_BUFFER_BIT); + } + if (!initColor && !initDepth && !initStencil) + return; + + // We only clear un-initialized renderbuffers when they are ready to be + // read, i.e., when the framebuffer is complete. + GraphicsContext3D* g3d = context()->graphicsContext3D(); + if (g3d->checkFramebufferStatus(GraphicsContext3D::FRAMEBUFFER) != GraphicsContext3D::FRAMEBUFFER_COMPLETE) + return; + + float colorClearValue[] = {0, 0, 0, 0}, depthClearValue = 0; + int stencilClearValue = 0; + unsigned char colorMask[] = {1, 1, 1, 1}, depthMask = 1, stencilMask = 1; + bool isScissorEnabled = false; + bool isDitherEnabled = false; + if (initColor) { + g3d->getFloatv(GraphicsContext3D::COLOR_CLEAR_VALUE, colorClearValue); + g3d->getBooleanv(GraphicsContext3D::COLOR_WRITEMASK, colorMask); + g3d->clearColor(0, 0, 0, 0); + g3d->colorMask(true, true, true, true); + } + if (initDepth) { + g3d->getFloatv(GraphicsContext3D::DEPTH_CLEAR_VALUE, &depthClearValue); + g3d->getBooleanv(GraphicsContext3D::DEPTH_WRITEMASK, &depthMask); + g3d->clearDepth(0); + g3d->depthMask(true); + } + if (initStencil) { + g3d->getIntegerv(GraphicsContext3D::STENCIL_CLEAR_VALUE, &stencilClearValue); + g3d->getBooleanv(GraphicsContext3D::STENCIL_WRITEMASK, &stencilMask); + g3d->clearStencil(0); + g3d->stencilMask(true); + } + isScissorEnabled = g3d->isEnabled(GraphicsContext3D::SCISSOR_TEST); + g3d->disable(GraphicsContext3D::SCISSOR_TEST); + isDitherEnabled = g3d->isEnabled(GraphicsContext3D::DITHER); + g3d->disable(GraphicsContext3D::DITHER); + + g3d->clear(mask); + + if (initColor) { + g3d->clearColor(colorClearValue[0], colorClearValue[1], colorClearValue[2], colorClearValue[3]); + g3d->colorMask(colorMask[0], colorMask[1], colorMask[2], colorMask[3]); + } + if (initDepth) { + g3d->clearDepth(depthClearValue); + g3d->depthMask(depthMask); + } + if (initStencil) { + g3d->clearStencil(stencilClearValue); + g3d->stencilMask(stencilMask); + } + if (isScissorEnabled) + g3d->enable(GraphicsContext3D::SCISSOR_TEST); + else + g3d->disable(GraphicsContext3D::SCISSOR_TEST); + if (isDitherEnabled) + g3d->enable(GraphicsContext3D::DITHER); + else + g3d->disable(GraphicsContext3D::DITHER); + + if (initColor) + setInitialized(m_colorAttachment); + if (initDepth && initStencil && m_depthStencilAttachment) + setInitialized(m_depthStencilAttachment); + else { + if (initDepth) + setInitialized(m_depthAttachment); + if (initStencil) + setInitialized(m_stencilAttachment); + } +} + } #endif // ENABLE(3D_CANVAS) diff --git a/WebCore/html/canvas/WebGLFramebuffer.h b/WebCore/html/canvas/WebGLFramebuffer.h index 71e5a27..93ab97c 100644 --- a/WebCore/html/canvas/WebGLFramebuffer.h +++ b/WebCore/html/canvas/WebGLFramebuffer.h @@ -32,18 +32,30 @@ #include <wtf/RefCounted.h> namespace WebCore { - + class WebGLFramebuffer : public CanvasObject { public: virtual ~WebGLFramebuffer() { deleteObject(); } static PassRefPtr<WebGLFramebuffer> create(WebGLRenderingContext*); - - void setIsAttached(unsigned long attachment, bool isAttached); - bool isDepthAttached() const { return m_isDepthAttached; } - bool isStencilAttached() const { return m_isStencilAttached; } - bool isDepthStencilAttached() const { return m_isDepthStencilAttached; } + bool isDepthAttached() const { return (m_depthAttachment && m_depthAttachment->object()); } + bool isStencilAttached() const { return (m_stencilAttachment && m_stencilAttachment->object()); } + bool isDepthStencilAttached() const { return (m_depthStencilAttachment && m_depthStencilAttachment->object()); } + + void setAttachment(unsigned long, CanvasObject*); + + // This function is called right after a framebuffer is bound. + // Because renderbuffers and textures attached to the framebuffer might + // have changed and the framebuffer might have become complete when it + // isn't bound, so we need to clear un-initialized renderbuffers. + void onBind(); + + // When a texture or a renderbuffer changes, we need to check the + // current bound framebuffer; if the newly changed object is attached + // to the framebuffer and the framebuffer becomes complete, we need to + // clear un-initialized renderbuffers. + void onAttachedObjectChange(CanvasObject*); protected: WebGLFramebuffer(WebGLRenderingContext*); @@ -53,9 +65,16 @@ namespace WebCore { private: virtual bool isFramebuffer() const { return true; } - bool m_isDepthAttached; - bool m_isStencilAttached; - bool m_isDepthStencilAttached; + bool isUninitialized(CanvasObject*); + void setInitialized(CanvasObject*); + void initializeRenderbuffers(); + + // These objects are kept alive by the global table in + // WebGLRenderingContext. + CanvasObject* m_colorAttachment; + CanvasObject* m_depthAttachment; + CanvasObject* m_stencilAttachment; + CanvasObject* m_depthStencilAttachment; }; } // namespace WebCore diff --git a/WebCore/html/canvas/WebGLRenderbuffer.cpp b/WebCore/html/canvas/WebGLRenderbuffer.cpp index 0ac9c7e..8d23b33 100644 --- a/WebCore/html/canvas/WebGLRenderbuffer.cpp +++ b/WebCore/html/canvas/WebGLRenderbuffer.cpp @@ -40,6 +40,7 @@ PassRefPtr<WebGLRenderbuffer> WebGLRenderbuffer::create(WebGLRenderingContext* c WebGLRenderbuffer::WebGLRenderbuffer(WebGLRenderingContext* ctx) : CanvasObject(ctx) , m_internalformat(GraphicsContext3D::RGBA4) + , m_initialized(false) { setObject(context()->graphicsContext3D()->createRenderbuffer()); } diff --git a/WebCore/html/canvas/WebGLRenderbuffer.h b/WebCore/html/canvas/WebGLRenderbuffer.h index e399012..4b6fc3e 100644 --- a/WebCore/html/canvas/WebGLRenderbuffer.h +++ b/WebCore/html/canvas/WebGLRenderbuffer.h @@ -42,6 +42,9 @@ namespace WebCore { void setInternalformat(unsigned long internalformat) { m_internalformat = internalformat; } unsigned long getInternalformat() const { return m_internalformat; } + bool isInitialized() const { return m_initialized; } + void setInitialized() { m_initialized = true; } + protected: WebGLRenderbuffer(WebGLRenderingContext*); @@ -51,6 +54,7 @@ namespace WebCore { virtual bool isRenderbuffer() const { return true; } unsigned long m_internalformat; + bool m_initialized; }; } // namespace WebCore diff --git a/WebCore/html/canvas/WebGLRenderingContext.cpp b/WebCore/html/canvas/WebGLRenderingContext.cpp index fe192a6..ca1d375 100644 --- a/WebCore/html/canvas/WebGLRenderingContext.cpp +++ b/WebCore/html/canvas/WebGLRenderingContext.cpp @@ -238,6 +238,8 @@ void WebGLRenderingContext::bindFramebuffer(unsigned long target, WebGLFramebuff } m_framebufferBinding = buffer; m_context->bindFramebuffer(target, buffer); + if (m_framebufferBinding) + m_framebufferBinding->onBind(); cleanupAfterGraphicsCall(false); } @@ -431,29 +433,31 @@ void WebGLRenderingContext::compileShader(WebGLShader* shader, ExceptionCode& ec void WebGLRenderingContext::copyTexImage2D(unsigned long target, long level, unsigned long internalformat, long x, long y, unsigned long width, unsigned long height, long border) { + RefPtr<WebGLTexture> tex = 0; + switch (target) { + case GraphicsContext3D::TEXTURE_2D: + tex = m_textureUnits[m_activeTextureUnit].m_texture2DBinding; + break; + case GraphicsContext3D::TEXTURE_CUBE_MAP_POSITIVE_X: + case GraphicsContext3D::TEXTURE_CUBE_MAP_NEGATIVE_X: + case GraphicsContext3D::TEXTURE_CUBE_MAP_POSITIVE_Y: + case GraphicsContext3D::TEXTURE_CUBE_MAP_NEGATIVE_Y: + case GraphicsContext3D::TEXTURE_CUBE_MAP_POSITIVE_Z: + case GraphicsContext3D::TEXTURE_CUBE_MAP_NEGATIVE_Z: + tex = m_textureUnits[m_activeTextureUnit].m_textureCubeMapBinding; + break; + } if (!isGLES2Compliant()) { if (level && WebGLTexture::isNPOT(width, height)) { m_context->synthesizeGLError(GraphicsContext3D::INVALID_VALUE); return; } - RefPtr<WebGLTexture> tex = 0; - switch (target) { - case GraphicsContext3D::TEXTURE_2D: - tex = m_textureUnits[m_activeTextureUnit].m_texture2DBinding; - break; - case GraphicsContext3D::TEXTURE_CUBE_MAP_POSITIVE_X: - case GraphicsContext3D::TEXTURE_CUBE_MAP_NEGATIVE_X: - case GraphicsContext3D::TEXTURE_CUBE_MAP_POSITIVE_Y: - case GraphicsContext3D::TEXTURE_CUBE_MAP_NEGATIVE_Y: - case GraphicsContext3D::TEXTURE_CUBE_MAP_POSITIVE_Z: - case GraphicsContext3D::TEXTURE_CUBE_MAP_NEGATIVE_Z: - tex = m_textureUnits[m_activeTextureUnit].m_textureCubeMapBinding; - break; - } if (tex && !level) // only for level 0 tex->setSize(target, width, height); } m_context->copyTexImage2D(target, level, internalformat, x, y, width, height, border); + if (m_framebufferBinding && tex) + m_framebufferBinding->onAttachedObjectChange(tex.get()); cleanupAfterGraphicsCall(false); } @@ -547,6 +551,8 @@ void WebGLRenderingContext::deleteRenderbuffer(WebGLRenderbuffer* renderbuffer) return; renderbuffer->deleteObject(); + if (m_framebufferBinding) + m_framebufferBinding->onAttachedObjectChange(renderbuffer); } void WebGLRenderingContext::deleteShader(WebGLShader* shader) @@ -563,6 +569,8 @@ void WebGLRenderingContext::deleteTexture(WebGLTexture* texture) return; texture->deleteObject(); + if (m_framebufferBinding) + m_framebufferBinding->onAttachedObjectChange(texture); } void WebGLRenderingContext::depthFunc(unsigned long func) @@ -845,7 +853,6 @@ void WebGLRenderingContext::framebufferRenderbuffer(unsigned long target, unsign } if (buffer && buffer->object()) { bool isConflicted = false; - bool isDepthOrStencil = true; switch (attachment) { case GraphicsContext3D::DEPTH_ATTACHMENT: if (m_framebufferBinding->isDepthStencilAttached() || m_framebufferBinding->isStencilAttached()) @@ -865,24 +872,14 @@ void WebGLRenderingContext::framebufferRenderbuffer(unsigned long target, unsign if (buffer->getInternalformat() != GraphicsContext3D::DEPTH_STENCIL) isConflicted = true; break; - default: - isDepthOrStencil = false; } if (isConflicted) { m_context->synthesizeGLError(GraphicsContext3D::INVALID_OPERATION); return; } - if (isDepthOrStencil) - m_framebufferBinding->setIsAttached(attachment, true); - } else { // Detach - switch (attachment) { - case GraphicsContext3D::DEPTH_ATTACHMENT: - case GraphicsContext3D::STENCIL_ATTACHMENT: - case GraphicsContext3D::DEPTH_STENCIL_ATTACHMENT: - m_framebufferBinding->setIsAttached(attachment, false); - } } m_context->framebufferRenderbuffer(target, attachment, renderbuffertarget, buffer); + m_framebufferBinding->setAttachment(attachment, buffer); cleanupAfterGraphicsCall(false); } @@ -901,6 +898,7 @@ void WebGLRenderingContext::framebufferTexture2D(unsigned long target, unsigned return; } m_context->framebufferTexture2D(target, attachment, textarget, texture, level); + m_framebufferBinding->setAttachment(attachment, texture); cleanupAfterGraphicsCall(false); } @@ -1734,8 +1732,11 @@ void WebGLRenderingContext::renderbufferStorage(unsigned long target, unsigned l case GraphicsContext3D::STENCIL_INDEX8: case GraphicsContext3D::DEPTH_STENCIL: m_context->renderbufferStorage(target, internalformat, width, height); - if (m_renderbufferBinding) + if (m_renderbufferBinding) { m_renderbufferBinding->setInternalformat(internalformat); + if (m_framebufferBinding) + m_framebufferBinding->onAttachedObjectChange(m_renderbufferBinding.get()); + } cleanupAfterGraphicsCall(false); break; default: @@ -1804,6 +1805,20 @@ void WebGLRenderingContext::texImage2DBase(unsigned target, unsigned level, unsi unsigned width, unsigned height, unsigned border, unsigned format, unsigned type, void* pixels, ExceptionCode& ec) { + RefPtr<WebGLTexture> tex = 0; + switch (target) { + case GraphicsContext3D::TEXTURE_2D: + tex = m_textureUnits[m_activeTextureUnit].m_texture2DBinding; + break; + case GraphicsContext3D::TEXTURE_CUBE_MAP_POSITIVE_X: + case GraphicsContext3D::TEXTURE_CUBE_MAP_NEGATIVE_X: + case GraphicsContext3D::TEXTURE_CUBE_MAP_POSITIVE_Y: + case GraphicsContext3D::TEXTURE_CUBE_MAP_NEGATIVE_Y: + case GraphicsContext3D::TEXTURE_CUBE_MAP_POSITIVE_Z: + case GraphicsContext3D::TEXTURE_CUBE_MAP_NEGATIVE_Z: + tex = m_textureUnits[m_activeTextureUnit].m_textureCubeMapBinding; + break; + } // FIXME: For now we ignore any errors returned ec = 0; if (!isGLES2Compliant()) { @@ -1811,25 +1826,13 @@ void WebGLRenderingContext::texImage2DBase(unsigned target, unsigned level, unsi m_context->synthesizeGLError(GraphicsContext3D::INVALID_VALUE); return; } - RefPtr<WebGLTexture> tex = 0; - switch (target) { - case GraphicsContext3D::TEXTURE_2D: - tex = m_textureUnits[m_activeTextureUnit].m_texture2DBinding; - break; - case GraphicsContext3D::TEXTURE_CUBE_MAP_POSITIVE_X: - case GraphicsContext3D::TEXTURE_CUBE_MAP_NEGATIVE_X: - case GraphicsContext3D::TEXTURE_CUBE_MAP_POSITIVE_Y: - case GraphicsContext3D::TEXTURE_CUBE_MAP_NEGATIVE_Y: - case GraphicsContext3D::TEXTURE_CUBE_MAP_POSITIVE_Z: - case GraphicsContext3D::TEXTURE_CUBE_MAP_NEGATIVE_Z: - tex = m_textureUnits[m_activeTextureUnit].m_textureCubeMapBinding; - break; - } if (tex && !level) // only for level 0 tex->setSize(target, width, height); } m_context->texImage2D(target, level, internalformat, width, height, border, format, type, pixels); + if (m_framebufferBinding && tex) + m_framebufferBinding->onAttachedObjectChange(tex.get()); cleanupAfterGraphicsCall(false); } |