Skip to content

Instantly share code, notes, and snippets.

@Griever
Created September 6, 2009 14:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Griever/181838 to your computer and use it in GitHub Desktop.
Save Griever/181838 to your computer and use it in GitHub Desktop.
<?xml version="1.0"?>
<!DOCTYPE overlay>
<!--
// ==UserScript==
// @name HideTitlebar.uc.xul
// @namespace http://d.hatena.ne.jp/Griever/
// @compatibility Firefox 3.6, 4.0b2pre
// @include main
// @version 7/8
// ==/UserScript==
// @更新履歴
7/8
stopRendering.js を利用させてもらった。
http://piro.sakura.ne.jp/latest/blosxom/mozilla/xul/2009-12-24_stop-rendering.htm
4.0b2pre 用に CSS を修正
5/24
細部を修正
5/14
CSS によるサイドバー右置きに対応
標準の終了ボタン類を条件付きで表示
CSS を調整
ちらつき防止策を試用
12/12
終了ボタン類を付けた
11/26
uc.xul に変更
-->
<?xml-stylesheet href="data:text/css,
@namespace url(http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul);
/* Resizer */
.hideTitlebar-resizer {
-moz-appearance: none !important;
width: 0;
height: 0;
border-width: 0px;
}
window[hidechrome='true'] > .hideTitlebar-resizer[dir='top'],
window[hidechrome='true'] > .hideTitlebar-resizer[dir='bottom'],
window[hidechrome='true'] > #browser > .hideTitlebar-resizer[dir='left'],
window[hidechrome='true'] > #browser > .hideTitlebar-resizer[dir='right']
{
border: solid gray/*InactiveCaption*/;
}
window[hidechrome='true'] > .hideTitlebar-resizer[dir='top'] { border-width: 4px 0 0 0; }
window[hidechrome='true'] > .hideTitlebar-resizer[dir='bottom'] { border-width: 0 0 4px 0; }
window[hidechrome='true'] > #browser > .hideTitlebar-resizer[dir='left'] { border-width: 0 0 0 4px; }
window[hidechrome='true'] > #browser > .hideTitlebar-resizer[dir='right'] { border-width: 0 4px 0 0; }
window[hidechrome='true'] > #browser-bottombox,
window[hidechrome='true'] > #navigator-toolbox
{
-moz-appearance: none !important;
border-width: 0 4px !important;
border-style: solid;
border-color: gray;
}
window[hidechrome='true'][active] > #browser-bottombox,
window[hidechrome='true'][active] > #navigator-toolbox,
window[hidechrome='true'][active] > .hideTitlebar-resizer[dir='top'],
window[hidechrome='true'][active] > .hideTitlebar-resizer[dir='bottom'],
window[hidechrome='true'][active] > #browser > .hideTitlebar-resizer[dir='left'],
window[hidechrome='true'][active] > #browser > .hideTitlebar-resizer[dir='right']
{
-moz-border-top-colors: #222 #555 #666 #222;
-moz-border-bottom-colors: #222 #555 #666 #222;
-moz-border-left-colors: #222 #555 #666 #222;
-moz-border-right-colors: #222 #555 #666 #222;
}
/* Buttons */
#minimize-button2,
#restore-button2,
#fullscreen-button2,
#close-button2 {
list-style-image: url('chrome://global/skin/icons/windowControls.png');
padding: 0px;
-moz-appearance: none !important;
border: none !important;
}
#minimize-button2 { -moz-image-region: rect( 0px, 16px, 16px, 0px); }
#minimize-button2:hover { -moz-image-region: rect(16px, 16px, 32px, 0px); }
#minimize-button2:hover:active { -moz-image-region: rect(32px, 16px, 48px, 0px); }
#restore-button2,
#fullscreen-button2 { -moz-image-region: rect( 0px, 32px, 16px, 16px); }
#restore-button2:hover,
#fullscreen-button2:hover { -moz-image-region: rect(16px, 32px, 32px, 16px); }
#restore-button2:hover:active,
#fullscreen-button2 { -moz-image-region: rect(32px, 32px, 48px, 16px); }
#close-button2 { -moz-image-region: rect( 0px, 48px, 16px, 32px); }
#close-button2:hover { -moz-image-region: rect(16px, 48px, 32px, 32px); }
#close-button2:hover:active { -moz-image-region: rect(32px, 48px, 48px, 32px); }
window[hidechrome='false'] #hideTitlebar-controls,
window[hidechrome='false'] .hideTitlebar-resizer
{ display: none !important; }
#main-window[hidechrome='true'] #toolbar-menubar[inactive='true'][autohide='true']:not([customized='true']) ~ #nav-bar > #fullscreenflex[hidden='true'],
#main-window[hidechrome='true'] #toolbar-menubar[inactive='true'][autohide='true']:not([customized='true']) ~ #nav-bar > #window-controls[hidden='true'] {
display: -moz-box !important;
}
" type="text/css"?>
<overlay id="hideTitlebar_overlay" xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul">
<popupset id="mainPopupSet">
<popup id="toolbar-context-menu">
<menuitem label="タイトルバー表示/非表示" accesskey="T" oncommand="hideTitlebar.toggle();" position="1"/>
<menuseparator position="1"/>
</popup>
<menupopup id="hideTitlebar-popup">
<menuitem label="タイトルバー表示/非表示" accesskey="T" oncommand="hideTitlebar.toggle();"/>
<menuitem command="cmd_CustomizeToolbars" label="カスタマイズ..." accesskey="C"/>
<menuseparator/>
<menuitem label="最小化" accesskey="N" oncommand="window.minimize();"/>
<menuitem label="最大化/元に戻す" accesskey="X" oncommand="window.windowState == window.STATE_MAXIMIZED ? window.restore() : window.maximize();"/>
<menuitem label="全画面表示" accesskey="F" oncommand="BrowserFullScreen();"/>
<menu label="リサイズ/移動" accesskey="S">
<menupopup>
<menuitem label="640*480" oncommand="window.resizeTo(640, 480);"/>
<menuitem label="800*600" oncommand="window.resizeTo(800, 600);"/>
<menuitem label="1024*768" oncommand="window.resizeTo(1024, 768);"/>
<menuitem label="1280*1024" oncommand="window.resizeTo(1280, 1024);"/>
<menuitem label="画面いっぱいに拡大" oncommand="if(window.windowState == window.STATE_MAXIMIZED) window.restore(); window.moveTo(screen.availLeft, screen.availTop); window.resizeTo(screen.availWidth, screen.availHeight);"/>
<menuitem label="画面左上に移動" oncommand="if(window.windowState == window.STATE_MAXIMIZED) window.restore(); window.moveTo(screen.availLeft, screen.availTop);"/>
<menuitem label="画面右上に移動" oncommand="if(window.windowState == window.STATE_MAXIMIZED) window.restore(); window.moveTo(screen.width - window.outerWidth, screen.availTop);"/>
</menupopup>
</menu>
<menuitem label="再起動" accesskey="R" oncommand="Application.restart();"/>
<menuitem label="終了" accesskey="C" oncommand="BrowserTryToCloseWindow();"/>
</menupopup>
</popupset>
<toolbar id="toolbar-menubar">
<hbox flex="1" context="hideTitlebar-popup"/>
<hbox hidden="false" id="hideTitlebar-controls" context="hideTitlebar-popup" onmousedown="hideTitlebar.move(event);">
<toolbarbutton id="minimize-button2" tooltiptext="最小化" oncommand="window.minimize();"/>
<toolbarbutton id="fullscreen-button2" tooltiptext="フルスクリーン" oncommand="BrowserFullScreen();"/>
<!--
<toolbarbutton id="restore-button2" tooltiptext="最大化/元に戻す" oncommand="window.windowState == window.STATE_MAXIMIZED ? window.restore() : window.maximize();"/>
-->
<toolbarbutton id="close-button2" tooltiptext="閉じる" oncommand="BrowserTryToCloseWindow();"/>
</hbox>
</toolbar>
<hbox id="window-controls" onmousedown="hideTitlebar.move(event);" context="hideTitlebar-popup"/>
<!-- リサイザー -->
<window id="main-window">
<resizer class="hideTitlebar-resizer" dir="top" position="1"/>
<resizer class="hideTitlebar-resizer" dir="bottom"/>
</window>
<hbox id="browser">
<resizer class="hideTitlebar-resizer" dir="left" position="1" onmouseover="this.setAttribute('dir', getComputedStyle(document.getElementById('browser'), null).direction == 'rtl'? 'right' : 'left');"/>
<resizer class="hideTitlebar-resizer" dir="right" onmouseover="this.setAttribute('dir', getComputedStyle(document.getElementById('browser'), null).direction == 'rtl'? 'left' : 'right');"/>
</hbox>
<script type="application/x-javascript" xmlns="http://www.w3.org/1999/xhtml"><![CDATA[
/*
Stop Rendering Library
Usage:
window['piro.sakura.ne.jp'].stopRendering.stop();
// do something
window['piro.sakura.ne.jp'].stopRendering.start();
lisence: The MIT License, Copyright (c) 2009-2010 SHIMODA "Piro" Hiroshi
http://www.cozmixng.org/repos/piro/fx3-compatibility-lib/trunk/license.txt
original:
http://www.cozmixng.org/repos/piro/fx3-compatibility-lib/trunk/stopRendering.js
*/
(function() {
const currentRevision = 7;
if (!('piro.sakura.ne.jp' in window)) window['piro.sakura.ne.jp'] = {};
var loadedRevision = 'stopRendering' in window['piro.sakura.ne.jp'] ?
window['piro.sakura.ne.jp'].stopRendering.revision :
0 ;
if (loadedRevision && loadedRevision > currentRevision) {
return;
}
if (loadedRevision &&
'destroy' in window['piro.sakura.ne.jp'].stopRendering)
window['piro.sakura.ne.jp'].stopRendering.destroy();
const Cc = Components.classes;
const Ci = Components.interfaces;
window['piro.sakura.ne.jp'].stopRendering = {
revision : currentRevision,
_stopLevel : 0,
_listening : false,
get baswWindow()
{
return window.top
.QueryInterface(Ci.nsIInterfaceRequestor)
.getInterface(Ci.nsIWebNavigation)
.QueryInterface(Ci.nsIDocShell)
.QueryInterface(Ci.nsIBaseWindow);
},
stop : function()
{
if (this.useCanvas) {
this.showCanvas();
}
else {
this.baswWindow.setPosition(window.top.innerWidth * 3, window.top.innerHeight * 3);
if (!this._listening) {
window.addEventListener('mousedown', this, true);
this._listening = true;
}
}
this._stopLevel++;
},
start : function()
{
this._stopLevel--;
if (this._stopLevel > 0)
return;
if (this._listening) {
window.removeEventListener('mousedown', this, true);
this._listening = false;
}
this._stopLevel = 0;
if (this.useCanvas) {
this.hideCanvas();
}
else {
this.baswWindow.setPosition(0, 0);
this._popups.forEach(function(aPopup, aIndex) {
if (aPopup.state != 'open') return;
var w = aPopup.boxObject.width;
var h = aPopup.boxObject.height;
var hasWidth = aPopup.hasAttribute('width');
var hasHeight = aPopup.hasAttribute('height');
aPopup.sizeTo(w, h-1);
aPopup.sizeTo(w, h);
if (!hasWidth || !hasHeight)
window.setTimeout(function() {
if (!hasWidth)
aPopup.removeAttribute('width');
if (!hasHeight)
aPopup.removeAttribute('height');
}, 0);
}, this);
}
},
onResize : function(aEvent)
{
if (aEvent.target != window || !this._stopLevel)
return;
this._stopLevel = 0;
this.start();
},
handleEvent : function(aEvent)
{
switch (aEvent.type)
{
case 'unload':
this.destroy();
return;
case 'resize':
this.onResize(aEvent);
return;
case 'popupshown':
let (index = this._popups.indexOf(aEvent.originalTarget)) {
if (index < 0)
this._popups.push(aEvent.originalTarget);
}
return;
case 'popuphidden':
let (index = this._popups.indexOf(aEvent.originalTarget)) {
if (index > -1)
this._popups.splice(index, 1);
}
return;
case 'mousedown':
this._stopLevel = 0;
this.hideCanvas();
aEvent.stopPropagation();
aEvent.preventDefault();
return;
}
},
init : function()
{
if (this.useCanvas) {
this.initCanvas();
}
else {
this._popups = [];
window.addEventListener('popupshown', this, false);
window.addEventListener('popuphidden', this, false);
}
window.addEventListener('resize', this, false);
window.addEventListener('unload', this, false);
},
destroy : function()
{
if (this.useCanvas) {
this.destroyCanvas();
}
else {
this._popups = [];
window.removeEventListener('popupshown', this, false);
window.removeEventListener('popuphidden', this, false);
}
window.removeEventListener('resize', this, false);
window.removeEventListener('unload', this, false);
},
// full screen canvas
useCanvas : (function() {
const XULAppInfo = Cc['@mozilla.org/xre/app-info;1']
.getService(Ci.nsIXULAppInfo);
const comparator = Cc['@mozilla.org/xpcom/version-comparator;1']
.getService(Ci.nsIVersionComparator);
return comparator.compare(XULAppInfo.version, '3.6.9999') > 0;
})(),
DRAW_WINDOW_FLAGS : Ci.nsIDOMCanvasRenderingContext2D.DRAWWINDOW_DRAW_VIEW |
Ci.nsIDOMCanvasRenderingContext2D.DRAWWINDOW_DRAW_CARET |
Ci.nsIDOMCanvasRenderingContext2D.DRAWWINDOW_DO_NOT_FLUSH,
DRAW_WINDOW_BGCOLOR : 'transparent',
showCanvas : function()
{
if (this.shown) return;
var canvas = this.canvas;
if (!canvas) return;
this.shown = true;
var rootBox = document.documentElement.boxObject;
var canvasW = window.innerWidth;
var canvasH = window.innerHeight;
var x = 0,
y = 0,
w = canvasW,
h = canvasH;
canvas.style.width = (canvas.width = canvasW)+'px';
canvas.style.height = (canvas.height = canvasH)+'px';
try {
var ctx = canvas.getContext('2d');
ctx.clearRect(0, 0, canvasW, canvasH);
ctx.save();
ctx.translate(x, y);
ctx.drawWindow(window, x, y, w, h, this.DRAW_WINDOW_BGCOLOR, this.DRAW_WINDOW_FLAGS);
ctx.restore();
this.browsers.forEach(function(aBrowser) {
try {
var b = aBrowser;
if (b.localName == 'subbrowser') b = b.browser;
var frame = b.contentWindow;
var box = (b.localName == 'tabbrowser' ? b.mCurrentBrowser : b ).boxObject;
var x = box.x;
var y = box.y;
var bw = box.width;
var bh = box.height;
var w = frame.innerWidth;
var h = frame.innerHeight;
ctx.save();
ctx.translate(x, y);
ctx.scale(bw / w, bh / h);
ctx.drawWindow(frame, 0, 0, w, h, this.DRAW_WINDOW_BGCOLOR, this.DRAW_WINDOW_FLAGS);
ctx.restore();
}
catch(e) {
}
}, this);
document.documentElement.setAttribute('fullScreenCanvas-state', 'shown');
}
catch(e) {
this.hideCanvas();
}
},
shown : false,
hideCanvas : function()
{
if (!this.shown) return;
document.documentElement.removeAttribute('fullScreenCanvas-state');
this.shown = false;
},
get browsers()
{
browsers = [].concat(Array.slice(document.getElementsByTagName('tabbrowser')))
.concat(Array.slice(document.getElementsByTagName('browser')));
if ('SplitBrowser' in window) browsers = browsers.concat(SplitBrowser.browsers);
return browsers;
},
initCanvas : function()
{
var canvas = document.createElementNS('http://www.w3.org/1999/xhtml', 'canvas');
canvas.setAttribute('id', 'fullScreenCanvas-canvas');
canvas.setAttribute('width', '0');
canvas.setAttribute('height', '0');
canvas.setAttribute('style', 'width:0;height:0;');
this.canvas = canvas;
var style = document.createElementNS('http://www.w3.org/1999/xhtml', 'style');
style.setAttribute('id', 'fullScreenCanvas-style');
style.setAttribute('type', 'text/css');
style.appendChild(document.createTextNode([
':root[fullScreenCanvas-state="shown"] > *:not(#fullScreenCanvas-box) {',
' visibility: hidden !important;',
'}',
'#fullScreenCanvas-style {',
' display: none;',
'}',
'#fullScreenCanvas-box {',
' position: fixed;',
' z-index: 65000;',
' top: 0;',
' left: 0;',
' visibility: collapse;',
'}',
':root[fullScreenCanvas-state="shown"] > #fullScreenCanvas-box {',
' visibility: visible;',
'}'
].join('')));
this.style = style;
var stylePI = document.createProcessingInstruction(
'xml-stylesheet',
'type="text/css" href="#fullScreenCanvas-style"'
);
this.stylePI = stylePI;
var box = document.createElement('box');
box.setAttribute('id', 'fullScreenCanvas-box');
box.setAttribute('onmousedown', 'window["piro.sakura.ne.jp"].stopRendering.handleEvent(event);');
this.box = box;
box.appendChild(canvas);
box.appendChild(style);
document.documentElement.appendChild(box);
document.insertBefore(stylePI, document.documentElement);
},
destroyCanvas : function()
{
document.documentElement.removeChild(this.box);
document.removeChild(this.stylePI);
this.box = null;
this.canvas = null;
this.style = null;
this.stylePI = null;
}
};
window['piro.sakura.ne.jp'].stopRendering.init();
})();
var hideTitlebar = {
hidechrome : function(bool){
window['piro.sakura.ne.jp'].stopRendering.stop();
document.documentElement.setAttribute('hidechrome', bool);
window.outerHeight--;
window.outerHeight++;
window['piro.sakura.ne.jp'].stopRendering.start();
},
toggle : function(){
this.hidechrome(document.documentElement.getAttribute('hidechrome') != 'true');
},
move : function(event){
if ( (event.ctrlKey || event.button == 1) && window.windowState == window.STATE_NORMAL && !window.fullScreen){
event.preventDefault();
event.stopPropagation();
this.x = event.screenX;
this.y = event.screenY;
this.sx = window.screenX;
this.sy = window.screenY;
document.addEventListener('mousemove', this, true);
document.addEventListener('mouseup', this, true);
}
},
handleEvent : function(event){
event.preventDefault();
event.stopPropagation();
switch(event.type){
case 'mousemove':
window.moveTo(event.screenX - this.x + this.sx, event.screenY - this.y + this.sy);
break;
case 'mouseup':
document.removeEventListener('mousemove', this, true);
document.removeEventListener('mouseup', this, true);
this.x = this.y = this.sx = this.sy = null;
break;
}
}
};
document.getElementById('mainPopupSet').height = 0;
hideTitlebar.hidechrome(true);
]]></script>
</overlay>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment