| 1 | /* |
| 2 | * Copyright (C) 1999 Lars Knoll (knoll@kde.org) |
| 3 | * (C) 1999 Antti Koivisto (koivisto@kde.org) |
| 4 | * Copyright (C) 2003-2018 Apple Inc. All rights reserved. |
| 5 | * |
| 6 | * This library is free software; you can redistribute it and/or |
| 7 | * modify it under the terms of the GNU Library General Public |
| 8 | * License as published by the Free Software Foundation; either |
| 9 | * version 2 of the License, or (at your option) any later version. |
| 10 | * |
| 11 | * This library is distributed in the hope that it will be useful, |
| 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 14 | * Library General Public License for more details. |
| 15 | * |
| 16 | * You should have received a copy of the GNU Library General Public License |
| 17 | * along with this library; see the file COPYING.LIB. If not, write to |
| 18 | * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, |
| 19 | * Boston, MA 02110-1301, USA. |
| 20 | * |
| 21 | */ |
| 22 | |
| 23 | #pragma once |
| 24 | |
| 25 | #include "CharacterData.h" |
| 26 | #include "RenderPtr.h" |
| 27 | |
| 28 | namespace WebCore { |
| 29 | |
| 30 | class RenderText; |
| 31 | |
| 32 | class Text : public CharacterData { |
| 33 | WTF_MAKE_ISO_ALLOCATED(Text); |
| 34 | public: |
| 35 | static const unsigned defaultLengthLimit = 1 << 16; |
| 36 | |
| 37 | static Ref<Text> create(Document&, const String&); |
| 38 | static Ref<Text> createWithLengthLimit(Document&, const String&, unsigned positionInString, unsigned lengthLimit = defaultLengthLimit); |
| 39 | static Ref<Text> createEditingText(Document&, const String&); |
| 40 | |
| 41 | virtual ~Text(); |
| 42 | |
| 43 | WEBCORE_EXPORT ExceptionOr<Ref<Text>> splitText(unsigned offset); |
| 44 | |
| 45 | // DOM Level 3: http://www.w3.org/TR/DOM-Level-3-Core/core.html#ID-1312295772 |
| 46 | |
| 47 | WEBCORE_EXPORT String wholeText() const; |
| 48 | WEBCORE_EXPORT RefPtr<Text> replaceWholeText(const String&); |
| 49 | |
| 50 | RenderPtr<RenderText> createTextRenderer(const RenderStyle&); |
| 51 | |
| 52 | bool canContainRangeEndPoint() const final { return true; } |
| 53 | |
| 54 | RenderText* renderer() const; |
| 55 | |
| 56 | void updateRendererAfterContentChange(unsigned offsetOfReplacedData, unsigned lengthOfReplacedData); |
| 57 | |
| 58 | protected: |
| 59 | Text(Document& document, const String& data, ConstructionType type) |
| 60 | : CharacterData(document, data, type) |
| 61 | { |
| 62 | } |
| 63 | |
| 64 | private: |
| 65 | String nodeName() const override; |
| 66 | NodeType nodeType() const override; |
| 67 | Ref<Node> cloneNodeInternal(Document&, CloningOperation) override; |
| 68 | bool childTypeAllowed(NodeType) const override; |
| 69 | |
| 70 | virtual Ref<Text> virtualCreate(const String&); |
| 71 | |
| 72 | #if ENABLE(TREE_DEBUGGING) |
| 73 | void formatForDebugger(char* buffer, unsigned length) const override; |
| 74 | #endif |
| 75 | }; |
| 76 | |
| 77 | } // namespace WebCore |
| 78 | |
| 79 | SPECIALIZE_TYPE_TRAITS_BEGIN(WebCore::Text) |
| 80 | static bool isType(const WebCore::Node& node) { return node.isTextNode(); } |
| 81 | SPECIALIZE_TYPE_TRAITS_END() |
| 82 | |