2004-02-24 00:29:06 +03:00
|
|
|
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
2004-04-18 18:30:37 +04:00
|
|
|
/* ***** BEGIN LICENSE BLOCK *****
|
|
|
|
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
|
2001-02-02 17:27:38 +03:00
|
|
|
*
|
2004-04-18 18:30:37 +04:00
|
|
|
* The contents of this file are subject to the Mozilla Public License Version
|
|
|
|
* 1.1 (the "License"); you may not use this file except in compliance with
|
|
|
|
* the License. You may obtain a copy of the License at
|
|
|
|
* http://www.mozilla.org/MPL/
|
|
|
|
*
|
|
|
|
* Software distributed under the License is distributed on an "AS IS" basis,
|
|
|
|
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
|
|
|
|
* for the specific language governing rights and limitations under the
|
|
|
|
* License.
|
2001-02-02 17:27:38 +03:00
|
|
|
*
|
|
|
|
* The Original Code is Mozilla MathML Project.
|
|
|
|
*
|
2004-04-18 18:30:37 +04:00
|
|
|
* The Initial Developer of the Original Code is
|
|
|
|
* The University Of Queensland.
|
|
|
|
* Portions created by the Initial Developer are Copyright (C) 1999
|
|
|
|
* the Initial Developer. All Rights Reserved.
|
2001-02-02 17:27:38 +03:00
|
|
|
*
|
|
|
|
* Contributor(s):
|
|
|
|
* Roger B. Sidje <rbs@maths.uq.edu.au>
|
|
|
|
* David J. Fiddes <D.J.Fiddes@hw.ac.uk>
|
|
|
|
* Pierre Phaneuf <pp@ludusdesign.com>
|
2008-01-03 07:33:21 +03:00
|
|
|
* Karl Tomlinson <karlt+@karlt.net>, Mozilla Corporation
|
2011-03-25 06:38:59 +03:00
|
|
|
* Frederic Wang <fred.wang@free.fr>
|
2004-04-18 18:30:37 +04:00
|
|
|
*
|
|
|
|
* Alternatively, the contents of this file may be used under the terms of
|
|
|
|
* either of the GNU General Public License Version 2 or later (the "GPL"),
|
|
|
|
* or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
|
|
|
|
* in which case the provisions of the GPL or the LGPL are applicable instead
|
|
|
|
* of those above. If you wish to allow use of your version of this file only
|
|
|
|
* under the terms of either the GPL or the LGPL, and not to allow others to
|
|
|
|
* use your version of this file under the terms of the MPL, indicate your
|
|
|
|
* decision by deleting the provisions above and replace them with the notice
|
|
|
|
* and other provisions required by the GPL or the LGPL. If you do not delete
|
|
|
|
* the provisions above, a recipient may use your version of this file under
|
|
|
|
* the terms of any one of the MPL, the GPL or the LGPL.
|
|
|
|
*
|
|
|
|
* ***** END LICENSE BLOCK ***** */
|
2001-02-02 17:27:38 +03:00
|
|
|
|
|
|
|
#include "nsCOMPtr.h"
|
|
|
|
#include "nsHTMLParts.h"
|
|
|
|
#include "nsFrame.h"
|
2004-08-01 03:15:21 +04:00
|
|
|
#include "nsPresContext.h"
|
2001-02-02 17:27:38 +03:00
|
|
|
#include "nsIPresShell.h"
|
2002-11-17 18:37:56 +03:00
|
|
|
#include "nsCSSAnonBoxes.h"
|
2003-02-22 03:32:13 +03:00
|
|
|
#include "nsStyleContext.h"
|
2001-02-02 17:27:38 +03:00
|
|
|
#include "nsStyleConsts.h"
|
|
|
|
#include "nsINameSpaceManager.h"
|
2011-04-08 05:04:40 +04:00
|
|
|
#include "nsRenderingContext.h"
|
2001-02-02 17:27:38 +03:00
|
|
|
#include "nsIFontMetrics.h"
|
|
|
|
|
2001-02-23 19:10:51 +03:00
|
|
|
#include "nsIDOMText.h"
|
2002-02-04 00:06:51 +03:00
|
|
|
#include "nsIDOMMutationEvent.h"
|
2004-02-24 00:29:06 +03:00
|
|
|
#include "nsFrameManager.h"
|
2002-01-09 21:51:30 +03:00
|
|
|
#include "nsStyleChangeList.h"
|
|
|
|
|
2006-12-26 20:47:52 +03:00
|
|
|
#include "nsGkAtoms.h"
|
2001-02-02 17:27:38 +03:00
|
|
|
#include "nsMathMLParts.h"
|
|
|
|
#include "nsMathMLContainerFrame.h"
|
2003-02-22 03:32:13 +03:00
|
|
|
#include "nsAutoPtr.h"
|
2004-01-28 03:18:22 +03:00
|
|
|
#include "nsStyleSet.h"
|
2006-01-26 05:29:17 +03:00
|
|
|
#include "nsDisplayList.h"
|
2005-12-29 00:52:39 +03:00
|
|
|
#include "nsCSSFrameConstructor.h"
|
2008-01-09 12:38:28 +03:00
|
|
|
#include "nsIReflowCallback.h"
|
2001-02-02 17:27:38 +03:00
|
|
|
|
2010-03-29 05:46:55 +04:00
|
|
|
using namespace mozilla;
|
|
|
|
|
2001-02-02 17:27:38 +03:00
|
|
|
//
|
|
|
|
// nsMathMLContainerFrame implementation
|
|
|
|
//
|
|
|
|
|
2009-09-12 20:49:24 +04:00
|
|
|
NS_IMPL_FRAMEARENA_HELPERS(nsMathMLContainerFrame)
|
|
|
|
|
2009-01-12 22:20:59 +03:00
|
|
|
NS_QUERYFRAME_HEAD(nsMathMLContainerFrame)
|
|
|
|
NS_QUERYFRAME_ENTRY(nsMathMLFrame)
|
|
|
|
NS_QUERYFRAME_TAIL_INHERITING(nsHTMLContainerFrame)
|
2001-02-02 17:27:38 +03:00
|
|
|
|
2001-02-23 19:10:51 +03:00
|
|
|
// =============================================================================
|
2001-02-02 17:27:38 +03:00
|
|
|
|
|
|
|
// error handlers
|
2002-01-25 09:48:30 +03:00
|
|
|
// provide a feedback to the user when a frame with bad markup can not be rendered
|
2001-02-02 17:27:38 +03:00
|
|
|
nsresult
|
2011-04-08 05:04:40 +04:00
|
|
|
nsMathMLContainerFrame::ReflowError(nsRenderingContext& aRenderingContext,
|
2006-08-04 03:27:55 +04:00
|
|
|
nsHTMLReflowMetrics& aDesiredSize)
|
2001-02-02 17:27:38 +03:00
|
|
|
{
|
|
|
|
nsresult rv;
|
|
|
|
|
|
|
|
// clear all other flags and record that there is an error with this frame
|
|
|
|
mEmbellishData.flags = 0;
|
|
|
|
mPresentationData.flags = NS_MATHML_ERROR;
|
|
|
|
|
|
|
|
///////////////
|
|
|
|
// Set font
|
2008-12-04 19:09:53 +03:00
|
|
|
nsLayoutUtils::SetFontFromStyle(&aRenderingContext, GetStyleContext());
|
2001-02-02 17:27:38 +03:00
|
|
|
|
|
|
|
// bounding metrics
|
2004-06-17 04:13:25 +04:00
|
|
|
nsAutoString errorMsg; errorMsg.AssignLiteral("invalid-markup");
|
2001-06-30 15:02:25 +04:00
|
|
|
rv = aRenderingContext.GetBoundingMetrics(errorMsg.get(),
|
2001-02-02 17:27:38 +03:00
|
|
|
PRUint32(errorMsg.Length()),
|
|
|
|
mBoundingMetrics);
|
|
|
|
if (NS_FAILED(rv)) {
|
2001-02-23 19:10:51 +03:00
|
|
|
NS_WARNING("GetBoundingMetrics failed");
|
2001-02-02 17:27:38 +03:00
|
|
|
aDesiredSize.width = aDesiredSize.height = 0;
|
2007-01-23 07:06:56 +03:00
|
|
|
aDesiredSize.ascent = 0;
|
2001-02-02 17:27:38 +03:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
// reflow metrics
|
2011-04-08 05:04:39 +04:00
|
|
|
nsCOMPtr<nsIFontMetrics> fm = aRenderingContext.GetFontMetrics();
|
2001-02-02 17:27:38 +03:00
|
|
|
fm->GetMaxAscent(aDesiredSize.ascent);
|
2007-01-23 07:06:56 +03:00
|
|
|
nscoord descent;
|
|
|
|
fm->GetMaxDescent(descent);
|
|
|
|
aDesiredSize.height = aDesiredSize.ascent + descent;
|
2001-02-02 17:27:38 +03:00
|
|
|
aDesiredSize.width = mBoundingMetrics.width;
|
|
|
|
|
|
|
|
// Also return our bounding metrics
|
|
|
|
aDesiredSize.mBoundingMetrics = mBoundingMetrics;
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2006-01-26 05:29:17 +03:00
|
|
|
class nsDisplayMathMLError : public nsDisplayItem {
|
|
|
|
public:
|
2010-08-13 14:01:13 +04:00
|
|
|
nsDisplayMathMLError(nsDisplayListBuilder* aBuilder, nsIFrame* aFrame)
|
|
|
|
: nsDisplayItem(aBuilder, aFrame) {
|
2006-01-29 21:48:58 +03:00
|
|
|
MOZ_COUNT_CTOR(nsDisplayMathMLError);
|
|
|
|
}
|
|
|
|
#ifdef NS_BUILD_REFCNT_LOGGING
|
|
|
|
virtual ~nsDisplayMathMLError() {
|
|
|
|
MOZ_COUNT_DTOR(nsDisplayMathMLError);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2009-09-07 04:35:14 +04:00
|
|
|
virtual void Paint(nsDisplayListBuilder* aBuilder,
|
2011-04-08 05:04:40 +04:00
|
|
|
nsRenderingContext* aCtx);
|
2010-07-16 01:07:49 +04:00
|
|
|
NS_DISPLAY_DECL_NAME("MathMLError", TYPE_MATHML_ERROR)
|
2006-01-26 05:29:17 +03:00
|
|
|
};
|
|
|
|
|
|
|
|
void nsDisplayMathMLError::Paint(nsDisplayListBuilder* aBuilder,
|
2011-04-08 05:04:40 +04:00
|
|
|
nsRenderingContext* aCtx)
|
2001-02-02 17:27:38 +03:00
|
|
|
{
|
2006-01-26 05:29:17 +03:00
|
|
|
// Set color and font ...
|
2008-12-04 19:09:53 +03:00
|
|
|
nsLayoutUtils::SetFontFromStyle(aCtx, mFrame->GetStyleContext());
|
2006-01-26 05:29:17 +03:00
|
|
|
|
2010-08-13 14:01:58 +04:00
|
|
|
nsPoint pt = ToReferenceFrame();
|
2006-01-26 05:29:17 +03:00
|
|
|
aCtx->SetColor(NS_RGB(255,0,0));
|
|
|
|
aCtx->FillRect(nsRect(pt, mFrame->GetSize()));
|
|
|
|
aCtx->SetColor(NS_RGB(255,255,255));
|
|
|
|
|
|
|
|
nscoord ascent;
|
2011-04-08 05:04:39 +04:00
|
|
|
nsCOMPtr<nsIFontMetrics> fm = aCtx->GetFontMetrics();
|
2006-01-26 05:29:17 +03:00
|
|
|
fm->GetMaxAscent(ascent);
|
|
|
|
|
|
|
|
nsAutoString errorMsg; errorMsg.AssignLiteral("invalid-markup");
|
|
|
|
aCtx->DrawString(errorMsg.get(), PRUint32(errorMsg.Length()), pt.x, pt.y+ascent);
|
2001-02-02 17:27:38 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
/* /////////////
|
2002-01-11 02:40:40 +03:00
|
|
|
* nsIMathMLFrame - support methods for stretchy elements
|
2001-02-02 17:27:38 +03:00
|
|
|
* =============================================================================
|
|
|
|
*/
|
|
|
|
|
2008-02-26 07:19:36 +03:00
|
|
|
static PRBool
|
|
|
|
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-29 05:46:55 +04:00
|
|
|
DestroyHTMLReflowMetrics(void *aPropertyValue)
|
2008-02-26 07:19:36 +03:00
|
|
|
{
|
|
|
|
delete static_cast<nsHTMLReflowMetrics*>(aPropertyValue);
|
|
|
|
}
|
|
|
|
|
2010-03-29 05:46:55 +04:00
|
|
|
NS_DECLARE_FRAME_PROPERTY(HTMLReflowMetricsProperty, DestroyHTMLReflowMetrics)
|
|
|
|
|
2008-02-26 07:19:36 +03:00
|
|
|
/* static */ void
|
|
|
|
nsMathMLContainerFrame::SaveReflowAndBoundingMetricsFor(nsIFrame* aFrame,
|
|
|
|
const nsHTMLReflowMetrics& aReflowMetrics,
|
|
|
|
const nsBoundingMetrics& aBoundingMetrics)
|
|
|
|
{
|
|
|
|
nsHTMLReflowMetrics *metrics = new nsHTMLReflowMetrics(aReflowMetrics);
|
|
|
|
metrics->mBoundingMetrics = aBoundingMetrics;
|
2010-03-29 05:46:55 +04:00
|
|
|
aFrame->Properties().Set(HTMLReflowMetricsProperty(), metrics);
|
2008-02-26 07:19:36 +03:00
|
|
|
}
|
|
|
|
|
2001-02-02 17:27:38 +03:00
|
|
|
// helper method to facilitate getting the reflow and bounding metrics
|
2008-02-26 07:19:36 +03:00
|
|
|
/* static */ void
|
2001-02-02 17:27:38 +03:00
|
|
|
nsMathMLContainerFrame::GetReflowAndBoundingMetricsFor(nsIFrame* aFrame,
|
|
|
|
nsHTMLReflowMetrics& aReflowMetrics,
|
2006-08-15 08:49:43 +04:00
|
|
|
nsBoundingMetrics& aBoundingMetrics,
|
|
|
|
eMathMLFrameType* aMathMLFrameType)
|
2001-02-02 17:27:38 +03:00
|
|
|
{
|
|
|
|
NS_PRECONDITION(aFrame, "null arg");
|
|
|
|
|
2008-02-26 07:19:36 +03:00
|
|
|
nsHTMLReflowMetrics *metrics = static_cast<nsHTMLReflowMetrics*>
|
2010-03-29 05:46:55 +04:00
|
|
|
(aFrame->Properties().Get(HTMLReflowMetricsProperty()));
|
2001-02-23 19:10:51 +03:00
|
|
|
|
2008-02-26 07:19:36 +03: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;
|
|
|
|
}
|
2001-02-23 19:10:51 +03:00
|
|
|
|
2008-02-26 07:19:36 +03:00
|
|
|
if (aMathMLFrameType) {
|
|
|
|
if (!IsForeignChild(aFrame)) {
|
2009-01-12 22:20:59 +03:00
|
|
|
nsIMathMLFrame* mathMLFrame = do_QueryFrame(aFrame);
|
2008-02-26 07:19:36 +03:00
|
|
|
if (mathMLFrame) {
|
2006-08-15 08:49:43 +04:00
|
|
|
*aMathMLFrameType = mathMLFrame->GetMathMLFrameType();
|
2008-02-26 07:19:36 +03:00
|
|
|
return;
|
|
|
|
}
|
2006-08-15 08:49:43 +04:00
|
|
|
}
|
2008-02-26 07:19:36 +03:00
|
|
|
*aMathMLFrameType = eMathMLFrameType_UNKNOWN;
|
2001-02-02 17:27:38 +03:00
|
|
|
}
|
2006-08-15 08:49:43 +04:00
|
|
|
|
2008-02-26 07:19:36 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
nsMathMLContainerFrame::ClearSavedChildMetrics()
|
|
|
|
{
|
|
|
|
nsIFrame* childFrame = mFrames.FirstChild();
|
2010-03-29 05:46:55 +04:00
|
|
|
FramePropertyTable* props = PresContext()->PropertyTable();
|
2008-02-26 07:19:36 +03:00
|
|
|
while (childFrame) {
|
2010-03-29 05:46:55 +04:00
|
|
|
props->Delete(childFrame, HTMLReflowMetricsProperty());
|
2008-02-26 07:19:36 +03:00
|
|
|
childFrame = childFrame->GetNextSibling();
|
|
|
|
}
|
2001-02-02 17:27:38 +03:00
|
|
|
}
|
|
|
|
|
2002-01-11 02:40:40 +03:00
|
|
|
// helper to get the preferred size that a container frame should use to fire
|
|
|
|
// the stretch on its stretchy child frames.
|
2002-01-02 08:32:33 +03:00
|
|
|
void
|
2011-04-08 05:04:40 +04:00
|
|
|
nsMathMLContainerFrame::GetPreferredStretchSize(nsRenderingContext& aRenderingContext,
|
2002-01-02 08:32:33 +03:00
|
|
|
PRUint32 aOptions,
|
|
|
|
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()
|
Bug 300030: Move intrinsic width computation out of nsIFrame::Reflow and into its own methods on nsIFrame. Replace reflow reasons, types, and commands with dirty bits/notifications. Thanks to bzbarsky for almost all of the HTML form controls (mozilla/layout/forms) changes, and many others for help testing and patching. For detailed commit logs, see REFLOW_YYYYMMDD_BRANCH, where YYYYMMDD is one of 20061031, 20060830, 20060603, 20060302, 20060119, 20051011, 20050804, 20050429, 20050315, 20050111, and 20041213.
2006-12-08 08:38:33 +03:00
|
|
|
nsHTMLReflowMetrics metrics;
|
2005-02-07 04:57:50 +03:00
|
|
|
Place(aRenderingContext, PR_FALSE, metrics);
|
2002-01-05 04:15:04 +03:00
|
|
|
aPreferredStretchSize = metrics.mBoundingMetrics;
|
2002-01-02 08:32:33 +03:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
// compute a size that doesn't include embellishements
|
|
|
|
NS_ASSERTION(NS_MATHML_IS_EMBELLISH_OPERATOR(mEmbellishData.flags) ||
|
2002-02-07 07:38:08 +03:00
|
|
|
NS_MATHML_WILL_STRETCH_ALL_CHILDREN_HORIZONTALLY(mPresentationData.flags) ||
|
|
|
|
NS_MATHML_WILL_STRETCH_ALL_CHILDREN_VERTICALLY(mPresentationData.flags),
|
2002-01-02 08:32:33 +03:00
|
|
|
"invalid call to GetPreferredStretchSize");
|
|
|
|
PRBool firstTime = PR_TRUE;
|
|
|
|
nsBoundingMetrics bm, bmChild;
|
|
|
|
// XXXrbs need overloaded FirstChild() and clean integration of <maction> throughout
|
2004-01-09 17:20:53 +03:00
|
|
|
nsIFrame* childFrame = GetFirstChild(nsnull);
|
2002-01-02 08:32:33 +03:00
|
|
|
while (childFrame) {
|
|
|
|
// initializations in case this child happens not to be a MathML frame
|
2009-01-12 22:20:59 +03:00
|
|
|
nsIMathMLFrame* mathMLFrame = do_QueryFrame(childFrame);
|
2002-01-11 02:40:40 +03:00
|
|
|
if (mathMLFrame) {
|
2005-09-07 03:47:01 +04:00
|
|
|
nsEmbellishData embellishData;
|
|
|
|
nsPresentationData presentationData;
|
|
|
|
mathMLFrame->GetEmbellishData(embellishData);
|
|
|
|
mathMLFrame->GetPresentationData(presentationData);
|
|
|
|
if (NS_MATHML_IS_EMBELLISH_OPERATOR(embellishData.flags) &&
|
|
|
|
embellishData.direction == aStretchDirection &&
|
|
|
|
presentationData.baseFrame) {
|
2002-01-02 08:32:33 +03:00
|
|
|
// embellishements are not included, only consider the inner first child itself
|
2008-02-26 07:19:36 +03:00
|
|
|
// XXXkt Does that mean the core descendent frame should be used
|
|
|
|
// instead of the base child?
|
2009-01-12 22:20:59 +03:00
|
|
|
nsIMathMLFrame* mathMLchildFrame = do_QueryFrame(presentationData.baseFrame);
|
2002-01-11 02:40:40 +03:00
|
|
|
if (mathMLchildFrame) {
|
2002-01-02 08:32:33 +03:00
|
|
|
mathMLFrame = mathMLchildFrame;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
mathMLFrame->GetBoundingMetrics(bmChild);
|
|
|
|
}
|
2008-02-26 07:19:36 +03:00
|
|
|
else {
|
|
|
|
nsHTMLReflowMetrics unused;
|
|
|
|
GetReflowAndBoundingMetricsFor(childFrame, unused, bmChild);
|
|
|
|
}
|
2002-01-02 08:32:33 +03:00
|
|
|
|
|
|
|
if (firstTime) {
|
|
|
|
firstTime = PR_FALSE;
|
|
|
|
bm = bmChild;
|
2002-02-07 07:38:08 +03:00
|
|
|
if (!NS_MATHML_WILL_STRETCH_ALL_CHILDREN_HORIZONTALLY(mPresentationData.flags) &&
|
|
|
|
!NS_MATHML_WILL_STRETCH_ALL_CHILDREN_VERTICALLY(mPresentationData.flags)) {
|
2002-01-02 08:32:33 +03:00
|
|
|
// we may get here for cases such as <msup><mo>...</mo> ... </msup>
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
2002-02-07 07:38:08 +03:00
|
|
|
if (NS_MATHML_WILL_STRETCH_ALL_CHILDREN_HORIZONTALLY(mPresentationData.flags)) {
|
2002-01-02 08:32:33 +03:00
|
|
|
// 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 11:32:46 +04: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;
|
|
|
|
}
|
2002-01-02 08:32:33 +03:00
|
|
|
if (bm.leftBearing > bmChild.leftBearing)
|
|
|
|
bm.leftBearing = bmChild.leftBearing;
|
|
|
|
if (bm.rightBearing < bmChild.rightBearing)
|
|
|
|
bm.rightBearing = bmChild.rightBearing;
|
|
|
|
}
|
2002-02-07 07:38:08 +03:00
|
|
|
else if (NS_MATHML_WILL_STRETCH_ALL_CHILDREN_VERTICALLY(mPresentationData.flags)) {
|
2002-01-02 08:32:33 +03:00
|
|
|
// just sum-up the sizes horizontally.
|
|
|
|
bm += bmChild;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
NS_ERROR("unexpected case in GetPreferredStretchSize");
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2003-07-08 15:00:00 +04:00
|
|
|
childFrame = childFrame->GetNextSibling();
|
2002-01-02 08:32:33 +03:00
|
|
|
}
|
|
|
|
aPreferredStretchSize = bm;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2001-02-02 17:27:38 +03:00
|
|
|
NS_IMETHODIMP
|
2011-04-08 05:04:40 +04:00
|
|
|
nsMathMLContainerFrame::Stretch(nsRenderingContext& aRenderingContext,
|
2001-02-02 17:27:38 +03:00
|
|
|
nsStretchDirection aStretchDirection,
|
|
|
|
nsBoundingMetrics& aContainerSize,
|
|
|
|
nsHTMLReflowMetrics& aDesiredStretchSize)
|
|
|
|
{
|
|
|
|
if (NS_MATHML_IS_EMBELLISH_OPERATOR(mEmbellishData.flags)) {
|
|
|
|
|
2002-02-07 07:38:08 +03:00
|
|
|
if (NS_MATHML_STRETCH_WAS_DONE(mPresentationData.flags)) {
|
2001-02-23 19:10:51 +03:00
|
|
|
NS_WARNING("it is wrong to fire stretch more than once on a frame");
|
2001-02-02 17:27:38 +03:00
|
|
|
return NS_OK;
|
|
|
|
}
|
2002-02-07 07:38:08 +03:00
|
|
|
mPresentationData.flags |= NS_MATHML_STRETCH_DONE;
|
2001-02-02 17:27:38 +03:00
|
|
|
|
|
|
|
if (NS_MATHML_HAS_ERROR(mPresentationData.flags)) {
|
2001-02-23 19:10:51 +03:00
|
|
|
NS_WARNING("it is wrong to fire stretch on a erroneous frame");
|
2001-02-02 17:27:38 +03:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2005-09-07 03:47:01 +04:00
|
|
|
// Pass the stretch to the base child ...
|
2001-02-02 17:27:38 +03:00
|
|
|
|
2007-12-29 02:04:19 +03:00
|
|
|
nsIFrame* baseFrame = mPresentationData.baseFrame;
|
|
|
|
if (baseFrame) {
|
2009-01-12 22:20:59 +03:00
|
|
|
nsIMathMLFrame* mathMLFrame = do_QueryFrame(baseFrame);
|
2002-01-11 02:40:40 +03:00
|
|
|
NS_ASSERTION(mathMLFrame, "Something is wrong somewhere");
|
|
|
|
if (mathMLFrame) {
|
2002-01-03 01:42:52 +03:00
|
|
|
PRBool stretchAll =
|
2002-02-07 07:38:08 +03:00
|
|
|
NS_MATHML_WILL_STRETCH_ALL_CHILDREN_VERTICALLY(mPresentationData.flags) ||
|
|
|
|
NS_MATHML_WILL_STRETCH_ALL_CHILDREN_HORIZONTALLY(mPresentationData.flags);
|
2001-02-02 17:27:38 +03:00
|
|
|
|
2001-02-23 19:10:51 +03:00
|
|
|
// And the trick is that the child's rect.x is still holding the descent,
|
2001-02-02 17:27:38 +03:00
|
|
|
// and rect.y is still holding the ascent ...
|
|
|
|
nsHTMLReflowMetrics childSize(aDesiredStretchSize);
|
2007-12-29 02:04:19 +03:00
|
|
|
GetReflowAndBoundingMetricsFor(baseFrame, childSize, childSize.mBoundingMetrics);
|
2001-02-23 19:10:51 +03:00
|
|
|
|
2002-01-05 04:15:04 +03: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>
|
2001-02-02 17:27:38 +03:00
|
|
|
nsBoundingMetrics containerSize = aContainerSize;
|
2001-02-23 19:10:51 +03:00
|
|
|
if (aStretchDirection != NS_STRETCH_DIRECTION_DEFAULT &&
|
2001-02-02 17:27:38 +03:00
|
|
|
aStretchDirection != mEmbellishData.direction) {
|
2002-01-05 04:15:04 +03:00
|
|
|
if (mEmbellishData.direction == NS_STRETCH_DIRECTION_UNSUPPORTED) {
|
|
|
|
containerSize = childSize.mBoundingMetrics;
|
|
|
|
}
|
|
|
|
else {
|
2005-02-07 04:57:50 +03:00
|
|
|
GetPreferredStretchSize(aRenderingContext,
|
2002-01-05 04:15:04 +03:00
|
|
|
stretchAll ? STRETCH_CONSIDER_EMBELLISHMENTS : 0,
|
|
|
|
mEmbellishData.direction, containerSize);
|
|
|
|
}
|
2001-02-02 17:27:38 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
// do the stretching...
|
2005-02-07 04:57:50 +03:00
|
|
|
mathMLFrame->Stretch(aRenderingContext,
|
2001-02-23 19:10:51 +03:00
|
|
|
mEmbellishData.direction, containerSize, childSize);
|
2001-02-02 17:27:38 +03:00
|
|
|
// store the updated metrics
|
2008-02-26 07:19:36 +03:00
|
|
|
SaveReflowAndBoundingMetricsFor(baseFrame, childSize,
|
|
|
|
childSize.mBoundingMetrics);
|
|
|
|
|
2002-01-02 08:32:33 +03: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
|
|
|
|
|
2002-01-03 01:42:52 +03:00
|
|
|
if (stretchAll) {
|
2002-01-02 08:32:33 +03:00
|
|
|
|
|
|
|
nsStretchDirection stretchDir =
|
2002-02-07 07:38:08 +03:00
|
|
|
NS_MATHML_WILL_STRETCH_ALL_CHILDREN_VERTICALLY(mPresentationData.flags) ?
|
2002-01-02 08:32:33 +03:00
|
|
|
NS_STRETCH_DIRECTION_VERTICAL : NS_STRETCH_DIRECTION_HORIZONTAL;
|
|
|
|
|
2005-02-07 04:57:50 +03:00
|
|
|
GetPreferredStretchSize(aRenderingContext, STRETCH_CONSIDER_EMBELLISHMENTS,
|
2002-01-02 08:32:33 +03:00
|
|
|
stretchDir, containerSize);
|
|
|
|
|
2007-12-29 02:04:19 +03:00
|
|
|
nsIFrame* childFrame = mFrames.FirstChild();
|
2002-01-02 08:32:33 +03:00
|
|
|
while (childFrame) {
|
2005-09-07 03:47:01 +04:00
|
|
|
if (childFrame != mPresentationData.baseFrame) {
|
2009-01-12 22:20:59 +03:00
|
|
|
mathMLFrame = do_QueryFrame(childFrame);
|
2002-01-11 02:40:40 +03:00
|
|
|
if (mathMLFrame) {
|
2002-01-02 08:32:33 +03:00
|
|
|
// retrieve the metrics that was stored at the previous pass
|
|
|
|
GetReflowAndBoundingMetricsFor(childFrame,
|
|
|
|
childSize, childSize.mBoundingMetrics);
|
|
|
|
// do the stretching...
|
2005-02-07 04:57:50 +03:00
|
|
|
mathMLFrame->Stretch(aRenderingContext, stretchDir,
|
|
|
|
containerSize, childSize);
|
2002-01-02 08:32:33 +03:00
|
|
|
// store the updated metrics
|
2008-02-26 07:19:36 +03:00
|
|
|
SaveReflowAndBoundingMetricsFor(childFrame, childSize,
|
|
|
|
childSize.mBoundingMetrics);
|
2002-01-02 08:32:33 +03:00
|
|
|
}
|
|
|
|
}
|
2003-07-08 15:00:00 +04:00
|
|
|
childFrame = childFrame->GetNextSibling();
|
2002-01-02 08:32:33 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// re-position all our children
|
2007-03-02 13:55:55 +03:00
|
|
|
nsresult rv = Place(aRenderingContext, PR_TRUE, aDesiredStretchSize);
|
|
|
|
if (NS_MATHML_HAS_ERROR(mPresentationData.flags) || NS_FAILED(rv)) {
|
|
|
|
// Make sure the child frames get their DidReflow() calls.
|
|
|
|
DidReflowChildren(mFrames.FirstChild());
|
|
|
|
}
|
2001-02-02 17:27:38 +03:00
|
|
|
|
|
|
|
// 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.
|
|
|
|
|
2002-02-07 07:38:08 +03:00
|
|
|
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
|
2005-11-21 01:05:24 +03:00
|
|
|
// on style data, and style changes could have occurred in the core since
|
2002-02-07 07:38:08 +03:00
|
|
|
// our last visit there)
|
2001-02-02 17:27:38 +03:00
|
|
|
nsEmbellishData coreData;
|
2002-02-07 07:38:08 +03:00
|
|
|
GetEmbellishDataFrom(mEmbellishData.coreFrame, coreData);
|
2001-02-02 17:27:38 +03:00
|
|
|
|
2002-01-05 04:15:04 +03:00
|
|
|
mBoundingMetrics.width += coreData.leftSpace + coreData.rightSpace;
|
|
|
|
aDesiredStretchSize.width = mBoundingMetrics.width;
|
|
|
|
aDesiredStretchSize.mBoundingMetrics.width = mBoundingMetrics.width;
|
2001-02-02 17:27:38 +03:00
|
|
|
|
2002-01-05 04:15:04 +03:00
|
|
|
nscoord dx = coreData.leftSpace;
|
2007-12-29 02:04:19 +03: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();
|
|
|
|
}
|
2001-02-02 17:27:38 +03:00
|
|
|
}
|
|
|
|
}
|
2007-12-29 02:04:19 +03:00
|
|
|
|
2008-02-26 07:19:36 +03:00
|
|
|
// Finished with these:
|
|
|
|
ClearSavedChildMetrics();
|
2007-12-29 02:04:19 +03:00
|
|
|
// Set our overflow area
|
|
|
|
GatherAndStoreOverflow(&aDesiredStretchSize);
|
2001-02-02 17:27:38 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
2011-04-08 05:04:40 +04:00
|
|
|
nsMathMLContainerFrame::FinalizeReflow(nsRenderingContext& aRenderingContext,
|
2001-02-02 17:27:38 +03: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
|
2001-02-23 19:10:51 +03:00
|
|
|
// targeted at us. If not, we go ahead and fire an involutive stretch on
|
2001-02-02 17:27:38 +03:00
|
|
|
// 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.
|
2002-01-05 04:15:04 +03:00
|
|
|
|
|
|
|
// 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.
|
2002-01-06 22:47:24 +03:00
|
|
|
// (<mo> needs to fire stretch on its MathMLChar in any case to initialize it)
|
2002-01-05 04:15:04 +03:00
|
|
|
PRBool placeOrigin = !NS_MATHML_IS_EMBELLISH_OPERATOR(mEmbellishData.flags) ||
|
2005-09-07 03:47:01 +04:00
|
|
|
(mEmbellishData.coreFrame != this && !mPresentationData.baseFrame &&
|
2002-01-05 04:15:04 +03:00
|
|
|
mEmbellishData.direction == NS_STRETCH_DIRECTION_UNSUPPORTED);
|
2007-03-02 13:55:55 +03:00
|
|
|
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)) {
|
|
|
|
DidReflowChildren(GetFirstChild(nsnull));
|
|
|
|
return rv;
|
2006-01-21 05:31:02 +03:00
|
|
|
}
|
|
|
|
|
2008-02-26 07:19:36 +03:00
|
|
|
PRBool parentWillFireStretch = PR_FALSE;
|
2001-02-02 17:27:38 +03:00
|
|
|
if (!placeOrigin) {
|
2001-02-23 19:10:51 +03:00
|
|
|
// This means the rect.x and rect.y of our children were not set!!
|
2001-02-02 17:27:38 +03:00
|
|
|
// 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 22:20:59 +03:00
|
|
|
nsIMathMLFrame* mathMLFrame = do_QueryFrame(mParent);
|
2002-01-11 02:40:40 +03:00
|
|
|
if (mathMLFrame) {
|
2002-02-07 07:38:08 +03:00
|
|
|
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)
|
2005-09-07 03:47:01 +04:00
|
|
|
&& presentationData.baseFrame == this))
|
2001-02-02 17:27:38 +03:00
|
|
|
{
|
|
|
|
parentWillFireStretch = PR_TRUE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (!parentWillFireStretch) {
|
|
|
|
// There is nobody who will fire the stretch for us, we do it ourselves!
|
|
|
|
|
2002-01-06 22:47:24 +03:00
|
|
|
PRBool stretchAll =
|
2002-02-07 07:38:08 +03:00
|
|
|
/* NS_MATHML_WILL_STRETCH_ALL_CHILDREN_VERTICALLY(mPresentationData.flags) || */
|
|
|
|
NS_MATHML_WILL_STRETCH_ALL_CHILDREN_HORIZONTALLY(mPresentationData.flags);
|
2002-01-06 22:47:24 +03:00
|
|
|
|
2002-01-02 08:32:33 +03:00
|
|
|
nsBoundingMetrics defaultSize;
|
2002-01-28 01:10:45 +03:00
|
|
|
if (mEmbellishData.coreFrame == this /* case of a bare <mo>...</mo> itself */
|
2002-01-06 22:47:24 +03:00
|
|
|
|| stretchAll) { /* or <mover><mo>...</mo>...</mover>, or friends */
|
|
|
|
// use our current size as computed earlier by Place()
|
2002-01-05 04:15:04 +03:00
|
|
|
defaultSize = aDesiredSize.mBoundingMetrics;
|
|
|
|
}
|
2002-01-06 22:47:24 +03:00
|
|
|
else { /* case of <msup><mo>...</mo>...</msup> or friends */
|
|
|
|
// compute a size that doesn't include embellishments
|
2005-02-07 04:57:50 +03:00
|
|
|
GetPreferredStretchSize(aRenderingContext, 0, mEmbellishData.direction,
|
|
|
|
defaultSize);
|
2002-01-05 04:15:04 +03:00
|
|
|
}
|
2005-02-07 04:57:50 +03:00
|
|
|
Stretch(aRenderingContext, NS_STRETCH_DIRECTION_DEFAULT, defaultSize,
|
|
|
|
aDesiredSize);
|
2007-03-02 13:55:55 +03:00
|
|
|
#ifdef NS_DEBUG
|
|
|
|
{
|
|
|
|
// The Place() call above didn't request FinishReflowChild(),
|
|
|
|
// so let's check that we eventually did through Stretch().
|
|
|
|
nsIFrame* childFrame = GetFirstChild(nsnull);
|
|
|
|
for ( ; childFrame; childFrame = childFrame->GetNextSibling()) {
|
|
|
|
NS_ASSERTION(!(childFrame->GetStateBits() & NS_FRAME_IN_REFLOW),
|
|
|
|
"DidReflow() was never called");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif
|
2001-02-02 17:27:38 +03:00
|
|
|
}
|
|
|
|
}
|
2001-02-23 19:10:51 +03:00
|
|
|
|
|
|
|
// see if we should fix the spacing
|
2005-02-07 04:57:50 +03:00
|
|
|
FixInterFrameSpacing(aDesiredSize);
|
2001-02-23 19:10:51 +03:00
|
|
|
|
2007-12-29 02:04:19 +03:00
|
|
|
// Also return our bounding metrics
|
|
|
|
aDesiredSize.mBoundingMetrics = mBoundingMetrics;
|
|
|
|
|
2008-02-26 07:19:36 +03:00
|
|
|
if (!parentWillFireStretch) {
|
|
|
|
// Not expecting a stretch.
|
|
|
|
// Finished with these:
|
|
|
|
ClearSavedChildMetrics();
|
|
|
|
// Set our overflow area.
|
2007-12-29 02:04:19 +03:00
|
|
|
GatherAndStoreOverflow(&aDesiredSize);
|
|
|
|
}
|
|
|
|
|
2001-02-02 17:27:38 +03:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/* /////////////
|
|
|
|
* nsIMathMLFrame - support methods for scripting elements (nested frames
|
2001-02-23 19:10:51 +03:00
|
|
|
* within msub, msup, msubsup, munder, mover, munderover, mmultiscripts,
|
2001-02-02 17:27:38 +03:00
|
|
|
* mfrac, mroot, mtable).
|
|
|
|
* =============================================================================
|
|
|
|
*/
|
|
|
|
|
2002-01-09 21:51:30 +03:00
|
|
|
// helper to let the update of presentation data pass through
|
|
|
|
// a subtree that may contain non-mathml container frames
|
|
|
|
/* static */ void
|
2005-02-07 04:57:50 +03:00
|
|
|
nsMathMLContainerFrame::PropagatePresentationDataFor(nsIFrame* aFrame,
|
2002-01-09 21:51:30 +03:00
|
|
|
PRUint32 aFlagsValues,
|
|
|
|
PRUint32 aFlagsToUpdate)
|
2001-02-02 17:27:38 +03:00
|
|
|
{
|
2008-01-09 12:38:28 +03:00
|
|
|
if (!aFrame || !aFlagsToUpdate)
|
2002-01-10 07:42:55 +03:00
|
|
|
return;
|
2009-01-12 22:20:59 +03:00
|
|
|
nsIMathMLFrame* mathMLFrame = do_QueryFrame(aFrame);
|
2002-01-09 21:51:30 +03:00
|
|
|
if (mathMLFrame) {
|
|
|
|
// update
|
2008-01-09 12:38:28 +03:00
|
|
|
mathMLFrame->UpdatePresentationData(aFlagsValues,
|
2005-02-07 04:57:50 +03:00
|
|
|
aFlagsToUpdate);
|
2002-01-10 07:42:55 +03:00
|
|
|
// propagate using the base method to make sure that the control
|
|
|
|
// is passed on to MathML frames that may be overloading the method
|
2005-02-07 04:57:50 +03:00
|
|
|
mathMLFrame->UpdatePresentationDataFromChildAt(0, -1,
|
2008-01-09 12:38:28 +03:00
|
|
|
aFlagsValues, aFlagsToUpdate);
|
2002-01-09 21:51:30 +03:00
|
|
|
}
|
2002-01-10 07:42:55 +03:00
|
|
|
else {
|
|
|
|
// propagate down the subtrees
|
2004-01-09 17:20:53 +03:00
|
|
|
nsIFrame* childFrame = aFrame->GetFirstChild(nsnull);
|
2002-01-10 07:42:55 +03:00
|
|
|
while (childFrame) {
|
2005-02-07 04:57:50 +03:00
|
|
|
PropagatePresentationDataFor(childFrame,
|
2008-01-09 12:38:28 +03:00
|
|
|
aFlagsValues, aFlagsToUpdate);
|
2003-07-08 15:00:00 +04:00
|
|
|
childFrame = childFrame->GetNextSibling();
|
2002-01-10 07:42:55 +03:00
|
|
|
}
|
2001-02-02 17:27:38 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2002-01-14 03:55:53 +03:00
|
|
|
/* static */ void
|
2005-02-07 04:57:50 +03:00
|
|
|
nsMathMLContainerFrame::PropagatePresentationDataFromChildAt(nsIFrame* aParentFrame,
|
2002-01-14 03:55:53 +03:00
|
|
|
PRInt32 aFirstChildIndex,
|
|
|
|
PRInt32 aLastChildIndex,
|
|
|
|
PRUint32 aFlagsValues,
|
|
|
|
PRUint32 aFlagsToUpdate)
|
|
|
|
{
|
2008-01-09 12:38:28 +03:00
|
|
|
if (!aParentFrame || !aFlagsToUpdate)
|
2002-01-14 03:55:53 +03:00
|
|
|
return;
|
|
|
|
PRInt32 index = 0;
|
2004-01-09 17:20:53 +03:00
|
|
|
nsIFrame* childFrame = aParentFrame->GetFirstChild(nsnull);
|
2002-01-14 03:55:53 +03:00
|
|
|
while (childFrame) {
|
|
|
|
if ((index >= aFirstChildIndex) &&
|
|
|
|
((aLastChildIndex <= 0) || ((aLastChildIndex > 0) &&
|
|
|
|
(index <= aLastChildIndex)))) {
|
2005-02-07 04:57:50 +03:00
|
|
|
PropagatePresentationDataFor(childFrame,
|
2008-01-09 12:38:28 +03:00
|
|
|
aFlagsValues, aFlagsToUpdate);
|
2002-01-14 03:55:53 +03:00
|
|
|
}
|
|
|
|
index++;
|
2003-07-08 15:00:00 +04:00
|
|
|
childFrame = childFrame->GetNextSibling();
|
2002-01-14 03:55:53 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2001-02-02 17:27:38 +03:00
|
|
|
/* //////////////////
|
|
|
|
* Frame construction
|
|
|
|
* =============================================================================
|
|
|
|
*/
|
|
|
|
|
2002-02-01 18:10:50 +03:00
|
|
|
|
2001-02-02 17:27:38 +03:00
|
|
|
NS_IMETHODIMP
|
2006-01-26 05:29:17 +03:00
|
|
|
nsMathMLContainerFrame::BuildDisplayList(nsDisplayListBuilder* aBuilder,
|
|
|
|
const nsRect& aDirtyRect,
|
|
|
|
const nsDisplayListSet& aLists)
|
2001-02-02 17:27:38 +03:00
|
|
|
{
|
|
|
|
// report an error if something wrong was found in this frame
|
|
|
|
if (NS_MATHML_HAS_ERROR(mPresentationData.flags)) {
|
2006-08-08 03:42:32 +04:00
|
|
|
if (!IsVisibleForPainting(aBuilder))
|
|
|
|
return NS_OK;
|
|
|
|
|
2010-08-13 14:01:13 +04:00
|
|
|
return aLists.Content()->AppendNewToTop(
|
|
|
|
new (aBuilder) nsDisplayMathMLError(aBuilder, this));
|
2001-02-02 17:27:38 +03:00
|
|
|
}
|
|
|
|
|
2006-08-08 03:42:32 +04:00
|
|
|
nsresult rv = DisplayBorderBackgroundOutline(aBuilder, aLists);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
2006-01-26 05:29:17 +03:00
|
|
|
rv = DisplayTextDecorationsAndChildren(aBuilder, aDirtyRect, aLists);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
2001-02-02 17:27:38 +03:00
|
|
|
|
2001-02-23 19:10:51 +03:00
|
|
|
#if defined(NS_DEBUG) && defined(SHOW_BOUNDING_BOX)
|
2001-02-02 17:27:38 +03: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
|
2006-01-26 05:29:17 +03:00
|
|
|
rv = DisplayBoundingMetrics(aBuilder, this, mReference, mBoundingMetrics, aLists);
|
2001-02-23 19:10:51 +03:00
|
|
|
#endif
|
2006-01-26 05:29:17 +03:00
|
|
|
return rv;
|
2001-02-02 17:27:38 +03:00
|
|
|
}
|
2001-02-23 19:10:51 +03:00
|
|
|
|
2002-02-04 00:06:51 +03:00
|
|
|
// Note that this method re-builds the automatic data in the children -- not
|
2002-02-07 07:38:08 +03:00
|
|
|
// in aParentFrame itself (except for those particular operations that the
|
|
|
|
// parent frame may do in its TransmitAutomaticData()).
|
2002-02-01 18:10:50 +03:00
|
|
|
/* static */ void
|
2005-02-07 04:57:50 +03:00
|
|
|
nsMathMLContainerFrame::RebuildAutomaticDataForChildren(nsIFrame* aParentFrame)
|
2002-02-01 18:10:50 +03:00
|
|
|
{
|
|
|
|
// 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
|
2004-01-09 17:20:53 +03:00
|
|
|
nsIFrame* childFrame = aParentFrame->GetFirstChild(nsnull);
|
2002-02-01 18:10:50 +03:00
|
|
|
while (childFrame) {
|
2009-01-12 22:20:59 +03:00
|
|
|
nsIMathMLFrame* childMathMLFrame = do_QueryFrame(childFrame);
|
2002-02-01 18:10:50 +03:00
|
|
|
if (childMathMLFrame) {
|
2005-02-07 04:57:50 +03:00
|
|
|
childMathMLFrame->InheritAutomaticData(aParentFrame);
|
2001-02-02 17:27:38 +03:00
|
|
|
}
|
2005-02-07 04:57:50 +03:00
|
|
|
RebuildAutomaticDataForChildren(childFrame);
|
2003-07-08 15:00:00 +04:00
|
|
|
childFrame = childFrame->GetNextSibling();
|
2002-02-01 18:10:50 +03:00
|
|
|
}
|
2009-01-12 22:20:59 +03:00
|
|
|
nsIMathMLFrame* mathMLFrame = do_QueryFrame(aParentFrame);
|
2002-02-01 18:10:50 +03:00
|
|
|
if (mathMLFrame) {
|
2005-02-07 04:57:50 +03:00
|
|
|
mathMLFrame->TransmitAutomaticData();
|
2001-02-02 17:27:38 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2002-02-04 00:06:51 +03:00
|
|
|
/* static */ nsresult
|
2009-02-11 01:05:27 +03:00
|
|
|
nsMathMLContainerFrame::ReLayoutChildren(nsIFrame* aParentFrame)
|
2002-02-04 00:06:51 +03:00
|
|
|
{
|
2006-01-10 23:38:46 +03:00
|
|
|
if (!aParentFrame)
|
|
|
|
return NS_OK;
|
|
|
|
|
2002-02-04 00:06:51 +03:00
|
|
|
// walk-up to the first frame that is a MathML frame, stop if we reach <math>
|
2002-02-07 07:38:08 +03:00
|
|
|
nsIFrame* frame = aParentFrame;
|
2006-01-10 23:38:46 +03:00
|
|
|
while (1) {
|
|
|
|
nsIFrame* parent = frame->GetParent();
|
|
|
|
if (!parent || !parent->GetContent())
|
|
|
|
break;
|
|
|
|
|
2002-02-04 00:06:51 +03:00
|
|
|
// stop if it is a MathML frame
|
2009-01-12 22:20:59 +03:00
|
|
|
nsIMathMLFrame* mathMLFrame = do_QueryFrame(frame);
|
2008-01-09 12:38:28 +03:00
|
|
|
if (mathMLFrame)
|
2002-02-04 00:06:51 +03:00
|
|
|
break;
|
2006-01-10 23:38:46 +03:00
|
|
|
|
2002-02-04 00:06:51 +03:00
|
|
|
// stop if we reach the root <math> tag
|
2003-07-08 15:00:00 +04:00
|
|
|
nsIContent* content = frame->GetContent();
|
2002-04-02 07:57:56 +04:00
|
|
|
NS_ASSERTION(content, "dangling frame without a content node");
|
|
|
|
if (!content)
|
2002-02-04 00:06:51 +03:00
|
|
|
break;
|
Bug 300030: Move intrinsic width computation out of nsIFrame::Reflow and into its own methods on nsIFrame. Replace reflow reasons, types, and commands with dirty bits/notifications. Thanks to bzbarsky for almost all of the HTML form controls (mozilla/layout/forms) changes, and many others for help testing and patching. For detailed commit logs, see REFLOW_YYYYMMDD_BRANCH, where YYYYMMDD is one of 20061031, 20060830, 20060603, 20060302, 20060119, 20051011, 20050804, 20050429, 20050315, 20050111, and 20041213.
2006-12-08 08:38:33 +03:00
|
|
|
// XXXldb This should check namespaces too.
|
2006-12-26 20:47:52 +03:00
|
|
|
if (content->Tag() == nsGkAtoms::math)
|
2006-01-10 23:38:46 +03:00
|
|
|
break;
|
|
|
|
|
2007-05-06 23:16:51 +04: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-11 01:05:27 +03: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.
|
2003-07-08 15:00:00 +04:00
|
|
|
frame->AddStateBits(NS_FRAME_IS_DIRTY | NS_FRAME_HAS_DIRTY_CHILDREN);
|
2006-01-10 23:38:46 +03:00
|
|
|
|
|
|
|
frame = parent;
|
2002-02-04 00:06:51 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
// re-sync the presentation data and embellishment data of our children
|
2005-02-07 04:57:50 +03:00
|
|
|
RebuildAutomaticDataForChildren(frame);
|
2002-02-04 00:06:51 +03:00
|
|
|
|
|
|
|
// Ask our parent frame to reflow us
|
2005-10-27 03:21:09 +04:00
|
|
|
nsIFrame* parent = frame->GetParent();
|
|
|
|
NS_ASSERTION(parent, "No parent to pass the reflow request up to");
|
|
|
|
if (!parent)
|
|
|
|
return NS_OK;
|
|
|
|
|
2010-03-21 00:54:19 +03:00
|
|
|
frame->PresContext()->PresShell()->
|
2009-02-11 01:05:27 +03:00
|
|
|
FrameNeedsReflow(frame, nsIPresShell::eStyleChange, NS_FRAME_IS_DIRTY);
|
2010-03-21 00:54:19 +03:00
|
|
|
|
|
|
|
return NS_OK;
|
2002-02-04 00:06:51 +03: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
|
2005-02-07 04:57:50 +03:00
|
|
|
nsMathMLContainerFrame::ChildListChanged(PRInt32 aModType)
|
2002-02-04 00:06:51 +03:00
|
|
|
{
|
2005-03-14 08:30:49 +03: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) {
|
2006-08-16 09:28:26 +04:00
|
|
|
nsIFrame* parent = mParent;
|
2005-03-14 08:30:49 +03:00
|
|
|
nsEmbellishData embellishData;
|
2006-08-16 09:28:26 +04:00
|
|
|
for ( ; parent; frame = parent, parent = parent->GetParent()) {
|
|
|
|
GetEmbellishDataFrom(parent, embellishData);
|
2005-03-14 08:30:49 +03:00
|
|
|
if (embellishData.coreFrame != mEmbellishData.coreFrame)
|
|
|
|
break;
|
2007-05-06 23:16:51 +04:00
|
|
|
|
|
|
|
// Important: do not do this to the frame we plan to pass to
|
|
|
|
// ReLayoutChildren
|
2009-02-11 01:05:27 +03: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 23:16:51 +04:00
|
|
|
frame->AddStateBits(NS_FRAME_IS_DIRTY | NS_FRAME_HAS_DIRTY_CHILDREN);
|
2005-03-14 08:30:49 +03:00
|
|
|
}
|
|
|
|
}
|
2009-02-11 01:05:27 +03:00
|
|
|
return ReLayoutChildren(frame);
|
2002-02-04 00:06:51 +03:00
|
|
|
}
|
|
|
|
|
2002-01-25 09:48:30 +03:00
|
|
|
NS_IMETHODIMP
|
2005-02-07 04:57:50 +03:00
|
|
|
nsMathMLContainerFrame::AppendFrames(nsIAtom* aListName,
|
2009-07-30 21:23:32 +04:00
|
|
|
nsFrameList& aFrameList)
|
2002-01-25 09:48:30 +03:00
|
|
|
{
|
|
|
|
if (aListName) {
|
|
|
|
return NS_ERROR_INVALID_ARG;
|
|
|
|
}
|
2009-07-30 21:23:32 +04:00
|
|
|
mFrames.AppendFrames(this, aFrameList);
|
|
|
|
return ChildListChanged(nsIDOMMutationEvent::ADDITION);
|
2002-01-25 09:48:30 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2005-02-07 04:57:50 +03:00
|
|
|
nsMathMLContainerFrame::InsertFrames(nsIAtom* aListName,
|
2002-01-25 09:48:30 +03:00
|
|
|
nsIFrame* aPrevFrame,
|
2009-07-30 21:23:32 +04:00
|
|
|
nsFrameList& aFrameList)
|
2002-01-25 09:48:30 +03:00
|
|
|
{
|
|
|
|
if (aListName) {
|
|
|
|
return NS_ERROR_INVALID_ARG;
|
|
|
|
}
|
2009-07-30 21:23:32 +04:00
|
|
|
// Insert frames after aPrevFrame
|
|
|
|
mFrames.InsertFrames(this, aPrevFrame, aFrameList);
|
|
|
|
return ChildListChanged(nsIDOMMutationEvent::ADDITION);
|
2002-01-25 09:48:30 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2005-02-07 04:57:50 +03:00
|
|
|
nsMathMLContainerFrame::RemoveFrame(nsIAtom* aListName,
|
2002-01-25 09:48:30 +03:00
|
|
|
nsIFrame* aOldFrame)
|
|
|
|
{
|
|
|
|
if (aListName) {
|
|
|
|
return NS_ERROR_INVALID_ARG;
|
|
|
|
}
|
2002-02-01 18:10:50 +03:00
|
|
|
// remove the child frame
|
2006-04-10 04:16:29 +04:00
|
|
|
mFrames.DestroyFrame(aOldFrame);
|
2005-02-07 04:57:50 +03:00
|
|
|
return ChildListChanged(nsIDOMMutationEvent::REMOVAL);
|
2002-01-25 09:48:30 +03:00
|
|
|
}
|
|
|
|
|
2001-02-23 19:10:51 +03:00
|
|
|
NS_IMETHODIMP
|
2005-09-07 20:49:21 +04:00
|
|
|
nsMathMLContainerFrame::AttributeChanged(PRInt32 aNameSpaceID,
|
2001-02-23 19:10:51 +03:00
|
|
|
nsIAtom* aAttribute,
|
2003-07-12 01:16:12 +04:00
|
|
|
PRInt32 aModType)
|
2001-02-23 19:10:51 +03:00
|
|
|
{
|
2006-09-07 07:45:45 +04: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.
|
Bug 300030: Move intrinsic width computation out of nsIFrame::Reflow and into its own methods on nsIFrame. Replace reflow reasons, types, and commands with dirty bits/notifications. Thanks to bzbarsky for almost all of the HTML form controls (mozilla/layout/forms) changes, and many others for help testing and patching. For detailed commit logs, see REFLOW_YYYYMMDD_BRANCH, where YYYYMMDD is one of 20061031, 20060830, 20060603, 20060302, 20060119, 20051011, 20050804, 20050429, 20050315, 20050111, and 20041213.
2006-12-08 08:38:33 +03:00
|
|
|
// XXXldb This should only do work for attributes that cause changes!
|
2010-03-21 00:54:19 +03:00
|
|
|
PresContext()->PresShell()->
|
|
|
|
FrameNeedsReflow(this, nsIPresShell::eStyleChange, NS_FRAME_IS_DIRTY);
|
|
|
|
|
|
|
|
return NS_OK;
|
2001-02-02 17:27:38 +03:00
|
|
|
}
|
|
|
|
|
2007-12-29 02:04:19 +03:00
|
|
|
void
|
|
|
|
nsMathMLContainerFrame::GatherAndStoreOverflow(nsHTMLReflowMetrics* aMetrics)
|
|
|
|
{
|
|
|
|
// nsIFrame::FinishAndStoreOverflow likes the overflow area to include the
|
|
|
|
// frame rectangle.
|
2010-10-07 08:25:46 +04:00
|
|
|
aMetrics->SetOverflowAreasToDesiredBounds();
|
2007-12-29 02:04:19 +03:00
|
|
|
|
2008-06-13 02:02:32 +04:00
|
|
|
// Text-shadow overflows.
|
|
|
|
if (PresContext()->CompatibilityMode() != eCompatibility_NavQuirks) {
|
2010-10-07 08:25:46 +04:00
|
|
|
nsRect frameRect(0, 0, aMetrics->width, aMetrics->height);
|
2008-06-13 02:02:32 +04:00
|
|
|
nsRect shadowRect = nsLayoutUtils::GetTextShadowRectsUnion(frameRect, this);
|
2010-10-07 08:25:46 +04:00
|
|
|
// shadows contribute only to visual overflow
|
|
|
|
nsRect& visOverflow = aMetrics->VisualOverflow();
|
|
|
|
visOverflow.UnionRect(visOverflow, shadowRect);
|
2008-06-13 02:02:32 +04:00
|
|
|
}
|
|
|
|
|
2007-12-29 02:04:19 +03: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-07 08:25:46 +04:00
|
|
|
// REVIEW: Maybe this should contribute only to visual overflow
|
|
|
|
// and not scrollable?
|
|
|
|
aMetrics->mOverflowAreas.UnionAllWith(boundingBox);
|
2007-12-29 02:04:19 +03: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-07 08:25:46 +04:00
|
|
|
ConsiderChildOverflow(aMetrics->mOverflowAreas, childFrame);
|
2007-12-29 02:04:19 +03:00
|
|
|
childFrame = childFrame->GetNextSibling();
|
|
|
|
}
|
|
|
|
|
|
|
|
FinishAndStoreOverflow(aMetrics);
|
|
|
|
}
|
|
|
|
|
2006-01-04 10:29:09 +03: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 12:30:54 +04:00
|
|
|
#ifdef DEBUG
|
2009-01-12 22:20:59 +03:00
|
|
|
nsInlineFrame* inlineFrame = do_QueryFrame(aChildFrame);
|
2007-10-12 12:30:54 +04:00
|
|
|
NS_ASSERTION(!inlineFrame, "Inline frames should be wrapped in blocks");
|
|
|
|
#endif
|
|
|
|
|
|
|
|
nsresult rv = nsHTMLContainerFrame::
|
|
|
|
ReflowChild(aChildFrame, aPresContext, aDesiredSize, aReflowState,
|
|
|
|
0, 0, NS_FRAME_NO_MOVE_FRAME, aStatus);
|
2007-12-03 03:54:23 +03:00
|
|
|
|
2008-02-26 07:19:36 +03:00
|
|
|
if (NS_FAILED(rv))
|
|
|
|
return rv;
|
|
|
|
|
2007-12-03 03:54:23 +03: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-26 07:19:36 +03:00
|
|
|
if (IsForeignChild(aChildFrame)) {
|
2007-12-03 03:54:23 +03:00
|
|
|
// use ComputeTightBounds API as aDesiredSize.mBoundingMetrics is not set.
|
2007-12-19 02:01:15 +03:00
|
|
|
nsRect r = aChildFrame->ComputeTightBounds(aReflowState.rendContext->ThebesContext());
|
2007-10-12 12:30:54 +04:00
|
|
|
aDesiredSize.mBoundingMetrics.leftBearing = r.x;
|
|
|
|
aDesiredSize.mBoundingMetrics.rightBearing = r.XMost();
|
2007-12-03 03:54:23 +03:00
|
|
|
aDesiredSize.mBoundingMetrics.ascent = aDesiredSize.ascent - r.y;
|
|
|
|
aDesiredSize.mBoundingMetrics.descent = r.YMost() - aDesiredSize.ascent;
|
2007-10-12 12:30:54 +04:00
|
|
|
aDesiredSize.mBoundingMetrics.width = aDesiredSize.width;
|
|
|
|
}
|
|
|
|
return rv;
|
2006-01-04 10:29:09 +03:00
|
|
|
}
|
|
|
|
|
2001-02-02 17:27:38 +03:00
|
|
|
NS_IMETHODIMP
|
2007-12-29 02:04:19 +03:00
|
|
|
nsMathMLContainerFrame::Reflow(nsPresContext* aPresContext,
|
2001-02-02 17:27:38 +03:00
|
|
|
nsHTMLReflowMetrics& aDesiredSize,
|
|
|
|
const nsHTMLReflowState& aReflowState,
|
|
|
|
nsReflowStatus& aStatus)
|
|
|
|
{
|
|
|
|
aDesiredSize.width = aDesiredSize.height = 0;
|
2007-01-23 07:06:56 +03:00
|
|
|
aDesiredSize.ascent = 0;
|
2011-04-08 05:04:40 +04:00
|
|
|
aDesiredSize.mBoundingMetrics = nsBoundingMetrics();
|
2001-02-02 17:27:38 +03:00
|
|
|
|
|
|
|
/////////////
|
|
|
|
// Reflow children
|
|
|
|
// Asking each child to cache its bounding metrics
|
|
|
|
|
|
|
|
nsReflowStatus childStatus;
|
2007-11-09 09:53:04 +03:00
|
|
|
nsSize availSize(aReflowState.ComputedWidth(), NS_UNCONSTRAINEDSIZE);
|
2001-02-02 17:27:38 +03:00
|
|
|
nsIFrame* childFrame = mFrames.FirstChild();
|
|
|
|
while (childFrame) {
|
2007-12-03 03:54:23 +03:00
|
|
|
nsHTMLReflowMetrics childDesiredSize(aDesiredSize.mFlags);
|
2001-02-23 19:10:51 +03:00
|
|
|
nsHTMLReflowState childReflowState(aPresContext, aReflowState,
|
Bug 300030: Move intrinsic width computation out of nsIFrame::Reflow and into its own methods on nsIFrame. Replace reflow reasons, types, and commands with dirty bits/notifications. Thanks to bzbarsky for almost all of the HTML form controls (mozilla/layout/forms) changes, and many others for help testing and patching. For detailed commit logs, see REFLOW_YYYYMMDD_BRANCH, where YYYYMMDD is one of 20061031, 20060830, 20060603, 20060302, 20060119, 20051011, 20050804, 20050429, 20050315, 20050111, and 20041213.
2006-12-08 08:38:33 +03:00
|
|
|
childFrame, availSize);
|
2007-12-29 02:04:19 +03:00
|
|
|
nsresult rv = ReflowChild(childFrame, aPresContext, childDesiredSize,
|
|
|
|
childReflowState, childStatus);
|
2001-02-23 19:10:51 +03:00
|
|
|
//NS_ASSERTION(NS_FRAME_IS_COMPLETE(childStatus), "bad status");
|
2007-03-02 13:55:55 +03:00
|
|
|
if (NS_FAILED(rv)) {
|
|
|
|
// Call DidReflow() for the child frames we successfully did reflow.
|
|
|
|
DidReflowChildren(mFrames.FirstChild(), childFrame);
|
|
|
|
return rv;
|
|
|
|
}
|
2001-02-23 19:10:51 +03:00
|
|
|
|
2008-02-26 07:19:36 +03:00
|
|
|
SaveReflowAndBoundingMetricsFor(childFrame, childDesiredSize,
|
|
|
|
childDesiredSize.mBoundingMetrics);
|
2003-07-08 15:00:00 +04:00
|
|
|
childFrame = childFrame->GetNextSibling();
|
2001-02-02 17:27:38 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
/////////////
|
2001-02-23 19:10:51 +03:00
|
|
|
// If we are a container which is entitled to stretch its children, then we
|
2001-02-02 17:27:38 +03:00
|
|
|
// ask our stretchy children to stretch themselves
|
|
|
|
|
2002-01-02 08:32:33 +03:00
|
|
|
// The stretching of siblings of an embellished child is _deferred_ until
|
|
|
|
// after finishing the stretching of the embellished child - bug 117652
|
2001-02-02 17:27:38 +03:00
|
|
|
|
2002-01-02 08:32:33 +03:00
|
|
|
if (!NS_MATHML_IS_EMBELLISH_OPERATOR(mEmbellishData.flags) &&
|
2002-02-07 07:38:08 +03:00
|
|
|
(NS_MATHML_WILL_STRETCH_ALL_CHILDREN_VERTICALLY(mPresentationData.flags) ||
|
|
|
|
NS_MATHML_WILL_STRETCH_ALL_CHILDREN_HORIZONTALLY(mPresentationData.flags))) {
|
2001-02-02 17:27:38 +03:00
|
|
|
|
2002-01-02 08:32:33 +03:00
|
|
|
// get the stretchy direction
|
2001-02-23 19:10:51 +03:00
|
|
|
nsStretchDirection stretchDir =
|
2002-02-07 07:38:08 +03:00
|
|
|
NS_MATHML_WILL_STRETCH_ALL_CHILDREN_VERTICALLY(mPresentationData.flags)
|
2002-01-02 08:32:33 +03:00
|
|
|
? 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;
|
2005-02-07 04:57:50 +03:00
|
|
|
GetPreferredStretchSize(*aReflowState.rendContext, 0, stretchDir,
|
|
|
|
containerSize);
|
2001-02-02 17:27:38 +03:00
|
|
|
|
|
|
|
// fire the stretch on each child
|
|
|
|
childFrame = mFrames.FirstChild();
|
|
|
|
while (childFrame) {
|
2009-01-12 22:20:59 +03:00
|
|
|
nsIMathMLFrame* mathMLFrame = do_QueryFrame(childFrame);
|
2002-01-11 02:40:40 +03:00
|
|
|
if (mathMLFrame) {
|
2002-01-02 08:32:33 +03:00
|
|
|
// retrieve the metrics that was stored at the previous pass
|
2007-12-03 03:54:23 +03:00
|
|
|
nsHTMLReflowMetrics childDesiredSize;
|
2002-01-02 08:32:33 +03:00
|
|
|
GetReflowAndBoundingMetricsFor(childFrame,
|
|
|
|
childDesiredSize, childDesiredSize.mBoundingMetrics);
|
|
|
|
|
2005-02-07 04:57:50 +03:00
|
|
|
mathMLFrame->Stretch(*aReflowState.rendContext, stretchDir,
|
|
|
|
containerSize, childDesiredSize);
|
2002-01-02 08:32:33 +03:00
|
|
|
// store the updated metrics
|
2008-02-26 07:19:36 +03:00
|
|
|
SaveReflowAndBoundingMetricsFor(childFrame, childDesiredSize,
|
|
|
|
childDesiredSize.mBoundingMetrics);
|
2001-02-02 17:27:38 +03:00
|
|
|
}
|
2003-07-08 15:00:00 +04:00
|
|
|
childFrame = childFrame->GetNextSibling();
|
2001-02-02 17:27:38 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/////////////
|
|
|
|
// Place children now by re-adjusting the origins to align the baselines
|
2005-02-07 04:57:50 +03:00
|
|
|
FinalizeReflow(*aReflowState.rendContext, aDesiredSize);
|
2001-02-02 17:27:38 +03:00
|
|
|
|
|
|
|
aStatus = NS_FRAME_COMPLETE;
|
2002-05-29 02:50:43 +04:00
|
|
|
NS_FRAME_SET_TRUNCATION(aStatus, aReflowState, aDesiredSize);
|
2001-02-02 17:27:38 +03:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2008-02-27 13:45:36 +03:00
|
|
|
/* virtual */ nscoord
|
2011-04-08 05:04:40 +04:00
|
|
|
nsMathMLContainerFrame::GetMinWidth(nsRenderingContext *aRenderingContext)
|
2008-02-27 13:45:36 +03:00
|
|
|
{
|
|
|
|
nscoord result;
|
|
|
|
DISPLAY_MIN_WIDTH(this, result);
|
|
|
|
result = GetIntrinsicWidth(aRenderingContext);
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* virtual */ nscoord
|
2011-04-08 05:04:40 +04:00
|
|
|
nsMathMLContainerFrame::GetPrefWidth(nsRenderingContext *aRenderingContext)
|
2008-02-27 13:45:36 +03:00
|
|
|
{
|
|
|
|
nscoord result;
|
|
|
|
DISPLAY_MIN_WIDTH(this, result);
|
|
|
|
result = GetIntrinsicWidth(aRenderingContext);
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* virtual */ nscoord
|
2011-04-08 05:04:40 +04:00
|
|
|
nsMathMLContainerFrame::GetIntrinsicWidth(nsRenderingContext* aRenderingContext)
|
2008-02-27 13:45:36 +03: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 15:08:35 +04:00
|
|
|
nsresult rv = MeasureForWidth(*aRenderingContext, desiredSize);
|
2008-02-27 13:45:36 +03:00
|
|
|
if (NS_FAILED(rv)) {
|
|
|
|
ReflowError(*aRenderingContext, desiredSize);
|
|
|
|
}
|
|
|
|
|
|
|
|
ClearSavedChildMetrics();
|
|
|
|
|
|
|
|
return desiredSize.width;
|
|
|
|
}
|
|
|
|
|
2008-03-18 08:06:23 +03:00
|
|
|
/* virtual */ nsresult
|
2011-04-08 05:04:40 +04:00
|
|
|
nsMathMLContainerFrame::MeasureForWidth(nsRenderingContext& aRenderingContext,
|
2009-05-29 15:08:35 +04:00
|
|
|
nsHTMLReflowMetrics& aDesiredSize)
|
2008-03-18 08:06:23 +03:00
|
|
|
{
|
|
|
|
return Place(aRenderingContext, PR_FALSE, aDesiredSize);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2001-02-02 17:27:38 +03:00
|
|
|
// see spacing table in Chapter 18, TeXBook (p.170)
|
2002-08-13 03:30:35 +04:00
|
|
|
// Our table isn't quite identical to TeX because operators have
|
|
|
|
// built-in values for lspace & rspace in the Operator Dictionary.
|
2005-09-07 03:47:01 +04:00
|
|
|
static PRInt32 kInterFrameSpacingTable[eMathMLFrameType_COUNT][eMathMLFrameType_COUNT] =
|
2001-02-02 17:27:38 +03:00
|
|
|
{
|
|
|
|
// in units of muspace.
|
|
|
|
// upper half of the byte is set if the
|
|
|
|
// spacing is not to be used for scriptlevel > 0
|
2005-09-07 03:47:01 +04:00
|
|
|
|
|
|
|
/* Ord OpOrd OpInv OpUsr Inner Italic Upright */
|
2005-09-16 04:39:27 +04:00
|
|
|
/*Ord */ {0x00, 0x00, 0x00, 0x01, 0x01, 0x00, 0x00},
|
2005-09-07 03:47:01 +04:00
|
|
|
/*OpOrd*/ {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00},
|
|
|
|
/*OpInv*/ {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00},
|
|
|
|
/*OpUsr*/ {0x01, 0x00, 0x00, 0x01, 0x01, 0x01, 0x01},
|
2005-09-16 04:39:27 +04:00
|
|
|
/*Inner*/ {0x01, 0x00, 0x00, 0x01, 0x01, 0x01, 0x01},
|
|
|
|
/*Italic*/ {0x00, 0x00, 0x00, 0x01, 0x01, 0x00, 0x01},
|
|
|
|
/*Upright*/ {0x00, 0x00, 0x00, 0x01, 0x01, 0x01, 0x01}
|
2001-02-02 17:27:38 +03:00
|
|
|
};
|
|
|
|
|
2002-08-13 04:52:38 +04:00
|
|
|
#define GET_INTERSPACE(scriptlevel_, frametype1_, frametype2_, space_) \
|
2002-08-13 03:30:35 +04:00
|
|
|
/* no space if there is a frame that we know nothing about */ \
|
2002-08-13 04:52:38 +04:00
|
|
|
if (frametype1_ == eMathMLFrameType_UNKNOWN || \
|
|
|
|
frametype2_ == eMathMLFrameType_UNKNOWN) \
|
|
|
|
space_ = 0; \
|
2002-08-13 03:30:35 +04:00
|
|
|
else { \
|
2002-08-13 04:52:38 +04:00
|
|
|
space_ = kInterFrameSpacingTable[frametype1_][frametype2_]; \
|
|
|
|
space_ = (scriptlevel_ > 0 && (space_ & 0xF0)) \
|
2002-08-13 03:30:35 +04:00
|
|
|
? 0 /* spacing is disabled */ \
|
2002-08-13 04:52:38 +04:00
|
|
|
: space_ & 0x0F; \
|
2002-08-13 03:30:35 +04:00
|
|
|
} \
|
|
|
|
|
|
|
|
// 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).
|
2001-02-02 17:27:38 +03:00
|
|
|
static nscoord
|
2002-08-13 03:30:35 +04:00
|
|
|
GetInterFrameSpacing(PRInt32 aScriptLevel,
|
2006-08-15 08:49:43 +04:00
|
|
|
eMathMLFrameType aFirstFrameType,
|
|
|
|
eMathMLFrameType aSecondFrameType,
|
2002-08-13 03:30:35 +04:00
|
|
|
eMathMLFrameType* aFromFrameType, // IN/OUT
|
|
|
|
PRInt32* aCarrySpace) // IN/OUT
|
2001-02-02 17:27:38 +03:00
|
|
|
{
|
2006-08-15 08:49:43 +04:00
|
|
|
eMathMLFrameType firstType = aFirstFrameType;
|
|
|
|
eMathMLFrameType secondType = aSecondFrameType;
|
2002-08-13 03:30:35 +04:00
|
|
|
|
|
|
|
PRInt32 space;
|
|
|
|
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;
|
2001-02-02 17:27:38 +03:00
|
|
|
}
|
2002-08-13 03:30:35 +04:00
|
|
|
else if (*aFromFrameType != eMathMLFrameType_UNKNOWN) {
|
|
|
|
// no carry-forward anymore, get the real inter-space between
|
|
|
|
// the two frames of interest
|
2005-09-07 03:47:01 +04:00
|
|
|
|
|
|
|
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);
|
2002-08-13 03:30:35 +04:00
|
|
|
|
|
|
|
// 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.
|
2005-09-07 03:47:01 +04:00
|
|
|
if (secondType != eMathMLFrameType_OperatorOrdinary &&
|
2002-08-13 03:30:35 +04:00
|
|
|
space < *aCarrySpace)
|
|
|
|
space = *aCarrySpace;
|
|
|
|
|
|
|
|
// reset everything now that the carry-forward is done
|
|
|
|
*aFromFrameType = eMathMLFrameType_UNKNOWN;
|
|
|
|
*aCarrySpace = 0;
|
2001-02-02 17:27:38 +03:00
|
|
|
}
|
2002-08-13 03:30:35 +04:00
|
|
|
|
|
|
|
return space;
|
2001-02-02 17:27:38 +03:00
|
|
|
}
|
|
|
|
|
2008-01-03 07:33:21 +03: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),
|
|
|
|
mChildFrame(aParentFrame->mFrames.FirstChild()),
|
|
|
|
mX(0),
|
|
|
|
mCarrySpace(0),
|
|
|
|
mFromFrameType(eMathMLFrameType_UNKNOWN)
|
|
|
|
{
|
|
|
|
if (!mChildFrame)
|
|
|
|
return;
|
|
|
|
|
|
|
|
InitMetricsForChild();
|
|
|
|
// Remove left correction in <msqrt> because the sqrt glyph itself is
|
|
|
|
// there first.
|
|
|
|
if (mParentFrame->GetContent()->Tag() == nsGkAtoms::msqrt_) {
|
|
|
|
mX = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
RowChildFrameIterator& operator++()
|
|
|
|
{
|
|
|
|
// add child size + italic correction
|
|
|
|
mX += mSize.mBoundingMetrics.width + mItalicCorrection;
|
|
|
|
|
|
|
|
mChildFrame = mChildFrame->GetNextSibling();
|
|
|
|
if (!mChildFrame)
|
|
|
|
return *this;
|
|
|
|
|
|
|
|
eMathMLFrameType prevFrameType = mChildFrameType;
|
|
|
|
InitMetricsForChild();
|
|
|
|
|
|
|
|
// add inter frame spacing
|
2008-01-09 12:38:28 +03:00
|
|
|
const nsStyleFont* font = mParentFrame->GetStyleFont();
|
2008-01-03 07:33:21 +03:00
|
|
|
nscoord space =
|
2008-01-09 12:38:28 +03:00
|
|
|
GetInterFrameSpacing(font->mScriptLevel,
|
2008-01-03 07:33:21 +03:00
|
|
|
prevFrameType, mChildFrameType,
|
|
|
|
&mFromFrameType, &mCarrySpace);
|
2008-01-09 12:38:28 +03:00
|
|
|
mX += space * GetThinSpace(font);
|
2008-01-03 07:33:21 +03: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;
|
|
|
|
PRInt32 mCarrySpace;
|
|
|
|
eMathMLFrameType mFromFrameType;
|
|
|
|
|
|
|
|
void InitMetricsForChild()
|
|
|
|
{
|
|
|
|
GetReflowAndBoundingMetricsFor(mChildFrame, mSize, mSize.mBoundingMetrics,
|
|
|
|
&mChildFrameType);
|
|
|
|
nscoord leftCorrection;
|
|
|
|
GetItalicCorrection(mSize.mBoundingMetrics, leftCorrection,
|
|
|
|
mItalicCorrection);
|
|
|
|
// add left correction -- this fixes the problem of the italic 'f'
|
|
|
|
// e.g., <mo>q</mo> <mi>f</mi> <mo>I</mo>
|
|
|
|
mX += leftCorrection;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2008-03-18 07:52:48 +03:00
|
|
|
/* virtual */ nsresult
|
2011-04-08 05:04:40 +04:00
|
|
|
nsMathMLContainerFrame::Place(nsRenderingContext& aRenderingContext,
|
2001-02-02 17:27:38 +03:00
|
|
|
PRBool aPlaceOrigin,
|
|
|
|
nsHTMLReflowMetrics& aDesiredSize)
|
|
|
|
{
|
2008-01-03 07:33:21 +03:00
|
|
|
// This is needed in case this frame is empty (i.e., no child frames)
|
2011-04-08 05:04:40 +04:00
|
|
|
mBoundingMetrics = nsBoundingMetrics();
|
2001-02-02 17:27:38 +03:00
|
|
|
|
2008-01-03 07:33:21 +03:00
|
|
|
RowChildFrameIterator child(this);
|
2007-01-23 07:06:56 +03:00
|
|
|
nscoord ascent = 0, descent = 0;
|
2008-01-03 07:33:21 +03: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;
|
2001-02-02 17:27:38 +03:00
|
|
|
}
|
2008-01-03 07:33:21 +03: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();
|
|
|
|
|
2001-02-02 17:27:38 +03:00
|
|
|
aDesiredSize.width = mBoundingMetrics.width;
|
2007-01-23 07:06:56 +03:00
|
|
|
aDesiredSize.height = ascent + descent;
|
|
|
|
aDesiredSize.ascent = ascent;
|
2001-02-02 17:27:38 +03:00
|
|
|
aDesiredSize.mBoundingMetrics = mBoundingMetrics;
|
|
|
|
|
|
|
|
mReference.x = 0;
|
|
|
|
mReference.y = aDesiredSize.ascent;
|
|
|
|
|
|
|
|
//////////////////
|
|
|
|
// Place Children
|
|
|
|
|
|
|
|
if (aPlaceOrigin) {
|
2008-01-03 07:33:21 +03:00
|
|
|
PositionRowChildFrames(0, aDesiredSize.ascent);
|
2001-02-02 17:27:38 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2008-01-03 07:33:21 +03:00
|
|
|
void
|
|
|
|
nsMathMLContainerFrame::PositionRowChildFrames(nscoord aOffsetX,
|
|
|
|
nscoord aBaseline)
|
|
|
|
{
|
|
|
|
RowChildFrameIterator child(this);
|
|
|
|
while (child.Frame()) {
|
|
|
|
nscoord dx = aOffsetX + child.X();
|
|
|
|
nscoord dy = aBaseline - child.Ascent();
|
|
|
|
FinishReflowChild(child.Frame(), PresContext(), nsnull,
|
|
|
|
child.ReflowMetrics(), dx, dy, 0);
|
|
|
|
++child;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-01-09 12:38:28 +03:00
|
|
|
class ForceReflow : public nsIReflowCallback {
|
|
|
|
public:
|
|
|
|
virtual PRBool ReflowFinished() {
|
|
|
|
return PR_TRUE;
|
|
|
|
}
|
|
|
|
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
|
|
|
|
nsMathMLContainerFrame::SetIncrementScriptLevel(PRInt32 aChildIndex, PRBool aIncrement)
|
|
|
|
{
|
2009-09-18 15:09:36 +04:00
|
|
|
nsIFrame* child = GetChildList(nsnull).FrameAt(aChildIndex);
|
2008-01-09 12:38:28 +03:00
|
|
|
if (!child)
|
|
|
|
return;
|
|
|
|
nsIContent* content = child->GetContent();
|
2009-08-25 00:02:07 +04:00
|
|
|
if (!content->IsMathML())
|
2008-01-09 12:38:28 +03: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.
|
|
|
|
element->SetIncrementScriptLevel(aIncrement, PR_TRUE);
|
|
|
|
PresContext()->PresShell()->PostReflowCallback(&gForceReflow);
|
|
|
|
}
|
|
|
|
|
2002-08-13 03:30:35 +04:00
|
|
|
// helpers to fix the inter-spacing when <math> is the only parent
|
2001-02-23 19:10:51 +03:00
|
|
|
// e.g., it fixes <math> <mi>f</mi> <mo>q</mo> <mi>f</mi> <mo>I</mo> </math>
|
2002-08-13 03:30:35 +04:00
|
|
|
|
|
|
|
static nscoord
|
2005-02-07 04:57:50 +03:00
|
|
|
GetInterFrameSpacingFor(PRInt32 aScriptLevel,
|
2002-08-13 03:30:35 +04:00
|
|
|
nsIFrame* aParentFrame,
|
|
|
|
nsIFrame* aChildFrame)
|
|
|
|
{
|
2004-01-09 17:20:53 +03:00
|
|
|
nsIFrame* childFrame = aParentFrame->GetFirstChild(nsnull);
|
2002-08-13 03:30:35 +04:00
|
|
|
if (!childFrame || aChildFrame == childFrame)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
PRInt32 carrySpace = 0;
|
|
|
|
eMathMLFrameType fromFrameType = eMathMLFrameType_UNKNOWN;
|
2006-08-15 08:49:43 +04:00
|
|
|
eMathMLFrameType prevFrameType = eMathMLFrameType_UNKNOWN;
|
|
|
|
eMathMLFrameType childFrameType = nsMathMLFrame::GetMathMLFrameTypeFor(childFrame);
|
2003-07-08 15:00:00 +04:00
|
|
|
childFrame = childFrame->GetNextSibling();
|
2002-08-13 03:30:35 +04:00
|
|
|
while (childFrame) {
|
|
|
|
prevFrameType = childFrameType;
|
2006-08-15 08:49:43 +04:00
|
|
|
childFrameType = nsMathMLFrame::GetMathMLFrameTypeFor(childFrame);
|
2002-08-13 03:30:35 +04:00
|
|
|
nscoord space = GetInterFrameSpacing(aScriptLevel,
|
|
|
|
prevFrameType, childFrameType, &fromFrameType, &carrySpace);
|
|
|
|
if (aChildFrame == childFrame) {
|
|
|
|
// get thinspace
|
2003-02-22 03:32:13 +03:00
|
|
|
nsStyleContext* parentContext = aParentFrame->GetStyleContext();
|
2008-01-03 07:33:21 +03:00
|
|
|
nscoord thinSpace = GetThinSpace(parentContext->GetStyleFont());
|
2002-08-13 03:30:35 +04:00
|
|
|
// we are done
|
|
|
|
return space * thinSpace;
|
|
|
|
}
|
2003-07-08 15:00:00 +04:00
|
|
|
childFrame = childFrame->GetNextSibling();
|
2002-08-13 03:30:35 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_NOTREACHED("child not in the childlist of its parent");
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2005-09-16 04:39:27 +04:00
|
|
|
nscoord
|
2005-02-07 04:57:50 +03:00
|
|
|
nsMathMLContainerFrame::FixInterFrameSpacing(nsHTMLReflowMetrics& aDesiredSize)
|
2001-02-23 19:10:51 +03:00
|
|
|
{
|
2005-09-16 04:39:27 +04:00
|
|
|
nscoord gap = 0;
|
2003-07-08 15:00:00 +04:00
|
|
|
nsIContent* parentContent = mParent->GetContent();
|
2007-03-15 22:09:37 +03:00
|
|
|
if (NS_UNLIKELY(!parentContent)) {
|
|
|
|
return 0;
|
|
|
|
}
|
Bug 300030: Move intrinsic width computation out of nsIFrame::Reflow and into its own methods on nsIFrame. Replace reflow reasons, types, and commands with dirty bits/notifications. Thanks to bzbarsky for almost all of the HTML form controls (mozilla/layout/forms) changes, and many others for help testing and patching. For detailed commit logs, see REFLOW_YYYYMMDD_BRANCH, where YYYYMMDD is one of 20061031, 20060830, 20060603, 20060302, 20060119, 20051011, 20050804, 20050429, 20050315, 20050111, and 20041213.
2006-12-08 08:38:33 +03:00
|
|
|
// XXXldb This should check namespaces too.
|
2003-11-19 04:20:56 +03:00
|
|
|
nsIAtom *parentTag = parentContent->Tag();
|
2006-12-26 20:47:52 +03:00
|
|
|
if (parentTag == nsGkAtoms::math ||
|
|
|
|
parentTag == nsGkAtoms::mtd_) {
|
2008-01-09 12:38:28 +03:00
|
|
|
gap = GetInterFrameSpacingFor(GetStyleFont()->mScriptLevel, mParent, this);
|
2001-02-23 19:10:51 +03:00
|
|
|
// add our own italic correction
|
2002-08-13 03:30:35 +04:00
|
|
|
nscoord leftCorrection = 0, italicCorrection = 0;
|
2001-02-23 19:10:51 +03:00
|
|
|
GetItalicCorrection(mBoundingMetrics, leftCorrection, italicCorrection);
|
2001-12-18 13:11:42 +03:00
|
|
|
gap += leftCorrection;
|
|
|
|
// see if we should shift our children to account for the correction
|
|
|
|
if (gap) {
|
2002-08-13 03:30:35 +04:00
|
|
|
nsIFrame* childFrame = mFrames.FirstChild();
|
2001-12-18 13:11:42 +03:00
|
|
|
while (childFrame) {
|
2003-07-08 15:00:00 +04:00
|
|
|
childFrame->SetPosition(childFrame->GetPosition() + nsPoint(gap, 0));
|
|
|
|
childFrame = childFrame->GetNextSibling();
|
2001-02-23 19:10:51 +03:00
|
|
|
}
|
2001-12-18 13:11:42 +03:00
|
|
|
mBoundingMetrics.leftBearing += gap;
|
|
|
|
mBoundingMetrics.rightBearing += gap;
|
|
|
|
mBoundingMetrics.width += gap;
|
|
|
|
aDesiredSize.width += gap;
|
2001-02-23 19:10:51 +03:00
|
|
|
}
|
2001-12-18 13:11:42 +03:00
|
|
|
mBoundingMetrics.width += italicCorrection;
|
|
|
|
aDesiredSize.width += italicCorrection;
|
2001-02-23 19:10:51 +03:00
|
|
|
}
|
2005-09-16 04:39:27 +04:00
|
|
|
return gap;
|
2001-02-23 19:10:51 +03:00
|
|
|
}
|
|
|
|
|
2008-12-11 22:08:35 +03:00
|
|
|
/* static */ void
|
2007-03-02 13:55:55 +03:00
|
|
|
nsMathMLContainerFrame::DidReflowChildren(nsIFrame* aFirst, nsIFrame* aStop)
|
2001-02-02 17:27:38 +03:00
|
|
|
|
2007-03-02 13:55:55 +03:00
|
|
|
{
|
2007-03-04 19:13:15 +03:00
|
|
|
if (NS_UNLIKELY(!aFirst))
|
|
|
|
return;
|
2007-03-02 13:55:55 +03:00
|
|
|
|
|
|
|
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 22:08:35 +03:00
|
|
|
// finish off principal descendants, too
|
|
|
|
nsIFrame* grandchild = frame->GetFirstChild(nsnull);
|
|
|
|
if (grandchild)
|
|
|
|
DidReflowChildren(grandchild, nsnull);
|
|
|
|
|
2007-03-31 01:11:41 +04:00
|
|
|
frame->DidReflow(frame->PresContext(), nsnull,
|
2007-03-02 13:55:55 +03:00
|
|
|
NS_FRAME_REFLOW_FINISHED);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2001-02-02 17:27:38 +03:00
|
|
|
|
2011-03-25 06:38:59 +03: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;
|
|
|
|
PRBool embellishedOpFound = PR_FALSE;
|
|
|
|
nsEmbellishData embellishData;
|
|
|
|
|
|
|
|
for (childFrame = GetFirstChild(nsnull);
|
|
|
|
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;
|
|
|
|
embellishedOpFound = PR_TRUE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
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
|
|
|
|
mPresentationData.baseFrame = nsnull;
|
|
|
|
mEmbellishData.flags = 0;
|
|
|
|
mEmbellishData.coreFrame = nsnull;
|
|
|
|
mEmbellishData.direction = NS_STRETCH_DIRECTION_UNSUPPORTED;
|
|
|
|
mEmbellishData.leftSpace = 0;
|
|
|
|
mEmbellishData.rightSpace = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (childFrame || embellishedOpFound) {
|
|
|
|
// The element is not space-like
|
|
|
|
mPresentationData.flags &= ~NS_MATHML_SPACE_LIKE;
|
|
|
|
}
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2001-02-23 19:10:51 +03:00
|
|
|
//==========================
|
2002-02-01 18:10:50 +03:00
|
|
|
|
2005-11-11 05:36:29 +03:00
|
|
|
nsIFrame*
|
2007-10-12 12:30:54 +04:00
|
|
|
NS_NewMathMLmathBlockFrame(nsIPresShell* aPresShell, nsStyleContext* aContext,
|
|
|
|
PRUint32 aFlags)
|
2001-02-02 17:27:38 +03:00
|
|
|
{
|
2007-10-12 12:30:54 +04:00
|
|
|
nsMathMLmathBlockFrame* it = new (aPresShell) nsMathMLmathBlockFrame(aContext);
|
|
|
|
if (it) {
|
|
|
|
it->SetFlags(aFlags);
|
|
|
|
}
|
|
|
|
return it;
|
2001-02-02 17:27:38 +03:00
|
|
|
}
|
|
|
|
|
2009-09-12 20:49:24 +04:00
|
|
|
NS_IMPL_FRAMEARENA_HELPERS(nsMathMLmathBlockFrame)
|
|
|
|
|
2005-11-11 05:36:29 +03:00
|
|
|
nsIFrame*
|
2006-03-27 01:30:36 +04:00
|
|
|
NS_NewMathMLmathInlineFrame(nsIPresShell* aPresShell, nsStyleContext* aContext)
|
2001-02-02 17:27:38 +03:00
|
|
|
{
|
2006-03-27 01:30:36 +04:00
|
|
|
return new (aPresShell) nsMathMLmathInlineFrame(aContext);
|
2001-02-02 17:27:38 +03:00
|
|
|
}
|
2009-09-12 20:49:24 +04:00
|
|
|
|
|
|
|
NS_IMPL_FRAMEARENA_HELPERS(nsMathMLmathInlineFrame)
|