/*
 * Renderer.java
 *
 * Copyright (C) 2009-11 by RStudio, Inc.
 *
 * This program is licensed to you under the terms of version 3 of the
 * GNU Affero General Public License. This program is distributed WITHOUT
 * ANY EXPRESS OR IMPLIED WARRANTY, INCLUDING THOSE OF NON-INFRINGEMENT,
 * MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE. Please refer to the
 * AGPL (http://www.gnu.org/licenses/agpl-3.0.txt) for more details.
 *
 */
package org.rstudio.studio.client.workbench.views.source.editors.text.ace;

import com.google.gwt.core.client.JavaScriptObject;
import com.google.gwt.user.client.Element;

public class Renderer extends JavaScriptObject
{
   public static class ScreenCoordinates extends JavaScriptObject
   {
      protected ScreenCoordinates() {}

      public native final int getPageX() /*-{
         return Math.round(this.pageX);
      }-*/;

      public native final int getPageY() /*-{
         return Math.round(this.pageY);
      }-*/;
   }

   protected Renderer() {}

   public native final ScreenCoordinates textToScreenCoordinates(int row,
                                                                 int col) /*-{
      return this.textToScreenCoordinates(row, col);
   }-*/;

   public native final void forceScrollbarUpdate() /*-{
      // WebKit-based browsers have problems repainting the scrollbar after
      // the editor is hidden and then made visible again. Poking the style
      // a little bit seems to force a redraw.
      var style = this.scrollBar.element.style;
      style.marginBottom = (style.marginBottom == "-1px") ? "0" : "-1px";     
   }-*/;

   public native final void updateFontSize() /*-{
      this.updateFontSize();
   }-*/;

   public native final void onResize(boolean force) /*-{
      this.onResize(force);
   }-*/;

   public native final void setHScrollBarAlwaysVisible(boolean on) /*-{
      this.setHScrollBarAlwaysVisible(on);
   }-*/;

   public native final void setShowGutter(boolean on) /*-{
      this.setShowGutter(on);
   }-*/;

   public native final void setShowPrintMargin(boolean on) /*-{
      this.setShowPrintMargin(on);
   }-*/;

   public native final void setPrintMarginColumn(int column) /*-{
      this.setPrintMarginColumn(column);
   }-*/;

   public native final void setPadding(int padding) /*-{
      this.setPadding(padding);
   }-*/;

   public native final int getLineHeight() /*-{
      return this.lineHeight;
   }-*/;

   public native final double getCharacterWidth() /*-{
      return this.characterWidth;
   }-*/;

   public native final Element getCursorElement() /*-{
      return this.$cursorLayer.cursor;
   }-*/;

   public native final int getScrollTop() /*-{
      return this.getScrollTop() || 0;
   }-*/;

   public native final int getScrollLeft() /*-{
      return this.getScrollLeft() || 0;
   }-*/;

   public native final void scrollToY(int scrollTop) /*-{
      this.scrollToY(scrollTop);
   }-*/;

   public native final void scrollToX(int scrollLeft) /*-{
      this.scrollToX(scrollLeft);
   }-*/;

   public native final void forceImmediateRender() /*-{
      this.$renderChanges(this.CHANGE_FULL);
   }-*/;

   public native final void debug_forceTopsToZero() /*-{
      this.scroller.style.top = "0";
      this.content.style.top = "0";
   }-*/;

   public native final void setPasswordMode(boolean passwordMode) /*-{

      if (passwordMode)
      {
         this.characterWidth = 0;
         this.$textLayer.element.style.visibility = 'hidden';
         this.$renderChanges(this.CHANGE_FULL);
      }
      else
      {
         this.characterWidth = this.$textLayer.getCharacterWidth();
         this.$textLayer.element.style.visibility = 'visible';
         this.$renderChanges(this.CHANGE_FULL);
      }
   }-*/;

}

@@ -3265,16 +3265,51 @@
  = %220%22;%0A
+      this.scroller.scrollTop = 0;%0A
    %7D-*/;

Modify debug command "force tops to zero"