Revision: 10204
Author: fre...@google.com
Date: Mon May 23 11:13:45 2011
Log: - Modify the default HTML template to indicate that quirks mode
is not supported
- Cleanup UserAgentGenerator.java, for consistency with
DocumentModeGenerator.java
- Add two new configuration properties:
1. document.compatMode, to enumerate the permitted values
{'CSS1Compat', 'BackCompat'} for
$doc.compatMode, by default:
<set-configuration-property name="document.compatMode" value="CSS1Compat"/>
2. document.compatMode.severity, to control the runtime check: IGNORE (no
check), WARN (Development
Mode warning only), ERROR (runtime error). Current default:
<!-- The default value will be changed to 'ERROR' in a future release -->
<set-configuration-property name="document.compatMode.severity"
value="WARN" />
Fixes issues: 6086, 6306
Review at http://gwt-code-reviews.appspot.com/1422816
Review by: jlaba...@google.com
http://code.google.com/p/google-web-toolkit/source/detail?r=10204
Added:
/trunk/user/src/com/google/gwt/user/DocumentMode.gwt.xml
/trunk/user/src/com/google/gwt/user/client/DocumentModeAsserter.java
/trunk/user/src/com/google/gwt/user/rebind/DocumentModeGenerator.java
Modified:
/trunk/user/src/com/google/gwt/user/User.gwt.xml
/trunk/user/src/com/google/gwt/user/rebind/UserAgentGenerator.java
/trunk/user/src/com/google/gwt/user/tools/templates/sample/_warFolder_/_moduleShortName_.htmlsrc
=======================================
--- /dev/null
+++ /trunk/user/src/com/google/gwt/user/DocumentMode.gwt.xml Mon May 23
11:13:45 2011
@@ -0,0 +1,53 @@
+<!--
-->
+<!-- Copyright 2011 Google
Inc. -->
+<!-- Licensed under the Apache License, Version 2.0 (the "License");
you -->
+<!-- may not use this file except in compliance with the License. You
may -->
+<!-- may obtain a copy of the License
at -->
+<!--
-->
+<!--
http://www.apache.org/licenses/LICENSE-2.0 -->
+<!--
-->
+<!-- Unless required by applicable law or agreed to in writing,
software -->
+<!-- distributed under the License is distributed on an "AS IS"
BASIS, -->
+<!-- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
or -->
+<!-- implied. License for the specific language governing permissions
and -->
+<!-- limitations under the
License. -->
+
+<!-- Defines the user.agent property and its provider
function. -->
+<!--
-->
+<!-- This module is typically inherited via
com.google.gwt.user.User -->
+<!--
-->
+<module>
+
+ <!--
+ Enumerate one or more valid browser rendering modes, to be compared
with
+ the runtime value of $doc.compatMode
+ - Specify 'CSS1Compat' for Standards Mode
+ - Specify 'BackCompat' for Quirks Mode
+
+ See http://en.wikipedia.org/wiki/Quirks_mode
+ -->
+ <define-configuration-property name="document.compatMode"
+ is-multi-valued="true" />
+ <!-- GWT only supports Standards Mode; Quirks Mode is deprecated -->
+ <set-configuration-property name="document.compatMode"
value="CSS1Compat"/>
+
+ <!--
+ Determine the severity of the runtime $doc.compatMode check:
+ - Specify 'ERROR' to receive an error message at runtime
+ - Specify 'WARN' to receive a warning in Development Mode
+ - Specify 'IGNORE' for no runtime check
+ -->
+ <define-configuration-property name="document.compatMode.severity"
+ is-multi-valued="false" />
+ <!-- The default value will be changed to 'ERROR' in a future release -->
+ <set-configuration-property name="document.compatMode.severity"
+ value="WARN" />
+
+ <!-- Asserts a valid browser rendering mode at runtime -->
+ <entry-point class="com.google.gwt.user.client.DocumentModeAsserter" />
+
+ <generate-with class="com.google.gwt.user.rebind.DocumentModeGenerator">
+ <when-type-assignable
class="com.google.gwt.user.client.DocumentModeAsserter.DocumentModeProperty"
/>
+ </generate-with>
+
+</module>
=======================================
--- /dev/null
+++ /trunk/user/src/com/google/gwt/user/client/DocumentModeAsserter.java
Mon May 23 11:13:45 2011
@@ -0,0 +1,137 @@
+/*
+ * Copyright 2011 Google Inc.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License"); you may
not
+ * use this file except in compliance with the License. You may obtain a
copy of
+ * the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+ * License for the specific language governing permissions and limitations
under
+ * the License.
+ */
+
+package com.google.gwt.user.client;
+
+import com.google.gwt.core.client.EntryPoint;
+import com.google.gwt.core.client.GWT;
+import com.google.gwt.dom.client.Document;
+
+/**
+ * Helper class, which, during startup, asserts that the browser's current
+ * rendering mode is one of the values allowed by the
+ * {@value #PROPERTY_DOCUMENT_COMPATMODE}.
+ *
+ * @see <a href="http://en.wikipedia.org/wiki/Quirks_mode">Quirks Mode</a>
+ */
+public class DocumentModeAsserter implements EntryPoint {
+
+ /**
+ * Interface to provide {@value #PROPERTY_DOCUMENT_COMPATMODE}
configuration
+ * property value.
+ */
+ public interface DocumentModeProperty {
+ String[] getAllowedDocumentModes();
+
+ Severity getDocumentModeSeverity();
+ }
+
+ /**
+ * Determine the severity of the runtime {@literal $doc.compatMode}
check:
+ */
+ public static enum Severity {
+ /**
+ * Receive an error message at runtime.
+ */
+ ERROR,
+
+ /**
+ * No runtime check.
+ */
+ IGNORE,
+
+ /**
+ * Receive a warning in Development Mode.
+ */
+ WARN;
+ }
+
+ /**
+ * GWT module configuration property, which enumerates one or more valid
+ * browser rendering modes, to be compared with value of
+ * {@literal $doc.compatMode} at runtime.
+ */
+ public static final String PROPERTY_DOCUMENT_COMPATMODE
= "document.compatMode";
+
+ /**
+ * GWT module configuration property, which determines the severity of
the
+ * runtime {@literal $doc.compatMode} check. Valid values are specified
by
+ * {@link Severity}.
+ */
+ public static final String PROPERTY_DOCUMENT_COMPATMODE_SEVERITY
= "document.compatMode.severity";
+
+ /**
+ * Value of {@literal $doc.compatMode} in Quirks Mode, {@value}.
+ */
+ private static final String QUIRKS_MODE_BACK_COMPAT = "BackCompat";
+
+ /**
+ * Value of {@literal $doc.compatMode} in Standards Mode, {@value}.
+ */
+ private static final String STANDARDS_MODE_CSS1_COMPAT = "CSS1Compat";
+
+ @Override
+ public void onModuleLoad() {
+ DocumentModeProperty impl = GWT.create(DocumentModeProperty.class);
+ Severity severity = impl.getDocumentModeSeverity();
+ if (severity == Severity.IGNORE) {
+ return;
+ }
+
+ String currentMode = Document.get().getCompatMode();
+ String[] allowedModes = impl.getAllowedDocumentModes();
+ for (int i = 0; i < allowedModes.length; i++) {
+ if (allowedModes[i].equals(currentMode)) {
+ return;
+ }
+ }
+
+ String message;
+ if (allowedModes.length == 1 &&
STANDARDS_MODE_CSS1_COMPAT.equals(allowedModes[0])
+ && QUIRKS_MODE_BACK_COMPAT.equals(currentMode)) {
+ /*
+ * GWT no longer supports Quirks Mode.
+ */
+ message = "GWT no longer supports Quirks Mode
(document.compatMode=' "
+ + QUIRKS_MODE_BACK_COMPAT
+ + "').<br>Make sure your application's host HTML page has a
Standards Mode "
+ + "(document.compatMode=' "
+ + STANDARDS_MODE_CSS1_COMPAT
+ + "') doctype,<br>e.g. by using <!doctype html> at the
start of your application's HTML "
+ + "page.<br><br>To continue using this unsupported rendering
mode and risk layout problems, "
+ + "suppress this message by adding<br>the following line to
your*.gwt.xml module file:<br>"
+ + " <extend-configuration-property
name=\"document.compatMode\" value=\""
+ + currentMode + "\"/>";
+ } else {
+ /*
+ * Developer is doing something custom and have modified the default
+ * document.compatMode configuration property settings from
+ * DocumentMode.gwt.xml, so they're mostly on their own.
+ */
+ message = "Your *.gwt.xml module configuration prohibits the use of
the current doucment "
+ + "rendering mode (document.compatMode=' " + currentMode
+ + "').<br>Modify your application's host HTML page doctype, or
update your custom "
+ + "'document.compatMode' configuration property settings.";
+ }
+
+ if (severity == Severity.ERROR) {
+ throw new RuntimeException(message);
+ }
+
+ // Warning compiled out in Production Mode
+ GWT.log(message);
+ }
+}
=======================================
--- /dev/null
+++ /trunk/user/src/com/google/gwt/user/rebind/DocumentModeGenerator.java
Mon May 23 11:13:45 2011
@@ -0,0 +1,129 @@
+/*
+ * Copyright 2011 Google Inc.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License"); you may
not
+ * use this file except in compliance with the License. You may obtain a
copy of
+ * the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+ * License for the specific language governing permissions and limitations
under
+ * the License.
+ */
+
+package com.google.gwt.user.rebind;
+
+import com.google.gwt.core.ext.BadPropertyValueException;
+import com.google.gwt.core.ext.ConfigurationProperty;
+import com.google.gwt.core.ext.Generator;
+import com.google.gwt.core.ext.GeneratorContext;
+import com.google.gwt.core.ext.PropertyOracle;
+import com.google.gwt.core.ext.TreeLogger;
+import com.google.gwt.core.ext.UnableToCompleteException;
+import com.google.gwt.core.ext.typeinfo.JClassType;
+import com.google.gwt.core.ext.typeinfo.NotFoundException;
+import com.google.gwt.core.ext.typeinfo.TypeOracle;
+import com.google.gwt.user.client.DocumentModeAsserter;
+import com.google.gwt.user.client.DocumentModeAsserter.Severity;
+
+import java.io.PrintWriter;
+import java.util.Arrays;
+import java.util.List;
+
+/**
+ * Generator for {@link com.google.gwt.user.client.DocumentModeAsserter}.
+ */
+public class DocumentModeGenerator extends Generator {
+
+ @Override
+ public String generate(TreeLogger logger, GeneratorContext context,
String typeName)
+ throws UnableToCompleteException {
+ TypeOracle typeOracle = context.getTypeOracle();
+
+ JClassType userType;
+ try {
+ userType = typeOracle.getType(typeName);
+ } catch (NotFoundException e) {
+ logger.log(TreeLogger.ERROR, "Unable to find metadata for type: " +
typeName, e);
+ throw new UnableToCompleteException();
+ }
+ String packageName = userType.getPackage().getName();
+ String className = userType.getName();
+ className = className.replace('.', '_');
+
+ if (userType.isInterface() == null) {
+ logger.log(TreeLogger.ERROR, userType.getQualifiedSourceName() + "
is not an interface", null);
+ throw new UnableToCompleteException();
+ }
+
+ PropertyOracle propertyOracle = context.getPropertyOracle();
+
+ String severityText;
+ try {
+ ConfigurationProperty property =
propertyOracle.getConfigurationProperty(DocumentModeAsserter.PROPERTY_DOCUMENT_COMPATMODE_SEVERITY);
+ severityText = property.getValues().get(0);
+ } catch (BadPropertyValueException e) {
+ logger.log(TreeLogger.ERROR, "Unable to find value for '"
+ + DocumentModeAsserter.PROPERTY_DOCUMENT_COMPATMODE_SEVERITY
+ "'", e);
+ throw new UnableToCompleteException();
+ }
+ Severity severity;
+ try {
+ severity = Severity.valueOf(severityText);
+ } catch (IllegalArgumentException e) {
+ logger.log(TreeLogger.ERROR, "Value '" + severityText + "' for '"
+ + DocumentModeAsserter.PROPERTY_DOCUMENT_COMPATMODE_SEVERITY
+ "' is not one of: "
+ + Arrays.toString(Severity.values()), e);
+ throw new UnableToCompleteException();
+ }
+
+ List<String> documentModes;
+ try {
+ ConfigurationProperty property =
propertyOracle.getConfigurationProperty(DocumentModeAsserter.PROPERTY_DOCUMENT_COMPATMODE);
+ documentModes = property.getValues();
+ } catch (BadPropertyValueException e) {
+ logger.log(TreeLogger.ERROR, "Unable to find value for '"
+ + DocumentModeAsserter.PROPERTY_DOCUMENT_COMPATMODE + "'", e);
+ throw new UnableToCompleteException();
+ }
+
+ ClassSourceFileComposerFactory composerFactory = new
ClassSourceFileComposerFactory(
+ packageName, className);
+
composerFactory.addImplementedInterface(userType.getQualifiedSourceName());
+
composerFactory.addImport(DocumentModeAsserter.Severity.class.getCanonicalName());
+
+ PrintWriter pw = context.tryCreate(logger, packageName, className);
+ if (pw != null) {
+ SourceWriter sw = composerFactory.createSourceWriter(context, pw);
+
+ sw.println();
+
+ sw.println("public String[] getAllowedDocumentModes() {");
+ sw.indent();
+ sw.println("return new String[] {");
+ sw.indent();
+ for (String mode : documentModes) {
+ sw.println("\"" + mode + "\", ");
+ }
+ sw.outdent();
+ sw.println("};");
+ sw.outdent();
+ sw.println("}");
+
+ sw.println();
+
+ sw.println("public Severity getDocumentModeSeverity() {");
+ sw.indent();
+ sw.println("return Severity." + severity.toString() + ";");
+ sw.outdent();
+ sw.println("}");
+ sw.println();
+
+ sw.commit(logger);
+ }
+ return composerFactory.getCreatedClassName();
+ }
+}
=======================================
--- /trunk/user/src/com/google/gwt/user/User.gwt.xml Tue Apr 26 05:06:08
2011
+++ /trunk/user/src/com/google/gwt/user/User.gwt.xml Mon May 23 11:13:45
2011
@@ -38,6 +38,7 @@
<inherits name="com.google.gwt.user.cellview.CellView"/>
<inherits name="com.google.gwt.user.ClippedImage"/>
<inherits name="com.google.gwt.user.datepicker.DatePicker"/>
+ <inherits name="com.google.gwt.user.DocumentMode"/>
<inherits name="com.google.gwt.user.DocumentRoot" />
<inherits name="com.google.gwt.user.DOM"/>
<inherits name="com.google.gwt.user.FileUpload"/>
=======================================
--- /trunk/user/src/com/google/gwt/user/rebind/UserAgentGenerator.java Tue
Mar 8 09:11:26 2011
+++ /trunk/user/src/com/google/gwt/user/rebind/UserAgentGenerator.java Mon
May 23 11:13:45 2011
@@ -39,40 +39,31 @@
static final String PROPERTY_USER_AGENT_RUNTIME_WARNING
= "user.agent.runtimeWarning";
@Override
- public String generate(TreeLogger logger, GeneratorContext context,
- String typeName) throws UnableToCompleteException {
+ public String generate(TreeLogger logger, GeneratorContext context,
String typeName)
+ throws UnableToCompleteException {
TypeOracle typeOracle = context.getTypeOracle();
JClassType userType;
try {
userType = typeOracle.getType(typeName);
} catch (NotFoundException e) {
- logger.log(TreeLogger.ERROR, "OOPS", e);
+ logger.log(TreeLogger.ERROR, "Unable to find metadata for type: " +
typeName, e);
throw new UnableToCompleteException();
}
String packageName = userType.getPackage().getName();
String className = userType.getName();
className = className.replace('.', '_');
- JClassType remoteService = typeOracle.findType(typeName);
- if (remoteService == null) {
- logger.log(TreeLogger.ERROR, "Unable to find metadata for type '"
- + typeName + "'", null);
+ if (userType.isInterface() == null) {
+ logger.log(TreeLogger.ERROR, userType.getQualifiedSourceName() + "
is not an interface", null);
throw new UnableToCompleteException();
}
-
- if (remoteService.isInterface() == null) {
- logger.log(TreeLogger.ERROR, remoteService.getQualifiedSourceName()
- + " is not an interface", null);
- throw new UnableToCompleteException();
- }
PropertyOracle propertyOracle = context.getPropertyOracle();
boolean userAgentRuntimeWarning = true;
try {
- ConfigurationProperty property =
-
propertyOracle.getConfigurationProperty(PROPERTY_USER_AGENT_RUNTIME_WARNING);
+ ConfigurationProperty property =
propertyOracle.getConfigurationProperty(PROPERTY_USER_AGENT_RUNTIME_WARNING);
userAgentRuntimeWarning =
Boolean.valueOf(property.getValues().get(0));
} catch (BadPropertyValueException e) {
logger.log(TreeLogger.WARN, "Unable to find value for '"
@@ -82,12 +73,10 @@
String userAgentValue;
SelectionProperty selectionProperty;
try {
- selectionProperty = propertyOracle.getSelectionProperty(logger,
- PROPERTY_USER_AGENT);
+ selectionProperty = propertyOracle.getSelectionProperty(logger,
PROPERTY_USER_AGENT);
userAgentValue = selectionProperty.getCurrentValue();
} catch (BadPropertyValueException e) {
- logger.log(TreeLogger.ERROR, "Unable to find value for '"
- + PROPERTY_USER_AGENT + "'", e);
+ logger.log(TreeLogger.ERROR, "Unable to find value for '" +
PROPERTY_USER_AGENT + "'", e);
throw new UnableToCompleteException();
}
@@ -97,7 +86,7 @@
ClassSourceFileComposerFactory composerFactory = new
ClassSourceFileComposerFactory(
packageName, className);
-
composerFactory.addImplementedInterface(remoteService.getQualifiedSourceName());
+
composerFactory.addImplementedInterface(userType.getQualifiedSourceName());
PrintWriter pw = context.tryCreate(logger, packageName, className);
if (pw != null) {
@@ -114,7 +103,7 @@
sw.println();
sw.println("public native String getRuntimeValue() /*-{");
sw.indent();
- UserAgentPropertyGenerator.writeUserAgentPropertyJavaScript(sw,
+ UserAgentPropertyGenerator.writeUserAgentPropertyJavaScript(sw,
selectionProperty.getPossibleValues());
sw.outdent();
sw.println("}-*/;");
=======================================
---
/trunk/user/src/com/google/gwt/user/tools/templates/sample/_warFolder_/_moduleShortName_.htmlsrc
Mon Mar 7 08:21:08 2011
+++
/trunk/user/src/com/google/gwt/user/tools/templates/sample/_warFolder_/_moduleShortName_.htmlsrc
Mon May 23 11:13:45 2011
@@ -1,9 +1,8 @@
<!doctype html>
-<!-- The DOCTYPE declaration above will set the -->
-<!-- browser's rendering engine into -->
-<!-- "Standards Mode". Replacing this declaration -->
-<!-- with a "Quirks Mode" doctype may lead to some -->
-<!-- differences in layout. -->
+<!-- The DOCTYPE declaration above will set the -->
+<!-- browser's rendering engine into -->
+<!-- "Standards Mode". Replacing this declaration -->
+<!-- with a "Quirks Mode" doctype is not supported. -->
<html>
<head>
--
http://groups.google.com/group/Google-Web-Toolkit-Contributors