Update To 11.40.268.0
[platform/framework/web/crosswalk.git] / src / third_party / WebKit / Source / devtools / front_end / timeline / TransformController.js
index 0d3e284..d49e2c1 100644 (file)
@@ -14,16 +14,18 @@ WebInspector.TransformController = function(element, disableRotate)
 {
     this._shortcuts = {};
     this.element = element;
+    if (this.element.tabIndex < 0)
+        this.element.tabIndex = 0;
     this._registerShortcuts();
+    WebInspector.installDragHandle(element, this._onDragStart.bind(this), this._onDrag.bind(this), this._onDragEnd.bind(this), "move", null);
     element.addEventListener("keydown", this._onKeyDown.bind(this), false);
     element.addEventListener("keyup", this._onKeyUp.bind(this), false);
-    element.addEventListener("mousemove", this._onMouseMove.bind(this), false);
-    element.addEventListener("mousedown", this._onMouseDown.bind(this), false);
-    element.addEventListener("mouseup", this._onMouseUp.bind(this), false);
     element.addEventListener("mousewheel", this._onMouseWheel.bind(this), false);
     this._disableRotate = disableRotate;
+    this._minScale = 0;
+    this._maxScale = Infinity;
 
-    this._controlPanelElement = document.createElement("div");
+    this._controlPanelElement = createElement("div");
     this._controlPanelElement.classList.add("transform-control-panel");
 
     this._modeButtons = {};
@@ -159,6 +161,29 @@ WebInspector.TransformController.prototype = {
     },
 
     /**
+     * @param {number} minScale
+     * @param {number} maxScale
+     */
+    setScaleConstraints: function(minScale, maxScale)
+    {
+        this._minScale = minScale;
+        this._maxScale = maxScale;
+        this._scale = Number.constrain(this._scale, minScale, maxScale);
+    },
+
+    /**
+     * @param {number} minX
+     * @param {number} maxX
+     * @param {number} minY
+     * @param {number} maxY
+     */
+    clampOffsets: function(minX, maxX, minY, maxY)
+    {
+        this._offsetX = Number.constrain(this._offsetX, minX, maxX);
+        this._offsetY = Number.constrain(this._offsetY, minY, maxY);
+    },
+
+    /**
      * @return {number}
      */
     scale: function()
@@ -205,6 +230,7 @@ WebInspector.TransformController.prototype = {
      */
     _onScale: function(scaleFactor, x, y)
     {
+        scaleFactor = Number.constrain(this._scale * scaleFactor, this._minScale, this._maxScale) / this._scale;
         this._scale *= scaleFactor;
         this._offsetX -= (x - this._offsetX) * (scaleFactor - 1);
         this._offsetY -= (y - this._offsetY) * (scaleFactor - 1);
@@ -274,10 +300,8 @@ WebInspector.TransformController.prototype = {
     /**
      * @param {!Event} event
      */
-    _onMouseMove: function(event)
+    _onDrag: function(event)
     {
-        if (event.which !== 1 || typeof this._originX !== "number")
-            return;
         if (this._mode === WebInspector.TransformController.Modes.Rotate) {
             this._onRotate(this._oldRotateX + (this._originY - event.clientY) / this.element.clientHeight * 180, this._oldRotateY - (this._originX - event.clientX) / this.element.clientWidth * 180);
         } else {
@@ -288,17 +312,19 @@ WebInspector.TransformController.prototype = {
     },
 
     /**
-     * @param {!Event} event
+     * @param {!MouseEvent} event
      */
-    _setReferencePoint: function(event)
+    _onDragStart: function(event)
     {
+        this.element.focus();
         this._originX = event.clientX;
         this._originY = event.clientY;
         this._oldRotateX = this._rotateX;
         this._oldRotateY = this._rotateY;
+        return true;
     },
 
-    _resetReferencePoint: function()
+    _onDragEnd: function()
     {
         delete this._originX;
         delete this._originY;
@@ -306,25 +332,5 @@ WebInspector.TransformController.prototype = {
         delete this._oldRotateY;
     },
 
-    /**
-     * @param {!Event} event
-     */
-    _onMouseDown: function(event)
-    {
-        if (event.which !== 1)
-            return;
-        this._setReferencePoint(event);
-    },
-
-    /**
-     * @param {!Event} event
-     */
-    _onMouseUp: function(event)
-    {
-        if (event.which !== 1)
-            return;
-        this._resetReferencePoint();
-    },
-
     __proto__: WebInspector.Object.prototype
 }