Skip to content

Commit

Permalink
[WPE][GTK] Expose availability of certain editing commands in WebKitE…
Browse files Browse the repository at this point in the history
…ditorState

https://bugs.webkit.org/show_bug.cgi?id=168219

Reviewed by Ryosuke Niwa.

Source/WebCore:

Make Editor::canUndo and Editor::canRedo const.

Also, remove unused allowsCopy from HitTestResult.

* editing/Editor.cpp:
(WebCore::Editor::canUndo const):
(WebCore::Editor::canRedo const):
(WebCore::Editor::canUndo): Deleted.
(WebCore::Editor::canRedo): Deleted.
* editing/Editor.h:
* rendering/HitTestResult.cpp:
(WebCore::HitTestResult::allowsCopy const): Deleted.
* rendering/HitTestResult.h:
* rendering/SelectionRangeData.cpp:

Source/WebKit:

Expose canCut, canCopy, canPaste, canUndo, and canRedo in EditorState::PostLayouData.

Add corresponding new WPE/GTK API.

Remove allowsCopy from WebKitTestResultData. It's unused, does not work correctly in all
circumstances, and irritates Ryosuke.

Also, remove a bunch of #ifs guarding post layout data, since it's now used on all ports.

* Shared/EditorState.cpp:
(WebKit::EditorState::encode const):
(WebKit::EditorState::decode):
(WebKit::EditorState::PostLayoutData::encode const):
(WebKit::EditorState::PostLayoutData::decode):
* Shared/EditorState.h:
(WebKit::EditorState::postLayoutData const const):
* Shared/WebHitTestResultData.cpp:
(WebKit::WebHitTestResultData::WebHitTestResultData):
(WebKit::WebHitTestResultData::encode const):
(WebKit::WebHitTestResultData::decode):
* Shared/WebHitTestResultData.h:
* UIProcess/API/APIHitTestResult.h:
(API::HitTestResult::allowsCopy const): Deleted.
* UIProcess/API/glib/WebKitEditorState.cpp:
(webkitEditorStateChanged):
(webkit_editor_state_is_cut_available):
(webkit_editor_state_is_copy_available):
(webkit_editor_state_is_paste_available):
(webkit_editor_state_is_undo_available):
(webkit_editor_state_is_redo_available):
* UIProcess/API/glib/WebKitWebView.cpp:
(webkit_web_view_can_execute_editing_command):
* UIProcess/API/gtk/WebKitEditorState.h:
* UIProcess/API/gtk/docs/webkit2gtk-4.0-sections.txt:
* UIProcess/API/wpe/WebKitEditorState.h:
* WebProcess/WebPage/WebPage.cpp:
(WebKit::WebPage::editorState const):
* WebProcess/WebPage/mac/WebPageMac.mm:
(WebKit::WebPage::performImmediateActionHitTestAtLocation):

Tools:

Test it.

* TestWebKitAPI/Tests/WebKitGtk/TestWebViewEditor.cpp:
(testWebViewEditorCutCopyPasteNonEditable):
(testWebViewEditorCutCopyPasteEditable):
(testWebViewEditorSelectAllNonEditable):
(testWebViewEditorSelectAllEditable):
(loadContentsAndTryToCutSelection):
(testWebViewEditorNonEditable):
(testWebViewEditorEditorStateTypingAttributes):
(testWebViewEditorInsertImage):
(testWebViewEditorCreateLink):

Canonical link: https://commits.webkit.org/195144@main
git-svn-id: https://svn.webkit.org/repository/webkit/trunk@224179 268f45cc-cd09-0410-ab3c-d52691b4dbfc
  • Loading branch information
mcatanzaro committed Oct 30, 2017
1 parent e031392 commit 95719c3
Show file tree
Hide file tree
Showing 20 changed files with 325 additions and 54 deletions.
22 changes: 22 additions & 0 deletions Source/WebCore/ChangeLog
@@ -1,3 +1,25 @@
2017-10-30 Michael Catanzaro <mcatanzaro@igalia.com>

[WPE][GTK] Expose availability of certain editing commands in WebKitEditorState
https://bugs.webkit.org/show_bug.cgi?id=168219

Reviewed by Ryosuke Niwa.

Make Editor::canUndo and Editor::canRedo const.

Also, remove unused allowsCopy from HitTestResult.

* editing/Editor.cpp:
(WebCore::Editor::canUndo const):
(WebCore::Editor::canRedo const):
(WebCore::Editor::canUndo): Deleted.
(WebCore::Editor::canRedo): Deleted.
* editing/Editor.h:
* rendering/HitTestResult.cpp:
(WebCore::HitTestResult::allowsCopy const): Deleted.
* rendering/HitTestResult.h:
* rendering/SelectionRangeData.cpp:

2017-10-27 Antti Koivisto <antti@apple.com>

Destroy all unneeded anonymous wrappers in RenderObject::removeFromParentAndDestroyCleaningUpAnonymousWrappers()
Expand Down
4 changes: 2 additions & 2 deletions Source/WebCore/editing/Editor.cpp
Expand Up @@ -1639,7 +1639,7 @@ void Editor::clearUndoRedoOperations()
client()->clearUndoRedoOperations();
}

bool Editor::canUndo()
bool Editor::canUndo() const
{
return client() && client()->canUndo();
}
Expand All @@ -1650,7 +1650,7 @@ void Editor::undo()
client()->undo();
}

bool Editor::canRedo()
bool Editor::canRedo() const
{
return client() && client()->canRedo();
}
Expand Down
4 changes: 2 additions & 2 deletions Source/WebCore/editing/Editor.h
Expand Up @@ -303,9 +303,9 @@ class Editor {
bool shouldEndEditing(Range*);

void clearUndoRedoOperations();
bool canUndo();
WEBCORE_EXPORT bool canUndo() const;
void undo();
bool canRedo();
WEBCORE_EXPORT bool canRedo() const;
void redo();

void didBeginEditing();
Expand Down
15 changes: 0 additions & 15 deletions Source/WebCore/rendering/HitTestResult.cpp
Expand Up @@ -594,21 +594,6 @@ bool HitTestResult::isOverTextInsideFormControlElement() const
return !wordRange->text().isEmpty();
}

bool HitTestResult::allowsCopy() const
{
Node* node = innerNode();
if (!node)
return false;

RenderObject* renderer = node->renderer();
if (!renderer)
return false;

bool isUserSelectNone = renderer->style().userSelect() == SELECT_NONE;
bool isPasswordField = is<HTMLInputElement>(node) && downcast<HTMLInputElement>(*node).isPasswordField();
return !isPasswordField && !isUserSelectNone;
}

URL HitTestResult::absoluteLinkURL() const
{
if (m_innerURLElement)
Expand Down
1 change: 0 additions & 1 deletion Source/WebCore/rendering/HitTestResult.h
Expand Up @@ -131,7 +131,6 @@ class HitTestResult {

WEBCORE_EXPORT bool isDownloadableMedia() const;
WEBCORE_EXPORT bool isOverTextInsideFormControlElement() const;
WEBCORE_EXPORT bool allowsCopy() const;

HitTestProgress addNodeToListBasedTestResult(Node*, const HitTestRequest&, const HitTestLocation& pointInContainer, const LayoutRect& = LayoutRect());
HitTestProgress addNodeToListBasedTestResult(Node*, const HitTestRequest&, const HitTestLocation& pointInContainer, const FloatRect&);
Expand Down
47 changes: 47 additions & 0 deletions Source/WebKit/ChangeLog
@@ -1,3 +1,50 @@
2017-10-30 Michael Catanzaro <mcatanzaro@igalia.com>

[WPE][GTK] Expose availability of certain editing commands in WebKitEditorState
https://bugs.webkit.org/show_bug.cgi?id=168219

Reviewed by Ryosuke Niwa.

Expose canCut, canCopy, canPaste, canUndo, and canRedo in EditorState::PostLayouData.

Add corresponding new WPE/GTK API.

Remove allowsCopy from WebKitTestResultData. It's unused, does not work correctly in all
circumstances, and irritates Ryosuke.

Also, remove a bunch of #ifs guarding post layout data, since it's now used on all ports.

* Shared/EditorState.cpp:
(WebKit::EditorState::encode const):
(WebKit::EditorState::decode):
(WebKit::EditorState::PostLayoutData::encode const):
(WebKit::EditorState::PostLayoutData::decode):
* Shared/EditorState.h:
(WebKit::EditorState::postLayoutData const const):
* Shared/WebHitTestResultData.cpp:
(WebKit::WebHitTestResultData::WebHitTestResultData):
(WebKit::WebHitTestResultData::encode const):
(WebKit::WebHitTestResultData::decode):
* Shared/WebHitTestResultData.h:
* UIProcess/API/APIHitTestResult.h:
(API::HitTestResult::allowsCopy const): Deleted.
* UIProcess/API/glib/WebKitEditorState.cpp:
(webkitEditorStateChanged):
(webkit_editor_state_is_cut_available):
(webkit_editor_state_is_copy_available):
(webkit_editor_state_is_paste_available):
(webkit_editor_state_is_undo_available):
(webkit_editor_state_is_redo_available):
* UIProcess/API/glib/WebKitWebView.cpp:
(webkit_web_view_can_execute_editing_command):
* UIProcess/API/gtk/WebKitEditorState.h:
* UIProcess/API/gtk/docs/webkit2gtk-4.0-sections.txt:
* UIProcess/API/wpe/WebKitEditorState.h:
* WebProcess/WebPage/WebPage.cpp:
(WebKit::WebPage::editorState const):
* WebProcess/WebPage/mac/WebPageMac.mm:
(WebKit::WebPage::performImmediateActionHitTestAtLocation):

2017-10-27 Sam Weinig <sam@webkit.org>

[Settings] Generate more of the WebKit preferences code
Expand Down
22 changes: 16 additions & 6 deletions Source/WebKit/Shared/EditorState.cpp
Expand Up @@ -42,10 +42,8 @@ void EditorState::encode(IPC::Encoder& encoder) const
encoder << hasComposition;
encoder << isMissingPostLayoutData;

#if PLATFORM(IOS) || PLATFORM(GTK) || PLATFORM(MAC)
if (!isMissingPostLayoutData)
m_postLayoutData.encode(encoder);
#endif

#if PLATFORM(IOS)
encoder << firstMarkedRect;
Expand Down Expand Up @@ -83,12 +81,10 @@ bool EditorState::decode(IPC::Decoder& decoder, EditorState& result)
if (!decoder.decode(result.isMissingPostLayoutData))
return false;

#if PLATFORM(IOS) || PLATFORM(GTK) || PLATFORM(MAC)
if (!result.isMissingPostLayoutData) {
if (!PostLayoutData::decode(decoder, result.postLayoutData()))
return false;
}
#endif

#if PLATFORM(IOS)
if (!decoder.decode(result.firstMarkedRect))
Expand All @@ -102,7 +98,6 @@ bool EditorState::decode(IPC::Decoder& decoder, EditorState& result)
return true;
}

#if PLATFORM(IOS) || PLATFORM(GTK) || PLATFORM(MAC)
void EditorState::PostLayoutData::encode(IPC::Encoder& encoder) const
{
encoder << typingAttributes;
Expand Down Expand Up @@ -135,6 +130,11 @@ void EditorState::PostLayoutData::encode(IPC::Encoder& encoder) const
encoder << paragraphContextForCandidateRequest;
encoder << stringForCandidateRequest;
#endif
encoder << canCut;
encoder << canCopy;
encoder << canPaste;
encoder << canUndo;
encoder << canRedo;
}

bool EditorState::PostLayoutData::decode(IPC::Decoder& decoder, PostLayoutData& result)
Expand Down Expand Up @@ -194,8 +194,18 @@ bool EditorState::PostLayoutData::decode(IPC::Decoder& decoder, PostLayoutData&
return false;
#endif

if (!decoder.decode(result.canCut))
return false;
if (!decoder.decode(result.canCopy))
return false;
if (!decoder.decode(result.canPaste))
return false;
if (!decoder.decode(result.canUndo))
return false;
if (!decoder.decode(result.canRedo))
return false;

return true;
}
#endif // PLATFORM(IOS) || PLATFORM(GTK) || PLATFORM(MAC)

}
12 changes: 6 additions & 6 deletions Source/WebKit/Shared/EditorState.h
Expand Up @@ -77,7 +77,6 @@ struct EditorState {
String markedText;
#endif

#if PLATFORM(IOS) || PLATFORM(GTK) || PLATFORM(MAC)
struct PostLayoutData {
uint32_t typingAttributes { AttributeNone };
#if PLATFORM(IOS) || PLATFORM(GTK)
Expand Down Expand Up @@ -110,24 +109,26 @@ struct EditorState {
String stringForCandidateRequest;
#endif

bool canCut { false };
bool canCopy { false };
bool canPaste { false };
bool canUndo { false };
bool canRedo { false };

void encode(IPC::Encoder&) const;
static bool decode(IPC::Decoder&, PostLayoutData&);
};

const PostLayoutData& postLayoutData() const;
PostLayoutData& postLayoutData();
#endif // PLATFORM(IOS) || PLATFORM(GTK) || PLATFORM(MAC)

void encode(IPC::Encoder&) const;
static bool decode(IPC::Decoder&, EditorState&);

#if PLATFORM(IOS) || PLATFORM(GTK) || PLATFORM(MAC)
private:
PostLayoutData m_postLayoutData;
#endif
};

#if PLATFORM(IOS) || PLATFORM(GTK) || PLATFORM(MAC)
inline auto EditorState::postLayoutData() -> PostLayoutData&
{
ASSERT_WITH_MESSAGE(!isMissingPostLayoutData, "Attempt to access post layout data before receiving it");
Expand All @@ -139,7 +140,6 @@ inline auto EditorState::postLayoutData() const -> const PostLayoutData&
ASSERT_WITH_MESSAGE(!isMissingPostLayoutData, "Attempt to access post layout data before receiving it");
return m_postLayoutData;
}
#endif

}

Expand Down
4 changes: 0 additions & 4 deletions Source/WebKit/Shared/WebHitTestResultData.cpp
Expand Up @@ -53,7 +53,6 @@ WebHitTestResultData::WebHitTestResultData(const WebCore::HitTestResult& hitTest
, isSelected(hitTestResult.isSelected())
, isTextNode(hitTestResult.innerNode() && hitTestResult.innerNode()->isTextNode())
, isOverTextInsideFormControlElement(hitTestResult.isOverTextInsideFormControlElement())
, allowsCopy(hitTestResult.allowsCopy())
, isDownloadableMedia(hitTestResult.isDownloadableMedia())
, imageSize(0)
{
Expand All @@ -73,7 +72,6 @@ WebHitTestResultData::WebHitTestResultData(const WebCore::HitTestResult& hitTest
, isSelected(hitTestResult.isSelected())
, isTextNode(hitTestResult.innerNode() && hitTestResult.innerNode()->isTextNode())
, isOverTextInsideFormControlElement(hitTestResult.isOverTextInsideFormControlElement())
, allowsCopy(hitTestResult.allowsCopy())
, isDownloadableMedia(hitTestResult.isDownloadableMedia())
, imageSize(0)
{
Expand Down Expand Up @@ -109,7 +107,6 @@ void WebHitTestResultData::encode(IPC::Encoder& encoder) const
encoder << isSelected;
encoder << isTextNode;
encoder << isOverTextInsideFormControlElement;
encoder << allowsCopy;
encoder << isDownloadableMedia;
encoder << lookupText;
encoder << dictionaryPopupInfo;
Expand Down Expand Up @@ -143,7 +140,6 @@ bool WebHitTestResultData::decode(IPC::Decoder& decoder, WebHitTestResultData& h
|| !decoder.decode(hitTestResultData.isSelected)
|| !decoder.decode(hitTestResultData.isTextNode)
|| !decoder.decode(hitTestResultData.isOverTextInsideFormControlElement)
|| !decoder.decode(hitTestResultData.allowsCopy)
|| !decoder.decode(hitTestResultData.isDownloadableMedia)
|| !decoder.decode(hitTestResultData.lookupText)
|| !decoder.decode(hitTestResultData.dictionaryPopupInfo))
Expand Down
1 change: 0 additions & 1 deletion Source/WebKit/Shared/WebHitTestResultData.h
Expand Up @@ -57,7 +57,6 @@ struct WebHitTestResultData {
bool isSelected;
bool isTextNode;
bool isOverTextInsideFormControlElement;
bool allowsCopy;
bool isDownloadableMedia;

String lookupText;
Expand Down
2 changes: 0 additions & 2 deletions Source/WebKit/UIProcess/API/APIHitTestResult.h
Expand Up @@ -70,8 +70,6 @@ class HitTestResult : public API::ObjectImpl<API::Object::Type::HitTestResult> {

bool isOverTextInsideFormControlElement() const { return m_data.isOverTextInsideFormControlElement; }

bool allowsCopy() const { return m_data.allowsCopy; }

bool isDownloadableMedia() const { return m_data.isDownloadableMedia; }

private:
Expand Down

0 comments on commit 95719c3

Please sign in to comment.