Title: [231291] trunk
Revision
231291
Author
bfulg...@apple.com
Date
2018-05-02 18:08:55 -0700 (Wed, 02 May 2018)

Log Message

Use RetainPtr for form input type
https://bugs.webkit.org/show_bug.cgi?id=185210
<rdar://problem/39734040>

Reviewed by Ryosuke Niwa.

Source/WebCore:

Refactor our HTMLInputElement class to store its InputType member as a RefPtr.

Test: fast/forms/access-key-mutation-2.html.

* html/HTMLInputElement.cpp:
(WebCore::HTMLInputElement::HTMLInputElement):
(WebCore::HTMLInputElement::didAddUserAgentShadowRoot):
(WebCore::HTMLInputElement::accessKeyAction):
(WebCore::HTMLInputElement::parseAttribute):
(WebCore::HTMLInputElement::appendFormData):
* html/HTMLInputElement.h:
* html/InputType.cpp:
(WebCore::createInputType):
(WebCore::InputType::create):
(WebCore::InputType::createText):
* html/InputType.h:

LayoutTests:

* fast/forms/access-key-mutation-2-expected.txt: Added.
* fast/forms/access-key-mutation-2.html: Added.

Modified Paths

Added Paths

Diff

Modified: trunk/LayoutTests/ChangeLog (231290 => 231291)


--- trunk/LayoutTests/ChangeLog	2018-05-03 01:03:26 UTC (rev 231290)
+++ trunk/LayoutTests/ChangeLog	2018-05-03 01:08:55 UTC (rev 231291)
@@ -1,3 +1,14 @@
+2018-05-02  Brent Fulgham  <bfulg...@apple.com>
+
+        Use RetainPtr for form input type
+        https://bugs.webkit.org/show_bug.cgi?id=185210
+        <rdar://problem/39734040>
+
+        Reviewed by Ryosuke Niwa.
+
+        * fast/forms/access-key-mutation-2-expected.txt: Added.
+        * fast/forms/access-key-mutation-2.html: Added.
+
 2018-05-01  Ryan Haddad  <ryanhad...@apple.com>
 
         Skip transitions/opacity-transition-zindex.html.

Added: trunk/LayoutTests/fast/forms/access-key-mutation-2-expected.txt (0 => 231291)


--- trunk/LayoutTests/fast/forms/access-key-mutation-2-expected.txt	                        (rev 0)
+++ trunk/LayoutTests/fast/forms/access-key-mutation-2-expected.txt	2018-05-03 01:08:55 UTC (rev 231291)
@@ -0,0 +1,10 @@
+Access key should work when input type attribute is mutated. To test this manually, press the <alt>+k keys (on Mac OS X, press <Ctrl>+<Opt> instead of <alt>).
+
+On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE".
+
+
+PASS if not crashed.
+PASS successfullyParsed is true
+
+TEST COMPLETE
+ 

Added: trunk/LayoutTests/fast/forms/access-key-mutation-2.html (0 => 231291)


--- trunk/LayoutTests/fast/forms/access-key-mutation-2.html	                        (rev 0)
+++ trunk/LayoutTests/fast/forms/access-key-mutation-2.html	2018-05-03 01:08:55 UTC (rev 231291)
@@ -0,0 +1,39 @@
+<!DOCTYPE html>
+<html>
+<head>
+<script src=""
+<script>
+description('Access key should work when input type attribute is mutated. To test this manually, press the &lt;alt&gt;+k keys (on Mac OS X, press &lt;Ctrl&gt;+&lt;Opt&gt; instead of &lt;alt&gt;).');
+
+jsTestIsAsync = true;
+
+function pressKey(key)
+{
+    if (navigator.userAgent.search(/\bMac OS X\b/) !== -1)
+        modifiers = ["ctrlKey", "altKey"];
+    else
+        modifiers = ["altKey"];
+
+    if (window.eventSender)
+        eventSender.keyDown(key, modifiers);
+}
+
+function eventhandler()
+{
+    input.type = "button"
+}
+
+function start()
+{
+    pressKey('k');
+    testPassed('if not crashed.');
+    finishJSTest();
+}
+</script>
+</head>
+<body>
+<input id="input" type="range" accesskey="k" _onfocus_="eventhandler()">
+<iframe _onload_="start()"></iframe>
+</body>
+</html>
+

Modified: trunk/Source/WebCore/ChangeLog (231290 => 231291)


--- trunk/Source/WebCore/ChangeLog	2018-05-03 01:03:26 UTC (rev 231290)
+++ trunk/Source/WebCore/ChangeLog	2018-05-03 01:08:55 UTC (rev 231291)
@@ -1,3 +1,28 @@
+2018-05-02  Brent Fulgham  <bfulg...@apple.com>
+
+        Use RetainPtr for form input type
+        https://bugs.webkit.org/show_bug.cgi?id=185210
+        <rdar://problem/39734040>
+
+        Reviewed by Ryosuke Niwa.
+
+        Refactor our HTMLInputElement class to store its InputType member as a RefPtr.
+
+        Test: fast/forms/access-key-mutation-2.html.
+
+        * html/HTMLInputElement.cpp:
+        (WebCore::HTMLInputElement::HTMLInputElement):
+        (WebCore::HTMLInputElement::didAddUserAgentShadowRoot):
+        (WebCore::HTMLInputElement::accessKeyAction):
+        (WebCore::HTMLInputElement::parseAttribute):
+        (WebCore::HTMLInputElement::appendFormData):
+        * html/HTMLInputElement.h:
+        * html/InputType.cpp:
+        (WebCore::createInputType):
+        (WebCore::InputType::create):
+        (WebCore::InputType::createText):
+        * html/InputType.h:
+
 2018-05-01  Yusuke Suzuki  <utatane....@gmail.com>
 
         Use pointer instead of std::optional<std::reference_wrapper<>>

Modified: trunk/Source/WebCore/html/HTMLInputElement.cpp (231290 => 231291)


--- trunk/Source/WebCore/html/HTMLInputElement.cpp	2018-05-03 01:03:26 UTC (rev 231290)
+++ trunk/Source/WebCore/html/HTMLInputElement.cpp	2018-05-03 01:08:55 UTC (rev 231291)
@@ -103,7 +103,6 @@
 HTMLInputElement::HTMLInputElement(const QualifiedName& tagName, Document& document, HTMLFormElement* form, bool createdByParser)
     : HTMLTextFormControlElement(tagName, document, form)
     , m_size(defaultSize)
-    , m_maxResults(-1)
     , m_isChecked(false)
     , m_reflectsCheckedAttribute(true)
     , m_isIndeterminate(false)
@@ -126,10 +125,12 @@
     , m_hasTouchEventHandler(false)
 #endif
     , m_isSpellcheckDisabledExceptTextReplacement(false)
+{
     // m_inputType is lazily created when constructed by the parser to avoid constructing unnecessarily a text inputType and
     // its shadow subtree, just to destroy them when the |type| attribute gets set by the parser to something else than 'text'.
-    , m_inputType(createdByParser ? nullptr : InputType::createText(*this))
-{
+    if (!createdByParser)
+        m_inputType = InputType::createText(*this);
+
     ASSERT(hasTagName(inputTag));
     setHasCustomStyleResolveCallbacks();
 }
@@ -152,7 +153,8 @@
 
 void HTMLInputElement::didAddUserAgentShadowRoot(ShadowRoot&)
 {
-    m_inputType->createShadowSubtree();
+    Ref<InputType> protectedInputType(*m_inputType);
+    protectedInputType->createShadowSubtree();
     updateInnerTextElementEditability();
 }
 
@@ -625,7 +627,8 @@
 
 void HTMLInputElement::accessKeyAction(bool sendMouseEvents)
 {
-    m_inputType->accessKeyAction(sendMouseEvents);
+    Ref<InputType> protectedInputType(*m_inputType);
+    protectedInputType->accessKeyAction(sendMouseEvents);
 }
 
 bool HTMLInputElement::isPresentationAttribute(const QualifiedName& name) const
@@ -682,6 +685,7 @@
 void HTMLInputElement::parseAttribute(const QualifiedName& name, const AtomicString& value)
 {
     ASSERT(m_inputType);
+    Ref<InputType> protectedInputType(*m_inputType);
 
     if (name == nameAttr) {
         removeFromRadioButtonGroup();
@@ -889,6 +893,7 @@
 
 bool HTMLInputElement::appendFormData(DOMFormData& formData, bool multipart)
 {
+    Ref<InputType> protectedInputType(*m_inputType);
     return m_inputType->isFormDataAppendable() && m_inputType->appendFormData(formData, multipart);
 }
 

Modified: trunk/Source/WebCore/html/HTMLInputElement.h (231290 => 231291)


--- trunk/Source/WebCore/html/HTMLInputElement.h	2018-05-03 01:03:26 UTC (rev 231290)
+++ trunk/Source/WebCore/html/HTMLInputElement.h	2018-05-03 01:08:55 UTC (rev 231291)
@@ -447,7 +447,7 @@
     AtomicString m_name;
     String m_valueIfDirty;
     unsigned m_size;
-    short m_maxResults;
+    short m_maxResults { -1 };
     bool m_isChecked : 1;
     bool m_reflectsCheckedAttribute : 1;
     bool m_isIndeterminate : 1;
@@ -470,7 +470,7 @@
     bool m_hasTouchEventHandler : 1;
 #endif
     bool m_isSpellcheckDisabledExceptTextReplacement : 1;
-    std::unique_ptr<InputType> m_inputType;
+    RefPtr<InputType> m_inputType;
     // The ImageLoader must be owned by this element because the loader code assumes
     // that it lives as long as its owning element lives. If we move the loader into
     // the ImageInput object we may delete the loader while this element lives on.

Modified: trunk/Source/WebCore/html/InputType.cpp (231290 => 231291)


--- trunk/Source/WebCore/html/InputType.cpp	2018-05-03 01:03:26 UTC (rev 231290)
+++ trunk/Source/WebCore/html/InputType.cpp	2018-05-03 01:08:55 UTC (rev 231291)
@@ -2,7 +2,7 @@
  * Copyright (C) 1999 Lars Knoll (kn...@kde.org)
  *           (C) 1999 Antti Koivisto (koivi...@kde.org)
  *           (C) 2001 Dirk Mueller (muel...@kde.org)
- * Copyright (C) 2004-2017 Apple Inc. All rights reserved.
+ * Copyright (C) 2004-2018 Apple Inc. All rights reserved.
  *           (C) 2006 Alexey Proskuryakov (a...@nypop.com)
  * Copyright (C) 2007 Samuel Weinig (s...@webkit.org)
  * Copyright (C) 2009, 2010, 2011, 2012 Google Inc. All rights reserved.
@@ -85,13 +85,13 @@
 
 typedef bool (RuntimeEnabledFeatures::*InputTypeConditionalFunction)() const;
 typedef const AtomicString& (*InputTypeNameFunction)();
-typedef std::unique_ptr<InputType> (*InputTypeFactoryFunction)(HTMLInputElement&);
+typedef Ref<InputType> (*InputTypeFactoryFunction)(HTMLInputElement&);
 typedef HashMap<AtomicString, InputTypeFactoryFunction, ASCIICaseInsensitiveHash> InputTypeFactoryMap;
 
 template<class T>
-static std::unique_ptr<InputType> createInputType(HTMLInputElement& element)
+static Ref<InputType> createInputType(HTMLInputElement& element)
 {
-    return std::make_unique<T>(element);
+    return adoptRef(*new T(element));
 }
 
 static InputTypeFactoryMap createInputTypeFactoryMap()
@@ -149,7 +149,7 @@
     return map;
 }
 
-std::unique_ptr<InputType> InputType::create(HTMLInputElement& element, const AtomicString& typeName)
+Ref<InputType> InputType::create(HTMLInputElement& element, const AtomicString& typeName)
 {
     if (!typeName.isEmpty()) {
         static const auto factoryMap = makeNeverDestroyed(createInputTypeFactoryMap());
@@ -156,12 +156,12 @@
         if (auto factory = factoryMap.get().get(typeName))
             return factory(element);
     }
-    return std::make_unique<TextInputType>(element);
+    return adoptRef(*new TextInputType(element));
 }
 
-std::unique_ptr<InputType> InputType::createText(HTMLInputElement& element)
+Ref<InputType> InputType::createText(HTMLInputElement& element)
 {
-    return std::make_unique<TextInputType>(element);
+    return adoptRef(*new TextInputType(element));
 }
 
 InputType::~InputType() = default;

Modified: trunk/Source/WebCore/html/InputType.h (231290 => 231291)


--- trunk/Source/WebCore/html/InputType.h	2018-05-03 01:03:26 UTC (rev 231290)
+++ trunk/Source/WebCore/html/InputType.h	2018-05-03 01:08:55 UTC (rev 231291)
@@ -1,6 +1,6 @@
 /*
  * Copyright (C) 2010 Google Inc. All rights reserved.
- * Copyright (C) 2011-2017 Apple Inc. All rights reserved.
+ * Copyright (C) 2011-2018 Apple Inc. All rights reserved.
  * Copyright (C) 2012 Samsung Electronics. All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
@@ -37,6 +37,7 @@
 #include "StepRange.h"
 #include <wtf/FastMalloc.h>
 #include <wtf/Forward.h>
+#include <wtf/RefCounted.h>
 #include <wtf/RefPtr.h>
 
 #if PLATFORM(IOS)
@@ -68,12 +69,12 @@
 // An InputType object represents the type-specific part of an HTMLInputElement.
 // Do not expose instances of InputType and classes derived from it to classes
 // other than HTMLInputElement.
-class InputType {
+class InputType : public RefCounted<InputType> {
     WTF_MAKE_FAST_ALLOCATED;
 
 public:
-    static std::unique_ptr<InputType> create(HTMLInputElement&, const AtomicString&);
-    static std::unique_ptr<InputType> createText(HTMLInputElement&);
+    static Ref<InputType> create(HTMLInputElement&, const AtomicString&);
+    static Ref<InputType> createText(HTMLInputElement&);
     virtual ~InputType();
 
     static bool themeSupportsDataListUI(InputType*);
_______________________________________________
webkit-changes mailing list
webkit-changes@lists.webkit.org
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to