View Javadoc
1   /*
2    * Copyright 2011 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.ui.client.widget.touch;
17  
18  import com.google.gwt.event.dom.client.MouseDownEvent;
19  import com.google.gwt.event.dom.client.MouseMoveEvent;
20  import com.google.gwt.event.dom.client.MouseUpEvent;
21  import com.google.gwt.event.shared.HandlerRegistration;
22  import com.google.gwt.user.client.ui.Widget;
23  import com.googlecode.mgwt.dom.client.event.mouse.HandlerRegistrationCollection;
24  import com.googlecode.mgwt.dom.client.event.mouse.TouchEndToMouseUpHandler;
25  import com.googlecode.mgwt.dom.client.event.mouse.TouchMoveToMouseMoveHandler;
26  import com.googlecode.mgwt.dom.client.event.mouse.TouchStartToMouseDownHandler;
27  import com.googlecode.mgwt.dom.client.event.touch.TouchCancelHandler;
28  import com.googlecode.mgwt.dom.client.event.touch.TouchEndHandler;
29  import com.googlecode.mgwt.dom.client.event.touch.TouchMoveHandler;
30  import com.googlecode.mgwt.dom.client.event.touch.TouchStartHandler;
31  import com.googlecode.mgwt.ui.client.util.NoopHandlerRegistration;
32  
33  /**
34   * The implementation for mouse devices of {@link TouchWidgetImpl}
35   * 
36   * @author Daniel Kurka
37   * @version $Id: $
38   */
39  public class TouchWidgetDesktopImpl implements TouchWidgetImpl {
40  
41  	/*
42  	 * (non-Javadoc)
43  	 * @see com.googlecode.mgwt.ui.client.widget.touch.TouchWidgetImpl#addTouchStartHandler(com.google.gwt.user.client.ui.Widget, com.googlecode.mgwt.dom.client.event.touch.TouchStartHandler)
44  	 */
45  	/** {@inheritDoc} */
46  	@Override
47  	public HandlerRegistration addTouchStartHandler(Widget w, TouchStartHandler handler) {
48  		return w.addDomHandler(new TouchStartToMouseDownHandler(handler), MouseDownEvent.getType());
49  	}
50  
51  	/*
52  	 * (non-Javadoc)
53  	 * @see com.googlecode.mgwt.ui.client.widget.touch.TouchWidgetImpl#addTouchMoveHandler(com.google.gwt.user.client.ui.Widget, com.googlecode.mgwt.dom.client.event.touch.TouchMoveHandler)
54  	 */
55  	/** {@inheritDoc} */
56  	@Override
57  	public HandlerRegistration addTouchMoveHandler(Widget w, TouchMoveHandler handler) {
58  		TouchMoveToMouseMoveHandler touchMoveToMouseMoveHandler = new TouchMoveToMouseMoveHandler(handler);
59  		HandlerRegistrationCollection handlerRegistrationCollection = new HandlerRegistrationCollection();
60  		handlerRegistrationCollection.addHandlerRegistration(w.addDomHandler(touchMoveToMouseMoveHandler, MouseDownEvent.getType()));
61  		handlerRegistrationCollection.addHandlerRegistration(w.addDomHandler(touchMoveToMouseMoveHandler, MouseUpEvent.getType()));
62  		handlerRegistrationCollection.addHandlerRegistration(w.addDomHandler(touchMoveToMouseMoveHandler, MouseMoveEvent.getType()));
63  		return handlerRegistrationCollection;
64  	}
65  
66  	/*
67  	 * (non-Javadoc)
68  	 * @see com.googlecode.mgwt.ui.client.widget.touch.TouchWidgetImpl#addTouchCancelHandler(com.google.gwt.user.client.ui.Widget, com.googlecode.mgwt.dom.client.event.touch.TouchCancelHandler)
69  	 */
70  	/** {@inheritDoc} */
71  	@Override
72  	public HandlerRegistration addTouchCancelHandler(Widget w, TouchCancelHandler handler) {
73  		return new NoopHandlerRegistration();
74  	}
75  
76  	/*
77  	 * (non-Javadoc)
78  	 * @see com.googlecode.mgwt.ui.client.widget.touch.TouchWidgetImpl#addTouchEndHandler(com.google.gwt.user.client.ui.Widget, com.googlecode.mgwt.dom.client.event.touch.TouchEndHandler)
79  	 */
80  	/** {@inheritDoc} */
81  	@Override
82  	public HandlerRegistration addTouchEndHandler(Widget w, TouchEndHandler handler) {
83  		return w.addDomHandler(new TouchEndToMouseUpHandler(handler), MouseUpEvent.getType());
84  	}
85  
86  }