Commit 3391cee5 authored by Yoshifumi Inoue's avatar Yoshifumi Inoue Committed by Commit Bot

Make Editor::CanCopy() to use flat tree version of selection

This patch changes |Editor::CanCopy()| to use flat tree version of selection
instead of DOM tree version since serialization for "copy" command traverses
flat tree, to allow users to copy selection crossing shadow boundary.

Bug: 866175
Cq-Include-Trybots: luci.chromium.try:linux_layout_tests_layout_ng
Change-Id: I89152cf2843a39af6197ef3aa9153f72fd728ad9
Reviewed-on: https://chromium-review.googlesource.com/1149940
Commit-Queue: Yoshifumi Inoue <yosin@chromium.org>
Reviewed-by: default avatarXiaocheng Hu <xiaochengh@chromium.org>
Reviewed-by: default avatarYoichi Osato <yoichio@chromium.org>
Cr-Commit-Position: refs/heads/master@{#578216}
parent 6adb1477
...@@ -238,9 +238,12 @@ bool Editor::CanCopy() const { ...@@ -238,9 +238,12 @@ bool Editor::CanCopy() const {
FrameSelection& selection = GetFrameSelection(); FrameSelection& selection = GetFrameSelection();
if (!selection.IsAvailable()) if (!selection.IsAvailable())
return false; return false;
return selection.ComputeVisibleSelectionInDOMTreeDeprecated().IsRange() && frame_->GetDocument()->UpdateStyleAndLayoutIgnorePendingStylesheets();
const VisibleSelectionInFlatTree& visible_selection =
selection.ComputeVisibleSelectionInFlatTree();
return visible_selection.IsRange() &&
!IsInPasswordFieldWithUnrevealedPassword( !IsInPasswordFieldWithUnrevealedPassword(
selection.ComputeVisibleSelectionInDOMTree().Start()); ToPositionInDOMTree(visible_selection.Start()));
} }
bool Editor::CanPaste() const { bool Editor::CanPaste() const {
......
...@@ -6,6 +6,8 @@ ...@@ -6,6 +6,8 @@
#include "third_party/blink/renderer/core/clipboard/system_clipboard.h" #include "third_party/blink/renderer/core/clipboard/system_clipboard.h"
#include "third_party/blink/renderer/core/editing/commands/editor_command.h" #include "third_party/blink/renderer/core/editing/commands/editor_command.h"
#include "third_party/blink/renderer/core/editing/frame_selection.h"
#include "third_party/blink/renderer/core/editing/selection_template.h"
#include "third_party/blink/renderer/core/editing/testing/editing_test_base.h" #include "third_party/blink/renderer/core/editing/testing/editing_test_base.h"
#include "third_party/blink/renderer/core/html/forms/html_input_element.h" #include "third_party/blink/renderer/core/html/forms/html_input_element.h"
#include "third_party/blink/renderer/platform/testing/unit_test_helpers.h" #include "third_party/blink/renderer/platform/testing/unit_test_helpers.h"
...@@ -26,6 +28,13 @@ class EditorTest : public EditingTestBase { ...@@ -26,6 +28,13 @@ class EditorTest : public EditingTestBase {
} }
}; };
TEST_F(EditorTest, CanCopyCrossingShadowBoundary) {
const SelectionInDOMTree selection = SetSelectionTextToBody(
"<p><template data-mode=open>^abc</template></p><b>|</b>");
Selection().SetSelection(selection, SetSelectionOptions());
EXPECT_TRUE(GetDocument().GetFrame()->GetEditor().CanCopy());
}
TEST_F(EditorTest, copyGeneratedPassword) { TEST_F(EditorTest, copyGeneratedPassword) {
// Checks that if the password field has the value generated by Chrome // Checks that if the password field has the value generated by Chrome
// (HTMLInputElement::shouldRevealPassword will be true), copying the field // (HTMLInputElement::shouldRevealPassword will be true), copying the field
......
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