Update the caret after creating a new frame, if the node has focus. b=536421 r=ehsan a=blocking2.0:final
authorMats Palmgren <matspal@gmail.com>
Mon, 11 Oct 2010 00:07:01 +0200
changeset 55284 e841ade1b0c599dc2ae16677155ef1824d025c85
parent 55283 de4ba0fc5a78ae37e675e2b7f8905a655e2f551b
child 55285 cc8777e97c21429992238c28f5b059a56b3cb745
push idunknown
push userunknown
push dateunknown
reviewersehsan, blocking2
bugs536421
milestone2.0b8pre
Update the caret after creating a new frame, if the node has focus. b=536421 r=ehsan a=blocking2.0:final
editor/libeditor/base/nsEditor.cpp
layout/reftests/editor/input-text-notheme-onfocus-reframe-ref.html
layout/reftests/editor/input-text-notheme-onfocus-reframe.html
layout/reftests/editor/input-text-onfocus-reframe-ref.html
layout/reftests/editor/input-text-onfocus-reframe.html
layout/reftests/editor/reftest.list
--- a/editor/libeditor/base/nsEditor.cpp
+++ b/editor/libeditor/base/nsEditor.cpp
@@ -306,29 +306,34 @@ nsEditor::PostCreate()
   // nuke the modification count, so the doc appears unmodified
   // do this before we notify listeners
   ResetModificationCount();
   
   // update the UI with our state
   NotifyDocumentListeners(eDocumentCreated);
   NotifyDocumentListeners(eDocumentStateChanged);
   
-  // update nsTextStateManager if we have focus
+  // update nsTextStateManager and caret if we have focus
   if (HasFocus()) {
     nsFocusManager* fm = nsFocusManager::GetFocusManager();
     NS_ASSERTION(fm, "no focus manager?");
 
     nsCOMPtr<nsIContent> focusedContent = fm->GetFocusedContent();
     if (focusedContent) {
       nsCOMPtr<nsIPresShell> ps = do_QueryReferent(mPresShellWeak);
       NS_ASSERTION(ps, "no pres shell even though we have focus");
       nsPresContext* pc = ps->GetPresContext(); 
 
       nsIMEStateManager::OnTextStateBlur(pc, nsnull);
       nsIMEStateManager::OnTextStateFocus(pc, focusedContent);
+
+      nsCOMPtr<nsIDOMEventTarget> target = do_QueryInterface(focusedContent);
+      if (target) {
+        InitializeSelection(target);
+      }
     }
   }
   return NS_OK;
 }
 
 nsresult
 nsEditor::CreateEventListeners()
 {
new file mode 100644
--- /dev/null
+++ b/layout/reftests/editor/input-text-notheme-onfocus-reframe-ref.html
@@ -0,0 +1,28 @@
+<!DOCTYPE HTML>
+<html class="reftest-wait">
+<head>
+	<title>bug 536421</title>
+	<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
+<style>
+input { border:1px solid blue; }
+</style>
+</head>
+<body onload="doTest()">
+  <input value="test" id="textbox" onfocus="triggerBug();" type="text">
+  <script type="text/javascript">
+    function finishTest()
+    {
+      document.documentElement.removeAttribute("class");
+    }
+    function triggerBug()
+    {
+      finishTest();
+    }
+    function doTest()
+    {
+      var t = document.getElementById("textbox");
+      t.focus();
+    }
+  </script>
+</body>
+</html>
new file mode 100644
--- /dev/null
+++ b/layout/reftests/editor/input-text-notheme-onfocus-reframe.html
@@ -0,0 +1,32 @@
+<!DOCTYPE HTML>
+<html class="reftest-wait">
+<head>
+	<title>bug 536421</title>
+	<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
+<style>
+input { border:1px solid blue; }
+</style>
+</head>
+<body onload="doTest()">
+  <input value="test" id="textbox" onfocus="triggerBug();" type="text">
+  <script type="text/javascript">
+    function finishTest()
+    {
+      document.documentElement.removeAttribute("class");
+    }
+    function triggerBug()
+    {
+      var t = document.getElementById("textbox");
+      t.style.display = "none";
+      document.body.offsetWidth;
+      t.style.display = "";
+      finishTest();
+    }
+    function doTest()
+    {
+      var t = document.getElementById("textbox");
+      t.focus();
+    }
+  </script>
+</body>
+</html>
new file mode 100644
--- /dev/null
+++ b/layout/reftests/editor/input-text-onfocus-reframe-ref.html
@@ -0,0 +1,25 @@
+<!DOCTYPE HTML>
+<html class="reftest-wait">
+<head>
+	<title>bug 536421</title>
+	<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
+</head>
+<body onload="doTest()">
+  <input value="test" id="textbox" onfocus="triggerBug();" type="text">
+  <script type="text/javascript">
+    function finishTest()
+    {
+      document.documentElement.removeAttribute("class");
+    }
+    function triggerBug()
+    {
+      finishTest();
+    }
+    function doTest()
+    {
+      var t = document.getElementById("textbox");
+      t.focus();
+    }
+  </script>
+</body>
+</html>
new file mode 100644
--- /dev/null
+++ b/layout/reftests/editor/input-text-onfocus-reframe.html
@@ -0,0 +1,29 @@
+<!DOCTYPE HTML>
+<html class="reftest-wait">
+<head>
+	<title>bug 536421</title>
+	<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
+</head>
+<body onload="doTest()">
+  <input value="test" id="textbox" onfocus="triggerBug();" type="text">
+  <script type="text/javascript">
+    function finishTest()
+    {
+      document.documentElement.removeAttribute("class");
+    }
+    function triggerBug()
+    {
+      var t = document.getElementById("textbox");
+      t.style.display = "none";
+      document.body.offsetWidth;
+      t.style.display = "";
+      finishTest();
+    }
+    function doTest()
+    {
+      var t = document.getElementById("textbox");
+      t.focus();
+    }
+  </script>
+</body>
+</html>
--- a/layout/reftests/editor/reftest.list
+++ b/layout/reftests/editor/reftest.list
@@ -14,8 +14,10 @@ include xul/reftest.list
 != passwd-2.html passwd-ref.html
 == passwd-3.html passwd-ref.html
 == passwd-4.html passwd-ref.html
 == emptypasswd-1.html emptypasswd-ref.html
 == emptypasswd-2.html emptypasswd-ref.html
 == caret_on_positioned.html caret_on_positioned-ref.html
 == spellcheck-1.html spellcheck-ref.html
 != caret_on_textarea_lastline.html caret_on_textarea_lastline-ref.html
+== input-text-onfocus-reframe.html input-text-onfocus-reframe-ref.html
+== input-text-notheme-onfocus-reframe.html input-text-notheme-onfocus-reframe-ref.html