From c3acb8ce317afe53705615ba8b259491320ba22f Mon Sep 17 00:00:00 2001 From: Robert O'Callahan Date: Wed, 7 Oct 2009 17:28:41 +1300 Subject: [PATCH] Bug 476547. Make lquote and rquote actually work, especially when there are dynamic changes, by finding the correct text frames to modify and notifying the text frame that the DOM text has changed. r=karlt --- layout/mathml/crashtests/476547-1.xhtml | 5 +++ layout/mathml/crashtests/crashtests.list | 1 + layout/mathml/nsMathMLTokenFrame.cpp | 53 +++++++++-------------- layout/mathml/nsMathMLTokenFrame.h | 2 +- layout/reftests/mathml/quotes-1-ref.xhtml | 9 ++++ layout/reftests/mathml/quotes-1.xhtml | 23 ++++++++++ layout/reftests/mathml/reftest.list | 7 +-- 7 files changed, 63 insertions(+), 37 deletions(-) create mode 100644 layout/mathml/crashtests/476547-1.xhtml create mode 100644 layout/reftests/mathml/quotes-1-ref.xhtml create mode 100644 layout/reftests/mathml/quotes-1.xhtml diff --git a/layout/mathml/crashtests/476547-1.xhtml b/layout/mathml/crashtests/476547-1.xhtml new file mode 100644 index 000000000000..0cece35eaa39 --- /dev/null +++ b/layout/mathml/crashtests/476547-1.xhtml @@ -0,0 +1,5 @@ + + + + + diff --git a/layout/mathml/crashtests/crashtests.list b/layout/mathml/crashtests/crashtests.list index 20b5d7039802..2920040a5af1 100644 --- a/layout/mathml/crashtests/crashtests.list +++ b/layout/mathml/crashtests/crashtests.list @@ -47,3 +47,4 @@ load 420420-1.xhtml load 443089-1.xhtml load 463763-1.xhtml load 463763-2.xhtml +load 476547-1.xhtml diff --git a/layout/mathml/nsMathMLTokenFrame.cpp b/layout/mathml/nsMathMLTokenFrame.cpp index 48fbffe94829..829e073a7bc7 100644 --- a/layout/mathml/nsMathMLTokenFrame.cpp +++ b/layout/mathml/nsMathMLTokenFrame.cpp @@ -142,7 +142,7 @@ nsMathMLTokenFrame::SetInitialChildList(nsIAtom* aListName, if (NS_FAILED(rv)) return rv; - SetQuotes(); + SetQuotes(PR_FALSE); ProcessTextData(); return rv; } @@ -259,7 +259,7 @@ nsMathMLTokenFrame::AttributeChanged(PRInt32 aNameSpaceID, { if (nsGkAtoms::lquote_ == aAttribute || nsGkAtoms::rquote_ == aAttribute) { - SetQuotes(); + SetQuotes(PR_TRUE); } return nsMathMLContainerFrame:: @@ -378,57 +378,44 @@ nsMathMLTokenFrame::SetTextStyle() // So the main idea in this code is to see if there are lquote and // rquote attributes. If these are there, we ovewrite the default // quotes in the text frames. +// XXX this is somewhat bogus, we probably should map lquote and rquote +// to 'content' style rules // // But what if the mathml.css file wasn't loaded? // We also check that we are not relying on null pointers... static void -SetQuote(nsIFrame* aFrame, - nsString& aValue) +SetQuote(nsIFrame* aFrame, nsString& aValue, PRBool aNotify) { - nsIFrame* textFrame; - do { - // walk down the hierarchy of first children because they could be wrapped - textFrame = aFrame->GetFirstChild(nsnull); - if (textFrame) { - if (textFrame->GetType() == nsGkAtoms::textFrame) - break; - } - aFrame = textFrame; - } while (textFrame); - if (textFrame) { - nsIContent* quoteContent = textFrame->GetContent(); - if (quoteContent && quoteContent->IsNodeOfType(nsINode::eTEXT)) { - quoteContent->SetText(aValue, PR_FALSE); // no notify since we don't want a reflow yet - } - } + if (!aFrame) + return; + + nsIFrame* textFrame = aFrame->GetFirstChild(nsnull); + if (!textFrame) + return; + + nsIContent* quoteContent = textFrame->GetContent(); + if (!quoteContent->IsNodeOfType(nsINode::eTEXT)) + return; + + quoteContent->SetText(aValue, aNotify); } void -nsMathMLTokenFrame::SetQuotes() +nsMathMLTokenFrame::SetQuotes(PRBool aNotify) { if (mContent->Tag() != nsGkAtoms::ms_) return; - nsIFrame* rightFrame = nsnull; - nsIFrame* baseFrame = nsnull; - nsIFrame* leftFrame = mFrames.FirstChild(); - if (leftFrame) - baseFrame = leftFrame->GetNextSibling(); - if (baseFrame) - rightFrame = baseFrame->GetNextSibling(); - if (!leftFrame || !baseFrame || !rightFrame) - return; - nsAutoString value; // lquote if (GetAttribute(mContent, mPresentationData.mstyle, nsGkAtoms::lquote_, value)) { - SetQuote(leftFrame, value); + SetQuote(nsLayoutUtils::GetBeforeFrame(this), value, aNotify); } // rquote if (GetAttribute(mContent, mPresentationData.mstyle, nsGkAtoms::rquote_, value)) { - SetQuote(rightFrame, value); + SetQuote(nsLayoutUtils::GetAfterFrame(this), value, aNotify); } } diff --git a/layout/mathml/nsMathMLTokenFrame.h b/layout/mathml/nsMathMLTokenFrame.h index a2ef8fdae5b4..e5d360341d00 100644 --- a/layout/mathml/nsMathMLTokenFrame.h +++ b/layout/mathml/nsMathMLTokenFrame.h @@ -102,7 +102,7 @@ protected: PRBool SetTextStyle(); // helper to set the quotes of - void SetQuotes(); + void SetQuotes(PRBool aNotify); }; #endif /* nsMathMLTokentFrame_h___ */ diff --git a/layout/reftests/mathml/quotes-1-ref.xhtml b/layout/reftests/mathml/quotes-1-ref.xhtml new file mode 100644 index 000000000000..6afae30adeb9 --- /dev/null +++ b/layout/reftests/mathml/quotes-1-ref.xhtml @@ -0,0 +1,9 @@ + + +

:L_R

+

:L_”

+

:“_R

+

:L_”

+

:“_R

+ + diff --git a/layout/reftests/mathml/quotes-1.xhtml b/layout/reftests/mathml/quotes-1.xhtml new file mode 100644 index 000000000000..4f175b2bc75f --- /dev/null +++ b/layout/reftests/mathml/quotes-1.xhtml @@ -0,0 +1,23 @@ + + +

:_

+

:_

+

:_

+

:_

+

:_

+ + + diff --git a/layout/reftests/mathml/reftest.list b/layout/reftests/mathml/reftest.list index 0a998614a3c4..7c833b56a0a3 100644 --- a/layout/reftests/mathml/reftest.list +++ b/layout/reftests/mathml/reftest.list @@ -1,8 +1,9 @@ == dynamic-mi.xhtml dynamic-mi-ref.xhtml == mi-mathvariant-1.xhtml mi-mathvariant-1-ref.xhtml == mi-mathvariant-2.xhtml mi-mathvariant-2-ref.xhtml -== table-width-1.xhtml table-width-1-ref.xhtml -== overbar-width-1.xhtml overbar-width-1-ref.xhtml -== underbar-width-1.xhtml underbar-width-1-ref.xhtml != non-spacing-accent-1.xhtml non-spacing-accent-1-ref.xhtml +== overbar-width-1.xhtml overbar-width-1-ref.xhtml +== quotes-1.xhtml quotes-1-ref.xhtml != stretchy-underbar-1.xhtml stretchy-underbar-1-ref.xhtml +== table-width-1.xhtml table-width-1-ref.xhtml +== underbar-width-1.xhtml underbar-width-1-ref.xhtml