Commit 18fdc89d authored by Tima Vaisburd's avatar Tima Vaisburd Committed by Commit Bot

Revert "[Smart Text] Disable surrounding text for input elements."

This reverts commit afd38807.

Reason for revert: breaks smart text selection for GMail editor, http://crbug.com/757945

Original change's description:
> [Smart Text] Disable surrounding text for input elements.
> 
> This CL effectively reverts
> https://codereview.chromium.org/2907963002, which appears to
> causing problems, including leaking of input fields to
> Google servers.
> 
> Disabling until a better fix is found.
> 
> BUG=751408, 753579, 721840
> 
> Change-Id: Iecddba6ebed8faf3c266daa232613c57fa5a7464
> Reviewed-on: https://chromium-review.googlesource.com/622747
> Reviewed-by: Yoshifumi Inoue <yosin@chromium.org>
> Commit-Queue: Tima Vaisburd <timav@chromium.org>
> Cr-Commit-Position: refs/heads/master@{#495985}

TBR=yosin@chromium.org,donnd@chromium.org,timav@chromium.org

# Not skipping CQ checks because original CL landed > 1 day ago.

Bug: 751408, 753579, 721840
Change-Id: Ifc8d987a25fe1b98a206dbd6e572436444545490
Reviewed-on: https://chromium-review.googlesource.com/627576Reviewed-by: default avatarTima Vaisburd <timav@chromium.org>
Reviewed-by: default avatarDonn Denman <donnd@chromium.org>
Reviewed-by: default avatarYoshifumi Inoue <yosin@chromium.org>
Commit-Queue: Yoshifumi Inoue <yosin@chromium.org>
Cr-Commit-Position: refs/heads/master@{#496615}
parent d3602dbc
...@@ -64,11 +64,14 @@ void SurroundingText::Initialize(const Position& start_position, ...@@ -64,11 +64,14 @@ void SurroundingText::Initialize(const Position& start_position,
return; return;
DCHECK(!document->NeedsLayoutTreeUpdate()); DCHECK(!document->NeedsLayoutTreeUpdate());
// Do not create surrounding text for input elements. // The forward range starts at the selection end and ends at the document's
// or the input element's end. It will then be updated to only contain the
// text in the right range around the selection.
DCHECK_EQ(RootEditableElementOf(start_position), DCHECK_EQ(RootEditableElementOf(start_position),
RootEditableElementOf(end_position)); RootEditableElementOf(end_position));
if (RootEditableElementOf(start_position)) Element* const root_editable = RootEditableElementOf(start_position);
return; Element* const root_element =
root_editable ? root_editable : document->documentElement();
// Do not create surrounding text if start or end position is within a // Do not create surrounding text if start or end position is within a
// control. // control.
...@@ -78,13 +81,9 @@ void SurroundingText::Initialize(const Position& start_position, ...@@ -78,13 +81,9 @@ void SurroundingText::Initialize(const Position& start_position,
end_position.ComputeContainerNode())) end_position.ComputeContainerNode()))
return; return;
// The forward range starts at the selection end and ends at the document's
// end. It will then be updated to only contain the text in the right range
// around the selection.
CharacterIterator forward_iterator( CharacterIterator forward_iterator(
end_position, end_position,
Position::LastPositionInNode(*document->documentElement()) Position::LastPositionInNode(*root_element).ParentAnchoredEquivalent(),
.ParentAnchoredEquivalent(),
TextIteratorBehavior::Builder().SetStopsOnFormControls(true).Build()); TextIteratorBehavior::Builder().SetStopsOnFormControls(true).Build());
if (!forward_iterator.AtEnd()) if (!forward_iterator.AtEnd())
forward_iterator.Advance(max_length - half_max_length); forward_iterator.Advance(max_length - half_max_length);
...@@ -93,8 +92,7 @@ void SurroundingText::Initialize(const Position& start_position, ...@@ -93,8 +92,7 @@ void SurroundingText::Initialize(const Position& start_position,
// starts at the document's or input element's start and ends at the selection // starts at the document's or input element's start and ends at the selection
// start and will be updated. // start and will be updated.
BackwardsCharacterIterator backwards_iterator( BackwardsCharacterIterator backwards_iterator(
Position::FirstPositionInNode(*document->documentElement()) Position::FirstPositionInNode(*root_element).ParentAnchoredEquivalent(),
.ParentAnchoredEquivalent(),
start_position, start_position,
TextIteratorBehavior::Builder().SetStopsOnFormControls(true).Build()); TextIteratorBehavior::Builder().SetStopsOnFormControls(true).Build());
if (!backwards_iterator.AtEnd()) if (!backwards_iterator.AtEnd())
......
...@@ -11,6 +11,7 @@ ...@@ -11,6 +11,7 @@
#include "core/editing/Position.h" #include "core/editing/Position.h"
#include "core/editing/VisibleSelection.h" #include "core/editing/VisibleSelection.h"
#include "core/html/HTMLElement.h" #include "core/html/HTMLElement.h"
#include "core/html/TextControlElement.h"
#include "core/testing/DummyPageHolder.h" #include "core/testing/DummyPageHolder.h"
#include "testing/gtest/include/gtest/gtest.h" #include "testing/gtest/include/gtest/gtest.h"
...@@ -285,4 +286,24 @@ TEST_F(SurroundingTextTest, TreeRangeSelection) { ...@@ -285,4 +286,24 @@ TEST_F(SurroundingTextTest, TreeRangeSelection) {
} }
} }
TEST_F(SurroundingTextTest, TextAreaSelection) {
SetHTML(
String("<p>First paragraph</p>"
"<textarea id='selection'>abc def ghi</textarea>"
"<p>Second paragraph</p>"));
TextControlElement* text_ctrl =
(TextControlElement*)GetDocument().getElementById("selection");
text_ctrl->SetSelectionRange(4, 7);
VisibleSelection selection = CreateVisibleSelection(text_ctrl->Selection());
SurroundingText surrounding_text(
*CreateRange(FirstEphemeralRangeOf(selection)), 20);
EXPECT_EQ("abc def ghi", surrounding_text.Content().SimplifyWhiteSpace());
EXPECT_EQ(4u, surrounding_text.StartOffsetInContent());
EXPECT_EQ(7u, surrounding_text.EndOffsetInContent());
}
} // namespace blink } // namespace blink
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