incubator-xap-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jmarga...@apache.org
Subject svn commit: r576646 - in /incubator/xap/trunk/codebase/src/dojo/src/html: color.js display.js layout.js style.js util.js
Date Tue, 18 Sep 2007 01:34:25 GMT
Author: jmargaris
Date: Mon Sep 17 18:34:24 2007
New Revision: 576646

URL: http://svn.apache.org/viewvc?rev=576646&view=rev
Log:
efficiency changes for computed style and such

Modified:
    incubator/xap/trunk/codebase/src/dojo/src/html/color.js
    incubator/xap/trunk/codebase/src/dojo/src/html/display.js
    incubator/xap/trunk/codebase/src/dojo/src/html/layout.js
    incubator/xap/trunk/codebase/src/dojo/src/html/style.js
    incubator/xap/trunk/codebase/src/dojo/src/html/util.js

Modified: incubator/xap/trunk/codebase/src/dojo/src/html/color.js
URL: http://svn.apache.org/viewvc/incubator/xap/trunk/codebase/src/dojo/src/html/color.js?rev=576646&r1=576645&r2=576646&view=diff
==============================================================================
--- incubator/xap/trunk/codebase/src/dojo/src/html/color.js (original)
+++ incubator/xap/trunk/codebase/src/dojo/src/html/color.js Mon Sep 17 18:34:24 2007
@@ -20,7 +20,8 @@
 	node = dojo.byId(node);
 	var color;
 	do{
-		color = dojo.html.getStyle(node, "background-color");
+		//DOJO efficiency change
+		color = dojo.html.getStyle2(node, "background-color", "backgroundColor");
 		// Safari doesn't say "transparent"
 		if(color.toLowerCase() == "rgba(0, 0, 0, 0)") { color = "transparent"; }
 		if(node == document.getElementsByTagName("body")[0]) { node = null; break; }

Modified: incubator/xap/trunk/codebase/src/dojo/src/html/display.js
URL: http://svn.apache.org/viewvc/incubator/xap/trunk/codebase/src/dojo/src/html/display.js?rev=576646&r1=576645&r2=576646&view=diff
==============================================================================
--- incubator/xap/trunk/codebase/src/dojo/src/html/display.js (original)
+++ incubator/xap/trunk/codebase/src/dojo/src/html/display.js Mon Sep 17 18:34:24 2007
@@ -21,7 +21,8 @@
 	//	summary
 	//	Show the passed element by reverting display property set by dojo.html.hide
 	node = dojo.byId(node);
-	if(dojo.html.getStyleProperty(node, 'display')=='none'){
+	//DOJO efficiency change
+	if(dojo.html.getStyleProperty2(node, 'display', 'display')=='none'){
 		dojo.html.setStyle(node, 'display', (node.dojoDisplayCache||''));
 		node.dojoDisplayCache = undefined;	// cannot use delete on a node in IE6
 	}
@@ -32,7 +33,8 @@
 	//	Hide the passed element by setting display:none
 	node = dojo.byId(node);
 	if(typeof node["dojoDisplayCache"] == "undefined"){ // it could == '', so we cannot say
!node.dojoDisplayCount
-		var d = dojo.html.getStyleProperty(node, 'display')
+		//DOJO efficiency change
+		var d = dojo.html.getStyleProperty2(node, 'display', 'display')
 		if(d!='none'){
 			node.dojoDisplayCache = d;
 		}
@@ -50,7 +52,8 @@
 	//	summary
 	//	Returns whether the element is displayed or not.
 	// FIXME: returns true if node is bad, isHidden would be easier to make correct
-	return (dojo.html.getStyleProperty(node, 'display') != 'none');	//	boolean
+	//DOJO efficiency change
+	return (dojo.html.getStyleProperty2(node, 'display', 'display') != 'none');	//	boolean
 }
 
 dojo.html.toggleShowing = function(/* HTMLElement */node){
@@ -85,7 +88,8 @@
 	//	summary
 	// 	Is true if the the computed display style for node is not 'none'
 	// 	FIXME: returns true if node is bad, isNotDisplayed would be easier to make correct
-	return (dojo.html.getComputedStyle(node, 'display') != 'none');	//	boolean
+	//DOJO efficiency change
+	return (dojo.html.getComputedStyle2(node, 'display', 'display') != 'none');	//	boolean
 }
 
 dojo.html.toggleDisplay = function(/* HTMLElement */node){
@@ -106,7 +110,8 @@
 	//	summary
 	// 	Returns true if the the computed visibility style for node is not 'hidden'
 	// 	FIXME: returns true if node is bad, isInvisible would be easier to make correct
-	return (dojo.html.getComputedStyle(node, 'visibility') != 'hidden');	//	boolean
+	//DOJO efficiency change
+	return (dojo.html.getComputedStyle2(node, 'visibility', 'visibility') != 'hidden');	//	boolean
 }
 
 dojo.html.toggleVisibility = function(node){

Modified: incubator/xap/trunk/codebase/src/dojo/src/html/layout.js
URL: http://svn.apache.org/viewvc/incubator/xap/trunk/codebase/src/dojo/src/html/layout.js?rev=576646&r1=576645&r2=576646&view=diff
==============================================================================
--- incubator/xap/trunk/codebase/src/dojo/src/html/layout.js (original)
+++ incubator/xap/trunk/codebase/src/dojo/src/html/layout.js Mon Sep 17 18:34:24 2007
@@ -22,7 +22,8 @@
 	
 	var retVal = 0;
 	while(node){
-		if(dojo.html.getComputedStyle(node, 'position') == 'fixed'){
+		//DOJO efficiency change
+		if(dojo.html.getComputedStyle2(node, 'position', 'position') == 'fixed'){
 			return 0;
 		}
 		var val = node[prop];
@@ -189,7 +190,8 @@
 dojo.html.isPositionAbsolute = function(/* HTMLElement */node){
 	//	summary
 	//	Returns true if the element is absolutely positioned.
-	return (dojo.html.getComputedStyle(node, 'position') == 'absolute');	//	boolean
+	//DOJO efficiency change
+	return (dojo.html.getComputedStyle2(node, 'position', 'position') == 'absolute');	//	boolean
 }
 
 dojo.html._sumPixelValues = function(/* HTMLElement */node, selectors, autoIsZero){
@@ -201,20 +203,25 @@
 }
 
 dojo.html.getMargin = function(/* HTMLElement */node){
+	//DOJO efficiency change
+	var isAbsolute = (dojo.html.getComputedStyle2(node, 'position', 'position') == 'absolute');
 	//	summary
 	//	Returns the width and height of the passed node's margin
 	return {
-		width: dojo.html._sumPixelValues(node, ["margin-left", "margin-right"], (dojo.html.getComputedStyle(node,
'position') == 'absolute')),
-		height: dojo.html._sumPixelValues(node, ["margin-top", "margin-bottom"], (dojo.html.getComputedStyle(node,
'position') == 'absolute'))
+		width: dojo.html._sumPixelValues2(node, ["margin-left", "margin-right"], isAbsolute, ['marginLeft','marginRight']),
+		height: dojo.html._sumPixelValues2(node, ["margin-top", "margin-bottom"], isAbsolute, ['marginTop','marginBottom'])
 	};	//	object
 }
 
 dojo.html.getBorder = function(/* HTMLElement */node){
+	//DOJO efficiency change
 	//	summary
 	//	Returns the width and height of the passed node's border
 	return {
-		width: dojo.html.getBorderExtent(node, 'left') + dojo.html.getBorderExtent(node, 'right'),
-		height: dojo.html.getBorderExtent(node, 'top') + dojo.html.getBorderExtent(node, 'bottom')
+		width: dojo.html.getBorderExtent2(node, ['border-left-style', 'border-left-width'], ['borderLeftStyle','borderLeftWidth'])
+ 
+			dojo.html.getBorderExtent2(node, ['border-right-style', 'border-right-width'], ['borderRightStyle','borderRightWidth']),
+		height: dojo.html.getBorderExtent2(node, ['border-top-style', 'border-top-width'], ['borderTopStyle','borderTopWidth'])
+ 
+			dojo.html.getBorderExtent2(node, ['border-bottom-right', 'border-bottom-width'], ['borderBottomStyle','borderBottomWidth'])
 	};	//	object
 }
 
@@ -236,12 +243,29 @@
 	return dojo.html._sumPixelValues(node, ["padding-" + side], true);	//	integer
 }
 
+
+//DOJO efficiency change
+dojo.html._sumPixelValues2 = function(/* HTMLElement */node, selectors, autoIsZero, properties){
+	var total = 0;
+	for(var x=0; x<selectors.length; x++){
+		total += dojo.html.getPixelValue2(node, selectors[x], autoIsZero, properties[x]);
+	}
+	return total;
+}
+
+dojo.html.getBorderExtent2 = function(/* HTMLElement */node, cssSelector, propertyName){
+	//	summary
+	//	returns the width of the requested border
+	return (dojo.html.getStyle2(node, cssSelector[0], propertyName[0]) == 'none' ? 0 : dojo.html.getPixelValue2(node,
cssSelector[1], propertyName[1]));	// integer
+}
+
 dojo.html.getPadding = function(/* HTMLElement */node){
+	//DOJO efficiency change
 	//	summary
 	//	Returns the width and height of the passed node's padding
 	return {
-		width: dojo.html._sumPixelValues(node, ["padding-left", "padding-right"], true),
-		height: dojo.html._sumPixelValues(node, ["padding-top", "padding-bottom"], true)
+		width: dojo.html._sumPixelValues(node, ["padding-left", "padding-right"], true, ['paddingLeft','paddingRight']),
+		height: dojo.html._sumPixelValues(node, ["padding-top", "padding-bottom"], true, ['paddingTop','paddingBottom'])
 	};	//	object
 }
 

Modified: incubator/xap/trunk/codebase/src/dojo/src/html/style.js
URL: http://svn.apache.org/viewvc/incubator/xap/trunk/codebase/src/dojo/src/html/style.js?rev=576646&r1=576645&r2=576646&view=diff
==============================================================================
--- incubator/xap/trunk/codebase/src/dojo/src/html/style.js (original)
+++ incubator/xap/trunk/codebase/src/dojo/src/html/style.js Mon Sep 17 18:34:24 2007
@@ -225,6 +225,43 @@
 	return selector.replace(dojo.html.toSelectorCase.re, "-$1" ).toLowerCase();	//	string
 }
 
+//the original version of this method does a lot of manipulation which is bad,
+//here we force them to just pass in the right strings to begin with.
+//the CSS selector should be the real css name, and the property (the new param) should be
the param name
+//DOJO efficiency change
+dojo.html.getComputedStyle2 = function(/* HTMLElement */node, /* string */cssSelector, property,
/* integer? */inValue){
+	//	summary
+	//	Returns the computed style of cssSelector on node.
+	node = dojo.byId(node);
+	// cssSelector may actually be in camel case, so force selector version
+	if(!node || !node.style){
+		return inValue;			
+	} else if (document.defaultView && dojo.html.isDescendantOf(node, node.ownerDocument)){
// W3, gecko, KHTML
+		try{
+			// mozilla segfaults when margin-* and node is removed from doc
+			// FIXME: need to figure out a if there is quicker workaround
+			var cs = document.defaultView.getComputedStyle(node, "");
+			if(cs){
+				return cs.getPropertyValue(cssSelector);	//	integer
+			} 
+		}catch(e){ // reports are that Safari can throw an exception above
+			if(node.style.getPropertyValue){ // W3
+				return node.style.getPropertyValue(cssSelector);	//	integer
+			} else {
+				return inValue;	//	integer
+			}
+		}
+	} else if(node.currentStyle){ // IE
+		return node.currentStyle[property];	//	integer
+	}
+	
+	if(node.style.getPropertyValue){ // W3
+		return node.style.getPropertyValue(cssSelector);	//	integer
+	}else{
+		return inValue;	//	integer
+	}
+}
+
 dojo.html.getComputedStyle = function(/* HTMLElement */node, /* string */cssSelector, /*
integer? */inValue){
 	//	summary
 	//	Returns the computed style of cssSelector on node.
@@ -267,6 +304,14 @@
 	return (node && node.style ? node.style[dojo.html.toCamelCase(cssSelector)] : undefined);
//	string
 }
 
+//DOJO efficiency change
+dojo.html.getStyleProperty2 = function(/* HTMLElement */node, /* string */cssSelector, property){
+	//	summary
+	//	Returns the value of the passed style
+	node = dojo.byId(node);
+	return (node && node.style ? node.style[property] : undefined);	//	string
+}
+
 dojo.html.getStyle = function(/* HTMLElement */node, /* string */cssSelector){
 	//	summary
 	//	Returns the computed value of the passed style
@@ -274,6 +319,14 @@
 	return (value ? value : dojo.html.getComputedStyle(node, cssSelector));	//	string || integer
 }
 
+//DOJO efficiency change
+dojo.html.getStyle2 = function(/* HTMLElement */node, /* string */cssSelector, property){
+	//	summary
+	//	Returns the computed value of the passed style
+	var value = dojo.html.getStyleProperty2(node, cssSelector, property);
+	return (value ? value : dojo.html.getComputedStyle2(node, cssSelector, property));	//	string
|| integer
+}
+
 dojo.html.setStyle = function(/* HTMLElement */node, /* string */cssSelector, /* string */value){
 	//	summary
 	//	Set the value of passed style on node
@@ -305,6 +358,20 @@
 	dojo.html.addClass(target, dojo.html.getClass(source));
 }
 
+//DOJO efficiency change
+dojo.html.getUnitValue2 = function(/* HTMLElement */node, /* string */cssSelector, /* boolean?
*/autoIsZero, property){
+	//	summary
+	//	Get the value of passed selector, with the specific units used
+	var s = dojo.html.getComputedStyle2(node, cssSelector,property);
+	if((!s)||((s == 'auto')&&(autoIsZero))){ 
+		return { value: 0, units: 'px' };	//	object 
+	}
+	// FIXME: is regex inefficient vs. parseInt or some manual test? 
+	var match = s.match(/(\-?[\d.]+)([a-z%]*)/i);
+	if (!match){return dojo.html.getUnitValue.bad;}
+	return { value: Number(match[1]), units: match[2].toLowerCase() };	//	object
+}
+
 dojo.html.getUnitValue = function(/* HTMLElement */node, /* string */cssSelector, /* boolean?
*/autoIsZero){
 	//	summary
 	//	Get the value of passed selector, with the specific units used
@@ -323,6 +390,23 @@
 	//	summary
 	//	Get the value of passed selector in pixels.
 	var result = dojo.html.getUnitValue(node, cssSelector, autoIsZero);
+	// FIXME: there is serious debate as to whether or not this is the right solution
+	if(isNaN(result.value)){ 
+		return 0; //	integer 
+	}	
+	// FIXME: code exists for converting other units to px (see Dean Edward's IE7) 
+	// but there are cross-browser complexities
+	if((result.value)&&(result.units != 'px')){ 
+		return NaN;	//	integer 
+	}
+	return result.value;	//	integer
+}
+
+//DOJO efficiency change
+dojo.html.getPixelValue2 = function(/* HTMLElement */node, /* string */cssSelector, /* boolean?
*/autoIsZero, propertyName){
+	//	summary
+	//	Get the value of passed selector in pixels.
+	var result = dojo.html.getUnitValue2(node, cssSelector, autoIsZero, propertyName);
 	// FIXME: there is serious debate as to whether or not this is the right solution
 	if(isNaN(result.value)){ 
 		return 0; //	integer 

Modified: incubator/xap/trunk/codebase/src/dojo/src/html/util.js
URL: http://svn.apache.org/viewvc/incubator/xap/trunk/codebase/src/dojo/src/html/util.js?rev=576646&r1=576645&r2=576646&view=diff
==============================================================================
--- incubator/xap/trunk/codebase/src/dojo/src/html/util.js (original)
+++ incubator/xap/trunk/codebase/src/dojo/src/html/util.js Mon Sep 17 18:34:24 2007
@@ -126,7 +126,8 @@
 			case 5: // ENTITY_REFERENCE_NODE
 				var display = "unknown";
 				try {
-					display = dojo.html.getStyle(node.childNodes[i], "display");
+					//DOJO efficiency change
+					display = dojo.html.getStyle2(node.childNodes[i], "display", "display");
 				} catch(E) {}
 				switch (display) {
 					case "block": case "list-item": case "run-in":



Mime
View raw message