Bug 398388 - XUL numberboxes for the Print Preview. r=gavin
authorKUROSAWA, Takeshi <taken.spc@gmail.com>
Tue, 29 Sep 2009 21:18:20 +0200
changeset 33273 fcf5834e1b6aacb9de0cbb531c6207583ab9e442
parent 33272 df6c8194f8c7d81eca66ffb1b9702dde820daf82
child 33274 7f98f7dd1044708d7f7a9431f4c15f530a120c87
push idunknown
push userunknown
push dateunknown
reviewersgavin
bugs398388
milestone1.9.3a1pre
Bug 398388 - XUL numberboxes for the Print Preview. r=gavin
toolkit/components/printing/content/printPreviewBindings.xml
--- a/toolkit/components/printing/content/printPreviewBindings.xml
+++ b/toolkit/components/printing/content/printPreviewBindings.xml
@@ -64,18 +64,18 @@
       <xul:vbox align="center" pack="center">
         <xul:label value="&page.label;" accesskey="&page.accesskey;" control="pageNumber"/>
       </xul:vbox>
       <xul:toolbarbutton class="home-arrow tabbable"
         oncommand="parentNode.navigate(0, 0, 'home');" tooltiptext="&homearrow.tooltip;"/>
       <xul:toolbarbutton class="left-arrow tabbable"
         oncommand="parentNode.navigate(-1, 0, 0);" tooltiptext="&leftarrow.tooltip;"/>
       <xul:hbox align="center" pack="center">
-        <xul:textbox id="pageNumber" size="3" value="1" lastvalid="1"
-          onchange="navigate(0, this.value, 0);"/>
+        <xul:textbox id="pageNumber" size="3" value="1" min="1" type="number"
+          hidespinbuttons="true" onchange="navigate(0, this.valueNumber, 0);"/>
         <xul:label value="&of.label;"/>
         <xul:label value="1"/>
       </xul:hbox>
       <xul:toolbarbutton class="right-arrow tabbable"
         oncommand="parentNode.navigate(1, 0, 0);" tooltiptext="&rightarrow.tooltip;"/>
       <xul:toolbarbutton class="end-arrow tabbable"
         oncommand="parentNode.navigate(0, 0, 'end');" tooltiptext="&endarrow.tooltip;"/>
 
@@ -158,16 +158,17 @@
       </field>
       <field name="mWebProgress">
       </field>
      
       <constructor>
       <![CDATA[
         var print = PrintUtils.getWebBrowserPrint();
         this.mTotalPages.value = print.printPreviewNumPages;
+        this.mPageTextBox.max = print.printPreviewNumPages;
 
         this.updateToolbar();
 
         // Hide the ``Print...'' button when the underlying gfx code does not
         // support multiple devicecontext to be used concurrently
         // (e.g. printing and printpreview at the same time; required as 
         // legacy support for unices.'s PostScript module
         // XXX the scaling widgets, and the orientation widgets on unices.
@@ -231,18 +232,16 @@
 
       <method name="navigate">
         <parameter name="aDirection"/>
         <parameter name="aPageNum"/>
         <parameter name="aHomeOrEnd"/>
         <body>
         <![CDATA[          
           var print = PrintUtils.getWebBrowserPrint();
-          var validInput = false;
-          var total;
 
           // we use only one of aHomeOrEnd, aDirection, or aPageNum
           if (aHomeOrEnd)
           {
             var homeOrEnd;
             if (aHomeOrEnd == "home")
             {
               homeOrEnd = print.PRINTPREVIEW_HOME;
@@ -250,58 +249,28 @@
             }
             else
             {
               homeOrEnd = print.PRINTPREVIEW_END;
               this.mPageTextBox.value = print.printPreviewNumPages;
             }
             
             print.printPreviewNavigate(homeOrEnd, 0);
-            validInput = true;
           }
           else if (aDirection)
           {
-            var textBoxStr  = this.mPageTextBox.value;
-            var newPageNum  = parseInt(textBoxStr) + aDirection;
-            total = print.printPreviewNumPages;
-
-            // bounds check potentially user-entered number
-            if (newPageNum > 0 && newPageNum <= total) 
-            {
-              this.mPageTextBox.value = newPageNum;
-              print.printPreviewNavigate(
-                print.PRINTPREVIEW_GOTO_PAGENUM, newPageNum);
-              validInput = true;
-            }
+            this.mPageTextBox.valueNumber += aDirection;
+            print.printPreviewNavigate(
+              print.PRINTPREVIEW_GOTO_PAGENUM,
+              this.mPageTextBox.valueNumber);
           }
           else 
           {
-            total = print.printPreviewNumPages;
-
-            // bounds check potentially user-entered number
-            if (aPageNum > 0 && aPageNum <= total) 
-            {
-              print.printPreviewNavigate(
-                print.PRINTPREVIEW_GOTO_PAGENUM, aPageNum);
-              validInput = true;
-            }
-          }
-
-          if (validInput)          
-          {
-            // store the valid page number for future use to replace 
-            // the textbox value if erroneous input made it in
-            this.mPageTextBox.setAttribute(
-              "lastvalid", this.mPageTextBox.value);
-          }
-          else
-          { 
-            // restore last known valid value in place of erroneous input
-            this.mPageTextBox.value = 
-              this.mPageTextBox.getAttribute("lastvalid");
+            print.printPreviewNavigate(
+              print.PRINTPREVIEW_GOTO_PAGENUM, aPageNum);
           }
         ]]>
         </body>
       </method>
 
       <method name="promptForScaleValue">
         <parameter name="aValue"/>
         <body>
@@ -408,16 +377,17 @@
 
           if (settings.shrinkToFit) {
             this.mScaleCombobox.value = "ShrinkToFit";
           } else {
             this.setScaleCombobox(settings.scaling);
           }
 
           this.mTotalPages.value = print.printPreviewNumPages;
+          this.mPageTextBox.max = print.printPreviewNumPages;
           this.mPageTextBox.value = 1;
         ]]>
         </body>
       </method>
 
       <method name="savePrintSettings">
         <parameter name="settings"/>
         <parameter name="flags"/>