1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/toolkit/components/printing/content/printPreviewBindings.xml Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,326 @@ 1.4 +<?xml version="1.0"?> 1.5 + 1.6 +<!-- This Source Code Form is subject to the terms of the Mozilla Public 1.7 + - License, v. 2.0. If a copy of the MPL was not distributed with this 1.8 + - file, You can obtain one at http://mozilla.org/MPL/2.0/. --> 1.9 + 1.10 +<!-- this file depends on printUtils.js --> 1.11 + 1.12 +<!DOCTYPE bindings [ 1.13 +<!ENTITY % printPreviewDTD SYSTEM "chrome://global/locale/printPreview.dtd" > 1.14 +%printPreviewDTD; 1.15 +]> 1.16 + 1.17 +<bindings id="printPreviewBindings" 1.18 + xmlns="http://www.mozilla.org/xbl" 1.19 + xmlns:xul="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul"> 1.20 + 1.21 + <binding id="printpreviewtoolbar" 1.22 + extends="chrome://global/content/bindings/toolbar.xml#toolbar"> 1.23 + <resources> 1.24 + <stylesheet src="chrome://global/skin/printPreview.css"/> 1.25 + </resources> 1.26 + 1.27 + <content> 1.28 + <xul:button label="&print.label;" accesskey="&print.accesskey;" 1.29 + oncommand="PrintUtils.print();" icon="print"/> 1.30 + 1.31 + <xul:button label="&pageSetup.label;" accesskey="&pageSetup.accesskey;" 1.32 + oncommand="this.parentNode.doPageSetup();"/> 1.33 + 1.34 + <xul:vbox align="center" pack="center"> 1.35 + <xul:label value="&page.label;" accesskey="&page.accesskey;" control="pageNumber"/> 1.36 + </xul:vbox> 1.37 + <xul:toolbarbutton class="home-arrow tabbable" 1.38 + oncommand="parentNode.navigate(0, 0, 'home');" tooltiptext="&homearrow.tooltip;"/> 1.39 + <xul:toolbarbutton class="previous-arrow tabbable" 1.40 + oncommand="parentNode.navigate(-1, 0, 0);" tooltiptext="&previousarrow.tooltip;"/> 1.41 + <xul:hbox align="center" pack="center"> 1.42 + <xul:textbox id="pageNumber" size="3" value="1" min="1" type="number" 1.43 + hidespinbuttons="true" onchange="navigate(0, this.valueNumber, 0);"/> 1.44 + <xul:label value="&of.label;"/> 1.45 + <xul:label value="1"/> 1.46 + </xul:hbox> 1.47 + <xul:toolbarbutton class="next-arrow tabbable" 1.48 + oncommand="parentNode.navigate(1, 0, 0);" tooltiptext="&nextarrow.tooltip;"/> 1.49 + <xul:toolbarbutton class="end-arrow tabbable" 1.50 + oncommand="parentNode.navigate(0, 0, 'end');" tooltiptext="&endarrow.tooltip;"/> 1.51 + 1.52 + <xul:toolbarseparator class="toolbarseparator-primary"/> 1.53 + <xul:vbox align="center" pack="center"> 1.54 + <xul:label value="&scale.label;" accesskey="&scale.accesskey;" control="scale"/> 1.55 + </xul:vbox> 1.56 + 1.57 + <xul:hbox align="center" pack="center"> 1.58 + <xul:menulist id="scale" crop="none" 1.59 + oncommand="parentNode.parentNode.scale(this.selectedItem.value);"> 1.60 + <xul:menupopup> 1.61 + <xul:menuitem value="0.3" label="&p30.label;"/> 1.62 + <xul:menuitem value="0.4" label="&p40.label;"/> 1.63 + <xul:menuitem value="0.5" label="&p50.label;"/> 1.64 + <xul:menuitem value="0.6" label="&p60.label;"/> 1.65 + <xul:menuitem value="0.7" label="&p70.label;"/> 1.66 + <xul:menuitem value="0.8" label="&p80.label;"/> 1.67 + <xul:menuitem value="0.9" label="&p90.label;"/> 1.68 + <xul:menuitem value="1" label="&p100.label;"/> 1.69 + <xul:menuitem value="1.25" label="&p125.label;"/> 1.70 + <xul:menuitem value="1.5" label="&p150.label;"/> 1.71 + <xul:menuitem value="1.75" label="&p175.label;"/> 1.72 + <xul:menuitem value="2" label="&p200.label;"/> 1.73 + <xul:menuseparator/> 1.74 + <xul:menuitem flex="1" value="ShrinkToFit" 1.75 + label="&ShrinkToFit.label;"/> 1.76 + <xul:menuitem value="Custom" label="&Custom.label;"/> 1.77 + </xul:menupopup> 1.78 + </xul:menulist> 1.79 + </xul:hbox> 1.80 + 1.81 + <xul:toolbarseparator class="toolbarseparator-primary"/> 1.82 + <xul:hbox align="center" pack="center"> 1.83 + <xul:toolbarbutton label="&portrait.label;" checked="true" 1.84 + accesskey="&portrait.accesskey;" 1.85 + type="radio" group="orient" class="toolbar-portrait-page tabbable" 1.86 + oncommand="parentNode.parentNode.orient('portrait');"/> 1.87 + <xul:toolbarbutton label="&landscape.label;" 1.88 + accesskey="&landscape.accesskey;" 1.89 + type="radio" group="orient" class="toolbar-landscape-page tabbable" 1.90 + oncommand="parentNode.parentNode.orient('landscape');"/> 1.91 + </xul:hbox> 1.92 + 1.93 + <xul:toolbarseparator class="toolbarseparator-primary"/> 1.94 + <xul:button label="&close.label;" accesskey="&close.accesskey;" 1.95 + oncommand="PrintUtils.exitPrintPreview();" icon="close"/> 1.96 + <xul:data value="&customPrompt.title;"/> 1.97 + </content> 1.98 + 1.99 + <implementation> 1.100 + <field name="mPrintButton"> 1.101 + document.getAnonymousNodes(this)[0] 1.102 + </field> 1.103 + <field name="mPageTextBox"> 1.104 + document.getAnonymousNodes(this)[5].childNodes[0] 1.105 + </field> 1.106 + <field name="mTotalPages"> 1.107 + document.getAnonymousNodes(this)[5].childNodes[2] 1.108 + </field> 1.109 + <field name="mScaleLabel"> 1.110 + document.getAnonymousNodes(this)[9].firstChild 1.111 + </field> 1.112 + <field name="mScaleCombobox"> 1.113 + document.getAnonymousNodes(this)[10].firstChild 1.114 + </field> 1.115 + <field name="mOrientButtonsBox"> 1.116 + document.getAnonymousNodes(this)[12] 1.117 + </field> 1.118 + <field name="mPortaitButton"> 1.119 + this.mOrientButtonsBox.childNodes[0] 1.120 + </field> 1.121 + <field name="mLandscapeButton"> 1.122 + this.mOrientButtonsBox.childNodes[1] 1.123 + </field> 1.124 + <field name="mCustomTitle"> 1.125 + document.getAnonymousNodes(this)[15].firstChild 1.126 + </field> 1.127 + <field name="mPrintPreviewObs"> 1.128 + </field> 1.129 + <field name="mWebProgress"> 1.130 + </field> 1.131 + 1.132 + <constructor> 1.133 + <![CDATA[ 1.134 + var print = PrintUtils.getPrintPreview(); 1.135 + this.mTotalPages.value = print.printPreviewNumPages; 1.136 + this.mPageTextBox.max = print.printPreviewNumPages; 1.137 + 1.138 + this.updateToolbar(); 1.139 + ]]> 1.140 + </constructor> 1.141 + 1.142 + <method name="doPageSetup"> 1.143 + <body> 1.144 + <![CDATA[ 1.145 + var didOK = PrintUtils.showPageSetup(); 1.146 + if (didOK) { 1.147 + // the changes that effect the UI 1.148 + this.updateToolbar(); 1.149 + 1.150 + // Now do PrintPreview 1.151 + PrintUtils.printPreview(); 1.152 + } 1.153 + ]]> 1.154 + </body> 1.155 + </method> 1.156 + 1.157 + <method name="navigate"> 1.158 + <parameter name="aDirection"/> 1.159 + <parameter name="aPageNum"/> 1.160 + <parameter name="aHomeOrEnd"/> 1.161 + <body> 1.162 + <![CDATA[ 1.163 + var print = PrintUtils.getPrintPreview(); 1.164 + 1.165 + // we use only one of aHomeOrEnd, aDirection, or aPageNum 1.166 + if (aHomeOrEnd) 1.167 + { 1.168 + var homeOrEnd; 1.169 + if (aHomeOrEnd == "home") 1.170 + { 1.171 + homeOrEnd = print.PRINTPREVIEW_HOME; 1.172 + this.mPageTextBox.value = 1; 1.173 + } 1.174 + else 1.175 + { 1.176 + homeOrEnd = print.PRINTPREVIEW_END; 1.177 + this.mPageTextBox.value = print.printPreviewNumPages; 1.178 + } 1.179 + 1.180 + print.printPreviewNavigate(homeOrEnd, 0); 1.181 + } 1.182 + else if (aDirection) 1.183 + { 1.184 + this.mPageTextBox.valueNumber += aDirection; 1.185 + print.printPreviewNavigate( 1.186 + print.PRINTPREVIEW_GOTO_PAGENUM, 1.187 + this.mPageTextBox.valueNumber); 1.188 + } 1.189 + else 1.190 + { 1.191 + print.printPreviewNavigate( 1.192 + print.PRINTPREVIEW_GOTO_PAGENUM, aPageNum); 1.193 + } 1.194 + ]]> 1.195 + </body> 1.196 + </method> 1.197 + 1.198 + <method name="promptForScaleValue"> 1.199 + <parameter name="aValue"/> 1.200 + <body> 1.201 + <![CDATA[ 1.202 + var value = Math.round(aValue); 1.203 + var promptService = Components.classes["@mozilla.org/embedcomp/prompt-service;1"].getService(Components.interfaces.nsIPromptService); 1.204 + var promptStr = this.mScaleLabel.value; 1.205 + var renameTitle = this.mCustomTitle; 1.206 + var result = {value:value}; 1.207 + var confirmed = promptService.prompt(window, renameTitle, promptStr, result, null, {value:value}); 1.208 + if (!confirmed || (!result.value) || (result.value == "") || result.value == value) { 1.209 + return(-1); 1.210 + } 1.211 + return result.value; 1.212 + ]]> 1.213 + </body> 1.214 + </method> 1.215 + 1.216 + <method name="setScaleCombobox"> 1.217 + <parameter name="aValue"/> 1.218 + <body> 1.219 + <![CDATA[ 1.220 + var scaleValues = [0.3, 0.4, 0.5, 0.6, 0.7, 0.8, 0.9, 1, 1.25, 1.5, 1.75, 2]; 1.221 + 1.222 + aValue = new Number(aValue); 1.223 + 1.224 + for (var i = 0; i < scaleValues.length; i++) { 1.225 + if (aValue == scaleValues[i]) { 1.226 + this.mScaleCombobox.selectedIndex = i; 1.227 + return; 1.228 + } 1.229 + } 1.230 + this.mScaleCombobox.value = "Custom"; 1.231 + ]]> 1.232 + </body> 1.233 + </method> 1.234 + 1.235 + <method name="scale"> 1.236 + <parameter name="aValue"/> 1.237 + <body> 1.238 + <![CDATA[ 1.239 + var settings = PrintUtils.getPrintSettings(); 1.240 + if (aValue == "ShrinkToFit") { 1.241 + if (!settings.shrinkToFit) { 1.242 + settings.shrinkToFit = true; 1.243 + this.savePrintSettings(settings, settings.kInitSaveShrinkToFit | settings.kInitSaveScaling); 1.244 + PrintUtils.printPreview(); 1.245 + } 1.246 + return; 1.247 + } 1.248 + 1.249 + if (aValue == "Custom") { 1.250 + aValue = this.promptForScaleValue(settings.scaling * 100.0); 1.251 + if (aValue >= 10) { 1.252 + aValue /= 100.0; 1.253 + } else { 1.254 + if (this.mScaleCombobox.hasAttribute('lastValidInx')) { 1.255 + this.mScaleCombobox.selectedIndex = this.mScaleCombobox.getAttribute('lastValidInx'); 1.256 + } 1.257 + return; 1.258 + } 1.259 + } 1.260 + 1.261 + this.setScaleCombobox(aValue); 1.262 + this.mScaleCombobox.setAttribute('lastValidInx', this.mScaleCombobox.selectedIndex); 1.263 + 1.264 + if (settings.scaling != aValue || settings.shrinkToFit) 1.265 + { 1.266 + settings.shrinkToFit = false; 1.267 + settings.scaling = aValue; 1.268 + this.savePrintSettings(settings, settings.kInitSaveShrinkToFit | settings.kInitSaveScaling); 1.269 + PrintUtils.printPreview(); 1.270 + } 1.271 + ]]> 1.272 + </body> 1.273 + </method> 1.274 + 1.275 + <method name="orient"> 1.276 + <parameter name="aOrientation"/> 1.277 + <body> 1.278 + <![CDATA[ 1.279 + const kIPrintSettings = Components.interfaces.nsIPrintSettings; 1.280 + var orientValue = (aOrientation == "portrait") ? kIPrintSettings.kPortraitOrientation : 1.281 + kIPrintSettings.kLandscapeOrientation; 1.282 + var settings = PrintUtils.getPrintSettings(); 1.283 + if (settings.orientation != orientValue) 1.284 + { 1.285 + settings.orientation = orientValue; 1.286 + this.savePrintSettings(settings, settings.kInitSaveOrientation); 1.287 + PrintUtils.printPreview(); 1.288 + } 1.289 + ]]> 1.290 + </body> 1.291 + </method> 1.292 + 1.293 + <method name="updateToolbar"> 1.294 + <body> 1.295 + <![CDATA[ 1.296 + var print = PrintUtils.getPrintPreview(); 1.297 + var settings = PrintUtils.getPrintSettings(); 1.298 + 1.299 + var isPortrait = settings.orientation == Components.interfaces.nsIPrintSettings.kPortraitOrientation; 1.300 + 1.301 + this.mPortaitButton.checked = isPortrait; 1.302 + this.mLandscapeButton.checked = !isPortrait; 1.303 + 1.304 + if (settings.shrinkToFit) { 1.305 + this.mScaleCombobox.value = "ShrinkToFit"; 1.306 + } else { 1.307 + this.setScaleCombobox(settings.scaling); 1.308 + } 1.309 + 1.310 + this.mTotalPages.value = print.printPreviewNumPages; 1.311 + this.mPageTextBox.max = print.printPreviewNumPages; 1.312 + this.mPageTextBox.value = 1; 1.313 + ]]> 1.314 + </body> 1.315 + </method> 1.316 + 1.317 + <method name="savePrintSettings"> 1.318 + <parameter name="settings"/> 1.319 + <parameter name="flags"/> 1.320 + <body><![CDATA[ 1.321 + var PSSVC = Components.classes["@mozilla.org/gfx/printsettings-service;1"] 1.322 + .getService(Components.interfaces.nsIPrintSettingsService); 1.323 + PSSVC.savePrintSettingsToPrefs(settings, true, flags); 1.324 + ]]></body> 1.325 + </method> 1.326 + </implementation> 1.327 + </binding> 1.328 + 1.329 +</bindings>