View Javadoc
1   /*
2    * Copyright 2012 Daniel Kurka
3    * 
4    * Licensed under the Apache License, Version 2.0 (the "License"); you may not
5    * use this file except in compliance with the License. You may obtain a copy of
6    * the License at
7    * 
8    * http://www.apache.org/licenses/LICENSE-2.0
9    * 
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
12   * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13   * License for the specific language governing permissions and limitations under
14   * the License.
15   */
16  package com.googlecode.mgwt.dom.client.recognizer;
17  
18  import com.google.gwt.core.client.Scheduler;
19  import com.google.gwt.core.client.Scheduler.ScheduledCommand;
20  import com.google.gwt.event.shared.GwtEvent;
21  import com.google.gwt.event.shared.HasHandlers;
22  
23  /**
24   * Propagate events from a source. There is an issue on mobile webkit which gets
25   * confused about events if an alert is shown from an event handler, see:
26   * http://
27   * blog.daniel-kurka.de/2012/05/mobile-webkit-alert-dialog-breaks-touch.html
28   * 
29   * This class provides a workaround by propagating events with a
30   * ScheduledCommand
31   * 
32   * @author Daniel Kurka
33   * 
34   */
35  public class EventPropagatorMobileImpl implements EventPropagator {
36  
37  	private static class SCommand implements ScheduledCommand {
38  		private final HasHandlers source;
39  		private final GwtEvent<?> event;
40  
41  		public SCommand(HasHandlers source, GwtEvent<?> event) {
42  			this.source = source;
43  			this.event = event;
44  		}
45  
46  		@Override
47  		public void execute() {
48  			source.fireEvent(event);
49  
50  		}
51  
52  	}
53  
54  	/*
55  	 * (non-Javadoc)
56  	 * @see com.googlecode.mgwt.dom.client.recognizer.EventPropagator#fireEvent(com.google.gwt.event.shared.HasHandlers, com.google.gwt.event.shared.GwtEvent)
57  	 */
58  	@Override
59  	public void fireEvent(final HasHandlers source, final GwtEvent<?> event) {
60  		// see issue 135
61  		// http://code.google.com/p/mgwt/issues/detail?id=135
62  		Scheduler.get().scheduleDeferred(new SCommand(source, event));
63  
64  	}
65  
66  }