Subversion Repository Public Repository

litesoft

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
/*
 * Copyright 2008 Google Inc.
 *
 * Licensed under the Apache License, Version 2.0 (the "License"); you may not
 * use this file except in compliance with the License. You may obtain a copy of
 * the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
 * License for the specific language governing permissions and limitations under
 * the License.
 */
package com.google.gwt.gen2.event.dom.client;

import com.google.gwt.core.client.*;
import com.google.gwt.gen2.event.shared.*;
import com.google.gwt.user.client.*;

import java.util.*;

/**
 * {@link DomEvent} is a subclass of AbstractEvent that provides events that map
 * to DOM Level 2 Events. It provides an additional method to access the
 * underlying native browser event object as well as a subclass of
 * AbstractEvent.Key that understands GWT event bits used by sinkEvents().
 *
 * @deprecated use the com.google.gwt.event.dom.client classes instead
 */
@Deprecated
public abstract class DomEvent extends AbstractEvent {

    /**
     * Type class used by BrowserEvent subclasses.
     *
     * @param <EventType>   event type
     * @param <HandlerType> handler type
     */
    public abstract static class Type<EventType extends DomEvent, HandlerType extends EventHandler> extends AbstractEvent.Type<EventType, HandlerType> {
        private int nativeEventType;
        DomEvent cached;

        /**
         * Constructor.
         *
         * @param nativeEventType the native event type
         */
        public Type( int nativeEventType ) {
            // All clinit activity should take place here for DomEvent.
            if ( registered == null ) {
                registered = new WrappedKeyMap();
            }
            this.nativeEventType = nativeEventType;
            registered.put( getType( nativeEventType ), this );
        }

        /**
         * Gets the native {@link Event} type integer corresponding to the native
         * event.
         *
         * @return the native event type
         */
        public int getNativeEventType() {
            return nativeEventType;
        }

        /**
         * Wraps the native event.
         *
         * @param nativeEvent the native event
         *
         * @return the wrapped native event
         */
        abstract EventType wrap( Event nativeEvent );
    }

    // Eventually should be replaced by JsStringMap.
    private static class WrappedKeyMap {
        private static class KeyMap extends JavaScriptObject {
            public static KeyMap create() {
                return (KeyMap) JavaScriptObject.createObject();
            }

            protected KeyMap() {
            }

            public final native DomEvent.Type get( String nativeEventType ) /*-{
                return this[nativeEventType];
            }-*/;

            public final native void put( String nativeEventType, DomEvent.Type key ) /*-{
                this[nativeEventType] = key;
            }-*/;
        }

        private KeyMap map;

        private HashMap<String, DomEvent.Type> javaMap;

        WrappedKeyMap() {
            if ( GWT.isScript() ) {
                map = KeyMap.create();
            } else {
                javaMap = new HashMap<String, DomEvent.Type>();
            }
        }

        public final DomEvent.Type get( String nativeEventType ) {
            if ( GWT.isScript() ) {
                return map.get( nativeEventType );
            } else {
                return javaMap.get( nativeEventType );
            }
        }

        public final void put( String nativeEventType, DomEvent.Type key ) {
            if ( GWT.isScript() ) {
                map.put( nativeEventType, key );
            } else {
                javaMap.put( nativeEventType, key );
            }
        }
    }

    private static WrappedKeyMap registered;

    /**
     * Fires the given native event on the manager with a null underlying native
     * event.
     * <p/>
     * <p>
     * This method is used in the rare case that GWT widgets have to fire native
     * events but do not have access to the corresponding native event. It allows
     * the compiler to avoid instantiating event types that are never handlers.
     * </p>
     *
     * @param eventType the GWT event type representing the type of the native
     *                  event.
     * @param manager   the event manager
     */
    public static void fireNativeEvent( int eventType, HandlerManager manager ) {
        if ( registered != null ) {
            DomEvent.Type typeKey = registered.get( getType( eventType ) );
            if ( typeKey != null && manager.isEventHandled( typeKey ) ) {
                if ( typeKey.cached == null || typeKey.cached.isLive() ) {
                    typeKey.cached = typeKey.wrap( null );
                } else {
                    typeKey.cached.reset( null );
                }
                manager.fireEvent( typeKey.cached );
            }
        }
    }

    /**
     * Fires the given native event on the manager.
     *
     * @param nativeEvent the native event
     * @param manager     the event manager
     */
    public static void fireNativeEvent( Event nativeEvent, HandlerManager manager ) {
        if ( registered != null ) {
            DomEvent.Type typeKey = registered.get( nativeEvent.getType() );
            if ( typeKey != null && manager.isEventHandled( typeKey ) ) {
                if ( typeKey.cached == null || typeKey.cached.isLive() ) {
                    typeKey.cached = typeKey.wrap( nativeEvent );
                } else {
                    typeKey.cached.reset( nativeEvent );
                }
                manager.fireEvent( typeKey.cached );
            }
        }
    }

    private static String getType( int type ) {
        switch ( type ) {
            case 0x01000:
                return "blur";
            case 0x00400:
                return "change";
            case 0x00001:
                return "click";
            case 0x00002:
                return "dblclick";
            case 0x00800:
                return "focus";
            case 0x00080:
                return "keydown";
            case 0x00100:
                return "keypress";
            case 0x00200:
                return "keyup";
            case 0x08000:
                return "load";
            case 0x02000:
                return "losecapture";
            case 0x00004:
                return "mousedown";
            case 0x00040:
                return "mousemove";
            case 0x00020:
                return "mouseout";
            case 0x00010:
                return "mouseover";
            case 0x00008:
                return "mouseup";
            case 0x04000:
                return "scroll";
            case 0x10000:
                return "error";
            case 0x20000:
                return "mousewheel";
            case 0x40000:
                return "contextmenu";
            default:
                return null;
        }
    }

    private Event nativeEvent;

    /**
     * Constructor.
     *
     * @param nativeEvent the native event
     */
    protected DomEvent( Event nativeEvent ) {
        this.nativeEvent = nativeEvent;
    }

    /**
     * Gets the underlying native event for this {@link DomEvent}.
     *
     * @return gets the native event
     */
    public final Event getNativeEvent() {
        assertLive();
        return nativeEvent;
    }

    /**
     * Prevents the wrapped native event's default action.
     */
    public void preventDefault() {
        assertLive();
        nativeEvent.preventDefault();
    }

    /**
     * Stops the propagation of the underlying native event.
     */
    public void stopPropagation() {
        assertLive();
        nativeEvent.cancelBubble( true );
    }

    @Override
    public String toString() {
        return getType( getType().getNativeEventType() ) + " event";
    }

    @Override
    protected abstract DomEvent.Type getType();

    void reset( Event event ) {
        super.revive();
        nativeEvent = event;
    }
}

Commits for litesoft/trunk/Java/GWT/Client/src/com/google/gwt/gen2/event/dom/client/DomEvent.java

Diff revisions: vs.
Revision Author Commited Message
948 Diff Diff GeorgeS picture GeorgeS Sat 07 Jun, 2014 23:42:39 +0000

Jusefuls Formatter Updated to New Code Format

939 Diff Diff GeorgeS picture GeorgeS Mon 02 Jun, 2014 21:30:31 +0000

Extracting commonfoundation

475 Diff Diff GeorgeS picture GeorgeS Sat 03 Sep, 2011 13:54:51 +0000
282 GeorgeS picture GeorgeS Fri 17 Jun, 2011 13:54:39 +0000