Commit ce8ee2a4 authored by hyatt@apple.com's avatar hyatt@apple.com

https://bugs.webkit.org/show_bug.cgi?id=44788, implement HTML5-compliant doctype switching.

Reviewed by Simon Fraser.

WebCore: 

Rename the various modes to match the HTML5 specification:
    ParseMode -> CompatibilityMode
    CompatMode -> QuirksMode
    AlmostStrictMode -> LimitedQuirksMode
    StrictMode -> NoQuirksMode
            
Remove the htmlHacks() accessor from RenderStyle and make rendering code just go to the document
instead.  This makes switching modes avoid forcing all RenderStyles to detect as changed.
        
Clean up user stylesheets to minimize style recalculation when the mode is switched.
        
Fix bugs with the propagation of correct modes in the HTML5 parser.  Make sure the
dummy document created for fragment parsing properly inherits the real document's CompatibilityMode.
Make sure the tree builder properly changes the insertion mode to "BeforeHTML" after handling
a doctype token.
        
determineParseMode -> setCompatibilityModeFromDoctype, and it now implements the HTML5 algorithm
precisely.
        
* WebCore.exp.in:
* css/CSSStyleSelector.cpp:
(WebCore::CSSStyleSelector::styleForDocument):
(WebCore::CSSStyleSelector::applyProperty):
(WebCore::CSSStyleSelector::fontSizeForKeyword):
* dom/ClassNodeList.cpp:
(WebCore::ClassNodeList::ClassNodeList):
* dom/DecodedDataDocumentParser.cpp:
(WebCore::DecodedDataDocumentParser::appendBytes):
* dom/Document.cpp:
(WebCore::Document::Document):
(WebCore::Document::setCompatibilityMode):
(WebCore::Document::setDocType):
(WebCore::Document::unscheduleStyleRecalc):
(WebCore::Document::recalcStyle):
(WebCore::Document::updateStyleIfNeeded):
(WebCore::Document::createStyleSelector):
(WebCore::Document::implicitOpen):
(WebCore::Document::pageUserSheet):
(WebCore::Document::clearPageUserSheet):
(WebCore::Document::updatePageUserSheet):
(WebCore::Document::pageGroupUserSheets):
(WebCore::Document::clearPageGroupUserSheets):
(WebCore::Document::updatePageGroupUserSheets):
(WebCore::Document::findAnchor):
* dom/Document.h:
(WebCore::Document::):
(WebCore::Document::setCompatibilityModeFromDoctype):
(WebCore::Document::lockCompatibilityMode):
(WebCore::Document::compatibilityMode):
(WebCore::Document::inQuirksMode):
(WebCore::Document::inLimitedQuirksMode):
(WebCore::Document::inNoQuirksMode):
* dom/Element.cpp:
(WebCore::Element::clientWidth):
(WebCore::Element::clientHeight):
(WebCore::Element::webkitMatchesSelector):
* dom/NamedNodeMap.cpp:
(WebCore::NamedNodeMap::setClass):
* dom/Node.cpp:
(WebCore::Node::querySelector):
(WebCore::Node::querySelectorAll):
* dom/OptionElement.cpp:
(WebCore::OptionElement::collectOptionLabelOrText):
* dom/SelectorNodeList.cpp:
(WebCore::createSelectorNodeList):
* dom/StyleElement.cpp:
(WebCore::StyleElement::createSheet):
* dom/StyledElement.cpp:
(WebCore::StyledElement::createInlineStyleDecl):
(WebCore::StyledElement::parseMappedAttribute):
* editing/ReplaceSelectionCommand.cpp:
(WebCore::ReplaceSelectionCommand::shouldRemoveEndBR):
* html/HTMLBodyElement.cpp:
(WebCore::HTMLBodyElement::createLinkDecl):
* html/HTMLCanvasElement.cpp:
(WebCore::HTMLCanvasElement::getContext):
* html/HTMLConstructionSite.cpp:
(WebCore::HTMLConstructionSite::insertDoctype):
* html/HTMLDocument.cpp:
(WebCore::HTMLDocument::HTMLDocument):
(WebCore::HTMLDocument::compatMode):
(WebCore::HTMLDocument::setCompatibilityModeFromDoctype):
* html/HTMLDocument.h:
* html/HTMLLinkElement.cpp:
(WebCore::HTMLLinkElement::setCSSStyleSheet):
* html/HTMLTreeBuilder.cpp:
(WebCore::HTMLTreeBuilder::HTMLTreeBuilder):
(WebCore::HTMLTreeBuilder::FragmentParsingContext::FragmentParsingContext):
(WebCore::HTMLTreeBuilder::processDoctypeToken):
(WebCore::HTMLTreeBuilder::processStartTagForInBody):
(WebCore::HTMLTreeBuilder::defaultForInitial):
* html/HTMLViewSourceDocument.cpp:
(WebCore::HTMLViewSourceDocument::HTMLViewSourceDocument):
* loader/DocumentWriter.cpp:
(WebCore::DocumentWriter::replaceDocument):
(WebCore::DocumentWriter::reportDataReceived):
* loader/DocumentWriter.h:
* loader/ImageDocument.cpp:
(WebCore::ImageDocument::ImageDocument):
* loader/MediaDocument.cpp:
(WebCore::MediaDocument::MediaDocument):
* loader/PluginDocument.cpp:
(WebCore::PluginDocument::PluginDocument):
* loader/SinkDocument.cpp:
(WebCore::SinkDocument::SinkDocument):
* loader/TextDocument.cpp:
(WebCore::TextDocument::TextDocument):
* page/Page.cpp:
(WebCore::Page::userStyleSheetLocationChanged):
* page/PageGroup.cpp:
(WebCore::PageGroup::resetUserStyleCacheInAllFrames):
* page/Settings.cpp:
(WebCore::Settings::Settings):
(WebCore::Settings::setEnforceCSSMIMETypeInNoQuirksMode):
* page/Settings.h:
(WebCore::Settings::enforceCSSMIMETypeInNoQuirksMode):
* rendering/AutoTableLayout.cpp:
(WebCore::AutoTableLayout::recalcColumn):
* rendering/FixedTableLayout.cpp:
(WebCore::FixedTableLayout::calcPrefWidths):
* rendering/InlineFlowBox.cpp:
(WebCore::InlineFlowBox::paintBoxDecorations):
(WebCore::InlineFlowBox::paintMask):
(WebCore::InlineFlowBox::paintTextDecorations):
* rendering/InlineTextBox.cpp:
(WebCore::InlineTextBox::paint):
* rendering/RenderBlock.cpp:
(WebCore::RenderBlock::isSelfCollapsingBlock):
(WebCore::RenderBlock::collapseMargins):
(WebCore::RenderBlock::handleBottomOfBlock):
(WebCore::RenderBlock::calcInlinePrefWidths):
(WebCore::RenderBlock::calcBlockPrefWidths):
* rendering/RenderBlockLineLayout.cpp:
(WebCore::createInlineBoxForRenderer):
(WebCore::RenderBlock::findNextLineBreak):
* rendering/RenderBox.cpp:
(WebCore::RenderBox::calcPercentageHeight):
(WebCore::RenderBox::calcAbsoluteHorizontal):
(WebCore::RenderBox::calcAbsoluteHorizontalReplaced):
* rendering/RenderBox.h:
(WebCore::RenderBox::stretchesToViewHeight):
* rendering/RenderListItem.cpp:
(WebCore::getParentOfFirstLineBox):
* rendering/RenderTable.cpp:
(WebCore::RenderTable::layout):
* rendering/RenderTableSection.cpp:
(WebCore::RenderTableSection::calcRowHeight):
* rendering/RootInlineBox.cpp:
(WebCore::RootInlineBox::verticallyAlignBoxes):
* rendering/style/RenderStyle.cpp:
(WebCore::RenderStyle::diff):
* rendering/style/RenderStyle.h:
(WebCore::):
(WebCore::InheritedFlags::setBitDefaults):

WebKit/mac: 

Rename the various modes to match the HTML5 specification:
    ParseMode -> CompatibilityMode
    CompatMode -> QuirksMode
    AlmostStrictMode -> LimitedQuirksMode
    StrictMode -> NoQuirksMode
            
Remove the htmlHacks() accessor from RenderStyle and make rendering code just go to the document
instead.  This makes switching modes avoid forcing all RenderStyles to detect as changed.
        
Clean up user stylesheets to minimize style recalculation when the mode is switched.
        
Fix bugs with the propagation of correct modes in the HTML5 parser.  Make sure the
dummy document created for fragment parsing properly inherits the real document's CompatibilityMode.
Make sure the tree builder properly changes the insertion mode to "BeforeHTML" after handling
a doctype token.
        
determineParseMode -> setCompatibilityModeFromDoctype, and it now implements the HTML5 algorithm
precisely.

* WebView/WebView.mm:
(-[WebView _preferencesChangedNotification:]):



git-svn-id: http://svn.webkit.org/repository/webkit/trunk@66247 268f45cc-cd09-0410-ab3c-d52691b4dbfc
parent 98dc4093
......@@ -15,9 +15,9 @@ ensure that document.open clears the document but does not change the document p
PASS iframeDocument is iframe.contentWindow.document
document.open should also clear the document and reset the doctype)
PASS treeAsString(iframeDocument) is "#document"
PASS iframeDocument.compatMode is "BackCompat"
document.write of "" should leave the document in quirksmode and add no content to the document
PASS iframeDocument.compatMode is "BackCompat"
PASS iframeDocument.compatMode is "CSS1Compat"
document.write of "" should leave the document in no-quirks mode and add no content to the document
PASS iframeDocument.compatMode is "CSS1Compat"
PASS treeAsString(iframeDocument) is "#document"
document.write calls can change the doctype until an <html> is created
PASS iframeDocument.compatMode is "CSS1Compat"
......
......@@ -49,11 +49,11 @@ debug("ensure that document.open clears the document but does not change the doc
shouldBe("iframeDocument", "iframe.contentWindow.document");
debug("document.open should also clear the document and reset the doctype)")
shouldBeEqualToString("treeAsString(iframeDocument)", "#document");
shouldBeEqualToString("iframeDocument.compatMode", "BackCompat");
shouldBeEqualToString("iframeDocument.compatMode", "CSS1Compat");
debug("document.write of \"\" should leave the document in quirksmode and add no content to the document")
debug("document.write of \"\" should leave the document in no-quirks mode and add no content to the document")
iframeDocument.write("");
shouldBeEqualToString("iframeDocument.compatMode", "BackCompat");
shouldBeEqualToString("iframeDocument.compatMode", "CSS1Compat");
shouldBeEqualToString("treeAsString(iframeDocument)", "#document");
debug("document.write calls can change the doctype until an &lt;html> is created")
......
2010-08-27 David Hyatt <hyatt@apple.com>
Reviewed by Simon Fraser.
https://bugs.webkit.org/show_bug.cgi?id=44788, implement HTML5-compliant doctype switching.
Rename the various modes to match the HTML5 specification:
ParseMode -> CompatibilityMode
CompatMode -> QuirksMode
AlmostStrictMode -> LimitedQuirksMode
StrictMode -> NoQuirksMode
Remove the htmlHacks() accessor from RenderStyle and make rendering code just go to the document
instead. This makes switching modes avoid forcing all RenderStyles to detect as changed.
Clean up user stylesheets to minimize style recalculation when the mode is switched.
Fix bugs with the propagation of correct modes in the HTML5 parser. Make sure the
dummy document created for fragment parsing properly inherits the real document's CompatibilityMode.
Make sure the tree builder properly changes the insertion mode to "BeforeHTML" after handling
a doctype token.
determineParseMode -> setCompatibilityModeFromDoctype, and it now implements the HTML5 algorithm
precisely.
* WebCore.exp.in:
* css/CSSStyleSelector.cpp:
(WebCore::CSSStyleSelector::styleForDocument):
(WebCore::CSSStyleSelector::applyProperty):
(WebCore::CSSStyleSelector::fontSizeForKeyword):
* dom/ClassNodeList.cpp:
(WebCore::ClassNodeList::ClassNodeList):
* dom/DecodedDataDocumentParser.cpp:
(WebCore::DecodedDataDocumentParser::appendBytes):
* dom/Document.cpp:
(WebCore::Document::Document):
(WebCore::Document::setCompatibilityMode):
(WebCore::Document::setDocType):
(WebCore::Document::unscheduleStyleRecalc):
(WebCore::Document::recalcStyle):
(WebCore::Document::updateStyleIfNeeded):
(WebCore::Document::createStyleSelector):
(WebCore::Document::implicitOpen):
(WebCore::Document::pageUserSheet):
(WebCore::Document::clearPageUserSheet):
(WebCore::Document::updatePageUserSheet):
(WebCore::Document::pageGroupUserSheets):
(WebCore::Document::clearPageGroupUserSheets):
(WebCore::Document::updatePageGroupUserSheets):
(WebCore::Document::findAnchor):
* dom/Document.h:
(WebCore::Document::):
(WebCore::Document::setCompatibilityModeFromDoctype):
(WebCore::Document::lockCompatibilityMode):
(WebCore::Document::compatibilityMode):
(WebCore::Document::inQuirksMode):
(WebCore::Document::inLimitedQuirksMode):
(WebCore::Document::inNoQuirksMode):
* dom/Element.cpp:
(WebCore::Element::clientWidth):
(WebCore::Element::clientHeight):
(WebCore::Element::webkitMatchesSelector):
* dom/NamedNodeMap.cpp:
(WebCore::NamedNodeMap::setClass):
* dom/Node.cpp:
(WebCore::Node::querySelector):
(WebCore::Node::querySelectorAll):
* dom/OptionElement.cpp:
(WebCore::OptionElement::collectOptionLabelOrText):
* dom/SelectorNodeList.cpp:
(WebCore::createSelectorNodeList):
* dom/StyleElement.cpp:
(WebCore::StyleElement::createSheet):
* dom/StyledElement.cpp:
(WebCore::StyledElement::createInlineStyleDecl):
(WebCore::StyledElement::parseMappedAttribute):
* editing/ReplaceSelectionCommand.cpp:
(WebCore::ReplaceSelectionCommand::shouldRemoveEndBR):
* html/HTMLBodyElement.cpp:
(WebCore::HTMLBodyElement::createLinkDecl):
* html/HTMLCanvasElement.cpp:
(WebCore::HTMLCanvasElement::getContext):
* html/HTMLConstructionSite.cpp:
(WebCore::HTMLConstructionSite::insertDoctype):
* html/HTMLDocument.cpp:
(WebCore::HTMLDocument::HTMLDocument):
(WebCore::HTMLDocument::compatMode):
(WebCore::HTMLDocument::setCompatibilityModeFromDoctype):
* html/HTMLDocument.h:
* html/HTMLLinkElement.cpp:
(WebCore::HTMLLinkElement::setCSSStyleSheet):
* html/HTMLTreeBuilder.cpp:
(WebCore::HTMLTreeBuilder::HTMLTreeBuilder):
(WebCore::HTMLTreeBuilder::FragmentParsingContext::FragmentParsingContext):
(WebCore::HTMLTreeBuilder::processDoctypeToken):
(WebCore::HTMLTreeBuilder::processStartTagForInBody):
(WebCore::HTMLTreeBuilder::defaultForInitial):
* html/HTMLViewSourceDocument.cpp:
(WebCore::HTMLViewSourceDocument::HTMLViewSourceDocument):
* loader/DocumentWriter.cpp:
(WebCore::DocumentWriter::replaceDocument):
(WebCore::DocumentWriter::reportDataReceived):
* loader/DocumentWriter.h:
* loader/ImageDocument.cpp:
(WebCore::ImageDocument::ImageDocument):
* loader/MediaDocument.cpp:
(WebCore::MediaDocument::MediaDocument):
* loader/PluginDocument.cpp:
(WebCore::PluginDocument::PluginDocument):
* loader/SinkDocument.cpp:
(WebCore::SinkDocument::SinkDocument):
* loader/TextDocument.cpp:
(WebCore::TextDocument::TextDocument):
* page/Page.cpp:
(WebCore::Page::userStyleSheetLocationChanged):
* page/PageGroup.cpp:
(WebCore::PageGroup::resetUserStyleCacheInAllFrames):
* page/Settings.cpp:
(WebCore::Settings::Settings):
(WebCore::Settings::setEnforceCSSMIMETypeInNoQuirksMode):
* page/Settings.h:
(WebCore::Settings::enforceCSSMIMETypeInNoQuirksMode):
* rendering/AutoTableLayout.cpp:
(WebCore::AutoTableLayout::recalcColumn):
* rendering/FixedTableLayout.cpp:
(WebCore::FixedTableLayout::calcPrefWidths):
* rendering/InlineFlowBox.cpp:
(WebCore::InlineFlowBox::paintBoxDecorations):
(WebCore::InlineFlowBox::paintMask):
(WebCore::InlineFlowBox::paintTextDecorations):
* rendering/InlineTextBox.cpp:
(WebCore::InlineTextBox::paint):
* rendering/RenderBlock.cpp:
(WebCore::RenderBlock::isSelfCollapsingBlock):
(WebCore::RenderBlock::collapseMargins):
(WebCore::RenderBlock::handleBottomOfBlock):
(WebCore::RenderBlock::calcInlinePrefWidths):
(WebCore::RenderBlock::calcBlockPrefWidths):
* rendering/RenderBlockLineLayout.cpp:
(WebCore::createInlineBoxForRenderer):
(WebCore::RenderBlock::findNextLineBreak):
* rendering/RenderBox.cpp:
(WebCore::RenderBox::calcPercentageHeight):
(WebCore::RenderBox::calcAbsoluteHorizontal):
(WebCore::RenderBox::calcAbsoluteHorizontalReplaced):
* rendering/RenderBox.h:
(WebCore::RenderBox::stretchesToViewHeight):
* rendering/RenderListItem.cpp:
(WebCore::getParentOfFirstLineBox):
* rendering/RenderTable.cpp:
(WebCore::RenderTable::layout):
* rendering/RenderTableSection.cpp:
(WebCore::RenderTableSection::calcRowHeight):
* rendering/RootInlineBox.cpp:
(WebCore::RootInlineBox::verticallyAlignBoxes):
* rendering/style/RenderStyle.cpp:
(WebCore::RenderStyle::diff):
* rendering/style/RenderStyle.h:
(WebCore::):
(WebCore::InheritedFlags::setBitDefaults):
2010-08-27 Gavin Barraclough <barraclough@apple.com>
Reviewed by Oliver Hunt.
......@@ -733,7 +733,7 @@ __ZN7WebCore8Settings31setShrinksStandaloneImagesToFitEb
__ZN7WebCore8Settings32setAcceleratedCompositingEnabledEb
__ZN7WebCore8Settings32setNeedsAdobeFrameReloadingQuirkEb
__ZN7WebCore8Settings33setDownloadableBinaryFontsEnabledEb
__ZN7WebCore8Settings33setEnforceCSSMIMETypeInStrictModeEb
__ZN7WebCore8Settings35setEnforceCSSMIMETypeInNoQuirksModeEb
__ZN7WebCore8Settings34setLocalFileContentSniffingEnabledEb
__ZN7WebCore8Settings35setAllowUniversalAccessFromFileURLsEb
__ZN7WebCore8Settings35setExperimentalNotificationsEnabledEb
......
......@@ -1138,8 +1138,6 @@ PassRefPtr<RenderStyle> CSSStyleSelector::styleForDocument(Document* document)
documentStyle->setFontDescription(fontDescription);
documentStyle->font().update(0);
if (document->inCompatMode())
documentStyle->setHtmlHacks(true); // enable html specific rendering tricks
return documentStyle.release();
}
......@@ -4083,10 +4081,10 @@ void CSSStyleSelector::applyProperty(int id, CSSValue *value)
fontDescription.setKeywordSize(primitiveValue->getIdent() - CSSValueXxSmall + 1);
break;
case CSSValueLarger:
size = largerFontSize(oldSize, m_style->htmlHacks());
size = largerFontSize(oldSize, m_checker.m_document->inQuirksMode());
break;
case CSSValueSmaller:
size = smallerFontSize(oldSize, m_style->htmlHacks());
size = smallerFontSize(oldSize, m_checker.m_document->inQuirksMode());
break;
default:
return;
......@@ -6312,7 +6310,7 @@ float CSSStyleSelector::fontSizeForKeyword(Document* document, int keyword, bool
if (!settings)
return 1.0f;
bool quirksMode = document->inCompatMode();
bool quirksMode = document->inQuirksMode();
int mediumSize = fixed ? settings->defaultFixedFontSize() : settings->defaultFontSize();
if (mediumSize >= fontSizeTableMin && mediumSize <= fontSizeTableMax) {
// Look up the entry in the table.
......
......@@ -37,7 +37,7 @@ namespace WebCore {
ClassNodeList::ClassNodeList(PassRefPtr<Node> rootNode, const String& classNames)
: DynamicNodeList(rootNode)
, m_classNames(classNames, m_rootNode->document()->inCompatMode())
, m_classNames(classNames, m_rootNode->document()->inQuirksMode())
, m_originalClassNames(classNames)
{
}
......
......@@ -50,7 +50,7 @@ void DecodedDataDocumentParser::appendBytes(DocumentWriter* writer , const char*
if (decoded.isEmpty())
return;
writer->reportDataRecieved();
writer->reportDataReceived();
append(decoded);
}
......
......@@ -353,6 +353,8 @@ private:
Document::Document(Frame* frame, const KURL& url, bool isXHTML, bool isHTML)
: ContainerNode(0)
, m_compatibilityMode(NoQuirksMode)
, m_compatibilityModeLocked(false)
, m_domTreeVersion(0)
, m_styleSheets(StyleSheetList::create(this))
, m_styleRecalcTimer(this, &Document::styleRecalcTimerFired)
......@@ -424,8 +426,6 @@ Document::Document(Frame* frame, const KURL& url, bool isXHTML, bool isHTML)
m_bParsing = false;
m_wellFormed = false;
setParseMode(Strict);
m_textColor = Color::black;
m_listenerTypes = 0;
setInDocument();
......@@ -581,6 +581,20 @@ void Document::destroyAllWrapperCaches()
}
#endif
void Document::setCompatibilityMode(CompatibilityMode mode)
{
if (m_compatibilityModeLocked || mode == m_compatibilityMode)
return;
ASSERT(!documentElement() && !m_styleSheets->length());
bool wasInQuirksMode = inQuirksMode();
m_compatibilityMode = mode;
if (inQuirksMode() != wasInQuirksMode) {
// All user stylesheets have to reparse using the different mode.
clearPageUserSheet();
clearPageGroupUserSheets();
}
}
void Document::resetLinkColor()
{
m_linkColor = Color(0, 0, 238);
......@@ -599,14 +613,10 @@ void Document::resetActiveLinkColor()
void Document::setDocType(PassRefPtr<DocumentType> docType)
{
// This should never be called more than once.
// Note: This is not a public DOM method and can only be called by the parser.
ASSERT(!m_docType || !docType);
if (m_docType && docType)
return;
m_docType = docType;
if (m_docType)
m_docType->setDocument(this);
determineParseMode();
}
DOMImplementation* Document::implementation() const
......@@ -1394,6 +1404,7 @@ void Document::unscheduleStyleRecalc()
documentsThatNeedStyleRecalc->remove(this);
m_styleRecalcTimer.stop();
m_pendingStyleRecalcShouldForce = false;
}
void Document::styleRecalcTimerFired(Timer<Document>*)
......@@ -1431,6 +1442,9 @@ void Document::recalcStyle(StyleChange change)
ASSERT(!renderer() || renderArena());
if (!renderer() || !renderArena())
goto bail_out;
if (m_pendingStyleRecalcShouldForce)
change = Force;
if (change == Force) {
// style selector may set this again during recalc
......@@ -1488,9 +1502,7 @@ void Document::updateStyleIfNeeded()
if (m_frame)
m_frame->animation()->beginAnimationUpdate();
recalcStyle(m_pendingStyleRecalcShouldForce ? Force : NoChange);
m_pendingStyleRecalcShouldForce = false;
recalcStyle(NoChange);
// Tell the animation controller that updateStyleIfNeeded is finished and it can do any post-processing
if (m_frame)
......@@ -1623,7 +1635,7 @@ void Document::createStyleSelector()
if (Settings* docSettings = settings())
matchAuthorAndUserStyles = docSettings->authorAndUserStylesEnabled();
m_styleSelector.set(new CSSStyleSelector(this, m_styleSheets.get(), m_mappedElementSheet.get(), pageUserSheet(), pageGroupUserSheets(),
!inCompatMode(), matchAuthorAndUserStyles));
!inQuirksMode(), matchAuthorAndUserStyles));
}
void Document::attach()
......@@ -1846,6 +1858,8 @@ void Document::implicitOpen()
removeChildren();
setCompatibilityMode(NoQuirksMode);
m_parser = createParser();
setParsing(true);
......@@ -2222,14 +2236,23 @@ CSSStyleSheet* Document::pageUserSheet()
// Parse the sheet and cache it.
m_pageUserSheet = CSSStyleSheet::createInline(this, settings()->userStyleSheetLocation());
m_pageUserSheet->setIsUserStyleSheet(true);
m_pageUserSheet->parseString(userSheetText, !inCompatMode());
m_pageUserSheet->parseString(userSheetText, !inQuirksMode());
return m_pageUserSheet.get();
}
void Document::clearPageUserSheet()
{
m_pageUserSheet = 0;
styleSelectorChanged(DeferRecalcStyle);
if (m_pageUserSheet) {
m_pageUserSheet = 0;
styleSelectorChanged(DeferRecalcStyle);
}
}
void Document::updatePageUserSheet()
{
clearPageUserSheet();
if (pageUserSheet())
styleSelectorChanged(RecalcStyleImmediately);
}
const Vector<RefPtr<CSSStyleSheet> >* Document::pageGroupUserSheets() const
......@@ -2259,7 +2282,7 @@ const Vector<RefPtr<CSSStyleSheet> >* Document::pageGroupUserSheets() const
continue;
RefPtr<CSSStyleSheet> parsedSheet = CSSStyleSheet::createInline(const_cast<Document*>(this), sheet->url());
parsedSheet->setIsUserStyleSheet(sheet->level() == UserStyleSheet::UserLevel);
parsedSheet->parseString(sheet->source(), !inCompatMode());
parsedSheet->parseString(sheet->source(), !inQuirksMode());
if (!m_pageGroupUserSheets)
m_pageGroupUserSheets.set(new Vector<RefPtr<CSSStyleSheet> >);
m_pageGroupUserSheets->append(parsedSheet.release());
......@@ -2271,9 +2294,18 @@ const Vector<RefPtr<CSSStyleSheet> >* Document::pageGroupUserSheets() const
void Document::clearPageGroupUserSheets()
{
m_pageGroupUserSheets.clear();
m_pageGroupUserSheetCacheValid = false;
styleSelectorChanged(DeferRecalcStyle);
if (m_pageGroupUserSheets && m_pageGroupUserSheets->size()) {
m_pageGroupUserSheets->clear();
styleSelectorChanged(DeferRecalcStyle);
}
}
void Document::updatePageGroupUserSheets()
{
clearPageGroupUserSheets();
if (pageGroupUserSheets() && pageGroupUserSheets()->size())
styleSelectorChanged(RecalcStyleImmediately);
}
CSSStyleSheet* Document::elementSheet()
......@@ -4517,7 +4549,7 @@ Element* Document::findAnchor(const String& name)
for (Node* node = this; node; node = node->traverseNextNode()) {
if (node->hasTagName(aTag)) {
HTMLAnchorElement* anchor = static_cast<HTMLAnchorElement*>(node);
if (inCompatMode()) {
if (inQuirksMode()) {
// Quirks mode, case insensitive comparison of names.
if (equalIgnoringCase(anchor->name(), name))
return anchor;
......
......@@ -553,9 +553,11 @@ public:
CSSStyleSheet* pageUserSheet();
void clearPageUserSheet();
void updatePageUserSheet();
const Vector<RefPtr<CSSStyleSheet> >* pageGroupUserSheets() const;
void clearPageGroupUserSheets();
void updatePageGroupUserSheets();
CSSStyleSheet* elementSheet();
CSSStyleSheet* mappedElementSheet();
......@@ -572,14 +574,16 @@ public:
bool paginated() const { return printing() || paginatedForScreen(); }
enum ParseMode { Compat, AlmostStrict, Strict };
enum CompatibilityMode { QuirksMode, LimitedQuirksMode, NoQuirksMode };
void setParseMode(ParseMode m) { m_parseMode = m; }
ParseMode parseMode() const { return m_parseMode; }
virtual void setCompatibilityModeFromDoctype() { }
void setCompatibilityMode(CompatibilityMode m);
void lockCompatibilityMode() { m_compatibilityModeLocked = true; }
CompatibilityMode compatibilityMode() const { return m_compatibilityMode; }
bool inCompatMode() const { return m_parseMode == Compat; }
bool inAlmostStrictMode() const { return m_parseMode == AlmostStrict; }
bool inStrictMode() const { return m_parseMode == Strict; }
bool inQuirksMode() const { return m_compatibilityMode == QuirksMode; }
bool inLimitedQuirksMode() const { return m_compatibilityMode == LimitedQuirksMode; }
bool inNoQuirksMode() const { return m_compatibilityMode == NoQuirksMode; }
void setParsing(bool);
bool parsing() const { return m_bParsing; }
......@@ -1015,7 +1019,6 @@ private:
virtual bool isDocument() const { return true; }
virtual void removedLastRef();
virtual void determineParseMode() { }
virtual void childrenChanged(bool changedByParser = false, Node* beforeChange = 0, Node* afterChange = 0, int childCountDelta = 0);
......@@ -1103,7 +1106,8 @@ private:
bool m_ignoreAutofocus;
ParseMode m_parseMode;
CompatibilityMode m_compatibilityMode;
bool m_compatibilityModeLocked; // This is cheaper than making setCompatibilityMode virtual.
Color m_textColor;
......
......@@ -367,9 +367,9 @@ int Element::clientWidth()
// When in strict mode, clientWidth for the document element should return the width of the containing frame.
// When in quirks mode, clientWidth for the body element should return the width of the containing frame.
bool inCompatMode = document()->inCompatMode();
if ((!inCompatMode && document()->documentElement() == this) ||
(inCompatMode && isHTMLElement() && document()->body() == this)) {
bool inQuirksMode = document()->inQuirksMode();
if ((!inQuirksMode && document()->documentElement() == this) ||
(inQuirksMode && isHTMLElement() && document()->body() == this)) {
if (FrameView* view = document()->view()) {
if (RenderView* renderView = document()->renderView())
return adjustForAbsoluteZoom(view->layoutWidth(), renderView);
......@@ -387,10 +387,10 @@ int Element::clientHeight()
// When in strict mode, clientHeight for the document element should return the height of the containing frame.
// When in quirks mode, clientHeight for the body element should return the height of the containing frame.
bool inCompatMode = document()->inCompatMode();
bool inQuirksMode = document()->inQuirksMode();
if ((!inCompatMode && document()->documentElement() == this) ||
(inCompatMode && isHTMLElement() && document()->body() == this)) {
if ((!inQuirksMode && document()->documentElement() == this) ||
(inQuirksMode && isHTMLElement() && document()->body() == this)) {
if (FrameView* view = document()->view()) {
if (RenderView* renderView = document()->renderView())
return adjustForAbsoluteZoom(view->layoutHeight(), renderView);
......@@ -1498,7 +1498,7 @@ bool Element::webkitMatchesSelector(const String& selector, ExceptionCode& ec)
return false;
}
bool strictParsing = !document()->inCompatMode();
bool strictParsing = !document()->inQuirksMode();
CSSParser p(strictParsing);
CSSSelectorList selectorList;
......
......@@ -309,7 +309,7 @@ void NamedNodeMap::setClass(const String& classStr)
return;
}
m_classNames.set(classStr, element()->document()->inCompatMode());
m_classNames.set(classStr, element()->document()->inQuirksMode());
}
int NamedNodeMap::declCount() const
......
......@@ -1641,7 +1641,7 @@ PassRefPtr<Element> Node::querySelector(const String& selectors, ExceptionCode&
ec = SYNTAX_ERR;
return 0;
}
bool strictParsing = !document()->inCompatMode();
bool strictParsing = !document()->inQuirksMode();
CSSParser p(strictParsing);
CSSSelectorList querySelectorList;
......@@ -1688,7 +1688,7 @@ PassRefPtr<NodeList> Node::querySelectorAll(const String& selectors, ExceptionCo
ec = SYNTAX_ERR;
return 0;
}
bool strictParsing = !document()->inCompatMode();
bool strictParsing = !document()->inQuirksMode();
CSSParser p(strictParsing);
CSSSelectorList querySelectorList;
......
......@@ -73,7 +73,7 @@ String OptionElement::collectOptionLabelOrText(const OptionElementData& data, co
String text;
// WinIE does not use the label attribute, so as a quirk, we ignore it.
if (!document->inCompatMode())
if (!document->inQuirksMode())
text = data.label();
if (text.isEmpty())
text = collectOptionInnerText(element);
......
......@@ -46,7 +46,7 @@ PassRefPtr<StaticNodeList> createSelectorNodeList(Node* rootNode, const CSSSelec
Vector<RefPtr<Node> > nodes;
Document* document = rootNode->document();
CSSSelector* onlySelector = querySelectorList.hasOneSelector() ? querySelectorList.first() : 0;
bool strictParsing = !document->inCompatMode();
bool strictParsing = !document->inQuirksMode();
CSSStyleSelector::SelectorChecker selectorChecker(document, strictParsing);
......
......@@ -137,7 +137,7 @@ void StyleElement::createSheet(Element* e, int startLineNumber, const String& te
document->addPendingSheet();
m_loading = true;
m_sheet = CSSStyleSheet::create(e, String(), KURL(), document->inputEncoding());
m_sheet->parseStringAtLine(text, !document->inCompatMode(), startLineNumber);
m_sheet->parseStringAtLine(text, !document->inQuirksMode(), startLineNumber);
m_sheet->setMedia(mediaList.get());
m_sheet->setTitle(e->title());
m_loading = false;
......
......@@ -126,7 +126,7 @@ void StyledElement::createInlineStyleDecl()
m_inlineStyleDecl = CSSMutableStyleDeclaration::create();
m_inlineStyleDecl->setParent(document()->elementSheet());
m_inlineStyleDecl->setNode(this);
m_inlineStyleDecl->setStrictParsing(isHTMLElement() && !document()->inCompatMode());
m_inlineStyleDecl->setStrictParsing(isHTMLElement() && !document()->inQuirksMode());
}
void StyledElement::destroyInlineStyleDecl()
......@@ -234,7 +234,7 @@ void StyledElement::parseMappedAttribute(Attribute* attr)
if (attributeMap()) {
if (attr->isNull())
attributeMap()->setIdForStyleResolution(nullAtom);
else if (document()->inCompatMode())
else if (document()->inQuirksMode())
attributeMap()->setIdForStyleResolution(attr->value().lower());
else
attributeMap()->setIdForStyleResolution(attr->value());
......
......@@ -1115,7 +1115,7 @@ bool ReplaceSelectionCommand::shouldRemoveEndBR(Node* endBR, const VisiblePositi
return false;
// Remove the br if it is collapsed away and so is unnecessary.
if (!document()->inStrictMode() && isEndOfBlock(visiblePos) && !isStartOfParagraph(visiblePos))
if (!document()->inNoQuirksMode() && isEndOfBlock(visiblePos) && !isStartOfParagraph(visiblePos))
return true;
// A br that was originally holding a line open should be displaced by inserted content or turned into a line break.
......
......@@ -68,7 +68,7 @@ void HTMLBodyElement::createLinkDecl()
m_linkDecl = CSSMutableStyleDeclaration::create();
m_linkDecl->setParent(document()->elementSheet());
m_linkDecl->setNode(this);
m_linkDecl->setStrictParsing(!document()->inCompatMode());
m_linkDecl->setStrictParsing(!document()->inQuirksMode());
}
bool HTMLBodyElement::mapToEntry(const QualifiedName& attrName, MappedAttributeEntry& result) const
......
......@@ -146,7 +146,7 @@ CanvasRenderingContext* HTMLCanvasElement::getContext(const String& type, Canvas
if (Settings* settings = document()->settings())
usesDashbardCompatibilityMode = settings->usesDashboardBackwardCompatibilityMode();
#endif
m_context = adoptPtr(new CanvasRenderingContext2D(this, document()->inCompatMode(), usesDashbardCompatibilityMode));
m_context = adoptPtr(new CanvasRenderingContext2D(this, document()->inQuirksMode(), usesDashbardCompatibilityMode));
#if ENABLE(ACCELERATED_2D_CANVAS) && USE(ACCELERATED_COMPOSITING)
if (m_context) {
// Need to make sure a RenderLayer and compositing layer get created for the Canvas
......
......@@ -203,10 +203,11 @@ void HTMLConstructionSite::insertDoctype(AtomicHTMLToken& token)
{
ASSERT(token.type() == HTMLToken::DOCTYPE);
attach(m_document, DocumentType::create(m_document, token.name(), String::adopt(token.publicIdentifier()), String::adopt(token.systemIdentifier())));
// FIXME: Move quirks mode detection from DocumentType element to here.
notImplemented();
if (token.forceQuirks())
m_document->setParseMode(Document::Compat);
m_document->setCompatibilityMode(Document::QuirksMode);
else
m_document->setCompatibilityModeFromDoctype();
}
void HTMLConstructionSite::insertComment(AtomicHTMLToken& token)
......
......@@ -84,7 +84,6 @@ HTMLDocument::HTMLDocument(Frame* frame, const KURL& url)
: Document(frame, url, false, true)
{
clearXMLVersion();
setParseMode(Compat);
}
HTMLDocument::~HTMLDocument()
......@@ -139,7 +138,7 @@ void HTMLDocument::setDesignMode(const String& value)
String HTMLDocument::compatMode() const
{
return inCompatMode() ? "BackCompat" : "CSS1Compat";
return inQuirksMode() ? "BackCompat" : "CSS1Compat";
}
Element* HTMLDocument::activeElement()
......@@ -343,65 +342,97 @@ void HTMLDocument::removeExtraNamedItem(const AtomicString& name)
removeItemFromMap(m_extraNamedItemCounts, name);
}
void HTMLDocument::determineParseMode()
void HTMLDocument::setCompatibilityModeFromDoctype()
{
// FIXME: It's terrible that this code runs separately and isn't just built in to the
// HTML tokenizer/parser.
// This code more or less mimics Mozilla's implementation (specifically the
// doctype parsing implemented by David Baron in Mozilla's nsParser.cpp).
//
// There are three possible parse modes:
// COMPAT - quirks mode emulates WinIE and NS4. CSS parsing is also relaxed in this mode, e.g., unit types can
// There are three possible compatibility modes:
// Quirks - quirks mode emulates WinIE and NS4. CSS parsing is also relaxed in this mode, e.g., unit types can
// be omitted from numbers.
// ALMOST STRICT - This mode is identical to strict mode except for its treatment of line-height in the inline box model. For
// now (until the inline box model is re-written), this mode is identical to STANDARDS mode.