Commit 7af7b857 authored by Doug Turner's avatar Doug Turner Committed by Commit Bot

Migrate removeSelection from BrowserAccessiblity to AXPlatformNode

Bug: 703369
Change-Id: Ifab324cf226c59881214be0d2d7c5c22ba1d0066
Reviewed-on: https://chromium-review.googlesource.com/659257
Commit-Queue: Dominic Mazzoni <dmazzoni@chromium.org>
Reviewed-by: default avatarDominic Mazzoni <dmazzoni@chromium.org>
Cr-Commit-Position: refs/heads/master@{#501481}
parent b7b11b3d
...@@ -629,23 +629,7 @@ STDMETHODIMP BrowserAccessibilityComWin::addSelection(LONG start_offset, ...@@ -629,23 +629,7 @@ STDMETHODIMP BrowserAccessibilityComWin::addSelection(LONG start_offset,
} }
STDMETHODIMP BrowserAccessibilityComWin::removeSelection(LONG selection_index) { STDMETHODIMP BrowserAccessibilityComWin::removeSelection(LONG selection_index) {
WIN_ACCESSIBILITY_API_HISTOGRAM(UMA_API_REMOVE_SELECTION); return AXPlatformNodeWin::removeSelection(selection_index);
AddAccessibilityModeFlags(kScreenReaderAndHTMLAccessibilityModes);
if (!owner())
return E_FAIL;
if (selection_index != 0)
return E_INVALIDARG;
// Simply collapse the selection to the position of the caret if a caret is
// visible, otherwise set the selection to 0.
LONG caret_offset = 0;
int selection_start, selection_end;
GetSelectionOffsets(&selection_start, &selection_end);
if (owner()->HasCaret() && selection_end >= 0)
caret_offset = selection_end;
SetIA2HypertextSelection(caret_offset, caret_offset);
return S_OK;
} }
STDMETHODIMP BrowserAccessibilityComWin::setCaretOffset(LONG offset) { STDMETHODIMP BrowserAccessibilityComWin::setCaretOffset(LONG offset) {
......
...@@ -2448,6 +2448,10 @@ STDMETHODIMP AXPlatformNodeWin::addSelection(LONG start_offset, ...@@ -2448,6 +2448,10 @@ STDMETHODIMP AXPlatformNodeWin::addSelection(LONG start_offset,
} }
STDMETHODIMP AXPlatformNodeWin::removeSelection(LONG selection_index) { STDMETHODIMP AXPlatformNodeWin::removeSelection(LONG selection_index) {
WIN_ACCESSIBILITY_API_HISTOGRAM(UMA_API_REMOVE_SELECTION);
COM_OBJECT_VALIDATE();
AXPlatformNode::NotifyAddAXModeFlags(kScreenReaderAndHTMLAccessibilityModes);
if (selection_index != 0) if (selection_index != 0)
return E_INVALIDARG; return E_INVALIDARG;
// Simply collapse the selection to the position of the caret if a caret is // Simply collapse the selection to the position of the caret if a caret is
......
...@@ -2207,4 +2207,29 @@ TEST_F(AXPlatformNodeWinTest, TestIAccessibleTextGetNCharacters) { ...@@ -2207,4 +2207,29 @@ TEST_F(AXPlatformNodeWinTest, TestIAccessibleTextGetNCharacters) {
EXPECT_EQ(4, count); EXPECT_EQ(4, count);
} }
TEST_F(AXPlatformNodeWinTest, TestIAccessibleTextRemoveSelection) {
AXNodeData text_field_node;
text_field_node.id = 1;
text_field_node.role = AX_ROLE_TEXT_FIELD;
text_field_node.state = 1 << AX_STATE_EDITABLE;
text_field_node.state |= 1 << AX_STATE_SELECTED;
text_field_node.AddIntAttribute(ui::AX_ATTR_TEXT_SEL_START, 1);
text_field_node.AddIntAttribute(ui::AX_ATTR_TEXT_SEL_END, 2);
text_field_node.SetValue("Hi");
Init(text_field_node);
ScopedComPtr<IAccessible2> ia2_text_field =
ToIAccessible2(GetRootIAccessible());
ScopedComPtr<IAccessibleText> text_field;
ia2_text_field.CopyTo(text_field.GetAddressOf());
ASSERT_NE(nullptr, text_field.Get());
EXPECT_HRESULT_SUCCEEDED(text_field->removeSelection(0));
LONG start_offset, end_offset;
EXPECT_HRESULT_SUCCEEDED(
text_field->get_selection(0, &start_offset, &end_offset));
ASSERT_EQ(2, start_offset);
ASSERT_EQ(2, end_offset);
}
} // namespace ui } // namespace ui
...@@ -175,12 +175,49 @@ TestAXNodeWrapper::GetTargetForNativeAccessibilityEvent() { ...@@ -175,12 +175,49 @@ TestAXNodeWrapper::GetTargetForNativeAccessibilityEvent() {
return gfx::kNullAcceleratedWidget; return gfx::kNullAcceleratedWidget;
} }
void TestAXNodeWrapper::ReplaceIntAttribute(int32_t node_id,
AXIntAttribute attribute,
int32_t value) {
if (!tree_)
return;
AXNode* node = tree_->GetFromId(node_id);
if (!node)
return;
AXNodeData new_data = node->data();
std::vector<std::pair<AXIntAttribute, int32_t>>& attributes =
new_data.int_attributes;
auto deleted = std::remove_if(
attributes.begin(), attributes.end(),
[attribute](auto& pair) { return pair.first == attribute; });
attributes.erase(deleted, attributes.end());
new_data.AddIntAttribute(attribute, value);
node->SetData(new_data);
}
bool TestAXNodeWrapper::AccessibilityPerformAction( bool TestAXNodeWrapper::AccessibilityPerformAction(
const ui::AXActionData& data) { const ui::AXActionData& data) {
if (data.action == ui::AX_ACTION_SCROLL_TO_POINT) if (data.action == ui::AX_ACTION_SCROLL_TO_POINT) {
g_offset = gfx::Vector2d(data.target_point.x(), data.target_point.x()); g_offset = gfx::Vector2d(data.target_point.x(), data.target_point.x());
else if (data.action == ui::AX_ACTION_SCROLL_TO_MAKE_VISIBLE) return true;
}
if (data.action == ui::AX_ACTION_SCROLL_TO_MAKE_VISIBLE) {
g_offset = gfx::Vector2d(data.target_rect.x(), data.target_rect.x()); g_offset = gfx::Vector2d(data.target_rect.x(), data.target_rect.x());
return true;
}
if (data.action == ui::AX_ACTION_SET_SELECTION) {
ReplaceIntAttribute(data.anchor_node_id, AX_ATTR_TEXT_SEL_START,
data.anchor_offset);
ReplaceIntAttribute(data.anchor_node_id, AX_ATTR_TEXT_SEL_END,
data.focus_offset);
return true;
}
return true; return true;
} }
......
...@@ -48,6 +48,9 @@ class TestAXNodeWrapper : public AXPlatformNodeDelegate { ...@@ -48,6 +48,9 @@ class TestAXNodeWrapper : public AXPlatformNodeDelegate {
private: private:
TestAXNodeWrapper(AXTree* tree, AXNode* node); TestAXNodeWrapper(AXTree* tree, AXNode* node);
void ReplaceIntAttribute(int32_t node_id,
AXIntAttribute attribute,
int32_t value);
TestAXNodeWrapper* HitTestSyncInternal(int x, int y); TestAXNodeWrapper* HitTestSyncInternal(int x, int y);
......
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