⚠ Archived content — this site is no longer maintained.   Current WebKit documentation is at docs.webkit.org.

Changeset 243712 in webkit


Ignore:
Timestamp:
Apr 1, 2019, 2:08:31 PM (7 years ago)
Author:
timothy_horton@apple.com
Message:

Make UIWKDocumentContext rects per-character instead of per-word
https://bugs.webkit.org/show_bug.cgi?id=196459

Reviewed by Wenson Hsieh.

Source/WebCore:

No new tests; adjusted expected results of WebKit.DocumentEditingContext.

  • editing/TextIterator.cpp:

(WebCore::CharacterIterator::CharacterIterator):

  • editing/TextIterator.h:

(WebCore::CharacterIterator::atEnd const):
(WebCore::CharacterIterator::text const):
Add WEBCORE_EXPORT to some things.
Introduce a CharacterIterator constructor that takes Positions, like one that TextIterator has.
Move initializers to the header.

Source/WebKit:

  • WebProcess/WebPage/ios/WebPageIOS.mm:

(WebKit::WebPage::requestDocumentEditingContext):
Switch to CharacterIterator instead of TextIterator directly, to get
per-character rects as the API requests.

Tools:

  • TestWebKitAPI/Tests/WebKitCocoa/DocumentEditingContext.mm:

(TEST):
Adjust test results due to switching to per-character rects.

Location:
trunk
Files:
7 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebCore/ChangeLog

    r243709 r243712  
     12019-04-01  Tim Horton  <timothy_horton@apple.com>
     2
     3        Make UIWKDocumentContext rects per-character instead of per-word
     4        https://bugs.webkit.org/show_bug.cgi?id=196459
     5
     6        Reviewed by Wenson Hsieh.
     7
     8        No new tests; adjusted expected results of WebKit.DocumentEditingContext.
     9
     10        * editing/TextIterator.cpp:
     11        (WebCore::CharacterIterator::CharacterIterator):
     12        * editing/TextIterator.h:
     13        (WebCore::CharacterIterator::atEnd const):
     14        (WebCore::CharacterIterator::text const):
     15        Add WEBCORE_EXPORT to some things.
     16        Introduce a CharacterIterator constructor that takes Positions, like one that TextIterator has.
     17        Move initializers to the header.
     18
    1192019-04-01  Antti Koivisto  <antti@apple.com>
    220
  • trunk/Source/WebCore/editing/TextIterator.cpp

    r243354 r243712  
    15291529CharacterIterator::CharacterIterator(const Range& range, TextIteratorBehavior behavior)
    15301530    : m_underlyingIterator(&range, behavior)
    1531     , m_offset(0)
    1532     , m_runOffset(0)
    1533     , m_atBreak(true)
     1531{
     1532    while (!atEnd() && !m_underlyingIterator.text().length())
     1533        m_underlyingIterator.advance();
     1534}
     1535
     1536CharacterIterator::CharacterIterator(Position start, Position end, TextIteratorBehavior behavior)
     1537    : m_underlyingIterator(start, end, behavior)
    15341538{
    15351539    while (!atEnd() && !m_underlyingIterator.text().length())
  • trunk/Source/WebCore/editing/TextIterator.h

    r243354 r243712  
    256256public:
    257257    explicit CharacterIterator(const Range&, TextIteratorBehavior = TextIteratorDefaultBehavior);
    258    
     258    WEBCORE_EXPORT explicit CharacterIterator(Position start, Position end, TextIteratorBehavior = TextIteratorDefaultBehavior);
     259   
     260    bool atEnd() const { return m_underlyingIterator.atEnd(); }
     261    WEBCORE_EXPORT void advance(int numCharacters);
     262   
     263    StringView text() const { return m_underlyingIterator.text().substring(m_runOffset); }
     264    WEBCORE_EXPORT Ref<Range> range() const;
     265
     266    bool atBreak() const { return m_atBreak; }
     267    int characterOffset() const { return m_offset; }
     268
     269private:
     270    TextIterator m_underlyingIterator;
     271
     272    int m_offset { 0 };
     273    int m_runOffset { 0 };
     274    bool m_atBreak { true };
     275};
     276   
     277class BackwardsCharacterIterator {
     278public:
     279    explicit BackwardsCharacterIterator(const Range&);
     280
    259281    bool atEnd() const { return m_underlyingIterator.atEnd(); }
    260282    void advance(int numCharacters);
    261    
    262     StringView text() const { return m_underlyingIterator.text().substring(m_runOffset); }
     283
    263284    Ref<Range> range() const;
    264285
    265     bool atBreak() const { return m_atBreak; }
    266     int characterOffset() const { return m_offset; }
    267 
    268 private:
    269     TextIterator m_underlyingIterator;
     286private:
     287    SimplifiedBackwardsTextIterator m_underlyingIterator;
    270288
    271289    int m_offset;
     
    273291    bool m_atBreak;
    274292};
    275    
    276 class BackwardsCharacterIterator {
    277 public:
    278     explicit BackwardsCharacterIterator(const Range&);
    279 
    280     bool atEnd() const { return m_underlyingIterator.atEnd(); }
    281     void advance(int numCharacters);
    282 
    283     Ref<Range> range() const;
    284 
    285 private:
    286     SimplifiedBackwardsTextIterator m_underlyingIterator;
    287 
    288     int m_offset;
    289     int m_runOffset;
    290     bool m_atBreak;
    291 };
    292293
    293294// Similar to the TextIterator, except that the chunks of text returned are "well behaved", meaning
  • trunk/Source/WebKit/ChangeLog

    r243711 r243712  
     12019-04-01  Tim Horton  <timothy_horton@apple.com>
     2
     3        Make UIWKDocumentContext rects per-character instead of per-word
     4        https://bugs.webkit.org/show_bug.cgi?id=196459
     5
     6        Reviewed by Wenson Hsieh.
     7
     8        * WebProcess/WebPage/ios/WebPageIOS.mm:
     9        (WebKit::WebPage::requestDocumentEditingContext):
     10        Switch to CharacterIterator instead of TextIterator directly, to get
     11        per-character rects as the API requests.
     12
    1132019-04-01  Chris Dumez  <cdumez@apple.com>
    214
  • trunk/Source/WebKit/WebProcess/WebPage/ios/WebPageIOS.mm

    r243677 r243712  
    35193519
    35203520    if (wantsRects) {
    3521         TextIterator contextIterator(contextBeforeStart.deepEquivalent(), contextAfterEnd.deepEquivalent());
     3521        CharacterIterator contextIterator(contextBeforeStart.deepEquivalent(), contextAfterEnd.deepEquivalent());
    35223522        unsigned currentLocation = 0;
    35233523        while (!contextIterator.atEnd()) {
    35243524            unsigned length = contextIterator.text().length();
    35253525            if (!length) {
    3526                 contextIterator.advance();
     3526                contextIterator.advance(1);
    35273527                continue;
    35283528            }
     
    35303530            DocumentEditingContext::TextRectAndRange rect;
    35313531            rect.rect = contextIterator.range()->absoluteBoundingBox();
    3532             rect.range = { currentLocation, length };
     3532            rect.range = { currentLocation, 1 };
    35333533            context.textRects.append(rect);
    35343534
    3535             currentLocation += length;
    3536             contextIterator.advance();
     3535            currentLocation++;
     3536            contextIterator.advance(1);
    35373537        }
    35383538    }
  • trunk/Tools/ChangeLog

    r243711 r243712  
     12019-04-01  Tim Horton  <timothy_horton@apple.com>
     2
     3        Make UIWKDocumentContext rects per-character instead of per-word
     4        https://bugs.webkit.org/show_bug.cgi?id=196459
     5
     6        Reviewed by Wenson Hsieh.
     7
     8        * TestWebKitAPI/Tests/WebKitCocoa/DocumentEditingContext.mm:
     9        (TEST):
     10        Adjust test results due to switching to per-character rects.
     11
    1122019-04-01  Chris Dumez  <cdumez@apple.com>
    213
  • trunk/Tools/TestWebKitAPI/Tests/WebKitCocoa/DocumentEditingContext.mm

    r243484 r243712  
    207207    EXPECT_NULL(context.contextAfter);
    208208
    209     NSArray<NSValue *> *rects = [context characterRectsForCharacterRange:NSMakeRange(0, 1)];
    210     EXPECT_EQ(1UL, rects.count);
    211     EXPECT_RECT_EQ(0, 0, 92, 24, rects.firstObject.CGRectValue);
     209    NSArray<NSValue *> *rects = [[context characterRectsForCharacterRange:NSMakeRange(0, 4)] sortedArrayUsingComparator:^(NSValue *a, NSValue *b) {
     210        return [@(a.CGRectValue.origin.x) compare:@(b.CGRectValue.origin.x)];
     211    }];
     212    EXPECT_EQ(4UL, rects.count);
     213    EXPECT_RECT_EQ(0, 0, 23, 24, rects[0].CGRectValue);
     214    EXPECT_RECT_EQ(23, 0, 23, 24, rects[1].CGRectValue);
     215    EXPECT_RECT_EQ(46, 0, 23, 24, rects[2].CGRectValue);
     216    EXPECT_RECT_EQ(69, 0, 23, 24, rects[3].CGRectValue);
    212217    rects = [context characterRectsForCharacterRange:NSMakeRange(5, 1)];
    213218    EXPECT_EQ(0UL, rects.count);
     
    217222    rects = [context characterRectsForCharacterRange:NSMakeRange(0, 1)];
    218223    EXPECT_EQ(1UL, rects.count);
    219     EXPECT_RECT_EQ(0, 0, 92, 24, rects.firstObject.CGRectValue);
     224    EXPECT_RECT_EQ(0, 0, 23, 24, rects.firstObject.CGRectValue);
    220225    rects = [context characterRectsForCharacterRange:NSMakeRange(6, 1)];
    221226    EXPECT_EQ(1UL, rects.count);
    222     EXPECT_RECT_EQ(92, 0, 92, 24, rects.firstObject.CGRectValue);
     227    EXPECT_RECT_EQ(138, 0, 23, 24, rects.firstObject.CGRectValue);
    223228
    224229    // Text Input Context
Note: See TracChangeset for help on using the changeset viewer.