LCOV - code coverage report
Current view: top level - layout/mathml - nsMathMLsemanticsFrame.cpp (source / functions) Hit Total Coverage
Test: output.info Lines: 0 43 0.0 %
Date: 2017-07-14 16:53:18 Functions: 0 5 0.0 %
Legend: Lines: hit not hit

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

Generated by: LCOV version 1.13