mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-11-25 05:41:12 +00:00
Bug 914618 - Reimplement XML pretty printing with events. r=smaug
This commit is contained in:
parent
7078351f62
commit
bb811af3a1
@ -12,18 +12,6 @@
|
||||
<html:span style="display: none;"><children/></html:span>
|
||||
</content>
|
||||
|
||||
<implementation implements="nsIObserver">
|
||||
<method name="observe">
|
||||
<parameter name="aSubject"/>
|
||||
<parameter name="aTopic"/>
|
||||
<parameter name="aData"/>
|
||||
<body>
|
||||
if (aTopic == "prettyprint-dom-created")
|
||||
document.getAnonymousNodes(this).item(0).appendChild(aSubject);
|
||||
</body>
|
||||
</method>
|
||||
</implementation>
|
||||
|
||||
<handlers>
|
||||
<handler event="click" button="0">
|
||||
<![CDATA[
|
||||
@ -43,6 +31,11 @@
|
||||
}
|
||||
]]>
|
||||
</handler>
|
||||
<handler event="prettyprint-dom-created" allowuntrusted="false">
|
||||
<![CDATA[
|
||||
document.getAnonymousNodes(this).item(0).appendChild(event.detail);
|
||||
]]>
|
||||
</handler>
|
||||
</handlers>
|
||||
|
||||
</binding>
|
||||
|
@ -22,6 +22,9 @@
|
||||
#include "nsIScriptSecurityManager.h"
|
||||
#include "mozilla/Preferences.h"
|
||||
#include "nsIDocument.h"
|
||||
#include "nsVariant.h"
|
||||
#include "nsIDOMCustomEvent.h"
|
||||
#include "GeneratedEvents.h"
|
||||
|
||||
using namespace mozilla;
|
||||
using namespace mozilla::dom;
|
||||
@ -152,16 +155,23 @@ nsXMLPrettyPrinter::PrettyPrint(nsIDocument* aDocument,
|
||||
getter_AddRefs(unused), &ignored);
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
|
||||
// Hand the result document to the binding
|
||||
nsCOMPtr<nsIObserver> binding;
|
||||
aDocument->BindingManager()->GetBindingImplementation(rootCont,
|
||||
NS_GET_IID(nsIObserver),
|
||||
(void**)getter_AddRefs(binding));
|
||||
NS_ASSERTION(binding, "Prettyprint binding doesn't implement nsIObserver");
|
||||
NS_ENSURE_TRUE(binding, NS_ERROR_UNEXPECTED);
|
||||
|
||||
rv = binding->Observe(resultFragment, "prettyprint-dom-created",
|
||||
EmptyString().get());
|
||||
// Fire an event at the bound element to pass it |resultFragment|.
|
||||
nsCOMPtr<nsIDOMEvent> domEvent;
|
||||
rv = NS_NewDOMCustomEvent(getter_AddRefs(domEvent), rootCont,
|
||||
nullptr, nullptr);
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
nsCOMPtr<nsIDOMCustomEvent> customEvent = do_QueryInterface(domEvent);
|
||||
MOZ_ASSERT(customEvent);
|
||||
nsCOMPtr<nsIWritableVariant> resultFragmentVariant = new nsVariant();
|
||||
rv = resultFragmentVariant->SetAsISupports(resultFragment);
|
||||
MOZ_ASSERT(NS_SUCCEEDED(rv));
|
||||
rv = customEvent->InitCustomEvent(NS_LITERAL_STRING("prettyprint-dom-created"),
|
||||
/* bubbles = */ false, /* cancelable = */ false,
|
||||
/* detail = */ resultFragmentVariant);
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
customEvent->SetTrusted(true);
|
||||
bool dummy;
|
||||
rv = rootCont->DispatchEvent(domEvent, &dummy);
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
|
||||
// Observe the document so we know when to switch to "normal" view
|
||||
|
Loading…
Reference in New Issue
Block a user