layout/mathml/nsMathMLmspaceFrame.cpp

Tue, 06 Jan 2015 21:39:09 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Tue, 06 Jan 2015 21:39:09 +0100
branch
TOR_BUG_9701
changeset 8
97036ab72558
permissions
-rw-r--r--

Conditionally force memory storage according to privacy.thirdparty.isolate;
This solves Tor bug #9701, complying with disk avoidance documented in
https://www.torproject.org/projects/torbrowser/design/#disk-avoidance.

     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/. */
     6 #include "nsMathMLmspaceFrame.h"
     7 #include "nsMathMLElement.h"
     8 #include "mozilla/gfx/2D.h"
     9 #include <algorithm>
    12 //
    13 // <mspace> -- space - implementation
    14 //
    16 nsIFrame*
    17 NS_NewMathMLmspaceFrame(nsIPresShell* aPresShell, nsStyleContext* aContext)
    18 {
    19   return new (aPresShell) nsMathMLmspaceFrame(aContext);
    20 }
    22 NS_IMPL_FRAMEARENA_HELPERS(nsMathMLmspaceFrame)
    24 nsMathMLmspaceFrame::~nsMathMLmspaceFrame()
    25 {
    26 }
    28 bool
    29 nsMathMLmspaceFrame::IsLeaf() const
    30 {
    31   return true;
    32 }
    34 void
    35 nsMathMLmspaceFrame::ProcessAttributes(nsPresContext* aPresContext)
    36 {
    37   nsAutoString value;
    39   // width 
    40   //
    41   // "Specifies the desired width of the space."
    42   //
    43   // values: length
    44   // default: 0em
    45   //
    46   // The default value is "0em", so unitless values can be ignored.
    47   // <mspace/> is listed among MathML elements allowing negative spacing and
    48   // the MathML test suite contains "Presentation/TokenElements/mspace/mspace2" 
    49   // as an example. Hence we allow negative values.
    50   //
    51   mWidth = 0;
    52   mContent->GetAttr(kNameSpaceID_None, nsGkAtoms::width, value);
    53   if (!value.IsEmpty()) {
    54     ParseNumericValue(value, &mWidth,
    55                       nsMathMLElement::PARSE_ALLOW_NEGATIVE,
    56                       aPresContext, mStyleContext);
    57   }
    59   // height
    60   //
    61   // "Specifies the desired height (above the baseline) of the space."
    62   //
    63   // values: length
    64   // default: 0ex
    65   //
    66   // The default value is "0ex", so unitless values can be ignored.
    67   // We do not allow negative values. See bug 716349.
    68   //
    69   mHeight = 0;
    70   mContent->GetAttr(kNameSpaceID_None, nsGkAtoms::height, value);
    71   if (!value.IsEmpty()) {
    72     ParseNumericValue(value, &mHeight, 0,
    73                       aPresContext, mStyleContext);
    74   }
    76   // depth
    77   //
    78   // "Specifies the desired depth (below the baseline) of the space."
    79   //
    80   // values: length
    81   // default: 0ex
    82   //
    83   // The default value is "0ex", so unitless values can be ignored.
    84   // We do not allow negative values. See bug 716349.
    85   //
    86   mDepth = 0;
    87   mContent->GetAttr(kNameSpaceID_None, nsGkAtoms::depth_, value);
    88   if (!value.IsEmpty()) {
    89     ParseNumericValue(value, &mDepth, 0,
    90                       aPresContext, mStyleContext);
    91   }
    92 }
    94 nsresult
    95 nsMathMLmspaceFrame::Reflow(nsPresContext*          aPresContext,
    96                             nsHTMLReflowMetrics&     aDesiredSize,
    97                             const nsHTMLReflowState& aReflowState,
    98                             nsReflowStatus&          aStatus)
    99 {
   100   ProcessAttributes(aPresContext);
   102   mBoundingMetrics = nsBoundingMetrics();
   103   mBoundingMetrics.width = mWidth;
   104   mBoundingMetrics.ascent = mHeight;
   105   mBoundingMetrics.descent = mDepth;
   106   mBoundingMetrics.leftBearing = 0;
   107   mBoundingMetrics.rightBearing = mBoundingMetrics.width;
   109   aDesiredSize.SetTopAscent(mHeight);
   110   aDesiredSize.Width() = std::max(0, mBoundingMetrics.width);
   111   aDesiredSize.Height() = aDesiredSize.TopAscent() + mDepth;
   112   // Also return our bounding metrics
   113   aDesiredSize.mBoundingMetrics = mBoundingMetrics;
   115   aStatus = NS_FRAME_COMPLETE;
   116   NS_FRAME_SET_TRUNCATION(aStatus, aReflowState, aDesiredSize);
   117   return NS_OK;
   118 }
   120 /* virtual */ nsresult
   121 nsMathMLmspaceFrame::MeasureForWidth(nsRenderingContext& aRenderingContext,
   122                                      nsHTMLReflowMetrics& aDesiredSize)
   123 {
   124   ProcessAttributes(PresContext());
   125   mBoundingMetrics = nsBoundingMetrics();
   126   mBoundingMetrics.width = mWidth;
   127   aDesiredSize.Width() = std::max(0, mBoundingMetrics.width);
   128   aDesiredSize.mBoundingMetrics = mBoundingMetrics;
   129   return NS_OK;
   130 }

mercurial