| 1 | /* |
| 2 | * Copyright (C) 2010 Alex Milowski (alex@milowski.com). All rights reserved. |
| 3 | * |
| 4 | * Redistribution and use in source and binary forms, with or without |
| 5 | * modification, are permitted provided that the following conditions |
| 6 | * are met: |
| 7 | * 1. Redistributions of source code must retain the above copyright |
| 8 | * notice, this list of conditions and the following disclaimer. |
| 9 | * 2. Redistributions in binary form must reproduce the above copyright |
| 10 | * notice, this list of conditions and the following disclaimer in the |
| 11 | * documentation and/or other materials provided with the distribution. |
| 12 | * |
| 13 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
| 14 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
| 15 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
| 16 | * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
| 17 | * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
| 18 | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
| 19 | * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
| 20 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
| 21 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| 22 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
| 23 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 24 | */ |
| 25 | |
| 26 | #pragma once |
| 27 | |
| 28 | #if ENABLE(MATHML) |
| 29 | |
| 30 | #include "MathMLOperatorDictionary.h" |
| 31 | #include "MathOperator.h" |
| 32 | #include "RenderMathMLToken.h" |
| 33 | |
| 34 | namespace WebCore { |
| 35 | |
| 36 | class MathMLOperatorElement; |
| 37 | |
| 38 | class RenderMathMLOperator : public RenderMathMLToken { |
| 39 | WTF_MAKE_ISO_ALLOCATED(RenderMathMLOperator); |
| 40 | public: |
| 41 | RenderMathMLOperator(MathMLOperatorElement&, RenderStyle&&); |
| 42 | RenderMathMLOperator(Document&, RenderStyle&&); |
| 43 | MathMLOperatorElement& element() const; |
| 44 | |
| 45 | void stretchTo(LayoutUnit heightAboveBaseline, LayoutUnit depthBelowBaseline); |
| 46 | void stretchTo(LayoutUnit width); |
| 47 | LayoutUnit stretchSize() const { return isVertical() ? m_stretchHeightAboveBaseline + m_stretchDepthBelowBaseline : m_stretchWidth; } |
| 48 | void resetStretchSize(); |
| 49 | void setStretchWidthLocked(bool stretchWidthLocked) { m_isStretchWidthLocked = stretchWidthLocked; } |
| 50 | bool isStretchWidthLocked() const { return m_isStretchWidthLocked; } |
| 51 | |
| 52 | virtual bool hasOperatorFlag(MathMLOperatorDictionary::Flag) const; |
| 53 | bool isLargeOperatorInDisplayStyle() const { return !hasOperatorFlag(MathMLOperatorDictionary::Stretchy) && hasOperatorFlag(MathMLOperatorDictionary::LargeOp) && mathMLStyle().displayStyle(); } |
| 54 | bool shouldMoveLimits() const { return hasOperatorFlag(MathMLOperatorDictionary::MovableLimits) && !mathMLStyle().displayStyle(); } |
| 55 | virtual bool isVertical() const; |
| 56 | LayoutUnit italicCorrection() const { return m_mathOperator.italicCorrection(); } |
| 57 | |
| 58 | void updateTokenContent() final; |
| 59 | void updateFromElement() final; |
| 60 | virtual UChar32 textContent() const; |
| 61 | bool isStretchy() const { return textContent() && hasOperatorFlag(MathMLOperatorDictionary::Stretchy); } |
| 62 | |
| 63 | protected: |
| 64 | virtual void updateMathOperator(); |
| 65 | virtual LayoutUnit leadingSpace() const; |
| 66 | virtual LayoutUnit trailingSpace() const; |
| 67 | virtual LayoutUnit minSize() const; |
| 68 | virtual LayoutUnit maxSize() const; |
| 69 | virtual bool useMathOperator() const; |
| 70 | |
| 71 | private: |
| 72 | void styleDidChange(StyleDifference, const RenderStyle* oldStyle) final; |
| 73 | void computePreferredLogicalWidths() final; |
| 74 | void layoutBlock(bool relayoutChildren, LayoutUnit pageLogicalHeight = 0_lu) final; |
| 75 | void paint(PaintInfo&, const LayoutPoint&) final; |
| 76 | |
| 77 | const char* renderName() const final { return isAnonymous() ? "RenderMathMLOperator (anonymous)" : "RenderMathMLOperator" ; } |
| 78 | void paintChildren(PaintInfo& forSelf, const LayoutPoint&, PaintInfo& forChild, bool usePrintRect) final; |
| 79 | bool isRenderMathMLOperator() const final { return true; } |
| 80 | bool isInvisibleOperator() const; |
| 81 | |
| 82 | Optional<int> firstLineBaseline() const final; |
| 83 | RenderMathMLOperator* unembellishedOperator() const final { return const_cast<RenderMathMLOperator*>(this); } |
| 84 | |
| 85 | LayoutUnit verticalStretchedOperatorShift() const; |
| 86 | |
| 87 | LayoutUnit m_stretchHeightAboveBaseline { 0 }; |
| 88 | LayoutUnit m_stretchDepthBelowBaseline { 0 }; |
| 89 | LayoutUnit m_stretchWidth; |
| 90 | bool m_isStretchWidthLocked { false }; |
| 91 | |
| 92 | MathOperator m_mathOperator; |
| 93 | }; |
| 94 | |
| 95 | } // namespace WebCore |
| 96 | |
| 97 | SPECIALIZE_TYPE_TRAITS_RENDER_OBJECT(RenderMathMLOperator, isRenderMathMLOperator()) |
| 98 | |
| 99 | #endif // ENABLE(MATHML) |
| 100 | |