AdfRichUIPeer.createPeerClass(AdfDhtmlEditableValuePeer, "AdfDhtmlRichTextEditorPeer", false);
AdfDhtmlRichTextEditorPeer.InitSubclass = function() {
  AdfRichUIPeer.addSuppressedPPRAttributes(this, AdfRichTextEditor.EDIT_MODE);
  AdfRichUIPeer.addComponentEventHandlers(this, AdfActionEvent.ACTION_EVENT_TYPE, AdfUIInputEvent.CLICK_EVENT_TYPE, AdfUIInputEvent.FOCUS_EVENT_TYPE, AdfUIInputEvent.MOUSE_DOWN_EVENT_TYPE, AdfUIInputEvent.MOUSE_UP_EVENT_TYPE, AdfUIInputEvent.KEY_DOWN_EVENT_TYPE, AdfUIInputEvent.KEY_UP_EVENT_TYPE);
  AdfRichUIPeer.addComponentPropertyGetters(this, AdfRichTextEditor.LABEL);
  AdfRichUIPeer.addComponentPropertyChanges(this, AdfRichTextEditor.LABEL);
  AdfObject.ensureClassInitialization(AdfDhtmlInputBasePeer);
  this.InitConstants()
};
AdfDhtmlRichTextEditorPeer.InitConstants = function() {
  if(this._CONTENT_FIELD_SUB_ID != null) {
    return
  }
  this._TOOLBAR_POPUP_CONTAINER_ID = "_tbPopCont";
  this._TOOLBAR_POPUP_INPUT_CONTAINER_ID = "_tbPopInpCont";
  this._TOOLBAR_POPUP_LINK_INPUT_ID = "_tbPopLnkInput";
  this._TOOLBAR_POPUP_LINK_SELECTED_INPUT_ID = "_tbPopLnkSelectedInput";
  this._CONTENT_INPUT_CONTAINER_SUBID = "_cic";
  this._CONTENT_FIELD_SUB_ID = "cont";
  this._SOURCE_FIELD_SUB_ID = "src";
  this._FIELD_ID_ATTR_NAME = "__afrRichTextEditorFieldId";
  this._SOURCE_FIELD_ID_ATTR_NAME = "__afrRichTextEditorSourceFieldId";
  this.STYLE_BOLD = "style_bold";
  this.STYLE_ITALIC = "style_italic";
  this.STYLE_UNDERLINE = "style_underline";
  this.STYLE_STRIKETHROUGH = "style_strikethrough";
  this.STYLE_LIST_UNORDERED = "style_list_unordered";
  this.STYLE_LIST_ORDERED = "style_list_ordered";
  this.STYLE_INDENT = "style_indent";
  this.STYLE_OUTDENT = "style_outdent";
  this.STYLE_JUSTIFY_LEFT = "style_justify_left";
  this.STYLE_JUSTIFY_CENTER = "style_justify_center";
  this.STYLE_JUSTIFY_RIGHT = "style_justify_right";
  this.STYLE_JUSTIFY_FULL = "style_justify_full";
  this.STYLE_SUPERSCRIPT = "style_superscript";
  this.STYLE_SUBSCRIPT = "style_subscript";
  this.STYLE_COLOR_FOREGROUND = "style_color_foreground";
  this.STYLE_COLOR_BACKGROUND = "style_color_background";
  this.STYLE_FONT_SIZE = "style_font_size";
  this.STYLE_FONT_NAME = "style_font_name";
  this.COMMAND_UNDO = "cmd_undo";
  this.COMMAND_REDO = "cmd_redo";
  this.COMMAND_LINK = "cmd_link";
  this.COMMAND_UNLINK = "cmd_unlink";
  this.COMMAND_CLEAR_STYLING = "cmd_clear_styling";
  this.COMMAND_INSERT = "cmd_insert";
  this.COMMAND_MODE_RICH_TEXT = "cmd_mode_rich_text";
  this.COMMAND_MODE_CODE = "cmd_mode_code";
  this._execCommandMap = new Object;
  this._execCommandMap[this.STYLE_BOLD] = "bold";
  this._execCommandMap[this.STYLE_ITALIC] = "italic";
  this._execCommandMap[this.STYLE_UNDERLINE] = "underline";
  this._execCommandMap[this.STYLE_STRIKETHROUGH] = "strikethrough";
  this._execCommandMap[this.STYLE_LIST_UNORDERED] = "insertunorderedlist";
  this._execCommandMap[this.STYLE_LIST_ORDERED] = "insertorderedlist";
  this._execCommandMap[this.STYLE_INDENT] = "indent";
  this._execCommandMap[this.STYLE_OUTDENT] = "outdent";
  this._execCommandMap[this.STYLE_JUSTIFY_LEFT] = "justifyleft";
  this._execCommandMap[this.STYLE_JUSTIFY_CENTER] = "justifycenter";
  this._execCommandMap[this.STYLE_JUSTIFY_RIGHT] = "justifyright";
  this._execCommandMap[this.STYLE_JUSTIFY_FULL] = "justifyfull";
  this._execCommandMap[this.STYLE_SUPERSCRIPT] = "superscript";
  this._execCommandMap[this.STYLE_SUBSCRIPT] = "subscript";
  this._execCommandMap[this.STYLE_COLOR_FOREGROUND] = "forecolor";
  this._execCommandMap[this.STYLE_COLOR_BACKGROUND] = "backcolor";
  this._execCommandMap[this.STYLE_FONT_SIZE] = "fontsize";
  this._execCommandMap[this.STYLE_FONT_NAME] = "fontname";
  this._execCommandMap[this.COMMAND_UNDO] = "undo";
  this._execCommandMap[this.COMMAND_REDO] = "redo";
  this._execCommandMap[this.COMMAND_LINK] = "createlink";
  this._execCommandMap[this.COMMAND_UNLINK] = "unlink";
  this._execCommandMap[this.COMMAND_CLEAR_STYLING] = "removeformat";
  this._execCommandMap[this.COMMAND_INSERT] = "insert";
  this._execCommandMap[this.COMMAND_MODE_RICH_TEXT] = "moderichtext";
  this._execCommandMap[this.COMMAND_MODE_CODE] = "modecode";
  this._COLOR_REGEX = /rgba?\((\d+),\s*(\d+),\s*(\d+)(,\s*((\d+)))?\)/
};
AdfDhtmlRichTextEditorPeer.HandleTimerUpdate = function(clientId) {
  var component = AdfPage.PAGE.findComponent(clientId);
  if(component) {
    var peer = component.getPeer();
    peer._updateValue();
    peer._handleContextChangedForCommands()
  }
};
AdfDhtmlRichTextEditorPeer.prototype.Init = function(component) {
  AdfDhtmlRichTextEditorPeer.superclass.Init.call(this, component);
  this._ignoreEvents = {}
};
AdfDhtmlRichTextEditorPeer.prototype.InitDomElement = function(component, domElement) {
  var readOnly = component.getReadOnly();
  if(!readOnly) {
    var clientId = component.getClientId();
    var fieldSubId = AdfRichUIPeer.CreateSubId(clientId, AdfDhtmlRichTextEditorPeer._CONTENT_FIELD_SUB_ID);
    AdfAgent.AGENT.setExpandoProperty(domElement, AdfDhtmlRichTextEditorPeer._FIELD_ID_ATTR_NAME, fieldSubId);
    var sourceFieldSubId = AdfRichUIPeer.CreateSubId(clientId, AdfDhtmlRichTextEditorPeer._SOURCE_FIELD_SUB_ID);
    AdfAgent.AGENT.setExpandoProperty(domElement, AdfDhtmlRichTextEditorPeer._SOURCE_FIELD_ID_ATTR_NAME, sourceFieldSubId);
    AdfPage.PAGE.registerLoadingComponent(component)
  }
  AdfDhtmlRichTextEditorPeer.superclass.InitDomElement.call(this, component, domElement);
  this._isTouch = AdfAgent.AGENT.getCapabilities()[AdfAgent.CAP_TOUCH_SCREEN] != AdfAgent.CAP_TOUCH_SCREEN_NONE;
  if(!readOnly) {
    if(component.getEditMode() == "source") {
      this._codeEditingMode = true
    }
    if(component.getToolbarDisplay() === "popup") {
      this._toolbarPopupListenerInitialized = false
    }
    this._createIframe(component)
  }
};
AdfDhtmlRichTextEditorPeer.prototype.GetReadyState = function() {
  var component = this.getComponent();
  var iframeDomElement = this._getContentField(component);
  if(iframeDomElement && iframeDomElement.getAttribute("data-afr-rte-loaded") === "1") {
    AdfLogger.LOGGER.fine("AdfDhtmlRichTextEditorPeer.GetReadyState: RTE loaded");
    try {
      var innerWindow = iframeDomElement.contentWindow;
      if(innerWindow.document.readyState === "complete") {
        AdfLogger.LOGGER.fine("AdfDhtmlRichTextEditorPeer.GetReadyState: RTE ready");
        return AdfUIComponent.STATE_COMPLETE
      }else {
        AdfLogger.LOGGER.fine("AdfDhtmlRichTextEditorPeer.GetReadyState: RTE inner document not yet ready");
        return AdfUIComponent.STATE_LOADING
      }
    }catch(e) {
      AdfLogger.LOGGER.fine("AdfDhtmlRichTextEditor.GetReadyState: exception.", "Nothing more to do");
      return AdfUIComponent.STATE_COMPLETE
    }
  }
  AdfLogger.LOGGER.fine("AdfDhtmlRichTextEditorPeer.GetReadyState: richTextEditor's onload has not fired");
  return AdfUIComponent.STATE_LOADING
};
AdfDhtmlRichTextEditorPeer.prototype._isContainerStretched = function() {
  return AdfDomUtils.containsCSSClassName(AdfRichUIPeer.getDomNodeForComponent(this.getComponent()), "p_AFStretched")
};
AdfDhtmlRichTextEditorPeer.prototype.needsResizeNotify = function(component) {
  return true
};
AdfDhtmlRichTextEditorPeer.prototype.ResizeNotify = function(oldWidth, oldHeight, newWidth, newHeight) {
  if(!this._isContainerStretched()) {
    return
  }
  var agent = AdfAgent.AGENT;
  var component = this.getComponent();
  var clientId = component.getClientId();
  var cicNode = agent.getElementById(AdfRichUIPeer.CreateSubId(clientId, AdfDhtmlRichTextEditorPeer._CONTENT_INPUT_CONTAINER_SUBID));
  var contentNode = agent.getElementById(AdfRichUIPeer.CreateSubId(clientId, "content"));
  var childNodes = contentNode.childNodes;
  if(!cicNode) {
    return
  }
  var height = 0;
  for(var i = 0, j = childNodes.length;i < j;i++) {
    if(childNodes[i] === cicNode) {
      continue
    }
    height += childNodes[i].offsetHeight
  }
  cicNode.style.height = newHeight - height + "px"
};
AdfDhtmlRichTextEditorPeer.prototype.GetInlineEditor = function(event) {
  return AdfDhtmlSimpleLabelEditor.getInlineEditor()
};
AdfDhtmlRichTextEditorPeer.prototype.isEmpty = function(value) {
  if(!value) {
    value = this.GetSubmittedValue(this.getComponent(), this.getDomElement())
  }
  value = value.replace(/(<([^>]+)>)/ig, "");
  value = AdfStrings.trim(value);
  return value.length == 0
};
AdfDhtmlRichTextEditorPeer.prototype.getCurrentContent = function(component, keepOriginal) {
  var editingAgent = AdfEditingAgent.getInstance();
  return editingAgent.getInlineFrameContent(this._getContentField(component), keepOriginal)
};
AdfDhtmlRichTextEditorPeer.prototype.addBinding = function(componentClientId, componentClient, command, commandParameter, propertyName, eventType) {
  AdfAssert.assertString(componentClientId);
  AdfAssert.assertString(command);
  if(command.substring(0, 5) == "style") {
    AdfAssert.assertString(propertyName);
    AdfAssert.assertStringOrNull(eventType);
    if(eventType == undefined) {
      eventType = AdfActionEvent.ACTION_EVENT_TYPE
    }
    this._addStyleBinding(componentClientId, propertyName, command, eventType)
  }else {
    if(command.substring(0, 3) == "cmd") {
      this._addCommandBinding(componentClientId, componentClient, command, commandParameter)
    }else {
      AdfLogger.LOGGER.severe("Unable to add binding [", command, "] for ", componentClientId, " to ", this.getComponent().getClientId())
    }
  }
};
AdfDhtmlRichTextEditorPeer.prototype.setCodeEditingMode = function(newCodeEditingMode) {
  var oldCodeEditingMode = this._codeEditingMode;
  if(oldCodeEditingMode == null) {
    oldCodeEditingMode = false
  }
  if(oldCodeEditingMode != newCodeEditingMode) {
    this._codeEditingMode = newCodeEditingMode;
    var component = this.getComponent();
    if(newCodeEditingMode) {
      component.setProperty("editMode", "source", true)
    }else {
      component.setProperty("editMode", "wysiwyg", true)
    }
    var toolboxClientId = this._toolboxClientId;
    if(toolboxClientId == null) {
      var rteClientId = component.getClientId();
      toolboxClientId = rteClientId + "_afrToolbox";
      this._toolboxClientId = toolboxClientId;
      this._modeButtonRichTextClientId = rteClientId + "_afrModeRichText";
      this._modeButtonCodeClientId = rteClientId + "_afrModeCode"
    }
    var toolboxComponent = AdfPage.PAGE.findComponent(toolboxClientId);
    var children = [];
    this.visitChildren(toolboxComponent, AdfDhtmlRichTextEditorPeer._toolboxVisitChildrenCallback, this, true);
    var editingAgent = AdfEditingAgent.getInstance();
    var richTextField = this._getContentField(component);
    var codeField = this._getSourceCodeField(component);
    if(newCodeEditingMode) {
      var innerHtml = this.getCurrentContent(component);
      codeField.value = "" + innerHtml;
      richTextField.blur();
      this._removeSelection();
      richTextField.style.display = "none";
      codeField.style.display = "block";
      codeField.focus()
    }else {
      codeField.blur();
      codeField.style.display = "none";
      richTextField.style.display = "block";
      richTextField.focus();
      var code = codeField.value;
      editingAgent.setInlineFrameContent(richTextField, code);
      this.focus(component);
      AdfEditingAgent.getInstance().setInlineFrameContentEditable(richTextField);
      this._ignoreNextContextChanged = true
    }
  }
};
AdfDhtmlRichTextEditorPeer.prototype.Focus = function() {
  var component = this.getComponent();
  if(this._codeEditingMode) {
    var codeField = this._getSourceCodeField(component);
    codeField.focus()
  }else {
    var contentField = this._getContentField(component);
    if(contentField.nodeName == "IFRAME" && contentField != document.activeElement) {
      try {
        var containerDiv = contentField.parentElement;
        var isContainerDivTabIdx = containerDiv.hasAttribute("tabindex");
        if(!isContainerDivTabIdx) {
          containerDiv.setAttribute("tabindex", "0")
        }
        AdfFocusUtils.focusElement(containerDiv);
        if(!isContainerDivTabIdx) {
          containerDiv.removeAttribute("tabindex")
        }
      }catch(err) {
      }
    }
    var isIE11 = AdfAgent.AGENT.getPlatform() == AdfAgent.IE_PLATFORM && AdfAgent.AGENT.getVersion() == 11;
    if(isIE11) {
      if(this._hadFirstFocus && !this._isComponentHavingFocus()) {
        AdfFocusUtils.focusElement(contentField)
      }
    }else {
      AdfFocusUtils.focusElement(contentField)
    }
    this._stopDialogsFromBeingInactivatedDueToIframes()
  }
};
AdfDhtmlRichTextEditorPeer.prototype._isComponentHavingFocus = function() {
  var domDocument = AdfAgent.AGENT.getDomDocument();
  var activeElement = domDocument.activeElement;
  var component = this.getComponent();
  var contentNode = this._codeEditingMode ? this._getSourceCodeField(component) : this._getContentField(component);
  return activeElement && activeElement.id == contentNode.id
};
AdfDhtmlRichTextEditorPeer.prototype.executeCommand = function(cmd, value) {
  this._execCommand(cmd, value)
};
AdfDhtmlRichTextEditorPeer.prototype.getSelectionRange = function(component) {
  var editingAgent = AdfEditingAgent.getInstance();
  var inlineFrame = this._getContentField(component);
  return editingAgent.getSelectionRange(inlineFrame)
};
AdfDhtmlRichTextEditorPeer.prototype.GetComponentLabel = function(component, domElement) {
  var labelElements = domElement.getElementsByTagName("LABEL");
  var labelElement = labelElements.length ? labelElements[0] : null;
  if(labelElement != null) {
    var clientId = component.getClientId();
    var fieldSubId = AdfRichUIPeer.CreateSubId(clientId, "content");
    if(labelElement.htmlFor == fieldSubId) {
      return AdfAgent.AGENT.getTextContent(labelElement)
    }
    var sourceFieldSubId = AdfRichUIPeer.CreateSubId(clientId, AdfDhtmlRichTextEditorPeer._SOURCE_FIELD_SUB_ID);
    if(labelElement.htmlFor == sourceFieldSubId) {
      return AdfAgent.AGENT.getTextContent(labelElement)
    }
  }
  return null
};
AdfDhtmlRichTextEditorPeer.prototype.HandleComponentFocus = function(componentEvent) {
  AdfDhtmlRichTextEditorPeer.superclass.HandleComponentFocus.call(this, componentEvent);
  var agent = AdfAgent.AGENT;
  var component = this.getComponent();
  if(!component.getReadOnly()) {
    this._stopDialogsFromBeingInactivatedDueToIframes();
    if(!this._commandBeingProcessed) {
      var activeNode = AdfPage.PAGE.getActiveDomElement();
      var contentNode = this._getContentField(component);
      if(activeNode == contentNode) {
        this.focus(component);
        var value = this._getSourceCodeField(component).value;
        AdfDhtmlInputBasePeer.setLastValue(contentNode, value)
      }
      if(component.getToolbarDisplay() === "popup" && !AdfDomUtils.isVisible(this._getToolbarPopupNode(component))) {
        this._showToolbarPopup()
      }
    }
  }
};
AdfDhtmlRichTextEditorPeer.prototype.HandleComponentClick = function(componentEvent) {
  AdfDhtmlRichTextEditorPeer.superclass.HandleComponentClick.call(this, componentEvent);
  var target = componentEvent.getNativeEventTarget();
  if(target && target.nodeName == "LABEL") {
    this.focus(this.getComponent())
  }
};
AdfDhtmlRichTextEditorPeer.prototype.HandleComponentMouseDown = function(componentEvent) {
  this._handleClonedEvent(componentEvent)
};
AdfDhtmlRichTextEditorPeer.prototype.HandleComponentMouseUp = function(componentEvent) {
  this._handleClonedEvent(componentEvent)
};
AdfDhtmlRichTextEditorPeer.prototype.HandleComponentKeyDown = function(componentEvent) {
  this._handleClonedEvent(componentEvent)
};
AdfDhtmlRichTextEditorPeer.prototype.HandleComponentKeyUp = function(componentEvent) {
  this._handleClonedEvent(componentEvent)
};
AdfDhtmlRichTextEditorPeer.prototype.GetSubmittedValue = function(component, domElement) {
  if(this._isTouch && this.WasSubmitted(component)) {
    var richTextField = this._getContentField(component);
    var newValue = this.getCurrentContent(component);
    var lastValue = AdfDhtmlInputBasePeer.getLastValue(richTextField);
    if(lastValue != newValue && !(lastValue === undefined)) {
      this._updateValue()
    }
  }
  if(component.getReadOnly()) {
    var domNode = AdfDhtmlEditableValuePeer.getContentNode(component, domElement);
    return domNode.innerHTML
  }
  var domNode = this._getSourceCodeField(component);
  return domNode.value
};
AdfDhtmlRichTextEditorPeer.prototype.SetDisplayValue = function(component, domElement, newValue) {
  AdfAssert.assertString(newValue);
  if(component.getReadOnly()) {
    domElement.innerHTML = newValue
  }else {
    var content = this._getSourceCodeField(component).value;
    var contentField = this._getContentField(component);
    this._setInlineFrameContent(contentField, content)
  }
};
AdfDhtmlRichTextEditorPeer.prototype.HandleComponentAction = function(componentEvent) {
  this._styleBindingActionListener(componentEvent);
  this._commandBindingActionListener(componentEvent)
};
AdfDhtmlRichTextEditorPeer.prototype.ShowFormatHint = function() {
  return true
};
AdfDhtmlRichTextEditorPeer.prototype.ComponentRemoved = function(component) {
  var readOnly = component.getReadOnly();
  if(!readOnly) {
    page.unregisterLoadingComponent(component)
  }
  if(!(readOnly || component.getDisabled())) {
    this._removeStyleBindings(component);
    this._removeCommandBindings(component);
    this._removeContextChangeListeners(component);
    if(this._loadCallback) {
      AdfAgent.AGENT.removeBubbleEventListener(this._getContentField(component), "load", this._loadCallback);
      delete this._loadCallback
    }
    AdfRichTextEditorBehaviorManager.getInstance().unregisterComponent(component);
    delete this._hadFirstFocus;
    delete this._lastSelectionRange
  }
  AdfDhtmlRichTextEditorPeer.superclass.ComponentRemoved.call(this, component)
};
AdfDhtmlRichTextEditorPeer.prototype.ScrollIntoView = function(component, focus, subTargetId) {
  var rootElement = this.getDomElement();
  rootElement.scrollIntoView();
  var domDoc = this.getDomDocument();
  var readOnly = component.getReadOnly();
  var inlineFrame;
  if(!readOnly) {
    inlineFrame = this._getContentField(component);
    var editingAgent = AdfEditingAgent.getInstance();
    domDoc = editingAgent.getInlineFrameDocument(inlineFrame)
  }
  var subTargetElement = null;
  if(subTargetId != null) {
    subTargetElement = domDoc.getElementById(subTargetId);
    if(subTargetElement) {
      subTargetElement.scrollIntoView()
    }else {
      AdfLogger.LOGGER.warning("Invalid subTargetId specified:" + subTargetId)
    }
  }
  if(focus) {
    if(subTargetElement) {
      AdfFocusUtils.focusElement(subTargetElement)
    }else {
      if(!readOnly) {
        AdfFocusUtils.focusElement(inlineFrame)
      }
    }
  }
};
AdfDhtmlRichTextEditorPeer.prototype._stopDialogsFromBeingInactivatedDueToIframes = function() {
  var cancelNeeded = true;
  var domDocument = AdfAgent.AGENT.getDomDocument();
  var activeTagName;
  var activeElement = domDocument.activeElement;
  if(activeElement) {
    activeTagName = activeElement.tagName
  }
  if(activeTagName == "IFRAME") {
    cancelNeeded = false
  }
  if(cancelNeeded) {
    AdfPage.PAGE.getAutoDismissalManager().cancelBlurTimeout()
  }
};
AdfDhtmlRichTextEditorPeer._toolboxVisitChildrenCallback = function(component) {
  var result = 0;
  var codeEditingMode = this._codeEditingMode;
  if(component instanceof AdfRichCommandToolbarButton) {
    var clientId = component.getClientId();
    if(clientId != this._modeButtonRichTextClientId && clientId != this._modeButtonCodeClientId) {
      component.setProperty("selected", false, false, AdfUIComponent.PROPAGATE_IF_KNOWN_PROPERTY);
      component.setProperty("disabled", codeEditingMode, false, AdfUIComponent.PROPAGATE_IF_KNOWN_PROPERTY);
      result = 1
    }
  }else {
    if(component instanceof AdfRichSelectOneChoice || component instanceof AdfRichInputNumberSpinbox || component instanceof AdfRichInputColor) {
      component.setProperty("disabled", codeEditingMode, false, AdfUIComponent.PROPAGATE_IF_KNOWN_PROPERTY);
      result = 1
    }else {
      if(component instanceof AdfRichPanelGroupLayout) {
        var domElement = AdfRichUIPeer.getDomElementForComponent(component);
        if(codeEditingMode) {
          AdfDomUtils.addCSSClassName(domElement, AdfRichUIPeer.DISABLED_STYLECLASS)
        }else {
          AdfDomUtils.removeCSSClassName(domElement, AdfRichUIPeer.DISABLED_STYLECLASS)
        }
        result = 1
      }
    }
  }
  return result
};
AdfDhtmlRichTextEditorPeer.prototype._handleMouseUp = function(event) {
  this._handleContextChanged();
  var agentName = navigator.userAgent.toLowerCase();
  var target = event.target;
  if(agentName.indexOf("chrome") != -1 && target.nodeName.toLowerCase() == "html") {
    target.getElementsByTagName("body")[0].focus()
  }
};
AdfDhtmlRichTextEditorPeer.prototype._handleContextChanged = function() {
  if(this._ignoreNextContextChanged) {
    delete this._ignoreNextContextChanged
  }else {
    if(this._codeEditingMode != true) {
      this._saveSelection();
      this._handleContextChangedForCommands();
      this._handleContextChangedForStyles()
    }
  }
};
AdfDhtmlRichTextEditorPeer.prototype._handleKeyDown = function(evt) {
  var isIE = AdfAgent.AGENT.getPlatform() == AdfAgent.IE_PLATFORM;
  var isGecko = AdfAgent.AGENT.getPlatform() == AdfAgent.GECKO_PLATFORM;
  var equals_key = 187;
  var equals_key_2 = equals_key;
  var minus_key = 189;
  if(isIE) {
    var time = this._keyTimer;
    if(time) {
      clearTimeout(time)
    }
    var methodCall = "AdfDhtmlRichTextEditorPeer.HandleTimerUpdate('" + this.getComponent().getClientId() + "')";
    this._keyTimer = setTimeout(methodCall, 3E3)
  }
  if(isGecko) {
    equals_key = 61;
    equals_key_2 = 107;
    minus_key = 109
  }
  var keyCode = evt.keyCode;
  if(keyCode == 9) {
    if(evt.shiftKey) {
      this._mouseDownOrTabBack = true
    }
    var component = this.getComponent();
    var editMode = component.getEditMode();
    var toolbarElement = this._getToolbarPopupNode(component);
    var isToolbarPopupVisible = component.getToolbarDisplay() === "popup" && AdfDomUtils.isVisible(toolbarElement);
    if(editMode == "wysiwyg") {
      if(isToolbarPopupVisible) {
        AdfAgent.AGENT.preventDefault(evt);
        if(evt.shiftKey) {
          AdfFocusUtils.focusElement(AdfFocusUtils.getLastTabStop(toolbarElement))
        }else {
          AdfFocusUtils.focusNextTabStop(this._getContentField(component))
        }
      }else {
        AdfEditingAgent.getInstance().handleTab(this._getContentField(component), evt);
        if(isIE) {
          if(evt.shiftKey) {
            this._tabBack = true
          }else {
            this._tabForward = true
          }
        }
      }
    }else {
      if(isToolbarPopupVisible) {
        AdfAgent.AGENT.preventDefault(evt);
        if(evt.shiftKey) {
          AdfFocusUtils.focusElement(AdfFocusUtils.getLastFocusableDescendant(toolbarElement))
        }else {
          AdfFocusUtils.focusNextTabStop(this._getSourceCodeField(component))
        }
      }
    }
  }else {
    if(evt.ctrlKey) {
      var cancelEvent = true;
      if(evt.altKey) {
        switch(keyCode) {
          case equals_key:
          ;
          case equals_key_2:
            this._execCommand(AdfDhtmlRichTextEditorPeer.STYLE_SUPERSCRIPT);
            break;
          case minus_key:
            this._execCommand(AdfDhtmlRichTextEditorPeer.STYLE_SUBSCRIPT);
            break;
          case 121:
            var toolBarComp = AdfPage.PAGE.findComponent(this.getComponent().getClientId() + "_afrToolbox");
            if(toolBarComp) {
              toolBarComp.focus()
            }
            break;
          default:
            cancelEvent = false
        }
      }else {
        if(evt.shiftKey) {
          switch(keyCode) {
            case 72:
              this._execCommand(AdfDhtmlRichTextEditorPeer.COMMAND_UNLINK);
              break;
            case 77:
              this._execCommand(AdfDhtmlRichTextEditorPeer.STYLE_OUTDENT);
              break;
            case 83:
              this._execCommand(AdfDhtmlRichTextEditorPeer.COMMAND_CLEAR_STYLING);
              break;
            case 87:
              this._execCommand(AdfDhtmlRichTextEditorPeer.STYLE_COLOR_FOREGROUND);
              break;
            default:
              cancelEvent = false
          }
        }else {
          switch(keyCode) {
            case 53:
              this._execCommand(AdfDhtmlRichTextEditorPeer.STYLE_STRIKETHROUGH);
              break;
            case 66:
              this._execCommand(AdfDhtmlRichTextEditorPeer.STYLE_BOLD);
              break;
            case 69:
              this._execCommand(AdfDhtmlRichTextEditorPeer.STYLE_JUSTIFY_CENTER);
              break;
            case 72:
              window.setTimeout(this.createCallback(this._cmdCreateLink), 0);
              break;
            case 73:
              this._execCommand(AdfDhtmlRichTextEditorPeer.STYLE_ITALIC);
              break;
            case 74:
              this._execCommand(AdfDhtmlRichTextEditorPeer.STYLE_JUSTIFY_FULL);
              break;
            case 76:
              this._execCommand(AdfDhtmlRichTextEditorPeer.STYLE_JUSTIFY_LEFT);
              break;
            case 77:
              this._execCommand(AdfDhtmlRichTextEditorPeer.STYLE_INDENT);
              break;
            case 82:
              this._execCommand(AdfDhtmlRichTextEditorPeer.STYLE_JUSTIFY_RIGHT);
              break;
            case 85:
              this._execCommand(AdfDhtmlRichTextEditorPeer.STYLE_UNDERLINE);
              break;
            case 87:
              this._execCommand(AdfDhtmlRichTextEditorPeer.STYLE_COLOR_BACKGROUND);
              break;
            case 219:
              var value = this._getOneThroughSevenFontSize(this._queryCommandValue(AdfDhtmlRichTextEditorPeer.STYLE_FONT_SIZE));
              if(value > 1) {
                var newValue = +value - 1;
                this._execCommand(AdfDhtmlRichTextEditorPeer.STYLE_FONT_SIZE, newValue)
              }
              break;
            case 221:
              var value = this._getOneThroughSevenFontSize(this._queryCommandValue(AdfDhtmlRichTextEditorPeer.STYLE_FONT_SIZE));
              if(value < 7) {
                var newValue = +value + 1;
                this._execCommand(AdfDhtmlRichTextEditorPeer.STYLE_FONT_SIZE, newValue)
              }
              break;
            default:
              cancelEvent = false
          }
        }
      }
      if(cancelEvent) {
        AdfAgent.AGENT.eatEvent(evt)
      }
    }
  }
};
AdfDhtmlRichTextEditorPeer.prototype._cmdCreateLink = function() {
  return this._execCommand(AdfDhtmlRichTextEditorPeer.COMMAND_LINK)
};
AdfDhtmlRichTextEditorPeer.prototype._saveSelection = function() {
  var editingAgent = AdfEditingAgent.getInstance(), range = editingAgent.getSelectionRange(this._getContentField(this.getComponent()));
  if(this._isTouch) {
    if(range != null) {
      this._lastSelectionRange = range
    }
  }else {
    this._lastSelectionRange = range
  }
  var component = this.getComponent();
  if(component.getToolbarDisplay() === "popup") {
    var contNode = this._getToolbarPopupInputContainer(component);
    if(AdfDomUtils.isVisible(contNode)) {
      var dtComp = this._getToolbarPopupDisplayedTextComp(component);
      dtComp.setValue(editingAgent.getSelectionRangeString(range))
    }
  }
};
AdfDhtmlRichTextEditorPeer.prototype._handleClonedEvent = function(componentEvent) {
  var evt = componentEvent.getNativeEvent();
  if(this._clonedEventMap != null && this._clonedEventMap[evt] != null) {
    var peer = this;
    var originalEvent = this._clonedEventMap[evt];
    componentEvent.cancel = function() {
      AdfDomUIInputEvent.superclass.cancel.call(componentEvent);
      AdfAgent.AGENT.preventDefault(evt);
      AdfAgent.AGENT.preventDefault(originalEvent);
      delete peer._clonedEventMap[evt]
    }
  }
};
AdfDhtmlRichTextEditorPeer.prototype._removeSelection = function() {
  delete this._lastSelectionRange
};
AdfDhtmlRichTextEditorPeer.prototype._restoreSelection = function() {
  if(this._lastSelectionRange != null) {
    AdfEditingAgent.getInstance().setSelectionRange(this._getContentField(this.getComponent()), this._lastSelectionRange)
  }
};
AdfDhtmlRichTextEditorPeer.prototype._handleContextChangedForCommands = function() {
  if(this._commandObservers == undefined) {
    return false
  }
  var component = this.getComponent();
  var contentField = this._getContentField(component);
  var editingAgent = AdfEditingAgent.getInstance();
  var commandObservers = this._commandObservers;
  var length = commandObservers.length;
  var oldCommandValues = this._oldCommandValues;
  if(oldCommandValues == undefined) {
    oldCommandValues = {}
  }
  var cached = {};
  for(var i = 0;i < length;i++) {
    var observerObj = commandObservers[i];
    var commandKey = observerObj.command;
    var listenerComponent = AdfPage.PAGE.findComponent(observerObj.componentId);
    AdfAssert.assert(listenerComponent);
    if(cached[commandKey] === undefined) {
      var execCommandKey = AdfDhtmlRichTextEditorPeer._execCommandMap[commandKey];
      if(execCommandKey == null) {
        cached[commandKey] = null
      }else {
        cached[commandKey] = editingAgent.queryCommandEnabled(component, contentField, execCommandKey)
      }
    }
    var value = cached[commandKey];
    if(commandKey === AdfDhtmlRichTextEditorPeer.COMMAND_LINK && component.getToolbarDisplay() === "popup") {
      this._updateToolbarPopupURLVal()
    }
    if(oldCommandValues[commandKey] !== cached[commandKey]) {
      switch(commandKey) {
        case AdfDhtmlRichTextEditorPeer.COMMAND_INSERT:
        ;
        case AdfDhtmlRichTextEditorPeer.COMMAND_MODE_RICH_TEXT:
        ;
        case AdfDhtmlRichTextEditorPeer.COMMAND_MODE_CODE:
          break;
        default:
          listenerComponent.setProperty("disabled", !cached[commandKey], false, false)
      }
    }
  }
  this._oldCommandValues = cached
};
AdfDhtmlRichTextEditorPeer.prototype._handleContextChangedForStyles = function() {
  var agent = AdfAgent.AGENT;
  if(this._styleObservers == undefined) {
    return false
  }
  var length = this._styleObservers.length;
  var oldStyleValues = this._oldStyleValues;
  if(oldStyleValues == undefined) {
    oldStyleValues = {}
  }
  var cached = {};
  for(var i = 0;i < length;i++) {
    var observerObj = this._styleObservers[i];
    var styleKey = observerObj.styleKey;
    var listenerComponent = AdfPage.PAGE.findComponent(observerObj.componentId);
    AdfAssert.assert(listenerComponent);
    var value = null;
    if(cached[styleKey] == undefined) {
      value = this._getSelectionStyling(styleKey);
      if(value != null) {
        cached[styleKey] = value
      }
    }else {
      value = cached[styleKey]
    }
    if(oldStyleValues[styleKey] !== value && value != null) {
      var indeterminateValue = false;
      if(styleKey == AdfDhtmlRichTextEditorPeer.STYLE_COLOR_BACKGROUND || styleKey == AdfDhtmlRichTextEditorPeer.STYLE_COLOR_FOREGROUND) {
        value = AdfEditingAgent.getInstance().getColor(value)
      }else {
        if(styleKey == AdfDhtmlRichTextEditorPeer.STYLE_FONT_SIZE) {
          value = this._getOneThroughSevenFontSize(value);
          if(!(value > 0 && value < 8)) {
            value = "2";
            indeterminateValue = true
          }else {
            value = value + ""
          }
        }else {
          if(styleKey == AdfDhtmlRichTextEditorPeer.STYLE_FONT_NAME) {
            if(listenerComponent instanceof AdfRichSelectOneChoice) {
              var selectItems = listenerComponent.getSelectItems();
              var selectItemsLength = selectItems.length;
              var matched = false;
              if(value != null) {
                value = ("" + value).replace(/'/g, "");
                var agentName = navigator.userAgent.toLowerCase();
                if(agentName.indexOf("chrome") != -1 || this._isTouch && agent.getPlatform() == AdfAgent.WEBKIT_PLATFORM) {
                  value = ("" + value).replace(/, /gi, ",")
                }
              }
              for(var j = 0;j < selectItemsLength;j++) {
                if(selectItems[j].getLabel() == value) {
                  value = selectItems[j].getValue();
                  matched = true;
                  break
                }
              }
              if(!matched) {
                var bestMatch = Number.MAX_VALUE;
                var match;
                var matchedValue;
                for(var k = 0;k < selectItemsLength;k++) {
                  if((match = selectItems[k].getValue().search(value)) > -1) {
                    if(match < bestMatch) {
                      bestMatch = match;
                      matchedValue = selectItems[k].getValue()
                    }
                    matched = true
                  }
                }
                if(!matched) {
                  for(var k = 1;k < selectItemsLength;k++) {
                    if((match = value.search(selectItems[k].getLabel())) > -1) {
                      if(match < bestMatch) {
                        bestMatch = match;
                        matchedValue = selectItems[k].getValue()
                      }
                      matched = true
                    }
                  }
                }
                if(matched) {
                  value = matchedValue
                }else {
                  value = selectItems[0].getValue()
                }
              }
            }
          }
        }
      }
      indeterminateValue = indeterminateValue || this._getIndeterminateStyling(styleKey);
      var oldValue = listenerComponent.getProperty(observerObj.propertyName);
      var valueChanged = !AdfUIUtils.compareValues(oldValue, value);
      if(valueChanged) {
        if(observerObj.propertyName == "value") {
          this._ignoreNextEvent(styleKey)
        }
        listenerComponent.setProperty(observerObj.propertyName, value, false, false)
      }
    }
  }
  this._oldStyleValues = cached
};
AdfDhtmlRichTextEditorPeer.prototype._getOneThroughSevenFontSize = function(value) {
  var result;
  var rawValue = "" + value;
  var pxIndex = rawValue.indexOf("px");
  if(pxIndex != -1) {
    result = parseInt(rawValue.substring(0, pxIndex));
    if(result <= 10) {
      result = 1
    }else {
      if(result <= 13) {
        result = 2
      }else {
        if(result <= 16) {
          result = 3
        }else {
          if(result <= 18) {
            result = 4
          }else {
            if(result <= 24) {
              result = 5
            }else {
              if(result <= 32) {
                result = 6
              }else {
                result = 7
              }
            }
          }
        }
      }
    }
  }else {
    result = parseInt(value) || 2
  }
  return result
};
AdfDhtmlRichTextEditorPeer.prototype._createIframe = function(component) {
  var agent = AdfAgent.AGENT;
  var contentField = this._getContentField(component);
  var page = AdfPage.PAGE;
  var iframe = this.getDomDocument().createElement("IFRAME");
  iframe.frameBorder = "0";
  var cssText = contentField.style.cssText;
  if(cssText.length > 0) {
    iframe.style.cssText = cssText
  }
  iframe.className = contentField.className;
  iframe.id = contentField.id;
  iframe.title = page.getLookAndFeel().getTranslatedString("af_richTextEditor.IFRAME_TITLE");
  if(component.getContentDelivery() == "lazy") {
    iframe.src = page.getLazyFetchURI(component.getClientId())
  }else {
    var src = contentField.getAttribute("src");
    if(src && src != "") {
      iframe.src = src
    }
  }
  this._loadCallback = this.createCallback(this._handleLoad);
  agent.addBubbleEventListener(iframe, "load", this._loadCallback);
  contentField.parentNode.replaceChild(iframe, contentField);
  agent.elementsRemoved(contentField);
  agent.elementsAdded(iframe)
};
AdfDhtmlRichTextEditorPeer.prototype._makeEditable = function(component) {
  var contentField = this._getContentField(component);
  AdfAssert.assertDomElement(contentField);
  AdfEditingAgent.getInstance().setInlineFrameContentEditable(contentField);
  this._addContextChangeListeners(contentField)
};
AdfDhtmlRichTextEditorPeer.prototype._setInlineFrameContent = function(inlineFrame, content) {
  AdfAssert.assertDomElement(inlineFrame, "IFRAME");
  AdfAssert.assertString(content);
  var editingAgent = AdfEditingAgent.getInstance();
  var inlineFrameDocument = editingAgent.getInlineFrameDocument(inlineFrame);
  editingAgent.setRTL(inlineFrameDocument);
  this._setInlineFrameStyle(inlineFrameDocument);
  var inlineFrameBody = inlineFrameDocument.body;
  if(content == "") {
    content = editingAgent.getDefaultContent()
  }
  inlineFrameBody.innerHTML = content
};
AdfDhtmlRichTextEditorPeer.prototype._setInlineFrameStyle = function(inlineFrameDocument) {
  var inlineFrameBody = inlineFrameDocument.body;
  var inlineFrameBodyStyle = inlineFrameBody.style;
  var inlineFrameBodyInlineStyle = this._inlineFrameBodyInlineStyle;
  if(inlineFrameBodyInlineStyle == null) {
    var isIE = AdfAgent.AGENT.getPlatform() == AdfAgent.IE_PLATFORM;
    var page = AdfPage.PAGE;
    var laf = page.getLookAndFeel();
    inlineFrameBodyInlineStyle = laf.getSkinProperty("af|richTextEditor-tr-field-inline-style");
    if(isIE && inlineFrameBodyInlineStyle == undefined) {
      page.scheduleTimer(this, this._updateInlineFrameStyle, inlineFrameBodyInlineStyle, 0, {"isSynchronized":true})
    }else {
      this._updateInlineFrameStyle(inlineFrameBodyInlineStyle)
    }
    inlineFrameBodyStyle.cssText = this._inlineFrameBodyInlineStyle
  }else {
    inlineFrameBodyStyle.cssText = inlineFrameBodyInlineStyle
  }
};
AdfDhtmlRichTextEditorPeer.prototype._updateInlineFrameStyle = function(inlineFrameBodyInlineStyle) {
  if(inlineFrameBodyInlineStyle == undefined) {
    var laf = AdfPage.PAGE.getLookAndFeel();
    inlineFrameBodyInlineStyle = laf.getSkinProperty("af|richTextEditor-tr-field-inline-style")
  }
  inlineFrameBodyInlineStyle = inlineFrameBodyInlineStyle.replace(/ /g, ";").replace(/\+/g, " ").replace(/_/g, ":");
  this._inlineFrameBodyInlineStyle = inlineFrameBodyInlineStyle
};
AdfDhtmlRichTextEditorPeer.prototype._getContentField = function(component) {
  var subId = AdfAgent.AGENT.getExpandoProperty(AdfRichUIPeer.getDomElementForComponent(component), AdfDhtmlRichTextEditorPeer._FIELD_ID_ATTR_NAME);
  var domNode = AdfAgent.AGENT.getElementById(subId);
  AdfAssert.assertDomElement(domNode);
  return domNode
};
AdfDhtmlRichTextEditorPeer.prototype._getSourceCodeField = function(component) {
  var subId = AdfAgent.AGENT.getExpandoProperty(AdfRichUIPeer.getDomElementForComponent(component), AdfDhtmlRichTextEditorPeer._SOURCE_FIELD_ID_ATTR_NAME);
  var domNode = AdfAgent.AGENT.getElementById(subId);
  AdfAssert.assertDomElement(domNode);
  return domNode
};
AdfDhtmlRichTextEditorPeer.prototype._execCommand = function(key, value) {
  var agent = AdfAgent.AGENT;
  if(this._codeEditingMode != true || key == AdfDhtmlRichTextEditorPeer.COMMAND_MODE_RICH_TEXT || key == AdfDhtmlRichTextEditorPeer.COMMAND_INSERT) {
    AdfAssert.assertString(key);
    var command = AdfDhtmlRichTextEditorPeer._execCommandMap[key];
    AdfAssert.assertString(command);
    var component = this.getComponent();
    var element;
    if(key == AdfDhtmlRichTextEditorPeer.COMMAND_INSERT && this._codeEditingMode == true) {
      element = this._getSourceCodeField(component)
    }else {
      element = this._getContentField(component);
      AdfAssert.assertDomElement(element, "IFRAME");
      if(this._isTouch && agent.getPlatform() == AdfAgent.WEBKIT_PLATFORM) {
        element.focus()
      }
      this._restoreSelection()
    }
    var editingAgent = AdfEditingAgent.getInstance();
    if(editingAgent.isEmptySelection(element)) {
      var needExecCommand = this._invokeAdditionalCommands(component, element, command, value);
      if(needExecCommand) {
        editingAgent.execCommand(component, element, command, value)
      }
    }else {
      editingAgent.execCommand(component, element, command, value)
    }
  }
};
AdfDhtmlRichTextEditorPeer.prototype._invokeAdditionalCommands = function(component, element, command, value) {
  var commands = [];
  var tempCommand;
  var styles = [AdfDhtmlRichTextEditorPeer.STYLE_BOLD, AdfDhtmlRichTextEditorPeer.STYLE_ITALIC, AdfDhtmlRichTextEditorPeer.STYLE_UNDERLINE, AdfDhtmlRichTextEditorPeer.STYLE_STRIKETHROUGH, AdfDhtmlRichTextEditorPeer.STYLE_SUPERSCRIPT, AdfDhtmlRichTextEditorPeer.STYLE_SUBSCRIPT];
  var oldStyleValues = this._oldStyleValues;
  if(oldStyleValues == undefined) {
    return true
  }
  switch(command) {
    case "bold":
    ;
    case "italic":
    ;
    case "underline":
    ;
    case "strikethrough":
    ;
    case "superscript":
    ;
    case "subscript":
      break;
    default:
      return true
  }
  var result = true;
  var index;
  for(index = 0;index < styles.length;++index) {
    tempCommand = AdfDhtmlRichTextEditorPeer._execCommandMap[styles[index]];
    if(tempCommand == undefined) {
      continue
    }else {
      if(tempCommand == command) {
        if(oldStyleValues[styles[index]] && !this._getSelectionStyling(styles[index])) {
          result = false
        }
      }else {
        var oldValue = oldStyleValues[styles[index]];
        var selectionStyle = this._getSelectionStyling(styles[index]);
        if(!(oldValue === undefined)) {
          if(oldValue != selectionStyle) {
            commands[commands.length] = tempCommand
          }
        }
      }
    }
  }
  var editingAgent = AdfEditingAgent.getInstance();
  for(index = 0;index < commands.length;++index) {
    editingAgent.execCommand(component, element, commands[index], value)
  }
  return result
};
AdfDhtmlRichTextEditorPeer.prototype._queryCommandValue = function(key) {
  AdfAssert.assertString(key);
  var command = AdfDhtmlRichTextEditorPeer._execCommandMap[key];
  AdfAssert.assertString(command);
  var component = this.getComponent();
  var element = this._getContentField(component);
  AdfAssert.assertDomElement(element, "IFRAME");
  return AdfEditingAgent.getInstance().queryCommandValue(element, command)
};
AdfDhtmlRichTextEditorPeer.prototype._styleBindingActionListener = function(event) {
  if(this._styleObservers == undefined || this._commandBeingProcessed) {
    return
  }
  this._commandBeingProcessed = true;
  var eventComponentId = event.getSource().getClientId();
  var observers = this._styleObservers;
  var length = observers.length;
  for(var i = 0;i < length;i++) {
    var observer = observers[i];
    if(observer.componentId == eventComponentId) {
      event.setPartial(true);
      if(!this._isIgnoreNextEvent(observer.styleKey)) {
        if(observer.eventType == AdfActionEvent.ACTION_EVENT_TYPE) {
          this._toggleSelectionStyling(observer.styleKey)
        }else {
          if(observer.eventType == AdfValueChangeEvent.VALUE_CHANGE_TYPE) {
            var value = event.getNewValue();
            if(value && value._class && value._class == "TrColor") {
              var converter = new TrColorConverter(["#RRGGBB"], false);
              value = converter.getAsString(value);
              if(observer.styleKey == AdfDhtmlRichTextEditorPeer.STYLE_COLOR_BACKGROUND) {
                this._oldStyleValues[observer.styleKey] = value
              }
            }
            this._execCommand(observer.styleKey, value)
          }else {
            AdfLogger.LOGGER.severe("This eventType (", eventType, ") is not supported by richTextEditor.")
          }
        }
        this._handleContextChanged()
      }
      if(this._hadFirstFocus) {
        this.focus(this.getComponent())
      }
      event.cancel()
    }
  }
  this._updateValue();
  delete this._commandBeingProcessed
};
AdfDhtmlRichTextEditorPeer.prototype._commandBindingActionListener = function(event) {
  if(this._commandObservers == undefined || this._commandBeingProcessed) {
    return
  }
  this._commandBeingProcessed = true;
  var eventComponentId = event.getSource().getClientId();
  var observers = this._commandObservers;
  var length = observers.length;
  var insertCmdExecuted = false;
  for(var i = 0;i < length;i++) {
    var observer = observers[i];
    if(observer.componentId == eventComponentId) {
      event.setPartial(true);
      var commandKey = observer.command;
      this._execCommand(commandKey, observer.commandParameter);
      this._handleContextChanged();
      event.cancel();
      if(commandKey == AdfDhtmlRichTextEditorPeer.COMMAND_INSERT) {
        insertCmdExecuted = true
      }
    }
  }
  this._updateValue();
  if(insertCmdExecuted) {
    var component = this.getComponent();
    this.Validate(component, this.GetSubmittedValue(component, this.getDomElement()))
  }
  delete this._commandBeingProcessed
};
AdfDhtmlRichTextEditorPeer.prototype._toggleSelectionStyling = function(styleKey) {
  AdfAssert.assertString(styleKey);
  return this._execCommand(styleKey, null)
};
AdfDhtmlRichTextEditorPeer.prototype._addContextChangeListeners = function(field) {
  var component = this.getComponent();
  var agent = AdfAgent.AGENT;
  var editingAgent = AdfEditingAgent.getInstance();
  var focusBlurElement = editingAgent.getFocusBlurElement(field);
  this._focusCallback = this.createCallback(this._handleFocus);
  this._blurCallback = this.createCallback(this._handleBlur);
  if(this._isTouch && agent.getPlatform() == AdfAgent.WEBKIT_PLATFORM) {
    agent.addBubbleEventListener(field, "blur", this._blurCallback);
    var peer = this;
    this._clickCallback = this.createCallback(this._handleClick);
    agent.addBubbleEventListener(focusBlurElement, "click", this._clickCallback)
  }
  agent.addBubbleEventListener(focusBlurElement, "blur", this._blurCallback);
  agent.addBubbleEventListener(focusBlurElement, "focus", this._focusCallback);
  var sourceCodeField = this._getSourceCodeField(component);
  this._sourceBlurCallback = this.createCallback(this._handleBlur);
  this._sourceFocusCallback = this.createCallback(this._handleFocus);
  agent.addBubbleEventListener(sourceCodeField, "blur", this._sourceBlurCallback);
  agent.addBubbleEventListener(sourceCodeField, "focus", this._sourceFocusCallback);
  var doc = editingAgent.getInlineFrameDocument(field);
  this._keyDownCallback = this.createCallback(this._handleKeyDown);
  agent.addBubbleEventListener(doc, "keydown", this._keyDownCallback);
  agent.addBubbleEventListener(sourceCodeField, "keydown", this._keyDownCallback);
  this._contextChangeCallback = this.createCallback(this._handleContextChanged);
  this._mouseUpCallBack = this.createCallback(this._handleMouseUp);
  agent.addBubbleEventListener(doc, "mouseup", this._mouseUpCallBack);
  agent.addBubbleEventListener(doc, "keyup", this._contextChangeCallback);
  this._dragEndCallback = this.createCallback(this._handleDragEnd);
  agent.addBubbleEventListener(doc, "dragend", this._dragEndCallback);
  this._mouseDownCallback = this.createCallback(this._handleMouseDown);
  agent.addBubbleEventListener(this.getDomElement(), "mousedown", this._mouseDownCallback);
  if(AdfAgent.AGENT.getPlatform() != AdfAgent.IE_PLATFORM) {
    agent.addBubbleEventListener(doc, "blur", this._contextChangeCallback)
  }
  if(this._isTouch && AdfAgent.guessOS() != AdfAgent.WINDOWS_OS) {
    var peer = this;
    this._saveSelectionInterval = setInterval(function() {
      peer._saveSelection()
    }, 500);
    if(agent.getPlatform() == AdfAgent.WEBKIT_PLATFORM && agent.getVersion() < 536) {
      this._handleCopyCallback = this.createCallback(this._handleCopy);
      this.getDomDocument().addEventListener("copy", this._handleCopyCallback, true);
      this._handlePasteCallback = this.createCallback(this._handlePaste);
      this.getDomDocument().addEventListener("paste", this._handlePasteCallback, true)
    }
  }
  this._redistributeEventsToNewTargetCallback = this.createCallback(this._redistributeEventsToNewTarget);
  agent.addEventBubbles(doc, this._redistributeEventsToNewTargetCallback)
};
AdfDhtmlRichTextEditorPeer.prototype._removeContextChangeListeners = function(component) {
  var agent = AdfAgent.AGENT;
  var field = this._getContentField(component);
  var editingAgent = AdfEditingAgent.getInstance();
  var focusBlurElement = editingAgent.getFocusBlurElement(field);
  if(this._isTouch && agent.getPlatform() == AdfAgent.WEBKIT_PLATFORM) {
    agent.removeBubbleEventListener(field, "blur", this._blurCallback);
    if(AdfAgent.guessOS() != AdfAgent.ANDROID_OS) {
      agent.removeBubbleEventListener(focusBlurElement, "blur", this._iOSBlurCallback)
    }
    agent.removeBubbleEventListener(focusBlurElement, "click", this._clickCallback);
    delete this._clickCallback
  }else {
    agent.removeBubbleEventListener(focusBlurElement, "blur", this._blurCallback)
  }
  delete this._blurCallback;
  agent.removeBubbleEventListener(focusBlurElement, "focus", this._focusCallback);
  delete this._focusCallback;
  var sourceCodeField = this._getSourceCodeField(component);
  agent.removeBubbleEventListener(sourceCodeField, "blur", this._sourceBlurCallback);
  delete this._sourceBlurCallback;
  agent.removeBubbleEventListener(sourceCodeField, "focus", this._sourceFocusCallback);
  delete this._sourceFocusCallback;
  var doc = editingAgent.getInlineFrameDocument(field);
  agent.removeBubbleEventListener(doc, "mouseup", this._mouseUpCallBack);
  delete this._mouseUpCallBack;
  agent.removeBubbleEventListener(doc, "keyup", this._contextChangeCallback);
  if(AdfAgent.AGENT.getPlatform() != AdfAgent.IE_PLATFORM) {
    agent.removeBubbleEventListener(doc, "blur", this._contextChangeCallback)
  }
  delete this._contextChangeCallback;
  agent.removeBubbleEventListener(doc, "keydown", this._keyDownCallback);
  delete this._keyDownCallback;
  agent.removeEventBubbles(doc, this._redistributeEventsToNewTargetCallback);
  delete this._redistributeEventsToNewTargetCallback;
  if(this._isTouch && this._saveSelectionInterval) {
    clearInterval(this._saveSelectionInterval)
  }
};
AdfDhtmlRichTextEditorPeer.prototype._redistributeEventsToNewTarget = function(evt) {
  var comp = this.getComponent();
  if(!evt) {
    evt = this._getContentField(comp).contentWindow.event
  }
  var agent = AdfAgent.AGENT;
  if(agent.isKeyboardEvent(evt) || agent.isMouseEvent(evt)) {
    var newEvent = AdfAgent.AGENT.cloneEvent(evt, this._getSourceCodeField(comp));
    if(!this._clonedEventMap) {
      this._clonedEventMap = new Array
    }
    this._clonedEventMap[newEvent] = evt;
    AdfPage.PAGE._redistribute(newEvent)
  }
};
AdfDhtmlRichTextEditorPeer.prototype._handleFocus = function(evt) {
  var agent = AdfAgent.AGENT;
  if(!this._commandBeingProcessed) {
    var component = this.getComponent();
    if(!this._hadFirstFocus) {
      this._hadFirstFocus = true
    }
    var componentEvent = AdfAgent.AGENT.getComponentEvent(component, evt);
    var field = this._getContentField(component);
    AdfPage.PAGE.__setActiveDomNodeInfo(field, component.getClientId());
    var focusTarget;
    if(this._codeEditingMode) {
      focusTarget = this._getSourceCodeField(component)
    }else {
      focusTarget = AdfEditingAgent.getInstance().getContentWindow(field);
      focusTarget = focusTarget.document
    }
    if(focusTarget == evt.originalTarget && componentEvent.getEventPhase() == AdfBaseEvent.CAPTURING_PHASE) {
      componentEvent.nextEventPhase()
    }
    this.HandleComponentFocus(componentEvent)
  }
  if(this._isTouch && agent.getPlatform() == AdfAgent.WEBKIT_PLATFORM && AdfAgent.guessOS() != AdfAgent.ANDROID_OS) {
    if(agent._getTouchEventListeners) {
      var touchEventListeners = agent._getTouchEventListeners();
      if(touchEventListeners) {
        for(var i = 0;i < touchEventListeners.length;i++) {
          this.getDomDocument().removeEventListener(touchEventListeners[i].eventType, touchEventListeners[i].listener, touchEventListeners[i].capture)
        }
      }
    }
  }
};
AdfDhtmlRichTextEditorPeer.prototype._handleLoad = function(nativeEvent) {
  var editingAgent = AdfEditingAgent.getInstance();
  var component = this.getComponent();
  AdfAssert.assertObject(component, "Unexpected unbound peer for load event on iframe.");
  var contentField = this._getContentField(component);
  AdfAssert.assertDomElement(contentField);
  var needsDesignMode = !component.getDisabled() && !editingAgent.isDesignMode(contentField);
  if(editingAgent.isDesignModeReloadingFrame()) {
    if(needsDesignMode) {
      this._makeEditable(component);
      return
    }
  }
  var hiddenInputElement = this._getSourceCodeField(component);
  AdfAssert.assertDomElement(hiddenInputElement);
  if(component.getContentDelivery() != "lazy") {
    this._setInlineFrameContent(contentField, hiddenInputElement.value)
  }else {
    var value = this.getCurrentContent(component, true);
    hiddenInputElement.value = value;
    var inlineFrameDocument = editingAgent.getInlineFrameDocument(contentField);
    this._setInlineFrameStyle(inlineFrameDocument)
  }
  if(needsDesignMode) {
    this._makeEditable(component)
  }
  if(!component.getReadOnly()) {
    AdfRichTextEditorBehaviorManager.getInstance().registerComponent(component)
  }
  contentField.setAttribute("data-afr-rte-loaded", "1")
};
AdfDhtmlRichTextEditorPeer.prototype._handleBlur = function(evt) {
  var agent = AdfAgent.AGENT;
  if(!this._commandBeingProcessed) {
    var component = this.getComponent();
    var contentNode = this._getContentField(component);
    var lastValue = AdfDhtmlInputBasePeer.getLastValue(contentNode);
    if(this._tabForward) {
      delete this._tabForward;
      AdfFocusUtils.focusNextTabStop(AdfPage.PAGE.getActiveDomElement())
    }else {
      if(this._tabBack) {
        delete this._tabBack;
        AdfFocusUtils.focusPreviousTabStop(AdfPage.PAGE.getActiveDomElement())
      }
    }
    this._updateValue();
    if(this._mouseDownOrTabBack) {
      delete this._mouseDownOrTabBack
    }
    var isValueChanged = false;
    var newValue = this._getSourceCodeField(component).value;
    if(lastValue != newValue && !(lastValue === undefined)) {
      isValueChanged = true
    }
    if(isValueChanged && (!this._mouseDownOrTabBack || !component.getValid(component.getClientId()))) {
      this.Validate(component, this.GetSubmittedValue(component, this.getDomElement()));
      AdfDhtmlInputBasePeer.setLastValue(contentNode, newValue)
    }
  }
  if(this._isTouch && agent.getPlatform() == AdfAgent.WEBKIT_PLATFORM && AdfAgent.guessOS() != AdfAgent.ANDROID_OS) {
    this._keyboardClose();
    if(agent._getTouchEventListeners) {
      var touchEventListeners = agent._getTouchEventListeners();
      if(touchEventListeners) {
        for(var i = 0;i < touchEventListeners.length;i++) {
          this.getDomDocument().addEventListener(touchEventListeners[i].eventType, touchEventListeners[i].listener, touchEventListeners[i].capture)
        }
      }
    }
  }
};
AdfDhtmlRichTextEditorPeer.prototype._handleClick = function(evt) {
  this.Focus()
};
AdfDhtmlRichTextEditorPeer.prototype._handleMouseDown = function(evt) {
  this._mouseDownOrTabBack = true
};
AdfDhtmlRichTextEditorPeer.prototype._handleDragEnd = function(evt) {
  if(AdfAgent.AGENT.getPlatform() == AdfAgent.IE_PLATFORM) {
    var time = this._keyTimer;
    if(time) {
      clearTimeout(time)
    }
    AdfPage.PAGE.scheduleTimer(this, AdfDhtmlRichTextEditorPeer.HandleTimerUpdate, this.getComponent().getClientId(), 0)
  }else {
    this._handleContextChanged()
  }
};
AdfDhtmlRichTextEditorPeer.prototype._handleCopy = function(event) {
  if(event.clipboardData && this._lastSelectionRange != null) {
    if(!this._isInPopup() && AdfPage.PAGE.getModalityManager().isGlassPaneVisible()) {
      return
    }
    var document = this.getDomDocument();
    var copyElement = document.createElement("div");
    copyElement.style.position = "absolute";
    copyElement.style.left = "-1000px";
    copyElement.style.top = "-1000px";
    copyElement.contentEditable = "true";
    copyElement.textContent = this._lastSelectionRange.toString();
    document.body.appendChild(copyElement);
    var rangeToSelect = document.createRange();
    rangeToSelect.selectNodeContents(copyElement);
    var selection = window.getSelection();
    selection.removeAllRanges();
    selection.addRange(rangeToSelect);
    document.execCommand("copy", false, null);
    setTimeout(function() {
      document.body.removeChild(copyElement)
    }, 500)
  }
};
AdfDhtmlRichTextEditorPeer.prototype._handlePaste = function(event) {
  var agent = AdfAgent.AGENT;
  if(event.clipboardData) {
    if(!this._isInPopup() && AdfPage.PAGE.getModalityManager().isGlassPaneVisible()) {
      return
    }
    if(this._isInPopup() && agent.getPlatform() == AdfAgent.WEBKIT_PLATFORM && agent.getVersion() < 536) {
      if(this._hasPasteEvent) {
        return
      }else {
        this._hasPasteEvent = true;
        var peer = this;
        setTimeout(function() {
          delete peer._hasPasteEvent
        }, 500)
      }
    }
    var pasteText = event.clipboardData.getData("Text");
    this._execCommand("cmd_insert", pasteText)
  }
};
AdfDhtmlRichTextEditorPeer.prototype._updateValue = function() {
  var component = this.getComponent();
  var richTextField = this._getContentField(component);
  if(this._keyTimer) {
    clearTimeout(this._keyTimer);
    delete this._keyTimer
  }
  if(richTextField.style.display != "none") {
    var contentNode = this._getSourceCodeField(component);
    var editingAgent = AdfEditingAgent.getInstance();
    var newValue = this.getCurrentContent(component);
    var agentName = navigator.userAgent.toLowerCase();
    if(agentName.indexOf("chrome") != -1 && newValue.includes("span")) {
      newValue = newValue.replace(/; /gi, ";").replace(/: /gi, ":")
    }
    contentNode.value = newValue;
    editingAgent.updateValueHistory(component, richTextField, newValue)
  }
};
AdfDhtmlRichTextEditorPeer.prototype._getSelectionStyling = function(styleKey) {
  AdfAssert.assertString(styleKey);
  var commandIdentifier = AdfDhtmlRichTextEditorPeer._execCommandMap[styleKey];
  AdfAssert.assertString(commandIdentifier);
  return AdfEditingAgent.getInstance().queryCommandState(this._getContentField(this.getComponent()), commandIdentifier)
};
AdfDhtmlRichTextEditorPeer.prototype._getIndeterminateStyling = function(styleKey) {
  AdfAssert.assertString(styleKey);
  var commandIdentifier = AdfDhtmlRichTextEditorPeer._execCommandMap[styleKey];
  AdfAssert.assertString(commandIdentifier);
  return AdfEditingAgent.getInstance().queryCommandIndeterminate(this._getContentField(this.getComponent()), commandIdentifier)
};
AdfDhtmlRichTextEditorPeer.prototype._addStyleBinding = function(componentId, propertyName, styleKey, eventType) {
  AdfAssert.assertString(componentId);
  AdfAssert.assertString(propertyName);
  AdfAssert.assertString(styleKey);
  AdfAssert.assertStringOrNull(eventType);
  if(eventType == undefined) {
    eventType = AdfActionEvent.ACTION_EVENT_TYPE
  }
  var bindComponent = AdfPage.PAGE.findComponent(componentId);
  var styleObserver = {componentId:componentId, propertyName:propertyName, styleKey:styleKey, eventType:eventType};
  if(!this._styleObservers) {
    this._styleObservers = new Array
  }
  this._styleObservers.push(styleObserver);
  if(eventType != AdfActionEvent.ACTION_EVENT_TYPE || !bindComponent.isDescendant(this.getComponent())) {
    bindComponent.addEventListener(eventType, this._styleBindingActionListener, this)
  }
};
AdfDhtmlRichTextEditorPeer.prototype._removeStyleBindings = function(component) {
  var observers = this._styleObservers;
  if(observers == undefined) {
    return
  }
  var length = observers.length;
  var listener = this._styleBindingActionListener;
  for(var i = 0;i < length;i++) {
    var observer = observers[i];
    var boundComponent = AdfPage.PAGE.findComponent(observer.componentId);
    if(boundComponent != undefined) {
      if(observer.eventType != AdfActionEvent.ACTION_EVENT_TYPE || !boundComponent.isDescendant(component)) {
        boundComponent.removeEventListener(observer.eventType, listener, this)
      }
    }
  }
};
AdfDhtmlRichTextEditorPeer.prototype._addCommandBinding = function(componentId, bindComponent, command, commandParameter) {
  AdfAssert.assertString(componentId);
  AdfAssert.assertString(command);
  if(!this._commandObservers) {
    this._commandObservers = new Array
  }
  var length = this._commandObservers.length;
  var commandObserver = null;
  for(var i = 0;i < length;i++) {
    var observerObj = this._commandObservers[i];
    if(observerObj.componentId == componentId && observerObj.command == command) {
      observerObj.commandParameter = commandParameter;
      commandObserver = observerObj;
      break
    }
  }
  if(commandObserver == null) {
    commandObserver = {componentId:componentId, command:command, commandParameter:commandParameter};
    this._commandObservers.push(commandObserver)
  }
  if(!bindComponent.isDescendant(this.getComponent())) {
    bindComponent.addEventListener(AdfActionEvent.ACTION_EVENT_TYPE, this._commandBindingActionListener, this)
  }
};
AdfDhtmlRichTextEditorPeer.prototype._removeCommandBindings = function(component) {
  var observers = this._commandObservers;
  if(observers == undefined) {
    return
  }
  var length = observers.length;
  var listener = this._commandBindingActionListener;
  for(var i = 0;i < length;i++) {
    var observer = observers[i];
    var boundComponent = AdfPage.PAGE.findComponent(observer.componentId);
    if(boundComponent != undefined) {
      if(!boundComponent.isDescendant(component)) {
        boundComponent.removeEventListener(AdfActionEvent.ACTION_EVENT_TYPE, listener, this)
      }
    }
  }
};
AdfDhtmlRichTextEditorPeer.prototype._ignoreNextEvent = function(styleKey) {
  AdfAssert.assertString(styleKey);
  if(this._ignoreEvents[styleKey] == undefined) {
    this._ignoreEvents[styleKey] = 0
  }
  this._ignoreEvents[styleKey]++
};
AdfDhtmlRichTextEditorPeer.prototype._isIgnoreNextEvent = function(styleKey) {
  AdfAssert.assertString(styleKey);
  if(this._ignoreEvents[styleKey] == undefined || this._ignoreEvents[styleKey] == 0) {
    return false
  }else {
    this._ignoreEvents[styleKey]--;
    return true
  }
};
AdfDhtmlRichTextEditorPeer.prototype._isInPopup = function() {
  var parent = null;
  try {
    parent = this.getComponent().getParent()
  }catch(err) {
  }
  if(parent == null) {
    return false
  }
  while(parent != null) {
    if(parent instanceof AdfRichPopup) {
      return true
    }else {
      try {
        parent = parent.getParent()
      }catch(err) {
        return false
      }
    }
    if(parent == null) {
      return false
    }
  }
};
AdfDhtmlRichTextEditorPeer.prototype._keyboardClose = function() {
  var editingAgent = AdfEditingAgent.getInstance();
  var inlineFrame = this._getContentField(this.getComponent());
  var domDoc = editingAgent.getInlineFrameDocument(inlineFrame);
  var focusBlurElement = editingAgent.getFocusBlurElement(inlineFrame);
  var inputElement = domDoc.createElement("input");
  inputElement.type = "text";
  inputElement.style.position = "absolute";
  inputElement.style.left = "0px";
  inputElement.style.top = "0px";
  inputElement.style.height = "0px";
  inputElement.style.width = "0px";
  inputElement.style.opacity = "0";
  focusBlurElement.appendChild(inputElement);
  inputElement.focus();
  inputElement.blur();
  focusBlurElement.removeChild(inputElement)
};
AdfDhtmlRichTextEditorPeer.prototype._emptySelection = function(selRange) {
  return!selRange || AdfEditingAgent.getInstance().getSelectionRangeString(selRange).length == 0
};
AdfDhtmlRichTextEditorPeer.prototype._toolbarPopupURLBlur = function(componentEvent) {
  if(componentEvent.getEventPhase() == AdfBaseEvent.AT_TARGET_PHASE) {
    var selRange = this._lastSelectionRange;
    if(this._emptySelection(selRange)) {
      return
    }
    var target = componentEvent.getCurrentTarget();
    var value = target.getValue();
    if(value === "about:blank") {
      return
    }
    if(!/^http:\/\//.test(value)) {
      value = "http://" + value
    }
    this._execCommand(AdfDhtmlRichTextEditorPeer.COMMAND_LINK, value);
    this._saveSelection()
  }
};
AdfDhtmlRichTextEditorPeer.prototype._toolbarPopupDisplayedTextBlur = function(componentEvent) {
  if(componentEvent.getEventPhase() == AdfBaseEvent.AT_TARGET_PHASE) {
    var selRange = this._lastSelectionRange;
    var editingAgent = AdfEditingAgent.getInstance();
    if(this._emptySelection(selRange)) {
      return
    }
    var target = componentEvent.getCurrentTarget();
    var value = target.getValue();
    var selectionRangeString = editingAgent.getSelectionRangeString(selRange);
    if(value === selectionRangeString) {
      return
    }
    this._execCommand(AdfDhtmlRichTextEditorPeer.COMMAND_INSERT, value)
  }
};
AdfDhtmlRichTextEditorPeer.prototype._getToolbarPopupNode = function(component) {
  return AdfAgent.AGENT.getElementById(AdfRichUIPeer.CreateSubId(component.getClientId(), AdfDhtmlRichTextEditorPeer._TOOLBAR_POPUP_CONTAINER_ID))
};
AdfDhtmlRichTextEditorPeer.prototype._getToolbarPopupInputContainer = function(component) {
  return AdfAgent.AGENT.getElementById(component.getId() + AdfDhtmlRichTextEditorPeer._TOOLBAR_POPUP_INPUT_CONTAINER_ID)
};
AdfDhtmlRichTextEditorPeer.prototype._getToolbarPopupURLComp = function(component) {
  return AdfPage.PAGE.findComponent(component.getId() + AdfDhtmlRichTextEditorPeer._TOOLBAR_POPUP_LINK_INPUT_ID)
};
AdfDhtmlRichTextEditorPeer.prototype._getToolbarPopupDisplayedTextComp = function(component) {
  return AdfPage.PAGE.findComponent(component.getId() + AdfDhtmlRichTextEditorPeer._TOOLBAR_POPUP_LINK_SELECTED_INPUT_ID)
};
AdfDhtmlRichTextEditorPeer.prototype._showToolbarPopup = function(nativeEvent) {
  var agent = AdfAgent.AGENT, component = this.getComponent(), clientId = component.getClientId(), alignDom = agent.getElementById(AdfRichUIPeer.CreateSubId(clientId, AdfDhtmlRichTextEditorPeer._CONTENT_INPUT_CONTAINER_SUBID)), toolbarPopupNode = this._getToolbarPopupNode(component), hints = {};
  hints[AdfDhtmlPopupHints.AUTODISMISS] = AdfDhtmlPopupHints.AUTODISMISS_ALWAYS;
  hints[AdfDhtmlPopupHints.ALIGN_ELEMENT] = alignDom;
  hints[AdfRichPopup.HINT_ALIGN] = AdfRichPopup.ALIGN_BEFORE_START;
  hints[AdfDhtmlPopupHints.FOCUS] = false;
  AdfDomUtils.setVisible(toolbarPopupNode, true);
  if(!this._toolbarPopupListenerInitialized) {
    var dtComp = this._getToolbarPopupDisplayedTextComp(component);
    var urlComp = this._getToolbarPopupURLComp(component);
    var selectTextHandler = function(componentEvent) {
      var comp = componentEvent.getCurrentTarget();
      AdfDhtmlEditableValuePeer.getContentNode(comp, comp.getPeer().getDomElement()).select()
    };
    urlComp.addEventListener(AdfUIInputEvent.BLUR_EVENT_TYPE, this._toolbarPopupURLBlur, this);
    urlComp.addEventListener(AdfUIInputEvent.FOCUS_EVENT_TYPE, selectTextHandler, this);
    dtComp.addEventListener(AdfUIInputEvent.BLUR_EVENT_TYPE, this._toolbarPopupDisplayedTextBlur, this);
    dtComp.addEventListener(AdfUIInputEvent.FOCUS_EVENT_TYPE, selectTextHandler, this);
    this._toolbarPopupListenerInitialized = true
  }
  this.showPopup(component, toolbarPopupNode, hints, clientId)
};
AdfDhtmlRichTextEditorPeer.prototype.PopupClosed = function(component, contentDom, popupId) {
  AdfDhtmlRichTextEditorPeer.superclass.PopupClosed.call(this, component, contentDom);
  var popupDom = this._getToolbarPopupNode(component);
  if(popupDom == contentDom && AdfDomUtils.isVisible(popupDom)) {
    var agent = AdfAgent.AGENT;
    var compId = component.getId();
    var clientId = this.getComponent().getClientId();
    var contentNode = agent.getElementById(AdfRichUIPeer.CreateSubId(clientId, "content"));
    var cicNode = agent.getElementById(AdfRichUIPeer.CreateSubId(clientId, AdfDhtmlRichTextEditorPeer._CONTENT_INPUT_CONTAINER_SUBID));
    var contNode = agent.getElementById(compId + AdfDhtmlRichTextEditorPeer._TOOLBAR_POPUP_INPUT_CONTAINER_ID);
    contentNode.insertBefore(contentDom, cicNode);
    AdfDomUtils.setVisible(contNode, false);
    AdfDomUtils.setVisible(contentDom, false)
  }
};
AdfDhtmlRichTextEditorPeer.prototype._updateToolbarPopupURLVal = function() {
  var component = this.getComponent();
  var contNode = this._getToolbarPopupInputContainer(component);
  if(AdfDomUtils.isVisible(contNode)) {
    var inputComp = this._getToolbarPopupURLComp(component);
    var currentLinkURL = AdfEditingAgent.getInstance()._getLinkURLForSelection(component, this._getContentField(component));
    inputComp.setValue(currentLinkURL)
  }
};
AdfDhtmlRichTextEditorPeer.prototype._processToolbarPopupAddLinkCmd = function(currentLinkURL) {
  var component = this.getComponent();
  var selRange = this._lastSelectionRange;
  var editingAgent = AdfEditingAgent.getInstance();
  if(this._emptySelection(selRange)) {
    return
  }
  var contNode = this._getToolbarPopupInputContainer(component);
  if(AdfDomUtils.isVisible(contNode)) {
    AdfDomUtils.setVisible(contNode, false);
    return
  }
  var dtComp = this._getToolbarPopupDisplayedTextComp(component);
  var inputComp = this._getToolbarPopupURLComp(component);
  dtComp.setValue(editingAgent.getSelectionRangeString(selRange));
  inputComp.setValue(currentLinkURL);
  AdfDomUtils.setVisible(contNode, true)
};
