|
1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ |
|
2 /* vim: set ts=2 sw=2 et tw=80: */ |
|
3 /* This Source Code Form is subject to the terms of the Mozilla Public |
|
4 * License, v. 2.0. If a copy of the MPL was not distributed with this |
|
5 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ |
|
6 |
|
7 #ifndef mozilla_IMEContentObserver_h_ |
|
8 #define mozilla_IMEContentObserver_h_ |
|
9 |
|
10 #include "mozilla/Attributes.h" |
|
11 #include "nsCOMPtr.h" |
|
12 #include "nsCycleCollectionParticipant.h" |
|
13 #include "nsIDocShell.h" // XXX Why does only this need to be included here? |
|
14 #include "nsIReflowObserver.h" |
|
15 #include "nsISelectionListener.h" |
|
16 #include "nsIScrollObserver.h" |
|
17 #include "nsIWidget.h" // for nsIMEUpdatePreference |
|
18 #include "nsStubMutationObserver.h" |
|
19 #include "nsWeakReference.h" |
|
20 |
|
21 class nsIContent; |
|
22 class nsINode; |
|
23 class nsISelection; |
|
24 class nsPresContext; |
|
25 |
|
26 namespace mozilla { |
|
27 |
|
28 class EventStateManager; |
|
29 |
|
30 // IMEContentObserver notifies widget of any text and selection changes |
|
31 // in the currently focused editor |
|
32 class IMEContentObserver MOZ_FINAL : public nsISelectionListener, |
|
33 public nsStubMutationObserver, |
|
34 public nsIReflowObserver, |
|
35 public nsIScrollObserver, |
|
36 public nsSupportsWeakReference |
|
37 { |
|
38 public: |
|
39 IMEContentObserver(); |
|
40 |
|
41 NS_DECL_CYCLE_COLLECTING_ISUPPORTS |
|
42 NS_DECL_CYCLE_COLLECTION_CLASS_AMBIGUOUS(IMEContentObserver, |
|
43 nsISelectionListener) |
|
44 NS_DECL_NSISELECTIONLISTENER |
|
45 NS_DECL_NSIMUTATIONOBSERVER_CHARACTERDATACHANGED |
|
46 NS_DECL_NSIMUTATIONOBSERVER_CONTENTAPPENDED |
|
47 NS_DECL_NSIMUTATIONOBSERVER_CONTENTINSERTED |
|
48 NS_DECL_NSIMUTATIONOBSERVER_CONTENTREMOVED |
|
49 NS_DECL_NSIMUTATIONOBSERVER_ATTRIBUTEWILLCHANGE |
|
50 NS_DECL_NSIMUTATIONOBSERVER_ATTRIBUTECHANGED |
|
51 NS_DECL_NSIREFLOWOBSERVER |
|
52 |
|
53 // nsIScrollObserver |
|
54 virtual void ScrollPositionChanged() MOZ_OVERRIDE; |
|
55 |
|
56 void Init(nsIWidget* aWidget, nsPresContext* aPresContext, |
|
57 nsIContent* aContent); |
|
58 void Destroy(); |
|
59 /** |
|
60 * IMEContentObserver is stored by EventStateManager during observing. |
|
61 * DisconnectFromEventStateManager() is called when EventStateManager stops |
|
62 * storing the instance. |
|
63 */ |
|
64 void DisconnectFromEventStateManager(); |
|
65 bool IsManaging(nsPresContext* aPresContext, nsIContent* aContent); |
|
66 bool IsEditorHandlingEventForComposition() const; |
|
67 bool KeepAliveDuringDeactive() const |
|
68 { |
|
69 return mUpdatePreference.WantDuringDeactive(); |
|
70 } |
|
71 nsIWidget* GetWidget() const { return mWidget; } |
|
72 nsresult GetSelectionAndRoot(nsISelection** aSelection, |
|
73 nsIContent** aRoot) const; |
|
74 |
|
75 private: |
|
76 void NotifyContentAdded(nsINode* aContainer, int32_t aStart, int32_t aEnd); |
|
77 void ObserveEditableNode(); |
|
78 |
|
79 nsCOMPtr<nsIWidget> mWidget; |
|
80 nsCOMPtr<nsISelection> mSelection; |
|
81 nsCOMPtr<nsIContent> mRootContent; |
|
82 nsCOMPtr<nsINode> mEditableNode; |
|
83 nsCOMPtr<nsIDocShell> mDocShell; |
|
84 |
|
85 EventStateManager* mESM; |
|
86 |
|
87 nsIMEUpdatePreference mUpdatePreference; |
|
88 uint32_t mPreAttrChangeLength; |
|
89 }; |
|
90 |
|
91 } // namespace mozilla |
|
92 |
|
93 #endif // mozilla_IMEContentObserver_h_ |