Bug 964504 - Add Editor.setFontSize/getFontSize. r=msucan
☠☠ backed out by 9fdb8b893c75 ☠ ☠
authorAnton Kovalyov <anton@mozilla.com>
Tue, 28 Jan 2014 13:48:09 -0800
changeset 165636 95c958fa3cf2ca71696d0c5a8ee830b5c3922316
parent 165635 d3150d5a665d6b82b3e5344d77013ed78ced06e6
child 165637 4b86247721b2429a3bb0011f6efc009df668100d
push id4628
push userakovalyov@mozilla.com
push dateTue, 28 Jan 2014 23:23:00 +0000
treeherderfx-team@95c958fa3cf2 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmsucan
bugs964504
milestone29.0a1
Bug 964504 - Add Editor.setFontSize/getFontSize. r=msucan
browser/devtools/sourceeditor/editor.js
browser/devtools/sourceeditor/test/browser_editor_basic.js
--- a/browser/devtools/sourceeditor/editor.js
+++ b/browser/devtools/sourceeditor/editor.js
@@ -746,16 +746,35 @@ Editor.prototype = {
     // value and maintain the selection of the text.
     cm.replaceRange(value, { line: start.line, ch: 0 },
       { line: end.line + 1, ch: cm.getLine(end.line + 1).length});
     cm.setSelection({ line: start.line + 1, ch: start.ch },
       { line: end.line + 1, ch: end.ch });
   },
 
   /**
+   * Returns current font size for the editor area, in pixels.
+   */
+  getFontSize: function () {
+    let cm  = editors.get(this);
+    let el  = cm.getWrapperElement();
+    let win = el.ownerDocument.defaultView;
+
+    return parseInt(win.getComputedStyle(el).getPropertyValue("font-size"), 10);
+  },
+
+  /**
+   * Sets font size for the editor area.
+   */
+  setFontSize: function (size) {
+    let cm = editors.get(this);
+    cm.getWrapperElement().style.fontSize = parseInt(size, 10) + "px";
+  },
+
+  /**
    * Extends an instance of the Editor object with additional
    * functions. Each function will be called with context as
    * the first argument. Context is a {ed, cm} object where
    * 'ed' is an instance of the Editor object and 'cm' is an
    * instance of the CodeMirror object. Example:
    *
    * function hello(ctx, name) {
    *   let { cm, ed } = ctx;
--- a/browser/devtools/sourceeditor/test/browser_editor_basic.js
+++ b/browser/devtools/sourceeditor/test/browser_editor_basic.js
@@ -46,11 +46,16 @@ function test() {
     // Line classes
     ed.setText("Hello!\nHow are you?");
     ok(!ed.hasLineClass(0, "test"), "no test line class");
     ed.addLineClass(0, "test");
     ok(ed.hasLineClass(0, "test"), "test line class is there");
     ed.removeLineClass(0, "test");
     ok(!ed.hasLineClass(0, "test"), "test line class is gone");
 
+    // Font size
+    is(ed.getFontSize(), 11, "default font size is 11");
+    ed.setFontSize(ed.getFontSize() + 1);
+    is(ed.getFontSize(), 12, "new font size is 12");
+
     teardown(ed, win);
   });
-}
\ No newline at end of file
+}