1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/dom/events/IMEContentObserver.h Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,93 @@ 1.4 +/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ 1.5 +/* vim: set ts=2 sw=2 et tw=80: */ 1.6 +/* This Source Code Form is subject to the terms of the Mozilla Public 1.7 + * License, v. 2.0. If a copy of the MPL was not distributed with this 1.8 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ 1.9 + 1.10 +#ifndef mozilla_IMEContentObserver_h_ 1.11 +#define mozilla_IMEContentObserver_h_ 1.12 + 1.13 +#include "mozilla/Attributes.h" 1.14 +#include "nsCOMPtr.h" 1.15 +#include "nsCycleCollectionParticipant.h" 1.16 +#include "nsIDocShell.h" // XXX Why does only this need to be included here? 1.17 +#include "nsIReflowObserver.h" 1.18 +#include "nsISelectionListener.h" 1.19 +#include "nsIScrollObserver.h" 1.20 +#include "nsIWidget.h" // for nsIMEUpdatePreference 1.21 +#include "nsStubMutationObserver.h" 1.22 +#include "nsWeakReference.h" 1.23 + 1.24 +class nsIContent; 1.25 +class nsINode; 1.26 +class nsISelection; 1.27 +class nsPresContext; 1.28 + 1.29 +namespace mozilla { 1.30 + 1.31 +class EventStateManager; 1.32 + 1.33 +// IMEContentObserver notifies widget of any text and selection changes 1.34 +// in the currently focused editor 1.35 +class IMEContentObserver MOZ_FINAL : public nsISelectionListener, 1.36 + public nsStubMutationObserver, 1.37 + public nsIReflowObserver, 1.38 + public nsIScrollObserver, 1.39 + public nsSupportsWeakReference 1.40 +{ 1.41 +public: 1.42 + IMEContentObserver(); 1.43 + 1.44 + NS_DECL_CYCLE_COLLECTING_ISUPPORTS 1.45 + NS_DECL_CYCLE_COLLECTION_CLASS_AMBIGUOUS(IMEContentObserver, 1.46 + nsISelectionListener) 1.47 + NS_DECL_NSISELECTIONLISTENER 1.48 + NS_DECL_NSIMUTATIONOBSERVER_CHARACTERDATACHANGED 1.49 + NS_DECL_NSIMUTATIONOBSERVER_CONTENTAPPENDED 1.50 + NS_DECL_NSIMUTATIONOBSERVER_CONTENTINSERTED 1.51 + NS_DECL_NSIMUTATIONOBSERVER_CONTENTREMOVED 1.52 + NS_DECL_NSIMUTATIONOBSERVER_ATTRIBUTEWILLCHANGE 1.53 + NS_DECL_NSIMUTATIONOBSERVER_ATTRIBUTECHANGED 1.54 + NS_DECL_NSIREFLOWOBSERVER 1.55 + 1.56 + // nsIScrollObserver 1.57 + virtual void ScrollPositionChanged() MOZ_OVERRIDE; 1.58 + 1.59 + void Init(nsIWidget* aWidget, nsPresContext* aPresContext, 1.60 + nsIContent* aContent); 1.61 + void Destroy(); 1.62 + /** 1.63 + * IMEContentObserver is stored by EventStateManager during observing. 1.64 + * DisconnectFromEventStateManager() is called when EventStateManager stops 1.65 + * storing the instance. 1.66 + */ 1.67 + void DisconnectFromEventStateManager(); 1.68 + bool IsManaging(nsPresContext* aPresContext, nsIContent* aContent); 1.69 + bool IsEditorHandlingEventForComposition() const; 1.70 + bool KeepAliveDuringDeactive() const 1.71 + { 1.72 + return mUpdatePreference.WantDuringDeactive(); 1.73 + } 1.74 + nsIWidget* GetWidget() const { return mWidget; } 1.75 + nsresult GetSelectionAndRoot(nsISelection** aSelection, 1.76 + nsIContent** aRoot) const; 1.77 + 1.78 +private: 1.79 + void NotifyContentAdded(nsINode* aContainer, int32_t aStart, int32_t aEnd); 1.80 + void ObserveEditableNode(); 1.81 + 1.82 + nsCOMPtr<nsIWidget> mWidget; 1.83 + nsCOMPtr<nsISelection> mSelection; 1.84 + nsCOMPtr<nsIContent> mRootContent; 1.85 + nsCOMPtr<nsINode> mEditableNode; 1.86 + nsCOMPtr<nsIDocShell> mDocShell; 1.87 + 1.88 + EventStateManager* mESM; 1.89 + 1.90 + nsIMEUpdatePreference mUpdatePreference; 1.91 + uint32_t mPreAttrChangeLength; 1.92 +}; 1.93 + 1.94 +} // namespace mozilla 1.95 + 1.96 +#endif // mozilla_IMEContentObserver_h_