Upstream version 5.34.104.0
[platform/framework/web/crosswalk.git] / src / third_party / WebKit / Source / devtools / front_end / CodeMirrorUtils.js
index c01eeb0..1d0aaa2 100644 (file)
  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  */
 
-WebInspector.CodeMirrorUtils = {
+/**
+ * @constructor
+ * @extends {WebInspector.InplaceEditor}
+ */
+WebInspector.CodeMirrorUtils = function()
+{
+    WebInspector.InplaceEditor.call(this);
+}
+
+WebInspector.CodeMirrorUtils.prototype = {
+    /**
+     * @return {string}
+     */
+    editorContent: function(editingContext) {
+        return editingContext.codeMirror.getValue();
+    },
+
+    /**
+     * @param {?Event} e
+     */
+    _consumeCopy: function(e)
+    {
+        e.consume();
+    },
+
+    setUpEditor: function(editingContext)
+    {
+        var element = editingContext.element;
+        var config = editingContext.config;
+        loadScript("CodeMirrorTextEditor.js");
+        editingContext.cssLoadView = new WebInspector.CodeMirrorCSSLoadView();
+        editingContext.cssLoadView.show(element);
+        WebInspector.setCurrentFocusElement(element);
+        element.addEventListener("copy", this._consumeCopy, false);
+        var codeMirror = window.CodeMirror(element, {
+            mode: config.mode,
+            lineWrapping: config.lineWrapping,
+            smartIndent: config.smartIndent,
+            autofocus: true,
+            theme: config.theme,
+            value: config.initialValue
+        });
+        codeMirror.getWrapperElement().classList.add("source-code");
+        codeMirror.on("cursorActivity", function(cm) {
+            cm.display.cursor.scrollIntoViewIfNeeded(false);
+        });
+        editingContext.codeMirror = codeMirror;
+    },
+
+    closeEditor: function(editingContext)
+    {
+        editingContext.element.removeEventListener("copy", this._consumeCopy, false);
+        editingContext.cssLoadView.detach();
+    },
+
+    cancelEditing: function(editingContext)
+    {
+        editingContext.codeMirror.setValue(editingContext.oldText);
+    },
+
+    augmentEditingHandle: function(editingContext, handle)
+    {
+        function setWidth(editingContext, width)
+        {
+            var padding = 30;
+            var codeMirror = editingContext.codeMirror;
+            codeMirror.getWrapperElement().style.width = (width - codeMirror.getWrapperElement().offsetLeft - padding) + "px";
+            codeMirror.refresh();
+        }
+
+        handle.codeMirror = editingContext.codeMirror;
+        handle.setWidth = setWidth.bind(null, editingContext);
+    },
+
+    __proto__: WebInspector.InplaceEditor.prototype
+}
+
+/**
+ * @constructor
+ * @implements {WebInspector.TokenizerFactory}
+ */
+WebInspector.CodeMirrorUtils.TokenizerFactory = function() { }
+
+WebInspector.CodeMirrorUtils.TokenizerFactory.prototype = {
     /**
      * @param {string} mimeType
      * @return {function(string, function(string, ?string, number, number))}
@@ -50,3 +133,21 @@ WebInspector.CodeMirrorUtils = {
         return tokenize;
     }
 }
+
+/**
+ * This bogus view is needed to load/unload CodeMirror-related CSS on demand.
+ *
+ * @constructor
+ * @extends {WebInspector.View}
+ */
+WebInspector.CodeMirrorCSSLoadView = function()
+{
+    WebInspector.View.call(this);
+    this.element.classList.add("hidden");
+    this.registerRequiredCSS("cm/codemirror.css");
+    this.registerRequiredCSS("cm/cmdevtools.css");
+}
+
+WebInspector.CodeMirrorCSSLoadView.prototype = {
+    __proto__: WebInspector.View.prototype
+}