Bug 120862 - MouseEnter and MouseLeave may be emitted on Document nodes
Summary: MouseEnter and MouseLeave may be emitted on Document nodes
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: Allan Sandfeld Jensen
URL:
Keywords:
Depends on:
Blocks: 120786 121026
  Show dependency treegraph
 
Reported: 2013-09-06 08:59 PDT by Allan Sandfeld Jensen
Modified: 2013-09-09 07:38 PDT (History)
6 users (show)

See Also:


Attachments
Patch (9.39 KB, patch)
2013-09-06 09:04 PDT, Allan Sandfeld Jensen
no flags Details | Formatted Diff | Diff
Archive of layout-test-results from webkit-ews-09 for mac-mountainlion-wk2 (452.49 KB, application/zip)
2013-09-07 02:26 PDT, Build Bot
no flags Details
Archive of layout-test-results from webkit-ews-03 for mac-mountainlion (531.64 KB, application/zip)
2013-09-07 05:52 PDT, Build Bot
no flags Details
Patch (9.53 KB, patch)
2013-09-09 02:43 PDT, Allan Sandfeld Jensen
no flags Details | Formatted Diff | Diff
Archive of layout-test-results from webkit-ews-04 for mac-mountainlion (504.68 KB, application/zip)
2013-09-09 03:48 PDT, Build Bot
no flags Details
Patch (6.64 KB, patch)
2013-09-09 05:54 PDT, Allan Sandfeld Jensen
no flags Details | Formatted Diff | Diff
Patch (8.27 KB, patch)
2013-09-09 07:03 PDT, Allan Sandfeld Jensen
tonikitoo: review+
Details | Formatted Diff | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Allan Sandfeld Jensen 2013-09-06 08:59:53 PDT
Only Elements can be targets of mouse-events, which means emitting mouseenter or mouseleave on a document node is a mistake.

This bug was noticed when cleaning up the overgeneric use of Nodes and replacing them with Elements in Document::updateHoverActiveState.
Comment 1 Allan Sandfeld Jensen 2013-09-06 09:04:42 PDT
Created attachment 210761 [details]
Patch
Comment 2 Andreas Kling 2013-09-06 09:50:48 PDT
This patch looks cool, though the new test seems to be failing on EWS. Any idea what's up with that?
Comment 3 Allan Sandfeld Jensen 2013-09-06 10:14:37 PDT
(In reply to comment #2)
> This patch looks cool, though the new test seems to be failing on EWS. Any idea what's up with that?

I will take a look, but it does assume the mouse pointer starts outside the document before the test and can be moved off it again by moving it to -10,-10.
Comment 4 Darin Adler 2013-09-06 13:57:22 PDT
Comment on attachment 210761 [details]
Patch

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

> Source/WebCore/dom/Document.cpp:5868
>              for (Node* node = oldHoveredElement.get(); node; node = node->parentNode()) {
> -                if (!mustBeInActiveChain || (node->isElementNode() && toElement(node)->inActiveChain()))
> -                    nodesToRemoveFromChain.append(node);
> +                if (!node->isElementNode())
> +                    continue;
> +                Element* element = toElement(node);
> +                if (!mustBeInActiveChain || element->inActiveChain())
> +                    elementsToRemoveFromChain.append(element);
>              }

Should just write:

    for (Element* element = oldHoveredElement.get(); element; element = element->parentElement()) {

That would eliminate three lines of code below.

Also, mustBeInActiveChain should be checked outside the loop, not inside it.

> Source/WebCore/dom/Document.cpp:5878
>          for (RenderObject* curr = oldHoverObj; curr && curr != ancestor; curr = curr->hoverAncestor()) {
> -            if (!curr->node() || curr->isText())
> +            if (!curr->node() || !curr->node()->isElementNode())
>                  continue;
> -            if (!mustBeInActiveChain || (curr->node()->isElementNode() && toElement(curr->node())->inActiveChain()))
> -                nodesToRemoveFromChain.append(curr->node());
> +            Element* element = toElement(curr->node());
> +            if (!mustBeInActiveChain || element->inActiveChain())
> +                elementsToRemoveFromChain.append(element);
>          }

!mustBeInActiveChain should be checked outside the loop

> Source/WebCore/dom/Document.cpp:5893
>      for (RenderObject* curr = newHoverObj; curr; curr = curr->hoverAncestor()) {
> -        if (!curr->node() || curr->isText())
> +        if (!curr->node() || !curr->node()->isElementNode())
>              continue;
> -        if (!mustBeInActiveChain || (curr->node()->isElementNode() && toElement(curr->node())->inActiveChain()))
> -            nodesToAddToChain.append(curr->node());
> +        Element* element = toElement(curr->node());
> +        if (!mustBeInActiveChain || element->inActiveChain())
> +            elementsToAddToChain.append(element);
>      }

!mustBeInActiveChain should be checked outside the loop

> Source/WebCore/dom/Document.cpp:5896
> -    size_t removeCount = nodesToRemoveFromChain.size();
> +    size_t removeCount = elementsToRemoveFromChain.size();
>      for (size_t i = 0; i < removeCount; ++i) {

Our modern style for this is:

    for (size_t i = 0, size = elementsToRemoveFromChain.size(); i < size; ++i) {

Please consider using that style.
Comment 5 Build Bot 2013-09-07 02:26:56 PDT
Comment on attachment 210761 [details]
Patch

Attachment 210761 [details] did not pass mac-wk2-ews (mac-wk2):
Output: http://webkit-queues.appspot.com/results/1709623

New failing tests:
fast/events/mouseenterleave-on-document.html
Comment 6 Build Bot 2013-09-07 02:26:58 PDT
Created attachment 210900 [details]
Archive of layout-test-results from webkit-ews-09 for mac-mountainlion-wk2

The attached test failures were seen while running run-webkit-tests on the mac-wk2-ews.
Bot: webkit-ews-09  Port: mac-mountainlion-wk2  Platform: Mac OS X 10.8.4
Comment 7 Build Bot 2013-09-07 05:52:14 PDT
Comment on attachment 210761 [details]
Patch

Attachment 210761 [details] did not pass mac-ews (mac):
Output: http://webkit-queues.appspot.com/results/1704707

New failing tests:
fast/events/mouseenterleave-on-document.html
Comment 8 Build Bot 2013-09-07 05:52:17 PDT
Created attachment 210901 [details]
Archive of layout-test-results from webkit-ews-03 for mac-mountainlion

The attached test failures were seen while running run-webkit-tests on the mac-ews.
Bot: webkit-ews-03  Port: mac-mountainlion  Platform: Mac OS X 10.8.4
Comment 9 Allan Sandfeld Jensen 2013-09-09 02:33:17 PDT
(In reply to comment #3)
> (In reply to comment #2)
> > This patch looks cool, though the new test seems to be failing on EWS. Any idea what's up with that?
> 
> I will take a look, but it does assume the mouse pointer starts outside the document before the test and can be moved off it again by moving it to -10,-10.

Yes, it is leaving the document that appears to be problematic
Comment 10 Allan Sandfeld Jensen 2013-09-09 02:37:42 PDT
(In reply to comment #4)
> Also, mustBeInActiveChain should be checked outside the loop, not inside it.
> 
I am not sure I understand that part. mustBeInActiveChain is checked as part of an else statement, if I moved it outside the loop I would need two different loops to choose from.
Comment 11 Allan Sandfeld Jensen 2013-09-09 02:43:06 PDT
Created attachment 211021 [details]
Patch

Cleanup suggested by darin, and the test now moves the mouse out of the document in positive coordinates
Comment 12 Build Bot 2013-09-09 03:48:22 PDT
Comment on attachment 211021 [details]
Patch

Attachment 211021 [details] did not pass mac-ews (mac):
Output: http://webkit-queues.appspot.com/results/1726533

New failing tests:
fast/events/mouseenterleave-on-document.html
Comment 13 Build Bot 2013-09-09 03:48:24 PDT
Created attachment 211026 [details]
Archive of layout-test-results from webkit-ews-04 for mac-mountainlion

The attached test failures were seen while running run-webkit-tests on the mac-ews.
Bot: webkit-ews-04  Port: mac-mountainlion  Platform: Mac OS X 10.8.4
Comment 14 Allan Sandfeld Jensen 2013-09-09 04:45:02 PDT
(In reply to comment #12)
> (From update of attachment 211021 [details])
> Attachment 211021 [details] did not pass mac-ews (mac):
> Output: http://webkit-queues.appspot.com/results/1726533
> 
> New failing tests:
> fast/events/mouseenterleave-on-document.html

It seems moving the mouse out of the webview doesn't work on the mac test bots. If the test I uploaded to bug 121026 works on Mac though, that should be able to test this bug as well.
Comment 15 Antonio Gomes 2013-09-09 05:23:27 PDT
Comment on attachment 211021 [details]
Patch

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

> Source/WebCore/ChangeLog:9
> +        This cleans up the code and fixes a hidden bug.

You should mention why the change, and what the hidden bug is.
Comment 16 Allan Sandfeld Jensen 2013-09-09 05:39:19 PDT
(In reply to comment #15)
> (From update of attachment 211021 [details])
> View in context: https://bugs.webkit.org/attachment.cgi?id=211021&action=review
> 
> > Source/WebCore/ChangeLog:9
> > +        This cleans up the code and fixes a hidden bug.
> 
> You should mention why the change, and what the hidden bug is.

Right. The hidden bug is then one mentioned in the title, but yes it is not really clear.
Comment 17 Allan Sandfeld Jensen 2013-09-09 05:54:47 PDT
Created attachment 211032 [details]
Patch
Comment 18 Antonio Gomes 2013-09-09 05:57:49 PDT
Comment on attachment 211032 [details]
Patch

Looks good. Can we test that with iframe documents?
Comment 19 Allan Sandfeld Jensen 2013-09-09 06:13:25 PDT
(In reply to comment #18)
> (From update of attachment 211032 [details])
> Looks good. Can we test that with iframe documents?

I assume so. I am waiting for the output from EWS on the patch in bug 121026, but it should be exactly this bug it demonstrates since the test also depends on this fix.
Comment 20 Allan Sandfeld Jensen 2013-09-09 07:03:55 PDT
Created attachment 211037 [details]
Patch
Comment 21 Allan Sandfeld Jensen 2013-09-09 07:38:46 PDT
Committed r155351: <http://trac.webkit.org/changeset/155351>