Browse Source

Only show move/drag button when clipping. Cleanup.

Cleanup:

- remove unused changeViewportMeta function from include/ui.js
- remove some debug output and debug CSS.
- rename panel toggle functions and put them in same location in the
  code.
- refactor some code from updateState to updateVisualState routine
  (renamed from updateSettingsState).
Joel Martin 14 years ago
parent
commit
c506a48154
4 changed files with 90 additions and 104 deletions
  1. 0 4
      include/base.css
  2. 0 3
      include/display.js
  3. 85 92
      include/ui.js
  4. 5 5
      vnc.html

+ 0 - 4
include/base.css

@@ -286,7 +286,6 @@ html {
 }
 }
 #noVNC_clipboard_text {
 #noVNC_clipboard_text {
   width: 500px;
   width: 500px;
-  border-color: red;
 }
 }
 
 
 #noVNC_logo {
 #noVNC_logo {
@@ -300,7 +299,6 @@ html {
   }
   }
   #noVNC_clipboard_text {
   #noVNC_clipboard_text {
     width: 410px;
     width: 410px;
-    border-color: yellow;
   }
   }
   #noVNC_logo {
   #noVNC_logo {
     font-size: 150px;
     font-size: 150px;
@@ -314,7 +312,6 @@ html {
   }
   }
   #noVNC_clipboard_text {
   #noVNC_clipboard_text {
     width: 250px;
     width: 250px;
-    border-color: green;
   }
   }
   #noVNC_logo {
   #noVNC_logo {
     font-size: 110px;
     font-size: 110px;
@@ -328,7 +325,6 @@ html {
   }
   }
   #noVNC_clipboard_text {
   #noVNC_clipboard_text {
     width: 220px;
     width: 220px;
-    border-color: blue;
   }
   }
   #noVNC_logo {
   #noVNC_logo {
     font-size: 90px;
     font-size: 90px;

+ 0 - 3
include/display.js

@@ -279,9 +279,6 @@ that.viewportChange = function(deltaX, deltaY, width, height) {
 
 
 
 
         if (v.w > 0 && v.h > 0 && c.width > 0 && c.height > 0) {
         if (v.w > 0 && v.h > 0 && c.width > 0 && c.height > 0) {
-            console.log("here1:",
-                    ((c.width < v.w) ? c.width : v.w),
-                    ((c.height < v.h) ? c.height : v.h));
             saveImg = c_ctx.getImageData(0, 0,
             saveImg = c_ctx.getImageData(0, 0,
                     (c.width < v.w) ? c.width : v.w,
                     (c.width < v.w) ? c.width : v.w,
                     (c.height < v.h) ? c.height : v.h);
                     (c.height < v.h) ? c.height : v.h);

+ 85 - 92
include/ui.js

@@ -56,7 +56,7 @@ load: function() {
     UI.rfb = RFB({'target': $D('noVNC_canvas'),
     UI.rfb = RFB({'target': $D('noVNC_canvas'),
                   'onUpdateState': UI.updateState,
                   'onUpdateState': UI.updateState,
                   'onClipboard': UI.clipReceive});
                   'onClipboard': UI.clipReceive});
-    UI.updateSettingsState(false);
+    UI.updateVisualState();
  
  
     // Unfocus clipboard when over the VNC area
     // Unfocus clipboard when over the VNC area
     //$D('VNC_screen').onmousemove = function () {
     //$D('VNC_screen').onmousemove = function () {
@@ -178,10 +178,53 @@ initSetting: function(name, defVal) {
 },
 },
 
 
 
 
+// Show the clipboard panel
+toggleClipboardPanel: function() {
+    //Close settings if open
+    if (UI.settingsOpen == true) {
+        UI.settingsApply();
+        UI.closeSettingsMenu();
+    }
+    //Close connection settings if open
+    if (UI.connSettingsOpen == true) {
+        UI.toggleConnectPanel();
+    }
+    //Toggle Clipboard Panel
+    if (UI.clipboardOpen == true) {
+        $D('noVNC_clipboard').style.display = "none";
+        UI.clipboardOpen = false;
+    } else {
+        $D('noVNC_clipboard').style.display = "block";
+        UI.clipboardOpen = true;
+    }
+},
+
+// Show the connection settings panel/menu
+toggleConnectPanel: function() {
+    //Close connection settings if open
+    if (UI.settingsOpen == true) {
+        UI.settingsApply();
+        UI.closeSettingsMenu();
+    }
+    if (UI.clipboardOpen == true) {
+        UI.toggleClipboardPanel(); 
+    } 
+
+    //Toggle Connection Panel
+    if (UI.connSettingsOpen == true) {
+        $D('noVNC_controls').style.display = "none";
+        UI.connSettingsOpen = false;
+    } else {
+        $D('noVNC_controls').style.display = "block";
+        UI.connSettingsOpen = true;
+        $D('noVNC_host').focus();
+    }
+},
+
 // Toggle the settings menu:
 // Toggle the settings menu:
 //   On open, settings are refreshed from saved cookies.
 //   On open, settings are refreshed from saved cookies.
 //   On close, settings are applied
 //   On close, settings are applied
-clickSettingsMenu: function() {
+toggleSettingsPanel: function() {
     if (UI.settingsOpen) {
     if (UI.settingsOpen) {
         UI.settingsApply();
         UI.settingsApply();
         UI.closeSettingsMenu();
         UI.closeSettingsMenu();
@@ -207,11 +250,11 @@ clickSettingsMenu: function() {
 // Open menu
 // Open menu
 openSettingsMenu: function() {
 openSettingsMenu: function() {
     if (UI.clipboardOpen == true) {
     if (UI.clipboardOpen == true) {
-        UI.showClipboard(); 
+        UI.toggleClipboardPanel(); 
     } 
     } 
     //Close connection settings if open
     //Close connection settings if open
     if (UI.connSettingsOpen == true) {
     if (UI.connSettingsOpen == true) {
-        UI.connectPanelbutton();
+        UI.toggleConnectPanel();
     }
     }
     $D('noVNC_settings').style.display = "block";
     $D('noVNC_settings').style.display = "block";
     UI.settingsOpen = true;
     UI.settingsOpen = true;
@@ -241,6 +284,7 @@ settingsApply: function() {
     WebUtil.selectStylesheet(UI.getSetting('stylesheet'));
     WebUtil.selectStylesheet(UI.getSetting('stylesheet'));
     WebUtil.init_logging(UI.getSetting('logging'));
     WebUtil.init_logging(UI.getSetting('logging'));
     UI.setViewClip();
     UI.setViewClip();
+    UI.setViewDrag(UI.rfb.get_viewportDrag());
     //Util.Debug("<< settingsApply");
     //Util.Debug("<< settingsApply");
 },
 },
 
 
@@ -252,7 +296,7 @@ setPassword: function() {
     $D('noVNC_connect_button').value = "Connect";
     $D('noVNC_connect_button').value = "Connect";
     $D('noVNC_connect_button').onclick = UI.Connect;
     $D('noVNC_connect_button').onclick = UI.Connect;
     //Hide connection panel.
     //Hide connection panel.
-    UI.connectPanelbutton();
+    UI.toggleConnectPanel();
     return false;
     return false;
 },
 },
 
 
@@ -292,47 +336,29 @@ updateState: function(rfb, state, oldstate, msg) {
     UI.rfb_state = state;
     UI.rfb_state = state;
     s = $D('noVNC_status');
     s = $D('noVNC_status');
     sb = $D('noVNC_status_bar');
     sb = $D('noVNC_status_bar');
-    c = $D('connectPanelbutton');
-    d = $D('disconnectButton');
     switch (state) {
     switch (state) {
         case 'failed':
         case 'failed':
         case 'fatal':
         case 'fatal':
-            c.style.display = "";
-            d.style.display = "none";
-            UI.updateSettingsState(false);
             klass = "noVNC_status_error";
             klass = "noVNC_status_error";
             break;
             break;
         case 'normal':
         case 'normal':
-            c.style.display = "none";
-            d.style.display = "";
-            UI.updateSettingsState(true);
             klass = "noVNC_status_normal";
             klass = "noVNC_status_normal";
             break;
             break;
         case 'disconnected':
         case 'disconnected':
             $D('noVNC_logo').style.display = "block";
             $D('noVNC_logo').style.display = "block";
         case 'loaded':
         case 'loaded':
-            //c.value = "Connection";
-            c.style.display = "";
-            d.style.display = "none";
-            UI.updateSettingsState(false);
             klass = "noVNC_status_normal";
             klass = "noVNC_status_normal";
             break;
             break;
         case 'password':
         case 'password':
-            UI.connectPanelbutton();
+            UI.toggleConnectPanel();
 
 
             $D('noVNC_connect_button').value = "Send Password";
             $D('noVNC_connect_button').value = "Send Password";
             $D('noVNC_connect_button').onclick = UI.setPassword;
             $D('noVNC_connect_button').onclick = UI.setPassword;
             $D('noVNC_password').focus();
             $D('noVNC_password').focus();
 
 
-            c.style.display = "none";
-            d.style.display = "";
-            UI.updateSettingsState(false);
             klass = "noVNC_status_warn";
             klass = "noVNC_status_warn";
             break;
             break;
         default:
         default:
-            c.style.display = "none";
-            d.style.display = "";
-            UI.updateSettingsState(false);
             klass = "noVNC_status_warn";
             klass = "noVNC_status_warn";
             break;
             break;
     }
     }
@@ -343,12 +369,14 @@ updateState: function(rfb, state, oldstate, msg) {
         s.innerHTML = msg;
         s.innerHTML = msg;
     }
     }
 
 
+    UI.updateVisualState();
 },
 },
 
 
 // Disable/enable controls depending on connection state
 // Disable/enable controls depending on connection state
-updateSettingsState: function(connected) {
+updateVisualState: function() {
+    var connected = UI.rfb_state === 'normal' ? true : false;
 
 
-    //Util.Debug(">> updateSettingsState");
+    //Util.Debug(">> updateVisualState");
     $D('noVNC_encrypt').disabled = connected;
     $D('noVNC_encrypt').disabled = connected;
     $D('noVNC_true_color').disabled = connected;
     $D('noVNC_true_color').disabled = connected;
     if (UI.rfb && UI.rfb.get_display() &&
     if (UI.rfb && UI.rfb.get_display() &&
@@ -365,17 +393,29 @@ updateSettingsState: function(connected) {
         UI.setViewClip();
         UI.setViewClip();
         UI.setMouseButton(1);
         UI.setMouseButton(1);
         $D('sendCtrlAltDelButton').style.display = "inline";
         $D('sendCtrlAltDelButton').style.display = "inline";
-        $D('noVNC_view_drag_button').style.display = "inline";
     } else {
     } else {
         UI.setMouseButton();
         UI.setMouseButton();
         $D('sendCtrlAltDelButton').style.display = "none";
         $D('sendCtrlAltDelButton').style.display = "none";
-        $D('noVNC_view_drag_button').style.display = "none";
     }
     }
-
     // State change disables viewport dragging.
     // State change disables viewport dragging.
     // It is enabled (toggled) by direct click on the button
     // It is enabled (toggled) by direct click on the button
     UI.setViewDrag(false);
     UI.setViewDrag(false);
-    //Util.Debug("<< updateSettingsState");
+
+    switch (UI.rfb_state) {
+        case 'fatal':
+        case 'failed':
+        case 'loaded':
+        case 'disconnected':
+            $D('connectButton').style.display = "";
+            $D('disconnectButton').style.display = "none";
+            break;
+        default:
+            $D('connectButton').style.display = "none";
+            $D('disconnectButton').style.display = "";
+            break;
+    }
+
+    //Util.Debug("<< updateVisualState");
 },
 },
 
 
 
 
@@ -390,7 +430,7 @@ connect: function() {
     var host, port, password;
     var host, port, password;
 
 
     UI.closeSettingsMenu();
     UI.closeSettingsMenu();
-    UI.connectPanelbutton();
+    UI.toggleConnectPanel();
 
 
     host = $D('noVNC_host').value;
     host = $D('noVNC_host').value;
     port = $D('noVNC_port').value;
     port = $D('noVNC_port').value;
@@ -417,7 +457,7 @@ disconnect: function() {
 
 
     $D('noVNC_logo').style.display = "block";
     $D('noVNC_logo').style.display = "block";
     UI.connSettingsOpen = false;
     UI.connSettingsOpen = false;
-    UI.connectPanelbutton();
+    UI.toggleConnectPanel();
 },
 },
 
 
 displayBlur: function() {
 displayBlur: function() {
@@ -442,26 +482,8 @@ clipSend: function() {
     Util.Debug("<< UI.clipSend");
     Util.Debug("<< UI.clipSend");
 },
 },
 
 
-showClipboard: function() {
-    //Close settings if open
-    if (UI.settingsOpen == true) {
-        UI.settingsApply();
-        UI.closeSettingsMenu();
-    }
-    //Close connection settings if open
-    if (UI.connSettingsOpen == true) {
-        UI.connectPanelbutton();
-    }
-    //Toggle Connection Panel
-    if (UI.clipboardOpen == true) {
-        $D('noVNC_clipboard').style.display = "none";
-        UI.clipboardOpen = false;
-    } else {
-        $D('noVNC_clipboard').style.display = "block";
-        UI.clipboardOpen = true;
-    }
-},
 
 
+// Enable/disable and configure viewport clipping
 setViewClip: function(clip) {
 setViewClip: function(clip) {
     var display, cur_clip, pos, new_w, new_h;
     var display, cur_clip, pos, new_w, new_h;
 
 
@@ -473,11 +495,12 @@ setViewClip: function(clip) {
 
 
     cur_clip = display.get_viewport();
     cur_clip = display.get_viewport();
 
 
-    if (typeof(clip) === 'undefined') {
+    if (typeof(clip) !== 'undefined') {
         // Nothing
         // Nothing
         clip = UI.getSetting('clip');
         clip = UI.getSetting('clip');
     }
     }
 
 
+    console.log("clip:" + clip + " cur_clip: " + cur_clip);
     if (clip && !cur_clip) {
     if (clip && !cur_clip) {
         // Turn clipping on
         // Turn clipping on
         UI.updateSetting('clip', true);
         UI.updateSetting('clip', true);
@@ -499,10 +522,18 @@ setViewClip: function(clip) {
     }
     }
 },
 },
 
 
+// Toggle/set/unset the viewport drag/move button
 setViewDrag: function(drag) {
 setViewDrag: function(drag) {
     var vmb = $D('noVNC_view_drag_button');
     var vmb = $D('noVNC_view_drag_button');
     if (!UI.rfb) { return; }
     if (!UI.rfb) { return; }
 
 
+    if (UI.rfb_state === 'normal' &&
+        UI.rfb.get_display().get_viewport()) {
+        $D('noVNC_view_drag_button').style.display = "inline";
+    } else {
+        $D('noVNC_view_drag_button').style.display = "none";
+    }
+
     if (typeof(drag) === "undefined") {
     if (typeof(drag) === "undefined") {
         // If not specified, then toggle
         // If not specified, then toggle
         drag = !UI.rfb.get_viewportDrag();
         drag = !UI.rfb.get_viewportDrag();
@@ -518,30 +549,13 @@ setViewDrag: function(drag) {
     }
     }
 },
 },
 
 
+// On touch devices, show the OS keyboard
 showKeyboard: function() {
 showKeyboard: function() {
     $D('keyboardinput').focus();
     $D('keyboardinput').focus();
 },
 },
 
 
 
 
-changeViewportMeta: function (newattributes) {
-
-    // First, get the array of meta-tag elements
-    var metatags = document.getElementsByTagName("meta");
-
-    // Update only the Viewport meta tag
-    for (var cnt = 0; cnt < metatags.length; cnt++)
-    {
-        var name = metatags[cnt].getAttribute("name");
-        var content = metatags[cnt].getAttribute("content");
-
-        // Update the Viewport meta tag
-        if (metatags[cnt].getAttribute("name") == "viewport") {
-            metatags[cnt].setAttribute("content", newattributes);
-        }
-    }
-},
-
-//iOS < Version 5 does not support position fixed. Javascript workaround:
+// iOS < Version 5 does not support position fixed. Javascript workaround:
 setOnscroll: function() {
 setOnscroll: function() {
     window.onscroll = function() {
     window.onscroll = function() {
         UI.setBarPosition();
         UI.setBarPosition();
@@ -569,27 +583,6 @@ setBarPosition: function() {
     
     
     var vncwidth = $D('noVNC_screen').style.offsetWidth;
     var vncwidth = $D('noVNC_screen').style.offsetWidth;
     $D('noVNC-control-bar').style.width = vncwidth + 'px';
     $D('noVNC-control-bar').style.width = vncwidth + 'px';
-},
-
-connectPanelbutton: function() {
-    //Close connection settings if open
-    if (UI.settingsOpen == true) {
-        UI.settingsApply();
-        UI.closeSettingsMenu();
-    }
-    if (UI.clipboardOpen == true) {
-        UI.showClipboard(); 
-    } 
-
-    //Toggle Connection Panel
-    if (UI.connSettingsOpen == true) {
-        $D('noVNC_controls').style.display = "none";
-        UI.connSettingsOpen = false;
-    } else {
-        $D('noVNC_controls').style.display = "block";
-        UI.connSettingsOpen = true;
-        $D('noVNC_host').focus();
-    }
 }
 }
 
 
 };
 };

+ 5 - 5
vnc.html

@@ -84,15 +84,15 @@
             <input type="image" src="images/clipboard.png"
             <input type="image" src="images/clipboard.png"
                 id="clipboardButton" class="noVNC_status_button"
                 id="clipboardButton" class="noVNC_status_button"
                 value="Clipboard" title="Clipboard"
                 value="Clipboard" title="Clipboard"
-                onclick="UI.showClipboard();" />
+                onclick="UI.toggleClipboardPanel();" />
             <input type="image" src="images/settings.png"
             <input type="image" src="images/settings.png"
-                id="menuButton" class="noVNC_status_button"
+                id="settingsButton" class="noVNC_status_button"
                 value="Settings" title="Settings"
                 value="Settings" title="Settings"
-                onclick="UI.clickSettingsMenu();" />
+                onclick="UI.toggleSettingsPanel();" />
             <input type="image" src="images/connect.png"
             <input type="image" src="images/connect.png"
-                id="connectPanelbutton" class="noVNC_status_button"
+                id="connectButton" class="noVNC_status_button"
                 value="Connect" title="Connect"
                 value="Connect" title="Connect"
-                onclick="UI.connectPanelbutton()" />
+                onclick="UI.toggleConnectPanel()" />
             <input type="image" src="images/disconnect.png"
             <input type="image" src="images/disconnect.png"
                 id="disconnectButton" class="noVNC_status_button"
                 id="disconnectButton" class="noVNC_status_button"
                 value="Disconnect" title="Disconnect"
                 value="Disconnect" title="Disconnect"