2017-10-27 20:33:53 +03:00
|
|
|
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
|
|
|
/* vim: set ts=8 sts=2 et sw=2 tw=80: */
|
|
|
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
2012-05-21 15:12:37 +04:00
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
2007-01-16 23:51:52 +03:00
|
|
|
|
|
|
|
#ifndef NSTEXTFRAMEUTILS_H_
|
|
|
|
#define NSTEXTFRAMEUTILS_H_
|
|
|
|
|
|
|
|
#include "gfxSkipChars.h"
|
2014-09-24 21:10:56 +04:00
|
|
|
#include "nsBidiUtils.h"
|
2007-01-16 23:51:52 +03:00
|
|
|
|
2012-04-17 02:32:12 +04:00
|
|
|
class nsIContent;
|
|
|
|
struct nsStyleText;
|
|
|
|
|
2019-05-22 08:18:48 +03:00
|
|
|
namespace mozilla {
|
|
|
|
namespace dom {
|
|
|
|
class Text;
|
|
|
|
}
|
|
|
|
} // namespace mozilla
|
|
|
|
|
2007-01-16 23:51:52 +03:00
|
|
|
#define BIG_TEXT_NODE_SIZE 4096
|
|
|
|
|
2007-07-03 03:36:59 +04:00
|
|
|
#define CH_NBSP 160
|
|
|
|
#define CH_SHY 173
|
|
|
|
#define CH_CJKSP 12288 // U+3000 IDEOGRAPHIC SPACE (CJK Full-Width Space)
|
|
|
|
|
2007-01-16 23:51:52 +03:00
|
|
|
class nsTextFrameUtils {
|
|
|
|
public:
|
|
|
|
// These constants are used as textrun flags for textframe textruns.
|
2017-05-05 00:27:05 +03:00
|
|
|
enum class Flags : uint16_t {
|
2007-01-16 23:51:52 +03:00
|
|
|
// The following flags are set by TransformText
|
|
|
|
|
|
|
|
// the text has at least one untransformed tab character
|
2019-04-26 02:03:04 +03:00
|
|
|
HasTab = 0x01,
|
2007-01-16 23:51:52 +03:00
|
|
|
// the original text has at least one soft hyphen character
|
2019-04-26 02:03:04 +03:00
|
|
|
HasShy = 0x02,
|
|
|
|
UnusedFlags = 0x0C,
|
2007-01-16 23:51:52 +03:00
|
|
|
|
|
|
|
// The following flags are set by nsTextFrame
|
|
|
|
|
2019-04-26 02:03:04 +03:00
|
|
|
IsSimpleFlow = 0x10,
|
|
|
|
IncomingWhitespace = 0x20,
|
|
|
|
TrailingWhitespace = 0x40,
|
|
|
|
CompressedLeadingWhitespace = 0x80,
|
|
|
|
NoBreaks = 0x100,
|
|
|
|
IsTransformed = 0x200,
|
2007-12-03 11:22:07 +03:00
|
|
|
// This gets set if there's a break opportunity at the end of the textrun.
|
|
|
|
// We normally don't use this break opportunity because the following text
|
|
|
|
// will have a break opportunity at the start, but it's useful for line
|
|
|
|
// layout to know about it in case the following content is not text
|
2019-04-26 02:03:04 +03:00
|
|
|
HasTrailingBreak = 0x400,
|
2013-12-02 20:49:27 +04:00
|
|
|
|
|
|
|
// This is set if the textrun was created for a textframe whose
|
2014-01-16 09:10:09 +04:00
|
|
|
// NS_FRAME_IS_IN_SINGLE_CHAR_MI flag is set. This occurs if the textframe
|
2013-12-02 20:49:27 +04:00
|
|
|
// belongs to a MathML <mi> element whose embedded text consists of a
|
|
|
|
// single character.
|
2019-04-26 02:03:04 +03:00
|
|
|
IsSingleCharMi = 0x800,
|
2016-07-24 12:40:01 +03:00
|
|
|
|
|
|
|
// This is set if the text run might be observing for glyph changes.
|
2019-04-26 02:03:04 +03:00
|
|
|
MightHaveGlyphChanges = 0x1000,
|
2017-05-05 00:25:16 +03:00
|
|
|
|
|
|
|
// For internal use by the memory reporter when accounting for
|
|
|
|
// storage used by textruns.
|
|
|
|
// Because the reporter may visit each textrun multiple times while
|
|
|
|
// walking the frame trees and textrun cache, it needs to mark
|
|
|
|
// textruns that have been seen so as to avoid multiple-accounting.
|
2019-04-26 02:03:04 +03:00
|
|
|
RunSizeAccounted = 0x2000,
|
2017-05-05 00:25:16 +03:00
|
|
|
|
|
|
|
// The following are defined by gfxTextRunFactory rather than here,
|
|
|
|
// so that it also has access to the _INCOMING and MATH_SCRIPT flags
|
|
|
|
// for shaping purposes.
|
|
|
|
// They live in the gfxShapedText::mFlags field rather than the
|
|
|
|
// gfxTextRun::mFlags2 field.
|
2009-01-01 16:04:13 +03:00
|
|
|
// TEXT_TRAILING_ARABICCHAR
|
|
|
|
// TEXT_INCOMING_ARABICCHAR
|
2014-01-30 19:59:16 +04:00
|
|
|
// TEXT_USE_MATH_SCRIPT
|
2008-12-18 23:12:53 +03:00
|
|
|
};
|
|
|
|
|
|
|
|
// These constants are used in TransformText to represent context information
|
|
|
|
// from previous textruns.
|
|
|
|
enum { INCOMING_NONE = 0, INCOMING_WHITESPACE = 1, INCOMING_ARABICCHAR = 2 };
|
2007-01-16 23:51:52 +03:00
|
|
|
|
|
|
|
/**
|
2011-10-17 18:59:28 +04:00
|
|
|
* Returns true if aChars/aLength are something that make a space
|
2014-09-24 21:10:56 +04:00
|
|
|
* character not be whitespace when they follow the space character
|
|
|
|
* (combining mark or join control, ignoring intervening direction
|
|
|
|
* controls).
|
2007-01-16 23:51:52 +03:00
|
|
|
*/
|
2014-01-04 19:02:17 +04:00
|
|
|
static bool IsSpaceCombiningSequenceTail(const char16_t* aChars,
|
2019-04-02 20:00:49 +03:00
|
|
|
int32_t aLength);
|
2017-01-12 04:27:02 +03:00
|
|
|
static bool IsSpaceCombiningSequenceTail(const uint8_t* aChars,
|
|
|
|
int32_t aLength) {
|
|
|
|
return false;
|
|
|
|
}
|
2007-01-16 23:51:52 +03:00
|
|
|
|
2008-08-12 12:31:56 +04:00
|
|
|
enum CompressionMode {
|
|
|
|
COMPRESS_NONE,
|
|
|
|
COMPRESS_WHITESPACE,
|
2012-09-07 09:42:19 +04:00
|
|
|
COMPRESS_WHITESPACE_NEWLINE,
|
2014-06-05 07:25:15 +04:00
|
|
|
COMPRESS_NONE_TRANSFORM_TO_SPACE
|
2008-08-12 12:31:56 +04:00
|
|
|
};
|
|
|
|
|
2007-01-16 23:51:52 +03:00
|
|
|
/**
|
|
|
|
* Create a text run from a run of Unicode text. The text may have whitespace
|
|
|
|
* compressed. A preformatted tab is sent to the text run as a single space.
|
|
|
|
* (Tab spacing must be performed by textframe later.) Certain other
|
|
|
|
* characters are discarded.
|
2017-01-12 04:27:01 +03:00
|
|
|
*
|
2016-11-28 15:45:37 +03:00
|
|
|
* @param aCompression control what is compressed to a
|
2008-08-12 12:31:56 +04:00
|
|
|
* single space character: no compression, compress spaces (not followed
|
2012-09-07 09:42:19 +04:00
|
|
|
* by combining mark) and tabs, compress those plus newlines, or
|
|
|
|
* no compression except newlines are discarded.
|
2008-12-18 23:12:53 +03:00
|
|
|
* @param aIncomingFlags a flag indicating whether there was whitespace
|
|
|
|
* or an Arabic character preceding this text. We set it to indicate if
|
|
|
|
* there's an Arabic character or whitespace preceding the end of this text.
|
2007-01-16 23:51:52 +03:00
|
|
|
*/
|
2017-01-12 04:27:02 +03:00
|
|
|
template <class CharT>
|
|
|
|
static CharT* TransformText(const CharT* aText, uint32_t aLength,
|
|
|
|
CharT* aOutput, CompressionMode aCompression,
|
|
|
|
uint8_t* aIncomingFlags, gfxSkipChars* aSkipChars,
|
2017-05-05 00:27:05 +03:00
|
|
|
nsTextFrameUtils::Flags* aAnalysisFlags);
|
2007-11-26 11:27:06 +03:00
|
|
|
|
2017-01-17 08:45:43 +03:00
|
|
|
/**
|
|
|
|
* Returns whether aChar is a character that nsTextFrameUtils::TransformText
|
|
|
|
* might mark as skipped. This is used by
|
|
|
|
* SVGTextContentElement::GetNumberOfChars to know whether reflowing frames,
|
|
|
|
* so that we have the results of TransformText, is required, or whether we
|
|
|
|
* can use a fast path instead.
|
|
|
|
*/
|
|
|
|
template <class CharT>
|
|
|
|
static bool IsSkippableCharacterForTransformText(CharT aChar);
|
|
|
|
|
2012-08-22 19:56:38 +04:00
|
|
|
static void AppendLineBreakOffset(nsTArray<uint32_t>* aArray,
|
|
|
|
uint32_t aOffset) {
|
2019-05-29 23:48:41 +03:00
|
|
|
if (aArray->Length() > 0 && (*aArray)[aArray->Length() - 1] == aOffset) {
|
2007-11-26 11:27:06 +03:00
|
|
|
return;
|
2019-05-29 23:48:41 +03:00
|
|
|
}
|
2007-11-26 11:27:06 +03:00
|
|
|
aArray->AppendElement(aOffset);
|
|
|
|
}
|
|
|
|
|
2012-04-17 02:32:12 +04:00
|
|
|
static uint32_t ComputeApproximateLengthWithWhitespaceCompression(
|
2019-05-22 08:18:48 +03:00
|
|
|
mozilla::dom::Text* aText, const nsStyleText* aStyleText);
|
2007-01-16 23:51:52 +03:00
|
|
|
};
|
|
|
|
|
2017-05-05 00:27:05 +03:00
|
|
|
MOZ_MAKE_ENUM_CLASS_BITWISE_OPERATORS(nsTextFrameUtils::Flags)
|
|
|
|
|
2007-01-16 23:51:52 +03:00
|
|
|
class nsSkipCharsRunIterator {
|
|
|
|
public:
|
|
|
|
enum LengthMode {
|
2011-10-17 18:59:28 +04:00
|
|
|
LENGTH_UNSKIPPED_ONLY = false,
|
|
|
|
LENGTH_INCLUDES_SKIPPED = true
|
2007-01-16 23:51:52 +03:00
|
|
|
};
|
|
|
|
nsSkipCharsRunIterator(const gfxSkipCharsIterator& aStart,
|
2018-04-13 16:01:28 +03:00
|
|
|
LengthMode aLengthIncludesSkipped, uint32_t aLength)
|
|
|
|
: mIterator(aStart),
|
|
|
|
mRemainingLength(aLength),
|
|
|
|
mRunLength(0),
|
2018-07-12 09:42:14 +03:00
|
|
|
mSkipped(false),
|
|
|
|
mVisitSkipped(false),
|
2018-04-13 16:01:28 +03:00
|
|
|
mLengthIncludesSkipped(aLengthIncludesSkipped) {}
|
2011-10-17 18:59:28 +04:00
|
|
|
void SetVisitSkipped() { mVisitSkipped = true; }
|
2012-08-22 19:56:38 +04:00
|
|
|
void SetOriginalOffset(int32_t aOffset) {
|
2007-01-16 23:51:52 +03:00
|
|
|
mIterator.SetOriginalOffset(aOffset);
|
|
|
|
}
|
2012-08-22 19:56:38 +04:00
|
|
|
void SetSkippedOffset(uint32_t aOffset) {
|
2007-01-16 23:51:52 +03:00
|
|
|
mIterator.SetSkippedOffset(aOffset);
|
|
|
|
}
|
|
|
|
|
|
|
|
// guaranteed to return only positive-length runs
|
2011-09-29 10:19:26 +04:00
|
|
|
bool NextRun();
|
|
|
|
bool IsSkipped() const { return mSkipped; }
|
2007-01-16 23:51:52 +03:00
|
|
|
// Always returns something > 0
|
2012-08-22 19:56:38 +04:00
|
|
|
int32_t GetRunLength() const { return mRunLength; }
|
2007-01-16 23:51:52 +03:00
|
|
|
const gfxSkipCharsIterator& GetPos() const { return mIterator; }
|
2012-08-22 19:56:38 +04:00
|
|
|
int32_t GetOriginalOffset() const { return mIterator.GetOriginalOffset(); }
|
|
|
|
uint32_t GetSkippedOffset() const { return mIterator.GetSkippedOffset(); }
|
2007-01-16 23:51:52 +03:00
|
|
|
|
|
|
|
private:
|
|
|
|
gfxSkipCharsIterator mIterator;
|
2012-08-22 19:56:38 +04:00
|
|
|
int32_t mRemainingLength;
|
|
|
|
int32_t mRunLength;
|
2011-09-29 10:19:26 +04:00
|
|
|
bool mSkipped;
|
|
|
|
bool mVisitSkipped;
|
|
|
|
bool mLengthIncludesSkipped;
|
2007-01-16 23:51:52 +03:00
|
|
|
};
|
|
|
|
|
|
|
|
#endif /*NSTEXTFRAMEUTILS_H_*/
|