Bumping manifests a=b2g-bump
[gecko.git] / layout / generic / nsTextFrameUtils.h
blob26ddf0b6eef5fb18bbb55affdd63595e964aeda6
1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
2 * This Source Code Form is subject to the terms of the Mozilla Public
3 * License, v. 2.0. If a copy of the MPL was not distributed with this
4 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
6 #ifndef NSTEXTFRAMEUTILS_H_
7 #define NSTEXTFRAMEUTILS_H_
9 #include "gfxSkipChars.h"
10 #include "nsBidiUtils.h"
11 #include "nsUnicodeProperties.h"
13 class nsIContent;
14 struct nsStyleText;
16 #define BIG_TEXT_NODE_SIZE 4096
18 #define CH_NBSP 160
19 #define CH_SHY 173
20 #define CH_CJKSP 12288 // U+3000 IDEOGRAPHIC SPACE (CJK Full-Width Space)
22 class nsTextFrameUtils {
23 public:
24 // These constants are used as textrun flags for textframe textruns.
25 enum {
26 // The following flags are set by TransformText
28 // the text has at least one untransformed tab character
29 TEXT_HAS_TAB = 0x010000,
30 // the original text has at least one soft hyphen character
31 TEXT_HAS_SHY = 0x020000,
32 TEXT_WAS_TRANSFORMED = 0x040000,
33 TEXT_UNUSED_FLAG = 0x080000,
35 // The following flags are set by nsTextFrame
37 TEXT_IS_SIMPLE_FLOW = 0x100000,
38 TEXT_INCOMING_WHITESPACE = 0x200000,
39 TEXT_TRAILING_WHITESPACE = 0x400000,
40 TEXT_COMPRESSED_LEADING_WHITESPACE = 0x800000,
41 TEXT_NO_BREAKS = 0x1000000,
42 TEXT_IS_TRANSFORMED = 0x2000000,
43 // This gets set if there's a break opportunity at the end of the textrun.
44 // We normally don't use this break opportunity because the following text
45 // will have a break opportunity at the start, but it's useful for line
46 // layout to know about it in case the following content is not text
47 TEXT_HAS_TRAILING_BREAK = 0x4000000,
49 // This is set if the textrun was created for a textframe whose
50 // NS_FRAME_IS_IN_SINGLE_CHAR_MI flag is set. This occurs if the textframe
51 // belongs to a MathML <mi> element whose embedded text consists of a
52 // single character.
53 TEXT_IS_SINGLE_CHAR_MI = 0x8000000
55 // The following are defined by gfxTextRunWordCache rather than here,
56 // so that it also has access to the _INCOMING flag
57 // TEXT_TRAILING_ARABICCHAR
58 // TEXT_INCOMING_ARABICCHAR
60 // This is defined in gfxTextRunFactory to allow access in gfxFont.
61 // TEXT_USE_MATH_SCRIPT
64 // These constants are used in TransformText to represent context information
65 // from previous textruns.
66 enum {
67 INCOMING_NONE = 0,
68 INCOMING_WHITESPACE = 1,
69 INCOMING_ARABICCHAR = 2
72 /**
73 * Returns true if aChars/aLength are something that make a space
74 * character not be whitespace when they follow the space character
75 * (combining mark or join control, ignoring intervening direction
76 * controls).
78 static bool
79 IsSpaceCombiningSequenceTail(const char16_t* aChars, int32_t aLength) {
80 return aLength > 0 &&
81 (mozilla::unicode::IsClusterExtender(aChars[0]) ||
82 (IsBidiControl(aChars[0]) &&
83 IsSpaceCombiningSequenceTail(aChars + 1, aLength - 1)
88 enum CompressionMode {
89 COMPRESS_NONE,
90 COMPRESS_WHITESPACE,
91 COMPRESS_WHITESPACE_NEWLINE,
92 COMPRESS_NONE_TRANSFORM_TO_SPACE
95 /**
96 * Create a text run from a run of Unicode text. The text may have whitespace
97 * compressed. A preformatted tab is sent to the text run as a single space.
98 * (Tab spacing must be performed by textframe later.) Certain other
99 * characters are discarded.
101 * @param aCompressWhitespace control what is compressed to a
102 * single space character: no compression, compress spaces (not followed
103 * by combining mark) and tabs, compress those plus newlines, or
104 * no compression except newlines are discarded.
105 * @param aIncomingFlags a flag indicating whether there was whitespace
106 * or an Arabic character preceding this text. We set it to indicate if
107 * there's an Arabic character or whitespace preceding the end of this text.
109 static char16_t* TransformText(const char16_t* aText, uint32_t aLength,
110 char16_t* aOutput,
111 CompressionMode aCompression,
112 uint8_t * aIncomingFlags,
113 gfxSkipChars* aSkipChars,
114 uint32_t* aAnalysisFlags);
116 static uint8_t* TransformText(const uint8_t* aText, uint32_t aLength,
117 uint8_t* aOutput,
118 CompressionMode aCompression,
119 uint8_t * aIncomingFlags,
120 gfxSkipChars* aSkipChars,
121 uint32_t* aAnalysisFlags);
123 static void
124 AppendLineBreakOffset(nsTArray<uint32_t>* aArray, uint32_t aOffset)
126 if (aArray->Length() > 0 && (*aArray)[aArray->Length() - 1] == aOffset)
127 return;
128 aArray->AppendElement(aOffset);
131 static uint32_t
132 ComputeApproximateLengthWithWhitespaceCompression(nsIContent *aContent,
133 const nsStyleText
134 *aStyleText);
137 class nsSkipCharsRunIterator {
138 public:
139 enum LengthMode {
140 LENGTH_UNSKIPPED_ONLY = false,
141 LENGTH_INCLUDES_SKIPPED = true
143 nsSkipCharsRunIterator(const gfxSkipCharsIterator& aStart,
144 LengthMode aLengthIncludesSkipped, uint32_t aLength)
145 : mIterator(aStart), mRemainingLength(aLength), mRunLength(0),
146 mVisitSkipped(false),
147 mLengthIncludesSkipped(aLengthIncludesSkipped) {
149 void SetVisitSkipped() { mVisitSkipped = true; }
150 void SetOriginalOffset(int32_t aOffset) {
151 mIterator.SetOriginalOffset(aOffset);
153 void SetSkippedOffset(uint32_t aOffset) {
154 mIterator.SetSkippedOffset(aOffset);
157 // guaranteed to return only positive-length runs
158 bool NextRun();
159 bool IsSkipped() const { return mSkipped; }
160 // Always returns something > 0
161 int32_t GetRunLength() const { return mRunLength; }
162 const gfxSkipCharsIterator& GetPos() const { return mIterator; }
163 int32_t GetOriginalOffset() const { return mIterator.GetOriginalOffset(); }
164 uint32_t GetSkippedOffset() const { return mIterator.GetSkippedOffset(); }
166 private:
167 gfxSkipCharsIterator mIterator;
168 int32_t mRemainingLength;
169 int32_t mRunLength;
170 bool mSkipped;
171 bool mVisitSkipped;
172 bool mLengthIncludesSkipped;
175 #endif /*NSTEXTFRAMEUTILS_H_*/