| 1 | /* |
| 2 | * (C) 1999 Lars Knoll (knoll@kde.org) |
| 3 | * (C) 2000 Dirk Mueller (mueller@kde.org) |
| 4 | * Copyright (C) 2004, 2005, 2006, 2007 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 "RenderText.h" |
| 26 | |
| 27 | namespace WebCore { |
| 28 | |
| 29 | // Used to represent a text substring of an element, e.g., for text runs that are split because of |
| 30 | // first letter and that must therefore have different styles (and positions in the render tree). |
| 31 | // We cache offsets so that text transformations can be applied in such a way that we can recover |
| 32 | // the original unaltered string from our corresponding DOM node. |
| 33 | class RenderTextFragment final : public RenderText { |
| 34 | WTF_MAKE_ISO_ALLOCATED(RenderTextFragment); |
| 35 | public: |
| 36 | RenderTextFragment(Text&, const String&, int startOffset, int length); |
| 37 | RenderTextFragment(Document&, const String&, int startOffset, int length); |
| 38 | RenderTextFragment(Document&, const String&); |
| 39 | |
| 40 | virtual ~RenderTextFragment(); |
| 41 | |
| 42 | bool canBeSelectionLeaf() const override; |
| 43 | |
| 44 | unsigned start() const { return m_start; } |
| 45 | unsigned end() const { return m_end; } |
| 46 | |
| 47 | RenderBoxModelObject* firstLetter() const { return m_firstLetter.get(); } |
| 48 | void setFirstLetter(RenderBoxModelObject& firstLetter) { m_firstLetter = makeWeakPtr(firstLetter); } |
| 49 | |
| 50 | RenderBlock* blockForAccompanyingFirstLetter(); |
| 51 | |
| 52 | void setContentString(const String& text); |
| 53 | StringImpl* contentString() const { return m_contentString.impl(); } |
| 54 | |
| 55 | void setText(const String&, bool force = false) override; |
| 56 | |
| 57 | const String& altText() const { return m_altText; } |
| 58 | void setAltText(const String& altText) { m_altText = altText; } |
| 59 | |
| 60 | private: |
| 61 | bool isTextFragment() const override { return true; } |
| 62 | void styleDidChange(StyleDifference, const RenderStyle* oldStyle) override; |
| 63 | |
| 64 | UChar previousCharacter() const override; |
| 65 | |
| 66 | unsigned m_start; |
| 67 | unsigned m_end; |
| 68 | // Alternative description that can be used for accessibility instead of the native text. |
| 69 | String m_altText; |
| 70 | String m_contentString; |
| 71 | WeakPtr<RenderBoxModelObject> m_firstLetter; |
| 72 | }; |
| 73 | |
| 74 | } // namespace WebCore |
| 75 | |
| 76 | SPECIALIZE_TYPE_TRAITS_BEGIN(WebCore::RenderTextFragment) |
| 77 | static bool isType(const WebCore::RenderText& renderer) { return renderer.isTextFragment(); } |
| 78 | static bool isType(const WebCore::RenderObject& renderer) { return is<WebCore::RenderText>(renderer) && isType(downcast<WebCore::RenderText>(renderer)); } |
| 79 | SPECIALIZE_TYPE_TRAITS_END() |
| 80 | |