Commit 68992307 authored by Dmitry Gozman's avatar Dmitry Gozman Committed by Commit Bot

Remove SpellCheckerClient

After removing web/, SpellCheckerClient is just an extra indirection
layer to talk from core/ to core/ through WebViewImpl.
This patch replaces it with a single page-wide SpellCheckState field.

We can make a page supplement to avoid even mentioning spell checking
in Page, but that's probably too much trouble for little benefit.

Bug: none
Change-Id: Ia8778941ce066a17a5a4fe8e34cd69971053d407
Reviewed-on: https://chromium-review.googlesource.com/764977
Commit-Queue: Dmitry Gozman <dgozman@chromium.org>
Reviewed-by: default avatarXiaocheng Hu <xiaochengh@chromium.org>
Reviewed-by: default avatarDaniel Cheng <dcheng@chromium.org>
Reviewed-by: default avatarYoshifumi Inoue <yosin@chromium.org>
Cr-Commit-Position: refs/heads/master@{#516357}
parent c7f96e57
......@@ -278,9 +278,6 @@ blink_core_sources("editing") {
"spellcheck/SpellCheckRequester.h",
"spellcheck/SpellChecker.cpp",
"spellcheck/SpellChecker.h",
"spellcheck/SpellCheckerClient.h",
"spellcheck/SpellCheckerClientImpl.cpp",
"spellcheck/SpellCheckerClientImpl.h",
"spellcheck/TextCheckerClientImpl.cpp",
"spellcheck/TextCheckerClientImpl.h",
"spellcheck/TextCheckingParagraph.cpp",
......
......@@ -11,9 +11,8 @@ namespace blink {
void SpellCheckTestBase::SetUp() {
Page::PageClients page_clients;
FillWithEmptyClients(page_clients);
spell_checker_client_ = WTF::WrapUnique(new DummySpellCheckerClient);
page_clients.spell_checker_client = spell_checker_client_.get();
SetupPageWithClients(&page_clients);
GetPage().SetSpellCheckStatus(Page::SpellCheckStatus::kForcedOn);
}
SpellChecker& SpellCheckTestBase::GetSpellChecker() const {
......
......@@ -18,16 +18,6 @@ class SpellCheckTestBase : public EditingTestBase {
void SetUp() override;
SpellChecker& GetSpellChecker() const;
private:
class DummySpellCheckerClient : public EmptySpellCheckerClient {
public:
virtual ~DummySpellCheckerClient() {}
bool IsSpellCheckingEnabled() override { return true; }
};
std::unique_ptr<DummySpellCheckerClient> spell_checker_client_;
};
} // namespace blink
......
......@@ -47,7 +47,6 @@
#include "core/editing/markers/SpellCheckMarker.h"
#include "core/editing/spellcheck/IdleSpellCheckCallback.h"
#include "core/editing/spellcheck/SpellCheckRequester.h"
#include "core/editing/spellcheck/SpellCheckerClient.h"
#include "core/editing/spellcheck/TextCheckingParagraph.h"
#include "core/frame/LocalFrame.h"
#include "core/frame/Settings.h"
......@@ -56,6 +55,7 @@
#include "core/input_type_names.h"
#include "core/layout/LayoutTextControl.h"
#include "core/loader/EmptyClients.h"
#include "core/page/FocusController.h"
#include "core/page/Page.h"
#include "platform/text/TextBreakIterator.h"
#include "platform/text/TextCheckerClient.h"
......@@ -80,17 +80,6 @@ SpellChecker* SpellChecker::Create(LocalFrame& frame) {
return new SpellChecker(frame);
}
static SpellCheckerClient& GetEmptySpellCheckerClient() {
DEFINE_STATIC_LOCAL(EmptySpellCheckerClient, client, ());
return client;
}
SpellCheckerClient& SpellChecker::GetSpellCheckerClient() const {
if (Page* page = GetFrame().GetPage())
return page->GetSpellCheckerClient();
return GetEmptySpellCheckerClient();
}
static WebSpellCheckPanelHostClient& GetEmptySpellCheckPanelHostClient() {
DEFINE_STATIC_LOCAL(EmptySpellCheckPanelHostClient, client, ());
return client;
......@@ -114,13 +103,31 @@ SpellChecker::SpellChecker(LocalFrame& frame)
idle_spell_check_callback_(IdleSpellCheckCallback::Create(frame)) {}
bool SpellChecker::IsSpellCheckingEnabled() const {
return GetSpellCheckerClient().IsSpellCheckingEnabled();
if (Page* page = GetFrame().GetPage()) {
if (page->GetSpellCheckStatus() == Page::SpellCheckStatus::kForcedOff)
return false;
if (page->GetSpellCheckStatus() == Page::SpellCheckStatus::kForcedOn)
return true;
}
return ShouldSpellcheckByDefault();
}
void SpellChecker::ToggleSpellCheckingEnabled() {
GetSpellCheckerClient().ToggleSpellCheckingEnabled();
if (IsSpellCheckingEnabled())
Page* page = GetFrame().GetPage();
if (!page)
return;
if (IsSpellCheckingEnabled()) {
page->SetSpellCheckStatus(Page::SpellCheckStatus::kForcedOff);
for (Frame* frame = page->MainFrame(); frame;
frame = frame->Tree().TraverseNext()) {
if (!frame->IsLocalFrame())
continue;
ToLocalFrame(frame)->GetDocument()->Markers().RemoveMarkersOfTypes(
DocumentMarker::MisspellingMarkers());
}
} else {
page->SetSpellCheckStatus(Page::SpellCheckStatus::kForcedOn);
}
}
void SpellChecker::IgnoreSpelling() {
......@@ -659,6 +666,37 @@ void SpellChecker::PrepareForLeakDetection() {
idle_spell_check_callback_->Deactivate();
}
bool SpellChecker::ShouldSpellcheckByDefault() const {
// Spellcheck should be enabled for all editable areas (such as textareas,
// contentEditable regions, designMode docs and inputs).
Page* page = GetFrame().GetPage();
if (!page)
return false;
Frame* focused_frame = page->GetFocusController().FocusedOrMainFrame();
if (!focused_frame->IsLocalFrame())
return false;
const LocalFrame* frame = ToLocalFrame(focused_frame);
if (frame->GetSpellChecker().IsSpellCheckingEnabledInFocusedNode())
return true;
const Document* document = frame->GetDocument();
if (!document)
return false;
const Element* element = document->FocusedElement();
// If |element| is null, we default to allowing spellchecking. This is done
// in order to mitigate the issue when the user clicks outside the textbox,
// as a result of which |element| becomes null, resulting in all the spell
// check markers being deleted. Also, the LocalFrame will decide not to do
// spellchecking if the user can't edit - so returning true here will not
// cause any problems to the LocalFrame's behavior.
if (!element)
return true;
const LayoutObject* layout_object = element->GetLayoutObject();
if (!layout_object)
return false;
return true;
}
Vector<TextCheckingResult> SpellChecker::FindMisspellings(const String& text) {
Vector<UChar> characters;
text.AppendTo(characters);
......
......@@ -39,7 +39,6 @@ class Element;
class IdleSpellCheckCallback;
class LocalFrame;
class HTMLElement;
class SpellCheckerClient;
class SpellCheckMarker;
class SpellCheckRequest;
class SpellCheckRequester;
......@@ -55,7 +54,6 @@ class CORE_EXPORT SpellChecker final : public GarbageCollected<SpellChecker> {
void Trace(blink::Visitor*);
SpellCheckerClient& GetSpellCheckerClient() const;
WebSpellCheckPanelHostClient& SpellCheckPanelHostClient() const;
TextCheckerClient& TextChecker() const;
......@@ -112,6 +110,15 @@ class CORE_EXPORT SpellChecker final : public GarbageCollected<SpellChecker> {
return *frame_;
}
// Returns whether or not the focused control needs spell-checking.
// Currently, this function just retrieves the focused node and determines
// whether or not it is a <textarea> element or an element whose
// contenteditable attribute is true.
// FIXME: Bug 740540: This code just implements the default behavior
// proposed in this issue. We should also retrieve "spellcheck" attributes
// for text fields and create a flag to over-write the default behavior.
bool ShouldSpellcheckByDefault() const;
// Helper functions for advanceToNextMisspelling()
Vector<TextCheckingResult> FindMisspellings(const String&);
std::pair<String, int> FindFirstMisspelling(const Position&, const Position&);
......
/*
* Copyright (C) 2006, 2007 Apple Inc. All rights reserved.
* Copyright (C) 2008 Nokia Corporation and/or its subsidiary(-ies)
*
* 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 COMPUTER, INC. ``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 COMPUTER, INC. OR
* 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 SpellCheckerClient_h
#define SpellCheckerClient_h
#include "platform/wtf/Forward.h"
namespace blink {
class SpellCheckerClient {
public:
virtual ~SpellCheckerClient() {}
virtual bool IsSpellCheckingEnabled() = 0;
virtual void ToggleSpellCheckingEnabled() = 0;
};
} // namespace blink
#endif // SpellCheckerClient_h
/*
* Copyright (C) 2006, 2007 Apple, Inc. All rights reserved.
* Copyright (C) 2012 Google, 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 COMPUTER, INC. ``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 COMPUTER, INC. OR
* 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.
*/
#include "core/editing/spellcheck/SpellCheckerClientImpl.h"
#include "core/dom/Element.h"
#include "core/editing/FrameSelection.h"
#include "core/editing/markers/DocumentMarkerController.h"
#include "core/editing/spellcheck/SpellChecker.h"
#include "core/exported/WebViewImpl.h"
#include "core/frame/LocalFrame.h"
#include "core/page/Page.h"
namespace blink {
SpellCheckerClientImpl::SpellCheckerClientImpl(WebViewImpl* webview)
: web_view_(webview),
spell_check_this_field_status_(kSpellCheckAutomatic) {}
SpellCheckerClientImpl::~SpellCheckerClientImpl() {}
bool SpellCheckerClientImpl::ShouldSpellcheckByDefault() {
// Spellcheck should be enabled for all editable areas (such as textareas,
// contentEditable regions, designMode docs and inputs).
if (!web_view_->FocusedCoreFrame()->IsLocalFrame())
return false;
const LocalFrame* frame = ToLocalFrame(web_view_->FocusedCoreFrame());
if (!frame)
return false;
if (frame->GetSpellChecker().IsSpellCheckingEnabledInFocusedNode())
return true;
const Document* document = frame->GetDocument();
if (!document)
return false;
const Element* element = document->FocusedElement();
// If |element| is null, we default to allowing spellchecking. This is done
// in order to mitigate the issue when the user clicks outside the textbox,
// as a result of which |element| becomes null, resulting in all the spell
// check markers being deleted. Also, the LocalFrame will decide not to do
// spellchecking if the user can't edit - so returning true here will not
// cause any problems to the LocalFrame's behavior.
if (!element)
return true;
const LayoutObject* layout_object = element->GetLayoutObject();
if (!layout_object)
return false;
return true;
}
bool SpellCheckerClientImpl::IsSpellCheckingEnabled() {
if (spell_check_this_field_status_ == kSpellCheckForcedOff)
return false;
if (spell_check_this_field_status_ == kSpellCheckForcedOn)
return true;
return ShouldSpellcheckByDefault();
}
void SpellCheckerClientImpl::ToggleSpellCheckingEnabled() {
if (IsSpellCheckingEnabled()) {
spell_check_this_field_status_ = kSpellCheckForcedOff;
Page* const page = web_view_->GetPage();
if (!page)
return;
for (Frame* frame = page->MainFrame(); frame;
frame = frame->Tree().TraverseNext()) {
if (!frame->IsLocalFrame())
continue;
ToLocalFrame(frame)->GetDocument()->Markers().RemoveMarkersOfTypes(
DocumentMarker::MisspellingMarkers());
}
return;
}
spell_check_this_field_status_ = kSpellCheckForcedOn;
}
} // namespace blink
/*
* Copyright (C) 2009 Google 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:
*
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* * 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.
* * Neither the name of Google Inc. nor the names of its
* contributors may be used to endorse or promote products derived from
* this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND 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 THE COPYRIGHT
* OWNER OR 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 SpellCheckerClientImpl_h
#define SpellCheckerClientImpl_h
#include "core/CoreExport.h"
#include "core/editing/spellcheck/SpellCheckerClient.h"
namespace blink {
class WebViewImpl;
class CORE_EXPORT SpellCheckerClientImpl final : public SpellCheckerClient {
public:
explicit SpellCheckerClientImpl(WebViewImpl*);
~SpellCheckerClientImpl() override;
bool IsSpellCheckingEnabled() override;
void ToggleSpellCheckingEnabled() override;
private:
// Returns whether or not the focused control needs spell-checking.
// Currently, this function just retrieves the focused node and determines
// whether or not it is a <textarea> element or an element whose
// contenteditable attribute is true.
// FIXME: Bug 740540: This code just implements the default behavior
// proposed in this issue. We should also retrieve "spellcheck" attributes
// for text fields and create a flag to over-write the default behavior.
bool ShouldSpellcheckByDefault();
WebViewImpl* web_view_;
// This flag is set to false if spell check for this editor is manually
// turned off. The default setting is SpellCheckAutomatic.
enum {
kSpellCheckAutomatic,
kSpellCheckForcedOn,
kSpellCheckForcedOff
} spell_check_this_field_status_;
};
} // namespace blink
#endif
......@@ -335,7 +335,6 @@ WebViewImpl::WebViewImpl(WebViewClient* client,
chrome_client_(ChromeClientImpl::Create(this)),
context_menu_client_(*this),
editor_client_(*this),
spell_checker_client_impl_(this),
should_auto_resize_(false),
zoom_level_(0),
minimum_zoom_level_(ZoomFactorToZoomLevel(kMinTextSizeMultiplier)),
......@@ -380,7 +379,6 @@ WebViewImpl::WebViewImpl(WebViewClient* client,
page_clients.chrome_client = chrome_client_.Get();
page_clients.context_menu_client = &context_menu_client_;
page_clients.editor_client = &editor_client_;
page_clients.spell_checker_client = &spell_checker_client_impl_;
page_ = Page::CreateOrdinary(page_clients);
CoreInitializer::GetInstance().ProvideModulesToPage(*page_, client_);
......
......@@ -35,7 +35,6 @@
#include "build/build_config.h"
#include "core/CoreExport.h"
#include "core/editing/spellcheck/SpellCheckerClientImpl.h"
#include "core/exported/WebPagePopupImpl.h"
#include "core/frame/ResizeViewportAnchor.h"
#include "core/page/ChromeClient.h"
......@@ -574,7 +573,6 @@ class CORE_EXPORT WebViewImpl final
Persistent<ChromeClient> chrome_client_;
ContextMenuClient context_menu_client_;
EditorClient editor_client_;
SpellCheckerClientImpl spell_checker_client_impl_;
WebSize size_;
// If true, automatically resize the layout view around its content.
......
......@@ -55,9 +55,6 @@ void FillWithEmptyClients(Page::PageClients& page_clients) {
DEFINE_STATIC_LOCAL(EmptyEditorClient, dummy_editor_client, ());
page_clients.editor_client = &dummy_editor_client;
DEFINE_STATIC_LOCAL(EmptySpellCheckerClient, dummy_spell_checker_client, ());
page_clients.spell_checker_client = &dummy_spell_checker_client;
}
class EmptyPopupMenu : public PopupMenu {
......
......@@ -32,7 +32,6 @@
#include <memory>
#include "core/CoreExport.h"
#include "core/editing/spellcheck/SpellCheckerClient.h"
#include "core/frame/ContentSettingsClient.h"
#include "core/frame/LocalFrameClient.h"
#include "core/frame/RemoteFrameClient.h"
......@@ -390,18 +389,6 @@ class CORE_EXPORT EmptyTextCheckerClient : public TextCheckerClient {
void CancelAllPendingRequests() override;
};
class EmptySpellCheckerClient : public SpellCheckerClient {
WTF_MAKE_NONCOPYABLE(EmptySpellCheckerClient);
USING_FAST_MALLOC(EmptySpellCheckerClient);
public:
EmptySpellCheckerClient() {}
~EmptySpellCheckerClient() override {}
bool IsSpellCheckingEnabled() override { return false; }
void ToggleSpellCheckingEnabled() override {}
};
class EmptySpellCheckPanelHostClient : public WebSpellCheckPanelHostClient {
WTF_MAKE_NONCOPYABLE(EmptySpellCheckPanelHostClient);
USING_FAST_MALLOC(EmptySpellCheckPanelHostClient);
......
......@@ -130,7 +130,6 @@ Page::Page(PageClients& page_clients)
main_frame_(nullptr),
plugin_data_(nullptr),
editor_client_(page_clients.editor_client),
spell_checker_client_(page_clients.spell_checker_client),
use_counter_(page_clients.chrome_client &&
page_clients.chrome_client->IsSVGImageChromeClient()
? UseCounter::kSVGImageContext
......@@ -730,8 +729,7 @@ ScrollbarTheme& Page::GetScrollbarTheme() const {
Page::PageClients::PageClients()
: chrome_client(nullptr),
context_menu_client(nullptr),
editor_client(nullptr),
spell_checker_client(nullptr) {}
editor_client(nullptr) {}
Page::PageClients::~PageClients() {}
......
......@@ -73,7 +73,6 @@ class ScrollbarTheme;
class SmoothScrollSequencer;
class Settings;
class ConsoleMessageStorage;
class SpellCheckerClient;
class TopDocumentRootScrollerController;
class ValidationMessageClient;
class VisualViewport;
......@@ -105,7 +104,6 @@ class CORE_EXPORT Page final : public GarbageCollectedFinalized<Page>,
Member<ChromeClient> chrome_client;
ContextMenuClient* context_menu_client;
EditorClient* editor_client;
SpellCheckerClient* spell_checker_client;
};
static Page* Create(PageClients& page_clients) {
......@@ -147,9 +145,14 @@ class CORE_EXPORT Page final : public GarbageCollectedFinalized<Page>,
static void ResetPluginData();
EditorClient& GetEditorClient() const { return *editor_client_; }
SpellCheckerClient& GetSpellCheckerClient() const {
return *spell_checker_client_;
// This flag controls whether spell check for this page is manually
// turned on/off. The default setting is kAutomatic.
enum class SpellCheckStatus { kAutomatic, kForcedOn, kForcedOff };
void SetSpellCheckStatus(SpellCheckStatus status) {
spell_check_status_ = status;
}
SpellCheckStatus GetSpellCheckStatus() { return spell_check_status_; }
void SetMainFrame(Frame*);
Frame* MainFrame() const { return main_frame_; }
......@@ -361,7 +364,7 @@ class CORE_EXPORT Page final : public GarbageCollectedFinalized<Page>,
Member<PluginData> plugin_data_;
EditorClient* const editor_client_;
SpellCheckerClient* const spell_checker_client_;
SpellCheckStatus spell_check_status_ = SpellCheckStatus::kAutomatic;
Member<ValidationMessageClient> validation_message_client_;
UseCounter use_counter_;
......
......@@ -64,8 +64,6 @@ DummyPageHolder::DummyPageHolder(
page_clients.context_menu_client =
page_clients_argument->context_menu_client;
page_clients.editor_client = page_clients_argument->editor_client;
page_clients.spell_checker_client =
page_clients_argument->spell_checker_client;
}
page_ = Page::Create(page_clients);
Settings& settings = page_->GetSettings();
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment