/src/mozilla-central/layout/mathml/nsMathMLsemanticsFrame.cpp
Line | Count | Source (jump to first uncovered line) |
1 | | /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ |
2 | | /* vim: set ts=8 sts=2 et sw=2 tw=80: */ |
3 | | /* This Source Code Form is subject to the terms of the Mozilla Public |
4 | | * License, v. 2.0. If a copy of the MPL was not distributed with this |
5 | | * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ |
6 | | |
7 | | |
8 | | #include "nsMathMLsemanticsFrame.h" |
9 | | #include "nsMimeTypes.h" |
10 | | #include "mozilla/gfx/2D.h" |
11 | | |
12 | | // |
13 | | // <semantics> -- associate annotations with a MathML expression |
14 | | // |
15 | | |
16 | | nsIFrame* |
17 | | NS_NewMathMLsemanticsFrame(nsIPresShell* aPresShell, ComputedStyle* aStyle) |
18 | 0 | { |
19 | 0 | return new (aPresShell) nsMathMLsemanticsFrame(aStyle); |
20 | 0 | } |
21 | | |
22 | | NS_IMPL_FRAMEARENA_HELPERS(nsMathMLsemanticsFrame) |
23 | | |
24 | | nsMathMLsemanticsFrame::~nsMathMLsemanticsFrame() |
25 | 0 | { |
26 | 0 | } |
27 | | |
28 | | nsIFrame* |
29 | | nsMathMLsemanticsFrame::GetSelectedFrame() |
30 | 0 | { |
31 | 0 | // By default, we will display the first child of the <semantics> element. |
32 | 0 | nsIFrame* childFrame = mFrames.FirstChild(); |
33 | 0 | mSelectedFrame = childFrame; |
34 | 0 |
|
35 | 0 | // An empty <semantics> is invalid |
36 | 0 | if (!childFrame) { |
37 | 0 | mInvalidMarkup = true; |
38 | 0 | return mSelectedFrame; |
39 | 0 | } |
40 | 0 | mInvalidMarkup = false; |
41 | 0 |
|
42 | 0 | // Using <annotation> or <annotation-xml> as a first child is invalid. |
43 | 0 | // However some people use this syntax so we take care of this case too. |
44 | 0 | bool firstChildIsAnnotation = false; |
45 | 0 | nsIContent* childContent = childFrame->GetContent(); |
46 | 0 | if (childContent->IsAnyOfMathMLElements(nsGkAtoms::annotation_, |
47 | 0 | nsGkAtoms::annotation_xml_)) { |
48 | 0 | firstChildIsAnnotation = true; |
49 | 0 | } |
50 | 0 |
|
51 | 0 | // If the first child is a presentation MathML element other than |
52 | 0 | // <annotation> or <annotation-xml>, we are done. |
53 | 0 | if (!firstChildIsAnnotation && |
54 | 0 | childFrame->IsFrameOfType(nsIFrame::eMathML)) { |
55 | 0 | nsIMathMLFrame* mathMLFrame = do_QueryFrame(childFrame); |
56 | 0 | if (mathMLFrame) { |
57 | 0 | TransmitAutomaticData(); |
58 | 0 | return mSelectedFrame; |
59 | 0 | } |
60 | 0 | // The first child is not an annotation, so skip it. |
61 | 0 | childFrame = childFrame->GetNextSibling(); |
62 | 0 | } |
63 | 0 |
|
64 | 0 | // Otherwise, we read the list of annotations and select the first one that |
65 | 0 | // could be displayed in place of the first child of <semantics>. If none is |
66 | 0 | // found, we fallback to this first child. |
67 | 0 | for ( ; childFrame; childFrame = childFrame->GetNextSibling()) { |
68 | 0 | nsIContent* childContent = childFrame->GetContent(); |
69 | 0 |
|
70 | 0 | if (childContent->IsMathMLElement(nsGkAtoms::annotation_)) { |
71 | 0 |
|
72 | 0 | // If the <annotation> element has an src attribute we ignore it. |
73 | 0 | // XXXfredw Should annotation images be supported? See the related |
74 | 0 | // bug 297465 for mglyph. |
75 | 0 | if (childContent->AsElement()->HasAttr(kNameSpaceID_None, nsGkAtoms::src)) |
76 | 0 | continue; |
77 | 0 | |
78 | 0 | // Otherwise, we assume it is a text annotation that can always be |
79 | 0 | // displayed and stop here. |
80 | 0 | mSelectedFrame = childFrame; |
81 | 0 | break; |
82 | 0 | } |
83 | 0 | |
84 | 0 | if (childContent->IsMathMLElement(nsGkAtoms::annotation_xml_)) { |
85 | 0 | // If the <annotation-xml> element has an src attribute we ignore it. |
86 | 0 | if (childContent->AsElement()->HasAttr(kNameSpaceID_None, nsGkAtoms::src)) |
87 | 0 | continue; |
88 | 0 | |
89 | 0 | // If the <annotation-xml> element has an encoding attribute |
90 | 0 | // describing presentation MathML, SVG or HTML we assume the content |
91 | 0 | // can be displayed and stop here. |
92 | 0 | // |
93 | 0 | // We recognize the following encoding values: |
94 | 0 | // |
95 | 0 | // - "MathML-Presentation", which is mentioned in the MathML3 REC |
96 | 0 | // - "SVG1.1" which is mentioned in the W3C note |
97 | 0 | // http://www.w3.org/Math/Documents/Notes/graphics.xml |
98 | 0 | // - Other mime Content-Types for SVG and HTML |
99 | 0 | // |
100 | 0 | // We exclude APPLICATION_MATHML_XML = "application/mathml+xml" which |
101 | 0 | // is ambiguous about whether it is Presentation or Content MathML. |
102 | 0 | // Authors must use a more explicit encoding value. |
103 | 0 | nsAutoString value; |
104 | 0 | childContent->AsElement()->GetAttr(kNameSpaceID_None, |
105 | 0 | nsGkAtoms::encoding, |
106 | 0 | value); |
107 | 0 | if (value.EqualsLiteral("application/mathml-presentation+xml") || |
108 | 0 | value.EqualsLiteral("MathML-Presentation") || |
109 | 0 | value.EqualsLiteral(IMAGE_SVG_XML) || |
110 | 0 | value.EqualsLiteral("SVG1.1") || |
111 | 0 | value.EqualsLiteral(APPLICATION_XHTML_XML) || |
112 | 0 | value.EqualsLiteral(TEXT_HTML)) { |
113 | 0 | mSelectedFrame = childFrame; |
114 | 0 | break; |
115 | 0 | } |
116 | 0 | } |
117 | 0 | } |
118 | 0 |
|
119 | 0 | TransmitAutomaticData(); |
120 | 0 | return mSelectedFrame; |
121 | 0 | } |