Bug 122687 - Extract an iterator/resolver class from calculateAdjustedNodes
Summary: Extract an iterator/resolver class from calculateAdjustedNodes
Status: RESOLVED FIXED
Alias: None
Product: WebKit
Classification: Unclassified
Component: UI Events (show other bugs)
Version: 528+ (Nightly build)
Hardware: Unspecified Unspecified
: P2 Normal
Assignee: Ryosuke Niwa
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2013-10-11 20:01 PDT by Ryosuke Niwa
Modified: 2013-10-11 21:51 PDT (History)
9 users (show)

See Also:


Attachments
Cleanup (9.29 KB, patch)
2013-10-11 20:07 PDT, Ryosuke Niwa
no flags Details | Formatted Diff | Diff
Patch for landing (9.63 KB, patch)
2013-10-11 20:24 PDT, Ryosuke Niwa
no flags Details | Formatted Diff | Diff
Fixed EFL build (9.63 KB, patch)
2013-10-11 20:33 PDT, Ryosuke Niwa
no flags Details | Formatted Diff | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Ryosuke Niwa 2013-10-11 20:01:13 PDT
Right now, we traverse through the DOM tree three times to figure a mouse event.

1. To create EventContexts for each node
2. To set relatedTarget on each context we've created
3. Actually firing events through

We reduce this to at most two traversals.  In this bug, I'm going to extract EventRelatedNodeResolver class, a stageful iterator class, that lets us update the relatedTarget as we walk up the tree.
Using this class, the current calculateAdjustedNodes can be reimplemented as:

static size_t calculateAdjustedNodes(Node* relatedNode, const EventPath& eventPath, Vector<RefPtr<Node>>& adjustedNodes)
{
    EventRelatedNodeResolver it(*relatedNode);

    size_t eventPathSize = eventPath.size();
    for (size_t i = 0; i < eventPathSize; i++)
        adjustedNodes.append(it.moveToParentOrShadowHost(*eventPath.contextAt(i).node()));

    return eventPathSize;
}

This allows us to compute the related targets of event contexts as we create them.
Comment 1 Ryosuke Niwa 2013-10-11 20:07:52 PDT
Created attachment 214046 [details]
Cleanup
Comment 2 Darin Adler 2013-10-11 20:12:02 PDT
Comment on attachment 214046 [details]
Cleanup

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

Surprised that so much if this in terms of nodes rather than elements.

> Source/WebCore/dom/EventContext.h:98
> +    enum TouchListType {
> +        Touches,
> +        TargetTouches,
> +        ChangedTouches,
> +    };

I think this would read nicely on one line.

> Source/WebCore/dom/EventContext.h:100
> +    TouchList* touchList(TouchListType type)

Why a pointer instead of a reference for the return value?

> Source/WebCore/dom/EventContext.h:111
> +        return 0;

nullptr

> Source/WebCore/dom/EventDispatcher.cpp:114
> +        , m_relatedNodeInCurrentTreeScope(0)
> +        , m_currentTreeScope(0)

nullptr

> Source/WebCore/dom/EventDispatcher.cpp:115
> +    { }

When the rest of the definition is vertical, I prefer that this be vertical too:

    {
    }

> Source/WebCore/dom/EventDispatcher.cpp:117
> +    Node* moveToParentOrShadowHost(Node& newTarget)

Does the return value really need to be a pointer?

> Source/WebCore/dom/EventDispatcher.cpp:413
> +        EventRelatedNodeResolver it(*touch.target()->toNode());

I suggest the name resolver rather than it.

> Source/WebCore/dom/EventDispatcher.cpp:436
> +    EventRelatedNodeResolver it(*relatedNode);

I suggest calling this resolver rather than it.
Comment 3 EFL EWS Bot 2013-10-11 20:12:15 PDT
Comment on attachment 214046 [details]
Cleanup

Attachment 214046 [details] did not pass efl-ews (efl):
Output: http://webkit-queues.appspot.com/results/3953292
Comment 4 Ryosuke Niwa 2013-10-11 20:24:07 PDT
Created attachment 214047 [details]
Patch for landing
Comment 5 EFL EWS Bot 2013-10-11 20:29:18 PDT
Comment on attachment 214047 [details]
Patch for landing

Attachment 214047 [details] did not pass efl-ews (efl):
Output: http://webkit-queues.appspot.com/results/3951268
Comment 6 EFL EWS Bot 2013-10-11 20:30:53 PDT
Comment on attachment 214047 [details]
Patch for landing

Attachment 214047 [details] did not pass efl-wk2-ews (efl-wk2):
Output: http://webkit-queues.appspot.com/results/3766348
Comment 7 Ryosuke Niwa 2013-10-11 20:33:32 PDT
Created attachment 214048 [details]
Fixed EFL build
Comment 8 WebKit Commit Bot 2013-10-11 21:51:13 PDT
Comment on attachment 214048 [details]
Fixed EFL build

Clearing flags on attachment: 214048

Committed r157331: <http://trac.webkit.org/changeset/157331>
Comment 9 WebKit Commit Bot 2013-10-11 21:51:16 PDT
All reviewed patches have been landed.  Closing bug.