Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
2011-01-04 Anders Carlsson <andersca@apple.com>
        Reviewed by Sam Weinig.

        Send over text checker state to the web process
        https://bugs.webkit.org/show_bug.cgi?id=51896

        * Platform/CoreIPC/Arguments.h:
        Remove 'const' from the argument, this matches all the other Arguments classes.

        * Shared/TextCheckerState.h: Added.
        New class with text checker state.

        * Shared/WebProcessCreationParameters.cpp:
        (WebKit::WebProcessCreationParameters::encode):
        (WebKit::WebProcessCreationParameters::decode):
        * Shared/WebProcessCreationParameters.h:
        Add textCheckerState.

        * UIProcess/API/mac/WKView.mm:
        (-[WKView validateUserInterfaceItem:]):
        (-[WKView toggleContinuousSpellChecking:]):
        (-[WKView toggleGrammarChecking:]):
        (-[WKView toggleAutomaticSpellingCorrection:]):
        Get the needed flags from the text checker state.

        * UIProcess/TextChecker.h:
        Add state() function, remove getters.

        * UIProcess/WebContext.cpp:
        (WebKit::WebContext::ensureWebProcess):
        Initialize the text checker state.

        * UIProcess/WebProcessProxy.cpp:
        (WebKit::WebProcessProxy::updateTextCheckerState):
        Send the SetTextCheckerState message to the web process.

        * UIProcess/mac/TextCheckerMac.mm:
        (WebKit::initializeState):
        Initialize the state from the user defaults.

        (WebKit::TextChecker::state):
        Return the state.

        (WebKit::TextChecker::setContinuousSpellCheckingEnabled):
        (WebKit::TextChecker::setGrammarCheckingEnabled):
        (WebKit::TextChecker::setAutomaticSpellingCorrectionEnabled):
        Make sure to write the new state.

        * UIProcess/qt/TextCheckerQt.cpp:
        (WebKit::TextChecker::state):
        * UIProcess/win/TextCheckerWin.cpp:
        (WebKit::TextChecker::state):
        Add stubs.

        * WebKit2.xcodeproj/project.pbxproj:
        Add TextCheckerState.h.

        * WebProcess/WebProcess.cpp:
        (WebKit::WebProcess::WebProcess):
        Initialize m_textCheckerState.

        (WebKit::WebProcess::setTextCheckerState):
        Update.

        * WebProcess/WebProcess.messages.in:
        Add SetTextCheckerState message.

        * win/WebKit2.vcproj:
        Add TextCheckerState.h.


Canonical link: https://commits.webkit.org/65338@main
git-svn-id: https://svn.webkit.org/repository/webkit/trunk@75010 268f45cc-cd09-0410-ab3c-d52691b4dbfc
  • Loading branch information
Anders Carlsson committed Jan 4, 2011
1 parent e04f4ba commit 485fa01
Show file tree
Hide file tree
Showing 18 changed files with 249 additions and 34 deletions.
71 changes: 71 additions & 0 deletions WebKit2/ChangeLog
@@ -1,3 +1,74 @@
2011-01-04 Anders Carlsson <andersca@apple.com>

Reviewed by Sam Weinig.

Send over text checker state to the web process
https://bugs.webkit.org/show_bug.cgi?id=51896

* Platform/CoreIPC/Arguments.h:
Remove 'const' from the argument, this matches all the other Arguments classes.

* Shared/TextCheckerState.h: Added.
New class with text checker state.

* Shared/WebProcessCreationParameters.cpp:
(WebKit::WebProcessCreationParameters::encode):
(WebKit::WebProcessCreationParameters::decode):
* Shared/WebProcessCreationParameters.h:
Add textCheckerState.

* UIProcess/API/mac/WKView.mm:
(-[WKView validateUserInterfaceItem:]):
(-[WKView toggleContinuousSpellChecking:]):
(-[WKView toggleGrammarChecking:]):
(-[WKView toggleAutomaticSpellingCorrection:]):
Get the needed flags from the text checker state.

* UIProcess/TextChecker.h:
Add state() function, remove getters.

* UIProcess/WebContext.cpp:
(WebKit::WebContext::ensureWebProcess):
Initialize the text checker state.

* UIProcess/WebProcessProxy.cpp:
(WebKit::WebProcessProxy::updateTextCheckerState):
Send the SetTextCheckerState message to the web process.

* UIProcess/mac/TextCheckerMac.mm:
(WebKit::initializeState):
Initialize the state from the user defaults.

(WebKit::TextChecker::state):
Return the state.

(WebKit::TextChecker::setContinuousSpellCheckingEnabled):
(WebKit::TextChecker::setGrammarCheckingEnabled):
(WebKit::TextChecker::setAutomaticSpellingCorrectionEnabled):
Make sure to write the new state.

* UIProcess/qt/TextCheckerQt.cpp:
(WebKit::TextChecker::state):
* UIProcess/win/TextCheckerWin.cpp:
(WebKit::TextChecker::state):
Add stubs.

* WebKit2.xcodeproj/project.pbxproj:
Add TextCheckerState.h.

* WebProcess/WebProcess.cpp:
(WebKit::WebProcess::WebProcess):
Initialize m_textCheckerState.

(WebKit::WebProcess::setTextCheckerState):
Update.

* WebProcess/WebProcess.messages.in:
Add SetTextCheckerState message.

* win/WebKit2.vcproj:
Add TextCheckerState.h.

2011-01-04 Brady Eidson <beidson@apple.com>

Rubberstamped by Anders Carlsson.
Expand Down
2 changes: 1 addition & 1 deletion WebKit2/Platform/CoreIPC/Arguments.h
Expand Up @@ -56,7 +56,7 @@ inline Arguments0 Out()
}

template<typename T1> struct Arguments1 {
typedef Arguments1<typename WTF::RemoveReference<T1>::Type> ValueType;
typedef Arguments1<typename WTF::RemoveConst<typename WTF::RemoveReference<T1>::Type>::Type> ValueType;

Arguments1()
{
Expand Down
48 changes: 48 additions & 0 deletions WebKit2/Shared/TextCheckerState.h
@@ -0,0 +1,48 @@
/*
* Copyright (C) 2011 Apple Inc. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
* THE POSSIBILITY OF SUCH DAMAGE.
*/

#ifndef TextCheckerState_h
#define TextCheckerState_h

#include "ArgumentCoders.h"

namespace WebKit {

struct TextCheckerState {
bool isContinuousSpellCheckingEnabled;
bool isGrammarCheckingEnabled;

#if PLATFORM(MAC)
bool isAutomaticSpellingCorrectionEnabled;
#endif
};

} // namespace WebKit

namespace CoreIPC {
template<> struct ArgumentCoder<WebKit::TextCheckerState> : SimpleArgumentCoder<WebKit::TextCheckerState> { };
};

#endif // TextCheckerState_h
4 changes: 4 additions & 0 deletions WebKit2/Shared/WebProcessCreationParameters.cpp
Expand Up @@ -54,6 +54,7 @@ void WebProcessCreationParameters::encode(CoreIPC::ArgumentEncoder* encoder) con
encoder->encode(shouldTrackVisitedLinks);
encoder->encode(shouldAlwaysUseComplexTextCodePath);
encoder->encode(languageCode);
encoder->encode(textCheckerState);
#if PLATFORM(MAC)
encoder->encode(nsURLCachePath);
encoder->encode(nsURLCacheMemoryCapacity);
Expand Down Expand Up @@ -88,6 +89,9 @@ bool WebProcessCreationParameters::decode(CoreIPC::ArgumentDecoder* decoder, Web
return false;
if (!decoder->decode(parameters.languageCode))
return false;
if (!decoder->decode(parameters.textCheckerState))
return false;

#if PLATFORM(MAC)
if (!decoder->decode(parameters.nsURLCachePath))
return false;
Expand Down
3 changes: 3 additions & 0 deletions WebKit2/Shared/WebProcessCreationParameters.h
Expand Up @@ -28,6 +28,7 @@

#include "CacheModel.h"
#include "SandboxExtension.h"
#include "TextCheckerState.h"
#include <wtf/Vector.h>
#include <wtf/text/WTFString.h>

Expand Down Expand Up @@ -69,6 +70,8 @@ struct WebProcessCreationParameters {

String languageCode;

TextCheckerState textCheckerState;

#if PLATFORM(MAC)
String nsURLCachePath;
uint64_t nsURLCacheMemoryCapacity;
Expand Down
19 changes: 13 additions & 6 deletions WebKit2/UIProcess/API/mac/WKView.mm
Expand Up @@ -35,6 +35,7 @@
#import "PageClientImpl.h"
#import "RunLoop.h"
#import "TextChecker.h"
#import "TextCheckerState.h"
#import "WKAPICast.h"
#import "WKStringCF.h"
#import "WKTextInputWindowController.h"
Expand Down Expand Up @@ -348,19 +349,19 @@ - (BOOL)validateUserInterfaceItem:(id <NSValidatedUserInterfaceItem>)item

if (action == @selector(toggleContinuousSpellChecking:)) {
bool enabled = TextChecker::isContinuousSpellCheckingAllowed();
bool checked = enabled && TextChecker::isContinuousSpellCheckingEnabled();
bool checked = enabled && TextChecker::state().isContinuousSpellCheckingEnabled;
[menuItem(item) setState:checked ? NSOnState : NSOffState];
return enabled;
}

if (action == @selector(toggleGrammarChecking:)) {
bool checked = TextChecker::isGrammarCheckingEnabled();
bool checked = TextChecker::state().isGrammarCheckingEnabled;
[menuItem(item) setState:checked ? NSOnState : NSOffState];
return YES;
}

if (action == @selector(toggleAutomaticSpellingCorrection:)) {
bool checked = TextChecker::isAutomaticSpellingCorrectionEnabled();
bool checked = TextChecker::state().isAutomaticSpellingCorrectionEnabled;
[menuItem(item) setState:checked ? NSOnState : NSOffState];
return _data->_page->selectionState().isContentEditable;
}
Expand Down Expand Up @@ -424,25 +425,31 @@ - (IBAction)checkSpelling:(id)sender

- (IBAction)toggleContinuousSpellChecking:(id)sender
{
bool spellCheckingEnabled = !TextChecker::isContinuousSpellCheckingEnabled();
bool spellCheckingEnabled = !TextChecker::state().isContinuousSpellCheckingEnabled;
TextChecker::setContinuousSpellCheckingEnabled(spellCheckingEnabled);

_data->_page->process()->updateTextCheckerState();

if (!spellCheckingEnabled)
_data->_page->unmarkAllMisspellings();
}

- (IBAction)toggleGrammarChecking:(id)sender
{
bool grammarCheckingEnabled = !TextChecker::isGrammarCheckingEnabled();
bool grammarCheckingEnabled = !TextChecker::state().isGrammarCheckingEnabled;
TextChecker::setGrammarCheckingEnabled(grammarCheckingEnabled);

_data->_page->process()->updateTextCheckerState();

if (!grammarCheckingEnabled)
_data->_page->unmarkAllBadGrammar();
}

- (IBAction)toggleAutomaticSpellingCorrection:(id)sender
{
TextChecker::setAutomaticSpellingCorrectionEnabled(!TextChecker::isAutomaticSpellingCorrectionEnabled());
TextChecker::setAutomaticSpellingCorrectionEnabled(!TextChecker::state().isAutomaticSpellingCorrectionEnabled);

_data->_page->process()->updateTextCheckerState();
}

// Events
Expand Down
10 changes: 6 additions & 4 deletions WebKit2/UIProcess/TextChecker.h
Expand Up @@ -28,17 +28,19 @@

namespace WebKit {

class TextCheckerState;

class TextChecker {
public:
static const TextCheckerState& state();
static bool isContinuousSpellCheckingAllowed();
static bool isContinuousSpellCheckingEnabled();
static void setContinuousSpellCheckingEnabled(bool);

static bool isGrammarCheckingEnabled();
static void setContinuousSpellCheckingEnabled(bool);
static void setGrammarCheckingEnabled(bool);

#if PLATFORM(MAC)
static void setAutomaticSpellingCorrectionEnabled(bool);
static bool isAutomaticSpellingCorrectionEnabled();
#endif
};

} // namespace WebKit
Expand Down
3 changes: 3 additions & 0 deletions WebKit2/UIProcess/WebContext.cpp
Expand Up @@ -29,6 +29,7 @@
#include "ImmutableArray.h"
#include "InjectedBundleMessageKinds.h"
#include "RunLoop.h"
#include "TextChecker.h"
#include "WKContextPrivate.h"
#include "WebContextMessageKinds.h"
#include "WebContextUserMessageCoders.h"
Expand Down Expand Up @@ -174,6 +175,8 @@ void WebContext::ensureWebProcess()

parameters.shouldAlwaysUseComplexTextCodePath = m_alwaysUsesComplexTextCodePath;

parameters.textCheckerState = TextChecker::state();

// Add any platform specific parameters
platformInitializeWebProcess(parameters);

Expand Down
10 changes: 10 additions & 0 deletions WebKit2/UIProcess/WebProcessProxy.cpp
Expand Up @@ -27,6 +27,8 @@

#include "PluginInfoStore.h"
#include "PluginProcessManager.h"
#include "TextChecker.h"
#include "TextCheckerState.h"
#include "WebBackForwardListItem.h"
#include "WebContext.h"
#include "WebNavigationDataStore.h"
Expand Down Expand Up @@ -391,4 +393,12 @@ size_t WebProcessProxy::frameCountInPage(WebPageProxy* page) const
return result;
}

void WebProcessProxy::updateTextCheckerState()
{
if (!isValid())
return;

send(Messages::WebProcess::SetTextCheckerState(TextChecker::state()), 0);
}

} // namespace WebKit
2 changes: 2 additions & 0 deletions WebKit2/UIProcess/WebProcessProxy.h
Expand Up @@ -102,6 +102,8 @@ class WebProcessProxy : public RefCounted<WebProcessProxy>, CoreIPC::Connection:
void disconnectFramesFromPage(WebPageProxy*); // Including main frame.
size_t frameCountInPage(WebPageProxy*) const; // Including main frame.

void updateTextCheckerState();

private:
explicit WebProcessProxy(WebContext*);

Expand Down

0 comments on commit 485fa01

Please sign in to comment.