зеркало из https://github.com/mozilla/pjs.git
Bug 552914 nsEditor::mFlags is never modified by SetFlags() r=smaug
This commit is contained in:
Родитель
213ecdd292
Коммит
42aa94a56a
|
@ -44,18 +44,34 @@ interface nsIPlaintextEditor : nsISupports
|
|||
{
|
||||
|
||||
// XXX Why aren't these in nsIEditor?
|
||||
const long eEditorPlaintextMask = 0x0001; /* only plain text entry is allowed via events */
|
||||
const long eEditorSingleLineMask = 0x0002; /* enter key and CR-LF handled specially */
|
||||
const long eEditorPasswordMask = 0x0004; /* text is not entered into content, only a representative character */
|
||||
const long eEditorReadonlyMask = 0x0008; /* editing events are disabled. Editor may still accept focus. */
|
||||
const long eEditorDisabledMask = 0x0010; /* all events are disabled (like scrolling). Editor will not accept focus. */
|
||||
const long eEditorFilterInputMask = 0x0020; /* text input is limited to certain character types, use mFilter */
|
||||
const long eEditorMailMask = 0x0040; /* use mail-compose editing rules */
|
||||
const long eEditorUseAsyncUpdatesMask = 0x0080; /* prevent immediate reflows and view refreshes */
|
||||
const long eEditorEnableWrapHackMask = 0x0100; /* allow the editor to set font: monospace on the root node */
|
||||
const long eEditorWidgetMask = 0x0200; /* bit for widgets */
|
||||
const long eEditorNoCSSMask = 0x0400; /* this HTML editor should not create css styles */
|
||||
const long eEditorAllowInteraction = 0x0800; /* */
|
||||
// only plain text entry is allowed via events
|
||||
const long eEditorPlaintextMask = 0x0001;
|
||||
// enter key and CR-LF handled specially
|
||||
const long eEditorSingleLineMask = 0x0002;
|
||||
// text is not entered into content, only a representative character
|
||||
const long eEditorPasswordMask = 0x0004;
|
||||
// editing events are disabled. Editor may still accept focus.
|
||||
const long eEditorReadonlyMask = 0x0008;
|
||||
// all events are disabled (like scrolling). Editor will not accept focus.
|
||||
const long eEditorDisabledMask = 0x0010;
|
||||
// text input is limited to certain character types, use mFilter
|
||||
const long eEditorFilterInputMask = 0x0020;
|
||||
// use mail-compose editing rules
|
||||
const long eEditorMailMask = 0x0040;
|
||||
// prevent immediate reflows and view refreshes
|
||||
const long eEditorUseAsyncUpdatesMask = 0x0080;
|
||||
// allow the editor to set font: monospace on the root node
|
||||
const long eEditorEnableWrapHackMask = 0x0100;
|
||||
// bit for widgets (form elements)
|
||||
const long eEditorWidgetMask = 0x0200;
|
||||
// this HTML editor should not create css styles
|
||||
const long eEditorNoCSSMask = 0x0400;
|
||||
// whether HTML document specific actions are executed or not.
|
||||
// e.g., if this flag is set, the editor doesn't handle Tab key.
|
||||
// besides, anchors of HTML are not clickable.
|
||||
const long eEditorAllowInteraction = 0x0800;
|
||||
// when this is set, the characters in password editor are always masked.
|
||||
// see bug 530367 for the detail.
|
||||
const long eEditorDontEchoPassword = 0x1000;
|
||||
|
||||
/*
|
||||
|
|
|
@ -38,10 +38,10 @@
|
|||
#ifndef nsEditRules_h__
|
||||
#define nsEditRules_h__
|
||||
|
||||
// 783223c9-153a-4e01-8422-39a3afe469da
|
||||
// FB45AC36-E8F1-44ae-8FB7-466E1BE119B0
|
||||
#define NS_IEDITRULES_IID \
|
||||
{ 0x783223c9, 0x153a, 0x4e01, \
|
||||
{ 0x84, 0x22, 0x39, 0xa3, 0xaf, 0xe4, 0x69, 0xda } }
|
||||
{ 0xfb45ac36, 0xe8f1, 0x44ae, \
|
||||
{ 0x8f, 0xb7, 0x46, 0x6e, 0x1b, 0xe1, 0x19, 0xb0 } }
|
||||
|
||||
class nsPlaintextEditor;
|
||||
class nsISelection;
|
||||
|
@ -72,14 +72,12 @@ public:
|
|||
//Interfaces for addref and release and queryinterface
|
||||
//NOTE: Use NS_DECL_ISUPPORTS_INHERITED in any class inherited from nsIEditRules
|
||||
|
||||
NS_IMETHOD Init(nsPlaintextEditor *aEditor, PRUint32 aFlags)=0;
|
||||
NS_IMETHOD Init(nsPlaintextEditor *aEditor)=0;
|
||||
NS_IMETHOD DetachEditor()=0;
|
||||
NS_IMETHOD BeforeEdit(PRInt32 action, nsIEditor::EDirection aDirection)=0;
|
||||
NS_IMETHOD AfterEdit(PRInt32 action, nsIEditor::EDirection aDirection)=0;
|
||||
NS_IMETHOD WillDoAction(nsISelection *aSelection, nsRulesInfo *aInfo, PRBool *aCancel, PRBool *aHandled)=0;
|
||||
NS_IMETHOD DidDoAction(nsISelection *aSelection, nsRulesInfo *aInfo, nsresult aResult)=0;
|
||||
NS_IMETHOD GetFlags(PRUint32 *aFlags)=0;
|
||||
NS_IMETHOD SetFlags(PRUint32 aFlags)=0;
|
||||
NS_IMETHOD DocumentIsEmpty(PRBool *aDocumentIsEmpty)=0;
|
||||
};
|
||||
|
||||
|
|
|
@ -231,10 +231,13 @@ nsEditor::Init(nsIDOMDocument *aDoc, nsIPresShell* aPresShell, nsIContent *aRoot
|
|||
if ((nsnull==aDoc) || (nsnull==aPresShell))
|
||||
return NS_ERROR_NULL_POINTER;
|
||||
|
||||
mFlags = aFlags;
|
||||
mDocWeak = do_GetWeakReference(aDoc); // weak reference to doc
|
||||
mPresShellWeak = do_GetWeakReference(aPresShell); // weak reference to pres shell
|
||||
mSelConWeak = do_GetWeakReference(aSelCon); // weak reference to selectioncontroller
|
||||
|
||||
nsresult rv = SetFlags(aFlags);
|
||||
NS_ASSERTION(NS_SUCCEEDED(rv), "SetFlags() failed");
|
||||
|
||||
nsCOMPtr<nsIPresShell> ps = do_QueryReferent(mPresShellWeak);
|
||||
if (!ps) return NS_ERROR_NOT_INITIALIZED;
|
||||
|
||||
|
@ -483,11 +486,7 @@ nsEditor::GetDesiredSpellCheckState()
|
|||
|
||||
// Check for password/readonly/disabled, which are not spellchecked
|
||||
// regardless of DOM
|
||||
PRUint32 flags;
|
||||
if (NS_SUCCEEDED(GetFlags(&flags)) &&
|
||||
flags & (nsIPlaintextEditor::eEditorPasswordMask |
|
||||
nsIPlaintextEditor::eEditorReadonlyMask |
|
||||
nsIPlaintextEditor::eEditorDisabledMask)) {
|
||||
if (IsPasswordEditor() || IsReadonly() || IsDisabled()) {
|
||||
return PR_FALSE;
|
||||
}
|
||||
|
||||
|
@ -2115,8 +2114,9 @@ nsEditor::ForceCompositionEnd()
|
|||
#endif
|
||||
|
||||
#ifdef XP_UNIX
|
||||
if(mFlags & nsIPlaintextEditor::eEditorPasswordMask)
|
||||
return NS_OK;
|
||||
if(IsPasswordEditor()) {
|
||||
return NS_OK;
|
||||
}
|
||||
#endif
|
||||
|
||||
nsCOMPtr<nsIWidget> widget;
|
||||
|
@ -2139,12 +2139,7 @@ nsEditor::GetPreferredIMEState(PRUint32 *aState)
|
|||
NS_ENSURE_ARG_POINTER(aState);
|
||||
*aState = nsIContent::IME_STATUS_ENABLE;
|
||||
|
||||
PRUint32 flags;
|
||||
nsresult rv = GetFlags(&flags);
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
|
||||
if (flags & (nsIPlaintextEditor::eEditorReadonlyMask |
|
||||
nsIPlaintextEditor::eEditorDisabledMask)) {
|
||||
if (IsReadonly() || IsDisabled()) {
|
||||
*aState = nsIContent::IME_STATUS_DISABLE;
|
||||
return NS_OK;
|
||||
}
|
||||
|
@ -2157,7 +2152,7 @@ nsEditor::GetPreferredIMEState(PRUint32 *aState)
|
|||
|
||||
switch (frame->GetStyleUIReset()->mIMEMode) {
|
||||
case NS_STYLE_IME_MODE_AUTO:
|
||||
if (flags & (nsIPlaintextEditor::eEditorPasswordMask))
|
||||
if (IsPasswordEditor())
|
||||
*aState = nsIContent::IME_STATUS_PASSWORD;
|
||||
break;
|
||||
case NS_STYLE_IME_MODE_DISABLED:
|
||||
|
|
|
@ -43,6 +43,7 @@
|
|||
#include "nsWeakReference.h"
|
||||
|
||||
#include "nsIEditor.h"
|
||||
#include "nsIPlaintextEditor.h"
|
||||
#include "nsIEditorIMESupport.h"
|
||||
#include "nsIPhonetic.h"
|
||||
|
||||
|
@ -580,6 +581,72 @@ public:
|
|||
// Fast non-refcounting editor root element accessor
|
||||
nsIDOMElement *GetRoot();
|
||||
|
||||
// Accessor methods to flags
|
||||
PRBool IsPlaintextEditor() const
|
||||
{
|
||||
return (mFlags & nsIPlaintextEditor::eEditorPlaintextMask) != 0;
|
||||
}
|
||||
|
||||
PRBool IsSingleLineEditor() const
|
||||
{
|
||||
return (mFlags & nsIPlaintextEditor::eEditorSingleLineMask) != 0;
|
||||
}
|
||||
|
||||
PRBool IsPasswordEditor() const
|
||||
{
|
||||
return (mFlags & nsIPlaintextEditor::eEditorPasswordMask) != 0;
|
||||
}
|
||||
|
||||
PRBool IsReadonly() const
|
||||
{
|
||||
return (mFlags & nsIPlaintextEditor::eEditorReadonlyMask) != 0;
|
||||
}
|
||||
|
||||
PRBool IsDisabled() const
|
||||
{
|
||||
return (mFlags & nsIPlaintextEditor::eEditorDisabledMask) != 0;
|
||||
}
|
||||
|
||||
PRBool IsInputFiltered() const
|
||||
{
|
||||
return (mFlags & nsIPlaintextEditor::eEditorFilterInputMask) != 0;
|
||||
}
|
||||
|
||||
PRBool IsMailEditor() const
|
||||
{
|
||||
return (mFlags & nsIPlaintextEditor::eEditorMailMask) != 0;
|
||||
}
|
||||
|
||||
PRBool UseAsyncUpdate() const
|
||||
{
|
||||
return (mFlags & nsIPlaintextEditor::eEditorUseAsyncUpdatesMask) != 0;
|
||||
}
|
||||
|
||||
PRBool IsWrapHackEnabled() const
|
||||
{
|
||||
return (mFlags & nsIPlaintextEditor::eEditorEnableWrapHackMask) != 0;
|
||||
}
|
||||
|
||||
PRBool IsFormWidget() const
|
||||
{
|
||||
return (mFlags & nsIPlaintextEditor::eEditorWidgetMask) != 0;
|
||||
}
|
||||
|
||||
PRBool NoCSS() const
|
||||
{
|
||||
return (mFlags & nsIPlaintextEditor::eEditorNoCSSMask) != 0;
|
||||
}
|
||||
|
||||
PRBool IsInteractionAllowed() const
|
||||
{
|
||||
return (mFlags & nsIPlaintextEditor::eEditorAllowInteraction) != 0;
|
||||
}
|
||||
|
||||
PRBool DontEchoPassword() const
|
||||
{
|
||||
return (mFlags & nsIPlaintextEditor::eEditorDontEchoPassword) != 0;
|
||||
}
|
||||
|
||||
protected:
|
||||
|
||||
PRUint32 mModCount; // number of modifications (for undo/redo stack)
|
||||
|
|
|
@ -178,30 +178,20 @@ nsEditorEventListener::KeyPress(nsIDOMEvent* aKeyEvent)
|
|||
return NS_OK;
|
||||
}
|
||||
|
||||
// we should check a flag here to see if we should be using built-in key bindings
|
||||
// mEditor->GetFlags(&flags);
|
||||
// if (flags & ...)
|
||||
|
||||
PRUint32 keyCode;
|
||||
keyEvent->GetKeyCode(&keyCode);
|
||||
|
||||
// if we are readonly or disabled, then do nothing.
|
||||
PRUint32 flags;
|
||||
if (NS_SUCCEEDED(mEditor->GetFlags(&flags)))
|
||||
nsEditor* editor = static_cast<nsEditor*>(mEditor);
|
||||
if (editor->IsReadonly() || editor->IsDisabled())
|
||||
{
|
||||
if (flags & nsIPlaintextEditor::eEditorReadonlyMask ||
|
||||
flags & nsIPlaintextEditor::eEditorDisabledMask)
|
||||
{
|
||||
// consume backspace for disabled and readonly textfields, to prevent
|
||||
// back in history, which could be confusing to users
|
||||
if (keyCode == nsIDOMKeyEvent::DOM_VK_BACK_SPACE)
|
||||
aKeyEvent->PreventDefault();
|
||||
// consume backspace for disabled and readonly textfields, to prevent
|
||||
// back in history, which could be confusing to users
|
||||
if (keyCode == nsIDOMKeyEvent::DOM_VK_BACK_SPACE)
|
||||
aKeyEvent->PreventDefault();
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
return NS_OK;
|
||||
}
|
||||
else
|
||||
return NS_ERROR_FAILURE; // Editor unable to handle this.
|
||||
|
||||
nsCOMPtr<nsIPlaintextEditor> textEditor (do_QueryInterface(mEditor));
|
||||
if (!textEditor) return NS_ERROR_NO_INTERFACE;
|
||||
|
@ -262,11 +252,10 @@ nsEditorEventListener::KeyPress(nsIDOMEvent* aKeyEvent)
|
|||
break;
|
||||
|
||||
case nsIDOMKeyEvent::DOM_VK_TAB:
|
||||
if ((flags & nsIPlaintextEditor::eEditorSingleLineMask) ||
|
||||
(flags & nsIPlaintextEditor::eEditorPasswordMask) ||
|
||||
(flags & nsIPlaintextEditor::eEditorWidgetMask) ||
|
||||
(flags & nsIPlaintextEditor::eEditorAllowInteraction))
|
||||
if (editor->IsSingleLineEditor() || editor->IsPasswordEditor() ||
|
||||
editor->IsFormWidget() || editor->IsInteractionAllowed()) {
|
||||
return NS_OK; // let it be used for focus switching
|
||||
}
|
||||
|
||||
if (isAnyModifierKeyButShift)
|
||||
return NS_OK;
|
||||
|
@ -281,7 +270,7 @@ nsEditorEventListener::KeyPress(nsIDOMEvent* aKeyEvent)
|
|||
if (isAnyModifierKeyButShift)
|
||||
return NS_OK;
|
||||
|
||||
if (!(flags & nsIPlaintextEditor::eEditorSingleLineMask))
|
||||
if (!editor->IsSingleLineEditor())
|
||||
{
|
||||
textEditor->HandleKeyPress(keyEvent);
|
||||
aKeyEvent->PreventDefault(); // consumed
|
||||
|
@ -433,31 +422,25 @@ nsEditorEventListener::MouseOut(nsIDOMEvent* aMouseEvent)
|
|||
NS_IMETHODIMP
|
||||
nsEditorEventListener::HandleText(nsIDOMEvent* aTextEvent)
|
||||
{
|
||||
nsCOMPtr<nsIPrivateTextEvent> textEvent = do_QueryInterface(aTextEvent);
|
||||
if (!textEvent) {
|
||||
//non-ui event passed in. bad things.
|
||||
return NS_OK;
|
||||
}
|
||||
nsCOMPtr<nsIPrivateTextEvent> textEvent = do_QueryInterface(aTextEvent);
|
||||
if (!textEvent) {
|
||||
//non-ui event passed in. bad things.
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
nsAutoString composedText;
|
||||
nsresult result;
|
||||
nsCOMPtr<nsIPrivateTextRangeList> textRangeList;
|
||||
nsAutoString composedText;
|
||||
nsCOMPtr<nsIPrivateTextRangeList> textRangeList;
|
||||
|
||||
textEvent->GetText(composedText);
|
||||
textRangeList = textEvent->GetInputRange();
|
||||
nsCOMPtr<nsIEditorIMESupport> imeEditor = do_QueryInterface(mEditor, &result);
|
||||
if (imeEditor) {
|
||||
PRUint32 flags;
|
||||
// if we are readonly or disabled, then do nothing.
|
||||
if (NS_SUCCEEDED(mEditor->GetFlags(&flags))) {
|
||||
if (flags & nsIPlaintextEditor::eEditorReadonlyMask ||
|
||||
flags & nsIPlaintextEditor::eEditorDisabledMask) {
|
||||
return NS_OK;
|
||||
}
|
||||
}
|
||||
result = imeEditor->SetCompositionString(composedText, textRangeList);
|
||||
}
|
||||
return result;
|
||||
textEvent->GetText(composedText);
|
||||
textRangeList = textEvent->GetInputRange();
|
||||
|
||||
nsEditor* editor = static_cast<nsEditor*>(mEditor);
|
||||
// if we are readonly or disabled, then do nothing.
|
||||
if (editor->IsReadonly() || editor->IsDisabled()) {
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
return editor->SetCompositionString(composedText, textRangeList);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -617,11 +600,8 @@ nsEditorEventListener::Drop(nsIDOMDragEvent* aMouseEvent)
|
|||
if (!canDrop)
|
||||
{
|
||||
// was it because we're read-only?
|
||||
|
||||
PRUint32 flags;
|
||||
if (NS_SUCCEEDED(mEditor->GetFlags(&flags))
|
||||
&& ((flags & nsIPlaintextEditor::eEditorDisabledMask) ||
|
||||
(flags & nsIPlaintextEditor::eEditorReadonlyMask)) )
|
||||
nsEditor* editor = static_cast<nsEditor*>(mEditor);
|
||||
if (editor->IsReadonly() || editor->IsDisabled())
|
||||
{
|
||||
// it was decided to "eat" the event as this is the "least surprise"
|
||||
// since someone else handling it might be unintentional and the
|
||||
|
@ -643,12 +623,8 @@ PRBool
|
|||
nsEditorEventListener::CanDrop(nsIDOMDragEvent* aEvent)
|
||||
{
|
||||
// if the target doc is read-only, we can't drop
|
||||
PRUint32 flags;
|
||||
if (NS_FAILED(mEditor->GetFlags(&flags)))
|
||||
return PR_FALSE;
|
||||
|
||||
if ((flags & nsIPlaintextEditor::eEditorDisabledMask) ||
|
||||
(flags & nsIPlaintextEditor::eEditorReadonlyMask)) {
|
||||
nsEditor* editor = static_cast<nsEditor*>(mEditor);
|
||||
if (editor->IsReadonly() || editor->IsDisabled()) {
|
||||
return PR_FALSE;
|
||||
}
|
||||
|
||||
|
@ -669,8 +645,7 @@ nsEditorEventListener::CanDrop(nsIDOMDragEvent* aEvent)
|
|||
dragSession->IsDataFlavorSupported(kMozTextInternal, &flavorSupported);
|
||||
|
||||
// if we aren't plaintext editing, we can accept more flavors
|
||||
if (!flavorSupported
|
||||
&& (flags & nsIPlaintextEditor::eEditorPlaintextMask) == 0)
|
||||
if (!flavorSupported && !editor->IsPlaintextEditor())
|
||||
{
|
||||
dragSession->IsDataFlavorSupported(kHTMLMime, &flavorSupported);
|
||||
if (!flavorSupported)
|
||||
|
@ -760,11 +735,8 @@ nsEditorEventListener::HandleEndComposition(nsIDOMEvent* aCompositionEvent)
|
|||
*/
|
||||
|
||||
static already_AddRefed<nsIContent>
|
||||
FindSelectionRoot(nsIEditor *aEditor, nsIContent *aContent)
|
||||
FindSelectionRoot(nsEditor *aEditor, nsIContent *aContent)
|
||||
{
|
||||
PRUint32 flags;
|
||||
aEditor->GetFlags(&flags);
|
||||
|
||||
nsIDocument *document = aContent->GetCurrentDoc();
|
||||
if (!document) {
|
||||
return nsnull;
|
||||
|
@ -777,7 +749,7 @@ FindSelectionRoot(nsIEditor *aEditor, nsIContent *aContent)
|
|||
return root;
|
||||
}
|
||||
|
||||
if (flags & nsIPlaintextEditor::eEditorReadonlyMask) {
|
||||
if (aEditor->IsReadonly()) {
|
||||
// We still want to allow selection in a readonly editor.
|
||||
nsCOMPtr<nsIDOMElement> rootElement;
|
||||
aEditor->GetRootElement(getter_AddRefs(rootElement));
|
||||
|
@ -817,16 +789,15 @@ nsEditorEventListener::Focus(nsIDOMEvent* aEvent)
|
|||
// turn on selection and caret
|
||||
if (mEditor)
|
||||
{
|
||||
PRUint32 flags;
|
||||
mEditor->GetFlags(&flags);
|
||||
if (! (flags & nsIPlaintextEditor::eEditorDisabledMask))
|
||||
nsEditor* editor = static_cast<nsEditor*>(mEditor);
|
||||
if (!editor->IsDisabled())
|
||||
{ // only enable caret and selection if the editor is not disabled
|
||||
nsCOMPtr<nsIContent> content = do_QueryInterface(target);
|
||||
|
||||
PRBool targetIsEditableDoc = PR_FALSE;
|
||||
nsCOMPtr<nsIContent> editableRoot;
|
||||
if (content) {
|
||||
editableRoot = FindSelectionRoot(mEditor, content);
|
||||
editableRoot = FindSelectionRoot(editor, content);
|
||||
|
||||
// make sure that the element is really focused in case an earlier
|
||||
// listener in the chain changed the focus.
|
||||
|
@ -864,8 +835,7 @@ nsEditorEventListener::Focus(nsIDOMEvent* aEvent)
|
|||
}
|
||||
}
|
||||
|
||||
const PRBool kIsReadonly = (flags & nsIPlaintextEditor::eEditorReadonlyMask) != 0;
|
||||
selCon->SetCaretReadOnly(kIsReadonly);
|
||||
selCon->SetCaretReadOnly(editor->IsReadonly());
|
||||
selCon->SetCaretEnabled(PR_TRUE);
|
||||
selCon->SetDisplaySelection(nsISelectionController::SELECTION_ON);
|
||||
selCon->RepaintSelection(nsISelectionController::SELECTION_NORMAL);
|
||||
|
@ -934,13 +904,10 @@ nsEditorEventListener::Blur(nsIDOMEvent* aEvent)
|
|||
|
||||
selCon->SetCaretEnabled(PR_FALSE);
|
||||
|
||||
PRUint32 flags;
|
||||
mEditor->GetFlags(&flags);
|
||||
if((flags & nsIPlaintextEditor::eEditorWidgetMask) ||
|
||||
(flags & nsIPlaintextEditor::eEditorPasswordMask) ||
|
||||
(flags & nsIPlaintextEditor::eEditorReadonlyMask) ||
|
||||
(flags & nsIPlaintextEditor::eEditorDisabledMask) ||
|
||||
(flags & nsIPlaintextEditor::eEditorFilterInputMask))
|
||||
nsEditor* editor = static_cast<nsEditor*>(mEditor);
|
||||
if(editor->IsFormWidget() || editor->IsPasswordEditor() ||
|
||||
editor->IsReadonly() || editor->IsDisabled() ||
|
||||
editor->IsInputFiltered())
|
||||
{
|
||||
selCon->SetDisplaySelection(nsISelectionController::SELECTION_HIDDEN);//hide but do NOT turn off
|
||||
}
|
||||
|
|
|
@ -1103,7 +1103,8 @@ NS_IMETHODIMP nsHTMLEditor::PrepareHTMLTransferable(nsITransferable **aTransfera
|
|||
{
|
||||
// Create the desired DataFlavor for the type of data
|
||||
// we want to get out of the transferable
|
||||
if ((mFlags & eEditorPlaintextMask) == 0) // This should only happen in html editors, not plaintext
|
||||
// This should only happen in html editors, not plaintext
|
||||
if (!IsPlaintextEditor())
|
||||
{
|
||||
if (!aHavePrivFlavor)
|
||||
{
|
||||
|
@ -1727,12 +1728,7 @@ nsHTMLEditor::PutDragDataInTransferable(nsITransferable **aTransferable)
|
|||
nsAutoString buffer, parents, info;
|
||||
|
||||
// find out if we're a plaintext control or not
|
||||
PRUint32 editorFlags = 0;
|
||||
rv = GetFlags(&editorFlags);
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
PRBool bIsPlainTextControl = ((editorFlags & eEditorPlaintextMask) != 0);
|
||||
if (!bIsPlainTextControl)
|
||||
if (!IsPlaintextEditor())
|
||||
{
|
||||
// encode the selection as html with contextual info
|
||||
rv = docEncoder->EncodeToStringWithContext(parents, info, buffer);
|
||||
|
@ -1760,7 +1756,7 @@ nsHTMLEditor::PutDragDataInTransferable(nsITransferable **aTransferable)
|
|||
nsCOMPtr<nsITransferable> trans = do_CreateInstance("@mozilla.org/widget/transferable;1");
|
||||
NS_ENSURE_TRUE(trans, NS_ERROR_FAILURE);
|
||||
|
||||
if (bIsPlainTextControl)
|
||||
if (IsPlaintextEditor())
|
||||
{
|
||||
// Add the unicode flavor to the transferable
|
||||
rv = trans->AddDataFlavor(kUnicodeMime);
|
||||
|
@ -1999,14 +1995,11 @@ NS_IMETHODIMP nsHTMLEditor::CanPaste(PRInt32 aSelectionType, PRBool *aCanPaste)
|
|||
nsresult rv;
|
||||
nsCOMPtr<nsIClipboard> clipboard(do_GetService("@mozilla.org/widget/clipboard;1", &rv));
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
PRUint32 editorFlags;
|
||||
GetFlags(&editorFlags);
|
||||
|
||||
|
||||
PRBool haveFlavors;
|
||||
|
||||
// Use the flavors depending on the current editor mask
|
||||
if ((editorFlags & eEditorPlaintextMask))
|
||||
if (IsPlaintextEditor())
|
||||
rv = clipboard->HasDataMatchingFlavors(textEditorFlavors,
|
||||
NS_ARRAY_LENGTH(textEditorFlavors),
|
||||
aSelectionType, &haveFlavors);
|
||||
|
@ -2039,13 +2032,10 @@ NS_IMETHODIMP nsHTMLEditor::CanPasteTransferable(nsITransferable *aTransferable,
|
|||
|
||||
// Peek in |aTransferable| to see if it contains a supported MIME type.
|
||||
|
||||
PRUint32 editorFlags;
|
||||
GetFlags(&editorFlags);
|
||||
|
||||
// Use the flavors depending on the current editor mask
|
||||
const char ** flavors;
|
||||
unsigned length;
|
||||
if ((editorFlags & eEditorPlaintextMask)) {
|
||||
if (IsPlaintextEditor()) {
|
||||
flavors = textEditorFlavors;
|
||||
length = NS_ARRAY_LENGTH(textEditorFlavors);
|
||||
} else {
|
||||
|
@ -2075,7 +2065,7 @@ NS_IMETHODIMP nsHTMLEditor::CanPasteTransferable(nsITransferable *aTransferable,
|
|||
//
|
||||
NS_IMETHODIMP nsHTMLEditor::PasteAsQuotation(PRInt32 aSelectionType)
|
||||
{
|
||||
if (mFlags & eEditorPlaintextMask)
|
||||
if (IsPlaintextEditor())
|
||||
return PasteAsPlaintextQuotation(aSelectionType);
|
||||
|
||||
nsAutoString citation;
|
||||
|
@ -2281,7 +2271,7 @@ nsHTMLEditor::InsertTextWithQuotations(const nsAString &aStringToInsert)
|
|||
NS_IMETHODIMP nsHTMLEditor::InsertAsQuotation(const nsAString & aQuotedText,
|
||||
nsIDOMNode **aNodeInserted)
|
||||
{
|
||||
if (mFlags & eEditorPlaintextMask)
|
||||
if (IsPlaintextEditor())
|
||||
return InsertAsPlaintextQuotation(aQuotedText, PR_TRUE, aNodeInserted);
|
||||
|
||||
nsAutoString citation;
|
||||
|
@ -2416,7 +2406,7 @@ nsHTMLEditor::InsertAsCitedQuotation(const nsAString & aQuotedText,
|
|||
nsIDOMNode **aNodeInserted)
|
||||
{
|
||||
// Don't let anyone insert html into a "plaintext" editor:
|
||||
if (mFlags & eEditorPlaintextMask)
|
||||
if (IsPlaintextEditor())
|
||||
{
|
||||
NS_ASSERTION(!aInsertHTML, "InsertAsCitedQuotation: trying to insert html into plaintext editor");
|
||||
return InsertAsPlaintextQuotation(aQuotedText, PR_TRUE, aNodeInserted);
|
||||
|
|
|
@ -248,13 +248,13 @@ NS_IMPL_QUERY_INTERFACE_INHERITED2(nsHTMLEditRules, nsTextEditRules, nsIHTMLEdit
|
|||
********************************************************/
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsHTMLEditRules::Init(nsPlaintextEditor *aEditor, PRUint32 aFlags)
|
||||
nsHTMLEditRules::Init(nsPlaintextEditor *aEditor)
|
||||
{
|
||||
mHTMLEditor = static_cast<nsHTMLEditor*>(aEditor);
|
||||
nsresult res;
|
||||
|
||||
// call through to base class Init
|
||||
res = nsTextEditRules::Init(aEditor, aFlags);
|
||||
res = nsTextEditRules::Init(aEditor);
|
||||
if (NS_FAILED(res)) return res;
|
||||
|
||||
// cache any prefs we care about
|
||||
|
@ -1373,8 +1373,6 @@ nsHTMLEditRules::WillInsertText(PRInt32 aAction,
|
|||
nsCOMPtr<nsIDOMNode> selNode;
|
||||
PRInt32 selOffset;
|
||||
|
||||
PRBool bPlaintext = mFlags & nsIPlaintextEditor::eEditorPlaintextMask;
|
||||
|
||||
// if the selection isn't collapsed, delete it.
|
||||
PRBool bCollapsed;
|
||||
res = aSelection->GetIsCollapsed(&bCollapsed);
|
||||
|
@ -1450,7 +1448,7 @@ nsHTMLEditRules::WillInsertText(PRInt32 aAction,
|
|||
// for efficiency, break out the pre case separately. This is because
|
||||
// its a lot cheaper to search the input string for only newlines than
|
||||
// it is to search for both tabs and newlines.
|
||||
if (isPRE || bPlaintext)
|
||||
if (isPRE || IsPlaintextEditor())
|
||||
{
|
||||
while (unicodeBuf && (pos != -1) && (pos < (PRInt32)(*inString).Length()))
|
||||
{
|
||||
|
@ -1583,8 +1581,6 @@ nsHTMLEditRules::WillInsertBreak(nsISelection *aSelection, PRBool *aCancel, PRBo
|
|||
// initialize out param
|
||||
*aCancel = PR_FALSE;
|
||||
*aHandled = PR_FALSE;
|
||||
|
||||
PRBool bPlaintext = mFlags & nsIPlaintextEditor::eEditorPlaintextMask;
|
||||
|
||||
// if the selection isn't collapsed, delete it.
|
||||
PRBool bCollapsed;
|
||||
|
@ -1605,9 +1601,9 @@ nsHTMLEditRules::WillInsertBreak(nsISelection *aSelection, PRBool *aCancel, PRBo
|
|||
|
||||
// split any mailcites in the way.
|
||||
// should we abort this if we encounter table cell boundaries?
|
||||
if (mFlags & nsIPlaintextEditor::eEditorMailMask)
|
||||
if (IsMailEditor())
|
||||
{
|
||||
res = SplitMailCites(aSelection, bPlaintext, aHandled);
|
||||
res = SplitMailCites(aSelection, IsPlaintextEditor(), aHandled);
|
||||
if (NS_FAILED(res)) return res;
|
||||
if (*aHandled) return NS_OK;
|
||||
}
|
||||
|
@ -1697,7 +1693,7 @@ nsHTMLEditRules::StandardBreakImpl(nsIDOMNode *aNode, PRInt32 aOffset, nsISelect
|
|||
nsCOMPtr<nsIDOMNode> node(aNode);
|
||||
nsCOMPtr<nsISelectionPrivate> selPriv(do_QueryInterface(aSelection));
|
||||
|
||||
if (mFlags & nsIPlaintextEditor::eEditorPlaintextMask)
|
||||
if (IsPlaintextEditor())
|
||||
{
|
||||
res = mHTMLEditor->CreateBR(node, aOffset, address_of(brNode));
|
||||
}
|
||||
|
@ -1917,8 +1913,6 @@ nsHTMLEditRules::WillDeleteSelection(nsISelection *aSelection,
|
|||
}
|
||||
|
||||
nsresult res = NS_OK;
|
||||
PRBool bPlaintext = mFlags & nsIPlaintextEditor::eEditorPlaintextMask;
|
||||
|
||||
PRBool bCollapsed, join = PR_FALSE;
|
||||
res = aSelection->GetIsCollapsed(&bCollapsed);
|
||||
if (NS_FAILED(res)) return res;
|
||||
|
@ -2363,7 +2357,7 @@ nsHTMLEditRules::WillDeleteSelection(nsISelection *aSelection,
|
|||
|
||||
// figure out if the endpoints are in nodes that can be merged
|
||||
// adjust surrounding whitespace in preperation to delete selection
|
||||
if (!bPlaintext)
|
||||
if (!IsPlaintextEditor())
|
||||
{
|
||||
nsAutoTxnsConserveSelection dontSpazMySelection(mHTMLEditor);
|
||||
res = nsWSRunObject::PrepareToDeleteRange(mHTMLEditor,
|
||||
|
@ -2388,10 +2382,10 @@ nsHTMLEditRules::WillDeleteSelection(nsISelection *aSelection,
|
|||
// figure out mailcite ancestors
|
||||
nsCOMPtr<nsIDOMNode> endCiteNode, startCiteNode;
|
||||
res = GetTopEnclosingMailCite(startNode, address_of(startCiteNode),
|
||||
mFlags & nsIPlaintextEditor::eEditorPlaintextMask);
|
||||
IsPlaintextEditor());
|
||||
if (NS_FAILED(res)) return res;
|
||||
res = GetTopEnclosingMailCite(endNode, address_of(endCiteNode),
|
||||
mFlags & nsIPlaintextEditor::eEditorPlaintextMask);
|
||||
IsPlaintextEditor());
|
||||
if (NS_FAILED(res)) return res;
|
||||
|
||||
// if we only have a mailcite at one of the two endpoints, set the directionality
|
||||
|
@ -2997,7 +2991,7 @@ nsHTMLEditRules::DidDeleteSelection(nsISelection *aSelection,
|
|||
// find any enclosing mailcite
|
||||
nsCOMPtr<nsIDOMNode> citeNode;
|
||||
res = GetTopEnclosingMailCite(startNode, address_of(citeNode),
|
||||
mFlags & nsIPlaintextEditor::eEditorPlaintextMask);
|
||||
IsPlaintextEditor());
|
||||
if (NS_FAILED(res)) return res;
|
||||
if (citeNode)
|
||||
{
|
||||
|
|
|
@ -86,7 +86,7 @@ public:
|
|||
|
||||
|
||||
// nsIEditRules methods
|
||||
NS_IMETHOD Init(nsPlaintextEditor *aEditor, PRUint32 aFlags);
|
||||
NS_IMETHOD Init(nsPlaintextEditor *aEditor);
|
||||
NS_IMETHOD DetachEditor();
|
||||
NS_IMETHOD BeforeEdit(PRInt32 action, nsIEditor::EDirection aDirection);
|
||||
NS_IMETHOD AfterEdit(PRInt32 action, nsIEditor::EDirection aDirection);
|
||||
|
|
|
@ -272,10 +272,8 @@ nsHTMLEditor::Init(nsIDOMDocument *aDoc, nsIPresShell *aPresShell,
|
|||
result = nsPlaintextEditor::Init(aDoc, aPresShell, aRoot, aSelCon, aFlags);
|
||||
if (NS_FAILED(result)) { return result; }
|
||||
|
||||
UpdateForFlags(aFlags);
|
||||
|
||||
// disable Composer-only features
|
||||
if (aFlags & eEditorMailMask)
|
||||
if (IsMailEditor())
|
||||
{
|
||||
SetAbsolutePositioningEnabled(PR_FALSE);
|
||||
SetSnapToGridEnabled(PR_FALSE);
|
||||
|
@ -291,7 +289,7 @@ nsHTMLEditor::Init(nsIDOMDocument *aDoc, nsIPresShell *aPresShell,
|
|||
// disable links
|
||||
nsPresContext *context = aPresShell->GetPresContext();
|
||||
if (!context) return NS_ERROR_NULL_POINTER;
|
||||
if (!(mFlags & (eEditorPlaintextMask | eEditorAllowInteraction))) {
|
||||
if (!IsPlaintextEditor() && !IsInteractionAllowed()) {
|
||||
mLinkHandler = context->GetLinkHandler();
|
||||
|
||||
context->SetLinkHandler(nsnull);
|
||||
|
@ -306,7 +304,7 @@ nsHTMLEditor::Init(nsIDOMDocument *aDoc, nsIPresShell *aPresShell,
|
|||
mSelectionListenerP = new ResizerSelectionListener(this);
|
||||
if (!mSelectionListenerP) {return NS_ERROR_NULL_POINTER;}
|
||||
|
||||
if (!(mFlags & eEditorAllowInteraction)) {
|
||||
if (!IsInteractionAllowed()) {
|
||||
// ignore any errors from this in case the file is missing
|
||||
AddOverrideStyleSheet(NS_LITERAL_STRING("resource://gre/res/EditorOverride.css"));
|
||||
}
|
||||
|
@ -387,21 +385,18 @@ nsHTMLEditor::RemoveEventListeners()
|
|||
nsPlaintextEditor::RemoveEventListeners();
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsHTMLEditor::GetFlags(PRUint32 *aFlags)
|
||||
{
|
||||
if (!mRules || !aFlags) { return NS_ERROR_NULL_POINTER; }
|
||||
return mRules->GetFlags(aFlags);
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsHTMLEditor::SetFlags(PRUint32 aFlags)
|
||||
{
|
||||
if (!mRules) { return NS_ERROR_NULL_POINTER; }
|
||||
nsresult rv = nsPlaintextEditor::SetFlags(aFlags);
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
|
||||
UpdateForFlags(aFlags);
|
||||
// Sets mCSSAware to correspond to aFlags. This toggles whether CSS is
|
||||
// used to style elements in the editor. Note that the editor is only CSS
|
||||
// aware by default in Composer and in the mail editor.
|
||||
mCSSAware = !NoCSS() && !IsMailEditor();
|
||||
|
||||
return mRules->SetFlags(aFlags);
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
|
@ -411,7 +406,7 @@ nsHTMLEditor::InitRules()
|
|||
nsresult res = NS_NewHTMLEditRules(getter_AddRefs(mRules));
|
||||
if (NS_FAILED(res)) return res;
|
||||
if (!mRules) return NS_ERROR_UNEXPECTED;
|
||||
res = mRules->Init(static_cast<nsPlaintextEditor*>(this), mFlags);
|
||||
res = mRules->Init(static_cast<nsPlaintextEditor*>(this));
|
||||
|
||||
return res;
|
||||
}
|
||||
|
@ -1143,11 +1138,7 @@ nsHTMLEditor::GetIsDocumentEditable(PRBool *aIsDocumentEditable)
|
|||
|
||||
PRBool nsHTMLEditor::IsModifiable()
|
||||
{
|
||||
PRUint32 flags;
|
||||
if (NS_SUCCEEDED(GetFlags(&flags)))
|
||||
return ((flags & nsIPlaintextEditor::eEditorReadonlyMask) == 0);
|
||||
else
|
||||
return PR_FALSE;
|
||||
return !IsReadonly();
|
||||
}
|
||||
|
||||
#ifdef XP_MAC
|
||||
|
@ -1213,7 +1204,7 @@ NS_IMETHODIMP nsHTMLEditor::HandleKeyPress(nsIDOMKeyEvent* aKeyEvent)
|
|||
|
||||
if (keyCode == nsIDOMKeyEvent::DOM_VK_TAB)
|
||||
{
|
||||
if (!(mFlags & eEditorPlaintextMask)) {
|
||||
if (!IsPlaintextEditor()) {
|
||||
nsCOMPtr<nsISelection>selection;
|
||||
res = GetSelection(getter_AddRefs(selection));
|
||||
if (NS_FAILED(res)) return res;
|
||||
|
@ -1259,7 +1250,7 @@ NS_IMETHODIMP nsHTMLEditor::HandleKeyPress(nsIDOMKeyEvent* aKeyEvent)
|
|||
{
|
||||
aKeyEvent->PreventDefault();
|
||||
nsString empty;
|
||||
if (isShift && !(mFlags&eEditorPlaintextMask))
|
||||
if (isShift && !IsPlaintextEditor())
|
||||
{
|
||||
return TypedText(empty, eTypedBR); // only inserts a br node
|
||||
}
|
||||
|
@ -5119,18 +5110,13 @@ nsHTMLEditor::SetIsCSSEnabled(PRBool aIsCSSPrefChecked)
|
|||
}
|
||||
// Disable the eEditorNoCSSMask flag if we're enabling StyleWithCSS.
|
||||
if (NS_SUCCEEDED(err)) {
|
||||
PRUint32 flags = 0;
|
||||
err = GetFlags(&flags);
|
||||
NS_ENSURE_SUCCESS(err, err);
|
||||
|
||||
PRUint32 flags = mFlags;
|
||||
if (aIsCSSPrefChecked) {
|
||||
// Turn off NoCSS as we're enabling CSS
|
||||
if (flags & eEditorNoCSSMask) {
|
||||
flags -= eEditorNoCSSMask;
|
||||
}
|
||||
} else if (!(flags & eEditorNoCSSMask)) {
|
||||
flags &= ~eEditorNoCSSMask;
|
||||
} else {
|
||||
// Turn on NoCSS, as we're disabling CSS.
|
||||
flags += eEditorNoCSSMask;
|
||||
flags |= eEditorNoCSSMask;
|
||||
}
|
||||
|
||||
err = SetFlags(flags);
|
||||
|
|
|
@ -312,7 +312,6 @@ public:
|
|||
/** Internal, static version */
|
||||
static nsresult NodeIsBlockStatic(nsIDOMNode *aNode, PRBool *aIsBlock);
|
||||
|
||||
NS_IMETHOD GetFlags(PRUint32 *aFlags);
|
||||
NS_IMETHOD SetFlags(PRUint32 aFlags);
|
||||
|
||||
NS_IMETHOD Paste(PRInt32 aSelectionType);
|
||||
|
@ -432,13 +431,6 @@ protected:
|
|||
|
||||
virtual void RemoveEventListeners();
|
||||
|
||||
// Sets mCSSAware to correspond to aFlags. This toggles whether CSS is
|
||||
// used to style elements in the editor. Note that the editor is only CSS
|
||||
// aware by default in Composer and in the mail editor.
|
||||
void UpdateForFlags(PRUint32 aFlags) {
|
||||
mCSSAware = ((aFlags & (eEditorNoCSSMask | eEditorMailMask)) == 0);
|
||||
}
|
||||
|
||||
// Return TRUE if aElement is a table-related elemet and caret was set
|
||||
PRBool SetCaretInTableCell(nsIDOMElement* aElement);
|
||||
PRBool IsElementInBody(nsIDOMElement* aElement);
|
||||
|
|
|
@ -526,16 +526,10 @@ nsPlaintextEditor::SetupDocEncoder(nsIDocumentEncoder **aDocEncoder)
|
|||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
// find out if we're a plaintext control or not
|
||||
PRUint32 editorFlags = 0;
|
||||
rv = GetFlags(&editorFlags);
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
PRBool bIsPlainTextControl = ((editorFlags & eEditorPlaintextMask) != 0);
|
||||
|
||||
// get correct mimeType and document encoder flags set
|
||||
nsAutoString mimeType;
|
||||
PRUint32 docEncoderFlags = 0;
|
||||
if (bIsPlainTextControl)
|
||||
if (IsPlaintextEditor())
|
||||
{
|
||||
docEncoderFlags |= nsIDocumentEncoder::OutputBodyOnly | nsIDocumentEncoder::OutputPreformatted;
|
||||
mimeType.AssignLiteral(kUnicodeMime);
|
||||
|
@ -593,12 +587,7 @@ nsPlaintextEditor::PutDragDataInTransferable(nsITransferable **aTransferable)
|
|||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
|
||||
// find out if we're a plaintext control or not
|
||||
PRUint32 editorFlags = 0;
|
||||
rv = GetFlags(&editorFlags);
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
PRBool bIsPlainTextControl = ((editorFlags & eEditorPlaintextMask) != 0);
|
||||
if (bIsPlainTextControl)
|
||||
if (IsPlaintextEditor())
|
||||
{
|
||||
// Add the unicode flavor to the transferable
|
||||
rv = trans->AddDataFlavor(kUnicodeMime);
|
||||
|
@ -619,7 +608,7 @@ nsPlaintextEditor::PutDragDataInTransferable(nsITransferable **aTransferable)
|
|||
// QI the data object an |nsISupports| so that when the transferable holds
|
||||
// onto it, it will addref the correct interface.
|
||||
nsCOMPtr<nsISupports> nsisupportsDataWrapper = do_QueryInterface(dataWrapper);
|
||||
rv = trans->SetTransferData(bIsPlainTextControl ? kUnicodeMime : kHTMLMime,
|
||||
rv = trans->SetTransferData(IsPlaintextEditor() ? kUnicodeMime : kHTMLMime,
|
||||
nsisupportsDataWrapper, buffer.Length() * sizeof(PRUnichar));
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
|
|
|
@ -305,21 +305,6 @@ nsPlaintextEditor::SetDocumentCharacterSet(const nsACString & characterSet)
|
|||
return result;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsPlaintextEditor::GetFlags(PRUint32 *aFlags)
|
||||
{
|
||||
if (!mRules || !aFlags) { return NS_ERROR_NULL_POINTER; }
|
||||
return mRules->GetFlags(aFlags);
|
||||
}
|
||||
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsPlaintextEditor::SetFlags(PRUint32 aFlags)
|
||||
{
|
||||
if (!mRules) { return NS_ERROR_NULL_POINTER; }
|
||||
return mRules->SetFlags(aFlags);
|
||||
}
|
||||
|
||||
|
||||
NS_IMETHODIMP nsPlaintextEditor::InitRules()
|
||||
{
|
||||
|
@ -327,7 +312,7 @@ NS_IMETHODIMP nsPlaintextEditor::InitRules()
|
|||
nsresult res = NS_NewTextEditRules(getter_AddRefs(mRules));
|
||||
if (NS_FAILED(res)) return res;
|
||||
if (!mRules) return NS_ERROR_UNEXPECTED;
|
||||
return mRules->Init(this, mFlags);
|
||||
return mRules->Init(this);
|
||||
}
|
||||
|
||||
|
||||
|
@ -345,11 +330,7 @@ nsPlaintextEditor::GetIsDocumentEditable(PRBool *aIsDocumentEditable)
|
|||
|
||||
PRBool nsPlaintextEditor::IsModifiable()
|
||||
{
|
||||
PRUint32 flags;
|
||||
if (NS_SUCCEEDED(GetFlags(&flags)))
|
||||
return ((flags & eEditorReadonlyMask) == 0);
|
||||
|
||||
return PR_FALSE;
|
||||
return !IsReadonly();
|
||||
}
|
||||
|
||||
|
||||
|
@ -871,7 +852,7 @@ nsPlaintextEditor::BeginComposition()
|
|||
{
|
||||
NS_ENSURE_TRUE(!mInIMEMode, NS_OK);
|
||||
|
||||
if(mFlags & nsIPlaintextEditor::eEditorPasswordMask) {
|
||||
if (IsPasswordEditor()) {
|
||||
if (mRules) {
|
||||
nsIEditRules *p = mRules.get();
|
||||
nsTextEditRules *textEditRules = static_cast<nsTextEditRules *>(p);
|
||||
|
@ -993,9 +974,7 @@ nsPlaintextEditor::SetWrapWidth(PRInt32 aWrapColumn)
|
|||
|
||||
// Make sure we're a plaintext editor, otherwise we shouldn't
|
||||
// do the rest of this.
|
||||
PRUint32 flags = 0;
|
||||
GetFlags(&flags);
|
||||
if (!(flags & eEditorPlaintextMask))
|
||||
if (!IsPlaintextEditor())
|
||||
return NS_OK;
|
||||
|
||||
// Ought to set a style sheet here ...
|
||||
|
@ -1026,14 +1005,14 @@ nsPlaintextEditor::SetWrapWidth(PRInt32 aWrapColumn)
|
|||
// Make sure we have fixed-width font. This should be done for us,
|
||||
// but it isn't, see bug 22502, so we have to add "font: -moz-fixed;".
|
||||
// Only do this if we're wrapping.
|
||||
if ((flags & eEditorEnableWrapHackMask) && aWrapColumn >= 0)
|
||||
if (IsWrapHackEnabled() && aWrapColumn >= 0)
|
||||
styleValue.AppendLiteral("font-family: -moz-fixed; ");
|
||||
|
||||
// If "mail.compose.wrap_to_window_width" is set, and we're a mail editor,
|
||||
// then remember our wrap width (for output purposes) but set the visual
|
||||
// wrapping to window width.
|
||||
// We may reset mWrapToWindow here, based on the pref's current value.
|
||||
if (flags & eEditorMailMask)
|
||||
if (IsMailEditor())
|
||||
{
|
||||
nsresult rv;
|
||||
nsCOMPtr<nsIPrefBranch> prefBranch =
|
||||
|
|
|
@ -111,9 +111,6 @@ public:
|
|||
|
||||
NS_IMETHOD SetDocumentCharacterSet(const nsACString & characterSet);
|
||||
|
||||
NS_IMETHOD GetFlags(PRUint32 *aFlags);
|
||||
NS_IMETHOD SetFlags(PRUint32 aFlags);
|
||||
|
||||
NS_IMETHOD Undo(PRUint32 aCount);
|
||||
NS_IMETHOD Redo(PRUint32 aCount);
|
||||
|
||||
|
|
|
@ -72,7 +72,7 @@
|
|||
static NS_DEFINE_CID(kLookAndFeelCID, NS_LOOKANDFEEL_CID);
|
||||
|
||||
#define CANCEL_OPERATION_IF_READONLY_OR_DISABLED \
|
||||
if ((mFlags & nsIPlaintextEditor::eEditorReadonlyMask) || (mFlags & nsIPlaintextEditor::eEditorDisabledMask)) \
|
||||
if (IsReadonly() || IsDisabled()) \
|
||||
{ \
|
||||
*aCancel = PR_TRUE; \
|
||||
return NS_OK; \
|
||||
|
@ -98,7 +98,6 @@ nsTextEditRules::nsTextEditRules()
|
|||
, mPasswordText()
|
||||
, mPasswordIMEText()
|
||||
, mPasswordIMEIndex(0)
|
||||
, mFlags(0) // initialized to 0 ("no flags set"). Real initial value is given in Init()
|
||||
, mActionNesting(0)
|
||||
, mLockRulesSniffing(PR_FALSE)
|
||||
, mDidExplicitlySetInterline(PR_FALSE)
|
||||
|
@ -136,13 +135,11 @@ NS_IMPL_CYCLE_COLLECTING_RELEASE(nsTextEditRules)
|
|||
********************************************************/
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsTextEditRules::Init(nsPlaintextEditor *aEditor, PRUint32 aFlags)
|
||||
nsTextEditRules::Init(nsPlaintextEditor *aEditor)
|
||||
{
|
||||
if (!aEditor) { return NS_ERROR_NULL_POINTER; }
|
||||
|
||||
mEditor = aEditor; // we hold a non-refcounted reference back to our editor
|
||||
// call SetFlags only aftet mEditor has been initialized!
|
||||
SetFlags(aFlags);
|
||||
nsCOMPtr<nsISelection> selection;
|
||||
mEditor->GetSelection(getter_AddRefs(selection));
|
||||
NS_ASSERTION(selection, "editor cannot get selection");
|
||||
|
@ -165,7 +162,7 @@ nsTextEditRules::Init(nsPlaintextEditor *aEditor, PRUint32 aFlags)
|
|||
NS_ENSURE_SUCCESS(res, res);
|
||||
}
|
||||
|
||||
if (mFlags & nsIPlaintextEditor::eEditorPlaintextMask)
|
||||
if (IsPlaintextEditor())
|
||||
{
|
||||
// ensure trailing br node
|
||||
res = CreateTrailingBRIfNeeded();
|
||||
|
@ -216,28 +213,6 @@ nsTextEditRules::DetachEditor()
|
|||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsTextEditRules::GetFlags(PRUint32 *aFlags)
|
||||
{
|
||||
if (!aFlags) { return NS_ERROR_NULL_POINTER; }
|
||||
*aFlags = mFlags;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsTextEditRules::SetFlags(PRUint32 aFlags)
|
||||
{
|
||||
if (mFlags == aFlags) return NS_OK;
|
||||
|
||||
// XXX - this won't work if body element already has
|
||||
// a style attribute on it, don't know why.
|
||||
// SetFlags() is really meant to only be called once
|
||||
// and at editor init time.
|
||||
|
||||
mFlags = aFlags;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsTextEditRules::BeforeEdit(PRInt32 action, nsIEditor::EDirection aDirection)
|
||||
{
|
||||
|
@ -457,7 +432,7 @@ nsTextEditRules::WillInsertBreak(nsISelection *aSelection, PRBool *aCancel, PRBo
|
|||
if (!aSelection || !aCancel || !aHandled) { return NS_ERROR_NULL_POINTER; }
|
||||
CANCEL_OPERATION_IF_READONLY_OR_DISABLED
|
||||
*aHandled = PR_FALSE;
|
||||
if (mFlags & nsIPlaintextEditor::eEditorSingleLineMask) {
|
||||
if (IsSingleLineEditor()) {
|
||||
*aCancel = PR_TRUE;
|
||||
}
|
||||
else
|
||||
|
@ -490,7 +465,9 @@ nsTextEditRules::DidInsertBreak(nsISelection *aSelection, nsresult aResult)
|
|||
// we only need to execute the stuff below if we are a plaintext editor.
|
||||
// html editors have a different mechanism for putting in mozBR's
|
||||
// (because there are a bunch more places you have to worry about it in html)
|
||||
if (!nsIPlaintextEditor::eEditorPlaintextMask & mFlags) return NS_OK;
|
||||
if (!IsPlaintextEditor()) {
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
// if we are at the end of the document, we need to insert
|
||||
// a special mozBR following the normal br, and then set the
|
||||
|
@ -554,7 +531,7 @@ GetTextNode(nsISelection *selection, nsEditor *editor) {
|
|||
}
|
||||
#ifdef DEBUG
|
||||
#define ASSERT_PASSWORD_LENGTHS_EQUAL() \
|
||||
if (mFlags & nsIPlaintextEditor::eEditorPasswordMask) { \
|
||||
if (IsPasswordEditor()) { \
|
||||
PRInt32 txtLen; \
|
||||
mEditor->GetTextLength(&txtLen); \
|
||||
NS_ASSERTION(mPasswordText.Length() == txtLen, \
|
||||
|
@ -669,7 +646,7 @@ nsTextEditRules::WillInsertText(PRInt32 aAction,
|
|||
PRUint32 end = 0;
|
||||
|
||||
// handle password field docs
|
||||
if (mFlags & nsIPlaintextEditor::eEditorPasswordMask)
|
||||
if (IsPasswordEditor())
|
||||
{
|
||||
res = mEditor->GetTextSelectionOffsets(aSelection, start, end);
|
||||
NS_ASSERTION((NS_SUCCEEDED(res)), "getTextSelectionOffsets failed!");
|
||||
|
@ -695,7 +672,7 @@ nsTextEditRules::WillInsertText(PRInt32 aAction,
|
|||
// handle password field data
|
||||
// this has the side effect of changing all the characters in aOutString
|
||||
// to the replacement character
|
||||
if (mFlags & nsIPlaintextEditor::eEditorPasswordMask)
|
||||
if (IsPasswordEditor())
|
||||
{
|
||||
if (aAction == kInsertTextIME) {
|
||||
res = RemoveIMETextFromPWBuf(start, outString);
|
||||
|
@ -713,7 +690,7 @@ nsTextEditRules::WillInsertText(PRInt32 aAction,
|
|||
// 4. replace with commas
|
||||
// 5. strip newlines and surrounding whitespace
|
||||
// So find out what we're expected to do:
|
||||
if (nsIPlaintextEditor::eEditorSingleLineMask & mFlags)
|
||||
if (IsSingleLineEditor())
|
||||
{
|
||||
nsAutoString tString(*outString);
|
||||
|
||||
|
@ -722,14 +699,13 @@ nsTextEditRules::WillInsertText(PRInt32 aAction,
|
|||
outString->Assign(tString);
|
||||
}
|
||||
|
||||
if (mFlags & nsIPlaintextEditor::eEditorPasswordMask)
|
||||
if (IsPasswordEditor())
|
||||
{
|
||||
// manage the password buffer
|
||||
mPasswordText.Insert(*outString, start);
|
||||
|
||||
nsCOMPtr<nsILookAndFeel> lookAndFeel = do_GetService(kLookAndFeelCID);
|
||||
if (lookAndFeel->GetEchoPassword() &&
|
||||
!(mFlags & nsIPlaintextEditor::eEditorDontEchoPassword)) {
|
||||
if (lookAndFeel->GetEchoPassword() && !DontEchoPassword()) {
|
||||
HideLastPWInput();
|
||||
mLastStart = start;
|
||||
mLastLength = outString->Length();
|
||||
|
@ -820,7 +796,7 @@ nsTextEditRules::WillInsertText(PRInt32 aAction,
|
|||
// is it a return?
|
||||
if (subStr.EqualsLiteral(LFSTR))
|
||||
{
|
||||
if (nsIPlaintextEditor::eEditorSingleLineMask & mFlags)
|
||||
if (IsSingleLineEditor())
|
||||
{
|
||||
NS_ASSERTION((mEditor->mNewlineHandling == nsIPlaintextEditor::eNewlinesPasteIntact),
|
||||
"Newline improperly getting into single-line edit field!");
|
||||
|
@ -937,7 +913,7 @@ nsTextEditRules::WillSetTextProperty(nsISelection *aSelection, PRBool *aCancel,
|
|||
{ return NS_ERROR_NULL_POINTER; }
|
||||
|
||||
// XXX: should probably return a success value other than NS_OK that means "not allowed"
|
||||
if (nsIPlaintextEditor::eEditorPlaintextMask & mFlags) {
|
||||
if (IsPlaintextEditor()) {
|
||||
*aCancel = PR_TRUE;
|
||||
}
|
||||
return NS_OK;
|
||||
|
@ -956,7 +932,7 @@ nsTextEditRules::WillRemoveTextProperty(nsISelection *aSelection, PRBool *aCance
|
|||
{ return NS_ERROR_NULL_POINTER; }
|
||||
|
||||
// XXX: should probably return a success value other than NS_OK that means "not allowed"
|
||||
if (nsIPlaintextEditor::eEditorPlaintextMask & mFlags) {
|
||||
if (IsPlaintextEditor()) {
|
||||
*aCancel = PR_TRUE;
|
||||
}
|
||||
return NS_OK;
|
||||
|
@ -989,7 +965,7 @@ nsTextEditRules::WillDeleteSelection(nsISelection *aSelection,
|
|||
|
||||
nsresult res = NS_OK;
|
||||
|
||||
if (mFlags & nsIPlaintextEditor::eEditorPasswordMask)
|
||||
if (IsPasswordEditor())
|
||||
{
|
||||
res = mEditor->ExtendSelectionForDelete(aSelection, &aCollapsedAction);
|
||||
NS_ENSURE_SUCCESS(res, res);
|
||||
|
@ -1195,7 +1171,7 @@ nsTextEditRules::WillOutputText(nsISelection *aSelection,
|
|||
ToLowerCase(outputFormat);
|
||||
if (outputFormat.EqualsLiteral("text/plain"))
|
||||
{ // only use these rules for plain text output
|
||||
if (mFlags & nsIPlaintextEditor::eEditorPasswordMask)
|
||||
if (IsPasswordEditor())
|
||||
{
|
||||
*aOutString = mPasswordText;
|
||||
*aHandled = PR_TRUE;
|
||||
|
@ -1297,7 +1273,7 @@ nsresult
|
|||
nsTextEditRules::CreateTrailingBRIfNeeded()
|
||||
{
|
||||
// but only if we aren't a single line edit field
|
||||
if (mFlags & nsIPlaintextEditor::eEditorSingleLineMask)
|
||||
if (IsSingleLineEditor())
|
||||
return NS_OK;
|
||||
nsIDOMNode *body = mEditor->GetRoot();
|
||||
if (!body)
|
||||
|
@ -1396,8 +1372,7 @@ nsTextEditRules::TruncateInsertionIfNeeded(nsISelection *aSelection,
|
|||
nsresult res = NS_OK;
|
||||
*aOutString = *aInString;
|
||||
|
||||
if ((-1 != aMaxLength) && (mFlags & nsIPlaintextEditor::eEditorPlaintextMask)
|
||||
&& !mEditor->IsIMEComposing() )
|
||||
if ((-1 != aMaxLength) && IsPlaintextEditor() && !mEditor->IsIMEComposing() )
|
||||
{
|
||||
// Get the current text length.
|
||||
// Get the length of inString.
|
||||
|
|
|
@ -68,14 +68,12 @@ public:
|
|||
virtual ~nsTextEditRules();
|
||||
|
||||
// nsIEditRules methods
|
||||
NS_IMETHOD Init(nsPlaintextEditor *aEditor, PRUint32 aFlags);
|
||||
NS_IMETHOD Init(nsPlaintextEditor *aEditor);
|
||||
NS_IMETHOD DetachEditor();
|
||||
NS_IMETHOD BeforeEdit(PRInt32 action, nsIEditor::EDirection aDirection);
|
||||
NS_IMETHOD AfterEdit(PRInt32 action, nsIEditor::EDirection aDirection);
|
||||
NS_IMETHOD WillDoAction(nsISelection *aSelection, nsRulesInfo *aInfo, PRBool *aCancel, PRBool *aHandled);
|
||||
NS_IMETHOD DidDoAction(nsISelection *aSelection, nsRulesInfo *aInfo, nsresult aResult);
|
||||
NS_IMETHOD GetFlags(PRUint32 *aFlags);
|
||||
NS_IMETHOD SetFlags(PRUint32 aFlags);
|
||||
NS_IMETHOD DocumentIsEmpty(PRBool *aDocumentIsEmpty);
|
||||
|
||||
// nsTextEditRules action id's
|
||||
|
@ -235,6 +233,35 @@ protected:
|
|||
|
||||
nsresult HideLastPWInput();
|
||||
|
||||
PRBool IsPasswordEditor() const
|
||||
{
|
||||
return mEditor ? mEditor->IsPasswordEditor() : PR_FALSE;
|
||||
}
|
||||
PRBool IsSingleLineEditor() const
|
||||
{
|
||||
return mEditor ? mEditor->IsSingleLineEditor() : PR_FALSE;
|
||||
}
|
||||
PRBool IsPlaintextEditor() const
|
||||
{
|
||||
return mEditor ? mEditor->IsPlaintextEditor() : PR_FALSE;
|
||||
}
|
||||
PRBool IsReadonly() const
|
||||
{
|
||||
return mEditor ? mEditor->IsReadonly() : PR_FALSE;
|
||||
}
|
||||
PRBool IsDisabled() const
|
||||
{
|
||||
return mEditor ? mEditor->IsDisabled() : PR_FALSE;
|
||||
}
|
||||
PRBool IsMailEditor() const
|
||||
{
|
||||
return mEditor ? mEditor->IsMailEditor() : PR_FALSE;
|
||||
}
|
||||
PRBool DontEchoPassword() const
|
||||
{
|
||||
return mEditor ? mEditor->DontEchoPassword() : PR_FALSE;
|
||||
}
|
||||
|
||||
// data members
|
||||
nsPlaintextEditor *mEditor; // note that we do not refcount the editor
|
||||
nsString mPasswordText; // a buffer we use to store the real value of password editors
|
||||
|
@ -243,7 +270,6 @@ protected:
|
|||
nsCOMPtr<nsIDOMNode> mBogusNode; // magic node acts as placeholder in empty doc
|
||||
nsCOMPtr<nsIDOMNode> mCachedSelectionNode; // cached selected node
|
||||
PRInt32 mCachedSelectionOffset; // cached selected offset
|
||||
PRUint32 mFlags;
|
||||
PRUint32 mActionNesting;
|
||||
PRPackedBool mLockRulesSniffing;
|
||||
PRPackedBool mDidExplicitlySetInterline;
|
||||
|
|
Загрузка…
Ссылка в новой задаче