I use the following code to disable text selection on an element:
/**
* Enables or disables text selection for the element. A circular
reference
* will be created when disabling text selection. Disabling should
be cleared
* when the element is detached. See the <code>Component</code>
source for
* an example.
*
* @param elem the element
* @param disable <code>true</code> to disable
*/
public static void disableTextSelection(Element elem, boolean
disable) {
setStyleName(elem, "my-no-selection", disable);
disableTextSelectInternal(elem, disable);
}
private native static void disableTextSelectInternal(Element e,
boolean disable)/*-{
if (disable) {
e.ondrag = function () { return false; };
e.onselectstart = function () { return false; };
} else {
e.ondrag = null;
e.onselectstart = null;
}
}-*/;
It will create a circular reference if you do not clear the anonymous
function. In MyGWT the function is enabled and cleared when a widget
is attached and detached to prevent the memory leak.
Darrell
MyGWT Library
http://mygwt.net
On Jan 30, 4:53 pm, "Fred Sauer" <
f...@allen-sauer.com> wrote:
> Take a look at DOM.eventPreventDefault, which will prevent the text
> selection.
>
> Some browsers also support CSS options like 'user-select: none'.
>
> Only one element can be capturing at any time.
>
> HTH
> Fred
>
> On Jan 30, 2008 2:26 PM, yilativs <
yilat...@gmail.com> wrote:
>
>
>
>
>
> > Hello,
>
> > How to disable default text selection behavior when pressing left
> > mouse button and moving the mouse at
> > same time AND let all my widgets handle the mouse events?
>
> > I managed to do it in Firefox with:
> > DOM.setCapture(myWidget.getElement());
> > while doing same in IE6/7 all my widgets stop repsonding on mouse
> > operations.
>
> > Can I use DOM.setCapture for several widgets at once?
>
> > Regards,
> > Vitaliy S
>
> --
> Fred Sauer
>
f...@allen-sauer.com