Bug 183646 ::-moz-selection does not work in form controls (input[type=text], input[type=password], textarea) r=dbaron
authorMasayuki Nakano <masayuki@d-toybox.com>
Wed, 07 Apr 2010 11:10:54 +0900
changeset 40526 8e6ef255d9d6a9cf369af9a8aa60a2378441cb30
parent 40525 2c04659a51ce9e8fb93cf52dd7eca1fa373d2530
child 40527 9996ac775114cd3dcef81c9095772f5cf0132c16
push idunknown
push userunknown
push dateunknown
reviewersdbaron
bugs183646
milestone1.9.3a4pre
Bug 183646 ::-moz-selection does not work in form controls (input[type=text], input[type=password], textarea) r=dbaron
layout/generic/nsTextFrameThebes.cpp
layout/reftests/selection/pseudo-element-of-native-anonymous-ref.html
layout/reftests/selection/pseudo-element-of-native-anonymous.html
layout/reftests/selection/reftest.list
--- a/layout/generic/nsTextFrameThebes.cpp
+++ b/layout/generic/nsTextFrameThebes.cpp
@@ -3123,22 +3123,27 @@ nsTextPaintStyle::InitCommonColors()
                                            selectionBGColor)),
                   NS_LUMINOSITY_DIFFERENCE(defaultWindowBackgroundColor,
                                            selectionBGColor));
 
   mInitCommonColors = PR_TRUE;
 }
 
 static nsIContent*
-FindElementAncestor(nsINode* aNode)
-{
-  while (aNode && !aNode->IsNodeOfType(nsINode::eELEMENT)) {
-    aNode = aNode->GetParent();
-  }
-  return static_cast<nsIContent*>(aNode);
+FindElementAncestorForMozSelection(nsIContent* aContent)
+{
+  NS_ENSURE_TRUE(aContent, nsnull);
+  while (aContent && aContent->IsInNativeAnonymousSubtree()) {
+    aContent = aContent->GetBindingParent();
+  }
+  NS_ASSERTION(aContent, "aContent isn't in non-anonymous tree?");
+  while (aContent && !aContent->IsNodeOfType(nsINode::eELEMENT)) {
+    aContent = aContent->GetParent();
+  }
+  return aContent;
 }
 
 PRBool
 nsTextPaintStyle::InitSelectionColors()
 {
   if (mInitSelectionColors)
     return PR_TRUE;
 
@@ -3150,17 +3155,18 @@ nsTextPaintStyle::InitSelectionColors()
     // We're not caching this fact, so every call to GetSelectionColors
     // will come through here. We could avoid this, but it's not really worth it.
     return PR_FALSE;
   }
 
   mInitSelectionColors = PR_TRUE;
 
   nsIFrame* nonGeneratedAncestor = nsLayoutUtils::GetNonGeneratedAncestor(mFrame);
-  nsIContent* selectionContent = FindElementAncestor(nonGeneratedAncestor->GetContent());
+  nsIContent* selectionContent =
+    FindElementAncestorForMozSelection(nonGeneratedAncestor->GetContent());
 
   if (selectionContent &&
       selectionStatus == nsISelectionController::SELECTION_ON) {
     nsRefPtr<nsStyleContext> sc = nsnull;
     sc = mPresContext->StyleSet()->
       ProbePseudoElementStyle(selectionContent,
                               nsCSSPseudoElements::ePseudo_mozSelection,
                               mFrame->GetStyleContext());
new file mode 100644
--- /dev/null
+++ b/layout/reftests/selection/pseudo-element-of-native-anonymous-ref.html
@@ -0,0 +1,13 @@
+<html>
+<head>
+<style type="text/css">
+input {
+  color: white;
+  background-color: green;
+}
+</style>
+</head>
+<body onload="document.getElementById('i').select();">
+<input value="text" id="i">
+</body>
+</html>
\ No newline at end of file
new file mode 100644
--- /dev/null
+++ b/layout/reftests/selection/pseudo-element-of-native-anonymous.html
@@ -0,0 +1,17 @@
+<html>
+<head>
+<style type="text/css">
+input {
+  color: white;
+  background-color: green;
+}
+input::-moz-selection {
+  color: red;
+  background-color: blue;
+}
+</style>
+</head>
+<body onload="document.getElementById('i').select();">
+<input value="text" id="i">
+</body>
+</html>
\ No newline at end of file
--- a/layout/reftests/selection/reftest.list
+++ b/layout/reftests/selection/reftest.list
@@ -19,8 +19,9 @@
 == extend-3d.html extend-3-ref.html
 == extend-3e.html extend-3-ref.html
 == extend-3f.html extend-3-ref.html
 == extend-3g.html extend-3-ref.html
 == extend-3h.html extend-3-ref.html
 == extend-3i.html extend-3-ref.html
 == extend-4a.html extend-4-ref.html
 == extend-4b.html extend-4-ref.html
+!= pseudo-element-of-native-anonymous.html pseudo-element-of-native-anonymous-ref.html