Fix event reception bubbling
This commit is contained in:
parent
d9efbcd494
commit
d4bae780d3
|
@ -1,5 +1,5 @@
|
|||
|
||||
const debug = false;
|
||||
const debug = true;
|
||||
|
||||
const nodes = {};
|
||||
|
||||
|
|
|
@ -134,8 +134,7 @@ namespace Ooui
|
|||
{
|
||||
if (message == null)
|
||||
return;
|
||||
if (message.TargetId != Id)
|
||||
return;
|
||||
if (message.TargetId == Id)
|
||||
SaveStateMessageIfNeeded (message);
|
||||
TriggerEventFromMessage (message);
|
||||
}
|
||||
|
@ -168,8 +167,10 @@ namespace Ooui
|
|||
}
|
||||
}
|
||||
|
||||
protected virtual void TriggerEventFromMessage (Message message)
|
||||
protected virtual bool TriggerEventFromMessage (Message message)
|
||||
{
|
||||
if (message.TargetId != Id)
|
||||
return false;
|
||||
List<EventHandler> handlers = null;
|
||||
lock (eventListeners) {
|
||||
List<EventHandler> hs;
|
||||
|
@ -177,11 +178,12 @@ namespace Ooui
|
|||
handlers = new List<EventHandler> (hs);
|
||||
}
|
||||
}
|
||||
if (handlers == null) return;
|
||||
if (handlers == null) return true;
|
||||
var args = EventArgs.Empty;
|
||||
foreach (var h in handlers) {
|
||||
h.Invoke (this, args);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
12
Ooui/Node.cs
12
Ooui/Node.cs
|
@ -133,5 +133,17 @@ namespace Ooui
|
|||
break;
|
||||
}
|
||||
}
|
||||
|
||||
protected override bool TriggerEventFromMessage (Message message)
|
||||
{
|
||||
if (base.TriggerEventFromMessage (message))
|
||||
return true;
|
||||
var ch = Children;
|
||||
for (var i = 0; i < ch.Count; i++) {
|
||||
if (ch[i].TriggerEventFromMessage (message))
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -37,5 +37,19 @@ namespace Tests
|
|||
Assert.AreEqual (c0, c0s.GetValue (0));
|
||||
Assert.AreEqual (c2, c0s.GetValue (1));
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void EventReceptionBubblesDown ()
|
||||
{
|
||||
var p = new Div ();
|
||||
var b = new Button ();
|
||||
p.AppendChild (b);
|
||||
var clicked = false;
|
||||
b.Clicked += (s, e) => {
|
||||
clicked = true;
|
||||
};
|
||||
p.Receive (Message.Event (b.Id, "click"));
|
||||
Assert.IsTrue (clicked);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue