/* This Source Code Form is subject to the terms of the Mozilla Public * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ use dom::bindings::codegen::BindingDeclarations::HTMLButtonElementBinding; use dom::bindings::codegen::InheritTypes::HTMLButtonElementDerived; use dom::bindings::js::{JSRef, Temporary}; use dom::bindings::error::ErrorResult; use dom::document::Document; use dom::element::HTMLButtonElementTypeId; use dom::eventtarget::{EventTarget, NodeTargetTypeId}; use dom::htmlelement::HTMLElement; use dom::htmlformelement::HTMLFormElement; use dom::node::{Node, ElementNodeTypeId, window_from_node}; use dom::validitystate::ValidityState; use servo_util::str::DOMString; #[deriving(Encodable)] pub struct HTMLButtonElement { pub htmlelement: HTMLElement } impl HTMLButtonElementDerived for EventTarget { fn is_htmlbuttonelement(&self) -> bool { self.type_id == NodeTargetTypeId(ElementNodeTypeId(HTMLButtonElementTypeId)) } } impl HTMLButtonElement { pub fn new_inherited(localName: DOMString, document: &JSRef) -> HTMLButtonElement { HTMLButtonElement { htmlelement: HTMLElement::new_inherited(HTMLButtonElementTypeId, localName, document) } } pub fn new(localName: DOMString, document: &JSRef) -> Temporary { let element = HTMLButtonElement::new_inherited(localName, document); Node::reflect_node(box element, document, HTMLButtonElementBinding::Wrap) } } pub trait HTMLButtonElementMethods { fn Autofocus(&self) -> bool; fn SetAutofocus(&self, _autofocus: bool) -> ErrorResult; fn Disabled(&self) -> bool; fn SetDisabled(&self, _disabled: bool) -> ErrorResult; fn GetForm(&self) -> Option>; fn FormAction(&self) -> DOMString; fn SetFormAction(&self, _formaction: DOMString) -> ErrorResult; fn FormEnctype(&self) -> DOMString; fn SetFormEnctype(&self, _formenctype: DOMString) -> ErrorResult; fn FormMethod(&self) -> DOMString; fn SetFormMethod(&self, _formmethod: DOMString) -> ErrorResult; fn FormNoValidate(&self) -> bool; fn SetFormNoValidate(&self, _novalidate: bool) -> ErrorResult; fn FormTarget(&self) -> DOMString; fn SetFormTarget(&self, _formtarget: DOMString) -> ErrorResult; fn Name(&self) -> DOMString; fn SetName(&self, _name: DOMString) -> ErrorResult; fn Type(&self) -> DOMString; fn SetType(&self, _type: DOMString) -> ErrorResult; fn Value(&self) -> DOMString; fn SetValue(&self, _value: DOMString) -> ErrorResult; fn WillValidate(&self) -> bool; fn SetWillValidate(&self, _will_validate: bool); fn Validity(&self) -> Temporary; fn ValidationMessage(&self) -> DOMString; fn SetValidationMessage(&self, _message: DOMString) -> ErrorResult; fn CheckValidity(&self) -> bool; fn SetCustomValidity(&self, _error: DOMString); } impl<'a> HTMLButtonElementMethods for JSRef<'a, HTMLButtonElement> { fn Autofocus(&self) -> bool { false } fn SetAutofocus(&self, _autofocus: bool) -> ErrorResult { Ok(()) } fn Disabled(&self) -> bool { false } fn SetDisabled(&self, _disabled: bool) -> ErrorResult { Ok(()) } fn GetForm(&self) -> Option> { None } fn FormAction(&self) -> DOMString { "".to_owned() } fn SetFormAction(&self, _formaction: DOMString) -> ErrorResult { Ok(()) } fn FormEnctype(&self) -> DOMString { "".to_owned() } fn SetFormEnctype(&self, _formenctype: DOMString) -> ErrorResult { Ok(()) } fn FormMethod(&self) -> DOMString { "".to_owned() } fn SetFormMethod(&self, _formmethod: DOMString) -> ErrorResult { Ok(()) } fn FormNoValidate(&self) -> bool { false } fn SetFormNoValidate(&self, _novalidate: bool) -> ErrorResult { Ok(()) } fn FormTarget(&self) -> DOMString { "".to_owned() } fn SetFormTarget(&self, _formtarget: DOMString) -> ErrorResult { Ok(()) } fn Name(&self) -> DOMString { "".to_owned() } fn SetName(&self, _name: DOMString) -> ErrorResult { Ok(()) } fn Type(&self) -> DOMString { "".to_owned() } fn SetType(&self, _type: DOMString) -> ErrorResult { Ok(()) } fn Value(&self) -> DOMString { "".to_owned() } fn SetValue(&self, _value: DOMString) -> ErrorResult { Ok(()) } fn WillValidate(&self) -> bool { false } fn SetWillValidate(&self, _will_validate: bool) { } fn Validity(&self) -> Temporary { let window = window_from_node(self).root(); ValidityState::new(&*window) } fn ValidationMessage(&self) -> DOMString { "".to_owned() } fn SetValidationMessage(&self, _message: DOMString) -> ErrorResult { Ok(()) } fn CheckValidity(&self) -> bool { true } fn SetCustomValidity(&self, _error: DOMString) { } }