5#ifndef UI_ACCESSIBILITY_PLATFORM_AX_PLATFORM_NODE_TEXTRANGEPROVIDER_WIN_H_
6#define UI_ACCESSIBILITY_PLATFORM_AX_PLATFORM_NODE_TEXTRANGEPROVIDER_WIN_H_
11#include <UIAutomationCore.h>
20class AX_EXPORT __declspec(uuid("3071e40d-a10d-45ff-a59f-6e8e1138e2c1"))
21 AXPlatformNodeTextRangeProviderWin
22 :
public CComObjectRootEx<CComMultiThreadModel>,
23 public ITextRangeProvider {
25 BEGIN_COM_MAP(AXPlatformNodeTextRangeProviderWin)
26 COM_INTERFACE_ENTRY(ITextRangeProvider)
27 COM_INTERFACE_ENTRY(AXPlatformNodeTextRangeProviderWin)
30 AXPlatformNodeTextRangeProviderWin();
31 ~AXPlatformNodeTextRangeProviderWin();
33 static ITextRangeProvider* CreateTextRangeProvider(
34 AXNodePosition::AXPositionInstance start,
35 AXNodePosition::AXPositionInstance end);
39 static ITextRangeProvider* CreateTextRangeProviderForTesting(
40 AXPlatformNodeWin* owner,
41 AXNodePosition::AXPositionInstance start,
42 AXNodePosition::AXPositionInstance end);
48 IFACEMETHODIMP Clone(ITextRangeProvider** clone) override;
51 CompareEndpoints(TextPatternRangeEndpoint this_endpoint,
52 ITextRangeProvider* other,
53 TextPatternRangeEndpoint other_endpoint,
55 IFACEMETHODIMP ExpandToEnclosingUnit(TextUnit unit) override;
57 FindAttribute(TEXTATTRIBUTEID attribute_id,
60 ITextRangeProvider**
result) override;
65 ITextRangeProvider**
result) override;
66 IFACEMETHODIMP GetAttributeValue(TEXTATTRIBUTEID attribute_id,
69 GetBoundingRectangles(SAFEARRAY** screen_physical_pixel_rectangles) override;
71 GetEnclosingElement(IRawElementProviderSimple** element) override;
72 IFACEMETHODIMP GetText(
int max_count, BSTR*
text) override;
73 IFACEMETHODIMP Move(TextUnit unit,
int count,
int* units_moved) override;
75 MoveEndpointByUnit(TextPatternRangeEndpoint endpoint,
78 int* units_moved) override;
80 MoveEndpointByRange(TextPatternRangeEndpoint this_endpoint,
81 ITextRangeProvider* other,
82 TextPatternRangeEndpoint other_endpoint) override;
83 IFACEMETHODIMP Select() override;
84 IFACEMETHODIMP AddToSelection() override;
85 IFACEMETHODIMP RemoveFromSelection() override;
86 IFACEMETHODIMP ScrollIntoView(
BOOL align_to_top) override;
87 IFACEMETHODIMP GetChildren(SAFEARRAY** children) override;
89 AXPlatformNodeWin* GetOwner() const;
90 void SetOwnerForTesting(AXPlatformNodeWin* owner);
93 using AXPositionInstance = AXNodePosition::AXPositionInstance;
94 using AXPositionInstanceType = typename AXPositionInstance::element_type;
95 using AXNodeRange = AXRange<AXPositionInstanceType>;
97 friend class AXPlatformNodeTextRangeProviderTest;
98 friend class AXPlatformNodeTextProviderTest;
99 friend class AXRangePhysicalPixelRectDelegate;
101 static
bool AtStartOfLinePredicate(const AXPositionInstance& position);
102 static
bool AtEndOfLinePredicate(const AXPositionInstance& position);
104 static AXPositionInstance GetNextTextBoundaryPosition(
105 const AXPositionInstance& position,
113 HRESULT MoveEndpointByUnitImpl(TextPatternRangeEndpoint endpoint,
118 IFACEMETHODIMP ExpandToEnclosingUnitImpl(TextUnit unit);
120 std::u16string GetString(
int max_count,
121 size_t* appended_newlines_count =
nullptr);
122 const AXPositionInstance& start()
const {
return endpoints_.GetStart(); }
123 const AXPositionInstance&
end()
const {
return endpoints_.GetEnd(); }
124 AXPlatformNodeDelegate* GetDelegate(
125 const AXPositionInstanceType* position)
const;
126 AXPlatformNodeDelegate* GetDelegate(
const AXTreeID tree_id,
129 template <
typename AnchorIterator,
typename ExpandMatchLambda>
130 HRESULT FindAttributeRange(
const TEXTATTRIBUTEID text_attribute_id,
132 const AnchorIterator first,
133 const AnchorIterator last,
134 ExpandMatchLambda expand_match);
136 AXPositionInstance MoveEndpointByCharacter(
const AXPositionInstance& endpoint,
139 AXPositionInstance MoveEndpointByWord(
const AXPositionInstance& endpoint,
142 AXPositionInstance MoveEndpointByLine(
const AXPositionInstance& endpoint,
143 bool is_start_endpoint,
146 AXPositionInstance MoveEndpointByParagraph(
const AXPositionInstance& endpoint,
147 const bool is_start_endpoint,
150 AXPositionInstance MoveEndpointByPage(
const AXPositionInstance& endpoint,
151 const bool is_start_endpoint,
154 AXPositionInstance MoveEndpointByDocument(
const AXPositionInstance& endpoint,
158 AXPositionInstance MoveEndpointByUnitHelper(
159 const AXPositionInstance& endpoint,
174 void NormalizeTextRange(AXPositionInstance& start, AXPositionInstance& end);
175 static void NormalizeAsUnignoredPosition(AXPositionInstance& position);
176 static void NormalizeAsUnignoredTextRange(AXPositionInstance& start,
177 AXPositionInstance& end);
179 AXPlatformNodeDelegate* GetRootDelegate(
const ui::AXTreeID tree_id);
180 AXNode* GetSelectionCommonAnchor();
181 void RemoveFocusFromPreviousSelectionIfNeeded(
182 const AXNodeRange& new_selection);
183 AXPlatformNodeWin* GetPlatformNodeFromAXNode(
const AXNode* node)
const;
184 AXPlatformNodeWin* GetLowestAccessibleCommonPlatformNode()
const;
185 bool HasTextRangeOrSelectionInAtomicTextField(
186 const AXPositionInstance& start_position,
187 const AXPositionInstance& end_position)
const;
189 void SetStart(AXPositionInstance start);
190 void SetEnd(AXPositionInstance end);
192 static bool TextAttributeIsArrayType(TEXTATTRIBUTEID attribute_id);
193 static bool TextAttributeIsUiaReservedValue(
195 static bool ShouldReleaseTextAttributeAsSafearray(
196 TEXTATTRIBUTEID attribute_id,
199 Microsoft::WRL::ComPtr<AXPlatformNodeWin> owner_for_test_;
250 class TextRangeEndpoints :
public AXTreeObserver {
252 TextRangeEndpoints();
253 ~TextRangeEndpoints()
override;
254 const AXPositionInstance& GetStart()
const {
return start_; }
255 const AXPositionInstance& GetEnd()
const {
return end_; }
256 void SetStart(AXPositionInstance new_start);
257 void SetEnd(AXPositionInstance new_end);
259 void AddObserver(
const AXTreeID tree_id);
260 void RemoveObserver(
const AXTreeID tree_id);
261 void OnSubtreeWillBeDeleted(AXTree* tree, AXNode* node)
override;
262 void OnNodeDeleted(AXTree* tree,
AXNode::AXID node_id)
override;
265 struct DeletionOfInterest {
270 void AdjustEndpointForSubtreeDeletion(AXTree* tree,
271 const AXNode*
const node,
272 bool is_start_endpoint);
274 AXPositionInstance start_;
275 AXPositionInstance end_;
277 std::optional<DeletionOfInterest> validation_necessary_for_start_;
278 std::optional<DeletionOfInterest> validation_necessary_for_end_;
280 TextRangeEndpoints endpoints_;
287 std::u16string_view find_in,
def Compare(symbols1, symbols2)
bool StringSearch(std::u16string_view search_string, std::u16string_view find_in, size_t *find_start, size_t *find_length, bool ignore_case, bool backwards)