summaryrefslogtreecommitdiff
path: root/Source/WebKit2/WebProcess/WebCoreSupport/WebEditorClient.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'Source/WebKit2/WebProcess/WebCoreSupport/WebEditorClient.cpp')
-rw-r--r--Source/WebKit2/WebProcess/WebCoreSupport/WebEditorClient.cpp224
1 files changed, 139 insertions, 85 deletions
diff --git a/Source/WebKit2/WebProcess/WebCoreSupport/WebEditorClient.cpp b/Source/WebKit2/WebProcess/WebCoreSupport/WebEditorClient.cpp
index 9059f1e45..9c60ff5a8 100644
--- a/Source/WebKit2/WebProcess/WebCoreSupport/WebEditorClient.cpp
+++ b/Source/WebKit2/WebProcess/WebCoreSupport/WebEditorClient.cpp
@@ -28,11 +28,12 @@
#include "EditorState.h"
#include "WebCoreArgumentCoders.h"
-#include "WebFrameLoaderClient.h"
+#include "WebFrame.h"
#include "WebPage.h"
#include "WebPageProxy.h"
#include "WebPageProxyMessages.h"
#include "WebProcess.h"
+#include "WebUndoStep.h"
#include <WebCore/ArchiveResource.h>
#include <WebCore/DocumentFragment.h>
#include <WebCore/FocusController.h>
@@ -50,9 +51,14 @@
#include <WebCore/TextIterator.h>
#include <WebCore/UndoStep.h>
#include <WebCore/UserTypingGestureIndicator.h>
+#include <WebCore/VisibleUnits.h>
#include <wtf/NeverDestroyed.h>
#include <wtf/text/StringView.h>
+#if PLATFORM(GTK)
+#include <WebCore/PlatformDisplay.h>
+#endif
+
using namespace WebCore;
using namespace HTMLNames;
@@ -64,26 +70,13 @@ static uint64_t generateTextCheckingRequestID()
return uniqueTextCheckingRequestID++;
}
-void WebEditorClient::pageDestroyed()
-{
- delete this;
-}
-
bool WebEditorClient::shouldDeleteRange(Range* range)
{
- bool result = m_page->injectedBundleEditorClient().shouldDeleteRange(m_page, range);
+ bool result = m_page->injectedBundleEditorClient().shouldDeleteRange(*m_page, range);
notImplemented();
return result;
}
-#if ENABLE(DELETION_UI)
-bool WebEditorClient::shouldShowDeleteInterface(HTMLElement*)
-{
- notImplemented();
- return false;
-}
-#endif
-
bool WebEditorClient::smartInsertDeleteEnabled()
{
return m_page->isSmartInsertDeleteEnabled();
@@ -96,7 +89,7 @@ bool WebEditorClient::isSelectTrailingWhitespaceEnabled()
bool WebEditorClient::isContinuousSpellCheckingEnabled()
{
- return WebProcess::shared().textCheckerState().isContinuousSpellCheckingEnabled;
+ return WebProcess::singleton().textCheckerState().isContinuousSpellCheckingEnabled;
}
void WebEditorClient::toggleContinuousSpellChecking()
@@ -106,7 +99,7 @@ void WebEditorClient::toggleContinuousSpellChecking()
bool WebEditorClient::isGrammarCheckingEnabled()
{
- return WebProcess::shared().textCheckerState().isGrammarCheckingEnabled;
+ return WebProcess::singleton().textCheckerState().isGrammarCheckingEnabled;
}
void WebEditorClient::toggleGrammarChecking()
@@ -122,47 +115,52 @@ int WebEditorClient::spellCheckerDocumentTag()
bool WebEditorClient::shouldBeginEditing(Range* range)
{
- bool result = m_page->injectedBundleEditorClient().shouldBeginEditing(m_page, range);
+ bool result = m_page->injectedBundleEditorClient().shouldBeginEditing(*m_page, range);
notImplemented();
return result;
}
bool WebEditorClient::shouldEndEditing(Range* range)
{
- bool result = m_page->injectedBundleEditorClient().shouldEndEditing(m_page, range);
+ bool result = m_page->injectedBundleEditorClient().shouldEndEditing(*m_page, range);
notImplemented();
return result;
}
bool WebEditorClient::shouldInsertNode(Node* node, Range* rangeToReplace, EditorInsertAction action)
{
- bool result = m_page->injectedBundleEditorClient().shouldInsertNode(m_page, node, rangeToReplace, action);
+ bool result = m_page->injectedBundleEditorClient().shouldInsertNode(*m_page, node, rangeToReplace, action);
notImplemented();
return result;
}
bool WebEditorClient::shouldInsertText(const String& text, Range* rangeToReplace, EditorInsertAction action)
{
- bool result = m_page->injectedBundleEditorClient().shouldInsertText(m_page, text.impl(), rangeToReplace, action);
+ bool result = m_page->injectedBundleEditorClient().shouldInsertText(*m_page, text.impl(), rangeToReplace, action);
notImplemented();
return result;
}
bool WebEditorClient::shouldChangeSelectedRange(Range* fromRange, Range* toRange, EAffinity affinity, bool stillSelecting)
{
- bool result = m_page->injectedBundleEditorClient().shouldChangeSelectedRange(m_page, fromRange, toRange, affinity, stillSelecting);
+ bool result = m_page->injectedBundleEditorClient().shouldChangeSelectedRange(*m_page, fromRange, toRange, affinity, stillSelecting);
notImplemented();
return result;
}
bool WebEditorClient::shouldApplyStyle(StyleProperties* style, Range* range)
{
- Ref<MutableStyleProperties> mutableStyle(style->isMutable() ? static_cast<MutableStyleProperties&>(*style) : style->mutableCopy());
- bool result = m_page->injectedBundleEditorClient().shouldApplyStyle(m_page, mutableStyle->ensureCSSStyleDeclaration(), range);
+ Ref<MutableStyleProperties> mutableStyle(style->isMutable() ? Ref<MutableStyleProperties>(static_cast<MutableStyleProperties&>(*style)) : style->mutableCopy());
+ bool result = m_page->injectedBundleEditorClient().shouldApplyStyle(*m_page, mutableStyle->ensureCSSStyleDeclaration(), range);
notImplemented();
return result;
}
+void WebEditorClient::didApplyStyle()
+{
+ notImplemented();
+}
+
bool WebEditorClient::shouldMoveRangeAfterDelete(Range*, Range*)
{
notImplemented();
@@ -173,21 +171,21 @@ void WebEditorClient::didBeginEditing()
{
// FIXME: What good is a notification name, if it's always the same?
static NeverDestroyed<String> WebViewDidBeginEditingNotification(ASCIILiteral("WebViewDidBeginEditingNotification"));
- m_page->injectedBundleEditorClient().didBeginEditing(m_page, WebViewDidBeginEditingNotification.get().impl());
+ m_page->injectedBundleEditorClient().didBeginEditing(*m_page, WebViewDidBeginEditingNotification.get().impl());
notImplemented();
}
void WebEditorClient::respondToChangedContents()
{
static NeverDestroyed<String> WebViewDidChangeNotification(ASCIILiteral("WebViewDidChangeNotification"));
- m_page->injectedBundleEditorClient().didChange(m_page, WebViewDidChangeNotification.get().impl());
+ m_page->injectedBundleEditorClient().didChange(*m_page, WebViewDidChangeNotification.get().impl());
notImplemented();
}
void WebEditorClient::respondToChangedSelection(Frame* frame)
{
static NeverDestroyed<String> WebViewDidChangeSelectionNotification(ASCIILiteral("WebViewDidChangeSelectionNotification"));
- m_page->injectedBundleEditorClient().didChangeSelection(m_page, WebViewDidChangeSelectionNotification.get().impl());
+ m_page->injectedBundleEditorClient().didChangeSelection(*m_page, WebViewDidChangeSelectionNotification.get().impl());
if (!frame)
return;
@@ -198,43 +196,63 @@ void WebEditorClient::respondToChangedSelection(Frame* frame)
#endif
}
+void WebEditorClient::didChangeSelectionAndUpdateLayout()
+{
+ m_page->sendPostLayoutEditorStateIfNeeded();
+}
+
+void WebEditorClient::updateEditorStateAfterLayoutIfEditabilityChanged()
+{
+ m_page->updateEditorStateAfterLayoutIfEditabilityChanged();
+}
+
+void WebEditorClient::discardedComposition(Frame*)
+{
+ m_page->discardedComposition();
+}
+
+void WebEditorClient::canceledComposition()
+{
+ m_page->canceledComposition();
+}
+
void WebEditorClient::didEndEditing()
{
static NeverDestroyed<String> WebViewDidEndEditingNotification(ASCIILiteral("WebViewDidEndEditingNotification"));
- m_page->injectedBundleEditorClient().didEndEditing(m_page, WebViewDidEndEditingNotification.get().impl());
+ m_page->injectedBundleEditorClient().didEndEditing(*m_page, WebViewDidEndEditingNotification.get().impl());
notImplemented();
}
void WebEditorClient::didWriteSelectionToPasteboard()
{
- m_page->injectedBundleEditorClient().didWriteToPasteboard(m_page);
+ m_page->injectedBundleEditorClient().didWriteToPasteboard(*m_page);
}
void WebEditorClient::willWriteSelectionToPasteboard(Range* range)
{
- m_page->injectedBundleEditorClient().willWriteToPasteboard(m_page, range);
+ m_page->injectedBundleEditorClient().willWriteToPasteboard(*m_page, range);
}
void WebEditorClient::getClientPasteboardDataForRange(Range* range, Vector<String>& pasteboardTypes, Vector<RefPtr<SharedBuffer>>& pasteboardData)
{
- m_page->injectedBundleEditorClient().getPasteboardDataForRange(m_page, range, pasteboardTypes, pasteboardData);
+ m_page->injectedBundleEditorClient().getPasteboardDataForRange(*m_page, range, pasteboardTypes, pasteboardData);
}
-void WebEditorClient::registerUndoStep(PassRefPtr<UndoStep> step)
+void WebEditorClient::registerUndoStep(UndoStep& step)
{
// FIXME: Add assertion that the command being reapplied is the same command that is
// being passed to us.
if (m_page->isInRedo())
return;
- RefPtr<WebUndoStep> webStep = WebUndoStep::create(step);
- m_page->addWebUndoStep(webStep->stepID(), webStep.get());
- uint32_t editAction = static_cast<uint32_t>(webStep->step()->editingAction());
+ auto webStep = WebUndoStep::create(&step);
+ auto editAction = static_cast<uint32_t>(webStep->step()->editingAction());
+ m_page->addWebUndoStep(webStep->stepID(), webStep.ptr());
m_page->send(Messages::WebPageProxy::RegisterEditCommandForUndo(webStep->stepID(), editAction));
}
-void WebEditorClient::registerRedoStep(PassRefPtr<UndoStep>)
+void WebEditorClient::registerRedoStep(UndoStep&)
{
}
@@ -279,7 +297,7 @@ void WebEditorClient::redo()
m_page->sendSync(Messages::WebPageProxy::ExecuteUndoRedo(static_cast<uint32_t>(WebPageProxy::Redo)), Messages::WebPageProxy::ExecuteUndoRedo::Reply(result));
}
-#if !PLATFORM(GTK) && !PLATFORM(MAC) && !PLATFORM(EFL)
+#if !PLATFORM(GTK) && !PLATFORM(COCOA)
void WebEditorClient::handleKeyboardEvent(KeyboardEvent* event)
{
if (m_page->handleEditingKeyboardEvent(event))
@@ -294,55 +312,57 @@ void WebEditorClient::handleInputMethodKeydown(KeyboardEvent*)
void WebEditorClient::textFieldDidBeginEditing(Element* element)
{
- if (!isHTMLInputElement(element))
+ if (!is<HTMLInputElement>(*element))
return;
- WebFrameLoaderClient* webFrameLoaderClient = toWebFrameLoaderClient(element->document().frame()->loader().client());
- WebFrame* webFrame = webFrameLoaderClient ? webFrameLoaderClient->webFrame() : 0;
+ WebFrame* webFrame = WebFrame::fromCoreFrame(*element->document().frame());
ASSERT(webFrame);
- m_page->injectedBundleFormClient().textFieldDidBeginEditing(m_page, toHTMLInputElement(element), webFrame);
+ m_page->injectedBundleFormClient().textFieldDidBeginEditing(m_page, downcast<HTMLInputElement>(element), webFrame);
}
void WebEditorClient::textFieldDidEndEditing(Element* element)
{
- if (!isHTMLInputElement(element))
+ if (!is<HTMLInputElement>(*element))
return;
- WebFrameLoaderClient* webFrameLoaderClient = toWebFrameLoaderClient(element->document().frame()->loader().client());
- WebFrame* webFrame = webFrameLoaderClient ? webFrameLoaderClient->webFrame() : 0;
+ WebFrame* webFrame = WebFrame::fromCoreFrame(*element->document().frame());
ASSERT(webFrame);
- m_page->injectedBundleFormClient().textFieldDidEndEditing(m_page, toHTMLInputElement(element), webFrame);
+ m_page->injectedBundleFormClient().textFieldDidEndEditing(m_page, downcast<HTMLInputElement>(element), webFrame);
}
void WebEditorClient::textDidChangeInTextField(Element* element)
{
- if (!isHTMLInputElement(element))
+ if (!is<HTMLInputElement>(*element))
return;
- if (!UserTypingGestureIndicator::processingUserTypingGesture() || UserTypingGestureIndicator::focusedElementAtGestureStart() != element)
- return;
+ bool initiatedByUserTyping = UserTypingGestureIndicator::processingUserTypingGesture() && UserTypingGestureIndicator::focusedElementAtGestureStart() == element;
- WebFrameLoaderClient* webFrameLoaderClient = toWebFrameLoaderClient(element->document().frame()->loader().client());
- WebFrame* webFrame = webFrameLoaderClient ? webFrameLoaderClient->webFrame() : 0;
+ WebFrame* webFrame = WebFrame::fromCoreFrame(*element->document().frame());
ASSERT(webFrame);
- m_page->injectedBundleFormClient().textDidChangeInTextField(m_page, toHTMLInputElement(element), webFrame);
+ m_page->injectedBundleFormClient().textDidChangeInTextField(m_page, downcast<HTMLInputElement>(element), webFrame, initiatedByUserTyping);
}
void WebEditorClient::textDidChangeInTextArea(Element* element)
{
- if (!isHTMLTextAreaElement(element))
+ if (!is<HTMLTextAreaElement>(*element))
return;
- WebFrameLoaderClient* webFrameLoaderClient = toWebFrameLoaderClient(element->document().frame()->loader().client());
- WebFrame* webFrame = webFrameLoaderClient ? webFrameLoaderClient->webFrame() : 0;
+ WebFrame* webFrame = WebFrame::fromCoreFrame(*element->document().frame());
ASSERT(webFrame);
- m_page->injectedBundleFormClient().textDidChangeInTextArea(m_page, toHTMLTextAreaElement(element), webFrame);
+ m_page->injectedBundleFormClient().textDidChangeInTextArea(m_page, downcast<HTMLTextAreaElement>(element), webFrame);
}
+#if !PLATFORM(IOS)
+void WebEditorClient::overflowScrollPositionChanged()
+{
+ notImplemented();
+}
+#endif
+
static bool getActionTypeForKeyEvent(KeyboardEvent* event, WKInputFieldActionType& type)
{
String key = event->keyIdentifier();
@@ -365,38 +385,59 @@ static bool getActionTypeForKeyEvent(KeyboardEvent* event, WKInputFieldActionTyp
return true;
}
+static API::InjectedBundle::FormClient::InputFieldAction toInputFieldAction(WKInputFieldActionType action)
+{
+ switch (action) {
+ case WKInputFieldActionTypeMoveUp:
+ return API::InjectedBundle::FormClient::InputFieldAction::MoveUp;
+ case WKInputFieldActionTypeMoveDown:
+ return API::InjectedBundle::FormClient::InputFieldAction::MoveDown;
+ case WKInputFieldActionTypeCancel:
+ return API::InjectedBundle::FormClient::InputFieldAction::Cancel;
+ case WKInputFieldActionTypeInsertTab:
+ return API::InjectedBundle::FormClient::InputFieldAction::InsertTab;
+ case WKInputFieldActionTypeInsertNewline:
+ return API::InjectedBundle::FormClient::InputFieldAction::InsertNewline;
+ case WKInputFieldActionTypeInsertDelete:
+ return API::InjectedBundle::FormClient::InputFieldAction::InsertDelete;
+ case WKInputFieldActionTypeInsertBacktab:
+ return API::InjectedBundle::FormClient::InputFieldAction::InsertBacktab;
+ }
+
+ ASSERT_NOT_REACHED();
+ return API::InjectedBundle::FormClient::InputFieldAction::Cancel;
+}
+
bool WebEditorClient::doTextFieldCommandFromEvent(Element* element, KeyboardEvent* event)
{
- if (!isHTMLInputElement(element))
+ if (!is<HTMLInputElement>(*element))
return false;
WKInputFieldActionType actionType = static_cast<WKInputFieldActionType>(0);
if (!getActionTypeForKeyEvent(event, actionType))
return false;
- WebFrameLoaderClient* webFrameLoaderClient = toWebFrameLoaderClient(element->document().frame()->loader().client());
- WebFrame* webFrame = webFrameLoaderClient ? webFrameLoaderClient->webFrame() : 0;
+ WebFrame* webFrame = WebFrame::fromCoreFrame(*element->document().frame());
ASSERT(webFrame);
- return m_page->injectedBundleFormClient().shouldPerformActionInTextField(m_page, toHTMLInputElement(element), actionType, webFrame);
+ return m_page->injectedBundleFormClient().shouldPerformActionInTextField(m_page, downcast<HTMLInputElement>(element), toInputFieldAction(actionType), webFrame);
}
void WebEditorClient::textWillBeDeletedInTextField(Element* element)
{
- if (!isHTMLInputElement(element))
+ if (!is<HTMLInputElement>(*element))
return;
- WebFrameLoaderClient* webFrameLoaderClient = toWebFrameLoaderClient(element->document().frame()->loader().client());
- WebFrame* webFrame = webFrameLoaderClient ? webFrameLoaderClient->webFrame() : 0;
+ WebFrame* webFrame = WebFrame::fromCoreFrame(*element->document().frame());
ASSERT(webFrame);
- m_page->injectedBundleFormClient().shouldPerformActionInTextField(m_page, toHTMLInputElement(element), WKInputFieldActionTypeInsertDelete, webFrame);
+ m_page->injectedBundleFormClient().shouldPerformActionInTextField(m_page, downcast<HTMLInputElement>(element), toInputFieldAction(WKInputFieldActionTypeInsertDelete), webFrame);
}
bool WebEditorClient::shouldEraseMarkersAfterChangeSelection(WebCore::TextCheckingType type) const
{
// This prevents erasing spelling markers on OS X Lion or later to match AppKit on these Mac OS X versions.
-#if PLATFORM(MAC) || PLATFORM(EFL)
+#if PLATFORM(COCOA)
return type != TextCheckingTypeSpelling;
#else
UNUSED_PARAM(type);
@@ -414,12 +455,11 @@ void WebEditorClient::learnWord(const String& word)
m_page->send(Messages::WebPageProxy::LearnWord(word));
}
-void WebEditorClient::checkSpellingOfString(const UChar* text, int length, int* misspellingLocation, int* misspellingLength)
+void WebEditorClient::checkSpellingOfString(StringView text, int* misspellingLocation, int* misspellingLength)
{
int32_t resultLocation = -1;
int32_t resultLength = 0;
- // FIXME: It would be nice if we wouldn't have to copy the text here.
- m_page->sendSync(Messages::WebPageProxy::CheckSpellingOfString(String(text, length)),
+ m_page->sendSync(Messages::WebPageProxy::CheckSpellingOfString(text.toStringWithoutCopying()),
Messages::WebPageProxy::CheckSpellingOfString::Reply(resultLocation, resultLength));
*misspellingLocation = resultLocation;
*misspellingLength = resultLength;
@@ -431,23 +471,29 @@ String WebEditorClient::getAutoCorrectSuggestionForMisspelledWord(const String&)
return String();
}
-void WebEditorClient::checkGrammarOfString(const UChar* text, int length, Vector<WebCore::GrammarDetail>& grammarDetails, int* badGrammarLocation, int* badGrammarLength)
+void WebEditorClient::checkGrammarOfString(StringView text, Vector<WebCore::GrammarDetail>& grammarDetails, int* badGrammarLocation, int* badGrammarLength)
{
int32_t resultLocation = -1;
int32_t resultLength = 0;
- // FIXME: It would be nice if we wouldn't have to copy the text here.
- m_page->sendSync(Messages::WebPageProxy::CheckGrammarOfString(String(text, length)),
+ m_page->sendSync(Messages::WebPageProxy::CheckGrammarOfString(text.toStringWithoutCopying()),
Messages::WebPageProxy::CheckGrammarOfString::Reply(grammarDetails, resultLocation, resultLength));
*badGrammarLocation = resultLocation;
*badGrammarLength = resultLength;
}
+static int32_t insertionPointFromCurrentSelection(const VisibleSelection& currentSelection)
+{
+ VisiblePosition selectionStart = currentSelection.visibleStart();
+ VisiblePosition paragraphStart = startOfParagraph(selectionStart);
+ return TextIterator::rangeLength(makeRange(paragraphStart, selectionStart).get());
+}
+
#if USE(UNIFIED_TEXT_CHECKING)
-Vector<TextCheckingResult> WebEditorClient::checkTextOfParagraph(StringView stringView, WebCore::TextCheckingTypeMask checkingTypes)
+Vector<TextCheckingResult> WebEditorClient::checkTextOfParagraph(StringView stringView, WebCore::TextCheckingTypeMask checkingTypes, const VisibleSelection& currentSelection)
{
Vector<TextCheckingResult> results;
- m_page->sendSync(Messages::WebPageProxy::CheckTextOfParagraph(stringView.toStringWithoutCopying(), checkingTypes), Messages::WebPageProxy::CheckTextOfParagraph::Reply(results));
+ m_page->sendSync(Messages::WebPageProxy::CheckTextOfParagraph(stringView.toStringWithoutCopying(), checkingTypes, insertionPointFromCurrentSelection(currentSelection)), Messages::WebPageProxy::CheckTextOfParagraph::Reply(results));
return results;
}
@@ -475,38 +521,46 @@ bool WebEditorClient::spellingUIIsShowing()
return isShowing;
}
-void WebEditorClient::getGuessesForWord(const String& word, const String& context, Vector<String>& guesses)
+void WebEditorClient::getGuessesForWord(const String& word, const String& context, const VisibleSelection& currentSelection, Vector<String>& guesses)
{
- m_page->sendSync(Messages::WebPageProxy::GetGuessesForWord(word, context), Messages::WebPageProxy::GetGuessesForWord::Reply(guesses));
+ m_page->sendSync(Messages::WebPageProxy::GetGuessesForWord(word, context, insertionPointFromCurrentSelection(currentSelection)), Messages::WebPageProxy::GetGuessesForWord::Reply(guesses));
}
-void WebEditorClient::requestCheckingOfString(WTF::PassRefPtr<TextCheckingRequest> prpRequest)
+void WebEditorClient::requestCheckingOfString(TextCheckingRequest& request, const WebCore::VisibleSelection& currentSelection)
{
- RefPtr<TextCheckingRequest> request = prpRequest;
-
uint64_t requestID = generateTextCheckingRequestID();
- m_page->addTextCheckingRequest(requestID, request);
+ m_page->addTextCheckingRequest(requestID, &request);
- m_page->send(Messages::WebPageProxy::RequestCheckingOfString(requestID, request->data()));
+ m_page->send(Messages::WebPageProxy::RequestCheckingOfString(requestID, request.data(), insertionPointFromCurrentSelection(currentSelection)));
}
void WebEditorClient::willSetInputMethodState()
{
}
-void WebEditorClient::setInputMethodState(bool)
+void WebEditorClient::setInputMethodState(bool enabled)
{
+#if PLATFORM(GTK)
+ m_page->setInputMethodState(enabled);
+#else
notImplemented();
+ UNUSED_PARAM(enabled);
+#endif
}
bool WebEditorClient::supportsGlobalSelection()
{
-#if PLATFORM(GTK) && PLATFORM(X11)
- return true;
-#else
- // FIXME: Return true on other X11 platforms when they support global selection.
- return false;
+#if PLATFORM(GTK)
+#if PLATFORM(X11)
+ if (PlatformDisplay::sharedDisplay().type() == PlatformDisplay::Type::X11)
+ return true;
#endif
+#if PLATFORM(WAYLAND)
+ if (PlatformDisplay::sharedDisplay().type() == PlatformDisplay::Type::Wayland)
+ return true;
+#endif
+#endif
+ return false;
}
} // namespace WebKit