| 1 | /* |
| 2 | * Copyright (C) 2016 Igalia S.L. 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 | #include "config.h" |
| 27 | #include "RenderMathMLFencedOperator.h" |
| 28 | |
| 29 | #if ENABLE(MATHML) |
| 30 | |
| 31 | #include "MathMLOperatorDictionary.h" |
| 32 | #include "MathMLOperatorElement.h" |
| 33 | #include <wtf/IsoMallocInlines.h> |
| 34 | |
| 35 | namespace WebCore { |
| 36 | |
| 37 | using namespace MathMLOperatorDictionary; |
| 38 | |
| 39 | WTF_MAKE_ISO_ALLOCATED_IMPL(RenderMathMLFencedOperator); |
| 40 | |
| 41 | RenderMathMLFencedOperator::RenderMathMLFencedOperator(Document& document, RenderStyle&& style, const String& operatorString, MathMLOperatorDictionary::Form form, unsigned short flags) |
| 42 | : RenderMathMLOperator(document, WTFMove(style)) |
| 43 | , m_operatorForm(form) |
| 44 | , m_operatorFlags(flags) |
| 45 | { |
| 46 | updateOperatorContent(operatorString); |
| 47 | } |
| 48 | |
| 49 | void RenderMathMLFencedOperator::updateOperatorContent(const String& operatorString) |
| 50 | { |
| 51 | m_operatorChar = MathMLOperatorElement::parseOperatorChar(operatorString); |
| 52 | |
| 53 | // We try and read spacing and boolean properties from the operator dictionary. |
| 54 | // However we preserve the Fence and Separator properties specified in the constructor. |
| 55 | if (auto entry = search(m_operatorChar.character, m_operatorForm, true)) { |
| 56 | m_leadingSpaceInMathUnit = entry.value().leadingSpaceInMathUnit; |
| 57 | m_trailingSpaceInMathUnit = entry.value().trailingSpaceInMathUnit; |
| 58 | m_operatorFlags = (m_operatorFlags & (MathMLOperatorDictionary::Fence | MathMLOperatorDictionary::Separator)) | entry.value().flags; |
| 59 | } else { |
| 60 | m_operatorFlags &= MathMLOperatorDictionary::Fence | MathMLOperatorDictionary::Separator; // Flags are disabled by default. |
| 61 | m_leadingSpaceInMathUnit = 5; // Default spacing is thickmathspace. |
| 62 | m_trailingSpaceInMathUnit = 5; // Default spacing is thickmathspace. |
| 63 | } |
| 64 | |
| 65 | updateMathOperator(); |
| 66 | } |
| 67 | |
| 68 | LayoutUnit RenderMathMLFencedOperator::leadingSpace() const |
| 69 | { |
| 70 | MathMLElement::Length leadingSpace; |
| 71 | leadingSpace.type = MathMLElement::LengthType::MathUnit; |
| 72 | leadingSpace.value = static_cast<float>(m_leadingSpaceInMathUnit); |
| 73 | return toUserUnits(leadingSpace, style(), 0); |
| 74 | } |
| 75 | |
| 76 | LayoutUnit RenderMathMLFencedOperator::trailingSpace() const |
| 77 | { |
| 78 | MathMLElement::Length trailingSpace; |
| 79 | trailingSpace.type = MathMLElement::LengthType::MathUnit; |
| 80 | trailingSpace.value = static_cast<float>(m_trailingSpaceInMathUnit); |
| 81 | return toUserUnits(trailingSpace, style(), 0); |
| 82 | } |
| 83 | |
| 84 | } |
| 85 | |
| 86 | #endif |
| 87 | |