KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > google > gwt > user > client > ui > impl > TextBoxImplIE6


1 /*
2  * Copyright 2006 Google Inc.
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.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   public native int getCursorPos(Element elem) /*-{
27     try {
28       var tr = elem.document.selection.createRange();
29       if (tr.parentElement().uniqueID != elem.uniqueID)
30         return -1;
31       return -tr.move("character", -65535);
32     }
33     catch (e) {
34       return 0;
35     }
36   }-*/
;
37
38   public native int getSelectionLength(Element elem) /*-{
39     try {
40       var tr = elem.document.selection.createRange();
41       if (tr.parentElement().uniqueID != elem.uniqueID)
42         return 0;
43       return tr.text.length;
44     }
45     catch (e) {
46       return 0;
47     }
48   }-*/
;
49
50   public native int getTextAreaCursorPos(Element elem) /*-{
51     try {
52       var tr = elem.document.selection.createRange();
53       var tr2 = tr.duplicate();
54       tr2.moveToElementText(elem);
55       tr.setEndPoint('EndToStart', tr2);
56       return tr.text.length;
57     }
58     catch (e) {
59       return 0;
60     }
61   }-*/
;
62
63   public native void setSelectionRange(Element elem, int pos, int length) /*-{
64     try {
65       var tr = elem.createTextRange();
66       tr.collapse(true);
67       tr.moveStart('character', pos);
68       tr.moveEnd('character', length);
69       tr.select();
70     }
71     catch (e) {
72     }
73   }-*/
;
74
75 }
76
Popular Tags