Editable images sometimes don't become focused when tapped
authortimothy_horton@apple.com <timothy_horton@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Wed, 9 Jan 2019 01:09:06 +0000 (01:09 +0000)
committertimothy_horton@apple.com <timothy_horton@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Wed, 9 Jan 2019 01:09:06 +0000 (01:09 +0000)
https://bugs.webkit.org/show_bug.cgi?id=193259
<rdar://problem/47038424>

Reviewed by Wenson Hsieh.

Often when tapping an editable image inside an editable text area, the
text area's selection will change instead of focusing the editable image.

No new tests; I have had no luck writing a test that reliably failed
beforehand (the "sometimes" is a problem).

* html/HTMLImageElement.cpp:
(WebCore::HTMLImageElement::defaultEventHandler):
* html/HTMLImageElement.h:
Override mousedown on editable images, focus the image, and prevent
the default behavior.

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@239756 268f45cc-cd09-0410-ab3c-d52691b4dbfc

Source/WebCore/ChangeLog
Source/WebCore/html/HTMLImageElement.cpp
Source/WebCore/html/HTMLImageElement.h

index 50a6706..0e498f0 100644 (file)
@@ -1,3 +1,23 @@
+2019-01-08  Tim Horton  <timothy_horton@apple.com>
+
+        Editable images sometimes don't become focused when tapped
+        https://bugs.webkit.org/show_bug.cgi?id=193259
+        <rdar://problem/47038424>
+
+        Reviewed by Wenson Hsieh.
+
+        Often when tapping an editable image inside an editable text area, the
+        text area's selection will change instead of focusing the editable image.
+
+        No new tests; I have had no luck writing a test that reliably failed 
+        beforehand (the "sometimes" is a problem).
+
+        * html/HTMLImageElement.cpp:
+        (WebCore::HTMLImageElement::defaultEventHandler):
+        * html/HTMLImageElement.h:
+        Override mousedown on editable images, focus the image, and prevent
+        the default behavior.
+
 2019-01-08  Jiewen Tan  <jiewen_tan@apple.com>
 
         [WebAuthN] Support U2F HID Authenticators on macOS
index 7fb2713..2e728ae 100644 (file)
@@ -31,6 +31,7 @@
 #include "EditableImageReference.h"
 #include "Editor.h"
 #include "ElementIterator.h"
+#include "EventNames.h"
 #include "FrameView.h"
 #include "HTMLAnchorElement.h"
 #include "HTMLAttachmentElement.h"
@@ -46,6 +47,7 @@
 #include "MediaList.h"
 #include "MediaQueryEvaluator.h"
 #include "NodeTraversal.h"
+#include "PlatformMouseEvent.h"
 #include "RenderImage.h"
 #include "RenderView.h"
 #include "RuntimeEnabledFeatures.h"
@@ -839,4 +841,14 @@ void HTMLImageElement::copyNonAttributePropertiesFromElement(const Element& sour
     Element::copyNonAttributePropertiesFromElement(source);
 }
 
+void HTMLImageElement::defaultEventHandler(Event& event)
+{
+    if (hasEditableImageAttribute() && event.type() == eventNames().mousedownEvent && is<MouseEvent>(event) && downcast<MouseEvent>(event).button() == LeftButton) {
+        focus();
+        event.setDefaultHandled();
+        return;
+    }
+    HTMLElement::defaultEventHandler(event);
+}
+
 }
index ad6aa93..8995cbf 100644 (file)
@@ -121,6 +121,8 @@ public:
     WEBCORE_EXPORT GraphicsLayer::EmbeddedViewID editableImageViewID() const;
     WEBCORE_EXPORT bool hasEditableImageAttribute() const;
 
+    void defaultEventHandler(Event&) final;
+
 protected:
     HTMLImageElement(const QualifiedName&, Document&, HTMLFormElement* = 0);