Bug 1319273 - Accessible: Make TextBounds return rect of whole frame if content is empty. r=surkov
☠☠ backed out by 9c58416b4af6 ☠ ☠
authorSamuel Thibault <samuel.thibault@ens-lyon.org>
Wed, 23 May 2018 17:02:33 +0200
changeset 420903 f585271d250d8750240e8ab4ec8e462e56eac21e
parent 420902 af6951f3fd418e6f363eaca1fb286658c627e57f
child 420904 7fa83e49f708bb49690b0ac86ebb8b12e3766e0c
push id103926
push userryanvm@gmail.com
push dateFri, 01 Jun 2018 19:03:21 +0000
treeherdermozilla-inbound@f585271d250d [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerssurkov
bugs1319273
milestone62.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 1319273 - Accessible: Make TextBounds return rect of whole frame if content is empty. r=surkov
accessible/generic/HyperTextAccessible.cpp
accessible/tests/browser/bounds/browser_test_zoom_text.js
--- a/accessible/generic/HyperTextAccessible.cpp
+++ b/accessible/generic/HyperTextAccessible.cpp
@@ -1236,16 +1236,27 @@ HyperTextAccessible::TextBounds(int32_t 
   index_t startOffset = ConvertMagicOffset(aStartOffset);
   index_t endOffset = ConvertMagicOffset(aEndOffset);
   if (!startOffset.IsValid() || !endOffset.IsValid() ||
       startOffset > endOffset || endOffset > CharacterCount()) {
     NS_ERROR("Wrong in offset");
     return nsIntRect();
   }
 
+  if (CharacterCount() == 0) {
+    nsPresContext* presContext = mDoc->PresContext();
+    // Empty content, use our own bound to at least get x,y coordinates
+    return GetFrame()->GetScreenRectInAppUnits().
+      ToNearestPixels(presContext->AppUnitsPerDevPixel());
+  }
+
+  if (startOffset == endOffset) {
+    NS_ERROR("Wrong in offset");
+    return nsIntRect();
+  }
 
   int32_t childIdx = GetChildIndexAtOffset(startOffset);
   if (childIdx == -1)
     return nsIntRect();
 
   nsIntRect bounds;
   int32_t prevOffset = GetChildOffset(childIdx);
   int32_t offset1 = startOffset - prevOffset;
--- a/accessible/tests/browser/bounds/browser_test_zoom_text.js
+++ b/accessible/tests/browser/bounds/browser_test_zoom_text.js
@@ -14,20 +14,31 @@ async function runTests(browser, accDoc)
     let textNode = hyperTextNode.firstChild;
 
     let contentDPR = await getContentDPR(browser);
     let [x, y, width, height] = getBounds(textNode, contentDPR);
     testTextBounds(hyperTextNode, 0, -1, [x, y, width, height],
                    COORDTYPE_SCREEN_RELATIVE);
   }
 
+  async function testEmptyInputNode(id) {
+    var inputNode = findAccessibleChildByID(accDoc, id);
+
+    var [x, y, width, height] = getBounds(inputNode);
+    testTextBounds(inputNode, 0, -1, [x, y, width, height],
+                   COORDTYPE_SCREEN_RELATIVE);
+    testTextBounds(inputNode, 0, 0, [x, y, width, height],
+                   COORDTYPE_SCREEN_RELATIVE);
+  }
+
   loadFrameScripts(browser, { name: "layout.js", dir: MOCHITESTS_DIR });
 
   await testTextNode("p1");
   await testTextNode("p2");
+  await testEmptyInputNode("i1");
 
   await ContentTask.spawn(browser, {}, () => {
     zoomDocument(document, 2.0);
   });
 
   await testTextNode("p1");
 
   await ContentTask.spawn(browser, {}, () => {
@@ -35,10 +46,11 @@ async function runTests(browser, accDoc)
   });
 }
 
 /**
  * Test the text range boundary when page is zoomed
  */
 addAccessibleTask(`
   <p id='p1' style='font-family: monospace;'>Tilimilitryamdiya</p>
-  <p id='p2'>ل</p>`, runTests
+  <p id='p2'>ل</p>
+  <form><input id='i1' /></form>`, runTests
 );