1/*
2 * Copyright (C) 2009 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#include "config.h"
27#include "RenderMathMLFenced.h"
28
29#if ENABLE(MATHML)
30
31#include "FontSelector.h"
32#include "MathMLNames.h"
33#include "MathMLRowElement.h"
34#include "RenderInline.h"
35#include "RenderMathMLFencedOperator.h"
36#include "RenderText.h"
37#include "RenderTreeBuilder.h"
38#include <wtf/IsoMallocInlines.h>
39#include <wtf/text/StringBuilder.h>
40
41namespace WebCore {
42
43using namespace MathMLNames;
44
45WTF_MAKE_ISO_ALLOCATED_IMPL(RenderMathMLFenced);
46
47static const char* gOpeningBraceChar = "(";
48static const char* gClosingBraceChar = ")";
49
50RenderMathMLFenced::RenderMathMLFenced(MathMLRowElement& element, RenderStyle&& style)
51 : RenderMathMLRow(element, WTFMove(style))
52{
53}
54
55void RenderMathMLFenced::updateFromElement()
56{
57 const auto& fenced = element();
58
59 // The open operator defaults to a left parenthesis.
60 auto& open = fenced.attributeWithoutSynchronization(MathMLNames::openAttr);
61 m_open = open.isNull() ? gOpeningBraceChar : open;
62
63 // The close operator defaults to a right parenthesis.
64 auto& close = fenced.attributeWithoutSynchronization(MathMLNames::closeAttr);
65 m_close = close.isNull() ? gClosingBraceChar : close;
66
67 auto& separators = fenced.attributeWithoutSynchronization(MathMLNames::separatorsAttr);
68 if (!separators.isNull()) {
69 StringBuilder characters;
70 for (unsigned i = 0; i < separators.length(); i++) {
71 if (!isSpaceOrNewline(separators[i]))
72 characters.append(separators[i]);
73 }
74 m_separators = !characters.length() ? 0 : characters.toString().impl();
75 } else {
76 // The separator defaults to a single comma.
77 m_separators = StringImpl::create(",");
78 }
79
80 if (firstChild()) {
81 // FIXME: The mfenced element fails to update dynamically when its open, close and separators attributes are changed (https://bugs.webkit.org/show_bug.cgi?id=57696).
82 if (is<RenderMathMLFencedOperator>(*firstChild()))
83 downcast<RenderMathMLFencedOperator>(*firstChild()).updateOperatorContent(m_open);
84 m_closeFenceRenderer->updateOperatorContent(m_close);
85 }
86}
87
88}
89
90#endif
91