1/* 2 * Copyright (C) 2010 Alex Milowski (alex@milowski.com). All rights reserved. 3 * Copyright (C) 2013 The MathJax Consortium. 4 * 5 * Redistribution and use in source and binary forms, with or without 6 * modification, are permitted provided that the following conditions 7 * are met: 8 * 1. Redistributions of source code must retain the above copyright 9 * notice, this list of conditions and the following disclaimer. 10 * 2. Redistributions in binary form must reproduce the above copyright 11 * notice, this list of conditions and the following disclaimer in the 12 * documentation and/or other materials provided with the distribution. 13 * 14 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 15 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 16 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 17 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 18 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 19 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 20 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 21 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 22 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 23 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 24 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 25 */ 26 27#ifndef RenderMathMLScripts_h 28#define RenderMathMLScripts_h 29 30#if ENABLE(MATHML) 31 32#include "RenderMathMLBlock.h" 33 34namespace WebCore { 35 36class RenderMathMLScripts; 37 38class RenderMathMLScriptsWrapper : public RenderMathMLBlock { 39 40friend class RenderMathMLScripts; 41 42public: 43 enum WrapperType { Base, SubSupPair }; 44 45 virtual void addChild(RenderObject* child, RenderObject* beforeChild = 0) override; 46 virtual RenderObject* removeChild(RenderObject&) override; 47 48private: 49 RenderMathMLScriptsWrapper(Document& document, PassRef<RenderStyle> style, WrapperType kind) 50 : RenderMathMLBlock(document, WTF::move(style)) 51 , m_kind(kind) 52 { 53 } 54 55 static RenderMathMLScriptsWrapper* createAnonymousWrapper(RenderMathMLScripts* renderObject, WrapperType); 56 57 void addChildInternal(bool normalInsertion, RenderObject* child, RenderObject* beforeChild = 0); 58 RenderObject* removeChildInternal(bool normalRemoval, RenderObject& child); 59 60 virtual const char* renderName() const override { return m_kind == Base ? "Base Wrapper" : "SubSupPair Wrapper"; } 61 virtual bool isRenderMathMLScriptsWrapper() const override final { return true; } 62 63 RenderMathMLScripts* parentMathMLScripts(); 64 65 WrapperType m_kind; 66}; 67 68RENDER_OBJECT_TYPE_CASTS(RenderMathMLScriptsWrapper, isRenderMathMLScriptsWrapper()) 69 70// Render a base with scripts. 71class RenderMathMLScripts : public RenderMathMLBlock { 72 73friend class RenderMathMLScriptsWrapper; 74 75public: 76 RenderMathMLScripts(Element&, PassRef<RenderStyle>); 77 virtual void addChild(RenderObject* child, RenderObject* beforeChild = 0) override; 78 virtual RenderObject* removeChild(RenderObject&) override; 79 80 virtual RenderMathMLOperator* unembellishedOperator(); 81 virtual int firstLineBaseline() const override; 82 83protected: 84 virtual void layout(); 85 86private: 87 void addChildInternal(bool normalInsertion, RenderObject* child, RenderObject* beforeChild = 0); 88 RenderObject* removeChildInternal(bool normalRemoval, RenderObject& child); 89 90 virtual bool isRenderMathMLScripts() const override final { return true; } 91 virtual const char* renderName() const override { return "RenderMathMLScripts"; } 92 93 void fixAnonymousStyleForSubSupPair(RenderObject* subSupPair, bool isPostScript); 94 void fixAnonymousStyles(); 95 96 virtual void styleDidChange(StyleDifference, const RenderStyle* oldStyle) override; 97 98 // Omit our subscript and/or superscript. This may return 0 for a non-MathML base (which 99 // won't occur in valid MathML). 100 RenderBoxModelObject* base() const; 101 102 enum ScriptsType { Sub, Super, SubSup, Multiscripts }; 103 104 ScriptsType m_kind; 105 RenderMathMLScriptsWrapper* m_baseWrapper; 106}; 107 108RENDER_OBJECT_TYPE_CASTS(RenderMathMLScripts, isRenderMathMLScripts()) 109 110} 111 112#endif // ENABLE(MATHML) 113 114#endif // RenderMathMLScripts_h 115