2005-09-14 Chris Toshok <toshok@ximian.com>
authorChris Toshok <toshok@novell.com>
Wed, 14 Sep 2005 09:02:06 +0000 (09:02 -0000)
committerChris Toshok <toshok@novell.com>
Wed, 14 Sep 2005 09:02:06 +0000 (09:02 -0000)
* Microsoft.Web.Atlas_test.dll.sources: add HoverBehaviorTest.cs

* Microsoft.Web.Atlas.dll.sources: add HoverBehavior.cs

* Microsoft.Web.UI/HoverBehavior.cs: new implementation.

* Test/Microsoft.Web.UI/HoverBehaviorTest.cs: new tests.

svn path=/trunk/mcs/; revision=50028

mcs/class/Microsoft.Web.Atlas/ChangeLog
mcs/class/Microsoft.Web.Atlas/Microsoft.Web.Atlas.dll.sources
mcs/class/Microsoft.Web.Atlas/Microsoft.Web.Atlas_test.dll.sources
mcs/class/Microsoft.Web.Atlas/Microsoft.Web.UI/HoverBehavior.cs [new file with mode: 0644]
mcs/class/Microsoft.Web.Atlas/Test/Microsoft.Web.UI/HoverBehaviorTest.cs [new file with mode: 0644]

index 76cbdf76229d58e0cda3f3b3d63d490828dd8b47..6e74b135949a7118bf82bae60d2669444ee143bb 100644 (file)
@@ -1,3 +1,13 @@
+2005-09-14  Chris Toshok  <toshok@ximian.com>
+
+       * Microsoft.Web.Atlas_test.dll.sources: add HoverBehaviorTest.cs
+
+       * Microsoft.Web.Atlas.dll.sources: add HoverBehavior.cs
+
+       * Microsoft.Web.UI/HoverBehavior.cs: new implementation.
+
+       * Test/Microsoft.Web.UI/HoverBehaviorTest.cs: new tests.
+
 2005-09-14  Chris Toshok  <toshok@ximian.com>
 
        * Microsoft.Web.UI/ClickBehavior.cs: fix a nullref in kind of a
index 06ede587331070ad82d9094cd67ef3c9ed48f53a..4ac4357110c39ce0db5277f30117ddb84f3749c8 100644 (file)
@@ -32,6 +32,7 @@ Microsoft.Web.UI/Button.cs
 Microsoft.Web.UI/ClickBehavior.cs
 Microsoft.Web.UI/DragMode.cs
 Microsoft.Web.UI/FloatingBehavior.cs
+Microsoft.Web.UI/HoverBehavior.cs
 Microsoft.Web.UI/MapStyle.cs
 Microsoft.Web.UI/PositioningMode.cs
 Microsoft.Web.UI/Script.cs
index 1197956c4fc58552415337adb2dbddec656829ca..18887d5b4db8853843af0af6e83c93fd477eef65 100644 (file)
@@ -9,3 +9,4 @@ Microsoft.Web/ScriptPropertyDescriptorTest.cs
 Microsoft.Web/ScriptTypeDescriptorTest.cs
 Microsoft.Web.UI/ClickBehaviorTest.cs
 Microsoft.Web.UI/FloatingBehaviorTest.cs
+Microsoft.Web.UI/HoverBehaviorTest.cs
diff --git a/mcs/class/Microsoft.Web.Atlas/Microsoft.Web.UI/HoverBehavior.cs b/mcs/class/Microsoft.Web.Atlas/Microsoft.Web.UI/HoverBehavior.cs
new file mode 100644 (file)
index 0000000..6d8ecfd
--- /dev/null
@@ -0,0 +1,103 @@
+//
+// Microsoft.Web.UI.HoverBehavior
+//
+// Author:
+//   Chris Toshok (toshok@ximian.com)
+//
+//
+// Copyright (C) 2005 Novell, Inc (http://www.novell.com)
+//
+// 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.
+//
+
+#if NET_2_0
+
+using System;
+
+namespace Microsoft.Web.UI
+{
+       public class HoverBehavior : Behavior
+       {
+               public HoverBehavior ()
+               {
+               }
+
+               protected override void InitializeTypeDescriptor (ScriptTypeDescriptor typeDescriptor)
+               {
+                       base.InitializeTypeDescriptor (typeDescriptor);
+
+                       /* XXX should make this use Hover/Unhover, but Owner == null is causing exceptions */
+                       typeDescriptor.AddEvent (new ScriptEventDescriptor ("hover", true));
+                       typeDescriptor.AddEvent (new ScriptEventDescriptor ("unhover", true));
+
+                       typeDescriptor.AddProperty (new ScriptPropertyDescriptor ("hoverElement", ScriptType.Object, false, "HoverElementID"));
+                       typeDescriptor.AddProperty (new ScriptPropertyDescriptor ("unhoverDelay", ScriptType.Number, false, "UnhoverDelay"));
+               }
+
+               ScriptEvent hover;
+               public ScriptEvent Hover {
+                       get {
+                               if (hover == null)
+                                       hover = new ScriptEvent (Owner, "hover", true);
+
+                               return hover;
+                       }
+               }
+
+               string hoverElementID = "";
+               public string HoverElementID {
+                       get {
+                               return hoverElementID;
+                       }
+                       set {
+                               hoverElementID = (value == null ? "" : value);
+                       }
+               }
+
+
+               ScriptEvent unhover;
+               public ScriptEvent Unhover {
+                       get {
+                               if (unhover == null)
+                                       unhover = new ScriptEvent (Owner, "unhover", true);
+
+                               return unhover;
+                       }
+               }
+
+               int unhoverDelay = 0;
+               public int UnhoverDelay {
+                       get {
+                               return unhoverDelay;
+                       }
+                       set {
+                               unhoverDelay = value;
+                       }
+               }
+
+               public override string TagName {
+                       get {
+                               return "hoverBehavior";
+                       }
+               }
+       }
+}
+
+#endif
diff --git a/mcs/class/Microsoft.Web.Atlas/Test/Microsoft.Web.UI/HoverBehaviorTest.cs b/mcs/class/Microsoft.Web.Atlas/Test/Microsoft.Web.UI/HoverBehaviorTest.cs
new file mode 100644 (file)
index 0000000..98fbe4e
--- /dev/null
@@ -0,0 +1,153 @@
+//
+// Tests for Microsoft.Web.UI.HoverBehavior
+//
+// Author:
+//     Chris Toshok (toshok@ximian.com)
+//
+
+//
+// Copyright (C) 2005 Novell, Inc (http://www.novell.com)
+//
+// 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.
+//
+
+#if NET_2_0
+
+using NUnit.Framework;
+using System;
+using System.Collections.Generic;
+using System.IO;
+using Microsoft.Web;
+using Microsoft.Web.UI;
+
+namespace MonoTests.Microsoft.Web.UI
+{
+       [TestFixture]
+       public class HoverBehaviorTest
+       {
+               [Test]
+               public void Properties ()
+               {
+                       HoverBehavior b = new HoverBehavior ();
+
+                       // default
+                       Assert.AreEqual ("hoverBehavior", b.TagName, "A1");
+                       Assert.AreEqual ("", b.HoverElementID, "A2");
+                       Assert.AreEqual (0, b.UnhoverDelay, "A3");
+
+                       // getter/setter
+                       b.HoverElementID = "hi";
+                       Assert.AreEqual ("hi", b.HoverElementID, "A4");
+                       b.UnhoverDelay = 5;
+                       Assert.AreEqual (5, b.UnhoverDelay, "A5");
+                       // XXX negative delay?
+               }
+
+               [Test]
+               public void Render ()
+               {
+                       HoverBehavior b = new HoverBehavior ();
+                       StringWriter sw;
+                       ScriptTextWriter w;
+
+                       sw = new StringWriter();
+                       w = new ScriptTextWriter (sw);
+
+                       b.HoverElementID = "hi";
+                       b.UnhoverDelay = 100;
+
+                       ((IScriptComponent)b).RenderScript (w);
+
+                       Assert.AreEqual ("", sw.ToString(), "A1");
+               }
+
+               void DoEvent (ScriptEventDescriptor e, string eventName, bool supportsActions)
+               {
+                       Assert.AreEqual (eventName, e.EventName, eventName + " EventName");
+                       Assert.AreEqual (eventName, e.MemberName, eventName + " MemberName");
+                       Assert.AreEqual (supportsActions, e.SupportsActions, eventName + " SupportsActions");
+               }
+
+               void DoProperty (ScriptPropertyDescriptor p, string propertyName, ScriptType type, bool readOnly, string serverPropertyName)
+               {
+                       Assert.AreEqual (propertyName, p.PropertyName, propertyName + " PropertyName");
+                       Assert.AreEqual (propertyName, p.MemberName, propertyName + " MemberName");
+                       Assert.AreEqual (readOnly, p.ReadOnly, propertyName + " ReadOnly");
+                       Assert.AreEqual (type, p.Type, propertyName + " Type");
+               }
+
+               [Test]
+               public void TypeDescriptor ()
+               {
+                       HoverBehavior a = new HoverBehavior();
+                       ScriptTypeDescriptor desc = ((IScriptObject)a).GetTypeDescriptor ();
+
+                       Assert.AreEqual (a, desc.ScriptObject, "A1");
+
+                       // events
+                       IEnumerable<ScriptEventDescriptor> events = desc.GetEvents();
+                       Assert.IsNotNull (events, "A2");
+
+                       IEnumerator<ScriptEventDescriptor> ee = events.GetEnumerator();
+                       Assert.IsTrue (ee.MoveNext(), "A3");
+                       DoEvent (ee.Current, "propertyChanged", true);
+                       Assert.IsTrue (ee.MoveNext(), "A3");
+                       DoEvent (ee.Current, "hover", true);
+                       Assert.IsTrue (ee.MoveNext(), "A4");
+                       DoEvent (ee.Current, "unhover", true);
+                       Assert.IsFalse (ee.MoveNext(), "A5");
+
+                       // methods
+                       IEnumerable<ScriptMethodDescriptor> methods = desc.GetMethods();
+                       Assert.IsNotNull (methods, "A6");
+
+                       IEnumerator<ScriptMethodDescriptor> me = methods.GetEnumerator();
+                       Assert.IsFalse (me.MoveNext ());
+
+                       // properties
+                       IEnumerable<ScriptPropertyDescriptor> props = desc.GetProperties();
+                       Assert.IsNotNull (props, "A7");
+
+                       IEnumerator<ScriptPropertyDescriptor> pe = props.GetEnumerator();
+                       Assert.IsTrue (pe.MoveNext(), "A8");
+                       DoProperty (pe.Current, "bindings", ScriptType.Array, true, "Bindings");
+                       Assert.IsTrue (pe.MoveNext(), "A9");
+                       DoProperty (pe.Current, "dataContext", ScriptType.Object, false, "");
+                       Assert.IsTrue (pe.MoveNext(), "A10");
+                       DoProperty (pe.Current, "id", ScriptType.String, false, "ID");
+                       Assert.IsTrue (pe.MoveNext(), "A11");
+                       DoProperty (pe.Current, "hoverElement", ScriptType.Object, false, "HoverElementID");
+                       Assert.IsTrue (pe.MoveNext(), "A12");
+                       DoProperty (pe.Current, "unhoverDelay", ScriptType.Number, false, "UnhoverDelay");
+                       Assert.IsFalse (pe.MoveNext(), "A13");
+               }
+
+               [Test]
+               [ExpectedException (typeof (InvalidOperationException))]
+               public void IsTypeDescriptorClosed ()
+               {
+                       HoverBehavior a = new HoverBehavior();
+                       ScriptTypeDescriptor desc = ((IScriptObject)a).GetTypeDescriptor ();
+
+                       desc.AddEvent (new ScriptEventDescriptor ("testEvent", true));
+               }
+       }
+}
+#endif