1999-02-12 20:18:58 +03:00
|
|
|
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*-
|
|
|
|
*
|
|
|
|
* The contents of this file are subject to the Netscape Public License
|
|
|
|
* Version 1.0 (the "NPL"); you may not use this file except in
|
|
|
|
* compliance with the NPL. You may obtain a copy of the NPL at
|
|
|
|
* http://www.mozilla.org/NPL/
|
|
|
|
*
|
|
|
|
* Software distributed under the NPL is distributed on an "AS IS" basis,
|
|
|
|
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
|
|
|
|
* for the specific language governing rights and limitations under the
|
|
|
|
* NPL.
|
|
|
|
*
|
|
|
|
* The Initial Developer of this code under the NPL is Netscape
|
|
|
|
* Communications Corporation. Portions created by Netscape are
|
|
|
|
* Copyright (C) 1998 Netscape Communications Corporation. All Rights
|
|
|
|
* Reserved.
|
|
|
|
*/
|
|
|
|
#include "nsEditorEventListeners.h"
|
|
|
|
#include "nsEditor.h"
|
1999-08-09 05:37:50 +04:00
|
|
|
#include "nsVoidArray.h"
|
|
|
|
#include "nsString.h"
|
|
|
|
|
1999-02-12 20:18:58 +03:00
|
|
|
#include "nsIDOMDocument.h"
|
Preparation for ender-based text control
* added focus listener. Doesn't do much yet, but when focus notifications start appearing, we'll be ready for them. The code is in
place to hide selection when we lose focus and paint selection when we get focus. That's probably not quite right, but it's a start.
We will need to be able to determine the distinction between losing focus to another control within our app, and losing focus to
another app.
* added support for disabled and readonly states in the editor. This is accomplished by having flags set by the client, and letting the
rules system deal with those flags. The flags I added are:
TEXT_EDITOR_FLAG_PLAINTEXT 0x01 // only plain text editing is allowed
TEXT_EDITOR_FLAG_SINGLELINE 0x02 // enter key and CR-LF handled specially
TEXT_EDITOR_FLAG_PASSWORD 0x04 // text is not entered into content, only a representative character
TEXT_EDITOR_FLAG_READONLY 0x08 // editing events are disabled. Editor may still accept focus.
TEXT_EDITOR_FLAG_DISALBED 0x10 // all events are disabled (like scrolling). Editor will not accept focus.
* added WillInsertBreak/DidInsertBreak into text rules, so flags could be checked. This gets us readonly, disabled, and single line
behavior.
* cleaned up the code that allocates, registers, and destroys event listeners. Thanks to Kin and Simon for cleaning up the
ownership model on the listeners, it was a big help.
* added support for a max text length. You can now tell the text editor, be no bigger than n characters.
1999-05-29 01:24:18 +04:00
|
|
|
#include "nsIDocument.h"
|
|
|
|
#include "nsIPresShell.h"
|
1999-02-12 20:18:58 +03:00
|
|
|
#include "nsIDOMElement.h"
|
1999-05-07 23:22:38 +04:00
|
|
|
#include "nsIDOMSelection.h"
|
1999-02-12 20:18:58 +03:00
|
|
|
#include "nsIDOMCharacterData.h"
|
1999-02-24 20:24:37 +03:00
|
|
|
#include "nsIEditProperty.h"
|
|
|
|
#include "nsISupportsArray.h"
|
1999-03-23 01:10:29 +03:00
|
|
|
#include "nsIStringStream.h"
|
1999-05-19 03:51:04 +04:00
|
|
|
#include "nsIDOMUIEvent.h"
|
1999-06-09 01:51:40 +04:00
|
|
|
#include "nsIDOMNSUIEvent.h"
|
1999-08-06 06:32:13 +04:00
|
|
|
#include "nsIPrivateTextEvent.h"
|
1999-08-31 05:20:32 +04:00
|
|
|
#include "nsIPrivateCompositionEvent.h"
|
1999-08-09 05:37:50 +04:00
|
|
|
#include "nsIEditorMailSupport.h"
|
1999-08-24 22:30:19 +04:00
|
|
|
#include "nsIDocumentEncoder.h"
|
1999-04-20 21:43:26 +04:00
|
|
|
|
1999-08-02 17:53:23 +04:00
|
|
|
// for repainting hack only
|
|
|
|
#include "nsIView.h"
|
|
|
|
#include "nsIViewManager.h"
|
|
|
|
// end repainting hack only
|
|
|
|
|
1999-04-07 00:24:09 +04:00
|
|
|
// Drag & Drop, Clipboard
|
|
|
|
#include "nsIServiceManager.h"
|
|
|
|
#include "nsWidgetsCID.h"
|
|
|
|
#include "nsIClipboard.h"
|
1999-04-17 17:52:28 +04:00
|
|
|
#include "nsIDragService.h"
|
1999-05-07 23:42:27 +04:00
|
|
|
#include "nsIDragSession.h"
|
1999-04-07 00:24:09 +04:00
|
|
|
#include "nsITransferable.h"
|
|
|
|
#include "nsIFormatConverter.h"
|
1999-08-19 17:30:48 +04:00
|
|
|
#include "nsIContentIterator.h"
|
|
|
|
#include "nsIContent.h"
|
1999-08-25 12:35:06 +04:00
|
|
|
#include "nsISupportsPrimitives.h"
|
1999-08-19 17:30:48 +04:00
|
|
|
#include "nsLayoutCID.h"
|
1999-04-07 00:24:09 +04:00
|
|
|
|
|
|
|
// Drag & Drop, Clipboard Support
|
1999-05-07 23:42:27 +04:00
|
|
|
static NS_DEFINE_CID(kCDragServiceCID, NS_DRAGSERVICE_CID);
|
1999-05-14 01:53:57 +04:00
|
|
|
static NS_DEFINE_CID(kCTransferableCID, NS_TRANSFERABLE_CID);
|
1999-05-07 23:42:27 +04:00
|
|
|
static NS_DEFINE_IID(kCDataFlavorCID, NS_DATAFLAVOR_CID);
|
1999-08-19 17:30:48 +04:00
|
|
|
static NS_DEFINE_IID(kContentIteratorCID, NS_CONTENTITERATOR_CID);
|
|
|
|
static NS_DEFINE_CID(kCClipboardCID, NS_CLIPBOARD_CID);
|
|
|
|
static NS_DEFINE_IID(kCXIFConverterCID, NS_XIFFORMATCONVERTER_CID);
|
|
|
|
|
1999-04-07 00:24:09 +04:00
|
|
|
|
|
|
|
|
1999-02-12 20:18:58 +03:00
|
|
|
/*
|
|
|
|
* nsTextEditorKeyListener implementation
|
|
|
|
*/
|
|
|
|
|
|
|
|
NS_IMPL_ADDREF(nsTextEditorKeyListener)
|
|
|
|
|
|
|
|
NS_IMPL_RELEASE(nsTextEditorKeyListener)
|
|
|
|
|
|
|
|
|
1999-03-20 02:36:20 +03:00
|
|
|
nsTextEditorKeyListener::nsTextEditorKeyListener()
|
1999-02-12 20:18:58 +03:00
|
|
|
{
|
|
|
|
NS_INIT_REFCNT();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
nsTextEditorKeyListener::~nsTextEditorKeyListener()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
nsresult
|
|
|
|
nsTextEditorKeyListener::QueryInterface(REFNSIID aIID, void** aInstancePtr)
|
|
|
|
{
|
|
|
|
if (nsnull == aInstancePtr) {
|
|
|
|
return NS_ERROR_NULL_POINTER;
|
|
|
|
}
|
1999-06-30 01:01:31 +04:00
|
|
|
if (aIID.Equals(nsCOMTypeInfo<nsISupports>::GetIID())) {
|
1999-02-12 20:18:58 +03:00
|
|
|
*aInstancePtr = (void*)(nsISupports*)this;
|
|
|
|
NS_ADDREF_THIS();
|
|
|
|
return NS_OK;
|
|
|
|
}
|
1999-05-28 04:19:51 +04:00
|
|
|
if (aIID.Equals(nsIDOMEventListener::GetIID())) {
|
1999-02-12 20:18:58 +03:00
|
|
|
*aInstancePtr = (void*)(nsIDOMEventListener*)this;
|
|
|
|
NS_ADDREF_THIS();
|
|
|
|
return NS_OK;
|
|
|
|
}
|
1999-05-28 04:19:51 +04:00
|
|
|
if (aIID.Equals(nsIDOMKeyListener::GetIID())) {
|
1999-02-12 20:18:58 +03:00
|
|
|
*aInstancePtr = (void*)(nsIDOMKeyListener*)this;
|
|
|
|
NS_ADDREF_THIS();
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
return NS_NOINTERFACE;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
nsresult
|
1999-03-29 02:27:38 +04:00
|
|
|
nsTextEditorKeyListener::HandleEvent(nsIDOMEvent* aEvent)
|
1999-02-12 20:18:58 +03:00
|
|
|
{
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
1999-07-07 03:31:08 +04:00
|
|
|
// individual key handlers return NS_OK to indicate NOT consumed
|
|
|
|
// by default, an error is returned indicating event is consumed
|
|
|
|
// joki is fixing this interface.
|
1999-06-04 09:14:01 +04:00
|
|
|
nsresult
|
|
|
|
nsTextEditorKeyListener::KeyDown(nsIDOMEvent* aKeyEvent)
|
|
|
|
{
|
1999-09-19 14:30:30 +04:00
|
|
|
PRUint32 keyCode;
|
|
|
|
nsCOMPtr<nsIDOMUIEvent>uiEvent;
|
|
|
|
uiEvent = do_QueryInterface(aKeyEvent);
|
|
|
|
if (uiEvent)
|
|
|
|
{
|
|
|
|
if (NS_SUCCEEDED(uiEvent->GetKeyCode(&keyCode)))
|
|
|
|
{
|
|
|
|
if (nsIDOMUIEvent::VK_TAB==keyCode)
|
|
|
|
{
|
|
|
|
nsCOMPtr<nsIHTMLEditor> htmlEditor = do_QueryInterface(mEditor);
|
|
|
|
PRUint32 flags=0;
|
|
|
|
mEditor->GetFlags(&flags);
|
|
|
|
if ((flags & nsIHTMLEditor::eEditorSingleLineMask))
|
|
|
|
return NS_OK; // let it be used for focus switching
|
|
|
|
|
|
|
|
// else we insert the tab straight through
|
|
|
|
htmlEditor->EditorKeyPress(uiEvent);
|
|
|
|
ScrollSelectionIntoView();
|
|
|
|
return NS_ERROR_BASE; // "I handled the event, don't do default processing"
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
1999-09-18 00:11:13 +04:00
|
|
|
return NS_OK;
|
1999-02-12 20:18:58 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
nsresult
|
|
|
|
nsTextEditorKeyListener::KeyUp(nsIDOMEvent* aKeyEvent)
|
|
|
|
{
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
1999-06-04 09:14:01 +04:00
|
|
|
nsresult
|
|
|
|
nsTextEditorKeyListener::KeyPress(nsIDOMEvent* aKeyEvent)
|
|
|
|
{
|
1999-08-25 14:51:55 +04:00
|
|
|
nsAutoString key;
|
|
|
|
PRUint32 character;
|
|
|
|
PRUint32 keyCode;
|
|
|
|
|
|
|
|
nsCOMPtr<nsIDOMUIEvent>uiEvent;
|
|
|
|
uiEvent = do_QueryInterface(aKeyEvent);
|
|
|
|
if (!uiEvent)
|
|
|
|
{
|
|
|
|
//non-key event passed to keydown. bad things.
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
//
|
|
|
|
// look at the keyCode if it is return or backspace, process it
|
|
|
|
// we handle these two special characters here because it makes windows integration
|
|
|
|
// eaiser
|
|
|
|
//
|
1999-07-08 23:52:44 +04:00
|
|
|
|
1999-08-20 17:14:03 +04:00
|
|
|
PRBool keyProcessed;
|
|
|
|
ProcessShortCutKeys(aKeyEvent, keyProcessed);
|
|
|
|
if (PR_FALSE==keyProcessed)
|
|
|
|
{
|
1999-08-25 14:51:55 +04:00
|
|
|
PRBool ctrlKey, altKey, metaKey;
|
|
|
|
uiEvent->GetCtrlKey(&ctrlKey);
|
|
|
|
uiEvent->GetAltKey(&altKey);
|
|
|
|
uiEvent->GetMetaKey(&metaKey);
|
|
|
|
|
1999-09-18 00:11:13 +04:00
|
|
|
#ifdef BLOCK_META_FOR_SOME_REASON
|
1999-08-25 14:51:55 +04:00
|
|
|
if (metaKey)
|
|
|
|
return NS_OK; // don't consume
|
1999-09-18 00:11:13 +04:00
|
|
|
#endif
|
1999-08-25 14:51:55 +04:00
|
|
|
|
|
|
|
nsCOMPtr<nsIHTMLEditor> htmlEditor = do_QueryInterface(mEditor);
|
|
|
|
if (!htmlEditor) return NS_ERROR_NO_INTERFACE;
|
|
|
|
|
|
|
|
if (NS_SUCCEEDED(uiEvent->GetKeyCode(&keyCode)))
|
|
|
|
{
|
|
|
|
if (nsIDOMUIEvent::VK_BACK==keyCode)
|
|
|
|
{
|
|
|
|
mEditor->DeleteSelection(nsIEditor::eDeletePrevious);
|
1999-08-31 05:14:40 +04:00
|
|
|
ScrollSelectionIntoView();
|
|
|
|
return NS_ERROR_BASE; // consumed
|
1999-08-25 14:51:55 +04:00
|
|
|
}
|
1999-09-18 00:11:13 +04:00
|
|
|
if (nsIDOMUIEvent::VK_DELETE==keyCode)
|
|
|
|
{
|
|
|
|
mEditor->DeleteSelection(nsIEditor::eDeleteNext);
|
|
|
|
ScrollSelectionIntoView();
|
|
|
|
return NS_ERROR_BASE; // consumed
|
|
|
|
}
|
|
|
|
if (nsIDOMUIEvent::VK_TAB==keyCode)
|
|
|
|
{
|
|
|
|
if (metaKey || altKey) // why block option-tab?
|
|
|
|
return NS_OK; // don't consume
|
|
|
|
|
|
|
|
PRUint32 flags=0;
|
|
|
|
mEditor->GetFlags(&flags);
|
|
|
|
if ((flags & nsIHTMLEditor::eEditorSingleLineMask))
|
|
|
|
return NS_OK; // let it be used for focus switching
|
|
|
|
|
|
|
|
// else we insert the tab straight through
|
|
|
|
htmlEditor->EditorKeyPress(uiEvent);
|
|
|
|
ScrollSelectionIntoView();
|
|
|
|
return NS_ERROR_BASE; // "I handled the event, don't do default processing"
|
|
|
|
}
|
1999-08-25 14:51:55 +04:00
|
|
|
if (nsIDOMUIEvent::VK_RETURN==keyCode)
|
1999-08-23 10:42:04 +04:00
|
|
|
{
|
1999-09-18 00:11:13 +04:00
|
|
|
PRUint32 flags=0;
|
1999-08-23 10:42:04 +04:00
|
|
|
mEditor->GetFlags(&flags);
|
|
|
|
if (!(flags & nsIHTMLEditor::eEditorSingleLineMask))
|
|
|
|
{
|
1999-09-13 13:37:51 +04:00
|
|
|
//htmlEditor->InsertBreak();
|
|
|
|
htmlEditor->EditorKeyPress(uiEvent);
|
1999-08-31 05:14:40 +04:00
|
|
|
ScrollSelectionIntoView();
|
1999-08-25 14:51:55 +04:00
|
|
|
return NS_ERROR_BASE; // consumed
|
1999-08-23 10:42:04 +04:00
|
|
|
}
|
1999-08-25 14:51:55 +04:00
|
|
|
else
|
|
|
|
{
|
1999-08-23 10:42:04 +04:00
|
|
|
return NS_OK;
|
|
|
|
}
|
1999-08-25 14:51:55 +04:00
|
|
|
}
|
|
|
|
}
|
1999-09-13 13:37:51 +04:00
|
|
|
|
|
|
|
// i turned off the blocking of alt keys - these are option-keypresses on mac and
|
|
|
|
// it's traditional that those go through (and they are used to generate some additional
|
|
|
|
// characters) - joe
|
|
|
|
if (/*(PR_FALSE==altKey) &&*/ (PR_FALSE==ctrlKey) &&
|
1999-08-25 14:51:55 +04:00
|
|
|
(NS_SUCCEEDED(uiEvent->GetCharCode(&character))))
|
|
|
|
{
|
|
|
|
if (nsIDOMUIEvent::VK_TAB==character)
|
|
|
|
{
|
|
|
|
return NS_OK; // ignore tabs here, they're handled in keyDown if at all
|
|
|
|
}
|
1999-09-13 13:37:51 +04:00
|
|
|
htmlEditor->EditorKeyPress(uiEvent);
|
1999-08-31 05:14:40 +04:00
|
|
|
ScrollSelectionIntoView();
|
1999-08-25 14:51:55 +04:00
|
|
|
}
|
|
|
|
}
|
1999-08-31 05:14:40 +04:00
|
|
|
else
|
|
|
|
ScrollSelectionIntoView();
|
1999-08-25 14:51:55 +04:00
|
|
|
|
|
|
|
return NS_ERROR_BASE; // consumed
|
1999-06-04 09:14:01 +04:00
|
|
|
|
|
|
|
}
|
|
|
|
|
1999-02-12 20:18:58 +03:00
|
|
|
|
|
|
|
/* these includes are for debug only. this module should never instantiate it's own transactions */
|
|
|
|
#include "SplitElementTxn.h"
|
|
|
|
#include "TransactionFactory.h"
|
1999-05-27 08:08:59 +04:00
|
|
|
|
1999-02-12 20:18:58 +03:00
|
|
|
nsresult
|
|
|
|
nsTextEditorKeyListener::ProcessShortCutKeys(nsIDOMEvent* aKeyEvent, PRBool& aProcessed)
|
|
|
|
{
|
|
|
|
aProcessed=PR_FALSE;
|
|
|
|
PRUint32 keyCode;
|
|
|
|
PRBool isShift;
|
|
|
|
PRBool ctrlKey;
|
1999-03-23 01:10:29 +03:00
|
|
|
PRBool altKey;
|
1999-05-19 03:51:04 +04:00
|
|
|
|
|
|
|
nsCOMPtr<nsIDOMUIEvent>uiEvent;
|
|
|
|
uiEvent = do_QueryInterface(aKeyEvent);
|
|
|
|
if (!uiEvent) {
|
|
|
|
//non-key event passed in. bad things.
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
1999-08-20 17:14:03 +04:00
|
|
|
if (NS_SUCCEEDED(uiEvent->GetCharCode(&keyCode)) &&
|
|
|
|
// if (NS_SUCCEEDED(uiEvent->GetKeyCode(&keyCode)) &&
|
1999-05-19 03:51:04 +04:00
|
|
|
NS_SUCCEEDED(uiEvent->GetShiftKey(&isShift)) &&
|
|
|
|
NS_SUCCEEDED(uiEvent->GetCtrlKey(&ctrlKey)) &&
|
1999-08-25 14:51:55 +04:00
|
|
|
NS_SUCCEEDED(uiEvent->GetAltKey(&altKey)) )
|
1999-02-12 20:18:58 +03:00
|
|
|
{
|
1999-09-10 18:42:20 +04:00
|
|
|
#ifdef XP_MAC
|
|
|
|
// hack to make Mac work for hard-coded keybindings
|
|
|
|
// metaKey query is only way to query for command key on Mac
|
|
|
|
// if that's pressed, we'll set the ctrlKey boolean
|
|
|
|
// (even though the control key might also be pressed)
|
|
|
|
PRBool isMetaKey;
|
|
|
|
if (NS_SUCCEEDED(uiEvent->GetMetaKey(&isMetaKey)) && PR_TRUE==isMetaKey) {
|
|
|
|
ctrlKey = PR_TRUE;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
1999-07-07 03:31:08 +04:00
|
|
|
if (PR_TRUE==ctrlKey) {
|
|
|
|
aProcessed = PR_TRUE;
|
|
|
|
}
|
|
|
|
// swallow all control keys
|
1999-02-12 20:18:58 +03:00
|
|
|
// XXX: please please please get these mappings from an external source!
|
|
|
|
switch (keyCode)
|
|
|
|
{
|
1999-03-10 22:49:43 +03:00
|
|
|
// XXX: hard-coded select all
|
1999-05-19 03:51:04 +04:00
|
|
|
case nsIDOMUIEvent::VK_A:
|
1999-09-10 18:42:20 +04:00
|
|
|
case (PRUint32)('a'):
|
1999-03-10 22:49:43 +03:00
|
|
|
if (PR_TRUE==ctrlKey)
|
|
|
|
{
|
|
|
|
if (mEditor)
|
|
|
|
mEditor->SelectAll();
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
1999-03-11 01:46:15 +03:00
|
|
|
// XXX: hard-coded cut
|
1999-05-19 03:51:04 +04:00
|
|
|
case nsIDOMUIEvent::VK_X:
|
1999-08-28 04:31:06 +04:00
|
|
|
case (PRUint32)('x'):
|
1999-03-11 01:46:15 +03:00
|
|
|
if (PR_TRUE==ctrlKey)
|
|
|
|
{
|
|
|
|
if (mEditor)
|
|
|
|
mEditor->Cut();
|
|
|
|
}
|
1999-06-09 23:12:28 +04:00
|
|
|
else if (PR_TRUE==altKey)
|
|
|
|
{
|
|
|
|
aProcessed=PR_TRUE;
|
1999-09-15 03:40:16 +04:00
|
|
|
nsAutoString output;
|
1999-06-09 23:12:28 +04:00
|
|
|
nsresult res = NS_ERROR_FAILURE;
|
1999-09-15 03:40:16 +04:00
|
|
|
nsAutoString format;
|
1999-07-14 22:54:29 +04:00
|
|
|
if (isShift)
|
|
|
|
format = "text/plain";
|
|
|
|
else
|
|
|
|
format = "text/html";
|
|
|
|
res = mEditor->OutputToString(output, format,
|
1999-08-24 22:30:19 +04:00
|
|
|
nsIDocumentEncoder::OutputFormatted);
|
1999-06-09 23:12:28 +04:00
|
|
|
if (NS_SUCCEEDED(res))
|
|
|
|
{
|
|
|
|
char* buf = output.ToNewCString();
|
|
|
|
if (buf)
|
|
|
|
{
|
|
|
|
puts(buf);
|
1999-09-06 10:22:51 +04:00
|
|
|
nsCRT::free(buf);
|
1999-06-09 23:12:28 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
1999-03-11 01:46:15 +03:00
|
|
|
break;
|
|
|
|
|
|
|
|
// XXX: hard-coded copy
|
1999-05-19 03:51:04 +04:00
|
|
|
case nsIDOMUIEvent::VK_C:
|
1999-09-10 18:42:20 +04:00
|
|
|
case (PRUint32)('c'):
|
1999-03-11 01:46:15 +03:00
|
|
|
if (PR_TRUE==ctrlKey)
|
|
|
|
{
|
|
|
|
if (mEditor)
|
|
|
|
mEditor->Copy();
|
|
|
|
}
|
1999-05-14 02:11:05 +04:00
|
|
|
else if (PR_TRUE==altKey)
|
|
|
|
{
|
|
|
|
printf("Getting number of columns\n");
|
|
|
|
aProcessed=PR_TRUE;
|
1999-08-09 05:37:50 +04:00
|
|
|
nsCOMPtr<nsIEditorMailSupport> mailEditor = do_QueryInterface(mEditor);
|
|
|
|
if (mailEditor)
|
|
|
|
{
|
1999-08-25 14:51:55 +04:00
|
|
|
PRInt32 wrap;
|
|
|
|
if (NS_SUCCEEDED(mailEditor->GetBodyWrapWidth(&wrap)))
|
|
|
|
printf("Currently wrapping to %d\n", wrap);
|
|
|
|
else
|
|
|
|
printf("GetBodyWrapWidth returned an error\n");
|
1999-08-09 05:37:50 +04:00
|
|
|
}
|
1999-05-14 02:11:05 +04:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
1999-05-19 03:51:04 +04:00
|
|
|
case nsIDOMUIEvent::VK_OPEN_BRACKET:
|
1999-05-14 02:11:05 +04:00
|
|
|
// hard coded "Decrease wrap size"
|
|
|
|
if (PR_TRUE==altKey)
|
|
|
|
{
|
1999-08-25 14:51:55 +04:00
|
|
|
nsCOMPtr<nsIEditorMailSupport> mailEditor = do_QueryInterface(mEditor);
|
|
|
|
if (mailEditor)
|
|
|
|
{
|
|
|
|
aProcessed=PR_TRUE;
|
|
|
|
PRInt32 wrap;
|
|
|
|
if (!NS_SUCCEEDED(mailEditor->GetBodyWrapWidth(&wrap)))
|
|
|
|
{
|
|
|
|
printf("GetBodyWrapWidth returned an error\n");
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
mailEditor->SetBodyWrapWidth(wrap - 5);
|
|
|
|
if (!NS_SUCCEEDED(mailEditor->GetBodyWrapWidth(&wrap)))
|
|
|
|
{
|
|
|
|
printf("Second GetBodyWrapWidth returned an error\n");
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
else printf("Now wrapping to %d\n", wrap);
|
|
|
|
}
|
1999-05-14 02:11:05 +04:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
1999-05-19 03:51:04 +04:00
|
|
|
case nsIDOMUIEvent::VK_CLOSE_BRACKET:
|
1999-05-14 02:11:05 +04:00
|
|
|
// hard coded "Increase wrap size"
|
|
|
|
if (PR_TRUE==altKey)
|
|
|
|
{
|
1999-08-25 14:51:55 +04:00
|
|
|
nsCOMPtr<nsIEditorMailSupport> mailEditor = do_QueryInterface(mEditor);
|
|
|
|
if (mailEditor)
|
|
|
|
{
|
|
|
|
aProcessed=PR_TRUE;
|
|
|
|
PRInt32 wrap;
|
|
|
|
if (!NS_SUCCEEDED(mailEditor->GetBodyWrapWidth(&wrap)))
|
|
|
|
{
|
|
|
|
printf("GetBodyWrapWidth returned an error\n");
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
mailEditor->SetBodyWrapWidth(wrap + 5);
|
|
|
|
if (!NS_SUCCEEDED(mailEditor->GetBodyWrapWidth(&wrap)))
|
|
|
|
{
|
|
|
|
printf("Second GetBodyWrapWidth returned an error\n");
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
else printf("Now wrapping to %d\n", wrap);
|
|
|
|
}
|
1999-05-14 02:11:05 +04:00
|
|
|
}
|
1999-03-11 01:46:15 +03:00
|
|
|
break;
|
|
|
|
|
1999-08-21 02:39:48 +04:00
|
|
|
// Hard coded "No wrap" or "wrap to window size"
|
|
|
|
case nsIDOMUIEvent::VK_BACK_SLASH:
|
|
|
|
{
|
|
|
|
if (PR_TRUE==ctrlKey)
|
|
|
|
{
|
|
|
|
nsCOMPtr<nsIEditorMailSupport> mailEditor =
|
|
|
|
do_QueryInterface(mEditor);
|
|
|
|
if (mailEditor)
|
|
|
|
{
|
|
|
|
aProcessed=PR_TRUE;
|
|
|
|
mailEditor->SetBodyWrapWidth(0);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (PR_TRUE==altKey)
|
|
|
|
{
|
|
|
|
nsCOMPtr<nsIEditorMailSupport> mailEditor =
|
|
|
|
do_QueryInterface(mEditor);
|
|
|
|
if (mailEditor)
|
|
|
|
{
|
|
|
|
aProcessed=PR_TRUE;
|
|
|
|
mailEditor->SetBodyWrapWidth(-1);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
1999-03-11 01:46:15 +03:00
|
|
|
// XXX: hard-coded paste
|
1999-05-19 03:51:04 +04:00
|
|
|
case nsIDOMUIEvent::VK_V:
|
1999-09-10 18:42:20 +04:00
|
|
|
case (PRUint32)('v'):
|
1999-03-11 01:46:15 +03:00
|
|
|
if (PR_TRUE==ctrlKey)
|
|
|
|
{
|
|
|
|
printf("control-v\n");
|
|
|
|
if (mEditor)
|
1999-05-27 04:08:15 +04:00
|
|
|
{
|
|
|
|
if (altKey)
|
1999-08-09 05:37:50 +04:00
|
|
|
{
|
|
|
|
nsCOMPtr<nsIEditorMailSupport> mailEditor = do_QueryInterface(mEditor);
|
|
|
|
if (mailEditor)
|
|
|
|
mailEditor->PasteAsQuotation();
|
|
|
|
}
|
1999-05-27 04:08:15 +04:00
|
|
|
else
|
|
|
|
mEditor->Paste();
|
|
|
|
}
|
1999-03-11 01:46:15 +03:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
1999-02-12 20:18:58 +03:00
|
|
|
// XXX: hard-coded undo
|
1999-05-19 03:51:04 +04:00
|
|
|
case nsIDOMUIEvent::VK_Z:
|
1999-09-10 18:42:20 +04:00
|
|
|
case (PRUint32)('z'):
|
1999-06-15 05:24:23 +04:00
|
|
|
if (PR_TRUE==ctrlKey)
|
1999-02-12 20:18:58 +03:00
|
|
|
{
|
1999-03-02 10:52:41 +03:00
|
|
|
if (mEditor)
|
1999-02-12 20:18:58 +03:00
|
|
|
mEditor->Undo(1);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
// XXX: hard-coded redo
|
1999-05-19 03:51:04 +04:00
|
|
|
case nsIDOMUIEvent::VK_Y:
|
1999-09-10 18:42:20 +04:00
|
|
|
case (PRUint32)('y'):
|
1999-02-12 20:18:58 +03:00
|
|
|
if (PR_TRUE==ctrlKey)
|
|
|
|
{
|
1999-03-02 10:52:41 +03:00
|
|
|
if (mEditor)
|
1999-02-12 20:18:58 +03:00
|
|
|
mEditor->Redo(1);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
1999-02-24 20:24:37 +03:00
|
|
|
// hard-coded ChangeTextAttributes test -- italics
|
1999-05-19 03:51:04 +04:00
|
|
|
case nsIDOMUIEvent::VK_I:
|
1999-02-12 20:18:58 +03:00
|
|
|
if (PR_TRUE==ctrlKey)
|
|
|
|
{
|
1999-08-09 05:37:50 +04:00
|
|
|
nsCOMPtr<nsIHTMLEditor> htmlEditor = do_QueryInterface(mEditor);
|
|
|
|
if (htmlEditor)
|
1999-02-12 20:18:58 +03:00
|
|
|
{
|
1999-04-04 22:01:35 +04:00
|
|
|
// XXX: move this logic down into texteditor rules delegate
|
|
|
|
// should just call mEditor->ChangeTextProperty(prop)
|
|
|
|
PRBool any = PR_FALSE;
|
|
|
|
PRBool all = PR_FALSE;
|
|
|
|
PRBool first = PR_FALSE;
|
1999-08-09 05:37:50 +04:00
|
|
|
htmlEditor->GetInlineProperty(nsIEditProperty::i, nsnull, nsnull, first, any, all);
|
1999-04-04 22:01:35 +04:00
|
|
|
if (PR_FALSE==first) {
|
1999-08-09 05:37:50 +04:00
|
|
|
htmlEditor->SetInlineProperty(nsIEditProperty::i, nsnull, nsnull);
|
1999-04-04 22:01:35 +04:00
|
|
|
}
|
|
|
|
else {
|
1999-08-09 05:37:50 +04:00
|
|
|
htmlEditor->RemoveInlineProperty(nsIEditProperty::i, nsnull);
|
1999-04-04 22:01:35 +04:00
|
|
|
}
|
1999-02-24 20:24:37 +03:00
|
|
|
}
|
|
|
|
}
|
1999-03-23 01:10:29 +03:00
|
|
|
|
|
|
|
// Hardcoded Insert Arbitrary HTML
|
|
|
|
else if (PR_TRUE==altKey)
|
|
|
|
{
|
|
|
|
aProcessed=PR_TRUE;
|
1999-08-09 05:37:50 +04:00
|
|
|
nsCOMPtr<nsIHTMLEditor> htmlEditor = do_QueryInterface(mEditor);
|
1999-05-07 23:22:38 +04:00
|
|
|
if (htmlEditor)
|
1999-03-23 01:10:29 +03:00
|
|
|
{
|
1999-09-15 03:40:16 +04:00
|
|
|
nsAutoString nsstr ("This is <b>bold <em>and emphasized</em></b> text");
|
1999-06-11 01:31:42 +04:00
|
|
|
htmlEditor->InsertHTML(nsstr);
|
1999-03-23 01:10:29 +03:00
|
|
|
}
|
|
|
|
}
|
1999-02-24 20:24:37 +03:00
|
|
|
break;
|
|
|
|
|
|
|
|
// hard-coded ChangeTextAttributes test -- bold
|
1999-05-19 03:51:04 +04:00
|
|
|
case nsIDOMUIEvent::VK_B:
|
1999-02-24 20:24:37 +03:00
|
|
|
if (PR_TRUE==ctrlKey)
|
|
|
|
{
|
1999-08-09 05:37:50 +04:00
|
|
|
nsCOMPtr<nsIHTMLEditor> htmlEditor = do_QueryInterface(mEditor);
|
|
|
|
if (htmlEditor)
|
1999-02-24 20:24:37 +03:00
|
|
|
{
|
1999-04-04 22:01:35 +04:00
|
|
|
// XXX: move this logic down into texteditor rules delegate
|
|
|
|
// should just call mEditor->ChangeTextProperty(prop)
|
|
|
|
PRBool any = PR_FALSE;
|
|
|
|
PRBool all = PR_FALSE;
|
|
|
|
PRBool first = PR_FALSE;
|
1999-08-09 05:37:50 +04:00
|
|
|
htmlEditor->GetInlineProperty(nsIEditProperty::b, nsnull, nsnull, first, any, all);
|
1999-04-04 22:01:35 +04:00
|
|
|
if (PR_FALSE==first) {
|
1999-08-09 05:37:50 +04:00
|
|
|
htmlEditor->SetInlineProperty(nsIEditProperty::b, nsnull, nsnull);
|
1999-04-04 22:01:35 +04:00
|
|
|
}
|
|
|
|
else {
|
1999-08-09 05:37:50 +04:00
|
|
|
htmlEditor->RemoveInlineProperty(nsIEditProperty::b, nsnull);
|
1999-04-04 22:01:35 +04:00
|
|
|
}
|
1999-03-02 10:52:41 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
As a reminder, we decided to do this based strictly content. Some support for style-based text properties is written, but not used
anywhere any more.
* Cleaned up split and join undo/redo.
* Added TypeInState, a data struct that remembers things about text properties for collapsed selections, so you can type
* Ctrl-B with an insertion point and the next character will be bold.
* Added all the logic to handle inline vs. block elements when setting text properties.
* Added some support for italic and underline as well. Adding these things is pretty easy now. Ctrl-B, Ctrl-I, Ctrl-U for testing bold, italic, underline.
* Added all the logic to make sure we only add style tags where they're needed, so you should never get the same style tag nested within itself, except as needed for block elements.
* Added methods for testing a node to see if a particular style is set. This isn't 100% done yet, but with very little work we could have toolbar buttons that respond to selection changed notification that show the state of bold, italic, underline, etc. in real time. Supports tri-state: whole selection is bold, some of selection is bold, none of selection is bold, ...
* Fully undoable and redoable.
* Added some debug printfs to transactions and editors. all controlled by a gNoisy static in each module. helps me track down undo/redo problems. if the output bugs people enough, I'll shut it off and re-enable it in my local tree.
Noticably missing: make un-bold, make un-italic, etc. This is coming soon.
1999-04-01 21:58:07 +04:00
|
|
|
// hard-coded ChangeTextAttributes test -- underline
|
1999-05-19 03:51:04 +04:00
|
|
|
case nsIDOMUIEvent::VK_U:
|
1999-03-02 10:52:41 +03:00
|
|
|
if (PR_TRUE==ctrlKey)
|
|
|
|
{
|
1999-08-09 05:37:50 +04:00
|
|
|
nsCOMPtr<nsIHTMLEditor> htmlEditor = do_QueryInterface(mEditor);
|
|
|
|
if (htmlEditor)
|
1999-03-02 10:52:41 +03:00
|
|
|
{
|
1999-04-04 22:01:35 +04:00
|
|
|
// XXX: move this logic down into texteditor rules delegate
|
|
|
|
// should just call mEditor->ChangeTextProperty(prop)
|
|
|
|
PRBool any = PR_FALSE;
|
|
|
|
PRBool all = PR_FALSE;
|
|
|
|
PRBool first = PR_FALSE;
|
1999-08-09 05:37:50 +04:00
|
|
|
htmlEditor->GetInlineProperty(nsIEditProperty::u, nsnull, nsnull, first, any, all);
|
1999-04-04 22:01:35 +04:00
|
|
|
if (PR_FALSE==first) {
|
1999-08-09 05:37:50 +04:00
|
|
|
htmlEditor->SetInlineProperty(nsIEditProperty::u, nsnull, nsnull);
|
1999-04-04 22:01:35 +04:00
|
|
|
}
|
|
|
|
else {
|
1999-08-09 05:37:50 +04:00
|
|
|
htmlEditor->RemoveInlineProperty(nsIEditProperty::u, nsnull);
|
1999-04-04 22:01:35 +04:00
|
|
|
}
|
1999-02-12 20:18:58 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
1999-04-15 10:06:33 +04:00
|
|
|
|
|
|
|
// hard-coded ChangeTextAttributes test -- font color red
|
1999-05-19 03:51:04 +04:00
|
|
|
case nsIDOMUIEvent::VK_1:
|
1999-04-15 10:06:33 +04:00
|
|
|
if (PR_TRUE==ctrlKey)
|
|
|
|
{
|
1999-08-09 05:37:50 +04:00
|
|
|
nsCOMPtr<nsIHTMLEditor> htmlEditor = do_QueryInterface(mEditor);
|
|
|
|
if (htmlEditor)
|
1999-04-15 10:06:33 +04:00
|
|
|
{
|
|
|
|
// XXX: move this logic down into texteditor rules delegate
|
|
|
|
// should just call mEditor->ChangeTextProperty(prop)
|
|
|
|
PRBool any = PR_FALSE;
|
|
|
|
PRBool all = PR_FALSE;
|
|
|
|
PRBool first = PR_FALSE;
|
1999-04-16 22:29:12 +04:00
|
|
|
nsAutoString color = "COLOR";
|
1999-04-15 10:06:33 +04:00
|
|
|
nsAutoString value = "red";
|
1999-08-09 05:37:50 +04:00
|
|
|
htmlEditor->GetInlineProperty(nsIEditProperty::font, &color, &value, first, any, all);
|
1999-04-22 18:46:53 +04:00
|
|
|
if (!all) {
|
1999-08-09 05:37:50 +04:00
|
|
|
htmlEditor->SetInlineProperty(nsIEditProperty::font, &color, &value);
|
1999-04-22 18:46:53 +04:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
printf("NOOP: all selected text is already red\n");
|
|
|
|
}
|
1999-04-15 10:06:33 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
1999-04-22 18:46:53 +04:00
|
|
|
// hard-coded ChangeTextAttributes test -- remove font color
|
1999-05-19 03:51:04 +04:00
|
|
|
case nsIDOMUIEvent::VK_2:
|
1999-04-15 10:06:33 +04:00
|
|
|
if (PR_TRUE==ctrlKey)
|
|
|
|
{
|
1999-08-09 05:37:50 +04:00
|
|
|
nsCOMPtr<nsIHTMLEditor> htmlEditor = do_QueryInterface(mEditor);
|
|
|
|
if (htmlEditor)
|
1999-04-15 10:06:33 +04:00
|
|
|
{
|
|
|
|
// XXX: move this logic down into texteditor rules delegate
|
|
|
|
// should just call mEditor->ChangeTextProperty(prop)
|
|
|
|
PRBool any = PR_FALSE;
|
|
|
|
PRBool all = PR_FALSE;
|
|
|
|
PRBool first = PR_FALSE;
|
1999-04-16 22:29:12 +04:00
|
|
|
nsAutoString color = "COLOR";
|
1999-08-09 05:37:50 +04:00
|
|
|
htmlEditor->GetInlineProperty(nsIEditProperty::font, &color, nsnull, first, any, all);
|
1999-04-22 18:46:53 +04:00
|
|
|
if (any) {
|
1999-08-09 05:37:50 +04:00
|
|
|
htmlEditor->RemoveInlineProperty(nsIEditProperty::font, &color);
|
1999-04-22 18:46:53 +04:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
printf("NOOP: no color set\n");
|
|
|
|
}
|
1999-04-15 10:06:33 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
1999-04-20 21:43:26 +04:00
|
|
|
// hard-coded ChangeTextAttributes test -- font size +2
|
1999-05-19 03:51:04 +04:00
|
|
|
case nsIDOMUIEvent::VK_3:
|
1999-04-20 21:43:26 +04:00
|
|
|
if (PR_TRUE==ctrlKey)
|
|
|
|
{
|
1999-08-09 05:37:50 +04:00
|
|
|
nsCOMPtr<nsIHTMLEditor> htmlEditor = do_QueryInterface(mEditor);
|
|
|
|
if (htmlEditor)
|
1999-04-20 21:43:26 +04:00
|
|
|
{
|
|
|
|
// XXX: move this logic down into texteditor rules delegate
|
|
|
|
// should just call mEditor->ChangeTextProperty(prop)
|
1999-05-07 23:22:38 +04:00
|
|
|
//PRBool any = PR_FALSE;
|
|
|
|
//PRBool all = PR_FALSE;
|
|
|
|
//PRBool first = PR_FALSE;
|
1999-04-20 21:43:26 +04:00
|
|
|
nsAutoString prop = "SIZE";
|
|
|
|
nsAutoString value = "+2";
|
1999-08-09 05:37:50 +04:00
|
|
|
htmlEditor->SetInlineProperty(nsIEditProperty::font, &prop, &value);
|
1999-04-20 21:43:26 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
// hard-coded ChangeTextAttributes test -- font size -2
|
1999-05-19 03:51:04 +04:00
|
|
|
case nsIDOMUIEvent::VK_4:
|
1999-04-20 21:43:26 +04:00
|
|
|
if (PR_TRUE==ctrlKey)
|
|
|
|
{
|
1999-08-09 05:37:50 +04:00
|
|
|
nsCOMPtr<nsIHTMLEditor> htmlEditor = do_QueryInterface(mEditor);
|
|
|
|
if (htmlEditor)
|
1999-04-20 21:43:26 +04:00
|
|
|
{
|
|
|
|
// XXX: move this logic down into texteditor rules delegate
|
|
|
|
// should just call mEditor->ChangeTextProperty(prop)
|
1999-05-07 23:22:38 +04:00
|
|
|
//PRBool any = PR_FALSE;
|
|
|
|
//PRBool all = PR_FALSE;
|
|
|
|
//PRBool first = PR_FALSE;
|
1999-04-20 21:43:26 +04:00
|
|
|
nsAutoString prop = "SIZE";
|
|
|
|
nsAutoString value = "-2";
|
1999-08-09 05:37:50 +04:00
|
|
|
htmlEditor->SetInlineProperty(nsIEditProperty::font, &prop, &value);
|
1999-04-20 21:43:26 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
1999-04-22 18:46:53 +04:00
|
|
|
// hard-coded ChangeTextAttributes test -- font face helvetica
|
1999-05-19 03:51:04 +04:00
|
|
|
case nsIDOMUIEvent::VK_5:
|
1999-04-20 21:43:26 +04:00
|
|
|
if (PR_TRUE==ctrlKey)
|
|
|
|
{
|
1999-08-09 05:37:50 +04:00
|
|
|
nsCOMPtr<nsIHTMLEditor> htmlEditor = do_QueryInterface(mEditor);
|
|
|
|
if (htmlEditor)
|
1999-04-20 21:43:26 +04:00
|
|
|
{
|
|
|
|
// XXX: move this logic down into texteditor rules delegate
|
|
|
|
// should just call mEditor->ChangeTextProperty(prop)
|
1999-05-07 23:22:38 +04:00
|
|
|
//PRBool any = PR_FALSE;
|
|
|
|
//PRBool all = PR_FALSE;
|
|
|
|
//PRBool first = PR_FALSE;
|
1999-04-20 21:43:26 +04:00
|
|
|
nsAutoString prop = "FACE";
|
|
|
|
nsAutoString value = "helvetica";
|
1999-08-09 05:37:50 +04:00
|
|
|
htmlEditor->SetInlineProperty(nsIEditProperty::font, &prop, &value);
|
1999-04-20 21:43:26 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
// hard-coded ChangeTextAttributes test -- font face times
|
1999-05-19 03:51:04 +04:00
|
|
|
case nsIDOMUIEvent::VK_6:
|
1999-04-20 21:43:26 +04:00
|
|
|
if (PR_TRUE==ctrlKey)
|
|
|
|
{
|
1999-08-09 05:37:50 +04:00
|
|
|
nsCOMPtr<nsIHTMLEditor> htmlEditor = do_QueryInterface(mEditor);
|
|
|
|
if (htmlEditor)
|
1999-04-20 21:43:26 +04:00
|
|
|
{
|
|
|
|
// XXX: move this logic down into texteditor rules delegate
|
|
|
|
// should just call mEditor->ChangeTextProperty(prop)
|
1999-05-07 23:22:38 +04:00
|
|
|
//PRBool any = PR_FALSE;
|
|
|
|
//PRBool all = PR_FALSE;
|
|
|
|
//PRBool first = PR_FALSE;
|
1999-04-20 21:43:26 +04:00
|
|
|
nsAutoString prop = "FACE";
|
|
|
|
nsAutoString value = "times";
|
1999-08-09 05:37:50 +04:00
|
|
|
htmlEditor->SetInlineProperty(nsIEditProperty::font, &prop, &value);
|
1999-04-20 21:43:26 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
1999-05-01 02:40:18 +04:00
|
|
|
// hard-coded change structure test -- transform block H1
|
1999-05-19 03:51:04 +04:00
|
|
|
case nsIDOMUIEvent::VK_7:
|
1999-04-20 21:43:26 +04:00
|
|
|
if (PR_TRUE==ctrlKey)
|
|
|
|
{
|
1999-08-09 05:37:50 +04:00
|
|
|
nsCOMPtr<nsIHTMLEditor> htmlEditor = do_QueryInterface(mEditor);
|
|
|
|
if (htmlEditor)
|
1999-04-20 21:43:26 +04:00
|
|
|
{
|
1999-08-09 05:37:50 +04:00
|
|
|
nsAutoString tag;
|
|
|
|
nsIEditProperty::h1->ToString(tag);
|
|
|
|
htmlEditor->ReplaceBlockParent(tag);
|
1999-04-20 21:43:26 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
1999-05-01 02:40:18 +04:00
|
|
|
// hard-coded change structure test -- transform block H2
|
1999-05-19 03:51:04 +04:00
|
|
|
case nsIDOMUIEvent::VK_8:
|
1999-04-20 21:43:26 +04:00
|
|
|
if (PR_TRUE==ctrlKey)
|
|
|
|
{
|
1999-08-09 05:37:50 +04:00
|
|
|
nsCOMPtr<nsIHTMLEditor> htmlEditor = do_QueryInterface(mEditor);
|
|
|
|
if (htmlEditor)
|
1999-04-20 21:43:26 +04:00
|
|
|
{
|
1999-08-09 05:37:50 +04:00
|
|
|
nsAutoString tag;
|
|
|
|
nsIEditProperty::h2->ToString(tag);
|
|
|
|
htmlEditor->ReplaceBlockParent(tag);
|
1999-04-20 21:43:26 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
// hard-coded change structure test -- normal
|
1999-05-19 03:51:04 +04:00
|
|
|
case nsIDOMUIEvent::VK_9:
|
1999-04-20 21:43:26 +04:00
|
|
|
if (PR_TRUE==ctrlKey)
|
|
|
|
{
|
1999-08-09 05:37:50 +04:00
|
|
|
nsCOMPtr<nsIHTMLEditor> htmlEditor = do_QueryInterface(mEditor);
|
|
|
|
if (htmlEditor) {
|
|
|
|
htmlEditor->RemoveParagraphStyle();
|
1999-05-05 08:05:19 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
// hard-coded change structure test -- GetParagraphStyle
|
1999-05-19 03:51:04 +04:00
|
|
|
case nsIDOMUIEvent::VK_0:
|
1999-05-05 08:05:19 +04:00
|
|
|
if (PR_TRUE==ctrlKey)
|
|
|
|
{
|
1999-08-09 05:37:50 +04:00
|
|
|
nsCOMPtr<nsIHTMLEditor> htmlEditor = do_QueryInterface(mEditor);
|
1999-05-05 08:05:19 +04:00
|
|
|
{
|
1999-08-09 05:37:50 +04:00
|
|
|
printf("testing GetParagraphStyle\n");
|
|
|
|
nsStringArray styles;
|
|
|
|
nsresult result = htmlEditor->GetParagraphStyle(&styles);
|
|
|
|
if (NS_SUCCEEDED(result))
|
1999-05-05 08:05:19 +04:00
|
|
|
{
|
1999-08-09 05:37:50 +04:00
|
|
|
PRInt32 count = styles.Count();
|
|
|
|
PRInt32 i;
|
|
|
|
for (i=0; i<count; i++)
|
1999-05-05 08:05:19 +04:00
|
|
|
{
|
1999-08-09 05:37:50 +04:00
|
|
|
nsString *tag = styles.StringAt(i);
|
|
|
|
char *tagCString = tag->ToNewCString();
|
|
|
|
printf("%s ", tagCString);
|
1999-09-06 10:22:51 +04:00
|
|
|
nsCRT::free(tagCString);
|
1999-05-05 08:05:19 +04:00
|
|
|
}
|
1999-08-09 05:37:50 +04:00
|
|
|
printf("\n");
|
1999-04-20 21:43:26 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
1999-05-01 02:40:18 +04:00
|
|
|
// hard-coded change structure test -- block blockquote (indent)
|
1999-05-19 03:51:04 +04:00
|
|
|
case nsIDOMUIEvent::VK_COMMA:
|
1999-05-01 02:40:18 +04:00
|
|
|
if (PR_TRUE==ctrlKey)
|
|
|
|
{
|
1999-08-09 05:37:50 +04:00
|
|
|
nsCOMPtr<nsIHTMLEditor> htmlEditor = do_QueryInterface(mEditor);
|
|
|
|
if (htmlEditor)
|
1999-05-01 02:40:18 +04:00
|
|
|
{
|
1999-08-09 05:37:50 +04:00
|
|
|
nsAutoString tag;
|
|
|
|
nsIEditProperty::blockquote->ToString(tag);
|
|
|
|
htmlEditor->AddBlockParent(tag);
|
1999-05-01 02:40:18 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
1999-04-22 18:46:53 +04:00
|
|
|
// hard-coded change structure test -- un-BlockQuote
|
1999-05-19 03:51:04 +04:00
|
|
|
case nsIDOMUIEvent::VK_PERIOD:
|
1999-04-22 18:46:53 +04:00
|
|
|
if (PR_TRUE==ctrlKey)
|
|
|
|
{
|
1999-08-09 05:37:50 +04:00
|
|
|
nsCOMPtr<nsIHTMLEditor> htmlEditor = do_QueryInterface(mEditor);
|
|
|
|
if (htmlEditor)
|
1999-04-22 18:46:53 +04:00
|
|
|
{
|
1999-08-09 05:37:50 +04:00
|
|
|
nsAutoString tag;
|
|
|
|
nsIEditProperty::blockquote->ToString(tag);
|
|
|
|
htmlEditor->RemoveParent(tag);
|
1999-04-22 18:46:53 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
1999-04-20 21:43:26 +04:00
|
|
|
|
1999-04-15 10:06:33 +04:00
|
|
|
#ifdef NS_DEBUG
|
|
|
|
// hard-coded Text Editor Unit Test
|
1999-05-19 03:51:04 +04:00
|
|
|
case nsIDOMUIEvent::VK_T:
|
1999-04-15 10:06:33 +04:00
|
|
|
if (PR_TRUE==ctrlKey)
|
|
|
|
{
|
|
|
|
if (mEditor)
|
|
|
|
{
|
1999-05-27 08:08:59 +04:00
|
|
|
PRInt32 numTests, numFailed;
|
|
|
|
// the unit tests are only exposed through nsIEditor
|
|
|
|
nsCOMPtr<nsIEditor> editor = do_QueryInterface(mEditor);
|
|
|
|
if (editor)
|
1999-08-25 14:51:55 +04:00
|
|
|
editor->DebugUnitTests(&numTests, &numFailed);
|
1999-04-15 10:06:33 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
#endif
|
|
|
|
|
1999-02-12 20:18:58 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
1999-08-31 05:14:40 +04:00
|
|
|
nsresult
|
|
|
|
nsTextEditorKeyListener::ScrollSelectionIntoView()
|
|
|
|
{
|
|
|
|
nsCOMPtr<nsIPresShell> presShell;
|
|
|
|
|
|
|
|
nsresult result = mEditor->GetPresShell(getter_AddRefs(presShell));
|
|
|
|
|
|
|
|
if (NS_FAILED(result))
|
|
|
|
return result;
|
|
|
|
|
|
|
|
if (!presShell)
|
|
|
|
return NS_ERROR_NULL_POINTER;
|
1999-02-12 20:18:58 +03:00
|
|
|
|
1999-08-31 05:14:40 +04:00
|
|
|
return presShell->ScrollSelectionIntoView(SELECTION_NORMAL, SELECTION_FOCUS_REGION);
|
|
|
|
}
|
1999-02-12 20:18:58 +03:00
|
|
|
|
|
|
|
/*
|
|
|
|
* nsTextEditorMouseListener implementation
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
NS_IMPL_ADDREF(nsTextEditorMouseListener)
|
|
|
|
|
|
|
|
NS_IMPL_RELEASE(nsTextEditorMouseListener)
|
|
|
|
|
|
|
|
|
|
|
|
nsTextEditorMouseListener::nsTextEditorMouseListener()
|
|
|
|
{
|
|
|
|
NS_INIT_REFCNT();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
nsTextEditorMouseListener::~nsTextEditorMouseListener()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
nsresult
|
|
|
|
nsTextEditorMouseListener::QueryInterface(REFNSIID aIID, void** aInstancePtr)
|
|
|
|
{
|
|
|
|
if (nsnull == aInstancePtr) {
|
|
|
|
return NS_ERROR_NULL_POINTER;
|
|
|
|
}
|
1999-05-28 04:19:51 +04:00
|
|
|
|
1999-06-30 01:01:31 +04:00
|
|
|
if (aIID.Equals(nsCOMTypeInfo<nsISupports>::GetIID())) {
|
1999-02-12 20:18:58 +03:00
|
|
|
*aInstancePtr = (void*)(nsISupports*)this;
|
|
|
|
NS_ADDREF_THIS();
|
|
|
|
return NS_OK;
|
|
|
|
}
|
1999-05-28 04:19:51 +04:00
|
|
|
if (aIID.Equals(nsIDOMEventListener::GetIID())) {
|
1999-02-12 20:18:58 +03:00
|
|
|
*aInstancePtr = (void*)(nsIDOMEventListener*)this;
|
|
|
|
NS_ADDREF_THIS();
|
|
|
|
return NS_OK;
|
|
|
|
}
|
1999-05-28 04:19:51 +04:00
|
|
|
if (aIID.Equals(nsIDOMMouseListener::GetIID())) {
|
1999-02-12 20:18:58 +03:00
|
|
|
*aInstancePtr = (void*)(nsIDOMMouseListener*)this;
|
|
|
|
NS_ADDREF_THIS();
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
return NS_NOINTERFACE;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
nsresult
|
1999-03-29 02:27:38 +04:00
|
|
|
nsTextEditorMouseListener::HandleEvent(nsIDOMEvent* aEvent)
|
1999-02-12 20:18:58 +03:00
|
|
|
{
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
1999-08-19 17:30:48 +04:00
|
|
|
// XXX: evil global functions, move them to proper support module
|
|
|
|
|
|
|
|
nsresult
|
|
|
|
IsNodeInSelection(nsIDOMNode *aInNode, nsIDOMSelection *aInSelection, PRBool &aOutIsInSel)
|
|
|
|
{
|
1999-08-25 14:51:55 +04:00
|
|
|
aOutIsInSel = PR_FALSE; // init out-param
|
|
|
|
if (!aInNode || !aInSelection) { return NS_ERROR_NULL_POINTER; }
|
1999-08-19 17:30:48 +04:00
|
|
|
|
|
|
|
nsCOMPtr<nsIContentIterator>iter;
|
|
|
|
nsresult result = nsComponentManager::CreateInstance(kContentIteratorCID, nsnull,
|
|
|
|
nsIContentIterator::GetIID(),
|
1999-09-13 13:37:51 +04:00
|
|
|
getter_AddRefs(iter));
|
1999-08-25 14:51:55 +04:00
|
|
|
if (NS_FAILED(result)) { return result; }
|
|
|
|
if (!iter) { return NS_ERROR_OUT_OF_MEMORY; }
|
1999-08-19 17:30:48 +04:00
|
|
|
|
1999-08-25 14:51:55 +04:00
|
|
|
nsCOMPtr<nsIEnumerator> enumerator;
|
1999-08-19 17:30:48 +04:00
|
|
|
result = aInSelection->GetEnumerator(getter_AddRefs(enumerator));
|
|
|
|
if (NS_FAILED(result)) { return result; }
|
1999-08-25 14:51:55 +04:00
|
|
|
if (!enumerator) { return NS_ERROR_OUT_OF_MEMORY; }
|
1999-08-19 17:30:48 +04:00
|
|
|
|
|
|
|
for (enumerator->First(); NS_OK!=enumerator->IsDone(); enumerator->Next())
|
|
|
|
{
|
|
|
|
nsCOMPtr<nsISupports> currentItem;
|
|
|
|
result = enumerator->CurrentItem(getter_AddRefs(currentItem));
|
|
|
|
if ((NS_SUCCEEDED(result)) && (currentItem))
|
|
|
|
{
|
|
|
|
nsCOMPtr<nsIDOMRange> range( do_QueryInterface(currentItem) );
|
|
|
|
|
1999-08-25 14:51:55 +04:00
|
|
|
iter->Init(range);
|
|
|
|
nsCOMPtr<nsIContent> currentContent;
|
|
|
|
iter->CurrentNode(getter_AddRefs(currentContent));
|
|
|
|
while (NS_COMFALSE == iter->IsDone())
|
|
|
|
{
|
|
|
|
nsCOMPtr<nsIDOMNode>currentNode = do_QueryInterface(currentContent);
|
|
|
|
if (currentNode.get()==aInNode)
|
|
|
|
{
|
|
|
|
// if it's a start or end node, need to test whether the (x,y)
|
|
|
|
// of the event falls within the selection
|
|
|
|
|
|
|
|
// talk to Mike
|
|
|
|
|
|
|
|
aOutIsInSel = PR_TRUE;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
/* do not check result here, and especially do not return the result code.
|
|
|
|
* we rely on iter->IsDone to tell us when the iteration is complete
|
|
|
|
*/
|
|
|
|
iter->Next();
|
|
|
|
iter->CurrentNode(getter_AddRefs(currentContent));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return NS_OK;
|
1999-08-19 17:30:48 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
1999-02-12 20:18:58 +03:00
|
|
|
nsresult
|
|
|
|
nsTextEditorMouseListener::MouseDown(nsIDOMEvent* aMouseEvent)
|
|
|
|
{
|
1999-05-07 23:22:38 +04:00
|
|
|
if (!aMouseEvent)
|
|
|
|
return NS_OK; // NS_OK means "we didn't process the event". Go figure.
|
|
|
|
|
1999-05-19 03:51:04 +04:00
|
|
|
nsCOMPtr<nsIDOMUIEvent>uiEvent;
|
|
|
|
uiEvent = do_QueryInterface(aMouseEvent);
|
|
|
|
if (!uiEvent) {
|
|
|
|
//non-ui event passed in. bad things.
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
1999-08-25 14:51:55 +04:00
|
|
|
nsCOMPtr<nsIEditor> editor (do_QueryInterface(mEditor));
|
1999-08-19 17:30:48 +04:00
|
|
|
if (!editor) { return NS_OK; }
|
1999-06-09 01:51:40 +04:00
|
|
|
|
1999-08-19 17:30:48 +04:00
|
|
|
|
1999-08-25 14:51:55 +04:00
|
|
|
// get the document
|
|
|
|
nsCOMPtr<nsIDOMDocument>domDoc;
|
1999-08-19 17:30:48 +04:00
|
|
|
editor->GetDocument(getter_AddRefs(domDoc));
|
1999-08-25 14:51:55 +04:00
|
|
|
if (!domDoc) { return NS_OK; }
|
|
|
|
nsCOMPtr<nsIDocument>doc = do_QueryInterface(domDoc);
|
|
|
|
if (!doc) { return NS_OK; }
|
1999-05-27 04:08:15 +04:00
|
|
|
|
1999-08-19 17:30:48 +04:00
|
|
|
PRUint16 button = 0;
|
|
|
|
uiEvent->GetButton(&button);
|
1999-08-25 14:51:55 +04:00
|
|
|
// left button click might be a drag-start
|
|
|
|
if (1==button)
|
|
|
|
{
|
1999-08-19 17:30:48 +04:00
|
|
|
#ifndef EXPERIMENTAL_DRAG_CODE
|
1999-08-25 14:51:55 +04:00
|
|
|
return NS_OK;
|
1999-08-19 17:30:48 +04:00
|
|
|
#else
|
1999-08-25 14:51:55 +04:00
|
|
|
nsString XIFBuffer;
|
|
|
|
// get the DOM select here
|
|
|
|
nsCOMPtr<nsIDOMSelection> sel;
|
|
|
|
editor->GetSelection(getter_AddRefs(sel));
|
1999-08-19 17:30:48 +04:00
|
|
|
|
1999-08-25 14:51:55 +04:00
|
|
|
// convert the DOMselection to XIF
|
|
|
|
if (sel)
|
|
|
|
{
|
|
|
|
// if we are within the selection, start the drag
|
|
|
|
|
|
|
|
nsCOMPtr<nsIDOMNode> target;
|
|
|
|
nsresult rv = aMouseEvent->GetTarget(getter_AddRefs(target));
|
|
|
|
if (NS_FAILED(rv) || !target) { return NS_OK; }
|
|
|
|
PRBool isInSel;
|
|
|
|
rv = IsNodeInSelection(target, sel, isInSel);
|
|
|
|
if (NS_FAILED(rv) || PR_FALSE==isInSel) { return NS_OK; }
|
|
|
|
doc->CreateXIF(XIFBuffer, sel);
|
|
|
|
|
|
|
|
// Get the Clipboard
|
|
|
|
nsIClipboard* clipboard;
|
|
|
|
rv = nsServiceManager::GetService(kCClipboardCID,
|
1999-09-13 13:37:51 +04:00
|
|
|
nsIClipboard::GetIID(),
|
|
|
|
(nsISupports **)&clipboard);
|
1999-08-25 14:51:55 +04:00
|
|
|
if (NS_OK == rv)
|
|
|
|
{
|
|
|
|
// Create a data flavor to tell the transferable
|
|
|
|
// that it is about to receive XIF
|
|
|
|
nsAutoString flavor(kXIFMime);
|
|
|
|
|
|
|
|
// Create a transferable for putting data on the Clipboard
|
|
|
|
nsCOMPtr<nsITransferable> trans;
|
|
|
|
rv = nsComponentManager::CreateInstance(kCTransferableCID, nsnull,
|
1999-09-13 13:37:51 +04:00
|
|
|
nsITransferable::GetIID(),
|
|
|
|
(void**) getter_AddRefs(trans));
|
1999-08-25 14:51:55 +04:00
|
|
|
if (NS_OK == rv) {
|
|
|
|
// The data on the clipboard will be in "XIF" format
|
|
|
|
// so give the clipboard transferable a "XIFConverter" for
|
|
|
|
// converting from XIF to other formats
|
|
|
|
nsCOMPtr<nsIFormatConverter> xifConverter;
|
|
|
|
rv = nsComponentManager::CreateInstance(kCXIFConverterCID, nsnull,
|
1999-09-13 13:37:51 +04:00
|
|
|
nsIFormatConverter::GetIID(),
|
|
|
|
(void**) getter_AddRefs(xifConverter));
|
1999-08-25 14:51:55 +04:00
|
|
|
if (NS_OK == rv) {
|
|
|
|
// Add the XIF DataFlavor to the transferable
|
|
|
|
// this tells the transferable that it can handle receiving the XIF format
|
|
|
|
trans->AddDataFlavor(&flavor);
|
|
|
|
|
|
|
|
// Add the converter for going from XIF to other formats
|
|
|
|
trans->SetConverter(xifConverter);
|
|
|
|
|
|
|
|
// Now add the XIF data to the transferable
|
|
|
|
// the transferable wants the number bytes for the data and since it is double byte
|
|
|
|
// we multiply by 2
|
|
|
|
trans->SetTransferData(&flavor, XIFBuffer.ToNewUnicode(), XIFBuffer.Length()*2);
|
|
|
|
|
|
|
|
// Now invoke the drag session
|
|
|
|
nsIDragService* dragService;
|
|
|
|
nsresult rv = nsServiceManager::GetService(kCDragServiceCID,
|
1999-09-13 13:37:51 +04:00
|
|
|
nsIDragService::GetIID(),
|
|
|
|
(nsISupports **)&dragService);
|
1999-08-25 14:51:55 +04:00
|
|
|
if (NS_OK == rv) {
|
|
|
|
nsCOMPtr<nsISupportsArray> items;
|
|
|
|
NS_NewISupportsArray(getter_AddRefs(items));
|
|
|
|
if ( items ) {
|
|
|
|
items->AppendElement(trans);
|
1999-09-13 13:37:51 +04:00
|
|
|
dragService->InvokeDragSession(items, nsnull,
|
|
|
|
nsIDragService::DRAGDROP_ACTION_COPY |
|
|
|
|
nsIDragService::DRAGDROP_ACTION_MOVE);
|
1999-08-25 14:51:55 +04:00
|
|
|
}
|
|
|
|
nsServiceManager::ReleaseService(kCDragServiceCID, dragService);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
nsServiceManager::ReleaseService(kCClipboardCID, clipboard);
|
|
|
|
}
|
|
|
|
return NS_ERROR_BASE; // return that we've handled the event
|
|
|
|
}
|
1999-08-19 17:30:48 +04:00
|
|
|
#endif
|
1999-08-09 05:37:50 +04:00
|
|
|
}
|
1999-08-19 17:30:48 +04:00
|
|
|
// middle-mouse click (paste);
|
|
|
|
else if (button == 2)
|
1999-08-25 14:51:55 +04:00
|
|
|
{
|
1999-08-19 17:30:48 +04:00
|
|
|
|
|
|
|
// Set the selection to the point under the mouse cursor:
|
1999-08-25 14:51:55 +04:00
|
|
|
nsCOMPtr<nsIDOMNSUIEvent> mouseEvent (do_QueryInterface(aMouseEvent));
|
|
|
|
|
|
|
|
if (!mouseEvent)
|
|
|
|
return NS_ERROR_BASE; // NS_ERROR_BASE means "We did process the event".
|
|
|
|
nsCOMPtr<nsIDOMNode> parent;
|
|
|
|
if (!NS_SUCCEEDED(mouseEvent->GetRangeParent(getter_AddRefs(parent))))
|
|
|
|
return NS_ERROR_BASE; // NS_ERROR_BASE means "We did process the event".
|
|
|
|
PRInt32 offset = 0;
|
|
|
|
if (!NS_SUCCEEDED(mouseEvent->GetRangeOffset(&offset)))
|
|
|
|
return NS_ERROR_BASE; // NS_ERROR_BASE means "We did process the event".
|
|
|
|
|
|
|
|
nsCOMPtr<nsIDOMSelection> selection;
|
|
|
|
if (NS_SUCCEEDED(editor->GetSelection(getter_AddRefs(selection))))
|
|
|
|
(void)selection->Collapse(parent, offset);
|
|
|
|
|
|
|
|
// If the ctrl key is pressed, we'll do paste as quotation.
|
|
|
|
// Would've used the alt key, but the kde wmgr treats alt-middle specially.
|
|
|
|
PRBool ctrlKey = PR_FALSE;
|
|
|
|
uiEvent->GetCtrlKey(&ctrlKey);
|
|
|
|
|
|
|
|
if (ctrlKey)
|
|
|
|
{
|
|
|
|
nsCOMPtr<nsIEditorMailSupport> mailEditor = do_QueryInterface(mEditor);
|
|
|
|
if (mailEditor)
|
|
|
|
mailEditor->PasteAsQuotation();
|
|
|
|
}
|
|
|
|
editor->Paste();
|
|
|
|
return NS_ERROR_BASE; // NS_ERROR_BASE means "We did process the event".
|
|
|
|
}
|
|
|
|
return NS_OK; // did not process the event
|
1999-02-12 20:18:58 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
1999-08-19 17:30:48 +04:00
|
|
|
|
1999-02-12 20:18:58 +03:00
|
|
|
nsresult
|
|
|
|
nsTextEditorMouseListener::MouseUp(nsIDOMEvent* aMouseEvent)
|
|
|
|
{
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
nsresult
|
|
|
|
nsTextEditorMouseListener::MouseClick(nsIDOMEvent* aMouseEvent)
|
|
|
|
{
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
nsresult
|
|
|
|
nsTextEditorMouseListener::MouseDblClick(nsIDOMEvent* aMouseEvent)
|
|
|
|
{
|
1999-08-25 14:51:55 +04:00
|
|
|
nsCOMPtr<nsIHTMLEditor> htmlEditor = do_QueryInterface(mEditor);
|
1999-08-09 05:37:50 +04:00
|
|
|
if (htmlEditor)
|
1999-06-25 00:59:45 +04:00
|
|
|
{
|
1999-08-09 05:37:50 +04:00
|
|
|
nsCOMPtr<nsIDOMElement> selectedElement;
|
1999-09-13 13:37:51 +04:00
|
|
|
if (NS_SUCCEEDED(htmlEditor->GetSelectedElement("", getter_AddRefs(selectedElement)))
|
|
|
|
&& selectedElement)
|
1999-06-25 00:59:45 +04:00
|
|
|
{
|
1999-08-09 05:37:50 +04:00
|
|
|
nsAutoString TagName;
|
|
|
|
selectedElement->GetTagName(TagName);
|
|
|
|
TagName.ToLowerCase();
|
1999-06-25 00:59:45 +04:00
|
|
|
|
|
|
|
#if DEBUG_cmanske
|
1999-08-09 05:37:50 +04:00
|
|
|
char szTagName[64];
|
|
|
|
TagName.ToCString(szTagName, 64);
|
|
|
|
printf("Single Selected element found: %s\n", szTagName);
|
1999-06-25 00:59:45 +04:00
|
|
|
#endif
|
|
|
|
}
|
|
|
|
}
|
1999-02-12 20:18:58 +03:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
nsresult
|
|
|
|
nsTextEditorMouseListener::MouseOver(nsIDOMEvent* aMouseEvent)
|
|
|
|
{
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
nsresult
|
|
|
|
nsTextEditorMouseListener::MouseOut(nsIDOMEvent* aMouseEvent)
|
|
|
|
{
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
1999-03-20 02:36:20 +03:00
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
* nsTextEditorMouseListener implementation
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
NS_IMPL_ADDREF(nsTextEditorTextListener)
|
|
|
|
|
|
|
|
NS_IMPL_RELEASE(nsTextEditorTextListener)
|
|
|
|
|
|
|
|
|
|
|
|
nsTextEditorTextListener::nsTextEditorTextListener()
|
1999-08-25 14:51:55 +04:00
|
|
|
: mCommitText(PR_FALSE),
|
|
|
|
mInTransaction(PR_FALSE)
|
1999-03-20 02:36:20 +03:00
|
|
|
{
|
|
|
|
NS_INIT_REFCNT();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
nsTextEditorTextListener::~nsTextEditorTextListener()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
|
|
|
nsTextEditorTextListener::QueryInterface(REFNSIID aIID, void** aInstancePtr)
|
|
|
|
{
|
|
|
|
if (nsnull == aInstancePtr) {
|
|
|
|
return NS_ERROR_NULL_POINTER;
|
|
|
|
}
|
1999-05-28 04:19:51 +04:00
|
|
|
|
1999-06-30 01:01:31 +04:00
|
|
|
if (aIID.Equals(nsCOMTypeInfo<nsISupports>::GetIID())) {
|
1999-03-20 02:36:20 +03:00
|
|
|
*aInstancePtr = (void*)(nsISupports*)this;
|
|
|
|
NS_ADDREF_THIS();
|
|
|
|
return NS_OK;
|
|
|
|
}
|
1999-05-28 04:19:51 +04:00
|
|
|
if (aIID.Equals(nsIDOMEventListener::GetIID())) {
|
1999-03-20 02:36:20 +03:00
|
|
|
*aInstancePtr = (void*)(nsIDOMEventListener*)this;
|
|
|
|
NS_ADDREF_THIS();
|
|
|
|
return NS_OK;
|
|
|
|
}
|
1999-05-28 04:19:51 +04:00
|
|
|
if (aIID.Equals(nsIDOMTextListener::GetIID())) {
|
1999-03-20 02:36:20 +03:00
|
|
|
*aInstancePtr = (void*)(nsIDOMTextListener*)this;
|
|
|
|
NS_ADDREF_THIS();
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
return NS_NOINTERFACE;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
1999-03-29 02:27:38 +04:00
|
|
|
nsTextEditorTextListener::HandleEvent(nsIDOMEvent* aEvent)
|
1999-03-20 02:36:20 +03:00
|
|
|
{
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
nsresult
|
|
|
|
nsTextEditorTextListener::HandleText(nsIDOMEvent* aTextEvent)
|
|
|
|
{
|
1999-09-15 03:40:16 +04:00
|
|
|
nsAutoString composedText;
|
1999-08-25 14:51:55 +04:00
|
|
|
nsresult result = NS_OK;
|
|
|
|
nsCOMPtr<nsIPrivateTextEvent> textEvent;
|
|
|
|
nsIPrivateTextRangeList *textRangeList;
|
|
|
|
nsTextEventReply *textEventReply;
|
|
|
|
|
|
|
|
textEvent = do_QueryInterface(aTextEvent);
|
|
|
|
if (!textEvent) {
|
|
|
|
//non-ui event passed in. bad things.
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
textEvent->GetText(composedText);
|
|
|
|
textEvent->GetInputRange(&textRangeList);
|
|
|
|
textEvent->GetEventReply(&textEventReply);
|
|
|
|
textRangeList->AddRef();
|
|
|
|
nsCOMPtr<nsIEditorIMESupport> imeEditor = do_QueryInterface(mEditor, &result);
|
|
|
|
if (imeEditor)
|
1999-08-09 05:37:50 +04:00
|
|
|
result = imeEditor->SetCompositionString(composedText,textRangeList,textEventReply);
|
1999-08-25 14:51:55 +04:00
|
|
|
return result;
|
1999-03-20 02:36:20 +03:00
|
|
|
}
|
|
|
|
|
1999-05-07 23:42:27 +04:00
|
|
|
/*
|
|
|
|
* nsTextEditorDragListener implementation
|
|
|
|
*/
|
|
|
|
|
|
|
|
NS_IMPL_ADDREF(nsTextEditorDragListener)
|
|
|
|
|
|
|
|
NS_IMPL_RELEASE(nsTextEditorDragListener)
|
|
|
|
|
|
|
|
|
|
|
|
nsTextEditorDragListener::nsTextEditorDragListener()
|
|
|
|
{
|
|
|
|
NS_INIT_REFCNT();
|
|
|
|
}
|
|
|
|
|
|
|
|
nsTextEditorDragListener::~nsTextEditorDragListener()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
1999-03-14 07:45:00 +03:00
|
|
|
nsresult
|
|
|
|
nsTextEditorDragListener::QueryInterface(REFNSIID aIID, void** aInstancePtr)
|
|
|
|
{
|
|
|
|
if (nsnull == aInstancePtr) {
|
|
|
|
return NS_ERROR_NULL_POINTER;
|
|
|
|
}
|
1999-05-28 04:19:51 +04:00
|
|
|
|
1999-06-30 01:01:31 +04:00
|
|
|
if (aIID.Equals(nsCOMTypeInfo<nsISupports>::GetIID())) {
|
1999-03-14 07:45:00 +03:00
|
|
|
*aInstancePtr = (void*)(nsISupports*)this;
|
|
|
|
NS_ADDREF_THIS();
|
|
|
|
return NS_OK;
|
|
|
|
}
|
1999-05-28 04:19:51 +04:00
|
|
|
if (aIID.Equals(nsIDOMEventListener::GetIID())) {
|
1999-03-14 07:45:00 +03:00
|
|
|
*aInstancePtr = (void*)(nsIDOMEventListener*)this;
|
|
|
|
NS_ADDREF_THIS();
|
|
|
|
return NS_OK;
|
|
|
|
}
|
1999-05-28 04:19:51 +04:00
|
|
|
if (aIID.Equals(nsIDOMDragListener::GetIID())) {
|
1999-03-14 07:45:00 +03:00
|
|
|
*aInstancePtr = (void*)(nsIDOMDragListener*)this;
|
|
|
|
NS_ADDREF_THIS();
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
return NS_NOINTERFACE;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
nsresult
|
1999-03-29 02:27:38 +04:00
|
|
|
nsTextEditorDragListener::HandleEvent(nsIDOMEvent* aEvent)
|
1999-03-14 07:45:00 +03:00
|
|
|
{
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
1999-08-19 23:48:33 +04:00
|
|
|
nsresult
|
|
|
|
nsTextEditorDragListener::DragGesture(nsIDOMEvent* aDragEvent)
|
|
|
|
{
|
|
|
|
// ...figure out if a drag should be started...
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
1999-03-14 07:45:00 +03:00
|
|
|
|
|
|
|
nsresult
|
1999-04-07 00:24:09 +04:00
|
|
|
nsTextEditorDragListener::DragEnter(nsIDOMEvent* aDragEvent)
|
|
|
|
{
|
1999-08-25 12:35:06 +04:00
|
|
|
nsresult rv;
|
|
|
|
NS_WITH_SERVICE ( nsIDragService, dragService, kCDragServiceCID, &rv );
|
|
|
|
if ( NS_SUCCEEDED(rv) ) {
|
1999-05-07 23:42:27 +04:00
|
|
|
nsCOMPtr<nsIDragSession> dragSession(do_QueryInterface(dragService));
|
1999-08-25 12:35:06 +04:00
|
|
|
if ( dragSession ) {
|
|
|
|
PRBool flavorSupported = PR_FALSE;
|
|
|
|
dragSession->IsDataFlavorSupported(kTextMime, &flavorSupported);
|
|
|
|
if ( flavorSupported )
|
|
|
|
dragSession->SetCanDrop(PR_TRUE);
|
1999-05-07 23:42:27 +04:00
|
|
|
}
|
1999-04-17 17:52:28 +04:00
|
|
|
}
|
1999-06-16 08:52:05 +04:00
|
|
|
|
1999-04-07 00:24:09 +04:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
nsresult
|
|
|
|
nsTextEditorDragListener::DragOver(nsIDOMEvent* aDragEvent)
|
|
|
|
{
|
1999-08-25 12:35:06 +04:00
|
|
|
nsresult rv;
|
|
|
|
NS_WITH_SERVICE ( nsIDragService, dragService, kCDragServiceCID, &rv );
|
|
|
|
if ( NS_SUCCEEDED(rv) ) {
|
1999-05-07 23:42:27 +04:00
|
|
|
nsCOMPtr<nsIDragSession> dragSession(do_QueryInterface(dragService));
|
1999-08-25 12:35:06 +04:00
|
|
|
if ( dragSession ) {
|
|
|
|
PRBool flavorSupported = PR_FALSE;
|
|
|
|
dragSession->IsDataFlavorSupported(kTextMime, &flavorSupported);
|
|
|
|
if ( flavorSupported )
|
|
|
|
dragSession->SetCanDrop(PR_TRUE);
|
1999-05-07 23:42:27 +04:00
|
|
|
}
|
1999-04-17 17:52:28 +04:00
|
|
|
}
|
1999-06-16 08:52:05 +04:00
|
|
|
|
1999-04-07 00:24:09 +04:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
nsresult
|
|
|
|
nsTextEditorDragListener::DragExit(nsIDOMEvent* aDragEvent)
|
1999-03-14 07:45:00 +03:00
|
|
|
{
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
nsresult
|
|
|
|
nsTextEditorDragListener::DragDrop(nsIDOMEvent* aMouseEvent)
|
|
|
|
{
|
1999-05-07 23:42:27 +04:00
|
|
|
// Create drag service for getting state of drag
|
1999-04-17 17:52:28 +04:00
|
|
|
nsIDragService* dragService;
|
|
|
|
nsresult rv = nsServiceManager::GetService(kCDragServiceCID,
|
1999-05-07 23:42:27 +04:00
|
|
|
nsIDragService::GetIID(),
|
1999-04-17 17:52:28 +04:00
|
|
|
(nsISupports **)&dragService);
|
|
|
|
if (NS_OK == rv) {
|
1999-05-07 23:42:27 +04:00
|
|
|
nsCOMPtr<nsIDragSession> dragSession(do_QueryInterface(dragService));
|
|
|
|
|
|
|
|
if (dragSession) {
|
1999-04-17 17:52:28 +04:00
|
|
|
|
1999-05-07 23:42:27 +04:00
|
|
|
// Create transferable for getting the drag data
|
1999-05-14 01:53:57 +04:00
|
|
|
nsCOMPtr<nsITransferable> trans;
|
|
|
|
rv = nsComponentManager::CreateInstance(kCTransferableCID, nsnull,
|
|
|
|
nsITransferable::GetIID(),
|
|
|
|
(void**) getter_AddRefs(trans));
|
1999-05-14 22:44:28 +04:00
|
|
|
if ( NS_SUCCEEDED(rv) && trans ) {
|
1999-05-07 23:42:27 +04:00
|
|
|
// Add the text Flavor to the transferable,
|
1999-06-15 08:07:36 +04:00
|
|
|
// because that is the only type of data we are
|
|
|
|
// looking for at the moment.
|
1999-08-25 12:35:06 +04:00
|
|
|
trans->AddDataFlavor(kTextMime);
|
1999-05-27 01:08:14 +04:00
|
|
|
//trans->AddDataFlavor(mImageDataFlavor);
|
|
|
|
|
|
|
|
// Fill the transferable with data for each drag item in succession
|
|
|
|
PRUint32 numItems = 0;
|
|
|
|
if (NS_SUCCEEDED(dragSession->GetNumDropItems(&numItems))) {
|
|
|
|
|
|
|
|
printf("Num Drop Items %d\n", numItems);
|
|
|
|
|
|
|
|
PRUint32 i;
|
|
|
|
for (i=0;i<numItems;++i) {
|
|
|
|
if (NS_SUCCEEDED(dragSession->GetData(trans, i))) {
|
|
|
|
|
|
|
|
// Get the string data out of the transferable
|
|
|
|
// Note: the transferable owns the pointer to the data
|
1999-08-25 12:35:06 +04:00
|
|
|
nsCOMPtr<nsISupports> genericDataObj;
|
1999-05-27 01:08:14 +04:00
|
|
|
PRUint32 len;
|
1999-08-31 05:14:40 +04:00
|
|
|
char* whichFlavor = nsnull;
|
1999-08-25 12:35:06 +04:00
|
|
|
trans->GetAnyTransferData(&whichFlavor, getter_AddRefs(genericDataObj), &len);
|
|
|
|
nsCOMPtr<nsISupportsString> textDataObj( do_QueryInterface(genericDataObj) );
|
1999-05-27 01:08:14 +04:00
|
|
|
// If the string was not empty then paste it in
|
1999-08-25 12:35:06 +04:00
|
|
|
if ( textDataObj )
|
1999-08-09 05:37:50 +04:00
|
|
|
{
|
1999-08-25 12:35:06 +04:00
|
|
|
char* text = nsnull;
|
1999-08-25 13:15:18 +04:00
|
|
|
textDataObj->ToString(&text);
|
1999-08-09 05:37:50 +04:00
|
|
|
nsCOMPtr<nsIHTMLEditor> htmlEditor = do_QueryInterface(mEditor);
|
1999-08-25 12:35:06 +04:00
|
|
|
if ( htmlEditor && text )
|
|
|
|
htmlEditor->InsertText(text);
|
1999-05-27 01:08:14 +04:00
|
|
|
dragSession->SetCanDrop(PR_TRUE);
|
|
|
|
}
|
1999-05-07 23:42:27 +04:00
|
|
|
|
1999-09-06 10:22:51 +04:00
|
|
|
nsCRT::free(whichFlavor);
|
1999-05-27 01:08:14 +04:00
|
|
|
// XXX This is where image support might go
|
|
|
|
//void * data;
|
|
|
|
//trans->GetTransferData(mImageDataFlavor, (void **)&data, &len);
|
|
|
|
}
|
|
|
|
} // foreach drag item
|
1999-04-17 17:52:28 +04:00
|
|
|
}
|
1999-05-27 01:08:14 +04:00
|
|
|
} // if valid transferable
|
|
|
|
} // if valid drag session
|
1999-04-23 18:43:30 +04:00
|
|
|
nsServiceManager::ReleaseService(kCDragServiceCID, dragService);
|
1999-05-27 01:08:14 +04:00
|
|
|
} // if valid drag service
|
1999-04-07 00:24:09 +04:00
|
|
|
|
1999-03-14 07:45:00 +03:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
1999-05-07 23:42:27 +04:00
|
|
|
|
1999-05-04 02:57:48 +04:00
|
|
|
nsTextEditorCompositionListener::nsTextEditorCompositionListener()
|
|
|
|
{
|
|
|
|
NS_INIT_REFCNT();
|
|
|
|
}
|
|
|
|
|
|
|
|
nsTextEditorCompositionListener::~nsTextEditorCompositionListener()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
nsresult
|
|
|
|
nsTextEditorCompositionListener::QueryInterface(REFNSIID aIID, void** aInstancePtr)
|
|
|
|
{
|
|
|
|
if (nsnull == aInstancePtr) {
|
|
|
|
return NS_ERROR_NULL_POINTER;
|
|
|
|
}
|
1999-06-30 01:01:31 +04:00
|
|
|
if (aIID.Equals(nsCOMTypeInfo<nsISupports>::GetIID())) {
|
1999-05-04 02:57:48 +04:00
|
|
|
*aInstancePtr = (void*)(nsISupports*)this;
|
|
|
|
NS_ADDREF_THIS();
|
|
|
|
return NS_OK;
|
|
|
|
}
|
1999-05-28 04:19:51 +04:00
|
|
|
if (aIID.Equals(nsIDOMEventListener::GetIID())) {
|
1999-05-04 02:57:48 +04:00
|
|
|
*aInstancePtr = (void*)(nsIDOMEventListener*)this;
|
|
|
|
NS_ADDREF_THIS();
|
|
|
|
return NS_OK;
|
|
|
|
}
|
1999-05-28 04:19:51 +04:00
|
|
|
if (aIID.Equals(nsIDOMCompositionListener::GetIID())) {
|
1999-05-04 02:57:48 +04:00
|
|
|
*aInstancePtr = (void*)(nsIDOMCompositionListener*)this;
|
|
|
|
NS_ADDREF_THIS();
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
return NS_NOINTERFACE;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMPL_ADDREF(nsTextEditorCompositionListener)
|
|
|
|
|
|
|
|
NS_IMPL_RELEASE(nsTextEditorCompositionListener)
|
|
|
|
|
|
|
|
nsresult
|
|
|
|
nsTextEditorCompositionListener::HandleEvent(nsIDOMEvent* aEvent)
|
|
|
|
{
|
|
|
|
return NS_OK;
|
|
|
|
}
|
1999-08-09 05:37:50 +04:00
|
|
|
|
|
|
|
void nsTextEditorCompositionListener::SetEditor(nsIEditor *aEditor)
|
|
|
|
{
|
|
|
|
nsCOMPtr<nsIEditorIMESupport> imeEditor = do_QueryInterface(aEditor);
|
1999-08-25 14:51:55 +04:00
|
|
|
if (!imeEditor) return; // should return an error here!
|
1999-08-09 05:37:50 +04:00
|
|
|
|
|
|
|
// note that we don't hold an extra reference here.
|
|
|
|
mEditor = imeEditor;
|
|
|
|
}
|
|
|
|
|
1999-05-04 02:57:48 +04:00
|
|
|
nsresult
|
|
|
|
nsTextEditorCompositionListener::HandleStartComposition(nsIDOMEvent* aCompositionEvent)
|
|
|
|
{
|
1999-08-31 05:20:32 +04:00
|
|
|
nsCOMPtr<nsIPrivateCompositionEvent> pCompositionEvent = do_QueryInterface(aCompositionEvent);
|
|
|
|
nsTextEventReply* eventReply;
|
|
|
|
|
|
|
|
if (!pCompositionEvent) return NS_ERROR_FAILURE;
|
|
|
|
|
|
|
|
nsresult rv = pCompositionEvent->GetCompositionReply(&eventReply);
|
|
|
|
if (NS_FAILED(rv)) return rv;
|
|
|
|
|
|
|
|
return mEditor->BeginComposition(eventReply);
|
1999-05-04 02:57:48 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
|
|
|
nsTextEditorCompositionListener::HandleEndComposition(nsIDOMEvent* aCompositionEvent)
|
|
|
|
{
|
1999-08-25 14:51:55 +04:00
|
|
|
return mEditor->EndComposition();
|
1999-05-04 02:57:48 +04:00
|
|
|
}
|
|
|
|
|
1999-02-12 20:18:58 +03:00
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Factory functions
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
nsresult
|
|
|
|
NS_NewEditorKeyListener(nsIDOMEventListener ** aInstancePtrResult,
|
1999-08-09 05:37:50 +04:00
|
|
|
nsIEditor *aEditor)
|
1999-02-12 20:18:58 +03:00
|
|
|
{
|
|
|
|
nsTextEditorKeyListener* it = new nsTextEditorKeyListener();
|
|
|
|
if (nsnull == it) {
|
|
|
|
return NS_ERROR_OUT_OF_MEMORY;
|
|
|
|
}
|
|
|
|
|
|
|
|
it->SetEditor(aEditor);
|
|
|
|
|
1999-05-28 04:19:51 +04:00
|
|
|
return it->QueryInterface(nsIDOMEventListener::GetIID(), (void **) aInstancePtrResult);
|
1999-02-12 20:18:58 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
nsresult
|
|
|
|
NS_NewEditorMouseListener(nsIDOMEventListener ** aInstancePtrResult,
|
1999-08-09 05:37:50 +04:00
|
|
|
nsIEditor *aEditor)
|
1999-02-12 20:18:58 +03:00
|
|
|
{
|
|
|
|
nsTextEditorMouseListener* it = new nsTextEditorMouseListener();
|
|
|
|
if (nsnull == it) {
|
|
|
|
return NS_ERROR_OUT_OF_MEMORY;
|
|
|
|
}
|
|
|
|
|
|
|
|
it->SetEditor(aEditor);
|
|
|
|
|
1999-05-28 04:19:51 +04:00
|
|
|
return it->QueryInterface(nsIDOMEventListener::GetIID(), (void **) aInstancePtrResult);
|
1999-02-12 20:18:58 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
|
1999-03-20 02:36:20 +03:00
|
|
|
nsresult
|
1999-08-09 05:37:50 +04:00
|
|
|
NS_NewEditorTextListener(nsIDOMEventListener** aInstancePtrResult, nsIEditor* aEditor)
|
1999-03-20 02:36:20 +03:00
|
|
|
{
|
1999-08-25 14:51:55 +04:00
|
|
|
nsTextEditorTextListener* it = new nsTextEditorTextListener();
|
|
|
|
if (nsnull==it) {
|
|
|
|
return NS_ERROR_OUT_OF_MEMORY;
|
|
|
|
}
|
1999-03-20 02:36:20 +03:00
|
|
|
|
1999-08-25 14:51:55 +04:00
|
|
|
it->SetEditor(aEditor);
|
1999-03-20 02:36:20 +03:00
|
|
|
|
1999-08-25 14:51:55 +04:00
|
|
|
return it->QueryInterface(nsIDOMEventListener::GetIID(), (void **) aInstancePtrResult);
|
1999-03-20 02:36:20 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
|
1999-02-12 20:18:58 +03:00
|
|
|
|
1999-03-14 07:45:00 +03:00
|
|
|
nsresult
|
|
|
|
NS_NewEditorDragListener(nsIDOMEventListener ** aInstancePtrResult,
|
1999-08-09 05:37:50 +04:00
|
|
|
nsIEditor *aEditor)
|
1999-03-14 07:45:00 +03:00
|
|
|
{
|
|
|
|
nsTextEditorDragListener* it = new nsTextEditorDragListener();
|
|
|
|
if (nsnull == it) {
|
|
|
|
return NS_ERROR_OUT_OF_MEMORY;
|
|
|
|
}
|
|
|
|
|
|
|
|
it->SetEditor(aEditor);
|
|
|
|
|
1999-05-28 04:19:51 +04:00
|
|
|
return it->QueryInterface(nsIDOMEventListener::GetIID(), (void **) aInstancePtrResult);
|
1999-03-14 07:45:00 +03:00
|
|
|
}
|
|
|
|
|
1999-05-04 02:57:48 +04:00
|
|
|
nsresult
|
1999-08-09 05:37:50 +04:00
|
|
|
NS_NewEditorCompositionListener(nsIDOMEventListener** aInstancePtrResult, nsIEditor* aEditor)
|
1999-05-04 02:57:48 +04:00
|
|
|
{
|
1999-08-25 14:51:55 +04:00
|
|
|
nsTextEditorCompositionListener* it = new nsTextEditorCompositionListener();
|
|
|
|
if (nsnull==it) {
|
|
|
|
return NS_ERROR_OUT_OF_MEMORY;
|
|
|
|
}
|
|
|
|
it->SetEditor(aEditor);
|
Preparation for ender-based text control
* added focus listener. Doesn't do much yet, but when focus notifications start appearing, we'll be ready for them. The code is in
place to hide selection when we lose focus and paint selection when we get focus. That's probably not quite right, but it's a start.
We will need to be able to determine the distinction between losing focus to another control within our app, and losing focus to
another app.
* added support for disabled and readonly states in the editor. This is accomplished by having flags set by the client, and letting the
rules system deal with those flags. The flags I added are:
TEXT_EDITOR_FLAG_PLAINTEXT 0x01 // only plain text editing is allowed
TEXT_EDITOR_FLAG_SINGLELINE 0x02 // enter key and CR-LF handled specially
TEXT_EDITOR_FLAG_PASSWORD 0x04 // text is not entered into content, only a representative character
TEXT_EDITOR_FLAG_READONLY 0x08 // editing events are disabled. Editor may still accept focus.
TEXT_EDITOR_FLAG_DISALBED 0x10 // all events are disabled (like scrolling). Editor will not accept focus.
* added WillInsertBreak/DidInsertBreak into text rules, so flags could be checked. This gets us readonly, disabled, and single line
behavior.
* cleaned up the code that allocates, registers, and destroys event listeners. Thanks to Kin and Simon for cleaning up the
ownership model on the listeners, it was a big help.
* added support for a max text length. You can now tell the text editor, be no bigger than n characters.
1999-05-29 01:24:18 +04:00
|
|
|
return it->QueryInterface(nsIDOMEventListener::GetIID(), (void **) aInstancePtrResult);
|
|
|
|
}
|
1999-05-04 02:57:48 +04:00
|
|
|
|
Preparation for ender-based text control
* added focus listener. Doesn't do much yet, but when focus notifications start appearing, we'll be ready for them. The code is in
place to hide selection when we lose focus and paint selection when we get focus. That's probably not quite right, but it's a start.
We will need to be able to determine the distinction between losing focus to another control within our app, and losing focus to
another app.
* added support for disabled and readonly states in the editor. This is accomplished by having flags set by the client, and letting the
rules system deal with those flags. The flags I added are:
TEXT_EDITOR_FLAG_PLAINTEXT 0x01 // only plain text editing is allowed
TEXT_EDITOR_FLAG_SINGLELINE 0x02 // enter key and CR-LF handled specially
TEXT_EDITOR_FLAG_PASSWORD 0x04 // text is not entered into content, only a representative character
TEXT_EDITOR_FLAG_READONLY 0x08 // editing events are disabled. Editor may still accept focus.
TEXT_EDITOR_FLAG_DISALBED 0x10 // all events are disabled (like scrolling). Editor will not accept focus.
* added WillInsertBreak/DidInsertBreak into text rules, so flags could be checked. This gets us readonly, disabled, and single line
behavior.
* cleaned up the code that allocates, registers, and destroys event listeners. Thanks to Kin and Simon for cleaning up the
ownership model on the listeners, it was a big help.
* added support for a max text length. You can now tell the text editor, be no bigger than n characters.
1999-05-29 01:24:18 +04:00
|
|
|
nsresult
|
|
|
|
NS_NewEditorFocusListener(nsIDOMEventListener ** aInstancePtrResult,
|
1999-08-09 05:37:50 +04:00
|
|
|
nsIEditor *aEditor)
|
Preparation for ender-based text control
* added focus listener. Doesn't do much yet, but when focus notifications start appearing, we'll be ready for them. The code is in
place to hide selection when we lose focus and paint selection when we get focus. That's probably not quite right, but it's a start.
We will need to be able to determine the distinction between losing focus to another control within our app, and losing focus to
another app.
* added support for disabled and readonly states in the editor. This is accomplished by having flags set by the client, and letting the
rules system deal with those flags. The flags I added are:
TEXT_EDITOR_FLAG_PLAINTEXT 0x01 // only plain text editing is allowed
TEXT_EDITOR_FLAG_SINGLELINE 0x02 // enter key and CR-LF handled specially
TEXT_EDITOR_FLAG_PASSWORD 0x04 // text is not entered into content, only a representative character
TEXT_EDITOR_FLAG_READONLY 0x08 // editing events are disabled. Editor may still accept focus.
TEXT_EDITOR_FLAG_DISALBED 0x10 // all events are disabled (like scrolling). Editor will not accept focus.
* added WillInsertBreak/DidInsertBreak into text rules, so flags could be checked. This gets us readonly, disabled, and single line
behavior.
* cleaned up the code that allocates, registers, and destroys event listeners. Thanks to Kin and Simon for cleaning up the
ownership model on the listeners, it was a big help.
* added support for a max text length. You can now tell the text editor, be no bigger than n characters.
1999-05-29 01:24:18 +04:00
|
|
|
{
|
|
|
|
nsTextEditorFocusListener* it = new nsTextEditorFocusListener();
|
|
|
|
if (nsnull == it) {
|
|
|
|
return NS_ERROR_OUT_OF_MEMORY;
|
|
|
|
}
|
|
|
|
it->SetEditor(aEditor);
|
1999-08-25 14:51:55 +04:00
|
|
|
return it->QueryInterface(nsIDOMEventListener::GetIID(), (void **) aInstancePtrResult);
|
1999-05-04 02:57:48 +04:00
|
|
|
}
|
1999-02-12 20:18:58 +03:00
|
|
|
|
1999-03-20 02:36:20 +03:00
|
|
|
|
Preparation for ender-based text control
* added focus listener. Doesn't do much yet, but when focus notifications start appearing, we'll be ready for them. The code is in
place to hide selection when we lose focus and paint selection when we get focus. That's probably not quite right, but it's a start.
We will need to be able to determine the distinction between losing focus to another control within our app, and losing focus to
another app.
* added support for disabled and readonly states in the editor. This is accomplished by having flags set by the client, and letting the
rules system deal with those flags. The flags I added are:
TEXT_EDITOR_FLAG_PLAINTEXT 0x01 // only plain text editing is allowed
TEXT_EDITOR_FLAG_SINGLELINE 0x02 // enter key and CR-LF handled specially
TEXT_EDITOR_FLAG_PASSWORD 0x04 // text is not entered into content, only a representative character
TEXT_EDITOR_FLAG_READONLY 0x08 // editing events are disabled. Editor may still accept focus.
TEXT_EDITOR_FLAG_DISALBED 0x10 // all events are disabled (like scrolling). Editor will not accept focus.
* added WillInsertBreak/DidInsertBreak into text rules, so flags could be checked. This gets us readonly, disabled, and single line
behavior.
* cleaned up the code that allocates, registers, and destroys event listeners. Thanks to Kin and Simon for cleaning up the
ownership model on the listeners, it was a big help.
* added support for a max text length. You can now tell the text editor, be no bigger than n characters.
1999-05-29 01:24:18 +04:00
|
|
|
|
|
|
|
/*
|
|
|
|
* nsTextEditorFocusListener implementation
|
|
|
|
*/
|
|
|
|
|
|
|
|
NS_IMPL_ADDREF(nsTextEditorFocusListener)
|
|
|
|
|
|
|
|
NS_IMPL_RELEASE(nsTextEditorFocusListener)
|
|
|
|
|
|
|
|
|
|
|
|
nsTextEditorFocusListener::nsTextEditorFocusListener()
|
|
|
|
{
|
|
|
|
NS_INIT_REFCNT();
|
|
|
|
}
|
|
|
|
|
|
|
|
nsTextEditorFocusListener::~nsTextEditorFocusListener()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
|
|
|
nsTextEditorFocusListener::QueryInterface(REFNSIID aIID, void** aInstancePtr)
|
|
|
|
{
|
|
|
|
if (nsnull == aInstancePtr) {
|
|
|
|
return NS_ERROR_NULL_POINTER;
|
|
|
|
}
|
|
|
|
static NS_DEFINE_IID(kIDOMFocusListenerIID, NS_IDOMFOCUSLISTENER_IID);
|
|
|
|
static NS_DEFINE_IID(kIDOMEventListenerIID, NS_IDOMEVENTLISTENER_IID);
|
|
|
|
static NS_DEFINE_IID(kISupportsIID, NS_ISUPPORTS_IID);
|
|
|
|
if (aIID.Equals(kISupportsIID)) {
|
|
|
|
*aInstancePtr = (void*)(nsISupports*)this;
|
|
|
|
NS_ADDREF_THIS();
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
if (aIID.Equals(kIDOMEventListenerIID)) {
|
|
|
|
*aInstancePtr = (void*)(nsIDOMEventListener*)this;
|
|
|
|
NS_ADDREF_THIS();
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
if (aIID.Equals(kIDOMFocusListenerIID)) {
|
|
|
|
*aInstancePtr = (void*)(nsIDOMFocusListener*)this;
|
|
|
|
NS_ADDREF_THIS();
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
return NS_NOINTERFACE;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
|
|
|
nsTextEditorFocusListener::HandleEvent(nsIDOMEvent* aEvent)
|
|
|
|
{
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
1999-08-02 17:53:23 +04:00
|
|
|
nsTextEditorFocusListener::Focus(nsIDOMEvent* aEvent)
|
Preparation for ender-based text control
* added focus listener. Doesn't do much yet, but when focus notifications start appearing, we'll be ready for them. The code is in
place to hide selection when we lose focus and paint selection when we get focus. That's probably not quite right, but it's a start.
We will need to be able to determine the distinction between losing focus to another control within our app, and losing focus to
another app.
* added support for disabled and readonly states in the editor. This is accomplished by having flags set by the client, and letting the
rules system deal with those flags. The flags I added are:
TEXT_EDITOR_FLAG_PLAINTEXT 0x01 // only plain text editing is allowed
TEXT_EDITOR_FLAG_SINGLELINE 0x02 // enter key and CR-LF handled specially
TEXT_EDITOR_FLAG_PASSWORD 0x04 // text is not entered into content, only a representative character
TEXT_EDITOR_FLAG_READONLY 0x08 // editing events are disabled. Editor may still accept focus.
TEXT_EDITOR_FLAG_DISALBED 0x10 // all events are disabled (like scrolling). Editor will not accept focus.
* added WillInsertBreak/DidInsertBreak into text rules, so flags could be checked. This gets us readonly, disabled, and single line
behavior.
* cleaned up the code that allocates, registers, and destroys event listeners. Thanks to Kin and Simon for cleaning up the
ownership model on the listeners, it was a big help.
* added support for a max text length. You can now tell the text editor, be no bigger than n characters.
1999-05-29 01:24:18 +04:00
|
|
|
{
|
|
|
|
// turn on selection and caret
|
|
|
|
if (mEditor)
|
|
|
|
{
|
1999-08-07 09:28:57 +04:00
|
|
|
PRUint32 flags;
|
|
|
|
mEditor->GetFlags(&flags);
|
1999-08-09 05:37:50 +04:00
|
|
|
if (! (flags & nsIHTMLEditor::eEditorDisabledMask))
|
1999-08-07 09:28:57 +04:00
|
|
|
{ // only enable caret and selection if the editor is not disabled
|
|
|
|
nsCOMPtr<nsIEditor>editor = do_QueryInterface(mEditor);
|
|
|
|
if (editor)
|
Preparation for ender-based text control
* added focus listener. Doesn't do much yet, but when focus notifications start appearing, we'll be ready for them. The code is in
place to hide selection when we lose focus and paint selection when we get focus. That's probably not quite right, but it's a start.
We will need to be able to determine the distinction between losing focus to another control within our app, and losing focus to
another app.
* added support for disabled and readonly states in the editor. This is accomplished by having flags set by the client, and letting the
rules system deal with those flags. The flags I added are:
TEXT_EDITOR_FLAG_PLAINTEXT 0x01 // only plain text editing is allowed
TEXT_EDITOR_FLAG_SINGLELINE 0x02 // enter key and CR-LF handled specially
TEXT_EDITOR_FLAG_PASSWORD 0x04 // text is not entered into content, only a representative character
TEXT_EDITOR_FLAG_READONLY 0x08 // editing events are disabled. Editor may still accept focus.
TEXT_EDITOR_FLAG_DISALBED 0x10 // all events are disabled (like scrolling). Editor will not accept focus.
* added WillInsertBreak/DidInsertBreak into text rules, so flags could be checked. This gets us readonly, disabled, and single line
behavior.
* cleaned up the code that allocates, registers, and destroys event listeners. Thanks to Kin and Simon for cleaning up the
ownership model on the listeners, it was a big help.
* added support for a max text length. You can now tell the text editor, be no bigger than n characters.
1999-05-29 01:24:18 +04:00
|
|
|
{
|
1999-08-07 09:28:57 +04:00
|
|
|
nsCOMPtr<nsIPresShell>ps;
|
|
|
|
editor->GetPresShell(getter_AddRefs(ps));
|
|
|
|
if (ps)
|
Preparation for ender-based text control
* added focus listener. Doesn't do much yet, but when focus notifications start appearing, we'll be ready for them. The code is in
place to hide selection when we lose focus and paint selection when we get focus. That's probably not quite right, but it's a start.
We will need to be able to determine the distinction between losing focus to another control within our app, and losing focus to
another app.
* added support for disabled and readonly states in the editor. This is accomplished by having flags set by the client, and letting the
rules system deal with those flags. The flags I added are:
TEXT_EDITOR_FLAG_PLAINTEXT 0x01 // only plain text editing is allowed
TEXT_EDITOR_FLAG_SINGLELINE 0x02 // enter key and CR-LF handled specially
TEXT_EDITOR_FLAG_PASSWORD 0x04 // text is not entered into content, only a representative character
TEXT_EDITOR_FLAG_READONLY 0x08 // editing events are disabled. Editor may still accept focus.
TEXT_EDITOR_FLAG_DISALBED 0x10 // all events are disabled (like scrolling). Editor will not accept focus.
* added WillInsertBreak/DidInsertBreak into text rules, so flags could be checked. This gets us readonly, disabled, and single line
behavior.
* cleaned up the code that allocates, registers, and destroys event listeners. Thanks to Kin and Simon for cleaning up the
ownership model on the listeners, it was a big help.
* added support for a max text length. You can now tell the text editor, be no bigger than n characters.
1999-05-29 01:24:18 +04:00
|
|
|
{
|
1999-08-09 05:37:50 +04:00
|
|
|
if (! (flags & nsIHTMLEditor::eEditorReadonlyMask))
|
1999-08-07 09:28:57 +04:00
|
|
|
{ // only enable caret if the editor is not readonly
|
|
|
|
ps->SetCaretEnabled(PR_TRUE);
|
|
|
|
}
|
|
|
|
|
|
|
|
nsCOMPtr<nsIDOMDocument>domDoc;
|
|
|
|
editor->GetDocument(getter_AddRefs(domDoc));
|
|
|
|
if (domDoc)
|
1999-08-02 17:53:23 +04:00
|
|
|
{
|
1999-08-07 09:28:57 +04:00
|
|
|
nsCOMPtr<nsIDocument>doc = do_QueryInterface(domDoc);
|
|
|
|
if (doc)
|
|
|
|
{
|
|
|
|
doc->SetDisplaySelection(PR_TRUE);
|
|
|
|
}
|
1999-08-02 17:53:23 +04:00
|
|
|
}
|
1999-08-31 05:14:40 +04:00
|
|
|
#ifdef USE_HACK_REPAINT
|
1999-08-07 09:28:57 +04:00
|
|
|
// begin hack repaint
|
|
|
|
nsCOMPtr<nsIViewManager> viewmgr;
|
|
|
|
ps->GetViewManager(getter_AddRefs(viewmgr));
|
|
|
|
if (viewmgr) {
|
|
|
|
nsIView* view;
|
1999-08-25 14:51:55 +04:00
|
|
|
viewmgr->GetRootView(view); // views are not refCounted
|
1999-08-07 09:28:57 +04:00
|
|
|
if (view) {
|
|
|
|
viewmgr->UpdateView(view,nsnull,NS_VMREFRESH_IMMEDIATE);
|
|
|
|
}
|
1999-08-31 04:51:23 +04:00
|
|
|
}
|
1999-08-31 05:14:40 +04:00
|
|
|
// end hack repaint
|
|
|
|
#else
|
|
|
|
ps->RepaintSelection(SELECTION_NORMAL);
|
|
|
|
#endif
|
Preparation for ender-based text control
* added focus listener. Doesn't do much yet, but when focus notifications start appearing, we'll be ready for them. The code is in
place to hide selection when we lose focus and paint selection when we get focus. That's probably not quite right, but it's a start.
We will need to be able to determine the distinction between losing focus to another control within our app, and losing focus to
another app.
* added support for disabled and readonly states in the editor. This is accomplished by having flags set by the client, and letting the
rules system deal with those flags. The flags I added are:
TEXT_EDITOR_FLAG_PLAINTEXT 0x01 // only plain text editing is allowed
TEXT_EDITOR_FLAG_SINGLELINE 0x02 // enter key and CR-LF handled specially
TEXT_EDITOR_FLAG_PASSWORD 0x04 // text is not entered into content, only a representative character
TEXT_EDITOR_FLAG_READONLY 0x08 // editing events are disabled. Editor may still accept focus.
TEXT_EDITOR_FLAG_DISALBED 0x10 // all events are disabled (like scrolling). Editor will not accept focus.
* added WillInsertBreak/DidInsertBreak into text rules, so flags could be checked. This gets us readonly, disabled, and single line
behavior.
* cleaned up the code that allocates, registers, and destroys event listeners. Thanks to Kin and Simon for cleaning up the
ownership model on the listeners, it was a big help.
* added support for a max text length. You can now tell the text editor, be no bigger than n characters.
1999-05-29 01:24:18 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
1999-08-02 17:53:23 +04:00
|
|
|
nsTextEditorFocusListener::Blur(nsIDOMEvent* aEvent)
|
Preparation for ender-based text control
* added focus listener. Doesn't do much yet, but when focus notifications start appearing, we'll be ready for them. The code is in
place to hide selection when we lose focus and paint selection when we get focus. That's probably not quite right, but it's a start.
We will need to be able to determine the distinction between losing focus to another control within our app, and losing focus to
another app.
* added support for disabled and readonly states in the editor. This is accomplished by having flags set by the client, and letting the
rules system deal with those flags. The flags I added are:
TEXT_EDITOR_FLAG_PLAINTEXT 0x01 // only plain text editing is allowed
TEXT_EDITOR_FLAG_SINGLELINE 0x02 // enter key and CR-LF handled specially
TEXT_EDITOR_FLAG_PASSWORD 0x04 // text is not entered into content, only a representative character
TEXT_EDITOR_FLAG_READONLY 0x08 // editing events are disabled. Editor may still accept focus.
TEXT_EDITOR_FLAG_DISALBED 0x10 // all events are disabled (like scrolling). Editor will not accept focus.
* added WillInsertBreak/DidInsertBreak into text rules, so flags could be checked. This gets us readonly, disabled, and single line
behavior.
* cleaned up the code that allocates, registers, and destroys event listeners. Thanks to Kin and Simon for cleaning up the
ownership model on the listeners, it was a big help.
* added support for a max text length. You can now tell the text editor, be no bigger than n characters.
1999-05-29 01:24:18 +04:00
|
|
|
{
|
|
|
|
// turn off selection and caret
|
|
|
|
if (mEditor)
|
|
|
|
{
|
|
|
|
nsCOMPtr<nsIEditor>editor = do_QueryInterface(mEditor);
|
|
|
|
if (editor)
|
|
|
|
{
|
|
|
|
nsCOMPtr<nsIPresShell>ps;
|
|
|
|
editor->GetPresShell(getter_AddRefs(ps));
|
|
|
|
if (ps)
|
|
|
|
{
|
|
|
|
ps->SetCaretEnabled(PR_FALSE);
|
1999-08-03 10:07:29 +04:00
|
|
|
|
|
|
|
nsCOMPtr<nsIDOMDocument>domDoc;
|
|
|
|
editor->GetDocument(getter_AddRefs(domDoc));
|
|
|
|
if (domDoc)
|
Preparation for ender-based text control
* added focus listener. Doesn't do much yet, but when focus notifications start appearing, we'll be ready for them. The code is in
place to hide selection when we lose focus and paint selection when we get focus. That's probably not quite right, but it's a start.
We will need to be able to determine the distinction between losing focus to another control within our app, and losing focus to
another app.
* added support for disabled and readonly states in the editor. This is accomplished by having flags set by the client, and letting the
rules system deal with those flags. The flags I added are:
TEXT_EDITOR_FLAG_PLAINTEXT 0x01 // only plain text editing is allowed
TEXT_EDITOR_FLAG_SINGLELINE 0x02 // enter key and CR-LF handled specially
TEXT_EDITOR_FLAG_PASSWORD 0x04 // text is not entered into content, only a representative character
TEXT_EDITOR_FLAG_READONLY 0x08 // editing events are disabled. Editor may still accept focus.
TEXT_EDITOR_FLAG_DISALBED 0x10 // all events are disabled (like scrolling). Editor will not accept focus.
* added WillInsertBreak/DidInsertBreak into text rules, so flags could be checked. This gets us readonly, disabled, and single line
behavior.
* cleaned up the code that allocates, registers, and destroys event listeners. Thanks to Kin and Simon for cleaning up the
ownership model on the listeners, it was a big help.
* added support for a max text length. You can now tell the text editor, be no bigger than n characters.
1999-05-29 01:24:18 +04:00
|
|
|
{
|
1999-08-03 10:07:29 +04:00
|
|
|
nsCOMPtr<nsIDocument>doc = do_QueryInterface(domDoc);
|
|
|
|
if (doc)
|
|
|
|
{
|
|
|
|
doc->SetDisplaySelection(PR_FALSE);
|
|
|
|
}
|
Preparation for ender-based text control
* added focus listener. Doesn't do much yet, but when focus notifications start appearing, we'll be ready for them. The code is in
place to hide selection when we lose focus and paint selection when we get focus. That's probably not quite right, but it's a start.
We will need to be able to determine the distinction between losing focus to another control within our app, and losing focus to
another app.
* added support for disabled and readonly states in the editor. This is accomplished by having flags set by the client, and letting the
rules system deal with those flags. The flags I added are:
TEXT_EDITOR_FLAG_PLAINTEXT 0x01 // only plain text editing is allowed
TEXT_EDITOR_FLAG_SINGLELINE 0x02 // enter key and CR-LF handled specially
TEXT_EDITOR_FLAG_PASSWORD 0x04 // text is not entered into content, only a representative character
TEXT_EDITOR_FLAG_READONLY 0x08 // editing events are disabled. Editor may still accept focus.
TEXT_EDITOR_FLAG_DISALBED 0x10 // all events are disabled (like scrolling). Editor will not accept focus.
* added WillInsertBreak/DidInsertBreak into text rules, so flags could be checked. This gets us readonly, disabled, and single line
behavior.
* cleaned up the code that allocates, registers, and destroys event listeners. Thanks to Kin and Simon for cleaning up the
ownership model on the listeners, it was a big help.
* added support for a max text length. You can now tell the text editor, be no bigger than n characters.
1999-05-29 01:24:18 +04:00
|
|
|
}
|
1999-08-31 05:14:40 +04:00
|
|
|
#ifdef USE_HACK_REPAINT
|
1999-08-03 10:07:29 +04:00
|
|
|
// begin hack repaint
|
|
|
|
nsCOMPtr<nsIViewManager> viewmgr;
|
|
|
|
ps->GetViewManager(getter_AddRefs(viewmgr));
|
|
|
|
if (viewmgr)
|
|
|
|
{
|
|
|
|
nsIView* view;
|
1999-08-25 14:51:55 +04:00
|
|
|
viewmgr->GetRootView(view); // views are not refCounted
|
1999-08-03 10:07:29 +04:00
|
|
|
if (view) {
|
|
|
|
viewmgr->UpdateView(view,nsnull,NS_VMREFRESH_IMMEDIATE);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
// end hack repaint
|
1999-08-31 05:14:40 +04:00
|
|
|
#else
|
|
|
|
ps->RepaintSelection(SELECTION_NORMAL);
|
|
|
|
#endif
|
Preparation for ender-based text control
* added focus listener. Doesn't do much yet, but when focus notifications start appearing, we'll be ready for them. The code is in
place to hide selection when we lose focus and paint selection when we get focus. That's probably not quite right, but it's a start.
We will need to be able to determine the distinction between losing focus to another control within our app, and losing focus to
another app.
* added support for disabled and readonly states in the editor. This is accomplished by having flags set by the client, and letting the
rules system deal with those flags. The flags I added are:
TEXT_EDITOR_FLAG_PLAINTEXT 0x01 // only plain text editing is allowed
TEXT_EDITOR_FLAG_SINGLELINE 0x02 // enter key and CR-LF handled specially
TEXT_EDITOR_FLAG_PASSWORD 0x04 // text is not entered into content, only a representative character
TEXT_EDITOR_FLAG_READONLY 0x08 // editing events are disabled. Editor may still accept focus.
TEXT_EDITOR_FLAG_DISALBED 0x10 // all events are disabled (like scrolling). Editor will not accept focus.
* added WillInsertBreak/DidInsertBreak into text rules, so flags could be checked. This gets us readonly, disabled, and single line
behavior.
* cleaned up the code that allocates, registers, and destroys event listeners. Thanks to Kin and Simon for cleaning up the
ownership model on the listeners, it was a big help.
* added support for a max text length. You can now tell the text editor, be no bigger than n characters.
1999-05-29 01:24:18 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|