From: <no...@us...> - 2003-06-16 21:03:28
|
Log Message: ----------- Patch from Barnaby Court to consolidate all the input logic into HtmlInput. One test is currently broken. Modified Files: -------------- /cvsroot/htmlunit/htmlunit/src/java/com/gargoylesoftware/htmlunit/javascript: SimpleScriptable.java FormElementsArray.java JavaScriptEngine.java /cvsroot/htmlunit/htmlunit/src/java/com/gargoylesoftware/htmlunit/html: HtmlSubmitInput.java HtmlForm.java HtmlPage.java HtmlCheckBoxInput.java HtmlButtonInput.java HtmlInput.java HtmlHiddenInput.java HtmlFileInput.java HtmlPasswordInput.java HtmlTextInput.java HtmlRadioButtonInput.java HtmlImageInput.java HtmlResetInput.java /cvsroot/htmlunit/htmlunit/src/java/com/gargoylesoftware/htmlunit/javascript/host: Input.java Button.java Revision Data ------------- Index: HtmlSubmitInput.java =================================================================== RCS file: /cvsroot/htmlunit/htmlunit/src/java/com/gargoylesoftware/htmlunit/html/HtmlSubmitInput.java,v retrieving revision 1.9 retrieving revision 1.10 diff -u -d -r1.9 -r1.10 --- HtmlSubmitInput.java 10 Jun 2003 11:56:58 -0000 1.9 +++ HtmlSubmitInput.java 16 Jun 2003 21:03:24 -0000 1.10 @@ -37,9 +37,6 @@ */ package com.gargoylesoftware.htmlunit.html; -import com.gargoylesoftware.htmlunit.ElementNotFoundException; -import com.gargoylesoftware.htmlunit.Page; -import java.io.IOException; import org.w3c.dom.Element; /** @@ -60,56 +57,5 @@ super( page, element ); } - - /** - * Submit the form that contains this input - * - * @deprecated Use {@link #click()} instead - * @return The Page that is the result of submitting this page to the - * server - * @exception IOException If an io error occurs - * @exception ElementNotFoundException If a particular xml element could - * not be found in the dom model - */ - public Page submit() - throws - IOException, - ElementNotFoundException { - - return click(); - } - - - /** - * Submit the form that contains this input - * - * @return The Page that is the result of submitting this page to the - * server - * @exception IOException If an io error occurs - */ - public Page click() throws IOException { - return super.click(); - } - - - /** - * This method will be called if there either wasn't an onclick handler or there was - * but the result of that handler was true. This is the default behaviour of clicking - * the element. In this case, the method will submit the form. - * - * @return The page that is currently loaded after execution of this method - * @throws IOException If an IO error occured - */ - protected Page doClickAction() throws IOException { - return getEnclosingFormOrDie().submit(this); - } - - - /** - * Reset the value of this element to its initial state. This is a no-op for - * this component. - */ - public void reset() { - } } Index: HtmlForm.java =================================================================== RCS file: /cvsroot/htmlunit/htmlunit/src/java/com/gargoylesoftware/htmlunit/html/HtmlForm.java,v retrieving revision 1.20 retrieving revision 1.21 diff -u -d -r1.20 -r1.21 --- HtmlForm.java 10 Jun 2003 11:56:57 -0000 1.20 +++ HtmlForm.java 16 Jun 2003 21:03:24 -0000 1.21 @@ -99,7 +99,7 @@ final Iterator iterator = inputList.iterator(); while( iterator.hasNext() ) { final HtmlInput input = (HtmlInput)iterator.next(); - if( input instanceof HtmlSubmitInput ) { + if( input.getTypeAttribute().equals("submit")) { return submit( ( SubmittableElement )input ); } } Index: HtmlPage.java =================================================================== RCS file: /cvsroot/htmlunit/htmlunit/src/java/com/gargoylesoftware/htmlunit/html/HtmlPage.java,v retrieving revision 1.46 retrieving revision 1.47 diff -u -d -r1.46 -r1.47 --- HtmlPage.java 10 Jun 2003 11:56:58 -0000 1.46 +++ HtmlPage.java 16 Jun 2003 21:03:24 -0000 1.47 @@ -1132,11 +1132,8 @@ if( element instanceof HtmlButton ) { newPage = ((HtmlButton)element).click(); } - else if( element instanceof HtmlSubmitInput ) { - newPage = ((HtmlSubmitInput)element).click(); - } - else if( element instanceof HtmlResetInput ) { - newPage = ((HtmlResetInput)element).click(); + else if( element instanceof HtmlInput ) { + newPage = ((HtmlInput)element).click(); } else { newPage = this; Index: HtmlCheckBoxInput.java =================================================================== RCS file: /cvsroot/htmlunit/htmlunit/src/java/com/gargoylesoftware/htmlunit/html/HtmlCheckBoxInput.java,v retrieving revision 1.12 retrieving revision 1.13 diff -u -d -r1.12 -r1.13 --- HtmlCheckBoxInput.java 10 Jun 2003 11:56:57 -0000 1.12 +++ HtmlCheckBoxInput.java 16 Jun 2003 21:03:24 -0000 1.13 @@ -37,8 +37,6 @@ */ package com.gargoylesoftware.htmlunit.html; -import com.gargoylesoftware.htmlunit.Page; -import java.io.IOException; import org.w3c.dom.Element; /** @@ -49,8 +47,6 @@ */ public class HtmlCheckBoxInput extends HtmlInput { - private final boolean initialCheckedState_; - /** * Create an instance * @@ -59,52 +55,6 @@ */ HtmlCheckBoxInput( final HtmlPage page, final Element element ) { super( page, element ); - initialCheckedState_ = isAttributeDefined("checked"); - } - - - /** - * Set the "checked" attribute - * - * @param isChecked true if this element is to be selected - */ - public void setChecked( final boolean isChecked ) { - if( isChecked ) { - getElement().setAttribute( "checked", "checked" ); - } - else { - getElement().removeAttribute( "checked" ); - } - } - - - /** - * Return true if this element is currently selected - * - * @return See above - */ - public boolean isChecked() { - return isAttributeDefined("checked"); - } - - - /** - * Return the value of this element to what it was at the time the page was loaded. - */ - public void reset() { - setChecked(initialCheckedState_); - } - - - /** - * Submit the form that contains this input - * - * @return The Page that is the result of submitting this page to the - * server - * @exception IOException If an io error occurs - */ - public Page click() throws IOException { - return super.click(); } } Index: HtmlButtonInput.java =================================================================== RCS file: /cvsroot/htmlunit/htmlunit/src/java/com/gargoylesoftware/htmlunit/html/HtmlButtonInput.java,v retrieving revision 1.8 retrieving revision 1.9 diff -u -d -r1.8 -r1.9 --- HtmlButtonInput.java 10 Jun 2003 11:56:57 -0000 1.8 +++ HtmlButtonInput.java 16 Jun 2003 21:03:24 -0000 1.9 @@ -37,8 +37,6 @@ */ package com.gargoylesoftware.htmlunit.html; -import com.gargoylesoftware.htmlunit.Page; -import java.io.IOException; import org.w3c.dom.Element; /** @@ -57,25 +55,6 @@ */ HtmlButtonInput( final HtmlPage page, final Element element ) { super( page, element ); - } - - - /** - * Reset this element to its original values. This is a no-op for a button. - */ - public void reset() { - } - - - /** - * Submit the form that contains this input - * - * @return The Page that is the result of submitting this page to the - * server - * @exception IOException If an io error occurs - */ - public Page click() throws IOException { - return super.click(); } } Index: HtmlInput.java =================================================================== RCS file: /cvsroot/htmlunit/htmlunit/src/java/com/gargoylesoftware/htmlunit/html/HtmlInput.java,v retrieving revision 1.22 retrieving revision 1.23 diff -u -d -r1.22 -r1.23 --- HtmlInput.java 10 Jun 2003 11:56:57 -0000 1.22 +++ HtmlInput.java 16 Jun 2003 21:03:24 -0000 1.23 @@ -38,6 +38,7 @@ package com.gargoylesoftware.htmlunit.html; import com.gargoylesoftware.htmlunit.Assert; +import com.gargoylesoftware.htmlunit.ElementNotFoundException; import com.gargoylesoftware.htmlunit.KeyValuePair; import com.gargoylesoftware.htmlunit.Page; import com.gargoylesoftware.htmlunit.ScriptResult; @@ -50,7 +51,7 @@ * @version $Revision$ * @author <a href="mailto:mb...@Ga...">Mike Bowler</a> */ -public abstract class HtmlInput +public class HtmlInput extends HtmlElement implements SubmittableElement { @@ -65,6 +66,9 @@ HtmlInput( final HtmlPage page, final Element element ) { super( page, element ); originalValue_ = element.getAttribute("value"); + //From the checkbox creator + initialCheckedState_ = isAttributeDefined("checked"); + initialValue_ = getValueAttribute(); } @@ -94,6 +98,16 @@ * @return See above */ public KeyValuePair[] getSubmitKeyValuePairs() { + if (getTypeAttribute().equals("image")) { + final String name = getNameAttribute(); + if( wasPositionSpecified_ == true ) { + return new KeyValuePair[]{ + new KeyValuePair( name, getValueAttribute() ), + new KeyValuePair( name+".x", String.valueOf(xPosition_) ), + new KeyValuePair( name+".y", String.valueOf(yPosition_) ) + }; + } + } return new KeyValuePair[]{new KeyValuePair( getNameAttribute(), getValueAttribute() )}; } @@ -107,7 +121,17 @@ * server * @exception IOException If an io error occurs */ - protected Page click() throws IOException { + public Page click() throws IOException { + + String type = this.getTypeAttribute(); + if (type.equals("file") || type.equals("hidden") || type.equals("password") || type.equals("text")) { + return getPage(); + } + if (type.equals("image")){ + if (! processingClick_ ) { + wasPositionSpecified_ = false; + } + } if( isDisabled() == true ) { return getPage(); @@ -137,7 +161,16 @@ * @throws IOException If an IO error occured */ protected Page doClickAction() throws IOException { - return getPage(); + final String type = getTypeAttribute(); + if (type.equals("image") || type.equals("submit")) { + return getEnclosingFormOrDie().submit(this); + } + else if (type.equals("reset")){ + return getEnclosingFormOrDie().reset(); + } + else { + return getPage(); + } } /** @@ -414,7 +447,7 @@ */ public final String getValueAttribute() { String value = getAttributeValue("value"); - if( value == ATTRIBUTE_NOT_DEFINED && this instanceof HtmlCheckBoxInput ) { + if( value == ATTRIBUTE_NOT_DEFINED && getTypeAttribute().equals("checkbox")) { value = "on"; } return value; @@ -636,4 +669,141 @@ public final String getAlignAttribute() { return getAttributeValue("align"); } + + //For Checkbox, radio + private final boolean initialCheckedState_; + //for Hidden, password + private final String initialValue_; + //For Image + private boolean wasPositionSpecified_ = false; + private boolean processingClick_ = false; + private int xPosition_; + private int yPosition_; + + /** + * Reset this element to its original values. + */ + public void reset() { + String type = this.getTypeAttribute(); + if( type.equals("checkbox")) { + setChecked(initialCheckedState_); + } + else if (type.equals("hidden") || type.equals("password")|| type.equals("text")) { + setValueAttribute(initialValue_); + } + else if (type.equals("radio")) { + if( initialCheckedState_ ) { + getElement().setAttribute("checked", "checked"); + } + else { + getElement().removeAttribute("checked"); + } + } + } + + /** + * Set the "checked" attribute + * + * @param isChecked true if this element is to be selected + */ + public void setChecked( final boolean isChecked ) { + String type = this.getTypeAttribute(); + if (type.equals("checkbox") ) { + setCheckedCheckBox(isChecked); + } + else if (type.equals("radio")){ + setCheckedRadio(isChecked); + } + } + + /** + * Set the "checked" attribute + * + * @param isChecked true if this element is to be selected + */ + private void setCheckedCheckBox( final boolean isChecked ) { + if( isChecked ) { + getElement().setAttribute( "checked", "checked" ); + } + else { + getElement().removeAttribute( "checked" ); + } + } + + /** + * Set the "checked" attribute + * + * @param isChecked true if this element is to be selected + */ + private final void setCheckedRadio( final boolean isChecked ) { + final HtmlForm form = getEnclosingForm(); + + if( isChecked ) { + try { + form.setCheckedRadioButton( getNameAttribute(), getValueAttribute() ); + } + catch( final ElementNotFoundException e ) { + // Shouldn't be possible + throw new IllegalStateException("Can't find this element when going up to the form and back down."); + } + } + else { + getElement().removeAttribute( "checked" ); + } + } + + + /** + * Return true if this element is currently selected + * + * @return See above + */ + public boolean isChecked() { + return isAttributeDefined("checked"); + } + /** + * Simulate clicking this input with a pointing device. The x and y coordinates + * of the pointing device will be sent to the server. + * + * @param x The x coordinate of the pointing device at the time of clicking + * @param y The y coordinate of the pointing device at the time of clicking + * @return The page that is loaded after the click has taken place. + * @exception IOException If an io error occurs + * @exception ElementNotFoundException If a particular xml element could + * not be found in the dom model + */ + public Page click( final int x, final int y ) + throws + IOException, + ElementNotFoundException { + + wasPositionSpecified_ = true; + xPosition_ = x; + yPosition_ = y; + processingClick_ = true; + Page returnValue = this.click(); + processingClick_ = false; + + return returnValue; + } + + /** + * Submit the form that contains this input + * + * @deprecated Use {@link #click()} instead + * @return The Page that is the result of submitting this page to the + * server + * @exception IOException If an io error occurs + * @exception ElementNotFoundException If a particular xml element could + * not be found in the dom model + */ + public Page submit() + throws + IOException, + ElementNotFoundException { + + return click(); + } + + } Index: HtmlHiddenInput.java =================================================================== RCS file: /cvsroot/htmlunit/htmlunit/src/java/com/gargoylesoftware/htmlunit/html/HtmlHiddenInput.java,v retrieving revision 1.5 retrieving revision 1.6 diff -u -d -r1.5 -r1.6 --- HtmlHiddenInput.java 10 Jun 2003 11:56:57 -0000 1.5 +++ HtmlHiddenInput.java 16 Jun 2003 21:03:24 -0000 1.6 @@ -46,9 +46,6 @@ * @author <a href="mailto:mb...@Ga...">Mike Bowler</a> */ public class HtmlHiddenInput extends HtmlInput { - - private final String initialValue_; - /** * Create an instance * @@ -57,15 +54,7 @@ */ HtmlHiddenInput( final HtmlPage page, final Element element ) { super( page, element ); - initialValue_ = getValueAttribute(); } - - /** - * Reset the value of this element to its initial state. - */ - public void reset() { - setValueAttribute(initialValue_); - } } Index: HtmlFileInput.java =================================================================== RCS file: /cvsroot/htmlunit/htmlunit/src/java/com/gargoylesoftware/htmlunit/html/HtmlFileInput.java,v retrieving revision 1.5 retrieving revision 1.6 diff -u -d -r1.5 -r1.6 --- HtmlFileInput.java 10 Jun 2003 11:56:57 -0000 1.5 +++ HtmlFileInput.java 16 Jun 2003 21:03:24 -0000 1.6 @@ -56,13 +56,5 @@ HtmlFileInput( final HtmlPage page, final Element element ) { super( page, element ); } - - - /** - * Reset the value of this element to its initial state. This is a no-op for - * this component. - */ - public void reset() { - } } Index: HtmlPasswordInput.java =================================================================== RCS file: /cvsroot/htmlunit/htmlunit/src/java/com/gargoylesoftware/htmlunit/html/HtmlPasswordInput.java,v retrieving revision 1.5 retrieving revision 1.6 diff -u -d -r1.5 -r1.6 --- HtmlPasswordInput.java 10 Jun 2003 11:56:58 -0000 1.5 +++ HtmlPasswordInput.java 16 Jun 2003 21:03:24 -0000 1.6 @@ -47,8 +47,6 @@ */ public class HtmlPasswordInput extends HtmlInput { - private final String initialValue_; - /** * Create an instance * @@ -57,15 +55,7 @@ */ HtmlPasswordInput( final HtmlPage page, final Element element ) { super( page, element ); - initialValue_ = getValueAttribute(); } - - /** - * Reset the value of this element to its initial state. - */ - public void reset() { - setValueAttribute(initialValue_); - } } Index: HtmlTextInput.java =================================================================== RCS file: /cvsroot/htmlunit/htmlunit/src/java/com/gargoylesoftware/htmlunit/html/HtmlTextInput.java,v retrieving revision 1.5 retrieving revision 1.6 diff -u -d -r1.5 -r1.6 --- HtmlTextInput.java 10 Jun 2003 11:56:58 -0000 1.5 +++ HtmlTextInput.java 16 Jun 2003 21:03:24 -0000 1.6 @@ -46,7 +46,6 @@ * @author <a href="mailto:mb...@Ga...">Mike Bowler</a> */ public class HtmlTextInput extends HtmlInput { - private final String initialValue_; /** * Create an instance @@ -56,15 +55,6 @@ */ HtmlTextInput( final HtmlPage page, final Element element ) { super( page, element ); - initialValue_ = getValueAttribute(); - } - - - /** - * Return the value of this element to what it was at the time the page was loaded. - */ - public void reset() { - setValueAttribute(initialValue_); } } Index: HtmlRadioButtonInput.java =================================================================== RCS file: /cvsroot/htmlunit/htmlunit/src/java/com/gargoylesoftware/htmlunit/html/HtmlRadioButtonInput.java,v retrieving revision 1.10 retrieving revision 1.11 diff -u -d -r1.10 -r1.11 --- HtmlRadioButtonInput.java 10 Jun 2003 11:56:58 -0000 1.10 +++ HtmlRadioButtonInput.java 16 Jun 2003 21:03:24 -0000 1.11 @@ -37,9 +37,6 @@ */ package com.gargoylesoftware.htmlunit.html; -import com.gargoylesoftware.htmlunit.Page; -import com.gargoylesoftware.htmlunit.ElementNotFoundException; -import java.io.IOException; import org.w3c.dom.Element; /** @@ -49,7 +46,6 @@ * @author <a href="mailto:mb...@Ga...">Mike Bowler</a> */ public class HtmlRadioButtonInput extends HtmlInput { - private final boolean initialCheckedState_; /** * Create an instance @@ -59,65 +55,6 @@ */ HtmlRadioButtonInput( final HtmlPage page, final Element element ) { super( page, element ); - initialCheckedState_ = isAttributeDefined("checked"); - } - - - /** - * Set the "checked" attribute - * - * @param isChecked true if this element is to be selected - */ - public final void setChecked( final boolean isChecked ) { - final HtmlForm form = getEnclosingForm(); - - if( isChecked ) { - try { - form.setCheckedRadioButton( getNameAttribute(), getValueAttribute() ); - } - catch( final ElementNotFoundException e ) { - // Shouldn't be possible - throw new IllegalStateException("Can't find this element when going up to the form and back down."); - } - } - else { - getElement().removeAttribute( "checked" ); - } - } - - - /** - * Return true if this element is currently selected - * - * @return See above - */ - public final boolean isChecked() { - return isAttributeDefined("checked"); - } - - - /** - * Return the value of this element to what it was at the time the page was loaded. - */ - public void reset() { - if( initialCheckedState_ ) { - getElement().setAttribute("checked", "checked"); - } - else { - getElement().removeAttribute("checked"); - } - } - - - /** - * Submit the form that contains this input - * - * @return The Page that is the result of submitting this page to the - * server - * @exception IOException If an io error occurs - */ - public Page click() throws IOException { - return super.click(); } } Index: HtmlImageInput.java =================================================================== RCS file: /cvsroot/htmlunit/htmlunit/src/java/com/gargoylesoftware/htmlunit/html/HtmlImageInput.java,v retrieving revision 1.11 retrieving revision 1.12 diff -u -d -r1.11 -r1.12 --- HtmlImageInput.java 10 Jun 2003 11:56:57 -0000 1.11 +++ HtmlImageInput.java 16 Jun 2003 21:03:24 -0000 1.12 @@ -37,10 +37,6 @@ */ package com.gargoylesoftware.htmlunit.html; -import com.gargoylesoftware.htmlunit.ElementNotFoundException; -import com.gargoylesoftware.htmlunit.KeyValuePair; -import com.gargoylesoftware.htmlunit.Page; -import java.io.IOException; import org.w3c.dom.Element; /** @@ -50,11 +46,6 @@ * @author <a href="mailto:mb...@Ga...">Mike Bowler</a> */ public class HtmlImageInput extends HtmlInput { - private boolean wasPositionSpecified_ = false; - private int xPosition_; - private int yPosition_; - - /** * Create an instance * @@ -65,85 +56,5 @@ super( page, element ); } - - /** - * Simulate clicking this input in some way other than with a pointing device. - * No x,y coordinates will be sent to the server. - * - * @return The page that is loaded after the click has taken place. - * @exception IOException If an io error occurs - */ - public Page click() throws IOException { - wasPositionSpecified_ = false; - return super.click(); - } - - - /** - * This method will be called if there either wasn't an onclick handler or there was - * but the result of that handler was true. This is the default behaviour of clicking - * the element. In this case, the method will submit the form. - * - * @return The page that is currently loaded after execution of this method - * @throws IOException If an IO error occured - */ - protected Page doClickAction() throws IOException { - return getEnclosingFormOrDie().submit(this); - } - - - /** - * Simulate clicking this input with a pointing device. The x and y coordinates - * of the pointing device will be sent to the server. - * - * @param x The x coordinate of the pointing device at the time of clicking - * @param y The y coordinate of the pointing device at the time of clicking - * @return The page that is loaded after the click has taken place. - * @exception IOException If an io error occurs - * @exception ElementNotFoundException If a particular xml element could - * not be found in the dom model - */ - public Page click( final int x, final int y ) - throws - IOException, - ElementNotFoundException { - - wasPositionSpecified_ = true; - xPosition_ = x; - yPosition_ = y; - return super.click(); - } - - - /** - * Return an array of KeyValuePairs that are the values that will be sent - * back to the server whenever the current form is submitted.<p> - * - * THIS METHOD IS INTENDED FOR THE USE OF THE FRAMEWORK ONLY AND SHOULD NOT - * BE USED BY CONSUMERS OF HTMLUNIT. USE AT YOUR OWN RISK. - * - * @return See above - */ - public KeyValuePair[] getSubmitKeyValuePairs() { - final String name = getNameAttribute(); - if( wasPositionSpecified_ == true ) { - return new KeyValuePair[]{ - new KeyValuePair( name, getValueAttribute() ), - new KeyValuePair( name+".x", String.valueOf(xPosition_) ), - new KeyValuePair( name+".y", String.valueOf(yPosition_) ) - }; - } - else { - return new KeyValuePair[]{new KeyValuePair( name, getValueAttribute() )}; - } - } - - - /** - * Reset the value of this element to its initial state. This is a no-op for - * this component. - */ - public void reset() { - } } Index: HtmlResetInput.java =================================================================== RCS file: /cvsroot/htmlunit/htmlunit/src/java/com/gargoylesoftware/htmlunit/html/HtmlResetInput.java,v retrieving revision 1.9 retrieving revision 1.10 diff -u -d -r1.9 -r1.10 --- HtmlResetInput.java 10 Jun 2003 11:56:58 -0000 1.9 +++ HtmlResetInput.java 16 Jun 2003 21:03:24 -0000 1.10 @@ -37,8 +37,6 @@ */ package com.gargoylesoftware.htmlunit.html; -import com.gargoylesoftware.htmlunit.Page; -import java.io.IOException; import org.w3c.dom.Element; /** @@ -59,37 +57,5 @@ super( page, element ); } - - /** - * Reset the form that contains this input - * - * @return The Page that is the result of reseting this page. Typically this - * will be the current page but if javascript is invoked by this click then - * another page could have been loaded. - * @exception IOException If an io error occurs - */ - public Page click() throws IOException { - return super.click(); - } - - - /** - * This method will be called if there either wasn't an onclick handler or there was - * but the result of that handler was true. This is the default behaviour of clicking - * the element. In this case, the method will reset the form. - * - * @return The page that is currently loaded after execution of this method - * @throws IOException If an IO error occured - */ - protected Page doClickAction() throws IOException { - return getEnclosingFormOrDie().reset(); - } - - - /** - * Reset this element to its original values. This is a no-op for a button. - */ - public void reset() { - } } Index: SimpleScriptable.java =================================================================== RCS file: /cvsroot/htmlunit/htmlunit/src/java/com/gargoylesoftware/htmlunit/javascript/SimpleScriptable.java,v retrieving revision 1.29 retrieving revision 1.30 diff -u -d -r1.29 -r1.30 --- SimpleScriptable.java 10 Jun 2003 11:56:58 -0000 1.29 +++ SimpleScriptable.java 16 Jun 2003 21:03:24 -0000 1.30 @@ -40,7 +40,6 @@ import com.gargoylesoftware.htmlunit.Assert; import com.gargoylesoftware.htmlunit.BrowserVersion; import com.gargoylesoftware.htmlunit.ScriptException; -import com.gargoylesoftware.htmlunit.html.HtmlButton; import com.gargoylesoftware.htmlunit.html.HtmlElement; import java.lang.reflect.InvocationTargetException; import java.lang.reflect.Method; @@ -95,20 +94,20 @@ final String[][] mapping = { {"HtmlAnchor", "Anchor"}, {"HtmlButton", "Button"}, - {"HtmlButtonInput", "Button"}, - {"HtmlCheckBoxInput", "Checkbox"}, - {"HtmlFileInput", "FileUpload"}, + {"HtmlInput", "Input"}, + {"HtmlCheckBoxInput", "Input"}, + {"HtmlFileInput", "Input"}, {"HtmlForm", "Form"}, - {"HtmlHiddenInput", "Hidden"}, + {"HtmlHiddenInput", "Input"}, {"HtmlImage", "Image"}, {"HtmlInlineFrame", "Window"}, {"HtmlOption", "Option"}, - {"HtmlPasswordInput", "Password"}, - {"HtmlRadioButtonInput", "Radio"}, - {"HtmlResetInput", "Reset"}, + {"HtmlPasswordInput", "Input"}, + {"HtmlRadioButtonInput", "Input"}, + {"HtmlResetInput", "Input"}, {"HtmlSelect", "Select"}, - {"HtmlSubmitInput", "Submit"}, - {"HtmlTextInput", "Text"}, + {"HtmlSubmitInput", "Input"}, + {"HtmlTextInput", "Input"}, {"HtmlTextArea", "Textarea"}, {"HtmlElement", "HTMLElement"}, }; @@ -464,14 +463,7 @@ } final String javaScriptClassName; - if( htmlElement instanceof HtmlButton ) { - // TODO: The proper solution is to make HtmlButton abstract and have a hierarchy just like HtmlInput - // Until that happens, we touch up the javascript name here. - javaScriptClassName = getJavaScriptClassNameForButtonKludge((HtmlButton)htmlElement); - } - else { - javaScriptClassName = (String)getHtmlJavaScriptMapping().get(htmlElement.getClass()); - } + javaScriptClassName = (String)getHtmlJavaScriptMapping().get(htmlElement.getClass()); if( javaScriptClassName == null ) { // We don't have a specific subclass for this element so create something generic. final SimpleScriptable scriptable = makeJavaScriptObject("HTMLElement"); @@ -484,47 +476,6 @@ scriptable.setHtmlElement(htmlElement); return scriptable; } - } - - - private String getJavaScriptClassNameForButtonKludge( final HtmlButton button ) { - final String typeAttribute = button.getTypeAttribute(); - final String className; - if( typeAttribute == HtmlButton.ATTRIBUTE_NOT_DEFINED ) { - className = "Button"; - } - else if( typeAttribute.equals("submit") ) { - className = "Submit"; - } - else if( typeAttribute.equals("reset") ) { - className = "Reset"; - } - else if( typeAttribute.equals("checkbox") ) { - className = "Checkbox"; - } - else if( typeAttribute.equals("radio") ) { - className = "Radio"; - } - else if( typeAttribute.equals("text") ) { - className = "Text"; - } - else if( typeAttribute.equals("hidden") ) { - className = "Hidden"; - } - else if( typeAttribute.equals("password") ) { - className = "Password"; - } - else if( typeAttribute.equals("image") ) { - className = "Image"; - } - else if( typeAttribute.equals("file") ) { - className = "File"; - } - else { - className = "Button"; - } - - return className; } Index: FormElementsArray.java =================================================================== RCS file: /cvsroot/htmlunit/htmlunit/src/java/com/gargoylesoftware/htmlunit/javascript/FormElementsArray.java,v retrieving revision 1.7 retrieving revision 1.8 diff -u -d -r1.7 -r1.8 --- FormElementsArray.java 10 Jun 2003 11:56:58 -0000 1.7 +++ FormElementsArray.java 16 Jun 2003 21:03:24 -0000 1.8 @@ -40,7 +40,7 @@ import com.gargoylesoftware.htmlunit.Assert; import com.gargoylesoftware.htmlunit.html.HtmlElement; import com.gargoylesoftware.htmlunit.html.HtmlForm; -import com.gargoylesoftware.htmlunit.html.HtmlRadioButtonInput; +import com.gargoylesoftware.htmlunit.html.HtmlInput; import java.util.ArrayList; import java.util.Arrays; import java.util.Iterator; @@ -124,13 +124,13 @@ while( iterator.hasNext() ) { htmlElement = (HtmlElement)iterator.next(); if( htmlElement.getAttributeValue("name").equals(name) ) { - if( htmlElement instanceof HtmlRadioButtonInput ) { + if( htmlElement instanceof HtmlInput ) { final List collectedRadioButtons = new ArrayList(elementList.size()); collectedRadioButtons.add(getScriptableFor(htmlElement)); while( iterator.hasNext() ) { htmlElement = (HtmlElement)iterator.next(); - if( htmlElement instanceof HtmlRadioButtonInput - && ((HtmlRadioButtonInput)htmlElement).getNameAttribute().equals(name) ) { + if( htmlElement instanceof HtmlInput + && ((HtmlInput)htmlElement).getNameAttribute().equals(name) ) { collectedRadioButtons.add(getScriptableFor(htmlElement)); } } Index: JavaScriptEngine.java =================================================================== RCS file: /cvsroot/htmlunit/htmlunit/src/java/com/gargoylesoftware/htmlunit/javascript/JavaScriptEngine.java,v retrieving revision 1.17 retrieving revision 1.18 diff -u -d -r1.17 -r1.18 --- JavaScriptEngine.java 10 Jun 2003 11:56:58 -0000 1.17 +++ JavaScriptEngine.java 16 Jun 2003 21:03:24 -0000 1.18 @@ -133,9 +133,8 @@ final String hostClassNames[] = { "HTMLElement" ,"Window", "Document", "Form", "Input", "Navigator", - "Screen", "History", "Radio", "Location", "Text", "Button", "Checkbox", - "FileUpload", "Hidden", "Select", "Password", "Reset", "Submit", "Textarea", - "Image", "Style", "Option", "Anchor" + "Screen", "History", "Location", "Button", "Select", "Textarea", + "Style", "Option", "Anchor", "Image" }; for( int i=0; i<hostClassNames.length; i++ ) { Index: Input.java =================================================================== RCS file: /cvsroot/htmlunit/htmlunit/src/java/com/gargoylesoftware/htmlunit/javascript/host/Input.java,v retrieving revision 1.9 retrieving revision 1.10 diff -u -d -r1.9 -r1.10 --- Input.java 10 Jun 2003 11:56:59 -0000 1.9 +++ Input.java 16 Jun 2003 21:03:24 -0000 1.10 @@ -39,6 +39,8 @@ import org.w3c.dom.Element; +import com.gargoylesoftware.htmlunit.html.HtmlInput; + /** * The javascript object that represents something that can be put in a form. * @@ -123,8 +125,14 @@ * set */ public void jsSet_checked( final boolean checked ) { - getLog().debug( "Input.jsSet_checked(" + checked - + ") was called for class " + getClass().getName() ); + String type = getHtmlElementOrDie().getAttributeValue("type"); + if (type.equals("checkbox") || type.equals("radio")){ + ((HtmlInput)getHtmlElementOrDie()).setChecked(checked); + } + else { + getLog().debug( "Input.jsSet_checked(" + checked + + ") was called for class " + getClass().getName() ); + } } @@ -137,8 +145,14 @@ *@return The checked property. */ public boolean jsGet_checked() { - getLog().warn( "Input.jsGet_checked() was called for class " + getClass().getName() ); - return false; + String type = getHtmlElementOrDie().getAttributeValue("type"); + if (type.equals("checkbox") || type.equals("radio")){ + return ((HtmlInput)getHtmlElementOrDie()).isChecked(); + } + else { + getLog().warn( "Input.jsGet_checked() was called for class " + getClass().getName() ); + return false; + } } Index: Button.java =================================================================== RCS file: /cvsroot/htmlunit/htmlunit/src/java/com/gargoylesoftware/htmlunit/javascript/host/Button.java,v retrieving revision 1.4 retrieving revision 1.5 diff -u -d -r1.4 -r1.5 --- Button.java 10 Jun 2003 11:56:59 -0000 1.4 +++ Button.java 16 Jun 2003 21:03:24 -0000 1.5 @@ -60,13 +60,5 @@ public void jsConstructor() { } - - /** - * Return the type of this input. - * @return The type - */ - public String jsGet_type() { - return "button"; - } } |