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:
CommandListener, Plugin
Direct Known Subclasses:
IELinePlugin

public class LinePlugin
extends org.xwiki.gwt.wysiwyg.client.plugin.internal.AbstractPlugin
implements CommandListener

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

Version:
$Id: 01616bc2570384721ef263e2a2cbcbf5c957b360 $

Field Summary
static String BR
          The name of the <br/> tag.
static String CLASS_NAME
          The class name attribute.
protected  DOMUtils domUtils
          Collection of DOM utility methods.
static String LI
          The name of the <li> tag.
static 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 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 String TD
          The name of the <td> tag.
static 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()
           
protected  void ensureLineBreakIsVisible(com.google.gwt.dom.client.Node lineBreak, com.google.gwt.dom.client.Node container)
          Ensures that the line created by inserting a line break is visible.
protected  void handleRepeatableKey(Event event)
          Handles a repeatable key press.
 void init(RichTextArea textArea, Config config)
           
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, String param)
          
 void onCommand(CommandManager sender, Command command, 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.
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 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 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 String CLASS_NAME
The class name attribute.

See Also:
Constant Field Values

BR

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

See Also:
Constant Field Values

LI

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

See Also:
Constant Field Values

TD

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

See Also:
Constant Field Values

TH

public static final 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)
Specified by:
init in interface Plugin
Overrides:
init in class org.xwiki.gwt.wysiwyg.client.plugin.internal.AbstractPlugin

destroy

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

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,
                               String param)

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

onCommand

public void onCommand(CommandManager sender,
                      Command command,
                      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

ensureLineBreakIsVisible

protected void ensureLineBreakIsVisible(com.google.gwt.dom.client.Node lineBreak,
                                        com.google.gwt.dom.client.Node container)
Ensures that the line created by inserting a line break is visible. This is need especially when the line break is inserted at the end of an existing line because most browsers don't allow the caret to be placed on invisible lines.

Parameters:
lineBreak - the line break that was inserted
container - the container (e.g. the paragraph) where the line break was inserted

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–2014 XWiki. All rights reserved.