[Pkg-mozext-commits] [adblock-plus-element-hiding-helper] 391/483: Composer: Display attributes via templates rather than XBL binding to prevent memory leaks. While at it, fix attribute label stealing focus and only show focus ring when the checkbox is focused, not the textbox.

David Prévot taffit at moszumanska.debian.org
Thu Jan 22 21:42:00 UTC 2015


This is an automated email from the git hooks/post-receive script.

taffit pushed a commit to branch master
in repository adblock-plus-element-hiding-helper.

commit b6b2fd2adb23f61a60ca13941d2ded7a417f68f8
Author: Wladimir Palant <trev at adblockplus.org>
Date:   Wed Jan 25 14:07:58 2012 +0100

    Composer: Display attributes via templates rather than XBL binding to prevent memory leaks. While at it, fix attribute label stealing focus and only show focus ring when the checkbox is focused, not the textbox.
---
 chrome/content/attribute.xml | 54 ------------------------
 chrome/content/composer.js   | 99 ++++++++++++++++++++++++--------------------
 chrome/content/composer.xul  | 12 ++++++
 chrome/skin/composer.css     | 12 +++---
 4 files changed, 72 insertions(+), 105 deletions(-)

diff --git a/chrome/content/attribute.xml b/chrome/content/attribute.xml
deleted file mode 100644
index 66e2ed9..0000000
--- a/chrome/content/attribute.xml
+++ /dev/null
@@ -1,54 +0,0 @@
-<?xml version="1.0"?>
-
-<!-- This Source Code is subject to the terms of the Mozilla Public License
-   - version 2.0 (the "License"). You can obtain a copy of the License at
-   - http://mozilla.org/MPL/2.0/. -->
-
-<bindings id="attributeBindings"
-   xmlns="http://www.mozilla.org/xbl"
-   xmlns:xul="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul"
-   xmlns:xbl="http://www.mozilla.org/xbl">
-
-  <binding id="attributeBasic">
-    <content>
-      <xul:checkbox anonid="checkbox" xbl:inherits="checked,label"/>
-    </content>
-    <implementation>
-      <property name="checked">
-        <getter>
-          return document.getAnonymousElementByAttribute(this, "anonid", "checkbox").checked;
-        </getter>
-      </property>
-    </implementation>
-    <handlers>
-      <handler event="command" phase="bubble" action="toggleAttr(event.currentTarget);"/>
-      <handler event="focus" phase="bubble" action="event.currentTarget.setAttribute('selected', 'true');"/>
-      <handler event="blur" phase="bubble" action="event.currentTarget.removeAttribute('selected');"/>
-    </handlers>
-  </binding>
-
-  <binding id="attributeAdvanced" extends="#attributeBasic">
-    <content>
-      <xul:checkbox anonid="checkbox" xbl:inherits="checked"/>
-      <xul:vbox flex="1">
-        <xul:label anonid="label" xbl:inherits="value=label" onclick="document.getAnonymousElementByAttribute(this.parentNode.parentNode, 'anonid', 'checkbox').click();"/>
-        <xul:textbox anonid="textbox" xbl:inherits="value"/>
-      </xul:vbox>
-    </content>
-    <implementation>
-      <constructor>
-        var randID = new String(Math.random()).replace(/\D/g, "");
-        document.getAnonymousElementByAttribute(this, "anonid", "checkbox").setAttribute("id", randID);
-        document.getAnonymousElementByAttribute(this, "anonid", "label").setAttribute("control", randID);
-      </constructor>
-      <property name="value">
-        <getter>
-          return document.getAnonymousElementByAttribute(this, "anonid", "textbox").value;
-        </getter>
-      </property>
-    </implementation>
-    <handlers>
-      <handler event="input" phase="bubble" action="setSelectedAttrValue(event.currentTarget);"/>
-    </handlers>
-  </binding>
-</bindings>
diff --git a/chrome/content/composer.js b/chrome/content/composer.js
index 3c038d5..9d35762 100644
--- a/chrome/content/composer.js
+++ b/chrome/content/composer.js
@@ -465,70 +465,79 @@ function fillNodes(nodeData) {
     body.appendChild(curContainer.firstChild);
 }
 
-function fillAttributes(nodeData) {
+function createAttribute(template, attr, text, value)
+{
+  template = E(template == "basic" ? "basicAttributeTemplate" : "advancedAttributeTemplate");
+
+  let result = template.cloneNode(true);
+  result.removeAttribute("id");
+  result.removeAttribute("hidden");
+  result.attr = attr;
+
+  let checkbox = result.getElementsByClassName("checkbox")[0];
+  checkbox.setAttribute("checked", attr.checked);
+  checkbox.attr = attr;
+
+  let label = result.getElementsByClassName("label");
+  if (label.length)
+  {
+    label = label[0];
+    label.setAttribute("value", text);
+
+    let randID = "i" + String(Math.random()).replace(/\D/g, "");
+    checkbox.setAttribute("id", randID);
+    label.setAttribute("control", randID);
+  }
+  else
+    checkbox.setAttribute("label", text);
+
+  let textbox = result.getElementsByClassName("textbox");
+  if (textbox.length)
+  {
+    textbox = textbox[0];
+    textbox.setAttribute("value", value);
+    textbox.attr = attr;
+  }
+
+  return result;
+}
+
+function fillAttributes(nodeData)
+{
   selectedNode = nodeData;
 
-  var list = document.getElementById("attributes-list");
+  let list = document.getElementById("attributes-list");
   while(list.firstChild)
     list.removeChild(list.firstChild);
 
-  // Work-around for bug 719180 - don't access XBL binding via its chrome:// address
-  let chromeRegistry = Cc["@mozilla.org/chrome/chrome-registry;1"]
-                         .getService(Ci.nsIChromeRegistry);
-  let xblURL = chromeRegistry.convertChromeURL(Services.io.newURI("chrome://elemhidehelper/content/attribute.xml", null, null)).spec;
-  let xblBasic = "url(" + xblURL + "#attributeBasic)";
-  let xblAdvanced = "url(" + xblURL + "#attributeAdvanced)";
-
   // Add tag name entry
-  var node = document.createElement("attribute");
-  node.attr = nodeData.tagName;
-  node.setAttribute("notextbox", "true");
-  node.setAttribute("checked", nodeData.tagName.checked);
-  node.setAttribute("label", list.getAttribute("_labeltagname") + " " + nodeData.tagName.value);
-  node.style.MozBinding = xblBasic;
+  let node = createAttribute("basic", nodeData.tagName, list.getAttribute("_labeltagname") + " " + nodeData.tagName.value);
   list.appendChild(node);
 
   // Add first/last child entries
-  if (advancedMode && "firstChild" in nodeData) {
-    node = document.createElement("attribute");
-    node.attr = nodeData.firstChild;
-    node.setAttribute("notextbox", "true");
-    node.setAttribute("checked", nodeData.firstChild.checked);
-    node.setAttribute("label", list.getAttribute("_labelfirstchild"));
-    node.style.MozBinding = xblBasic;
+  if (advancedMode && "firstChild" in nodeData)
+  {
+    node = createAttribute("basic", nodeData.firstChild, list.getAttribute("_labelfirstchild"));
     list.appendChild(node);
   }
-  if (advancedMode && "lastChild" in nodeData) {
-    node = document.createElement("attribute");
-    node.attr = nodeData.lastChild;
-    node.setAttribute("notextbox", "true");
-    node.setAttribute("checked", nodeData.lastChild.checked);
-    node.setAttribute("label", list.getAttribute("_labellastchild"));
-    node.style.MozBinding = xblBasic;
+  if (advancedMode && "lastChild" in nodeData)
+  {
+    node = createAttribute("basic", nodeData.lastChild, list.getAttribute("_labellastchild"));
     list.appendChild(node);
   }
 
   // Add attribute entries
-  for (var i = 0; i < nodeData.attributes.length; i++) {
-    var attr = nodeData.attributes[i];
-
-    node = document.createElement("attribute");
-    node.attr = attr;
-    node.setAttribute("checked", attr.checked);
-    node.setAttribute("label", attr.name + ": " + attr.value);
-    node.setAttribute("value", attr.selected);
-    node.style.MozBinding = advancedMode ? xblAdvanced : xblBasic;
+  for (let i = 0; i < nodeData.attributes.length; i++)
+  {
+    let attr = nodeData.attributes[i];
+    node = createAttribute(advancedMode ? "advanced" : "basic", attr, attr.name + ": " + attr.value, attr.selected);
     list.appendChild(node);
   }
 
-  if (advancedMode) {
+  if (advancedMode)
+  {
     // Add custom CSS entry
-    node = document.createElement("attribute");
-    node.attr = nodeData.customCSS;
-    node.setAttribute("checked", nodeData.customCSS.checked);
-    node.setAttribute("label", list.getAttribute("_labelcustom"));
-    node.setAttribute("value", nodeData.customCSS.selected);
-    node.style.MozBinding = xblAdvanced;
+    node = createAttribute("advanced", nodeData.customCSS, list.getAttribute("_labelcustom"), nodeData.customCSS.selected);
     list.appendChild(node);
   }
 }
diff --git a/chrome/content/composer.xul b/chrome/content/composer.xul
index dff9479..0eb6c2f 100644
--- a/chrome/content/composer.xul
+++ b/chrome/content/composer.xul
@@ -39,6 +39,18 @@
     </hbox>
   </vbox>
 
+  <hbox id="basicAttributeTemplate" class="attribute basic" hidden="true">
+    <checkbox class="checkbox" oncommand="toggleAttr(this);"/>
+  </hbox>
+
+  <hbox id="advancedAttributeTemplate" class="attribute advanced" hidden="true">
+    <checkbox class="checkbox" oncommand="toggleAttr(this);"/>
+    <vbox flex="1">
+      <label class="label" onclick="this.parentNode.previousSibling.click();"/>
+      <textbox class="textbox" oninput="setSelectedAttrValue(this);"/>
+    </vbox>
+  </hbox>
+
   <hbox id="choices" flex="1">
     <groupbox id="domain" orient="vertical">
       <caption label="&domain.label;"/>
diff --git a/chrome/skin/composer.css b/chrome/skin/composer.css
index bdeab87..57de6fe 100644
--- a/chrome/skin/composer.css
+++ b/chrome/skin/composer.css
@@ -31,19 +31,19 @@ treechildren::-moz-tree-row(anchor, selected-false)
   background-color: #FFC0C0;
 }
 
-attribute
+.attribute
 {
   padding: 5px;
 }
-attribute vbox
+.attribute > checkbox:focus + vbox
 {
-  border: 1px solid transparent;
+  outline: 1px dotted ThreeDDarkShadow;
 }
-attribute[selected="true"] vbox
+.attribute .label
 {
-  border: 1px dotted ThreeDDarkShadow;
+  -moz-user-focus: ignore;
 }
-dialog[advancedMode=true] attribute:not([notextbox]) .checkbox-label-box
+.attribute.advanced .checkbox-label-box
 {
   display: none;
 }

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-mozext/adblock-plus-element-hiding-helper.git



More information about the Pkg-mozext-commits mailing list