Commit 557d75a1 authored by Nektarios Paisios's avatar Nektarios Paisios Committed by Commit Bot

Exposes affinity in text fields

Affinity is retrieved from the frame selection,
i.e. from the currently visible selection.
Text fields don't expose their affinity in Javascript,
so it doesn't make sense to cache its value so that it could be retrieved when the text field is not focused.
Any time the text field is not focused, we return
a cached selection that has a downstream affinity.
R=dmazzoni@chromium.org, yosin@chromium.org

Bug: 639340
Change-Id: If488edc29cd72e9835c7120466ea8dfa01d5841d
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1535051Reviewed-by: default avatarKeishi Hattori <keishi@chromium.org>
Reviewed-by: default avatarYoshifumi Inoue <yosin@chromium.org>
Reviewed-by: default avatarDominic Mazzoni <dmazzoni@chromium.org>
Commit-Queue: Nektarios Paisios <nektar@chromium.org>
Cr-Commit-Position: refs/heads/master@{#645337}
parent dc86dd8c
......@@ -42,6 +42,7 @@
#include "third_party/blink/renderer/core/editing/selection_template.h"
#include "third_party/blink/renderer/core/editing/serializers/serialization.h"
#include "third_party/blink/renderer/core/editing/set_selection_options.h"
#include "third_party/blink/renderer/core/editing/text_affinity.h"
#include "third_party/blink/renderer/core/editing/visible_position.h"
#include "third_party/blink/renderer/core/frame/local_frame.h"
#include "third_party/blink/renderer/core/frame/use_counter.h"
......@@ -659,8 +660,16 @@ SelectionInDOMTree TextControlElement::Selection() const {
if (!start_node || !end_node)
return SelectionInDOMTree();
TextAffinity affinity = TextAffinity::kDownstream;
if (GetDocument().FocusedElement() == this && GetDocument().GetFrame()) {
const SelectionInDOMTree& selection =
GetDocument().GetFrame()->Selection().GetSelectionInDOMTree();
affinity = selection.Affinity();
}
return SelectionInDOMTree::Builder()
.SetBaseAndExtent(Position(start_node, start), Position(end_node, end))
.SetAffinity(affinity)
.Build();
}
......
......@@ -678,9 +678,8 @@ TEST_F(AccessibilitySelectionTest, FromCurrentSelectionInTextareaWithAffinity) {
EXPECT_EQ(TextAffinity::kDownstream, ax_selection.Extent().Affinity());
}
TEST_F(
AccessibilitySelectionTest,
DISABLED_FromCurrentSelectionInTextareaWithCollapsedSelectionAndAffinity) {
TEST_F(AccessibilitySelectionTest,
FromCurrentSelectionInTextareaWithCollapsedSelectionAndAffinity) {
SetBodyInnerHTML(R"HTML(
<textarea id="textarea"
rows="2" cols="15"
......
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