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"
11 #include "nsISelection.h"
22 LINE_BREAK_TYPE_NATIVE
,
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
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
);
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
);
72 nsresult
InitCommon();
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
,
83 LineBreakType aLineBreakType
);
84 static nsresult
GetFlatTextOffsetOfRange(nsIContent
* aRootContent
,
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
91 static uint32_t GetNativeTextLength(nsIContent
* aContent
,
92 uint32_t aStartOffset
,
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
);
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
,
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
122 nsresult
GetStartFrameAndOffset(nsRange
* aRange
,
124 int32_t* aOffsetInFrame
);
125 // Convert the frame relative offset to the root view relative offset.
126 nsresult
ConvertToRootViewRelativeOffset(nsIFrame
* aFrame
,
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_