<s> """<STR_LIT>""" <EOL> from __pyjamas__ import doc , wnd , get_main_frame , JS <EOL> from pyjamas import DOM <EOL> from pyjamas . Timer import Timer <EOL> from pyjamas . ui . RichTextAreaImpl import RichTextAreaImpl <EOL> from pyjamas . ui import RichTextAreaConsts <EOL> elem_focussers = { } <EOL> """<STR_LIT>""" <EOL> class RichTextAreaImplStandard ( RichTextAreaImpl ) : <EOL> def __init__ ( self ) : <EOL> RichTextAreaImpl . __init__ ( self ) <EOL> """<STR_LIT>""" <EOL> self . beforeInitPlaceholder = DOM . createDiv ( ) <EOL> """<STR_LIT>""" <EOL> self . initializing = False <EOL> self . css_styling = False <EOL> def createElement ( self ) : <EOL> return DOM . createElement ( '<STR_LIT>' ) <EOL> def createLink ( self , url ) : <EOL> self . execCommand ( "<STR_LIT>" , url ) <EOL> def getBackColor ( self ) : <EOL> return self . queryCommandValue ( "<STR_LIT>" ) <EOL> def getForeColor ( self ) : <EOL> return self . queryCommandValue ( "<STR_LIT>" ) <EOL> def getHTML ( self ) : <EOL> if self . beforeInitPlaceholder is None : <EOL> return self . getHTMLImpl ( ) <EOL> return DOM . getInnerHTML ( self . beforeInitPlaceholder ) <EOL> def getText ( self ) : <EOL> if self . beforeInitPlaceholder is None : <EOL> return self . getTextImpl ( ) <EOL> return DOM . getInnerText ( self . beforeInitPlaceholder ) <EOL> def onTimer ( self , tid ) : <EOL> print "<STR_LIT>" , tid <EOL> self . elem . contentWindow . document . designMode = '<STR_LIT>' <EOL> self . onElementInitialized ( ) <EOL> def initElement ( self ) : <EOL> print "<STR_LIT>" <EOL> self . initializing = True <EOL> Timer ( <NUM_LIT:50> , self ) <EOL> def insertHorizontalRule ( self ) : <EOL> self . execCommand ( "<STR_LIT>" , '<STR_LIT>' ) <EOL> def insertImage ( self , url ) : <EOL> self . execCommand ( "<STR_LIT>" , url ) <EOL> def insertOrderedList ( self ) : <EOL> self . execCommand ( "<STR_LIT>" , '<STR_LIT>' ) <EOL> def insertUnorderedList ( self ) : <EOL> self . execCommand ( "<STR_LIT>" , '<STR_LIT>' ) <EOL> def isBasicEditingSupported ( self ) : <EOL> return True <EOL> def isBold ( self ) : <EOL> return self . queryCommandState ( "<STR_LIT>" ) <EOL> def isExtendedEditingSupported ( self ) : <EOL> return True <EOL> def isItalic ( self ) : <EOL> return self . queryCommandState ( "<STR_LIT>" ) <EOL> def isStrikethrough ( self ) : <EOL> return self . queryCommandState ( "<STR_LIT>" ) <EOL> def isSubscript ( self ) : <EOL> return self . queryCommandState ( "<STR_LIT>" ) <EOL> def isSuperscript ( self ) : <EOL> return self . queryCommandState ( "<STR_LIT>" ) <EOL> def isUnderlined ( self ) : <EOL> return self . queryCommandState ( "<STR_LIT>" ) <EOL> def leftIndent ( self ) : <EOL> self . execCommand ( "<STR_LIT>" , '<STR_LIT>' ) <EOL> def removeFormat ( self ) : <EOL> self . execCommand ( "<STR_LIT>" , '<STR_LIT>' ) <EOL> def removeLink ( self ) : <EOL> self . execCommand ( "<STR_LIT>" , "<STR_LIT:False>" ) <EOL> def rightIndent ( self ) : <EOL> self . execCommand ( "<STR_LIT>" , '<STR_LIT>' ) <EOL> def selectAll ( self ) : <EOL> self . execCommand ( "<STR_LIT>" , '<STR_LIT>' ) <EOL> def setBackColor ( self , color ) : <EOL> self . execCommand ( "<STR_LIT>" , color ) <EOL> def setFocus ( self , focused ) : <EOL> if focused : <EOL> self . elem . contentWindow . focus ( ) <EOL> else : <EOL> self . elem . contentWindow . blur ( ) <EOL> def setFontName ( self , name ) : <EOL> self . execCommand ( "<STR_LIT>" , name ) <EOL> def setFontSize ( self , fontSize ) : <EOL> self . execCommand ( "<STR_LIT>" , str ( fontSize ) ) <EOL> def setForeColor ( self , color ) : <EOL> self . execCommand ( "<STR_LIT>" , color ) <EOL> def setHTML ( self , html ) : <EOL> if self . beforeInitPlaceholder is None : <EOL> self . setHTMLImpl ( html ) <EOL> else : <EOL> DOM . setInnerHTML ( self . beforeInitPlaceholder , html ) <EOL> def setJustification ( self , justification ) : <EOL> if justification == RichTextAreaConsts . CENTER : <EOL> self . execCommand ( "<STR_LIT>" , '<STR_LIT>' ) <EOL> elif justification == RichTextAreaConsts . LEFT : <EOL> self . execCommand ( "<STR_LIT>" , '<STR_LIT>' ) <EOL> elif justification == RichTextAreaConsts . RIGHT : <EOL> self . execCommand ( "<STR_LIT>" , '<STR_LIT>' ) <EOL> def setText ( self , text ) : <EOL> if self . beforeInitPlaceholder is None : <EOL> self . setTextImpl ( text ) <EOL> else : <EOL> DOM . setInnerText ( self . beforeInitPlaceholder , text ) <EOL> def toggleBold ( self ) : <EOL> self . execCommand ( "<STR_LIT>" , "<STR_LIT:False>" ) <EOL> def toggleItalic ( self ) : <EOL> self . execCommand ( "<STR_LIT>" , "<STR_LIT:False>" ) <EOL> def toggleStrikethrough ( self ) : <EOL> self . execCommand ( "<STR_LIT>" , "<STR_LIT:False>" ) <EOL> def toggleSubscript ( self ) : <EOL> self . execCommand ( "<STR_LIT>" , "<STR_LIT:False>" ) <EOL> def toggleSuperscript ( self ) : <EOL> self . execCommand ( "<STR_LIT>" , "<STR_LIT:False>" ) <EOL> def toggleUnderline ( self ) : <EOL> self . execCommand ( "<STR_LIT>" , "<STR_LIT:False>" ) <EOL> def uninitElement ( self ) : <EOL> if self . initializing : <EOL> self . initializing = False <EOL> return <EOL> self . unhookEvents ( ) <EOL> html = self . getHTML ( ) <EOL> self . beforeInitPlaceholder = DOM . createDiv ( ) <EOL> DOM . setInnerHTML ( self . beforeInitPlaceholder , html ) <EOL> self . elem . contentWindow . document . designMode = '<STR_LIT>' <EOL> def getHTMLImpl ( self ) : <EOL> return self . elem . contentWindow . document . body . innerHTML <EOL> def getTextImpl ( self ) : <EOL> return self . elem . contentWindow . document . body . textContent <EOL> def __gwt_handler ( self , view , evt , from_window ) : <EOL> listener = DOM . get_listener ( self . elem ) <EOL> if listener is not None : <EOL> DOM . dispatchEvent ( evt , self . elem , listener ) <EOL> def __gwt_focus_handler ( self , view , evt , from_window ) : <EOL> if elem_focussers . get ( self . elem , False ) : <EOL> return <EOL> elem_focussers [ self . elem ] = True <EOL> self . __gwt_handler ( view , evt , from_window ) <EOL> def __gwt_blur_handler ( self , view , evt , from_window ) : <EOL> if not elem_focussers . get ( self . elem , False ) : <EOL> return <EOL> elem_focussers [ self . elem ] = False <EOL> self . __gwt_handler ( view , evt , from_window ) <EOL> def hookEvents ( self ) : <EOL> print self , "<STR_LIT>" <EOL> elem = self . elem ; <EOL> win = elem . contentWindow ; <EOL> mf = get_main_frame ( ) <EOL> mf . _addWindowEventListener ( '<STR_LIT>' , self . __gwt_handler , win ) <EOL> mf . _addWindowEventListener ( '<STR_LIT>' , self . __gwt_handler , win ) <EOL> mf . _addWindowEventListener ( '<STR_LIT>' , self . __gwt_handler , win ) <EOL> mf . _addWindowEventListener ( '<STR_LIT>' , self . __gwt_handler , win ) <EOL> mf . _addWindowEventListener ( '<STR_LIT>' , self . __gwt_handler , win ) <EOL> mf . _addWindowEventListener ( '<STR_LIT>' , self . __gwt_handler , win ) <EOL> mf . _addWindowEventListener ( '<STR_LIT>' , self . __gwt_handler , win ) <EOL> mf . _addWindowEventListener ( '<STR_LIT>' , self . __gwt_handler , win ) <EOL> mf . _addWindowEventListener ( '<STR_LIT>' , self . __gwt_handler , win ) <EOL> mf . _addWindowEventListener ( '<STR_LIT>' , self . __gwt_focus_handler , win ) <EOL> mf . _addWindowEventListener ( '<STR_LIT>' , self . __gwt_blur_handler , win ) <EOL> def onElementInitialized ( self ) : <EOL> if not self . initializing : <EOL> return <EOL> print "<STR_LIT>" , DOM . getInnerHTML ( self . beforeInitPlaceholder ) <EOL> self . initializing = False <EOL> RichTextAreaImpl . onElementInitialized ( self ) <EOL> if self . css_styling : <EOL> elem = self . elem ; <EOL> _doc = elem . contentWindow . document <EOL> fragment = _doc . createDocumentFragment ( ) <EOL> nl = doc ( ) . getElementsByTagName ( "<STR_LIT>" ) <EOL> for i in range ( nl . length ) : <EOL> n = nl . item ( i ) <EOL> fragment . appendChild ( n . cloneNode ( True ) ) <EOL> _doc . getElementsByTagName ( "<STR_LIT>" ) . item ( <NUM_LIT:0> ) . appendChild ( fragment ) <EOL> if self . beforeInitPlaceholder is not None : <EOL> self . setHTMLImpl ( DOM . getInnerHTML ( self . beforeInitPlaceholder ) ) <EOL> self . beforeInitPlaceholder = None <EOL> def setHTMLImpl ( self , html ) : <EOL> self . elem . contentWindow . document . body . innerHTML = html ; <EOL> def setTextImpl ( self , text ) : <EOL> self . elem . contentWindow . document . body . textContent = text ; <EOL> def unhookEvents ( self ) : <EOL> print """<STR_LIT>""" <EOL> def execCommand ( self , cmd , param ) : <EOL> if self . isRichEditingActive ( self . elem ) : <EOL> self . setFocus ( True ) <EOL> self . execCommandAssumingFocus ( cmd , param ) <EOL> def execCommandAssumingFocus ( self , cmd , param ) : <EOL> self . elem . contentWindow . document . execCommand ( cmd , False , param ) <EOL> def isRichEditingActive ( self , e ) : <EOL> return str ( e . contentWindow . document . designMode ) . upper ( ) == '<STR_LIT>' <EOL> def queryCommandState ( self , cmd ) : <EOL> if self . isRichEditingActive ( self . elem ) : <EOL> self . setFocus ( True ) <EOL> return self . queryCommandStateAssumingFocus ( cmd ) <EOL> else : <EOL> return False <EOL> def queryCommandStateAssumingFocus ( self , cmd ) : <EOL> return self . elem . contentWindow . document . queryCommandState ( cmd ) <EOL> def queryCommandValue ( self , cmd ) : <EOL> self . setFocus ( True ) <EOL> return self . queryCommandValueAssumingFocus ( cmd ) <EOL> def queryCommandValueAssumingFocus ( self , cmd ) : <EOL> return self . elem . contentWindow . document . queryCommandValue ( cmd ) <EOL> def setCssStyling ( self ) : <EOL> self . css_styling = True </s>
