Changeset 116975 in webkit


Ignore:
Timestamp:
May 14, 2012 11:57:34 AM (12 years ago)
Author:
commit-queue@webkit.org
Message:

Unify RenderMathMLSquareRoot.cpp and RenderMathMLRoot.cpp
https://bugs.webkit.org/show_bug.cgi?id=86319

Patch by David Barton <Dave Barton> on 2012-05-14
Reviewed by Darin Adler.

Source/WebCore:

Most of RenderMathMLSquareRoot.cpp is duplicated in RenderMathMLRoot.cpp and can be
eliminated. We also define RenderMathMLRoot::computePreferredLogicalWidths().

Test: mathml/presentation/mroot-pref-width.html

  • rendering/mathml/RenderMathMLRoot.cpp:

(WebCore::RenderMathMLRoot::computePreferredLogicalWidths):
(WebCore::RenderMathMLRoot::layout):
(WebCore::RenderMathMLRoot::paint):

  • rendering/mathml/RenderMathMLRoot.h:
  • rendering/mathml/RenderMathMLSquareRoot.cpp:

(WebCore::RenderMathMLSquareRoot::RenderMathMLSquareRoot):
(WebCore::RenderMathMLSquareRoot::addChild):

  • rendering/mathml/RenderMathMLSquareRoot.h:

LayoutTests:

  • mathml/presentation/mroot-pref-width.html: Added.
  • platform/mac/mathml/presentation/mroot-pref-width-expected.png: Added.
  • platform/mac/mathml/presentation/mroot-pref-width-expected.txt: Added.
Location:
trunk
Files:
3 added
6 edited

Legend:

Unmodified
Added
Removed
  • trunk/LayoutTests/ChangeLog

    r116972 r116975  
     12012-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
    1122012-05-14  Allan Sandfeld Jensen  <allan.jensen@nokia.com>
    213
  • trunk/Source/WebCore/ChangeLog

    r116974 r116975  
     12012-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
    1232012-05-14  MORITA Hajime  <morrita@google.com>
    224
  • trunk/Source/WebCore/rendering/mathml/RenderMathMLRoot.cpp

    r114012 r116975  
    3232
    3333#include "GraphicsContext.h"
    34 #include "MathMLNames.h"
    3534#include "PaintInfo.h"
    3635
     
    3938namespace WebCore {
    4039   
    41 using namespace MathMLNames;
    42 
    4340// FIXME: This whole file should be changed to work with various writing modes. See https://bugs.webkit.org/show_bug.cgi?id=48951.
    4441
     
    5552// Horizontal position of the top left point of the radical "dip" (* frontWidth)
    5653const 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)
     55const float gSqrtRadicalDipLeftPointYPos = 0.5f;
     56// Vertical position of the top left point of an nth root radical "dip" (* baseHeight)
     57const float gRootRadicalDipLeftPointYPos = 0.625f;
    5958// Vertical shift of the left end point of the radical (em)
    6059const float gRadicalLeftEndYShiftEms = 0.05f;
     
    8281}
    8382
     83void 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
     127void 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
    84142void RenderMathMLRoot::paint(PaintInfo& info, const LayoutPoint& paintOffset)
    85143{
     
    89147        return;
    90148   
    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;
    95154   
    96155    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;
    105160   
    106161    FloatPoint overbarLeftPoint(startX - m_overbarLeftPointShift, adjustedPaintOffset.y());
    107162    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);
    109164    FloatPoint leftEnd(startX - frontWidth, dipLeftPoint.y() + gRadicalLeftEndYShiftEms * style()->fontSize());
    110165   
     
    154209}
    155210
    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 changes
    166     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 
    196211}
    197212
  • trunk/Source/WebCore/rendering/mathml/RenderMathMLRoot.h

    r114012 r116975  
    3333namespace WebCore {
    3434   
    35 // Render base^(1/index), using radical notation.
     35// Render base^(1/index), or sqrt(base) via the derived class RenderMathMLSquareRoot, using radical notation.
    3636class RenderMathMLRoot : public RenderMathMLBlock {
    3737public:
     
    4646    virtual const char* renderName() const { return "RenderMathMLRoot"; }
    4747   
     48    virtual void computePreferredLogicalWidths() OVERRIDE;
     49   
    4850    // This may return 0 for a non-MathML index (which won't occur in valid MathML).
    4951    RenderBoxModelObject* index() const;
    5052   
    5153    int m_overbarLeftPointShift;
     54    int m_indexTop;
    5255};
    5356   
  • trunk/Source/WebCore/rendering/mathml/RenderMathMLSquareRoot.cpp

    r114012 r116975  
    3131#include "RenderMathMLSquareRoot.h"
    3232
    33 #include "GraphicsContext.h"
    34 #include "MathMLNames.h"
    35 #include "PaintInfo.h"
    3633#include "RenderMathMLRow.h"
    37 
    38 using namespace std;
    3934
    4035namespace WebCore {
    4136   
    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    
    7037RenderMathMLSquareRoot::RenderMathMLSquareRoot(Element* element)
    71     : RenderMathMLBlock(element)
     38    : RenderMathMLRoot(element)
    7239{
    7340}
     
    7845        RenderMathMLRow* newMRow = RenderMathMLRow::createAnonymousWithParentRenderer(this);
    7946       
    80         RenderMathMLBlock::addChild(newMRow);
     47        RenderMathMLRoot::addChild(newMRow);
    8148       
    8249        // newMRow->isAnonymousBlock() is false because newMRow's display is INLINE_BLOCK,
     
    8956}
    9057
    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 changes
    130     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 top
    158     root.addLineTo(overbarLeftPoint);
    159     // draw from top left corner to bottom point of radical
    160     root.addLineTo(bottomPoint);
    161     // draw from bottom point to top of left part of radical base "dip"
    162     root.addLineTo(dipLeftPoint);
    163     // draw to end
    164     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 
    19158}
    19259
  • trunk/Source/WebCore/rendering/mathml/RenderMathMLSquareRoot.h

    r113749 r116975  
    2929#if ENABLE(MATHML)
    3030
    31 #include "RenderMathMLBlock.h"
     31#include "RenderMathMLRoot.h"
    3232
    3333namespace WebCore {
    3434   
    3535// Render sqrt(base), using radical notation.
    36 class RenderMathMLSquareRoot : public RenderMathMLBlock {
     36class RenderMathMLSquareRoot : public RenderMathMLRoot {
    3737public:
    3838    RenderMathMLSquareRoot(Element*);
     
    4444   
    4545    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;
    5246};
    5347   
Note: See TracChangeset for help on using the changeset viewer.