KickJava   Java API By Example, From Geeks To Geeks.

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


1 /*
2  * Copyright 2007 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.DOM;
19 import com.google.gwt.user.client.Element;
20
21 /**
22  * IE6-specific implementation of rich-text editing.
23  */

24 public class RichTextAreaImplIE6 extends RichTextAreaImplStandard {
25
26   private static native void detachEvents(Element elem) /*-{
27     var body = elem.contentWindow.document.body;
28     body.onkeydown =
29     body.onkeyup =
30     body.onkeypress =
31     body.onmousedown =
32     body.onmouseup =
33     body.onmousemove =
34     body.onmouseover =
35     body.onmouseout =
36     body.onclick = null;
37   }-*/
;
38
39   private static native String JavaDoc getText(Element elem) /*-{
40     return elem.contentWindow.document.body.innerText;
41   }-*/
;
42
43   private static native void initEvents(Element elem) /*-{
44     var handler = function() {
45       if (elem.__listener) {
46         // Weird: this code has the context of the script frame, but we need the
47         // event from the edit iframe's window.
48         var evt = elem.contentWindow.event;
49         elem.__listener.@com.google.gwt.user.client.ui.RichTextArea::onBrowserEvent(Lcom/google/gwt/user/client/Event;)(evt);
50       }
51     };
52
53     var body = elem.contentWindow.document.body;
54     body.onkeydown =
55     body.onkeyup =
56     body.onkeypress =
57     body.onmousedown =
58     body.onmouseup =
59     body.onmousemove =
60     body.onmouseover =
61     body.onmouseout =
62     body.onclick = handler;
63   }-*/
;
64
65   private static native void setText(Element elem, String JavaDoc text) /*-{
66     elem.contentWindow.document.body.innerText = text;
67   }-*/
;
68
69   public Element createElement() {
70     Element elem = super.createElement();
71     DOM.setElementProperty(elem, "src", "javascript:''");
72     return elem;
73   }
74
75   public native void initElement() /*-{
76     var _this = this;
77     window.setTimeout(function() {
78       var elem = _this.@com.google.gwt.user.client.ui.impl.RichTextAreaImpl::elem;
79       var doc = elem.contentWindow.document;
80       doc.write('<html><body CONTENTEDITABLE="true"></body></html>');
81
82       // Initialize event handling.
83       @com.google.gwt.user.client.ui.impl.RichTextAreaImplIE6::initEvents(Lcom/google/gwt/user/client/Element;)(elem);
84
85       // Send notification that the iframe has reached design mode.
86       _this.@com.google.gwt.user.client.ui.impl.RichTextAreaImplStandard::onElementInitialized()();
87     }, 1);
88   }-*/
;
89
90   public void unhookEvents() {
91     super.unhookEvents();
92     detachEvents(elem);
93   }
94
95   protected String JavaDoc getTextImpl() {
96     return getText(elem);
97   }
98
99   protected void setTextImpl(String JavaDoc text) {
100     setText(elem, text);
101   }
102   
103   boolean isRichEditingActive(Element elem) {
104     return true;
105   }
106 }
107
Popular Tags