Remove some PLATFORM(IOS_FAMILY) guards in TextFieldInputType
https://bugs.webkit.org/show_bug.cgi?id=209883
Reviewed by Darin Adler.
Refactor what is currently a compile-time IOS_FAMILY guard into a runtime check behind a private helper method
on TextFieldInputType. This makes the intention behind the iOS-specific logic more self-evident; no change in
behavior.
* html/TextFieldInputType.cpp:
(WebCore::TextFieldInputType::handleFocusEvent):
(WebCore::TextFieldInputType::handleBlurEvent):
(WebCore::TextFieldInputType::createDataListDropdownIndicator):
(WebCore::TextFieldInputType::shouldOnlyShowDataListDropdownButtonWhenFocusedOrEdited const):
(WebCore::TextFieldInputType::didSetValueByUserEdit):
(WebCore::TextFieldInputType::listAttributeTargetChanged):
* html/TextFieldInputType.h:
git-svn-id: http://svn.webkit.org/repository/webkit/trunk@259375 268f45cc-cd09-0410-ab3c-d52691b4dbfc
diff --git a/Source/WebCore/ChangeLog b/Source/WebCore/ChangeLog
index f16dac0..77b3697 100644
--- a/Source/WebCore/ChangeLog
+++ b/Source/WebCore/ChangeLog
@@ -1,3 +1,23 @@
+2020-04-01 Wenson Hsieh <wenson_hsieh@apple.com>
+
+ Remove some PLATFORM(IOS_FAMILY) guards in TextFieldInputType
+ https://bugs.webkit.org/show_bug.cgi?id=209883
+
+ Reviewed by Darin Adler.
+
+ Refactor what is currently a compile-time IOS_FAMILY guard into a runtime check behind a private helper method
+ on TextFieldInputType. This makes the intention behind the iOS-specific logic more self-evident; no change in
+ behavior.
+
+ * html/TextFieldInputType.cpp:
+ (WebCore::TextFieldInputType::handleFocusEvent):
+ (WebCore::TextFieldInputType::handleBlurEvent):
+ (WebCore::TextFieldInputType::createDataListDropdownIndicator):
+ (WebCore::TextFieldInputType::shouldOnlyShowDataListDropdownButtonWhenFocusedOrEdited const):
+ (WebCore::TextFieldInputType::didSetValueByUserEdit):
+ (WebCore::TextFieldInputType::listAttributeTargetChanged):
+ * html/TextFieldInputType.h:
+
2020-04-01 Per Arne Vollan <pvollan@apple.com>
[Cocoa] UTI from MIME type cache can be removed after r258915
diff --git a/Source/WebCore/html/TextFieldInputType.cpp b/Source/WebCore/html/TextFieldInputType.cpp
index 3cae38d..7895a7e 100644
--- a/Source/WebCore/html/TextFieldInputType.cpp
+++ b/Source/WebCore/html/TextFieldInputType.cpp
@@ -268,8 +268,8 @@
ASSERT_UNUSED(oldFocusedNode, oldFocusedNode != element());
if (RefPtr<Frame> frame = element()->document().frame()) {
frame->editor().textFieldDidBeginEditing(element());
-#if ENABLE(DATALIST_ELEMENT) && PLATFORM(IOS_FAMILY)
- if (element()->list() && m_dataListDropdownIndicator)
+#if ENABLE(DATALIST_ELEMENT)
+ if (shouldOnlyShowDataListDropdownButtonWhenFocusedOrEdited() && element()->list() && m_dataListDropdownIndicator)
m_dataListDropdownIndicator->setInlineStyleProperty(CSSPropertyDisplay, suggestions().size() ? CSSValueBlock : CSSValueNone, true);
#endif
}
@@ -280,8 +280,8 @@
InputType::handleBlurEvent();
ASSERT(element());
element()->endEditing();
-#if ENABLE(DATALIST_ELEMENT) && PLATFORM(IOS_FAMILY)
- if (element()->list() && m_dataListDropdownIndicator)
+#if ENABLE(DATALIST_ELEMENT)
+ if (shouldOnlyShowDataListDropdownButtonWhenFocusedOrEdited() && element()->list() && m_dataListDropdownIndicator)
m_dataListDropdownIndicator->setInlineStyleProperty(CSSPropertyDisplay, CSSValueNone, true);
#endif
}
@@ -448,6 +448,7 @@
}
#if ENABLE(DATALIST_ELEMENT)
+
void TextFieldInputType::createDataListDropdownIndicator()
{
ASSERT(!m_dataListDropdownIndicator);
@@ -459,9 +460,18 @@
m_container->appendChild(*m_dataListDropdownIndicator);
m_dataListDropdownIndicator->setPseudo(AtomString("-webkit-list-button", AtomString::ConstructFromLiteral));
m_dataListDropdownIndicator->setInlineStyleProperty(CSSPropertyDisplay, CSSValueNone, true);
-
}
+
+bool TextFieldInputType::shouldOnlyShowDataListDropdownButtonWhenFocusedOrEdited()
+{
+#if PLATFORM(IOS_FAMILY)
+ return true;
+#else
+ return false;
#endif
+}
+
+#endif // ENABLE(DATALIST_ELEMENT)
static String limitLength(const String& string, unsigned maxNumGraphemeClusters)
{
@@ -667,10 +677,9 @@
if (RefPtr<Frame> frame = element()->document().frame())
frame->editor().textDidChangeInTextField(element());
#if ENABLE(DATALIST_ELEMENT)
-#if PLATFORM(IOS_FAMILY)
- if (element()->list() && m_dataListDropdownIndicator)
+ if (shouldOnlyShowDataListDropdownButtonWhenFocusedOrEdited() && element()->list() && m_dataListDropdownIndicator)
m_dataListDropdownIndicator->setInlineStyleProperty(CSSPropertyDisplay, suggestions().size() ? CSSValueBlock : CSSValueNone, true);
-#endif
+
if (element()->list())
displaySuggestions(DataListSuggestionActivationType::TextChanged);
#endif
@@ -833,9 +842,8 @@
if (!m_dataListDropdownIndicator)
createDataListDropdownIndicator();
-#if !PLATFORM(IOS_FAMILY)
- m_dataListDropdownIndicator->setInlineStyleProperty(CSSPropertyDisplay, element()->list() ? CSSValueBlock : CSSValueNone, true);
-#endif
+ if (!shouldOnlyShowDataListDropdownButtonWhenFocusedOrEdited())
+ m_dataListDropdownIndicator->setInlineStyleProperty(CSSPropertyDisplay, element()->list() ? CSSValueBlock : CSSValueNone, true);
}
HTMLElement* TextFieldInputType::dataListButtonElement() const
diff --git a/Source/WebCore/html/TextFieldInputType.h b/Source/WebCore/html/TextFieldInputType.h
index 5a17f15..d1d89a7 100644
--- a/Source/WebCore/html/TextFieldInputType.h
+++ b/Source/WebCore/html/TextFieldInputType.h
@@ -136,6 +136,8 @@
void didSelectDataListOption(const String&) final;
void didCloseSuggestions() final;
+ static bool shouldOnlyShowDataListDropdownButtonWhenFocusedOrEdited();
+
void dataListButtonElementWasClicked() final;
RefPtr<DataListButtonElement> m_dataListDropdownIndicator;