01: /*
02: * This file is not part of the ItsNat framework.
03: *
04: * Original source code use and closed source derivatives are authorized
05: * to third parties with no restriction or fee.
06: * The original source code is owned by the author.
07: *
08: * This program is distributed AS IS in the hope that it will be useful,
09: * but WITHOUT ANY WARRANTY; without even the implied warranty of
10: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
11: *
12: * Author: Jose Maria Arranz Santamaria
13: * (C) Innowhere Software Services S.L., Spanish company, year 2007
14: */
15:
16: package org.itsnat.feashow.features.components.functest;
17:
18: import org.itsnat.core.ItsNatDocument;
19: import org.w3c.dom.Element;
20: import org.w3c.dom.events.DocumentEvent;
21: import org.w3c.dom.events.Event;
22: import org.w3c.dom.events.EventTarget;
23: import org.w3c.dom.events.MouseEvent;
24: import org.w3c.dom.views.AbstractView;
25: import org.w3c.dom.views.DocumentView;
26:
27: public class FuncTestNotBrowserUtil {
28: protected ItsNatDocument itsNatDoc;
29:
30: public FuncTestNotBrowserUtil(ItsNatDocument itsNatDoc) {
31: this .itsNatDoc = itsNatDoc;
32: }
33:
34: public void sendHTMLEvent(Element elem, String type) {
35: Event event = createHTMLEvent(type);
36: dispatchEvent(elem, event);
37: }
38:
39: public void clickElement(Element elem) {
40: sendMouseEvent(elem, "click");
41: }
42:
43: public void sendMouseEvent(Element elem, String type) {
44: sendMouseEvent(elem, type, false);
45: }
46:
47: public void sendMouseEvent(Element elem, String type,
48: boolean shiftKey) {
49: Event event = createMouseEvent(type, shiftKey);
50: dispatchEvent(elem, event);
51: }
52:
53: public void dispatchEvent(Element elem, Event event) {
54: EventTarget target = (EventTarget) itsNatDoc
55: .getItsNatNode(elem);
56:
57: target.dispatchEvent(event);
58: }
59:
60: public MouseEvent createMouseEvent(String type, boolean shiftKey) {
61: DocumentEvent docEvent = (DocumentEvent) itsNatDoc;
62: MouseEvent event = (MouseEvent) docEvent
63: .createEvent("MouseEvents");
64: AbstractView view = ((DocumentView) itsNatDoc).getDefaultView();
65: event.initMouseEvent(type, true, true, view, 0, 0, 0, 0, 0,
66: false, false, shiftKey, false,
67: (short) 0/*left button*/, null);
68: return event;
69: }
70:
71: public Event createHTMLEvent(String type) {
72: DocumentEvent docEvent = (DocumentEvent) itsNatDoc;
73: Event event = docEvent.createEvent("HTMLEvents");
74: event.initEvent(type, true, true);
75: return event;
76: }
77:
78: }
|