Commit a3a58b3a authored by Aaron Leventhal's avatar Aaron Leventhal Committed by Commit Bot

Do not fire a11y events for caret unless caret or selection is visible

Bug: 870020
Change-Id: Ic0173972f01d506d5e8b18b8c6de629ecc6b6a6e
Reviewed-on: https://chromium-review.googlesource.com/1159188Reviewed-by: default avatarSadrul Chowdhury <sadrul@chromium.org>
Reviewed-by: default avatarDominic Mazzoni <dmazzoni@chromium.org>
Commit-Queue: Aaron Leventhal <aleventhal@chromium.org>
Cr-Commit-Position: refs/heads/master@{#583788}
parent 35fb8a86
...@@ -691,20 +691,24 @@ bool BrowserAccessibility::HasAction(ax::mojom::Action action_enum) const { ...@@ -691,20 +691,24 @@ bool BrowserAccessibility::HasAction(ax::mojom::Action action_enum) const {
return GetData().HasAction(action_enum); return GetData().HasAction(action_enum);
} }
bool BrowserAccessibility::HasCaret() const { bool BrowserAccessibility::HasVisibleCaretOrSelection() const {
if (IsPlainTextField() &&
HasIntAttribute(ax::mojom::IntAttribute::kTextSelStart) &&
HasIntAttribute(ax::mojom::IntAttribute::kTextSelEnd)) {
return true;
}
// The caret is always at the focus of the selection.
int32_t focus_id = manager()->GetTreeData().sel_focus_object_id; int32_t focus_id = manager()->GetTreeData().sel_focus_object_id;
BrowserAccessibility* focus_object = manager()->GetFromID(focus_id); BrowserAccessibility* focus_object = manager()->GetFromID(focus_id);
if (!focus_object) if (!focus_object)
return false; return false;
return focus_object->IsDescendantOf(this); // Selection or caret will be visible in a focused editable area.
if (HasState(ax::mojom::State::kEditable)) {
return IsPlainTextField() ? focus_object == this
: focus_object->IsDescendantOf(this);
}
// The selection will be visible in non-editable content only if it is not
// collapsed into a caret.
return (focus_id != manager()->GetTreeData().sel_anchor_object_id ||
manager()->GetTreeData().sel_focus_offset !=
manager()->GetTreeData().sel_anchor_offset) &&
focus_object->IsDescendantOf(this);
} }
bool BrowserAccessibility::IsWebAreaForPresentationalIframe() const { bool BrowserAccessibility::IsWebAreaForPresentationalIframe() const {
......
...@@ -303,8 +303,8 @@ class CONTENT_EXPORT BrowserAccessibility : public ui::AXPlatformNodeDelegate { ...@@ -303,8 +303,8 @@ class CONTENT_EXPORT BrowserAccessibility : public ui::AXPlatformNodeDelegate {
bool HasState(ax::mojom::State state_enum) const; bool HasState(ax::mojom::State state_enum) const;
bool HasAction(ax::mojom::Action action_enum) const; bool HasAction(ax::mojom::Action action_enum) const;
// Returns true if the caret is active on this object. // Returns true if the caret or selection is visible on this object.
bool HasCaret() const; bool HasVisibleCaretOrSelection() const;
// True if this is a web area, and its grandparent is a presentational iframe. // True if this is a web area, and its grandparent is a presentational iframe.
bool IsWebAreaForPresentationalIframe() const; bool IsWebAreaForPresentationalIframe() const;
......
...@@ -169,7 +169,7 @@ void BrowserAccessibilityManagerWin::FireGeneratedEvent( ...@@ -169,7 +169,7 @@ void BrowserAccessibilityManagerWin::FireGeneratedEvent(
// Fire the event on the object where the focus of the selection is. // Fire the event on the object where the focus of the selection is.
int32_t focus_id = GetTreeData().sel_focus_object_id; int32_t focus_id = GetTreeData().sel_focus_object_id;
BrowserAccessibility* focus_object = GetFromID(focus_id); BrowserAccessibility* focus_object = GetFromID(focus_id);
if (focus_object) if (focus_object->HasVisibleCaretOrSelection())
FireWinAccessibilityEvent(IA2_EVENT_TEXT_CARET_MOVED, focus_object); FireWinAccessibilityEvent(IA2_EVENT_TEXT_CARET_MOVED, focus_object);
break; break;
} }
......
...@@ -2389,6 +2389,16 @@ void RenderWidgetHostViewAura::OnSelectionBoundsChanged( ...@@ -2389,6 +2389,16 @@ void RenderWidgetHostViewAura::OnSelectionBoundsChanged(
if (!region) if (!region)
return; return;
// Do not notify of change unless selection or caret is visible.
if (region->anchor == region->focus) {
// If selection is collapsed, check to see if user is editing (caret will be
// visible).
const TextInputState* state = GetTextInputManager()->GetTextInputState();
if (!state || (state->type == ui::TEXT_INPUT_TYPE_NONE &&
state->mode == ui::TEXT_INPUT_MODE_NONE))
return;
}
const gfx::Rect caret_rect = ConvertRectToScreen(gfx::Rect( const gfx::Rect caret_rect = ConvertRectToScreen(gfx::Rect(
region->focus.edge_top_rounded().x(), region->focus.edge_top_rounded().x(),
region->focus.edge_top_rounded().y(), 1, region->focus.GetHeight())); region->focus.edge_top_rounded().y(), 1, region->focus.GetHeight()));
......
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