View Javadoc
1   /*
2    * Copyright 2010 Daniel Kurka
3    * 
4    * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
5    * in compliance with the License. You may obtain a copy of the License at
6    * 
7    * http://www.apache.org/licenses/LICENSE-2.0
8    * 
9    * Unless required by applicable law or agreed to in writing, software distributed under the License
10   * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
11   * or implied. See the License for the specific language governing permissions and limitations under
12   * the License.
13   */
14  package com.googlecode.mgwt.dom.client.event.mouse;
15  
16  import com.google.gwt.event.dom.client.MouseDownEvent;
17  import com.google.gwt.event.dom.client.MouseDownHandler;
18  import com.googlecode.mgwt.dom.client.event.touch.TouchStartHandler;
19  
20  /**
21   * Convert TouchStartHandlers to mouse down handlers for non touch devices or dev mode
22   * 
23   * @author Daniel Kurka
24   * @version $Id: $
25   */
26  public class TouchStartToMouseDownHandler implements MouseDownHandler {
27  
28    private final TouchStartHandler handler;
29  
30    /**
31     * <p>
32     * Constructor for TouchStartToMouseDownHandler.
33     * </p>
34     * 
35     * @param handler a {@link com.googlecode.mgwt.dom.client.event.touch.TouchStartHandler} object.
36     */
37    public TouchStartToMouseDownHandler(TouchStartHandler handler) {
38  
39      this.handler = handler;
40  
41    }
42  
43    /** {@inheritDoc} */
44    @Override
45    public void onMouseDown(MouseDownEvent event) {
46      if (event.isAltKeyDown()) {
47        SimulatedTouchStartEvent simulatedTouchStartEvent = new SimulatedTouchStartEvent(event, false);
48        handler.onTouchStart(simulatedTouchStartEvent);
49        simulatedTouchStartEvent = new SimulatedTouchStartEvent(event, true);
50        handler.onTouchStart(simulatedTouchStartEvent);
51      } else {
52        SimulatedTouchStartEvent simulatedTouchStartEvent = new SimulatedTouchStartEvent(event, false);
53        handler.onTouchStart(simulatedTouchStartEvent);
54      }
55  
56    }
57  
58  }