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
|
|
|
|
2013-08-30 14:37:12 -07:00
|
|
|
#include "nsMathMLTokenFrame.h"
|
2007-03-22 10:30:00 -07:00
|
|
|
#include "nsPresContext.h"
|
|
|
|
#include "nsContentUtils.h"
|
2012-08-30 18:32:02 -07:00
|
|
|
#include "nsTextFrame.h"
|
2013-08-19 15:55:18 -07:00
|
|
|
#include "RestyleManager.h"
|
2013-01-15 04:22:03 -08:00
|
|
|
#include <algorithm>
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
nsIFrame*
|
|
|
|
NS_NewMathMLTokenFrame(nsIPresShell* aPresShell, nsStyleContext* aContext)
|
|
|
|
{
|
|
|
|
return new (aPresShell) nsMathMLTokenFrame(aContext);
|
|
|
|
}
|
2009-09-12 09:49:24 -07:00
|
|
|
|
|
|
|
NS_IMPL_FRAMEARENA_HELPERS(nsMathMLTokenFrame)
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
nsMathMLTokenFrame::~nsMathMLTokenFrame()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2011-05-12 14:37:03 -07:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsMathMLTokenFrame::InheritAutomaticData(nsIFrame* aParent)
|
|
|
|
{
|
|
|
|
// let the base class get the default from our parent
|
|
|
|
nsMathMLContainerFrame::InheritAutomaticData(aParent);
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
eMathMLFrameType
|
|
|
|
nsMathMLTokenFrame::GetMathMLFrameType()
|
|
|
|
{
|
|
|
|
// treat everything other than <mi> as ordinary...
|
|
|
|
if (mContent->Tag() != nsGkAtoms::mi_) {
|
|
|
|
return eMathMLFrameType_Ordinary;
|
|
|
|
}
|
|
|
|
|
2013-12-02 08:50:10 -08:00
|
|
|
uint8_t mathVariant = StyleFont()->mMathVariant;
|
|
|
|
if ((mathVariant == NS_MATHML_MATHVARIANT_NONE &&
|
|
|
|
(StyleFont()->mFont.style == NS_STYLE_FONT_STYLE_ITALIC ||
|
2014-01-15 21:10:09 -08:00
|
|
|
HasAnyStateBits(NS_FRAME_IS_IN_SINGLE_CHAR_MI))) ||
|
2013-12-02 08:50:10 -08:00
|
|
|
mathVariant == NS_MATHML_MATHVARIANT_ITALIC ||
|
|
|
|
mathVariant == NS_MATHML_MATHVARIANT_BOLD_ITALIC ||
|
|
|
|
mathVariant == NS_MATHML_MATHVARIANT_SANS_SERIF_ITALIC ||
|
|
|
|
mathVariant == NS_MATHML_MATHVARIANT_SANS_SERIF_BOLD_ITALIC) {
|
2008-03-15 19:10:47 -07:00
|
|
|
return eMathMLFrameType_ItalicIdentifier;
|
|
|
|
}
|
|
|
|
return eMathMLFrameType_UprightIdentifier;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2012-08-30 18:32:02 -07:00
|
|
|
void
|
2013-09-30 08:55:51 -07:00
|
|
|
nsMathMLTokenFrame::MarkTextFramesAsTokenMathML()
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2013-12-02 08:50:10 -08:00
|
|
|
nsIFrame* child = nullptr;
|
|
|
|
uint32_t childCount = 0;
|
|
|
|
|
|
|
|
// Set flags on child text frames
|
|
|
|
// - to force them to trim their leading and trailing whitespaces.
|
|
|
|
// - Indicate which frames are suitable for mathvariant
|
|
|
|
// - flag single character <mi> frames for special italic treatment
|
2012-08-30 18:32:02 -07:00
|
|
|
for (nsIFrame* childFrame = GetFirstPrincipalChild(); childFrame;
|
|
|
|
childFrame = childFrame->GetNextSibling()) {
|
2013-09-30 08:55:51 -07:00
|
|
|
for (nsIFrame* childFrame2 = childFrame->GetFirstPrincipalChild();
|
|
|
|
childFrame2; childFrame2 = childFrame2->GetNextSibling()) {
|
|
|
|
if (childFrame2->GetType() == nsGkAtoms::textFrame) {
|
|
|
|
childFrame2->AddStateBits(TEXT_IS_IN_TOKEN_MATHML);
|
2013-12-02 08:50:10 -08:00
|
|
|
child = childFrame2;
|
|
|
|
childCount++;
|
2013-09-30 08:55:51 -07:00
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
}
|
2013-12-02 08:50:10 -08:00
|
|
|
if (mContent->Tag() == nsGkAtoms::mi_ && childCount == 1) {
|
|
|
|
nsAutoString data;
|
|
|
|
nsContentUtils::GetNodeTextContent(mContent, false, data);
|
|
|
|
data.CompressWhitespace();
|
|
|
|
int32_t length = data.Length();
|
|
|
|
|
|
|
|
bool isSingleCharacter = length == 1 ||
|
|
|
|
(length == 2 && NS_IS_HIGH_SURROGATE(data[0]));
|
|
|
|
|
|
|
|
if (isSingleCharacter) {
|
2014-01-15 21:10:09 -08:00
|
|
|
child->AddStateBits(NS_FRAME_IS_IN_SINGLE_CHAR_MI);
|
2013-12-02 08:50:10 -08:00
|
|
|
}
|
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2014-02-17 23:47:48 -08:00
|
|
|
nsresult
|
2011-08-24 13:54:30 -07:00
|
|
|
nsMathMLTokenFrame::SetInitialChildList(ChildListID aListID,
|
2009-07-28 05:53:20 -07:00
|
|
|
nsFrameList& aChildList)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
|
|
|
// First, let the base class do its work
|
2011-08-24 13:54:30 -07:00
|
|
|
nsresult rv = nsMathMLContainerFrame::SetInitialChildList(aListID, aChildList);
|
2007-03-22 10:30:00 -07:00
|
|
|
if (NS_FAILED(rv))
|
|
|
|
return rv;
|
|
|
|
|
2013-09-30 08:55:51 -07:00
|
|
|
MarkTextFramesAsTokenMathML();
|
2012-08-30 18:32:02 -07:00
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
2014-02-17 23:47:48 -08:00
|
|
|
nsresult
|
2012-08-30 18:32:02 -07:00
|
|
|
nsMathMLTokenFrame::AppendFrames(ChildListID aListID,
|
|
|
|
nsFrameList& aChildList)
|
|
|
|
{
|
|
|
|
nsresult rv = nsMathMLContainerFrame::AppendFrames(aListID, aChildList);
|
|
|
|
if (NS_FAILED(rv))
|
|
|
|
return rv;
|
|
|
|
|
2013-09-30 08:55:51 -07:00
|
|
|
MarkTextFramesAsTokenMathML();
|
2012-08-30 18:32:02 -07:00
|
|
|
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
2014-02-17 23:47:48 -08:00
|
|
|
nsresult
|
2012-08-30 18:32:02 -07:00
|
|
|
nsMathMLTokenFrame::InsertFrames(ChildListID aListID,
|
|
|
|
nsIFrame* aPrevFrame,
|
|
|
|
nsFrameList& aChildList)
|
|
|
|
{
|
|
|
|
nsresult rv = nsMathMLContainerFrame::InsertFrames(aListID, aPrevFrame,
|
|
|
|
aChildList);
|
|
|
|
if (NS_FAILED(rv))
|
|
|
|
return rv;
|
|
|
|
|
2013-09-30 08:55:51 -07:00
|
|
|
MarkTextFramesAsTokenMathML();
|
2012-08-30 18:32:02 -07:00
|
|
|
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
nsresult
|
|
|
|
nsMathMLTokenFrame::Reflow(nsPresContext* aPresContext,
|
|
|
|
nsHTMLReflowMetrics& aDesiredSize,
|
|
|
|
const nsHTMLReflowState& aReflowState,
|
|
|
|
nsReflowStatus& aStatus)
|
|
|
|
{
|
|
|
|
nsresult rv = NS_OK;
|
|
|
|
|
|
|
|
// initializations needed for empty markup like <mtag></mtag>
|
2013-12-27 09:59:52 -08:00
|
|
|
aDesiredSize.Width() = aDesiredSize.Height() = 0;
|
|
|
|
aDesiredSize.SetTopAscent(0);
|
2011-04-07 18:04:40 -07:00
|
|
|
aDesiredSize.mBoundingMetrics = nsBoundingMetrics();
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2008-01-14 17:13:21 -08:00
|
|
|
nsSize availSize(aReflowState.ComputedWidth(), NS_UNCONSTRAINEDSIZE);
|
2011-08-24 13:54:30 -07:00
|
|
|
nsIFrame* childFrame = GetFirstPrincipalChild();
|
2007-03-22 10:30:00 -07:00
|
|
|
while (childFrame) {
|
2007-12-02 16:54:23 -08:00
|
|
|
// ask our children to compute their bounding metrics
|
2013-12-27 09:59:52 -08:00
|
|
|
nsHTMLReflowMetrics childDesiredSize(aReflowState.GetWritingMode(),
|
|
|
|
aDesiredSize.mFlags
|
2007-12-02 16:54:23 -08:00
|
|
|
| NS_REFLOW_CALC_BOUNDING_METRICS);
|
2007-03-22 10:30:00 -07:00
|
|
|
nsHTMLReflowState childReflowState(aPresContext, aReflowState,
|
|
|
|
childFrame, availSize);
|
|
|
|
rv = ReflowChild(childFrame, aPresContext, childDesiredSize,
|
|
|
|
childReflowState, aStatus);
|
|
|
|
//NS_ASSERTION(NS_FRAME_IS_COMPLETE(aStatus), "bad status");
|
|
|
|
if (NS_FAILED(rv)) {
|
|
|
|
// Call DidReflow() for the child frames we successfully did reflow.
|
2011-08-24 13:54:30 -07:00
|
|
|
DidReflowChildren(GetFirstPrincipalChild(), childFrame);
|
2007-03-22 10:30:00 -07:00
|
|
|
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();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// place and size children
|
|
|
|
FinalizeReflow(*aReflowState.rendContext, aDesiredSize);
|
|
|
|
|
|
|
|
aStatus = NS_FRAME_COMPLETE;
|
|
|
|
NS_FRAME_SET_TRUNCATION(aStatus, aReflowState, aDesiredSize);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
// For token elements, mBoundingMetrics is computed at the ReflowToken
|
|
|
|
// pass, it is not computed here because our children may be text frames
|
|
|
|
// that do not implement the GetBoundingMetrics() interface.
|
2008-03-17 21:52:48 -07:00
|
|
|
/* virtual */ nsresult
|
2011-04-07 18:04:40 -07:00
|
|
|
nsMathMLTokenFrame::Place(nsRenderingContext& aRenderingContext,
|
2011-09-28 23:19:26 -07:00
|
|
|
bool aPlaceOrigin,
|
2007-03-22 10:30:00 -07:00
|
|
|
nsHTMLReflowMetrics& aDesiredSize)
|
|
|
|
{
|
2011-04-07 18:04:40 -07:00
|
|
|
mBoundingMetrics = nsBoundingMetrics();
|
2011-08-24 13:54:30 -07:00
|
|
|
for (nsIFrame* childFrame = GetFirstPrincipalChild(); childFrame;
|
2009-02-19 09:48:37 -08:00
|
|
|
childFrame = childFrame->GetNextSibling()) {
|
2013-12-27 09:59:52 -08:00
|
|
|
nsHTMLReflowMetrics childSize(aDesiredSize.GetWritingMode());
|
2008-02-27 02:45:36 -08:00
|
|
|
GetReflowAndBoundingMetricsFor(childFrame, childSize,
|
2012-07-30 07:20:58 -07:00
|
|
|
childSize.mBoundingMetrics, nullptr);
|
2008-02-27 02:45:36 -08:00
|
|
|
// compute and cache the bounding metrics
|
|
|
|
mBoundingMetrics += childSize.mBoundingMetrics;
|
|
|
|
}
|
|
|
|
|
2011-08-14 10:08:04 -07:00
|
|
|
nsRefPtr<nsFontMetrics> fm;
|
|
|
|
nsLayoutUtils::GetFontMetricsForFrame(this, getter_AddRefs(fm));
|
2011-04-07 21:18:43 -07:00
|
|
|
nscoord ascent = fm->MaxAscent();
|
|
|
|
nscoord descent = fm->MaxDescent();
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
aDesiredSize.mBoundingMetrics = mBoundingMetrics;
|
2013-12-27 09:59:52 -08:00
|
|
|
aDesiredSize.Width() = mBoundingMetrics.width;
|
|
|
|
aDesiredSize.SetTopAscent(std::max(mBoundingMetrics.ascent, ascent));
|
|
|
|
aDesiredSize.Height() = aDesiredSize.TopAscent() +
|
2013-01-15 04:22:03 -08:00
|
|
|
std::max(mBoundingMetrics.descent, descent);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
if (aPlaceOrigin) {
|
|
|
|
nscoord dy, dx = 0;
|
2011-08-24 13:54:30 -07:00
|
|
|
for (nsIFrame* childFrame = GetFirstPrincipalChild(); childFrame;
|
2009-02-19 09:48:37 -08:00
|
|
|
childFrame = childFrame->GetNextSibling()) {
|
2013-12-27 09:59:52 -08:00
|
|
|
nsHTMLReflowMetrics childSize(aDesiredSize.GetWritingMode());
|
2008-02-25 20:19:36 -08:00
|
|
|
GetReflowAndBoundingMetricsFor(childFrame, childSize,
|
|
|
|
childSize.mBoundingMetrics);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
// place and size the child; (dx,0) makes the caret happy - bug 188146
|
2013-12-27 09:59:52 -08:00
|
|
|
dy = childSize.Height() == 0 ? 0 : aDesiredSize.TopAscent() - childSize.TopAscent();
|
2014-01-16 17:34:44 -08:00
|
|
|
FinishReflowChild(childFrame, PresContext(), childSize, nullptr, dx, dy, 0);
|
2013-12-27 09:59:52 -08:00
|
|
|
dx += childSize.Width();
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-12-27 09:59:52 -08:00
|
|
|
SetReference(nsPoint(0, aDesiredSize.TopAscent()));
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|