1 /* 2 * Renderer.java 3 * 4 * Copyright (C) 2021 by RStudio, PBC 5 * 6 * Unless you have received this program directly from RStudio pursuant 7 * to the terms of a commercial license agreement with RStudio, then 8 * this program is licensed to you under the terms of version 3 of the 9 * GNU Affero General Public License. This program is distributed WITHOUT 10 * ANY EXPRESS OR IMPLIED WARRANTY, INCLUDING THOSE OF NON-INFRINGEMENT, 11 * MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE. Please refer to the 12 * AGPL (http://www.gnu.org/licenses/agpl-3.0.txt) for more details. 13 * 14 */ 15 package org.rstudio.studio.client.workbench.views.source.editors.text.ace; 16 17 import com.google.gwt.core.client.JavaScriptObject; 18 import com.google.gwt.dom.client.Element; 19 20 public class Renderer extends JavaScriptObject 21 { 22 public static class ScreenCoordinates extends JavaScriptObject 23 { ScreenCoordinates()24 protected ScreenCoordinates() {} 25 create(int pageX, int pageY)26 public native final static ScreenCoordinates create(int pageX, int pageY) /*-{ 27 return { 28 pageX: pageX, 29 pageY: pageY 30 }; 31 }-*/; 32 getPageX()33 public native final int getPageX() /*-{ 34 return Math.round(this.pageX); 35 }-*/; 36 getPageY()37 public native final int getPageY() /*-{ 38 return Math.round(this.pageY); 39 }-*/; 40 } 41 Renderer()42 protected Renderer() {} 43 textToScreenCoordinates(int row, int col)44 public native final ScreenCoordinates textToScreenCoordinates(int row, 45 int col) /*-{ 46 return this.textToScreenCoordinates(row, col); 47 }-*/; 48 textToScreenCoordinates(Position pos)49 public final ScreenCoordinates textToScreenCoordinates(Position pos) 50 { 51 return textToScreenCoordinates(pos.getRow(), pos.getColumn()); 52 } 53 screenToTextCoordinates(int pageX, int pageY)54 public native final Position screenToTextCoordinates(int pageX, int pageY) /*-{ 55 return this.screenToTextCoordinates(pageX, pageY); 56 }-*/; 57 forceScrollbarUpdate()58 public native final void forceScrollbarUpdate() /*-{ 59 // WebKit-based browsers have problems repainting the scrollbar after 60 // the editor is hidden and then made visible again. Poking the style 61 // a little bit seems to force a redraw. 62 var style = this.scrollBar.element.style; 63 style.marginBottom = (style.marginBottom == "-1px") ? "0" : "-1px"; 64 }-*/; 65 updateFontSize()66 public native final void updateFontSize() /*-{ 67 this.updateFontSize(); 68 }-*/; 69 updateFull(boolean force)70 public native final void updateFull(boolean force) /*-{ 71 this.updateFull(force); 72 }-*/; 73 onResize(boolean force)74 public native final void onResize(boolean force) /*-{ 75 this.onResize(force); 76 }-*/; 77 setHScrollBarAlwaysVisible(boolean on)78 public native final void setHScrollBarAlwaysVisible(boolean on) /*-{ 79 this.setHScrollBarAlwaysVisible(on); 80 }-*/; 81 setShowGutter(boolean on)82 public native final void setShowGutter(boolean on) /*-{ 83 this.setShowGutter(on); 84 }-*/; 85 setShowPrintMargin(boolean on)86 public native final void setShowPrintMargin(boolean on) /*-{ 87 this.setShowPrintMargin(on); 88 }-*/; 89 setPrintMarginColumn(int column)90 public native final void setPrintMarginColumn(int column) /*-{ 91 this.setPrintMarginColumn(column); 92 }-*/; 93 setShowInvisibles(boolean show)94 public native final void setShowInvisibles(boolean show) /*-{ 95 this.setShowInvisibles(show); 96 }-*/; 97 setShowIndentGuides(boolean show)98 public native final void setShowIndentGuides(boolean show) /*-{ 99 this.setDisplayIndentGuides(show); 100 }-*/; 101 setPadding(int padding)102 public native final void setPadding(int padding) /*-{ 103 this.setPadding(padding); 104 }-*/; 105 getLineHeight()106 public native final int getLineHeight() /*-{ 107 return this.lineHeight; 108 }-*/; 109 getCharacterWidth()110 public native final double getCharacterWidth() /*-{ 111 return this.characterWidth; 112 }-*/; 113 getCursorElement()114 public native final Element getCursorElement() /*-{ 115 return this.$cursorLayer.cursor; 116 }-*/; 117 getScrollTop()118 public native final int getScrollTop() /*-{ 119 return this.getScrollTop() || 0; 120 }-*/; 121 getScrollLeft()122 public native final int getScrollLeft() /*-{ 123 return this.getScrollLeft() || 0; 124 }-*/; 125 scrollToY(int scrollTop)126 public native final void scrollToY(int scrollTop) /*-{ 127 this.scrollToY(scrollTop); 128 }-*/; 129 scrollToX(int scrollLeft)130 public native final void scrollToX(int scrollLeft) /*-{ 131 this.scrollToX(scrollLeft); 132 }-*/; 133 setAnimatedScroll(boolean animate)134 public native final void setAnimatedScroll(boolean animate) /*-{ 135 this.setAnimatedScroll(animate); 136 }-*/; 137 getAnimatedScroll()138 public native final boolean getAnimatedScroll() /*-{ 139 return this.getAnimatedScroll(); 140 }-*/; 141 forceImmediateRender()142 public native final void forceImmediateRender() /*-{ 143 this.$renderChanges(this.CHANGE_FULL); 144 }-*/; 145 renderCursor()146 public native final void renderCursor() /*-{ 147 this.$renderChanges(this.CHANGE_CURSOR); 148 }-*/; 149 renderMarkers()150 public native final void renderMarkers() /*-{ 151 this.$renderChanges(this.CHANGE_MARKER); 152 }-*/; 153 fixVerticalOffsetBug()154 public native final void fixVerticalOffsetBug() /*-{ 155 this.scroller.scrollTop = 0; 156 }-*/; 157 setPasswordMode(boolean passwordMode)158 public native final void setPasswordMode(boolean passwordMode) /*-{ 159 160 if (passwordMode) 161 { 162 this.characterWidth = 0; 163 this.$textLayer.element.style.visibility = 'hidden'; 164 this.$renderChanges(this.CHANGE_FULL); 165 } 166 else 167 { 168 this.characterWidth = this.$textLayer.getCharacterWidth(); 169 this.$textLayer.element.style.visibility = 'visible'; 170 this.$renderChanges(this.CHANGE_FULL); 171 } 172 }-*/; 173 addGutterDecoration(int line, String clazz)174 public native final void addGutterDecoration(int line, String clazz) /*-{ 175 this.session.addGutterDecoration(line, clazz); 176 }-*/; 177 removeGutterDecoration(int line, String clazz)178 public native final void removeGutterDecoration(int line, String clazz) /*-{ 179 this.session.removeGutterDecoration(line, clazz); 180 }-*/; 181 alignCursor(Position position, double ratio)182 public final native void alignCursor(Position position, double ratio) /*-{ 183 this.alignCursor(position, ratio); 184 }-*/; 185 setScrollPastEnd(boolean value)186 public final native void setScrollPastEnd(boolean value) /*-{ 187 this.$scrollPastEnd = value; 188 }-*/; 189 getScrollPastEnd()190 public final native boolean getScrollPastEnd() /*-{ 191 return !!this.$scrollPastEnd; 192 }-*/; 193 getFirstFullyVisibleRow()194 public final native int getFirstFullyVisibleRow() /*-{ 195 return this.getFirstFullyVisibleRow(); 196 }-*/; 197 198 } 199