org.xwiki.gwt.wysiwyg.client.plugin.line
Class LinePlugin

java.lang.Object
  extended by org.xwiki.gwt.wysiwyg.client.plugin.internal.AbstractPlugin
      extended by org.xwiki.gwt.wysiwyg.client.plugin.line.LinePlugin
All Implemented Interfaces:
com.google.gwt.event.dom.client.KeyDownHandler, com.google.gwt.event.dom.client.KeyPressHandler, com.google.gwt.event.dom.client.KeyUpHandler, com.google.gwt.event.shared.EventHandler, CommandListener, Plugin
Direct Known Subclasses:
IELinePlugin, MozillaLinePlugin

public class LinePlugin
extends org.xwiki.gwt.wysiwyg.client.plugin.internal.AbstractPlugin
implements com.google.gwt.event.dom.client.KeyDownHandler, com.google.gwt.event.dom.client.KeyUpHandler, com.google.gwt.event.dom.client.KeyPressHandler, CommandListener

Overwrites the behavior of creating new lines of text and merging existing ones.

Version:
$Id: LinePlugin.java 26786 2010-02-07 16:46:17Z mflorea $

Field Summary
static java.lang.String BR
          The name of the <br/> tag.
static java.lang.String CLASS_NAME
          The class name attribute.
protected  DOMUtils domUtils
          Collection of DOM utility methods.
static java.lang.String LI
          The name of the <li> tag.
static java.lang.String LINE_BREAK
          The CSS class name associated with BRs that are present in the rich text area's HTML input and which have to be kept even when they are placed at the end of a block-level element.
static Command RESET
          The command that notifies us when the content of the rich text area has been reset.
static java.lang.String SPACER
          The CSS class name associated with BRs added at edit time to make items like empty block-level elements editable.
static Command SUBMIT
          The command that stores the value of the rich text area in an HTML form field.
static java.lang.String TD
          The name of the <td> tag.
static java.lang.String TH
          The name of the <th> tag.
 
Constructor Summary
LinePlugin()
           
 
Method Summary
protected  void adjustLineBreak(com.google.gwt.dom.client.Node container, com.google.gwt.dom.client.Node br)
          Adjusts the line break position so that: Anchors don't start or end with a line break.
protected  void copyLineStyle(Element sourceLine, Element destinationLine)
          Copy some of the CSS styles from the source line to the destination line.
 void destroy()
          Notifies the plug-in to release its resources before being unloaded from the WYSIWYG editor.
protected  void handleRepeatableKey(Event event)
          Handles a repeatable key press.
 void init(RichTextArea textArea, Config config)
          Initialize the plug-in.
protected  void insertEmptyLine(com.google.gwt.dom.client.Node container, Range caret)
          Inserts an empty line before the block containing the caret.
protected  void insertLineBreak(com.google.gwt.dom.client.Node container, Range caret)
          Inserts a line break at the specified position in the document.
protected  boolean isAfterLineBreak(com.google.gwt.dom.client.Node container, Range caret)
           
protected  boolean isAtStart(com.google.gwt.dom.client.Node container, Range caret)
           
protected  boolean isEmptyLine(com.google.gwt.dom.client.Node node)
           
protected  boolean isLineBreak(com.google.gwt.dom.client.Node node)
           
protected  void markInitialLineBreaks()
          Marks the initial line breaks so they are not mistaken as SPACER.
protected  void markSpacers()
          Marks the BRs that have been added as spacers during the editing.
protected  boolean needsSpace(com.google.gwt.dom.client.Node leaf)
           
protected  void onBackspace(Event event)
          Overwrites the default rich text area behavior when the Backspace key is being pressed.
 boolean onBeforeCommand(CommandManager sender, Command command, java.lang.String param)
          
 void onCommand(CommandManager sender, Command command, java.lang.String param)
          
protected  void onEnter(Event event)
          Overwrites the default rich text area behavior when the Enter key is being pressed.
protected  void onEnterParagraph(com.google.gwt.dom.client.Node container, Range caret, Event event)
          Behaves as if the caret is inside a paragraph.
 void onKeyDown(com.google.gwt.event.dom.client.KeyDownEvent event)
          
 void onKeyPress(com.google.gwt.event.dom.client.KeyPressEvent event)
          
 void onKeyUp(com.google.gwt.event.dom.client.KeyUpEvent event)
          
protected  void onReset()
          Called after the content of the rich text area has been reset.
protected  void replaceEmptyLinesWithParagraphs()
          Replaces <div class="wikimodel-emptyline"/> with <p/>.
protected  void splitLine(com.google.gwt.dom.client.Node container, Range caret)
          Splits a line after a line break.
protected  void unMarkSpacers()
           
 
Methods inherited from class org.xwiki.gwt.wysiwyg.client.plugin.internal.AbstractPlugin
getConfig, getTextArea, getUIExtensionList, getUIExtensions, saveRegistration, saveRegistrations
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

SUBMIT

public static final Command SUBMIT
The command that stores the value of the rich text area in an HTML form field.


RESET

public static final Command RESET
The command that notifies us when the content of the rich text area has been reset.


SPACER

public static final java.lang.String SPACER
The CSS class name associated with BRs added at edit time to make items like empty block-level elements editable.

See Also:
Constant Field Values

LINE_BREAK

public static final java.lang.String LINE_BREAK
The CSS class name associated with BRs that are present in the rich text area's HTML input and which have to be kept even when they are placed at the end of a block-level element. We need to mark this initial BRs so they are not mistaken with the SPACER BRs we add during the editing.

See Also:
Constant Field Values

CLASS_NAME

public static final java.lang.String CLASS_NAME
The class name attribute.

See Also:
Constant Field Values

BR

public static final java.lang.String BR
The name of the <br/> tag.

See Also:
Constant Field Values

LI

public static final java.lang.String LI
The name of the <li> tag.

See Also:
Constant Field Values

TD

public static final java.lang.String TD
The name of the <td> tag.

See Also:
Constant Field Values

TH

public static final java.lang.String TH
The name of the <th> tag.

See Also:
Constant Field Values

domUtils

protected final DOMUtils domUtils
Collection of DOM utility methods.

Constructor Detail

LinePlugin

public LinePlugin()
Method Detail

init

public void init(RichTextArea textArea,
                 Config config)
Initialize the plug-in. Plug-ins need to know the text area in order to provide only those feature that are supported.

Specified by:
init in interface Plugin
Overrides:
init in class org.xwiki.gwt.wysiwyg.client.plugin.internal.AbstractPlugin
Parameters:
textArea - the text area of the editor
config - the configuration object
See Also:
AbstractPlugin.init(RichTextArea, Config)

destroy

public void destroy()
Notifies the plug-in to release its resources before being unloaded from the WYSIWYG editor.

Specified by:
destroy in interface Plugin
Overrides:
destroy in class org.xwiki.gwt.wysiwyg.client.plugin.internal.AbstractPlugin
See Also:
AbstractPlugin.destroy()

onKeyDown

public void onKeyDown(com.google.gwt.event.dom.client.KeyDownEvent event)

Specified by:
onKeyDown in interface com.google.gwt.event.dom.client.KeyDownHandler
See Also:
KeyDownHandler.onKeyDown(KeyDownEvent)

onKeyPress

public void onKeyPress(com.google.gwt.event.dom.client.KeyPressEvent event)

Specified by:
onKeyPress in interface com.google.gwt.event.dom.client.KeyPressHandler
See Also:
KeyPressHandler.onKeyPress(KeyPressEvent)

onKeyUp

public void onKeyUp(com.google.gwt.event.dom.client.KeyUpEvent event)

Specified by:
onKeyUp in interface com.google.gwt.event.dom.client.KeyUpHandler
See Also:
KeyUpHandler.onKeyUp(KeyUpEvent)

handleRepeatableKey

protected void handleRepeatableKey(Event event)
Handles a repeatable key press.

Parameters:
event - the native event that was fired

onBeforeCommand

public boolean onBeforeCommand(CommandManager sender,
                               Command command,
                               java.lang.String param)

Specified by:
onBeforeCommand in interface CommandListener
See Also:
CommandListener.onBeforeCommand(CommandManager, Command, String)

onCommand

public void onCommand(CommandManager sender,
                      Command command,
                      java.lang.String param)

Specified by:
onCommand in interface CommandListener
See Also:
CommandListener.onCommand(CommandManager, Command, String)

markSpacers

protected void markSpacers()
Marks the BRs that have been added as spacers during the editing. These BRs were added to overcome a Mozilla bug that prevents us from typing inside an empty block level element.


unMarkSpacers

protected void unMarkSpacers()
See Also:
markSpacers()

needsSpace

protected boolean needsSpace(com.google.gwt.dom.client.Node leaf)
Parameters:
leaf - a DOM node which has not children
Returns:
true if the given leaf needs space on the screen in order to be rendered, false otherwise

markInitialLineBreaks

protected void markInitialLineBreaks()
Marks the initial line breaks so they are not mistaken as SPACER.


replaceEmptyLinesWithParagraphs

protected void replaceEmptyLinesWithParagraphs()
Replaces <div class="wikimodel-emptyline"/> with <p/>. Empty lines are used by WikiModel to separate block level elements, but since the user should be able to write on these empty lines we convert them to paragraphs.


onEnter

protected void onEnter(Event event)
Overwrites the default rich text area behavior when the Enter key is being pressed.

Parameters:
event - the native event that was fired

onEnterParagraph

protected void onEnterParagraph(com.google.gwt.dom.client.Node container,
                                Range caret,
                                Event event)
Behaves as if the caret is inside a paragraph. Precisely:

Parameters:
container - a block-level element containing the caret
caret - the position of the caret inside the document
event - the native event that was fired

isAtStart

protected boolean isAtStart(com.google.gwt.dom.client.Node container,
                            Range caret)
Parameters:
container - a block level element containing the caret
caret - the position of the caret inside the document
Returns:
true if the caret is at the beginning of its block level container, false otherwise

isAfterLineBreak

protected boolean isAfterLineBreak(com.google.gwt.dom.client.Node container,
                                   Range caret)
Parameters:
container - a block level element containing the caret
caret - the position of the caret in the document
Returns:
true if the caret is immediately after a line break inside the given container, false otherwise

isLineBreak

protected boolean isLineBreak(com.google.gwt.dom.client.Node node)
Parameters:
node - a DOM node
Returns:
true if the given node marks a line break, false otherwise

adjustLineBreak

protected void adjustLineBreak(com.google.gwt.dom.client.Node container,
                               com.google.gwt.dom.client.Node br)
Adjusts the line break position so that:

Parameters:
container - the block-level element containing the line break
br - the line break
See Also:
When hitting Return at the end of the link the new line should not be a link

insertLineBreak

protected void insertLineBreak(com.google.gwt.dom.client.Node container,
                               Range caret)
Inserts a line break at the specified position in the document.

Parameters:
container - a block-level element containing the caret
caret - the place where to insert the line break

splitLine

protected void splitLine(com.google.gwt.dom.client.Node container,
                         Range caret)
Splits a line after a line break.

Parameters:
container - a block-level element containing the caret
caret - the position of the caret in the document

insertEmptyLine

protected void insertEmptyLine(com.google.gwt.dom.client.Node container,
                               Range caret)
Inserts an empty line before the block containing the caret. This is useful when the caret is at the beginning of a block and we want to move that block down by one line; by pressing Enter we can do that.

Parameters:
container - a block-level element containing the caret
caret - the place where to insert the empty line

onBackspace

protected void onBackspace(Event event)
Overwrites the default rich text area behavior when the Backspace key is being pressed.

Parameters:
event - the native event that was fired

isEmptyLine

protected boolean isEmptyLine(com.google.gwt.dom.client.Node node)
Parameters:
node - a DOM node
Returns:
true if the given node represents an empty line

onReset

protected void onReset()
Called after the content of the rich text area has been reset.


copyLineStyle

protected void copyLineStyle(Element sourceLine,
                             Element destinationLine)
Copy some of the CSS styles from the source line to the destination line. Call this method to ensure the important line styles are preserved on the new line after splitting a line.

Parameters:
sourceLine - the line from where to copy the styles
destinationLine - the line whose style will be changed
See Also:
splitLine(Node, Range)


Copyright © 2004-2011 XWiki. All Rights Reserved.