2007-03-22 10:30:00 -07:00
|
|
|
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
2012-05-21 04:12:37 -07:00
|
|
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
#include "nsCOMPtr.h"
|
|
|
|
#include "nsHTMLParts.h"
|
|
|
|
#include "nsFrame.h"
|
|
|
|
#include "nsPresContext.h"
|
|
|
|
#include "nsIPresShell.h"
|
|
|
|
#include "nsCSSAnonBoxes.h"
|
|
|
|
#include "nsStyleContext.h"
|
|
|
|
#include "nsStyleConsts.h"
|
|
|
|
#include "nsINameSpaceManager.h"
|
2011-04-07 18:04:40 -07:00
|
|
|
#include "nsRenderingContext.h"
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
#include "nsIDOMMutationEvent.h"
|
|
|
|
#include "nsFrameManager.h"
|
|
|
|
#include "nsStyleChangeList.h"
|
|
|
|
|
|
|
|
#include "nsGkAtoms.h"
|
|
|
|
#include "nsMathMLParts.h"
|
|
|
|
#include "nsMathMLContainerFrame.h"
|
|
|
|
#include "nsAutoPtr.h"
|
|
|
|
#include "nsStyleSet.h"
|
|
|
|
#include "nsDisplayList.h"
|
|
|
|
#include "nsCSSFrameConstructor.h"
|
2008-01-09 01:38:28 -08:00
|
|
|
#include "nsIReflowCallback.h"
|
2012-10-26 06:32:10 -07:00
|
|
|
#include "mozilla/Likely.h"
|
2012-12-27 08:12:05 -08:00
|
|
|
#include "nsIScriptError.h"
|
|
|
|
#include "nsContentUtils.h"
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2010-03-28 18:46:55 -07:00
|
|
|
using namespace mozilla;
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
//
|
|
|
|
// nsMathMLContainerFrame implementation
|
|
|
|
//
|
|
|
|
|
2009-09-12 09:49:24 -07:00
|
|
|
NS_IMPL_FRAMEARENA_HELPERS(nsMathMLContainerFrame)
|
|
|
|
|
2009-01-12 11:20:59 -08:00
|
|
|
NS_QUERYFRAME_HEAD(nsMathMLContainerFrame)
|
2013-04-03 16:35:07 -07:00
|
|
|
NS_QUERYFRAME_ENTRY(nsIMathMLFrame)
|
2011-12-27 12:18:48 -08:00
|
|
|
NS_QUERYFRAME_TAIL_INHERITING(nsContainerFrame)
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
// =============================================================================
|
|
|
|
|
|
|
|
// error handlers
|
|
|
|
// provide a feedback to the user when a frame with bad markup can not be rendered
|
|
|
|
nsresult
|
2011-04-07 18:04:40 -07:00
|
|
|
nsMathMLContainerFrame::ReflowError(nsRenderingContext& aRenderingContext,
|
2007-03-22 10:30:00 -07:00
|
|
|
nsHTMLReflowMetrics& aDesiredSize)
|
|
|
|
{
|
|
|
|
// clear all other flags and record that there is an error with this frame
|
|
|
|
mEmbellishData.flags = 0;
|
|
|
|
mPresentationData.flags = NS_MATHML_ERROR;
|
|
|
|
|
|
|
|
///////////////
|
|
|
|
// Set font
|
2011-08-14 10:08:04 -07:00
|
|
|
nsRefPtr<nsFontMetrics> fm;
|
|
|
|
nsLayoutUtils::GetFontMetricsForFrame(this, getter_AddRefs(fm));
|
|
|
|
aRenderingContext.SetFont(fm);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
// bounding metrics
|
|
|
|
nsAutoString errorMsg; errorMsg.AssignLiteral("invalid-markup");
|
2011-04-07 18:04:40 -07:00
|
|
|
mBoundingMetrics =
|
|
|
|
aRenderingContext.GetBoundingMetrics(errorMsg.get(), errorMsg.Length());
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
// reflow metrics
|
2011-04-07 21:18:43 -07:00
|
|
|
aDesiredSize.ascent = fm->MaxAscent();
|
|
|
|
nscoord descent = fm->MaxDescent();
|
2007-03-22 10:30:00 -07:00
|
|
|
aDesiredSize.height = aDesiredSize.ascent + descent;
|
|
|
|
aDesiredSize.width = mBoundingMetrics.width;
|
|
|
|
|
|
|
|
// Also return our bounding metrics
|
|
|
|
aDesiredSize.mBoundingMetrics = mBoundingMetrics;
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
class nsDisplayMathMLError : public nsDisplayItem {
|
|
|
|
public:
|
2010-08-13 03:01:13 -07:00
|
|
|
nsDisplayMathMLError(nsDisplayListBuilder* aBuilder, nsIFrame* aFrame)
|
|
|
|
: nsDisplayItem(aBuilder, aFrame) {
|
2007-03-22 10:30:00 -07:00
|
|
|
MOZ_COUNT_CTOR(nsDisplayMathMLError);
|
|
|
|
}
|
|
|
|
#ifdef NS_BUILD_REFCNT_LOGGING
|
|
|
|
virtual ~nsDisplayMathMLError() {
|
|
|
|
MOZ_COUNT_DTOR(nsDisplayMathMLError);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2009-09-06 17:35:14 -07:00
|
|
|
virtual void Paint(nsDisplayListBuilder* aBuilder,
|
2011-04-07 18:04:40 -07:00
|
|
|
nsRenderingContext* aCtx);
|
2010-07-15 14:07:49 -07:00
|
|
|
NS_DISPLAY_DECL_NAME("MathMLError", TYPE_MATHML_ERROR)
|
2007-03-22 10:30:00 -07:00
|
|
|
};
|
|
|
|
|
|
|
|
void nsDisplayMathMLError::Paint(nsDisplayListBuilder* aBuilder,
|
2011-04-07 18:04:40 -07:00
|
|
|
nsRenderingContext* aCtx)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
|
|
|
// Set color and font ...
|
2011-08-14 10:08:04 -07:00
|
|
|
nsRefPtr<nsFontMetrics> fm;
|
|
|
|
nsLayoutUtils::GetFontMetricsForFrame(mFrame, getter_AddRefs(fm));
|
|
|
|
aCtx->SetFont(fm);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2010-08-13 03:01:58 -07:00
|
|
|
nsPoint pt = ToReferenceFrame();
|
2007-03-22 10:30:00 -07:00
|
|
|
aCtx->SetColor(NS_RGB(255,0,0));
|
|
|
|
aCtx->FillRect(nsRect(pt, mFrame->GetSize()));
|
|
|
|
aCtx->SetColor(NS_RGB(255,255,255));
|
|
|
|
|
2011-04-07 21:18:43 -07:00
|
|
|
nscoord ascent = aCtx->FontMetrics()->MaxAscent();
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2011-04-07 21:18:43 -07:00
|
|
|
NS_NAMED_LITERAL_STRING(errorMsg, "invalid-markup");
|
2012-08-22 08:56:38 -07:00
|
|
|
aCtx->DrawString(errorMsg.get(), uint32_t(errorMsg.Length()),
|
2011-04-07 21:18:43 -07:00
|
|
|
pt.x, pt.y+ascent);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
/* /////////////
|
|
|
|
* nsIMathMLFrame - support methods for stretchy elements
|
|
|
|
* =============================================================================
|
|
|
|
*/
|
|
|
|
|
2011-09-28 23:19:26 -07:00
|
|
|
static bool
|
2008-02-25 20:19:36 -08:00
|
|
|
IsForeignChild(const nsIFrame* aFrame)
|
|
|
|
{
|
|
|
|
// This counts nsMathMLmathBlockFrame as a foreign child, because it
|
|
|
|
// uses block reflow
|
|
|
|
return !(aFrame->IsFrameOfType(nsIFrame::eMathML)) ||
|
|
|
|
aFrame->GetType() == nsGkAtoms::blockFrame;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2010-03-28 18:46:55 -07:00
|
|
|
DestroyHTMLReflowMetrics(void *aPropertyValue)
|
2008-02-25 20:19:36 -08:00
|
|
|
{
|
|
|
|
delete static_cast<nsHTMLReflowMetrics*>(aPropertyValue);
|
|
|
|
}
|
|
|
|
|
2010-03-28 18:46:55 -07:00
|
|
|
NS_DECLARE_FRAME_PROPERTY(HTMLReflowMetricsProperty, DestroyHTMLReflowMetrics)
|
|
|
|
|
2008-02-25 20:19:36 -08:00
|
|
|
/* static */ void
|
|
|
|
nsMathMLContainerFrame::SaveReflowAndBoundingMetricsFor(nsIFrame* aFrame,
|
|
|
|
const nsHTMLReflowMetrics& aReflowMetrics,
|
|
|
|
const nsBoundingMetrics& aBoundingMetrics)
|
|
|
|
{
|
|
|
|
nsHTMLReflowMetrics *metrics = new nsHTMLReflowMetrics(aReflowMetrics);
|
|
|
|
metrics->mBoundingMetrics = aBoundingMetrics;
|
2010-03-28 18:46:55 -07:00
|
|
|
aFrame->Properties().Set(HTMLReflowMetricsProperty(), metrics);
|
2008-02-25 20:19:36 -08:00
|
|
|
}
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
// helper method to facilitate getting the reflow and bounding metrics
|
2008-02-25 20:19:36 -08:00
|
|
|
/* static */ void
|
2007-03-22 10:30:00 -07:00
|
|
|
nsMathMLContainerFrame::GetReflowAndBoundingMetricsFor(nsIFrame* aFrame,
|
|
|
|
nsHTMLReflowMetrics& aReflowMetrics,
|
|
|
|
nsBoundingMetrics& aBoundingMetrics,
|
|
|
|
eMathMLFrameType* aMathMLFrameType)
|
|
|
|
{
|
|
|
|
NS_PRECONDITION(aFrame, "null arg");
|
|
|
|
|
2008-02-25 20:19:36 -08:00
|
|
|
nsHTMLReflowMetrics *metrics = static_cast<nsHTMLReflowMetrics*>
|
2010-03-28 18:46:55 -07:00
|
|
|
(aFrame->Properties().Get(HTMLReflowMetricsProperty()));
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2008-02-25 20:19:36 -08:00
|
|
|
// IMPORTANT: This function is only meant to be called in Place() methods
|
|
|
|
// where it is assumed that SaveReflowAndBoundingMetricsFor has recorded the
|
|
|
|
// information.
|
|
|
|
NS_ASSERTION(metrics, "Didn't SaveReflowAndBoundingMetricsFor frame!");
|
|
|
|
if (metrics) {
|
|
|
|
aReflowMetrics = *metrics;
|
|
|
|
aBoundingMetrics = metrics->mBoundingMetrics;
|
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2008-02-25 20:19:36 -08:00
|
|
|
if (aMathMLFrameType) {
|
|
|
|
if (!IsForeignChild(aFrame)) {
|
2009-01-12 11:20:59 -08:00
|
|
|
nsIMathMLFrame* mathMLFrame = do_QueryFrame(aFrame);
|
2008-02-25 20:19:36 -08:00
|
|
|
if (mathMLFrame) {
|
2007-03-22 10:30:00 -07:00
|
|
|
*aMathMLFrameType = mathMLFrame->GetMathMLFrameType();
|
2008-02-25 20:19:36 -08:00
|
|
|
return;
|
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
2008-02-25 20:19:36 -08:00
|
|
|
*aMathMLFrameType = eMathMLFrameType_UNKNOWN;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2008-02-25 20:19:36 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
nsMathMLContainerFrame::ClearSavedChildMetrics()
|
|
|
|
{
|
|
|
|
nsIFrame* childFrame = mFrames.FirstChild();
|
2010-03-28 18:46:55 -07:00
|
|
|
FramePropertyTable* props = PresContext()->PropertyTable();
|
2008-02-25 20:19:36 -08:00
|
|
|
while (childFrame) {
|
2010-03-28 18:46:55 -07:00
|
|
|
props->Delete(childFrame, HTMLReflowMetricsProperty());
|
2008-02-25 20:19:36 -08:00
|
|
|
childFrame = childFrame->GetNextSibling();
|
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
// helper to get the preferred size that a container frame should use to fire
|
|
|
|
// the stretch on its stretchy child frames.
|
|
|
|
void
|
2011-04-07 18:04:40 -07:00
|
|
|
nsMathMLContainerFrame::GetPreferredStretchSize(nsRenderingContext& aRenderingContext,
|
2012-08-22 08:56:38 -07:00
|
|
|
uint32_t aOptions,
|
2007-03-22 10:30:00 -07:00
|
|
|
nsStretchDirection aStretchDirection,
|
|
|
|
nsBoundingMetrics& aPreferredStretchSize)
|
|
|
|
{
|
|
|
|
if (aOptions & STRETCH_CONSIDER_ACTUAL_SIZE) {
|
|
|
|
// when our actual size is ok, just use it
|
|
|
|
aPreferredStretchSize = mBoundingMetrics;
|
|
|
|
}
|
|
|
|
else if (aOptions & STRETCH_CONSIDER_EMBELLISHMENTS) {
|
|
|
|
// compute our up-to-date size using Place()
|
|
|
|
nsHTMLReflowMetrics metrics;
|
2011-10-17 07:59:28 -07:00
|
|
|
Place(aRenderingContext, false, metrics);
|
2007-03-22 10:30:00 -07:00
|
|
|
aPreferredStretchSize = metrics.mBoundingMetrics;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
// compute a size that doesn't include embellishements
|
2011-09-28 23:19:26 -07:00
|
|
|
bool stretchAll =
|
2011-05-12 17:01:08 -07:00
|
|
|
NS_MATHML_WILL_STRETCH_ALL_CHILDREN_VERTICALLY(mPresentationData.flags) ||
|
|
|
|
NS_MATHML_WILL_STRETCH_ALL_CHILDREN_HORIZONTALLY(mPresentationData.flags);
|
2007-03-22 10:30:00 -07:00
|
|
|
NS_ASSERTION(NS_MATHML_IS_EMBELLISH_OPERATOR(mEmbellishData.flags) ||
|
2011-05-12 17:01:08 -07:00
|
|
|
stretchAll,
|
2007-03-22 10:30:00 -07:00
|
|
|
"invalid call to GetPreferredStretchSize");
|
2011-09-28 23:19:26 -07:00
|
|
|
bool firstTime = true;
|
2007-03-22 10:30:00 -07:00
|
|
|
nsBoundingMetrics bm, bmChild;
|
2011-05-12 17:01:08 -07:00
|
|
|
nsIFrame* childFrame =
|
2011-08-24 13:54:30 -07:00
|
|
|
stretchAll ? GetFirstPrincipalChild() : mPresentationData.baseFrame;
|
2007-03-22 10:30:00 -07:00
|
|
|
while (childFrame) {
|
|
|
|
// initializations in case this child happens not to be a MathML frame
|
2009-01-12 11:20:59 -08:00
|
|
|
nsIMathMLFrame* mathMLFrame = do_QueryFrame(childFrame);
|
2007-03-22 10:30:00 -07:00
|
|
|
if (mathMLFrame) {
|
|
|
|
nsEmbellishData embellishData;
|
|
|
|
nsPresentationData presentationData;
|
|
|
|
mathMLFrame->GetEmbellishData(embellishData);
|
|
|
|
mathMLFrame->GetPresentationData(presentationData);
|
|
|
|
if (NS_MATHML_IS_EMBELLISH_OPERATOR(embellishData.flags) &&
|
|
|
|
embellishData.direction == aStretchDirection &&
|
|
|
|
presentationData.baseFrame) {
|
|
|
|
// embellishements are not included, only consider the inner first child itself
|
2008-02-25 20:19:36 -08:00
|
|
|
// XXXkt Does that mean the core descendent frame should be used
|
|
|
|
// instead of the base child?
|
2009-01-12 11:20:59 -08:00
|
|
|
nsIMathMLFrame* mathMLchildFrame = do_QueryFrame(presentationData.baseFrame);
|
2007-03-22 10:30:00 -07:00
|
|
|
if (mathMLchildFrame) {
|
|
|
|
mathMLFrame = mathMLchildFrame;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
mathMLFrame->GetBoundingMetrics(bmChild);
|
|
|
|
}
|
2008-02-25 20:19:36 -08:00
|
|
|
else {
|
|
|
|
nsHTMLReflowMetrics unused;
|
|
|
|
GetReflowAndBoundingMetricsFor(childFrame, unused, bmChild);
|
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
if (firstTime) {
|
2011-10-17 07:59:28 -07:00
|
|
|
firstTime = false;
|
2007-03-22 10:30:00 -07:00
|
|
|
bm = bmChild;
|
2011-05-12 17:01:08 -07:00
|
|
|
if (!stretchAll) {
|
|
|
|
// we may get here for cases such as <msup><mo>...</mo> ... </msup>,
|
|
|
|
// or <maction>...<mo>...</mo></maction>.
|
2007-03-22 10:30:00 -07:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
if (NS_MATHML_WILL_STRETCH_ALL_CHILDREN_HORIZONTALLY(mPresentationData.flags)) {
|
|
|
|
// if we get here, it means this is container that will stack its children
|
|
|
|
// vertically and fire an horizontal stretch on each them. This is the case
|
|
|
|
// for \munder, \mover, \munderover. We just sum-up the size vertically.
|
|
|
|
bm.descent += bmChild.ascent + bmChild.descent;
|
2008-07-21 00:32:46 -07:00
|
|
|
// Sometimes non-spacing marks (when width is zero) are positioned
|
|
|
|
// to the left of the origin, but it is the distance between left
|
|
|
|
// and right bearing that is important rather than the offsets from
|
|
|
|
// the origin.
|
|
|
|
if (bmChild.width == 0) {
|
|
|
|
bmChild.rightBearing -= bmChild.leftBearing;
|
|
|
|
bmChild.leftBearing = 0;
|
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
if (bm.leftBearing > bmChild.leftBearing)
|
|
|
|
bm.leftBearing = bmChild.leftBearing;
|
|
|
|
if (bm.rightBearing < bmChild.rightBearing)
|
|
|
|
bm.rightBearing = bmChild.rightBearing;
|
|
|
|
}
|
|
|
|
else if (NS_MATHML_WILL_STRETCH_ALL_CHILDREN_VERTICALLY(mPresentationData.flags)) {
|
|
|
|
// just sum-up the sizes horizontally.
|
|
|
|
bm += bmChild;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
NS_ERROR("unexpected case in GetPreferredStretchSize");
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
childFrame = childFrame->GetNextSibling();
|
|
|
|
}
|
|
|
|
aPreferredStretchSize = bm;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2011-04-07 18:04:40 -07:00
|
|
|
nsMathMLContainerFrame::Stretch(nsRenderingContext& aRenderingContext,
|
2007-03-22 10:30:00 -07:00
|
|
|
nsStretchDirection aStretchDirection,
|
|
|
|
nsBoundingMetrics& aContainerSize,
|
|
|
|
nsHTMLReflowMetrics& aDesiredStretchSize)
|
|
|
|
{
|
|
|
|
if (NS_MATHML_IS_EMBELLISH_OPERATOR(mEmbellishData.flags)) {
|
|
|
|
|
|
|
|
if (NS_MATHML_STRETCH_WAS_DONE(mPresentationData.flags)) {
|
|
|
|
NS_WARNING("it is wrong to fire stretch more than once on a frame");
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
mPresentationData.flags |= NS_MATHML_STRETCH_DONE;
|
|
|
|
|
|
|
|
if (NS_MATHML_HAS_ERROR(mPresentationData.flags)) {
|
|
|
|
NS_WARNING("it is wrong to fire stretch on a erroneous frame");
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Pass the stretch to the base child ...
|
|
|
|
|
2007-12-28 15:04:19 -08:00
|
|
|
nsIFrame* baseFrame = mPresentationData.baseFrame;
|
|
|
|
if (baseFrame) {
|
2009-01-12 11:20:59 -08:00
|
|
|
nsIMathMLFrame* mathMLFrame = do_QueryFrame(baseFrame);
|
2007-03-22 10:30:00 -07:00
|
|
|
NS_ASSERTION(mathMLFrame, "Something is wrong somewhere");
|
|
|
|
if (mathMLFrame) {
|
2011-09-28 23:19:26 -07:00
|
|
|
bool stretchAll =
|
2007-03-22 10:30:00 -07:00
|
|
|
NS_MATHML_WILL_STRETCH_ALL_CHILDREN_VERTICALLY(mPresentationData.flags) ||
|
|
|
|
NS_MATHML_WILL_STRETCH_ALL_CHILDREN_HORIZONTALLY(mPresentationData.flags);
|
|
|
|
|
|
|
|
// And the trick is that the child's rect.x is still holding the descent,
|
|
|
|
// and rect.y is still holding the ascent ...
|
|
|
|
nsHTMLReflowMetrics childSize(aDesiredStretchSize);
|
2007-12-28 15:04:19 -08:00
|
|
|
GetReflowAndBoundingMetricsFor(baseFrame, childSize, childSize.mBoundingMetrics);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
// See if we should downsize and confine the stretch to us...
|
|
|
|
// XXX there may be other cases where we can downsize the stretch,
|
|
|
|
// e.g., the first ∑ might appear big in the following situation
|
|
|
|
// <math xmlns='http://www.w3.org/1998/Math/MathML'>
|
|
|
|
// <mstyle>
|
|
|
|
// <msub>
|
|
|
|
// <msub><mo>∑</mo><mfrac><mi>a</mi><mi>b</mi></mfrac></msub>
|
|
|
|
// <msub><mo>∑</mo><mfrac><mi>a</mi><mi>b</mi></mfrac></msub>
|
|
|
|
// </msub>
|
|
|
|
// </mstyle>
|
|
|
|
// </math>
|
|
|
|
nsBoundingMetrics containerSize = aContainerSize;
|
|
|
|
if (aStretchDirection != NS_STRETCH_DIRECTION_DEFAULT &&
|
|
|
|
aStretchDirection != mEmbellishData.direction) {
|
|
|
|
if (mEmbellishData.direction == NS_STRETCH_DIRECTION_UNSUPPORTED) {
|
|
|
|
containerSize = childSize.mBoundingMetrics;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
GetPreferredStretchSize(aRenderingContext,
|
|
|
|
stretchAll ? STRETCH_CONSIDER_EMBELLISHMENTS : 0,
|
|
|
|
mEmbellishData.direction, containerSize);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// do the stretching...
|
|
|
|
mathMLFrame->Stretch(aRenderingContext,
|
|
|
|
mEmbellishData.direction, containerSize, childSize);
|
|
|
|
// store the updated metrics
|
2008-02-25 20:19:36 -08:00
|
|
|
SaveReflowAndBoundingMetricsFor(baseFrame, childSize,
|
|
|
|
childSize.mBoundingMetrics);
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
// Remember the siblings which were _deferred_.
|
|
|
|
// Now that this embellished child may have changed, we need to
|
|
|
|
// fire the stretch on its siblings using our updated size
|
|
|
|
|
|
|
|
if (stretchAll) {
|
|
|
|
|
|
|
|
nsStretchDirection stretchDir =
|
|
|
|
NS_MATHML_WILL_STRETCH_ALL_CHILDREN_VERTICALLY(mPresentationData.flags) ?
|
|
|
|
NS_STRETCH_DIRECTION_VERTICAL : NS_STRETCH_DIRECTION_HORIZONTAL;
|
|
|
|
|
|
|
|
GetPreferredStretchSize(aRenderingContext, STRETCH_CONSIDER_EMBELLISHMENTS,
|
|
|
|
stretchDir, containerSize);
|
|
|
|
|
2007-12-28 15:04:19 -08:00
|
|
|
nsIFrame* childFrame = mFrames.FirstChild();
|
2007-03-22 10:30:00 -07:00
|
|
|
while (childFrame) {
|
|
|
|
if (childFrame != mPresentationData.baseFrame) {
|
2009-01-12 11:20:59 -08:00
|
|
|
mathMLFrame = do_QueryFrame(childFrame);
|
2007-03-22 10:30:00 -07:00
|
|
|
if (mathMLFrame) {
|
|
|
|
// retrieve the metrics that was stored at the previous pass
|
|
|
|
GetReflowAndBoundingMetricsFor(childFrame,
|
|
|
|
childSize, childSize.mBoundingMetrics);
|
|
|
|
// do the stretching...
|
|
|
|
mathMLFrame->Stretch(aRenderingContext, stretchDir,
|
|
|
|
containerSize, childSize);
|
|
|
|
// store the updated metrics
|
2008-02-25 20:19:36 -08:00
|
|
|
SaveReflowAndBoundingMetricsFor(childFrame, childSize,
|
|
|
|
childSize.mBoundingMetrics);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
childFrame = childFrame->GetNextSibling();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// re-position all our children
|
2011-10-17 07:59:28 -07:00
|
|
|
nsresult rv = Place(aRenderingContext, true, aDesiredStretchSize);
|
2007-03-22 10:30:00 -07:00
|
|
|
if (NS_MATHML_HAS_ERROR(mPresentationData.flags) || NS_FAILED(rv)) {
|
|
|
|
// Make sure the child frames get their DidReflow() calls.
|
|
|
|
DidReflowChildren(mFrames.FirstChild());
|
|
|
|
}
|
|
|
|
|
|
|
|
// If our parent is not embellished, it means we are the outermost embellished
|
|
|
|
// container and so we put the spacing, otherwise we don't include the spacing,
|
|
|
|
// the outermost embellished container will take care of it.
|
|
|
|
|
|
|
|
nsEmbellishData parentData;
|
|
|
|
GetEmbellishDataFrom(mParent, parentData);
|
|
|
|
// ensure that we are the embellished child, not just a sibling
|
|
|
|
// (need to test coreFrame since <mfrac> resets other things)
|
|
|
|
if (parentData.coreFrame != mEmbellishData.coreFrame) {
|
|
|
|
// (we fetch values from the core since they may use units that depend
|
|
|
|
// on style data, and style changes could have occurred in the core since
|
|
|
|
// our last visit there)
|
|
|
|
nsEmbellishData coreData;
|
|
|
|
GetEmbellishDataFrom(mEmbellishData.coreFrame, coreData);
|
|
|
|
|
2011-12-21 14:21:59 -08:00
|
|
|
mBoundingMetrics.width +=
|
|
|
|
coreData.leadingSpace + coreData.trailingSpace;
|
2007-03-22 10:30:00 -07:00
|
|
|
aDesiredStretchSize.width = mBoundingMetrics.width;
|
|
|
|
aDesiredStretchSize.mBoundingMetrics.width = mBoundingMetrics.width;
|
|
|
|
|
2013-05-29 16:26:40 -07:00
|
|
|
nscoord dx = (StyleVisibility()->mDirection ?
|
2011-12-21 14:21:59 -08:00
|
|
|
coreData.trailingSpace : coreData.leadingSpace);
|
2007-12-28 15:04:19 -08:00
|
|
|
if (dx != 0) {
|
|
|
|
mBoundingMetrics.leftBearing += dx;
|
|
|
|
mBoundingMetrics.rightBearing += dx;
|
|
|
|
aDesiredStretchSize.mBoundingMetrics.leftBearing += dx;
|
|
|
|
aDesiredStretchSize.mBoundingMetrics.rightBearing += dx;
|
|
|
|
|
|
|
|
nsIFrame* childFrame = mFrames.FirstChild();
|
|
|
|
while (childFrame) {
|
|
|
|
childFrame->SetPosition(childFrame->GetPosition()
|
|
|
|
+ nsPoint(dx, 0));
|
|
|
|
childFrame = childFrame->GetNextSibling();
|
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
}
|
2007-12-28 15:04:19 -08:00
|
|
|
|
2008-02-25 20:19:36 -08:00
|
|
|
// Finished with these:
|
|
|
|
ClearSavedChildMetrics();
|
2007-12-28 15:04:19 -08:00
|
|
|
// Set our overflow area
|
|
|
|
GatherAndStoreOverflow(&aDesiredStretchSize);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
2011-04-07 18:04:40 -07:00
|
|
|
nsMathMLContainerFrame::FinalizeReflow(nsRenderingContext& aRenderingContext,
|
2007-03-22 10:30:00 -07:00
|
|
|
nsHTMLReflowMetrics& aDesiredSize)
|
|
|
|
{
|
|
|
|
// During reflow, we use rect.x and rect.y as placeholders for the child's ascent
|
|
|
|
// and descent in expectation of a stretch command. Hence we need to ensure that
|
|
|
|
// a stretch command will actually be fired later on, after exiting from our
|
|
|
|
// reflow. If the stretch is not fired, the rect.x, and rect.y will remain
|
|
|
|
// with inappropriate data causing children to be improperly positioned.
|
|
|
|
// This helper method checks to see if our parent will fire a stretch command
|
|
|
|
// targeted at us. If not, we go ahead and fire an involutive stretch on
|
|
|
|
// ourselves. This will clear all the rect.x and rect.y, and return our
|
|
|
|
// desired size.
|
|
|
|
|
|
|
|
|
|
|
|
// First, complete the post-reflow hook.
|
|
|
|
// We use the information in our children rectangles to position them.
|
|
|
|
// If placeOrigin==false, then Place() will not touch rect.x, and rect.y.
|
|
|
|
// They will still be holding the ascent and descent for each child.
|
|
|
|
|
|
|
|
// The first clause caters for any non-embellished container.
|
|
|
|
// The second clause is for a container which won't fire stretch even though it is
|
|
|
|
// embellished, e.g., as in <mfrac><mo>...</mo> ... </mfrac>, the test is convoluted
|
|
|
|
// because it excludes the particular case of the core <mo>...</mo> itself.
|
|
|
|
// (<mo> needs to fire stretch on its MathMLChar in any case to initialize it)
|
2011-09-28 23:19:26 -07:00
|
|
|
bool placeOrigin = !NS_MATHML_IS_EMBELLISH_OPERATOR(mEmbellishData.flags) ||
|
2007-03-22 10:30:00 -07:00
|
|
|
(mEmbellishData.coreFrame != this && !mPresentationData.baseFrame &&
|
|
|
|
mEmbellishData.direction == NS_STRETCH_DIRECTION_UNSUPPORTED);
|
|
|
|
nsresult rv = Place(aRenderingContext, placeOrigin, aDesiredSize);
|
|
|
|
|
|
|
|
// Place() will call FinishReflowChild() when placeOrigin is true but if
|
|
|
|
// it returns before reaching FinishReflowChild() due to errors we need
|
|
|
|
// to fulfill the reflow protocol by calling DidReflow for the child frames
|
|
|
|
// that still needs it here (or we may crash - bug 366012).
|
|
|
|
// If placeOrigin is false we should reach Place() with aPlaceOrigin == true
|
|
|
|
// through Stretch() eventually.
|
|
|
|
if (NS_MATHML_HAS_ERROR(mPresentationData.flags) || NS_FAILED(rv)) {
|
2011-08-24 13:54:30 -07:00
|
|
|
DidReflowChildren(GetFirstPrincipalChild());
|
2007-03-22 10:30:00 -07:00
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
2011-09-28 23:19:26 -07:00
|
|
|
bool parentWillFireStretch = false;
|
2007-03-22 10:30:00 -07:00
|
|
|
if (!placeOrigin) {
|
|
|
|
// This means the rect.x and rect.y of our children were not set!!
|
|
|
|
// Don't go without checking to see if our parent will later fire a Stretch() command
|
|
|
|
// targeted at us. The Stretch() will cause the rect.x and rect.y to clear...
|
2009-01-12 11:20:59 -08:00
|
|
|
nsIMathMLFrame* mathMLFrame = do_QueryFrame(mParent);
|
2007-03-22 10:30:00 -07:00
|
|
|
if (mathMLFrame) {
|
|
|
|
nsEmbellishData embellishData;
|
|
|
|
nsPresentationData presentationData;
|
|
|
|
mathMLFrame->GetEmbellishData(embellishData);
|
|
|
|
mathMLFrame->GetPresentationData(presentationData);
|
|
|
|
if (NS_MATHML_WILL_STRETCH_ALL_CHILDREN_VERTICALLY(presentationData.flags) ||
|
|
|
|
NS_MATHML_WILL_STRETCH_ALL_CHILDREN_HORIZONTALLY(presentationData.flags) ||
|
|
|
|
(NS_MATHML_IS_EMBELLISH_OPERATOR(embellishData.flags)
|
|
|
|
&& presentationData.baseFrame == this))
|
|
|
|
{
|
2011-10-17 07:59:28 -07:00
|
|
|
parentWillFireStretch = true;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
if (!parentWillFireStretch) {
|
|
|
|
// There is nobody who will fire the stretch for us, we do it ourselves!
|
|
|
|
|
2011-09-28 23:19:26 -07:00
|
|
|
bool stretchAll =
|
2007-03-22 10:30:00 -07:00
|
|
|
/* NS_MATHML_WILL_STRETCH_ALL_CHILDREN_VERTICALLY(mPresentationData.flags) || */
|
|
|
|
NS_MATHML_WILL_STRETCH_ALL_CHILDREN_HORIZONTALLY(mPresentationData.flags);
|
|
|
|
|
|
|
|
nsBoundingMetrics defaultSize;
|
|
|
|
if (mEmbellishData.coreFrame == this /* case of a bare <mo>...</mo> itself */
|
|
|
|
|| stretchAll) { /* or <mover><mo>...</mo>...</mover>, or friends */
|
|
|
|
// use our current size as computed earlier by Place()
|
|
|
|
defaultSize = aDesiredSize.mBoundingMetrics;
|
|
|
|
}
|
|
|
|
else { /* case of <msup><mo>...</mo>...</msup> or friends */
|
|
|
|
// compute a size that doesn't include embellishments
|
|
|
|
GetPreferredStretchSize(aRenderingContext, 0, mEmbellishData.direction,
|
|
|
|
defaultSize);
|
|
|
|
}
|
|
|
|
Stretch(aRenderingContext, NS_STRETCH_DIRECTION_DEFAULT, defaultSize,
|
|
|
|
aDesiredSize);
|
2012-06-25 12:59:42 -07:00
|
|
|
#ifdef DEBUG
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
|
|
|
// The Place() call above didn't request FinishReflowChild(),
|
|
|
|
// so let's check that we eventually did through Stretch().
|
2011-08-24 13:54:30 -07:00
|
|
|
nsIFrame* childFrame = GetFirstPrincipalChild();
|
2007-03-22 10:30:00 -07:00
|
|
|
for ( ; childFrame; childFrame = childFrame->GetNextSibling()) {
|
|
|
|
NS_ASSERTION(!(childFrame->GetStateBits() & NS_FRAME_IN_REFLOW),
|
|
|
|
"DidReflow() was never called");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// see if we should fix the spacing
|
|
|
|
FixInterFrameSpacing(aDesiredSize);
|
|
|
|
|
2007-12-28 15:04:19 -08:00
|
|
|
// Also return our bounding metrics
|
|
|
|
aDesiredSize.mBoundingMetrics = mBoundingMetrics;
|
|
|
|
|
2008-02-25 20:19:36 -08:00
|
|
|
if (!parentWillFireStretch) {
|
|
|
|
// Not expecting a stretch.
|
|
|
|
// Finished with these:
|
|
|
|
ClearSavedChildMetrics();
|
|
|
|
// Set our overflow area.
|
2007-12-28 15:04:19 -08:00
|
|
|
GatherAndStoreOverflow(&aDesiredSize);
|
|
|
|
}
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/* /////////////
|
|
|
|
* nsIMathMLFrame - support methods for scripting elements (nested frames
|
|
|
|
* within msub, msup, msubsup, munder, mover, munderover, mmultiscripts,
|
|
|
|
* mfrac, mroot, mtable).
|
|
|
|
* =============================================================================
|
|
|
|
*/
|
|
|
|
|
|
|
|
// helper to let the update of presentation data pass through
|
|
|
|
// a subtree that may contain non-mathml container frames
|
|
|
|
/* static */ void
|
|
|
|
nsMathMLContainerFrame::PropagatePresentationDataFor(nsIFrame* aFrame,
|
2012-08-22 08:56:38 -07:00
|
|
|
uint32_t aFlagsValues,
|
|
|
|
uint32_t aFlagsToUpdate)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2008-01-09 01:38:28 -08:00
|
|
|
if (!aFrame || !aFlagsToUpdate)
|
2007-03-22 10:30:00 -07:00
|
|
|
return;
|
2009-01-12 11:20:59 -08:00
|
|
|
nsIMathMLFrame* mathMLFrame = do_QueryFrame(aFrame);
|
2007-03-22 10:30:00 -07:00
|
|
|
if (mathMLFrame) {
|
|
|
|
// update
|
2008-01-09 01:38:28 -08:00
|
|
|
mathMLFrame->UpdatePresentationData(aFlagsValues,
|
2007-03-22 10:30:00 -07:00
|
|
|
aFlagsToUpdate);
|
|
|
|
// propagate using the base method to make sure that the control
|
|
|
|
// is passed on to MathML frames that may be overloading the method
|
|
|
|
mathMLFrame->UpdatePresentationDataFromChildAt(0, -1,
|
2008-01-09 01:38:28 -08:00
|
|
|
aFlagsValues, aFlagsToUpdate);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
// propagate down the subtrees
|
2011-08-24 13:54:30 -07:00
|
|
|
nsIFrame* childFrame = aFrame->GetFirstPrincipalChild();
|
2007-03-22 10:30:00 -07:00
|
|
|
while (childFrame) {
|
|
|
|
PropagatePresentationDataFor(childFrame,
|
2008-01-09 01:38:28 -08:00
|
|
|
aFlagsValues, aFlagsToUpdate);
|
2007-03-22 10:30:00 -07:00
|
|
|
childFrame = childFrame->GetNextSibling();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* static */ void
|
|
|
|
nsMathMLContainerFrame::PropagatePresentationDataFromChildAt(nsIFrame* aParentFrame,
|
2012-08-22 08:56:38 -07:00
|
|
|
int32_t aFirstChildIndex,
|
|
|
|
int32_t aLastChildIndex,
|
|
|
|
uint32_t aFlagsValues,
|
|
|
|
uint32_t aFlagsToUpdate)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2008-01-09 01:38:28 -08:00
|
|
|
if (!aParentFrame || !aFlagsToUpdate)
|
2007-03-22 10:30:00 -07:00
|
|
|
return;
|
2012-08-22 08:56:38 -07:00
|
|
|
int32_t index = 0;
|
2011-08-24 13:54:30 -07:00
|
|
|
nsIFrame* childFrame = aParentFrame->GetFirstPrincipalChild();
|
2007-03-22 10:30:00 -07:00
|
|
|
while (childFrame) {
|
|
|
|
if ((index >= aFirstChildIndex) &&
|
|
|
|
((aLastChildIndex <= 0) || ((aLastChildIndex > 0) &&
|
|
|
|
(index <= aLastChildIndex)))) {
|
|
|
|
PropagatePresentationDataFor(childFrame,
|
2008-01-09 01:38:28 -08:00
|
|
|
aFlagsValues, aFlagsToUpdate);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
index++;
|
|
|
|
childFrame = childFrame->GetNextSibling();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* //////////////////
|
|
|
|
* Frame construction
|
|
|
|
* =============================================================================
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
2013-02-14 03:12:27 -08:00
|
|
|
void
|
2007-03-22 10:30:00 -07:00
|
|
|
nsMathMLContainerFrame::BuildDisplayList(nsDisplayListBuilder* aBuilder,
|
|
|
|
const nsRect& aDirtyRect,
|
|
|
|
const nsDisplayListSet& aLists)
|
|
|
|
{
|
|
|
|
// report an error if something wrong was found in this frame
|
|
|
|
if (NS_MATHML_HAS_ERROR(mPresentationData.flags)) {
|
|
|
|
if (!IsVisibleForPainting(aBuilder))
|
2013-02-14 03:12:27 -08:00
|
|
|
return;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2013-02-14 03:08:08 -08:00
|
|
|
aLists.Content()->AppendNewToTop(
|
|
|
|
new (aBuilder) nsDisplayMathMLError(aBuilder, this));
|
2013-02-14 03:12:27 -08:00
|
|
|
return;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2013-02-14 03:08:08 -08:00
|
|
|
DisplayBorderBackgroundOutline(aBuilder, aLists);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2013-02-14 03:08:08 -08:00
|
|
|
BuildDisplayListForNonBlockChildren(aBuilder, aDirtyRect, aLists,
|
|
|
|
DISPLAY_CHILD_INLINE);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2012-06-25 12:59:42 -07:00
|
|
|
#if defined(DEBUG) && defined(SHOW_BOUNDING_BOX)
|
2007-03-22 10:30:00 -07:00
|
|
|
// for visual debug
|
|
|
|
// ----------------
|
|
|
|
// if you want to see your bounding box, make sure to properly fill
|
|
|
|
// your mBoundingMetrics and mReference point, and set
|
|
|
|
// mPresentationData.flags |= NS_MATHML_SHOW_BOUNDING_METRICS
|
|
|
|
// in the Init() of your sub-class
|
2013-02-14 03:08:08 -08:00
|
|
|
DisplayBoundingMetrics(aBuilder, this, mReference, mBoundingMetrics, aLists);
|
2007-03-22 10:30:00 -07:00
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
// Note that this method re-builds the automatic data in the children -- not
|
|
|
|
// in aParentFrame itself (except for those particular operations that the
|
|
|
|
// parent frame may do in its TransmitAutomaticData()).
|
|
|
|
/* static */ void
|
|
|
|
nsMathMLContainerFrame::RebuildAutomaticDataForChildren(nsIFrame* aParentFrame)
|
|
|
|
{
|
|
|
|
// 1. As we descend the tree, make each child frame inherit data from
|
|
|
|
// the parent
|
|
|
|
// 2. As we ascend the tree, transmit any specific change that we want
|
|
|
|
// down the subtrees
|
2011-08-24 13:54:30 -07:00
|
|
|
nsIFrame* childFrame = aParentFrame->GetFirstPrincipalChild();
|
2007-03-22 10:30:00 -07:00
|
|
|
while (childFrame) {
|
2009-01-12 11:20:59 -08:00
|
|
|
nsIMathMLFrame* childMathMLFrame = do_QueryFrame(childFrame);
|
2007-03-22 10:30:00 -07:00
|
|
|
if (childMathMLFrame) {
|
|
|
|
childMathMLFrame->InheritAutomaticData(aParentFrame);
|
|
|
|
}
|
|
|
|
RebuildAutomaticDataForChildren(childFrame);
|
|
|
|
childFrame = childFrame->GetNextSibling();
|
|
|
|
}
|
2009-01-12 11:20:59 -08:00
|
|
|
nsIMathMLFrame* mathMLFrame = do_QueryFrame(aParentFrame);
|
2007-03-22 10:30:00 -07:00
|
|
|
if (mathMLFrame) {
|
|
|
|
mathMLFrame->TransmitAutomaticData();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* static */ nsresult
|
2009-02-10 14:05:27 -08:00
|
|
|
nsMathMLContainerFrame::ReLayoutChildren(nsIFrame* aParentFrame)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
|
|
|
if (!aParentFrame)
|
|
|
|
return NS_OK;
|
|
|
|
|
|
|
|
// walk-up to the first frame that is a MathML frame, stop if we reach <math>
|
|
|
|
nsIFrame* frame = aParentFrame;
|
|
|
|
while (1) {
|
|
|
|
nsIFrame* parent = frame->GetParent();
|
|
|
|
if (!parent || !parent->GetContent())
|
|
|
|
break;
|
|
|
|
|
|
|
|
// stop if it is a MathML frame
|
2009-01-12 11:20:59 -08:00
|
|
|
nsIMathMLFrame* mathMLFrame = do_QueryFrame(frame);
|
2008-01-09 01:38:28 -08:00
|
|
|
if (mathMLFrame)
|
2007-03-22 10:30:00 -07:00
|
|
|
break;
|
|
|
|
|
|
|
|
// stop if we reach the root <math> tag
|
|
|
|
nsIContent* content = frame->GetContent();
|
|
|
|
NS_ASSERTION(content, "dangling frame without a content node");
|
|
|
|
if (!content)
|
|
|
|
break;
|
2011-07-01 03:20:35 -07:00
|
|
|
if (content->GetNameSpaceID() == kNameSpaceID_MathML &&
|
|
|
|
content->Tag() == nsGkAtoms::math)
|
2007-03-22 10:30:00 -07:00
|
|
|
break;
|
|
|
|
|
2007-05-06 12:16:51 -07:00
|
|
|
// mark the frame dirty, and continue to climb up. It's important that
|
|
|
|
// we're NOT doing this to the frame we plan to pass to FrameNeedsReflow()
|
2009-02-10 14:05:27 -08:00
|
|
|
// XXXldb Why do we need to bother with this? Marking ancestor
|
|
|
|
// dirty (which we do below) should do a superset of the work this
|
|
|
|
// does.
|
2007-03-22 10:30:00 -07:00
|
|
|
frame->AddStateBits(NS_FRAME_IS_DIRTY | NS_FRAME_HAS_DIRTY_CHILDREN);
|
|
|
|
|
|
|
|
frame = parent;
|
|
|
|
}
|
|
|
|
|
|
|
|
// re-sync the presentation data and embellishment data of our children
|
|
|
|
RebuildAutomaticDataForChildren(frame);
|
|
|
|
|
|
|
|
// Ask our parent frame to reflow us
|
|
|
|
nsIFrame* parent = frame->GetParent();
|
|
|
|
NS_ASSERTION(parent, "No parent to pass the reflow request up to");
|
|
|
|
if (!parent)
|
|
|
|
return NS_OK;
|
|
|
|
|
2010-03-20 14:54:19 -07:00
|
|
|
frame->PresContext()->PresShell()->
|
2009-02-10 14:05:27 -08:00
|
|
|
FrameNeedsReflow(frame, nsIPresShell::eStyleChange, NS_FRAME_IS_DIRTY);
|
2010-03-20 14:54:19 -07:00
|
|
|
|
|
|
|
return NS_OK;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
// There are precise rules governing children of a MathML frame,
|
|
|
|
// and properties such as the scriptlevel depends on those rules.
|
|
|
|
// Hence for things to work, callers must use Append/Insert/etc wisely.
|
|
|
|
|
|
|
|
nsresult
|
2012-08-22 08:56:38 -07:00
|
|
|
nsMathMLContainerFrame::ChildListChanged(int32_t aModType)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
|
|
|
// If this is an embellished frame we need to rebuild the
|
|
|
|
// embellished hierarchy by walking-up to the parent of the
|
|
|
|
// outermost embellished container.
|
|
|
|
nsIFrame* frame = this;
|
|
|
|
if (mEmbellishData.coreFrame) {
|
|
|
|
nsIFrame* parent = mParent;
|
|
|
|
nsEmbellishData embellishData;
|
|
|
|
for ( ; parent; frame = parent, parent = parent->GetParent()) {
|
|
|
|
GetEmbellishDataFrom(parent, embellishData);
|
|
|
|
if (embellishData.coreFrame != mEmbellishData.coreFrame)
|
|
|
|
break;
|
2007-05-06 12:16:51 -07:00
|
|
|
|
|
|
|
// Important: do not do this to the frame we plan to pass to
|
|
|
|
// ReLayoutChildren
|
2009-02-10 14:05:27 -08:00
|
|
|
// XXXldb Why do we need to bother with this? Marking ancestor
|
|
|
|
// dirty (which we do below) should do a superset of the work this
|
|
|
|
// does.
|
2007-05-06 12:16:51 -07:00
|
|
|
frame->AddStateBits(NS_FRAME_IS_DIRTY | NS_FRAME_HAS_DIRTY_CHILDREN);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
}
|
2009-02-10 14:05:27 -08:00
|
|
|
return ReLayoutChildren(frame);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2011-08-24 13:54:30 -07:00
|
|
|
nsMathMLContainerFrame::AppendFrames(ChildListID aListID,
|
2009-07-30 10:23:32 -07:00
|
|
|
nsFrameList& aFrameList)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2011-08-24 13:54:30 -07:00
|
|
|
if (aListID != kPrincipalList) {
|
2007-03-22 10:30:00 -07:00
|
|
|
return NS_ERROR_INVALID_ARG;
|
|
|
|
}
|
2009-07-30 10:23:32 -07:00
|
|
|
mFrames.AppendFrames(this, aFrameList);
|
|
|
|
return ChildListChanged(nsIDOMMutationEvent::ADDITION);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2011-08-24 13:54:30 -07:00
|
|
|
nsMathMLContainerFrame::InsertFrames(ChildListID aListID,
|
2007-03-22 10:30:00 -07:00
|
|
|
nsIFrame* aPrevFrame,
|
2009-07-30 10:23:32 -07:00
|
|
|
nsFrameList& aFrameList)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2011-08-24 13:54:30 -07:00
|
|
|
if (aListID != kPrincipalList) {
|
2007-03-22 10:30:00 -07:00
|
|
|
return NS_ERROR_INVALID_ARG;
|
|
|
|
}
|
2009-07-30 10:23:32 -07:00
|
|
|
// Insert frames after aPrevFrame
|
|
|
|
mFrames.InsertFrames(this, aPrevFrame, aFrameList);
|
|
|
|
return ChildListChanged(nsIDOMMutationEvent::ADDITION);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2011-08-24 13:54:30 -07:00
|
|
|
nsMathMLContainerFrame::RemoveFrame(ChildListID aListID,
|
2007-03-22 10:30:00 -07:00
|
|
|
nsIFrame* aOldFrame)
|
|
|
|
{
|
2011-08-24 13:54:30 -07:00
|
|
|
if (aListID != kPrincipalList) {
|
2007-03-22 10:30:00 -07:00
|
|
|
return NS_ERROR_INVALID_ARG;
|
|
|
|
}
|
|
|
|
// remove the child frame
|
|
|
|
mFrames.DestroyFrame(aOldFrame);
|
|
|
|
return ChildListChanged(nsIDOMMutationEvent::REMOVAL);
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2012-08-22 08:56:38 -07:00
|
|
|
nsMathMLContainerFrame::AttributeChanged(int32_t aNameSpaceID,
|
2007-03-22 10:30:00 -07:00
|
|
|
nsIAtom* aAttribute,
|
2012-08-22 08:56:38 -07:00
|
|
|
int32_t aModType)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
|
|
|
// XXX Since they are numerous MathML attributes that affect layout, and
|
|
|
|
// we can't check all of them here, play safe by requesting a reflow.
|
|
|
|
// XXXldb This should only do work for attributes that cause changes!
|
2010-03-20 14:54:19 -07:00
|
|
|
PresContext()->PresShell()->
|
|
|
|
FrameNeedsReflow(this, nsIPresShell::eStyleChange, NS_FRAME_IS_DIRTY);
|
|
|
|
|
|
|
|
return NS_OK;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2007-12-28 15:04:19 -08:00
|
|
|
void
|
|
|
|
nsMathMLContainerFrame::GatherAndStoreOverflow(nsHTMLReflowMetrics* aMetrics)
|
|
|
|
{
|
|
|
|
// nsIFrame::FinishAndStoreOverflow likes the overflow area to include the
|
|
|
|
// frame rectangle.
|
2010-10-06 21:25:46 -07:00
|
|
|
aMetrics->SetOverflowAreasToDesiredBounds();
|
2007-12-28 15:04:19 -08:00
|
|
|
|
|
|
|
// All non-child-frame content such as nsMathMLChars (and most child-frame
|
|
|
|
// content) is included in mBoundingMetrics.
|
|
|
|
nsRect boundingBox(mBoundingMetrics.leftBearing,
|
|
|
|
aMetrics->ascent - mBoundingMetrics.ascent,
|
|
|
|
mBoundingMetrics.rightBearing - mBoundingMetrics.leftBearing,
|
|
|
|
mBoundingMetrics.ascent + mBoundingMetrics.descent);
|
|
|
|
|
2010-10-06 21:25:46 -07:00
|
|
|
// REVIEW: Maybe this should contribute only to visual overflow
|
|
|
|
// and not scrollable?
|
|
|
|
aMetrics->mOverflowAreas.UnionAllWith(boundingBox);
|
2007-12-28 15:04:19 -08:00
|
|
|
|
|
|
|
// mBoundingMetrics does not necessarily include content of <mpadded>
|
|
|
|
// elements whose mBoundingMetrics may not be representative of the true
|
|
|
|
// bounds, and doesn't include the CSS2 outline rectangles of children, so
|
|
|
|
// make such to include child overflow areas.
|
|
|
|
nsIFrame* childFrame = mFrames.FirstChild();
|
|
|
|
while (childFrame) {
|
2010-10-06 21:25:46 -07:00
|
|
|
ConsiderChildOverflow(aMetrics->mOverflowAreas, childFrame);
|
2007-12-28 15:04:19 -08:00
|
|
|
childFrame = childFrame->GetNextSibling();
|
|
|
|
}
|
|
|
|
|
|
|
|
FinishAndStoreOverflow(aMetrics);
|
|
|
|
}
|
|
|
|
|
2011-06-15 14:03:49 -07:00
|
|
|
bool
|
|
|
|
nsMathMLContainerFrame::UpdateOverflow()
|
|
|
|
{
|
|
|
|
// Our overflow areas may have changed, so reflow the frame.
|
|
|
|
PresContext()->PresShell()->FrameNeedsReflow(
|
|
|
|
this, nsIPresShell::eResize, NS_FRAME_IS_DIRTY);
|
|
|
|
|
|
|
|
// As we're reflowing, there's no need to propagate this change.
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
nsresult
|
|
|
|
nsMathMLContainerFrame::ReflowChild(nsIFrame* aChildFrame,
|
|
|
|
nsPresContext* aPresContext,
|
|
|
|
nsHTMLReflowMetrics& aDesiredSize,
|
|
|
|
const nsHTMLReflowState& aReflowState,
|
|
|
|
nsReflowStatus& aStatus)
|
|
|
|
{
|
|
|
|
// Having foreign/hybrid children, e.g., from html markups, is not defined by
|
|
|
|
// the MathML spec. But it can happen in practice, e.g., <html:img> allows us
|
|
|
|
// to do some cool demos... or we may have a child that is an nsInlineFrame
|
|
|
|
// from a generated content such as :before { content: open-quote } or
|
|
|
|
// :after { content: close-quote }. Unfortunately, the other frames out-there
|
|
|
|
// may expect their own invariants that are not met when we mix things.
|
|
|
|
// Hence we do not claim their support, but we will nevertheless attempt to keep
|
|
|
|
// them in the flow, if we can get their desired size. We observed that most
|
|
|
|
// frames may be reflowed generically, but nsInlineFrames need extra care.
|
|
|
|
|
2007-10-12 01:30:54 -07:00
|
|
|
#ifdef DEBUG
|
2009-01-12 11:20:59 -08:00
|
|
|
nsInlineFrame* inlineFrame = do_QueryFrame(aChildFrame);
|
2007-10-12 01:30:54 -07:00
|
|
|
NS_ASSERTION(!inlineFrame, "Inline frames should be wrapped in blocks");
|
|
|
|
#endif
|
|
|
|
|
2011-12-27 12:18:48 -08:00
|
|
|
nsresult rv = nsContainerFrame::
|
2007-10-12 01:30:54 -07:00
|
|
|
ReflowChild(aChildFrame, aPresContext, aDesiredSize, aReflowState,
|
|
|
|
0, 0, NS_FRAME_NO_MOVE_FRAME, aStatus);
|
2007-12-02 16:54:23 -08:00
|
|
|
|
2008-02-25 20:19:36 -08:00
|
|
|
if (NS_FAILED(rv))
|
|
|
|
return rv;
|
|
|
|
|
2007-12-02 16:54:23 -08:00
|
|
|
if (aDesiredSize.ascent == nsHTMLReflowMetrics::ASK_FOR_BASELINE) {
|
|
|
|
// This will be suitable for inline frames, which are wrapped in a block.
|
|
|
|
if(!nsLayoutUtils::GetLastLineBaseline(aChildFrame,
|
|
|
|
&aDesiredSize.ascent)) {
|
|
|
|
// We don't expect any other block children so just place the frame on
|
|
|
|
// the baseline instead of going through DidReflow() and
|
|
|
|
// GetBaseline(). This is what nsFrame::GetBaseline() will do anyway.
|
|
|
|
aDesiredSize.ascent = aDesiredSize.height;
|
|
|
|
}
|
|
|
|
}
|
2008-02-25 20:19:36 -08:00
|
|
|
if (IsForeignChild(aChildFrame)) {
|
2007-12-02 16:54:23 -08:00
|
|
|
// use ComputeTightBounds API as aDesiredSize.mBoundingMetrics is not set.
|
2007-12-18 15:01:15 -08:00
|
|
|
nsRect r = aChildFrame->ComputeTightBounds(aReflowState.rendContext->ThebesContext());
|
2007-10-12 01:30:54 -07:00
|
|
|
aDesiredSize.mBoundingMetrics.leftBearing = r.x;
|
|
|
|
aDesiredSize.mBoundingMetrics.rightBearing = r.XMost();
|
2007-12-02 16:54:23 -08:00
|
|
|
aDesiredSize.mBoundingMetrics.ascent = aDesiredSize.ascent - r.y;
|
|
|
|
aDesiredSize.mBoundingMetrics.descent = r.YMost() - aDesiredSize.ascent;
|
2007-10-12 01:30:54 -07:00
|
|
|
aDesiredSize.mBoundingMetrics.width = aDesiredSize.width;
|
|
|
|
}
|
|
|
|
return rv;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2007-12-28 15:04:19 -08:00
|
|
|
nsMathMLContainerFrame::Reflow(nsPresContext* aPresContext,
|
2007-03-22 10:30:00 -07:00
|
|
|
nsHTMLReflowMetrics& aDesiredSize,
|
|
|
|
const nsHTMLReflowState& aReflowState,
|
|
|
|
nsReflowStatus& aStatus)
|
|
|
|
{
|
|
|
|
aDesiredSize.width = aDesiredSize.height = 0;
|
|
|
|
aDesiredSize.ascent = 0;
|
2011-04-07 18:04:40 -07:00
|
|
|
aDesiredSize.mBoundingMetrics = nsBoundingMetrics();
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
/////////////
|
|
|
|
// Reflow children
|
|
|
|
// Asking each child to cache its bounding metrics
|
|
|
|
|
|
|
|
nsReflowStatus childStatus;
|
2007-11-08 22:53:04 -08:00
|
|
|
nsSize availSize(aReflowState.ComputedWidth(), NS_UNCONSTRAINEDSIZE);
|
2007-03-22 10:30:00 -07:00
|
|
|
nsIFrame* childFrame = mFrames.FirstChild();
|
|
|
|
while (childFrame) {
|
2007-12-02 16:54:23 -08:00
|
|
|
nsHTMLReflowMetrics childDesiredSize(aDesiredSize.mFlags);
|
2007-03-22 10:30:00 -07:00
|
|
|
nsHTMLReflowState childReflowState(aPresContext, aReflowState,
|
|
|
|
childFrame, availSize);
|
2007-12-28 15:04:19 -08:00
|
|
|
nsresult rv = ReflowChild(childFrame, aPresContext, childDesiredSize,
|
|
|
|
childReflowState, childStatus);
|
2007-03-22 10:30:00 -07:00
|
|
|
//NS_ASSERTION(NS_FRAME_IS_COMPLETE(childStatus), "bad status");
|
|
|
|
if (NS_FAILED(rv)) {
|
|
|
|
// Call DidReflow() for the child frames we successfully did reflow.
|
|
|
|
DidReflowChildren(mFrames.FirstChild(), childFrame);
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
2008-02-25 20:19:36 -08:00
|
|
|
SaveReflowAndBoundingMetricsFor(childFrame, childDesiredSize,
|
|
|
|
childDesiredSize.mBoundingMetrics);
|
2007-03-22 10:30:00 -07:00
|
|
|
childFrame = childFrame->GetNextSibling();
|
|
|
|
}
|
|
|
|
|
|
|
|
/////////////
|
|
|
|
// If we are a container which is entitled to stretch its children, then we
|
|
|
|
// ask our stretchy children to stretch themselves
|
|
|
|
|
|
|
|
// The stretching of siblings of an embellished child is _deferred_ until
|
|
|
|
// after finishing the stretching of the embellished child - bug 117652
|
|
|
|
|
|
|
|
if (!NS_MATHML_IS_EMBELLISH_OPERATOR(mEmbellishData.flags) &&
|
|
|
|
(NS_MATHML_WILL_STRETCH_ALL_CHILDREN_VERTICALLY(mPresentationData.flags) ||
|
|
|
|
NS_MATHML_WILL_STRETCH_ALL_CHILDREN_HORIZONTALLY(mPresentationData.flags))) {
|
|
|
|
|
|
|
|
// get the stretchy direction
|
|
|
|
nsStretchDirection stretchDir =
|
|
|
|
NS_MATHML_WILL_STRETCH_ALL_CHILDREN_VERTICALLY(mPresentationData.flags)
|
|
|
|
? NS_STRETCH_DIRECTION_VERTICAL
|
|
|
|
: NS_STRETCH_DIRECTION_HORIZONTAL;
|
|
|
|
|
|
|
|
// what size should we use to stretch our stretchy children
|
|
|
|
// We don't use STRETCH_CONSIDER_ACTUAL_SIZE -- because our size is not known yet
|
|
|
|
// We don't use STRETCH_CONSIDER_EMBELLISHMENTS -- because we don't want to
|
|
|
|
// include them in the caculations of the size of stretchy elements
|
|
|
|
nsBoundingMetrics containerSize;
|
|
|
|
GetPreferredStretchSize(*aReflowState.rendContext, 0, stretchDir,
|
|
|
|
containerSize);
|
|
|
|
|
|
|
|
// fire the stretch on each child
|
|
|
|
childFrame = mFrames.FirstChild();
|
|
|
|
while (childFrame) {
|
2009-01-12 11:20:59 -08:00
|
|
|
nsIMathMLFrame* mathMLFrame = do_QueryFrame(childFrame);
|
2007-03-22 10:30:00 -07:00
|
|
|
if (mathMLFrame) {
|
|
|
|
// retrieve the metrics that was stored at the previous pass
|
2007-12-02 16:54:23 -08:00
|
|
|
nsHTMLReflowMetrics childDesiredSize;
|
2007-03-22 10:30:00 -07:00
|
|
|
GetReflowAndBoundingMetricsFor(childFrame,
|
|
|
|
childDesiredSize, childDesiredSize.mBoundingMetrics);
|
|
|
|
|
|
|
|
mathMLFrame->Stretch(*aReflowState.rendContext, stretchDir,
|
|
|
|
containerSize, childDesiredSize);
|
|
|
|
// store the updated metrics
|
2008-02-25 20:19:36 -08:00
|
|
|
SaveReflowAndBoundingMetricsFor(childFrame, childDesiredSize,
|
|
|
|
childDesiredSize.mBoundingMetrics);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
childFrame = childFrame->GetNextSibling();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/////////////
|
|
|
|
// Place children now by re-adjusting the origins to align the baselines
|
|
|
|
FinalizeReflow(*aReflowState.rendContext, aDesiredSize);
|
|
|
|
|
|
|
|
aStatus = NS_FRAME_COMPLETE;
|
|
|
|
NS_FRAME_SET_TRUNCATION(aStatus, aReflowState, aDesiredSize);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2008-02-27 02:45:36 -08:00
|
|
|
/* virtual */ nscoord
|
2011-04-07 18:04:40 -07:00
|
|
|
nsMathMLContainerFrame::GetMinWidth(nsRenderingContext *aRenderingContext)
|
2008-02-27 02:45:36 -08:00
|
|
|
{
|
|
|
|
nscoord result;
|
|
|
|
DISPLAY_MIN_WIDTH(this, result);
|
|
|
|
result = GetIntrinsicWidth(aRenderingContext);
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* virtual */ nscoord
|
2011-04-07 18:04:40 -07:00
|
|
|
nsMathMLContainerFrame::GetPrefWidth(nsRenderingContext *aRenderingContext)
|
2008-02-27 02:45:36 -08:00
|
|
|
{
|
|
|
|
nscoord result;
|
|
|
|
DISPLAY_MIN_WIDTH(this, result);
|
|
|
|
result = GetIntrinsicWidth(aRenderingContext);
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* virtual */ nscoord
|
2011-04-07 18:04:40 -07:00
|
|
|
nsMathMLContainerFrame::GetIntrinsicWidth(nsRenderingContext* aRenderingContext)
|
2008-02-27 02:45:36 -08:00
|
|
|
{
|
|
|
|
// Get child widths
|
|
|
|
nsIFrame* childFrame = mFrames.FirstChild();
|
|
|
|
while (childFrame) {
|
|
|
|
// XXX This includes margin while Reflow currently doesn't consider
|
|
|
|
// margin, so we may end up with too much space, but, with stretchy
|
|
|
|
// characters, this is an approximation anyway.
|
|
|
|
nscoord width =
|
|
|
|
nsLayoutUtils::IntrinsicForContainer(aRenderingContext, childFrame,
|
|
|
|
nsLayoutUtils::PREF_WIDTH);
|
|
|
|
|
|
|
|
nsHTMLReflowMetrics childDesiredSize;
|
|
|
|
childDesiredSize.width = width;
|
|
|
|
childDesiredSize.mBoundingMetrics.width = width;
|
|
|
|
// TODO: we need nsIFrame::GetIntrinsicHBounds() for better values here.
|
|
|
|
childDesiredSize.mBoundingMetrics.leftBearing = 0;
|
|
|
|
childDesiredSize.mBoundingMetrics.rightBearing = width;
|
|
|
|
|
|
|
|
SaveReflowAndBoundingMetricsFor(childFrame, childDesiredSize,
|
|
|
|
childDesiredSize.mBoundingMetrics);
|
|
|
|
|
|
|
|
childFrame = childFrame->GetNextSibling();
|
|
|
|
}
|
|
|
|
|
|
|
|
// Measure
|
|
|
|
nsHTMLReflowMetrics desiredSize;
|
2009-05-29 04:08:35 -07:00
|
|
|
nsresult rv = MeasureForWidth(*aRenderingContext, desiredSize);
|
2008-02-27 02:45:36 -08:00
|
|
|
if (NS_FAILED(rv)) {
|
|
|
|
ReflowError(*aRenderingContext, desiredSize);
|
|
|
|
}
|
|
|
|
|
|
|
|
ClearSavedChildMetrics();
|
|
|
|
|
|
|
|
return desiredSize.width;
|
|
|
|
}
|
|
|
|
|
2008-03-17 22:06:23 -07:00
|
|
|
/* virtual */ nsresult
|
2011-04-07 18:04:40 -07:00
|
|
|
nsMathMLContainerFrame::MeasureForWidth(nsRenderingContext& aRenderingContext,
|
2009-05-29 04:08:35 -07:00
|
|
|
nsHTMLReflowMetrics& aDesiredSize)
|
2008-03-17 22:06:23 -07:00
|
|
|
{
|
2011-10-17 07:59:28 -07:00
|
|
|
return Place(aRenderingContext, false, aDesiredSize);
|
2008-03-17 22:06:23 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
// see spacing table in Chapter 18, TeXBook (p.170)
|
|
|
|
// Our table isn't quite identical to TeX because operators have
|
|
|
|
// built-in values for lspace & rspace in the Operator Dictionary.
|
2012-08-22 08:56:38 -07:00
|
|
|
static int32_t kInterFrameSpacingTable[eMathMLFrameType_COUNT][eMathMLFrameType_COUNT] =
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
|
|
|
// in units of muspace.
|
|
|
|
// upper half of the byte is set if the
|
|
|
|
// spacing is not to be used for scriptlevel > 0
|
|
|
|
|
|
|
|
/* Ord OpOrd OpInv OpUsr Inner Italic Upright */
|
|
|
|
/*Ord */ {0x00, 0x00, 0x00, 0x01, 0x01, 0x00, 0x00},
|
|
|
|
/*OpOrd*/ {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00},
|
|
|
|
/*OpInv*/ {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00},
|
|
|
|
/*OpUsr*/ {0x01, 0x00, 0x00, 0x01, 0x01, 0x01, 0x01},
|
|
|
|
/*Inner*/ {0x01, 0x00, 0x00, 0x01, 0x01, 0x01, 0x01},
|
|
|
|
/*Italic*/ {0x00, 0x00, 0x00, 0x01, 0x01, 0x00, 0x01},
|
2012-03-06 12:58:20 -08:00
|
|
|
/*Upright*/ {0x00, 0x00, 0x00, 0x01, 0x01, 0x01, 0x00}
|
2007-03-22 10:30:00 -07:00
|
|
|
};
|
|
|
|
|
|
|
|
#define GET_INTERSPACE(scriptlevel_, frametype1_, frametype2_, space_) \
|
|
|
|
/* no space if there is a frame that we know nothing about */ \
|
|
|
|
if (frametype1_ == eMathMLFrameType_UNKNOWN || \
|
|
|
|
frametype2_ == eMathMLFrameType_UNKNOWN) \
|
|
|
|
space_ = 0; \
|
|
|
|
else { \
|
|
|
|
space_ = kInterFrameSpacingTable[frametype1_][frametype2_]; \
|
|
|
|
space_ = (scriptlevel_ > 0 && (space_ & 0xF0)) \
|
|
|
|
? 0 /* spacing is disabled */ \
|
|
|
|
: space_ & 0x0F; \
|
|
|
|
} \
|
|
|
|
|
|
|
|
// This function computes the inter-space between two frames. However,
|
|
|
|
// since invisible operators need special treatment, the inter-space may
|
|
|
|
// be delayed when an invisible operator is encountered. In this case,
|
|
|
|
// the function will carry the inter-space forward until it is determined
|
|
|
|
// that it can be applied properly (i.e., until we encounter a visible
|
|
|
|
// frame where to decide whether to accept or reject the inter-space).
|
|
|
|
// aFromFrameType: remembers the frame when the carry-forward initiated.
|
|
|
|
// aCarrySpace: keeps track of the inter-space that is delayed.
|
|
|
|
// @returns: current inter-space (which is 0 when the true inter-space is
|
|
|
|
// delayed -- and thus has no effect since the frame is invisible anyway).
|
|
|
|
static nscoord
|
2012-08-22 08:56:38 -07:00
|
|
|
GetInterFrameSpacing(int32_t aScriptLevel,
|
2007-03-22 10:30:00 -07:00
|
|
|
eMathMLFrameType aFirstFrameType,
|
|
|
|
eMathMLFrameType aSecondFrameType,
|
|
|
|
eMathMLFrameType* aFromFrameType, // IN/OUT
|
2012-08-22 08:56:38 -07:00
|
|
|
int32_t* aCarrySpace) // IN/OUT
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
|
|
|
eMathMLFrameType firstType = aFirstFrameType;
|
|
|
|
eMathMLFrameType secondType = aSecondFrameType;
|
|
|
|
|
2012-08-22 08:56:38 -07:00
|
|
|
int32_t space;
|
2007-03-22 10:30:00 -07:00
|
|
|
GET_INTERSPACE(aScriptLevel, firstType, secondType, space);
|
|
|
|
|
|
|
|
// feedback control to avoid the inter-space to be added when not necessary
|
|
|
|
if (secondType == eMathMLFrameType_OperatorInvisible) {
|
|
|
|
// see if we should start to carry the space forward until we
|
|
|
|
// encounter a visible frame
|
|
|
|
if (*aFromFrameType == eMathMLFrameType_UNKNOWN) {
|
|
|
|
*aFromFrameType = firstType;
|
|
|
|
*aCarrySpace = space;
|
|
|
|
}
|
|
|
|
// keep carrying *aCarrySpace forward, while returning 0 for this stage
|
|
|
|
space = 0;
|
|
|
|
}
|
|
|
|
else if (*aFromFrameType != eMathMLFrameType_UNKNOWN) {
|
|
|
|
// no carry-forward anymore, get the real inter-space between
|
|
|
|
// the two frames of interest
|
|
|
|
|
|
|
|
firstType = *aFromFrameType;
|
|
|
|
|
|
|
|
// But... the invisible operator that we encountered earlier could
|
|
|
|
// be sitting between italic and upright identifiers, e.g.,
|
|
|
|
//
|
|
|
|
// 1. <mi>sin</mi> <mo>⁡</mo> <mi>x</mi>
|
|
|
|
// 2. <mi>x</mi> <mo>&InvisibileTime;</mo> <mi>sin</mi>
|
|
|
|
//
|
|
|
|
// the trick to get the inter-space in either situation
|
|
|
|
// is to promote "<mi>sin</mi><mo>⁡</mo>" and
|
|
|
|
// "<mo>&InvisibileTime;</mo><mi>sin</mi>" to user-defined operators...
|
|
|
|
if (firstType == eMathMLFrameType_UprightIdentifier) {
|
|
|
|
firstType = eMathMLFrameType_OperatorUserDefined;
|
|
|
|
}
|
|
|
|
else if (secondType == eMathMLFrameType_UprightIdentifier) {
|
|
|
|
secondType = eMathMLFrameType_OperatorUserDefined;
|
|
|
|
}
|
|
|
|
|
|
|
|
GET_INTERSPACE(aScriptLevel, firstType, secondType, space);
|
|
|
|
|
|
|
|
// Now, we have two values: the computed space and the space that
|
|
|
|
// has been carried forward until now. Which value do we pick?
|
|
|
|
// If the second type is an operator (e.g., fence), it already has
|
|
|
|
// built-in lspace & rspace, so we let them win. Otherwise we pick
|
|
|
|
// the max between the two values that we have.
|
|
|
|
if (secondType != eMathMLFrameType_OperatorOrdinary &&
|
|
|
|
space < *aCarrySpace)
|
|
|
|
space = *aCarrySpace;
|
|
|
|
|
|
|
|
// reset everything now that the carry-forward is done
|
|
|
|
*aFromFrameType = eMathMLFrameType_UNKNOWN;
|
|
|
|
*aCarrySpace = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
return space;
|
|
|
|
}
|
|
|
|
|
2008-01-02 20:33:21 -08:00
|
|
|
static nscoord GetThinSpace(const nsStyleFont* aStyleFont)
|
|
|
|
{
|
|
|
|
return NSToCoordRound(float(aStyleFont->mFont.size)*float(3) / float(18));
|
|
|
|
}
|
|
|
|
|
|
|
|
class nsMathMLContainerFrame::RowChildFrameIterator {
|
|
|
|
public:
|
|
|
|
explicit RowChildFrameIterator(nsMathMLContainerFrame* aParentFrame) :
|
|
|
|
mParentFrame(aParentFrame),
|
|
|
|
mX(0),
|
|
|
|
mCarrySpace(0),
|
2010-01-05 02:22:31 -08:00
|
|
|
mFromFrameType(eMathMLFrameType_UNKNOWN),
|
2013-05-29 16:26:40 -07:00
|
|
|
mRTL(aParentFrame->StyleVisibility()->mDirection)
|
2008-01-02 20:33:21 -08:00
|
|
|
{
|
2010-01-05 02:22:31 -08:00
|
|
|
if (!mRTL) {
|
|
|
|
mChildFrame = aParentFrame->mFrames.FirstChild();
|
|
|
|
} else {
|
|
|
|
mChildFrame = aParentFrame->mFrames.LastChild();
|
|
|
|
}
|
|
|
|
|
2008-01-02 20:33:21 -08:00
|
|
|
if (!mChildFrame)
|
|
|
|
return;
|
|
|
|
|
|
|
|
InitMetricsForChild();
|
|
|
|
}
|
|
|
|
|
|
|
|
RowChildFrameIterator& operator++()
|
|
|
|
{
|
|
|
|
// add child size + italic correction
|
|
|
|
mX += mSize.mBoundingMetrics.width + mItalicCorrection;
|
|
|
|
|
2010-01-05 02:22:31 -08:00
|
|
|
if (!mRTL) {
|
|
|
|
mChildFrame = mChildFrame->GetNextSibling();
|
|
|
|
} else {
|
|
|
|
mChildFrame = mChildFrame->GetPrevSibling();
|
|
|
|
}
|
|
|
|
|
2008-01-02 20:33:21 -08:00
|
|
|
if (!mChildFrame)
|
|
|
|
return *this;
|
|
|
|
|
|
|
|
eMathMLFrameType prevFrameType = mChildFrameType;
|
|
|
|
InitMetricsForChild();
|
|
|
|
|
|
|
|
// add inter frame spacing
|
2013-02-16 13:51:02 -08:00
|
|
|
const nsStyleFont* font = mParentFrame->StyleFont();
|
2008-01-02 20:33:21 -08:00
|
|
|
nscoord space =
|
2008-01-09 01:38:28 -08:00
|
|
|
GetInterFrameSpacing(font->mScriptLevel,
|
2008-01-02 20:33:21 -08:00
|
|
|
prevFrameType, mChildFrameType,
|
|
|
|
&mFromFrameType, &mCarrySpace);
|
2008-01-09 01:38:28 -08:00
|
|
|
mX += space * GetThinSpace(font);
|
2008-01-02 20:33:21 -08:00
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsIFrame* Frame() const { return mChildFrame; }
|
|
|
|
nscoord X() const { return mX; }
|
|
|
|
const nsHTMLReflowMetrics& ReflowMetrics() const { return mSize; }
|
|
|
|
nscoord Ascent() const { return mSize.ascent; }
|
|
|
|
nscoord Descent() const { return mSize.height - mSize.ascent; }
|
|
|
|
const nsBoundingMetrics& BoundingMetrics() const {
|
|
|
|
return mSize.mBoundingMetrics;
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
const nsMathMLContainerFrame* mParentFrame;
|
|
|
|
nsIFrame* mChildFrame;
|
|
|
|
nsHTMLReflowMetrics mSize;
|
|
|
|
nscoord mX;
|
|
|
|
|
|
|
|
nscoord mItalicCorrection;
|
|
|
|
eMathMLFrameType mChildFrameType;
|
2012-08-22 08:56:38 -07:00
|
|
|
int32_t mCarrySpace;
|
2008-01-02 20:33:21 -08:00
|
|
|
eMathMLFrameType mFromFrameType;
|
|
|
|
|
2010-01-05 02:22:31 -08:00
|
|
|
bool mRTL;
|
|
|
|
|
2008-01-02 20:33:21 -08:00
|
|
|
void InitMetricsForChild()
|
|
|
|
{
|
|
|
|
GetReflowAndBoundingMetricsFor(mChildFrame, mSize, mSize.mBoundingMetrics,
|
|
|
|
&mChildFrameType);
|
2010-01-05 02:22:31 -08:00
|
|
|
nscoord leftCorrection, rightCorrection;
|
|
|
|
GetItalicCorrection(mSize.mBoundingMetrics,
|
|
|
|
leftCorrection, rightCorrection);
|
|
|
|
if (!mChildFrame->GetPrevSibling() &&
|
|
|
|
mParentFrame->GetContent()->Tag() == nsGkAtoms::msqrt_) {
|
|
|
|
// Remove leading correction in <msqrt> because the sqrt glyph itself is
|
|
|
|
// there first.
|
|
|
|
if (!mRTL) {
|
|
|
|
leftCorrection = 0;
|
|
|
|
} else {
|
|
|
|
rightCorrection = 0;
|
|
|
|
}
|
|
|
|
}
|
2008-01-02 20:33:21 -08:00
|
|
|
// add left correction -- this fixes the problem of the italic 'f'
|
|
|
|
// e.g., <mo>q</mo> <mi>f</mi> <mo>I</mo>
|
|
|
|
mX += leftCorrection;
|
2010-01-05 02:22:31 -08:00
|
|
|
mItalicCorrection = rightCorrection;
|
2008-01-02 20:33:21 -08:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2008-03-17 21:52:48 -07:00
|
|
|
/* virtual */ nsresult
|
2011-04-07 18:04:40 -07:00
|
|
|
nsMathMLContainerFrame::Place(nsRenderingContext& aRenderingContext,
|
2011-09-28 23:19:26 -07:00
|
|
|
bool aPlaceOrigin,
|
2007-03-22 10:30:00 -07:00
|
|
|
nsHTMLReflowMetrics& aDesiredSize)
|
|
|
|
{
|
2008-01-02 20:33:21 -08:00
|
|
|
// This is needed in case this frame is empty (i.e., no child frames)
|
2011-04-07 18:04:40 -07:00
|
|
|
mBoundingMetrics = nsBoundingMetrics();
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2008-01-02 20:33:21 -08:00
|
|
|
RowChildFrameIterator child(this);
|
2007-03-22 10:30:00 -07:00
|
|
|
nscoord ascent = 0, descent = 0;
|
2008-01-02 20:33:21 -08:00
|
|
|
while (child.Frame()) {
|
|
|
|
if (descent < child.Descent())
|
|
|
|
descent = child.Descent();
|
|
|
|
if (ascent < child.Ascent())
|
|
|
|
ascent = child.Ascent();
|
|
|
|
// add the child size
|
|
|
|
mBoundingMetrics.width = child.X();
|
|
|
|
mBoundingMetrics += child.BoundingMetrics();
|
|
|
|
++child;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
2008-01-02 20:33:21 -08:00
|
|
|
// Add the italic correction at the end (including the last child).
|
|
|
|
// This gives a nice gap between math and non-math frames, and still
|
|
|
|
// gives the same math inter-spacing in case this frame connects to
|
|
|
|
// another math frame
|
|
|
|
mBoundingMetrics.width = child.X();
|
|
|
|
|
2013-04-17 04:47:09 -07:00
|
|
|
aDesiredSize.width = std::max(0, mBoundingMetrics.width);
|
2007-03-22 10:30:00 -07:00
|
|
|
aDesiredSize.height = ascent + descent;
|
|
|
|
aDesiredSize.ascent = ascent;
|
|
|
|
aDesiredSize.mBoundingMetrics = mBoundingMetrics;
|
|
|
|
|
|
|
|
mReference.x = 0;
|
|
|
|
mReference.y = aDesiredSize.ascent;
|
|
|
|
|
|
|
|
//////////////////
|
|
|
|
// Place Children
|
|
|
|
|
|
|
|
if (aPlaceOrigin) {
|
2008-01-02 20:33:21 -08:00
|
|
|
PositionRowChildFrames(0, aDesiredSize.ascent);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2008-01-02 20:33:21 -08:00
|
|
|
void
|
|
|
|
nsMathMLContainerFrame::PositionRowChildFrames(nscoord aOffsetX,
|
|
|
|
nscoord aBaseline)
|
|
|
|
{
|
|
|
|
RowChildFrameIterator child(this);
|
|
|
|
while (child.Frame()) {
|
|
|
|
nscoord dx = aOffsetX + child.X();
|
|
|
|
nscoord dy = aBaseline - child.Ascent();
|
2012-07-30 07:20:58 -07:00
|
|
|
FinishReflowChild(child.Frame(), PresContext(), nullptr,
|
2008-01-02 20:33:21 -08:00
|
|
|
child.ReflowMetrics(), dx, dy, 0);
|
|
|
|
++child;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-01-09 01:38:28 -08:00
|
|
|
class ForceReflow : public nsIReflowCallback {
|
|
|
|
public:
|
2011-09-28 23:19:26 -07:00
|
|
|
virtual bool ReflowFinished() {
|
2011-10-17 07:59:28 -07:00
|
|
|
return true;
|
2008-01-09 01:38:28 -08:00
|
|
|
}
|
|
|
|
virtual void ReflowCallbackCanceled() {}
|
|
|
|
};
|
|
|
|
|
|
|
|
// We only need one of these so we just make it a static global, no need
|
|
|
|
// to dynamically allocate/destroy it.
|
|
|
|
static ForceReflow gForceReflow;
|
|
|
|
|
|
|
|
void
|
2012-08-22 08:56:38 -07:00
|
|
|
nsMathMLContainerFrame::SetIncrementScriptLevel(int32_t aChildIndex, bool aIncrement)
|
2008-01-09 01:38:28 -08:00
|
|
|
{
|
2011-08-24 13:54:30 -07:00
|
|
|
nsIFrame* child = PrincipalChildList().FrameAt(aChildIndex);
|
2008-01-09 01:38:28 -08:00
|
|
|
if (!child)
|
|
|
|
return;
|
|
|
|
nsIContent* content = child->GetContent();
|
2009-08-24 13:02:07 -07:00
|
|
|
if (!content->IsMathML())
|
2008-01-09 01:38:28 -08:00
|
|
|
return;
|
|
|
|
nsMathMLElement* element = static_cast<nsMathMLElement*>(content);
|
|
|
|
|
|
|
|
if (element->GetIncrementScriptLevel() == aIncrement)
|
|
|
|
return;
|
|
|
|
|
|
|
|
// XXXroc this does a ContentStatesChanged, is it safe to call here? If
|
|
|
|
// not we should do it in a post-reflow callback.
|
2011-10-17 07:59:28 -07:00
|
|
|
element->SetIncrementScriptLevel(aIncrement, true);
|
2008-01-09 01:38:28 -08:00
|
|
|
PresContext()->PresShell()->PostReflowCallback(&gForceReflow);
|
|
|
|
}
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
// helpers to fix the inter-spacing when <math> is the only parent
|
|
|
|
// e.g., it fixes <math> <mi>f</mi> <mo>q</mo> <mi>f</mi> <mo>I</mo> </math>
|
|
|
|
|
|
|
|
static nscoord
|
2012-08-22 08:56:38 -07:00
|
|
|
GetInterFrameSpacingFor(int32_t aScriptLevel,
|
2007-03-22 10:30:00 -07:00
|
|
|
nsIFrame* aParentFrame,
|
|
|
|
nsIFrame* aChildFrame)
|
|
|
|
{
|
2011-08-24 13:54:30 -07:00
|
|
|
nsIFrame* childFrame = aParentFrame->GetFirstPrincipalChild();
|
2007-03-22 10:30:00 -07:00
|
|
|
if (!childFrame || aChildFrame == childFrame)
|
|
|
|
return 0;
|
|
|
|
|
2012-08-22 08:56:38 -07:00
|
|
|
int32_t carrySpace = 0;
|
2007-03-22 10:30:00 -07:00
|
|
|
eMathMLFrameType fromFrameType = eMathMLFrameType_UNKNOWN;
|
|
|
|
eMathMLFrameType prevFrameType = eMathMLFrameType_UNKNOWN;
|
|
|
|
eMathMLFrameType childFrameType = nsMathMLFrame::GetMathMLFrameTypeFor(childFrame);
|
|
|
|
childFrame = childFrame->GetNextSibling();
|
|
|
|
while (childFrame) {
|
|
|
|
prevFrameType = childFrameType;
|
|
|
|
childFrameType = nsMathMLFrame::GetMathMLFrameTypeFor(childFrame);
|
|
|
|
nscoord space = GetInterFrameSpacing(aScriptLevel,
|
|
|
|
prevFrameType, childFrameType, &fromFrameType, &carrySpace);
|
|
|
|
if (aChildFrame == childFrame) {
|
|
|
|
// get thinspace
|
2013-02-15 21:38:33 -08:00
|
|
|
nsStyleContext* parentContext = aParentFrame->StyleContext();
|
2013-02-16 13:51:02 -08:00
|
|
|
nscoord thinSpace = GetThinSpace(parentContext->StyleFont());
|
2007-03-22 10:30:00 -07:00
|
|
|
// we are done
|
|
|
|
return space * thinSpace;
|
|
|
|
}
|
|
|
|
childFrame = childFrame->GetNextSibling();
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_NOTREACHED("child not in the childlist of its parent");
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
nscoord
|
|
|
|
nsMathMLContainerFrame::FixInterFrameSpacing(nsHTMLReflowMetrics& aDesiredSize)
|
|
|
|
{
|
|
|
|
nscoord gap = 0;
|
|
|
|
nsIContent* parentContent = mParent->GetContent();
|
2012-10-26 06:32:10 -07:00
|
|
|
if (MOZ_UNLIKELY(!parentContent)) {
|
2007-03-22 10:30:00 -07:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
nsIAtom *parentTag = parentContent->Tag();
|
2011-07-01 03:20:35 -07:00
|
|
|
if (parentContent->GetNameSpaceID() == kNameSpaceID_MathML &&
|
|
|
|
(parentTag == nsGkAtoms::math || parentTag == nsGkAtoms::mtd_)) {
|
2013-02-16 13:51:02 -08:00
|
|
|
gap = GetInterFrameSpacingFor(StyleFont()->mScriptLevel, mParent, this);
|
2007-03-22 10:30:00 -07:00
|
|
|
// add our own italic correction
|
|
|
|
nscoord leftCorrection = 0, italicCorrection = 0;
|
|
|
|
GetItalicCorrection(mBoundingMetrics, leftCorrection, italicCorrection);
|
|
|
|
gap += leftCorrection;
|
|
|
|
// see if we should shift our children to account for the correction
|
|
|
|
if (gap) {
|
|
|
|
nsIFrame* childFrame = mFrames.FirstChild();
|
|
|
|
while (childFrame) {
|
|
|
|
childFrame->SetPosition(childFrame->GetPosition() + nsPoint(gap, 0));
|
|
|
|
childFrame = childFrame->GetNextSibling();
|
|
|
|
}
|
|
|
|
mBoundingMetrics.leftBearing += gap;
|
|
|
|
mBoundingMetrics.rightBearing += gap;
|
|
|
|
mBoundingMetrics.width += gap;
|
|
|
|
aDesiredSize.width += gap;
|
|
|
|
}
|
|
|
|
mBoundingMetrics.width += italicCorrection;
|
|
|
|
aDesiredSize.width += italicCorrection;
|
|
|
|
}
|
|
|
|
return gap;
|
|
|
|
}
|
|
|
|
|
2008-12-11 11:08:35 -08:00
|
|
|
/* static */ void
|
2007-03-22 10:30:00 -07:00
|
|
|
nsMathMLContainerFrame::DidReflowChildren(nsIFrame* aFirst, nsIFrame* aStop)
|
|
|
|
|
|
|
|
{
|
2012-10-26 06:32:10 -07:00
|
|
|
if (MOZ_UNLIKELY(!aFirst))
|
2007-03-22 10:30:00 -07:00
|
|
|
return;
|
|
|
|
|
|
|
|
for (nsIFrame* frame = aFirst;
|
|
|
|
frame != aStop;
|
|
|
|
frame = frame->GetNextSibling()) {
|
|
|
|
NS_ASSERTION(frame, "aStop isn't a sibling");
|
|
|
|
if (frame->GetStateBits() & NS_FRAME_IN_REFLOW) {
|
2008-12-11 11:08:35 -08:00
|
|
|
// finish off principal descendants, too
|
2011-08-24 13:54:30 -07:00
|
|
|
nsIFrame* grandchild = frame->GetFirstPrincipalChild();
|
2008-12-11 11:08:35 -08:00
|
|
|
if (grandchild)
|
2012-07-30 07:20:58 -07:00
|
|
|
DidReflowChildren(grandchild, nullptr);
|
2008-12-11 11:08:35 -08:00
|
|
|
|
2012-07-30 07:20:58 -07:00
|
|
|
frame->DidReflow(frame->PresContext(), nullptr,
|
2012-11-13 22:47:33 -08:00
|
|
|
nsDidReflowStatus::FINISHED);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-03-24 20:38:59 -07:00
|
|
|
// helper used by mstyle, mphantom, mpadded and mrow in their implementations
|
|
|
|
// of TransmitAutomaticData().
|
|
|
|
nsresult
|
|
|
|
nsMathMLContainerFrame::TransmitAutomaticDataForMrowLikeElement()
|
|
|
|
{
|
|
|
|
//
|
|
|
|
// One loop to check both conditions below:
|
|
|
|
//
|
|
|
|
// 1) whether all the children of the mrow-like element are space-like.
|
|
|
|
//
|
|
|
|
// The REC defines the following elements to be "space-like":
|
|
|
|
// * an mstyle, mphantom, or mpadded element, all of whose direct
|
|
|
|
// sub-expressions are space-like;
|
|
|
|
// * an mrow all of whose direct sub-expressions are space-like.
|
|
|
|
//
|
|
|
|
// 2) whether all but one child of the mrow-like element are space-like and
|
|
|
|
// this non-space-like child is an embellished operator.
|
|
|
|
//
|
|
|
|
// The REC defines the following elements to be embellished operators:
|
|
|
|
// * one of the elements mstyle, mphantom, or mpadded, such that an mrow
|
|
|
|
// containing the same arguments would be an embellished operator;
|
|
|
|
// * an mrow whose arguments consist (in any order) of one embellished
|
|
|
|
// operator and zero or more space-like elements.
|
|
|
|
//
|
|
|
|
nsIFrame *childFrame, *baseFrame;
|
2011-09-28 23:19:26 -07:00
|
|
|
bool embellishedOpFound = false;
|
2011-03-24 20:38:59 -07:00
|
|
|
nsEmbellishData embellishData;
|
|
|
|
|
2011-08-24 13:54:30 -07:00
|
|
|
for (childFrame = GetFirstPrincipalChild();
|
2011-03-24 20:38:59 -07:00
|
|
|
childFrame;
|
|
|
|
childFrame = childFrame->GetNextSibling()) {
|
|
|
|
nsIMathMLFrame* mathMLFrame = do_QueryFrame(childFrame);
|
|
|
|
if (!mathMLFrame) break;
|
|
|
|
if (!mathMLFrame->IsSpaceLike()) {
|
|
|
|
if (embellishedOpFound) break;
|
|
|
|
baseFrame = childFrame;
|
|
|
|
GetEmbellishDataFrom(baseFrame, embellishData);
|
|
|
|
if (!NS_MATHML_IS_EMBELLISH_OPERATOR(embellishData.flags)) break;
|
2011-10-17 07:59:28 -07:00
|
|
|
embellishedOpFound = true;
|
2011-03-24 20:38:59 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!childFrame) {
|
|
|
|
// we successfully went to the end of the loop. This means that one of
|
|
|
|
// condition 1) or 2) holds.
|
|
|
|
if (!embellishedOpFound) {
|
|
|
|
// the mrow-like element is space-like.
|
|
|
|
mPresentationData.flags |= NS_MATHML_SPACE_LIKE;
|
|
|
|
} else {
|
|
|
|
// the mrow-like element is an embellished operator.
|
|
|
|
// let the state of the embellished operator found bubble to us.
|
|
|
|
mPresentationData.baseFrame = baseFrame;
|
|
|
|
mEmbellishData = embellishData;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (childFrame || !embellishedOpFound) {
|
|
|
|
// The element is not embellished operator
|
2012-07-30 07:20:58 -07:00
|
|
|
mPresentationData.baseFrame = nullptr;
|
2011-03-24 20:38:59 -07:00
|
|
|
mEmbellishData.flags = 0;
|
2012-07-30 07:20:58 -07:00
|
|
|
mEmbellishData.coreFrame = nullptr;
|
2011-03-24 20:38:59 -07:00
|
|
|
mEmbellishData.direction = NS_STRETCH_DIRECTION_UNSUPPORTED;
|
2011-12-21 14:21:59 -08:00
|
|
|
mEmbellishData.leadingSpace = 0;
|
|
|
|
mEmbellishData.trailingSpace = 0;
|
2011-03-24 20:38:59 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
if (childFrame || embellishedOpFound) {
|
|
|
|
// The element is not space-like
|
|
|
|
mPresentationData.flags &= ~NS_MATHML_SPACE_LIKE;
|
|
|
|
}
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2012-12-27 08:12:05 -08:00
|
|
|
nsresult
|
|
|
|
nsMathMLContainerFrame::ReportErrorToConsole(const char* errorMsgId,
|
|
|
|
const PRUnichar** aParams,
|
2013-01-07 15:21:50 -08:00
|
|
|
uint32_t aParamCount)
|
2012-12-27 08:12:05 -08:00
|
|
|
{
|
|
|
|
return nsContentUtils::ReportToConsole(nsIScriptError::errorFlag,
|
|
|
|
"MathML", mContent->OwnerDoc(),
|
|
|
|
nsContentUtils::eMATHML_PROPERTIES,
|
|
|
|
errorMsgId, aParams, aParamCount);
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
|
|
|
nsMathMLContainerFrame::ReportParseError(const PRUnichar* aAttribute,
|
|
|
|
const PRUnichar* aValue)
|
|
|
|
{
|
|
|
|
const PRUnichar* argv[] =
|
|
|
|
{ aValue, aAttribute, mContent->Tag()->GetUTF16String() };
|
|
|
|
return ReportErrorToConsole("AttributeParsingError", argv, 3);
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
|
|
|
nsMathMLContainerFrame::ReportChildCountError()
|
|
|
|
{
|
|
|
|
const PRUnichar* arg = mContent->Tag()->GetUTF16String();
|
|
|
|
return ReportErrorToConsole("ChildCountIncorrect", &arg, 1);
|
|
|
|
}
|
|
|
|
|
2013-08-19 06:09:34 -07:00
|
|
|
nsresult
|
|
|
|
nsMathMLContainerFrame::ReportInvalidChildError(nsIAtom* aChildTag)
|
|
|
|
{
|
|
|
|
const PRUnichar* argv[] =
|
|
|
|
{ aChildTag->GetUTF16String(), mContent->Tag()->GetUTF16String() };
|
|
|
|
return ReportErrorToConsole("InvalidChild", argv, 2);
|
|
|
|
}
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
//==========================
|
|
|
|
|
|
|
|
nsIFrame*
|
2007-10-12 01:30:54 -07:00
|
|
|
NS_NewMathMLmathBlockFrame(nsIPresShell* aPresShell, nsStyleContext* aContext,
|
2012-08-22 08:56:38 -07:00
|
|
|
uint32_t aFlags)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2007-10-12 01:30:54 -07:00
|
|
|
nsMathMLmathBlockFrame* it = new (aPresShell) nsMathMLmathBlockFrame(aContext);
|
2013-08-02 21:11:06 -07:00
|
|
|
it->SetFlags(aFlags);
|
2007-10-12 01:30:54 -07:00
|
|
|
return it;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2009-09-12 09:49:24 -07:00
|
|
|
NS_IMPL_FRAMEARENA_HELPERS(nsMathMLmathBlockFrame)
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
nsIFrame*
|
|
|
|
NS_NewMathMLmathInlineFrame(nsIPresShell* aPresShell, nsStyleContext* aContext)
|
|
|
|
{
|
|
|
|
return new (aPresShell) nsMathMLmathInlineFrame(aContext);
|
|
|
|
}
|
2009-09-12 09:49:24 -07:00
|
|
|
|
|
|
|
NS_IMPL_FRAMEARENA_HELPERS(nsMathMLmathInlineFrame)
|