TODO freynaud use keyboard.js bot.Keyboard.prototype.moveCursor = function(element)
557064
private String getNativeElementClickOnItAndTypeUsingKeyboardScript(String value)
      throws Exception {


    StringBuilder script = new StringBuilder();
    script.append("var keyboard; var waiter = 10; while(waiter-- > 0){try{ " +
            "keyboard = UIAutomation.cache.get('1').keyboard(); break;}catch(e){UIATarget.localTarget().delay(1);}}; ");

    Boolean keyboardResigned = false;
    boolean ios7 = new IOSVersion(session.getCapabilities().getSDKVersion()).isGreaterOrEqualTo("7.0");

    StringBuilder current = new StringBuilder();
    XPath2Engine xpathEngine = null;
    for (int i = 0; i < value.length(); i++) {
      int idx = specialKeys.indexOf(value.charAt(i));
      if (idx >= 0) {
        if (xpathEngine == null) {
          xpathEngine = XPath2Engine.getXpath2Engine(nativeDriver);
        }
        if (current.length() > 0) {
          script.append(getKeyboardTypeStringSegement(current.toString()));
          current = new StringBuilder();
        }
        switch (idx) {
          case 0:
            // DELETE
            // TODO, i don't like this xpath... should find the key in a better way
            // (like keyboard.shift)
            script.append(getReferenceToTapByXpath(xpathEngine, "//UIAKeyboard/UIAKey[" +
                ( nativeDriver.getCapabilities().getDevice() == DeviceType.ipad ?
                    (ios7? "13" : "11") : (ios7? "last()-2" : "last()-3")) + ']'
            ));
            break;
          case 1:
          case 2:
            // ENTER / RETURN
            // TODO another smelly xpath.
            script.append(getReferenceToTapByXpath(xpathEngine, "//UIAKeyboard/UIAButton[" +
                ( nativeDriver.getCapabilities().getDevice() == DeviceType.ipad ?
                    "1" : (ios7? "4" : "2")) + ']'
            ));
            keyboardResigned = true;
            break;
          case 3:
            // SHIFT
            script.append("keyboard.shift();");
            break;
          default:
            throw new RuntimeException("Special key found in the list but not taken care of??");
        }
      } else {
        current.append(value.charAt(i));
      }
    }
    if (current.length() > 0) {
      script.append(getKeyboardTypeStringSegement(current.toString()));
    }

      //check to see if the user wants to keep the keyboard after typing in text
    Boolean showKeyboardAfterClickAndType = Boolean.TRUE.equals(session.getCapabilities()
            .getCapability((IOSCapabilities.SHOW_KEYBOARD_AFTER_CLICK_AND_TYPE)));

    if (!showKeyboardAfterClickAndType) {
      if (!keyboardResigned) {
        script.append("keyboard.hide();");
      }
    }

    return script.toString();
  }
331403
function (ctrl) {
        var self = this, i = self.length;

        while (i--) {
          if (self[i] === ctrl) {
            break;
          }
        }

        return i;
      }
207292
function moveCursorRelative(stream, dx, dy) {
  if (dx < 0) {
    stream.write('\x1b[' + (-dx) + 'D');
  } else if (dx > 0) {
    stream.write('\x1b[' + dx + 'C');
  }

  if (dy < 0) {
    stream.write('\x1b[' + (-dy) + 'A');
  } else if (dy > 0) {
    stream.write('\x1b[' + dy + 'B');
  }
}
609428
def Ctrl(cls, key):
        
        element = cls._element()        
        element.send_keys(Keys.CONTROL, key)
774721
function(){
      var value = this.get();
      var cursor = this;

      while (cursor = cursor.handler)
        cursor.fn.call(cursor.context, value);
    }
280530
function trapTabKey(node, event) {
    var focusableChildren = getFocusableChildren(node);
    var focusedItemIndex = focusableChildren.index($(document.activeElement));

    if (event.shiftKey && focusedItemIndex === 0) {
      focusableChildren[focusableChildren.length - 1].focus();
      event.preventDefault();
    } else if (!event.shiftKey && focusedItemIndex === focusableChildren.length - 1) {
      focusableChildren[0].focus();
      event.preventDefault();
    }
  }
133756
function( domRange ) {
					var cursor,
						walker = new characterWalker( domRange );
					this._.cursors = [];
					do {
						cursor = walker.next();
						if ( cursor.character ) this._.cursors.push( cursor );
					}
					while ( cursor.character );
					this._.rangeLength = this._.cursors.length;
				}
264516
function (event) {

        event = normalizeEvent(this.dom, event);

        // Mark touch, which is useful in distinguish touch and
        // mouse event in upper applicatoin.
        event.zrByTouch = true;

        this.handler.processGesture(this, event, 'change');

        // Mouse move should always be triggered no matter whether
        // there is gestrue event, because mouse move and pinch may
        // be used at the same time.
        domHandlers.mousemove.call(this, event);

        setTouchTimer(this);
    }
1201006
function (/*HTMLElement*/ obj, /*String*/ type, /*Function*/ fn, /*Object*/ context) {
		var id = TL.Util.stamp(fn),
			key = '_tl_' + type + id;

		if (obj[key]) {
			return;
		}

		var handler = function (e) {
			return fn.call(context || obj, e || TL.DomEvent._getEvent());
		};

		if (TL.Browser.touch && (type === 'dblclick') && this.addDoubleTapListener) {
			this.addDoubleTapListener(obj, handler, id);
		} else if ('addEventListener' in obj) {
			if (type === 'mousewheel') {
				obj.addEventListener('DOMMouseScroll', handler, false);
				obj.addEventListener(type, handler, false);
			} else if ((type === 'mouseenter') || (type === 'mouseleave')) {
				var originalHandler = handler,
					newType = (type === 'mouseenter' ? 'mouseover' : 'mouseout');
				handler = function (e) {
					if (!TL.DomEvent._checkMouse(obj, e)) {
						return;
					}
					return originalHandler(e);
				};
				obj.addEventListener(newType, handler, false);
			} else {
				obj.addEventListener(type, handler, false);
			}
		} else if ('attachEvent' in obj) {
			obj.attachEvent("on" + type, handler);
		}

		obj[key] = handler;
	}
824774
function Keyboard(keyMap) {
	/**
	 * The current key states.
	 * @member {object}
	 * @private
	 */
	this.keys = {};

	var self = this;
	for (var kc in keyMap) {
		if (keyMap.hasOwnProperty(kc)) {
			this.keys[keyMap[kc]] = 0;
		}
	}
	window.addEventListener("keydown", function(event) {
		if (keyMap.hasOwnProperty(event.keyCode)) {
			if (self.keys[keyMap[event.keyCode]] === 0) {
				self.keys[keyMap[event.keyCode]] = 2;
			}
			return false;
		}
	});
	window.addEventListener("keyup", function(event) {
		if (keyMap.hasOwnProperty(event.keyCode)) {
			self.keys[keyMap[event.keyCode]] = 0;
			return false;
		}
	});
}
198169
function() {
      element.find('a, button').mousemove(function(e) {
        if (buttonPickerEnabled) {
          if (e.target !== buttonToPickElement) {
            buttonToPickCounter = 0;
            buttonToPickElement = e.target;
          }

          buttonToPickCounter += 1;
          if (buttonToPickCounter > 50) {
            element.find('a, button').css('border', '');
            $(e.target).css('border', 'solid 2px green');

            var createSelector = function(element) {
              if (element.attr('id')) {
                return '#' + element.attr('id');
              } else {
                var classes = element.attr('class').split(/\s/);
                return classes.map(function(x) {
                  return '.' + x;
                }).join('');
              }
            };

            if (buttonToPick === 'undo') {
              editor.find('.kelmu-editor-undo-button').val(createSelector($(e.target)));
            } else if (buttonToPick === 'redo') {
              editor.find('.kelmu-editor-redo-button').val(createSelector($(e.target)));
            } else if (buttonToPick === 'step') {
              editor.find('.kelmu-editor-step-button').val(createSelector($(e.target)));
            } else if (buttonToPick === 'begin') {
              editor.find('.kelmu-editor-begin-button').val(createSelector($(e.target)));
            }

            buttonPickerEnabled = false;
            buttonToPickCounter = 0;

            setTimeout(function() {
              element.find('a, button').css('border', '');
            }, 5000);

          }
        }
      });
      buttonPickerCreated = true;
    }
1020959
function setCursor_(a) {
    if(a) {
      src.style.cursor = draggingCursor_;
    } else {
      src.style.cursor = draggableCursor_;
    }
  }
1125942
function mouseMove_(ev) {
    var e=ev||event;
    currentX_ = formerX_+((e.pageX||(e.clientX+document.body.scrollLeft+document.documentElement.scrollLeft))-formerMouseX_);
    currentY_ = formerY_+((e.pageY||(e.clientY+document.body.scrollTop+document.documentElement.scrollTop))-formerMouseY_);
    formerX_ = currentX_;
    formerY_ = currentY_;
    formerMouseX_ = e.pageX||(e.clientX+document.body.scrollLeft+document.documentElement.scrollLeft);
    formerMouseY_ = e.pageY||(e.clientY+document.body.scrollTop+document.documentElement.scrollTop);
    if (moving_) {
      moveTo_(currentX_,currentY_, preventDefault_);
      event_.trigger(me, "drag", {mouseX: formerMouseX_, mouseY: formerMouseY_, startLeft: originalX_, startTop: originalY_, event:e});
    }
  }
1289153
function getOnKeyDownListener( editor ) {
		var keystrokes = { 37: 1, 39: 1, 8: 1, 46: 1 };

		return function( evt ) {
			var keystroke = evt.data.getKeystroke();

			// Handle only left/right/del/bspace keys.
			if ( !keystrokes[ keystroke ] )
				return;

			var sel = editor.getSelection(),
				ranges = sel.getRanges(),
				range = ranges[ 0 ];

			// Handle only single range and it has to be collapsed.
			if ( ranges.length != 1 || !range.collapsed )
				return;

			var next = range[ keystroke < 38 ? 'getPreviousEditableNode' : 'getNextEditableNode' ]();

			if ( next && next.type == CKEDITOR.NODE_ELEMENT && next.getAttribute( 'contenteditable' ) == 'false' ) {
				editor.getSelection().fake( next );
				evt.data.preventDefault();
				evt.cancel();
			}
		};
	}
1318788
function mousemove_callback(e) {
            var x  = e.pageX || e.originalEvent.touches[0].pageX;
            var y  = e.pageY || e.originalEvent.touches[0].pageY;

            if (Math.abs(oX - x) > maxMove || Math.abs(oY - y) > maxMove) {
                if (timeout) clearTimeout(timeout);
            }
        }
1176814
function () {
            var me = this, shortcutkeys = this.shortcutkeys;
            me.addListener('keydown', function (type, e) {
                var keyCode = e.keyCode || e.which;
                for (var i in shortcutkeys) {
                    var tmp = shortcutkeys[i].split(',');
                    for (var t = 0, ti; ti = tmp[t++];) {
                        ti = ti.split(':');
                        var key = ti[0], param = ti[1];
                        if (/^(ctrl)(\+shift)?\+(\d+)$/.test(key.toLowerCase()) || /^(\d+)$/.test(key)) {
                            if (( (RegExp.$1 == 'ctrl' ? (e.ctrlKey || e.metaKey) : 0)
                                && (RegExp.$2 != "" ? e[RegExp.$2.slice(1) + "Key"] : 1)
                                && keyCode == RegExp.$3
                                ) ||
                                keyCode == RegExp.$1
                                ) {
                                if (me.queryCommandState(i,param) != -1)
                                    me.execCommand(i, param);
                                domUtils.preventDefault(e);
                            }
                        }
                    }

                }
            });
        }
278274
function triggerTouch(touches, element, type) {
            var touchlist = [],
                event = document.createEvent('Event');

            event.initEvent('touch' + type, true, true);

            touchlist.identifiedTouch = touchlist.item = function(index) {
                return this[index] || {};
            };

            touches.forEach(function(touch, i) {
                var x = Math.round(touch.x),
                    y = Math.round(touch.y);
                touchlist.push({
                    pageX: x,
                    pageY: y,
                    clientX: x,
                    clientY: y,
                    screenX: x,
                    screenY: y,
                    target: element,
                    identifier: i
                });
            });

            event.touches = (type == 'end') ? [] : touchlist;
            event.targetTouches = (type == 'end') ? [] : touchlist;
            event.changedTouches = touchlist;

            element.dispatchEvent(event);
            config.showAction(touches);
        }