[webkit-changes] [WebKit/WebKit] 99eac4: Teach TextBreakIterator about strict and loose lin...

Myles C. Maxfield noreply at github.com
Mon May 22 14:12:26 PDT 2023


  Branch: refs/heads/main
  Home:   https://github.com/WebKit/WebKit
  Commit: 99eac467073eccfa5ff272ce4c8212273b2c1040
      https://github.com/WebKit/WebKit/commit/99eac467073eccfa5ff272ce4c8212273b2c1040
  Author: Myles C. Maxfield <mmaxfield at apple.com>
  Date:   2023-05-22 (Mon, 22 May 2023)

  Changed paths:
    M Source/WTF/wtf/text/LineBreakIteratorPoolICU.h
    M Source/WTF/wtf/text/TextBreakIterator.cpp
    M Source/WTF/wtf/text/TextBreakIterator.h
    M Source/WTF/wtf/text/WTFString.h
    M Source/WTF/wtf/text/cocoa/TextBreakIteratorInternalICUCocoa.cpp
    M Source/WTF/wtf/text/icu/TextBreakIteratorICU.h
    M Source/WebCore/platform/graphics/ComplexTextController.cpp
    M Source/WebCore/platform/graphics/ComposedCharacterClusterTextIterator.h
    M Source/WebCore/rendering/RenderText.cpp
    M Tools/TestWebKitAPI/Tests/WTF/TextBreakIterator.cpp

  Log Message:
  -----------
  Teach TextBreakIterator about strict and loose line breaking behaviors
https://bugs.webkit.org/show_bug.cgi?id=257108
rdar://109634206

Reviewed by Cameron McCormack.

This is the first part of our line breaker refactoring. We currently have 2 totally separate classes,
both of which can perform line breaking: TextBreakIterator and LazyLineBreakIterator.

TextBreakIterator has multiple backends - it can be backed by either ICU or Core Foundation. It also
supports all kinds of text segmentation: caret positions, grapheme cluster segmentation, etc.

LazyLineBreakIterator only works with ICU, and can only do line breaking. However, it supports loose
and strict line breaking modes, and supports a "prior context."

It's kind of a shame that we have 2 classes which both do similar things, so I'm going to try to
unify them into a single class which can do everything. I'd like to improve TextBreakIterator to be
able to do everything that LazyLineBreakIterator can do, and then delete LazyLineBreakIterator,
because I think that's going to be the most straightforward way of doing it.

This patch teaches TextBreakIterator about the different line breaking behaviors, by turning the
"mode" enum into a variant, and giving the Line struct a behavior enum.

* Source/WTF/wtf/text/TextBreakIterator.cpp:
(WTF::mapModeToBackingIterator):
* Source/WTF/wtf/text/TextBreakIterator.h:
(WTF::TextBreakIterator::LineMode::operator== const):
(WTF::TextBreakIterator::CaretMode::operator== const):
(WTF::TextBreakIterator::DeleteMode::operator== const):
(WTF::TextBreakIterator::CharacterMode::operator== const):
(WTF::LazyLineBreakIterator::get):
(WTF::TextBreakIteratorCache::TextBreakIteratorCache): Deleted.
* Source/WTF/wtf/text/WTFString.h:
(WTF::StringLiterals::operator _str):
* Source/WTF/wtf/text/cocoa/TextBreakIteratorInternalICUCocoa.cpp:
(WTF::mapModeToBackingIterator):
* Source/WTF/wtf/text/icu/TextBreakIteratorICU.h:
(WTF::TextBreakIteratorICU::TextBreakIteratorICU):
(WTF::TextBreakIteratorICU::makeLocaleWithBreakKeyword):
* Source/WebCore/platform/graphics/ComplexTextController.cpp:
(WebCore::ComplexTextController::offsetForPosition):
(WebCore::ComplexTextController::collectComplexTextRuns):
* Source/WebCore/platform/graphics/ComposedCharacterClusterTextIterator.h:
(WebCore::ComposedCharacterClusterTextIterator::ComposedCharacterClusterTextIterator):
* Source/WebCore/rendering/RenderText.cpp:
(WebCore::RenderText::previousOffset const):
(WebCore::RenderText::previousOffsetForBackwardDeletion const):
(WebCore::RenderText::nextOffset const):
* Tools/TestWebKitAPI/Tests/WTF/TextBreakIterator.cpp:
(TestWebKitAPI::TEST):

Canonical link: https://commits.webkit.org/264376@main




More information about the webkit-changes mailing list