Show horizontal scrollbar only when needed

This commit is contained in:
Joe Cheng 2011-02-14 21:34:20 +08:00 коммит произвёл Fabian Jakobs
Родитель 4d8e4b29ab
Коммит 14ebde8b24
2 изменённых файлов: 25 добавлений и 2 удалений

Просмотреть файл

@ -69,7 +69,7 @@ var ScrollBar = function(parent) {
};
this.setHeight = function(height) {
this.element.style.height = Math.max(0, height - this.width) + "px";
this.element.style.height = height + "px";
};
this.setInnerHeight = function(height) {

Просмотреть файл

@ -88,6 +88,10 @@ var VirtualRenderer = function(container, theme) {
this.$cursorLayer = new CursorLayer(this.content);
this.$cursorPadding = 8;
// Indicates whether the horizontal scrollbar is visible
this.$horizScroll = true;
this.$horizScrollAlwaysVisible = true;
this.scrollBar = new ScrollBar(container);
this.scrollBar.addEventListener("scroll", this.onScroll.bind(this));
@ -199,7 +203,7 @@ var VirtualRenderer = function(container, theme) {
this.$size.height = height;
this.scroller.style.height = height + "px";
this.scrollBar.setHeight(height);
this.scrollBar.setHeight(this.scroller.clientHeight);
if (this.session) {
this.scrollToY(this.getScrollTop());
@ -361,6 +365,14 @@ var VirtualRenderer = function(container, theme) {
this.$updatePrintMargin();
};
this.setHScrollBarAlwaysVisible = function(alwaysVisible) {
if (this.$horizScrollAlwaysVisible != alwaysVisible) {
this.$horizScrollAlwaysVisible = alwaysVisible;
if (!this.$horizScrollAlwaysVisible || !this.$horizScroll)
this.$loop.schedule(this.CHANGE_SCROLL);
}
}
this.onScroll = function(e) {
this.scrollToY(e.data);
};
@ -446,6 +458,12 @@ var VirtualRenderer = function(container, theme) {
var longestLine = this.$getLongestLine();
var widthChanged = !this.layerConfig ? true : (this.layerConfig.width != longestLine);
var horizScroll = this.$horizScrollAlwaysVisible || this.$size.scrollerWidth - longestLine < 0;
var horizScrollChanged = this.$horizScroll !== horizScroll;
this.$horizScroll = horizScroll;
if (horizScrollChanged)
this.scroller.style.overflowX = horizScroll ? "scroll" : "hidden";
var lineCount = Math.ceil(minHeight / this.lineHeight) - 1;
var firstRow = Math.max(0, Math.round((this.scrollTop - offset) / this.lineHeight));
var lastRow = firstRow + lineCount;
@ -480,6 +498,11 @@ var VirtualRenderer = function(container, theme) {
this.content.style.marginTop = (-offset) + "px";
this.content.style.width = longestLine + "px";
this.content.style.height = minHeight + "px";
// Horizontal scrollbar visibility may have changed, which changes
// the client height of the scroller
if (horizScrollChanged)
this.onResize(true);
};
this.$updateLines = function() {