use getBoundingClientRect for measuring text size

needed because on chrome 17+ line heights can be fractional
This commit is contained in:
nightwing 2012-04-11 13:48:12 +04:00
commit 9a45c466ae
2 changed files with 39 additions and 3 deletions

View file

@ -103,7 +103,7 @@ var Text = function(parentEl) {
lineHeight : 1
};
this.$measureSizes = function() {
this.$measureSizes = useragent.isIE || useragent.isOldGecko ? function() {
var n = 1000;
if (!this.$measureNode) {
var measureNode = this.$measureNode = dom.createElement("div");
@ -130,7 +130,6 @@ var Text = function(parentEl) {
container = container.parentNode;
container.appendChild(measureNode);
}
}
// Size and width can be null if the editor is not visible or
@ -150,7 +149,42 @@ var Text = function(parentEl) {
// Size and width can be null if the editor is not visible or
// detached from the document
if (size.width == 0 && size.height == 0)
if (size.width == 0 || size.height == 0)
return null;
return size;
}
: function() {
if (!this.$measureNode) {
var measureNode = this.$measureNode = dom.createElement("div");
var style = measureNode.style;
style.width = style.height = "auto";
style.left = style.top = -100 + "px";
style.visibility = "hidden";
style.position = "fixed";
style.overflow = "visible";
style.whiteSpace = "nowrap";
measureNode.innerHTML = "X";
var container = this.element.parentNode;
while (!dom.hasCssClass(container, "ace_editor"))
container = container.parentNode;
container.appendChild(measureNode);
}
var rect = this.$measureNode.getBoundingClientRect();
var size = {
height: rect.height,
width: rect.width
};
// Size and width can be null if the editor is not visible or
// detached from the document
if (size.width == 0 || size.height == 0)
return null;
return size;

View file

@ -83,6 +83,8 @@ var ScrollBar = function(parent) {
this.inner.style.height = height + "px";
};
// TODO: on chrome 17+ after for small zoom levels after this function
// this.element.scrollTop != scrollTop which makes page to scroll up.
this.setScrollTop = function(scrollTop) {
this.element.scrollTop = scrollTop;
};