1 : /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 : /* ***** BEGIN LICENSE BLOCK *****
3 : * Version: MPL 1.1/GPL 2.0/LGPL 2.1
4 : *
5 : * The contents of this file are subject to the Mozilla Public License Version
6 : * 1.1 (the "License"); you may not use this file except in compliance with
7 : * the License. You may obtain a copy of the License at
8 : * http://www.mozilla.org/MPL/
9 : *
10 : * Software distributed under the License is distributed on an "AS IS" basis,
11 : * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
12 : * for the specific language governing rights and limitations under the
13 : * License.
14 : *
15 : * The Original Code is mozilla.org code.
16 : *
17 : * The Initial Developer of the Original Code is
18 : * Mozilla Japan.
19 : * Portions created by the Initial Developer are Copyright (C) 2008
20 : * the Initial Developer. All Rights Reserved.
21 : *
22 : * Contributor(s):
23 : * Masayuki Nakano <masayuki@d-toybox.com>
24 : * Ningjie Chen <chenn@email.uc.edu>
25 : *
26 : * Alternatively, the contents of this file may be used under the terms of
27 : * either of the GNU General Public License Version 2 or later (the "GPL"),
28 : * or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
29 : * in which case the provisions of the GPL or the LGPL are applicable instead
30 : * of those above. If you wish to allow use of your version of this file only
31 : * under the terms of either the GPL or the LGPL, and not to allow others to
32 : * use your version of this file under the terms of the MPL, indicate your
33 : * decision by deleting the provisions above and replace them with the notice
34 : * and other provisions required by the GPL or the LGPL. If you do not delete
35 : * the provisions above, a recipient may use your version of this file under
36 : * the terms of any one of the MPL, the GPL or the LGPL.
37 : *
38 : * ***** END LICENSE BLOCK ***** */
39 :
40 : #ifndef nsContentEventHandler_h__
41 : #define nsContentEventHandler_h__
42 :
43 : #include "nscore.h"
44 : #include "nsCOMPtr.h"
45 :
46 : #include "nsISelection.h"
47 : #include "nsRange.h"
48 : #include "nsIContent.h"
49 : #include "nsIDOMTreeWalker.h"
50 :
51 : class nsPresContext;
52 : class nsIPresShell;
53 : class nsQueryContentEvent;
54 : class nsSelectionEvent;
55 : class nsCaret;
56 : struct nsRect;
57 :
58 : /*
59 : * Query Content Event Handler
60 : * nsContentEventHandler is a helper class for nsEventStateManager.
61 : * The platforms request some content informations, e.g., the selected text,
62 : * the offset of the selected text and the text for specified range.
63 : * This class answers to NS_QUERY_* events from actual contents.
64 : */
65 :
66 0 : class NS_STACK_CLASS nsContentEventHandler {
67 : public:
68 : nsContentEventHandler(nsPresContext *aPresContext);
69 :
70 : // NS_QUERY_SELECTED_TEXT event handler
71 : nsresult OnQuerySelectedText(nsQueryContentEvent* aEvent);
72 : // NS_QUERY_TEXT_CONTENT event handler
73 : nsresult OnQueryTextContent(nsQueryContentEvent* aEvent);
74 : // NS_QUERY_CARET_RECT event handler
75 : nsresult OnQueryCaretRect(nsQueryContentEvent* aEvent);
76 : // NS_QUERY_TEXT_RECT event handler
77 : nsresult OnQueryTextRect(nsQueryContentEvent* aEvent);
78 : // NS_QUERY_EDITOR_RECT event handler
79 : nsresult OnQueryEditorRect(nsQueryContentEvent* aEvent);
80 : // NS_QUERY_CONTENT_STATE event handler
81 : nsresult OnQueryContentState(nsQueryContentEvent* aEvent);
82 : // NS_QUERY_SELECTION_AS_TRANSFERABLE event handler
83 : nsresult OnQuerySelectionAsTransferable(nsQueryContentEvent* aEvent);
84 : // NS_QUERY_CHARACTER_AT_POINT event handler
85 : nsresult OnQueryCharacterAtPoint(nsQueryContentEvent* aEvent);
86 : // NS_QUERY_DOM_WIDGET_HITTEST event handler
87 : nsresult OnQueryDOMWidgetHittest(nsQueryContentEvent* aEvent);
88 :
89 : // NS_SELECTION_* event
90 : nsresult OnSelectionEvent(nsSelectionEvent* aEvent);
91 :
92 : protected:
93 : nsPresContext* mPresContext;
94 : nsCOMPtr<nsIPresShell> mPresShell;
95 : nsCOMPtr<nsISelection> mSelection;
96 : nsRefPtr<nsRange> mFirstSelectedRange;
97 : nsCOMPtr<nsIContent> mRootContent;
98 :
99 : nsresult Init(nsQueryContentEvent* aEvent);
100 : nsresult Init(nsSelectionEvent* aEvent);
101 :
102 : // InitCommon() is called from each Init().
103 : nsresult InitCommon();
104 :
105 : public:
106 : // FlatText means the text that is generated from DOM tree. The BR elements
107 : // are replaced to native linefeeds. Other elements are ignored.
108 :
109 : // Get the offset in FlatText of the range. (also used by nsIMEStateManager)
110 : static nsresult GetFlatTextOffsetOfRange(nsIContent* aRootContent,
111 : nsINode* aNode,
112 : PRInt32 aNodeOffset,
113 : PRUint32* aOffset);
114 : static nsresult GetFlatTextOffsetOfRange(nsIContent* aRootContent,
115 : nsRange* aRange,
116 : PRUint32* aOffset);
117 : protected:
118 : // Make the DOM range from the offset of FlatText and the text length.
119 : // If aExpandToClusterBoundaries is true, the start offset and the end one are
120 : // expanded to nearest cluster boundaries.
121 : nsresult SetRangeFromFlatTextOffset(nsRange* aRange,
122 : PRUint32 aNativeOffset,
123 : PRUint32 aNativeLength,
124 : bool aExpandToClusterBoundaries);
125 : // Find the first textframe for the range, and get the start offset in
126 : // the frame.
127 : nsresult GetStartFrameAndOffset(nsRange* aRange,
128 : nsIFrame** aFrame,
129 : PRInt32* aOffsetInFrame);
130 : // Convert the frame relative offset to the root view relative offset.
131 : nsresult ConvertToRootViewRelativeOffset(nsIFrame* aFrame,
132 : nsRect& aRect);
133 : // Expand aXPOffset to the nearest offset in cluster boundary. aForward is
134 : // true, it is expanded to forward.
135 : nsresult ExpandToClusterBoundary(nsIContent* aContent, bool aForward,
136 : PRUint32* aXPOffset);
137 : };
138 :
139 : #endif // nsContentEventHandler_h__
|