diff --git a/mozilla/content/base/src/nsStyleSet.cpp b/mozilla/content/base/src/nsStyleSet.cpp index f3a1c866fbf..453900ec559 100644 --- a/mozilla/content/base/src/nsStyleSet.cpp +++ b/mozilla/content/base/src/nsStyleSet.cpp @@ -118,6 +118,11 @@ public: nsIStyleContext* aParentContext, PRBool aForceUnique = PR_FALSE); + virtual nsIStyleContext* ResolveStyleForNonElement( + nsIPresContext* aPresContext, + nsIStyleContext* aParentContext, + PRBool aForceUnique = PR_FALSE); + virtual nsIStyleContext* ResolvePseudoStyleFor(nsIPresContext* aPresContext, nsIContent* aParentContent, nsIAtom* aPseudoTag, @@ -856,6 +861,8 @@ nsIStyleContext* StyleSetImpl::ResolveStyleFor(nsIPresContext* aPresContext, NS_ASSERTION(aContent, "must have content"); NS_ASSERTION(aPresContext, "must have pres context"); + NS_ASSERTION(aContent->IsContentOfType(nsIContent::eELEMENT), + "content must be element"); if (aContent && aPresContext) { GatherRuleProcessors(); @@ -881,6 +888,35 @@ nsIStyleContext* StyleSetImpl::ResolveStyleFor(nsIPresContext* aPresContext, return result; } +nsIStyleContext* StyleSetImpl::ResolveStyleForNonElement( + nsIPresContext* aPresContext, + nsIStyleContext* aParentContext, + PRBool aForceUnique) +{ + MOZ_TIMER_DEBUGLOG(("Start: StyleSetImpl::ResolveStyleForNonElement(), this=%p\n", this)); + STYLESET_START_TIMER(NS_TIMER_STYLE_RESOLUTION); + + nsIStyleContext* result = nsnull; + + NS_ASSERTION(aPresContext, "must have pres context"); + + if (aPresContext) { + GatherRuleProcessors(); + if (mBackstopRuleProcessors || + mDocRuleProcessors || + mOverrideRuleProcessors) { + EnsureRuleWalker(aPresContext); + result = GetContext(aPresContext, aParentContext, nsnull, aForceUnique); + NS_ASSERTION(mRuleWalker->AtRoot(), "rule walker must be at root"); + } + } + + MOZ_TIMER_DEBUGLOG(("Stop: StyleSetImpl::ResolveStyleForNonElement(), this=%p\n", this)); + STYLESET_STOP_TIMER(NS_TIMER_STYLE_RESOLUTION); + return result; +} + + struct PseudoRulesMatchingData { PseudoRulesMatchingData(nsIPresContext* aPresContext, nsIAtom* aMedium, @@ -933,6 +969,9 @@ nsIStyleContext* StyleSetImpl::ResolvePseudoStyleFor(nsIPresContext* aPresContex NS_ASSERTION(aPseudoTag, "must have pseudo tag"); NS_ASSERTION(aPresContext, "must have pres context"); + NS_ASSERTION(!aParentContent || + aParentContent->IsContentOfType(nsIContent::eELEMENT), + "content (if non-null) must be element"); if (aPseudoTag && aPresContext) { GatherRuleProcessors(); @@ -972,6 +1011,9 @@ nsIStyleContext* StyleSetImpl::ProbePseudoStyleFor(nsIPresContext* aPresContext, NS_ASSERTION(aPseudoTag, "must have pseudo tag"); NS_ASSERTION(aPresContext, "must have pres context"); + NS_ASSERTION(!aParentContent || + aParentContent->IsContentOfType(nsIContent::eELEMENT), + "content (if non-null) must be element"); if (aPseudoTag && aPresContext) { GatherRuleProcessors(); @@ -1168,7 +1210,11 @@ StyleSetImpl::HasStateDependentStyle(nsIPresContext* aPresContext, nsIContent* aContent) { GatherRuleProcessors(); - if (mBackstopRuleProcessors || mDocRuleProcessors || mOverrideRuleProcessors) { + + if (aContent->IsContentOfType(nsIContent::eELEMENT) && + (mBackstopRuleProcessors || + mDocRuleProcessors || + mOverrideRuleProcessors)) { nsIAtom* medium = nsnull; aPresContext->GetMedium(&medium); StatefulData data(aPresContext, medium, aContent); diff --git a/mozilla/content/html/content/src/nsHTMLAtomList.h b/mozilla/content/html/content/src/nsHTMLAtomList.h index d7ae6e7b074..4061759ed1e 100644 --- a/mozilla/content/html/content/src/nsHTMLAtomList.h +++ b/mozilla/content/html/content/src/nsHTMLAtomList.h @@ -119,7 +119,6 @@ HTML_ATOM(cols, "cols") HTML_ATOM(colspan, "colspan") HTML_ATOM(combobox, "combobox") HTML_ATOM(columnPseudo, ":body-column") -HTML_ATOM(commentPseudo, ":-moz-comment") HTML_ATOM(compact, "compact") HTML_ATOM(content, "content") HTML_ATOM(coords, "coords") @@ -235,7 +234,6 @@ HTML_ATOM(param, "param") HTML_ATOM(placeholderPseudo, ":placeholder-frame") HTML_ATOM(pointSize, "point-size") HTML_ATOM(pre, "pre") -HTML_ATOM(processingInstructionPseudo, ":-moz-pi") HTML_ATOM(profile, "profile") HTML_ATOM(prompt, "prompt") HTML_ATOM(radioPseudo, ":-moz-radio") @@ -287,7 +285,6 @@ HTML_ATOM(tfoot, "tfoot") HTML_ATOM(thead, "thead") HTML_ATOM(text, "text") HTML_ATOM(textarea, "textarea") -HTML_ATOM(textPseudo, ":-moz-text") HTML_ATOM(th, "th") HTML_ATOM(title, "title") HTML_ATOM(top, "top") diff --git a/mozilla/content/html/style/src/nsCSSStyleSheet.cpp b/mozilla/content/html/style/src/nsCSSStyleSheet.cpp index 8a346affb04..ca2b3851590 100644 --- a/mozilla/content/html/style/src/nsCSSStyleSheet.cpp +++ b/mozilla/content/html/style/src/nsCSSStyleSheet.cpp @@ -3226,7 +3226,8 @@ MOZ_DECL_CTOR_COUNTER(SelectorMatchesData) struct SelectorMatchesData { SelectorMatchesData(nsIPresContext* aPresContext, nsIContent* aContent, - nsRuleWalker* aRuleWalker, nsCompatibility* aCompat = nsnull); + nsRuleWalker* aRuleWalker, + nsCompatibility* aCompat = nsnull); virtual ~SelectorMatchesData() { @@ -3274,12 +3275,16 @@ struct SelectorMatchesData { SelectorMatchesData* mParentData; }; -SelectorMatchesData::SelectorMatchesData(nsIPresContext* aPresContext, nsIContent* aContent, - nsRuleWalker* aRuleWalker, - nsCompatibility* aCompat /*= nsnull*/) +SelectorMatchesData::SelectorMatchesData(nsIPresContext* aPresContext, + nsIContent* aContent, + nsRuleWalker* aRuleWalker, + nsCompatibility* aCompat /*= nsnull*/) { MOZ_COUNT_CTOR(SelectorMatchesData); + NS_ASSERTION(!aContent || aContent->IsContentOfType(nsIContent::eELEMENT), + "non-element leaked into SelectorMatches"); + mPresContext = aPresContext; mContent = aContent; mParentContent = nsnull; @@ -3404,7 +3409,7 @@ static PRBool ValueIncludes(const nsString& aValueList, const nsString& aValue, return PR_FALSE; } -static PRBool IsEventPseudo(nsIAtom* aAtom) +inline PRBool IsEventPseudo(nsIAtom* aAtom) { return PRBool ((nsCSSAtoms::activePseudo == aAtom) || (nsCSSAtoms::dragOverPseudo == aAtom) || @@ -3414,14 +3419,14 @@ static PRBool IsEventPseudo(nsIAtom* aAtom) // XXX selected, enabled, disabled, selection? } -static PRBool IsLinkPseudo(nsIAtom* aAtom) +inline PRBool IsLinkPseudo(nsIAtom* aAtom) { return PRBool ((nsCSSAtoms::linkPseudo == aAtom) || (nsCSSAtoms::visitedPseudo == aAtom) || (nsCSSAtoms::anyLinkPseudo == aAtom)); } -static PRBool PR_CALLBACK IsEventSensitive(nsIAtom *aPseudo, nsIAtom *aContentTag, PRBool aSelectorIsGlobal) +inline PRBool IsEventSensitive(nsIAtom *aPseudo, nsIAtom *aContentTag, PRBool aSelectorIsGlobal) { // if the selector is global, meaning it is not tied to a tag, then // we restrict the application of the event pseudo to the following tags @@ -3433,11 +3438,7 @@ static PRBool PR_CALLBACK IsEventSensitive(nsIAtom *aPseudo, nsIAtom *aContentTa (nsHTMLAtoms::li == aContentTag) || (nsHTMLAtoms::label == aContentTag) || (nsHTMLAtoms::select == aContentTag) || - (nsHTMLAtoms::textarea == aContentTag) || - (nsHTMLAtoms::textPseudo == aContentTag) || - // We require a Layout Atom too - (nsLayoutAtoms::textTagName == aContentTag) - ); + (nsHTMLAtoms::textarea == aContentTag)); } else { // selector is not global, so apply the event pseudo to everything except HTML and BODY return PRBool ((nsHTMLAtoms::html != aContentTag) && @@ -3952,6 +3953,8 @@ CSSRuleProcessor::RulesMatching(nsIPresContext* aPresContext, NS_PRECONDITION(nsnull != aPresContext, "null arg"); NS_PRECONDITION(nsnull != aContent, "null arg"); NS_PRECONDITION(nsnull != aRuleWalker, "null arg"); + NS_PRECONDITION(aContent->IsContentOfType(nsIContent::eELEMENT), + "content must be element"); RuleCascadeData* cascade = GetRuleCascade(aPresContext, aMedium); @@ -4066,6 +4069,9 @@ CSSRuleProcessor::RulesMatching(nsIPresContext* aPresContext, NS_PRECONDITION(nsnull != aPresContext, "null arg"); NS_PRECONDITION(nsnull != aPseudoTag, "null arg"); NS_PRECONDITION(nsnull != aRuleWalker, "null arg"); + NS_PRECONDITION(!aParentContent || + aParentContent->IsContentOfType(nsIContent::eELEMENT), + "content (if present) must be element"); RuleCascadeData* cascade = GetRuleCascade(aPresContext, aMedium); @@ -4116,6 +4122,9 @@ CSSRuleProcessor::HasStateDependentStyle(nsIPresContext* aPresContext, nsIAtom* aMedium, nsIContent* aContent) { + NS_PRECONDITION(aContent->IsContentOfType(nsIContent::eELEMENT), + "content must be element"); + PRBool isStateful = PR_FALSE; RuleCascadeData* cascade = GetRuleCascade(aPresContext, aMedium); @@ -4288,7 +4297,6 @@ CSSRuleProcessor::ClearRuleCascades(void) delete data; data = next; } - mRuleCascades = nsnull; return NS_OK; } @@ -4302,7 +4310,7 @@ PRBool BuildHashEnum(nsISupports* aRule, void* aHash) return PR_TRUE; } -static +inline PRBool IsStateSelector(nsCSSSelector& aSelector) { nsAtomList* pseudoClass = aSelector.mPseudoClassList; diff --git a/mozilla/content/shared/public/nsHTMLAtomList.h b/mozilla/content/shared/public/nsHTMLAtomList.h index d7ae6e7b074..4061759ed1e 100644 --- a/mozilla/content/shared/public/nsHTMLAtomList.h +++ b/mozilla/content/shared/public/nsHTMLAtomList.h @@ -119,7 +119,6 @@ HTML_ATOM(cols, "cols") HTML_ATOM(colspan, "colspan") HTML_ATOM(combobox, "combobox") HTML_ATOM(columnPseudo, ":body-column") -HTML_ATOM(commentPseudo, ":-moz-comment") HTML_ATOM(compact, "compact") HTML_ATOM(content, "content") HTML_ATOM(coords, "coords") @@ -235,7 +234,6 @@ HTML_ATOM(param, "param") HTML_ATOM(placeholderPseudo, ":placeholder-frame") HTML_ATOM(pointSize, "point-size") HTML_ATOM(pre, "pre") -HTML_ATOM(processingInstructionPseudo, ":-moz-pi") HTML_ATOM(profile, "profile") HTML_ATOM(prompt, "prompt") HTML_ATOM(radioPseudo, ":-moz-radio") @@ -287,7 +285,6 @@ HTML_ATOM(tfoot, "tfoot") HTML_ATOM(thead, "thead") HTML_ATOM(text, "text") HTML_ATOM(textarea, "textarea") -HTML_ATOM(textPseudo, ":-moz-text") HTML_ATOM(th, "th") HTML_ATOM(title, "title") HTML_ATOM(top, "top") diff --git a/mozilla/layout/base/nsCSSFrameConstructor.cpp b/mozilla/layout/base/nsCSSFrameConstructor.cpp index 0bccf9268b6..b4e790b6d0e 100644 --- a/mozilla/layout/base/nsCSSFrameConstructor.cpp +++ b/mozilla/layout/base/nsCSSFrameConstructor.cpp @@ -1433,6 +1433,9 @@ nsCSSFrameConstructor::CreateGeneratedContentFrame(nsIPresShell* aPresShe { *aResult = nsnull; // initialize OUT parameter + if (!aContent->IsContentOfType(nsIContent::eELEMENT)) + return PR_FALSE; + // Probe for the existence of the pseudo-element nsCOMPtr pseudoStyleContext; aPresContext->ProbePseudoStyleContextFor(aContent, aPseudoElement, aStyleContext, @@ -1476,9 +1479,9 @@ nsCSSFrameConstructor::CreateGeneratedContentFrame(nsIPresShell* aPresShe // Create another pseudo style context to use for all the generated child // frames nsIStyleContext* textStyleContext; - aPresContext->ResolvePseudoStyleContextFor(aContent, nsHTMLAtoms::textPseudo, - pseudoStyleContext, PR_FALSE, - &textStyleContext); + aPresContext->ResolveStyleContextForNonElement( + pseudoStyleContext, PR_FALSE, + &textStyleContext); // Now create content objects (and child frames) for each value of the // 'content' property @@ -2937,8 +2940,12 @@ nsCSSFrameConstructor::TableProcessChildren(nsIPresShell* aPresShell, iter != last; ++iter) { nsCOMPtr childContent = *iter; - if (childContent && NeedFrameFor(aParentFrame, childContent)) { - rv = TableProcessChild(aPresShell, aPresContext, aState, *childContent, aParentFrame, + if (childContent && + (childContent->IsContentOfType(nsIContent::eELEMENT) || + childContent->IsContentOfType(nsIContent::eTEXT)) && + NeedFrameFor(aParentFrame, childContent)) { + rv = TableProcessChild(aPresShell, aPresContext, aState, childContent, + aContent, aParentFrame, parentFrameType, parentStyleContext, aTableCreator, aChildItems, aCaption); } @@ -2958,7 +2965,8 @@ nsresult nsCSSFrameConstructor::TableProcessChild(nsIPresShell* aPresShell, nsIPresContext* aPresContext, nsFrameConstructorState& aState, - nsIContent& aChildContent, + nsIContent* aChildContent, + nsIContent* aParentContent, nsIFrame* aParentFrame, nsIAtom* aParentFrameType, nsIStyleContext* aParentStyleContext, @@ -2975,15 +2983,15 @@ nsCSSFrameConstructor::TableProcessChild(nsIPresShell* aPresShell, nsCOMPtr childStyleContext; // Resolve the style context and get its display - aPresContext->ResolveStyleContextFor(&aChildContent, aParentStyleContext, PR_FALSE, - getter_AddRefs(childStyleContext)); + ResolveStyleContext(aPresContext, aParentFrame, aChildContent, + getter_AddRefs(childStyleContext)); const nsStyleDisplay* styleDisplay = (const nsStyleDisplay*) childStyleContext->GetStyleData(eStyleStruct_Display); switch (styleDisplay->mDisplay) { case NS_STYLE_DISPLAY_TABLE: nsIFrame* innerTableFrame; - rv = ConstructTableFrame(aPresShell, aPresContext, aState, &aChildContent, aParentFrame, + rv = ConstructTableFrame(aPresShell, aPresContext, aState, aChildContent, aParentFrame, childStyleContext, aTableCreator, PR_FALSE, aChildItems, childFrame, innerTableFrame, isPseudoParent); break; @@ -2991,7 +2999,7 @@ nsCSSFrameConstructor::TableProcessChild(nsIPresShell* aPresShell, case NS_STYLE_DISPLAY_TABLE_CAPTION: if (!aCaption) { // only allow one caption nsIFrame* parentFrame = GetOuterTableFrame(aParentFrame); - rv = ConstructTableCaptionFrame(aPresShell, aPresContext, aState, &aChildContent, + rv = ConstructTableCaptionFrame(aPresShell, aPresContext, aState, aChildContent, parentFrame, childStyleContext, aTableCreator, aChildItems, aCaption, isPseudoParent); } @@ -2999,7 +3007,7 @@ nsCSSFrameConstructor::TableProcessChild(nsIPresShell* aPresShell, break; case NS_STYLE_DISPLAY_TABLE_COLUMN_GROUP: - rv = ConstructTableColGroupFrame(aPresShell, aPresContext, aState, &aChildContent, + rv = ConstructTableColGroupFrame(aPresShell, aPresContext, aState, aChildContent, aParentFrame, childStyleContext, aTableCreator, PR_FALSE, aChildItems, childFrame, isPseudoParent); break; @@ -3007,19 +3015,19 @@ nsCSSFrameConstructor::TableProcessChild(nsIPresShell* aPresShell, case NS_STYLE_DISPLAY_TABLE_HEADER_GROUP: case NS_STYLE_DISPLAY_TABLE_FOOTER_GROUP: case NS_STYLE_DISPLAY_TABLE_ROW_GROUP: - rv = ConstructTableRowGroupFrame(aPresShell, aPresContext, aState, &aChildContent, + rv = ConstructTableRowGroupFrame(aPresShell, aPresContext, aState, aChildContent, aParentFrame, childStyleContext, aTableCreator, PR_FALSE, aChildItems, childFrame, isPseudoParent); break; case NS_STYLE_DISPLAY_TABLE_ROW: - rv = ConstructTableRowFrame(aPresShell, aPresContext, aState, &aChildContent, + rv = ConstructTableRowFrame(aPresShell, aPresContext, aState, aChildContent, aParentFrame, childStyleContext, aTableCreator, PR_FALSE, aChildItems, childFrame, isPseudoParent); break; case NS_STYLE_DISPLAY_TABLE_COLUMN: - rv = ConstructTableColFrame(aPresShell, aPresContext, aState, &aChildContent, + rv = ConstructTableColFrame(aPresShell, aPresContext, aState, aChildContent, aParentFrame, childStyleContext, aTableCreator, PR_FALSE, aChildItems, childFrame, isPseudoParent); break; @@ -3027,13 +3035,16 @@ nsCSSFrameConstructor::TableProcessChild(nsIPresShell* aPresShell, case NS_STYLE_DISPLAY_TABLE_CELL: nsIFrame* innerCell; - rv = ConstructTableCellFrame(aPresShell, aPresContext, aState, &aChildContent, + rv = ConstructTableCellFrame(aPresShell, aPresContext, aState, aChildContent, aParentFrame, childStyleContext, aTableCreator, PR_FALSE, aChildItems, childFrame, innerCell, isPseudoParent); break; + case NS_STYLE_DISPLAY_NONE: + break; + default: - rv = ConstructTableForeignFrame(aPresShell, aPresContext, aState, &aChildContent, + rv = ConstructTableForeignFrame(aPresShell, aPresContext, aState, aChildContent, aParentFrame, childStyleContext, aTableCreator, aChildItems, childFrame, isPseudoParent); break; @@ -3230,9 +3241,8 @@ nsCSSFrameConstructor::ConstructDocElementFrame(nsIPresShell* aPresShell, } if (resolveStyle) { - nsCOMPtr tag; - aDocElement->GetTag(*getter_AddRefs(tag)); - rv = ResolveStyleContext(aPresContext, aParentFrame, aDocElement, tag, getter_AddRefs(styleContext)); + rv = ResolveStyleContext(aPresContext, aParentFrame, aDocElement, + getter_AddRefs(styleContext)); if (NS_FAILED(rv)) return rv; } @@ -6506,7 +6516,6 @@ nsresult nsCSSFrameConstructor::ResolveStyleContext(nsIPresContext* aPresContext, nsIFrame* aParentFrame, nsIContent* aContent, - nsIAtom* aTag, nsIStyleContext** aStyleContext) { nsresult rv = NS_OK; @@ -6515,43 +6524,23 @@ nsCSSFrameConstructor::ResolveStyleContext(nsIPresContext* aPresContext, nsCOMPtr parentStyleContext; aParentFrame->GetStyleContext(getter_AddRefs(parentStyleContext)); - if (nsLayoutAtoms::textTagName == aTag) { - // Use a special pseudo element style context for text - nsCOMPtr parentContent; - if (nsnull != aParentFrame) { - aParentFrame->GetContent(getter_AddRefs(parentContent)); - } - rv = aPresContext->ResolvePseudoStyleContextFor(parentContent, - nsHTMLAtoms::textPseudo, - parentStyleContext, - PR_FALSE, - aStyleContext); - } else if (nsLayoutAtoms::commentTagName == aTag) { - // Use a special pseudo element style context for comments - nsCOMPtr parentContent; - if (nsnull != aParentFrame) { - aParentFrame->GetContent(getter_AddRefs(parentContent)); - } - rv = aPresContext->ResolvePseudoStyleContextFor(parentContent, - nsHTMLAtoms::commentPseudo, - parentStyleContext, - PR_FALSE, - aStyleContext); - } else if (nsLayoutAtoms::processingInstructionTagName == aTag) { - // Use a special pseudo element style context for comments - nsCOMPtr parentContent; - if (nsnull != aParentFrame) { - aParentFrame->GetContent(getter_AddRefs(parentContent)); - } - rv = aPresContext->ResolvePseudoStyleContextFor(parentContent, - nsHTMLAtoms::processingInstructionPseudo, - parentStyleContext, - PR_FALSE, - aStyleContext); - } else { + if (aContent->IsContentOfType(nsIContent::eELEMENT)) { rv = aPresContext->ResolveStyleContextFor(aContent, parentStyleContext, PR_FALSE, aStyleContext); + } else { +#ifdef DEBUG + { + nsCOMPtr tag; + aContent->GetTag(*getter_AddRefs(tag)); + NS_ASSERTION(tag == nsLayoutAtoms::textTagName, + "shouldn't waste time creating style contexts for " + "comments and processing instructions"); + } +#endif + rv = aPresContext->ResolveStyleContextForNonElement(parentStyleContext, + PR_FALSE, + aStyleContext); } return rv; } @@ -6926,8 +6915,14 @@ nsCSSFrameConstructor::ConstructFrame(nsIPresShell* aPresShell, nsCOMPtr tag; aContent->GetTag(*getter_AddRefs(tag)); + // never create frames for comments on PIs + if (tag == nsLayoutAtoms::commentTagName || + tag == nsLayoutAtoms::processingInstructionTagName) + return rv; + nsCOMPtr styleContext; - rv = ResolveStyleContext(aPresContext, aParentFrame, aContent, tag, getter_AddRefs(styleContext)); + rv = ResolveStyleContext(aPresContext, aParentFrame, aContent, + getter_AddRefs(styleContext)); if (NS_SUCCEEDED(rv)) { @@ -6984,7 +6979,8 @@ nsCSSFrameConstructor::ConstructFrameInternal( nsIPresShell* aPresShe return NS_OK; if (resolveStyle) { - rv = ResolveStyleContext(aPresContext, aParentFrame, aContent, aTag, getter_AddRefs(styleContext)); + rv = ResolveStyleContext(aPresContext, aParentFrame, aContent, + getter_AddRefs(styleContext)); if (NS_FAILED(rv)) return rv; } @@ -8294,6 +8290,9 @@ nsCSSFrameConstructor::ContentInserted(nsIPresContext* aPresContext, PRInt32 aIndexInContainer, nsILayoutHistoryState* aFrameState) { + // XXXldb Do we need to re-resolve style to handle the CSS2 + combinator and + // the :empty pseudo-class? + #ifdef DEBUG if (gNoisyContentUpdates) { printf("nsCSSFrameConstructor::ContentInserted container=%p child=%p index=%d\n", @@ -8360,9 +8359,8 @@ nsCSSFrameConstructor::ContentInserted(nsIPresContext* aPresContext, // to check it for subsequent display changes (e.g., when you next // reopen). nsCOMPtr styleContext; - nsCOMPtr tagName; - aChild->GetTag(*getter_AddRefs(tagName)); - ResolveStyleContext(aPresContext, innerFrame, aChild, tagName, getter_AddRefs(styleContext)); + ResolveStyleContext(aPresContext, innerFrame, aChild, + getter_AddRefs(styleContext)); // Pre-check for display "none" - if we find that, don't reflow at all. const nsStyleDisplay* display = (const nsStyleDisplay*) @@ -8998,6 +8996,9 @@ nsCSSFrameConstructor::ContentRemoved(nsIPresContext* aPresContext, nsIContent* aChild, PRInt32 aIndexInContainer) { + // XXXldb Do we need to re-resolve style to handle the CSS2 + combinator and + // the :empty pseudo-class? + #ifdef DEBUG if (gNoisyContentUpdates) { printf("nsCSSFrameConstructor::ContentRemoved container=%p child=%p index=%d\n", @@ -10295,9 +10296,8 @@ nsCSSFrameConstructor::ConstructAlternateFrame(nsIPresShell* aPresShell, nsIStyleContext* textStyleContext; NS_NewTextFrame(aPresShell, &textFrame); - aPresContext->ResolvePseudoStyleContextFor(aContent, nsHTMLAtoms::textPseudo, - aStyleContext, PR_FALSE, - &textStyleContext); + aPresContext->ResolveStyleContextForNonElement(aStyleContext, PR_FALSE, + &textStyleContext); textFrame->Init(aPresContext, altTextContent, containerFrame, textStyleContext, nsnull); @@ -12528,15 +12528,9 @@ nsCSSFrameConstructor::CreateTreeWidgetContent(nsIPresContext* aPresContext, GetFloaterContainingBlock(aPresContext, aParentFrame), mTempFrameTreeState); - // Get the element's tag - nsCOMPtr tag; - aChild->GetTag(*getter_AddRefs(tag)); - - PRInt32 namespaceID; - aChild->GetNameSpaceID(namespaceID); - nsCOMPtr styleContext; - rv = ResolveStyleContext(aPresContext, aParentFrame, aChild, tag, getter_AddRefs(styleContext)); + rv = ResolveStyleContext(aPresContext, aParentFrame, aChild, + getter_AddRefs(styleContext)); if (NS_SUCCEEDED(rv)) { // Pre-check for display "none" - only if we find that, do we create @@ -12550,6 +12544,12 @@ nsCSSFrameConstructor::CreateTreeWidgetContent(nsIPresContext* aPresContext, } } + nsCOMPtr tag; + aChild->GetTag(*getter_AddRefs(tag)); + + PRInt32 namespaceID; + aChild->GetNameSpaceID(namespaceID); + rv = ConstructFrameInternal(shell, aPresContext, state, aChild, aParentFrame, tag, namespaceID, styleContext, frameItems, PR_FALSE); diff --git a/mozilla/layout/base/nsCSSFrameConstructor.h b/mozilla/layout/base/nsCSSFrameConstructor.h index 75aeabed2b1..20489d101c9 100644 --- a/mozilla/layout/base/nsCSSFrameConstructor.h +++ b/mozilla/layout/base/nsCSSFrameConstructor.h @@ -192,7 +192,6 @@ protected: nsresult ResolveStyleContext(nsIPresContext* aPresContext, nsIFrame* aParentFrame, nsIContent* aContent, - nsIAtom* aTag, nsIStyleContext** aStyleContext); nsresult ConstructFrame(nsIPresShell* aPresShell, @@ -427,7 +426,8 @@ protected: nsresult TableProcessChild(nsIPresShell* aPresShell, nsIPresContext* aPresContext, nsFrameConstructorState& aState, - nsIContent& aChildContent, + nsIContent* aChildContent, + nsIContent* aParentContent, nsIFrame* aParentFrame, nsIAtom* aParentFrameType, nsIStyleContext* aParentStyleContext, diff --git a/mozilla/layout/base/nsFrameManager.cpp b/mozilla/layout/base/nsFrameManager.cpp index 2f9fb945b1a..31a4a0ed2ad 100644 --- a/mozilla/layout/base/nsFrameManager.cpp +++ b/mozilla/layout/base/nsFrameManager.cpp @@ -1631,7 +1631,13 @@ FrameManager::ReResolveStyleContext(nsIPresContext* aPresContext, } else { NS_ASSERTION(localContent, "non pseudo-element frame without content node"); - aPresContext->ResolveStyleContextFor(content, aParentContext, PR_TRUE, &newContext); + if (content->IsContentOfType(nsIContent::eELEMENT)) { + aPresContext->ResolveStyleContextFor(content, aParentContext, + PR_TRUE, &newContext); + } else { + aPresContext->ResolveStyleContextForNonElement(aParentContext, + PR_TRUE, &newContext); + } } NS_ASSERTION(newContext, "failed to get new style context"); if (newContext) { @@ -1845,7 +1851,13 @@ FrameManager::ReResolveStyleContext(nsIPresContext* aPresContext, } else { NS_ASSERTION(localContent, "non pseudo-element frame without content node"); - aPresContext->ResolveStyleContextFor(content, aParentContext, PR_TRUE, &newContext); + if (content->IsContentOfType(nsIContent::eELEMENT)) { + aPresContext->ResolveStyleContextFor(content, aParentContext, + PR_TRUE, &newContext); + } else { + aPresContext->ResolveStyleContextForNonElement(aParentContext, + PR_TRUE, &newContext); + } } NS_ASSERTION(newContext, "failed to get new style context"); if (newContext) { @@ -1927,13 +1939,20 @@ FrameManager::ReResolveStyleContext(nsIPresContext* aPresContext, nsIStyleContext* undisplayedContext = nsnull; undisplayed->mStyle->GetPseudoType(pseudoTag); if (undisplayed->mContent && pseudoTag == nsnull) { // child content - aPresContext->ResolveStyleContextFor(undisplayed->mContent, newContext, - PR_TRUE, &undisplayedContext); + if (undisplayed->mContent->IsContentOfType(nsIContent::eELEMENT)) { + aPresContext->ResolveStyleContextFor(undisplayed->mContent, + newContext, + PR_TRUE, &undisplayedContext); + } else { + aPresContext->ResolveStyleContextForNonElement(newContext, + PR_TRUE, &undisplayedContext); + } } else { // pseudo element NS_ASSERTION(pseudoTag, "pseudo element without tag"); - aPresContext->ResolvePseudoStyleContextFor(localContent, pseudoTag, newContext, PR_FALSE, - &undisplayedContext); + aPresContext->ResolvePseudoStyleContextFor(localContent, pseudoTag, + newContext, PR_FALSE, + &undisplayedContext); } NS_IF_RELEASE(pseudoTag); if (undisplayedContext) { diff --git a/mozilla/layout/base/nsPresContext.cpp b/mozilla/layout/base/nsPresContext.cpp index c89472447c2..5e2e5dcc3d3 100644 --- a/mozilla/layout/base/nsPresContext.cpp +++ b/mozilla/layout/base/nsPresContext.cpp @@ -692,10 +692,7 @@ nsPresContext::SetShell(nsIPresShell* aShell) NS_IMETHODIMP nsPresContext::GetShell(nsIPresShell** aResult) { - NS_PRECONDITION(nsnull != aResult, "null ptr"); - if (nsnull == aResult) { - return NS_ERROR_NULL_POINTER; - } + NS_PRECONDITION(aResult, "null out param"); *aResult = mShell; NS_IF_ADDREF(mShell); return NS_OK; @@ -750,10 +747,7 @@ nsPresContext::Observe(nsISupports* aSubject, NS_IMETHODIMP nsPresContext::GetCompatibilityMode(nsCompatibility* aResult) { - NS_PRECONDITION(nsnull != aResult, "null ptr"); - if (nsnull == aResult) { - return NS_ERROR_NULL_POINTER; - } + NS_PRECONDITION(aResult, "null out param"); *aResult = mCompatibilityMode; return NS_OK; } @@ -782,7 +776,7 @@ nsPresContext::SetCompatibilityMode(nsCompatibility aMode) NS_IMETHODIMP nsPresContext::GetWidgetRenderingMode(nsWidgetRendering* aResult) { - NS_ENSURE_ARG_POINTER(aResult); + NS_PRECONDITION(aResult, "null out param"); *aResult = mWidgetRenderingMode; return NS_OK; } @@ -798,7 +792,7 @@ nsPresContext::SetWidgetRenderingMode(nsWidgetRendering aMode) NS_IMETHODIMP nsPresContext::GetImageAnimationMode(nsImageAnimation* aModeResult) { - NS_ENSURE_ARG_POINTER(aModeResult); + NS_PRECONDITION(aModeResult, "null out param"); *aModeResult = mImageAnimationMode; return NS_OK; } @@ -818,10 +812,7 @@ nsPresContext::SetImageAnimationMode(nsImageAnimation aMode) NS_IMETHODIMP nsPresContext::GetLookAndFeel(nsILookAndFeel** aLookAndFeel) { - NS_PRECONDITION(nsnull != aLookAndFeel, "null ptr"); - if (nsnull == aLookAndFeel) { - return NS_ERROR_NULL_POINTER; - } + NS_PRECONDITION(aLookAndFeel, "null out param"); nsresult result = NS_OK; if (! mLookAndFeel) { mLookAndFeel = do_GetService(kLookAndFeelCID,&result); @@ -836,10 +827,7 @@ nsPresContext::GetLookAndFeel(nsILookAndFeel** aLookAndFeel) NS_IMETHODIMP nsPresContext::GetBaseURL(nsIURI** aResult) { - NS_PRECONDITION(nsnull != aResult, "null ptr"); - if (nsnull == aResult) { - return NS_ERROR_NULL_POINTER; - } + NS_PRECONDITION(aResult, "null out param"); *aResult = mBaseURL; NS_IF_ADDREF(*aResult); return NS_OK; @@ -851,10 +839,7 @@ nsPresContext::ResolveStyleContextFor(nsIContent* aContent, PRBool aForceUnique, nsIStyleContext** aResult) { - NS_PRECONDITION(nsnull != aResult, "null ptr"); - if (nsnull == aResult) { - return NS_ERROR_NULL_POINTER; - } + NS_PRECONDITION(aResult, "null out param"); nsIStyleContext* result = nsnull; nsCOMPtr set; @@ -872,6 +857,27 @@ nsPresContext::ResolveStyleContextFor(nsIContent* aContent, return rv; } +NS_IMETHODIMP +nsPresContext::ResolveStyleContextForNonElement( + nsIStyleContext* aParentContext, + PRBool aForceUnique, + nsIStyleContext** aResult) +{ + NS_PRECONDITION(aResult, "null out param"); + + nsIStyleContext* result = nsnull; + nsCOMPtr set; + nsresult rv = mShell->GetStyleSet(getter_AddRefs(set)); + if (NS_SUCCEEDED(rv) && set) { + result = set->ResolveStyleForNonElement(this, aParentContext, + aForceUnique); + if (!result) + rv = NS_ERROR_OUT_OF_MEMORY; + } + *aResult = result; + return rv; +} + NS_IMETHODIMP nsPresContext::ResolvePseudoStyleContextFor(nsIContent* aParentContent, nsIAtom* aPseudoTag, @@ -891,10 +897,7 @@ nsPresContext::ResolvePseudoStyleWithComparator(nsIContent* aParentContent, nsICSSPseudoComparator* aComparator, nsIStyleContext** aResult) { - NS_PRECONDITION(nsnull != aResult, "null ptr"); - if (nsnull == aResult) { - return NS_ERROR_NULL_POINTER; - } + NS_PRECONDITION(aResult, "null out param"); nsIStyleContext* result = nsnull; nsCOMPtr set; @@ -919,10 +922,7 @@ nsPresContext::ProbePseudoStyleContextFor(nsIContent* aParentContent, PRBool aForceUnique, nsIStyleContext** aResult) { - NS_PRECONDITION(nsnull != aResult, "null ptr"); - if (nsnull == aResult) { - return NS_ERROR_NULL_POINTER; - } + NS_PRECONDITION(aResult, "null out param"); nsIStyleContext* result = nsnull; nsCOMPtr set; @@ -973,10 +973,7 @@ nsPresContext::FreeToShell(size_t aSize, void* aFreeChunk) NS_IMETHODIMP nsPresContext::GetMetricsFor(const nsFont& aFont, nsIFontMetrics** aResult) { - NS_PRECONDITION(nsnull != aResult, "null ptr"); - if (nsnull == aResult) { - return NS_ERROR_NULL_POINTER; - } + NS_PRECONDITION(aResult, "null out param"); nsIFontMetrics* metrics = nsnull; if (mDeviceContext) { @@ -1065,10 +1062,7 @@ nsPresContext::SetDefaultFont(const PRUint8 aFontID, const nsFont& aFont) NS_IMETHODIMP nsPresContext::GetFontScaler(PRInt32* aResult) { - NS_PRECONDITION(nsnull != aResult, "null ptr"); - if (nsnull == aResult) { - return NS_ERROR_NULL_POINTER; - } + NS_PRECONDITION(aResult, "null out param"); *aResult = mFontScaler; return NS_OK; @@ -1084,10 +1078,7 @@ nsPresContext::SetFontScaler(PRInt32 aScaler) NS_IMETHODIMP nsPresContext::GetDefaultColor(nscolor* aResult) { - NS_PRECONDITION(nsnull != aResult, "null ptr"); - if (nsnull == aResult) { - return NS_ERROR_NULL_POINTER; - } + NS_PRECONDITION(aResult, "null out param"); *aResult = mDefaultColor; return NS_OK; @@ -1096,10 +1087,7 @@ nsPresContext::GetDefaultColor(nscolor* aResult) NS_IMETHODIMP nsPresContext::GetDefaultBackgroundColor(nscolor* aResult) { - NS_PRECONDITION(nsnull != aResult, "null ptr"); - if (nsnull == aResult) { - return NS_ERROR_NULL_POINTER; - } + NS_PRECONDITION(aResult, "null out param"); *aResult = mDefaultBackgroundColor; return NS_OK; @@ -1115,8 +1103,7 @@ nsPresContext::GetDefaultBackgroundImage(nsString& aImage) NS_IMETHODIMP nsPresContext::GetDefaultBackgroundImageRepeat(PRUint8* aRepeat) { - NS_PRECONDITION(nsnull != aRepeat, "null ptr"); - if (nsnull == aRepeat) { return NS_ERROR_NULL_POINTER; } + NS_PRECONDITION(aRepeat, "null out param"); *aRepeat = mDefaultBackgroundImageRepeat; return NS_OK; } @@ -1124,8 +1111,7 @@ nsPresContext::GetDefaultBackgroundImageRepeat(PRUint8* aRepeat) NS_IMETHODIMP nsPresContext::GetDefaultBackgroundImageOffset(nscoord* aX, nscoord* aY) { - NS_PRECONDITION((nsnull != aX) && (nsnull != aY), "null ptr"); - if (!aX || !aY) { return NS_ERROR_NULL_POINTER; } + NS_PRECONDITION(aX && aY, "null out param"); *aX = mDefaultBackgroundImageOffsetX; *aY = mDefaultBackgroundImageOffsetY; return NS_OK; @@ -1134,8 +1120,7 @@ nsPresContext::GetDefaultBackgroundImageOffset(nscoord* aX, nscoord* aY) NS_IMETHODIMP nsPresContext::GetDefaultBackgroundImageAttachment(PRUint8* aAttachment) { - NS_PRECONDITION(nsnull != aAttachment, "null ptr"); - if (nsnull == aAttachment) { return NS_ERROR_NULL_POINTER; } + NS_PRECONDITION(aAttachment, "null out param"); *aAttachment = mDefaultBackgroundImageAttachment; return NS_OK; } @@ -1143,23 +1128,17 @@ nsPresContext::GetDefaultBackgroundImageAttachment(PRUint8* aAttachment) NS_IMETHODIMP nsPresContext::GetDefaultLinkColor(nscolor* aColor) { - NS_PRECONDITION(nsnull != aColor, "null argument"); - if (aColor) { - *aColor = mLinkColor; - return NS_OK; - } - return NS_ERROR_NULL_POINTER; + NS_PRECONDITION(aColor, "null out param"); + *aColor = mLinkColor; + return NS_OK; } NS_IMETHODIMP nsPresContext::GetDefaultVisitedLinkColor(nscolor* aColor) { - NS_PRECONDITION(nsnull != aColor, "null argument"); - if (aColor) { - *aColor = mVisitedLinkColor; - return NS_OK; - } - return NS_ERROR_NULL_POINTER; + NS_PRECONDITION(aColor, "null out param"); + *aColor = mVisitedLinkColor; + return NS_OK; } @@ -1182,35 +1161,26 @@ nsPresContext::GetUseFocusColors(PRBool& aUseFocusColors) NS_IMETHODIMP nsPresContext::GetFocusTextColor(nscolor* aColor) { - NS_PRECONDITION(nsnull != aColor, "null argument"); - if (aColor) { - *aColor = mFocusTextColor; - return NS_OK; - } - return NS_ERROR_NULL_POINTER; + NS_PRECONDITION(aColor, "null out param"); + *aColor = mFocusTextColor; + return NS_OK; } NS_IMETHODIMP nsPresContext::GetFocusBackgroundColor(nscolor* aColor) { - NS_PRECONDITION(nsnull != aColor, "null argument"); - if (aColor) { - *aColor = mFocusBackgroundColor; - return NS_OK; - } - return NS_ERROR_NULL_POINTER; + NS_PRECONDITION(aColor, "null out param"); + *aColor = mFocusBackgroundColor; + return NS_OK; } NS_IMETHODIMP nsPresContext::GetFocusRingWidth(PRUint8 *aFocusRingWidth) { - NS_PRECONDITION(nsnull != aFocusRingWidth, "null argument"); - if (aFocusRingWidth) { - *aFocusRingWidth = mFocusRingWidth; - return NS_OK; - } - return NS_ERROR_NULL_POINTER; + NS_PRECONDITION(aFocusRingWidth, "null out param"); + *aFocusRingWidth = mFocusRingWidth; + return NS_OK; } @@ -1288,10 +1258,7 @@ nsPresContext::SetVisibleArea(const nsRect& r) NS_IMETHODIMP nsPresContext::GetPixelsToTwips(float* aResult) const { - NS_PRECONDITION(nsnull != aResult, "null ptr"); - if (nsnull == aResult) { - return NS_ERROR_NULL_POINTER; - } + NS_PRECONDITION(aResult, "null out param"); float p2t = 1.0f; if (mDeviceContext) { @@ -1304,10 +1271,7 @@ nsPresContext::GetPixelsToTwips(float* aResult) const NS_IMETHODIMP nsPresContext::GetTwipsToPixels(float* aResult) const { - NS_PRECONDITION(nsnull != aResult, "null ptr"); - if (nsnull == aResult) { - return NS_ERROR_NULL_POINTER; - } + NS_PRECONDITION(aResult, "null out param"); float app2dev = 1.0f; if (mDeviceContext) { @@ -1320,10 +1284,7 @@ nsPresContext::GetTwipsToPixels(float* aResult) const NS_IMETHODIMP nsPresContext::GetScaledPixelsToTwips(float* aResult) const { - NS_PRECONDITION(nsnull != aResult, "null ptr"); - if (nsnull == aResult) { - return NS_ERROR_NULL_POINTER; - } + NS_PRECONDITION(aResult, "null out param"); float scale = 1.0f; if (mDeviceContext) @@ -1340,10 +1301,7 @@ nsPresContext::GetScaledPixelsToTwips(float* aResult) const NS_IMETHODIMP nsPresContext::GetDeviceContext(nsIDeviceContext** aResult) const { - NS_PRECONDITION(nsnull != aResult, "null ptr"); - if (nsnull == aResult) { - return NS_ERROR_NULL_POINTER; - } + NS_PRECONDITION(aResult, "null out param"); *aResult = mDeviceContext; NS_IF_ADDREF(*aResult); return NS_OK; @@ -1429,10 +1387,7 @@ nsPresContext::SetLinkHandler(nsILinkHandler* aHandler) NS_IMETHODIMP nsPresContext::GetLinkHandler(nsILinkHandler** aResult) { - NS_PRECONDITION(nsnull != aResult, "null ptr"); - if (nsnull == aResult) { - return NS_ERROR_NULL_POINTER; - } + NS_PRECONDITION(aResult, "null out param"); *aResult = mLinkHandler; NS_IF_ADDREF(mLinkHandler); return NS_OK; @@ -1451,10 +1406,7 @@ nsPresContext::SetContainer(nsISupports* aHandler) NS_IMETHODIMP nsPresContext::GetContainer(nsISupports** aResult) { - NS_PRECONDITION(nsnull != aResult, "null ptr"); - if (nsnull == aResult) { - return NS_ERROR_NULL_POINTER; - } + NS_PRECONDITION(aResult, "null out param"); *aResult = mContainer; NS_IF_ADDREF(mContainer); return NS_OK; @@ -1619,7 +1571,7 @@ nsPresContext::GetBidiCharset(nsAWritableString &aCharSet) NS_IMETHODIMP nsPresContext::GetLanguage(nsILanguageAtom** aLanguage) { - NS_ENSURE_ARG_POINTER(aLanguage); + NS_PRECONDITION(aLanguage, "null out param"); *aLanguage = mLanguage; NS_IF_ADDREF(*aLanguage); @@ -1631,7 +1583,7 @@ NS_IMETHODIMP nsPresContext::GetLanguageSpecificTransformType( nsLanguageSpecificTransformType* aType) { - NS_ENSURE_ARG_POINTER(aType); + NS_PRECONDITION(aType, "null out param"); *aType = mLanguageSpecificTransformType; return NS_OK; @@ -1640,7 +1592,7 @@ nsPresContext::GetLanguageSpecificTransformType( NS_IMETHODIMP nsPresContext::IsRenderingOnlySelection(PRBool* aResult) { - NS_ENSURE_ARG_POINTER(aResult); + NS_PRECONDITION(aResult, "null out param"); *aResult = mIsRenderingOnlySelection; return NS_OK; diff --git a/mozilla/layout/base/nsPresContext.h b/mozilla/layout/base/nsPresContext.h index fca5e03d633..196caf96617 100644 --- a/mozilla/layout/base/nsPresContext.h +++ b/mozilla/layout/base/nsPresContext.h @@ -199,6 +199,20 @@ public: PRBool aForceUnique, nsIStyleContext** aResult) = 0; + /** + * Resolve style for a non-element content node (i.e., one that is + * guaranteed not to match any rules). Eventually such nodes + * shouldn't have style contexts at all, but this at least prevents + * the rule matching. + * + * XXX This is temporary. It should go away when we stop creating + * style contexts for text nodes. + */ + NS_IMETHOD ResolveStyleContextForNonElement( + nsIStyleContext* aParentContext, + PRBool aForceUnique, + nsIStyleContext** aResult) = 0; + /** * Resolve style for a pseudo frame within the given aParentContent & aParentContext. * The tag should be lowercase and inclue the colon. diff --git a/mozilla/layout/base/public/nsIPresContext.h b/mozilla/layout/base/public/nsIPresContext.h index fca5e03d633..196caf96617 100644 --- a/mozilla/layout/base/public/nsIPresContext.h +++ b/mozilla/layout/base/public/nsIPresContext.h @@ -199,6 +199,20 @@ public: PRBool aForceUnique, nsIStyleContext** aResult) = 0; + /** + * Resolve style for a non-element content node (i.e., one that is + * guaranteed not to match any rules). Eventually such nodes + * shouldn't have style contexts at all, but this at least prevents + * the rule matching. + * + * XXX This is temporary. It should go away when we stop creating + * style contexts for text nodes. + */ + NS_IMETHOD ResolveStyleContextForNonElement( + nsIStyleContext* aParentContext, + PRBool aForceUnique, + nsIStyleContext** aResult) = 0; + /** * Resolve style for a pseudo frame within the given aParentContent & aParentContext. * The tag should be lowercase and inclue the colon. diff --git a/mozilla/layout/base/public/nsIStyleSet.h b/mozilla/layout/base/public/nsIStyleSet.h index a2d9878b697..8c35c3965fb 100644 --- a/mozilla/layout/base/public/nsIStyleSet.h +++ b/mozilla/layout/base/public/nsIStyleSet.h @@ -125,7 +125,21 @@ public: nsIStyleContext* aParentContext, PRBool aForceUnique = PR_FALSE) = 0; - // get a style context for a pseudo-frame (ie: tag = NS_NewAtom(":first-line"); + // Get a style context for a non-element (which no rules will match). + // Eventually, this should go away and we shouldn't even create style + // contexts for such content nodes. However, not doing any rule + // matching for them is a first step. + // + // XXX This is temporary. It should go away when we stop creating + // style contexts for text nodes. + // + virtual nsIStyleContext* ResolveStyleForNonElement( + nsIPresContext* aPresContext, + nsIStyleContext* aParentContext, + PRBool aForceUnique = PR_FALSE) = 0; + + // get a style context for a pseudo-element (i.e., + // |aPseudoTag == NS_NewAtom(":first-line")|; virtual nsIStyleContext* ResolvePseudoStyleFor(nsIPresContext* aPresContext, nsIContent* aParentContent, nsIAtom* aPseudoTag, diff --git a/mozilla/layout/base/public/nsPresContext.h b/mozilla/layout/base/public/nsPresContext.h index fca5e03d633..196caf96617 100644 --- a/mozilla/layout/base/public/nsPresContext.h +++ b/mozilla/layout/base/public/nsPresContext.h @@ -199,6 +199,20 @@ public: PRBool aForceUnique, nsIStyleContext** aResult) = 0; + /** + * Resolve style for a non-element content node (i.e., one that is + * guaranteed not to match any rules). Eventually such nodes + * shouldn't have style contexts at all, but this at least prevents + * the rule matching. + * + * XXX This is temporary. It should go away when we stop creating + * style contexts for text nodes. + */ + NS_IMETHOD ResolveStyleContextForNonElement( + nsIStyleContext* aParentContext, + PRBool aForceUnique, + nsIStyleContext** aResult) = 0; + /** * Resolve style for a pseudo frame within the given aParentContent & aParentContext. * The tag should be lowercase and inclue the colon. diff --git a/mozilla/layout/base/src/nsPresContext.cpp b/mozilla/layout/base/src/nsPresContext.cpp index c89472447c2..5e2e5dcc3d3 100644 --- a/mozilla/layout/base/src/nsPresContext.cpp +++ b/mozilla/layout/base/src/nsPresContext.cpp @@ -692,10 +692,7 @@ nsPresContext::SetShell(nsIPresShell* aShell) NS_IMETHODIMP nsPresContext::GetShell(nsIPresShell** aResult) { - NS_PRECONDITION(nsnull != aResult, "null ptr"); - if (nsnull == aResult) { - return NS_ERROR_NULL_POINTER; - } + NS_PRECONDITION(aResult, "null out param"); *aResult = mShell; NS_IF_ADDREF(mShell); return NS_OK; @@ -750,10 +747,7 @@ nsPresContext::Observe(nsISupports* aSubject, NS_IMETHODIMP nsPresContext::GetCompatibilityMode(nsCompatibility* aResult) { - NS_PRECONDITION(nsnull != aResult, "null ptr"); - if (nsnull == aResult) { - return NS_ERROR_NULL_POINTER; - } + NS_PRECONDITION(aResult, "null out param"); *aResult = mCompatibilityMode; return NS_OK; } @@ -782,7 +776,7 @@ nsPresContext::SetCompatibilityMode(nsCompatibility aMode) NS_IMETHODIMP nsPresContext::GetWidgetRenderingMode(nsWidgetRendering* aResult) { - NS_ENSURE_ARG_POINTER(aResult); + NS_PRECONDITION(aResult, "null out param"); *aResult = mWidgetRenderingMode; return NS_OK; } @@ -798,7 +792,7 @@ nsPresContext::SetWidgetRenderingMode(nsWidgetRendering aMode) NS_IMETHODIMP nsPresContext::GetImageAnimationMode(nsImageAnimation* aModeResult) { - NS_ENSURE_ARG_POINTER(aModeResult); + NS_PRECONDITION(aModeResult, "null out param"); *aModeResult = mImageAnimationMode; return NS_OK; } @@ -818,10 +812,7 @@ nsPresContext::SetImageAnimationMode(nsImageAnimation aMode) NS_IMETHODIMP nsPresContext::GetLookAndFeel(nsILookAndFeel** aLookAndFeel) { - NS_PRECONDITION(nsnull != aLookAndFeel, "null ptr"); - if (nsnull == aLookAndFeel) { - return NS_ERROR_NULL_POINTER; - } + NS_PRECONDITION(aLookAndFeel, "null out param"); nsresult result = NS_OK; if (! mLookAndFeel) { mLookAndFeel = do_GetService(kLookAndFeelCID,&result); @@ -836,10 +827,7 @@ nsPresContext::GetLookAndFeel(nsILookAndFeel** aLookAndFeel) NS_IMETHODIMP nsPresContext::GetBaseURL(nsIURI** aResult) { - NS_PRECONDITION(nsnull != aResult, "null ptr"); - if (nsnull == aResult) { - return NS_ERROR_NULL_POINTER; - } + NS_PRECONDITION(aResult, "null out param"); *aResult = mBaseURL; NS_IF_ADDREF(*aResult); return NS_OK; @@ -851,10 +839,7 @@ nsPresContext::ResolveStyleContextFor(nsIContent* aContent, PRBool aForceUnique, nsIStyleContext** aResult) { - NS_PRECONDITION(nsnull != aResult, "null ptr"); - if (nsnull == aResult) { - return NS_ERROR_NULL_POINTER; - } + NS_PRECONDITION(aResult, "null out param"); nsIStyleContext* result = nsnull; nsCOMPtr set; @@ -872,6 +857,27 @@ nsPresContext::ResolveStyleContextFor(nsIContent* aContent, return rv; } +NS_IMETHODIMP +nsPresContext::ResolveStyleContextForNonElement( + nsIStyleContext* aParentContext, + PRBool aForceUnique, + nsIStyleContext** aResult) +{ + NS_PRECONDITION(aResult, "null out param"); + + nsIStyleContext* result = nsnull; + nsCOMPtr set; + nsresult rv = mShell->GetStyleSet(getter_AddRefs(set)); + if (NS_SUCCEEDED(rv) && set) { + result = set->ResolveStyleForNonElement(this, aParentContext, + aForceUnique); + if (!result) + rv = NS_ERROR_OUT_OF_MEMORY; + } + *aResult = result; + return rv; +} + NS_IMETHODIMP nsPresContext::ResolvePseudoStyleContextFor(nsIContent* aParentContent, nsIAtom* aPseudoTag, @@ -891,10 +897,7 @@ nsPresContext::ResolvePseudoStyleWithComparator(nsIContent* aParentContent, nsICSSPseudoComparator* aComparator, nsIStyleContext** aResult) { - NS_PRECONDITION(nsnull != aResult, "null ptr"); - if (nsnull == aResult) { - return NS_ERROR_NULL_POINTER; - } + NS_PRECONDITION(aResult, "null out param"); nsIStyleContext* result = nsnull; nsCOMPtr set; @@ -919,10 +922,7 @@ nsPresContext::ProbePseudoStyleContextFor(nsIContent* aParentContent, PRBool aForceUnique, nsIStyleContext** aResult) { - NS_PRECONDITION(nsnull != aResult, "null ptr"); - if (nsnull == aResult) { - return NS_ERROR_NULL_POINTER; - } + NS_PRECONDITION(aResult, "null out param"); nsIStyleContext* result = nsnull; nsCOMPtr set; @@ -973,10 +973,7 @@ nsPresContext::FreeToShell(size_t aSize, void* aFreeChunk) NS_IMETHODIMP nsPresContext::GetMetricsFor(const nsFont& aFont, nsIFontMetrics** aResult) { - NS_PRECONDITION(nsnull != aResult, "null ptr"); - if (nsnull == aResult) { - return NS_ERROR_NULL_POINTER; - } + NS_PRECONDITION(aResult, "null out param"); nsIFontMetrics* metrics = nsnull; if (mDeviceContext) { @@ -1065,10 +1062,7 @@ nsPresContext::SetDefaultFont(const PRUint8 aFontID, const nsFont& aFont) NS_IMETHODIMP nsPresContext::GetFontScaler(PRInt32* aResult) { - NS_PRECONDITION(nsnull != aResult, "null ptr"); - if (nsnull == aResult) { - return NS_ERROR_NULL_POINTER; - } + NS_PRECONDITION(aResult, "null out param"); *aResult = mFontScaler; return NS_OK; @@ -1084,10 +1078,7 @@ nsPresContext::SetFontScaler(PRInt32 aScaler) NS_IMETHODIMP nsPresContext::GetDefaultColor(nscolor* aResult) { - NS_PRECONDITION(nsnull != aResult, "null ptr"); - if (nsnull == aResult) { - return NS_ERROR_NULL_POINTER; - } + NS_PRECONDITION(aResult, "null out param"); *aResult = mDefaultColor; return NS_OK; @@ -1096,10 +1087,7 @@ nsPresContext::GetDefaultColor(nscolor* aResult) NS_IMETHODIMP nsPresContext::GetDefaultBackgroundColor(nscolor* aResult) { - NS_PRECONDITION(nsnull != aResult, "null ptr"); - if (nsnull == aResult) { - return NS_ERROR_NULL_POINTER; - } + NS_PRECONDITION(aResult, "null out param"); *aResult = mDefaultBackgroundColor; return NS_OK; @@ -1115,8 +1103,7 @@ nsPresContext::GetDefaultBackgroundImage(nsString& aImage) NS_IMETHODIMP nsPresContext::GetDefaultBackgroundImageRepeat(PRUint8* aRepeat) { - NS_PRECONDITION(nsnull != aRepeat, "null ptr"); - if (nsnull == aRepeat) { return NS_ERROR_NULL_POINTER; } + NS_PRECONDITION(aRepeat, "null out param"); *aRepeat = mDefaultBackgroundImageRepeat; return NS_OK; } @@ -1124,8 +1111,7 @@ nsPresContext::GetDefaultBackgroundImageRepeat(PRUint8* aRepeat) NS_IMETHODIMP nsPresContext::GetDefaultBackgroundImageOffset(nscoord* aX, nscoord* aY) { - NS_PRECONDITION((nsnull != aX) && (nsnull != aY), "null ptr"); - if (!aX || !aY) { return NS_ERROR_NULL_POINTER; } + NS_PRECONDITION(aX && aY, "null out param"); *aX = mDefaultBackgroundImageOffsetX; *aY = mDefaultBackgroundImageOffsetY; return NS_OK; @@ -1134,8 +1120,7 @@ nsPresContext::GetDefaultBackgroundImageOffset(nscoord* aX, nscoord* aY) NS_IMETHODIMP nsPresContext::GetDefaultBackgroundImageAttachment(PRUint8* aAttachment) { - NS_PRECONDITION(nsnull != aAttachment, "null ptr"); - if (nsnull == aAttachment) { return NS_ERROR_NULL_POINTER; } + NS_PRECONDITION(aAttachment, "null out param"); *aAttachment = mDefaultBackgroundImageAttachment; return NS_OK; } @@ -1143,23 +1128,17 @@ nsPresContext::GetDefaultBackgroundImageAttachment(PRUint8* aAttachment) NS_IMETHODIMP nsPresContext::GetDefaultLinkColor(nscolor* aColor) { - NS_PRECONDITION(nsnull != aColor, "null argument"); - if (aColor) { - *aColor = mLinkColor; - return NS_OK; - } - return NS_ERROR_NULL_POINTER; + NS_PRECONDITION(aColor, "null out param"); + *aColor = mLinkColor; + return NS_OK; } NS_IMETHODIMP nsPresContext::GetDefaultVisitedLinkColor(nscolor* aColor) { - NS_PRECONDITION(nsnull != aColor, "null argument"); - if (aColor) { - *aColor = mVisitedLinkColor; - return NS_OK; - } - return NS_ERROR_NULL_POINTER; + NS_PRECONDITION(aColor, "null out param"); + *aColor = mVisitedLinkColor; + return NS_OK; } @@ -1182,35 +1161,26 @@ nsPresContext::GetUseFocusColors(PRBool& aUseFocusColors) NS_IMETHODIMP nsPresContext::GetFocusTextColor(nscolor* aColor) { - NS_PRECONDITION(nsnull != aColor, "null argument"); - if (aColor) { - *aColor = mFocusTextColor; - return NS_OK; - } - return NS_ERROR_NULL_POINTER; + NS_PRECONDITION(aColor, "null out param"); + *aColor = mFocusTextColor; + return NS_OK; } NS_IMETHODIMP nsPresContext::GetFocusBackgroundColor(nscolor* aColor) { - NS_PRECONDITION(nsnull != aColor, "null argument"); - if (aColor) { - *aColor = mFocusBackgroundColor; - return NS_OK; - } - return NS_ERROR_NULL_POINTER; + NS_PRECONDITION(aColor, "null out param"); + *aColor = mFocusBackgroundColor; + return NS_OK; } NS_IMETHODIMP nsPresContext::GetFocusRingWidth(PRUint8 *aFocusRingWidth) { - NS_PRECONDITION(nsnull != aFocusRingWidth, "null argument"); - if (aFocusRingWidth) { - *aFocusRingWidth = mFocusRingWidth; - return NS_OK; - } - return NS_ERROR_NULL_POINTER; + NS_PRECONDITION(aFocusRingWidth, "null out param"); + *aFocusRingWidth = mFocusRingWidth; + return NS_OK; } @@ -1288,10 +1258,7 @@ nsPresContext::SetVisibleArea(const nsRect& r) NS_IMETHODIMP nsPresContext::GetPixelsToTwips(float* aResult) const { - NS_PRECONDITION(nsnull != aResult, "null ptr"); - if (nsnull == aResult) { - return NS_ERROR_NULL_POINTER; - } + NS_PRECONDITION(aResult, "null out param"); float p2t = 1.0f; if (mDeviceContext) { @@ -1304,10 +1271,7 @@ nsPresContext::GetPixelsToTwips(float* aResult) const NS_IMETHODIMP nsPresContext::GetTwipsToPixels(float* aResult) const { - NS_PRECONDITION(nsnull != aResult, "null ptr"); - if (nsnull == aResult) { - return NS_ERROR_NULL_POINTER; - } + NS_PRECONDITION(aResult, "null out param"); float app2dev = 1.0f; if (mDeviceContext) { @@ -1320,10 +1284,7 @@ nsPresContext::GetTwipsToPixels(float* aResult) const NS_IMETHODIMP nsPresContext::GetScaledPixelsToTwips(float* aResult) const { - NS_PRECONDITION(nsnull != aResult, "null ptr"); - if (nsnull == aResult) { - return NS_ERROR_NULL_POINTER; - } + NS_PRECONDITION(aResult, "null out param"); float scale = 1.0f; if (mDeviceContext) @@ -1340,10 +1301,7 @@ nsPresContext::GetScaledPixelsToTwips(float* aResult) const NS_IMETHODIMP nsPresContext::GetDeviceContext(nsIDeviceContext** aResult) const { - NS_PRECONDITION(nsnull != aResult, "null ptr"); - if (nsnull == aResult) { - return NS_ERROR_NULL_POINTER; - } + NS_PRECONDITION(aResult, "null out param"); *aResult = mDeviceContext; NS_IF_ADDREF(*aResult); return NS_OK; @@ -1429,10 +1387,7 @@ nsPresContext::SetLinkHandler(nsILinkHandler* aHandler) NS_IMETHODIMP nsPresContext::GetLinkHandler(nsILinkHandler** aResult) { - NS_PRECONDITION(nsnull != aResult, "null ptr"); - if (nsnull == aResult) { - return NS_ERROR_NULL_POINTER; - } + NS_PRECONDITION(aResult, "null out param"); *aResult = mLinkHandler; NS_IF_ADDREF(mLinkHandler); return NS_OK; @@ -1451,10 +1406,7 @@ nsPresContext::SetContainer(nsISupports* aHandler) NS_IMETHODIMP nsPresContext::GetContainer(nsISupports** aResult) { - NS_PRECONDITION(nsnull != aResult, "null ptr"); - if (nsnull == aResult) { - return NS_ERROR_NULL_POINTER; - } + NS_PRECONDITION(aResult, "null out param"); *aResult = mContainer; NS_IF_ADDREF(mContainer); return NS_OK; @@ -1619,7 +1571,7 @@ nsPresContext::GetBidiCharset(nsAWritableString &aCharSet) NS_IMETHODIMP nsPresContext::GetLanguage(nsILanguageAtom** aLanguage) { - NS_ENSURE_ARG_POINTER(aLanguage); + NS_PRECONDITION(aLanguage, "null out param"); *aLanguage = mLanguage; NS_IF_ADDREF(*aLanguage); @@ -1631,7 +1583,7 @@ NS_IMETHODIMP nsPresContext::GetLanguageSpecificTransformType( nsLanguageSpecificTransformType* aType) { - NS_ENSURE_ARG_POINTER(aType); + NS_PRECONDITION(aType, "null out param"); *aType = mLanguageSpecificTransformType; return NS_OK; @@ -1640,7 +1592,7 @@ nsPresContext::GetLanguageSpecificTransformType( NS_IMETHODIMP nsPresContext::IsRenderingOnlySelection(PRBool* aResult) { - NS_ENSURE_ARG_POINTER(aResult); + NS_PRECONDITION(aResult, "null out param"); *aResult = mIsRenderingOnlySelection; return NS_OK; diff --git a/mozilla/layout/forms/nsComboboxControlFrame.cpp b/mozilla/layout/forms/nsComboboxControlFrame.cpp index 36d1b0b1fbd..8fdc9c96e1b 100644 --- a/mozilla/layout/forms/nsComboboxControlFrame.cpp +++ b/mozilla/layout/forms/nsComboboxControlFrame.cpp @@ -2269,11 +2269,10 @@ nsComboboxControlFrame::CreateDisplayFrame(nsIPresContext* aPresContext) if (NS_FAILED(rv)) { return rv; } if (!mTextFrame) { return NS_ERROR_NULL_POINTER; } nsCOMPtr textStyleContext; - rv = aPresContext->ResolvePseudoStyleContextFor(mContent, - nsHTMLAtoms::mozDisplayComboboxControlFrame, - styleContext, - PR_FALSE, - getter_AddRefs(textStyleContext)); + rv = aPresContext->ResolveStyleContextForNonElement( + styleContext, + PR_FALSE, + getter_AddRefs(textStyleContext)); if (NS_FAILED(rv)) { return rv; } if (!textStyleContext) { return NS_ERROR_NULL_POINTER; } nsCOMPtr content(do_QueryInterface(mDisplayContent)); @@ -2325,11 +2324,10 @@ nsComboboxControlFrame::CreateAnonymousContent(nsIPresContext* aPresContext, // Add a child text content node for the label nsresult result; nsCOMPtr labelContent(do_CreateInstance(kTextNodeCID,&result)); - nsAutoString value; value.AssignWithConversion("X"); if (NS_SUCCEEDED(result) && labelContent) { // set the value of the text node mDisplayContent = do_QueryInterface(labelContent); - mDisplayContent->SetText(value.get(), value.Length(), PR_TRUE); + mDisplayContent->SetText(NS_LITERAL_STRING("X"), PR_TRUE); nsCOMPtr doc; mContent->GetDocument(*getter_AddRefs(doc)); @@ -2400,7 +2398,7 @@ nsComboboxControlFrame::CreateFrameFor(nsIPresContext* aPresContext, // create the style context for the anonymous block frame nsCOMPtr styleContext; - rv = aPresContext->ResolvePseudoStyleContextFor(content, + rv = aPresContext->ResolvePseudoStyleContextFor(mContent, nsHTMLAtoms::mozDisplayComboboxControlFrame, mStyleContext, PR_FALSE, @@ -2413,11 +2411,10 @@ nsComboboxControlFrame::CreateFrameFor(nsIPresContext* aPresContext, if (NS_FAILED(rv)) { return rv; } if (!mTextFrame) { return NS_ERROR_NULL_POINTER; } nsCOMPtr textStyleContext; - rv = aPresContext->ResolvePseudoStyleContextFor(content, - nsHTMLAtoms::mozDisplayComboboxControlFrame,//nsHTMLAtoms::textPseudo, - styleContext, - PR_FALSE, - getter_AddRefs(textStyleContext)); + rv = aPresContext->ResolveStyleContextForNonElement( + styleContext, + PR_FALSE, + getter_AddRefs(textStyleContext)); if (NS_FAILED(rv)) { return rv; } if (!textStyleContext) { return NS_ERROR_NULL_POINTER; } diff --git a/mozilla/layout/forms/nsGfxButtonControlFrame.cpp b/mozilla/layout/forms/nsGfxButtonControlFrame.cpp index 4f72bc535ae..14ef47f3939 100644 --- a/mozilla/layout/forms/nsGfxButtonControlFrame.cpp +++ b/mozilla/layout/forms/nsGfxButtonControlFrame.cpp @@ -481,11 +481,10 @@ nsGfxButtonControlFrame::CreateFrameFor(nsIPresContext* aPresContext, if (NS_FAILED(rv)) { return rv; } if (!newFrame) { return NS_ERROR_NULL_POINTER; } nsCOMPtr textStyleContext; - rv = aPresContext->ResolvePseudoStyleContextFor(content, - nsHTMLAtoms::textPseudo, - styleContext, - PR_FALSE, - getter_AddRefs(textStyleContext)); + rv = aPresContext->ResolveStyleContextForNonElement( + styleContext, + PR_FALSE, + getter_AddRefs(textStyleContext)); if (NS_FAILED(rv)) { return rv; } if (!textStyleContext) { return NS_ERROR_NULL_POINTER; } diff --git a/mozilla/layout/generic/nsBlockFrame.cpp b/mozilla/layout/generic/nsBlockFrame.cpp index 75f159046f1..7e7c0806c12 100644 --- a/mozilla/layout/generic/nsBlockFrame.cpp +++ b/mozilla/layout/generic/nsBlockFrame.cpp @@ -332,31 +332,30 @@ nsBlockFrame::Destroy(nsIPresContext* aPresContext) NS_IMETHODIMP nsBlockFrame::QueryInterface(const nsIID& aIID, void** aInstancePtr) { - if (NULL == aInstancePtr) { - return NS_ERROR_NULL_POINTER; - } + NS_PRECONDITION(aInstancePtr, "null out param"); if (aIID.Equals(kBlockFrameCID)) { - nsBlockFrame* tmp = this; - *aInstancePtr = (void*) tmp; + *aInstancePtr = NS_STATIC_CAST(void*, NS_STATIC_CAST(nsBlockFrame*, this)); return NS_OK; } - if ( aIID.Equals(NS_GET_IID(nsILineIterator)) || - aIID.Equals(NS_GET_IID(nsILineIteratorNavigator)) ) + if (aIID.Equals(NS_GET_IID(nsILineIterator)) || + aIID.Equals(NS_GET_IID(nsILineIteratorNavigator))) { nsLineIterator* it = new nsLineIterator; if (!it) { *aInstancePtr = nsnull; return NS_ERROR_OUT_OF_MEMORY; } + NS_ADDREF(it); // reference passed to caller const nsStyleVisibility* visibility; GetStyleData(eStyleStruct_Visibility, (const nsStyleStruct*&) visibility); nsresult rv = it->Init(mLines, visibility->mDirection == NS_STYLE_DIRECTION_RTL); if (NS_FAILED(rv)) { - delete it; + NS_RELEASE(it); return rv; } - NS_ADDREF((nsILineIterator *) (*aInstancePtr = (void *) it)); + *aInstancePtr = NS_STATIC_CAST(void*, + NS_STATIC_CAST(nsILineIteratorNavigator*, it)); return NS_OK; } return nsBlockFrameSuper::QueryInterface(aIID, aInstancePtr); @@ -1400,6 +1399,7 @@ nsBlockFrame::ComputeFinalSize(const nsHTMLReflowState& aReflowState, // If we're requested to update our maximum width, then compute it if (aState.GetFlag(BRS_COMPUTEMAXWIDTH)) { // We need to add in for the right border/padding + // XXXldb Why right and not left? aMetrics.mMaximumWidth = aState.mMaximumWidth + borderPadding.right; #ifdef NOISY_MAXIMUM_WIDTH printf("nsBlockFrame::ComputeFinalSize block %p setting aMetrics.mMaximumWidth to %d\n", this, aMetrics.mMaximumWidth); @@ -4060,6 +4060,7 @@ nsBlockFrame::PlaceLine(nsBlockReflowState& aState, nsRect combinedArea; aLineLayout.RelativePositionFrames(combinedArea); // XXXldb This returned width as -15, 2001-06-12, Bugzilla + // XXX Changing the combined area here seems wrong. - LDB aLine->SetCombinedArea(combinedArea); if (addedBullet) { aLineLayout.RemoveBulletFrame(mBullet); @@ -5977,6 +5978,16 @@ nsBlockFrame::Init(nsIPresContext* aPresContext, nsIStyleContext* nsBlockFrame::GetFirstLetterStyle(nsIPresContext* aPresContext) { + // This check is here because nsComboboxControlFrame creates + // nsBlockFrame objects that have an |mContent| pointing to a text + // node. This check ensures we don't try to do selector matching on + // that text node. + // + // XXX This check should go away once we fix nsComboboxControlFrame. + // + if (!mContent->IsContentOfType(nsIContent::eELEMENT)) + return nsnull; + nsIStyleContext* fls; aPresContext->ProbePseudoStyleContextFor(mContent, nsHTMLAtoms::firstLetterPseudo, diff --git a/mozilla/layout/html/base/src/nsBlockFrame.cpp b/mozilla/layout/html/base/src/nsBlockFrame.cpp index 75f159046f1..7e7c0806c12 100644 --- a/mozilla/layout/html/base/src/nsBlockFrame.cpp +++ b/mozilla/layout/html/base/src/nsBlockFrame.cpp @@ -332,31 +332,30 @@ nsBlockFrame::Destroy(nsIPresContext* aPresContext) NS_IMETHODIMP nsBlockFrame::QueryInterface(const nsIID& aIID, void** aInstancePtr) { - if (NULL == aInstancePtr) { - return NS_ERROR_NULL_POINTER; - } + NS_PRECONDITION(aInstancePtr, "null out param"); if (aIID.Equals(kBlockFrameCID)) { - nsBlockFrame* tmp = this; - *aInstancePtr = (void*) tmp; + *aInstancePtr = NS_STATIC_CAST(void*, NS_STATIC_CAST(nsBlockFrame*, this)); return NS_OK; } - if ( aIID.Equals(NS_GET_IID(nsILineIterator)) || - aIID.Equals(NS_GET_IID(nsILineIteratorNavigator)) ) + if (aIID.Equals(NS_GET_IID(nsILineIterator)) || + aIID.Equals(NS_GET_IID(nsILineIteratorNavigator))) { nsLineIterator* it = new nsLineIterator; if (!it) { *aInstancePtr = nsnull; return NS_ERROR_OUT_OF_MEMORY; } + NS_ADDREF(it); // reference passed to caller const nsStyleVisibility* visibility; GetStyleData(eStyleStruct_Visibility, (const nsStyleStruct*&) visibility); nsresult rv = it->Init(mLines, visibility->mDirection == NS_STYLE_DIRECTION_RTL); if (NS_FAILED(rv)) { - delete it; + NS_RELEASE(it); return rv; } - NS_ADDREF((nsILineIterator *) (*aInstancePtr = (void *) it)); + *aInstancePtr = NS_STATIC_CAST(void*, + NS_STATIC_CAST(nsILineIteratorNavigator*, it)); return NS_OK; } return nsBlockFrameSuper::QueryInterface(aIID, aInstancePtr); @@ -1400,6 +1399,7 @@ nsBlockFrame::ComputeFinalSize(const nsHTMLReflowState& aReflowState, // If we're requested to update our maximum width, then compute it if (aState.GetFlag(BRS_COMPUTEMAXWIDTH)) { // We need to add in for the right border/padding + // XXXldb Why right and not left? aMetrics.mMaximumWidth = aState.mMaximumWidth + borderPadding.right; #ifdef NOISY_MAXIMUM_WIDTH printf("nsBlockFrame::ComputeFinalSize block %p setting aMetrics.mMaximumWidth to %d\n", this, aMetrics.mMaximumWidth); @@ -4060,6 +4060,7 @@ nsBlockFrame::PlaceLine(nsBlockReflowState& aState, nsRect combinedArea; aLineLayout.RelativePositionFrames(combinedArea); // XXXldb This returned width as -15, 2001-06-12, Bugzilla + // XXX Changing the combined area here seems wrong. - LDB aLine->SetCombinedArea(combinedArea); if (addedBullet) { aLineLayout.RemoveBulletFrame(mBullet); @@ -5977,6 +5978,16 @@ nsBlockFrame::Init(nsIPresContext* aPresContext, nsIStyleContext* nsBlockFrame::GetFirstLetterStyle(nsIPresContext* aPresContext) { + // This check is here because nsComboboxControlFrame creates + // nsBlockFrame objects that have an |mContent| pointing to a text + // node. This check ensures we don't try to do selector matching on + // that text node. + // + // XXX This check should go away once we fix nsComboboxControlFrame. + // + if (!mContent->IsContentOfType(nsIContent::eELEMENT)) + return nsnull; + nsIStyleContext* fls; aPresContext->ProbePseudoStyleContextFor(mContent, nsHTMLAtoms::firstLetterPseudo, diff --git a/mozilla/layout/html/base/src/nsFrameManager.cpp b/mozilla/layout/html/base/src/nsFrameManager.cpp index 2f9fb945b1a..31a4a0ed2ad 100644 --- a/mozilla/layout/html/base/src/nsFrameManager.cpp +++ b/mozilla/layout/html/base/src/nsFrameManager.cpp @@ -1631,7 +1631,13 @@ FrameManager::ReResolveStyleContext(nsIPresContext* aPresContext, } else { NS_ASSERTION(localContent, "non pseudo-element frame without content node"); - aPresContext->ResolveStyleContextFor(content, aParentContext, PR_TRUE, &newContext); + if (content->IsContentOfType(nsIContent::eELEMENT)) { + aPresContext->ResolveStyleContextFor(content, aParentContext, + PR_TRUE, &newContext); + } else { + aPresContext->ResolveStyleContextForNonElement(aParentContext, + PR_TRUE, &newContext); + } } NS_ASSERTION(newContext, "failed to get new style context"); if (newContext) { @@ -1845,7 +1851,13 @@ FrameManager::ReResolveStyleContext(nsIPresContext* aPresContext, } else { NS_ASSERTION(localContent, "non pseudo-element frame without content node"); - aPresContext->ResolveStyleContextFor(content, aParentContext, PR_TRUE, &newContext); + if (content->IsContentOfType(nsIContent::eELEMENT)) { + aPresContext->ResolveStyleContextFor(content, aParentContext, + PR_TRUE, &newContext); + } else { + aPresContext->ResolveStyleContextForNonElement(aParentContext, + PR_TRUE, &newContext); + } } NS_ASSERTION(newContext, "failed to get new style context"); if (newContext) { @@ -1927,13 +1939,20 @@ FrameManager::ReResolveStyleContext(nsIPresContext* aPresContext, nsIStyleContext* undisplayedContext = nsnull; undisplayed->mStyle->GetPseudoType(pseudoTag); if (undisplayed->mContent && pseudoTag == nsnull) { // child content - aPresContext->ResolveStyleContextFor(undisplayed->mContent, newContext, - PR_TRUE, &undisplayedContext); + if (undisplayed->mContent->IsContentOfType(nsIContent::eELEMENT)) { + aPresContext->ResolveStyleContextFor(undisplayed->mContent, + newContext, + PR_TRUE, &undisplayedContext); + } else { + aPresContext->ResolveStyleContextForNonElement(newContext, + PR_TRUE, &undisplayedContext); + } } else { // pseudo element NS_ASSERTION(pseudoTag, "pseudo element without tag"); - aPresContext->ResolvePseudoStyleContextFor(localContent, pseudoTag, newContext, PR_FALSE, - &undisplayedContext); + aPresContext->ResolvePseudoStyleContextFor(localContent, pseudoTag, + newContext, PR_FALSE, + &undisplayedContext); } NS_IF_RELEASE(pseudoTag); if (undisplayedContext) { diff --git a/mozilla/layout/html/document/src/forms.css b/mozilla/layout/html/document/src/forms.css index a9b6c7507a7..d471bfe2755 100644 --- a/mozilla/layout/html/document/src/forms.css +++ b/mozilla/layout/html/document/src/forms.css @@ -217,7 +217,7 @@ input[disabled], textarea[disabled], option[disabled], select[disabled], -select[disabled] > :-moz-display-comboboxcontrol-frame { +select[disabled]:-moz-display-comboboxcontrol-frame { color: GrayText; cursor: default; } diff --git a/mozilla/layout/html/document/src/html.css b/mozilla/layout/html/document/src/html.css index 73e8c070f2d..5bbcba2b081 100644 --- a/mozilla/layout/html/document/src/html.css +++ b/mozilla/layout/html/document/src/html.css @@ -432,7 +432,7 @@ noframes { /* hidden elements */ area, base, basefont, head, meta, script, style, title, -noembed, noscript, param, *|*:-moz-comment, *|*:-moz-pi { +noembed, noscript, param { display: none; } diff --git a/mozilla/layout/html/forms/src/nsComboboxControlFrame.cpp b/mozilla/layout/html/forms/src/nsComboboxControlFrame.cpp index 36d1b0b1fbd..8fdc9c96e1b 100644 --- a/mozilla/layout/html/forms/src/nsComboboxControlFrame.cpp +++ b/mozilla/layout/html/forms/src/nsComboboxControlFrame.cpp @@ -2269,11 +2269,10 @@ nsComboboxControlFrame::CreateDisplayFrame(nsIPresContext* aPresContext) if (NS_FAILED(rv)) { return rv; } if (!mTextFrame) { return NS_ERROR_NULL_POINTER; } nsCOMPtr textStyleContext; - rv = aPresContext->ResolvePseudoStyleContextFor(mContent, - nsHTMLAtoms::mozDisplayComboboxControlFrame, - styleContext, - PR_FALSE, - getter_AddRefs(textStyleContext)); + rv = aPresContext->ResolveStyleContextForNonElement( + styleContext, + PR_FALSE, + getter_AddRefs(textStyleContext)); if (NS_FAILED(rv)) { return rv; } if (!textStyleContext) { return NS_ERROR_NULL_POINTER; } nsCOMPtr content(do_QueryInterface(mDisplayContent)); @@ -2325,11 +2324,10 @@ nsComboboxControlFrame::CreateAnonymousContent(nsIPresContext* aPresContext, // Add a child text content node for the label nsresult result; nsCOMPtr labelContent(do_CreateInstance(kTextNodeCID,&result)); - nsAutoString value; value.AssignWithConversion("X"); if (NS_SUCCEEDED(result) && labelContent) { // set the value of the text node mDisplayContent = do_QueryInterface(labelContent); - mDisplayContent->SetText(value.get(), value.Length(), PR_TRUE); + mDisplayContent->SetText(NS_LITERAL_STRING("X"), PR_TRUE); nsCOMPtr doc; mContent->GetDocument(*getter_AddRefs(doc)); @@ -2400,7 +2398,7 @@ nsComboboxControlFrame::CreateFrameFor(nsIPresContext* aPresContext, // create the style context for the anonymous block frame nsCOMPtr styleContext; - rv = aPresContext->ResolvePseudoStyleContextFor(content, + rv = aPresContext->ResolvePseudoStyleContextFor(mContent, nsHTMLAtoms::mozDisplayComboboxControlFrame, mStyleContext, PR_FALSE, @@ -2413,11 +2411,10 @@ nsComboboxControlFrame::CreateFrameFor(nsIPresContext* aPresContext, if (NS_FAILED(rv)) { return rv; } if (!mTextFrame) { return NS_ERROR_NULL_POINTER; } nsCOMPtr textStyleContext; - rv = aPresContext->ResolvePseudoStyleContextFor(content, - nsHTMLAtoms::mozDisplayComboboxControlFrame,//nsHTMLAtoms::textPseudo, - styleContext, - PR_FALSE, - getter_AddRefs(textStyleContext)); + rv = aPresContext->ResolveStyleContextForNonElement( + styleContext, + PR_FALSE, + getter_AddRefs(textStyleContext)); if (NS_FAILED(rv)) { return rv; } if (!textStyleContext) { return NS_ERROR_NULL_POINTER; } diff --git a/mozilla/layout/html/forms/src/nsGfxButtonControlFrame.cpp b/mozilla/layout/html/forms/src/nsGfxButtonControlFrame.cpp index 4f72bc535ae..14ef47f3939 100644 --- a/mozilla/layout/html/forms/src/nsGfxButtonControlFrame.cpp +++ b/mozilla/layout/html/forms/src/nsGfxButtonControlFrame.cpp @@ -481,11 +481,10 @@ nsGfxButtonControlFrame::CreateFrameFor(nsIPresContext* aPresContext, if (NS_FAILED(rv)) { return rv; } if (!newFrame) { return NS_ERROR_NULL_POINTER; } nsCOMPtr textStyleContext; - rv = aPresContext->ResolvePseudoStyleContextFor(content, - nsHTMLAtoms::textPseudo, - styleContext, - PR_FALSE, - getter_AddRefs(textStyleContext)); + rv = aPresContext->ResolveStyleContextForNonElement( + styleContext, + PR_FALSE, + getter_AddRefs(textStyleContext)); if (NS_FAILED(rv)) { return rv; } if (!textStyleContext) { return NS_ERROR_NULL_POINTER; } diff --git a/mozilla/layout/html/style/src/nsCSSFrameConstructor.cpp b/mozilla/layout/html/style/src/nsCSSFrameConstructor.cpp index 0bccf9268b6..b4e790b6d0e 100644 --- a/mozilla/layout/html/style/src/nsCSSFrameConstructor.cpp +++ b/mozilla/layout/html/style/src/nsCSSFrameConstructor.cpp @@ -1433,6 +1433,9 @@ nsCSSFrameConstructor::CreateGeneratedContentFrame(nsIPresShell* aPresShe { *aResult = nsnull; // initialize OUT parameter + if (!aContent->IsContentOfType(nsIContent::eELEMENT)) + return PR_FALSE; + // Probe for the existence of the pseudo-element nsCOMPtr pseudoStyleContext; aPresContext->ProbePseudoStyleContextFor(aContent, aPseudoElement, aStyleContext, @@ -1476,9 +1479,9 @@ nsCSSFrameConstructor::CreateGeneratedContentFrame(nsIPresShell* aPresShe // Create another pseudo style context to use for all the generated child // frames nsIStyleContext* textStyleContext; - aPresContext->ResolvePseudoStyleContextFor(aContent, nsHTMLAtoms::textPseudo, - pseudoStyleContext, PR_FALSE, - &textStyleContext); + aPresContext->ResolveStyleContextForNonElement( + pseudoStyleContext, PR_FALSE, + &textStyleContext); // Now create content objects (and child frames) for each value of the // 'content' property @@ -2937,8 +2940,12 @@ nsCSSFrameConstructor::TableProcessChildren(nsIPresShell* aPresShell, iter != last; ++iter) { nsCOMPtr childContent = *iter; - if (childContent && NeedFrameFor(aParentFrame, childContent)) { - rv = TableProcessChild(aPresShell, aPresContext, aState, *childContent, aParentFrame, + if (childContent && + (childContent->IsContentOfType(nsIContent::eELEMENT) || + childContent->IsContentOfType(nsIContent::eTEXT)) && + NeedFrameFor(aParentFrame, childContent)) { + rv = TableProcessChild(aPresShell, aPresContext, aState, childContent, + aContent, aParentFrame, parentFrameType, parentStyleContext, aTableCreator, aChildItems, aCaption); } @@ -2958,7 +2965,8 @@ nsresult nsCSSFrameConstructor::TableProcessChild(nsIPresShell* aPresShell, nsIPresContext* aPresContext, nsFrameConstructorState& aState, - nsIContent& aChildContent, + nsIContent* aChildContent, + nsIContent* aParentContent, nsIFrame* aParentFrame, nsIAtom* aParentFrameType, nsIStyleContext* aParentStyleContext, @@ -2975,15 +2983,15 @@ nsCSSFrameConstructor::TableProcessChild(nsIPresShell* aPresShell, nsCOMPtr childStyleContext; // Resolve the style context and get its display - aPresContext->ResolveStyleContextFor(&aChildContent, aParentStyleContext, PR_FALSE, - getter_AddRefs(childStyleContext)); + ResolveStyleContext(aPresContext, aParentFrame, aChildContent, + getter_AddRefs(childStyleContext)); const nsStyleDisplay* styleDisplay = (const nsStyleDisplay*) childStyleContext->GetStyleData(eStyleStruct_Display); switch (styleDisplay->mDisplay) { case NS_STYLE_DISPLAY_TABLE: nsIFrame* innerTableFrame; - rv = ConstructTableFrame(aPresShell, aPresContext, aState, &aChildContent, aParentFrame, + rv = ConstructTableFrame(aPresShell, aPresContext, aState, aChildContent, aParentFrame, childStyleContext, aTableCreator, PR_FALSE, aChildItems, childFrame, innerTableFrame, isPseudoParent); break; @@ -2991,7 +2999,7 @@ nsCSSFrameConstructor::TableProcessChild(nsIPresShell* aPresShell, case NS_STYLE_DISPLAY_TABLE_CAPTION: if (!aCaption) { // only allow one caption nsIFrame* parentFrame = GetOuterTableFrame(aParentFrame); - rv = ConstructTableCaptionFrame(aPresShell, aPresContext, aState, &aChildContent, + rv = ConstructTableCaptionFrame(aPresShell, aPresContext, aState, aChildContent, parentFrame, childStyleContext, aTableCreator, aChildItems, aCaption, isPseudoParent); } @@ -2999,7 +3007,7 @@ nsCSSFrameConstructor::TableProcessChild(nsIPresShell* aPresShell, break; case NS_STYLE_DISPLAY_TABLE_COLUMN_GROUP: - rv = ConstructTableColGroupFrame(aPresShell, aPresContext, aState, &aChildContent, + rv = ConstructTableColGroupFrame(aPresShell, aPresContext, aState, aChildContent, aParentFrame, childStyleContext, aTableCreator, PR_FALSE, aChildItems, childFrame, isPseudoParent); break; @@ -3007,19 +3015,19 @@ nsCSSFrameConstructor::TableProcessChild(nsIPresShell* aPresShell, case NS_STYLE_DISPLAY_TABLE_HEADER_GROUP: case NS_STYLE_DISPLAY_TABLE_FOOTER_GROUP: case NS_STYLE_DISPLAY_TABLE_ROW_GROUP: - rv = ConstructTableRowGroupFrame(aPresShell, aPresContext, aState, &aChildContent, + rv = ConstructTableRowGroupFrame(aPresShell, aPresContext, aState, aChildContent, aParentFrame, childStyleContext, aTableCreator, PR_FALSE, aChildItems, childFrame, isPseudoParent); break; case NS_STYLE_DISPLAY_TABLE_ROW: - rv = ConstructTableRowFrame(aPresShell, aPresContext, aState, &aChildContent, + rv = ConstructTableRowFrame(aPresShell, aPresContext, aState, aChildContent, aParentFrame, childStyleContext, aTableCreator, PR_FALSE, aChildItems, childFrame, isPseudoParent); break; case NS_STYLE_DISPLAY_TABLE_COLUMN: - rv = ConstructTableColFrame(aPresShell, aPresContext, aState, &aChildContent, + rv = ConstructTableColFrame(aPresShell, aPresContext, aState, aChildContent, aParentFrame, childStyleContext, aTableCreator, PR_FALSE, aChildItems, childFrame, isPseudoParent); break; @@ -3027,13 +3035,16 @@ nsCSSFrameConstructor::TableProcessChild(nsIPresShell* aPresShell, case NS_STYLE_DISPLAY_TABLE_CELL: nsIFrame* innerCell; - rv = ConstructTableCellFrame(aPresShell, aPresContext, aState, &aChildContent, + rv = ConstructTableCellFrame(aPresShell, aPresContext, aState, aChildContent, aParentFrame, childStyleContext, aTableCreator, PR_FALSE, aChildItems, childFrame, innerCell, isPseudoParent); break; + case NS_STYLE_DISPLAY_NONE: + break; + default: - rv = ConstructTableForeignFrame(aPresShell, aPresContext, aState, &aChildContent, + rv = ConstructTableForeignFrame(aPresShell, aPresContext, aState, aChildContent, aParentFrame, childStyleContext, aTableCreator, aChildItems, childFrame, isPseudoParent); break; @@ -3230,9 +3241,8 @@ nsCSSFrameConstructor::ConstructDocElementFrame(nsIPresShell* aPresShell, } if (resolveStyle) { - nsCOMPtr tag; - aDocElement->GetTag(*getter_AddRefs(tag)); - rv = ResolveStyleContext(aPresContext, aParentFrame, aDocElement, tag, getter_AddRefs(styleContext)); + rv = ResolveStyleContext(aPresContext, aParentFrame, aDocElement, + getter_AddRefs(styleContext)); if (NS_FAILED(rv)) return rv; } @@ -6506,7 +6516,6 @@ nsresult nsCSSFrameConstructor::ResolveStyleContext(nsIPresContext* aPresContext, nsIFrame* aParentFrame, nsIContent* aContent, - nsIAtom* aTag, nsIStyleContext** aStyleContext) { nsresult rv = NS_OK; @@ -6515,43 +6524,23 @@ nsCSSFrameConstructor::ResolveStyleContext(nsIPresContext* aPresContext, nsCOMPtr parentStyleContext; aParentFrame->GetStyleContext(getter_AddRefs(parentStyleContext)); - if (nsLayoutAtoms::textTagName == aTag) { - // Use a special pseudo element style context for text - nsCOMPtr parentContent; - if (nsnull != aParentFrame) { - aParentFrame->GetContent(getter_AddRefs(parentContent)); - } - rv = aPresContext->ResolvePseudoStyleContextFor(parentContent, - nsHTMLAtoms::textPseudo, - parentStyleContext, - PR_FALSE, - aStyleContext); - } else if (nsLayoutAtoms::commentTagName == aTag) { - // Use a special pseudo element style context for comments - nsCOMPtr parentContent; - if (nsnull != aParentFrame) { - aParentFrame->GetContent(getter_AddRefs(parentContent)); - } - rv = aPresContext->ResolvePseudoStyleContextFor(parentContent, - nsHTMLAtoms::commentPseudo, - parentStyleContext, - PR_FALSE, - aStyleContext); - } else if (nsLayoutAtoms::processingInstructionTagName == aTag) { - // Use a special pseudo element style context for comments - nsCOMPtr parentContent; - if (nsnull != aParentFrame) { - aParentFrame->GetContent(getter_AddRefs(parentContent)); - } - rv = aPresContext->ResolvePseudoStyleContextFor(parentContent, - nsHTMLAtoms::processingInstructionPseudo, - parentStyleContext, - PR_FALSE, - aStyleContext); - } else { + if (aContent->IsContentOfType(nsIContent::eELEMENT)) { rv = aPresContext->ResolveStyleContextFor(aContent, parentStyleContext, PR_FALSE, aStyleContext); + } else { +#ifdef DEBUG + { + nsCOMPtr tag; + aContent->GetTag(*getter_AddRefs(tag)); + NS_ASSERTION(tag == nsLayoutAtoms::textTagName, + "shouldn't waste time creating style contexts for " + "comments and processing instructions"); + } +#endif + rv = aPresContext->ResolveStyleContextForNonElement(parentStyleContext, + PR_FALSE, + aStyleContext); } return rv; } @@ -6926,8 +6915,14 @@ nsCSSFrameConstructor::ConstructFrame(nsIPresShell* aPresShell, nsCOMPtr tag; aContent->GetTag(*getter_AddRefs(tag)); + // never create frames for comments on PIs + if (tag == nsLayoutAtoms::commentTagName || + tag == nsLayoutAtoms::processingInstructionTagName) + return rv; + nsCOMPtr styleContext; - rv = ResolveStyleContext(aPresContext, aParentFrame, aContent, tag, getter_AddRefs(styleContext)); + rv = ResolveStyleContext(aPresContext, aParentFrame, aContent, + getter_AddRefs(styleContext)); if (NS_SUCCEEDED(rv)) { @@ -6984,7 +6979,8 @@ nsCSSFrameConstructor::ConstructFrameInternal( nsIPresShell* aPresShe return NS_OK; if (resolveStyle) { - rv = ResolveStyleContext(aPresContext, aParentFrame, aContent, aTag, getter_AddRefs(styleContext)); + rv = ResolveStyleContext(aPresContext, aParentFrame, aContent, + getter_AddRefs(styleContext)); if (NS_FAILED(rv)) return rv; } @@ -8294,6 +8290,9 @@ nsCSSFrameConstructor::ContentInserted(nsIPresContext* aPresContext, PRInt32 aIndexInContainer, nsILayoutHistoryState* aFrameState) { + // XXXldb Do we need to re-resolve style to handle the CSS2 + combinator and + // the :empty pseudo-class? + #ifdef DEBUG if (gNoisyContentUpdates) { printf("nsCSSFrameConstructor::ContentInserted container=%p child=%p index=%d\n", @@ -8360,9 +8359,8 @@ nsCSSFrameConstructor::ContentInserted(nsIPresContext* aPresContext, // to check it for subsequent display changes (e.g., when you next // reopen). nsCOMPtr styleContext; - nsCOMPtr tagName; - aChild->GetTag(*getter_AddRefs(tagName)); - ResolveStyleContext(aPresContext, innerFrame, aChild, tagName, getter_AddRefs(styleContext)); + ResolveStyleContext(aPresContext, innerFrame, aChild, + getter_AddRefs(styleContext)); // Pre-check for display "none" - if we find that, don't reflow at all. const nsStyleDisplay* display = (const nsStyleDisplay*) @@ -8998,6 +8996,9 @@ nsCSSFrameConstructor::ContentRemoved(nsIPresContext* aPresContext, nsIContent* aChild, PRInt32 aIndexInContainer) { + // XXXldb Do we need to re-resolve style to handle the CSS2 + combinator and + // the :empty pseudo-class? + #ifdef DEBUG if (gNoisyContentUpdates) { printf("nsCSSFrameConstructor::ContentRemoved container=%p child=%p index=%d\n", @@ -10295,9 +10296,8 @@ nsCSSFrameConstructor::ConstructAlternateFrame(nsIPresShell* aPresShell, nsIStyleContext* textStyleContext; NS_NewTextFrame(aPresShell, &textFrame); - aPresContext->ResolvePseudoStyleContextFor(aContent, nsHTMLAtoms::textPseudo, - aStyleContext, PR_FALSE, - &textStyleContext); + aPresContext->ResolveStyleContextForNonElement(aStyleContext, PR_FALSE, + &textStyleContext); textFrame->Init(aPresContext, altTextContent, containerFrame, textStyleContext, nsnull); @@ -12528,15 +12528,9 @@ nsCSSFrameConstructor::CreateTreeWidgetContent(nsIPresContext* aPresContext, GetFloaterContainingBlock(aPresContext, aParentFrame), mTempFrameTreeState); - // Get the element's tag - nsCOMPtr tag; - aChild->GetTag(*getter_AddRefs(tag)); - - PRInt32 namespaceID; - aChild->GetNameSpaceID(namespaceID); - nsCOMPtr styleContext; - rv = ResolveStyleContext(aPresContext, aParentFrame, aChild, tag, getter_AddRefs(styleContext)); + rv = ResolveStyleContext(aPresContext, aParentFrame, aChild, + getter_AddRefs(styleContext)); if (NS_SUCCEEDED(rv)) { // Pre-check for display "none" - only if we find that, do we create @@ -12550,6 +12544,12 @@ nsCSSFrameConstructor::CreateTreeWidgetContent(nsIPresContext* aPresContext, } } + nsCOMPtr tag; + aChild->GetTag(*getter_AddRefs(tag)); + + PRInt32 namespaceID; + aChild->GetNameSpaceID(namespaceID); + rv = ConstructFrameInternal(shell, aPresContext, state, aChild, aParentFrame, tag, namespaceID, styleContext, frameItems, PR_FALSE); diff --git a/mozilla/layout/html/style/src/nsCSSFrameConstructor.h b/mozilla/layout/html/style/src/nsCSSFrameConstructor.h index 75aeabed2b1..20489d101c9 100644 --- a/mozilla/layout/html/style/src/nsCSSFrameConstructor.h +++ b/mozilla/layout/html/style/src/nsCSSFrameConstructor.h @@ -192,7 +192,6 @@ protected: nsresult ResolveStyleContext(nsIPresContext* aPresContext, nsIFrame* aParentFrame, nsIContent* aContent, - nsIAtom* aTag, nsIStyleContext** aStyleContext); nsresult ConstructFrame(nsIPresShell* aPresShell, @@ -427,7 +426,8 @@ protected: nsresult TableProcessChild(nsIPresShell* aPresShell, nsIPresContext* aPresContext, nsFrameConstructorState& aState, - nsIContent& aChildContent, + nsIContent* aChildContent, + nsIContent* aParentContent, nsIFrame* aParentFrame, nsIAtom* aParentFrameType, nsIStyleContext* aParentStyleContext, diff --git a/mozilla/layout/style/forms.css b/mozilla/layout/style/forms.css index a9b6c7507a7..d471bfe2755 100644 --- a/mozilla/layout/style/forms.css +++ b/mozilla/layout/style/forms.css @@ -217,7 +217,7 @@ input[disabled], textarea[disabled], option[disabled], select[disabled], -select[disabled] > :-moz-display-comboboxcontrol-frame { +select[disabled]:-moz-display-comboboxcontrol-frame { color: GrayText; cursor: default; } diff --git a/mozilla/layout/style/html.css b/mozilla/layout/style/html.css index 73e8c070f2d..5bbcba2b081 100644 --- a/mozilla/layout/style/html.css +++ b/mozilla/layout/style/html.css @@ -432,7 +432,7 @@ noframes { /* hidden elements */ area, base, basefont, head, meta, script, style, title, -noembed, noscript, param, *|*:-moz-comment, *|*:-moz-pi { +noembed, noscript, param { display: none; } diff --git a/mozilla/layout/style/nsCSSStyleSheet.cpp b/mozilla/layout/style/nsCSSStyleSheet.cpp index 8a346affb04..ca2b3851590 100644 --- a/mozilla/layout/style/nsCSSStyleSheet.cpp +++ b/mozilla/layout/style/nsCSSStyleSheet.cpp @@ -3226,7 +3226,8 @@ MOZ_DECL_CTOR_COUNTER(SelectorMatchesData) struct SelectorMatchesData { SelectorMatchesData(nsIPresContext* aPresContext, nsIContent* aContent, - nsRuleWalker* aRuleWalker, nsCompatibility* aCompat = nsnull); + nsRuleWalker* aRuleWalker, + nsCompatibility* aCompat = nsnull); virtual ~SelectorMatchesData() { @@ -3274,12 +3275,16 @@ struct SelectorMatchesData { SelectorMatchesData* mParentData; }; -SelectorMatchesData::SelectorMatchesData(nsIPresContext* aPresContext, nsIContent* aContent, - nsRuleWalker* aRuleWalker, - nsCompatibility* aCompat /*= nsnull*/) +SelectorMatchesData::SelectorMatchesData(nsIPresContext* aPresContext, + nsIContent* aContent, + nsRuleWalker* aRuleWalker, + nsCompatibility* aCompat /*= nsnull*/) { MOZ_COUNT_CTOR(SelectorMatchesData); + NS_ASSERTION(!aContent || aContent->IsContentOfType(nsIContent::eELEMENT), + "non-element leaked into SelectorMatches"); + mPresContext = aPresContext; mContent = aContent; mParentContent = nsnull; @@ -3404,7 +3409,7 @@ static PRBool ValueIncludes(const nsString& aValueList, const nsString& aValue, return PR_FALSE; } -static PRBool IsEventPseudo(nsIAtom* aAtom) +inline PRBool IsEventPseudo(nsIAtom* aAtom) { return PRBool ((nsCSSAtoms::activePseudo == aAtom) || (nsCSSAtoms::dragOverPseudo == aAtom) || @@ -3414,14 +3419,14 @@ static PRBool IsEventPseudo(nsIAtom* aAtom) // XXX selected, enabled, disabled, selection? } -static PRBool IsLinkPseudo(nsIAtom* aAtom) +inline PRBool IsLinkPseudo(nsIAtom* aAtom) { return PRBool ((nsCSSAtoms::linkPseudo == aAtom) || (nsCSSAtoms::visitedPseudo == aAtom) || (nsCSSAtoms::anyLinkPseudo == aAtom)); } -static PRBool PR_CALLBACK IsEventSensitive(nsIAtom *aPseudo, nsIAtom *aContentTag, PRBool aSelectorIsGlobal) +inline PRBool IsEventSensitive(nsIAtom *aPseudo, nsIAtom *aContentTag, PRBool aSelectorIsGlobal) { // if the selector is global, meaning it is not tied to a tag, then // we restrict the application of the event pseudo to the following tags @@ -3433,11 +3438,7 @@ static PRBool PR_CALLBACK IsEventSensitive(nsIAtom *aPseudo, nsIAtom *aContentTa (nsHTMLAtoms::li == aContentTag) || (nsHTMLAtoms::label == aContentTag) || (nsHTMLAtoms::select == aContentTag) || - (nsHTMLAtoms::textarea == aContentTag) || - (nsHTMLAtoms::textPseudo == aContentTag) || - // We require a Layout Atom too - (nsLayoutAtoms::textTagName == aContentTag) - ); + (nsHTMLAtoms::textarea == aContentTag)); } else { // selector is not global, so apply the event pseudo to everything except HTML and BODY return PRBool ((nsHTMLAtoms::html != aContentTag) && @@ -3952,6 +3953,8 @@ CSSRuleProcessor::RulesMatching(nsIPresContext* aPresContext, NS_PRECONDITION(nsnull != aPresContext, "null arg"); NS_PRECONDITION(nsnull != aContent, "null arg"); NS_PRECONDITION(nsnull != aRuleWalker, "null arg"); + NS_PRECONDITION(aContent->IsContentOfType(nsIContent::eELEMENT), + "content must be element"); RuleCascadeData* cascade = GetRuleCascade(aPresContext, aMedium); @@ -4066,6 +4069,9 @@ CSSRuleProcessor::RulesMatching(nsIPresContext* aPresContext, NS_PRECONDITION(nsnull != aPresContext, "null arg"); NS_PRECONDITION(nsnull != aPseudoTag, "null arg"); NS_PRECONDITION(nsnull != aRuleWalker, "null arg"); + NS_PRECONDITION(!aParentContent || + aParentContent->IsContentOfType(nsIContent::eELEMENT), + "content (if present) must be element"); RuleCascadeData* cascade = GetRuleCascade(aPresContext, aMedium); @@ -4116,6 +4122,9 @@ CSSRuleProcessor::HasStateDependentStyle(nsIPresContext* aPresContext, nsIAtom* aMedium, nsIContent* aContent) { + NS_PRECONDITION(aContent->IsContentOfType(nsIContent::eELEMENT), + "content must be element"); + PRBool isStateful = PR_FALSE; RuleCascadeData* cascade = GetRuleCascade(aPresContext, aMedium); @@ -4288,7 +4297,6 @@ CSSRuleProcessor::ClearRuleCascades(void) delete data; data = next; } - mRuleCascades = nsnull; return NS_OK; } @@ -4302,7 +4310,7 @@ PRBool BuildHashEnum(nsISupports* aRule, void* aHash) return PR_TRUE; } -static +inline PRBool IsStateSelector(nsCSSSelector& aSelector) { nsAtomList* pseudoClass = aSelector.mPseudoClassList; diff --git a/mozilla/layout/style/nsStyleSet.cpp b/mozilla/layout/style/nsStyleSet.cpp index f3a1c866fbf..453900ec559 100644 --- a/mozilla/layout/style/nsStyleSet.cpp +++ b/mozilla/layout/style/nsStyleSet.cpp @@ -118,6 +118,11 @@ public: nsIStyleContext* aParentContext, PRBool aForceUnique = PR_FALSE); + virtual nsIStyleContext* ResolveStyleForNonElement( + nsIPresContext* aPresContext, + nsIStyleContext* aParentContext, + PRBool aForceUnique = PR_FALSE); + virtual nsIStyleContext* ResolvePseudoStyleFor(nsIPresContext* aPresContext, nsIContent* aParentContent, nsIAtom* aPseudoTag, @@ -856,6 +861,8 @@ nsIStyleContext* StyleSetImpl::ResolveStyleFor(nsIPresContext* aPresContext, NS_ASSERTION(aContent, "must have content"); NS_ASSERTION(aPresContext, "must have pres context"); + NS_ASSERTION(aContent->IsContentOfType(nsIContent::eELEMENT), + "content must be element"); if (aContent && aPresContext) { GatherRuleProcessors(); @@ -881,6 +888,35 @@ nsIStyleContext* StyleSetImpl::ResolveStyleFor(nsIPresContext* aPresContext, return result; } +nsIStyleContext* StyleSetImpl::ResolveStyleForNonElement( + nsIPresContext* aPresContext, + nsIStyleContext* aParentContext, + PRBool aForceUnique) +{ + MOZ_TIMER_DEBUGLOG(("Start: StyleSetImpl::ResolveStyleForNonElement(), this=%p\n", this)); + STYLESET_START_TIMER(NS_TIMER_STYLE_RESOLUTION); + + nsIStyleContext* result = nsnull; + + NS_ASSERTION(aPresContext, "must have pres context"); + + if (aPresContext) { + GatherRuleProcessors(); + if (mBackstopRuleProcessors || + mDocRuleProcessors || + mOverrideRuleProcessors) { + EnsureRuleWalker(aPresContext); + result = GetContext(aPresContext, aParentContext, nsnull, aForceUnique); + NS_ASSERTION(mRuleWalker->AtRoot(), "rule walker must be at root"); + } + } + + MOZ_TIMER_DEBUGLOG(("Stop: StyleSetImpl::ResolveStyleForNonElement(), this=%p\n", this)); + STYLESET_STOP_TIMER(NS_TIMER_STYLE_RESOLUTION); + return result; +} + + struct PseudoRulesMatchingData { PseudoRulesMatchingData(nsIPresContext* aPresContext, nsIAtom* aMedium, @@ -933,6 +969,9 @@ nsIStyleContext* StyleSetImpl::ResolvePseudoStyleFor(nsIPresContext* aPresContex NS_ASSERTION(aPseudoTag, "must have pseudo tag"); NS_ASSERTION(aPresContext, "must have pres context"); + NS_ASSERTION(!aParentContent || + aParentContent->IsContentOfType(nsIContent::eELEMENT), + "content (if non-null) must be element"); if (aPseudoTag && aPresContext) { GatherRuleProcessors(); @@ -972,6 +1011,9 @@ nsIStyleContext* StyleSetImpl::ProbePseudoStyleFor(nsIPresContext* aPresContext, NS_ASSERTION(aPseudoTag, "must have pseudo tag"); NS_ASSERTION(aPresContext, "must have pres context"); + NS_ASSERTION(!aParentContent || + aParentContent->IsContentOfType(nsIContent::eELEMENT), + "content (if non-null) must be element"); if (aPseudoTag && aPresContext) { GatherRuleProcessors(); @@ -1168,7 +1210,11 @@ StyleSetImpl::HasStateDependentStyle(nsIPresContext* aPresContext, nsIContent* aContent) { GatherRuleProcessors(); - if (mBackstopRuleProcessors || mDocRuleProcessors || mOverrideRuleProcessors) { + + if (aContent->IsContentOfType(nsIContent::eELEMENT) && + (mBackstopRuleProcessors || + mDocRuleProcessors || + mOverrideRuleProcessors)) { nsIAtom* medium = nsnull; aPresContext->GetMedium(&medium); StatefulData data(aPresContext, medium, aContent);