michael@0: /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ michael@0: /* This Source Code Form is subject to the terms of the Mozilla Public michael@0: * License, v. 2.0. If a copy of the MPL was not distributed with this michael@0: * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ michael@0: michael@0: #include "nsMathMLmoFrame.h" michael@0: #include "nsPresContext.h" michael@0: #include "nsRenderingContext.h" michael@0: #include "nsContentUtils.h" michael@0: #include "nsFrameSelection.h" michael@0: #include "nsMathMLElement.h" michael@0: #include michael@0: michael@0: // michael@0: // -- operator, fence, or separator - implementation michael@0: // michael@0: michael@0: // additional style context to be used by our MathMLChar. michael@0: #define NS_MATHML_CHAR_STYLE_CONTEXT_INDEX 0 michael@0: michael@0: nsIFrame* michael@0: NS_NewMathMLmoFrame(nsIPresShell* aPresShell, nsStyleContext *aContext) michael@0: { michael@0: return new (aPresShell) nsMathMLmoFrame(aContext); michael@0: } michael@0: michael@0: NS_IMPL_FRAMEARENA_HELPERS(nsMathMLmoFrame) michael@0: michael@0: nsMathMLmoFrame::~nsMathMLmoFrame() michael@0: { michael@0: } michael@0: michael@0: static const char16_t kApplyFunction = char16_t(0x2061); michael@0: static const char16_t kInvisibleTimes = char16_t(0x2062); michael@0: static const char16_t kInvisibleSeparator = char16_t(0x2063); michael@0: static const char16_t kInvisiblePlus = char16_t(0x2064); michael@0: michael@0: eMathMLFrameType michael@0: nsMathMLmoFrame::GetMathMLFrameType() michael@0: { michael@0: return NS_MATHML_OPERATOR_IS_INVISIBLE(mFlags) michael@0: ? eMathMLFrameType_OperatorInvisible michael@0: : eMathMLFrameType_OperatorOrdinary; michael@0: } michael@0: michael@0: // since a mouse click implies selection, we cannot just rely on the michael@0: // frame's state bit in our child text frame. So we will first check michael@0: // its selected state bit, and use this little helper to double check. michael@0: bool michael@0: nsMathMLmoFrame::IsFrameInSelection(nsIFrame* aFrame) michael@0: { michael@0: NS_ASSERTION(aFrame, "null arg"); michael@0: if (!aFrame || !aFrame->IsSelected()) michael@0: return false; michael@0: michael@0: const nsFrameSelection* frameSelection = aFrame->GetConstFrameSelection(); michael@0: SelectionDetails* details = michael@0: frameSelection->LookUpSelection(aFrame->GetContent(), 0, 1, true); michael@0: michael@0: if (!details) michael@0: return false; michael@0: michael@0: while (details) { michael@0: SelectionDetails* next = details->mNext; michael@0: delete details; michael@0: details = next; michael@0: } michael@0: return true; michael@0: } michael@0: michael@0: bool michael@0: nsMathMLmoFrame::UseMathMLChar() michael@0: { michael@0: return (NS_MATHML_OPERATOR_GET_FORM(mFlags) && michael@0: NS_MATHML_OPERATOR_IS_MUTABLE(mFlags)) || michael@0: NS_MATHML_OPERATOR_IS_CENTERED(mFlags); michael@0: } michael@0: michael@0: void michael@0: nsMathMLmoFrame::BuildDisplayList(nsDisplayListBuilder* aBuilder, michael@0: const nsRect& aDirtyRect, michael@0: const nsDisplayListSet& aLists) michael@0: { michael@0: bool useMathMLChar = UseMathMLChar(); michael@0: michael@0: if (!useMathMLChar) { michael@0: // let the base class do everything michael@0: nsMathMLTokenFrame::BuildDisplayList(aBuilder, aDirtyRect, aLists); michael@0: } else { michael@0: DisplayBorderBackgroundOutline(aBuilder, aLists); michael@0: michael@0: // make our char selected if our inner child text frame is selected michael@0: bool isSelected = false; michael@0: nsRect selectedRect; michael@0: nsIFrame* firstChild = mFrames.FirstChild(); michael@0: if (IsFrameInSelection(firstChild)) { michael@0: mMathMLChar.GetRect(selectedRect); michael@0: // add a one pixel border (it renders better for operators like minus) michael@0: selectedRect.Inflate(nsPresContext::CSSPixelsToAppUnits(1)); michael@0: isSelected = true; michael@0: } michael@0: mMathMLChar.Display(aBuilder, this, aLists, 0, isSelected ? &selectedRect : nullptr); michael@0: michael@0: #if defined(DEBUG) && defined(SHOW_BOUNDING_BOX) michael@0: // for visual debug michael@0: DisplayBoundingMetrics(aBuilder, this, mReference, mBoundingMetrics, aLists); michael@0: #endif michael@0: } michael@0: } michael@0: michael@0: // get the text that we enclose and setup our nsMathMLChar michael@0: void michael@0: nsMathMLmoFrame::ProcessTextData() michael@0: { michael@0: mFlags = 0; michael@0: michael@0: nsAutoString data; michael@0: if (!nsContentUtils::GetNodeTextContent(mContent, false, data)) { michael@0: NS_RUNTIMEABORT("OOM"); michael@0: } michael@0: michael@0: data.CompressWhitespace(); michael@0: int32_t length = data.Length(); michael@0: char16_t ch = (length == 0) ? char16_t('\0') : data[0]; michael@0: michael@0: if ((length == 1) && michael@0: (ch == kApplyFunction || michael@0: ch == kInvisibleSeparator || michael@0: ch == kInvisiblePlus || michael@0: ch == kInvisibleTimes)) { michael@0: mFlags |= NS_MATHML_OPERATOR_INVISIBLE; michael@0: } michael@0: michael@0: // don't bother doing anything special if we don't have a single child michael@0: nsPresContext* presContext = PresContext(); michael@0: if (mFrames.GetLength() != 1) { michael@0: data.Truncate(); // empty data to reset the char michael@0: mMathMLChar.SetData(presContext, data); michael@0: ResolveMathMLCharStyle(presContext, mContent, mStyleContext, &mMathMLChar); michael@0: return; michael@0: } michael@0: michael@0: // special... in math mode, the usual minus sign '-' looks too short, so michael@0: // what we do here is to remap - to the official Unicode minus michael@0: // sign (U+2212) which looks much better. For background on this, see michael@0: // http://groups.google.com/groups?hl=en&th=66488daf1ade7635&rnum=1 michael@0: if (1 == length && ch == '-') { michael@0: ch = 0x2212; michael@0: data = ch; michael@0: } michael@0: michael@0: // cache the special bits: mutable, accent, movablelimits, centered. michael@0: // we need to do this in anticipation of other requirements, and these michael@0: // bits don't change. Do not reset these bits unless the text gets changed. michael@0: michael@0: // lookup all the forms under which the operator is listed in the dictionary, michael@0: // and record whether the operator has accent="true" or movablelimits="true" michael@0: nsOperatorFlags flags[4]; michael@0: float lspace[4], rspace[4]; michael@0: nsMathMLOperators::LookupOperators(data, flags, lspace, rspace); michael@0: nsOperatorFlags allFlags = michael@0: flags[NS_MATHML_OPERATOR_FORM_INFIX] | michael@0: flags[NS_MATHML_OPERATOR_FORM_POSTFIX] | michael@0: flags[NS_MATHML_OPERATOR_FORM_PREFIX]; michael@0: michael@0: mFlags |= allFlags & NS_MATHML_OPERATOR_ACCENT; michael@0: mFlags |= allFlags & NS_MATHML_OPERATOR_MOVABLELIMITS; michael@0: michael@0: // see if this is an operator that should be centered to cater for michael@0: // fonts that are not math-aware michael@0: if (1 == length) { michael@0: if ((ch == '+') || (ch == '=') || (ch == '*') || michael@0: (ch == 0x2212) || // − michael@0: (ch == 0x2264) || // ≤ michael@0: (ch == 0x2265) || // ≥ michael@0: (ch == 0x00D7)) { // × michael@0: mFlags |= NS_MATHML_OPERATOR_CENTERED; michael@0: } michael@0: } michael@0: michael@0: // cache the operator michael@0: mMathMLChar.SetData(presContext, data); michael@0: michael@0: // cache the native direction -- beware of bug 133429... michael@0: // mEmbellishData.direction must always retain our native direction, whereas michael@0: // mMathMLChar.GetStretchDirection() may change later, when Stretch() is called michael@0: mEmbellishData.direction = mMathMLChar.GetStretchDirection(); michael@0: michael@0: bool isMutable = michael@0: NS_MATHML_OPERATOR_IS_LARGEOP(allFlags) || michael@0: (mEmbellishData.direction != NS_STRETCH_DIRECTION_UNSUPPORTED); michael@0: if (isMutable) michael@0: mFlags |= NS_MATHML_OPERATOR_MUTABLE; michael@0: michael@0: ResolveMathMLCharStyle(presContext, mContent, mStyleContext, &mMathMLChar); michael@0: } michael@0: michael@0: // get our 'form' and lookup in the Operator Dictionary to fetch michael@0: // our default data that may come from there. Then complete our setup michael@0: // using attributes that we may have. To stay in sync, this function is michael@0: // called very often. We depend on many things that may change around us. michael@0: // However, we re-use unchanged values. michael@0: void michael@0: nsMathMLmoFrame::ProcessOperatorData() michael@0: { michael@0: // if we have been here before, we will just use our cached form michael@0: nsOperatorFlags form = NS_MATHML_OPERATOR_GET_FORM(mFlags); michael@0: nsAutoString value; michael@0: michael@0: // special bits are always kept in mFlags. michael@0: // remember the mutable bit from ProcessTextData(). michael@0: // Some chars are listed under different forms in the dictionary, michael@0: // and there could be a form under which the char is mutable. michael@0: // If the char is the core of an embellished container, we will keep michael@0: // it mutable irrespective of the form of the embellished container. michael@0: // Also remember the other special bits that we want to carry forward. michael@0: mFlags &= NS_MATHML_OPERATOR_MUTABLE | michael@0: NS_MATHML_OPERATOR_ACCENT | michael@0: NS_MATHML_OPERATOR_MOVABLELIMITS | michael@0: NS_MATHML_OPERATOR_CENTERED | michael@0: NS_MATHML_OPERATOR_INVISIBLE; michael@0: michael@0: if (!mEmbellishData.coreFrame) { michael@0: // i.e., we haven't been here before, the default form is infix michael@0: form = NS_MATHML_OPERATOR_FORM_INFIX; michael@0: michael@0: // reset everything so that we don't keep outdated values around michael@0: // in case of dynamic changes michael@0: mEmbellishData.flags = 0; michael@0: mEmbellishData.coreFrame = nullptr; michael@0: mEmbellishData.leadingSpace = 0; michael@0: mEmbellishData.trailingSpace = 0; michael@0: if (mMathMLChar.Length() != 1) michael@0: mEmbellishData.direction = NS_STRETCH_DIRECTION_UNSUPPORTED; michael@0: // else... retain the native direction obtained in ProcessTextData() michael@0: michael@0: if (!mFrames.FirstChild()) { michael@0: return; michael@0: } michael@0: michael@0: mEmbellishData.flags |= NS_MATHML_EMBELLISH_OPERATOR; michael@0: mEmbellishData.coreFrame = this; michael@0: michael@0: // there are two particular things that we also need to record so that if our michael@0: // parent is , , or , they will treat us properly: michael@0: // 1) do we have accent="true" michael@0: // 2) do we have movablelimits="true" michael@0: michael@0: // they need the extra information to decide how to treat their scripts/limits michael@0: // (note: , , or need not necessarily be our michael@0: // direct parent -- case of embellished operators) michael@0: michael@0: // default values from the Operator Dictionary were obtained in ProcessTextData() michael@0: // and these special bits are always kept in mFlags michael@0: if (NS_MATHML_OPERATOR_IS_ACCENT(mFlags)) michael@0: mEmbellishData.flags |= NS_MATHML_EMBELLISH_ACCENT; michael@0: if (NS_MATHML_OPERATOR_IS_MOVABLELIMITS(mFlags)) michael@0: mEmbellishData.flags |= NS_MATHML_EMBELLISH_MOVABLELIMITS; michael@0: michael@0: // see if the accent attribute is there michael@0: mContent->GetAttr(kNameSpaceID_None, nsGkAtoms::accent_, value); michael@0: if (value.EqualsLiteral("true")) michael@0: mEmbellishData.flags |= NS_MATHML_EMBELLISH_ACCENT; michael@0: else if (value.EqualsLiteral("false")) michael@0: mEmbellishData.flags &= ~NS_MATHML_EMBELLISH_ACCENT; michael@0: michael@0: // see if the movablelimits attribute is there michael@0: mContent->GetAttr(kNameSpaceID_None, nsGkAtoms::movablelimits_, value); michael@0: if (value.EqualsLiteral("true")) michael@0: mEmbellishData.flags |= NS_MATHML_EMBELLISH_MOVABLELIMITS; michael@0: else if (value.EqualsLiteral("false")) michael@0: mEmbellishData.flags &= ~NS_MATHML_EMBELLISH_MOVABLELIMITS; michael@0: michael@0: // --------------------------------------------------------------------- michael@0: // we will be called again to re-sync the rest of our state next time... michael@0: // (nobody needs the other values below at this stage) michael@0: mFlags |= form; michael@0: return; michael@0: } michael@0: michael@0: nsPresContext* presContext = PresContext(); michael@0: michael@0: // beware of bug 133814 - there is a two-way dependency in the michael@0: // embellished hierarchy: our embellished ancestors need to set michael@0: // their flags based on some of our state (set above), and here we michael@0: // need to re-sync our 'form' depending on our outermost embellished michael@0: // container. A null form here means that an earlier attempt to stretch michael@0: // our mMathMLChar failed, in which case we don't bother re-stretching again michael@0: if (form) { michael@0: // get our outermost embellished container and its parent. michael@0: // (we ensure that we are the core, not just a sibling of the core) michael@0: nsIFrame* embellishAncestor = this; michael@0: nsEmbellishData embellishData; michael@0: nsIFrame* parentAncestor = this; michael@0: do { michael@0: embellishAncestor = parentAncestor; michael@0: parentAncestor = embellishAncestor->GetParent(); michael@0: GetEmbellishDataFrom(parentAncestor, embellishData); michael@0: } while (embellishData.coreFrame == this); michael@0: michael@0: // flag if we have an embellished ancestor michael@0: if (embellishAncestor != this) michael@0: mFlags |= NS_MATHML_OPERATOR_EMBELLISH_ANCESTOR; michael@0: else michael@0: mFlags &= ~NS_MATHML_OPERATOR_EMBELLISH_ANCESTOR; michael@0: michael@0: // find the position of our outermost embellished container w.r.t michael@0: // its siblings. michael@0: michael@0: nsIFrame* nextSibling = embellishAncestor->GetNextSibling(); michael@0: nsIFrame* prevSibling = embellishAncestor->GetPrevSibling(); michael@0: michael@0: // flag to distinguish from a real infix. Set for (embellished) operators michael@0: // that live in (inferred) mrows. michael@0: nsIMathMLFrame* mathAncestor = do_QueryFrame(parentAncestor); michael@0: bool zeroSpacing = false; michael@0: if (mathAncestor) { michael@0: zeroSpacing = !mathAncestor->IsMrowLike(); michael@0: } else { michael@0: nsMathMLmathBlockFrame* blockFrame = do_QueryFrame(parentAncestor); michael@0: if (blockFrame) { michael@0: zeroSpacing = !blockFrame->IsMrowLike(); michael@0: } michael@0: } michael@0: if (zeroSpacing) { michael@0: mFlags |= NS_MATHML_OPERATOR_EMBELLISH_ISOLATED; michael@0: } else { michael@0: mFlags &= ~NS_MATHML_OPERATOR_EMBELLISH_ISOLATED; michael@0: } michael@0: michael@0: // find our form michael@0: form = NS_MATHML_OPERATOR_FORM_INFIX; michael@0: mContent->GetAttr(kNameSpaceID_None, nsGkAtoms::form, value); michael@0: if (!value.IsEmpty()) { michael@0: if (value.EqualsLiteral("prefix")) michael@0: form = NS_MATHML_OPERATOR_FORM_PREFIX; michael@0: else if (value.EqualsLiteral("postfix")) michael@0: form = NS_MATHML_OPERATOR_FORM_POSTFIX; michael@0: } michael@0: else { michael@0: // set our form flag depending on the position michael@0: if (!prevSibling && nextSibling) michael@0: form = NS_MATHML_OPERATOR_FORM_PREFIX; michael@0: else if (prevSibling && !nextSibling) michael@0: form = NS_MATHML_OPERATOR_FORM_POSTFIX; michael@0: } michael@0: mFlags &= ~NS_MATHML_OPERATOR_FORM; // clear the old form bits michael@0: mFlags |= form; michael@0: michael@0: // Use the default value suggested by the MathML REC. michael@0: // http://www.w3.org/TR/MathML/chapter3.html#presm.mo.attrs michael@0: // thickmathspace = 5/18em michael@0: float lspace = 5.0f/18.0f; michael@0: float rspace = 5.0f/18.0f; michael@0: // lookup the operator dictionary michael@0: nsAutoString data; michael@0: mMathMLChar.GetData(data); michael@0: nsMathMLOperators::LookupOperator(data, form, &mFlags, &lspace, &rspace); michael@0: // Spacing is zero if our outermost embellished operator is not in an michael@0: // inferred mrow. michael@0: if (!NS_MATHML_OPERATOR_EMBELLISH_IS_ISOLATED(mFlags) && michael@0: (lspace || rspace)) { michael@0: // Cache the default values of lspace and rspace. michael@0: // since these values are relative to the 'em' unit, convert to twips now michael@0: nscoord em; michael@0: nsRefPtr fm; michael@0: nsLayoutUtils::GetFontMetricsForFrame(this, getter_AddRefs(fm)); michael@0: GetEmHeight(fm, em); michael@0: michael@0: mEmbellishData.leadingSpace = NSToCoordRound(lspace * em); michael@0: mEmbellishData.trailingSpace = NSToCoordRound(rspace * em); michael@0: michael@0: // tuning if we don't want too much extra space when we are a script. michael@0: // (with its fonts, TeX sets lspace=0 & rspace=0 as soon as scriptlevel>0. michael@0: // Our fonts can be anything, so...) michael@0: if (StyleFont()->mScriptLevel > 0 && michael@0: !NS_MATHML_OPERATOR_HAS_EMBELLISH_ANCESTOR(mFlags)) { michael@0: mEmbellishData.leadingSpace /= 2; michael@0: mEmbellishData.trailingSpace /= 2; michael@0: } michael@0: } michael@0: } michael@0: michael@0: // If we are an accent without explicit lspace="." or rspace=".", michael@0: // we will ignore our default leading/trailing space michael@0: michael@0: // lspace michael@0: // michael@0: // "Specifies the leading space appearing before the operator" michael@0: // michael@0: // values: length michael@0: // default: set by dictionary (thickmathspace) michael@0: // michael@0: // XXXfredw Support for negative and relative values is not implemented michael@0: // (bug 805926). michael@0: // Relative values will give a multiple of the current leading space, michael@0: // which is not necessarily the default one. michael@0: // michael@0: nscoord leadingSpace = mEmbellishData.leadingSpace; michael@0: mContent->GetAttr(kNameSpaceID_None, nsGkAtoms::lspace_, value); michael@0: if (!value.IsEmpty()) { michael@0: nsCSSValue cssValue; michael@0: if (nsMathMLElement::ParseNumericValue(value, cssValue, 0, michael@0: mContent->OwnerDoc())) { michael@0: if ((eCSSUnit_Number == cssValue.GetUnit()) && !cssValue.GetFloatValue()) michael@0: leadingSpace = 0; michael@0: else if (cssValue.IsLengthUnit()) michael@0: leadingSpace = CalcLength(presContext, mStyleContext, cssValue); michael@0: mFlags |= NS_MATHML_OPERATOR_LSPACE_ATTR; michael@0: } michael@0: } michael@0: michael@0: // rspace michael@0: // michael@0: // "Specifies the trailing space appearing after the operator" michael@0: // michael@0: // values: length michael@0: // default: set by dictionary (thickmathspace) michael@0: // michael@0: // XXXfredw Support for negative and relative values is not implemented michael@0: // (bug 805926). michael@0: // Relative values will give a multiple of the current leading space, michael@0: // which is not necessarily the default one. michael@0: // michael@0: nscoord trailingSpace = mEmbellishData.trailingSpace; michael@0: mContent->GetAttr(kNameSpaceID_None, nsGkAtoms::rspace_, value); michael@0: if (!value.IsEmpty()) { michael@0: nsCSSValue cssValue; michael@0: if (nsMathMLElement::ParseNumericValue(value, cssValue, 0, michael@0: mContent->OwnerDoc())) { michael@0: if ((eCSSUnit_Number == cssValue.GetUnit()) && !cssValue.GetFloatValue()) michael@0: trailingSpace = 0; michael@0: else if (cssValue.IsLengthUnit()) michael@0: trailingSpace = CalcLength(presContext, mStyleContext, cssValue); michael@0: mFlags |= NS_MATHML_OPERATOR_RSPACE_ATTR; michael@0: } michael@0: } michael@0: michael@0: // little extra tuning to round lspace & rspace to at least a pixel so that michael@0: // operators don't look as if they are colliding with their operands michael@0: if (leadingSpace || trailingSpace) { michael@0: nscoord onePixel = nsPresContext::CSSPixelsToAppUnits(1); michael@0: if (leadingSpace && leadingSpace < onePixel) michael@0: leadingSpace = onePixel; michael@0: if (trailingSpace && trailingSpace < onePixel) michael@0: trailingSpace = onePixel; michael@0: } michael@0: michael@0: // the values that we get from our attributes override the dictionary michael@0: mEmbellishData.leadingSpace = leadingSpace; michael@0: mEmbellishData.trailingSpace = trailingSpace; michael@0: michael@0: // Now see if there are user-defined attributes that override the dictionary. michael@0: // XXX If an attribute can be forced to be true when it is false in the michael@0: // dictionary, then the following code has to change... michael@0: michael@0: // For each attribute overriden by the user, turn off its bit flag. michael@0: // symmetric|movablelimits|separator|largeop|accent|fence|stretchy|form michael@0: // special: accent and movablelimits are handled above, michael@0: // don't process them here michael@0: michael@0: mContent->GetAttr(kNameSpaceID_None, nsGkAtoms::stretchy_, value); michael@0: if (value.EqualsLiteral("false")) { michael@0: mFlags &= ~NS_MATHML_OPERATOR_STRETCHY; michael@0: } else if (value.EqualsLiteral("true")) { michael@0: mFlags |= NS_MATHML_OPERATOR_STRETCHY; michael@0: } michael@0: if (NS_MATHML_OPERATOR_IS_FENCE(mFlags)) { michael@0: mContent->GetAttr(kNameSpaceID_None, nsGkAtoms::fence_, value); michael@0: if (value.EqualsLiteral("false")) michael@0: mFlags &= ~NS_MATHML_OPERATOR_FENCE; michael@0: } michael@0: mContent->GetAttr(kNameSpaceID_None, nsGkAtoms::largeop_, value); michael@0: if (value.EqualsLiteral("false")) { michael@0: mFlags &= ~NS_MATHML_OPERATOR_LARGEOP; michael@0: } else if (value.EqualsLiteral("true")) { michael@0: mFlags |= NS_MATHML_OPERATOR_LARGEOP; michael@0: } michael@0: if (NS_MATHML_OPERATOR_IS_SEPARATOR(mFlags)) { michael@0: mContent->GetAttr(kNameSpaceID_None, nsGkAtoms::separator_, value); michael@0: if (value.EqualsLiteral("false")) michael@0: mFlags &= ~NS_MATHML_OPERATOR_SEPARATOR; michael@0: } michael@0: mContent->GetAttr(kNameSpaceID_None, nsGkAtoms::symmetric_, value); michael@0: if (value.EqualsLiteral("false")) michael@0: mFlags &= ~NS_MATHML_OPERATOR_SYMMETRIC; michael@0: else if (value.EqualsLiteral("true")) michael@0: mFlags |= NS_MATHML_OPERATOR_SYMMETRIC; michael@0: michael@0: michael@0: // minsize michael@0: // michael@0: // "Specifies the minimum size of the operator when stretchy" michael@0: // michael@0: // values: length michael@0: // default: set by dictionary (1em) michael@0: // michael@0: // We don't allow negative values. michael@0: // Note: Contrary to other "length" values, unitless and percentage do not michael@0: // give a multiple of the defaut value but a multiple of the operator at michael@0: // normal size. michael@0: // michael@0: mMinSize = 0; michael@0: mContent->GetAttr(kNameSpaceID_None, nsGkAtoms::minsize_, value); michael@0: if (!value.IsEmpty()) { michael@0: nsCSSValue cssValue; michael@0: if (nsMathMLElement::ParseNumericValue(value, cssValue, michael@0: nsMathMLElement:: michael@0: PARSE_ALLOW_UNITLESS, michael@0: mContent->OwnerDoc())) { michael@0: nsCSSUnit unit = cssValue.GetUnit(); michael@0: if (eCSSUnit_Number == unit) michael@0: mMinSize = cssValue.GetFloatValue(); michael@0: else if (eCSSUnit_Percent == unit) michael@0: mMinSize = cssValue.GetPercentValue(); michael@0: else if (eCSSUnit_Null != unit) { michael@0: mMinSize = float(CalcLength(presContext, mStyleContext, cssValue)); michael@0: mFlags |= NS_MATHML_OPERATOR_MINSIZE_ABSOLUTE; michael@0: } michael@0: } michael@0: } michael@0: michael@0: // maxsize michael@0: // michael@0: // "Specifies the maximum size of the operator when stretchy" michael@0: // michael@0: // values: length | "infinity" michael@0: // default: set by dictionary (infinity) michael@0: // michael@0: // We don't allow negative values. michael@0: // Note: Contrary to other "length" values, unitless and percentage do not michael@0: // give a multiple of the defaut value but a multiple of the operator at michael@0: // normal size. michael@0: // michael@0: mMaxSize = NS_MATHML_OPERATOR_SIZE_INFINITY; michael@0: mContent->GetAttr(kNameSpaceID_None, nsGkAtoms::maxsize_, value); michael@0: if (!value.IsEmpty()) { michael@0: nsCSSValue cssValue; michael@0: if (nsMathMLElement::ParseNumericValue(value, cssValue, michael@0: nsMathMLElement:: michael@0: PARSE_ALLOW_UNITLESS, michael@0: mContent->OwnerDoc())) { michael@0: nsCSSUnit unit = cssValue.GetUnit(); michael@0: if (eCSSUnit_Number == unit) michael@0: mMaxSize = cssValue.GetFloatValue(); michael@0: else if (eCSSUnit_Percent == unit) michael@0: mMaxSize = cssValue.GetPercentValue(); michael@0: else if (eCSSUnit_Null != unit) { michael@0: mMaxSize = float(CalcLength(presContext, mStyleContext, cssValue)); michael@0: mFlags |= NS_MATHML_OPERATOR_MAXSIZE_ABSOLUTE; michael@0: } michael@0: } michael@0: } michael@0: } michael@0: michael@0: static uint32_t michael@0: GetStretchHint(nsOperatorFlags aFlags, nsPresentationData aPresentationData, michael@0: bool aIsVertical, const nsStyleFont* aStyleFont) michael@0: { michael@0: uint32_t stretchHint = NS_STRETCH_NONE; michael@0: // See if it is okay to stretch, michael@0: // starting from what the Operator Dictionary said michael@0: if (NS_MATHML_OPERATOR_IS_MUTABLE(aFlags)) { michael@0: // set the largeop or largeopOnly flags to suitably cover all the michael@0: // 8 possible cases depending on whether displaystyle, largeop, michael@0: // stretchy are true or false (see bug 69325). michael@0: // . largeopOnly is taken if largeop=true and stretchy=false michael@0: // . largeop is taken if largeop=true and stretchy=true michael@0: if (aStyleFont->mMathDisplay == NS_MATHML_DISPLAYSTYLE_BLOCK && michael@0: NS_MATHML_OPERATOR_IS_LARGEOP(aFlags)) { michael@0: stretchHint = NS_STRETCH_LARGEOP; // (largeopOnly, not mask!) michael@0: if (NS_MATHML_OPERATOR_IS_INTEGRAL(aFlags)) { michael@0: stretchHint |= NS_STRETCH_INTEGRAL; michael@0: } michael@0: if (NS_MATHML_OPERATOR_IS_STRETCHY(aFlags)) { michael@0: stretchHint |= NS_STRETCH_NEARER | NS_STRETCH_LARGER; michael@0: } michael@0: } michael@0: else if(NS_MATHML_OPERATOR_IS_STRETCHY(aFlags)) { michael@0: if (aIsVertical) { michael@0: // TeX hint. Can impact some sloppy markups missing michael@0: stretchHint = NS_STRETCH_NEARER; michael@0: } michael@0: else { michael@0: stretchHint = NS_STRETCH_NORMAL; michael@0: } michael@0: } michael@0: // else if the stretchy and largeop attributes have been disabled, michael@0: // the operator is not mutable michael@0: } michael@0: return stretchHint; michael@0: } michael@0: michael@0: // NOTE: aDesiredStretchSize is an IN/OUT parameter michael@0: // On input - it contains our current size michael@0: // On output - the same size or the new size that we want michael@0: NS_IMETHODIMP michael@0: nsMathMLmoFrame::Stretch(nsRenderingContext& aRenderingContext, michael@0: nsStretchDirection aStretchDirection, michael@0: nsBoundingMetrics& aContainerSize, michael@0: nsHTMLReflowMetrics& aDesiredStretchSize) michael@0: { michael@0: if (NS_MATHML_STRETCH_WAS_DONE(mPresentationData.flags)) { michael@0: NS_WARNING("it is wrong to fire stretch more than once on a frame"); michael@0: return NS_OK; michael@0: } michael@0: mPresentationData.flags |= NS_MATHML_STRETCH_DONE; michael@0: michael@0: nsIFrame* firstChild = mFrames.FirstChild(); michael@0: michael@0: // get the axis height; michael@0: nsRefPtr fm; michael@0: nsLayoutUtils::GetFontMetricsForFrame(this, getter_AddRefs(fm)); michael@0: aRenderingContext.SetFont(fm); michael@0: nscoord axisHeight, height; michael@0: GetAxisHeight(aRenderingContext, fm, axisHeight); michael@0: michael@0: // get the leading to be left at the top and the bottom of the stretched char michael@0: // this seems more reliable than using fm->GetLeading() on suspicious fonts michael@0: nscoord em; michael@0: GetEmHeight(fm, em); michael@0: nscoord leading = NSToCoordRound(0.2f * em); michael@0: michael@0: // Operators that are stretchy, or those that are to be centered michael@0: // to cater for fonts that are not math-aware, are handled by the MathMLChar michael@0: // ('form' is reset if stretch fails -- i.e., we don't bother to stretch next time) michael@0: bool useMathMLChar = UseMathMLChar(); michael@0: michael@0: nsBoundingMetrics charSize; michael@0: nsBoundingMetrics container = aDesiredStretchSize.mBoundingMetrics; michael@0: bool isVertical = false; michael@0: michael@0: if (((aStretchDirection == NS_STRETCH_DIRECTION_VERTICAL) || michael@0: (aStretchDirection == NS_STRETCH_DIRECTION_DEFAULT)) && michael@0: (mEmbellishData.direction == NS_STRETCH_DIRECTION_VERTICAL)) { michael@0: isVertical = true; michael@0: } michael@0: michael@0: uint32_t stretchHint = michael@0: GetStretchHint(mFlags, mPresentationData, isVertical, StyleFont()); michael@0: michael@0: if (useMathMLChar) { michael@0: nsBoundingMetrics initialSize = aDesiredStretchSize.mBoundingMetrics; michael@0: michael@0: if (stretchHint != NS_STRETCH_NONE) { michael@0: michael@0: container = aContainerSize; michael@0: michael@0: // some adjustments if the operator is symmetric and vertical michael@0: michael@0: if (isVertical && NS_MATHML_OPERATOR_IS_SYMMETRIC(mFlags)) { michael@0: // we need to center about the axis michael@0: nscoord delta = std::max(container.ascent - axisHeight, michael@0: container.descent + axisHeight); michael@0: container.ascent = delta + axisHeight; michael@0: container.descent = delta - axisHeight; michael@0: michael@0: // get ready in case we encounter user-desired min-max size michael@0: delta = std::max(initialSize.ascent - axisHeight, michael@0: initialSize.descent + axisHeight); michael@0: initialSize.ascent = delta + axisHeight; michael@0: initialSize.descent = delta - axisHeight; michael@0: } michael@0: michael@0: // check for user-desired min-max size michael@0: michael@0: if (mMaxSize != NS_MATHML_OPERATOR_SIZE_INFINITY && mMaxSize > 0.0f) { michael@0: // if we are here, there is a user defined maxsize ... michael@0: //XXX Set stretchHint = NS_STRETCH_NORMAL? to honor the maxsize as close as possible? michael@0: if (NS_MATHML_OPERATOR_MAXSIZE_IS_ABSOLUTE(mFlags)) { michael@0: // there is an explicit value like maxsize="20pt" michael@0: // try to maintain the aspect ratio of the char michael@0: float aspect = mMaxSize / float(initialSize.ascent + initialSize.descent); michael@0: container.ascent = michael@0: std::min(container.ascent, nscoord(initialSize.ascent * aspect)); michael@0: container.descent = michael@0: std::min(container.descent, nscoord(initialSize.descent * aspect)); michael@0: // below we use a type cast instead of a conversion to avoid a VC++ bug michael@0: // see http://support.microsoft.com/support/kb/articles/Q115/7/05.ASP michael@0: container.width = michael@0: std::min(container.width, (nscoord)mMaxSize); michael@0: } michael@0: else { // multiplicative value michael@0: container.ascent = michael@0: std::min(container.ascent, nscoord(initialSize.ascent * mMaxSize)); michael@0: container.descent = michael@0: std::min(container.descent, nscoord(initialSize.descent * mMaxSize)); michael@0: container.width = michael@0: std::min(container.width, nscoord(initialSize.width * mMaxSize)); michael@0: } michael@0: michael@0: if (isVertical && !NS_MATHML_OPERATOR_IS_SYMMETRIC(mFlags)) { michael@0: // re-adjust to align the char with the bottom of the initial container michael@0: height = container.ascent + container.descent; michael@0: container.descent = aContainerSize.descent; michael@0: container.ascent = height - container.descent; michael@0: } michael@0: } michael@0: michael@0: if (mMinSize > 0.0f) { michael@0: // if we are here, there is a user defined minsize ... michael@0: // always allow the char to stretch in its natural direction, michael@0: // even if it is different from the caller's direction michael@0: if (aStretchDirection != NS_STRETCH_DIRECTION_DEFAULT && michael@0: aStretchDirection != mEmbellishData.direction) { michael@0: aStretchDirection = NS_STRETCH_DIRECTION_DEFAULT; michael@0: // but when we are not honoring the requested direction michael@0: // we should not use the caller's container size either michael@0: container = initialSize; michael@0: } michael@0: if (NS_MATHML_OPERATOR_MINSIZE_IS_ABSOLUTE(mFlags)) { michael@0: // there is an explicit value like minsize="20pt" michael@0: // try to maintain the aspect ratio of the char michael@0: float aspect = mMinSize / float(initialSize.ascent + initialSize.descent); michael@0: container.ascent = michael@0: std::max(container.ascent, nscoord(initialSize.ascent * aspect)); michael@0: container.descent = michael@0: std::max(container.descent, nscoord(initialSize.descent * aspect)); michael@0: container.width = michael@0: std::max(container.width, (nscoord)mMinSize); michael@0: } michael@0: else { // multiplicative value michael@0: container.ascent = michael@0: std::max(container.ascent, nscoord(initialSize.ascent * mMinSize)); michael@0: container.descent = michael@0: std::max(container.descent, nscoord(initialSize.descent * mMinSize)); michael@0: container.width = michael@0: std::max(container.width, nscoord(initialSize.width * mMinSize)); michael@0: } michael@0: michael@0: if (isVertical && !NS_MATHML_OPERATOR_IS_SYMMETRIC(mFlags)) { michael@0: // re-adjust to align the char with the bottom of the initial container michael@0: height = container.ascent + container.descent; michael@0: container.descent = aContainerSize.descent; michael@0: container.ascent = height - container.descent; michael@0: } michael@0: } michael@0: } michael@0: michael@0: // let the MathMLChar stretch itself... michael@0: nsresult res = mMathMLChar.Stretch(PresContext(), aRenderingContext, michael@0: aStretchDirection, container, charSize, michael@0: stretchHint, michael@0: StyleVisibility()->mDirection); michael@0: if (NS_FAILED(res)) { michael@0: // gracefully handle cases where stretching the char failed (i.e., GetBoundingMetrics failed) michael@0: // clear our 'form' to behave as if the operator wasn't in the dictionary michael@0: mFlags &= ~NS_MATHML_OPERATOR_FORM; michael@0: useMathMLChar = false; michael@0: } michael@0: } michael@0: michael@0: // Place our children using the default method michael@0: // This will allow our child text frame to get its DidReflow() michael@0: nsresult rv = Place(aRenderingContext, true, aDesiredStretchSize); michael@0: if (NS_MATHML_HAS_ERROR(mPresentationData.flags) || NS_FAILED(rv)) { michael@0: // Make sure the child frames get their DidReflow() calls. michael@0: DidReflowChildren(mFrames.FirstChild()); michael@0: } michael@0: michael@0: if (useMathMLChar) { michael@0: // update our bounding metrics... it becomes that of our MathML char michael@0: mBoundingMetrics = charSize; michael@0: michael@0: // if the returned direction is 'unsupported', the char didn't actually change. michael@0: // So we do the centering only if necessary michael@0: if (mMathMLChar.GetStretchDirection() != NS_STRETCH_DIRECTION_UNSUPPORTED || michael@0: NS_MATHML_OPERATOR_IS_CENTERED(mFlags)) { michael@0: michael@0: bool largeopOnly = michael@0: (NS_STRETCH_LARGEOP & stretchHint) != 0 && michael@0: (NS_STRETCH_VARIABLE_MASK & stretchHint) == 0; michael@0: michael@0: if (isVertical || NS_MATHML_OPERATOR_IS_CENTERED(mFlags)) { michael@0: // the desired size returned by mMathMLChar maybe different michael@0: // from the size of the container. michael@0: // the mMathMLChar.mRect.y calculation is subtle, watch out!!! michael@0: michael@0: height = mBoundingMetrics.ascent + mBoundingMetrics.descent; michael@0: if (NS_MATHML_OPERATOR_IS_SYMMETRIC(mFlags) || michael@0: NS_MATHML_OPERATOR_IS_CENTERED(mFlags)) { michael@0: // For symmetric and vertical operators, or for operators that are always michael@0: // centered ('+', '*', etc) we want to center about the axis of the container michael@0: mBoundingMetrics.descent = height/2 - axisHeight; michael@0: } else if (!largeopOnly) { michael@0: // Align the center of the char with the center of the container michael@0: mBoundingMetrics.descent = height/2 + michael@0: (container.ascent + container.descent)/2 - container.ascent; michael@0: } // else align the baselines michael@0: mBoundingMetrics.ascent = height - mBoundingMetrics.descent; michael@0: } michael@0: } michael@0: } michael@0: michael@0: // Fixup for the final height. michael@0: // On one hand, our stretchy height can sometimes be shorter than surrounding michael@0: // ASCII chars, e.g., arrow symbols have |mBoundingMetrics.ascent + leading| michael@0: // that is smaller than the ASCII's ascent, hence when painting the background michael@0: // later, it won't look uniform along the line. michael@0: // On the other hand, sometimes we may leave too much gap when our glyph happens michael@0: // to come from a font with tall glyphs. For example, since CMEX10 has very tall michael@0: // glyphs, its natural font metrics are large, even if we pick a small glyph michael@0: // whose size is comparable to the size of a normal ASCII glyph. michael@0: // So to avoid uneven spacing in either of these two cases, we use the height michael@0: // of the ASCII font as a reference and try to match it if possible. michael@0: michael@0: // special case for accents... keep them short to improve mouse operations... michael@0: // an accent can only be the non-first child of , , michael@0: bool isAccent = michael@0: NS_MATHML_EMBELLISH_IS_ACCENT(mEmbellishData.flags); michael@0: if (isAccent) { michael@0: nsEmbellishData parentData; michael@0: GetEmbellishDataFrom(mParent, parentData); michael@0: isAccent = michael@0: (NS_MATHML_EMBELLISH_IS_ACCENTOVER(parentData.flags) || michael@0: NS_MATHML_EMBELLISH_IS_ACCENTUNDER(parentData.flags)) && michael@0: parentData.coreFrame != this; michael@0: } michael@0: if (isAccent && firstChild) { michael@0: // see bug 188467 for what is going on here michael@0: nscoord dy = aDesiredStretchSize.TopAscent() - (mBoundingMetrics.ascent + leading); michael@0: aDesiredStretchSize.SetTopAscent(mBoundingMetrics.ascent + leading); michael@0: aDesiredStretchSize.Height() = aDesiredStretchSize.TopAscent() + mBoundingMetrics.descent; michael@0: michael@0: firstChild->SetPosition(firstChild->GetPosition() - nsPoint(0, dy)); michael@0: } michael@0: else if (useMathMLChar) { michael@0: nscoord ascent = fm->MaxAscent(); michael@0: nscoord descent = fm->MaxDescent(); michael@0: aDesiredStretchSize.SetTopAscent(std::max(mBoundingMetrics.ascent + leading, ascent)); michael@0: aDesiredStretchSize.Height() = aDesiredStretchSize.TopAscent() + michael@0: std::max(mBoundingMetrics.descent + leading, descent); michael@0: } michael@0: aDesiredStretchSize.Width() = mBoundingMetrics.width; michael@0: aDesiredStretchSize.mBoundingMetrics = mBoundingMetrics; michael@0: mReference.x = 0; michael@0: mReference.y = aDesiredStretchSize.TopAscent(); michael@0: // Place our mMathMLChar, its origin is in our coordinate system michael@0: if (useMathMLChar) { michael@0: nscoord dy = aDesiredStretchSize.TopAscent() - mBoundingMetrics.ascent; michael@0: mMathMLChar.SetRect(nsRect(0, dy, charSize.width, charSize.ascent + charSize.descent)); michael@0: } michael@0: michael@0: // Before we leave... there is a last item in the check-list: michael@0: // If our parent is not embellished, it means we are the outermost embellished michael@0: // container and so we put the spacing, otherwise we don't include the spacing, michael@0: // the outermost embellished container will take care of it. michael@0: michael@0: if (!NS_MATHML_OPERATOR_HAS_EMBELLISH_ANCESTOR(mFlags)) { michael@0: michael@0: // Account the spacing if we are not an accent with explicit attributes michael@0: nscoord leadingSpace = mEmbellishData.leadingSpace; michael@0: if (isAccent && !NS_MATHML_OPERATOR_HAS_LSPACE_ATTR(mFlags)) { michael@0: leadingSpace = 0; michael@0: } michael@0: nscoord trailingSpace = mEmbellishData.trailingSpace; michael@0: if (isAccent && !NS_MATHML_OPERATOR_HAS_RSPACE_ATTR(mFlags)) { michael@0: trailingSpace = 0; michael@0: } michael@0: michael@0: mBoundingMetrics.width += leadingSpace + trailingSpace; michael@0: aDesiredStretchSize.Width() = mBoundingMetrics.width; michael@0: aDesiredStretchSize.mBoundingMetrics.width = mBoundingMetrics.width; michael@0: michael@0: nscoord dx = (StyleVisibility()->mDirection ? michael@0: trailingSpace : leadingSpace); michael@0: if (dx) { michael@0: // adjust the offsets michael@0: mBoundingMetrics.leftBearing += dx; michael@0: mBoundingMetrics.rightBearing += dx; michael@0: aDesiredStretchSize.mBoundingMetrics.leftBearing += dx; michael@0: aDesiredStretchSize.mBoundingMetrics.rightBearing += dx; michael@0: michael@0: if (useMathMLChar) { michael@0: nsRect rect; michael@0: mMathMLChar.GetRect(rect); michael@0: mMathMLChar.SetRect(nsRect(rect.x + dx, rect.y, michael@0: rect.width, rect.height)); michael@0: } michael@0: else { michael@0: nsIFrame* childFrame = firstChild; michael@0: while (childFrame) { michael@0: childFrame->SetPosition(childFrame->GetPosition() + michael@0: nsPoint(dx, 0)); michael@0: childFrame = childFrame->GetNextSibling(); michael@0: } michael@0: } michael@0: } michael@0: } michael@0: michael@0: // Finished with these: michael@0: ClearSavedChildMetrics(); michael@0: // Set our overflow area michael@0: GatherAndStoreOverflow(&aDesiredStretchSize); michael@0: michael@0: // There used to be code here to change the height of the child frame to michael@0: // change the caret height, but the text frame that manages the caret is now michael@0: // not a direct child but wrapped in a block frame. See also bug 412033. michael@0: michael@0: return NS_OK; michael@0: } michael@0: michael@0: NS_IMETHODIMP michael@0: nsMathMLmoFrame::InheritAutomaticData(nsIFrame* aParent) michael@0: { michael@0: // retain our native direction, it only changes if our text content changes michael@0: nsStretchDirection direction = mEmbellishData.direction; michael@0: nsMathMLTokenFrame::InheritAutomaticData(aParent); michael@0: ProcessTextData(); michael@0: mEmbellishData.direction = direction; michael@0: return NS_OK; michael@0: } michael@0: michael@0: NS_IMETHODIMP michael@0: nsMathMLmoFrame::TransmitAutomaticData() michael@0: { michael@0: // this will cause us to re-sync our flags from scratch michael@0: // but our returned 'form' is still not final (bug 133429), it will michael@0: // be recomputed to its final value during the next call in Reflow() michael@0: mEmbellishData.coreFrame = nullptr; michael@0: ProcessOperatorData(); michael@0: return NS_OK; michael@0: } michael@0: michael@0: nsresult michael@0: nsMathMLmoFrame::SetInitialChildList(ChildListID aListID, michael@0: nsFrameList& aChildList) michael@0: { michael@0: // First, let the parent class do its work michael@0: nsresult rv = nsMathMLTokenFrame::SetInitialChildList(aListID, aChildList); michael@0: if (NS_FAILED(rv)) michael@0: return rv; michael@0: michael@0: ProcessTextData(); michael@0: return rv; michael@0: } michael@0: michael@0: nsresult michael@0: nsMathMLmoFrame::Reflow(nsPresContext* aPresContext, michael@0: nsHTMLReflowMetrics& aDesiredSize, michael@0: const nsHTMLReflowState& aReflowState, michael@0: nsReflowStatus& aStatus) michael@0: { michael@0: // certain values use units that depend on our style context, so michael@0: // it is safer to just process the whole lot here michael@0: ProcessOperatorData(); michael@0: michael@0: return nsMathMLTokenFrame::Reflow(aPresContext, aDesiredSize, michael@0: aReflowState, aStatus); michael@0: } michael@0: michael@0: /* virtual */ void michael@0: nsMathMLmoFrame::MarkIntrinsicWidthsDirty() michael@0: { michael@0: // if we get this, it may mean that something changed in the text michael@0: // content. So blow away everything an re-build the automatic data michael@0: // from the parent of our outermost embellished container (we ensure michael@0: // that we are the core, not just a sibling of the core) michael@0: michael@0: ProcessTextData(); michael@0: michael@0: nsIFrame* target = this; michael@0: nsEmbellishData embellishData; michael@0: do { michael@0: target = target->GetParent(); michael@0: GetEmbellishDataFrom(target, embellishData); michael@0: } while (embellishData.coreFrame == this); michael@0: michael@0: // we have automatic data to update in the children of the target frame michael@0: // XXXldb This should really be marking dirty rather than rebuilding michael@0: // so that we don't rebuild multiple times for the same change. michael@0: RebuildAutomaticDataForChildren(target); michael@0: michael@0: nsMathMLContainerFrame::MarkIntrinsicWidthsDirty(); michael@0: } michael@0: michael@0: /* virtual */ void michael@0: nsMathMLmoFrame::GetIntrinsicWidthMetrics(nsRenderingContext *aRenderingContext, nsHTMLReflowMetrics& aDesiredSize) michael@0: { michael@0: ProcessOperatorData(); michael@0: if (UseMathMLChar()) { michael@0: uint32_t stretchHint = GetStretchHint(mFlags, mPresentationData, true, michael@0: StyleFont()); michael@0: aDesiredSize.Width() = mMathMLChar. michael@0: GetMaxWidth(PresContext(), *aRenderingContext, michael@0: stretchHint, mMaxSize, michael@0: NS_MATHML_OPERATOR_MAXSIZE_IS_ABSOLUTE(mFlags)); michael@0: } michael@0: else { michael@0: nsMathMLTokenFrame::GetIntrinsicWidthMetrics(aRenderingContext, michael@0: aDesiredSize); michael@0: } michael@0: michael@0: // leadingSpace and trailingSpace are actually applied to the outermost michael@0: // embellished container but for determining total intrinsic width it should michael@0: // be safe to include it for the core here instead. michael@0: bool isRTL = StyleVisibility()->mDirection; michael@0: aDesiredSize.Width() += michael@0: mEmbellishData.leadingSpace + mEmbellishData.trailingSpace; michael@0: aDesiredSize.mBoundingMetrics.width = aDesiredSize.Width(); michael@0: if (isRTL) { michael@0: aDesiredSize.mBoundingMetrics.leftBearing += mEmbellishData.trailingSpace; michael@0: aDesiredSize.mBoundingMetrics.rightBearing += mEmbellishData.trailingSpace; michael@0: } else { michael@0: aDesiredSize.mBoundingMetrics.leftBearing += mEmbellishData.leadingSpace; michael@0: aDesiredSize.mBoundingMetrics.rightBearing += mEmbellishData.leadingSpace; michael@0: } michael@0: } michael@0: michael@0: nsresult michael@0: nsMathMLmoFrame::AttributeChanged(int32_t aNameSpaceID, michael@0: nsIAtom* aAttribute, michael@0: int32_t aModType) michael@0: { michael@0: // check if this is an attribute that can affect the embellished hierarchy michael@0: // in a significant way and re-layout the entire hierarchy. michael@0: if (nsGkAtoms::accent_ == aAttribute || michael@0: nsGkAtoms::movablelimits_ == aAttribute) { michael@0: michael@0: // set the target as the parent of our outermost embellished container michael@0: // (we ensure that we are the core, not just a sibling of the core) michael@0: nsIFrame* target = this; michael@0: nsEmbellishData embellishData; michael@0: do { michael@0: target = target->GetParent(); michael@0: GetEmbellishDataFrom(target, embellishData); michael@0: } while (embellishData.coreFrame == this); michael@0: michael@0: // we have automatic data to update in the children of the target frame michael@0: return ReLayoutChildren(target); michael@0: } michael@0: michael@0: return nsMathMLTokenFrame:: michael@0: AttributeChanged(aNameSpaceID, aAttribute, aModType); michael@0: } michael@0: michael@0: // ---------------------- michael@0: // No need to track the style context given to our MathML char. michael@0: // the Style System will use these to pass the proper style context to our MathMLChar michael@0: nsStyleContext* michael@0: nsMathMLmoFrame::GetAdditionalStyleContext(int32_t aIndex) const michael@0: { michael@0: switch (aIndex) { michael@0: case NS_MATHML_CHAR_STYLE_CONTEXT_INDEX: michael@0: return mMathMLChar.GetStyleContext(); michael@0: default: michael@0: return nullptr; michael@0: } michael@0: } michael@0: michael@0: void michael@0: nsMathMLmoFrame::SetAdditionalStyleContext(int32_t aIndex, michael@0: nsStyleContext* aStyleContext) michael@0: { michael@0: switch (aIndex) { michael@0: case NS_MATHML_CHAR_STYLE_CONTEXT_INDEX: michael@0: mMathMLChar.SetStyleContext(aStyleContext); michael@0: break; michael@0: } michael@0: }