Bug 1177014: Modify TransformOffset to correctly report bullet offsets, despite incorrect return from PeekOffset. r=Jamie
authorMorgan Reschenberg <mreschenberg@mozilla.com>
Wed, 25 Sep 2019 02:10:08 +0000
changeset 494998 7aa2279f941cf9c5f5fdf4d786604ac7dca053ea
parent 494997 e79b84e42250763cf51680a7314d614ad0e3006f
child 494999 caa26030e1f2b50fe93ddd3daa190a36f22a5ad4
push id114131
push userdluca@mozilla.com
push dateThu, 26 Sep 2019 09:47:34 +0000
treeherdermozilla-inbound@1dc1a755079a [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersJamie
bugs1177014
milestone71.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1177014: Modify TransformOffset to correctly report bullet offsets, despite incorrect return from PeekOffset. r=Jamie Differential Revision: https://phabricator.services.mozilla.com/D46490
accessible/generic/HyperTextAccessible.cpp
accessible/tests/mochitest/text/test_lineboundary.html
--- a/accessible/generic/HyperTextAccessible.cpp
+++ b/accessible/generic/HyperTextAccessible.cpp
@@ -290,20 +290,31 @@ uint32_t HyperTextAccessible::TransformO
 
     // This offset no longer applies because the passed-in text object is not
     // a child of the hypertext. This happens when there are nested hypertexts,
     // e.g. <div>abc<h1>def</h1>ghi</div>. Thus we need to adjust the offset
     // to make it relative the hypertext.
     // If the end offset is not supposed to be inclusive and the original point
     // is not at 0 offset then the returned offset should be after an embedded
     // character the original point belongs to.
-    if (aIsEndOffset)
-      offset = (offset > 0 || descendant->IndexInParent() > 0) ? 1 : 0;
-    else
+    if (aIsEndOffset) {
+      // Similar to our special casing in FindOffset, we add handling for
+      // bulleted lists here because PeekOffset returns the inner text node
+      // for a list when it should return the list bullet.
+      // We manually set the offset so the error doesn't propagate up.
+      if (offset == 0 && descendant->Parent()->IsHTMLListItem() &&
+          descendant->PrevSibling() && descendant->PrevSibling()->GetFrame() &&
+          descendant->PrevSibling()->GetFrame()->IsBulletFrame()) {
+        offset = 0;
+      } else {
+        offset = (offset > 0 || descendant->IndexInParent() > 0) ? 1 : 0;
+      }
+    } else {
       offset = 0;
+    }
 
     descendant = parent;
   }
 
   // If the given a11y point cannot be mapped into offset relative this
   // hypertext offset then return length as fallback value.
   return CharacterCount();
 }
--- a/accessible/tests/mochitest/text/test_lineboundary.html
+++ b/accessible/tests/mochitest/text/test_lineboundary.html
@@ -159,16 +159,23 @@
                          [ 4, 5, kEmbedChar, 4, 5 ] ]);
 
       // ////////////////////////////////////////////////////////////////////////
       // Nested hypertexts
 
       testTextAtOffset(["ht_5" ], BOUNDARY_LINE_START,
                        [ [ 0, 0, kEmbedChar, 0, 1 ] ]);
 
+      // ////////////////////////////////////////////////////////////////////////
+      // Block followed by list
+
+      testTextAtOffset([ "block_then_ul" ], BOUNDARY_LINE_START,
+                       [ [ 0, 0, kEmbedChar, 0, 1 ],
+                         [ 1, 1, kEmbedChar, 1, 2 ] ]);
+
       SimpleTest.finish();
     }
 
     SimpleTest.waitForExplicitFinish();
     addA11yLoadEvent(doTest);
   </script>
 </head>
 <body>
@@ -253,11 +260,16 @@ two words
       <p>seciofarus</p>
     </div>
   </div>
   <div id="line_test_1">
     Line 1
     <center><input type="TEXT"><input value="Button" type="SUBMIT"></center>
     Line 3
   </div>
+
+  <div id="block_then_ul">
+    <p>Block</p>
+    <ul><li>Li</li></ul>
+  </div>
   </body>
 </body>
 </html>