Make sure to retarget events when they leave native anonymous content. Also

make sure that native anonymous content is marked so (this way clicking on a
url()-created image in :before won't have an <img> node as a target).  Bug
233286, r+sr=bryner, a=dveditz
This commit is contained in:
bzbarsky@mit.edu
2004-02-15 04:45:18 +00:00
parent 337a035d3a
commit 1c0d47da46
4 changed files with 50 additions and 21 deletions

View File

@@ -1831,17 +1831,22 @@ nsGenericElement::HandleDOMEvent(nsIPresContext* aPresContext,
aFlags |= NS_EVENT_FLAG_BUBBLE | NS_EVENT_FLAG_CAPTURE; aFlags |= NS_EVENT_FLAG_BUBBLE | NS_EVENT_FLAG_CAPTURE;
} }
if (GetParent()) { // Find out whether we're anonymous.
// Find out if we're anonymous. if (IsNativeAnonymous()) {
retarget = PR_TRUE;
} else {
nsIContent* parent = GetParent();
if (parent) {
if (*aDOMEvent) { if (*aDOMEvent) {
(*aDOMEvent)->GetTarget(getter_AddRefs(oldTarget)); (*aDOMEvent)->GetTarget(getter_AddRefs(oldTarget));
nsCOMPtr<nsIContent> content(do_QueryInterface(oldTarget)); nsCOMPtr<nsIContent> content(do_QueryInterface(oldTarget));
if (content && content->GetBindingParent() == GetParent()) if (content && content->GetBindingParent() == parent)
retarget = PR_TRUE; retarget = PR_TRUE;
} else if (GetBindingParent() == GetParent()) { } else if (GetBindingParent() == parent) {
retarget = PR_TRUE; retarget = PR_TRUE;
} }
} }
}
// determine the parent: // determine the parent:
nsCOMPtr<nsIContent> parent; nsCOMPtr<nsIContent> parent;

View File

@@ -2785,16 +2785,20 @@ nsXULElement::HandleDOMEvent(nsIPresContext* aPresContext, nsEvent* aEvent,
return NS_OK; // Don't let these events bubble or be captured. Just allow them return NS_OK; // Don't let these events bubble or be captured. Just allow them
// on the target image. // on the target image.
if (GetParent()) { // Find out whether we're anonymous.
// Find out if we're anonymous. if (IsNativeAnonymous()) {
retarget = PR_TRUE;
} else {
nsIContent* parent = GetParent();
if (parent) {
if (*aDOMEvent) { if (*aDOMEvent) {
(*aDOMEvent)->GetTarget(getter_AddRefs(oldTarget)); (*aDOMEvent)->GetTarget(getter_AddRefs(oldTarget));
nsCOMPtr<nsIContent> content(do_QueryInterface(oldTarget)); nsCOMPtr<nsIContent> content(do_QueryInterface(oldTarget));
if (content && content->GetBindingParent() == GetParent()) if (content && content->GetBindingParent() == parent)
retarget = PR_TRUE;
} else if (GetBindingParent() == parent) {
retarget = PR_TRUE; retarget = PR_TRUE;
} }
else if (GetBindingParent() == GetParent()) {
retarget = PR_TRUE;
} }
} }

View File

@@ -1336,8 +1336,6 @@ nsCSSFrameConstructor::CreateGeneratedFrameFor(nsIPresContext* aPresContex
nsINodeInfoManager *nimgr = aDocument->GetNodeInfoManager(); nsINodeInfoManager *nimgr = aDocument->GetNodeInfoManager();
NS_ENSURE_TRUE(nimgr, NS_ERROR_FAILURE); NS_ENSURE_TRUE(nimgr, NS_ERROR_FAILURE);
// XXXldb We should not be creating an |image| element, because it
// matches selectors! See bug 109216.
nsCOMPtr<nsINodeInfo> nodeInfo; nsCOMPtr<nsINodeInfo> nodeInfo;
nimgr->GetNodeInfo(nsHTMLAtoms::img, nsnull, kNameSpaceID_None, nimgr->GetNodeInfo(nsHTMLAtoms::img, nsnull, kNameSpaceID_None,
getter_AddRefs(nodeInfo)); getter_AddRefs(nodeInfo));
@@ -1359,6 +1357,11 @@ nsCSSFrameConstructor::CreateGeneratedFrameFor(nsIPresContext* aPresContex
// way event handling works // way event handling works
content->SetParent(aContent); content->SetParent(aContent);
content->SetDocument(aDocument, PR_TRUE, PR_TRUE); content->SetDocument(aDocument, PR_TRUE, PR_TRUE);
content->SetNativeAnonymous(PR_TRUE);
// hack to make document rules not match (not like it matters, since we
// already have a non-element style context... which is totally wacky, but
// anyway).
content->SetBindingParent(content);
// Create an image frame and initialize it // Create an image frame and initialize it
nsIFrame* imageFrame = nsnull; nsIFrame* imageFrame = nsnull;
@@ -1419,6 +1422,8 @@ nsCSSFrameConstructor::CreateGeneratedFrameFor(nsIPresContext* aPresContex
// object. This way event handling works // object. This way event handling works
content->SetParent(aContent); content->SetParent(aContent);
content->SetDocument(aDocument, PR_TRUE, PR_TRUE); content->SetDocument(aDocument, PR_TRUE, PR_TRUE);
content->SetNativeAnonymous(PR_TRUE);
content->SetBindingParent(content);
// Create a text frame and initialize it // Create a text frame and initialize it
NS_NewTextFrame(shell, &textFrame); NS_NewTextFrame(shell, &textFrame);
@@ -1486,6 +1491,8 @@ nsCSSFrameConstructor::CreateGeneratedFrameFor(nsIPresContext* aPresContex
// way event handling works // way event handling works
textContent->SetParent(aContent); textContent->SetParent(aContent);
textContent->SetDocument(aDocument, PR_TRUE, PR_TRUE); textContent->SetDocument(aDocument, PR_TRUE, PR_TRUE);
textContent->SetNativeAnonymous(PR_TRUE);
textContent->SetBindingParent(textContent);
// Create a text frame and initialize it // Create a text frame and initialize it
NS_NewTextFrame(shell, &textFrame); NS_NewTextFrame(shell, &textFrame);
@@ -3554,6 +3561,9 @@ nsCSSFrameConstructor::ConstructRootFrame(nsIPresShell* aPresShell,
NS_NewViewportFrame(aPresShell, &viewportFrame); NS_NewViewportFrame(aPresShell, &viewportFrame);
// XXXbz do we _have_ to pass a null content pointer to that frame?
// Would it really kill us to pass in the root element or something?
// What would that break?
viewportFrame->Init(aPresContext, nsnull, nsnull, viewportPseudoStyle, nsnull); viewportFrame->Init(aPresContext, nsnull, nsnull, viewportPseudoStyle, nsnull);
// Bind the viewport frame to the root view // Bind the viewport frame to the root view

View File

@@ -1336,8 +1336,6 @@ nsCSSFrameConstructor::CreateGeneratedFrameFor(nsIPresContext* aPresContex
nsINodeInfoManager *nimgr = aDocument->GetNodeInfoManager(); nsINodeInfoManager *nimgr = aDocument->GetNodeInfoManager();
NS_ENSURE_TRUE(nimgr, NS_ERROR_FAILURE); NS_ENSURE_TRUE(nimgr, NS_ERROR_FAILURE);
// XXXldb We should not be creating an |image| element, because it
// matches selectors! See bug 109216.
nsCOMPtr<nsINodeInfo> nodeInfo; nsCOMPtr<nsINodeInfo> nodeInfo;
nimgr->GetNodeInfo(nsHTMLAtoms::img, nsnull, kNameSpaceID_None, nimgr->GetNodeInfo(nsHTMLAtoms::img, nsnull, kNameSpaceID_None,
getter_AddRefs(nodeInfo)); getter_AddRefs(nodeInfo));
@@ -1359,6 +1357,11 @@ nsCSSFrameConstructor::CreateGeneratedFrameFor(nsIPresContext* aPresContex
// way event handling works // way event handling works
content->SetParent(aContent); content->SetParent(aContent);
content->SetDocument(aDocument, PR_TRUE, PR_TRUE); content->SetDocument(aDocument, PR_TRUE, PR_TRUE);
content->SetNativeAnonymous(PR_TRUE);
// hack to make document rules not match (not like it matters, since we
// already have a non-element style context... which is totally wacky, but
// anyway).
content->SetBindingParent(content);
// Create an image frame and initialize it // Create an image frame and initialize it
nsIFrame* imageFrame = nsnull; nsIFrame* imageFrame = nsnull;
@@ -1419,6 +1422,8 @@ nsCSSFrameConstructor::CreateGeneratedFrameFor(nsIPresContext* aPresContex
// object. This way event handling works // object. This way event handling works
content->SetParent(aContent); content->SetParent(aContent);
content->SetDocument(aDocument, PR_TRUE, PR_TRUE); content->SetDocument(aDocument, PR_TRUE, PR_TRUE);
content->SetNativeAnonymous(PR_TRUE);
content->SetBindingParent(content);
// Create a text frame and initialize it // Create a text frame and initialize it
NS_NewTextFrame(shell, &textFrame); NS_NewTextFrame(shell, &textFrame);
@@ -1486,6 +1491,8 @@ nsCSSFrameConstructor::CreateGeneratedFrameFor(nsIPresContext* aPresContex
// way event handling works // way event handling works
textContent->SetParent(aContent); textContent->SetParent(aContent);
textContent->SetDocument(aDocument, PR_TRUE, PR_TRUE); textContent->SetDocument(aDocument, PR_TRUE, PR_TRUE);
textContent->SetNativeAnonymous(PR_TRUE);
textContent->SetBindingParent(textContent);
// Create a text frame and initialize it // Create a text frame and initialize it
NS_NewTextFrame(shell, &textFrame); NS_NewTextFrame(shell, &textFrame);
@@ -3554,6 +3561,9 @@ nsCSSFrameConstructor::ConstructRootFrame(nsIPresShell* aPresShell,
NS_NewViewportFrame(aPresShell, &viewportFrame); NS_NewViewportFrame(aPresShell, &viewportFrame);
// XXXbz do we _have_ to pass a null content pointer to that frame?
// Would it really kill us to pass in the root element or something?
// What would that break?
viewportFrame->Init(aPresContext, nsnull, nsnull, viewportPseudoStyle, nsnull); viewportFrame->Init(aPresContext, nsnull, nsnull, viewportPseudoStyle, nsnull);
// Bind the viewport frame to the root view // Bind the viewport frame to the root view