|
Lines 1-149
a/Source/WebCore/layout/formattingContexts/inline/InlineLineRun.h_sec1
|
| 1 |
/* |
|
|
| 2 |
* Copyright (C) 2020 Apple Inc. 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 APPLE INC. AND ITS CONTRIBUTORS ``AS IS'' |
| 14 |
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, |
| 15 |
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR |
| 16 |
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS |
| 17 |
* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR |
| 18 |
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF |
| 19 |
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS |
| 20 |
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN |
| 21 |
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) |
| 22 |
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF |
| 23 |
* THE POSSIBILITY OF SUCH DAMAGE. |
| 24 |
*/ |
| 25 |
|
| 26 |
#pragma once |
| 27 |
|
| 28 |
#if ENABLE(LAYOUT_FORMATTING_CONTEXT) |
| 29 |
|
| 30 |
#include "InlineRect.h" |
| 31 |
#include "LayoutBox.h" |
| 32 |
#include "TextFlags.h" |
| 33 |
|
| 34 |
namespace WebCore { |
| 35 |
namespace Layout { |
| 36 |
|
| 37 |
struct Run { |
| 38 |
WTF_MAKE_STRUCT_FAST_ALLOCATED; |
| 39 |
struct Text { |
| 40 |
WTF_MAKE_STRUCT_FAST_ALLOCATED; |
| 41 |
public: |
| 42 |
Text(size_t position, size_t length, const String& originalContent, String adjustedContentToRender = String(), bool hasHyphen = false); |
| 43 |
|
| 44 |
size_t start() const { return m_start; } |
| 45 |
size_t end() const { return start() + length(); } |
| 46 |
size_t length() const { return m_length; } |
| 47 |
StringView originalContent() const { return StringView(m_originalContent).substring(m_start, m_length); } |
| 48 |
StringView renderedContent() const { return m_adjustedContentToRender.isNull() ? originalContent() : m_adjustedContentToRender; } |
| 49 |
|
| 50 |
bool hasHyphen() const { return m_hasHyphen; } |
| 51 |
|
| 52 |
private: |
| 53 |
size_t m_start { 0 }; |
| 54 |
size_t m_length { 0 }; |
| 55 |
bool m_hasHyphen { false }; |
| 56 |
String m_originalContent; |
| 57 |
String m_adjustedContentToRender; |
| 58 |
}; |
| 59 |
|
| 60 |
enum class Type { |
| 61 |
Text, |
| 62 |
SoftLineBreak, |
| 63 |
LineBreakBox, |
| 64 |
AtomicInlineLevelBox, |
| 65 |
NonRootInlineBox, |
| 66 |
RootInlineBox, |
| 67 |
GenericInlineLevelBox |
| 68 |
}; |
| 69 |
struct Expansion; |
| 70 |
Run(size_t lineIndex, Type, const Box&, const InlineRect&, const InlineRect& inkOverflow, Expansion, std::optional<Text> = std::nullopt, bool hasContent = true); |
| 71 |
|
| 72 |
bool isText() const { return m_type == Type::Text; } |
| 73 |
bool isSoftLineBreak() const { return m_type == Type::SoftLineBreak; } |
| 74 |
bool isLineBreakBox() const { return m_type == Type::LineBreakBox; } |
| 75 |
bool isLineBreak() const { return isSoftLineBreak() || isLineBreakBox(); } |
| 76 |
bool isAtomicInlineLevelBox() const { return m_type == Type::AtomicInlineLevelBox; } |
| 77 |
bool isInlineBox() const { return isNonRootInlineBox() || isRootInlineBox(); } |
| 78 |
bool isNonRootInlineBox() const { return m_type == Type::NonRootInlineBox; } |
| 79 |
bool isRootInlineBox() const { return m_type == Type::RootInlineBox; } |
| 80 |
bool isGenericInlineLevelBox() const { return m_type == Type::GenericInlineLevelBox; } |
| 81 |
bool isInlineLevelBox() const { return isAtomicInlineLevelBox() || isLineBreakBox() || isInlineBox() || isGenericInlineLevelBox(); } |
| 82 |
bool isNonRootInlineLevelBox() const { return isInlineLevelBox() && !isRootInlineBox(); } |
| 83 |
Type type() const { return m_type; } |
| 84 |
|
| 85 |
bool hasContent() const { return m_hasContent; } |
| 86 |
|
| 87 |
const InlineRect& logicalRect() const { return m_logicalRect; } |
| 88 |
const InlineRect& inkOverflow() const { return m_inkOverflow; } |
| 89 |
|
| 90 |
InlineLayoutUnit logicalTop() const { return logicalRect().top(); } |
| 91 |
InlineLayoutUnit logicalBottom() const { return logicalRect().bottom(); } |
| 92 |
InlineLayoutUnit logicalLeft() const { return logicalRect().left(); } |
| 93 |
InlineLayoutUnit logicalRight() const { return logicalRect().right(); } |
| 94 |
|
| 95 |
InlineLayoutUnit logicalWidth() const { return logicalRect().width(); } |
| 96 |
InlineLayoutUnit logicalHeight() const { return logicalRect().height(); } |
| 97 |
|
| 98 |
void moveVertically(InlineLayoutUnit offset) { m_logicalRect.moveVertically(offset); } |
| 99 |
void adjustInkOverflow(const InlineRect& childBorderBox) { return m_inkOverflow.expandToContain(childBorderBox); } |
| 100 |
|
| 101 |
std::optional<Text>& text() { return m_text; } |
| 102 |
const std::optional<Text>& text() const { return m_text; } |
| 103 |
|
| 104 |
struct Expansion { |
| 105 |
ExpansionBehavior behavior { DefaultExpansion }; |
| 106 |
InlineLayoutUnit horizontalExpansion { 0 }; |
| 107 |
}; |
| 108 |
Expansion expansion() const { return m_expansion; } |
| 109 |
|
| 110 |
const Box& layoutBox() const { return *m_layoutBox; } |
| 111 |
const RenderStyle& style() const { return layoutBox().style(); } |
| 112 |
|
| 113 |
size_t lineIndex() const { return m_lineIndex; } |
| 114 |
|
| 115 |
private: |
| 116 |
const size_t m_lineIndex { 0 }; |
| 117 |
const Type m_type { Type::GenericInlineLevelBox }; |
| 118 |
WeakPtr<const Layout::Box> m_layoutBox; |
| 119 |
InlineRect m_logicalRect; |
| 120 |
InlineRect m_inkOverflow; |
| 121 |
bool m_hasContent { true }; |
| 122 |
Expansion m_expansion; |
| 123 |
std::optional<Text> m_text; |
| 124 |
}; |
| 125 |
|
| 126 |
inline Run::Run(size_t lineIndex, Type type, const Layout::Box& layoutBox, const InlineRect& logicalRect, const InlineRect& inkOverflow, Expansion expansion, std::optional<Text> text, bool hasContent) |
| 127 |
: m_lineIndex(lineIndex) |
| 128 |
, m_type(type) |
| 129 |
, m_layoutBox(makeWeakPtr(layoutBox)) |
| 130 |
, m_logicalRect(logicalRect) |
| 131 |
, m_inkOverflow(inkOverflow) |
| 132 |
, m_hasContent(hasContent) |
| 133 |
, m_expansion(expansion) |
| 134 |
, m_text(text) |
| 135 |
{ |
| 136 |
} |
| 137 |
|
| 138 |
inline Run::Text::Text(size_t start, size_t length, const String& originalContent, String adjustedContentToRender, bool hasHyphen) |
| 139 |
: m_start(start) |
| 140 |
, m_length(length) |
| 141 |
, m_hasHyphen(hasHyphen) |
| 142 |
, m_originalContent(originalContent) |
| 143 |
, m_adjustedContentToRender(adjustedContentToRender) |
| 144 |
{ |
| 145 |
} |
| 146 |
|
| 147 |
} |
| 148 |
} |
| 149 |
#endif |