/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- * * The contents of this file are subject to the Netscape Public * License Version 1.1 (the "License"); you may not use this file * except in compliance with the License. You may obtain a copy of * the License at http://www.mozilla.org/NPL/ * * Software distributed under the License is distributed on an "AS * IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or * implied. See the License for the specific language governing * rights and limitations under the License. * * The Original Code is mozilla.org code. * * The Initial Developer of the Original Code is Netscape * Communications Corporation. Portions created by Netscape are * Copyright (C) 1998 Netscape Communications Corporation. All * Rights Reserved. * * Contributor(s): */ #ifndef nsGfxTextControlFrame_h___ #define nsGfxTextControlFrame_h___ #include "nsIGfxTextControlFrame.h" #include "nsCOMPtr.h" #include "nsCWeakReference.h" #include "nsFormControlFrame.h" #include "nsIDocumentLoaderObserver.h" #include "nsIEditor.h" #include "nsIDocumentObserver.h" #include "nsIDOMKeyListener.h" #include "nsIDOMMouseListener.h" #include "nsIDOMDragListener.h" #include "nsIDOMFocusListener.h" #include "nsISelectionListener.h" #include "nsITransactionListener.h" #include "nsIDOMDocument.h" #include "nsIPresContext.h" #include "nsIContent.h" #include "nsIDOMMouseEvent.h" #include "nsIDOMKeyEvent.h" #include "nsITextContent.h" #include "nsHTMLValue.h" #include "nsIDocShell.h" #include "nsIViewManager.h" #include "nsIStatefulFrame.h" #include "nsCSSFrameConstructor.h" class nsIFrame; class nsISelection; class nsIDOMCharacterData; class nsGfxTextControlFrame; #define NS_IENDER_EVENT_LISTENER_IID \ {/* e4bf05b0-457f-11d3-86ea-000064657374*/ \ 0xe4bf05b0, 0x457f, 0x11d3, \ {0x86, 0xea, 0x0, 0x0, 0x64, 0x65, 0x73, 0x74} } /******************************************************************************* * EnderTempObserver * This class is responsible for notifying mFrame when the document * has finished loading. ******************************************************************************/ class EnderTempObserver : public nsIDocumentLoaderObserver { public: EnderTempObserver(); virtual ~EnderTempObserver(); NS_IMETHOD SetFrame(nsGfxTextControlFrame *aFrame); // nsISupports NS_DECL_ISUPPORTS // nsIDocumentLoaderObserver NS_DECL_NSIDOCUMENTLOADEROBSERVER protected: nsGfxTextControlFrame *mFrame; // not ref counted PRBool mFirstCall; }; /******************************************************************************* * nsEnderDocumentObserver * This class is responsible for notifying mFrame about document content changes. ******************************************************************************/ class nsEnderDocumentObserver : public nsIDocumentObserver { public: nsEnderDocumentObserver(); NS_IMETHOD SetFrame(nsGfxTextControlFrame *aFrame); virtual ~nsEnderDocumentObserver(); // nsISupports NS_DECL_ISUPPORTS NS_IMETHOD BeginUpdate(nsIDocument *aDocument); NS_IMETHOD EndUpdate(nsIDocument *aDocument); NS_IMETHOD BeginLoad(nsIDocument *aDocument); NS_IMETHOD EndLoad(nsIDocument *aDocument); NS_IMETHOD BeginReflow(nsIDocument *aDocument, nsIPresShell* aShell); NS_IMETHOD EndReflow(nsIDocument *aDocument, nsIPresShell* aShell); NS_IMETHOD ContentChanged(nsIDocument *aDocument, nsIContent* aContent, nsISupports* aSubContent); NS_IMETHOD ContentStatesChanged(nsIDocument* aDocument, nsIContent* aContent1, nsIContent* aContent2); NS_IMETHOD AttributeChanged(nsIDocument *aDocument, nsIContent* aContent, PRInt32 aNameSpaceID, nsIAtom* aAttribute, PRInt32 aHint); NS_IMETHOD ContentAppended(nsIDocument *aDocument, nsIContent* aContainer, PRInt32 aNewIndexInContainer); NS_IMETHOD ContentInserted(nsIDocument *aDocument, nsIContent* aContainer, nsIContent* aChild, PRInt32 aIndexInContainer); NS_IMETHOD ContentReplaced(nsIDocument *aDocument, nsIContent* aContainer, nsIContent* aOldChild, nsIContent* aNewChild, PRInt32 aIndexInContainer); NS_IMETHOD ContentRemoved(nsIDocument *aDocument, nsIContent* aContainer, nsIContent* aChild, PRInt32 aIndexInContainer); NS_IMETHOD StyleSheetAdded(nsIDocument *aDocument, nsIStyleSheet* aStyleSheet); NS_IMETHOD StyleSheetRemoved(nsIDocument *aDocument, nsIStyleSheet* aStyleSheet); NS_IMETHOD StyleSheetDisabledStateChanged(nsIDocument *aDocument, nsIStyleSheet* aStyleSheet, PRBool aDisabled); NS_IMETHOD StyleRuleChanged(nsIDocument *aDocument, nsIStyleSheet* aStyleSheet, nsIStyleRule* aStyleRule, PRInt32 aHint); NS_IMETHOD StyleRuleAdded(nsIDocument *aDocument, nsIStyleSheet* aStyleSheet, nsIStyleRule* aStyleRule); NS_IMETHOD StyleRuleRemoved(nsIDocument *aDocument, nsIStyleSheet* aStyleSheet, nsIStyleRule* aStyleRule); NS_IMETHOD DocumentWillBeDestroyed(nsIDocument *aDocument); protected: nsGfxTextControlFrame *mFrame; // not ref counted }; /****************************************************************************** * nsIEnderEventListener * Standard interface for event listeners that are attached to nsGfxTextControls ******************************************************************************/ class nsIEnderEventListener : public nsISupports { public: static const nsIID& GetIID() { static nsIID iid = NS_IENDER_EVENT_LISTENER_IID; return iid; } /** SetFrame sets the frame we send event messages to, when necessary * @param aFrame -- the frame, can be null, not ref counted (guaranteed to outlive us!) */ NS_IMETHOD SetFrame(nsGfxTextControlFrame *aFrame)=0; /** set the pres context associated with this listener instance */ NS_IMETHOD SetPresContext(nsIPresContext *aCx)=0; /** set the view associated with this listener instance */ NS_IMETHOD SetView(nsIView *aView)=0; NS_IMETHOD SetInnerPresShell(nsIPresShell* aPresShell)=0; // Weak ref }; /****************************************************************************** * nsEnderEventListener * This class is responsible for propogating events from the embedded docshell * of nsGfxTextControlFrame to the parent environment. This enables DOM * event listeners on text controls. ******************************************************************************/ class nsEnderEventListener; // forward declaration for factory /* factory for ender key listener */ nsresult NS_NewEnderEventListener(nsIEnderEventListener ** aInstancePtrResult); class nsEnderEventListener : public nsIEnderEventListener, public nsIDOMKeyListener, public nsIDOMMouseListener, public nsIDOMFocusListener, public nsISelectionListener, public nsITransactionListener { public: /** the default destructor */ virtual ~nsEnderEventListener(); /** interfaces for addref and release and queryinterface*/ NS_DECL_ISUPPORTS /** nsIEnderEventListener interfaces * @see nsIEnderEventListener */ NS_IMETHOD SetFrame(nsGfxTextControlFrame *aFrame); NS_IMETHOD SetPresContext(nsIPresContext *aCx) {mContext = do_QueryInterface(aCx); return NS_OK;} NS_IMETHOD SetView(nsIView *aView) {mView = aView; return NS_OK;} // views are not ref counted NS_IMETHOD SetInnerPresShell(nsIPresShell* aPresShell) { mInnerShell = aPresShell; return NS_OK; } /** nsIDOMKeyListener interfaces * @see nsIDOMKeyListener */ virtual nsresult HandleEvent(nsIDOMEvent* aEvent); virtual nsresult KeyDown(nsIDOMEvent* aKeyEvent); virtual nsresult KeyUp(nsIDOMEvent* aKeyEvent); virtual nsresult KeyPress(nsIDOMEvent* aKeyEvent); /* END interfaces from nsIDOMKeyListener*/ /** nsIDOMMouseListener interfaces * @see nsIDOMMouseListener */ virtual nsresult MouseDown(nsIDOMEvent* aMouseEvent); virtual nsresult MouseUp(nsIDOMEvent* aMouseEvent); virtual nsresult MouseClick(nsIDOMEvent* aMouseEvent); virtual nsresult MouseDblClick(nsIDOMEvent* aMouseEvent); virtual nsresult MouseOver(nsIDOMEvent* aMouseEvent); virtual nsresult MouseOut(nsIDOMEvent* aMouseEvent); /* END interfaces from nsIDOMMouseListener*/ /** nsIDOMFocusListener interfaces * used to propogate focus, blur, and change notifications * @see nsIDOMFocusListener */ virtual nsresult Focus(nsIDOMEvent* aEvent); virtual nsresult Blur (nsIDOMEvent* aEvent); /* END interfaces from nsIDOMFocusListener*/ /** nsISelectionListener interfaces * @see nsISelectionListener */ NS_IMETHOD NotifySelectionChanged(nsIDOMDocument *, nsISelection *, short); /*END interfaces from nsISelectionListener*/ /** nsITransactionListener interfaces */ NS_IMETHOD WillDo(nsITransactionManager *aManager, nsITransaction *aTransaction, PRBool *aInterrupt); NS_IMETHOD DidDo(nsITransactionManager *aManager, nsITransaction *aTransaction, nsresult aDoResult); NS_IMETHOD WillUndo(nsITransactionManager *aManager, nsITransaction *aTransaction, PRBool *aInterrupt); NS_IMETHOD DidUndo(nsITransactionManager *aManager, nsITransaction *aTransaction, nsresult aUndoResult); NS_IMETHOD WillRedo(nsITransactionManager *aManager, nsITransaction *aTransaction, PRBool *aInterrupt); NS_IMETHOD DidRedo(nsITransactionManager *aManager, nsITransaction *aTransaction, nsresult aRedoResult); NS_IMETHOD WillBeginBatch(nsITransactionManager *aManager, PRBool *aInterrupt); NS_IMETHOD DidBeginBatch(nsITransactionManager *aManager, nsresult aResult); NS_IMETHOD WillEndBatch(nsITransactionManager *aManager, PRBool *aInterrupt); NS_IMETHOD DidEndBatch(nsITransactionManager *aManager, nsresult aResult); NS_IMETHOD WillMerge(nsITransactionManager *aManager, nsITransaction *aTopTransaction, nsITransaction *aTransactionToMerge, PRBool *aInterrupt); NS_IMETHOD DidMerge(nsITransactionManager *aManager, nsITransaction *aTopTransaction, nsITransaction *aTransactionToMerge, PRBool aDidMerge, nsresult aMergeResult); friend nsresult NS_NewEnderEventListener(nsIEnderEventListener ** aInstancePtrResult); protected: /** the default constructor. Protected, use the factory to create an instance. * @see NS_NewEnderEventListener */ nsEnderEventListener(); /** key event dispatch helpers */ nsresult DispatchKeyEvent(nsIDOMKeyEvent* aOrigEvent, PRInt32 aEventType); /** mouse event dispatch helper */ nsresult DispatchMouseEvent(nsIDOMMouseEvent *aEvent, PRInt32 aEventType); protected: nsCWeakReference mFrame; nsIView *mView; // not ref counted nsCOMPtr mContext; // ref counted nsIPresShell* mInnerShell; // not ref counted nsCOMPtr mContent; // ref counted nsString mTextValue; // the value of the text field at focus PRBool mSkipFocusDispatch; // On Mouse down we don't want to dispatch // any focus events (they get dispatched // from the native widget // note nsGfxTextControlFrame is held as a weak ptr // because the frame can be deleted in the middle // of event processing. See the KeyUp handler // for places where this is a problem, and see // nsCWeakReference.h for notes on use. PRPackedBool mFirstDoOfFirstUndo; }; /****************************************************************************** * nsEnderFocusListenerForDisplayContent * used to watch for focus notifications on the text control frame's display content ******************************************************************************/ class nsEnderFocusListenerForDisplayContent : public nsIDOMFocusListener { public: /** the default destructor */ virtual ~nsEnderFocusListenerForDisplayContent(); /*interfaces for addref and release and queryinterface*/ NS_DECL_ISUPPORTS /* nsIDOMFocusListener interfaces */ virtual nsresult HandleEvent(nsIDOMEvent* aEvent); virtual nsresult Focus(nsIDOMEvent* aEvent); virtual nsresult Blur (nsIDOMEvent* aEvent); /* END interfaces from nsIDOMFocusListener*/ NS_IMETHOD SetFrame(nsGfxTextControlFrame *aFrame); nsEnderFocusListenerForDisplayContent(); protected: nsGfxTextControlFrame *mFrame; // not ref counted }; /****************************************************************************** * nsEnderListenerForContent * used to watch for drag notifications on the text control frame's content ******************************************************************************/ class nsEnderListenerForContent : public nsIDOMDragListener { public: /** the default destructor */ virtual ~nsEnderListenerForContent(); /*interfaces for addref and release and queryinterface*/ NS_DECL_ISUPPORTS /** nsIDOMDragListener interfaces * @see nsIDOMDragListener */ virtual nsresult HandleEvent(nsIDOMEvent* aEvent); virtual nsresult DragEnter(nsIDOMEvent* aDragEvent); virtual nsresult DragOver(nsIDOMEvent* aDragEvent); virtual nsresult DragExit(nsIDOMEvent* aDragEvent); virtual nsresult DragDrop(nsIDOMEvent* aDragEvent); virtual nsresult DragGesture(nsIDOMEvent* aDragEvent); /* END interfaces from nsIDOMDragListener*/ NS_IMETHOD SetFrame(nsGfxTextControlFrame *aFrame); nsEnderListenerForContent(); protected: nsGfxTextControlFrame *mFrame; // not ref counted nsCOMPtr mViewManager; }; /****************************************************************************** * nsGfxTextControlFrame * frame that represents an HTML text input element * handles both and