layout/mathml/nsMathMLmspaceFrame.cpp

Thu, 22 Jan 2015 13:21:57 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Thu, 22 Jan 2015 13:21:57 +0100
branch
TOR_BUG_9701
changeset 15
b8a032363ba2
permissions
-rw-r--r--

Incorporate requested changes from Mozilla in review:
https://bugzilla.mozilla.org/show_bug.cgi?id=1123480#c6

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

mercurial