Skip to content

Commit

Permalink
Cherry pick Legacy Toolbar Button support #1321 (part 4) - fixing up
Browse files Browse the repository at this point in the history
  • Loading branch information
AlexVallat committed May 30, 2015
1 parent e9633d4 commit 620a7d7
Show file tree
Hide file tree
Showing 6 changed files with 45 additions and 61 deletions.
17 changes: 6 additions & 11 deletions platform/firefox/img/browsericons/icon-large-off.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
17 changes: 6 additions & 11 deletions platform/firefox/img/browsericons/icon-large.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
59 changes: 28 additions & 31 deletions platform/firefox/vapi-background.js
Original file line number Diff line number Diff line change
Expand Up @@ -350,26 +350,26 @@ var windowWatcher = {

var attachToTabBrowser = function(window, tabBrowser) {
if (!tabBrowser) {
return;
}
return;
}

var tabContainer;
if ( tabBrowser.deck ) {
// Fennec
tabContainer = tabBrowser.deck;
} else if ( tabBrowser.tabContainer ) {
// desktop Firefox
tabContainer = tabBrowser.tabContainer;
if ( tabBrowser.deck ) {
// Fennec
tabContainer = tabBrowser.deck;
} else if (tabBrowser.tabContainer) {
// desktop Firefox
tabContainer = tabBrowser.tabContainer;
vAPI.contextMenu.register(window.document);
if (vAPI.toolbarButton.attachToNewWindow) {
vAPI.toolbarButton.attachToNewWindow(window);
}
} else {
return;
}
} else {
return;
}

tabContainer.addEventListener('TabClose', tabWatcher.onTabClose);
tabContainer.addEventListener('TabSelect', tabWatcher.onTabSelect);
tabContainer.addEventListener('TabClose', tabWatcher.onTabClose);
tabContainer.addEventListener('TabSelect', tabWatcher.onTabSelect);
// when new window is opened TabSelect doesn't run on the selected tab?
}

Expand Down Expand Up @@ -1610,9 +1610,9 @@ vAPI.toolbarButton.init = function() {

var forceLegacyToolbarButton = vAPI.localStorage.getBool("forceLegacyToolbarButton");
if (!forceLegacyToolbarButton) {
try {
CustomizableUI = Cu.import('resource:///modules/CustomizableUI.jsm', null).CustomizableUI;
} catch (ex) {
try {
CustomizableUI = Cu.import('resource:///modules/CustomizableUI.jsm', null).CustomizableUI;
} catch (ex) {
}
}

Expand Down Expand Up @@ -1642,8 +1642,8 @@ vAPI.toolbarButton.init = function() {
addLegacyToolbarButton(window);
}
}, 250);
return;
}
return;
}

var toolbarButton = document.createElement('toolbarbutton');
toolbarButton.setAttribute('id', legacyButtonId);
Expand Down Expand Up @@ -1772,11 +1772,11 @@ vAPI.toolbarButton.init = function() {

for ( var win of vAPI.tabs.getWindows() ) {
var button = win.document.getElementById(wId);
if ( buttonInPanel ) {
button.classList.remove('badged-button');
if ( button === null ) {
continue;
}
if ( button === null ) {
if ( buttonInPanel ) {
button.classList.remove('badged-button');
continue;
}
button.classList.add('badged-button');
Expand Down Expand Up @@ -1840,7 +1840,6 @@ vAPI.toolbarButton.init = function() {
};

CustomizableUI.createWidget(this);


cleanupTasks.push(function() {
if ( this.CUIEvents ) {
Expand Down Expand Up @@ -1899,12 +1898,14 @@ vAPI.toolbarButton.populatePanel = function(doc, panel) {

// Sanity check
attempts = (attempts || 0) + 1;
if (attempts > 1000) {
console.error('uBlock> delayedResize: giving up after too many attemps');
if (attempts > 1/*000*/) {
debugger;
console.error('uBlock> delayedResize: giving up after too many attempts');
return;
}

updateTimer = vAPI.setTimeout(resizePopup, 10, attempts); };
updateTimer = vAPI.setTimeout(resizePopup, 10, attempts);
};
var resizePopup = function(attempts) {
updateTimer = null;
var body = iframe.contentDocument.body;
Expand All @@ -1925,6 +1926,8 @@ vAPI.toolbarButton.populatePanel = function(doc, panel) {
delayedResize(attempts);
}
};

var CustomizableUI = this.CustomizableUI;
var onPopupReady = function() {
var win = this.contentWindow;

Expand All @@ -1933,7 +1936,6 @@ vAPI.toolbarButton.populatePanel = function(doc, panel) {
}

if (CustomizableUI) {

// https://github.com/gorhill/uBlock/issues/83
// Add `portrait` class if width is constrained.
try {
Expand All @@ -1944,11 +1946,6 @@ vAPI.toolbarButton.populatePanel = function(doc, panel) {
} catch (ex) {
/* noop */
}
var placement = CustomizableUI.getPlacementOfWidget(widgetId);
if (placement.area === CustomizableUI.AREA_PANEL) {
// Add some overrides for displaying the popup correctly in a panel
win.QueryInterface(Ci.nsIInterfaceRequestor).getInterface(Ci.nsIDOMWindowUtils)
.loadSheet(Services.io.newURI(vAPI.getURL("css/popup-vertical.css"), null, null), Ci.nsIDOMWindowUtils.AUTHOR_SHEET);
}

new win.MutationObserver(delayedResize).observe(win.document.body, {
Expand Down
4 changes: 2 additions & 2 deletions platform/firefox/vapi-client.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,8 @@ vAPI.sessionId = String.fromCharCode(Date.now() % 25 + 97) +

/******************************************************************************/

vAPI.setTimeout = vAPI.setTimeout || function(callback, delay) {
return setTimeout(function() { callback(); }, delay);
vAPI.setTimeout = vAPI.setTimeout || function(callback, delay, args) {
return setTimeout(function(args) { callback(args); }, delay, args);
};

/******************************************************************************/
Expand Down
4 changes: 2 additions & 2 deletions platform/firefox/vapi-common.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,8 @@ var vAPI = self.vAPI = self.vAPI || {};

/******************************************************************************/

vAPI.setTimeout = vAPI.setTimeout || function(callback, delay) {
return setTimeout(function() { callback(); }, delay);
vAPI.setTimeout = vAPI.setTimeout || function(callback, delay, args) {
return setTimeout(function(args) { callback(args); }, delay, args);
};

/******************************************************************************/
Expand Down
5 changes: 1 addition & 4 deletions src/js/scriptlets/element-picker.js
Original file line number Diff line number Diff line change
Expand Up @@ -902,7 +902,7 @@ var startPicker = function(details) {
// Try using mouse position
if (!elem && details.clientX !== -1) {
elem = elementFromPoint(details.clientX, details.clientY);
}
}

if (elem !== null) {
elem.scrollIntoView({
Expand All @@ -912,9 +912,6 @@ var startPicker = function(details) {
filtersFromElement(elem);
showDialog();
}

// A target was specified, but it wasn't found: abort.
stopPicker();
};

/******************************************************************************/
Expand Down

0 comments on commit 620a7d7

Please sign in to comment.