зеркало из https://github.com/mozilla/gecko-dev.git
18033: Add editor API for delete methods, and hook up an initial
set of emacs key bindings for Unix. r=jfrancis
This commit is contained in:
Родитель
c8fe63ef47
Коммит
757b1fce03
|
@ -4413,6 +4413,11 @@ nsEditor::CreateTxnForDeleteInsertionPoint(nsIDOMRange *aRange,
|
|||
aAction,
|
||||
EditAggregateTxn *aTxn)
|
||||
{
|
||||
// We haven't implemented these three modes yet:
|
||||
if (aAction == eDeleteNextWord || aAction == eDeletePreviousWord
|
||||
|| aAction == eDeleteToEndOfLine)
|
||||
return NS_ERROR_NOT_IMPLEMENTED;
|
||||
|
||||
nsCOMPtr<nsIDOMNode> node;
|
||||
PRBool isFirst;
|
||||
PRBool isLast;
|
||||
|
|
|
@ -377,7 +377,6 @@ nsEditorShell::PrepareDocumentForEditing(nsIURI *aUrl)
|
|||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
// get the URL of the page we are editing
|
||||
char* pageURLString = nsnull;
|
||||
if (aUrl)
|
||||
{
|
||||
char* pageURLString = nsnull;
|
||||
|
@ -654,6 +653,73 @@ nsEditorShell::UpdateInterfaceState(void)
|
|||
return mStateMaintainer->ForceUpdate();
|
||||
}
|
||||
|
||||
// Deletion routines
|
||||
nsresult
|
||||
nsEditorShell::ScrollSelectionIntoView()
|
||||
{
|
||||
nsCOMPtr<nsIEditor> editor = do_QueryInterface(mEditor);
|
||||
if (!editor) return NS_ERROR_NOT_INITIALIZED;
|
||||
nsCOMPtr<nsIPresShell> presShell;
|
||||
nsresult result = editor->GetPresShell(getter_AddRefs(presShell));
|
||||
if (NS_FAILED(result))
|
||||
return result;
|
||||
if (!presShell)
|
||||
return NS_ERROR_NULL_POINTER;
|
||||
|
||||
return presShell->ScrollSelectionIntoView(SELECTION_NORMAL,
|
||||
SELECTION_FOCUS_REGION);
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsEditorShell::DeleteCharForward()
|
||||
{
|
||||
nsCOMPtr<nsIEditor> editor = do_QueryInterface(mEditor);
|
||||
if (!editor) return NS_ERROR_NOT_INITIALIZED;
|
||||
nsresult rv = editor->DeleteSelection(nsIEditor::eDeleteNext);
|
||||
ScrollSelectionIntoView();
|
||||
return rv;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsEditorShell::DeleteCharBackward()
|
||||
{
|
||||
nsCOMPtr<nsIEditor> editor = do_QueryInterface(mEditor);
|
||||
if (!editor) return NS_ERROR_NOT_INITIALIZED;
|
||||
nsresult rv = editor->DeleteSelection(nsIEditor::eDeletePrevious);
|
||||
ScrollSelectionIntoView();
|
||||
return rv;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsEditorShell::DeleteWordForward()
|
||||
{
|
||||
nsCOMPtr<nsIEditor> editor = do_QueryInterface(mEditor);
|
||||
if (!editor) return NS_ERROR_NOT_INITIALIZED;
|
||||
nsresult rv = editor->DeleteSelection(nsIEditor::eDeleteNextWord);
|
||||
ScrollSelectionIntoView();
|
||||
return rv;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsEditorShell::DeleteWordBackward()
|
||||
{
|
||||
nsCOMPtr<nsIEditor> editor = do_QueryInterface(mEditor);
|
||||
if (!editor) return NS_ERROR_NOT_INITIALIZED;
|
||||
nsresult rv = editor->DeleteSelection(nsIEditor::eDeletePreviousWord);
|
||||
ScrollSelectionIntoView();
|
||||
return rv;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsEditorShell::DeleteToEndOfLine()
|
||||
{
|
||||
nsCOMPtr<nsIEditor> editor = do_QueryInterface(mEditor);
|
||||
if (!editor) return NS_ERROR_NOT_INITIALIZED;
|
||||
nsresult rv = editor->DeleteSelection(nsIEditor::eDeleteToEndOfLine);
|
||||
ScrollSelectionIntoView();
|
||||
return rv;
|
||||
}
|
||||
|
||||
// Generic attribute setting and removal
|
||||
NS_IMETHODIMP
|
||||
nsEditorShell::SetAttribute(nsIDOMElement *element, const PRUnichar *attr, const PRUnichar *value)
|
||||
|
|
|
@ -126,6 +126,7 @@ class nsEditorShell : public nsIEditorShell,
|
|||
NS_IMETHOD DoEditorMode(nsIWebShell *aWebShell);
|
||||
NS_IMETHOD ExecuteScript(nsIScriptContext * aContext, const nsString& aScript);
|
||||
NS_IMETHOD InstantiateEditor(nsIDOMDocument *aDoc, nsIPresShell *aPresShell);
|
||||
NS_IMETHOD ScrollSelectionIntoView();
|
||||
NS_IMETHOD TransferDocumentStateListeners();
|
||||
NS_IMETHOD RemoveOneProperty(const nsString& aProp, const nsString& aAttr);
|
||||
void SetButtonImage(nsIDOMNode * aParentNode, PRInt32 aBtnNum, const nsString &aResName);
|
||||
|
|
|
@ -377,7 +377,6 @@ nsEditorShell::PrepareDocumentForEditing(nsIURI *aUrl)
|
|||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
// get the URL of the page we are editing
|
||||
char* pageURLString = nsnull;
|
||||
if (aUrl)
|
||||
{
|
||||
char* pageURLString = nsnull;
|
||||
|
@ -654,6 +653,73 @@ nsEditorShell::UpdateInterfaceState(void)
|
|||
return mStateMaintainer->ForceUpdate();
|
||||
}
|
||||
|
||||
// Deletion routines
|
||||
nsresult
|
||||
nsEditorShell::ScrollSelectionIntoView()
|
||||
{
|
||||
nsCOMPtr<nsIEditor> editor = do_QueryInterface(mEditor);
|
||||
if (!editor) return NS_ERROR_NOT_INITIALIZED;
|
||||
nsCOMPtr<nsIPresShell> presShell;
|
||||
nsresult result = editor->GetPresShell(getter_AddRefs(presShell));
|
||||
if (NS_FAILED(result))
|
||||
return result;
|
||||
if (!presShell)
|
||||
return NS_ERROR_NULL_POINTER;
|
||||
|
||||
return presShell->ScrollSelectionIntoView(SELECTION_NORMAL,
|
||||
SELECTION_FOCUS_REGION);
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsEditorShell::DeleteCharForward()
|
||||
{
|
||||
nsCOMPtr<nsIEditor> editor = do_QueryInterface(mEditor);
|
||||
if (!editor) return NS_ERROR_NOT_INITIALIZED;
|
||||
nsresult rv = editor->DeleteSelection(nsIEditor::eDeleteNext);
|
||||
ScrollSelectionIntoView();
|
||||
return rv;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsEditorShell::DeleteCharBackward()
|
||||
{
|
||||
nsCOMPtr<nsIEditor> editor = do_QueryInterface(mEditor);
|
||||
if (!editor) return NS_ERROR_NOT_INITIALIZED;
|
||||
nsresult rv = editor->DeleteSelection(nsIEditor::eDeletePrevious);
|
||||
ScrollSelectionIntoView();
|
||||
return rv;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsEditorShell::DeleteWordForward()
|
||||
{
|
||||
nsCOMPtr<nsIEditor> editor = do_QueryInterface(mEditor);
|
||||
if (!editor) return NS_ERROR_NOT_INITIALIZED;
|
||||
nsresult rv = editor->DeleteSelection(nsIEditor::eDeleteNextWord);
|
||||
ScrollSelectionIntoView();
|
||||
return rv;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsEditorShell::DeleteWordBackward()
|
||||
{
|
||||
nsCOMPtr<nsIEditor> editor = do_QueryInterface(mEditor);
|
||||
if (!editor) return NS_ERROR_NOT_INITIALIZED;
|
||||
nsresult rv = editor->DeleteSelection(nsIEditor::eDeletePreviousWord);
|
||||
ScrollSelectionIntoView();
|
||||
return rv;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsEditorShell::DeleteToEndOfLine()
|
||||
{
|
||||
nsCOMPtr<nsIEditor> editor = do_QueryInterface(mEditor);
|
||||
if (!editor) return NS_ERROR_NOT_INITIALIZED;
|
||||
nsresult rv = editor->DeleteSelection(nsIEditor::eDeleteToEndOfLine);
|
||||
ScrollSelectionIntoView();
|
||||
return rv;
|
||||
}
|
||||
|
||||
// Generic attribute setting and removal
|
||||
NS_IMETHODIMP
|
||||
nsEditorShell::SetAttribute(nsIDOMElement *element, const PRUnichar *attr, const PRUnichar *value)
|
||||
|
|
|
@ -126,6 +126,7 @@ class nsEditorShell : public nsIEditorShell,
|
|||
NS_IMETHOD DoEditorMode(nsIWebShell *aWebShell);
|
||||
NS_IMETHOD ExecuteScript(nsIScriptContext * aContext, const nsString& aScript);
|
||||
NS_IMETHOD InstantiateEditor(nsIDOMDocument *aDoc, nsIPresShell *aPresShell);
|
||||
NS_IMETHOD ScrollSelectionIntoView();
|
||||
NS_IMETHOD TransferDocumentStateListeners();
|
||||
NS_IMETHOD RemoveOneProperty(const nsString& aProp, const nsString& aAttr);
|
||||
void SetButtonImage(nsIDOMNode * aParentNode, PRInt32 aBtnNum, const nsString &aResName);
|
||||
|
|
|
@ -266,6 +266,15 @@ interface nsIEditorShell : nsISupports
|
|||
*/
|
||||
void DeleteElement(in nsIDOMElement element);
|
||||
|
||||
/**
|
||||
* Deletion methods which need to be accessible to JS:
|
||||
*/
|
||||
void DeleteCharForward();
|
||||
void DeleteCharBackward();
|
||||
void DeleteWordForward();
|
||||
void DeleteWordBackward();
|
||||
void DeleteToEndOfLine();
|
||||
|
||||
void SelectElement(in nsIDOMElement element);
|
||||
void SetSelectionAfterElement(in nsIDOMElement element);
|
||||
|
||||
|
|
|
@ -4413,6 +4413,11 @@ nsEditor::CreateTxnForDeleteInsertionPoint(nsIDOMRange *aRange,
|
|||
aAction,
|
||||
EditAggregateTxn *aTxn)
|
||||
{
|
||||
// We haven't implemented these three modes yet:
|
||||
if (aAction == eDeleteNextWord || aAction == eDeletePreviousWord
|
||||
|| aAction == eDeleteToEndOfLine)
|
||||
return NS_ERROR_NOT_IMPLEMENTED;
|
||||
|
||||
nsCOMPtr<nsIDOMNode> node;
|
||||
PRBool isFirst;
|
||||
PRBool isLast;
|
||||
|
|
|
@ -54,7 +54,10 @@ public:
|
|||
typedef enum {
|
||||
eDoNothing,
|
||||
eDeleteNext,
|
||||
eDeletePrevious
|
||||
eDeletePrevious,
|
||||
eDeleteNextWord,
|
||||
eDeletePreviousWord,
|
||||
eDeleteToEndOfLine
|
||||
} ESelectionCollapseDirection;
|
||||
|
||||
|
||||
|
|
|
@ -213,6 +213,33 @@ function EditorShutdown()
|
|||
}
|
||||
|
||||
|
||||
// -------------------------- Key Bindings -------------------------
|
||||
|
||||
function EditorDeleteCharForward()
|
||||
{
|
||||
editorShell.DeleteCharForward();
|
||||
}
|
||||
|
||||
function EditorDeleteCharBackward()
|
||||
{
|
||||
editorShell.DeleteCharBackward();
|
||||
}
|
||||
|
||||
function EditorDeleteWordForward()
|
||||
{
|
||||
editorShell.DeleteWordForward();
|
||||
}
|
||||
|
||||
function EditorDeleteWordBackward()
|
||||
{
|
||||
editorShell.DeleteWordBackward();
|
||||
}
|
||||
|
||||
function EditorDeleteToEndOfLine()
|
||||
{
|
||||
editorShell.DeleteToEndOfLine();
|
||||
}
|
||||
|
||||
// --------------------------- File menu ---------------------------
|
||||
|
||||
function EditorOpen()
|
||||
|
|
|
@ -8,24 +8,42 @@
|
|||
xmlns:html="http://www.w3.org/TR/REC-html40"
|
||||
xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul">
|
||||
|
||||
<!-- change the xul key for Unix -->
|
||||
<keyset id="defaultKeySet">
|
||||
<xulkey key="alt" />
|
||||
</keyset>
|
||||
<!-- change the xul key for Unix -->
|
||||
<keyset id="defaultKeySet">
|
||||
<xulkey key="alt" />
|
||||
|
||||
<!-- close -->
|
||||
<menuitem id="menu_close" value="&closeCmd.label;" key="key_close" accesskey="&closeCmd.accesskey;" observes="cmd_close"/>
|
||||
<key id="key_close" xulkey="true" key="&closeCmd.key;" observes="cmd_close"/>
|
||||
<!-- emacs delete keys -->
|
||||
<key id="emacsbackspacekb" key="h" control="true" onkeypress="EditorDeleteCharBackward()" />
|
||||
<key id="emacsdeletekb" key="d" control="true" onkeypress="EditorDeleteCharForward()" />
|
||||
<key id="emacsdeletewordbackwardkb" key="w" control="true" onkeypress="EditorDeleteWordBackward()" />
|
||||
<key id="emacskilltoendkb" key="k" control="true" onkeypress="EditorDeleteToEndOfLine()" />
|
||||
|
||||
<!-- emacs motion keys -->
|
||||
<!-- These are still waiting on the selection controller API -->
|
||||
<key id="emacsbolkb" key="a" control="true" onkeypress="_EditorNotImplemented()" />
|
||||
<key id="emacseolkb" key="e" control="true" onkeypress="_EditorNotImplemented()" />
|
||||
<key id="emacsbackkb" key="b" control="true" onkeypress="_EditorNotImplemented()" />
|
||||
<key id="emacsforwardkb" key="f" control="true" onkeypress="_EditorNotImplemented()" />
|
||||
<key id="emacsupkb" key="p" control="true" onkeypress="_EditorNotImplemented()" />
|
||||
<key id="emacsdownkb" key="n" control="true" onkeypress="_EditorNotImplemented()" />
|
||||
<key id="emacspagedownkb" key="v" control="true" onkeypress="_EditorNotImplemented()" />
|
||||
<key id="emacspageupkb" key="v" meta="true" onkeypress="_EditorNotImplemented()" />
|
||||
|
||||
</keyset>
|
||||
|
||||
<!-- close -->
|
||||
<menuitem id="menu_close" value="&closeCmd.label;" key="key_close" accesskey="&closeCmd.accesskey;" observes="cmd_close"/>
|
||||
<key id="key_close" xulkey="true" key="&closeCmd.key;" observes="cmd_close"/>
|
||||
|
||||
<!-- quit -->
|
||||
<menupopup id="menu_FilePopup">
|
||||
<menuitem value="&quitApplicationCmd.label;" key="key_quit" accesskey="&quitApplicationCmd.accesskey;" observes="cmd_quit"/>
|
||||
</menupopup>
|
||||
<key id="key_quit" xulkey="true" key="&quitApplicationCmd.key;" observes="cmd_quit"/>
|
||||
<broadcaster id="cmd_quit" oncommand="goQuitApplication()"/>
|
||||
|
||||
<!-- quit -->
|
||||
<menupopup id="menu_FilePopup">
|
||||
<menuitem value="&quitApplicationCmd.label;" key="key_quit" accesskey="&quitApplicationCmd.accesskey;" observes="cmd_quit"/>
|
||||
</menupopup>
|
||||
<key id="key_quit" xulkey="true" key="&quitApplicationCmd.key;" observes="cmd_quit"/>
|
||||
<broadcaster id="cmd_quit" oncommand="goQuitApplication()"/>
|
||||
|
||||
<!-- Edit Menu -->
|
||||
<menuitem id="menu_redo" value="&redoCmd.label;" key="key_redo" accesskey="&redoCmd.accesskey;" observes="cmd_redo"/>
|
||||
<key id="key_redo" xulkey="true" shift="true" key="&redoCmd.key;" observes="cmd_redo"/>
|
||||
<!-- Edit Menu -->
|
||||
<menuitem id="menu_redo" value="&redoCmd.label;" key="key_redo" accesskey="&redoCmd.accesskey;" observes="cmd_redo"/>
|
||||
<key id="key_redo" xulkey="true" shift="true" key="&redoCmd.key;" observes="cmd_redo"/>
|
||||
|
||||
</overlay>
|
||||
|
|
Загрузка…
Ссылка в новой задаче