01: /*
02: * Copyright 2007 Google Inc.
03: *
04: * Licensed under the Apache License, Version 2.0 (the "License"); you may not
05: * use this file except in compliance with the License. You may obtain a copy of
06: * the License at
07: *
08: * http://www.apache.org/licenses/LICENSE-2.0
09: *
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.google.gwt.user.client.ui.impl;
17:
18: import com.google.gwt.user.client.Element;
19:
20: /**
21: * IE6-specific implementation of
22: * {@link com.google.gwt.user.client.ui.impl.TextBoxImpl}.
23: */
24: public class TextBoxImplIE6 extends TextBoxImpl {
25:
26: @Override
27: public native int getCursorPos(Element elem) /*-{
28: try {
29: var tr = elem.document.selection.createRange();
30: if (tr.parentElement().uniqueID != elem.uniqueID)
31: return -1;
32: return -tr.move("character", -65535);
33: }
34: catch (e) {
35: return 0;
36: }
37: }-*/;
38:
39: @Override
40: public native int getSelectionLength(Element elem) /*-{
41: try {
42: var tr = elem.document.selection.createRange();
43: if (tr.parentElement().uniqueID != elem.uniqueID)
44: return 0;
45: return tr.text.length;
46: }
47: catch (e) {
48: return 0;
49: }
50: }-*/;
51:
52: @Override
53: public native int getTextAreaCursorPos(Element elem) /*-{
54: try {
55: var tr = elem.document.selection.createRange();
56: var tr2 = tr.duplicate();
57: tr2.moveToElementText(elem);
58: tr.setEndPoint('EndToStart', tr2);
59: return tr.text.length;
60: }
61: catch (e) {
62: return 0;
63: }
64: }-*/;
65:
66: @Override
67: public native void setSelectionRange(Element elem, int pos,
68: int length) /*-{
69: try {
70: var tr = elem.createTextRange();
71: tr.collapse(true);
72: tr.moveStart('character', pos);
73: tr.moveEnd('character', length);
74: tr.select();
75: }
76: catch (e) {
77: }
78: }-*/;
79:
80: }
|