renderer changes from newclient

This commit is contained in:
nightwing 2013-07-14 07:47:17 +04:00
commit 7f8a47939c
3 changed files with 94 additions and 57 deletions

View file

@ -150,7 +150,8 @@ function GutterHandler(mouseHandler) {
hideTooltip(); hideTooltip();
}, 50); }, 50);
}); });
editor.on("changeSession", hideTooltip);
} }
exports.GutterHandler = GutterHandler; exports.GutterHandler = GutterHandler;

View file

@ -47,7 +47,7 @@ var EventEmitter = require("./lib/event_emitter").EventEmitter;
* *
* @constructor * @constructor
**/ **/
var ScrollBarV = function(parent) { var ScrollBarV = function(parent, renderer) {
this.element = dom.createElement("div"); this.element = dom.createElement("div");
this.element.className = "ace_scrollbar"; this.element.className = "ace_scrollbar";
@ -62,16 +62,19 @@ var ScrollBarV = function(parent) {
// of 0px // of 0px
// in Firefox 6+ scrollbar is hidden if element has the same width as scrollbar // in Firefox 6+ scrollbar is hidden if element has the same width as scrollbar
// make element a little bit wider to retain scrollbar when page is zoomed // make element a little bit wider to retain scrollbar when page is zoomed
this.width = dom.scrollbarWidth(parent.ownerDocument); renderer.once("beforeRender", function() {
this.fullWidth = this.width; renderer.$scrollbarWidth =
this.element.style.width = (this.width || 15) + 5 + "px"; this.width = dom.scrollbarWidth(parent.ownerDocument);
this.fullWidth = this.width;
this.element.style.width = (this.width || 15) + 5 + "px";
}.bind(this));
this.setVisible(false); this.setVisible(false);
this.element.style.overflowY = "scroll"; this.element.style.overflowY = "scroll";
event.addListener(this.element, "scroll", this.onScrollV.bind(this)); event.addListener(this.element, "scroll", this.onScrollV.bind(this));
}; };
var ScrollBarH = function(parent) { var ScrollBarH = function(parent, renderer) {
this.element = dom.createElement("div"); this.element = dom.createElement("div");
this.element.className = "ace_scrollbar-h"; this.element.className = "ace_scrollbar-h";
@ -86,9 +89,11 @@ var ScrollBarH = function(parent) {
// of 0px // of 0px
// in Firefox 6+ scrollbar is hidden if element has the same width as scrollbar // in Firefox 6+ scrollbar is hidden if element has the same width as scrollbar
// make element a little bit wider to retain scrollbar when page is zoomed // make element a little bit wider to retain scrollbar when page is zoomed
this.height = dom.scrollbarWidth(parent.ownerDocument); renderer.once("beforeRender", function() {
this.fullHeight = this.height; this.height = renderer.$scrollbarWidth;
this.element.style.height = (this.height || 15) + 5 + "px"; this.fullHeight = this.height;
this.element.style.height = (this.height || 15) + 5 + "px";
}.bind(this));
this.setVisible(false); this.setVisible(false);
this.element.style.overflowX = "scroll"; this.element.style.overflowX = "scroll";

View file

@ -105,8 +105,8 @@ var VirtualRenderer = function(container, theme) {
this.$vScroll = false; this.$vScroll = false;
this.scrollBar = this.scrollBar =
this.scrollBarV = new ScrollBarV(this.container); this.scrollBarV = new ScrollBarV(this.container, this);
this.scrollBarH = new ScrollBarH(this.container); this.scrollBarH = new ScrollBarH(this.container, this);
this.scrollBarV.addEventListener("scroll", function(e) { this.scrollBarV.addEventListener("scroll", function(e) {
if (!_self.$scrollAnimation) if (!_self.$scrollAnimation)
_self.session.setScrollTop(e.data - _self.scrollMargin.top); _self.session.setScrollTop(e.data - _self.scrollMargin.top);
@ -210,7 +210,9 @@ var VirtualRenderer = function(container, theme) {
this.setStyle("ace_nobold", !this.$allowBoldFonts); this.setStyle("ace_nobold", !this.$allowBoldFonts);
} }
this.layerConfig.characterWidth =
this.characterWidth = this.$textLayer.getCharacterWidth(); this.characterWidth = this.$textLayer.getCharacterWidth();
this.layerConfig.lineHeight =
this.lineHeight = this.$textLayer.getLineHeight(); this.lineHeight = this.$textLayer.getLineHeight();
this.$updatePrintMargin(); this.$updatePrintMargin();
}; };
@ -308,6 +310,8 @@ var VirtualRenderer = function(container, theme) {
* *
**/ **/
this.onResize = function(force, gutterWidth, width, height) { this.onResize = function(force, gutterWidth, width, height) {
// if (force)
// console.log("force resize requested", width, height)
if (this.resizing > 2) if (this.resizing > 2)
return; return;
else if (this.resizing > 0) else if (this.resizing > 0)
@ -318,9 +322,15 @@ var VirtualRenderer = function(container, theme) {
height = this.container.clientHeight; height = this.container.clientHeight;
if (!width) if (!width)
width = this.container.clientWidth; width = this.container.clientWidth;
var changes = this.$updateCachedSize(force, gutterWidth, width, height); var changes = this.$updateCachedSize(force, gutterWidth, width, height);
// console.log("resizing to", width, height, JSON.stringify(this.$size))
// setTimeout(function() {
// console.log("actual size ", this.container.clientWidth, this.container.clientHeight)
// }.bind(this), 500)
if (!this.$size.scrollerHeight) if (!this.$size.scrollerHeight)
return; return;
@ -347,7 +357,8 @@ var VirtualRenderer = function(container, theme) {
if (this.$horizScroll) if (this.$horizScroll)
size.scrollerHeight -= this.scrollBarH.getHeight(); size.scrollerHeight -= this.scrollBarH.getHeight();
this.scrollBarV.setHeight(size.scrollerHeight); // this.scrollBarV.setHeight(size.scrollerHeight);
this.scrollBarV.element.style.bottom = this.scrollBarH.getHeight() + "px";
if (this.session) { if (this.session) {
this.session.setScrollTop(this.getScrollTop()); this.session.setScrollTop(this.getScrollTop());
@ -355,19 +366,24 @@ var VirtualRenderer = function(container, theme) {
} }
} }
if (width && (force || this.resizing > 1 || size.width != width)) { if (width && (force || size.width != width)) {
changes = this.CHANGE_SIZE; changes = this.CHANGE_SIZE;
size.width = width; size.width = width;
gutterWidth = this.$showGutter ? this.$gutter.offsetWidth : 0; if (gutterWidth == null)
gutterWidth = this.$showGutter ? this.$gutter.offsetWidth : 0;
this.gutterWidth = gutterWidth;
this.scrollBarH.element.style.left = this.scrollBarH.element.style.left =
this.scroller.style.left = gutterWidth + "px"; this.scroller.style.left = gutterWidth + "px";
size.scrollerWidth = Math.max(0, width - gutterWidth - this.scrollBarV.getWidth()); size.scrollerWidth = Math.max(0, width - gutterWidth - this.scrollBarV.getWidth());
this.scrollBarH.element.style.right =
this.scroller.style.right = this.scrollBarV.getWidth() + "px"; this.scroller.style.right = this.scrollBarV.getWidth() + "px";
this.scroller.style.bottom = this.scrollBarH.getHeight() + "px"; this.scroller.style.bottom = this.scrollBarH.getHeight() + "px";
this.scrollBarH.setWidth(size.scrollerWidth); // this.scrollBarH.element.style.setWidth(size.scrollerWidth);
if (this.session && this.session.getUseWrapMode() && this.adjustWrapLimit() || force) if (this.session && this.session.getUseWrapMode() && this.adjustWrapLimit() || force)
changes = changes | this.CHANGE_FULL; changes = changes | this.CHANGE_FULL;
@ -376,17 +392,13 @@ var VirtualRenderer = function(container, theme) {
if (changes) if (changes)
this._signal("resize"); this._signal("resize");
if (this.$changes) {
changes |= this.$changes;
this.$changes = 0;
}
return changes; return changes;
}; };
this.onGutterResize = function() { this.onGutterResize = function() {
var gutterWidth = this.$showGutter ? this.$gutter.offsetWidth : 0; var gutterWidth = this.$showGutter ? this.$gutter.offsetWidth : 0;
this.$updateCachedSize(true, gutterWidth, this.$size.width, this.$size.height); if (gutterWidth != this.gutterWidth)
this.$updateCachedSize(true, gutterWidth, this.$size.width, this.$size.height);
if (this.session.getUseWrapMode() && this.adjustWrapLimit()) if (this.session.getUseWrapMode() && this.adjustWrapLimit())
this.$loop.schedule(this.CHANGE_FULL); this.$loop.schedule(this.CHANGE_FULL);
@ -714,10 +726,15 @@ var VirtualRenderer = function(container, theme) {
}; };
this.$renderChanges = function(changes, force) { this.$renderChanges = function(changes, force) {
if (!force && (!changes || !this.session || !this.container.offsetWidth)) { if ((!this.session || !this.container.offsetWidth) || (!changes && !force)) {
this.$changes = changes; this.$logChanges(changes);
this.$changes |= changes;
return; return;
} }
if (this.$changes) {
changes |= this.$changes;
this.$changes = 0;
}
// this.$logChanges(changes); // this.$logChanges(changes);
@ -730,7 +747,7 @@ var VirtualRenderer = function(container, theme) {
changes & this.CHANGE_SCROLL || changes & this.CHANGE_SCROLL ||
changes & this.CHANGE_H_SCROLL changes & this.CHANGE_H_SCROLL
) )
this.$computeLayerConfig(); changes |= this.$computeLayerConfig();
// horizontal scrolling // horizontal scrolling
if (changes & this.CHANGE_H_SCROLL) { if (changes & this.CHANGE_H_SCROLL) {
@ -841,9 +858,6 @@ var VirtualRenderer = function(container, theme) {
if (this.$maxLines && this.lineHeight > 1) if (this.$maxLines && this.lineHeight > 1)
this.$autosize(); this.$autosize();
if (!this.$size.scrollerHeight)
return this.onResize(true);
var session = this.session; var session = this.session;
var hideScrollbars = this.$size.height <= 2 * this.lineHeight; var hideScrollbars = this.$size.height <= 2 * this.lineHeight;
@ -933,12 +947,14 @@ var VirtualRenderer = function(container, theme) {
this.content.style.width = longestLine + 2 * this.$padding + "px"; this.content.style.width = longestLine + 2 * this.$padding + "px";
this.content.style.height = minHeight + "px"; this.content.style.height = minHeight + "px";
var changes = 0;
// Horizontal scrollbar visibility may have changed, which changes // Horizontal scrollbar visibility may have changed, which changes
// the client height of the scroller // the client height of the scroller
if (hScrollChanged || vScrollChanged) { if (hScrollChanged || vScrollChanged) {
this.onResize(true); changes = this.$updateCachedSize(true, this.gutterWidth, this.$size.width, this.$size.height);
this._signal("scrollbarVisibilityChanged"); this._signal("scrollbarVisibilityChanged");
} }
return changes;
}; };
this.$updateLines = function() { this.$updateLines = function() {
@ -1070,8 +1086,10 @@ var VirtualRenderer = function(container, theme) {
var left = pos.left; var left = pos.left;
var top = pos.top; var top = pos.top;
var scrollTop = this.$scrollAnimation ? this.session.getScrollTop() : this.scrollTop;
if (this.scrollTop > top) { if (scrollTop > top) {
if (offset) if (offset)
top -= offset * this.$size.scrollerHeight; top -= offset * this.$size.scrollerHeight;
if (top == 0) if (top == 0)
@ -1079,7 +1097,7 @@ var VirtualRenderer = function(container, theme) {
else if (top == 0) else if (top == 0)
top = + this.scrollMargin.bottom; top = + this.scrollMargin.bottom;
this.session.setScrollTop(top); this.session.setScrollTop(top);
} else if (this.scrollTop + this.$size.scrollerHeight < top + this.lineHeight) { } else if (scrollTop + this.$size.scrollerHeight < top + this.lineHeight) {
if (offset) if (offset)
top += offset * this.$size.scrollerHeight; top += offset * this.$size.scrollerHeight;
this.session.setScrollTop(top + this.lineHeight - this.$size.scrollerHeight); this.session.setScrollTop(top + this.lineHeight - this.$size.scrollerHeight);
@ -1196,31 +1214,44 @@ var VirtualRenderer = function(container, theme) {
this.animateScrolling = function(fromValue, callback) { this.animateScrolling = function(fromValue, callback) {
var toValue = this.scrollTop; var toValue = this.scrollTop;
if (this.$animatedScroll) { if (!this.$animatedScroll)
var _self = this; return;
var steps = _self.$calcSteps(fromValue, toValue); var _self = this;
this.$scrollAnimation = {from: fromValue, to: toValue};
if (fromValue == toValue)
clearInterval(this.$timer); return;
_self.session.setScrollTop(steps.shift()); if (this.$scrollAnimation) {
this.$timer = setInterval(function() { var oldSteps = this.$scrollAnimation.steps;
if (steps.length) { if (oldSteps.length) {
_self.session.setScrollTop(steps.shift()); fromValue = oldSteps[0];
// trick session to think it's already scrolled to not loose toValue if (fromValue == toValue)
_self.session.$scrollTop = toValue; return;
} else if (toValue != null) { }
_self.session.$scrollTop = -1;
_self.session.setScrollTop(toValue);
toValue = null;
} else {
// do this on separate step to not get spurious scroll event from scrollbar
_self.$timer = clearInterval(_self.$timer);
_self.$scrollAnimation = null;
callback && callback();
}
}, 10);
} }
var steps = _self.$calcSteps(fromValue, toValue);
this.$scrollAnimation = {from: fromValue, to: toValue, steps: steps};
clearInterval(this.$timer);
_self.session.setScrollTop(steps.shift());
this.$timer = setInterval(function() {
if (steps.length) {
_self.session.setScrollTop(steps.shift());
// trick session to think it's already scrolled to not loose toValue
_self.session.$scrollTop = toValue;
} else if (toValue != null) {
_self.session.$scrollTop = -1;
_self.session.setScrollTop(toValue);
toValue = null;
} else {
// do this on separate step to not get spurious scroll event from scrollbar
_self.$timer = clearInterval(_self.$timer);
_self.$scrollAnimation = null;
callback && callback();
}
}, 10);
}; };
/** /**