WebKit Bugzilla
Attachment 347707 Details for
Bug 188820
: Remove extern variable and simplify state initialization in TextCheckerMac.mm
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Requests
|
Help
|
New Account
|
Log In
Remember
[x]
|
Forgot Password
Login:
[x]
[patch]
Patch
bug-188820-20180821151202.patch (text/plain), 13.66 KB, created by
Daniel Bates
on 2018-08-21 15:12:02 PDT
(
hide
)
Description:
Patch
Filename:
MIME Type:
Creator:
Daniel Bates
Created:
2018-08-21 15:12:02 PDT
Size:
13.66 KB
patch
obsolete
>Subversion Revision: 234848 >diff --git a/Source/WebKit/ChangeLog b/Source/WebKit/ChangeLog >index 18c525c04cfdae953d1ffce6da6587a21cccabe6..54183457f1d2720003a8b9c6ce6cda36f0696809 100644 >--- a/Source/WebKit/ChangeLog >+++ b/Source/WebKit/ChangeLog >@@ -1,3 +1,34 @@ >+2018-08-21 Daniel Bates <dabates@apple.com> >+ >+ Remove extern variable and simplify state initialization in TextCheckerMac.mm >+ https://bugs.webkit.org/show_bug.cgi?id=188820 >+ >+ Reviewed by NOBODY (OOPS!). >+ >+ Use the same approach to initializing the TextCheckerState in TextCheckerMac.mm as we did in >+ TextCheckerIOS.mm. Make use of a static, non-member, file-local function and NeverDestroyed >+ to initialize a TextCheckerState object once and provide access to it from other implementation >+ functions. >+ >+ * UIProcess/mac/TextCheckerMac.mm: >+ (WebKit::mutableState): >+ (WebKit::TextChecker::state): >+ (WebKit::TextChecker::setTestingMode): >+ (WebKit::TextChecker::setContinuousSpellCheckingEnabled): >+ (WebKit::TextChecker::setGrammarCheckingEnabled): >+ (WebKit::TextChecker::setAutomaticSpellingCorrectionEnabled): >+ (WebKit::TextChecker::setAutomaticQuoteSubstitutionEnabled): >+ (WebKit::TextChecker::setAutomaticDashSubstitutionEnabled): >+ (WebKit::TextChecker::setAutomaticLinkDetectionEnabled): >+ (WebKit::TextChecker::setAutomaticTextReplacementEnabled): >+ (WebKit::TextChecker::didChangeAutomaticTextReplacementEnabled): >+ (WebKit::TextChecker::didChangeAutomaticSpellingCorrectionEnabled): >+ (WebKit::TextChecker::didChangeAutomaticQuoteSubstitutionEnabled): >+ (WebKit::TextChecker::didChangeAutomaticDashSubstitutionEnabled): >+ (WebKit::TextChecker::continuousSpellCheckingEnabledStateChanged): >+ (WebKit::TextChecker::grammarCheckingEnabledStateChanged): >+ (WebKit::initializeState): Deleted. >+ > 2018-08-21 Daniel Bates <dabates@apple.com> > > Cleanup: Remove unused file-local static variable from TextCheckerIOS.mm >diff --git a/Source/WebKit/UIProcess/mac/TextCheckerMac.mm b/Source/WebKit/UIProcess/mac/TextCheckerMac.mm >index 2f7b4774ce8013e1a82892c29e867ee1ac0fa3dc..4c0a4d458f6000d2d9d71068e2e7cb26fd09e1ad 100644 >--- a/Source/WebKit/UIProcess/mac/TextCheckerMac.mm >+++ b/Source/WebKit/UIProcess/mac/TextCheckerMac.mm >@@ -1,5 +1,5 @@ > /* >- * Copyright (C) 2010, 2011 Apple Inc. All rights reserved. >+ * Copyright (C) 2010-2018 Apple Inc. All rights reserved. > * > * Redistribution and use in source and binary forms, with or without > * modification, are permitted provided that the following conditions >@@ -31,6 +31,7 @@ > #import "TextCheckerState.h" > #import <WebCore/NotImplemented.h> > #import <pal/spi/mac/NSSpellCheckerSPI.h> >+#import <wtf/NeverDestroyed.h> > #import <wtf/RetainPtr.h> > #import <wtf/text/StringView.h> > >@@ -56,8 +57,6 @@ using namespace WebCore; > > namespace WebKit { > >-TextCheckerState textCheckerState; >- > static bool shouldAutomaticTextReplacementBeEnabled() > { > NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults]; >@@ -92,28 +91,25 @@ static bool shouldAutomaticDashSubstitutionBeEnabled() > return [defaults boolForKey:WebAutomaticDashSubstitutionEnabled]; > } > >-static void initializeState() >+static TextCheckerState& mutableState() > { >- static bool didInitializeState = false; >- >- if (didInitializeState) >- return; >- >- textCheckerState.isContinuousSpellCheckingEnabled = [[NSUserDefaults standardUserDefaults] boolForKey:WebContinuousSpellCheckingEnabled] && TextChecker::isContinuousSpellCheckingAllowed(); >- textCheckerState.isGrammarCheckingEnabled = [[NSUserDefaults standardUserDefaults] boolForKey:WebGrammarCheckingEnabled]; >- textCheckerState.isAutomaticTextReplacementEnabled = shouldAutomaticTextReplacementBeEnabled(); >- textCheckerState.isAutomaticSpellingCorrectionEnabled = shouldAutomaticSpellingCorrectionBeEnabled(); >- textCheckerState.isAutomaticQuoteSubstitutionEnabled = shouldAutomaticQuoteSubstitutionBeEnabled(); >- textCheckerState.isAutomaticDashSubstitutionEnabled = shouldAutomaticDashSubstitutionBeEnabled(); >- textCheckerState.isAutomaticLinkDetectionEnabled = [[NSUserDefaults standardUserDefaults] boolForKey:WebAutomaticLinkDetectionEnabled]; >- >- didInitializeState = true; >+ static NeverDestroyed<TextCheckerState> state = makeNeverDestroyed([] { >+ TextCheckerState initialState; >+ initialState.isContinuousSpellCheckingEnabled = [[NSUserDefaults standardUserDefaults] boolForKey:WebContinuousSpellCheckingEnabled] && TextChecker::isContinuousSpellCheckingAllowed(); >+ initialState.isGrammarCheckingEnabled = [[NSUserDefaults standardUserDefaults] boolForKey:WebGrammarCheckingEnabled]; >+ initialState.isAutomaticTextReplacementEnabled = shouldAutomaticTextReplacementBeEnabled(); >+ initialState.isAutomaticSpellingCorrectionEnabled = shouldAutomaticSpellingCorrectionBeEnabled(); >+ initialState.isAutomaticQuoteSubstitutionEnabled = shouldAutomaticQuoteSubstitutionBeEnabled(); >+ initialState.isAutomaticDashSubstitutionEnabled = shouldAutomaticDashSubstitutionBeEnabled(); >+ initialState.isAutomaticLinkDetectionEnabled = [[NSUserDefaults standardUserDefaults] boolForKey:WebAutomaticLinkDetectionEnabled]; >+ return initialState; >+ }()); >+ return state; > } > > const TextCheckerState& TextChecker::state() > { >- initializeState(); >- return textCheckerState; >+ return mutableState(); > } > > static bool testingModeEnabled = false; >@@ -121,13 +117,13 @@ static bool testingModeEnabled = false; > void TextChecker::setTestingMode(bool enabled) > { > if (enabled && !testingModeEnabled) { >- [[NSUserDefaults standardUserDefaults] setBool:textCheckerState.isContinuousSpellCheckingEnabled forKey:WebContinuousSpellCheckingEnabled]; >- [[NSUserDefaults standardUserDefaults] setBool:textCheckerState.isGrammarCheckingEnabled forKey:WebGrammarCheckingEnabled]; >- [[NSUserDefaults standardUserDefaults] setBool:textCheckerState.isAutomaticSpellingCorrectionEnabled forKey:WebAutomaticSpellingCorrectionEnabled]; >- [[NSUserDefaults standardUserDefaults] setBool:textCheckerState.isAutomaticQuoteSubstitutionEnabled forKey:WebAutomaticQuoteSubstitutionEnabled]; >- [[NSUserDefaults standardUserDefaults] setBool:textCheckerState.isAutomaticDashSubstitutionEnabled forKey:WebAutomaticDashSubstitutionEnabled]; >- [[NSUserDefaults standardUserDefaults] setBool:textCheckerState.isAutomaticLinkDetectionEnabled forKey:WebAutomaticLinkDetectionEnabled]; >- [[NSUserDefaults standardUserDefaults] setBool:textCheckerState.isAutomaticTextReplacementEnabled forKey:WebAutomaticTextReplacementEnabled]; >+ [[NSUserDefaults standardUserDefaults] setBool:mutableState().isContinuousSpellCheckingEnabled forKey:WebContinuousSpellCheckingEnabled]; >+ [[NSUserDefaults standardUserDefaults] setBool:mutableState().isGrammarCheckingEnabled forKey:WebGrammarCheckingEnabled]; >+ [[NSUserDefaults standardUserDefaults] setBool:mutableState().isAutomaticSpellingCorrectionEnabled forKey:WebAutomaticSpellingCorrectionEnabled]; >+ [[NSUserDefaults standardUserDefaults] setBool:mutableState().isAutomaticQuoteSubstitutionEnabled forKey:WebAutomaticQuoteSubstitutionEnabled]; >+ [[NSUserDefaults standardUserDefaults] setBool:mutableState().isAutomaticDashSubstitutionEnabled forKey:WebAutomaticDashSubstitutionEnabled]; >+ [[NSUserDefaults standardUserDefaults] setBool:mutableState().isAutomaticLinkDetectionEnabled forKey:WebAutomaticLinkDetectionEnabled]; >+ [[NSUserDefaults standardUserDefaults] setBool:mutableState().isAutomaticTextReplacementEnabled forKey:WebAutomaticTextReplacementEnabled]; > [[NSUserDefaults standardUserDefaults] setBool:isSmartInsertDeleteEnabled() forKey:WebSmartInsertDeleteEnabled]; > } > testingModeEnabled = enabled; >@@ -158,7 +154,7 @@ void TextChecker::setContinuousSpellCheckingEnabled(bool isContinuousSpellChecki > if (state().isContinuousSpellCheckingEnabled == isContinuousSpellCheckingEnabled) > return; > >- textCheckerState.isContinuousSpellCheckingEnabled = isContinuousSpellCheckingEnabled; >+ mutableState().isContinuousSpellCheckingEnabled = isContinuousSpellCheckingEnabled; > if (!testingModeEnabled) > [[NSUserDefaults standardUserDefaults] setBool:isContinuousSpellCheckingEnabled forKey:WebContinuousSpellCheckingEnabled]; > >@@ -170,7 +166,7 @@ void TextChecker::setGrammarCheckingEnabled(bool isGrammarCheckingEnabled) > if (state().isGrammarCheckingEnabled == isGrammarCheckingEnabled) > return; > >- textCheckerState.isGrammarCheckingEnabled = isGrammarCheckingEnabled; >+ mutableState().isGrammarCheckingEnabled = isGrammarCheckingEnabled; > if (!testingModeEnabled) > [[NSUserDefaults standardUserDefaults] setBool:isGrammarCheckingEnabled forKey:WebGrammarCheckingEnabled]; > [[NSSpellChecker sharedSpellChecker] updatePanels]; >@@ -184,7 +180,7 @@ void TextChecker::setAutomaticSpellingCorrectionEnabled(bool isAutomaticSpelling > if (state().isAutomaticSpellingCorrectionEnabled == isAutomaticSpellingCorrectionEnabled) > return; > >- textCheckerState.isAutomaticSpellingCorrectionEnabled = isAutomaticSpellingCorrectionEnabled; >+ mutableState().isAutomaticSpellingCorrectionEnabled = isAutomaticSpellingCorrectionEnabled; > if (!testingModeEnabled) > [[NSUserDefaults standardUserDefaults] setBool:isAutomaticSpellingCorrectionEnabled forKey:WebAutomaticSpellingCorrectionEnabled]; > >@@ -196,7 +192,7 @@ void TextChecker::setAutomaticQuoteSubstitutionEnabled(bool isAutomaticQuoteSubs > if (state().isAutomaticQuoteSubstitutionEnabled == isAutomaticQuoteSubstitutionEnabled) > return; > >- textCheckerState.isAutomaticQuoteSubstitutionEnabled = isAutomaticQuoteSubstitutionEnabled; >+ mutableState().isAutomaticQuoteSubstitutionEnabled = isAutomaticQuoteSubstitutionEnabled; > if (!testingModeEnabled) > [[NSUserDefaults standardUserDefaults] setBool:isAutomaticQuoteSubstitutionEnabled forKey:WebAutomaticQuoteSubstitutionEnabled]; > >@@ -208,7 +204,7 @@ void TextChecker::setAutomaticDashSubstitutionEnabled(bool isAutomaticDashSubsti > if (state().isAutomaticDashSubstitutionEnabled == isAutomaticDashSubstitutionEnabled) > return; > >- textCheckerState.isAutomaticDashSubstitutionEnabled = isAutomaticDashSubstitutionEnabled; >+ mutableState().isAutomaticDashSubstitutionEnabled = isAutomaticDashSubstitutionEnabled; > if (!testingModeEnabled) > [[NSUserDefaults standardUserDefaults] setBool:isAutomaticDashSubstitutionEnabled forKey:WebAutomaticDashSubstitutionEnabled]; > >@@ -220,7 +216,7 @@ void TextChecker::setAutomaticLinkDetectionEnabled(bool isAutomaticLinkDetection > if (state().isAutomaticLinkDetectionEnabled == isAutomaticLinkDetectionEnabled) > return; > >- textCheckerState.isAutomaticLinkDetectionEnabled = isAutomaticLinkDetectionEnabled; >+ mutableState().isAutomaticLinkDetectionEnabled = isAutomaticLinkDetectionEnabled; > if (!testingModeEnabled) > [[NSUserDefaults standardUserDefaults] setBool:isAutomaticLinkDetectionEnabled forKey:WebAutomaticLinkDetectionEnabled]; > >@@ -232,7 +228,7 @@ void TextChecker::setAutomaticTextReplacementEnabled(bool isAutomaticTextReplace > if (state().isAutomaticTextReplacementEnabled == isAutomaticTextReplacementEnabled) > return; > >- textCheckerState.isAutomaticTextReplacementEnabled = isAutomaticTextReplacementEnabled; >+ mutableState().isAutomaticTextReplacementEnabled = isAutomaticTextReplacementEnabled; > if (!testingModeEnabled) > [[NSUserDefaults standardUserDefaults] setBool:isAutomaticTextReplacementEnabled forKey:WebAutomaticTextReplacementEnabled]; > >@@ -267,25 +263,25 @@ void TextChecker::setSmartInsertDeleteEnabled(bool flag) > > void TextChecker::didChangeAutomaticTextReplacementEnabled() > { >- textCheckerState.isAutomaticTextReplacementEnabled = shouldAutomaticTextReplacementBeEnabled(); >+ mutableState().isAutomaticTextReplacementEnabled = shouldAutomaticTextReplacementBeEnabled(); > [[NSSpellChecker sharedSpellChecker] updatePanels]; > } > > void TextChecker::didChangeAutomaticSpellingCorrectionEnabled() > { >- textCheckerState.isAutomaticSpellingCorrectionEnabled = shouldAutomaticSpellingCorrectionBeEnabled(); >+ mutableState().isAutomaticSpellingCorrectionEnabled = shouldAutomaticSpellingCorrectionBeEnabled(); > [[NSSpellChecker sharedSpellChecker] updatePanels]; > } > > void TextChecker::didChangeAutomaticQuoteSubstitutionEnabled() > { >- textCheckerState.isAutomaticQuoteSubstitutionEnabled = shouldAutomaticQuoteSubstitutionBeEnabled(); >+ mutableState().isAutomaticQuoteSubstitutionEnabled = shouldAutomaticQuoteSubstitutionBeEnabled(); > [[NSSpellChecker sharedSpellChecker] updatePanels]; > } > > void TextChecker::didChangeAutomaticDashSubstitutionEnabled() > { >- textCheckerState.isAutomaticDashSubstitutionEnabled = shouldAutomaticDashSubstitutionBeEnabled(); >+ mutableState().isAutomaticDashSubstitutionEnabled = shouldAutomaticDashSubstitutionBeEnabled(); > [[NSSpellChecker sharedSpellChecker] updatePanels]; > } > >@@ -306,12 +302,12 @@ void TextChecker::toggleSubstitutionsPanelIsShowing() > > void TextChecker::continuousSpellCheckingEnabledStateChanged(bool enabled) > { >- textCheckerState.isContinuousSpellCheckingEnabled = enabled; >+ mutableState().isContinuousSpellCheckingEnabled = enabled; > } > > void TextChecker::grammarCheckingEnabledStateChanged(bool enabled) > { >- textCheckerState.isGrammarCheckingEnabled = enabled; >+ mutableState().isGrammarCheckingEnabled = enabled; > } > > SpellDocumentTag TextChecker::uniqueSpellDocumentTag(WebPageProxy*)
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Formatted Diff
|
Diff
Attachments on
bug 188820
: 347707