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.MouseUpEvent;
17  import com.google.gwt.event.dom.client.MouseUpHandler;
18  import com.googlecode.mgwt.dom.client.event.touch.TouchEndHandler;
19  
20  /**
21   * Convert TouchEndHandlers to MouseUpHandlers for non touch devices or dev mode
22   * 
23   * @author Daniel Kurka
24   * @version $Id: $
25   */
26  public class TouchEndToMouseUpHandler implements MouseUpHandler {
27    private final TouchEndHandler handler;
28  
29    /**
30     * <p>
31     * Constructor for TouchEndToMouseUpHandler.
32     * </p>
33     * 
34     * @param handler a {@link com.googlecode.mgwt.dom.client.event.touch.TouchEndHandler} object.
35     */
36    public TouchEndToMouseUpHandler(TouchEndHandler handler) {
37      this.handler = handler;
38    }
39  
40    /** {@inheritDoc} */
41    @Override
42    public void onMouseUp(MouseUpEvent event) {
43      if (event.isAltKeyDown() || MultiTouchMouseEmulator.isHasValues()) {
44        MultiTouchMouseEmulator.reset();
45        // fire to events
46        SimulatedTouchEndEvent simulatedTouchEndEvent = new SimulatedTouchEndEvent(event, true);
47        handler.onTouchEnd(simulatedTouchEndEvent);
48      }
49  
50      SimulatedTouchEndEvent simulatedTouchEndEvent = new SimulatedTouchEndEvent(event, false);
51      handler.onTouchEnd(simulatedTouchEndEvent);
52  
53    }
54  }