diff --git a/accessible/generic/HyperTextAccessible.cpp b/accessible/generic/HyperTextAccessible.cpp index b4d708720131..ce0f57136070 100644 --- a/accessible/generic/HyperTextAccessible.cpp +++ b/accessible/generic/HyperTextAccessible.cpp @@ -1818,8 +1818,16 @@ LayoutDeviceIntRect HyperTextAccessible::GetCaretRect(nsIWidget** aWidget) { // the character. This is important for font size transitions, and is // necessary because the Gecko caret uses the previous character's size as // the user moves forward in the text by character. + int32_t caretOffset = CaretOffset(); + if (NS_WARN_IF(caretOffset == -1)) { + // The caret offset will be -1 if this Accessible isn't focused. Note that + // the DOM node contaning the caret might be focused, but the Accessible + // might not be; e.g. due to an autocomplete popup suggestion having a11y + // focus. + return LayoutDeviceIntRect(); + } nsIntRect charRect = CharBounds( - CaretOffset(), nsIAccessibleCoordinateType::COORDTYPE_SCREEN_RELATIVE); + caretOffset, nsIAccessibleCoordinateType::COORDTYPE_SCREEN_RELATIVE); if (!charRect.IsEmpty()) { caretRect.SetTopEdge(charRect.Y()); } diff --git a/accessible/tests/mochitest/events/a11y.ini b/accessible/tests/mochitest/events/a11y.ini index 746b4cc1725e..74b75785492a 100644 --- a/accessible/tests/mochitest/events/a11y.ini +++ b/accessible/tests/mochitest/events/a11y.ini @@ -23,6 +23,7 @@ support-files = [test_flush.html] [test_focusable_statechange.html] [test_focus_aria_activedescendant.html] +[test_focus_autocomplete.html] [test_focus_autocomplete.xhtml] # Disabled on Linux and Windows due to frequent failures - bug 695019, bug 890795 skip-if = os == 'win' || os == 'linux' diff --git a/accessible/tests/mochitest/events/test_focus_autocomplete.html b/accessible/tests/mochitest/events/test_focus_autocomplete.html new file mode 100644 index 000000000000..7f5dee75102f --- /dev/null +++ b/accessible/tests/mochitest/events/test_focus_autocomplete.html @@ -0,0 +1,83 @@ + + +
+