Permalink
Browse files

Merge branch 'master' of github.com:firebug/firebug

  • Loading branch information...
2 parents 3be32f8 + ffff7be commit 085ebe3edd5e86e9f3b868d13369f8aadf1988c4 @janodvarko janodvarko committed Sep 17, 2012
@@ -10,9 +10,10 @@ define([
"firebug/chrome/window",
"firebug/lib/xml",
"firebug/lib/options",
- "firebug/lib/array"
+ "firebug/lib/array",
+ "firebug/editor/editorSelector"
],
-function(Obj, Firebug, Xpcom, Events, Url, Css, Win, Xml, Options, Arr) {
+function(Obj, Firebug, Xpcom, Events, Url, Css, Win, Xml, Options, Arr, EditorSelector) {
// ********************************************************************************************* //
// Constants
@@ -89,9 +90,10 @@ Firebug.CSSModule = Obj.extend(Firebug.Module, Firebug.EditorSelector,
deleteRule: function(src, ruleIndex)
{
+ var inlineStyle = (src instanceof window.Element);
if (FBTrace.DBG_CSS)
{
- if (src instanceof window.Element)
+ if (inlineStyle)
{
FBTrace.sysout("deleteRule: element.style", src);
}
@@ -102,12 +104,18 @@ Firebug.CSSModule = Obj.extend(Firebug.Module, Firebug.EditorSelector,
}
}
+ var rule = (inlineStyle ? src : src.cssRules[ruleIndex]);
+ var afterParams = [src, rule.style.cssText];
+ afterParams.push(inlineStyle ? "" : rule.selectorText);
+
Events.dispatch(this.fbListeners, "onCSSDeleteRule", [src, ruleIndex]);
if (src instanceof window.Element)
src.removeAttribute("style");
else
src.deleteRule(ruleIndex);
+
+ Events.dispatch(this.fbListeners, "onAfterCSSDeleteRule", afterParams);
},
setProperty: function(rule, propName, propValue, propPriority)
@@ -20,6 +20,7 @@ define([
"firebug/lib/persist",
"firebug/chrome/menu",
"firebug/lib/url",
+ "firebug/css/cssModule",
"firebug/css/cssReps",
"firebug/js/breakpoint",
"firebug/editor/editor",
@@ -30,7 +31,7 @@ define([
],
function(Obj, Firebug, Domplate, FirebugReps, Locale, HTMLLib, Events,
SourceLink, Css, Dom, Win, Options, Xpath, Str, Xml, Arr, Persist, Menu,
- Url, CSSInfoTip) {
+ Url, CSSModule, CSSInfoTip) {
with (Domplate) {
@@ -1182,6 +1183,74 @@ Firebug.HTMLPanel.prototype = Obj.extend(WalkingPanel,
},
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
+ // CSS Listener
+
+ updateVisibilitiesForSelectorInSheet: function(sheet, selector)
+ {
+ if (!selector)
+ return;
+ var doc = (sheet && sheet.ownerNode && sheet.ownerNode.ownerDocument);
+ if (!doc)
+ return;
+
+ var affected = doc.querySelectorAll(selector);
+ if (!affected.length || !this.ioBox.isInExistingRoot(affected[0]))
+ return;
+
+ for (var i = 0; i < affected.length; ++i)
+ {
+ var node = this.ioBox.findObjectBox(affected[i]);
+ if (node)
+ this.updateNodeVisibility(node);
+ }
+ },
+
+ updateVisibilitiesForRule: function(rule)
+ {
+ this.updateVisibilitiesForSelectorInSheet(rule.parentStyleSheet, rule.selectorText);
+ },
+
+ cssPropAffectsVisibility: function(propName)
+ {
+ // Pretend that "display" is the only property which affects visibility,
+ // which is a half-truth. We could make this more technically correct
+ // by unconditionally returning true, but forcing a synchronous reflow
+ // and computing offsetWidth/Height on up to every element on the page
+ // isn't worth it.
+ return (propName === "display");
+ },
+
+ cssTextAffectsVisibility: function(cssText)
+ {
+ return (cssText.indexOf("display:") !== -1);
+ },
+
+ onAfterCSSDeleteRule: function(styleSheet, cssText, selector)
+ {
+ if (this.cssTextAffectsVisibility(cssText))
+ this.updateVisibilitiesForSelectorInSheet(styleSheet, selector);
+ },
+
+ onCSSInsertRule: function(styleSheet, cssText, ruleIndex)
+ {
+ if (this.cssTextAffectsVisibility(cssText))
+ this.updateVisibilitiesForRule(styleSheet.cssRules[ruleIndex]);
+ },
+
+ onCSSSetProperty: function(style, propName, propValue, propPriority, prevValue,
+ prevPriority, rule, baseText)
+ {
+ if (this.cssPropAffectsVisibility(propName))
+ this.updateVisibilitiesForRule(rule);
+ },
+
+ onCSSRemoveProperty: function(style, propName, prevValue, prevPriority, rule, baseText)
+ {
+ if (this.cssPropAffectsVisibility(propName))
+ this.updateVisibilitiesForRule(rule);
+ },
+
+ // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
// extends Panel
name: "html",
@@ -1202,6 +1271,7 @@ Firebug.HTMLPanel.prototype = Obj.extend(WalkingPanel,
this.onKeyPress = Obj.bind(this.onKeyPress, this);
Firebug.Panel.initialize.apply(this, arguments);
+ Firebug.CSSModule.addListener(this);
},
destroy: function(state)
@@ -1220,6 +1290,7 @@ Firebug.HTMLPanel.prototype = Obj.extend(WalkingPanel,
delete this.inspectorHistory[i];
delete this.inspectorHistory;
+ Firebug.CSSModule.removeListener(this);
this.unregisterMutationListeners();
},
@@ -115,8 +115,8 @@ Css.getCSSShorthandCategory = function(nodeType, shorthandProp, keyword)
/**
* Parses the CSS properties of a CSSStyleRule
- * @param style CSSStyleRule to get the properties of
- * @param element Element to which the style applies. Needed for parsing shorthand properties correctly.
+ * @param {Object} style CSSStyleRule to get the properties of
+ * @param {Object} element Element to which the style applies. Needed for parsing shorthand properties correctly.
* @returns {Array} Properties represented by {name, value, priority, longhandProps}
*/
Css.parseCSSProps = function(style, element)
@@ -12,7 +12,9 @@ const dirService = Cc["@mozilla.org/file/directory_service;1"].getService(Ci.nsI
// https://developer.mozilla.org/en/Using_JavaScript_code_modules
var EXPORTED_SYMBOLS = ["Storage", "StorageService", "TextService"];
-Components.utils["import"]("resource://firebug/firebug-trace-service.js");
+Components.utils.import("resource://firebug/firebug-trace-service.js");
+Components.utils.import("resource://gre/modules/FileUtils.jsm");
+
var FBTrace = traceConsoleService.getTracer("extensions.firebug");
// ********************************************************************************************* //
@@ -92,7 +94,7 @@ Storage.prototype =
{
this.objectTable = {};
StorageService.setStorage(this, now);
- },
+ }
};
// ********************************************************************************************* //
@@ -139,7 +141,7 @@ var StorageService =
removeStorage: function(leafName)
{
ObjectPersister.deleteObject(leafname);
- },
+ }
};
// ********************************************************************************************* //
@@ -150,39 +152,12 @@ var StorageService =
*/
var ObjectPersister =
{
- getProfileDirectory: function()
- {
- var file = dirService.get("ProfD", Ci.nsIFile);
- return file;
- },
-
- getFileInDirectory: function(file, path) // forward slash separated
- {
- var segs = path.split('/');
- for (var i = 0; i < segs.length; i++)
- {
- file.append(segs[i]);
- }
- return file;
- },
-
- getFileInProfileDirectory: function(path)
- {
- // Get persistence file stored within the profile directory.
- var file = ObjectPersister.getProfileDirectory();
- file = ObjectPersister.getFileInDirectory(file, path);
- if (FBTrace.DBG_STORAGE)
- FBTrace.sysout("ObjectPersister getFileInProfileDirectory("+path+")="+file.path);
-
- return file;
- },
-
readObject: function(leafName)
{
if (FBTrace.DBG_STORAGE)
FBTrace.sysout("ObjectPersister read from leafName "+leafName);
- var file = ObjectPersister.getFileInProfileDirectory("firebug/"+leafName);
+ var file = FileUtils.getFile("ProfD", ["firebug", leafName]);
if (!file.exists())
{
@@ -283,7 +258,7 @@ var ObjectPersister =
{
// Convert data to JSON.
var jsonString = JSON.stringify(obj);
- var file = ObjectPersister.getFileInProfileDirectory("firebug/"+leafName);
+ var file = FileUtils.getFile("ProfD", ["firebug", leafName]);
ObjectPersister.writeTextToFile(file, jsonString);
}
catch(exc)
@@ -345,9 +320,7 @@ var ObjectPersister =
var TextService =
{
readText: ObjectPersister.readTextFromFile,
- writeText: ObjectPersister.writeTextToFile,
- getProfileDirectory: ObjectPersister.getProfileDirectory,
- getFileInDirectory: ObjectPersister.getFileInDirectory,
+ writeText: ObjectPersister.writeTextToFile
};
// ********************************************************************************************* //

0 comments on commit 085ebe3

Please sign in to comment.