Bumping gaia.json for 2 gaia revision(s) a=gaia-bump
[gecko.git] / dom / events / ContentEventHandler.h
blobf10818c57f43d63a79200e6f046d1f703510b4b0
1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* This Source Code Form is subject to the terms of the Mozilla Public
3 * License, v. 2.0. If a copy of the MPL was not distributed with this
4 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
6 #ifndef mozilla_ContentEventHandler_h_
7 #define mozilla_ContentEventHandler_h_
9 #include "mozilla/EventForwards.h"
10 #include "nsCOMPtr.h"
11 #include "nsISelection.h"
12 #include "nsRange.h"
14 class nsPresContext;
16 struct nsRect;
18 namespace mozilla {
20 enum LineBreakType
22 LINE_BREAK_TYPE_NATIVE,
23 LINE_BREAK_TYPE_XP
27 * Query Content Event Handler
28 * ContentEventHandler is a helper class for EventStateManager.
29 * The platforms request some content informations, e.g., the selected text,
30 * the offset of the selected text and the text for specified range.
31 * This class answers to NS_QUERY_* events from actual contents.
34 class MOZ_STACK_CLASS ContentEventHandler
36 public:
37 ContentEventHandler(nsPresContext* aPresContext);
39 // NS_QUERY_SELECTED_TEXT event handler
40 nsresult OnQuerySelectedText(WidgetQueryContentEvent* aEvent);
41 // NS_QUERY_TEXT_CONTENT event handler
42 nsresult OnQueryTextContent(WidgetQueryContentEvent* aEvent);
43 // NS_QUERY_CARET_RECT event handler
44 nsresult OnQueryCaretRect(WidgetQueryContentEvent* aEvent);
45 // NS_QUERY_TEXT_RECT event handler
46 nsresult OnQueryTextRect(WidgetQueryContentEvent* aEvent);
47 // NS_QUERY_EDITOR_RECT event handler
48 nsresult OnQueryEditorRect(WidgetQueryContentEvent* aEvent);
49 // NS_QUERY_CONTENT_STATE event handler
50 nsresult OnQueryContentState(WidgetQueryContentEvent* aEvent);
51 // NS_QUERY_SELECTION_AS_TRANSFERABLE event handler
52 nsresult OnQuerySelectionAsTransferable(WidgetQueryContentEvent* aEvent);
53 // NS_QUERY_CHARACTER_AT_POINT event handler
54 nsresult OnQueryCharacterAtPoint(WidgetQueryContentEvent* aEvent);
55 // NS_QUERY_DOM_WIDGET_HITTEST event handler
56 nsresult OnQueryDOMWidgetHittest(WidgetQueryContentEvent* aEvent);
58 // NS_SELECTION_* event
59 nsresult OnSelectionEvent(WidgetSelectionEvent* aEvent);
61 protected:
62 nsPresContext* mPresContext;
63 nsCOMPtr<nsIPresShell> mPresShell;
64 nsCOMPtr<nsISelection> mSelection;
65 nsRefPtr<nsRange> mFirstSelectedRange;
66 nsCOMPtr<nsIContent> mRootContent;
68 nsresult Init(WidgetQueryContentEvent* aEvent);
69 nsresult Init(WidgetSelectionEvent* aEvent);
71 nsresult InitBasic();
72 nsresult InitCommon();
74 public:
75 // FlatText means the text that is generated from DOM tree. The BR elements
76 // are replaced to native linefeeds. Other elements are ignored.
78 // Get the offset in FlatText of the range. (also used by IMEContentObserver)
79 static nsresult GetFlatTextOffsetOfRange(nsIContent* aRootContent,
80 nsINode* aNode,
81 int32_t aNodeOffset,
82 uint32_t* aOffset,
83 LineBreakType aLineBreakType);
84 static nsresult GetFlatTextOffsetOfRange(nsIContent* aRootContent,
85 nsRange* aRange,
86 uint32_t* aOffset,
87 LineBreakType aLineBreakType);
88 // Computes the native text length between aStartOffset and aEndOffset of
89 // aContent. Currently, this method supports only text node or br element
90 // for aContent.
91 static uint32_t GetNativeTextLength(nsIContent* aContent,
92 uint32_t aStartOffset,
93 uint32_t aEndOffset);
94 // Get the native text length of a content node excluding any children
95 static uint32_t GetNativeTextLength(nsIContent* aContent,
96 uint32_t aMaxLength = UINT32_MAX);
97 protected:
98 static uint32_t GetTextLength(nsIContent* aContent,
99 LineBreakType aLineBreakType,
100 uint32_t aMaxLength = UINT32_MAX);
101 static LineBreakType GetLineBreakType(WidgetQueryContentEvent* aEvent);
102 static LineBreakType GetLineBreakType(WidgetSelectionEvent* aEvent);
103 static LineBreakType GetLineBreakType(bool aUseNativeLineBreak);
104 // Returns focused content (including its descendant documents).
105 nsIContent* GetFocusedContent();
106 // Returns true if the content is a plugin host.
107 bool IsPlugin(nsIContent* aContent);
108 // QueryContentRect() sets the rect of aContent's frame(s) to aEvent.
109 nsresult QueryContentRect(nsIContent* aContent,
110 WidgetQueryContentEvent* aEvent);
111 // Make the DOM range from the offset of FlatText and the text length.
112 // If aExpandToClusterBoundaries is true, the start offset and the end one are
113 // expanded to nearest cluster boundaries.
114 nsresult SetRangeFromFlatTextOffset(nsRange* aRange,
115 uint32_t aOffset,
116 uint32_t aLength,
117 LineBreakType aLineBreakType,
118 bool aExpandToClusterBoundaries,
119 uint32_t* aNewOffset = nullptr);
120 // Find the first textframe for the range, and get the start offset in
121 // the frame.
122 nsresult GetStartFrameAndOffset(nsRange* aRange,
123 nsIFrame** aFrame,
124 int32_t* aOffsetInFrame);
125 // Convert the frame relative offset to the root view relative offset.
126 nsresult ConvertToRootViewRelativeOffset(nsIFrame* aFrame,
127 nsRect& aRect);
128 // Expand aXPOffset to the nearest offset in cluster boundary. aForward is
129 // true, it is expanded to forward.
130 nsresult ExpandToClusterBoundary(nsIContent* aContent, bool aForward,
131 uint32_t* aXPOffset);
134 } // namespace mozilla
136 #endif // mozilla_ContentEventHandler_h_