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
|
|
|
|
2014-07-24 01:28:46 -07:00
|
|
|
using namespace mozilla;
|
|
|
|
|
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...
|
2015-03-03 03:09:00 -08:00
|
|
|
if (!mContent->IsMathMLElement(nsGkAtoms::mi_)) {
|
2007-03-22 10:30:00 -07:00
|
|
|
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
|
2016-01-29 06:42:14 -08:00
|
|
|
for (nsIFrame* childFrame = PrincipalChildList().FirstChild(); childFrame;
|
2012-08-30 18:32:02 -07:00
|
|
|
childFrame = childFrame->GetNextSibling()) {
|
2016-01-29 06:42:14 -08:00
|
|
|
for (nsIFrame* childFrame2 = childFrame->PrincipalChildList().FirstChild();
|
2013-09-30 08:55:51 -07:00
|
|
|
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
|
|
|
}
|
|
|
|
}
|
2015-03-03 03:09:00 -08:00
|
|
|
if (mContent->IsMathMLElement(nsGkAtoms::mi_) && childCount == 1) {
|
2013-12-02 08:50:10 -08:00
|
|
|
nsAutoString data;
|
2015-05-22 11:16:20 -07:00
|
|
|
nsContentUtils::GetNodeTextContent(mContent, false, data);
|
2014-03-20 12:51:16 -07:00
|
|
|
|
2013-12-02 08:50:10 -08:00
|
|
|
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);
|
2014-03-21 05:49:51 -07:00
|
|
|
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-05-28 12:36:58 -07:00
|
|
|
void
|
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
|
2014-05-28 12:36:58 -07:00
|
|
|
nsMathMLContainerFrame::SetInitialChildList(aListID, aChildList);
|
2013-09-30 08:55:51 -07:00
|
|
|
MarkTextFramesAsTokenMathML();
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2014-05-28 12:36:58 -07:00
|
|
|
void
|
2012-08-30 18:32:02 -07:00
|
|
|
nsMathMLTokenFrame::AppendFrames(ChildListID aListID,
|
|
|
|
nsFrameList& aChildList)
|
|
|
|
{
|
2014-05-28 12:36:58 -07:00
|
|
|
nsMathMLContainerFrame::AppendFrames(aListID, aChildList);
|
2013-09-30 08:55:51 -07:00
|
|
|
MarkTextFramesAsTokenMathML();
|
2012-08-30 18:32:02 -07:00
|
|
|
}
|
|
|
|
|
2014-05-28 12:36:58 -07:00
|
|
|
void
|
2012-08-30 18:32:02 -07:00
|
|
|
nsMathMLTokenFrame::InsertFrames(ChildListID aListID,
|
|
|
|
nsIFrame* aPrevFrame,
|
|
|
|
nsFrameList& aChildList)
|
|
|
|
{
|
2014-05-28 12:36:58 -07:00
|
|
|
nsMathMLContainerFrame::InsertFrames(aListID, aPrevFrame, aChildList);
|
2013-09-30 08:55:51 -07:00
|
|
|
MarkTextFramesAsTokenMathML();
|
2012-08-30 18:32:02 -07:00
|
|
|
}
|
|
|
|
|
2014-05-12 17:47:52 -07:00
|
|
|
void
|
2007-03-22 10:30:00 -07:00
|
|
|
nsMathMLTokenFrame::Reflow(nsPresContext* aPresContext,
|
|
|
|
nsHTMLReflowMetrics& aDesiredSize,
|
|
|
|
const nsHTMLReflowState& aReflowState,
|
|
|
|
nsReflowStatus& aStatus)
|
|
|
|
{
|
2015-03-29 15:38:40 -07:00
|
|
|
MarkInReflow();
|
2015-03-29 15:38:39 -07:00
|
|
|
mPresentationData.flags &= ~NS_MATHML_ERROR;
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
// initializations needed for empty markup like <mtag></mtag>
|
2014-07-24 01:30:07 -07:00
|
|
|
aDesiredSize.ClearSize();
|
2014-06-11 02:45:31 -07:00
|
|
|
aDesiredSize.SetBlockStartAscent(0);
|
2011-04-07 18:04:40 -07:00
|
|
|
aDesiredSize.mBoundingMetrics = nsBoundingMetrics();
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2016-01-29 06:42:15 -08:00
|
|
|
for (nsIFrame* childFrame : PrincipalChildList()) {
|
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);
|
2014-07-24 01:28:46 -07:00
|
|
|
WritingMode wm = childFrame->GetWritingMode();
|
|
|
|
LogicalSize availSize = aReflowState.ComputedSize(wm);
|
|
|
|
availSize.BSize(wm) = NS_UNCONSTRAINEDSIZE;
|
2007-03-22 10:30:00 -07:00
|
|
|
nsHTMLReflowState childReflowState(aPresContext, aReflowState,
|
|
|
|
childFrame, availSize);
|
2014-05-12 17:47:52 -07:00
|
|
|
ReflowChild(childFrame, aPresContext, childDesiredSize,
|
|
|
|
childReflowState, aStatus);
|
2007-03-22 10:30:00 -07:00
|
|
|
//NS_ASSERTION(NS_FRAME_IS_COMPLETE(aStatus), "bad status");
|
2008-02-25 20:19:36 -08:00
|
|
|
SaveReflowAndBoundingMetricsFor(childFrame, childDesiredSize,
|
|
|
|
childDesiredSize.mBoundingMetrics);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
// place and size children
|
2015-12-15 13:56:41 -08:00
|
|
|
FinalizeReflow(aReflowState.rendContext->GetDrawTarget(), aDesiredSize);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
aStatus = NS_FRAME_COMPLETE;
|
|
|
|
NS_FRAME_SET_TRUNCATION(aStatus, aReflowState, aDesiredSize);
|
|
|
|
}
|
|
|
|
|
|
|
|
// 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
|
2015-12-15 13:56:41 -08:00
|
|
|
nsMathMLTokenFrame::Place(DrawTarget* aDrawTarget,
|
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();
|
2016-01-29 06:42:15 -08:00
|
|
|
for (nsIFrame* childFrame :PrincipalChildList()) {
|
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;
|
|
|
|
}
|
|
|
|
|
2015-10-17 22:24:48 -07:00
|
|
|
RefPtr<nsFontMetrics> fm;
|
2014-10-24 23:29:00 -07:00
|
|
|
nsLayoutUtils::GetFontMetricsForFrame(this, getter_AddRefs(fm),
|
|
|
|
nsLayoutUtils::
|
|
|
|
FontSizeInflationFor(this));
|
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;
|
2014-06-11 02:45:31 -07:00
|
|
|
aDesiredSize.SetBlockStartAscent(std::max(mBoundingMetrics.ascent, ascent));
|
|
|
|
aDesiredSize.Height() = aDesiredSize.BlockStartAscent() +
|
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;
|
2016-01-29 06:42:15 -08:00
|
|
|
for (nsIFrame* childFrame : PrincipalChildList()) {
|
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
|
2014-06-11 02:45:31 -07:00
|
|
|
dy = childSize.Height() == 0 ? 0 : aDesiredSize.BlockStartAscent() - childSize.BlockStartAscent();
|
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
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-06-11 02:45:31 -07:00
|
|
|
SetReference(nsPoint(0, aDesiredSize.BlockStartAscent()));
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|