Bug 209129 - Move most of TextIterator off of live ranges
Summary: Move most of TextIterator off of live ranges
Status: RESOLVED FIXED
Alias: None
Product: WebKit
Classification: Unclassified
Component: HTML Editing (show other bugs)
Version: WebKit Nightly Build
Hardware: All All
: P2 Normal
Assignee: Darin Adler
URL:
Keywords: InRadar
Depends on:
Blocks: 209932
  Show dependency treegraph
 
Reported: 2020-03-15 15:56 PDT by Darin Adler
Modified: 2020-04-03 12:10 PDT (History)
20 users (show)

See Also:


Attachments
Patch (104.80 KB, patch)
2020-03-15 16:45 PDT, Darin Adler
no flags Details | Formatted Diff | Diff
Patch (104.73 KB, patch)
2020-03-15 22:35 PDT, Darin Adler
koivisto: review+
Details | Formatted Diff | Diff
Crash Log from ews122 (114.11 KB, patch)
2020-03-16 10:24 PDT, Aakash Jain
no flags Details | Formatted Diff | Diff
Patch (121.01 KB, patch)
2020-03-16 12:01 PDT, Darin Adler
no flags Details | Formatted Diff | Diff
Patch (113.42 KB, patch)
2020-03-16 12:08 PDT, Darin Adler
no flags Details | Formatted Diff | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Darin Adler 2020-03-15 15:56:31 PDT
Move most of TextIterator off of live ranges
Comment 1 Darin Adler 2020-03-15 16:45:52 PDT Comment hidden (obsolete)
Comment 2 Darin Adler 2020-03-15 16:52:13 PDT Comment hidden (obsolete)
Comment 3 Darin Adler 2020-03-15 22:35:38 PDT
Created attachment 393633 [details]
Patch
Comment 4 Antti Koivisto 2020-03-16 00:13:28 PDT
Comment on attachment 393633 [details]
Patch

View in context: https://bugs.webkit.org/attachment.cgi?id=393633&action=review

> Source/WebCore/ChangeLog:17
> +        - Re-remove the include of SimpleRange.h from TextIterator.h. Instead, files that
> +          use TextIterator.h will include SimpleRange.h as needed. This probably re-breaks
> +          unified builds, but the fix will be to add includes of SimpleRange.h elsewhere,
> +          not to TextIterator.h itself.

Does this lead to fewer includes somewhere? Presumably at least every cpp file using TextIterator directly is going to need SimpleRange anyway.

If not, this might add unnecessary maintenance burden.

> Source/WebCore/accessibility/AXObjectCache.cpp:1905
> +    for (TextIterator it(*range); !it.atEnd(); it.advance()) {

Not sure if it is worth the effort but it would be nice to eventually be able to do something like

for (auto& textItem : textIteratorRange(*range))

> Source/WebKit/WebProcess/InjectedBundle/API/mac/WKDOMTextIterator.mm:52
> -    _textIterator = makeUnique<WebCore::TextIterator>(WebKit::toWebCoreRange(range));
> +    if (!range)
> +        return self;
> +
> +    _textIterator = makeUnique<WebCore::TextIterator>(*WebKit::toWebCoreRange(range));

I suppose an alternative in these cased would be to construct a TextIterator with empty range? That would lead to fewer null checks in other parts of the code and maybe fewer chances to get things wrong.
Comment 5 Antti Koivisto 2020-03-16 00:15:13 PDT
Comment on attachment 393633 [details]
Patch

View in context: https://bugs.webkit.org/attachment.cgi?id=393633&action=review

> Source/WebCore/dom/Range.h:46
> +// FIXME: Rename to LiveRange, while leaving the DOM-exposed name as Range.

Good idea!
Comment 6 Darin Adler 2020-03-16 08:43:31 PDT
Comment on attachment 393633 [details]
Patch

View in context: https://bugs.webkit.org/attachment.cgi?id=393633&action=review

Need to fix the iOS test failure before landing.

>> Source/WebCore/ChangeLog:17
>> +          not to TextIterator.h itself.
> 
> Does this lead to fewer includes somewhere? Presumably at least every cpp file using TextIterator directly is going to need SimpleRange anyway.
> 
> If not, this might add unnecessary maintenance burden.

There are functions in TextIterator.h that you can use without SimpleRange; like using an iterator created elsewhere and passed to you, for example. But, yes, still not 100% sure this is better. Would be willing to do the reverse and add it here and remove all the unnecessary places it’s included elsewhere.

>> Source/WebCore/accessibility/AXObjectCache.cpp:1905
>> +    for (TextIterator it(*range); !it.atEnd(); it.advance()) {
> 
> Not sure if it is worth the effort but it would be nice to eventually be able to do something like
> 
> for (auto& textItem : textIteratorRange(*range))

I like that idea. I think it’s worth it. It’s how I would design the text iterator if I was creating it now. I will eventually come back and do that.

>> Source/WebKit/WebProcess/InjectedBundle/API/mac/WKDOMTextIterator.mm:52
>> +    _textIterator = makeUnique<WebCore::TextIterator>(*WebKit::toWebCoreRange(range));
> 
> I suppose an alternative in these cased would be to construct a TextIterator with empty range? That would lead to fewer null checks in other parts of the code and maybe fewer chances to get things wrong.

Even an empty SimoleRange requires at least one node, which I don’t have here. But I could add a default constructor to TextIterator that makes an empty iterator. I chose this approach because the class is so small (only 5 null checks needed) and was already heap-allocating the TextIterator. But I would happily consider an alternative.
Comment 7 Antti Koivisto 2020-03-16 09:38:02 PDT
> There are functions in TextIterator.h that you can use without SimpleRange;
> like using an iterator created elsewhere and passed to you, for example.
> But, yes, still not 100% sure this is better. Would be willing to do the
> reverse and add it here and remove all the unnecessary places it’s included
> elsewhere.

I'd prefer that.

> Even an empty SimoleRange requires at least one node, which I don’t have
> here. But I could add a default constructor to TextIterator that makes an
> empty iterator. I chose this approach because the class is so small (only 5
> null checks needed) and was already heap-allocating the TextIterator. But I
> would happily consider an alternative.

Note that there is another similar class in WebKitLegacy following this pattern. I'm ok with the current approach too if you prefer it.
Comment 8 Aakash Jain 2020-03-16 10:24:49 PDT
Created attachment 393658 [details]
Crash Log from ews122

Manually copied crash log from ews122 from https://ews-build.webkit.org/#/builders/24/builds/13112
Comment 9 Darin Adler 2020-03-16 11:36:43 PDT
(In reply to Antti Koivisto from comment #7)
> > There are functions in TextIterator.h that you can use without SimpleRange;
> > like using an iterator created elsewhere and passed to you, for example.
> > But, yes, still not 100% sure this is better. Would be willing to do the
> > reverse and add it here and remove all the unnecessary places it’s included
> > elsewhere.
> 
> I'd prefer that.

Sure thing. I came to that conclusion already and was already working on it.

> > Even an empty SimoleRange requires at least one node, which I don’t have
> > here. But I could add a default constructor to TextIterator that makes an
> > empty iterator. I chose this approach because the class is so small (only 5
> > null checks needed) and was already heap-allocating the TextIterator. But I
> > would happily consider an alternative.
> 
> Note that there is another similar class in WebKitLegacy following this
> pattern. I'm ok with the current approach too if you prefer it.

Yes, it’s the same class, just copied and pasted for Legacy vs. Modern WebKit. I will stick with this approach for now. Could always come back later.
Comment 10 Darin Adler 2020-03-16 12:01:15 PDT Comment hidden (obsolete)
Comment 11 Darin Adler 2020-03-16 12:08:02 PDT
Created attachment 393670 [details]
Patch
Comment 12 Darin Adler 2020-03-16 16:02:16 PDT
Committed r258525: <https://trac.webkit.org/changeset/258525>
Comment 13 Radar WebKit Bug Importer 2020-03-16 16:03:15 PDT
<rdar://problem/60514402>