Commit d3ff4785 authored by David Tseng's avatar David Tseng Committed by Commit Bot

A collapsed (caret) selection should be collapsed in the accessibility tree

(i.e. focusObject == anchorObject)

Test: verify that moving a caret (*not a selection*) never results in a non-collapsed selection in the accessibility tree data
Cq-Include-Trybots: master.tryserver.chromium.linux:closure_compilation
Change-Id: I29f3d807fd7d9e29b997e3f1969f60d7a99b170a
Reviewed-on: https://chromium-review.googlesource.com/884991Reviewed-by: default avatarDominic Mazzoni <dmazzoni@chromium.org>
Reviewed-by: default avatarNektarios Paisios <nektar@chromium.org>
Commit-Queue: David Tseng <dtseng@chromium.org>
Cr-Commit-Position: refs/heads/master@{#532281}
parent fdeaf6e2
......@@ -816,7 +816,7 @@ editing.EditableLine.prototype = {
var finder = this.lineStart_;
while (finder.previousSibling) {
finder = finder.previousSibling;
textCountBeforeLineStart += finder.name.length;
textCountBeforeLineStart += finder.name ? finder.name.length : 0;
}
this.localLineStartContainerOffset_ = textCountBeforeLineStart;
......@@ -828,7 +828,7 @@ editing.EditableLine.prototype = {
finder = this.lineEnd_;
while (finder.nextSibling) {
finder = finder.nextSibling;
textCountAfterLineEnd += finder.name.length;
textCountAfterLineEnd += finder.name ? finder.name.length : 0;
}
if (this.lineEndContainer_.name) {
......
......@@ -1794,14 +1794,10 @@ AXObject::AXRange AXLayoutObject::Selection() const {
VisiblePosition visible_start = selection.VisibleStart();
Position start = visible_start.ToParentAnchoredPosition();
TextAffinity start_affinity = visible_start.Affinity();
VisiblePosition visible_end = selection.VisibleEnd();
Position end = visible_end.ToParentAnchoredPosition();
TextAffinity end_affinity = visible_end.Affinity();
Node* anchor_node = start.AnchorNode();
DCHECK(anchor_node);
AXLayoutObject* anchor_object = nullptr;
// Find the closest node that has a corresponding AXObject.
// This is because some nodes may be aria hidden or might not even have
// a layout object if they are part of the shadow DOM.
......@@ -1815,10 +1811,20 @@ AXObject::AXRange AXLayoutObject::Selection() const {
else
anchor_node = anchor_node->parentNode();
}
if (!anchor_object)
return AXRange();
int anchor_offset = anchor_object->IndexForVisiblePosition(visible_start);
DCHECK_GE(anchor_offset, 0);
if (selection.IsCaret()) {
return AXRange(anchor_object, anchor_offset, start_affinity, anchor_object,
anchor_offset, start_affinity);
}
VisiblePosition visible_end = selection.VisibleEnd();
Position end = visible_end.ToParentAnchoredPosition();
TextAffinity end_affinity = visible_end.Affinity();
Node* focus_node = end.AnchorNode();
DCHECK(focus_node);
AXLayoutObject* focus_object = nullptr;
while (focus_node) {
focus_object = GetUnignoredObjectFromNode(*focus_node);
......@@ -1830,12 +1836,8 @@ AXObject::AXRange AXLayoutObject::Selection() const {
else
focus_node = focus_node->parentNode();
}
if (!anchor_object || !focus_object)
if (!focus_object)
return AXRange();
int anchor_offset = anchor_object->IndexForVisiblePosition(visible_start);
DCHECK_GE(anchor_offset, 0);
int focus_offset = focus_object->IndexForVisiblePosition(visible_end);
DCHECK_GE(focus_offset, 0);
return AXRange(anchor_object, anchor_offset, start_affinity, focus_object,
......
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