@@ -1,3 +1,18 @@ | |||
/* | |||
* Copyright 2011 Google Inc. | |||
* | |||
* Licensed under the Apache License, Version 2.0 (the "License"); you may not | |||
* use this file except in compliance with the License. You may obtain a copy of | |||
* the License at | |||
* | |||
* http://www.apache.org/licenses/LICENSE-2.0 | |||
* | |||
* Unless required by applicable law or agreed to in writing, software | |||
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT | |||
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the | |||
* License for the specific language governing permissions and limitations under | |||
* the License. | |||
*/ | |||
package com.google.gwt.query.client.plugins; | |||
import com.google.gwt.core.client.GWT; | |||
@@ -12,13 +27,45 @@ import com.google.gwt.query.client.Plugin; | |||
import com.google.gwt.query.client.Predicate; | |||
/** | |||
* GWT clone of jQueryUi-core | |||
* | |||
* @author Julien Dramaix (julien.dramaix@gmail.com, @jdramaix) | |||
* GWT clone of jQueryUi-core. This class define some function present in the | |||
* jQuery-ui core and not directly in jQuery | |||
* | |||
*/ | |||
public class GQueryUi extends GQuery { | |||
/** | |||
* A POJO used to store dimension of an element | |||
* | |||
*/ | |||
public static class Dimension { | |||
private int height = 0; | |||
private int width = 0; | |||
public Dimension(Element e) { | |||
width = e.getOffsetWidth(); | |||
height = e.getOffsetHeight(); | |||
} | |||
public Dimension(int width, int height) { | |||
this.width = width; | |||
this.height = height; | |||
} | |||
/** | |||
* return the height value. | |||
*/ | |||
public int getHeight() { | |||
return height; | |||
} | |||
/** | |||
* return the width value | |||
*/ | |||
public int getWidth() { | |||
return width; | |||
} | |||
} | |||
/** | |||
* This object allows you to have a full copy of the original Event and | |||
* implements some useful method of the jQuery event model. This is also | |||
@@ -29,13 +76,14 @@ public class GQueryUi extends GQuery { | |||
* | |||
* TOBEFIXED : the method preventDefault() must be called directly on the | |||
* original event | |||
* | |||
* | |||
* @author jdramaix | |||
* | |||
* | |||
*/ | |||
public static class Event extends com.google.gwt.user.client.Event { | |||
/** | |||
* Create a new {@link Event} by copying the <code>originalEvent</code>. | |||
*/ | |||
public static Event create(com.google.gwt.user.client.Event originalEvent) { | |||
Event gQueryEvent = createObject().cast(); | |||
copy(originalEvent, gQueryEvent); | |||
@@ -53,15 +101,24 @@ public class GQueryUi extends GQuery { | |||
protected Event() { | |||
} | |||
/** | |||
* Return the original event (the one created by the browser) | |||
*/ | |||
public final native com.google.gwt.user.client.Event getOriginalEvent()/*-{ | |||
return this.originalEvent; | |||
}-*/; | |||
/** | |||
* Tell whether ctrl or cmd key is pressed | |||
* | |||
*/ | |||
public final boolean isMetaKeyPressed() { | |||
return getMetaKey() || getCtrlKey(); | |||
} | |||
/** | |||
* The mouse position relative to the left edge of the document | |||
* | |||
* @param mouseEvent | |||
* @return the mouse x-position in the page | |||
*/ | |||
public final int pageX() { | |||
return getClientX() + document.getScrollLeft(); | |||
@@ -70,54 +127,15 @@ public class GQueryUi extends GQuery { | |||
/** | |||
* The mouse position relative to the top edge of the document. | |||
* | |||
* @param mouseEvent | |||
* @return the mouse y-position in the page | |||
*/ | |||
public final int pageY() { | |||
return getClientY() + document.getScrollTop(); | |||
} | |||
/** | |||
* Tell if ctrl or cmd key is pressed | |||
* | |||
* @return | |||
*/ | |||
public final boolean isMetaKeyPressed() { | |||
return getMetaKey() || getCtrlKey(); | |||
} | |||
} | |||
public static class Dimension { | |||
private int width = 0; | |||
private int height = 0; | |||
public Dimension(Element e) { | |||
width = e.getOffsetWidth(); | |||
height = e.getOffsetHeight(); | |||
} | |||
public Dimension(int width, int height) { | |||
this.width = width; | |||
this.height = height; | |||
} | |||
public int getHeight() { | |||
return height; | |||
} | |||
public int getWidth() { | |||
return width; | |||
} | |||
} | |||
private static class GQueryUiImpl { | |||
private final Element getViewportElement() { | |||
return GQuery.document.isCSS1Compat() ? GQuery.document | |||
.getDocumentElement() : GQuery.document.getBody(); | |||
} | |||
public GQuery scrollParent(final GQueryUi gQueryUi) { | |||
GQuery scrollParent; | |||
@@ -150,16 +168,21 @@ public class GQueryUi extends GQuery { | |||
} | |||
protected boolean scrollParentPositionTest(GQueryUi gQueryUi) { | |||
return "absolute".equals(gQueryUi.css("position")); | |||
} | |||
private final Element getViewportElement() { | |||
return GQuery.document.isCSS1Compat() ? GQuery.document | |||
.getDocumentElement() : GQuery.document.getBody(); | |||
} | |||
private boolean isOverflowEnabled(GQuery e) { | |||
String overflow = e.css("overflow", true) + e.css("overflow-x", true) | |||
+ e.css("overflow-y", true); | |||
return overflow.contains("auto") || overflow.contains("scroll"); | |||
} | |||
protected boolean scrollParentPositionTest(GQueryUi gQueryUi) { | |||
return "absolute".equals(gQueryUi.css("position")); | |||
} | |||
} | |||
@SuppressWarnings("unused") | |||
@@ -185,14 +208,27 @@ public class GQueryUi extends GQuery { | |||
}); | |||
} | |||
protected HasHandlers eventBus; | |||
private GQueryUiImpl impl = GWT.create(GQueryUiImpl.class); | |||
/** | |||
* Return true if the <code>descendant</code> is a child of the parent. Return false elsewhere. | |||
*/ | |||
public static boolean contains(Element parent, Element descendant) { | |||
return parent != descendant && parent.isOrHasChild(descendant); | |||
} | |||
protected static void trigger(GwtEvent<?> e, Function callback, | |||
Element element, HasHandlers handlerManager) { | |||
if (handlerManager != null && e != null) { | |||
handlerManager.fireEvent(e); | |||
} | |||
if (callback != null) { | |||
callback.f(element); | |||
} | |||
} | |||
protected HasHandlers eventBus; | |||
private GQueryUiImpl impl = GWT.create(GQueryUiImpl.class); | |||
public GQueryUi() { | |||
super(); | |||
} | |||
@@ -214,9 +250,7 @@ public class GQueryUi extends GQuery { | |||
} | |||
/** | |||
* this function returns the immediate scrolling parent. | |||
* | |||
* @return the immediate scrolling parent | |||
* Return the immediate scrolling parent. | |||
*/ | |||
public GQuery scrollParent() { | |||
return impl.scrollParent(this); | |||
@@ -225,22 +259,9 @@ public class GQueryUi extends GQuery { | |||
/** | |||
* fire event and call callback function. | |||
* | |||
* @param e | |||
* @param callback | |||
* @param element | |||
*/ | |||
protected void trigger(GwtEvent<?> e, Function callback, Element element) { | |||
trigger(e, callback, element, eventBus); | |||
} | |||
protected static void trigger(GwtEvent<?> e, Function callback, | |||
Element element, HasHandlers handlerManager) { | |||
if (handlerManager != null && e != null) { | |||
handlerManager.fireEvent(e); | |||
} | |||
if (callback != null) { | |||
callback.f(element); | |||
} | |||
} | |||
} |
@@ -1,5 +1,5 @@ | |||
/* | |||
* Copyright 2010 The gwtquery plugins team. | |||
* Copyright 2011 Google Inc. | |||
* | |||
* Licensed under the Apache License, Version 2.0 (the "License"); you may not | |||
* use this file except in compliance with the License. You may obtain a copy of | |||
@@ -15,46 +15,53 @@ | |||
*/ | |||
package com.google.gwt.query.client.plugins; | |||
/** | |||
* Object use to configure a Plugin extending {@link MousePlugin} | |||
* | |||
*/ | |||
public class MouseOptions { | |||
/** | |||
* Prevents plugin working from starting on specified elements. | |||
*/ | |||
private String[] cancel; | |||
/** | |||
* Time in milliseconds to define when the plugin should start. It helps | |||
* preventing unwanted selections when clicking on an element. Default : 0 | |||
* | |||
*/ | |||
private int delay; | |||
/** | |||
* Tolerance, in pixels, for when plugin should start. If specified, selecting | |||
* will not start until after mouse is dragged beyond distance. Default : 1 | |||
* | |||
*/ | |||
private int distance; | |||
public MouseOptions() { | |||
initDefault(); | |||
} | |||
/** | |||
* Return an array of css selectors. The plugin will not start when the mouse | |||
* interacts with the elements selected by the selectors. | |||
* | |||
*/ | |||
public String[] getCancel() { | |||
return cancel; | |||
} | |||
/** | |||
* Return the tolerance, in pixels, for when plugin should start. If | |||
* specified, the plugin will not start until after mouse is dragged beyond | |||
* distance. | |||
* | |||
*/ | |||
public int getDelay() { | |||
return delay; | |||
} | |||
/** | |||
* return the time in milliseconds that define when the plugin should start. | |||
*/ | |||
public int getDistance() { | |||
return distance; | |||
} | |||
/** | |||
* Prevents starting of the plugin on specified elements | |||
* @param cancel array of css selectors | |||
* | |||
* @param cancel | |||
* array of css selectors | |||
*/ | |||
public void setCancel(String... cancel) { | |||
this.cancel = cancel; | |||
@@ -62,17 +69,18 @@ public class MouseOptions { | |||
/** | |||
* Time in milliseconds to define when the plugin should start. It helps | |||
* preventing unwanted selections when clicking on an element. | |||
* @param delay | |||
* preventing unwanted selections when clicking on an element. | |||
* | |||
*/ | |||
public void setDelay(int delay) { | |||
this.delay = delay; | |||
} | |||
/** | |||
* Tolerance, in pixels, for when plugin should start. If specified, selecting | |||
* will not start until after mouse is dragged beyond distance. Default : 1 | |||
* @param distance | |||
* Tolerance, in pixels, for when plugin should start. If specified, the | |||
* plugin will not start until after mouse is dragged beyond distance. Default | |||
* : 1 | |||
* | |||
*/ | |||
public void setDistance(int distance) { | |||
this.distance = distance; | |||
@@ -80,8 +88,7 @@ public class MouseOptions { | |||
protected void initDefault() { | |||
delay = 0; | |||
distance = 1; //by default, the mouse have to move one pixel ! | |||
cancel = new String[]{"input", "option"}; | |||
distance = 1; // by default, the mouse have to move one pixel ! | |||
cancel = new String[] { "input", "option" }; | |||
} | |||
} | |||
@@ -1,5 +1,5 @@ | |||
/* | |||
* Copyright 2010 The gwtquery plugins team. | |||
* Copyright 2011 Google Inc. | |||
* | |||
* Licensed under the Apache License, Version 2.0 (the "License"); you may not | |||
* use this file except in compliance with the License. You may obtain a copy of | |||
@@ -27,16 +27,12 @@ import com.google.gwt.query.client.plugins.Events; | |||
/** | |||
* Base class for all plug-in that need to handle some mouse interactions. | |||
* | |||
* @author Julien Dramaix (julien.dramaix@gmail.com, @jdramaix) | |||
* | |||
*/ | |||
public abstract class MousePlugin extends GQueryUi { | |||
private Event mouseDownEvent; | |||
private boolean mouseStarted = false; | |||
private Duration mouseUpDuration; | |||
// private int mouseDownX; | |||
// private int mouseDownY; | |||
private MouseOptions options; | |||
private boolean preventClickEvent = false; | |||
@@ -65,14 +61,12 @@ public abstract class MousePlugin extends GQueryUi { | |||
* Return a String identifying the plugin. This string is used as namespace | |||
* when we bind handlers. | |||
* | |||
* @return | |||
*/ | |||
protected abstract String getPluginName(); | |||
/** | |||
* This method initialize all needed handlers | |||
* | |||
* @param options | |||
*/ | |||
protected void initMouseHandler(MouseOptions options) { | |||
this.options = options; | |||
@@ -110,7 +104,6 @@ public abstract class MousePlugin extends GQueryUi { | |||
/** | |||
* Test if the mouse down event must be handled by the plugin or not. | |||
* | |||
* | |||
*/ | |||
protected boolean mouseCapture(Element draggable, Event event) { | |||
return true; | |||
@@ -119,9 +112,6 @@ public abstract class MousePlugin extends GQueryUi { | |||
/** | |||
* Method called when mouse click | |||
* | |||
* @param element | |||
* @param event | |||
* @return | |||
*/ | |||
protected boolean mouseClick(Element element, Event event) { | |||
return true; | |||
@@ -133,9 +123,6 @@ public abstract class MousePlugin extends GQueryUi { | |||
* You should not override this method. Instead, override | |||
* {@link #mouseStart(Element, Event)} method | |||
* | |||
* @param element | |||
* @param event | |||
* @return | |||
*/ | |||
protected boolean mouseDown(Element element, Event event) { | |||
@@ -174,9 +161,6 @@ public abstract class MousePlugin extends GQueryUi { | |||
/** | |||
* Method called when the mouse is dragging | |||
* | |||
* @param element | |||
* @param event | |||
* @return | |||
*/ | |||
protected abstract boolean mouseDrag(Element element, Event event); | |||
@@ -186,9 +170,6 @@ public abstract class MousePlugin extends GQueryUi { | |||
* You should not override this method. Instead, override | |||
* {@link #mouseMove(Element, Event)} method | |||
* | |||
* @param element | |||
* @param event | |||
* @return | |||
*/ | |||
protected boolean mouseMove(Element element, Event event) { | |||
if (mouseStarted) { | |||
@@ -212,18 +193,12 @@ public abstract class MousePlugin extends GQueryUi { | |||
* Method called when the mouse is clicked and all conditions for starting the | |||
* plugin are met. | |||
* | |||
* @param element | |||
* @param event | |||
* @return | |||
*/ | |||
protected abstract boolean mouseStart(Element element, Event event); | |||
/** | |||
* Method called when the mouse button is released | |||
* | |||
* @param element | |||
* @param event | |||
* @return | |||
*/ | |||
protected abstract boolean mouseStop(Element element, Event event); | |||
@@ -233,9 +208,6 @@ public abstract class MousePlugin extends GQueryUi { | |||
* You should not override this method. Instead, override | |||
* {@link #mouseStop(Element, Event)} method | |||
* | |||
* @param element | |||
* @param event | |||
* @return | |||
*/ | |||
protected boolean mouseUp(Element element, Event event) { | |||
unbindOtherMouseEvent(); |