Bug 120563 - Add element ancestor iterator
Summary: Add element ancestor iterator
Status: RESOLVED FIXED
Alias: None
Product: WebKit
Classification: Unclassified
Component: DOM (show other bugs)
Version: 528+ (Nightly build)
Hardware: Unspecified Unspecified
: P2 Normal
Assignee: Nobody
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2013-08-31 12:00 PDT by Antti Koivisto
Modified: 2013-09-05 16:20 PDT (History)
3 users (show)

See Also:


Attachments
patch (28.91 KB, patch)
2013-08-31 12:12 PDT, Antti Koivisto
kling: review+
Details | Formatted Diff | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Antti Koivisto 2013-08-31 12:00:42 PDT
rniwa wanted one
Comment 1 Antti Koivisto 2013-08-31 12:12:02 PDT
Created attachment 210201 [details]
patch
Comment 2 Andreas Kling 2013-08-31 13:09:39 PDT
Comment on attachment 210201 [details]
patch

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

> Source/WebCore/ChangeLog:22
> +        auto lineage = elementLineage(this);
> +        for (auto it = lineage.begin(), end = lineage.end(); it != end; ++it) {
> +            Element& element = *it;
> +            ...

Poetic.
Comment 3 Ryosuke Niwa 2013-08-31 15:53:03 PDT
Can we add a version that optionally stops when it hits a node with a certain condition? (Let it take a function pointer or node's member function? e.g. A lot of editing code needs to stop ancestor search once it hits an editing boundary.
Comment 4 Antti Koivisto 2013-09-01 00:53:53 PDT
I don't think anything else than actual iteration belong to iterators. They are stl compatible and you can add your own helpers.

With stl you can do things like:

auto lineage = elementLineage(this);
auto nearestEditable = std::find_if(lineage.begin(), lineage.end(), [](Element& e) { return e.rendererIsEditable(); } );
Comment 5 Antti Koivisto 2013-09-01 03:45:38 PDT
You could have *Adapter class that give ancestor ranges the editing code wants, something like:

auto editableAncestors = ancestorsWithinEditableBounds(this);
Comment 6 Antti Koivisto 2013-09-01 03:47:56 PDT
https://trac.webkit.org/r154940

Dropped Node* version of the interface functions in favour of Element only. Call sites should be tightened as needed.

Added lineageOfType<>.