From 9fd915fb41f40a9e09f748c6963a07e2be5e6239 Mon Sep 17 00:00:00 2001 From: Kris Maglione Date: Mon, 26 Sep 2011 16:20:26 -0400 Subject: [PATCH] Add dactylIUtils.createContents. Closes issue #581. --- binary/src/dactylIUtils.idl | 3 +++ binary/src/dactylUtils.cpp | 25 +++++++++++++++++++++++++ common/content/dactyl.js | 2 ++ common/modules/dom.jsm | 6 ++++++ 4 files changed, 36 insertions(+) diff --git a/binary/src/dactylIUtils.idl b/binary/src/dactylIUtils.idl index 84f941af..0a1aa9ae 100644 --- a/binary/src/dactylIUtils.idl +++ b/binary/src/dactylIUtils.idl @@ -1,6 +1,7 @@ /* Public Domain */ #include "nsISupports.idl" +#include "nsIDOMElement.idl" %{C++ #include "jsapi.h" @@ -19,6 +20,8 @@ interface dactylIUtils : nsISupports [optional] in ACString filename, [optional] in PRInt32 lineNumber); + void createContents(in nsIDOMElement element); + [implicit_jscontext] jsval getGlobalForObject(in jsval object); diff --git a/binary/src/dactylUtils.cpp b/binary/src/dactylUtils.cpp index 958b267d..86a4d46a 100644 --- a/binary/src/dactylUtils.cpp +++ b/binary/src/dactylUtils.cpp @@ -40,6 +40,9 @@ #include "jsdbgapi.h" #include "jsobj.h" +#include "nsIContent.h" +#include "nsIDOMXULElement.h" +#include "nsIXULTemplateBuilder.h" #include "nsIObserverService.h" #include "nsIScriptSecurityManager.h" #include "nsIXPCScriptable.h" @@ -271,6 +274,28 @@ dactylUtils::EvalInContext(const nsAString &aSource, return rv; } +NS_IMETHODIMP +dactylUtils::CreateContents(nsIDOMElement *aElement) +{ + nsCOMPtr content = do_QueryInterface(aElement); + + for (nsIContent *element = content; + element; + element = element->GetParent()) { + + nsCOMPtr xulelem = do_QueryInterface(element); + if (xulelem) { + nsCOMPtr builder; + xulelem->GetBuilder(getter_AddRefs(builder)); + if (builder) { + builder->CreateContents(content, PR_TRUE); + break; + } + } + } + return NS_OK; +} + NS_IMETHODIMP dactylUtils::GetGlobalForObject(const jsval &aObject, JSContext *cx, diff --git a/common/content/dactyl.js b/common/content/dactyl.js index f64a639f..533941e4 100644 --- a/common/content/dactyl.js +++ b/common/content/dactyl.js @@ -143,6 +143,8 @@ var Dactyl = Module("dactyl", XPCOM(Ci.nsISupportsWeakReference, ModuleBase), { } function addChildren(node, parent) { + DOM(node).createContents(); + if (~["menu", "menupopup"].indexOf(node.localName) && node.children.length) dispatch(node, "popupshowing"); diff --git a/common/modules/dom.jsm b/common/modules/dom.jsm index 47d5c9b7..ccb7e7ca 100644 --- a/common/modules/dom.jsm +++ b/common/modules/dom.jsm @@ -688,6 +688,9 @@ var DOM = Class("DOM", { }, this); }, + createContents: function createContents() + this.each(DOM.createContents, this), + getSet: function getSet(args, get, set) { if (!args.length) return this[0] && get.call(this, this[0]); @@ -1240,6 +1243,9 @@ var DOM = Class("DOM", { }) }), + createContents: Class.Memoize(function () services.has("dactyl") && services.dactyl.createContents + || function (elem) {}), + /** * The set of input element type attribute values that mark the element as * an editable field.