layout/generic/nsTextFrameUtils.h

Thu, 22 Jan 2015 13:21:57 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Thu, 22 Jan 2015 13:21:57 +0100
branch
TOR_BUG_9701
changeset 15
b8a032363ba2
permissions
-rw-r--r--

Incorporate requested changes from Mozilla in review:
https://bugzilla.mozilla.org/show_bug.cgi?id=1123480#c6

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

mercurial