Commit 0b5fb5f6 authored by luoe's avatar luoe Committed by Commit bot

Revert of evaluating clipboard event target acording to w3c specification...

Revert of evaluating clipboard event target acording to w3c specification (patchset #7 id:120001 of https://codereview.chromium.org/2685723005/ )

Reason for revert:
Changing this functionality improved spec conformance, but introduced regressions where text that used to be copied is no longer copied:
crbug.com/695568
crbug.com/700163

A proposal to change the spec was made here:
https://github.com/w3c/clipboard-apis/issues/40

Original issue's description:
> Make Editor::findEventTargetFrom() to align Clipboard API specification
>
> This patch changes |Editor::findEventTargetFrom()| to return focused element if
> selection start is not editable to align Clipboard API specification[1] for
> improving interoperability.
>
> [1] https://w3c.github.io/clipboard-apis/#to-fire-a-clipboard-event
>
> BUG=690104
> TEST=webkit_unittests --gtest_filter=ClipboardEventFlowTest.*
>
> Review-Url: https://codereview.chromium.org/2685723005
> Cr-Commit-Position: refs/heads/master@{#451716}
> Committed: https://chromium.googlesource.com/chromium/src/+/7afbab0f7619c89aa7a5896024d1628a59cc0ef1

TBR=tkent@chromium.org,ojan@chromium.org,yosin@chromium.org,yutak@chromium.org,sigbjornf@opera.com,mwrobel@opera.com
# Not skipping CQ checks because original CL landed more than 1 days ago.
BUG=690104

Review-Url: https://codereview.chromium.org/2745813002
Cr-Commit-Position: refs/heads/master@{#456232}
parent d62ba1f5
<body onpaste="paste(event)"> <div id="test" onpaste="paste(event)">This test verifies that we can get types from the clipboard
<div id="test">This test verifies that we can get types from the clipboard
during an onpaste event. This test requires DRT.</div> during an onpaste event. This test requires DRT.</div>
<div id="results">FAIL</div> <div id="results">FAIL</div>
...@@ -25,4 +24,3 @@ function editingTest() ...@@ -25,4 +24,3 @@ function editingTest()
runDumpAsTextEditingTest(false); runDumpAsTextEditingTest(false);
</script> </script>
</body>
...@@ -226,7 +226,6 @@ blink_core_sources("editing") { ...@@ -226,7 +226,6 @@ blink_core_sources("editing") {
source_set("unit_tests") { source_set("unit_tests") {
testonly = true testonly = true
sources = [ sources = [
"ClipboardEventFlowTest.cpp",
"CompositionUnderlineTest.cpp", "CompositionUnderlineTest.cpp",
"EditingCommandTest.cpp", "EditingCommandTest.cpp",
"EditingStrategyTest.cpp", "EditingStrategyTest.cpp",
......
// Copyright 2017 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "core/dom/Document.h"
#include "core/editing/EditingTestBase.h"
#include "core/editing/FrameSelection.h"
#include "core/editing/Position.h"
#include "core/editing/SelectionTemplate.h"
#include "core/events/EventListener.h"
#include "core/frame/LocalFrame.h"
#include "core/frame/Settings.h"
#include "core/html/HTMLBodyElement.h"
#include "core/html/HTMLButtonElement.h"
#include "core/html/HTMLDivElement.h"
#include "core/html/HTMLHtmlElement.h"
#include "core/layout/LayoutObject.h"
#include "testing/gmock/include/gmock/gmock.h"
namespace blink {
namespace {
class MockEventListener : public EventListener {
public:
MockEventListener() : EventListener(EventListener::CPPEventListenerType) {}
bool operator==(const EventListener& other) const final {
return this == &other;
}
MOCK_METHOD2(handleEvent, void(ExecutionContext*, Event*));
};
} // namespace
class ClipboardEventFlowTest : public EditingTestBase {
private:
void makeDocumentEmpty() {
while (document().firstChild())
document().removeChild(document().firstChild());
}
void setElementText(Element& element, const std::string& text) {
element.setInnerHTML(String::fromUTF8(text.c_str()), ASSERT_NO_EXCEPTION);
updateAllLifecyclePhases();
}
void setElementTextAndSelectIt(Element& element,
const std::string& text,
bool selectionEditable) {
setElementText(element, text);
frame().selection().setSelection(
SelectionInDOMTree::Builder()
.collapse(Position(element.firstChild(), 0))
.extend(Position(element.firstChild(), text.size()))
.build());
element.setAttribute(HTMLNames::contenteditableAttr,
selectionEditable ? "true" : "false");
}
protected:
void clipboardEventTargetDependsOnSelectionEditabilityTest(
const char* command,
bool selectionEditable) {
using testing::_;
auto* html = HTMLHtmlElement::create(document());
auto* body = HTMLBodyElement::create(document());
auto* focusableElement = HTMLButtonElement::create(document());
auto* elementWithSelection = HTMLDivElement::create(document());
auto* eventListenerInstalledOnFocusedElement = new MockEventListener;
auto* eventListenerInstalledOnElementWithSelection = new MockEventListener;
focusableElement->addEventListener(command,
eventListenerInstalledOnFocusedElement);
elementWithSelection->addEventListener(
command, eventListenerInstalledOnElementWithSelection);
makeDocumentEmpty();
document().setDesignMode("on");
body->appendChild(focusableElement);
body->appendChild(elementWithSelection);
html->appendChild(body);
document().appendChild(html);
focusableElement->focus();
setElementTextAndSelectIt(*elementWithSelection, "some dummy text",
selectionEditable);
// allow |document.execCommand| to access clipboard
frame().settings()->setJavaScriptCanAccessClipboard(true);
// test expectations
EXPECT_CALL(*eventListenerInstalledOnFocusedElement, handleEvent(_, _))
.Times(selectionEditable ? 0 : 1);
EXPECT_CALL(*eventListenerInstalledOnElementWithSelection,
handleEvent(_, _))
.Times(selectionEditable ? 1 : 0);
// execute command
NonThrowableExceptionState exceptionState;
document().execCommand(command, false, "", exceptionState);
}
};
TEST_F(ClipboardEventFlowTest,
copySetsClipboardEventTargetToActiveElementWhenSelectionIsNotEditable) {
clipboardEventTargetDependsOnSelectionEditabilityTest("copy", false);
}
TEST_F(
ClipboardEventFlowTest,
copySetsClipboardEventTargetToElementWithSelectionWhenSelectionIsEditable) {
clipboardEventTargetDependsOnSelectionEditabilityTest("copy", true);
}
TEST_F(ClipboardEventFlowTest,
cutSetsClipboardEventTargetToActiveElementWhenSelectionIsNotEditable) {
clipboardEventTargetDependsOnSelectionEditabilityTest("cut", false);
}
TEST_F(
ClipboardEventFlowTest,
cutSetsClipboardEventTargetToElementWithSelectionWhenSelectionIsEditable) {
clipboardEventTargetDependsOnSelectionEditabilityTest("cut", true);
}
TEST_F(ClipboardEventFlowTest,
pasteSetsClipboardEventTargetToActiveElementWhenSelectionIsNotEditable) {
// allow |document.execCommand| to execute 'paste' command
frame().settings()->setDOMPasteAllowed(true);
clipboardEventTargetDependsOnSelectionEditabilityTest("paste", false);
}
TEST_F(
ClipboardEventFlowTest,
pasteSetsClipboardEventTargetToElementWithSelectionWhenSelectionIsEditable) {
// allow |document.execCommand| to execute 'paste'
frame().settings()->setDOMPasteAllowed(true);
clipboardEventTargetDependsOnSelectionEditabilityTest("paste", true);
}
} // namespace blink
...@@ -772,9 +772,7 @@ void Editor::registerCommandGroup(CompositeEditCommand* commandGroupWrapper) { ...@@ -772,9 +772,7 @@ void Editor::registerCommandGroup(CompositeEditCommand* commandGroupWrapper) {
} }
Element* Editor::findEventTargetFrom(const VisibleSelection& selection) const { Element* Editor::findEventTargetFrom(const VisibleSelection& selection) const {
Element* target = selection.hasEditableStyle() Element* target = associatedElementOf(selection.start());
? associatedElementOf(selection.start())
: frame().document()->activeElement();
if (!target) if (!target)
target = frame().document()->body(); target = frame().document()->body();
......
...@@ -24,12 +24,11 @@ ...@@ -24,12 +24,11 @@
#ifndef HTMLButtonElement_h #ifndef HTMLButtonElement_h
#define HTMLButtonElement_h #define HTMLButtonElement_h
#include "core/CoreExport.h"
#include "core/html/HTMLFormControlElement.h" #include "core/html/HTMLFormControlElement.h"
namespace blink { namespace blink {
class CORE_EXPORT HTMLButtonElement final : public HTMLFormControlElement { class HTMLButtonElement final : public HTMLFormControlElement {
DEFINE_WRAPPERTYPEINFO(); DEFINE_WRAPPERTYPEINFO();
public: public:
......
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