     @server.setSize x, y if @server
 
   updateSize: (force=no) ->
-    return if not force and @pixelWidth is @container.prop("clientWidth") and @pixelHeight is @container.prop("clientHeight")
-    @container.scrollTop @container.scrollTop() + @pixelHeight - @container.prop("clientHeight") + 1 if @container.prop("clientHeight") < @pixelHeight
-    @pixelWidth  = @container.prop("clientWidth")
-    @pixelHeight = @container.prop("clientHeight")
-
-    width = 1
+    return if not force and @pixelWidth is @parent.getWidth() and @pixelHeight is @parent.getHeight()
+    @container.scrollTop @container.scrollTop() + @pixelHeight - @parent.getHeight() + 1 if @parent.getHeight() < @pixelHeight
+    @pixelWidth  = @parent.getWidth()
+    @pixelHeight = @parent.getHeight()
+
+    width  = 1
     height = 1
     for n in [0..10] # avoid infinite loop
-      text = ""
-      text += "\xA0" for x in [0...width]
-      elements = []
-      for y in [0...height]
-        div = $(document.createElement("div"))
-        div.text text
-        elements.push div
+      text      = ""
+      text     += "\xA0" for x in [0...width]
+      elements  = ($("<div>#{text}</div>") for y in [0...height])
       @measurebox.empty()
       @measurebox.append elements
-      break if newWidth is width and newHeight is height
-      break if newWidth > 1000 or newHeight > 1000 # sanity check
       newWidth  = Math.max width,  Math.floor @pixelWidth  / @measurebox.width()  * width
       newHeight = Math.max height, Math.floor @pixelHeight / @measurebox.height() * height
-      width = newWidth
+      break  if newWidth is width and newHeight is height
+      break  if newWidth > 1000 or newHeight > 1000 # sanity check
+      width  = newWidth
       height = newHeight
 
     @measurebox.empty()

    @cursor            = new WebTerm.Cursor(this)
    @controlCodeReader = WebTerm.createAnsiControlCodeReader(this)

    @measurebox        = $(document.createElement("div"))
    @updateSizeTimer   = null
    @measurebox.css "position", "absolute"
    @measurebox.css "visibility", "hidden"
    @container.append @measurebox
    @updateSize()


    '\\': '\\\\'
    '\u001b': '\\e'

  constructor: (containerView) ->
    localStorage?["WebTerm.logRawOutput"] ?= "false"
    localStorage?["WebTerm.slowDrawing"]  ?= "false"

    @parent               = containerView
    @container            = containerView.$()
    @server               = null
    @sessionEndedCallback = null
    @setTitleCallback     = null

    @keyInput = new KDCustomHTMLView
      tagName: 'input'
