Commits

Christian Krebs committed 1f6573a

Make the main UI text unselectable (not perfect).

  • Participants
  • Parent commits 6c8a259

Comments (0)

Files changed (4)

src/build-application/build_resource_manager_1_0.js

   //new cls.ResourceManagerImageView('resource_images', "Images", 'scroll', '', '');
   new cls.NetworkLogView('network_logger', ui_strings.M_VIEW_LABEL_NETWORK_LOG, 'scroll', '', '');
   new cls.RequestCraftingView('request_crafter', ui_strings.M_VIEW_LABEL_REQUEST_CRAFTER, 'scroll', '', '');
-  new cls.NetworkOptionsView('network_options', ui_strings.M_VIEW_LABEL_NETWORK_OPTIONS, 'scroll', '', '');
+  new cls.NetworkOptionsView('network_options', 
+                             ui_strings.M_VIEW_LABEL_NETWORK_OPTIONS,
+                             'scroll network-options-container', '', '');
 
   var setup_request_body_behaviour = function()
   {

src/client-en.xml

 <script src="./scripts/spec_links.js"/>
 <script src="./scripts/queue.js"/>
 <script src="./scripts/potools.js"/>
+<script src="./scripts/selectioncontroller.js"/>
 
 
 

src/scripts/selectioncontroller.js

+var SelectionController = function(css_query_selectable, if_check)
+{
+  /* interface */
+
+  this.is_selectable = function(target){};
+
+  /* private */
+
+  var selectable = null;
+  var start_node = null;
+  var start_offset = 0;
+
+  const RE_TEXT_INPUTS = GlobalActionHandler.RE_TEXT_INPUTS;
+
+  var mousedown = function(event)
+  {
+    var target = event.target;
+    if (target.nodeName.toLowerCase() == "textarea" ||
+        (target.nodeName.toLowerCase() == "input" && 
+         RE_TEXT_INPUTS.test(target.type)))
+      return;
+
+    if (selectable = is_selectable(event.target))
+    {
+      this.addEventListener('mousemove', mousemove, false);
+      this.addEventListener('mouseup', mouseup, false);
+    }
+    else
+      event.preventDefault();
+
+    start_node = null;
+  };
+
+  var mousemove = function()
+  {
+    var sel = getSelection();
+    if (sel && !sel.isCollapsed)
+    {
+      if (!start_node)
+      {
+        start_node = sel.anchorNode;
+        start_offset = sel.anchorOffset;
+      }
+
+      var range = sel.getRangeAt(0);
+      if (range && !selectable.contains(range.commonAncestorContainer))
+      {
+        if (sel.anchorNode == range.startContainer)
+        {
+          var last = selectable.lastChild;
+          range.setEnd(last, last.nodeType == 3 ?
+                             last.nodeValue.length :
+                             last.childNodes.length);
+        }
+        else
+        {
+          range.setStart(selectable.firstChild, 0);
+          range.setEnd(start_node, start_offset);
+        }
+        sel.removeAllRanges();
+        sel.addRange(range);
+      }
+    }
+  };
+
+  var mouseup = function()
+  {
+    this.removeEventListener('mousemove', mousemove, false);
+    this.removeEventListener('mouseup', mouseup, false);
+    setTimeout(mousemove, 0);
+  };
+
+  var is_selectable = function(target)
+  {
+    var cur = target.get_ancestor(css_query_selectable);
+    return cur && (if_check && if_check(cur)) && cur || null;
+  };
+
+  this.is_selectable = function(target)
+  {
+    return is_selectable(target);
+  };
+
+  document.addEventListener('mousedown', mousedown, true);
+
+};

src/ui-scripts/actions/globalactionhandler.js

   const
   MODE_DEFAULT = "default",
   MODE_EDIT = "edit",
-  RE_TEXT_INPUTS = new RegExp(["text",
-                               "search",
-                               "tel",
-                               "url",
-                               "email",
-                               "password",
-                               "datetime", 
-                               "date",
-                               "month",
-                               "week", 
-                               "time",
-                               "datetime-local", 
-                               "number",
-                               "file"].join("|"), "i");
+  RE_TEXT_INPUTS = GlobalActionHandler.RE_TEXT_INPUTS;
 
   this.mode = MODE_DEFAULT;
 
 
   /* privat */
 
-
   this._broker = ActionBroker.get_instance();
   this._handlers = {};
   this._private_handlers = [];
     
   this._handlers["select-all"] = function(action_id, event, target)
   {
-    var selection = getSelection();
-    var range = document.createRange();
-    selection.removeAllRanges()
-    range.selectNodeContents(target);
-    selection.addRange(range);
+    if (this._selection_controller.is_selectable(target))
+    {
+      var selection = getSelection();
+      var range = document.createRange();
+      selection.removeAllRanges();
+      range.selectNodeContents(target);
+      selection.addRange(range);
+    }
     return false;
-  };
+  }.bind(this);
 
   this._handlers["invert-spotlight-colors"] = function(action_id, event, target)
   {
 
   /* instatiation */
 
+  var if_check = function(conatiner)
+  {
+    return conatiner && !conatiner.querySelector(".info-box");
+  };
+
+  var is_selectable = 'container:not(.side-panel)' +
+                               ':not(.network-options-container)' +
+                               ':not(.screenshot-controls),' +
+                      'panel-container,' +
+                      '.screenshot-sample-values';
+
+  this._selection_controller =new SelectionController(is_selectable, if_check);
+
   /* message handling */
-
   messages.addListener("before-show-view", function(msg) {
     if (msg.id == "console_panel")
     {
       }
     }
   });
-}
 
+};
 
+GlobalActionHandler.RE_TEXT_INPUTS = new RegExp(["text",
+                                                 "search",
+                                                 "tel",
+                                                 "url",
+                                                 "email",
+                                                 "password",
+                                                 "datetime", 
+                                                 "date",
+                                                 "month",
+                                                 "week", 
+                                                 "time",
+                                                 "datetime-local", 
+                                                 "number",
+                                                 "file"].join("|"), "i");
+
+