Control debug prints via preferences

This commit is contained in:
YUKI Hiroshi 2015-10-26 16:32:31 +09:00
parent 5bdda35fe6
commit de777e7ff2
7 changed files with 59 additions and 38 deletions

View File

@ -703,3 +703,11 @@ pref("extensions.treestyletab.compatibility.TotalToolbar", true);
*/ */
pref("extensions.treestyletab.prefsVersion", 0); pref("extensions.treestyletab.prefsVersion", 0);
/**
* Flags to activate debug dumps for each module.
*/
pref("extensions.treestyletab.debug.all", false);
pref("extensions.treestyletab.debug.autoHide", false);
pref("extensions.treestyletab.debug.browser", false);
pref("extensions.treestyletab.debug.browserUIShowHideObserver", false);
pref("extensions.treestyletab.debug.tabbarDNDObserver", false);

View File

@ -36,8 +36,6 @@
var EXPORTED_SYMBOLS = ['AutoHideBrowser', 'AutoHideWindow']; var EXPORTED_SYMBOLS = ['AutoHideBrowser', 'AutoHideWindow'];
const DEBUG = false;
const Cc = Components.classes; const Cc = Components.classes;
const Ci = Components.interfaces; const Ci = Components.interfaces;
const Cu = Components.utils; const Cu = Components.utils;
@ -503,7 +501,7 @@ AutoHideBrowser.prototype = inherit(AutoHideBase.prototype, {
showHideOnMouseMove : function AHB_showHideOnMouseMove(aCoordinates) showHideOnMouseMove : function AHB_showHideOnMouseMove(aCoordinates)
{ {
var position = this.getMousePosition(aCoordinates); var position = this.getMousePosition(aCoordinates);
if (DEBUG) { if (utils.isDebugging('autoHide')) {
let humanReadablePosition = []; let humanReadablePosition = [];
if (position & this.MOUSE_POSITION_OUTSIDE) if (position & this.MOUSE_POSITION_OUTSIDE)
humanReadablePosition.push('outside'); humanReadablePosition.push('outside');
@ -839,7 +837,7 @@ AutoHideBrowser.prototype = inherit(AutoHideBase.prototype, {
this.showHideReason = aReason || this.showHideReason || this.kSHOWN_BY_UNKNOWN; this.showHideReason = aReason || this.showHideReason || this.kSHOWN_BY_UNKNOWN;
} }
if (DEBUG) { if (utils.isDebugging('autoHide')) {
let givenReason = this._getHumanReadableReason(aReason); let givenReason = this._getHumanReadableReason(aReason);
let unifiedReason = this._getHumanReadableReason(this.showHideReason); let unifiedReason = this._getHumanReadableReason(this.showHideReason);
if (this.expanded) if (this.expanded)

View File

@ -38,8 +38,6 @@
var EXPORTED_SYMBOLS = ['TreeStyleTabBrowser']; var EXPORTED_SYMBOLS = ['TreeStyleTabBrowser'];
const DEBUG = false;
const Cc = Components.classes; const Cc = Components.classes;
const Ci = Components.interfaces; const Ci = Components.interfaces;
const Cu = Components.utils; const Cu = Components.utils;
@ -1952,7 +1950,7 @@ TreeStyleTabBrowser.prototype = inherit(TreeStyleTabWindow.prototype, {
{ {
aReason = aReason || this.kTABBAR_UPDATE_BY_UNKNOWN_REASON; aReason = aReason || this.kTABBAR_UPDATE_BY_UNKNOWN_REASON;
if (DEBUG) { if (utils.isDebugging('browser')) {
let humanReadableReason = let humanReadableReason =
(aReason & this.kTABBAR_UPDATE_BY_RESET ? 'reset ' : '' ) + (aReason & this.kTABBAR_UPDATE_BY_RESET ? 'reset ' : '' ) +
(aReason & this.kTABBAR_UPDATE_BY_PREF_CHANGE ? 'prefchange ' : '' ) + (aReason & this.kTABBAR_UPDATE_BY_PREF_CHANGE ? 'prefchange ' : '' ) +
@ -3228,7 +3226,7 @@ TreeStyleTabBrowser.prototype = inherit(TreeStyleTabWindow.prototype, {
var closeParentBehavior = this.getCloseParentBehaviorForTab(tab); var closeParentBehavior = this.getCloseParentBehaviorForTab(tab);
var backupAttributes = this._collectBackupAttributes(tab); var backupAttributes = this._collectBackupAttributes(tab);
if (DEBUG) if (utils.isDebugging('browser'))
dump('onTabClose: backupAttributes = '+JSON.stringify(backupAttributes)+'\n'); dump('onTabClose: backupAttributes = '+JSON.stringify(backupAttributes)+'\n');
if (closeParentBehavior == this.kCLOSE_PARENT_BEHAVIOR_CLOSE_ALL_CHILDREN || if (closeParentBehavior == this.kCLOSE_PARENT_BEHAVIOR_CLOSE_ALL_CHILDREN ||
@ -3893,7 +3891,7 @@ TreeStyleTabBrowser.prototype = inherit(TreeStyleTabWindow.prototype, {
handleRestoredTab : function TSTBrowser_handleRestoredTab(aTab) handleRestoredTab : function TSTBrowser_handleRestoredTab(aTab)
{ {
if (aTab.__treestyletab__restoreState === undefined) { if (aTab.__treestyletab__restoreState === undefined) {
if (DEBUG) if (utils.isDebugging('browser'))
dump('handleRestoredTab: ' + aTab._tPos + ' is already restored!\n'); dump('handleRestoredTab: ' + aTab._tPos + ' is already restored!\n');
return false; return false;
} }
@ -4122,7 +4120,7 @@ TreeStyleTabBrowser.prototype = inherit(TreeStyleTabWindow.prototype, {
var restoringMultipleTabs = this.windowService.restoringTree; var restoringMultipleTabs = this.windowService.restoringTree;
var position = this._prepareInsertionPosition(aTab, aMayBeDuplicated); var position = this._prepareInsertionPosition(aTab, aMayBeDuplicated);
var parent = position.parent; var parent = position.parent;
if (DEBUG) if (utils.isDebugging('browser'))
dump('handleRestoredTab: found parent = ' + parent+'\n'); dump('handleRestoredTab: found parent = ' + parent+'\n');
if (parent) { if (parent) {
aTab.removeAttribute(this.kPARENT); aTab.removeAttribute(this.kPARENT);
@ -4169,7 +4167,7 @@ TreeStyleTabBrowser.prototype = inherit(TreeStyleTabWindow.prototype, {
} }
var ancestors = (this.getTabValue(aTab, this.kANCESTORS) || this.getTabValue(aTab, this.kPARENT)).split('|'); var ancestors = (this.getTabValue(aTab, this.kANCESTORS) || this.getTabValue(aTab, this.kPARENT)).split('|');
if (DEBUG) if (utils.isDebugging('browser'))
dump('handleRestoredTab: ancestors = ' + ancestors+'\n'); dump('handleRestoredTab: ancestors = ' + ancestors+'\n');
var parent = null; var parent = null;
for (let i in ancestors) for (let i in ancestors)
@ -4192,7 +4190,7 @@ TreeStyleTabBrowser.prototype = inherit(TreeStyleTabWindow.prototype, {
*/ */
if (!parent) { if (!parent) {
parent = aTab.getAttribute(this.kPARENT); parent = aTab.getAttribute(this.kPARENT);
if (DEBUG) if (utils.isDebugging('browser'))
dump('handleRestoredTab: parent = ' + parent+'\n'); dump('handleRestoredTab: parent = ' + parent+'\n');
if (parent && !next) if (parent && !next)
next = this.getNextSiblingTab(aTab); next = this.getNextSiblingTab(aTab);

View File

@ -36,8 +36,6 @@
var EXPORTED_SYMBOLS = ['BrowserUIShowHideObserver']; var EXPORTED_SYMBOLS = ['BrowserUIShowHideObserver'];
var DEBUG = false;
Components.utils.import('resource://treestyletab-modules/constants.js'); Components.utils.import('resource://treestyletab-modules/constants.js');
function BrowserUIShowHideObserver(aOwner, aBox) { function BrowserUIShowHideObserver(aOwner, aBox) {
@ -63,7 +61,7 @@ BrowserUIShowHideObserver.prototype = {
childList : true, childList : true,
attributes : true, attributes : true,
subtree : true, subtree : true,
attributeOldValue: DEBUG, attributeOldValue: utils.isDebugging('browserUIShowHideObserver'),
attributeFilter : [ attributeFilter : [
'hidden', 'hidden',
'collapsed', 'collapsed',
@ -149,7 +147,7 @@ BrowserUIShowHideObserver.prototype = {
) )
return; return;
if (DEBUG) { if (utils.isDebugging('browserUIShowHideObserver')) {
dump('BrowserUIShowHideObserver_onAttributeModified ' + dump('BrowserUIShowHideObserver_onAttributeModified ' +
target.localName + '#' + target.id + '.' + target.className + ', ' + target.localName + '#' + target.id + '.' + target.className + ', ' +
aMutation.attributeName + ', ' + aMutation.attributeName + ', ' +

View File

@ -35,8 +35,6 @@
var EXPORTED_SYMBOLS = ['ContentBridge']; var EXPORTED_SYMBOLS = ['ContentBridge'];
const DEBUG = false;
const Cc = Components.classes; const Cc = Components.classes;
const Ci = Components.interfaces; const Ci = Components.interfaces;
const Cu = Components.utils; const Cu = Components.utils;

View File

@ -37,8 +37,6 @@
var EXPORTED_SYMBOLS = ['TabbarDNDObserver']; var EXPORTED_SYMBOLS = ['TabbarDNDObserver'];
const DEBUG = false;
const Cc = Components.classes; const Cc = Components.classes;
const Ci = Components.interfaces; const Ci = Components.interfaces;
const Cu = Components.utils; const Cu = Components.utils;
@ -262,7 +260,8 @@ catch(e) {
getDropActionInternal : function TabbarDND_getDropActionInternal(aEvent, aSourceTab) getDropActionInternal : function TabbarDND_getDropActionInternal(aEvent, aSourceTab)
{ {
if (DEBUG) dump('getDropActionInternal: start\n'); if (utils.isDebugging('tabbarDNDObserver'))
dump('getDropActionInternal: start\n');
var sv = this.treeStyleTab; var sv = this.treeStyleTab;
var b = this.browser; var b = this.browser;
var d = this.document; var d = this.document;
@ -303,18 +302,21 @@ catch(e) {
var isNewTabAction = !aSourceTab || aSourceTab.ownerDocument != d; var isNewTabAction = !aSourceTab || aSourceTab.ownerDocument != d;
if (!tab || tab.localName != 'tab') { if (!tab || tab.localName != 'tab') {
if (DEBUG) dump(' not on a tab\n'); if (utils.isDebugging('tabbarDNDObserver'))
dump(' not on a tab\n');
let action = isTabMoveFromOtherWindow ? sv.kACTION_STAY : (sv.kACTION_MOVE | sv.kACTION_PART) ; let action = isTabMoveFromOtherWindow ? sv.kACTION_STAY : (sv.kACTION_MOVE | sv.kACTION_PART) ;
if (isNewTabAction) action |= sv.kACTION_NEWTAB; if (isNewTabAction) action |= sv.kACTION_NEWTAB;
if (aEvent[sv.screenPositionProp] < sv.getTabActualScreenPosition(firstTab)) { if (aEvent[sv.screenPositionProp] < sv.getTabActualScreenPosition(firstTab)) {
if (DEBUG) dump(' above the first tab\n'); if (utils.isDebugging('tabbarDNDObserver'))
dump(' above the first tab\n');
info.target = info.parent = info.insertBefore = firstTab; info.target = info.parent = info.insertBefore = firstTab;
info.position = isInverted ? sv.kDROP_AFTER : sv.kDROP_BEFORE ; info.position = isInverted ? sv.kDROP_AFTER : sv.kDROP_BEFORE ;
info.action = action; info.action = action;
return info; return info;
} }
else if (aEvent[sv.screenPositionProp] > sv.getTabActualScreenPosition(tabs[lastTabIndex]) + tabs[lastTabIndex].boxObject[sv.sizeProp]) { else if (aEvent[sv.screenPositionProp] > sv.getTabActualScreenPosition(tabs[lastTabIndex]) + tabs[lastTabIndex].boxObject[sv.sizeProp]) {
if (DEBUG) dump(' below the last tab\n'); if (utils.isDebugging('tabbarDNDObserver'))
dump(' below the last tab\n');
info.target = info.parent = tabs[lastTabIndex]; info.target = info.parent = tabs[lastTabIndex];
info.position = isInverted ? sv.kDROP_BEFORE : sv.kDROP_AFTER ; info.position = isInverted ? sv.kDROP_BEFORE : sv.kDROP_AFTER ;
info.action = action; info.action = action;
@ -324,25 +326,30 @@ catch(e) {
let index = b.getNewIndex ? let index = b.getNewIndex ?
b.getNewIndex(aEvent) : b.getNewIndex(aEvent) :
b.tabContainer._getDropIndex(aEvent) ; b.tabContainer._getDropIndex(aEvent) ;
if (DEBUG) dump(' on the tab '+index+'\n'); if (utils.isDebugging('tabbarDNDObserver'))
dump(' on the tab '+index+'\n');
index = Math.min(index, lastTabIndex); index = Math.min(index, lastTabIndex);
info.target = tab = tabs[index]; info.target = tab = tabs[index];
if (index == tabs[lastTabIndex]._tPos) { if (index == tabs[lastTabIndex]._tPos) {
if (index > 0) if (index > 0)
info.target = tab = tabs[index - 1]; info.target = tab = tabs[index - 1];
info.position = sv.kDROP_AFTER; info.position = sv.kDROP_AFTER;
if (DEBUG) dump(' => after the last tab\n'); if (utils.isDebugging('tabbarDNDObserver'))
dump(' => after the last tab\n');
} else if (index == firstTab._tPos) { } else if (index == firstTab._tPos) {
if (index < lastTabIndex - 1) if (index < lastTabIndex - 1)
info.target = tab = tabs[index + 1]; info.target = tab = tabs[index + 1];
info.position = sv.kDROP_BEFORE; info.position = sv.kDROP_BEFORE;
if (DEBUG) dump(' => before the first tab\n'); if (utils.isDebugging('tabbarDNDObserver'))
dump(' => before the first tab\n');
} }
if (DEBUG) dump(' info.target = ' + info.target._tPos + '\n'); if (utils.isDebugging('tabbarDNDObserver'))
dump(' info.target = ' + info.target._tPos + '\n');
} }
} }
else { else {
if (DEBUG) dump(' on the tab '+tab._tPos+'\n'); if (utils.isDebugging('tabbarDNDObserver'))
dump(' on the tab '+tab._tPos+'\n');
sv.ensureTabInitialized(tab); sv.ensureTabInitialized(tab);
info.target = tab; info.target = tab;
} }
@ -378,18 +385,21 @@ catch(e) {
switch (info.position) switch (info.position)
{ {
case sv.kDROP_ON: case sv.kDROP_ON:
if (DEBUG) dump(' position = on the tab\n'); if (utils.isDebugging('tabbarDNDObserver'))
dump(' position = on the tab\n');
var visible = sv.getNextVisibleTab(tab); var visible = sv.getNextVisibleTab(tab);
info.action = sv.kACTION_STAY | sv.kACTION_ATTACH; info.action = sv.kACTION_STAY | sv.kACTION_ATTACH;
info.parent = tab; info.parent = tab;
info.insertBefore = utils.getTreePref('insertNewChildAt') == sv.kINSERT_FISRT ? info.insertBefore = utils.getTreePref('insertNewChildAt') == sv.kINSERT_FISRT ?
(sv.getFirstChildTab(tab) || visible) : (sv.getFirstChildTab(tab) || visible) :
(sv.getNextSiblingTab(tab) || sv.getNextTab(sv.getLastDescendantTab(tab) || tab)); (sv.getNextSiblingTab(tab) || sv.getNextTab(sv.getLastDescendantTab(tab) || tab));
if (DEBUG && info.insertBefore) dump(' insertBefore = '+info.insertBefore._tPos+'\n'); if (utils.isDebugging('tabbarDNDObserver') && info.insertBefore)
dump(' insertBefore = '+info.insertBefore._tPos+'\n');
break; break;
case sv.kDROP_BEFORE: case sv.kDROP_BEFORE:
if (DEBUG) dump(' position = before the tab\n'); if (utils.isDebugging('tabbarDNDObserver'))
dump(' position = before the tab\n');
/* /*
<= detach from parent, and move <= detach from parent, and move
[TARGET ] [TARGET ]
@ -425,11 +435,13 @@ catch(e) {
info.action = sv.kACTION_MOVE | (info.parent ? sv.kACTION_ATTACH : sv.kACTION_PART ); info.action = sv.kACTION_MOVE | (info.parent ? sv.kACTION_ATTACH : sv.kACTION_PART );
info.insertBefore = tab; info.insertBefore = tab;
} }
if (DEBUG && info.insertBefore) dump(' insertBefore = '+info.insertBefore._tPos+'\n'); if (utils.isDebugging('tabbarDNDObserver') && info.insertBefore)
dump(' insertBefore = '+info.insertBefore._tPos+'\n');
break; break;
case sv.kDROP_AFTER: case sv.kDROP_AFTER:
if (DEBUG) dump(' position = after the tab\n'); if (utils.isDebugging('tabbarDNDObserver'))
dump(' position = after the tab\n');
/* /*
[TARGET ] [TARGET ]
<= if the target has a parent, attach to it and and move <= if the target has a parent, attach to it and and move
@ -473,7 +485,8 @@ catch(e) {
} }
} }
} }
if (DEBUG && info.insertBefore) dump(' insertBefore = '+info.insertBefore._tPos+'\n'); if (utils.isDebugging('tabbarDNDObserver') && info.insertBefore)
dump(' insertBefore = '+info.insertBefore._tPos+'\n');
break; break;
} }
@ -484,14 +497,16 @@ catch(e) {
performDrop : function TabbarDND_performDrop(aInfo, aDraggedTab) performDrop : function TabbarDND_performDrop(aInfo, aDraggedTab)
{ {
if (DEBUG) dump('performDrop: start\n'); if (utils.isDebugging('tabbarDNDObserver'))
dump('performDrop: start\n');
var sv = this.treeStyleTab; var sv = this.treeStyleTab;
var b = this.browser; var b = this.browser;
var w = this.window; var w = this.window;
var tabsInfo = this.getDraggedTabsInfoFromOneTab(aDraggedTab, aInfo); var tabsInfo = this.getDraggedTabsInfoFromOneTab(aDraggedTab, aInfo);
if (!tabsInfo.draggedTab) { if (!tabsInfo.draggedTab) {
if (DEBUG) dump(' => no dragged tab\n'); if (utils.isDebugging('tabbarDNDObserver'))
dump(' => no dragged tab\n');
return false; return false;
} }
@ -548,7 +563,8 @@ catch(e) {
sourceBrowser == targetBrowser && sourceBrowser == targetBrowser &&
sourceService.getNextVisibleTab(draggedTabs[draggedTabs.length-1]) == aInfo.insertBefore sourceService.getNextVisibleTab(draggedTabs[draggedTabs.length-1]) == aInfo.insertBefore
) { ) {
if (DEBUG) dump(' => no change\n'); if (utils.isDebugging('tabbarDNDObserver'))
dump(' => no change\n');
// then, do nothing // then, do nothing
return true; return true;
} }

View File

@ -229,6 +229,11 @@ var TreeStyleTabUtils = {
} }
this.setTreePref('prefsVersion', TST_PREF_VERSION); this.setTreePref('prefsVersion', TST_PREF_VERSION);
}, },
isDebugging : function utils_isDebugging(aModule)
{
return this.getTreePref('debug.' + aModule) || this.getTreePref('debug.all');
},
/* string bundle */ /* string bundle */
get treeBundle () { get treeBundle () {