2004-02-24 00:29:06 +03:00
|
|
|
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
2004-08-26 03:02:50 +04:00
|
|
|
/* ***** BEGIN LICENSE BLOCK *****
|
|
|
|
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
|
2002-08-17 01:36:31 +04:00
|
|
|
*
|
2004-08-26 03:02:50 +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.
|
2002-08-17 01:36:31 +04:00
|
|
|
*
|
|
|
|
* The Original Code is Mozilla MathML Project.
|
|
|
|
*
|
2004-08-26 03:02:50 +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.
|
2002-08-17 01:36:31 +04:00
|
|
|
*
|
|
|
|
* Contributor(s):
|
|
|
|
* Roger B. Sidje <rbs@maths.uq.edu.au>
|
2008-03-16 05:10:47 +03:00
|
|
|
* Karl Tomlinson <karlt+@karlt.net>, Mozilla Corporation
|
2004-08-26 03:02:50 +04:00
|
|
|
*
|
|
|
|
* Alternatively, the contents of this file may be used under the terms of
|
|
|
|
* either 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 ***** */
|
2002-08-17 01:36:31 +04:00
|
|
|
|
|
|
|
#include "nsCOMPtr.h"
|
|
|
|
#include "nsFrame.h"
|
2004-08-01 03:15:21 +04:00
|
|
|
#include "nsPresContext.h"
|
2003-02-22 03:32:13 +03:00
|
|
|
#include "nsStyleContext.h"
|
2002-08-17 01:36:31 +04:00
|
|
|
#include "nsStyleConsts.h"
|
2006-09-15 23:54:45 +04:00
|
|
|
#include "nsContentUtils.h"
|
2007-04-09 07:43:44 +04:00
|
|
|
#include "nsCSSFrameConstructor.h"
|
2002-08-17 01:36:31 +04:00
|
|
|
#include "nsMathMLTokenFrame.h"
|
|
|
|
|
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);
|
|
|
|
|
|
|
|
ProcessTextData();
|
|
|
|
|
|
|
|
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...
|
2006-12-26 20:47:52 +03:00
|
|
|
if (mContent->Tag() != nsGkAtoms::mi_) {
|
2006-08-15 08:49:43 +04:00
|
|
|
return eMathMLFrameType_Ordinary;
|
2005-09-07 03:47:01 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
// for <mi>, distinguish between italic and upright...
|
2008-03-16 05:10:47 +03:00
|
|
|
nsAutoString style;
|
|
|
|
// mathvariant overrides fontstyle
|
|
|
|
// http://www.w3.org/TR/2003/REC-MathML2-20031021/chapter3.html#presm.deprecatt
|
2010-03-10 15:49:33 +03:00
|
|
|
mContent->GetAttr(kNameSpaceID_None,
|
|
|
|
nsGkAtoms::_moz_math_fontstyle_, style) ||
|
2011-05-13 01:37:03 +04:00
|
|
|
GetAttribute(mContent, mPresentationData.mstyle, nsGkAtoms::mathvariant_,
|
|
|
|
style) ||
|
|
|
|
GetAttribute(mContent, mPresentationData.mstyle, nsGkAtoms::fontstyle_,
|
|
|
|
style);
|
2008-03-16 05:10:47 +03:00
|
|
|
|
|
|
|
if (style.EqualsLiteral("italic") || style.EqualsLiteral("bold-italic") ||
|
|
|
|
style.EqualsLiteral("script") || style.EqualsLiteral("bold-script") ||
|
|
|
|
style.EqualsLiteral("sans-serif-italic") ||
|
|
|
|
style.EqualsLiteral("sans-serif-bold-italic")) {
|
|
|
|
return eMathMLFrameType_ItalicIdentifier;
|
|
|
|
}
|
|
|
|
else if(style.EqualsLiteral("invariant")) {
|
|
|
|
nsAutoString data;
|
|
|
|
nsContentUtils::GetNodeTextContent(mContent, PR_FALSE, data);
|
|
|
|
eMATHVARIANT variant = nsMathMLOperators::LookupInvariantChar(data);
|
|
|
|
|
|
|
|
switch (variant) {
|
|
|
|
case eMATHVARIANT_italic:
|
|
|
|
case eMATHVARIANT_bold_italic:
|
|
|
|
case eMATHVARIANT_script:
|
|
|
|
case eMATHVARIANT_bold_script:
|
|
|
|
case eMATHVARIANT_sans_serif_italic:
|
|
|
|
case eMATHVARIANT_sans_serif_bold_italic:
|
|
|
|
return eMathMLFrameType_ItalicIdentifier;
|
|
|
|
default:
|
|
|
|
; // fall through to upright
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return eMathMLFrameType_UprightIdentifier;
|
2002-08-17 01:36:31 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
CompressWhitespace(nsIContent* aContent)
|
|
|
|
{
|
2003-09-27 08:18:26 +04:00
|
|
|
PRUint32 numKids = aContent->GetChildCount();
|
|
|
|
for (PRUint32 kid = 0; kid < numKids; kid++) {
|
2006-07-19 08:36:36 +04:00
|
|
|
nsIContent* cont = aContent->GetChildAt(kid);
|
|
|
|
if (cont && cont->IsNodeOfType(nsINode::eTEXT)) {
|
2003-09-27 08:18:26 +04:00
|
|
|
nsAutoString text;
|
2006-07-19 08:36:36 +04:00
|
|
|
cont->AppendTextTo(text);
|
2003-09-27 08:18:26 +04:00
|
|
|
text.CompressWhitespace();
|
2006-07-19 08:36:36 +04:00
|
|
|
cont->SetText(text, PR_FALSE); // not meant to be used if notify is needed
|
2002-08-17 01:36:31 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2006-03-09 21:55:21 +03:00
|
|
|
nsMathMLTokenFrame::Init(nsIContent* aContent,
|
2002-08-17 01:36:31 +04:00
|
|
|
nsIFrame* aParent,
|
|
|
|
nsIFrame* aPrevInFlow)
|
|
|
|
{
|
|
|
|
// leading and trailing whitespace doesn't count -- bug 15402
|
|
|
|
// brute force removal for people who do <mi> a </mi> instead of <mi>a</mi>
|
|
|
|
// XXX the best fix is to skip these in nsTextFrame
|
|
|
|
CompressWhitespace(aContent);
|
|
|
|
|
|
|
|
// let the base class do its Init()
|
2006-03-27 01:30:36 +04:00
|
|
|
return nsMathMLContainerFrame::Init(aContent, aParent, aPrevInFlow);
|
2002-08-17 01:36:31 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2006-04-10 04:16:29 +04:00
|
|
|
nsMathMLTokenFrame::SetInitialChildList(nsIAtom* aListName,
|
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
|
2006-04-10 04:16:29 +04:00
|
|
|
nsresult rv = nsMathMLContainerFrame::SetInitialChildList(aListName, aChildList);
|
2002-08-17 01:36:31 +04:00
|
|
|
if (NS_FAILED(rv))
|
|
|
|
return rv;
|
|
|
|
|
2009-10-07 08:28:41 +04:00
|
|
|
SetQuotes(PR_FALSE);
|
2008-01-27 05:49:47 +03:00
|
|
|
ProcessTextData();
|
2002-08-17 01:36:31 +04:00
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
2004-08-01 03:15:21 +04:00
|
|
|
nsMathMLTokenFrame::Reflow(nsPresContext* aPresContext,
|
2002-08-17 01:36:31 +04:00
|
|
|
nsHTMLReflowMetrics& aDesiredSize,
|
|
|
|
const nsHTMLReflowState& aReflowState,
|
|
|
|
nsReflowStatus& aStatus)
|
|
|
|
{
|
|
|
|
nsresult rv = NS_OK;
|
|
|
|
|
|
|
|
// initializations needed for empty markup like <mtag></mtag>
|
|
|
|
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();
|
2002-08-17 01:36:31 +04:00
|
|
|
|
2008-01-15 04:13:21 +03:00
|
|
|
nsSize availSize(aReflowState.ComputedWidth(), NS_UNCONSTRAINEDSIZE);
|
2004-01-09 17:20:53 +03:00
|
|
|
nsIFrame* childFrame = GetFirstChild(nsnull);
|
2002-08-17 01:36:31 +04:00
|
|
|
while (childFrame) {
|
2007-12-03 03:54:23 +03:00
|
|
|
// ask our children to compute their bounding metrics
|
|
|
|
nsHTMLReflowMetrics childDesiredSize(aDesiredSize.mFlags
|
|
|
|
| NS_REFLOW_CALC_BOUNDING_METRICS);
|
2002-08-17 01:36:31 +04: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);
|
2002-08-17 01:36:31 +04:00
|
|
|
rv = ReflowChild(childFrame, aPresContext, childDesiredSize,
|
|
|
|
childReflowState, aStatus);
|
|
|
|
//NS_ASSERTION(NS_FRAME_IS_COMPLETE(aStatus), "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(GetFirstChild(nsnull), childFrame);
|
|
|
|
return rv;
|
|
|
|
}
|
2002-08-17 01:36:31 +04:00
|
|
|
|
2008-02-26 07:19:36 +03:00
|
|
|
SaveReflowAndBoundingMetricsFor(childFrame, childDesiredSize,
|
|
|
|
childDesiredSize.mBoundingMetrics);
|
2002-08-17 01:36:31 +04:00
|
|
|
|
2003-07-08 15:00:00 +04:00
|
|
|
childFrame = childFrame->GetNextSibling();
|
2002-08-17 01:36:31 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// place and size children
|
2005-02-07 04:57:50 +03:00
|
|
|
FinalizeReflow(*aReflowState.rendContext, aDesiredSize);
|
2006-05-01 00:34:46 +04:00
|
|
|
|
2004-03-05 02:07:45 +03:00
|
|
|
aStatus = NS_FRAME_COMPLETE;
|
2002-08-17 01:36:31 +04:00
|
|
|
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-18 07:52:48 +03:00
|
|
|
/* virtual */ nsresult
|
2011-04-08 05:04:40 +04:00
|
|
|
nsMathMLTokenFrame::Place(nsRenderingContext& aRenderingContext,
|
2002-08-17 01:36:31 +04:00
|
|
|
PRBool aPlaceOrigin,
|
|
|
|
nsHTMLReflowMetrics& aDesiredSize)
|
|
|
|
{
|
2011-04-08 05:04:40 +04:00
|
|
|
mBoundingMetrics = nsBoundingMetrics();
|
2009-02-19 20:48:37 +03:00
|
|
|
for (nsIFrame* childFrame = GetFirstChild(nsnull); childFrame;
|
|
|
|
childFrame = childFrame->GetNextSibling()) {
|
2008-02-27 13:45:36 +03:00
|
|
|
nsHTMLReflowMetrics childSize;
|
|
|
|
GetReflowAndBoundingMetricsFor(childFrame, childSize,
|
|
|
|
childSize.mBoundingMetrics, nsnull);
|
|
|
|
// compute and cache the bounding metrics
|
|
|
|
mBoundingMetrics += childSize.mBoundingMetrics;
|
|
|
|
}
|
|
|
|
|
2011-04-08 05:05:49 +04:00
|
|
|
nsRefPtr<nsFontMetrics> fm =
|
2007-03-31 01:11:41 +04:00
|
|
|
PresContext()->GetMetricsFor(GetStyleFont()->mFont);
|
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;
|
|
|
|
aDesiredSize.width = mBoundingMetrics.width;
|
2009-09-16 19:01:36 +04:00
|
|
|
aDesiredSize.ascent = NS_MAX(mBoundingMetrics.ascent, ascent);
|
2007-01-23 07:06:56 +03:00
|
|
|
aDesiredSize.height = aDesiredSize.ascent +
|
2009-09-16 19:01:36 +04:00
|
|
|
NS_MAX(mBoundingMetrics.descent, descent);
|
2002-08-17 01:36:31 +04:00
|
|
|
|
|
|
|
if (aPlaceOrigin) {
|
|
|
|
nscoord dy, dx = 0;
|
2009-02-19 20:48:37 +03:00
|
|
|
for (nsIFrame* childFrame = GetFirstChild(nsnull); childFrame;
|
|
|
|
childFrame = childFrame->GetNextSibling()) {
|
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 childSize;
|
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
|
2008-02-26 07:19:36 +03:00
|
|
|
dy = childSize.height == 0 ? 0 : aDesiredSize.ascent - childSize.ascent;
|
2007-03-31 01:11:41 +04:00
|
|
|
FinishReflowChild(childFrame, PresContext(), nsnull, childSize, dx, dy, 0);
|
2008-02-26 07:19:36 +03:00
|
|
|
dx += childSize.width;
|
2002-08-17 01:36:31 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
SetReference(nsPoint(0, aDesiredSize.ascent));
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
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
|
|
|
/* virtual */ void
|
|
|
|
nsMathMLTokenFrame::MarkIntrinsicWidthsDirty()
|
2002-08-17 01:36:31 +04:00
|
|
|
{
|
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
|
|
|
// this could be called due to changes in the nsTextFrame beneath us
|
|
|
|
// when something changed in the text content. So re-process our text
|
2008-01-27 05:49:47 +03:00
|
|
|
ProcessTextData();
|
2002-08-17 01:36:31 +04:00
|
|
|
|
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
|
|
|
nsMathMLContainerFrame::MarkIntrinsicWidthsDirty();
|
2002-08-17 01:36:31 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2005-09-07 20:49:21 +04:00
|
|
|
nsMathMLTokenFrame::AttributeChanged(PRInt32 aNameSpaceID,
|
2002-08-17 01:36:31 +04:00
|
|
|
nsIAtom* aAttribute,
|
2003-07-12 01:16:12 +04:00
|
|
|
PRInt32 aModType)
|
2002-08-17 01:36:31 +04:00
|
|
|
{
|
2006-12-26 20:47:52 +03:00
|
|
|
if (nsGkAtoms::lquote_ == aAttribute ||
|
|
|
|
nsGkAtoms::rquote_ == aAttribute) {
|
2009-10-07 08:28:41 +04:00
|
|
|
SetQuotes(PR_TRUE);
|
2002-08-17 01:36:31 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
return nsMathMLContainerFrame::
|
2005-09-07 20:49:21 +04:00
|
|
|
AttributeChanged(aNameSpaceID, aAttribute, aModType);
|
2002-08-17 01:36:31 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2008-01-27 05:49:47 +03:00
|
|
|
nsMathMLTokenFrame::ProcessTextData()
|
2002-08-17 01:36:31 +04:00
|
|
|
{
|
2006-09-25 04:08:41 +04:00
|
|
|
// see if the style changes from normal to italic or vice-versa
|
2006-09-25 07:14:18 +04:00
|
|
|
if (!SetTextStyle())
|
2006-09-25 04:08:41 +04:00
|
|
|
return;
|
|
|
|
|
2007-04-09 07:43:44 +04:00
|
|
|
// explicitly request a re-resolve to pick up the change of style
|
2007-04-09 07:54:09 +04:00
|
|
|
PresContext()->PresShell()->FrameConstructor()->
|
2010-06-18 20:23:05 +04:00
|
|
|
PostRestyleEvent(mContent->AsElement(), eRestyle_Subtree, NS_STYLE_HINT_NONE);
|
2002-08-17 01:36:31 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
///////////////////////////////////////////////////////////////////////////
|
|
|
|
// For <mi>, if the content is not a single character, turn the font to
|
|
|
|
// normal (this function will also query attributes from the mstyle hierarchy)
|
2008-03-16 05:10:47 +03:00
|
|
|
// Returns PR_TRUE if there is a style change.
|
|
|
|
//
|
|
|
|
// http://www.w3.org/TR/2003/REC-MathML2-20031021/chapter3.html#presm.commatt
|
|
|
|
//
|
|
|
|
// "It is important to note that only certain combinations of
|
|
|
|
// character data and mathvariant attribute values make sense.
|
|
|
|
// ...
|
|
|
|
// By design, the only cases that have an unambiguous
|
|
|
|
// interpretation are exactly the ones that correspond to SMP Math
|
|
|
|
// Alphanumeric Symbol characters, which are enumerated in Section
|
|
|
|
// 6.2.3 Mathematical Alphanumeric Symbols Characters. In all other
|
|
|
|
// cases, it is suggested that renderers ignore the value of the
|
|
|
|
// mathvariant attribute if it is present."
|
|
|
|
//
|
|
|
|
// There are no corresponding characters for mathvariant=normal, suggesting
|
|
|
|
// that this value should be ignored, but this (from the same section of
|
|
|
|
// Chapter 3) implies that font-style should not be inherited, but set to
|
|
|
|
// normal for mathvariant=normal:
|
|
|
|
//
|
|
|
|
// "In particular, inheritance of the mathvariant attribute does not follow
|
|
|
|
// the CSS model. The default value for this attribute is "normal"
|
|
|
|
// (non-slanted) for all tokens except mi. ... (The deprecated fontslant
|
|
|
|
// attribute also behaves this way.)"
|
2002-08-17 01:36:31 +04:00
|
|
|
|
2006-09-25 04:08:41 +04:00
|
|
|
PRBool
|
2006-09-25 07:14:18 +04:00
|
|
|
nsMathMLTokenFrame::SetTextStyle()
|
2002-08-17 01:36:31 +04:00
|
|
|
{
|
2006-12-26 20:47:52 +03:00
|
|
|
if (mContent->Tag() != nsGkAtoms::mi_)
|
2006-09-25 04:08:41 +04:00
|
|
|
return PR_FALSE;
|
2002-08-17 01:36:31 +04:00
|
|
|
|
|
|
|
if (!mFrames.FirstChild())
|
2006-09-25 04:08:41 +04:00
|
|
|
return PR_FALSE;
|
2002-08-17 01:36:31 +04:00
|
|
|
|
|
|
|
// Get the text content that we enclose and its length
|
2006-09-15 23:54:45 +04:00
|
|
|
nsAutoString data;
|
|
|
|
nsContentUtils::GetNodeTextContent(mContent, PR_FALSE, data);
|
2002-08-17 01:36:31 +04:00
|
|
|
PRInt32 length = data.Length();
|
2005-09-07 03:47:01 +04:00
|
|
|
if (!length)
|
2006-09-25 04:08:41 +04:00
|
|
|
return PR_FALSE;
|
2005-09-07 03:47:01 +04:00
|
|
|
|
2002-08-17 01:36:31 +04:00
|
|
|
nsAutoString fontstyle;
|
2008-03-16 05:10:47 +03:00
|
|
|
PRBool isSingleCharacter =
|
|
|
|
length == 1 ||
|
|
|
|
(length == 2 && NS_IS_HIGH_SURROGATE(data[0]));
|
|
|
|
if (isSingleCharacter &&
|
|
|
|
nsMathMLOperators::LookupInvariantChar(data) != eMATHVARIANT_NONE) {
|
2005-09-07 03:47:01 +04:00
|
|
|
// bug 65951 - a non-stylable character has its own intrinsic appearance
|
|
|
|
fontstyle.AssignLiteral("invariant");
|
2002-08-17 01:36:31 +04:00
|
|
|
}
|
2008-03-16 05:10:47 +03:00
|
|
|
else {
|
|
|
|
// Attributes override the default behavior.
|
2011-05-13 01:37:03 +04:00
|
|
|
nsAutoString value;
|
|
|
|
if (!(GetAttribute(mContent, mPresentationData.mstyle,
|
|
|
|
nsGkAtoms::mathvariant_, value) ||
|
|
|
|
GetAttribute(mContent, mPresentationData.mstyle,
|
|
|
|
nsGkAtoms::fontstyle_, value))) {
|
2008-03-16 05:10:47 +03:00
|
|
|
if (!isSingleCharacter) {
|
|
|
|
fontstyle.AssignLiteral("normal");
|
|
|
|
}
|
|
|
|
else if (length == 1 && // BMP
|
|
|
|
!nsMathMLOperators::
|
|
|
|
TransformVariantChar(data[0], eMATHVARIANT_italic).
|
|
|
|
Equals(data)) {
|
|
|
|
// Transformation exists. Try to make the BMP character look like the
|
|
|
|
// styled character using the style system until bug 114365 is resolved.
|
|
|
|
fontstyle.AssignLiteral("italic");
|
|
|
|
}
|
|
|
|
// else single character but there is no corresponding Math Alphanumeric
|
|
|
|
// Symbol character: "ignore the value of the [default] mathvariant
|
|
|
|
// attribute".
|
|
|
|
}
|
2002-08-17 01:36:31 +04:00
|
|
|
}
|
|
|
|
|
2010-03-10 15:49:33 +03:00
|
|
|
// set the _moz-math-font-style attribute without notifying that we want a reflow
|
2008-03-16 05:10:47 +03:00
|
|
|
if (fontstyle.IsEmpty()) {
|
2010-03-10 15:49:33 +03:00
|
|
|
if (mContent->HasAttr(kNameSpaceID_None, nsGkAtoms::_moz_math_fontstyle_)) {
|
|
|
|
mContent->UnsetAttr(kNameSpaceID_None, nsGkAtoms::_moz_math_fontstyle_,
|
|
|
|
PR_FALSE);
|
2008-03-16 05:10:47 +03:00
|
|
|
return PR_TRUE;
|
|
|
|
}
|
|
|
|
}
|
2010-03-10 15:49:33 +03:00
|
|
|
else if (!mContent->AttrValueIs(kNameSpaceID_None,
|
|
|
|
nsGkAtoms::_moz_math_fontstyle_,
|
2008-03-16 05:10:47 +03:00
|
|
|
fontstyle, eCaseMatters)) {
|
2010-03-10 15:49:33 +03:00
|
|
|
mContent->SetAttr(kNameSpaceID_None, nsGkAtoms::_moz_math_fontstyle_,
|
2008-03-16 05:10:47 +03:00
|
|
|
fontstyle, PR_FALSE);
|
2006-09-25 04:08:41 +04:00
|
|
|
return PR_TRUE;
|
|
|
|
}
|
2002-08-17 01:36:31 +04:00
|
|
|
|
2006-09-25 04:08:41 +04:00
|
|
|
return PR_FALSE;
|
2002-08-17 01:36:31 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
///////////////////////////////////////////////////////////////////////////
|
|
|
|
// For <ms>, it is assumed that the mathml.css file contains two rules:
|
|
|
|
// ms:before { content: open-quote; }
|
|
|
|
// ms:after { content: close-quote; }
|
|
|
|
// With these two rules, the frame construction code will
|
|
|
|
// create inline frames that contain text frames which themselves
|
|
|
|
// contain the text content of the quotes.
|
|
|
|
// So the main idea in this code is to see if there are lquote and
|
|
|
|
// rquote attributes. If these are there, we ovewrite the default
|
|
|
|
// quotes in the text frames.
|
2009-10-07 08:28:41 +04:00
|
|
|
// XXX this is somewhat bogus, we probably should map lquote and rquote
|
|
|
|
// to 'content' style rules
|
2002-08-17 01:36:31 +04:00
|
|
|
//
|
|
|
|
// But what if the mathml.css file wasn't loaded?
|
|
|
|
// We also check that we are not relying on null pointers...
|
|
|
|
|
|
|
|
static void
|
2009-10-07 08:28:41 +04:00
|
|
|
SetQuote(nsIFrame* aFrame, nsString& aValue, PRBool aNotify)
|
2002-08-17 01:36:31 +04:00
|
|
|
{
|
2009-10-07 08:28:41 +04:00
|
|
|
if (!aFrame)
|
|
|
|
return;
|
|
|
|
|
|
|
|
nsIFrame* textFrame = aFrame->GetFirstChild(nsnull);
|
|
|
|
if (!textFrame)
|
|
|
|
return;
|
|
|
|
|
|
|
|
nsIContent* quoteContent = textFrame->GetContent();
|
|
|
|
if (!quoteContent->IsNodeOfType(nsINode::eTEXT))
|
|
|
|
return;
|
|
|
|
|
|
|
|
quoteContent->SetText(aValue, aNotify);
|
2002-08-17 01:36:31 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2009-10-07 08:28:41 +04:00
|
|
|
nsMathMLTokenFrame::SetQuotes(PRBool aNotify)
|
2002-08-17 01:36:31 +04:00
|
|
|
{
|
2006-12-26 20:47:52 +03:00
|
|
|
if (mContent->Tag() != nsGkAtoms::ms_)
|
2002-08-17 01:36:31 +04:00
|
|
|
return;
|
|
|
|
|
|
|
|
nsAutoString value;
|
|
|
|
// lquote
|
2005-10-28 15:25:24 +04:00
|
|
|
if (GetAttribute(mContent, mPresentationData.mstyle,
|
2006-12-26 20:47:52 +03:00
|
|
|
nsGkAtoms::lquote_, value)) {
|
2009-10-07 08:28:41 +04:00
|
|
|
SetQuote(nsLayoutUtils::GetBeforeFrame(this), value, aNotify);
|
2002-08-17 01:36:31 +04:00
|
|
|
}
|
|
|
|
// rquote
|
2005-10-28 15:25:24 +04:00
|
|
|
if (GetAttribute(mContent, mPresentationData.mstyle,
|
2006-12-26 20:47:52 +03:00
|
|
|
nsGkAtoms::rquote_, value)) {
|
2009-10-07 08:28:41 +04:00
|
|
|
SetQuote(nsLayoutUtils::GetAfterFrame(this), value, aNotify);
|
2002-08-17 01:36:31 +04:00
|
|
|
}
|
|
|
|
}
|