You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

JsniMousewheelHandler.java 2.6KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. /*
  2. * Copyright 2000-2018 Vaadin Ltd.
  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.vaadin.v7.client.ui;
  17. import com.google.gwt.core.client.JavaScriptObject;
  18. import com.google.gwt.dom.client.Element;
  19. import com.google.gwt.user.client.Event;
  20. import com.google.gwt.user.client.ui.Widget;
  21. /**
  22. * A mousewheel handling class to get around the limits of
  23. * {@link Event#ONMOUSEWHEEL}.
  24. *
  25. * For internal use only. May be removed or replaced in the future.
  26. *
  27. * @see com.vaadin.v7.client.widgets.JsniWorkaround JsniWorkaround
  28. */
  29. abstract class JsniMousewheelHandler {
  30. /**
  31. * A JavaScript function that handles the mousewheel DOM event, and passes
  32. * it on to Java code.
  33. *
  34. * @see #createMousewheelListenerFunction(Widget)
  35. */
  36. protected final JavaScriptObject mousewheelListenerFunction;
  37. protected JsniMousewheelHandler(final Widget widget) {
  38. mousewheelListenerFunction = createMousewheelListenerFunction(widget);
  39. }
  40. /**
  41. * A method that constructs the JavaScript function that will be stored into
  42. * {@link #mousewheelListenerFunction}.
  43. *
  44. * @param widget
  45. * a reference to the current instance of {@link Widget}
  46. */
  47. protected abstract JavaScriptObject createMousewheelListenerFunction(
  48. Widget widget);
  49. public native void attachMousewheelListener(Element element)
  50. /*-{
  51. if (element.addEventListener) {
  52. // FireFox likes "wheel", while others use "mousewheel"
  53. var eventName = 'onmousewheel' in element ? 'mousewheel' : 'wheel';
  54. element.addEventListener(eventName, this.@com.vaadin.v7.client.ui.JsniMousewheelHandler::mousewheelListenerFunction);
  55. }
  56. }-*/;
  57. public native void detachMousewheelListener(Element element)
  58. /*-{
  59. if (element.addEventListener) {
  60. // FireFox likes "wheel", while others use "mousewheel"
  61. var eventName = element.onwheel===undefined?"mousewheel":"wheel";
  62. element.removeEventListener(eventName, this.@com.vaadin.v7.client.ui.JsniMousewheelHandler::mousewheelListenerFunction);
  63. }
  64. }-*/;
  65. }