Bug 1319273 - Accessible: Make TextBounds return rect of whole frame if content is empty. r=surkov
authorSamuel Thibault <samuel.thibault@ens-lyon.org>
Wed, 23 May 2018 17:02:33 +0200
changeset 421039 9ea974e9f568ec4ef151702c35333d850c38ab5d
parent 421038 2426ac9d78fe52b238345e286b000424cbab4989
child 421040 5c47f8a1bad20a61a1ec699cc6508e21f39a7a98
push id103974
push userryanvm@gmail.com
push dateMon, 04 Jun 2018 13:10:43 +0000
treeherdermozilla-inbound@9ea974e9f568 [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,22 @@ 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());
+  }
 
   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) {
+    let inputNode = findAccessibleChildByID(accDoc, id);
+
+    let [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
 );