@@ -105,6 +105,16 @@ enum class AXEmbeddedObjectBehavior {
105
105
// overridden for testing.
106
106
AX_EXPORT extern AXEmbeddedObjectBehavior g_ax_embedded_object_behavior;
107
107
108
+ class AX_EXPORT ScopedAXEmbeddedObjectBehaviorSetter {
109
+ public:
110
+ explicit ScopedAXEmbeddedObjectBehaviorSetter (
111
+ AXEmbeddedObjectBehavior behavior);
112
+ ~ScopedAXEmbeddedObjectBehaviorSetter ();
113
+
114
+ private:
115
+ AXEmbeddedObjectBehavior prev_behavior_;
116
+ };
117
+
108
118
// Forward declarations.
109
119
template <class AXPositionType , class AXNodeType >
110
120
class AXPosition ;
@@ -324,8 +334,9 @@ class AXPosition {
324
334
BASE_DCHECK (GetAnchor ());
325
335
// If this position is anchored to an ignored node, then consider this
326
336
// position to be ignored.
327
- if (GetAnchor ()->IsIgnored ())
337
+ if (GetAnchor ()->IsIgnored ()) {
328
338
return true ;
339
+ }
329
340
330
341
switch (kind_) {
331
342
case AXPositionKind::NULL_POSITION:
@@ -372,8 +383,9 @@ class AXPosition {
372
383
// If the corresponding leaf position is ignored, the current text
373
384
// offset will point to ignored text. Therefore, consider this position
374
385
// to be ignored.
375
- if (!IsLeaf ())
386
+ if (!IsLeaf ()) {
376
387
return AsLeafTreePosition ()->IsIgnored ();
388
+ }
377
389
return false ;
378
390
}
379
391
}
@@ -417,8 +429,9 @@ class AXPosition {
417
429
(child_index_ >= 0 && child_index_ <= AnchorChildCount ())) &&
418
430
!IsInDescendantOfEmptyObject ();
419
431
case AXPositionKind::TEXT_POSITION:
420
- if (!GetAnchor () || IsInDescendantOfEmptyObject ())
432
+ if (!GetAnchor () || IsInDescendantOfEmptyObject ()) {
421
433
return false ;
434
+ }
422
435
423
436
// For performance reasons we skip any validation of the text offset
424
437
// that involves retrieving the anchor's text, if the offset is set to
@@ -1029,8 +1042,9 @@ class AXPosition {
1029
1042
const AXNodeType* ancestor_anchor,
1030
1043
ax::mojom::MoveDirection move_direction =
1031
1044
ax::mojom::MoveDirection::kForward ) const {
1032
- if (!ancestor_anchor)
1045
+ if (!ancestor_anchor) {
1033
1046
return CreateNullPosition ();
1047
+ }
1034
1048
1035
1049
AXPositionInstance ancestor_position = Clone ();
1036
1050
while (!ancestor_position->IsNullPosition () &&
@@ -1285,8 +1299,9 @@ class AXPosition {
1285
1299
}
1286
1300
1287
1301
AXPositionInstance AsLeafTextPosition () const {
1288
- if (IsNullPosition () || IsLeaf ())
1302
+ if (IsNullPosition () || IsLeaf ()) {
1289
1303
return AsTextPosition ();
1304
+ }
1290
1305
1291
1306
// Adjust the text offset.
1292
1307
// No need to check for "before text" positions here because they are only
@@ -1316,7 +1331,7 @@ class AXPosition {
1316
1331
child_position->affinity_ = ax::mojom::TextAffinity::kUpstream ;
1317
1332
break ;
1318
1333
}
1319
- child_position = text_position->CreateChildPositionAt (i);
1334
+ child_position = std::move ( text_position->CreateChildPositionAt (i) );
1320
1335
adjusted_offset -= max_text_offset_in_parent;
1321
1336
}
1322
1337
@@ -1902,7 +1917,7 @@ class AXPosition {
1902
1917
// the same as the one that would have been computed if the original
1903
1918
// position were at the start of the inline text box for "Line two".
1904
1919
const int max_text_offset = MaxTextOffset ();
1905
- const int max_text_offset_in_parent =
1920
+ int max_text_offset_in_parent =
1906
1921
IsEmbeddedObjectInParent () ? 1 : max_text_offset;
1907
1922
int parent_offset = AnchorTextOffsetInParent ();
1908
1923
ax::mojom::TextAffinity parent_affinity = affinity_;
@@ -1935,6 +1950,14 @@ class AXPosition {
1935
1950
parent_affinity = ax::mojom::TextAffinity::kDownstream ;
1936
1951
}
1937
1952
1953
+ // This dummy position serves to retrieve the max text offset of the
1954
+ // anchor-node in which we want to create the parent position.
1955
+ AXPositionInstance dummy_position =
1956
+ CreateTextPosition (tree_id, parent_id, 0 , parent_affinity);
1957
+ max_text_offset_in_parent = dummy_position->MaxTextOffset ();
1958
+ if (parent_offset > max_text_offset_in_parent) {
1959
+ parent_offset = max_text_offset_in_parent;
1960
+ }
1938
1961
AXPositionInstance parent_position = CreateTextPosition (
1939
1962
tree_id, parent_id, parent_offset, parent_affinity);
1940
1963
@@ -2061,6 +2084,7 @@ class AXPosition {
2061
2084
BASE_DCHECK (text_position->text_offset_ >= 0 );
2062
2085
return text_position;
2063
2086
}
2087
+
2064
2088
text_position = text_position->CreateNextLeafTextPosition ();
2065
2089
while (!text_position->IsNullPosition () &&
2066
2090
(text_position->IsIgnored () || !text_position->MaxTextOffset ())) {
0 commit comments