Skip to content

Commit

Permalink
Merge branch 'master' into frame-scope
Browse files Browse the repository at this point in the history
  • Loading branch information
gleneivey committed Apr 23, 2010
2 parents 97f13b8 + 15ce602 commit d421bd0
Show file tree
Hide file tree
Showing 13 changed files with 240 additions and 95 deletions.
5 changes: 5 additions & 0 deletions htmlparser/gwt2/checkout.sh
@@ -0,0 +1,5 @@
#!/bin/sh

# This is where active development occurs
#
hg clone https://hg.mozilla.org/projects/htmlparser
84 changes: 84 additions & 0 deletions specs/html/spec.js
Expand Up @@ -421,6 +421,72 @@ test('HTMLHtmlElement', function() {
equals(a.toString(), '[object HTMLHtmlElement]');
});

test('HTMLInputElement', function() {
var a = document.createElement('input');
ok(a, 'element created');
equals(a.toString(), '[object HTMLInputElement]');
equals(a.alt, '', 'empty alt is string');
a.alt = 'foo';
equals(a.alt, 'foo', 'set alt');

equals(a.src, '', 'empty src is string');
a.src = 'http://envjs.com/';
equals(a.src, 'http://envjs.com/', 'set src');
// TODO, src should make absolute any relative links

/**
* Checked is a virtual state, NOT an attribute
*
*/
equals(a.defaultChecked, false, 'defaultChecked value is false');
equals(a.checked, false, 'default checked value is false');
equals(a.getAttribute('checked'), null, 'getAttribte(checked) is null');
equals(a.hasAttribute('checked'), false, 'hasAttribute(checked) is false');

equals(typeof a.checked, 'boolean', 'default checked value is boolean');
a.checked = true;
equals(a.checked, true, 'set checked value is true');
equals(a.getAttribute('checked'), null, 'getAttribte(checked) is null');
equals(a.hasAttribute('checked'), false, 'hasAttribute(checked) is false');

a.checked = false;
equals(a.defaultChecked, false, 'defaultChecked value is still false');
a.defaultChecked = true;
equals(a.defaultChecked, true, 'set defaultChecked value is true');
equals(a.checked, false, 'set checked is still false');
equals(a.getAttribute('checked'), '', 'getAttribte(checked) is null');
equals(a.hasAttribute('checked'), true, 'hasAttribute(checked) is false');
a.defaultChecked = false
equals(a.defaultChecked, false, 'set defaultChecked value is false');
equals(a.hasAttribute('checked'), false, 'hasAttribute(checked) is false');

equals(a.useMap, '', 'useMap is false');
equals(typeof a.useMap, 'string', 'default useMap value is boolean');

/**
* Numeric-like things
*/
equals(a.maxLength, -1, 'default maxLength');
equals(typeof a.maxLength, 'number', 'default maxLegth is number');

// FF says it's undefined!
//equals(typeof a.height, 'undefined', 'default height is undefined');
//equals(typeof a.width,'undefined', 'default width is undefined');

a.maxLength = '10';
equals(a.maxLength, 10, 'set maxLength');
equals(typeof a.maxLength, 'number', 'maxLength is number');

a.width = '10';
equals(a.width, 10, 'set width');
equals(typeof a.width, 'string', 'width is number');

a.height = '10';
equals(a.height, 10, 'set height');
equals(typeof a.height, 'string', 'height is number');

});

test('HTMLLabelElement', function() {
var element;

Expand Down Expand Up @@ -566,6 +632,24 @@ test('HTMLTableSectionElement', function() {
equals(element.toString(), '[object HTMLTableSectionElement]', 'toString');
});

test('HTMLTextArea', function() {
var e;
e = document.createElement('textarea');
ok(e, 'element created');
equals(e.toString(), '[object HTMLTextAreaElement]', 'toString');

equals(e.cols, -1, 'default cols is -1');
e.cols = '10';
equals(e.cols, 10, 'set cols');
equals(typeof e.cols, 'number', 'cols is a number');

equals(e.rows, -1, 'default rows is -1');
e.rows = '11';
equals(e.rows, 11, 'set row');
equals(typeof e.rows, 'number', 'rows is a number');

});

test('HTMLTitleElement', function() {
var element;
element = document.createElement('title');
Expand Down
51 changes: 50 additions & 1 deletion specs/parser/spec.js
Expand Up @@ -357,4 +357,53 @@ test('Link Loading', function(){
doc.write('<html><head></head><body><link rel="stylesheet" type="text/css" href="/foo"></body></html>');
doc.close();
stop();
});
});

test('Form Named Element Lookup', function(){
expect(10);
if ((typeof Envjs == 'undefined') || !Envjs) {
Envjs = {};
}
var iframe = document.createElement("iframe");
document.body.appendChild(iframe);

iframe.addEventListener('load', function(){
var doc = iframe.contentDocument;
ok(true, 'frame loaded');
var form = doc.foo;
var elements = form.elements;
ok(elements instanceof HTMLCollection, "form.elements is an HTMLCollection");
equals(elements.length, 0, "form.elements does not include non-form elements");
equals(form.length, 0, "form.length is 0");

// ok now let's try to use innerHTML
var str = '<form name="bar"><input name="input1"/></form>';
doc.body.innerHTML = str;
form = doc.bar;
elements = doc.bar.elements;
equals(elements.length, 1, 'elements length is 1');
equals(form.length, 1, 'form length is 1');
//print('element is : ' + elements.input1);
ok(elements.input1 instanceof HTMLInputElement, 'is HTMLInputElement');
ok(form.input1 instanceof HTMLInputElement, 'is HTMLInputElement');

// let's change the name
var node = form.input1;
node.name = 'input2';
ok(elements.input1 instanceof HTMLInputElement, 'is HTMLInputElement');
ok(form.input1 instanceof HTMLInputElement, 'is HTMLInputElement');

/*
// the other one should be zapped
node2 = doc.foo;
ok(! node2, 'old named element is gone');
*/
document.body.removeChild(iframe);
start();
}, false);

var doc = iframe.contentDocument;
doc.write('<html><head></head><body><form name="foo"><div></div></form></body></html>');
doc.close();
stop();
});
36 changes: 0 additions & 36 deletions specs/window/spec.js
Expand Up @@ -11,7 +11,6 @@ function giveAHoot(){
var def = 456;
}


test('Window Interfaces Available', function(){

ok(Window, 'Window available');
Expand Down Expand Up @@ -593,38 +592,3 @@ test('Document Named Element Lookup', function(){
ok(!doc.foo, 'old named element not found via named lookup');
});

test('Form Named Element Lookup', function(){
expect(7);
var iframe = document.createElement("iframe");
var doc;

document.body.appendChild(iframe);
doc = iframe.contentDocument;
doc.open();
doc.write('<html><head></head><body><form name="foo"><div></div></form></body></html>');
doc.close();

var form = doc.foo;
var elements = form.elements;
ok(elements instanceof HTMLCollection, "form.elements is an HTMLCollection");
equals(elements.length, 0, "form.elements does not include non-form elements");
equals(form.length, 0, "form.length is 0");


// ok now let's try to use innerHTML
var str = '<form name="bar"><input name="input1"/></form>';
doc.body.innerHTML = str;
form = doc.bar;
elements = doc.bar.elements;
equals(elements.length, 1);
equals(form.length, 1);
//print('element is : ' + elements.input1);
ok(elements.input1 instanceof HTMLInputElement);
ok(form.input1 instanceof HTMLInputElement);

/*
// the other one should be zapped
node2 = doc.foo;
ok(! node2, 'old named element is gone');
*/
});
3 changes: 3 additions & 0 deletions src/html/button.js
Expand Up @@ -28,3 +28,6 @@ __extend__(HTMLButtonElement.prototype, {
}
});

// Named Element Support
HTMLElement.registerSetAttribute('BUTTON', 'name',
__updateFormForNamedElement__);
43 changes: 1 addition & 42 deletions src/html/element.js
Expand Up @@ -165,41 +165,6 @@ __extend__(HTMLElement.prototype, {
return ret;
},

/**
* Named Element Support
*/

/**
* Not all children of a form are named elements
* returns the parent form element or null if
* there is no parent form or if not a named element
*/
_isFormNamedElement: function(node) {
if (node.nodeType === Node.ELEMENT_NODE) {
switch (node.nodeName.toLowerCase()) {
case 'button':
case 'fieldset':
case 'input':
case 'keygen':
case 'select':
case 'output':
case 'select':
case 'textarea':
return true;
}
}
return false;
},
_updateFormForNamedElement: function() {
if (this._isFormNamedElement(this)) {
if (this.form) {
// to check for ID or NAME attribute too
// not, then nothing to do
this.form._updateElements();
}
}
},

/**
* setAttribute use a dispatch table that other tags can set to
* "listen" to various values being set. The dispatch table
Expand All @@ -211,8 +176,6 @@ __extend__(HTMLElement.prototype, {
setAttribute: function(name, value) {
var result = Element.prototype.setAttribute.apply(this, arguments);
this.ownerDocument._addNamedMap(this);
this._updateFormForNamedElement();

var tagname = this.tagName;
var callback = HTMLElement.getAttributeCallback('set', tagname, name);
if (callback) {
Expand All @@ -222,7 +185,6 @@ __extend__(HTMLElement.prototype, {
setAttributeNS: function(namespaceURI, name, value) {
var result = Element.prototype.setAttributeNS.apply(this, arguments);
this.ownerDocument._addNamedMap(this);
this._updateFormForNamedElement();

var tagname = this.tagName;
var callback = HTMLElement.getAttributeCallback('set', tagname, name);
Expand All @@ -235,7 +197,6 @@ __extend__(HTMLElement.prototype, {
setAttributeNode: function(newnode) {
var result = Element.prototype.setAttributeNode.apply(this, arguments);
this.ownerDocument._addNamedMap(this);
this._updateFormForNamedElement();

var tagname = this.tagName;
var callback = HTMLElement.getAttributeCallback('set', tagname, newnode.name);
Expand All @@ -247,7 +208,7 @@ __extend__(HTMLElement.prototype, {
setAttributeNodeNS: function(newnode) {
var result = Element.prototype.setAttributeNodeNS.apply(this, arguments);
this.ownerDocument._addNamedMap(this);
this._updateFormForNamedElement();

var tagname = this.tagName;
var callback = HTMLElement.getAttributeCallback('set', tagname, newnode.name);
if (callback) {
Expand All @@ -274,7 +235,6 @@ __extend__(HTMLElement.prototype, {
importNode: function(othernode, deep) {
var newnode = Element.prototype.importNode.apply(this, arguments);
this.ownerDocument._addNamedMap(newnode);
this._updateFormForNamedElement(newnode);
return newnode;
},

Expand All @@ -283,7 +243,6 @@ __extend__(HTMLElement.prototype, {
var newnode = Element.prototype.replaceNode.apply(this, arguments);
this.ownerDocument._removeNamedMap(oldchild);
this.ownerDocument._addNamedMap(newnode);
this._updateFormForNamedElement(newnode);
return newnode;
}
});
Expand Down
4 changes: 4 additions & 0 deletions src/html/fieldset.js
Expand Up @@ -20,3 +20,7 @@ __extend__(HTMLFieldSetElement.prototype, {
return '[object HTMLFieldSetElement]';
}
});

// Named Element Support
HTMLElement.registerSetAttribute('FIELDSET', 'name',
__updateFormForNamedElement__);
13 changes: 12 additions & 1 deletion src/html/form.js
Expand Up @@ -66,7 +66,18 @@ __extend__(HTMLFormElement.prototype,{
var alist = [];
var i;
for (i = 0; i < nodes.length; ++i) {
if (HTMLFormElement.prototype._isFormNamedElement(nodes[i])) {
nodename = nodes[i].nodeName;
// would like to replace switch with something else
// since it's redundant with the SetAttribute callbacks
switch (nodes[i].nodeName) {
case 'BUTTON':
case 'FIELDSET':
case 'INPUT':
case 'KEYGEN':
case 'OBJECT':
case 'OUTPUT':
case 'SELECT':
case 'TEXTAREA':
alist.push(nodes[i]);
this[i] = nodes[i];
if ('name' in nodes[i]) {
Expand Down
15 changes: 12 additions & 3 deletions src/html/input-elements.js
Expand Up @@ -10,12 +10,12 @@
* * legent (no value attr)
* * fieldset (no value attr)
* * label (no value attr)
* * option (custom)
* * option (custom value)
* HTMLTypeValueInputs (extends InputCommon)
* * select (custom)
* * select (custom value)
* * button (just sets value)
* HTMLInputAreaCommon (extends TypeValueIput)
* * input (X)
* * input (custom)
* * textarea (just sets value)
*
* -----------------------
Expand Down Expand Up @@ -264,3 +264,12 @@ __extend__(HTMLInputAreaCommon.prototype, {

}
});


var __updateFormForNamedElement__ = function(node, value) {
if (node.form) {
// to check for ID or NAME attribute too
// not, then nothing to do
node.form._updateElements();
}
};

0 comments on commit d421bd0

Please sign in to comment.