Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Restrict tab movement to 1/3rd of edges

  • Loading branch information...
commit 6a21733f0a2ecca7c601ff14b606444d83e31464 1 parent aabe0fe
@anantn authored
Showing with 53 additions and 100 deletions.
  1. +4 −0 bootstrap.js
  2. +49 −100 content/stack.xml
View
4 bootstrap.js
@@ -46,6 +46,10 @@ function Stacky(win, add)
this._activeGroup = null;
let bindingUri = add.getResourceURI("content/stack.xml").spec;
+ // Apply binding to tab strip of current window
+ let tabstrip = win.document.getElementById("tabbrowser-tabs");
+ tabstrip.style.MozBinding = "url(" + bindingUri + "#stacky-tabs)";
+
// Apply binding to tabs already open
let browser = win.gBrowser;
for (let i = 0; i < browser.tabs.length; i++) {
View
149 content/stack.xml
@@ -195,110 +195,28 @@
</handlers>
</binding>
- <binding id="stacky-tab" display="xul:hbox"
- extends="chrome://global/content/bindings/tabbox.xml#tab">
- <resources>
- <stylesheet src="chrome://browser/content/tabbrowser.css"/>
- </resources>
-
- <content context="tabContextMenu" closetabtext="&closeTab.label;">
- <xul:stack class="tab-stack" flex="1">
- <xul:hbox xbl:inherits="pinned,selected,titlechanged"
- class="tab-background">
- <xul:hbox xbl:inherits="pinned,selected,titlechanged"
- class="tab-background-start"/>
- <xul:hbox xbl:inherits="pinned,selected,titlechanged"
- class="tab-background-middle"/>
- <xul:hbox xbl:inherits="pinned,selected,titlechanged"
- class="tab-background-end"/>
- </xul:hbox>
- <xul:hbox xbl:inherits="pinned,selected,titlechanged"
- class="tab-content" align="center">
- <xul:image xbl:inherits="fadein,pinned,busy,progress,selected"
- class="tab-throbber"
- role="presentation"/>
- <xul:image xbl:inherits="validate,src=image,fadein,pinned,selected"
- class="tab-icon-image"
- role="presentation"/>
- <xul:label flex="1"
- xbl:inherits="value=label,crop,accesskey,fadein,pinned,selected"
- class="tab-text tab-label"
- role="presentation"/>
- <xul:toolbarbutton anonid="close-button"
- xbl:inherits="fadein,pinned,selected"
- tabindex="-1"
- clickthrough="never"
- class="tab-close-button"/>
- </xul:hbox>
- </xul:stack>
- </content>
-
+ <binding id="stacky-tab"
+ extends="chrome://browser/content/tabbrowser.xml#tabbrowser-tab">
<implementation>
<property name="isGroup" readonly="true" onget="return false;"/>
- <property name="pinned" readonly="true">
- <getter>
- return this.getAttribute("pinned") == "true";
- </getter>
- </property>
- <property name="hidden" readonly="true">
- <getter>
- return this.getAttribute("hidden") == "true";
- </getter>
- </property>
-
- <field name="mOverCloseButton">false</field>
- <field name="mCorrespondingMenuitem">null</field>
+ <method name="_shouldHandleDrop">
+ <parameter name="event"/>
+ <body><![CDATA[
+ let lbound = this.boxObject.screenX + this.boxObject.width / 3;
+ let rbound = lbound + this.boxObject.width / 3;
+ if (event.screenX > lbound && event.screenX < rbound)
+ return true;
+ return false;
+ ]]></body>
+ </method>
</implementation>
-
<handlers>
- <handler event="mouseover">
- var anonid = event.originalTarget.getAttribute("anonid");
- if (anonid == "close-button")
- this.mOverCloseButton = true;
- </handler>
- <handler event="mouseout">
- var anonid = event.originalTarget.getAttribute("anonid");
- if (anonid == "close-button")
- this.mOverCloseButton = false;
- </handler>
- <handler event="mousedown" button="0" phase="capturing">
- <![CDATA[
- if (this.mOverCloseButton) {
- event.stopPropagation();
- }
- else {
- this.style.MozUserFocus = 'ignore';
- this.clientTop; // just using this to flush style updates
- }
- ]]>
- </handler>
- <handler event="mousedown" button="1">
- this.style.MozUserFocus = 'ignore';
- this.clientTop;
- </handler>
- <handler event="mousedown" button="2">
- this.style.MozUserFocus = 'ignore';
- this.clientTop;
- </handler>
- <handler event="mouseup">
- this.style.MozUserFocus = '';
- </handler>
-
- <handler event="dragstart" phase="capturing"><![CDATA[
- this.style.MozUserFocus = '';
- ]]></handler>
- <handler event="dragenter"><![CDATA[
- if (event.dataTransfer.types.contains("application/x-moz-tabbrowser-tab")) {
- event.preventDefault();
- event.dataTransfer.dropEffect = "move";
- event.dataTransfer.effectAllowed = "move";
- }
- ]]></handler>
<handler event="dragover"><![CDATA[
- if (event.dataTransfer.types.contains("application/x-moz-tabbrowser-tab")) {
- event.preventDefault();
- event.dataTransfer.dropEffect = "move";
- event.dataTransfer.effectAllowed = "move";
+ if (event.dataTransfer.types.contains("application/x-moz-tabbrowser-tab")
+ && this._shouldHandleDrop(event)) {
+ event.preventDefault();
+ event.dataTransfer.dropEffect = "move";
+ event.dataTransfer.effectAllowed = "move";
}
]]></handler>
<handler event="drop"><![CDATA[
@@ -307,10 +225,41 @@
event.preventDefault();
]]></handler>
<handler event="dragleave"><![CDATA[
-
+
]]></handler>
</handlers>
</binding>
+ <binding id="stacky-tabs"
+ extends="chrome://browser/content/tabbrowser.xml#tabbrowser-tabs">
+ <implementation>
+ <method name="_getDropIndex">
+ <parameter name="event"/>
+ <body><![CDATA[
+ var tabs = this.childNodes;
+ var tab = this._getDragTargetTab(event);
+ if (window.getComputedStyle(this, null).direction == "ltr") {
+ for (let i = tab ? tab._tPos : 0; i < tabs.length; i++) {
+ let rbound = tabs[i].boxObject.screenX + tabs[i].boxObject.width / 3;
+ let lbound = tabs[i].boxObject.screenX - tabs[i].boxObject.width / 3;
+ if (event.screenX < rbound && event.screenX > lbound)
+ return i;
+ }
+ } else {
+ // FIXME: What's the math for rtl?
+ for (let i = tab ? tab._tPos : 0; i < tabs.length; i++)
+ if (event.screenX > tabs[i].boxObject.screenX + tabs[i].boxObject.width / 3)
+ return i;
+ }
+
+ // Again, we're assuming ltr
+ if (event.screenX > (tabs[tabs.length-1].boxObject.screenX +
+ tabs[tabs.length-1].boxObject.width * 2 / 3))
+ return tabs.length;
+ return -1;
+ ]]></body>
+ </method>
+ </implementation>
+ </binding>
</bindings>
Please sign in to comment.
Something went wrong with that request. Please try again.