layout/generic/nsTextFrameUtils.h

Wed, 31 Dec 2014 06:09:35 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:09:35 +0100
changeset 0
6474c204b198
permissions
-rw-r--r--

Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.

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

mercurial