Skip to content

Commit d6abfe4

Browse files
authored
Simplify RTA iframe loading in Firefox (#10315)
Removed FF-specific workaround for initializing the RTA iframe element, and added an empty src string to explicitly opt-out of the GWT workaround they added. Fixes #10292 Backport #10306
1 parent 186ab73 commit d6abfe4

2 files changed

Lines changed: 32 additions & 53 deletions

File tree

user/src/com/google/gwt/user/client/ui/impl/RichTextAreaImplMozilla.java

Lines changed: 9 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@
1515
*/
1616
package com.google.gwt.user.client.ui.impl;
1717

18+
import com.google.gwt.dom.client.Element;
19+
1820
/**
1921
* Mozilla-specific implementation of rich-text editing.
2022
*/
@@ -32,43 +34,13 @@ public String getBackColor() {
3234
}
3335

3436
@Override
35-
@SuppressWarnings("deprecation")
36-
public native void initElement() /*-{
37-
// Mozilla doesn't allow designMode to be set reliably until the iframe is
38-
// fully loaded.
39-
var _this = this;
40-
var iframe = _this.@com.google.gwt.user.client.ui.impl.RichTextAreaImpl::elem;
41-
_this.@com.google.gwt.user.client.ui.impl.RichTextAreaImplStandard::onElementInitializing()();
42-
_this.@com.google.gwt.user.client.ui.impl.RichTextAreaImplMozilla::isFirstFocus = true;
43-
44-
iframe.onload = $entry(function() {
45-
// Some Mozillae have the nasty habit of calling onload again when you set
46-
// designMode, so let's avoid doing it more than once.
47-
iframe.onload = null;
48-
49-
// Don't set designMode until the RTA is targeted by an event. This is
50-
// necessary because editing won't work on Mozilla if the iframe is
51-
// *hidden, but attached*. Waiting for an event gets around this issue.
52-
//
53-
// Note: These events will not conflict with the
54-
// addEventListener('oneventtype', ...) in RichTextAreaImplStandard.
55-
iframe.contentWindow.onfocus = function() {
56-
iframe.contentWindow.onfocus = null;
57-
iframe.contentWindow.onmouseover = null;
58-
iframe.contentWindow.document.designMode = 'On';
59-
};
60-
61-
// Issue 1441: we also need to catch the onmouseover event because focus
62-
// occurs after mouse down, so the cursor will not appear until the user
63-
// clicks twice, making the RichTextArea look uneditable. Catching the
64-
// mouseover event allows us to set design mode earlier. The focus event
65-
// is still needed to handle tab selection.
66-
iframe.contentWindow.onmouseover = iframe.contentWindow.onfocus;
67-
68-
// Send notification that the iframe has finished loading.
69-
_this.@com.google.gwt.user.client.ui.impl.RichTextAreaImplStandard::onElementInitialized()();
70-
});
71-
}-*/;
37+
public Element createElement() {
38+
Element element = super.createElement();
39+
// Explicitly set empty src string to signal that we don't need the workaround from Firefox.
40+
// See https://github.com/gwtproject/gwt/issues/10292
41+
element.setAttribute("src", "");
42+
return element;
43+
}
7244

7345
@Override
7446
public void setBackColor(String color) {

user/test/com/google/gwt/user/client/ui/RichTextAreaTest.java

Lines changed: 23 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,6 @@
2525
import com.google.gwt.event.dom.client.FocusHandler;
2626
import com.google.gwt.event.logical.shared.InitializeEvent;
2727
import com.google.gwt.event.logical.shared.InitializeHandler;
28-
import com.google.gwt.junit.DoNotRunWith;
29-
import com.google.gwt.junit.Platform;
3028
import com.google.gwt.junit.client.GWTTestCase;
3129
import com.google.gwt.safehtml.shared.SafeHtmlUtils;
3230
import com.google.gwt.user.client.Event;
@@ -49,12 +47,16 @@ public String getModuleName() {
4947
return "com.google.gwt.user.User";
5048
}
5149

50+
@Override
51+
protected void gwtTearDown() throws Exception {
52+
RootPanel.get().clear();
53+
}
54+
5255
/**
5356
* Test that removing and re-adding an RTA doesn't destroy its contents (Only
5457
* IE actually preserves dynamically-created iframe contents across DOM
5558
* removal/re-adding).
5659
*/
57-
@DoNotRunWith(Platform.HtmlUnitUnknown)
5860
public void testAddEditRemoveAdd() {
5961
final RichTextArea area = new RichTextArea();
6062
delayTestFinish(RICH_TEXT_ASYNC_DELAY);
@@ -126,6 +128,23 @@ public void testAddRemoveBeforeInit() {
126128
final RichTextArea richTextArea = new RichTextArea();
127129
RootPanel.get().add(richTextArea);
128130
RootPanel.get().remove(richTextArea);
131+
132+
// Delay 100ms and confirm that initialization has not fired
133+
boolean[] initFired = {false};
134+
richTextArea.addInitializeHandler(new InitializeHandler() {
135+
@Override
136+
public void onInitialize(InitializeEvent event) {
137+
initFired[0] = true;
138+
}
139+
});
140+
new Timer() {
141+
@Override
142+
public void run() {
143+
assertFalse(initFired[0]);
144+
finishTest();
145+
}
146+
}.schedule(100);
147+
delayTestFinish(RICH_TEXT_ASYNC_DELAY);
129148
}
130149

131150
public void testFormatAfterAttach() {
@@ -148,7 +167,6 @@ public void testFormatAfterAttach() {
148167
}
149168
}
150169

151-
@DoNotRunWith(Platform.HtmlUnitUnknown)
152170
public void testFormatAfterInitialize() {
153171
final RichTextArea area = new RichTextArea();
154172

@@ -186,7 +204,6 @@ public void testFormatBeforeAttach() {
186204
}
187205
}
188206

189-
@DoNotRunWith(Platform.HtmlUnitUnknown)
190207
public void testFormatWhenHidden() {
191208
final RichTextArea area = new RichTextArea();
192209
delayTestFinish(RICH_TEXT_ASYNC_DELAY);
@@ -209,7 +226,6 @@ public void onInitialize(InitializeEvent event) {
209226
/**
210227
* See that the custom InitializeEvent fires.
211228
*/
212-
@DoNotRunWith({Platform.HtmlUnitUnknown})
213229
public void testRichTextInitializeEvent() {
214230
delayTestFinish(RICH_TEXT_ASYNC_DELAY);
215231
final RichTextArea richTextArea = new RichTextArea();
@@ -225,7 +241,6 @@ public void onInitialize(InitializeEvent event) {
225241
/**
226242
* Test that a delayed call to setEnable is reflected.
227243
*/
228-
@DoNotRunWith(Platform.HtmlUnitUnknown)
229244
public void testSetEnabledAfterInit() {
230245
final RichTextArea richTextArea = new RichTextArea();
231246
delayTestFinish(RICH_TEXT_ASYNC_DELAY);
@@ -246,7 +261,6 @@ public void onInitialize(InitializeEvent event) {
246261
* Test that a call to setEnable is reflected immediately, and after the area
247262
* loads.
248263
*/
249-
@DoNotRunWith(Platform.HtmlUnitUnknown)
250264
public void testSetEnabledBeforeInit() {
251265
final RichTextArea richTextArea = new RichTextArea();
252266
richTextArea.setEnabled(false);
@@ -266,7 +280,6 @@ public void onInitialize(InitializeEvent event) {
266280
/**
267281
* Test that events are dispatched correctly to handlers.
268282
*/
269-
@DoNotRunWith(Platform.HtmlUnitUnknown)
270283
public void testEventDispatch() {
271284
final RichTextArea rta = new RichTextArea();
272285
RootPanel.get().add(rta);
@@ -300,9 +313,8 @@ public void run() {
300313
* Test that a delayed set of HTML is reflected. Some platforms have timing
301314
* subtleties that need to be tested.
302315
*/
303-
@DoNotRunWith(Platform.HtmlUnitUnknown)
304316
public void testSetHTMLAfterInit() {
305-
final RichTextArea richTextArea = new RichTextArea();
317+
final RichTextArea richTextArea = new RichTextArea();
306318
delayTestFinish(RICH_TEXT_ASYNC_DELAY);
307319
richTextArea.addInitializeHandler(new InitializeHandler() {
308320
@Override
@@ -319,7 +331,6 @@ public void onInitialize(InitializeEvent event) {
319331
* Test that an immediate set of HTML is reflected immediately and after the
320332
* area loads. Some platforms have timing subtleties that need to be tested.
321333
*/
322-
@DoNotRunWith(Platform.HtmlUnitUnknown)
323334
public void testSetHTMLBeforeInit() {
324335
final RichTextArea richTextArea = new RichTextArea();
325336
delayTestFinish(RICH_TEXT_ASYNC_DELAY);
@@ -344,7 +355,6 @@ public void run() {
344355
* Test that a delayed set of safe html is reflected. Some platforms have
345356
* timing subtleties that need to be tested.
346357
*/
347-
@DoNotRunWith(Platform.HtmlUnitUnknown)
348358
public void testSetSafeHtmlAfterInit() {
349359
final RichTextArea richTextArea = new RichTextArea();
350360
delayTestFinish(RICH_TEXT_ASYNC_DELAY);
@@ -364,7 +374,6 @@ public void onInitialize(InitializeEvent event) {
364374
* the area loads. Some platforms have timing subtleties that need to be
365375
* tested.
366376
*/
367-
@DoNotRunWith(Platform.HtmlUnitUnknown)
368377
public void testSetSafeHtmlBeforeInit() {
369378
final RichTextArea richTextArea = new RichTextArea();
370379
delayTestFinish(RICH_TEXT_ASYNC_DELAY);
@@ -389,7 +398,6 @@ public void run() {
389398
* Test that delayed set of text is reflected. Some platforms have timing
390399
* subtleties that need to be tested.
391400
*/
392-
@DoNotRunWith(Platform.HtmlUnitUnknown)
393401
public void testSetTextAfterInit() {
394402
final RichTextArea richTextArea = new RichTextArea();
395403
delayTestFinish(RICH_TEXT_ASYNC_DELAY);
@@ -408,7 +416,6 @@ public void onInitialize(InitializeEvent event) {
408416
* Test that an immediate set of text is reflected immediately and after the
409417
* area loads. Some platforms have timing subtleties that need to be tested.
410418
*/
411-
@DoNotRunWith(Platform.HtmlUnitUnknown)
412419
public void testSetTextBeforeInit() {
413420
final RichTextArea richTextArea = new RichTextArea();
414421
richTextArea.setText("foo");

0 commit comments

Comments
 (0)