選択できるのは25トピックまでです。 トピックは、先頭が英数字で、英数字とダッシュ('-')を使用した35文字以内のものにしてください。

JsniMousewheelHandler.java 2.6KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  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.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.client.widgets.JsniWorkaround JsniWorkaround
  28. */
  29. // FIXME remove the copy in v7 package
  30. abstract class JsniMousewheelHandler {
  31. /**
  32. * A JavaScript function that handles the mousewheel DOM event, and passes
  33. * it on to Java code.
  34. *
  35. * @see #createMousewheelListenerFunction(Widget)
  36. */
  37. protected final JavaScriptObject mousewheelListenerFunction;
  38. protected JsniMousewheelHandler(final Widget widget) {
  39. mousewheelListenerFunction = createMousewheelListenerFunction(widget);
  40. }
  41. /**
  42. * A method that constructs the JavaScript function that will be stored into
  43. * {@link #mousewheelListenerFunction}.
  44. *
  45. * @param widget
  46. * a reference to the current instance of {@link Widget}
  47. */
  48. protected abstract JavaScriptObject createMousewheelListenerFunction(
  49. Widget widget);
  50. public native void attachMousewheelListener(Element element)
  51. /*-{
  52. if (element.addEventListener) {
  53. // FireFox likes "wheel", while others use "mousewheel"
  54. var eventName = 'onmousewheel' in element ? 'mousewheel' : 'wheel';
  55. element.addEventListener(eventName, this.@com.vaadin.client.ui.JsniMousewheelHandler::mousewheelListenerFunction);
  56. }
  57. }-*/;
  58. public native void detachMousewheelListener(Element element)
  59. /*-{
  60. if (element.addEventListener) {
  61. // FireFox likes "wheel", while others use "mousewheel"
  62. var eventName = element.onwheel===undefined?"mousewheel":"wheel";
  63. element.removeEventListener(eventName, this.@com.vaadin.client.ui.JsniMousewheelHandler::mousewheelListenerFunction);
  64. }
  65. }-*/;
  66. }