1 // Permission is hereby granted, free of charge, to any person obtaining
2 // a copy of this software and associated documentation files (the
3 // "Software"), to deal in the Software without restriction, including
4 // without limitation the rights to use, copy, modify, merge, publish,
5 // distribute, sublicense, and/or sell copies of the Software, and to
6 // permit persons to whom the Software is furnished to do so, subject to
7 // the following conditions:
9 // The above copyright notice and this permission notice shall be
10 // included in all copies or substantial portions of the Software.
12 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
13 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
14 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
15 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
16 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
17 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
18 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
20 // Copyright (c) 2007, 2008 Novell, Inc.
23 // Andreia Gaita (avidigal@novell.com)
27 using System.Runtime.InteropServices;
30 using Mono.WebBrowser;
31 using Mono.WebBrowser.DOM;
33 namespace Mono.Mozilla.DOM
35 internal class HTMLElement : Element, IElement
37 protected nsIDOMHTMLElement node {
38 get { return base.node as nsIDOMHTMLElement; }
39 set { base.node = value as nsIDOMElement; }
42 public HTMLElement (WebBrowser control, nsIDOMHTMLElement domHtmlElement) : base (control, domHtmlElement as nsIDOMElement)
44 this.node = domHtmlElement;
47 #region IDisposable Members
48 protected override void Dispose (bool disposing)
55 base.Dispose(disposing);
59 #region IElement Members
60 public new string InnerHTML
63 nsIDOMNSHTMLElement nsElem = this.node as nsIDOMNSHTMLElement;
66 nsElem.getInnerHTML (storage);
67 return Base.StringGet (storage);
70 nsIDOMNSHTMLElement nsElem = this.node as nsIDOMNSHTMLElement;
73 Base.StringSet (storage, value);
74 nsElem.setInnerHTML (storage);
78 public override string OuterHTML
80 // bad emulation of outerHTML since gecko doesn't support it :P
83 control.DocEncoder.Flags = DocumentEncoderFlags.OutputRaw;
84 if (this.Equals (Owner.DocumentElement))
85 return control.DocEncoder.EncodeToString ((Document) Owner);
86 return control.DocEncoder.EncodeToString (this);
88 string tag = this.TagName;
89 string str = "<" + tag;
90 foreach (IAttribute att in this.Attributes) {
91 str += " " + att.Name + "=\"" + att.Value + "\"";
93 nsIDOMNSHTMLElement nsElem = this.node as nsIDOMNSHTMLElement;
94 nsElem.getInnerHTML (storage);
95 str += ">" + Base.StringGet (storage) + "</" + tag + ">";
100 nsIDOMDocumentRange docRange = ((Document) control.Document).XPComObject as nsIDOMDocumentRange;
102 docRange.createRange (out range);
103 range.setStartBefore (this.node);
104 nsIDOMNSRange nsRange = range as nsIDOMNSRange;
105 Base.StringSet (storage, value);
106 nsIDOMDocumentFragment fragment;
107 nsRange.createContextualFragment (storage, out fragment);
109 this.node.getParentNode (out parent);
110 parent = nsDOMNode.GetProxy (this.control, parent);
112 parent.replaceChild (fragment as nsIDOMNode, this.node as nsIDOMNode, out newNode);
113 this.node = newNode as Mono.Mozilla.nsIDOMHTMLElement;
117 public override io.Stream ContentStream {
120 control.DocEncoder.Flags = DocumentEncoderFlags.OutputRaw;
121 if (this.Equals (Owner.DocumentElement))
122 return control.DocEncoder.EncodeToStream ((Document) Owner);
123 return control.DocEncoder.EncodeToStream (this);
125 string tag = this.TagName;
126 string str = "<" + tag;
127 foreach (IAttribute att in this.Attributes) {
128 str += " " + att.Name + "=\"" + att.Value + "\"";
130 nsIDOMNSHTMLElement nsElem = this.node as nsIDOMNSHTMLElement;
131 nsElem.getInnerHTML (storage);
132 str += ">" + Base.StringGet (storage) + "</" + tag + ">";
133 byte[] bytes = System.Text.ASCIIEncoding.UTF8.GetBytes (str);
134 return new io.MemoryStream (bytes);
140 public override bool Disabled
143 if (this.HasAttribute ("disabled")) {
144 string dis = this.GetAttribute ("disabled");
145 return bool.Parse (dis);
150 if (this.HasAttribute ("disabled")) {
151 this.SetAttribute ("disabled", value.ToString ());
156 public override int TabIndex {
159 ((nsIDOMNSHTMLElement)this.node).getTabIndex (out tabIndex);
163 ((nsIDOMNSHTMLElement)this.node).setTabIndex (value);
167 public override int GetHashCode () {
168 return this.hashcode;