13#define UIA_VALIDATE_TEXTPROVIDER_CALL() \
14 if (!owner()->GetDelegate()) \
15 return UIA_E_ELEMENTNOTAVAILABLE;
16#define UIA_VALIDATE_TEXTPROVIDER_CALL_1_ARG(arg) \
17 if (!owner()->GetDelegate()) \
18 return UIA_E_ELEMENTNOTAVAILABLE; \
24AXPlatformNodeTextProviderWin::AXPlatformNodeTextProviderWin() {}
26AXPlatformNodeTextProviderWin::~AXPlatformNodeTextProviderWin() {}
30 AXPlatformNodeWin* owner) {
31 CComObject<AXPlatformNodeTextProviderWin>* text_provider =
nullptr;
32 if (
SUCCEEDED(CComObject<AXPlatformNodeTextProviderWin>::CreateInstance(
35 text_provider->owner_ = owner;
36 text_provider->AddRef();
44void AXPlatformNodeTextProviderWin::CreateIUnknown(AXPlatformNodeWin* owner,
46 Microsoft::WRL::ComPtr<AXPlatformNodeTextProviderWin> text_provider(
49 *unknown = text_provider.Detach();
56HRESULT AXPlatformNodeTextProviderWin::GetSelection(SAFEARRAY** selection) {
61 AXPlatformNodeDelegate* delegate = owner()->GetDelegate();
62 AXTree::Selection unignored_selection = delegate->GetUnignoredSelection();
64 AXPlatformNode* anchor_object =
65 delegate->GetFromNodeID(unignored_selection.anchor_object_id);
66 AXPlatformNode* focus_object =
67 delegate->GetFromNodeID(unignored_selection.focus_object_id);
71 auto start_offset = unignored_selection.anchor_offset;
72 auto end_offset = unignored_selection.focus_offset;
75 if (!anchor_object || !focus_object)
79 anchor_object->GetDelegate()->CreateTextPositionAt(start_offset);
81 focus_object->GetDelegate()->CreateTextPositionAt(end_offset);
90 Microsoft::WRL::ComPtr<ITextRangeProvider> text_range_provider =
91 AXPlatformNodeTextRangeProviderWin::CreateTextRangeProvider(
93 if (&text_range_provider ==
nullptr)
99 SafeArrayCreateVector(VT_UNKNOWN , 0 ,
102 if (!selections_to_return.
Get())
103 return E_OUTOFMEMORY;
106 HRESULT hr = SafeArrayPutElement(selections_to_return.
Get(), &index,
107 text_range_provider.Get());
115 *selection = selections_to_return.
Release();
120HRESULT AXPlatformNodeTextProviderWin::GetVisibleRanges(
121 SAFEARRAY** visible_ranges) {
124 const AXPlatformNodeDelegate* delegate = owner()->GetDelegate();
129 const gfx::Rect frame_rect = delegate->GetBoundsRect(
132 const auto start = delegate->CreateTextPositionAt(0);
133 const auto end =
start->CreatePositionAtEndOfAnchor();
138 std::vector<Microsoft::WRL::ComPtr<ITextRangeProvider>> ranges;
140 auto current_line_start =
start->Clone();
141 while (!current_line_start->IsNullPosition() && *current_line_start < *
end) {
142 auto current_line_end = current_line_start->CreateNextLineEndPosition(
144 if (current_line_end->IsNullPosition() || *current_line_end > *
end)
145 current_line_end =
end->Clone();
147 gfx::Rect current_rect = delegate->GetInnerTextRangeBoundsRect(
148 current_line_start->text_offset(), current_line_end->text_offset(),
151 if (frame_rect.
Contains(current_rect)) {
152 Microsoft::WRL::ComPtr<ITextRangeProvider> text_range_provider =
153 AXPlatformNodeTextRangeProviderWin::CreateTextRangeProvider(
154 current_line_start->Clone(), current_line_end->Clone());
156 ranges.emplace_back(text_range_provider);
159 current_line_start = current_line_start->CreateNextLineStartPosition(
164 SafeArrayCreateVector(VT_UNKNOWN , 0 ,
167 if (!scoped_visible_ranges.
Get())
168 return E_OUTOFMEMORY;
171 for (Microsoft::WRL::ComPtr<ITextRangeProvider>& current_provider : ranges) {
172 HRESULT hr = SafeArrayPutElement(scoped_visible_ranges.
Get(), &index,
173 current_provider.Get());
184 *visible_ranges = scoped_visible_ranges.
Release();
189HRESULT AXPlatformNodeTextProviderWin::RangeFromChild(
190 IRawElementProviderSimple* child,
191 ITextRangeProvider** range) {
196 Microsoft::WRL::ComPtr<ui::AXPlatformNodeWin> child_platform_node;
197 if (!
SUCCEEDED(child->QueryInterface(IID_PPV_ARGS(&child_platform_node))))
198 return UIA_E_INVALIDOPERATION;
200 if (!owner()->IsDescendant(child_platform_node.Get()))
203 *range = GetRangeFromChild(owner(), child_platform_node.Get());
208HRESULT AXPlatformNodeTextProviderWin::RangeFromPoint(
210 ITextRangeProvider** range) {
218 AXPlatformNodeWin* nearest_node =
219 static_cast<AXPlatformNodeWin*
>(owner()->NearestLeafToPoint(point));
224 start = nearest_node->GetDelegate()->CreateTextPositionAt(
225 nearest_node->NearestTextIndexToPoint(point));
229 *range = AXPlatformNodeTextRangeProviderWin::CreateTextRangeProvider(
234HRESULT AXPlatformNodeTextProviderWin::get_DocumentRange(
235 ITextRangeProvider** range) {
240 *range = GetRangeFromChild(owner(), owner());
245HRESULT AXPlatformNodeTextProviderWin::get_SupportedTextSelection(
246 enum SupportedTextSelection* text_selection) {
249 *text_selection = SupportedTextSelection_Single;
257HRESULT AXPlatformNodeTextProviderWin::GetActiveComposition(
258 ITextRangeProvider** range) {
262 return GetTextRangeProviderFromActiveComposition(range);
265HRESULT AXPlatformNodeTextProviderWin::GetConversionTarget(
266 ITextRangeProvider** range) {
270 return GetTextRangeProviderFromActiveComposition(range);
273ITextRangeProvider* AXPlatformNodeTextProviderWin::GetRangeFromChild(
274 ui::AXPlatformNodeWin* ancestor,
275 ui::AXPlatformNodeWin* descendant) {
285 descendant->GetDelegate()->CreateTextPositionAt(0)->AsLeafTextPosition();
288 if (descendant->GetChildCount() == 0) {
289 end = descendant->GetDelegate()
290 ->CreateTextPositionAt(0)
291 ->CreatePositionAtEndOfAnchor()
292 ->AsLeafTextPosition();
294 AXPlatformNodeBase* deepest_last_child = descendant->GetLastChild();
295 while (deepest_last_child && deepest_last_child->GetChildCount() > 0)
296 deepest_last_child = deepest_last_child->GetLastChild();
298 end = deepest_last_child->GetDelegate()
299 ->CreateTextPositionAt(0)
300 ->CreatePositionAtEndOfAnchor()
301 ->AsLeafTextPosition();
304 return AXPlatformNodeTextRangeProviderWin::CreateTextRangeProvider(
308ITextRangeProvider* AXPlatformNodeTextProviderWin::CreateDegenerateRangeAtStart(
309 ui::AXPlatformNodeWin* node) {
315 start = node->GetDelegate()->CreateTextPositionAt(0)->AsLeafTextPosition();
317 return AXPlatformNodeTextRangeProviderWin::CreateTextRangeProvider(
321ui::AXPlatformNodeWin* AXPlatformNodeTextProviderWin::owner()
const {
326AXPlatformNodeTextProviderWin::GetTextRangeProviderFromActiveComposition(
327 ITextRangeProvider** range) {
335 owner()->GetDelegate()->GetFocus()) ==
336 static_cast<AXPlatformNode*
>(owner())) &&
337 owner()->HasActiveComposition()) {
339 owner()->GetActiveCompositionOffsets();
341 owner()->GetDelegate()->CreateTextPositionAt(
342 active_composition_offset.
start());
344 owner()->GetDelegate()->CreateTextPositionAt(
345 active_composition_offset.
end());
347 *range = AXPlatformNodeTextRangeProviderWin::CreateTextRangeProvider(
static sk_sp< Effect > Create()
void swap(sk_sp< T > &a, sk_sp< T > &b)
#define UIA_VALIDATE_TEXTPROVIDER_CALL()
#define UIA_VALIDATE_TEXTPROVIDER_CALL_1_ARG(arg)
constexpr uint32_t end() const
constexpr uint32_t start() const
bool Contains(int point_x, int point_y) const
std::unique_ptr< AXPosition< AXNodePosition, AXNode > > AXPositionInstance
#define BASE_DCHECK(condition)