Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
[IPC] Adopt enum class for AutocapitalizeType
<https://webkit.org/b/212846>
<rdar://problem/64042825>

Reviewed by Darin Adler.

Summary:
- Move AutocapitalizeType into WebCore namespace.
- Convert AutocapitalizeType to an enum class.
- Add WTF::EnumTraits<AutocapitalizeType> for IPC.

Source/WebCore:

* html/Autocapitalize.cpp:
(WebCore::autocapitalizeTypeForAttributeValue):
(WebCore::stringForAutocapitalizeType):
* html/AutocapitalizeTypes.h:
* html/HTMLFormControlElement.cpp:
(WebCore::HTMLFormControlElement::autocapitalizeType const):

Source/WebKit:

* Shared/FocusedElementInformation.cpp:
(WebKit::FocusedElementInformation::encode const):
(WebKit::FocusedElementInformation::decode):
- Stop using decodeEnum() and encodeEnum() now that
  WTF::EnumTraits<AutocapitalizeType> exists.
* Shared/FocusedElementInformation.h:
* Shared/glib/InputMethodState.cpp:
(WebKit::InputMethodState::addHintsForAutocapitalizeType):
* Shared/glib/InputMethodState.h:
* UIProcess/ios/WKContentViewInteraction.mm:
(toUITextAutocapitalize):
* WebProcess/WebPage/ios/WebPageIOS.mm:
(WebKit::WebPage::getFocusedElementInformation):

Source/WebKitLegacy/mac:

* DOM/DOMHTML.mm:
(webAutocapitalizeType):


Canonical link: https://commits.webkit.org/225664@main
git-svn-id: https://svn.webkit.org/repository/webkit/trunk@262665 268f45cc-cd09-0410-ab3c-d52691b4dbfc
  • Loading branch information
ddkilzer committed Jun 6, 2020
1 parent 9fc30f1 commit f03432c
Show file tree
Hide file tree
Showing 13 changed files with 130 additions and 46 deletions.
20 changes: 20 additions & 0 deletions Source/WebCore/ChangeLog
@@ -1,3 +1,23 @@
2020-06-05 David Kilzer <ddkilzer@apple.com>

[IPC] Adopt enum class for AutocapitalizeType
<https://webkit.org/b/212846>
<rdar://problem/64042825>

Reviewed by Darin Adler.

Summary:
- Move AutocapitalizeType into WebCore namespace.
- Convert AutocapitalizeType to an enum class.
- Add WTF::EnumTraits<AutocapitalizeType> for IPC.

* html/Autocapitalize.cpp:
(WebCore::autocapitalizeTypeForAttributeValue):
(WebCore::stringForAutocapitalizeType):
* html/AutocapitalizeTypes.h:
* html/HTMLFormControlElement.cpp:
(WebCore::HTMLFormControlElement::autocapitalizeType const):

2020-06-05 Ryan Haddad <ryanhaddad@apple.com>

Unreviewed, reverting r262619, r262625, and r262641.
Expand Down
22 changes: 11 additions & 11 deletions Source/WebCore/html/Autocapitalize.cpp
Expand Up @@ -36,39 +36,39 @@ AutocapitalizeType autocapitalizeTypeForAttributeValue(const AtomString& attribu
{
// Omitted / missing values are the Default state.
if (attributeValue.isEmpty())
return AutocapitalizeTypeDefault;
return AutocapitalizeType::Default;

if (equalLettersIgnoringASCIICase(attributeValue, "on") || equalLettersIgnoringASCIICase(attributeValue, "sentences"))
return AutocapitalizeTypeSentences;
return AutocapitalizeType::Sentences;
if (equalLettersIgnoringASCIICase(attributeValue, "off") || equalLettersIgnoringASCIICase(attributeValue, "none"))
return AutocapitalizeTypeNone;
return AutocapitalizeType::None;
if (equalLettersIgnoringASCIICase(attributeValue, "words"))
return AutocapitalizeTypeWords;
return AutocapitalizeType::Words;
if (equalLettersIgnoringASCIICase(attributeValue, "characters"))
return AutocapitalizeTypeAllCharacters;
return AutocapitalizeType::AllCharacters;

// Unrecognized values fall back to "on".
return AutocapitalizeTypeSentences;
return AutocapitalizeType::Sentences;
}

const AtomString& stringForAutocapitalizeType(AutocapitalizeType type)
{
switch (type) {
case AutocapitalizeTypeDefault:
case AutocapitalizeType::Default:
return nullAtom();
case AutocapitalizeTypeNone: {
case AutocapitalizeType::None: {
static MainThreadNeverDestroyed<const AtomString> valueNone("none", AtomString::ConstructFromLiteral);
return valueNone;
}
case AutocapitalizeTypeSentences: {
case AutocapitalizeType::Sentences: {
static MainThreadNeverDestroyed<const AtomString> valueSentences("sentences", AtomString::ConstructFromLiteral);
return valueSentences;
}
case AutocapitalizeTypeWords: {
case AutocapitalizeType::Words: {
static MainThreadNeverDestroyed<const AtomString> valueWords("words", AtomString::ConstructFromLiteral);
return valueWords;
}
case AutocapitalizeTypeAllCharacters: {
case AutocapitalizeType::AllCharacters: {
static MainThreadNeverDestroyed<const AtomString> valueAllCharacters("characters", AtomString::ConstructFromLiteral);
return valueAllCharacters;
}
Expand Down
37 changes: 29 additions & 8 deletions Source/WebCore/html/AutocapitalizeTypes.h
@@ -1,5 +1,5 @@
/*
* Copyright (C) 2011 Apple Inc. All Rights Reserved.
* Copyright (C) 2011-2020 Apple Inc. All Rights Reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
Expand All @@ -25,10 +25,31 @@

#pragma once

typedef enum {
AutocapitalizeTypeDefault,
AutocapitalizeTypeNone,
AutocapitalizeTypeWords,
AutocapitalizeTypeSentences,
AutocapitalizeTypeAllCharacters
} AutocapitalizeType;
#include <wtf/EnumTraits.h>

namespace WebCore {

enum class AutocapitalizeType : uint8_t {
Default,
None,
Words,
Sentences,
AllCharacters
};

} // namespace WebCore

namespace WTF {

template<> struct EnumTraits<WebCore::AutocapitalizeType> {
using values = EnumValues<
WebCore::AutocapitalizeType,
WebCore::AutocapitalizeType::Default,
WebCore::AutocapitalizeType::None,
WebCore::AutocapitalizeType::Words,
WebCore::AutocapitalizeType::Sentences,
WebCore::AutocapitalizeType::AllCharacters
>;
};

} // namespace WTF
2 changes: 1 addition & 1 deletion Source/WebCore/html/HTMLFormControlElement.cpp
Expand Up @@ -633,7 +633,7 @@ bool HTMLFormControlElement::shouldAutocorrect() const
AutocapitalizeType HTMLFormControlElement::autocapitalizeType() const
{
AutocapitalizeType type = HTMLElement::autocapitalizeType();
if (type == AutocapitalizeTypeDefault) {
if (type == AutocapitalizeType::Default) {
if (RefPtr<HTMLFormElement> form = this->form())
return form->autocapitalizeType();
}
Expand Down
27 changes: 27 additions & 0 deletions Source/WebKit/ChangeLog
@@ -1,3 +1,30 @@
2020-06-05 David Kilzer <ddkilzer@apple.com>

[IPC] Adopt enum class for AutocapitalizeType
<https://webkit.org/b/212846>
<rdar://problem/64042825>

Reviewed by Darin Adler.

Summary:
- Move AutocapitalizeType into WebCore namespace.
- Convert AutocapitalizeType to an enum class.
- Add WTF::EnumTraits<AutocapitalizeType> for IPC.

* Shared/FocusedElementInformation.cpp:
(WebKit::FocusedElementInformation::encode const):
(WebKit::FocusedElementInformation::decode):
- Stop using decodeEnum() and encodeEnum() now that
WTF::EnumTraits<AutocapitalizeType> exists.
* Shared/FocusedElementInformation.h:
* Shared/glib/InputMethodState.cpp:
(WebKit::InputMethodState::addHintsForAutocapitalizeType):
* Shared/glib/InputMethodState.h:
* UIProcess/ios/WKContentViewInteraction.mm:
(toUITextAutocapitalize):
* WebProcess/WebPage/ios/WebPageIOS.mm:
(WebKit::WebPage::getFocusedElementInformation):

2020-06-05 Brent Fulgham <bfulgham@apple.com>

[iOS] Silence telemetry generated during download operations
Expand Down
4 changes: 2 additions & 2 deletions Source/WebKit/Shared/FocusedElementInformation.cpp
Expand Up @@ -76,7 +76,7 @@ void FocusedElementInformation::encode(IPC::Encoder& encoder) const
encoder << previousNodeRect;
encoder << isAutocorrect;
encoder << isRTL;
encoder.encodeEnum(autocapitalizeType);
encoder << autocapitalizeType;
encoder.encodeEnum(elementType);
encoder.encodeEnum(inputMode);
encoder.encodeEnum(enterKeyHint);
Expand Down Expand Up @@ -154,7 +154,7 @@ bool FocusedElementInformation::decode(IPC::Decoder& decoder, FocusedElementInfo
if (!decoder.decode(result.isRTL))
return false;

if (!decoder.decodeEnum(result.autocapitalizeType))
if (!decoder.decode(result.autocapitalizeType))
return false;

if (!decoder.decodeEnum(result.elementType))
Expand Down
6 changes: 3 additions & 3 deletions Source/WebKit/Shared/FocusedElementInformation.h
@@ -1,5 +1,5 @@
/*
* Copyright (C) 2014-2018 Apple Inc. All rights reserved.
* Copyright (C) 2014-2020 Apple Inc. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
Expand Down Expand Up @@ -116,7 +116,7 @@ struct FocusedElementInformation {
bool allowsUserScaling { false };
bool allowsUserScalingIgnoringAlwaysScalable { false };
bool insideFixedPosition { false };
AutocapitalizeType autocapitalizeType { AutocapitalizeTypeDefault };
WebCore::AutocapitalizeType autocapitalizeType { WebCore::AutocapitalizeType::Default };
InputType elementType { InputType::None };
WebCore::InputMode inputMode { WebCore::InputMode::Unspecified };
WebCore::EnterKeyHint enterKeyHint { WebCore::EnterKeyHint::Unspecified };
Expand Down Expand Up @@ -153,4 +153,4 @@ struct FocusedElementInformation {
};
#endif

}
} // namespace WebKit
12 changes: 6 additions & 6 deletions Source/WebKit/Shared/glib/InputMethodState.cpp
Expand Up @@ -83,21 +83,21 @@ void InputMethodState::setPurposeForInputElement(WebCore::HTMLInputElement& elem
purpose = Purpose::Digits;
}

void InputMethodState::addHintsForAutocapitalizeType(AutocapitalizeType autocapitalizeType)
void InputMethodState::addHintsForAutocapitalizeType(WebCore::AutocapitalizeType autocapitalizeType)
{
switch (autocapitalizeType) {
case AutocapitalizeTypeDefault:
case WebCore::AutocapitalizeType::Default:
break;
case AutocapitalizeTypeNone:
case WebCore::AutocapitalizeType::None:
hints.add(InputMethodState::Hint::Lowercase);
break;
case AutocapitalizeTypeWords:
case WebCore::AutocapitalizeType::Words:
hints.add(InputMethodState::Hint::UppercaseWords);
break;
case AutocapitalizeTypeSentences:
case WebCore::AutocapitalizeType::Sentences:
hints.add(InputMethodState::Hint::UppercaseSentences);
break;
case AutocapitalizeTypeAllCharacters:
case WebCore::AutocapitalizeType::AllCharacters:
hints.add(InputMethodState::Hint::UppercaseChars);
break;
}
Expand Down
2 changes: 1 addition & 1 deletion Source/WebKit/Shared/glib/InputMethodState.h
Expand Up @@ -64,7 +64,7 @@ struct InputMethodState {

void setPurposeOrHintForInputMode(WebCore::InputMode);
void setPurposeForInputElement(WebCore::HTMLInputElement&);
void addHintsForAutocapitalizeType(AutocapitalizeType);
void addHintsForAutocapitalizeType(WebCore::AutocapitalizeType);

void encode(IPC::Encoder&) const;
static Optional<InputMethodState> decode(IPC::Decoder&);
Expand Down
12 changes: 6 additions & 6 deletions Source/WebKit/UIProcess/ios/WKContentViewInteraction.mm
Expand Up @@ -4844,18 +4844,18 @@ - (BOOL)hasText

// end of UITextInput protocol implementation

static UITextAutocapitalizationType toUITextAutocapitalize(AutocapitalizeType webkitType)
static UITextAutocapitalizationType toUITextAutocapitalize(WebCore::AutocapitalizeType webkitType)
{
switch (webkitType) {
case AutocapitalizeTypeDefault:
case WebCore::AutocapitalizeType::Default:
return UITextAutocapitalizationTypeSentences;
case AutocapitalizeTypeNone:
case WebCore::AutocapitalizeType::None:
return UITextAutocapitalizationTypeNone;
case AutocapitalizeTypeWords:
case WebCore::AutocapitalizeType::Words:
return UITextAutocapitalizationTypeWords;
case AutocapitalizeTypeSentences:
case WebCore::AutocapitalizeType::Sentences:
return UITextAutocapitalizationTypeSentences;
case AutocapitalizeTypeAllCharacters:
case WebCore::AutocapitalizeType::AllCharacters:
return UITextAutocapitalizationTypeAllCharacters;
}

Expand Down
4 changes: 2 additions & 2 deletions Source/WebKit/WebProcess/WebPage/ios/WebPageIOS.mm
Expand Up @@ -3226,13 +3226,13 @@ static void populateCaretContext(const HitTestResult& hitTestResult, const Inter
information.shouldSynthesizeKeyEventsForEditing = focusedHTMLElement.document().settings().syntheticEditingCommandsEnabled();
} else {
information.isAutocorrect = true;
information.autocapitalizeType = AutocapitalizeTypeDefault;
information.autocapitalizeType = WebCore::AutocapitalizeType::Default;
}
information.isReadOnly = false;
}

if (focusedElement->document().quirks().shouldSuppressAutocorrectionAndAutocaptializationInHiddenEditableAreas() && isTransparentOrFullyClipped(*focusedElement)) {
information.autocapitalizeType = AutocapitalizeTypeNone;
information.autocapitalizeType = WebCore::AutocapitalizeType::None;
information.isAutocorrect = false;
}

Expand Down
16 changes: 16 additions & 0 deletions Source/WebKitLegacy/mac/ChangeLog
@@ -1,3 +1,19 @@
2020-06-05 David Kilzer <ddkilzer@apple.com>

[IPC] Adopt enum class for AutocapitalizeType
<https://webkit.org/b/212846>
<rdar://problem/64042825>

Reviewed by Darin Adler.

Summary:
- Move AutocapitalizeType into WebCore namespace.
- Convert AutocapitalizeType to an enum class.
- Add WTF::EnumTraits<AutocapitalizeType> for IPC.

* DOM/DOMHTML.mm:
(webAutocapitalizeType):

2020-06-05 David Kilzer <ddkilzer@apple.com>

[IPC] Adopt enum class for PluginLoadClientPolicy
Expand Down
12 changes: 6 additions & 6 deletions Source/WebKitLegacy/mac/DOM/DOMHTML.mm
Expand Up @@ -221,18 +221,18 @@ - (BOOL)_isEdited

@end

static WebAutocapitalizeType webAutocapitalizeType(AutocapitalizeType type)
static WebAutocapitalizeType webAutocapitalizeType(WebCore::AutocapitalizeType type)
{
switch (type) {
case AutocapitalizeTypeDefault:
case WebCore::AutocapitalizeType::Default:
return WebAutocapitalizeTypeDefault;
case AutocapitalizeTypeNone:
case WebCore::AutocapitalizeType::None:
return WebAutocapitalizeTypeNone;
case AutocapitalizeTypeWords:
case WebCore::AutocapitalizeType::Words:
return WebAutocapitalizeTypeWords;
case AutocapitalizeTypeSentences:
case WebCore::AutocapitalizeType::Sentences:
return WebAutocapitalizeTypeSentences;
case AutocapitalizeTypeAllCharacters:
case WebCore::AutocapitalizeType::AllCharacters:
return WebAutocapitalizeTypeAllCharacters;
}
}
Expand Down

0 comments on commit f03432c

Please sign in to comment.