1 | /* |
2 | * Copyright (C) 2013 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 | #include "SimpleLineLayoutCoverage.h" |
29 | #include "TextFlags.h" |
30 | #include <wtf/Vector.h> |
31 | #include <wtf/text/WTFString.h> |
32 | |
33 | #if COMPILER(MSVC) |
34 | #pragma warning(push) |
35 | #pragma warning(disable: 4200) // Disable "zero-sized array in struct/union" warning |
36 | #endif |
37 | |
38 | namespace WebCore { |
39 | |
40 | class RenderBlockFlow; |
41 | |
42 | namespace SimpleLineLayout { |
43 | |
44 | class RunResolver; |
45 | |
46 | bool canUseFor(const RenderBlockFlow&); |
47 | AvoidanceReasonFlags canUseForWithReason(const RenderBlockFlow&, IncludeReasons); |
48 | |
49 | struct Run { |
50 | #if COMPILER(MSVC) |
51 | Run() { } |
52 | #endif |
53 | Run(unsigned start, unsigned end, float logicalLeft, float logicalRight, bool isEndOfLine, bool hasHyphen) |
54 | : end(end) |
55 | , start(start) |
56 | , isEndOfLine(isEndOfLine) |
57 | , hasHyphen(hasHyphen) |
58 | , logicalLeft(logicalLeft) |
59 | , logicalRight(logicalRight) |
60 | { } |
61 | |
62 | unsigned end; |
63 | unsigned start : 30; |
64 | unsigned isEndOfLine : 1; |
65 | unsigned hasHyphen : 1; |
66 | float logicalLeft; |
67 | float logicalRight; |
68 | // TODO: Move these optional items out of SimpleLineLayout::Run to a supplementary structure. |
69 | float expansion { 0 }; |
70 | ExpansionBehavior expansionBehavior { ForbidLeadingExpansion | ForbidTrailingExpansion }; |
71 | }; |
72 | |
73 | struct SimpleLineStrut { |
74 | unsigned lineBreak; |
75 | float offset; |
76 | }; |
77 | |
78 | class Layout { |
79 | WTF_MAKE_FAST_ALLOCATED; |
80 | public: |
81 | using RunVector = Vector<Run, 10>; |
82 | using SimpleLineStruts = Vector<SimpleLineStrut, 4>; |
83 | static std::unique_ptr<Layout> create(const RunVector&, unsigned lineCount, const RenderBlockFlow&); |
84 | |
85 | ~Layout(); |
86 | |
87 | unsigned lineCount() const { return m_lineCount; } |
88 | |
89 | unsigned runCount() const { return m_runCount; } |
90 | const Run& runAt(unsigned i) const { return m_runs[i]; } |
91 | |
92 | void setIsPaginated() { m_isPaginated = true; } |
93 | bool isPaginated() const { return m_isPaginated; } |
94 | bool hasLineStruts() const { return !m_lineStruts.isEmpty(); } |
95 | void setLineStruts(SimpleLineStruts&& lineStruts) { m_lineStruts = lineStruts; } |
96 | const SimpleLineStruts& struts() const { return m_lineStruts; } |
97 | const RunResolver& runResolver() const; |
98 | |
99 | private: |
100 | Layout(const RunVector&, unsigned lineCount, const RenderBlockFlow&); |
101 | |
102 | unsigned m_lineCount; |
103 | unsigned m_runCount; |
104 | bool m_isPaginated { false }; |
105 | SimpleLineStruts m_lineStruts; |
106 | const RenderBlockFlow& m_blockFlowRenderer; |
107 | mutable std::unique_ptr<RunResolver> m_runResolver; |
108 | Run m_runs[0]; |
109 | }; |
110 | |
111 | std::unique_ptr<Layout> create(RenderBlockFlow&); |
112 | |
113 | } |
114 | } |
115 | |
116 | #if COMPILER(MSVC) |
117 | #pragma warning(pop) |
118 | #endif |
119 | |