Changeset 116975 in webkit
- Timestamp:
- May 14, 2012 11:57:34 AM (12 years ago)
- Location:
- trunk
- Files:
-
- 3 added
- 6 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/LayoutTests/ChangeLog
r116972 r116975 1 2012-05-14 David Barton <dbarton@mathscribe.com> 2 3 Unify RenderMathMLSquareRoot.cpp and RenderMathMLRoot.cpp 4 https://bugs.webkit.org/show_bug.cgi?id=86319 5 6 Reviewed by Darin Adler. 7 8 * mathml/presentation/mroot-pref-width.html: Added. 9 * platform/mac/mathml/presentation/mroot-pref-width-expected.png: Added. 10 * platform/mac/mathml/presentation/mroot-pref-width-expected.txt: Added. 11 1 12 2012-05-14 Allan Sandfeld Jensen <allan.jensen@nokia.com> 2 13 -
trunk/Source/WebCore/ChangeLog
r116974 r116975 1 2012-05-14 David Barton <dbarton@mathscribe.com> 2 3 Unify RenderMathMLSquareRoot.cpp and RenderMathMLRoot.cpp 4 https://bugs.webkit.org/show_bug.cgi?id=86319 5 6 Reviewed by Darin Adler. 7 8 Most of RenderMathMLSquareRoot.cpp is duplicated in RenderMathMLRoot.cpp and can be 9 eliminated. We also define RenderMathMLRoot::computePreferredLogicalWidths(). 10 11 Test: mathml/presentation/mroot-pref-width.html 12 13 * rendering/mathml/RenderMathMLRoot.cpp: 14 (WebCore::RenderMathMLRoot::computePreferredLogicalWidths): 15 (WebCore::RenderMathMLRoot::layout): 16 (WebCore::RenderMathMLRoot::paint): 17 * rendering/mathml/RenderMathMLRoot.h: 18 * rendering/mathml/RenderMathMLSquareRoot.cpp: 19 (WebCore::RenderMathMLSquareRoot::RenderMathMLSquareRoot): 20 (WebCore::RenderMathMLSquareRoot::addChild): 21 * rendering/mathml/RenderMathMLSquareRoot.h: 22 1 23 2012-05-14 MORITA Hajime <morrita@google.com> 2 24 -
trunk/Source/WebCore/rendering/mathml/RenderMathMLRoot.cpp
r114012 r116975 32 32 33 33 #include "GraphicsContext.h" 34 #include "MathMLNames.h"35 34 #include "PaintInfo.h" 36 35 … … 39 38 namespace WebCore { 40 39 41 using namespace MathMLNames;42 43 40 // FIXME: This whole file should be changed to work with various writing modes. See https://bugs.webkit.org/show_bug.cgi?id=48951. 44 41 … … 55 52 // Horizontal position of the top left point of the radical "dip" (* frontWidth) 56 53 const float gRadicalDipLeftPointXFront = 0.8f; 57 // Vertical position of the top left point of the radical "dip" (* baseHeight) 58 const float gRadicalDipLeftPointYPos = 0.625f; 54 // Vertical position of the top left point of a sqrt radical "dip" (* baseHeight) 55 const float gSqrtRadicalDipLeftPointYPos = 0.5f; 56 // Vertical position of the top left point of an nth root radical "dip" (* baseHeight) 57 const float gRootRadicalDipLeftPointYPos = 0.625f; 59 58 // Vertical shift of the left end point of the radical (em) 60 59 const float gRadicalLeftEndYShiftEms = 0.05f; … … 82 81 } 83 82 83 void RenderMathMLRoot::computePreferredLogicalWidths() 84 { 85 ASSERT(preferredLogicalWidthsDirty() && needsLayout()); 86 87 computeChildrenPreferredLogicalHeights(); 88 89 int baseHeight = firstChild() ? roundToInt(preferredLogicalHeightAfterSizing(firstChild())) : 0; 90 91 int frontWidth = lroundf(gFrontWidthEms * style()->fontSize()); 92 93 // Base height above which the shape of the root changes 94 float thresholdHeight = gThresholdBaseHeightEms * style()->fontSize(); 95 if (baseHeight > thresholdHeight && thresholdHeight) { 96 float shift = min<float>((baseHeight - thresholdHeight) / thresholdHeight, 1.0f); 97 m_overbarLeftPointShift = static_cast<int>(shift * gRadicalBottomPointXFront * frontWidth); 98 m_intrinsicPaddingAfter = lroundf(gBigRootBottomPaddingEms * style()->fontSize()); 99 } else { 100 m_overbarLeftPointShift = 0; 101 m_intrinsicPaddingAfter = 0; 102 } 103 104 int rootPad = lroundf(gSpaceAboveEms * style()->fontSize()); 105 m_intrinsicPaddingBefore = rootPad; 106 m_indexTop = 0; 107 if (RenderBoxModelObject* index = this->index()) { 108 m_intrinsicPaddingStart = roundToInt(index->maxPreferredLogicalWidth()) + m_overbarLeftPointShift; 109 110 int indexHeight = roundToInt(preferredLogicalHeightAfterSizing(index)); 111 int partDipHeight = lroundf((1 - gRootRadicalDipLeftPointYPos) * baseHeight); 112 int rootExtraTop = partDipHeight + indexHeight - (baseHeight + rootPad); 113 if (rootExtraTop > 0) 114 m_intrinsicPaddingBefore += rootExtraTop; 115 else 116 m_indexTop = - rootExtraTop; 117 } else 118 m_intrinsicPaddingStart = frontWidth; 119 120 RenderMathMLBlock::computePreferredLogicalWidths(); 121 122 // Shrink our logical width to its probable value now without triggering unnecessary relayout of our children. 123 ASSERT(needsLayout() && logicalWidth() >= maxPreferredLogicalWidth()); 124 setLogicalWidth(maxPreferredLogicalWidth()); 125 } 126 127 void RenderMathMLRoot::layout() 128 { 129 // Our computePreferredLogicalWidths() may change our logical width and then layout our children, which 130 // RenderBlock::layout()'s relayoutChildren logic isn't expecting. 131 if (preferredLogicalWidthsDirty()) 132 computePreferredLogicalWidths(); 133 134 RenderMathMLBlock::layout(); 135 136 RenderBoxModelObject* index = this->index(); 137 // If |index|, it should be a RenderBlock here, unless the user has overriden its { position: absolute }. 138 if (index && index->isBox()) 139 toRenderBox(index)->setLogicalTop(m_indexTop); 140 } 141 84 142 void RenderMathMLRoot::paint(PaintInfo& info, const LayoutPoint& paintOffset) 85 143 { … … 89 147 return; 90 148 91 if (!index()) 92 return; 93 94 IntPoint adjustedPaintOffset = roundedIntPoint(paintOffset + location() + computedCSSContentBoxRect().location()); 149 IntPoint adjustedPaintOffset = roundedIntPoint(paintOffset + location() + contentBoxRect().location()); 150 151 int startX = adjustedPaintOffset.x(); 152 int frontWidth = lroundf(gFrontWidthEms * style()->fontSize()); 153 int overbarWidth = roundToInt(getBoxModelObjectWidth(firstChild())) + m_overbarLeftPointShift; 95 154 96 155 int baseHeight = roundToInt(getBoxModelObjectHeight(firstChild())); 97 98 int overbarWidth = roundToInt(getBoxModelObjectWidth(firstChild())) + m_overbarLeftPointShift; 99 int indexWidth = index()->pixelSnappedOffsetWidth(); 100 int frontWidth = static_cast<int>(roundf(gFrontWidthEms * style()->fontSize())); 101 int startX = adjustedPaintOffset.x() + indexWidth + m_overbarLeftPointShift; 102 103 int rootPad = static_cast<int>(roundf(gSpaceAboveEms * style()->fontSize())); 104 adjustedPaintOffset.setY(adjustedPaintOffset.y() + m_intrinsicPaddingBefore - rootPad); 156 int rootPad = lroundf(gSpaceAboveEms * style()->fontSize()); 157 adjustedPaintOffset.setY(adjustedPaintOffset.y() - rootPad); 158 159 float radicalDipLeftPointYPos = (index() ? gRootRadicalDipLeftPointYPos : gSqrtRadicalDipLeftPointYPos) * baseHeight; 105 160 106 161 FloatPoint overbarLeftPoint(startX - m_overbarLeftPointShift, adjustedPaintOffset.y()); 107 162 FloatPoint bottomPoint(startX - gRadicalBottomPointXFront * frontWidth, adjustedPaintOffset.y() + baseHeight + gRadicalBottomPointLower); 108 FloatPoint dipLeftPoint(startX - gRadicalDipLeftPointXFront * frontWidth, adjustedPaintOffset.y() + gRadicalDipLeftPointYPos * baseHeight);163 FloatPoint dipLeftPoint(startX - gRadicalDipLeftPointXFront * frontWidth, adjustedPaintOffset.y() + radicalDipLeftPointYPos); 109 164 FloatPoint leftEnd(startX - frontWidth, dipLeftPoint.y() + gRadicalLeftEndYShiftEms * style()->fontSize()); 110 165 … … 154 209 } 155 210 156 void RenderMathMLRoot::layout()157 {158 RenderBlock::layout();159 160 if (!index())161 return;162 163 int baseHeight = roundToInt(getBoxModelObjectHeight(firstChild()));164 165 // Base height above which the shape of the root changes166 float thresholdHeight = gThresholdBaseHeightEms * style()->fontSize();167 if (baseHeight > thresholdHeight && thresholdHeight) {168 float shift = min<float>((baseHeight - thresholdHeight) / thresholdHeight, 1.0f);169 int frontWidth = static_cast<int>(roundf(gFrontWidthEms * style()->fontSize()));170 m_overbarLeftPointShift = static_cast<int>(shift * gRadicalBottomPointXFront * frontWidth);171 m_intrinsicPaddingAfter = static_cast<int>(roundf(gBigRootBottomPaddingEms * style()->fontSize()));172 } else {173 m_overbarLeftPointShift = 0;174 m_intrinsicPaddingAfter = 0;175 }176 177 RenderBoxModelObject* index = this->index();178 179 m_intrinsicPaddingStart = index->pixelSnappedOffsetWidth() + m_overbarLeftPointShift;180 181 int rootPad = static_cast<int>(roundf(gSpaceAboveEms * style()->fontSize()));182 int partDipHeight = static_cast<int>(roundf((1 - gRadicalDipLeftPointYPos) * baseHeight));183 int rootExtraTop = partDipHeight + index->pixelSnappedOffsetHeight() - (baseHeight + rootPad);184 m_intrinsicPaddingBefore = rootPad + max(rootExtraTop, 0);185 186 setNeedsLayout(true, MarkOnlyThis);187 setPreferredLogicalWidthsDirty(true, MarkOnlyThis); // FIXME: Can this really be right?188 // FIXME: Preferred logical widths are currently wrong the first time through, relying on layout() to set m_intrinsicPaddingStart.189 RenderBlock::layout();190 191 // |index| should be a RenderBlock here, unless the user has overriden its { position: absolute }.192 if (rootExtraTop < 0 && index->isBox())193 toRenderBox(index)->setLogicalTop(-rootExtraTop);194 }195 196 211 } 197 212 -
trunk/Source/WebCore/rendering/mathml/RenderMathMLRoot.h
r114012 r116975 33 33 namespace WebCore { 34 34 35 // Render base^(1/index), using radical notation.35 // Render base^(1/index), or sqrt(base) via the derived class RenderMathMLSquareRoot, using radical notation. 36 36 class RenderMathMLRoot : public RenderMathMLBlock { 37 37 public: … … 46 46 virtual const char* renderName() const { return "RenderMathMLRoot"; } 47 47 48 virtual void computePreferredLogicalWidths() OVERRIDE; 49 48 50 // This may return 0 for a non-MathML index (which won't occur in valid MathML). 49 51 RenderBoxModelObject* index() const; 50 52 51 53 int m_overbarLeftPointShift; 54 int m_indexTop; 52 55 }; 53 56 -
trunk/Source/WebCore/rendering/mathml/RenderMathMLSquareRoot.cpp
r114012 r116975 31 31 #include "RenderMathMLSquareRoot.h" 32 32 33 #include "GraphicsContext.h"34 #include "MathMLNames.h"35 #include "PaintInfo.h"36 33 #include "RenderMathMLRow.h" 37 38 using namespace std;39 34 40 35 namespace WebCore { 41 36 42 using namespace MathMLNames;43 44 // FIXME: This whole file should be changed to work with various writing modes. See https://bugs.webkit.org/show_bug.cgi?id=48951.45 46 // Threshold above which the radical shape is modified to look nice with big bases (em)47 const float gThresholdBaseHeightEms = 1.5f;48 // Normal width of the front of the radical sign, before the base & overbar (em)49 const float gFrontWidthEms = 0.75f;50 // Gap between the base and overbar (em)51 const float gSpaceAboveEms = 0.2f;52 // Horizontal position of the bottom point of the radical (* frontWidth)53 const float gRadicalBottomPointXFront = 0.5f;54 // Lower the radical sign's bottom point (px)55 const int gRadicalBottomPointLower = 3;56 // Horizontal position of the top left point of the radical "dip" (* frontWidth)57 const float gRadicalDipLeftPointXFront = 0.8f;58 // Vertical position of the top left point of the radical "dip" (* baseHeight)59 const float gRadicalDipLeftPointYPos = 0.5f;60 // Vertical shift of the left end point of the radical (em)61 const float gRadicalLeftEndYShiftEms = 0.05f;62 // Additional bottom root padding if baseHeight > threshold (em)63 const float gBigRootBottomPaddingEms = 0.2f;64 65 // Radical line thickness (em)66 const float gRadicalLineThicknessEms = 0.02f;67 // Radical thick line thickness (em)68 const float gRadicalThickLineThicknessEms = 0.1f;69 70 37 RenderMathMLSquareRoot::RenderMathMLSquareRoot(Element* element) 71 : RenderMathML Block(element)38 : RenderMathMLRoot(element) 72 39 { 73 40 } … … 78 45 RenderMathMLRow* newMRow = RenderMathMLRow::createAnonymousWithParentRenderer(this); 79 46 80 RenderMathML Block::addChild(newMRow);47 RenderMathMLRoot::addChild(newMRow); 81 48 82 49 // newMRow->isAnonymousBlock() is false because newMRow's display is INLINE_BLOCK, … … 89 56 } 90 57 91 void RenderMathMLSquareRoot::computePreferredLogicalWidths()92 {93 m_intrinsicPaddingStart = static_cast<int>(roundf(gFrontWidthEms * style()->fontSize()));94 95 RenderMathMLBlock::computePreferredLogicalWidths();96 }97 98 void RenderMathMLSquareRoot::computeLogicalHeight()99 {100 int baseHeight = roundToInt(getBoxModelObjectHeight(firstChild()));101 float thresholdHeight = gThresholdBaseHeightEms * style()->fontSize();102 m_intrinsicPaddingAfter = baseHeight > thresholdHeight ? static_cast<int>(roundf(gBigRootBottomPaddingEms * style()->fontSize())) : 0;103 setLogicalHeight(baseHeight + borderAndPaddingLogicalHeight());104 105 RenderMathMLBlock::computeLogicalHeight();106 }107 108 void RenderMathMLSquareRoot::layout()109 {110 m_intrinsicPaddingBefore = static_cast<int>(roundf(gSpaceAboveEms * style()->fontSize()));111 112 RenderMathMLBlock::layout();113 }114 115 void RenderMathMLSquareRoot::paint(PaintInfo& info, const LayoutPoint& paintOffset)116 {117 RenderMathMLBlock::paint(info, paintOffset);118 119 if (info.context->paintingDisabled())120 return;121 122 IntPoint adjustedPaintOffset = roundedIntPoint(paintOffset + location() + computedCSSContentBoxRect().location());123 124 int baseHeight = roundToInt(getBoxModelObjectHeight(firstChild()));125 int overbarWidth = roundToInt(getBoxModelObjectWidth(firstChild()));126 127 int frontWidth = m_intrinsicPaddingStart;128 int overbarLeftPointShift = 0;129 // Base height above which the shape of the root changes130 float thresholdHeight = gThresholdBaseHeightEms * style()->fontSize();131 132 if (baseHeight > thresholdHeight && thresholdHeight) {133 float shift = min<float>((baseHeight - thresholdHeight) / thresholdHeight, 1.0f);134 overbarLeftPointShift = static_cast<int>(shift * gRadicalBottomPointXFront * frontWidth);135 }136 137 overbarWidth += overbarLeftPointShift;138 139 int startX = adjustedPaintOffset.x() + frontWidth;140 141 FloatPoint overbarLeftPoint(startX - overbarLeftPointShift, adjustedPaintOffset.y());142 FloatPoint bottomPoint(startX - gRadicalBottomPointXFront * frontWidth, adjustedPaintOffset.y() + baseHeight + gRadicalBottomPointLower);143 FloatPoint dipLeftPoint(startX - gRadicalDipLeftPointXFront * frontWidth, adjustedPaintOffset.y() + gRadicalDipLeftPointYPos * baseHeight);144 FloatPoint leftEnd(startX - frontWidth, dipLeftPoint.y() + gRadicalLeftEndYShiftEms * style()->fontSize());145 146 GraphicsContextStateSaver stateSaver(*info.context);147 148 info.context->setStrokeThickness(gRadicalLineThicknessEms * style()->fontSize());149 info.context->setStrokeStyle(SolidStroke);150 info.context->setStrokeColor(style()->visitedDependentColor(CSSPropertyColor), ColorSpaceDeviceRGB);151 info.context->setLineJoin(MiterJoin);152 info.context->setMiterLimit(style()->fontSize());153 154 Path root;155 156 root.moveTo(FloatPoint(overbarLeftPoint.x() + overbarWidth, adjustedPaintOffset.y()));157 // draw top158 root.addLineTo(overbarLeftPoint);159 // draw from top left corner to bottom point of radical160 root.addLineTo(bottomPoint);161 // draw from bottom point to top of left part of radical base "dip"162 root.addLineTo(dipLeftPoint);163 // draw to end164 root.addLineTo(leftEnd);165 166 info.context->strokePath(root);167 168 GraphicsContextStateSaver maskStateSaver(*info.context);169 170 // Build a mask to draw the thick part of the root.171 Path mask;172 173 mask.moveTo(overbarLeftPoint);174 mask.addLineTo(bottomPoint);175 mask.addLineTo(dipLeftPoint);176 mask.addLineTo(FloatPoint(2 * dipLeftPoint.x() - leftEnd.x(), 2 * dipLeftPoint.y() - leftEnd.y()));177 178 info.context->clip(mask);179 180 // Draw the thick part of the root.181 info.context->setStrokeThickness(gRadicalThickLineThicknessEms * style()->fontSize());182 info.context->setLineCap(SquareCap);183 184 Path line;185 line.moveTo(bottomPoint);186 line.addLineTo(dipLeftPoint);187 188 info.context->strokePath(line);189 }190 191 58 } 192 59 -
trunk/Source/WebCore/rendering/mathml/RenderMathMLSquareRoot.h
r113749 r116975 29 29 #if ENABLE(MATHML) 30 30 31 #include "RenderMathML Block.h"31 #include "RenderMathMLRoot.h" 32 32 33 33 namespace WebCore { 34 34 35 35 // Render sqrt(base), using radical notation. 36 class RenderMathMLSquareRoot : public RenderMathML Block{36 class RenderMathMLSquareRoot : public RenderMathMLRoot { 37 37 public: 38 38 RenderMathMLSquareRoot(Element*); … … 44 44 45 45 virtual bool createsAnonymousWrapper() const OVERRIDE { return true; } 46 47 virtual void computePreferredLogicalWidths() OVERRIDE;48 virtual void computeLogicalHeight() OVERRIDE;49 virtual void layout() OVERRIDE;50 51 virtual void paint(PaintInfo&, const LayoutPoint&) OVERRIDE;52 46 }; 53 47
Note: See TracChangeset
for help on using the changeset viewer.