Title: [174637] trunk
Revision
174637
Author
[email protected]
Date
2014-10-12 01:35:34 -0700 (Sun, 12 Oct 2014)

Log Message

Support activation behavior of link element
https://bugs.webkit.org/show_bug.cgi?id=137597

Patch by Dhi Aurrahman <[email protected]> on 2014-10-12
Reviewed by Benjamin Poulain.

Source/WebCore:

Support activation behavior of link elements as defined in [1],
i.e. to follow the hyperlink created by the link element when it is fully active.

[1] https://html.spec.whatwg.org/multipage/semantics.html#the-link-element

Tests: fast/dom/html-link-element-activation-behavior-on-element-click.html
       fast/dom/html-link-element-activation-behavior-on-mouse-click.html
       fast/dom/html-link-element-activation-behavior-url-is-null.html

* dom/MouseEvent.cpp:
(WebCore::MouseEvent::triggerActivationBehavior):
* dom/MouseEvent.h:
* html/HTMLAnchorElement.cpp:
(WebCore::HTMLAnchorElement::defaultEventHandler):
(WebCore::isLinkClick): Deleted.
* html/HTMLAnchorElement.h:
* html/HTMLLinkElement.cpp:
(WebCore::HTMLLinkElement::defaultEventHandler):
(WebCore::HTMLLinkElement::handleClick):
* html/HTMLLinkElement.h:
* svg/SVGAElement.cpp:
(WebCore::SVGAElement::defaultEventHandler):

LayoutTests:

Add test cases for link element activation behavior.

* fast/dom/html-link-element-activation-behavior-on-element-click-expected.txt: Added.
* fast/dom/html-link-element-activation-behavior-on-element-click.html: Added.
* fast/dom/html-link-element-activation-behavior-on-mouse-click-expected.txt: Added.
* fast/dom/html-link-element-activation-behavior-on-mouse-click.html: Added.
* fast/dom/html-link-element-activation-behavior-url-is-null-expected.txt: Added.
* fast/dom/html-link-element-activation-behavior-url-is-null.html: Added.
* fast/dom/resources/html-link-element-activation-behavior-on-element-click-step1.html: Added.
* fast/dom/resources/html-link-element-activation-behavior-on-mouse-click-step1.html: Added.
* fast/dom/resources/html-link-element-activation-behavior-target.html: Added.

Modified Paths

Added Paths

Diff

Modified: trunk/LayoutTests/ChangeLog (174636 => 174637)


--- trunk/LayoutTests/ChangeLog	2014-10-12 07:15:25 UTC (rev 174636)
+++ trunk/LayoutTests/ChangeLog	2014-10-12 08:35:34 UTC (rev 174637)
@@ -1,3 +1,22 @@
+2014-10-12  Dhi Aurrahman  <[email protected]>
+
+        Support activation behavior of link element
+        https://bugs.webkit.org/show_bug.cgi?id=137597
+
+        Reviewed by Benjamin Poulain.
+
+        Add test cases for link element activation behavior.
+
+        * fast/dom/html-link-element-activation-behavior-on-element-click-expected.txt: Added.
+        * fast/dom/html-link-element-activation-behavior-on-element-click.html: Added.
+        * fast/dom/html-link-element-activation-behavior-on-mouse-click-expected.txt: Added.
+        * fast/dom/html-link-element-activation-behavior-on-mouse-click.html: Added.
+        * fast/dom/html-link-element-activation-behavior-url-is-null-expected.txt: Added.
+        * fast/dom/html-link-element-activation-behavior-url-is-null.html: Added.
+        * fast/dom/resources/html-link-element-activation-behavior-on-element-click-step1.html: Added.
+        * fast/dom/resources/html-link-element-activation-behavior-on-mouse-click-step1.html: Added.
+        * fast/dom/resources/html-link-element-activation-behavior-target.html: Added.
+
 2014-10-11  Simon Fraser  <[email protected]>
 
         Mark some more tests as sometimes passing.

Added: trunk/LayoutTests/fast/dom/html-link-element-activation-behavior-on-element-click-expected.txt (0 => 174637)


--- trunk/LayoutTests/fast/dom/html-link-element-activation-behavior-on-element-click-expected.txt	                        (rev 0)
+++ trunk/LayoutTests/fast/dom/html-link-element-activation-behavior-on-element-click-expected.txt	2014-10-12 08:35:34 UTC (rev 174637)
@@ -0,0 +1,10 @@
+This tests html link element activation behavior on DOM click
+
+On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE".
+
+
+PASS event.data is "test:ok"
+PASS successfullyParsed is true
+
+TEST COMPLETE
+

Added: trunk/LayoutTests/fast/dom/html-link-element-activation-behavior-on-element-click.html (0 => 174637)


--- trunk/LayoutTests/fast/dom/html-link-element-activation-behavior-on-element-click.html	                        (rev 0)
+++ trunk/LayoutTests/fast/dom/html-link-element-activation-behavior-on-element-click.html	2014-10-12 08:35:34 UTC (rev 174637)
@@ -0,0 +1,25 @@
+<!DOCTYPE html>
+<html>
+<head>
+<script src=""
+</head>
+<body>
+<div id="master"></div>
+<iframe id="frame" src=""
+<script>
+description("This tests html link element activation behavior on DOM click");
+function start(){
+    frame.postMessage("element:click", "*");
+}
+function listener(event){
+    shouldBeEqualToString("event.data", "test:ok")
+    finishJSTest();
+}
+var frame = document.getElementById("frame").contentWindow;
+window.addEventListener("message", listener);
+frame._onload_ = start;
+window.jsTestIsAsync = true;
+</script>
+<script src=""
+</body>
+</html>
\ No newline at end of file

Added: trunk/LayoutTests/fast/dom/html-link-element-activation-behavior-on-mouse-click-expected.txt (0 => 174637)


--- trunk/LayoutTests/fast/dom/html-link-element-activation-behavior-on-mouse-click-expected.txt	                        (rev 0)
+++ trunk/LayoutTests/fast/dom/html-link-element-activation-behavior-on-mouse-click-expected.txt	2014-10-12 08:35:34 UTC (rev 174637)
@@ -0,0 +1,10 @@
+This tests html link element activation behavior on mouse click
+
+On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE".
+
+
+PASS event.data is "test:ok"
+PASS successfullyParsed is true
+
+TEST COMPLETE
+

Added: trunk/LayoutTests/fast/dom/html-link-element-activation-behavior-on-mouse-click.html (0 => 174637)


--- trunk/LayoutTests/fast/dom/html-link-element-activation-behavior-on-mouse-click.html	                        (rev 0)
+++ trunk/LayoutTests/fast/dom/html-link-element-activation-behavior-on-mouse-click.html	2014-10-12 08:35:34 UTC (rev 174637)
@@ -0,0 +1,25 @@
+<!DOCTYPE html>
+<html>
+<head>
+<script src=""
+</head>
+<body>
+<div id="master"></div>
+<iframe id="frame" src=""
+<script>
+description("This tests html link element activation behavior on mouse click");
+function start(){
+    frame.postMessage("mouse:click", "*");
+}
+function listener(event){
+    shouldBeEqualToString("event.data", "test:ok")
+    finishJSTest();
+}
+var frame = document.getElementById("frame").contentWindow;
+window.addEventListener("message", listener);
+frame._onload_ = start;
+window.jsTestIsAsync = true;
+</script>
+<script src=""
+</body>
+</html>
\ No newline at end of file

Added: trunk/LayoutTests/fast/dom/html-link-element-activation-behavior-url-is-null-expected.txt (0 => 174637)


--- trunk/LayoutTests/fast/dom/html-link-element-activation-behavior-url-is-null-expected.txt	                        (rev 0)
+++ trunk/LayoutTests/fast/dom/html-link-element-activation-behavior-url-is-null-expected.txt	2014-10-12 08:35:34 UTC (rev 174637)
@@ -0,0 +1,10 @@
+This tests html link element activation behavior when url is null
+
+On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE".
+
+
+PASS target.dispatchEvent(mouseEvent) is true
+PASS successfullyParsed is true
+
+TEST COMPLETE
+

Added: trunk/LayoutTests/fast/dom/html-link-element-activation-behavior-url-is-null.html (0 => 174637)


--- trunk/LayoutTests/fast/dom/html-link-element-activation-behavior-url-is-null.html	                        (rev 0)
+++ trunk/LayoutTests/fast/dom/html-link-element-activation-behavior-url-is-null.html	2014-10-12 08:35:34 UTC (rev 174637)
@@ -0,0 +1,21 @@
+<!DOCTYPE html>
+<html>
+<head>
+<script src=""
+</head>
+<body>
+<link id="target">
+<script>
+description("This tests html link element activation behavior when url is null");
+function notNavigatedAnywhere(){
+    finishJSTest();
+}
+var mouseEvent = new MouseEvent("click");
+var target = document.getElementById("target");
+shouldBeTrue("target.dispatchEvent(mouseEvent)");
+setTimeout(notNavigatedAnywhere, 100);
+window.jsTestIsAsync = true;
+</script>
+<script src=""
+</body>
+</html>
\ No newline at end of file

Added: trunk/LayoutTests/fast/dom/resources/html-link-element-activation-behavior-on-element-click-step1.html (0 => 174637)


--- trunk/LayoutTests/fast/dom/resources/html-link-element-activation-behavior-on-element-click-step1.html	                        (rev 0)
+++ trunk/LayoutTests/fast/dom/resources/html-link-element-activation-behavior-on-element-click-step1.html	2014-10-12 08:35:34 UTC (rev 174637)
@@ -0,0 +1,18 @@
+<head>
+<style type="text/css">
+link {
+    display: block;
+    width: 100px;
+    height: 100px;
+    border: 1px solid red;
+}
+</style>
+</head>
+<div></div>
+<link id="target" href=""
+<script>
+function elementClick(){
+    document.getElementById("target").click();
+}
+window.addEventListener("message", elementClick);
+</script>
\ No newline at end of file

Added: trunk/LayoutTests/fast/dom/resources/html-link-element-activation-behavior-on-mouse-click-step1.html (0 => 174637)


--- trunk/LayoutTests/fast/dom/resources/html-link-element-activation-behavior-on-mouse-click-step1.html	                        (rev 0)
+++ trunk/LayoutTests/fast/dom/resources/html-link-element-activation-behavior-on-mouse-click-step1.html	2014-10-12 08:35:34 UTC (rev 174637)
@@ -0,0 +1,22 @@
+<head>
+<style type="text/css">
+link {
+    display: block;
+    width: 100px;
+    height: 100px;
+    border: 1px solid red;
+}
+</style>
+</head>
+<div></div>
+<link id="target" href=""
+<script>
+function mouseClick() {
+    if (window.eventSender) {
+        eventSender.mouseMoveTo(50, 140);
+        eventSender.mouseDown();
+        eventSender.mouseUp();
+    }	
+}
+window.addEventListener("message", mouseClick);
+</script>
\ No newline at end of file

Added: trunk/LayoutTests/fast/dom/resources/html-link-element-activation-behavior-target.html (0 => 174637)


--- trunk/LayoutTests/fast/dom/resources/html-link-element-activation-behavior-target.html	                        (rev 0)
+++ trunk/LayoutTests/fast/dom/resources/html-link-element-activation-behavior-target.html	2014-10-12 08:35:34 UTC (rev 174637)
@@ -0,0 +1,10 @@
+<head>
+<script>
+function ok(){
+    window.parent.postMessage("test:ok", "*");
+}
+</script>
+</head>
+<body _onload_="ok()">
+<h1>target</h1>
+</body>
\ No newline at end of file

Modified: trunk/Source/WebCore/ChangeLog (174636 => 174637)


--- trunk/Source/WebCore/ChangeLog	2014-10-12 07:15:25 UTC (rev 174636)
+++ trunk/Source/WebCore/ChangeLog	2014-10-12 08:35:34 UTC (rev 174637)
@@ -1,3 +1,33 @@
+2014-10-12  Dhi Aurrahman  <[email protected]>
+
+        Support activation behavior of link element
+        https://bugs.webkit.org/show_bug.cgi?id=137597
+
+        Reviewed by Benjamin Poulain.
+
+        Support activation behavior of link elements as defined in [1],
+        i.e. to follow the hyperlink created by the link element when it is fully active.
+
+        [1] https://html.spec.whatwg.org/multipage/semantics.html#the-link-element
+
+        Tests: fast/dom/html-link-element-activation-behavior-on-element-click.html
+               fast/dom/html-link-element-activation-behavior-on-mouse-click.html
+               fast/dom/html-link-element-activation-behavior-url-is-null.html
+
+        * dom/MouseEvent.cpp:
+        (WebCore::MouseEvent::triggerActivationBehavior):
+        * dom/MouseEvent.h:
+        * html/HTMLAnchorElement.cpp:
+        (WebCore::HTMLAnchorElement::defaultEventHandler):
+        (WebCore::isLinkClick): Deleted.
+        * html/HTMLAnchorElement.h:
+        * html/HTMLLinkElement.cpp:
+        (WebCore::HTMLLinkElement::defaultEventHandler):
+        (WebCore::HTMLLinkElement::handleClick):
+        * html/HTMLLinkElement.h:
+        * svg/SVGAElement.cpp:
+        (WebCore::SVGAElement::defaultEventHandler):
+
 2014-10-11  KwangHyuk Kim  <[email protected]>
 
         [EFL] Enable WebP support.

Modified: trunk/Source/WebCore/dom/MouseEvent.cpp (174636 => 174637)


--- trunk/Source/WebCore/dom/MouseEvent.cpp	2014-10-12 07:15:25 UTC (rev 174636)
+++ trunk/Source/WebCore/dom/MouseEvent.cpp	2014-10-12 08:35:34 UTC (rev 174637)
@@ -190,6 +190,11 @@
                || t == eventNames().dragstartEvent|| t == eventNames().dragEvent || t == eventNames().dragendEvent;
 }
 
+bool MouseEvent::canTriggerActivationBehavior(const Event& event)
+{
+    return event.type() == eventNames().clickEvent && (!is<MouseEvent>(event) || downcast<MouseEvent>(event).button() != RightButton);
+}
+
 int MouseEvent::which() const
 {
     // For the DOM, the return values for left, middle and right mouse buttons are 0, 1, 2, respectively.

Modified: trunk/Source/WebCore/dom/MouseEvent.h (174636 => 174637)


--- trunk/Source/WebCore/dom/MouseEvent.h	2014-10-12 07:15:25 UTC (rev 174636)
+++ trunk/Source/WebCore/dom/MouseEvent.h	2014-10-12 08:35:34 UTC (rev 174637)
@@ -99,6 +99,8 @@
 
     virtual bool isMouseEvent() const override;
     virtual bool isDragEvent() const override;
+    static bool canTriggerActivationBehavior(const Event&); 
+
     virtual int which() const override;
 
     virtual PassRefPtr<Event> cloneFor(HTMLIFrameElement*) const override;

Modified: trunk/Source/WebCore/html/HTMLAnchorElement.cpp (174636 => 174637)


--- trunk/Source/WebCore/html/HTMLAnchorElement.cpp	2014-10-12 07:15:25 UTC (rev 174636)
+++ trunk/Source/WebCore/html/HTMLAnchorElement.cpp	2014-10-12 08:35:34 UTC (rev 174637)
@@ -189,7 +189,7 @@
             return;
         }
 
-        if (isLinkClick(event) && treatLinkAsLiveForEventType(eventType(event))) {
+        if (MouseEvent::canTriggerActivationBehavior(*event) && treatLinkAsLiveForEventType(eventType(event))) {
             handleClick(event);
             return;
         }
@@ -597,11 +597,6 @@
     return event->type() == eventNames().keydownEvent && is<KeyboardEvent>(*event) && downcast<KeyboardEvent>(*event).keyIdentifier() == "Enter";
 }
 
-bool isLinkClick(Event* event)
-{
-    return event->type() == eventNames().clickEvent && (!is<MouseEvent>(*event) || downcast<MouseEvent>(*event).button() != RightButton);
-}
-
 bool shouldProhibitLinks(Element* element)
 {
     return isInSVGImage(element);

Modified: trunk/Source/WebCore/html/HTMLAnchorElement.h (174636 => 174637)


--- trunk/Source/WebCore/html/HTMLAnchorElement.h	2014-10-12 07:15:25 UTC (rev 174636)
+++ trunk/Source/WebCore/html/HTMLAnchorElement.h	2014-10-12 08:35:34 UTC (rev 174637)
@@ -152,7 +152,6 @@
 // Functions shared with the other anchor elements (i.e., SVG).
 
 bool isEnterKeyKeydownEvent(Event*);
-bool isLinkClick(Event*);
 bool shouldProhibitLinks(Element*);
 
 } // namespace WebCore

Modified: trunk/Source/WebCore/html/HTMLLinkElement.cpp (174636 => 174637)


--- trunk/Source/WebCore/html/HTMLLinkElement.cpp	2014-10-12 07:15:25 UTC (rev 174636)
+++ trunk/Source/WebCore/html/HTMLLinkElement.cpp	2014-10-12 08:35:34 UTC (rev 174637)
@@ -43,6 +43,7 @@
 #include "HTMLParserIdioms.h"
 #include "MediaList.h"
 #include "MediaQueryEvaluator.h"
+#include "MouseEvent.h"
 #include "Page.h"
 #include "RenderStyle.h"
 #include "SecurityOrigin.h"
@@ -396,6 +397,28 @@
     return attribute.name().localName() == hrefAttr || HTMLElement::isURLAttribute(attribute);
 }
 
+void HTMLLinkElement::defaultEventHandler(Event* event)
+{
+    ASSERT(event);
+    if (MouseEvent::canTriggerActivationBehavior(*event)) {
+        handleClick(*event);
+        return;
+    }
+    HTMLElement::defaultEventHandler(event);
+}
+
+void HTMLLinkElement::handleClick(Event& event)
+{
+    event.setDefaultHandled();
+    URL url = ""
+    if (url.isNull())
+        return;
+    Frame* frame = document().frame();
+    if (!frame)
+        return;
+    frame->loader().urlSelected(url, target(), PassRefPtr<Event>(&event), LockHistory::No, LockBackForwardList::No, MaybeSendReferrer);
+}
+
 URL HTMLLinkElement::href() const
 {
     return document().completeURL(getAttribute(hrefAttr));

Modified: trunk/Source/WebCore/html/HTMLLinkElement.h (174636 => 174637)


--- trunk/Source/WebCore/html/HTMLLinkElement.h	2014-10-12 07:15:25 UTC (rev 174636)
+++ trunk/Source/WebCore/html/HTMLLinkElement.h	2014-10-12 08:35:34 UTC (rev 174637)
@@ -97,6 +97,9 @@
 
     virtual bool isURLAttribute(const Attribute&) const override;
 
+    virtual void defaultEventHandler(Event*) override;
+    void handleClick(Event&);
+
 private:
     HTMLLinkElement(const QualifiedName&, Document&, bool createdByParser);
 

Modified: trunk/Source/WebCore/svg/SVGAElement.cpp (174636 => 174637)


--- trunk/Source/WebCore/svg/SVGAElement.cpp	2014-10-12 07:15:25 UTC (rev 174636)
+++ trunk/Source/WebCore/svg/SVGAElement.cpp	2014-10-12 08:35:34 UTC (rev 174637)
@@ -155,7 +155,7 @@
             return;
         }
 
-        if (isLinkClick(event)) {
+        if (MouseEvent::canTriggerActivationBehavior(*event)) {
             String url = ""
 
             if (url[0] == '#') {
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to