michael@0: /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ michael@0: /* vim: set ts=2 sw=2 et tw=80: */ michael@0: /* This Source Code Form is subject to the terms of the Mozilla Public michael@0: * License, v. 2.0. If a copy of the MPL was not distributed with this michael@0: * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ michael@0: michael@0: #ifndef mozilla_IMEContentObserver_h_ michael@0: #define mozilla_IMEContentObserver_h_ michael@0: michael@0: #include "mozilla/Attributes.h" michael@0: #include "nsCOMPtr.h" michael@0: #include "nsCycleCollectionParticipant.h" michael@0: #include "nsIDocShell.h" // XXX Why does only this need to be included here? michael@0: #include "nsIReflowObserver.h" michael@0: #include "nsISelectionListener.h" michael@0: #include "nsIScrollObserver.h" michael@0: #include "nsIWidget.h" // for nsIMEUpdatePreference michael@0: #include "nsStubMutationObserver.h" michael@0: #include "nsWeakReference.h" michael@0: michael@0: class nsIContent; michael@0: class nsINode; michael@0: class nsISelection; michael@0: class nsPresContext; michael@0: michael@0: namespace mozilla { michael@0: michael@0: class EventStateManager; michael@0: michael@0: // IMEContentObserver notifies widget of any text and selection changes michael@0: // in the currently focused editor michael@0: class IMEContentObserver MOZ_FINAL : public nsISelectionListener, michael@0: public nsStubMutationObserver, michael@0: public nsIReflowObserver, michael@0: public nsIScrollObserver, michael@0: public nsSupportsWeakReference michael@0: { michael@0: public: michael@0: IMEContentObserver(); michael@0: michael@0: NS_DECL_CYCLE_COLLECTING_ISUPPORTS michael@0: NS_DECL_CYCLE_COLLECTION_CLASS_AMBIGUOUS(IMEContentObserver, michael@0: nsISelectionListener) michael@0: NS_DECL_NSISELECTIONLISTENER michael@0: NS_DECL_NSIMUTATIONOBSERVER_CHARACTERDATACHANGED michael@0: NS_DECL_NSIMUTATIONOBSERVER_CONTENTAPPENDED michael@0: NS_DECL_NSIMUTATIONOBSERVER_CONTENTINSERTED michael@0: NS_DECL_NSIMUTATIONOBSERVER_CONTENTREMOVED michael@0: NS_DECL_NSIMUTATIONOBSERVER_ATTRIBUTEWILLCHANGE michael@0: NS_DECL_NSIMUTATIONOBSERVER_ATTRIBUTECHANGED michael@0: NS_DECL_NSIREFLOWOBSERVER michael@0: michael@0: // nsIScrollObserver michael@0: virtual void ScrollPositionChanged() MOZ_OVERRIDE; michael@0: michael@0: void Init(nsIWidget* aWidget, nsPresContext* aPresContext, michael@0: nsIContent* aContent); michael@0: void Destroy(); michael@0: /** michael@0: * IMEContentObserver is stored by EventStateManager during observing. michael@0: * DisconnectFromEventStateManager() is called when EventStateManager stops michael@0: * storing the instance. michael@0: */ michael@0: void DisconnectFromEventStateManager(); michael@0: bool IsManaging(nsPresContext* aPresContext, nsIContent* aContent); michael@0: bool IsEditorHandlingEventForComposition() const; michael@0: bool KeepAliveDuringDeactive() const michael@0: { michael@0: return mUpdatePreference.WantDuringDeactive(); michael@0: } michael@0: nsIWidget* GetWidget() const { return mWidget; } michael@0: nsresult GetSelectionAndRoot(nsISelection** aSelection, michael@0: nsIContent** aRoot) const; michael@0: michael@0: private: michael@0: void NotifyContentAdded(nsINode* aContainer, int32_t aStart, int32_t aEnd); michael@0: void ObserveEditableNode(); michael@0: michael@0: nsCOMPtr mWidget; michael@0: nsCOMPtr mSelection; michael@0: nsCOMPtr mRootContent; michael@0: nsCOMPtr mEditableNode; michael@0: nsCOMPtr mDocShell; michael@0: michael@0: EventStateManager* mESM; michael@0: michael@0: nsIMEUpdatePreference mUpdatePreference; michael@0: uint32_t mPreAttrChangeLength; michael@0: }; michael@0: michael@0: } // namespace mozilla michael@0: michael@0: #endif // mozilla_IMEContentObserver_h_