2010-05-12 14:11:59 +04: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/. */
|
2010-05-12 14:11:59 +04:00
|
|
|
|
|
|
|
|
|
|
|
#include "nsMathMLsemanticsFrame.h"
|
2013-05-10 16:40:44 +04:00
|
|
|
#include "nsMimeTypes.h"
|
2013-10-08 03:15:59 +04:00
|
|
|
#include "mozilla/gfx/2D.h"
|
2010-05-12 14:11:59 +04:00
|
|
|
|
|
|
|
//
|
|
|
|
// <semantics> -- associate annotations with a MathML expression
|
|
|
|
//
|
|
|
|
|
|
|
|
nsIFrame*
|
|
|
|
NS_NewMathMLsemanticsFrame(nsIPresShell* aPresShell, nsStyleContext* aContext)
|
|
|
|
{
|
|
|
|
return new (aPresShell) nsMathMLsemanticsFrame(aContext);
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMPL_FRAMEARENA_HELPERS(nsMathMLsemanticsFrame)
|
|
|
|
|
|
|
|
nsMathMLsemanticsFrame::~nsMathMLsemanticsFrame()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2013-05-10 16:40:44 +04:00
|
|
|
nsIFrame*
|
|
|
|
nsMathMLsemanticsFrame::GetSelectedFrame()
|
2010-05-12 14:11:59 +04:00
|
|
|
{
|
2013-05-10 16:40:44 +04:00
|
|
|
// By default, we will display the first child of the <semantics> element.
|
|
|
|
nsIFrame* childFrame = mFrames.FirstChild();
|
|
|
|
mSelectedFrame = childFrame;
|
|
|
|
|
|
|
|
// An empty <semantics> is invalid
|
|
|
|
if (!childFrame) {
|
|
|
|
mInvalidMarkup = true;
|
|
|
|
return mSelectedFrame;
|
|
|
|
}
|
|
|
|
mInvalidMarkup = false;
|
|
|
|
|
|
|
|
// Using <annotation> or <annotation-xml> as a first child is invalid.
|
|
|
|
// However some people use this syntax so we take care of this case too.
|
|
|
|
bool firstChildIsAnnotation = false;
|
|
|
|
nsIContent* childContent = childFrame->GetContent();
|
2015-03-03 14:09:00 +03:00
|
|
|
if (childContent->IsAnyOfMathMLElements(nsGkAtoms::annotation_,
|
|
|
|
nsGkAtoms::annotation_xml_)) {
|
2013-05-10 16:40:44 +04:00
|
|
|
firstChildIsAnnotation = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
// If the first child is a presentation MathML element other than
|
|
|
|
// <annotation> or <annotation-xml>, we are done.
|
|
|
|
if (!firstChildIsAnnotation &&
|
|
|
|
childFrame->IsFrameOfType(nsIFrame::eMathML)) {
|
|
|
|
nsIMathMLFrame* mathMLFrame = do_QueryFrame(childFrame);
|
|
|
|
if (mathMLFrame) {
|
|
|
|
TransmitAutomaticData();
|
|
|
|
return mSelectedFrame;
|
|
|
|
}
|
|
|
|
// The first child is not an annotation, so skip it.
|
|
|
|
childFrame = childFrame->GetNextSibling();
|
|
|
|
}
|
|
|
|
|
|
|
|
// Otherwise, we read the list of annotations and select the first one that
|
|
|
|
// could be displayed in place of the first child of <semantics>. If none is
|
|
|
|
// found, we fallback to this first child.
|
|
|
|
for ( ; childFrame; childFrame = childFrame->GetNextSibling()) {
|
|
|
|
nsIContent* childContent = childFrame->GetContent();
|
|
|
|
|
2015-03-03 14:09:00 +03:00
|
|
|
if (childContent->IsMathMLElement(nsGkAtoms::annotation_)) {
|
2013-05-10 16:40:44 +04:00
|
|
|
|
|
|
|
// If the <annotation> element has an src attribute we ignore it.
|
|
|
|
// XXXfredw Should annotation images be supported? See the related
|
|
|
|
// bug 297465 for mglyph.
|
|
|
|
if (childContent->HasAttr(kNameSpaceID_None, nsGkAtoms::src)) continue;
|
|
|
|
|
|
|
|
// Otherwise, we assume it is a text annotation that can always be
|
|
|
|
// displayed and stop here.
|
|
|
|
mSelectedFrame = childFrame;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2015-03-03 14:09:00 +03:00
|
|
|
if (childContent->IsMathMLElement(nsGkAtoms::annotation_xml_)) {
|
2013-05-10 16:40:44 +04:00
|
|
|
|
|
|
|
// If the <annotation-xml> element has an src attribute we ignore it.
|
|
|
|
if (childContent->HasAttr(kNameSpaceID_None, nsGkAtoms::src)) continue;
|
|
|
|
|
|
|
|
// If the <annotation-xml> element has an encoding attribute
|
|
|
|
// describing presentation MathML, SVG or HTML we assume the content
|
|
|
|
// can be displayed and stop here.
|
|
|
|
//
|
|
|
|
// We recognize the following encoding values:
|
|
|
|
//
|
|
|
|
// - "MathML-Presentation", which is mentioned in the MathML3 REC
|
|
|
|
// - "SVG1.1" which is mentioned in the W3C note
|
|
|
|
// http://www.w3.org/Math/Documents/Notes/graphics.xml
|
|
|
|
// - Other mime Content-Types for SVG and HTML
|
|
|
|
//
|
|
|
|
// We exclude APPLICATION_MATHML_XML = "application/mathml+xml" which
|
|
|
|
// is ambiguous about whether it is Presentation or Content MathML.
|
|
|
|
// Authors must use a more explicit encoding value.
|
|
|
|
nsAutoString value;
|
|
|
|
childContent->GetAttr(kNameSpaceID_None, nsGkAtoms::encoding, value);
|
|
|
|
if (value.EqualsLiteral("application/mathml-presentation+xml") ||
|
|
|
|
value.EqualsLiteral("MathML-Presentation") ||
|
|
|
|
value.EqualsLiteral(IMAGE_SVG_XML) ||
|
|
|
|
value.EqualsLiteral("SVG1.1") ||
|
|
|
|
value.EqualsLiteral(APPLICATION_XHTML_XML) ||
|
|
|
|
value.EqualsLiteral(TEXT_HTML)) {
|
|
|
|
mSelectedFrame = childFrame;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
TransmitAutomaticData();
|
|
|
|
return mSelectedFrame;
|
2010-05-12 14:11:59 +04:00
|
|
|
}
|