Backed out changeset 82a21d443b5e

This commit is contained in:
Johnny Stenback 2010-06-21 22:39:53 -07:00
parent 6268e31519
commit b5ac9ee398
14 changed files with 156 additions and 68 deletions

View File

@ -952,6 +952,7 @@ protected:
* @returns PR_TRUE if aId looks correct, PR_FALSE otherwise.
*/
static PRBool CheckGetElementByIdArg(const nsIAtom* aId);
nsIdentifierMapEntry* GetElementByIdInternal(nsIAtom* aID);
void DispatchContentLoadedEvents();

View File

@ -213,10 +213,15 @@ nsReferencedElement::HaveNewDocument(nsIDocument* aDocument, PRBool aWatch,
if (!aDocument) {
return;
}
nsCOMPtr<nsIDOMDocument> domDoc = do_QueryInterface(aDocument);
NS_ASSERTION(domDoc, "Content doesn't reference a dom Document");
Element *e = aDocument->GetElementById(aRef);
if (e) {
mElement = e;
// XXXbz we should really have a sane GetElementById on nsIDocument.
nsCOMPtr<nsIDOMElement> element;
domDoc->GetElementById(aRef, getter_AddRefs(element));
if (element) {
nsCOMPtr<nsIContent> content = do_QueryInterface(element);
mElement = content->AsElement();
}
}

View File

@ -47,7 +47,6 @@
#include "nsIDOMEventListener.h"
#include "nsINameSpaceManager.h"
#include "nsINodeInfo.h"
#include "mozilla/dom/Element.h"
PRBool nsXMLEventsListener::InitXMLEventsListener(nsIDocument * aDocument,
nsXMLEventsManager * aManager,
@ -68,7 +67,7 @@ PRBool nsXMLEventsListener::InitXMLEventsListener(nsIDocument * aDocument,
return PR_FALSE;
nsAutoString handlerURIStr;
PRBool hasHandlerURI = PR_FALSE;
nsIContent *handler = nsnull;
nsCOMPtr<nsIContent> handler;
nsAutoString observerID;
nsAutoString targetIdref;
@ -88,8 +87,13 @@ PRBool nsXMLEventsListener::InitXMLEventsListener(nsIDocument * aDocument,
//We support only XML Events Basic.
docURI->Equals(handlerURL, &equals);
if (equals) {
handler =
aDocument->GetElementById(NS_ConvertUTF8toUTF16(handlerRef));
nsCOMPtr<nsIDOMDocument> doc(do_QueryInterface(aDocument));
if (doc) {
nsCOMPtr<nsIDOMElement> domhandler;
doc->GetElementById(NS_ConvertUTF8toUTF16(handlerRef),
getter_AddRefs(domhandler));
handler = do_QueryInterface(domhandler);
}
}
}
}
@ -116,7 +120,7 @@ PRBool nsXMLEventsListener::InitXMLEventsListener(nsIDocument * aDocument,
aContent->AttrValueIs(nameSpaceID, nsGkAtoms::defaultAction,
nsGkAtoms::cancel, eCaseMatters);
nsIContent *observer;
nsCOMPtr<nsIContent> observer;
if (!hasObserver) {
if (!hasHandlerURI) //Parent should be the observer
observer = aContent->GetParent();
@ -124,9 +128,16 @@ PRBool nsXMLEventsListener::InitXMLEventsListener(nsIDocument * aDocument,
observer = aContent;
}
else if (!observerID.IsEmpty()) {
observer = aDocument->GetElementById(observerID);
nsCOMPtr<nsIDOMDocument> doc(do_QueryInterface(aDocument));
if (doc) {
nsCOMPtr<nsIDOMElement> el;
doc->GetElementById(observerID, getter_AddRefs(el));
observer = do_QueryInterface(el);
}
}
nsCOMPtr<nsIDOMEventTarget> eventObserver(do_QueryInterface(observer));
nsCOMPtr<nsIDOMEventTarget> eventObserver;
if (observer)
eventObserver = do_QueryInterface(observer);
if (eventObserver) {
nsXMLEventsListener * eli = new nsXMLEventsListener(aManager,
aContent,

View File

@ -443,8 +443,7 @@ nsHTMLLabelElement::GetControlContent()
nsCOMPtr<nsIFormControl> element = do_QueryInterface(content);
if (element && element->IsLabelableControl()) {
// Transfer the reference count of element to the returned value.
element.forget();
NS_ADDREF(content);
return content;
}

View File

@ -39,15 +39,17 @@
#include "nsReadableUtils.h"
#include "nsCOMPtr.h"
#include "nsIDocument.h"
#include "nsIContent.h"
#include "nsIHTMLDocument.h"
#include "nsIDOMDocument.h"
#include "nsIDOMNode.h"
#include "nsIDOMElement.h"
#include "nsIDOMHTMLMapElement.h"
#include "nsImageMapUtils.h"
/*static*/
already_AddRefed<nsIDOMHTMLMapElement>
nsImageMapUtils::FindImageMap(nsIDocument *aDocument,
const nsAString &aUsemap)
const nsAString &aUsemap)
{
if (!aDocument)
return nsnull;
@ -89,12 +91,16 @@ nsImageMapUtils::FindImageMap(nsIDocument *aDocument,
// XHTML. The attribute "name" is officially deprecated. This
// simplifies our life becase we can simply get the map with
// getElementById().
nsIContent *element = aDocument->GetElementById(usemap);
nsCOMPtr<nsIDOMDocument> domDoc(do_QueryInterface(aDocument));
if (domDoc) {
nsCOMPtr<nsIDOMElement> element;
domDoc->GetElementById(usemap, getter_AddRefs(element));
if (element) {
nsIDOMHTMLMapElement* map;
CallQueryInterface(element, &map);
return map;
if (element) {
nsIDOMHTMLMapElement* map;
CallQueryInterface(element, &map);
return map;
}
}
}

View File

@ -536,9 +536,10 @@ nsXBLWindowKeyHandler::WalkHandlersAndExecute(nsIDOMKeyEvent* aKeyEvent,
// Locate the command element in question. Note that we
// know "elt" is in a doc if we're dealing with it here.
NS_ASSERTION(elt->IsInDoc(), "elt must be in document");
nsIDocument *doc = elt->GetCurrentDoc();
if (doc)
commandElt = do_QueryInterface(doc->GetElementById(command));
nsCOMPtr<nsIDOMDocument> domDoc(
do_QueryInterface(elt->GetCurrentDoc()));
if (domDoc)
domDoc->GetElementById(command, getter_AddRefs(commandElt));
if (!commandElt) {
NS_ERROR("A XUL <key> is observing a command that doesn't exist. Unable to execute key binding!");

View File

@ -107,7 +107,13 @@ txXPathTreeWalker::moveToElementById(const nsAString& aID)
nsCOMPtr<nsIContent> content;
if (doc) {
content = doc->GetElementById(aID);
nsCOMPtr<nsIDOMDocument> document = do_QueryInterface(doc);
NS_ASSERTION(document, "QI failed");
nsCOMPtr<nsIDOMElement> element;
document->GetElementById(aID, getter_AddRefs(element));
content = do_QueryInterface(element);
}
else {
// We're in a disconnected subtree, search only that subtree.

View File

@ -1306,10 +1306,18 @@ nsXULDocument::Persist(const nsAString& aID,
nsresult rv;
nsIContent *element = nsDocument::GetElementById(aID);
if (! element)
nsCOMPtr<nsIDOMElement> domelement;
rv = nsDocument::GetElementById(aID, getter_AddRefs(domelement));
if (NS_FAILED(rv)) return rv;
if (! domelement)
return NS_OK;
nsCOMPtr<nsIContent> element = do_QueryInterface(domelement);
NS_ASSERTION(element != nsnull, "null ptr");
if (! element)
return NS_ERROR_UNEXPECTED;
nsCOMPtr<nsIAtom> tag;
PRInt32 nameSpaceID;
@ -3933,10 +3941,14 @@ nsXULDocument::OverlayForwardReference::Resolve()
else {
// The hook-up element has an id, try to match it with an element
// with the same id in the base document.
target = mDocument->GetElementById(id);
nsCOMPtr<nsIDOMElement> domtarget;
rv = mDocument->GetElementById(id, getter_AddRefs(domtarget));
if (NS_FAILED(rv)) return eResolve_Error;
// If we can't find the element in the document, defer the hookup
// until later.
target = do_QueryInterface(domtarget);
NS_ASSERTION(!domtarget || target, "not an nsIContent");
if (!target)
return eResolve_Later;
@ -4068,15 +4080,17 @@ nsXULDocument::OverlayForwardReference::Merge(nsIContent* aTargetNode,
for (i = 0; i < childCount; ++i) {
currContent = aOverlayNode->GetChildAt(0);
nsIAtom *idAtom = currContent->GetID();
nsAutoString id;
currContent->GetAttr(kNameSpaceID_None, nsGkAtoms::id, id);
nsIContent *elementInDocument = nsnull;
if (idAtom) {
nsIDocument *doc = aTargetNode->GetDocument();
if (!doc) return NS_ERROR_FAILURE;
nsCOMPtr<nsIDOMElement> nodeInDocument;
if (!id.IsEmpty()) {
nsCOMPtr<nsIDOMDocument> domDocument(
do_QueryInterface(aTargetNode->GetDocument()));
if (!domDocument) return NS_ERROR_FAILURE;
elementInDocument =
doc->GetElementById(nsDependentAtomString(idAtom));
rv = domDocument->GetElementById(id, getter_AddRefs(nodeInDocument));
if (NS_FAILED(rv)) return rv;
}
// The item has an 'id' attribute set, and we need to check with
@ -4084,21 +4098,24 @@ nsXULDocument::OverlayForwardReference::Merge(nsIContent* aTargetNode,
// this locale. If so, we want to merge the subtree under that
// node. Otherwise, we just do an append as if the element had
// no id attribute.
if (elementInDocument) {
if (nodeInDocument) {
// Given two parents, aTargetNode and aOverlayNode, we want
// to call merge on currContent if we find an associated
// node in the document with the same id as currContent that
// also has aTargetNode as its parent.
nsIContent *elementParent = elementInDocument->GetParent();
nsCOMPtr<nsIDOMNode> nodeParent;
rv = nodeInDocument->GetParentNode(getter_AddRefs(nodeParent));
if (NS_FAILED(rv)) return rv;
nsCOMPtr<nsIDOMElement> elementParent(do_QueryInterface(nodeParent));
nsIAtom *parentID = elementParent->GetID();
if (parentID &&
aTargetNode->AttrValueIs(kNameSpaceID_None, nsGkAtoms::id,
nsDependentAtomString(parentID),
eCaseMatters)) {
nsAutoString parentID;
elementParent->GetAttribute(NS_LITERAL_STRING("id"), parentID);
if (aTargetNode->AttrValueIs(kNameSpaceID_None, nsGkAtoms::id,
parentID, eCaseMatters)) {
// The element matches. "Go Deep!"
rv = Merge(elementInDocument, currContent, aNotify);
nsCOMPtr<nsIContent> childDocumentContent(do_QueryInterface(nodeInDocument));
rv = Merge(childDocumentContent, currContent, aNotify);
if (NS_FAILED(rv)) return rv;
rv = aOverlayNode->RemoveChildAt(0, PR_FALSE);
if (NS_FAILED(rv)) return rv;
@ -4381,18 +4398,20 @@ nsXULDocument::InsertElement(nsIContent* aParent, nsIContent* aChild, PRBool aNo
}
if (!posStr.IsEmpty()) {
nsIDocument *document = aParent->GetOwnerDoc();
if (!document) return NS_ERROR_FAILURE;
nsCOMPtr<nsIDOMDocument> domDocument(
do_QueryInterface(aParent->GetDocument()));
if (!domDocument) return NS_ERROR_FAILURE;
nsIContent *content = nsnull;
nsCOMPtr<nsIDOMElement> domElement;
char* str = ToNewCString(posStr);
char* rest;
char* token = nsCRT::strtok(str, ", ", &rest);
while (token) {
content = document->GetElementById(NS_ConvertASCIItoUTF16(token));
if (content)
rv = domDocument->GetElementById(NS_ConvertASCIItoUTF16(token),
getter_AddRefs(domElement));
if (domElement)
break;
token = nsCRT::strtok(rest, ", ", &rest);
@ -4401,7 +4420,12 @@ nsXULDocument::InsertElement(nsIContent* aParent, nsIContent* aChild, PRBool aNo
if (NS_FAILED(rv))
return rv;
if (content) {
if (domElement) {
nsCOMPtr<nsIContent> content(do_QueryInterface(domElement));
NS_ASSERTION(content != nsnull, "null ptr");
if (!content)
return NS_ERROR_UNEXPECTED;
PRInt32 pos = aParent->IndexOf(content);
if (pos != -1) {

View File

@ -4798,7 +4798,16 @@ nsWindowSH::GlobalScopePolluterNewResolve(JSContext *cx, JSObject *obj,
}
nsDependentJSString str(jsstr);
nsCOMPtr<nsISupports> result = document->GetElementById(str);
nsCOMPtr<nsISupports> result;
{
nsCOMPtr<nsIDOMDocument> dom_doc(do_QueryInterface(doc));
nsCOMPtr<nsIDOMElement> element;
dom_doc->GetElementById(str, getter_AddRefs(element));
result = element;
}
if (!result) {
doc->ResolveName(str, nsnull, getter_AddRefs(result));

View File

@ -3723,13 +3723,20 @@ PresShell::GoToAnchor(const nsAString& aAnchorName, PRBool aScroll)
return NS_OK;
}
nsCOMPtr<nsIDOMDocument> doc = do_QueryInterface(mDocument);
nsCOMPtr<nsIDOMHTMLDocument> htmlDoc = do_QueryInterface(mDocument);
nsresult rv = NS_OK;
nsCOMPtr<nsIContent> content;
// Search for an element with a matching "id" attribute
if (mDocument) {
content = mDocument->GetElementById(aAnchorName);
if (doc) {
nsCOMPtr<nsIDOMElement> element;
rv = doc->GetElementById(aAnchorName, getter_AddRefs(element));
if (NS_SUCCEEDED(rv) && element) {
// Get the nsIContent interface, because that's what we need to
// get the primary frame
content = do_QueryInterface(element);
}
}
// Search for an anchor element with a matching "name" attribute
@ -3761,7 +3768,6 @@ PresShell::GoToAnchor(const nsAString& aAnchorName, PRBool aScroll)
// Search for anchor in the HTML namespace with a matching name
if (!content && !htmlDoc)
{
nsCOMPtr<nsIDOMDocument> doc = do_QueryInterface(mDocument);
nsCOMPtr<nsIDOMNodeList> list;
NS_NAMED_LITERAL_STRING(nameSpace, "http://www.w3.org/1999/xhtml");
// Get the list of anchor elements

View File

@ -1015,12 +1015,13 @@ nsMenuFrame::BuildAcceleratorText()
return;
// Turn the document into a DOM document so we can use getElementById
nsIDocument *document = mContent->GetDocument();
if (!document)
nsCOMPtr<nsIDOMDocument> domDocument(do_QueryInterface(mContent->GetDocument()));
if (!domDocument)
return;
nsIContent *keyElement = document->GetElementById(keyValue);
if (!keyElement) {
nsCOMPtr<nsIDOMElement> keyDOMElement;
domDocument->GetElementById(keyValue, getter_AddRefs(keyDOMElement));
if (!keyDOMElement) {
#ifdef DEBUG
nsAutoString label;
mContent->GetAttr(kNameSpaceID_None, nsGkAtoms::label, label);
@ -1034,6 +1035,10 @@ nsMenuFrame::BuildAcceleratorText()
return;
}
nsCOMPtr<nsIContent> keyElement(do_QueryInterface(keyDOMElement));
if (!keyElement)
return;
// get the string to display as accelerator text
// check the key element's attributes in this order:
// |keytext|, |key|, |keycode|

View File

@ -382,7 +382,12 @@ nsResizerFrame::GetContentToResize(nsIPresShell* aPresShell, nsIBaseWindow** aWi
return parent ? parent->FindFirstNonNativeAnonymous() : nsnull;
}
return aPresShell->GetDocument()->GetElementById(elementid);
nsCOMPtr<nsIDOMDocument> doc = do_QueryInterface(aPresShell->GetDocument());
nsCOMPtr<nsIDOMElement> element;
doc->GetElementById(elementid, getter_AddRefs(element));
nsCOMPtr<nsIContent> content = do_QueryInterface(element);
return content.get();
}
/* adjust the window position and size according to the mouse movement and

View File

@ -608,12 +608,12 @@ nsXULTooltipListener::FindTooltip(nsIContent* aTarget, nsIContent** aTooltip)
return NS_ERROR_NULL_POINTER;
// before we go on, make sure that target node still has a window
nsIDocument *document = aTarget->GetDocument();
nsCOMPtr<nsIDocument> document = aTarget->GetDocument();
if (!document) {
NS_WARNING("Unable to retrieve the tooltip node document.");
return NS_ERROR_FAILURE;
}
nsPIDOMWindow *window = document->GetWindow();
nsCOMPtr<nsPIDOMWindow> window = document->GetWindow();
if (!window) {
return NS_OK;
}
@ -650,13 +650,20 @@ nsXULTooltipListener::FindTooltip(nsIContent* aTarget, nsIContent** aTooltip)
if (!tooltipId.IsEmpty()) {
// tooltip must be an id, use getElementById to find it
nsCOMPtr<nsIContent> tooltipEl = document->GetElementById(tooltipId);
nsCOMPtr<nsIDOMDocument> domDocument =
do_QueryInterface(document);
if (!domDocument) {
return NS_ERROR_FAILURE;
}
nsCOMPtr<nsIDOMElement> tooltipEl;
domDocument->GetElementById(tooltipId, getter_AddRefs(tooltipEl));
if (tooltipEl) {
#ifdef MOZ_XUL
mNeedTitletip = PR_FALSE;
#endif
*aTooltip = tooltipEl.forget().get();
CallQueryInterface(tooltipEl, aTooltip);
return NS_OK;
}
}

View File

@ -48,7 +48,7 @@
#include "nsWidgetAtoms.h"
#include "nsGUIEvent.h"
#include "mozilla/dom/Element.h"
#include "nsIContent.h"
#include "nsIWidget.h"
#include "nsIDocument.h"
#include "nsIDOMDocument.h"
@ -104,19 +104,20 @@ nsresult nsMenuItemX::Create(nsMenuX* aParent, const nsString& aLabel, EMenuItem
mMenuGroupOwner->RegisterForContentChanges(mContent, this);
nsIDocument *doc = mContent->GetCurrentDoc();
nsCOMPtr<nsIDOMDocument> domDoc(do_QueryInterface(mContent->GetCurrentDoc()));
// if we have a command associated with this menu item, register for changes
// to the command DOM node
if (doc) {
if (domDoc) {
nsAutoString ourCommand;
mContent->GetAttr(kNameSpaceID_None, nsWidgetAtoms::command, ourCommand);
if (!ourCommand.IsEmpty()) {
nsIContent *commandElement = doc->GetElementById(ourCommand);
nsCOMPtr<nsIDOMElement> commandElement;
domDoc->GetElementById(ourCommand, getter_AddRefs(commandElement));
if (commandElement) {
mCommandContent = commandElement;
mCommandContent = do_QueryInterface(commandElement);
// register to observe the command DOM element
mMenuGroupOwner->RegisterForContentChanges(mCommandContent, this);
}
@ -145,12 +146,14 @@ nsresult nsMenuItemX::Create(nsMenuX* aParent, const nsString& aLabel, EMenuItem
nsWidgetAtoms::_true, eCaseMatters));
// Set key shortcut and modifiers
if (doc) {
if (domDoc) {
nsAutoString keyValue;
mContent->GetAttr(kNameSpaceID_None, nsWidgetAtoms::key, keyValue);
if (!keyValue.IsEmpty()) {
nsIContent *keyContent = doc->GetElementById(keyValue);
if (keyContent) {
nsCOMPtr<nsIDOMElement> keyElement;
domDoc->GetElementById(keyValue, getter_AddRefs(keyElement));
if (keyElement) {
nsCOMPtr<nsIContent> keyContent(do_QueryInterface(keyElement));
nsAutoString keyChar(NS_LITERAL_STRING(" "));
keyContent->GetAttr(kNameSpaceID_None, nsWidgetAtoms::key, keyChar);