001: /*
002: * Copyright 2007 Google Inc.
003: *
004: * Licensed under the Apache License, Version 2.0 (the "License"); you may not
005: * use this file except in compliance with the License. You may obtain a copy of
006: * the License at
007: *
008: * http://www.apache.org/licenses/LICENSE-2.0
009: *
010: * Unless required by applicable law or agreed to in writing, software
011: * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
012: * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
013: * License for the specific language governing permissions and limitations under
014: * the License.
015: */
016: package com.google.gwt.user.client.ui.impl;
017:
018: import com.google.gwt.user.client.DOM;
019: import com.google.gwt.user.client.Element;
020:
021: /**
022: * IE6-specific implementation of rich-text editing.
023: */
024: public class RichTextAreaImplIE6 extends RichTextAreaImplStandard {
025:
026: @Override
027: public Element createElement() {
028: Element elem = super .createElement();
029: DOM.setElementProperty(elem, "src", "javascript:''");
030: return elem;
031: }
032:
033: @Override
034: public native void initElement() /*-{
035: var _this = this;
036: window.setTimeout(function() {
037: var elem = _this.@com.google.gwt.user.client.ui.impl.RichTextAreaImpl::elem;
038: var doc = elem.contentWindow.document;
039: doc.write('<html><body CONTENTEDITABLE="true"></body></html>');
040:
041: // Send notification that the iframe has reached design mode.
042: _this.@com.google.gwt.user.client.ui.impl.RichTextAreaImplStandard::onElementInitialized()();
043: }, 1);
044: }-*/;
045:
046: @Override
047: protected native String getTextImpl() /*-{
048: var elem = this.@com.google.gwt.user.client.ui.impl.RichTextAreaImpl::elem;
049: return elem.contentWindow.document.body.innerText;
050: }-*/;
051:
052: @Override
053: protected native void hookEvents() /*-{
054: var elem = this.@com.google.gwt.user.client.ui.impl.RichTextAreaImpl::elem;
055: var body = elem.contentWindow.document.body;
056:
057: var handler = function() {
058: if (elem.__listener) {
059: // Weird: this code has the context of the script frame, but we need the
060: // event from the edit iframe's window.
061: var evt = elem.contentWindow.event;
062: elem.__listener.@com.google.gwt.user.client.ui.RichTextArea::onBrowserEvent(Lcom/google/gwt/user/client/Event;)(evt);
063: }
064: };
065:
066: body.onkeydown =
067: body.onkeyup =
068: body.onkeypress =
069: body.onmousedown =
070: body.onmouseup =
071: body.onmousemove =
072: body.onmouseover =
073: body.onmouseout =
074: body.onclick = handler;
075:
076: elem.contentWindow.onfocus =
077: elem.contentWindow.onblur = handler;
078: }-*/;
079:
080: @Override
081: protected native void setTextImpl(String text) /*-{
082: var elem = this.@com.google.gwt.user.client.ui.impl.RichTextAreaImpl::elem;
083: elem.contentWindow.document.body.innerText = text;
084: }-*/;
085:
086: @Override
087: protected native void unhookEvents() /*-{
088: var elem = this.@com.google.gwt.user.client.ui.impl.RichTextAreaImpl::elem;
089: var body = elem.contentWindow.document.body;
090:
091: if (body) {
092: // The body can be undefined in the relatively obscure case that the RTA
093: // is attached and detached before it has a chance to finish initializing.
094: body.onkeydown =
095: body.onkeyup =
096: body.onkeypress =
097: body.onmousedown =
098: body.onmouseup =
099: body.onmousemove =
100: body.onmouseover =
101: body.onmouseout =
102: body.onclick = null;
103:
104: elem.contentWindow.onfocus =
105: elem.contentWindow.onblur = null;
106: }
107: }-*/;
108:
109: @Override
110: boolean isRichEditingActive(Element elem) {
111: return true;
112: }
113: }
|