Removed most of the RichTextAreaImplSafari implementation used only for older versions of Safari.
Patch by: jlabanca
Review by: jgw
Issue: 2813
git-svn-id: https://google-web-toolkit.googlecode.com/svn/trunk@5639 8db76d5a-ed1c-0410-87a9-c151d255dfc7
diff --git a/user/src/com/google/gwt/user/client/ui/RichTextArea.java b/user/src/com/google/gwt/user/client/ui/RichTextArea.java
index b31780c..5264375 100644
--- a/user/src/com/google/gwt/user/client/ui/RichTextArea.java
+++ b/user/src/com/google/gwt/user/client/ui/RichTextArea.java
@@ -56,7 +56,10 @@
* focused at least once. If you just want to initialize the content of
* the {@link RichTextArea}, use {@link RichTextArea#setHTML(String)} instead.
* </p>
+ *
+ * @deprecated use {@link Formatter} instead
*/
+ @Deprecated
public interface BasicFormatter {
/**
@@ -188,7 +191,10 @@
* focused at least once. If you just want to initialize the content of
* the {@link RichTextArea}, use {@link RichTextArea#setHTML(String)} instead.
* </p>
+ *
+ * @deprecated use {@link Formatter} instead
*/
+ @Deprecated
public interface ExtendedFormatter extends BasicFormatter {
/**
@@ -271,6 +277,215 @@
}
/**
+ * <p>
+ * This interface is used to access full formatting options, when available.
+ * If the implementation supports full formatting, then
+ * {@link RichTextArea#getFormatter()} will return an instance of this
+ * class.
+ * </p>
+ * <p>
+ * The formatter will format the user selected text in the
+ * {@link RichTextArea}. As a result, it will only work reliably if the
+ * {@link RichTextArea} is attached, visible to on the page, and has been
+ * focused at least once. If you just want to initialize the content of
+ * the {@link RichTextArea}, use {@link RichTextArea#setHTML(String)} instead.
+ * </p>
+ */
+ public interface Formatter extends ExtendedFormatter {
+ /**
+ * Creates a link to the supplied URL.
+ *
+ * @param url the URL to be linked to
+ */
+ void createLink(String url);
+
+ /**
+ * Gets the background color.
+ *
+ * @return the background color
+ */
+ String getBackColor();
+
+ /**
+ * Gets the foreground color.
+ *
+ * @return the foreground color
+ */
+ String getForeColor();
+
+ /**
+ * Inserts a horizontal rule.
+ */
+ void insertHorizontalRule();
+
+ /**
+ * Inserts generic html.
+ *
+ * @param html the HTML to insert
+ */
+ void insertHTML(String html);
+
+ /**
+ * Inserts an image element.
+ *
+ * @param url the url of the image to be inserted
+ */
+ void insertImage(String url);
+
+ /**
+ * Starts an numbered list. Indentation will create nested items.
+ */
+ void insertOrderedList();
+
+ /**
+ * Starts an bulleted list. Indentation will create nested items.
+ */
+ void insertUnorderedList();
+
+ /**
+ * Is the current region bold?
+ *
+ * @return true if the current region is bold
+ */
+ boolean isBold();
+
+ /**
+ * Is the current region italic?
+ *
+ * @return true if the current region is italic
+ */
+ boolean isItalic();
+
+ /**
+ * Is the current region strikethrough?
+ *
+ * @return true if the current region is strikethrough
+ */
+ boolean isStrikethrough();
+
+ /**
+ * Is the current region subscript?
+ *
+ * @return true if the current region is subscript
+ */
+ boolean isSubscript();
+
+ /**
+ * Is the current region superscript?
+ *
+ * @return true if the current region is superscript
+ */
+ boolean isSuperscript();
+
+ /**
+ * Is the current region underlined?
+ *
+ * @return true if the current region is underlined
+ */
+ boolean isUnderlined();
+
+ /**
+ * Left indent.
+ */
+ void leftIndent();
+
+ /**
+ * Redo an action that was just undone.
+ */
+ void redo();
+
+ /**
+ * Removes all formatting on the selected text.
+ */
+ void removeFormat();
+
+ /**
+ * Removes any link from the selected text.
+ */
+ void removeLink();
+
+ /**
+ * Right indent.
+ */
+ void rightIndent();
+
+ /**
+ * Selects all the text.
+ */
+ void selectAll();
+
+ /**
+ * Sets the background color.
+ *
+ * @param color the new background color
+ */
+ void setBackColor(String color);
+
+ /**
+ * Sets the font name.
+ *
+ * @param name the new font name
+ */
+ void setFontName(String name);
+
+ /**
+ * Sets the font size.
+ *
+ * @param fontSize the new font size
+ */
+ void setFontSize(FontSize fontSize);
+
+ /**
+ * Sets the foreground color.
+ *
+ * @param color the new foreground color
+ */
+ void setForeColor(String color);
+
+ /**
+ * Sets the justification.
+ *
+ * @param justification the new justification
+ */
+ void setJustification(Justification justification);
+
+ /**
+ * Toggles bold.
+ */
+ void toggleBold();
+
+ /**
+ * Toggles italic.
+ */
+ void toggleItalic();
+
+ /**
+ * Toggles strikethrough.
+ */
+ void toggleStrikethrough();
+
+ /**
+ * Toggles subscript.
+ */
+ void toggleSubscript();
+
+ /**
+ * Toggles superscript.
+ */
+ void toggleSuperscript();
+
+ /**
+ * Toggles underline.
+ */
+ void toggleUnderline();
+
+ /**
+ * Undo the last action.
+ */
+ void undo();
+ }
+
+ /**
* Font size enumeration. Represents the seven basic HTML font sizes, as
* defined in CSS.
*/
@@ -386,12 +601,11 @@
* page, and has been focused by the user.
*
* @return <code>null</code> if basic formatting is not supported
+ * @deprecated use {@link #getFormatter()} instead
*/
+ @Deprecated
public BasicFormatter getBasicFormatter() {
- if ((impl instanceof BasicFormatter) && (impl.isBasicEditingSupported())) {
- return (BasicFormatter) impl;
- }
- return null;
+ return getFormatter();
}
/**
@@ -400,11 +614,23 @@
* page, and has been focused by the user.
*
* @return <code>null</code> if full formatting is not supported
+ * @deprecated use {@link #getFormatter()} instead
*/
+ @Deprecated
public ExtendedFormatter getExtendedFormatter() {
- if ((impl instanceof ExtendedFormatter)
- && (impl.isExtendedEditingSupported())) {
- return (ExtendedFormatter) impl;
+ return getFormatter();
+ }
+
+ /**
+ * Gets the rich text formatting interface. Note that formatting can only be
+ * done when the {@link RichTextArea} is attached, visible on the page, and
+ * has been focused by the user.
+ *
+ * @return <code>null</code> if full formatting is not supported
+ */
+ public Formatter getFormatter() {
+ if (impl instanceof Formatter) {
+ return (Formatter) impl;
}
return null;
}
diff --git a/user/src/com/google/gwt/user/client/ui/impl/RichTextAreaImpl.java b/user/src/com/google/gwt/user/client/ui/impl/RichTextAreaImpl.java
index 59c7da1..0228633 100644
--- a/user/src/com/google/gwt/user/client/ui/impl/RichTextAreaImpl.java
+++ b/user/src/com/google/gwt/user/client/ui/impl/RichTextAreaImpl.java
@@ -51,14 +51,6 @@
onElementInitialized();
}
- public boolean isBasicEditingSupported() {
- return false;
- }
-
- public boolean isExtendedEditingSupported() {
- return false;
- }
-
public native void setFocus(boolean focused) /*-{
if (focused) {
this.@com.google.gwt.user.client.ui.impl.RichTextAreaImpl::elem.focus();
diff --git a/user/src/com/google/gwt/user/client/ui/impl/RichTextAreaImplSafari.java b/user/src/com/google/gwt/user/client/ui/impl/RichTextAreaImplSafari.java
index 96d0439..7d94ad6 100644
--- a/user/src/com/google/gwt/user/client/ui/impl/RichTextAreaImplSafari.java
+++ b/user/src/com/google/gwt/user/client/ui/impl/RichTextAreaImplSafari.java
@@ -15,111 +15,16 @@
*/
package com.google.gwt.user.client.ui.impl;
-import com.google.gwt.user.client.Element;
-import com.google.gwt.user.client.ui.RichTextArea.FontSize;
-
/**
* Safari rich text platform implementation.
*/
public class RichTextAreaImplSafari extends RichTextAreaImplStandard {
- private static final String[] sizeNumberCSSValues = new String[] {
- "medium", "xx-small", "x-small", "small", "medium", "large", "x-large",
- "xx-large"};
-
- private static int webKitVersion = getWebKitVersion();
-
- /**
- * WebKit v420 began suppporting full rich text editing.
- */
- private static boolean extendedEditingSupported = (webKitVersion >= 420);
-
- /**
- * WebKit v420 changed BackColor to HiliteColor.
- */
- private static boolean useHiliteColor = (webKitVersion >= 420);
-
- /**
- * WebKit version up to *and including* 420 require CSS font-size values
- * (e.g. 'medium', 'x-large') rather than size numbers. All subsequent
- * versions use size numbers like other browsers.
- */
- private static boolean oldSchoolSizeValues = (webKitVersion <= 420);
-
- private static native int getWebKitVersion() /*-{
- var exp = / AppleWebKit\/([\d]+)/;
- var result = exp.exec(navigator.userAgent);
- if (result) {
- var version = parseInt(result[1]);
- if (version) {
- return version;
- }
- }
-
- // Intentionally conservative fallback.
- return 0;
- }-*/;;
-
- @Override
- public Element createElement() {
- return super.createElement();
- }
-
- @Override
- public native boolean isBold() /*-{
- return !!this.@com.google.gwt.user.client.ui.impl.RichTextAreaImpl::elem.__gwt_isBold;
- }-*/;
-
- @Override
- public boolean isExtendedEditingSupported() {
- return extendedEditingSupported;
- }
-
- @Override
- public native boolean isItalic() /*-{
- return !!this.@com.google.gwt.user.client.ui.impl.RichTextAreaImpl::elem.__gwt_isItalic;
- }-*/;
-
- @Override
- public native boolean isUnderlined() /*-{
- return !!this.@com.google.gwt.user.client.ui.impl.RichTextAreaImpl::elem.__gwt_isUnderlined;
- }-*/;
-
@Override
public void setBackColor(String color) {
- if (useHiliteColor) {
- execCommand("HiliteColor", color);
- } else {
- super.setBackColor(color);
- }
- }
-
- @Override
- public native void setFocus(boolean focused) /*-{
- // Safari needs the *iframe* focused, not its window.
- var elem = this.@com.google.gwt.user.client.ui.impl.RichTextAreaImpl::elem;
- if (focused) {
- elem.focus();
- if (elem.__gwt_restoreSelection) {
- elem.__gwt_restoreSelection();
- }
- } else {
- elem.blur();
- }
- }-*/;
-
- @Override
- public void setFontSize(FontSize fontSize) {
- if (oldSchoolSizeValues) {
- // Safari2 only accepts css-style 'small, medium, large, etc' values.
- // Setting these doesn't seem to hurt Safari3.
- int number = fontSize.getNumber();
- if ((number >= 0) && (number <= 7)) {
- execCommand("FontSize", sizeNumberCSSValues[number]);
- }
- } else {
- super.setFontSize(fontSize);
- }
+ // Webkit uses 'BackColor' for the *entire area's* background. 'HiliteColor'
+ // does what we actually want.
+ execCommand("HiliteColor", color);
}
@Override
@@ -131,41 +36,8 @@
protected native void hookEvents() /*-{
var elem = this.@com.google.gwt.user.client.ui.impl.RichTextAreaImpl::elem;
var wnd = elem.contentWindow;
- var doc = wnd.document;
- // Create an expando on the element to hold the selection state.
- elem.__gwt_selection = { baseOffset:0, extentOffset:0, baseNode:null,
- extentNode:null };
-
- // A function for restoring the selection state.
- elem.__gwt_restoreSelection = function() {
- var sel = elem.__gwt_selection;
-
- // wnd.getSelection is not defined if the iframe isn't attached.
- if (wnd.getSelection) {
- wnd.getSelection().setBaseAndExtent(sel.baseNode, sel.baseOffset,
- sel.extentNode, sel.extentOffset);
- }
- };
-
- // Generic event dispatcher. Also stores selection state.
elem.__gwt_handler = function(evt) {
- // Store the editor's selection state.
- var s = wnd.getSelection();
- elem.__gwt_selection = {
- baseOffset:s.baseOffset,
- extentOffset:s.extentOffset,
-
- baseNode:s.baseNode,
- extentNode:s.extentNode
- };
-
- // Hang on to bold/italic/underlined states.
- elem.__gwt_isBold = doc.queryCommandState('Bold');
- elem.__gwt_isItalic = doc.queryCommandState('Italic');
- elem.__gwt_isUnderlined = doc.queryCommandState('Underline');
-
- // Dispatch the event.
if (elem.__listener) {
elem.__listener.@com.google.gwt.user.client.ui.Widget::onBrowserEvent(Lcom/google/gwt/user/client/Event;)(evt);
}
@@ -218,7 +90,6 @@
wnd.removeEventListener('mouseout', elem.__gwt_handler, true);
wnd.removeEventListener('click', elem.__gwt_handler, true);
- elem.__gwt_restoreSelection = null;
elem.__gwt_handler = null;
elem.onfocus = null;
diff --git a/user/src/com/google/gwt/user/client/ui/impl/RichTextAreaImplStandard.java b/user/src/com/google/gwt/user/client/ui/impl/RichTextAreaImplStandard.java
index 1dd081a..d4e99d1 100644
--- a/user/src/com/google/gwt/user/client/ui/impl/RichTextAreaImplStandard.java
+++ b/user/src/com/google/gwt/user/client/ui/impl/RichTextAreaImplStandard.java
@@ -25,8 +25,10 @@
/**
* Basic rich text platform implementation.
*/
+@SuppressWarnings("deprecation")
public abstract class RichTextAreaImplStandard extends RichTextAreaImpl implements
- RichTextArea.BasicFormatter, RichTextArea.ExtendedFormatter {
+ RichTextArea.BasicFormatter, RichTextArea.ExtendedFormatter,
+ RichTextArea.Formatter {
/**
* The message displayed when the formatter is used before the RichTextArea
@@ -117,20 +119,10 @@
execCommand("InsertUnorderedList", null);
}
- @Override
- public boolean isBasicEditingSupported() {
- return true;
- }
-
public boolean isBold() {
return queryCommandState("Bold");
}
- @Override
- public boolean isExtendedEditingSupported() {
- return true;
- }
-
public boolean isItalic() {
return queryCommandState("Italic");
}