Bug 1254096 - Update CaretPositionFromPoint() for type=number, r=ehsan
authorMark Capella <markcapella@twcny.rr.com>
Wed, 16 Mar 2016 16:15:17 -0400
changeset 288954 e2d35025431302e2f08b7194d16255512528a777
parent 288953 8de4fc84e7cfec86cbfcb8b71db9cb7715219f9b
child 288955 d2ce28624461deeae84431a1662ba96ad21a53e2
push id18216
push usermarkcapella@twcny.rr.com
push dateWed, 16 Mar 2016 20:15:23 +0000
treeherderfx-team@e2d350254313 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersehsan
bugs1254096
milestone48.0a1
Bug 1254096 - Update CaretPositionFromPoint() for type=number, r=ehsan
dom/base/nsDocument.cpp
dom/base/test/test_caretPositionFromPoint.html
--- a/dom/base/nsDocument.cpp
+++ b/dom/base/nsDocument.cpp
@@ -24,16 +24,17 @@
 #include "mozilla/Logging.h"
 #include "plstr.h"
 #include "mozilla/Snprintf.h"
 
 #include "mozilla/Telemetry.h"
 #include "nsIInterfaceRequestor.h"
 #include "nsIInterfaceRequestorUtils.h"
 #include "nsILoadContext.h"
+#include "nsITextControlFrame.h"
 #include "nsUnicharUtils.h"
 #include "nsContentList.h"
 #include "nsCSSPseudoElements.h"
 #include "nsIObserver.h"
 #include "nsIBaseWindow.h"
 #include "mozilla/css/Loader.h"
 #include "mozilla/css/ImageLoader.h"
 #include "nsDocShell.h"
@@ -10829,20 +10830,18 @@ nsIDocument::CaretPositionFromPoint(floa
   uint32_t offset = offsets.offset;
   nsCOMPtr<nsIContent> anonNode = node;
   bool nodeIsAnonymous = node && node->IsInNativeAnonymousSubtree();
   if (nodeIsAnonymous) {
     node = ptFrame->GetContent();
     nsIContent* nonanon = node->FindFirstNonChromeOnlyAccessContent();
     nsCOMPtr<nsIDOMHTMLInputElement> input = do_QueryInterface(nonanon);
     nsCOMPtr<nsIDOMHTMLTextAreaElement> textArea = do_QueryInterface(nonanon);
-    bool isText;
-    if (textArea || (input &&
-                     NS_SUCCEEDED(input->MozIsTextField(false, &isText)) &&
-                     isText)) {
+    nsITextControlFrame* textFrame = do_QueryFrame(nonanon->GetPrimaryFrame());
+    if (!!textFrame) {
       // If the anonymous content node has a child, then we need to make sure
       // that we get the appropriate child, as otherwise the offset may not be
       // correct when we construct a range for it.
       nsCOMPtr<nsIContent> firstChild = anonNode->GetFirstChild();
       if (firstChild) {
         anonNode = firstChild;
       }
 
--- a/dom/base/test/test_caretPositionFromPoint.html
+++ b/dom/base/test/test_caretPositionFromPoint.html
@@ -90,23 +90,34 @@
     var test5Element = document.getElementById('test5');
     var test5Rect = test5Element.getBoundingClientRect();
     var test5x = test5Rect.left + 5;
     var test5y = test5Rect.bottom - 10;
 
     todo(false, "test5Rect: (" + test5Rect.top + ", " + test5Rect.left + ", " + test5Rect.width + ", " + test5Rect.height + ")");
     checkOffsetsFromPoint(test5x, test5y, 0, 'test5');
 
+    // Check the first and last characters of the numeric input.
+    var test6Element = document.getElementById("test6");
+    var test6Rect = test6Element.getBoundingClientRect();
+    checkOffsetsFromPoint(Math.round(test6Rect.left + 5),
+                          Math.round(test6Rect.top + (test6Rect.height / 2)),
+                          0, "test6");
+    checkOffsetsFromPoint(Math.round(test6Rect.left + test6Rect.width - 30),
+                          Math.round(test6Rect.top + (test6Rect.height / 2)),
+                          5, "test6");
+
     SimpleTest.finish();
   }
 
   SimpleTest.waitForExplicitFinish();
 </script>
 </head>
 <body onload="doTesting();">
 <div id="a" contenteditable><span id="test1">abc, abc, abc</span><br>
 <span id="test2" style="color: blue;">abc, abc, abc</span><br>
 <textarea id="test3">abc</textarea><input id="test4" value="abcdef"><br><br>
 <marquee>marquee</marquee>
 </div>
 <input id="test5" value="The rabbit-hole went straight on like a tunnel for some way, and then dipped suddenly down, so suddenly that Alice had not a moment to think about stopping herself before she found herself falling down a very deep well. Either the well was very deep, or she fell very slowly, for she had plenty of time as she went down to look about her and to wonder what was going to happen next. First, she tried to look down and make out what she was coming to, but it was too dark to see anything; then she looked at the sides of the well, and noticed that they were filled with cupboards and book-shelves; here and there she saw maps and pictures hung upon pegs. She took down a jar from one of the shelves as she passed; it was labelled `ORANGE MARMALADE', but to her great disappointment it was empty: she did not like to drop the jar for fear of killing somebody, so managed to put it into one of the cupboards as she fell past it." type="text">
+<input id="test6" type="number" style="width:150px; height:57px;" value="31415"><br>
 </body>
 </html>