@@ -105,6 +105,16 @@ enum class AXEmbeddedObjectBehavior {
105105// overridden for testing.
106106AX_EXPORT extern AXEmbeddedObjectBehavior g_ax_embedded_object_behavior;
107107
108+ class AX_EXPORT ScopedAXEmbeddedObjectBehaviorSetter {
109+ public:
110+ explicit ScopedAXEmbeddedObjectBehaviorSetter (
111+ AXEmbeddedObjectBehavior behavior);
112+ ~ScopedAXEmbeddedObjectBehaviorSetter ();
113+
114+ private:
115+ AXEmbeddedObjectBehavior prev_behavior_;
116+ };
117+
108118// Forward declarations.
109119template <class AXPositionType , class AXNodeType >
110120class AXPosition ;
@@ -324,8 +334,9 @@ class AXPosition {
324334 BASE_DCHECK (GetAnchor ());
325335 // If this position is anchored to an ignored node, then consider this
326336 // position to be ignored.
327- if (GetAnchor ()->IsIgnored ())
337+ if (GetAnchor ()->IsIgnored ()) {
328338 return true ;
339+ }
329340
330341 switch (kind_) {
331342 case AXPositionKind::NULL_POSITION:
@@ -372,8 +383,9 @@ class AXPosition {
372383 // If the corresponding leaf position is ignored, the current text
373384 // offset will point to ignored text. Therefore, consider this position
374385 // to be ignored.
375- if (!IsLeaf ())
386+ if (!IsLeaf ()) {
376387 return AsLeafTreePosition ()->IsIgnored ();
388+ }
377389 return false ;
378390 }
379391 }
@@ -417,8 +429,9 @@ class AXPosition {
417429 (child_index_ >= 0 && child_index_ <= AnchorChildCount ())) &&
418430 !IsInDescendantOfEmptyObject ();
419431 case AXPositionKind::TEXT_POSITION:
420- if (!GetAnchor () || IsInDescendantOfEmptyObject ())
432+ if (!GetAnchor () || IsInDescendantOfEmptyObject ()) {
421433 return false ;
434+ }
422435
423436 // For performance reasons we skip any validation of the text offset
424437 // that involves retrieving the anchor's text, if the offset is set to
@@ -1029,8 +1042,9 @@ class AXPosition {
10291042 const AXNodeType* ancestor_anchor,
10301043 ax::mojom::MoveDirection move_direction =
10311044 ax::mojom::MoveDirection::kForward ) const {
1032- if (!ancestor_anchor)
1045+ if (!ancestor_anchor) {
10331046 return CreateNullPosition ();
1047+ }
10341048
10351049 AXPositionInstance ancestor_position = Clone ();
10361050 while (!ancestor_position->IsNullPosition () &&
@@ -1285,8 +1299,9 @@ class AXPosition {
12851299 }
12861300
12871301 AXPositionInstance AsLeafTextPosition () const {
1288- if (IsNullPosition () || IsLeaf ())
1302+ if (IsNullPosition () || IsLeaf ()) {
12891303 return AsTextPosition ();
1304+ }
12901305
12911306 // Adjust the text offset.
12921307 // No need to check for "before text" positions here because they are only
@@ -1316,7 +1331,7 @@ class AXPosition {
13161331 child_position->affinity_ = ax::mojom::TextAffinity::kUpstream ;
13171332 break ;
13181333 }
1319- child_position = text_position->CreateChildPositionAt (i);
1334+ child_position = std::move ( text_position->CreateChildPositionAt (i) );
13201335 adjusted_offset -= max_text_offset_in_parent;
13211336 }
13221337
@@ -1902,7 +1917,7 @@ class AXPosition {
19021917 // the same as the one that would have been computed if the original
19031918 // position were at the start of the inline text box for "Line two".
19041919 const int max_text_offset = MaxTextOffset ();
1905- const int max_text_offset_in_parent =
1920+ int max_text_offset_in_parent =
19061921 IsEmbeddedObjectInParent () ? 1 : max_text_offset;
19071922 int parent_offset = AnchorTextOffsetInParent ();
19081923 ax::mojom::TextAffinity parent_affinity = affinity_;
@@ -1935,6 +1950,14 @@ class AXPosition {
19351950 parent_affinity = ax::mojom::TextAffinity::kDownstream ;
19361951 }
19371952
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+ }
19381961 AXPositionInstance parent_position = CreateTextPosition (
19391962 tree_id, parent_id, parent_offset, parent_affinity);
19401963
@@ -2061,6 +2084,7 @@ class AXPosition {
20612084 BASE_DCHECK (text_position->text_offset_ >= 0 );
20622085 return text_position;
20632086 }
2087+
20642088 text_position = text_position->CreateNextLeafTextPosition ();
20652089 while (!text_position->IsNullPosition () &&
20662090 (text_position->IsIgnored () || !text_position->MaxTextOffset ())) {
0 commit comments