Imported Upstream version 3.6.0

Former-commit-id: da6be194a6b1221998fc28233f2503bd61dd9d14
This commit is contained in:
Jo Shields
2014-08-13 10:39:27 +01:00
commit a575963da9
50588 changed files with 8155799 additions and 0 deletions

View File

@@ -0,0 +1,18 @@
using System.Reflection;
using System.Runtime.CompilerServices;
// General Information about the assembly
[assembly: AssemblyTitle("Mono.WebBrowser")]
[assembly: AssemblyDescription("Managed Wrapper for xulrunner engine, to support WebBrowser")]
[assembly: AssemblyConfiguration("Development version")]
[assembly: AssemblyProduct("Mono.WebBrowser")]
[assembly: AssemblyCopyright("(c) 2007, 2008 Andreia Gaita")]
[assembly: AssemblyVersion (Consts.FxVersion)]
[assembly: AssemblyInformationalVersion (Consts.FxFileVersion)]
[assembly: AssemblyFileVersion (Consts.FxFileVersion)]
[assembly: AssemblyDelaySign(true)]
[assembly: AssemblyKeyFile("../mono.snk")]

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,17 @@
thisdir = class/Mono.WebBrowser
SUBDIRS =
include ../../build/rules.make
LIBRARY = Mono.WebBrowser.dll
LIB_MCS_FLAGS = -r:System.dll -warn:1
TEST_MCS_FLAGS = $(LIB_MCS_FLAGS)
EXTRA_DISTFILES = README build-csproj2k5
Mono.WebBrowser2K5.csproj: Mono.WebBrowser.dll.sources build-csproj2k5
./build-csproj2k5
include ../../build/library.make
$(the_lib): Mono.WebBrowser2K5.csproj

View File

@@ -0,0 +1,122 @@
//Permission is hereby granted, free of charge, to any person obtaining
//a copy of this software and associated documentation files (the
//"Software"), to deal in the Software without restriction, including
//without limitation the rights to use, copy, modify, merge, publish,
//distribute, sublicense, and/or sell copies of the Software, and to
//permit persons to whom the Software is furnished to do so, subject to
//the following conditions:
//
//The above copyright notice and this permission notice shall be
//included in all copies or substantial portions of the Software.
//
//THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
//EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
//MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
//NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
//LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
//OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
//WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
//Copyright (c) 2008 Novell, Inc.
//
//Authors:
// Andreia Gaita (avidigal@novell.com)
//
using System;
using System.Runtime.InteropServices;
namespace Mono.Mozilla
{
internal class AsciiString : IDisposable
{
[StructLayout(LayoutKind.Sequential)]
class nsStringContainer {
IntPtr v;
IntPtr d1;
uint d2;
IntPtr d3;
}
private bool disposed = false;
private nsStringContainer unmanagedContainer;
private HandleRef handle;
private string str = String.Empty;
private bool dirty;
public AsciiString(string value)
{
unmanagedContainer = new nsStringContainer ();
IntPtr p = Marshal.AllocHGlobal (Marshal.SizeOf (typeof (nsStringContainer)));
Marshal.StructureToPtr (unmanagedContainer, p, false);
handle = new HandleRef (typeof (nsStringContainer), p);
Base.gluezilla_CStringContainerInit (handle);
String = value;
}
~AsciiString ()
{
Dispose (false);
}
#region IDisposable Members
protected virtual void Dispose (bool disposing)
{
if (!disposed) {
if (disposing) {
Base.gluezilla_CStringContainerFinish (handle);
Marshal.FreeHGlobal (handle.Handle);
}
disposed = true;
}
}
public void Dispose ()
{
Dispose (true);
GC.SuppressFinalize (this);
}
#endregion
public HandleRef Handle {
get {
dirty = true;
return handle;
}
}
public string String {
get {
if (dirty) {
IntPtr buf;
bool term;
Base.gluezilla_CStringGetData (handle, out buf, out term);
str = Marshal.PtrToStringAnsi (buf);
dirty = false;
}
return str;
}
set {
if (str != value) {
str = value;
Base.gluezilla_CStringSetData (handle, str, (uint)str.Length);
}
}
}
public int Length {
get { return String.Length; }
}
public override string ToString ()
{
return String;
}
}
}

View File

@@ -0,0 +1,379 @@
// Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files (the
// "Software"), to deal in the Software without restriction, including
// without limitation the rights to use, copy, modify, merge, publish,
// distribute, sublicense, and/or sell copies of the Software, and to
// permit persons to whom the Software is furnished to do so, subject to
// the following conditions:
//
// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
// Copyright (c) 2007, 2008 Novell, Inc.
//
// Authors:
// Andreia Gaita (avidigal@novell.com)
//
using System;
using System.Text;
using System.Collections;
using System.Runtime.InteropServices;
using System.Diagnostics;
using Mono.WebBrowser;
namespace Mono.Mozilla
{
internal class Base
{
private static Hashtable boundControls;
private static bool initialized;
private static object initLock = new object ();
private static string monoMozDir;
private class BindingInfo
{
public CallbackBinder callback;
public IntPtr gluezilla;
}
private static bool isInitialized ()
{
if (!initialized)
return false;
return true;
}
private static BindingInfo getBinding (IWebBrowser control)
{
if (!boundControls.ContainsKey (control))
return null;
BindingInfo info = boundControls[control] as BindingInfo;
return info;
}
static Base ()
{
boundControls = new Hashtable ();
}
public Base () { }
public static void Debug (int signal)
{
gluezilla_debug (signal);
}
public static bool Init (WebBrowser control, Platform platform)
{
lock (initLock) {
if (!initialized) {
Platform mozPlatform;
try {
short version = gluezilla_init (platform, out mozPlatform);
monoMozDir = System.IO.Path.Combine (
System.IO.Path.Combine (
Environment.GetFolderPath (Environment.SpecialFolder.LocalApplicationData),
".mono"), "mozilla-" + version);
if (!System.IO.Directory.Exists (monoMozDir))
System.IO.Directory.CreateDirectory (monoMozDir);
}
catch (DllNotFoundException) {
Console.WriteLine ("libgluezilla not found. To have webbrowser support, you need libgluezilla installed");
initialized = false;
return false;
}
control.enginePlatform = mozPlatform;
initialized = true;
}
}
return initialized;
}
public static bool Bind (WebBrowser control, IntPtr handle, int width, int height)
{
if (!isInitialized ())
return false;
BindingInfo info = new BindingInfo ();
info.callback = new CallbackBinder (control.callbacks);
IntPtr ptrCallback = Marshal.AllocHGlobal (Marshal.SizeOf (info.callback));
Marshal.StructureToPtr (info.callback, ptrCallback, true);
info.gluezilla = gluezilla_bind (ptrCallback, handle, width, height, Environment.CurrentDirectory, monoMozDir, control.platform);
lock (initLock) {
if (info.gluezilla == IntPtr.Zero) {
Marshal.FreeHGlobal (ptrCallback);
info = null;
initialized = false;
return false;
}
}
boundControls.Add (control as IWebBrowser, info);
return true;
}
public static bool Create (IWebBrowser control) {
if (!isInitialized ())
return false;
BindingInfo info = getBinding (control);
gluezilla_createBrowserWindow (info.gluezilla);
return true;
}
public static void Shutdown (IWebBrowser control)
{
lock (initLock) {
if (!initialized)
return;
BindingInfo info = getBinding (control);
gluezilla_shutdown (info.gluezilla);
boundControls.Remove (control);
if (boundControls.Count == 0) {
info = null;
initialized = false;
}
}
}
// layout
public static void Focus (IWebBrowser control, FocusOption focus)
{
if (!isInitialized ())
return;
BindingInfo info = getBinding (control);
gluezilla_focus (info.gluezilla, focus);
}
public static void Blur (IWebBrowser control)
{
if (!isInitialized ())
return;
BindingInfo info = getBinding (control);
gluezilla_blur (info.gluezilla);
}
public static void Activate (IWebBrowser control)
{
if (!isInitialized ())
return;
BindingInfo info = getBinding (control);
gluezilla_activate (info.gluezilla);
}
public static void Deactivate (IWebBrowser control)
{
if (!isInitialized ())
return;
BindingInfo info = getBinding (control);
gluezilla_deactivate (info.gluezilla);
}
public static void Resize (IWebBrowser control, int width, int height)
{
if (!isInitialized ())
return;
BindingInfo info = getBinding (control);
gluezilla_resize (info.gluezilla, width, height);
}
// navigation
public static void Home (IWebBrowser control)
{
if (!isInitialized ())
return;
BindingInfo info = getBinding (control);
gluezilla_home (info.gluezilla);
}
public static nsIWebNavigation GetWebNavigation (IWebBrowser control)
{
if (!isInitialized ())
return null;
BindingInfo info = getBinding (control);
return gluezilla_getWebNavigation (info.gluezilla);
}
public static IntPtr StringInit ()
{
if (!isInitialized ())
return IntPtr.Zero;
return gluezilla_stringInit ();
}
public static void StringFinish (HandleRef str)
{
if (!isInitialized ())
return;
gluezilla_stringFinish (str);
}
public static string StringGet (HandleRef str)
{
if (!isInitialized ())
return String.Empty;
IntPtr p = gluezilla_stringGet (str);
return Marshal.PtrToStringUni (p);
}
public static void StringSet (HandleRef str, string text)
{
if (!isInitialized ())
return;
gluezilla_stringSet (str, text);
}
public static object GetProxyForObject (IWebBrowser control, Guid iid, object obj)
{
if (!isInitialized ())
return null;
BindingInfo info = getBinding (control);
IntPtr ret;
gluezilla_getProxyForObject (info.gluezilla, iid, obj, out ret);
object o = Marshal.GetObjectForIUnknown (ret);
return o;
}
public static nsIServiceManager GetServiceManager (IWebBrowser control)
{
if (!isInitialized ())
return null;
BindingInfo info = getBinding (control);
return gluezilla_getServiceManager2 (info.gluezilla);
}
public static string EvalScript (IWebBrowser control, string script)
{
if (!isInitialized ())
return null;
BindingInfo info = getBinding (control);
IntPtr p = gluezilla_evalScript (info.gluezilla, script);
return Marshal.PtrToStringAuto (p);
}
#region pinvokes
[DllImport("gluezilla")]
private static extern void gluezilla_debug(int signal);
[DllImport("gluezilla")]
private static extern short gluezilla_init (Platform platform, out Platform mozPlatform);
[DllImport ("gluezilla")]
private static extern IntPtr gluezilla_bind (IntPtr events, IntPtr hwnd,
Int32 width, Int32 height,
string startDir, string dataDir,
Platform platform);
[DllImport ("gluezilla")]
private static extern int gluezilla_createBrowserWindow (IntPtr instance);
[DllImport ("gluezilla")]
private static extern IntPtr gluezilla_shutdown (IntPtr instance);
// layout
[DllImport ("gluezilla")]
private static extern int gluezilla_focus (IntPtr instance, FocusOption focus);
[DllImport ("gluezilla")]
private static extern int gluezilla_blur (IntPtr instance);
[DllImport ("gluezilla")]
private static extern int gluezilla_activate (IntPtr instance);
[DllImport ("gluezilla")]
private static extern int gluezilla_deactivate (IntPtr instance);
[DllImport ("gluezilla")]
private static extern int gluezilla_resize (IntPtr instance, Int32 width, Int32 height);
// navigation
[DllImport ("gluezilla")]
private static extern int gluezilla_home (IntPtr instance);
// dom
[DllImport ("gluezilla")]
[return:MarshalAs(UnmanagedType.Interface)]
private static extern nsIWebNavigation gluezilla_getWebNavigation (IntPtr instance);
[DllImport ("gluezilla")]
private static extern IntPtr gluezilla_stringInit ();
[DllImport ("gluezilla")]
private static extern int gluezilla_stringFinish (HandleRef str);
[DllImport ("gluezilla")]
private static extern IntPtr gluezilla_stringGet (HandleRef str);
[DllImport ("gluezilla")]
private static extern void gluezilla_stringSet (HandleRef str, [MarshalAs (UnmanagedType.LPWStr)] string text);
[DllImport ("gluezilla")]
private static extern void gluezilla_getProxyForObject (
IntPtr instance,
[MarshalAs (UnmanagedType.LPStruct)] Guid iid,
[MarshalAs (UnmanagedType.Interface)] object obj,
out IntPtr ret);
[DllImport ("gluezilla")]
public static extern uint gluezilla_StringContainerInit (HandleRef /*nsStringContainer & */aStr);
[DllImport ("gluezilla")]
public static extern void gluezilla_StringContainerFinish (HandleRef /*nsStringContainer & */aStr);
[DllImport ("gluezilla")]
public static extern uint gluezilla_StringGetData (HandleRef /*const nsAString &*/ aStr,
out IntPtr /*const PRUnichar ** */aBuf,
out bool /*PRBool * */aTerm);
[DllImport ("gluezilla")]
public static extern uint gluezilla_StringSetData (HandleRef /*nsAString &*/ aStr,
[MarshalAs (UnmanagedType.LPWStr)] string /*const PRUnichar * */ aBuf, uint aCount);
[DllImport ("gluezilla")]
public static extern uint gluezilla_CStringContainerInit (HandleRef /*nsCStringContainer &*/ aStr);
[DllImport ("gluezilla")]
public static extern void gluezilla_CStringContainerFinish (HandleRef /*nsCStringContainer &*/ aStr);
[DllImport ("gluezilla")]
public static extern uint gluezilla_CStringGetData (HandleRef /*const nsACString &*/ aStr,
out IntPtr /*const PRUnichar ** */aBuf,
out bool /*PRBool **/ aTerm);
[DllImport ("gluezilla")]
public static extern uint gluezilla_CStringSetData (HandleRef /*nsACString &*/ aStr,
string aBuf,
uint aCount);
[DllImport ("gluezilla")]
[return: MarshalAs (UnmanagedType.Interface)]
public static extern nsIServiceManager gluezilla_getServiceManager2 (IntPtr instance);
[DllImport ("gluezilla")]
private static extern IntPtr gluezilla_evalScript (IntPtr instance, string script);
#endregion
}
}

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,83 @@
// Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files (the
// "Software"), to deal in the Software without restriction, including
// without limitation the rights to use, copy, modify, merge, publish,
// distribute, sublicense, and/or sell copies of the Software, and to
// permit persons to whom the Software is furnished to do so, subject to
// the following conditions:
//
// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
// Copyright (c) 2007, 2008 Novell, Inc.
//
// Authors:
// Andreia Gaita (avidigal@novell.com)
//
using System;
using System.Runtime.InteropServices;
using System.Text;
using Mono.WebBrowser;
using Mono.WebBrowser.DOM;
namespace Mono.Mozilla.DOM
{
internal class Attribute : Node, IAttribute
{
private nsIDOMAttr attribute;
public Attribute (WebBrowser control, nsIDOMAttr domAttribute)
: base (control, domAttribute as nsIDOMNode)
{
if (control.platform != control.enginePlatform)
this.attribute = nsDOMAttr.GetProxy (control, domAttribute);
else
this.attribute = domAttribute;
}
#region IDisposable Members
protected override void Dispose (bool disposing)
{
if (!disposed) {
if (disposing) {
this.attribute = null;
}
}
base.Dispose (disposing);
}
#endregion
#region IAttribute Members
public string Name {
get {
this.attribute.getName (storage);
return Base.StringGet (storage);
}
}
public new string Value {
get {
this.attribute.getValue (storage);
return Base.StringGet (storage);
}
set {
Base.StringSet (storage, value);
this.attribute.setValue (storage);
}
}
#endregion
public override int GetHashCode () {
return this.hashcode;
}
}
}

View File

@@ -0,0 +1,112 @@
// Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files (the
// "Software"), to deal in the Software without restriction, including
// without limitation the rights to use, copy, modify, merge, publish,
// distribute, sublicense, and/or sell copies of the Software, and to
// permit persons to whom the Software is furnished to do so, subject to
// the following conditions:
//
// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
// Copyright (c) 2008 Novell, Inc.
//
// Authors:
// Andreia Gaita (avidigal@novell.com)
using System;
using System.Collections;
using Mono.WebBrowser;
using Mono.WebBrowser.DOM;
namespace Mono.Mozilla.DOM
{
internal class AttributeCollection : NodeList, IAttributeCollection
{
protected new nsIDOMNamedNodeMap unmanagedNodes;
public AttributeCollection (WebBrowser control, nsIDOMNamedNodeMap nodeMap)
: base (control, true)
{
if (control.platform != control.enginePlatform)
unmanagedNodes = nsDOMNamedNodeMap.GetProxy (control, nodeMap);
else
unmanagedNodes = nodeMap;
}
public AttributeCollection (WebBrowser control) : base (control)
{
}
internal override void Load ()
{
if (unmanagedNodes == null) return;
Clear ();
uint count;
unmanagedNodes.getLength (out count);
nodeCount = (int) count;
nodes = new Node[count];
for (int i = 0; i < count; i++) {
nsIDOMNode node;
unmanagedNodes.item ((uint) i, out node);
nodes[i] = new Attribute (control, node as nsIDOMAttr);
}
}
public override int Count {
get {
if (unmanagedNodes != null && nodes == null)
Load ();
return nodeCount;
}
}
#region IList members
public new IAttribute this[int index]
{
get
{
if (index < 0 || index >= Count)
throw new ArgumentOutOfRangeException ("index");
return nodes[index] as IAttribute;
}
set { }
}
public IAttribute this[string name]
{
get
{
for (int i = 0; i < nodes.Length; i++) {
if (((IAttribute) nodes[i]).Name.Equals (name))
return nodes[i] as IAttribute;
}
return null;
}
}
public bool Exists (string name)
{
if (unmanagedNodes == null) return false;
Base.StringSet (storage, name);
nsIDOMNode ret;
unmanagedNodes.getNamedItem (storage, out ret);
return ret != null;
}
#endregion
public override int GetHashCode () {
if (unmanagedNodes == null) return base.GetHashCode ();
return this.unmanagedNodes.GetHashCode ();
}
}
}

View File

@@ -0,0 +1,121 @@
//Permission is hereby granted, free of charge, to any person obtaining
//a copy of this software and associated documentation files (the
//"Software"), to deal in the Software without restriction, including
//without limitation the rights to use, copy, modify, merge, publish,
//distribute, sublicense, and/or sell copies of the Software, and to
//permit persons to whom the Software is furnished to do so, subject to
//the following conditions:
//
//The above copyright notice and this permission notice shall be
//included in all copies or substantial portions of the Software.
//
//THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
//EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
//MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
//NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
//LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
//OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
//WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
//Copyright (c) 2008 Novell, Inc.
//
//Authors:
// Andreia Gaita (shana@jitted.com)
//
using System;
using System.ComponentModel;
using System.Runtime.InteropServices;
using Mono.WebBrowser;
namespace Mono.Mozilla.DOM
{
internal class ContentListener : nsIURIContentListener
{
WebBrowser owner;
public ContentListener (WebBrowser instance) {
owner = instance;
}
EventHandlerList events;
public EventHandlerList Events {
get {
if (events == null)
events = new EventHandlerList ();
return events;
}
}
public void AddHandler (NavigationRequestedEventHandler value) {
if (Events[WebBrowser.NavigationRequestedEvent] == null) {
if (owner.Navigation != null) {
nsIWebBrowser browser = (nsIWebBrowser) owner.navigation.navigation;
browser.setParentURIContentListener (this);
}
}
Events.AddHandler (WebBrowser.NavigationRequestedEvent, value);
}
public void RemoveHandler (NavigationRequestedEventHandler value) {
Events.RemoveHandler (WebBrowser.NavigationRequestedEvent, value);
}
bool nsIURIContentListener.onStartURIOpen (nsIURI aURI)
{
NavigationRequestedEventHandler eh = (NavigationRequestedEventHandler) (Events[WebBrowser.NavigationRequestedEvent]);
if (eh != null) {
AsciiString uri = new Mono.Mozilla.AsciiString ("");
aURI.getSpec (uri.Handle);
NavigationRequestedEventArgs args = new NavigationRequestedEventArgs (uri.ToString ());
eh (this, args);
return args.Cancel;
}
return true;
}
bool nsIURIContentListener.doContent (string aContentType,
bool aIsContentPreferred,
nsIRequest aRequest,
out nsIStreamListener aContentHandler)
{
aContentHandler = null;
return true;
}
bool nsIURIContentListener.isPreferred (string aContentType,
ref string aDesiredContentType)
{
return true;
}
bool nsIURIContentListener.canHandleContent (string aContentType,
bool aIsContentPreferred,
ref string aDesiredContentType)
{
return true;
}
[return: MarshalAs (UnmanagedType.Interface)] IntPtr nsIURIContentListener.getLoadCookie ()
{
return IntPtr.Zero;
}
void nsIURIContentListener.setLoadCookie ([MarshalAs (UnmanagedType.Interface)] IntPtr value)
{
return;
}
nsIURIContentListener nsIURIContentListener.getParentContentListener ()
{
return null;
}
void nsIURIContentListener.setParentContentListener (nsIURIContentListener value)
{
return;
}
}
}

View File

@@ -0,0 +1,96 @@
// Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files (the
// "Software"), to deal in the Software without restriction, including
// without limitation the rights to use, copy, modify, merge, publish,
// distribute, sublicense, and/or sell copies of the Software, and to
// permit persons to whom the Software is furnished to do so, subject to
// the following conditions:
//
// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
// Copyright (c) 2008 Novell, Inc.
//
// Authors:
// Andreia Gaita (avidigal@novell.com)
//
using System;
using Mono.WebBrowser.DOM;
namespace Mono.Mozilla.DOM
{
internal class DOMImplementation : DOMObject, IDOMImplementation
{
private nsIDOMDOMImplementation unmanagedDomImpl;
protected int hashcode;
public DOMImplementation(WebBrowser control, nsIDOMDOMImplementation domImpl) : base (control)
{
if (control.platform != control.enginePlatform)
unmanagedDomImpl = nsDOMDOMImplementation.GetProxy (control, domImpl);
else
unmanagedDomImpl = domImpl;
hashcode = unmanagedDomImpl.GetHashCode ();
}
#region IDisposable Members
protected override void Dispose (bool disposing)
{
if (!disposed) {
if (disposing) {
this.unmanagedDomImpl = null;
}
}
base.Dispose(disposing);
}
#endregion
#region IDOMImplementation Members
public bool HasFeature (string feature, string version)
{
Base.StringSet (storage, feature);
UniString ver = new UniString (version);
bool ret;
unmanagedDomImpl.hasFeature (storage, ver.Handle, out ret);
return ret;
}
public IDocumentType CreateDocumentType (string qualifiedName,
string publicId,
string systemId)
{
nsIDOMDocumentType doctype;
Base.StringSet (storage, qualifiedName);
UniString pubId = new UniString (publicId);
UniString sysId = new UniString (systemId);
unmanagedDomImpl.createDocumentType (storage, pubId.Handle, sysId.Handle, out doctype);
return new DocumentType (this.control, doctype);
}
public IDocument CreateDocument(string namespaceURI,
string qualifiedName,
IDocumentType doctype)
{
nsIDOMDocument doc;
Base.StringSet (storage, namespaceURI);
UniString qual = new UniString (qualifiedName);
unmanagedDomImpl.createDocument (storage, qual.Handle, ((DocumentType)doctype).ComObject, out doc);
control.documents.Add (doc.GetHashCode (), new Document (this.control, doc));
return control.documents[doc.GetHashCode ()] as IDocument;
}
#endregion
}
}

View File

@@ -0,0 +1,154 @@
// Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files (the
// "Software"), to deal in the Software without restriction, including
// without limitation the rights to use, copy, modify, merge, publish,
// distribute, sublicense, and/or sell copies of the Software, and to
// permit persons to whom the Software is furnished to do so, subject to
// the following conditions:
//
// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
// Copyright (c) 2007, 2008 Novell, Inc.
//
// Authors:
// Andreia Gaita (avidigal@novell.com)
//
using System;
using System.Text;
using System.ComponentModel;
using System.Runtime.InteropServices;
using System.Collections;
using Mono.WebBrowser;
namespace Mono.Mozilla.DOM
{
internal class DOMObject : IDisposable
{
private EventHandlerList event_handlers;
protected WebBrowser control;
internal HandleRef storage;
protected bool disposed = false;
protected Hashtable resources;
internal DOMObject (WebBrowser control)
{
this.control = control;
IntPtr p = Base.StringInit ();
storage = new HandleRef (this, p);
resources = new Hashtable ();
event_handlers = null;
}
~DOMObject ()
{
Dispose (false);
}
#region IDisposable Members
protected virtual void Dispose (bool disposing)
{
if (!disposed) {
if (disposing) {
Base.StringFinish (storage);
}
disposed = true;
}
}
public void Dispose ()
{
Dispose (true);
GC.SuppressFinalize (this);
}
#endregion
protected EventHandlerList Events {
get {
// Note: space vs. time tradeoff
// We create the object here if it's never be accessed before. This potentially
// saves space. However, we must check each time the propery is accessed to
// determine whether we need to create the object, which increases overhead.
// We could put the creation in the contructor, but that would waste space
// if it were never used. However, accessing this property would be faster.
if (null == event_handlers)
event_handlers = new EventHandlerList();
return event_handlers;
}
}
#region Private
internal Mono.WebBrowser.DOM.INode GetTypedNode (nsIDOMNode obj)
{
if (obj == null)
return null;
obj.getLocalName (storage);
ushort type;
obj.getNodeType (out type);
switch (type) {
case (ushort)NodeType.Element:
#if DEBUG
Console.Write (Base.StringGet (storage) + ":Getting typed object from NodeType.Element:");
#endif
if (obj is Mono.Mozilla.nsIDOMHTMLBodyElement) {
#if DEBUG
Console.WriteLine ("HTMLElement-nsIDOMHTMLBodyElement");
#endif
return new HTMLElement (control, obj as nsIDOMHTMLBodyElement);
}
else if (obj is Mono.Mozilla.nsIDOMHTMLStyleElement) {
#if DEBUG
Console.WriteLine ("HTMLElement-nsIDOMHTMLStyleElement");
#endif
return new HTMLElement (control, obj as nsIDOMHTMLStyleElement);
}
else if (obj is nsIDOMHTMLElement) {
#if DEBUG
Console.WriteLine ("HTMLElement-nsIDOMHTMLElement");
#endif
return new HTMLElement (control, obj as nsIDOMHTMLElement);
}
#if DEBUG
Console.WriteLine ("HTMLElement-nsIDOMHTMLElement");
#endif
return new Element (control, obj as nsIDOMElement);
break;
case (ushort)NodeType.Attribute:
return new Attribute (control, obj as nsIDOMAttr);
break;
case (ushort)NodeType.Document:
if (obj is nsIDOMHTMLDocument)
return new Document (control, obj as nsIDOMHTMLDocument);
return new Document (control, obj as nsIDOMDocument);
break;
case (ushort)NodeType.Text:
case (ushort)NodeType.CDataSection:
case (ushort)NodeType.EntityReference:
case (ushort)NodeType.Entity:
case (ushort)NodeType.ProcessingInstruction:
case (ushort)NodeType.Comment:
case (ushort)NodeType.DocumentType:
case (ushort)NodeType.DocumentFragment:
case (ushort)NodeType.Notation:
default:
return new Node (control, obj);
break;
}
}
#endregion
}
}

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,217 @@
// Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files (the
// "Software"), to deal in the Software without restriction, including
// without limitation the rights to use, copy, modify, merge, publish,
// distribute, sublicense, and/or sell copies of the Software, and to
// permit persons to whom the Software is furnished to do so, subject to
// the following conditions:
//
// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
// Copyright (c) 2008 Novell, Inc.
//
// Authors:
// Andreia Gaita (avidigal@novell.com)
//
using System;
using System.Runtime.InteropServices;
using System.Runtime.CompilerServices;
using System.Text;
using io=System.IO;
using Mono.Mozilla.DOM;
namespace Mono.Mozilla {
internal class DocumentEncoder : DOMObject {
nsIDocumentEncoder docEncoder = null;
public DocumentEncoder (WebBrowser control) : base (control) {
IntPtr docEncoderServicePtr = IntPtr.Zero;
this.control.ServiceManager.getServiceByContractID (
"@mozilla.org/layout/documentEncoder;1?type=text/html",
typeof (nsIDocumentEncoder).GUID,
out docEncoderServicePtr);
if (docEncoderServicePtr == IntPtr.Zero)
throw new Mono.WebBrowser.Exception (Mono.WebBrowser.Exception.ErrorCodes.DocumentEncoderService);
try {
docEncoder = (nsIDocumentEncoder)Marshal.GetObjectForIUnknown (docEncoderServicePtr);
} catch (System.Exception) {
throw new Mono.WebBrowser.Exception (Mono.WebBrowser.Exception.ErrorCodes.DocumentEncoderService);
}
if (control.platform != control.enginePlatform)
this.docEncoder = nsDocumentEncoder.GetProxy (control, docEncoder);
}
#region IDisposable Members
protected override void Dispose (bool disposing)
{
if (!disposed) {
if (disposing) {
this.docEncoder = null;
}
disposed = true;
}
}
#endregion
string mimeType;
public string MimeType {
get {
if (mimeType == null)
mimeType = "text/html";
return mimeType;
}
set {
mimeType = value;
}
}
DocumentEncoderFlags flags;
public DocumentEncoderFlags Flags {
get { return flags; }
set { flags = value; }
}
void Init (Document document, string mimeType, DocumentEncoderFlags flags)
{
UniString type = new UniString (mimeType);
try {
docEncoder.init ((nsIDOMDocument)document.nodeNoProxy,
type.Handle,
(uint)flags);
} catch (System.Exception ex) {
throw new Mono.WebBrowser.Exception (Mono.WebBrowser.Exception.ErrorCodes.DocumentEncoderService, ex);
}
}
public string EncodeToString (Document document) {
Init (document, MimeType, Flags);
docEncoder.encodeToString(storage);
return Base.StringGet (storage);
}
public string EncodeToString (HTMLElement element) {
Init ((Document)element.Owner, MimeType, Flags);
docEncoder.setNode (element.nodeNoProxy);
docEncoder.encodeToString(storage);
string content = Base.StringGet (storage);
string tag = element.TagName;
string str = "<" + tag;
foreach (Mono.WebBrowser.DOM.IAttribute att in element.Attributes) {
str += " " + att.Name + "=\"" + att.Value + "\"";
}
str += ">" + content + "</" + tag + ">";
return str;
}
public io.Stream EncodeToStream (Document document) {
Init (document, MimeType, Flags);
Stream m = new Stream (new io.MemoryStream ());
docEncoder.encodeToStream (m);
return m.BaseStream;
}
public io.Stream EncodeToStream (HTMLElement element) {
Init ((Document)element.Owner, MimeType, Flags);
docEncoder.setNode (element.nodeNoProxy);
Stream m = new Stream (new io.MemoryStream ());
docEncoder.encodeToStream (m);
return m.BaseStream;
}
/*
void nsIDocumentEncoder.setSelection ([MarshalAs (UnmanagedType.Interface)] nsISelection aSelection)
{
return ;
}
void nsIDocumentEncoder.setRange ([MarshalAs (UnmanagedType.Interface)] nsIDOMRange aRange)
{
return ;
}
void nsIDocumentEncoder.setNode ([MarshalAs (UnmanagedType.Interface)] nsIDOMNode aNode)
{
return ;
}
void nsIDocumentEncoder.setContainerNode ([MarshalAs (UnmanagedType.Interface)] nsIDOMNode aContainer)
{
return ;
}
void nsIDocumentEncoder.setCharset ( string aCharset)
{
return ;
}
void nsIDocumentEncoder.setWrapColumn ( uint aWrapColumn)
{
return ;
}
string nsIDocumentEncoder.getMimeType ()
{
return null;
}
void nsIDocumentEncoder.encodeToStream ([MarshalAs (UnmanagedType.Interface)] nsIOutputStream aStream)
{
return ;
}
string nsIDocumentEncoder.encodeToString ()
{
return ;
}
string nsIDocumentEncoder.encodeToStringWithContext (out string aContextString,
out string aInfoString)
{
return ;
}
void nsIDocumentEncoder.setNodeFixup ([MarshalAs (UnmanagedType.Interface)] nsIDocumentEncoderNodeFixup aFixup)
{
return ;
}
*/
}
}

View File

@@ -0,0 +1,109 @@
// Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files (the
// "Software"), to deal in the Software without restriction, including
// without limitation the rights to use, copy, modify, merge, publish,
// distribute, sublicense, and/or sell copies of the Software, and to
// permit persons to whom the Software is furnished to do so, subject to
// the following conditions:
//
// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
// Copyright (c) 2008 Novell, Inc.
//
// Authors:
// Andreia Gaita (avidigal@novell.com)
//
using System;
using Mono.WebBrowser.DOM;
namespace Mono.Mozilla.DOM
{
internal class DocumentType : Node, IDocumentType
{
internal nsIDOMDocumentType doctype;
public DocumentType (WebBrowser control, nsIDOMDocumentType doctype)
: base (control, doctype as nsIDOMNode)
{
if (control.platform != control.enginePlatform)
this.doctype = nsDOMDocumentType.GetProxy (control, doctype);
else
this.doctype = doctype;
}
#region IDisposable Members
protected override void Dispose (bool disposing)
{
if (!disposed) {
if (disposing) {
this.resources.Clear ();
this.doctype = null;
}
}
base.Dispose (disposing);
}
#endregion
internal nsIDOMDocumentType ComObject
{
get { return doctype; }
}
#region IDocumentType
public string Name {
get {
doctype.getName (storage);
return Base.StringGet (storage);
}
}
public INamedNodeMap Entities {
get {
nsIDOMNamedNodeMap nodeMap;
doctype.getEntities (out nodeMap);
return new NamedNodeMap (this.control, nodeMap);
}
}
public INamedNodeMap Notations {
get {
nsIDOMNamedNodeMap nodeMap;
doctype.getNotations (out nodeMap);
return new NamedNodeMap (this.control, nodeMap);
}
}
public string PublicId {
get {
doctype.getPublicId (storage);
return Base.StringGet (storage);
}
}
public string SystemId {
get {
doctype.getSystemId (storage);
return Base.StringGet (storage);
}
}
public string InternalSubset {
get {
doctype.getInternalSubset (storage);
return Base.StringGet (storage);
}
}
#endregion
public override int GetHashCode () {
return this.hashcode;
}
}
}

View File

@@ -0,0 +1,404 @@
// Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files (the
// "Software"), to deal in the Software without restriction, including
// without limitation the rights to use, copy, modify, merge, publish,
// distribute, sublicense, and/or sell copies of the Software, and to
// permit persons to whom the Software is furnished to do so, subject to
// the following conditions:
//
// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
// Copyright (c) 2008 Novell, Inc.
//
// Authors:
// Andreia Gaita (avidigal@novell.com)
//
using System;
using System.Runtime.InteropServices;
using io=System.IO;
using Mono.WebBrowser;
using Mono.WebBrowser.DOM;
namespace Mono.Mozilla.DOM
{
internal class Element : Node, IElement
{
internal nsIDOMElement node {
get { return base.node as nsIDOMElement;}
set { base.node = value as nsIDOMNode; }
}
public Element(WebBrowser control, nsIDOMElement domElement) : base (control, domElement as nsIDOMNode)
{
this.node = domElement;
}
#region IDisposable Members
protected override void Dispose (bool disposing)
{
if (!disposed) {
if (disposing) {
this.node = null;
}
}
base.Dispose(disposing);
}
#endregion
#region Properties
public virtual IElement AppendChild (IElement child) {
nsIDOMNode newChild;
Element elem = (Element) child;
this.node.appendChild (elem.node, out newChild);
return new Element (control, newChild as nsIDOMElement);
}
public virtual string InnerText
{
get
{
nsIDOMDocumentRange docRange = ((Document) control.Document).XPComObject as nsIDOMDocumentRange;
nsIDOMRange range;
docRange.createRange (out range);
range.selectNodeContents (this.node);
range.toString (storage);
return Base.StringGet (storage);
}
set
{
Base.StringSet (storage, value);
this.node.setNodeValue (storage);
}
}
public virtual string OuterText
{
get
{
nsIDOMDocumentRange docRange = ((Document) control.Document).XPComObject as nsIDOMDocumentRange;
nsIDOMRange range;
docRange.createRange (out range);
nsIDOMNode parent;
node.getParentNode (out parent);
range.selectNodeContents (parent);
range.toString (storage);
return Base.StringGet (storage);
}
set
{
Base.StringSet (storage, value);
nsIDOMNode parent;
node.getParentNode (out parent);
parent.setNodeValue (storage);
}
}
public virtual string InnerHTML {
get { return String.Empty; }
set { }
}
public virtual string OuterHTML {
get { return String.Empty; }
set {}
}
public virtual io.Stream ContentStream {
get { return null; }
}
public IElementCollection All {
get
{
if (!resources.Contains ("All")) {
HTMLElementCollection col = new HTMLElementCollection (control);
Recurse (col, this.node);
resources.Add ("All", col);
}
return resources["All"] as IElementCollection;
}
}
private void Recurse (HTMLElementCollection col, nsIDOMNode parent) {
nsIDOMNodeList children;
parent.getChildNodes (out children);
uint count;
children.getLength (out count);
for (int i = 0; i < count;i++) {
nsIDOMNode node;
children.item ((uint)i, out node);
ushort type;
node.getNodeType (out type);
if (type == (ushort)NodeType.Element) {
col.Add (new HTMLElement (control, (nsIDOMHTMLElement)node));
Recurse (col, node);
}
}
}
public IElementCollection Children {
get
{
if (!resources.Contains ("Children")) {
nsIDOMNodeList children;
this.node.getChildNodes (out children);
resources.Add ("Children", new HTMLElementCollection (control, children));
}
return resources["Children"] as IElementCollection;
}
}
public virtual int TabIndex {
get { return -1; }
set { }
}
public virtual string TagName {
get {
node.getTagName (storage);
return Base.StringGet (storage);
}
}
public virtual bool Disabled {
get { return false; }
set { }
}
public virtual int ClientWidth {
get {
nsIDOMNSHTMLElement e = this.node as nsIDOMNSHTMLElement;
if (e == null)
return 0;
int ret = 0;
e.getClientWidth (out ret);
return ret;
}
}
public virtual int ClientHeight {
get {
nsIDOMNSHTMLElement e = this.node as nsIDOMNSHTMLElement;
if (e == null)
return 0;
int ret = 0;
e.getClientHeight (out ret);
return ret;
}
}
public virtual int ScrollHeight {
get {
nsIDOMNSHTMLElement e = this.node as nsIDOMNSHTMLElement;
if (e == null)
return 0;
int ret = 0;
e.getScrollHeight(out ret);
return ret;
}
}
public virtual int ScrollWidth {
get {
nsIDOMNSHTMLElement e = this.node as nsIDOMNSHTMLElement;
if (e == null)
return 0;
int ret = 0;
e.getScrollWidth (out ret);
return ret;
}
}
public virtual int ScrollLeft {
get {
nsIDOMNSHTMLElement e = this.node as nsIDOMNSHTMLElement;
if (e == null)
return 0;
int ret = 0;
e.getScrollLeft (out ret);
return ret;
}
set {
nsIDOMNSHTMLElement e = this.node as nsIDOMNSHTMLElement;
if (e == null)
return;
e.setScrollLeft (value);
}
}
public virtual int ScrollTop {
get {
nsIDOMNSHTMLElement e = this.node as nsIDOMNSHTMLElement;
if (e == null)
return 0;
int ret = 0;
e.getScrollTop (out ret);
return ret;
}
set {
nsIDOMNSHTMLElement e = this.node as nsIDOMNSHTMLElement;
if (e == null)
return;
e.setScrollTop (value);
}
}
public virtual int OffsetHeight {
get {
nsIDOMNSHTMLElement e = this.node as nsIDOMNSHTMLElement;
if (e == null)
return 0;
int ret = 0;
e.getOffsetHeight (out ret);
return ret;
}
}
public virtual int OffsetWidth {
get {
nsIDOMNSHTMLElement e = this.node as nsIDOMNSHTMLElement;
if (e == null)
return 0;
int ret = 0;
e.getOffsetWidth (out ret);
return ret;
}
}
public virtual int OffsetLeft {
get {
nsIDOMNSHTMLElement e = this.node as nsIDOMNSHTMLElement;
if (e == null)
return 0;
int ret = 0;
e.getOffsetLeft (out ret);
return ret;
}
}
public virtual int OffsetTop {
get {
nsIDOMNSHTMLElement e = this.node as nsIDOMNSHTMLElement;
if (e == null)
return 0;
int ret = 0;
e.getOffsetTop (out ret);
return ret;
}
}
public virtual IElement OffsetParent {
get {
nsIDOMNSHTMLElement e = this.node as nsIDOMNSHTMLElement;
if (e == null)
return null;
nsIDOMElement ret;
e.getOffsetParent (out ret);
if ((ret as nsIDOMHTMLElement) != null)
return new HTMLElement (this.control, ret as nsIDOMHTMLElement);
return new Element (this.control, ret);
}
}
#endregion
#region Methods
public void Blur () {
nsIDOMNSHTMLElement elm = node as nsIDOMNSHTMLElement;
if (elm != null) {
elm.blur ();
}
}
public void Focus () {
nsIDOMNSHTMLElement elm = node as nsIDOMNSHTMLElement;
if (elm != null) {
elm.focus ();
}
}
public IElementCollection GetElementsByTagName (string name)
{
if (!resources.Contains ("GetElementsByTagName" + name)) {
nsIDOMNodeList nodes;
this.node.getElementsByTagName (storage, out nodes);
resources.Add ("GetElementsByTagName" + name, new HTMLElementCollection(control, nodes));
}
return resources["GetElementsByTagName" + name] as IElementCollection;
}
public override int GetHashCode () {
return this.hashcode;
}
public virtual bool HasAttribute (string name)
{
bool ret;
Base.StringSet (storage, name);
node.hasAttribute (storage, out ret);
return ret;
}
public virtual string GetAttribute (string name) {
UniString ret = new UniString (String.Empty);
Base.StringSet (storage, name);
node.getAttribute (storage, ret.Handle);
return ret.ToString ();
}
public void ScrollIntoView (bool alignWithTop)
{
nsIDOMNSHTMLElement elm = node as nsIDOMNSHTMLElement;
if (elm != null) {
elm.scrollIntoView (alignWithTop);
}
}
public virtual void SetAttribute (string name, string value) {
UniString strVal = new UniString (value);
Base.StringSet (storage, name);
node.setAttribute (storage, strVal.Handle);
}
#endregion
internal int Top {
get {
int ret;
((nsIDOMNSHTMLElement)this.node).getOffsetTop (out ret);
return ret;
}
}
internal int Left {
get {
int ret;
((nsIDOMNSHTMLElement)this.node).getOffsetLeft (out ret);
return ret;
}
}
internal int Width {
get {
int ret;
((nsIDOMNSHTMLElement)this.node).getOffsetWidth (out ret);
return ret;
}
}
internal int Height {
get {
int ret;
((nsIDOMNSHTMLElement)this.node).getOffsetHeight (out ret);
return ret;
}
}
}
}

View File

@@ -0,0 +1,146 @@
// Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files (the
// "Software"), to deal in the Software without restriction, including
// without limitation the rights to use, copy, modify, merge, publish,
// distribute, sublicense, and/or sell copies of the Software, and to
// permit persons to whom the Software is furnished to do so, subject to
// the following conditions:
//
// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
// Copyright (c) 2008 Novell, Inc.
//
// Authors:
// Andreia Gaita (avidigal@novell.com)
//
using System;
using System.ComponentModel;
using System.Runtime.InteropServices;
namespace Mono.Mozilla.DOM
{
internal class EventListener : nsIDOMEventListener
{
private HandleRef storage;
private bool disposed = false;
private object owner;
private EventHandlerList events;
public EventHandlerList Events {
get {
if (events == null)
events = new EventHandlerList ();
return events;
}
}
private nsIDOMEventTarget target;
public nsIDOMEventTarget Target {
get { return target; }
set { target = value; }
}
public EventListener(nsIDOMEventTarget target, object owner)
{
this.target = target;
this.owner = owner;
IntPtr p = Base.StringInit ();
storage = new HandleRef (this, p);
}
~EventListener ()
{
Dispose (false);
}
#region IDisposable Members
protected virtual void Dispose (bool disposing)
{
if (!disposed) {
if (disposing) {
Base.StringFinish (storage);
}
disposed = true;
}
}
public void Dispose ()
{
Dispose (true);
GC.SuppressFinalize (this);
}
#endregion
public void AddHandler (EventHandler handler, string _event)
{
string key = String.Intern (target.GetHashCode() + ":" + _event);
Events.AddHandler (key, handler);
Base.StringSet (storage, _event);
target.addEventListener (storage, this, true);
}
public void RemoveHandler (EventHandler handler, string _event)
{
string key = String.Intern (target.GetHashCode() + ":" + _event);
Events.RemoveHandler (key, handler);
Base.StringSet (storage, _event);
target.removeEventListener (storage, this, true);
}
public void AddHandler (Mono.WebBrowser.DOM.NodeEventHandler handler, string _event)
{
string key = String.Intern (target.GetHashCode() + ":" + _event);
Events.AddHandler (key, handler);
Base.StringSet (storage, _event);
target.addEventListener (storage, this, true);
}
public void RemoveHandler (Mono.WebBrowser.DOM.NodeEventHandler handler, string _event)
{
string key = String.Intern (target.GetHashCode() + ":" + _event);
Events.RemoveHandler (key, handler);
Base.StringSet (storage, _event);
target.removeEventListener (storage, this, true);
}
public int handleEvent (nsIDOMEvent _event)
{
_event.getType (storage);
string type = Base.StringGet (storage);
string key = String.Intern (target.GetHashCode () + ":" + type);
EventHandler eh = Events[key] as EventHandler;
if (eh != null) {
eh (owner, new EventArgs ());
return 0;
}
Mono.WebBrowser.DOM.NodeEventHandler eh1 = Events[key] as Mono.WebBrowser.DOM.NodeEventHandler;
if (eh1 != null) {
eh1 (owner, new Mono.WebBrowser.DOM.NodeEventArgs ((Mono.WebBrowser.DOM.INode)owner));
return 0;
}
Mono.WebBrowser.DOM.WindowEventHandler eh2 = Events[key] as Mono.WebBrowser.DOM.WindowEventHandler;
if (eh2 != null) {
eh2 (owner, new Mono.WebBrowser.DOM.WindowEventArgs ((Mono.WebBrowser.DOM.IWindow)owner));
return 0;
}
return 0;
}
}
}

View File

@@ -0,0 +1,172 @@
// Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files (the
// "Software"), to deal in the Software without restriction, including
// without limitation the rights to use, copy, modify, merge, publish,
// distribute, sublicense, and/or sell copies of the Software, and to
// permit persons to whom the Software is furnished to do so, subject to
// the following conditions:
//
// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
// Copyright (c) 2007, 2008 Novell, Inc.
//
// Authors:
// Andreia Gaita (avidigal@novell.com)
//
using System;
using System.Runtime.InteropServices;
using System.Text;
using io=System.IO;
using Mono.WebBrowser;
using Mono.WebBrowser.DOM;
namespace Mono.Mozilla.DOM
{
internal class HTMLElement : Element, IElement
{
protected nsIDOMHTMLElement node {
get { return base.node as nsIDOMHTMLElement; }
set { base.node = value as nsIDOMElement; }
}
public HTMLElement (WebBrowser control, nsIDOMHTMLElement domHtmlElement) : base (control, domHtmlElement as nsIDOMElement)
{
this.node = domHtmlElement;
}
#region IDisposable Members
protected override void Dispose (bool disposing)
{
if (!disposed) {
if (disposing) {
this.node = null;
}
}
base.Dispose(disposing);
}
#endregion
#region IElement Members
public new string InnerHTML
{
get {
nsIDOMNSHTMLElement nsElem = this.node as nsIDOMNSHTMLElement;
if (nsElem == null)
return null;
nsElem.getInnerHTML (storage);
return Base.StringGet (storage);
}
set {
nsIDOMNSHTMLElement nsElem = this.node as nsIDOMNSHTMLElement;
if (nsElem == null)
return;
Base.StringSet (storage, value);
nsElem.setInnerHTML (storage);
}
}
public override string OuterHTML
{
// bad emulation of outerHTML since gecko doesn't support it :P
get {
try {
control.DocEncoder.Flags = DocumentEncoderFlags.OutputRaw;
if (this.Equals (Owner.DocumentElement))
return control.DocEncoder.EncodeToString ((Document) Owner);
return control.DocEncoder.EncodeToString (this);
} catch {
string tag = this.TagName;
string str = "<" + tag;
foreach (IAttribute att in this.Attributes) {
str += " " + att.Name + "=\"" + att.Value + "\"";
}
nsIDOMNSHTMLElement nsElem = this.node as nsIDOMNSHTMLElement;
nsElem.getInnerHTML (storage);
str += ">" + Base.StringGet (storage) + "</" + tag + ">";
return str;
}
}
set {
nsIDOMDocumentRange docRange = ((Document) control.Document).XPComObject as nsIDOMDocumentRange;
nsIDOMRange range;
docRange.createRange (out range);
range.setStartBefore (this.node);
nsIDOMNSRange nsRange = range as nsIDOMNSRange;
Base.StringSet (storage, value);
nsIDOMDocumentFragment fragment;
nsRange.createContextualFragment (storage, out fragment);
nsIDOMNode parent;
this.node.getParentNode (out parent);
parent = nsDOMNode.GetProxy (this.control, parent);
nsIDOMNode newNode;
parent.replaceChild (fragment as nsIDOMNode, this.node as nsIDOMNode, out newNode);
this.node = newNode as Mono.Mozilla.nsIDOMHTMLElement;
}
}
public override io.Stream ContentStream {
get {
try {
control.DocEncoder.Flags = DocumentEncoderFlags.OutputRaw;
if (this.Equals (Owner.DocumentElement))
return control.DocEncoder.EncodeToStream ((Document) Owner);
return control.DocEncoder.EncodeToStream (this);
} catch {
string tag = this.TagName;
string str = "<" + tag;
foreach (IAttribute att in this.Attributes) {
str += " " + att.Name + "=\"" + att.Value + "\"";
}
nsIDOMNSHTMLElement nsElem = this.node as nsIDOMNSHTMLElement;
nsElem.getInnerHTML (storage);
str += ">" + Base.StringGet (storage) + "</" + tag + ">";
byte[] bytes = System.Text.ASCIIEncoding.UTF8.GetBytes (str);
return new io.MemoryStream (bytes);
}
}
}
public override bool Disabled
{
get {
if (this.HasAttribute ("disabled")) {
string dis = this.GetAttribute ("disabled");
return bool.Parse (dis);
}
return false;
}
set {
if (this.HasAttribute ("disabled")) {
this.SetAttribute ("disabled", value.ToString ());
}
}
}
public override int TabIndex {
get {
int tabIndex;
((nsIDOMNSHTMLElement)this.node).getTabIndex (out tabIndex);
return tabIndex;
}
set {
((nsIDOMNSHTMLElement)this.node).setTabIndex (value);
}
}
public override int GetHashCode () {
return this.hashcode;
}
#endregion
}
}

View File

@@ -0,0 +1,78 @@
// Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files (the
// "Software"), to deal in the Software without restriction, including
// without limitation the rights to use, copy, modify, merge, publish,
// distribute, sublicense, and/or sell copies of the Software, and to
// permit persons to whom the Software is furnished to do so, subject to
// the following conditions:
//
// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
// Copyright (c) 2008 Novell, Inc.
//
// Authors:
// Andreia Gaita (avidigal@novell.com)
//
using System;
using Mono.WebBrowser;
using Mono.WebBrowser.DOM;
namespace Mono.Mozilla.DOM
{
internal class HTMLElementCollection : NodeList, IElementCollection
{
public HTMLElementCollection (WebBrowser control, nsIDOMNodeList nodeList) : base (control, nodeList)
{
}
public HTMLElementCollection (WebBrowser control) : base (control)
{
}
internal override void Load ()
{
Clear ();
uint count;
unmanagedNodes.getLength (out count);
Node[] tmpnodes = new Node[count];
for (int i = 0; i < count;i++) {
nsIDOMNode node;
unmanagedNodes.item ((uint)i, out node);
ushort type;
node.getNodeType (out type);
if (type == (ushort)NodeType.Element)
tmpnodes[nodeCount++] = new HTMLElement (control, (nsIDOMHTMLElement)node);
}
nodes = new Node[nodeCount];
Array.Copy (tmpnodes, nodes, nodeCount);
}
#region IList members
public new IElement this [int index] {
get {
if (index < 0 || index >= nodeCount)
throw new ArgumentOutOfRangeException ("index");
return nodes [index] as IElement;
}
set {
if (index < 0 || index >= nodeCount)
throw new ArgumentOutOfRangeException ("index");
nodes [index] = value as INode;
}
}
#endregion
}
}

View File

@@ -0,0 +1,85 @@
// Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files (the
// "Software"), to deal in the Software without restriction, including
// without limitation the rights to use, copy, modify, merge, publish,
// distribute, sublicense, and/or sell copies of the Software, and to
// permit persons to whom the Software is furnished to do so, subject to
// the following conditions:
//
// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
// Copyright (c) 2008 Novell, Inc.
//
// Authors:
// Andreia Gaita (avidigal@novell.com)
//
using System;
using System.Runtime.InteropServices;
using System.Text;
using System.Collections;
using Mono.WebBrowser;
using Mono.WebBrowser.DOM;
namespace Mono.Mozilla.DOM
{
internal class History : DOMObject, IHistory
{
private Navigation navigation;
public History (WebBrowser control, Navigation navigation)
: base (control)
{
this.navigation = navigation;
}
public int Count {
get { return navigation.HistoryCount; }
}
public void Back (int count)
{
navigation.Go (count * -1, true);
}
public void Forward (int count)
{
navigation.Go (count, true);
}
public void GoToIndex (int index)
{
navigation.Go (index);
}
public void GoToUrl (string url)
{
int index = -1;
nsISHistory history;
navigation.navigation.getSessionHistory(out history);
int count = Count;
nsIHistoryEntry entry;
for (int i = 0; i < count; i++) {
nsIURI uri;
history.getEntryAtIndex(i, false, out entry);
entry.getURI (out uri);
AsciiString spec = new AsciiString(String.Empty);
uri.getSpec (spec.Handle);
if (string.Compare (spec.ToString (), url, true) == 0) {
index = i;
break;
}
}
if (index > -1)
this.GoToIndex (index);
}
}
}

View File

@@ -0,0 +1,150 @@
// Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files (the
// "Software"), to deal in the Software without restriction, including
// without limitation the rights to use, copy, modify, merge, publish,
// distribute, sublicense, and/or sell copies of the Software, and to
// permit persons to whom the Software is furnished to do so, subject to
// the following conditions:
//
// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
// Copyright (c) 2008 Novell, Inc.
//
// Authors:
// Andreia Gaita (avidigal@novell.com)
//
using System;
using System.Collections;
#if NET_2_0
using System.Collections.Generic;
#endif
using Mono.WebBrowser;
using Mono.WebBrowser.DOM;
namespace Mono.Mozilla.DOM
{
internal class NamedNodeMap : NodeList, INamedNodeMap
{
protected new nsIDOMNamedNodeMap unmanagedNodes;
public NamedNodeMap (WebBrowser control, nsIDOMNamedNodeMap nodeMap)
: base (control, true)
{
if (control.platform != control.enginePlatform)
unmanagedNodes = nsDOMNamedNodeMap.GetProxy (control, nodeMap);
else
unmanagedNodes = nodeMap;
}
internal override void Load ()
{
Clear ();
uint count;
unmanagedNodes.getLength (out count);
nodeCount = (int) count;
nodes = new Node[count];
for (int i = 0; i < count; i++) {
nsIDOMNode node;
unmanagedNodes.item ((uint) i, out node);
nodes[i] = new Attribute (control, node as nsIDOMAttr);
}
}
public override int Count {
get {
if (unmanagedNodes != null && nodes == null)
Load ();
return nodeCount;
}
}
#region IList members
public new INode this[int index]
{
get
{
if (index < 0 || index >= Count)
throw new ArgumentOutOfRangeException ("index");
return nodes[index] as INode;
}
set { }
}
public INode this [string name]
{
get {
Base.StringSet (storage, name);
nsIDOMNode ret;
unmanagedNodes.getNamedItem (storage, out ret);
for (int i = 0; i < Count; i++) {
if (nodes[i].GetHashCode ().Equals (ret.GetHashCode ()))
return nodes[i];
}
return null;
}
set {
}
}
public INode RemoveNamedItem (string name) {
Base.StringSet (storage, name);
nsIDOMNode ret;
unmanagedNodes.removeNamedItem (storage, out ret);
for (int i = 0; i < Count; i++) {
if (nodes[i].GetHashCode ().Equals (ret.GetHashCode ())) {
INode node = nodes[i];
this.Remove (nodes[i]);
return node;
}
}
return null;
}
public INode this[string namespaceURI, string localName] {
get {
Base.StringSet (storage, namespaceURI);
UniString str = new Mono.Mozilla.UniString(localName);
nsIDOMNode ret;
unmanagedNodes.getNamedItemNS (storage, str.Handle, out ret);
for (int i = 0; i < Count; i++) {
if (nodes[i].GetHashCode ().Equals (ret.GetHashCode ()))
return nodes[i];
}
return null;
}
set {
}
}
public INode RemoveNamedItemNS(string namespaceURI, string localName) {
Base.StringSet (storage, namespaceURI);
nsIDOMNode ret;
UniString str = new Mono.Mozilla.UniString(localName);
unmanagedNodes.removeNamedItemNS (storage, str.Handle, out ret);
for (int i = 0; i < Count; i++) {
if (nodes[i].GetHashCode ().Equals (ret.GetHashCode ())) {
INode node = nodes[i];
this.Remove (nodes[i]);
return node;
}
}
return null;
}
#endregion
public override int GetHashCode () {
return this.unmanagedNodes.GetHashCode ();
}
}
}

Some files were not shown because too many files have changed in this diff Show More