2004-02-24 00:29:06 +03:00
|
|
|
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
2012-05-21 15:12:37 +04: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/. */
|
2002-08-17 01:36:31 +04:00
|
|
|
|
2013-08-31 01:37:12 +04:00
|
|
|
#include "nsMathMLTokenFrame.h"
|
2004-08-01 03:15:21 +04:00
|
|
|
#include "nsPresContext.h"
|
2006-09-15 23:54:45 +04:00
|
|
|
#include "nsContentUtils.h"
|
2012-08-31 05:32:02 +04:00
|
|
|
#include "nsTextFrame.h"
|
2017-02-13 06:21:30 +03:00
|
|
|
#include "mozilla/GeckoRestyleManager.h"
|
2013-01-15 16:22:03 +04:00
|
|
|
#include <algorithm>
|
2002-08-17 01:36:31 +04:00
|
|
|
|
2014-07-24 12:28:46 +04:00
|
|
|
using namespace mozilla;
|
|
|
|
|
2005-11-11 05:36:29 +03:00
|
|
|
nsIFrame*
|
2006-03-27 01:30:36 +04:00
|
|
|
NS_NewMathMLTokenFrame(nsIPresShell* aPresShell, nsStyleContext* aContext)
|
2002-08-17 01:36:31 +04:00
|
|
|
{
|
2006-03-27 01:30:36 +04:00
|
|
|
return new (aPresShell) nsMathMLTokenFrame(aContext);
|
2002-08-17 01:36:31 +04:00
|
|
|
}
|
2009-09-12 20:49:24 +04:00
|
|
|
|
|
|
|
NS_IMPL_FRAMEARENA_HELPERS(nsMathMLTokenFrame)
|
|
|
|
|
2002-08-17 01:36:31 +04:00
|
|
|
nsMathMLTokenFrame::~nsMathMLTokenFrame()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2011-05-13 01:37:03 +04:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsMathMLTokenFrame::InheritAutomaticData(nsIFrame* aParent)
|
|
|
|
{
|
|
|
|
// let the base class get the default from our parent
|
|
|
|
nsMathMLContainerFrame::InheritAutomaticData(aParent);
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2006-08-15 08:49:43 +04:00
|
|
|
eMathMLFrameType
|
|
|
|
nsMathMLTokenFrame::GetMathMLFrameType()
|
2002-08-17 01:36:31 +04:00
|
|
|
{
|
2005-09-07 03:47:01 +04:00
|
|
|
// treat everything other than <mi> as ordinary...
|
2015-03-03 14:09:00 +03:00
|
|
|
if (!mContent->IsMathMLElement(nsGkAtoms::mi_)) {
|
2006-08-15 08:49:43 +04:00
|
|
|
return eMathMLFrameType_Ordinary;
|
2005-09-07 03:47:01 +04:00
|
|
|
}
|
|
|
|
|
2013-12-02 20:50:10 +04:00
|
|
|
uint8_t mathVariant = StyleFont()->mMathVariant;
|
|
|
|
if ((mathVariant == NS_MATHML_MATHVARIANT_NONE &&
|
|
|
|
(StyleFont()->mFont.style == NS_STYLE_FONT_STYLE_ITALIC ||
|
2014-01-16 09:10:09 +04:00
|
|
|
HasAnyStateBits(NS_FRAME_IS_IN_SINGLE_CHAR_MI))) ||
|
2013-12-02 20:50:10 +04: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-16 05:10:47 +03:00
|
|
|
return eMathMLFrameType_ItalicIdentifier;
|
|
|
|
}
|
|
|
|
return eMathMLFrameType_UprightIdentifier;
|
2002-08-17 01:36:31 +04:00
|
|
|
}
|
|
|
|
|
2012-08-31 05:32:02 +04:00
|
|
|
void
|
2013-09-30 19:55:51 +04:00
|
|
|
nsMathMLTokenFrame::MarkTextFramesAsTokenMathML()
|
2002-08-17 01:36:31 +04:00
|
|
|
{
|
2013-12-02 20:50:10 +04: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 17:42:14 +03:00
|
|
|
for (nsIFrame* childFrame = PrincipalChildList().FirstChild(); childFrame;
|
2012-08-31 05:32:02 +04:00
|
|
|
childFrame = childFrame->GetNextSibling()) {
|
2016-01-29 17:42:14 +03:00
|
|
|
for (nsIFrame* childFrame2 = childFrame->PrincipalChildList().FirstChild();
|
2013-09-30 19:55:51 +04:00
|
|
|
childFrame2; childFrame2 = childFrame2->GetNextSibling()) {
|
2017-04-30 18:30:08 +03:00
|
|
|
if (childFrame2->IsTextFrame()) {
|
2013-09-30 19:55:51 +04:00
|
|
|
childFrame2->AddStateBits(TEXT_IS_IN_TOKEN_MATHML);
|
2013-12-02 20:50:10 +04:00
|
|
|
child = childFrame2;
|
|
|
|
childCount++;
|
2013-09-30 19:55:51 +04:00
|
|
|
}
|
2002-08-17 01:36:31 +04:00
|
|
|
}
|
|
|
|
}
|
2015-03-03 14:09:00 +03:00
|
|
|
if (mContent->IsMathMLElement(nsGkAtoms::mi_) && childCount == 1) {
|
2013-12-02 20:50:10 +04:00
|
|
|
nsAutoString data;
|
2015-05-22 21:16:20 +03:00
|
|
|
nsContentUtils::GetNodeTextContent(mContent, false, data);
|
2014-03-20 23:51:16 +04:00
|
|
|
|
2013-12-02 20:50:10 +04:00
|
|
|
data.CompressWhitespace();
|
|
|
|
int32_t length = data.Length();
|
|
|
|
|
|
|
|
bool isSingleCharacter = length == 1 ||
|
|
|
|
(length == 2 && NS_IS_HIGH_SURROGATE(data[0]));
|
|
|
|
|
|
|
|
if (isSingleCharacter) {
|
2014-01-16 09:10:09 +04:00
|
|
|
child->AddStateBits(NS_FRAME_IS_IN_SINGLE_CHAR_MI);
|
2014-03-21 16:49:51 +04:00
|
|
|
AddStateBits(NS_FRAME_IS_IN_SINGLE_CHAR_MI);
|
2013-12-02 20:50:10 +04:00
|
|
|
}
|
|
|
|
}
|
2002-08-17 01:36:31 +04:00
|
|
|
}
|
|
|
|
|
2014-05-28 23:36:58 +04:00
|
|
|
void
|
2011-08-25 00:54:30 +04:00
|
|
|
nsMathMLTokenFrame::SetInitialChildList(ChildListID aListID,
|
2009-07-28 16:53:20 +04:00
|
|
|
nsFrameList& aChildList)
|
2002-08-17 01:36:31 +04:00
|
|
|
{
|
|
|
|
// First, let the base class do its work
|
2014-05-28 23:36:58 +04:00
|
|
|
nsMathMLContainerFrame::SetInitialChildList(aListID, aChildList);
|
2013-09-30 19:55:51 +04:00
|
|
|
MarkTextFramesAsTokenMathML();
|
2002-08-17 01:36:31 +04:00
|
|
|
}
|
|
|
|
|
2014-05-28 23:36:58 +04:00
|
|
|
void
|
2012-08-31 05:32:02 +04:00
|
|
|
nsMathMLTokenFrame::AppendFrames(ChildListID aListID,
|
|
|
|
nsFrameList& aChildList)
|
|
|
|
{
|
2014-05-28 23:36:58 +04:00
|
|
|
nsMathMLContainerFrame::AppendFrames(aListID, aChildList);
|
2013-09-30 19:55:51 +04:00
|
|
|
MarkTextFramesAsTokenMathML();
|
2012-08-31 05:32:02 +04:00
|
|
|
}
|
|
|
|
|
2014-05-28 23:36:58 +04:00
|
|
|
void
|
2012-08-31 05:32:02 +04:00
|
|
|
nsMathMLTokenFrame::InsertFrames(ChildListID aListID,
|
|
|
|
nsIFrame* aPrevFrame,
|
|
|
|
nsFrameList& aChildList)
|
|
|
|
{
|
2014-05-28 23:36:58 +04:00
|
|
|
nsMathMLContainerFrame::InsertFrames(aListID, aPrevFrame, aChildList);
|
2013-09-30 19:55:51 +04:00
|
|
|
MarkTextFramesAsTokenMathML();
|
2012-08-31 05:32:02 +04:00
|
|
|
}
|
|
|
|
|
2014-05-13 04:47:52 +04:00
|
|
|
void
|
2004-08-01 03:15:21 +04:00
|
|
|
nsMathMLTokenFrame::Reflow(nsPresContext* aPresContext,
|
2016-07-21 13:36:38 +03:00
|
|
|
ReflowOutput& aDesiredSize,
|
2016-07-21 13:36:39 +03:00
|
|
|
const ReflowInput& aReflowInput,
|
2002-08-17 01:36:31 +04:00
|
|
|
nsReflowStatus& aStatus)
|
|
|
|
{
|
2015-03-30 01:38:40 +03:00
|
|
|
MarkInReflow();
|
2015-03-30 01:38:39 +03:00
|
|
|
mPresentationData.flags &= ~NS_MATHML_ERROR;
|
|
|
|
|
2002-08-17 01:36:31 +04:00
|
|
|
// initializations needed for empty markup like <mtag></mtag>
|
2014-07-24 12:30:07 +04:00
|
|
|
aDesiredSize.ClearSize();
|
2014-06-11 13:45:31 +04:00
|
|
|
aDesiredSize.SetBlockStartAscent(0);
|
2011-04-08 05:04:40 +04:00
|
|
|
aDesiredSize.mBoundingMetrics = nsBoundingMetrics();
|
2002-08-17 01:36:31 +04:00
|
|
|
|
2016-01-29 17:42:15 +03:00
|
|
|
for (nsIFrame* childFrame : PrincipalChildList()) {
|
2007-12-03 03:54:23 +03:00
|
|
|
// ask our children to compute their bounding metrics
|
2016-07-21 13:36:39 +03:00
|
|
|
ReflowOutput childDesiredSize(aReflowInput.GetWritingMode(),
|
2013-12-27 21:59:52 +04:00
|
|
|
aDesiredSize.mFlags
|
2007-12-03 03:54:23 +03:00
|
|
|
| NS_REFLOW_CALC_BOUNDING_METRICS);
|
2014-07-24 12:28:46 +04:00
|
|
|
WritingMode wm = childFrame->GetWritingMode();
|
2016-07-21 13:36:39 +03:00
|
|
|
LogicalSize availSize = aReflowInput.ComputedSize(wm);
|
2014-07-24 12:28:46 +04:00
|
|
|
availSize.BSize(wm) = NS_UNCONSTRAINEDSIZE;
|
2016-07-21 13:36:39 +03:00
|
|
|
ReflowInput childReflowInput(aPresContext, aReflowInput,
|
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);
|
2014-05-13 04:47:52 +04:00
|
|
|
ReflowChild(childFrame, aPresContext, childDesiredSize,
|
2016-07-21 13:36:39 +03:00
|
|
|
childReflowInput, aStatus);
|
2017-02-11 17:45:07 +03:00
|
|
|
//NS_ASSERTION(aStatus.IsComplete(), "bad status");
|
2008-02-26 07:19:36 +03:00
|
|
|
SaveReflowAndBoundingMetricsFor(childFrame, childDesiredSize,
|
|
|
|
childDesiredSize.mBoundingMetrics);
|
2002-08-17 01:36:31 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
// place and size children
|
2016-07-21 13:36:39 +03:00
|
|
|
FinalizeReflow(aReflowInput.mRenderingContext->GetDrawTarget(), aDesiredSize);
|
2006-05-01 00:34:46 +04:00
|
|
|
|
2017-02-14 12:55:48 +03:00
|
|
|
aStatus.Reset();
|
2016-07-21 13:36:39 +03:00
|
|
|
NS_FRAME_SET_TRUNCATION(aStatus, aReflowInput, aDesiredSize);
|
2002-08-17 01:36:31 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
// 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-18 07:52:48 +03:00
|
|
|
/* virtual */ nsresult
|
2015-12-16 00:56:41 +03:00
|
|
|
nsMathMLTokenFrame::Place(DrawTarget* aDrawTarget,
|
2011-09-29 10:19:26 +04:00
|
|
|
bool aPlaceOrigin,
|
2016-07-21 13:36:38 +03:00
|
|
|
ReflowOutput& aDesiredSize)
|
2002-08-17 01:36:31 +04:00
|
|
|
{
|
2011-04-08 05:04:40 +04:00
|
|
|
mBoundingMetrics = nsBoundingMetrics();
|
2016-01-29 17:42:15 +03:00
|
|
|
for (nsIFrame* childFrame :PrincipalChildList()) {
|
2016-07-21 13:36:38 +03:00
|
|
|
ReflowOutput childSize(aDesiredSize.GetWritingMode());
|
2008-02-27 13:45:36 +03:00
|
|
|
GetReflowAndBoundingMetricsFor(childFrame, childSize,
|
2012-07-30 18:20:58 +04:00
|
|
|
childSize.mBoundingMetrics, nullptr);
|
2008-02-27 13:45:36 +03:00
|
|
|
// compute and cache the bounding metrics
|
|
|
|
mBoundingMetrics += childSize.mBoundingMetrics;
|
|
|
|
}
|
|
|
|
|
2016-03-17 08:55:48 +03:00
|
|
|
RefPtr<nsFontMetrics> fm =
|
|
|
|
nsLayoutUtils::GetInflatedFontMetricsForFrame(this);
|
2011-04-08 08:18:43 +04:00
|
|
|
nscoord ascent = fm->MaxAscent();
|
|
|
|
nscoord descent = fm->MaxDescent();
|
2002-08-17 01:36:31 +04:00
|
|
|
|
|
|
|
aDesiredSize.mBoundingMetrics = mBoundingMetrics;
|
2013-12-27 21:59:52 +04:00
|
|
|
aDesiredSize.Width() = mBoundingMetrics.width;
|
2014-06-11 13:45:31 +04:00
|
|
|
aDesiredSize.SetBlockStartAscent(std::max(mBoundingMetrics.ascent, ascent));
|
|
|
|
aDesiredSize.Height() = aDesiredSize.BlockStartAscent() +
|
2013-01-15 16:22:03 +04:00
|
|
|
std::max(mBoundingMetrics.descent, descent);
|
2002-08-17 01:36:31 +04:00
|
|
|
|
|
|
|
if (aPlaceOrigin) {
|
|
|
|
nscoord dy, dx = 0;
|
2016-01-29 17:42:15 +03:00
|
|
|
for (nsIFrame* childFrame : PrincipalChildList()) {
|
2016-07-21 13:36:38 +03:00
|
|
|
ReflowOutput childSize(aDesiredSize.GetWritingMode());
|
2008-02-26 07:19:36 +03:00
|
|
|
GetReflowAndBoundingMetricsFor(childFrame, childSize,
|
|
|
|
childSize.mBoundingMetrics);
|
2002-08-17 01:36:31 +04:00
|
|
|
|
2003-01-16 08:10:03 +03:00
|
|
|
// place and size the child; (dx,0) makes the caret happy - bug 188146
|
2014-06-11 13:45:31 +04:00
|
|
|
dy = childSize.Height() == 0 ? 0 : aDesiredSize.BlockStartAscent() - childSize.BlockStartAscent();
|
2014-01-17 05:34:44 +04:00
|
|
|
FinishReflowChild(childFrame, PresContext(), childSize, nullptr, dx, dy, 0);
|
2013-12-27 21:59:52 +04:00
|
|
|
dx += childSize.Width();
|
2002-08-17 01:36:31 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-06-11 13:45:31 +04:00
|
|
|
SetReference(nsPoint(0, aDesiredSize.BlockStartAscent()));
|
2002-08-17 01:36:31 +04:00
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|