Commit 287e77d7 authored by Alison Maher's avatar Alison Maher Committed by Commit Bot

Implement ITextRangeProvider::Move

This change implements Implement ITextRangeProvider::Move. This
implementation uses MoveEndpointByUnit to do most of the functionality,
with some edge cases handled.

Unit tests were added for all unit types except Format and Paragraph.
Unit tests for these will be added once MoveEndpointByUnit is
completed for each type.

AssertMoveEndpointByUnit() and AssertMove() helper functions were added
to the unit tests to decrease the amount of repeated code and to
increase readability.

Bug: 928948
Change-Id: I22dfa7017d162b83fdc6db66dbcfd5266d98bfcf
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1569522Reviewed-by: default avatarDominic Mazzoni <dmazzoni@chromium.org>
Commit-Queue: Alison Maher <almaher@microsoft.com>
Cr-Commit-Position: refs/heads/master@{#652854}
parent 9f5df0d2
...@@ -449,7 +449,49 @@ STDMETHODIMP AXPlatformNodeTextRangeProviderWin::Move(TextUnit unit, ...@@ -449,7 +449,49 @@ STDMETHODIMP AXPlatformNodeTextRangeProviderWin::Move(TextUnit unit,
int count, int count,
int* units_moved) { int* units_moved) {
WIN_ACCESSIBILITY_API_HISTOGRAM(UMA_API_TEXTRANGE_MOVE); WIN_ACCESSIBILITY_API_HISTOGRAM(UMA_API_TEXTRANGE_MOVE);
return E_NOTIMPL; UIA_VALIDATE_TEXTRANGEPROVIDER_CALL();
*units_moved = 0;
// Per MSDN, move with zero count has no effect.
if (count == 0)
return S_OK;
// Save a clone of start and end, in case one of the moves fails.
auto start_backup = start_->Clone();
auto end_backup = end_->Clone();
bool is_degenerate_range = (*start_ == *end_);
// Move the start of the text range forward or backward in the document by the
// requested number of text unit boundaries.
int start_units_moved = 0;
HRESULT hr = MoveEndpointByUnit(TextPatternRangeEndpoint_Start, unit, count,
&start_units_moved);
bool succeeded_move = SUCCEEDED(hr) && start_units_moved == count;
if (succeeded_move) {
end_ = start_->Clone();
if (!is_degenerate_range) {
// Expand the text range from the degenerate state by moving the
// endpoint forward by one text unit.
int end_units_moved = 0;
hr = MoveEndpointByUnit(TextPatternRangeEndpoint_End, unit, 1,
&end_units_moved);
succeeded_move = SUCCEEDED(hr) && end_units_moved == 1;
}
}
if (!succeeded_move) {
start_ = std::move(start_backup);
end_ = std::move(end_backup);
start_units_moved = 0;
if (!SUCCEEDED(hr))
return hr;
}
*units_moved = start_units_moved;
return S_OK;
} }
STDMETHODIMP AXPlatformNodeTextRangeProviderWin::MoveEndpointByUnit( STDMETHODIMP AXPlatformNodeTextRangeProviderWin::MoveEndpointByUnit(
......
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