Bug 1740831 Part 1 - Replace LineBreaker::WordBreak with WordBreakRule. r=m_kato

LineBreaker::WordBreak is just an alias of WordBreakRule in Segmenter.h. This is
to reduce the dependency of the legacy LineBreaker.

Differential Revision: https://phabricator.services.mozilla.com/D131025
This commit is contained in:
Ting-Yu Lin 2021-11-15 17:20:35 +00:00
parent 346a4dcdd2
commit 638eb14439
6 changed files with 31 additions and 31 deletions

View File

@ -18,6 +18,7 @@ using mozilla::AutoRestore;
using mozilla::intl::LineBreaker;
using mozilla::intl::Locale;
using mozilla::intl::LocaleParser;
using mozilla::intl::WordBreakRule;
nsLineBreaker::nsLineBreaker()
: mCurrentWordLanguage(nullptr),
@ -26,7 +27,7 @@ nsLineBreaker::nsLineBreaker()
mScriptIsChineseOrJapanese(false),
mAfterBreakableSpace(false),
mBreakHere(false),
mWordBreak(LineBreaker::WordBreak::Normal),
mWordBreak(WordBreakRule::Normal),
mStrictness(LineBreaker::Strictness::Auto),
mWordContinuation(false) {}
@ -76,7 +77,7 @@ nsresult nsLineBreaker::FlushCurrentWord() {
// For break-strict set everything internal to "break", otherwise
// to "no break"!
memset(breakState.Elements(),
mWordBreak == LineBreaker::WordBreak::BreakAll
mWordBreak == WordBreakRule::BreakAll
? gfxTextRun::CompressedGlyph::FLAG_BREAK_TYPE_NORMAL
: gfxTextRun::CompressedGlyph::FLAG_BREAK_TYPE_NONE,
length * sizeof(uint8_t));
@ -243,7 +244,7 @@ nsresult nsLineBreaker::AppendText(nsAtom* aHyphenationLanguage,
if (aSink && !noBreaksNeeded) {
breakState[offset] =
mBreakHere || (mAfterBreakableSpace && !isBreakableSpace) ||
mWordBreak == LineBreaker::WordBreak::BreakAll ||
mWordBreak == WordBreakRule::BreakAll ||
mStrictness == LineBreaker::Strictness::Anywhere
? gfxTextRun::CompressedGlyph::FLAG_BREAK_TYPE_NORMAL
: gfxTextRun::CompressedGlyph::FLAG_BREAK_TYPE_NONE;
@ -408,7 +409,7 @@ nsresult nsLineBreaker::AppendText(nsAtom* aHyphenationLanguage,
// will be set by nsILineBreaker, we don't consider CJK at this point.
breakState[offset] =
mBreakHere || (mAfterBreakableSpace && !isBreakableSpace) ||
mWordBreak == LineBreaker::WordBreak::BreakAll ||
mWordBreak == WordBreakRule::BreakAll ||
mStrictness == LineBreaker::Strictness::Anywhere
? gfxTextRun::CompressedGlyph::FLAG_BREAK_TYPE_NORMAL
: gfxTextRun::CompressedGlyph::FLAG_BREAK_TYPE_NONE;

View File

@ -174,10 +174,9 @@ class nsLineBreaker {
nsresult Reset(bool* aTrailingBreak);
/*
* Set word-break mode for linebreaker. This is set by word-break property.
* @param aMode is LineBreaker::WordBreak::* value.
* Set word-break mode for line breaker. This is set by word-break property.
*/
void SetWordBreak(mozilla::intl::LineBreaker::WordBreak aMode) {
void SetWordBreak(mozilla::intl::WordBreakRule aMode) {
// If current word is non-empty and mode is changing, flush the breaker.
if (aMode != mWordBreak && !mCurrentWord.IsEmpty()) {
nsresult rv = FlushCurrentWord();
@ -187,7 +186,7 @@ class nsLineBreaker {
// If previous mode was break-all, we should allow a break here.
// XXX (jfkthame) css-text spec seems unclear on this, raised question in
// https://github.com/w3c/csswg-drafts/issues/3897
if (mWordBreak == mozilla::intl::LineBreaker::WordBreak::BreakAll) {
if (mWordBreak == mozilla::intl::WordBreakRule::BreakAll) {
mBreakHere = true;
}
}
@ -272,8 +271,8 @@ class nsLineBreaker {
// True if a break must be allowed at the current position because
// a run of breakable whitespace ends here
bool mBreakHere;
// line break mode by "word-break" style
mozilla::intl::LineBreaker::WordBreak mWordBreak;
// Break rules for letters from the "word-break" property.
mozilla::intl::WordBreakRule mWordBreak;
// strictness of break rules, from line-break property
mozilla::intl::LineBreaker::Strictness mStrictness;
// Should the text be treated as continuing a word-in-progress (for purposes

View File

@ -941,7 +941,7 @@ int32_t LineBreaker::Next(const char16_t* aText, uint32_t aLen, uint32_t aPos) {
// XXX(Bug 1631371) Check if this should use a fallible operation as it
// pretended earlier.
breakState.AppendElements(end - begin);
ComputeBreakPositions(aText + begin, end - begin, WordBreak::Normal,
ComputeBreakPositions(aText + begin, end - begin, WordBreakRule::Normal,
Strictness::Auto, false, breakState.Elements());
ret = aPos;
@ -981,11 +981,9 @@ static bool SuppressBreakForKeepAll(uint32_t aPrev, uint32_t aCh) {
affectedByKeepAll(GetLineBreakClass(aCh));
}
void LineBreaker::ComputeBreakPositions(const char16_t* aChars,
uint32_t aLength, WordBreak aWordBreak,
Strictness aLevel,
bool aIsChineseOrJapanese,
uint8_t* aBreakBefore) {
void LineBreaker::ComputeBreakPositions(
const char16_t* aChars, uint32_t aLength, WordBreakRule aWordBreak,
Strictness aLevel, bool aIsChineseOrJapanese, uint8_t* aBreakBefore) {
uint32_t cur;
int8_t lastClass = CLASS_NONE;
ContextState state(aChars, aLength);
@ -1027,7 +1025,7 @@ void LineBreaker::ComputeBreakPositions(const char16_t* aChars,
// _CLOSE_LIKE_CHARACTER, or _NUMERIC by GetClass(), but those classes also
// include others that we don't want to touch here, so we re-check the
// Unicode line-break class to determine which ones to modify.
if (aWordBreak == WordBreak::BreakAll &&
if (aWordBreak == WordBreakRule::BreakAll &&
(cl == CLASS_CHARACTER || cl == CLASS_CLOSE ||
cl == CLASS_CLOSE_LIKE_CHARACTER || cl == CLASS_NUMERIC)) {
auto cls = GetLineBreakClass(ch);
@ -1053,14 +1051,14 @@ void LineBreaker::ComputeBreakPositions(const char16_t* aChars,
if (allowBreak) {
// word-break:keep-all suppresses breaks between certain line-break
// classes.
if (aWordBreak == WordBreak::KeepAll &&
if (aWordBreak == WordBreakRule::KeepAll &&
SuppressBreakForKeepAll(prev(), ch)) {
allowBreak = false;
}
// We also don't allow a break within a run of U+3000 chars unless
// word-break:break-all is in effect.
if (ch == 0x3000 && prev() == 0x3000 &&
aWordBreak != WordBreak::BreakAll) {
aWordBreak != WordBreakRule::BreakAll) {
allowBreak = false;
}
}
@ -1082,7 +1080,7 @@ void LineBreaker::ComputeBreakPositions(const char16_t* aChars,
}
}
if (aWordBreak == WordBreak::BreakAll) {
if (aWordBreak == WordBreakRule::BreakAll) {
// For break-all, we don't need to run a dictionary-based breaking
// algorithm, we just allow breaks between all grapheme clusters.
ClusterIterator ci(aChars + cur, end - cur);
@ -1111,7 +1109,8 @@ void LineBreaker::ComputeBreakPositions(const char16_t* aChars,
}
void LineBreaker::ComputeBreakPositions(const uint8_t* aChars, uint32_t aLength,
WordBreak aWordBreak, Strictness aLevel,
WordBreakRule aWordBreak,
Strictness aLevel,
bool aIsChineseOrJapanese,
uint8_t* aBreakBefore) {
uint32_t cur;
@ -1131,7 +1130,7 @@ void LineBreaker::ComputeBreakPositions(const uint8_t* aChars, uint32_t aLength,
state.NotifyNonHyphenCharacter(ch);
cl = GetClass(ch, aLevel, aIsChineseOrJapanese);
}
if (aWordBreak == WordBreak::BreakAll &&
if (aWordBreak == WordBreakRule::BreakAll &&
(cl == CLASS_CHARACTER || cl == CLASS_CLOSE ||
cl == CLASS_CLOSE_LIKE_CHARACTER || cl == CLASS_NUMERIC)) {
auto cls = GetLineBreakClass(ch);
@ -1147,7 +1146,7 @@ void LineBreaker::ComputeBreakPositions(const uint8_t* aChars, uint32_t aLength,
allowBreak =
(state.UseConservativeBreaking() ? GetPairConservative(lastClass, cl)
: GetPair(lastClass, cl)) &&
(aWordBreak != WordBreak::KeepAll ||
(aWordBreak != WordBreakRule::KeepAll ||
!SuppressBreakForKeepAll(aChars[cur - 1], ch));
}
aBreakBefore[cur] = allowBreak;

View File

@ -5,7 +5,7 @@
#ifndef mozilla_intl_LineBreaker_h__
#define mozilla_intl_LineBreaker_h__
#include "nscore.h"
#include <cstdint>
#include "mozilla/intl/Segmenter.h"
@ -13,10 +13,10 @@
namespace mozilla {
namespace intl {
enum class WordBreakRule : uint8_t;
class LineBreaker final {
public:
using WordBreak = WordBreakRule;
using Strictness = LineBreakRule;
// LineBreaker is a utility class with only static methods. No need to
@ -40,11 +40,11 @@ class LineBreaker final {
// aLength is the length of the aText array and also the length of the
// aBreakBefore output array.
static void ComputeBreakPositions(const char16_t* aText, uint32_t aLength,
WordBreak aWordBreak, Strictness aLevel,
WordBreakRule aWordBreak, Strictness aLevel,
bool aIsChineseOrJapanese,
uint8_t* aBreakBefore);
static void ComputeBreakPositions(const uint8_t* aText, uint32_t aLength,
WordBreak aWordBreak, Strictness aLevel,
WordBreakRule aWordBreak, Strictness aLevel,
bool aIsChineseOrJapanese,
uint8_t* aBreakBefore);
};

View File

@ -5,7 +5,7 @@
#ifndef mozilla_intl_WordBreaker_h__
#define mozilla_intl_WordBreaker_h__
#include "nscore.h"
#include <cstdint>
#define NS_WORDBREAKER_NEED_MORE_TEXT -1

View File

@ -2689,6 +2689,7 @@ static bool HasCompressedLeadingWhitespace(
void BuildTextRunsScanner::SetupBreakSinksForTextRun(gfxTextRun* aTextRun,
const void* aTextPtr) {
using mozilla::intl::LineBreaker;
using mozilla::intl::WordBreakRule;
// textruns have uniform language
const nsStyleFont* styleFont = mMappedFlows[0].mStartFrame->StyleFont();
@ -2710,15 +2711,15 @@ void BuildTextRunsScanner::SetupBreakSinksForTextRun(gfxTextRun* aTextRun,
auto wordBreak = styleText->EffectiveWordBreak();
switch (wordBreak) {
case StyleWordBreak::BreakAll:
mLineBreaker.SetWordBreak(LineBreaker::WordBreak::BreakAll);
mLineBreaker.SetWordBreak(WordBreakRule::BreakAll);
break;
case StyleWordBreak::KeepAll:
mLineBreaker.SetWordBreak(LineBreaker::WordBreak::KeepAll);
mLineBreaker.SetWordBreak(WordBreakRule::KeepAll);
break;
case StyleWordBreak::Normal:
default:
MOZ_ASSERT(wordBreak == StyleWordBreak::Normal);
mLineBreaker.SetWordBreak(LineBreaker::WordBreak::Normal);
mLineBreaker.SetWordBreak(WordBreakRule::Normal);
break;
}
switch (styleText->mLineBreak) {