1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/dom/events/ContentEventHandler.h Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,130 @@ 1.4 +/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ 1.5 +/* This Source Code Form is subject to the terms of the Mozilla Public 1.6 + * License, v. 2.0. If a copy of the MPL was not distributed with this 1.7 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ 1.8 + 1.9 +#ifndef mozilla_ContentEventHandler_h_ 1.10 +#define mozilla_ContentEventHandler_h_ 1.11 + 1.12 +#include "mozilla/EventForwards.h" 1.13 +#include "nsCOMPtr.h" 1.14 +#include "nsISelection.h" 1.15 +#include "nsRange.h" 1.16 + 1.17 +class nsPresContext; 1.18 + 1.19 +struct nsRect; 1.20 + 1.21 +namespace mozilla { 1.22 + 1.23 +enum LineBreakType 1.24 +{ 1.25 + LINE_BREAK_TYPE_NATIVE, 1.26 + LINE_BREAK_TYPE_XP 1.27 +}; 1.28 + 1.29 +/* 1.30 + * Query Content Event Handler 1.31 + * ContentEventHandler is a helper class for EventStateManager. 1.32 + * The platforms request some content informations, e.g., the selected text, 1.33 + * the offset of the selected text and the text for specified range. 1.34 + * This class answers to NS_QUERY_* events from actual contents. 1.35 + */ 1.36 + 1.37 +class MOZ_STACK_CLASS ContentEventHandler 1.38 +{ 1.39 +public: 1.40 + ContentEventHandler(nsPresContext* aPresContext); 1.41 + 1.42 + // NS_QUERY_SELECTED_TEXT event handler 1.43 + nsresult OnQuerySelectedText(WidgetQueryContentEvent* aEvent); 1.44 + // NS_QUERY_TEXT_CONTENT event handler 1.45 + nsresult OnQueryTextContent(WidgetQueryContentEvent* aEvent); 1.46 + // NS_QUERY_CARET_RECT event handler 1.47 + nsresult OnQueryCaretRect(WidgetQueryContentEvent* aEvent); 1.48 + // NS_QUERY_TEXT_RECT event handler 1.49 + nsresult OnQueryTextRect(WidgetQueryContentEvent* aEvent); 1.50 + // NS_QUERY_EDITOR_RECT event handler 1.51 + nsresult OnQueryEditorRect(WidgetQueryContentEvent* aEvent); 1.52 + // NS_QUERY_CONTENT_STATE event handler 1.53 + nsresult OnQueryContentState(WidgetQueryContentEvent* aEvent); 1.54 + // NS_QUERY_SELECTION_AS_TRANSFERABLE event handler 1.55 + nsresult OnQuerySelectionAsTransferable(WidgetQueryContentEvent* aEvent); 1.56 + // NS_QUERY_CHARACTER_AT_POINT event handler 1.57 + nsresult OnQueryCharacterAtPoint(WidgetQueryContentEvent* aEvent); 1.58 + // NS_QUERY_DOM_WIDGET_HITTEST event handler 1.59 + nsresult OnQueryDOMWidgetHittest(WidgetQueryContentEvent* aEvent); 1.60 + 1.61 + // NS_SELECTION_* event 1.62 + nsresult OnSelectionEvent(WidgetSelectionEvent* aEvent); 1.63 + 1.64 +protected: 1.65 + nsPresContext* mPresContext; 1.66 + nsCOMPtr<nsIPresShell> mPresShell; 1.67 + nsCOMPtr<nsISelection> mSelection; 1.68 + nsRefPtr<nsRange> mFirstSelectedRange; 1.69 + nsCOMPtr<nsIContent> mRootContent; 1.70 + 1.71 + nsresult Init(WidgetQueryContentEvent* aEvent); 1.72 + nsresult Init(WidgetSelectionEvent* aEvent); 1.73 + 1.74 + nsresult InitBasic(); 1.75 + nsresult InitCommon(); 1.76 + 1.77 +public: 1.78 + // FlatText means the text that is generated from DOM tree. The BR elements 1.79 + // are replaced to native linefeeds. Other elements are ignored. 1.80 + 1.81 + // Get the offset in FlatText of the range. (also used by IMEContentObserver) 1.82 + static nsresult GetFlatTextOffsetOfRange(nsIContent* aRootContent, 1.83 + nsINode* aNode, 1.84 + int32_t aNodeOffset, 1.85 + uint32_t* aOffset, 1.86 + LineBreakType aLineBreakType); 1.87 + static nsresult GetFlatTextOffsetOfRange(nsIContent* aRootContent, 1.88 + nsRange* aRange, 1.89 + uint32_t* aOffset, 1.90 + LineBreakType aLineBreakType); 1.91 + // Get the native text length of a content node excluding any children 1.92 + static uint32_t GetNativeTextLength(nsIContent* aContent, 1.93 + uint32_t aMaxLength = UINT32_MAX); 1.94 +protected: 1.95 + static uint32_t GetTextLength(nsIContent* aContent, 1.96 + LineBreakType aLineBreakType, 1.97 + uint32_t aMaxLength = UINT32_MAX); 1.98 + static LineBreakType GetLineBreakType(WidgetQueryContentEvent* aEvent); 1.99 + static LineBreakType GetLineBreakType(WidgetSelectionEvent* aEvent); 1.100 + static LineBreakType GetLineBreakType(bool aUseNativeLineBreak); 1.101 + // Returns focused content (including its descendant documents). 1.102 + nsIContent* GetFocusedContent(); 1.103 + // Returns true if the content is a plugin host. 1.104 + bool IsPlugin(nsIContent* aContent); 1.105 + // QueryContentRect() sets the rect of aContent's frame(s) to aEvent. 1.106 + nsresult QueryContentRect(nsIContent* aContent, 1.107 + WidgetQueryContentEvent* aEvent); 1.108 + // Make the DOM range from the offset of FlatText and the text length. 1.109 + // If aExpandToClusterBoundaries is true, the start offset and the end one are 1.110 + // expanded to nearest cluster boundaries. 1.111 + nsresult SetRangeFromFlatTextOffset(nsRange* aRange, 1.112 + uint32_t aOffset, 1.113 + uint32_t aLength, 1.114 + LineBreakType aLineBreakType, 1.115 + bool aExpandToClusterBoundaries, 1.116 + uint32_t* aNewOffset = nullptr); 1.117 + // Find the first textframe for the range, and get the start offset in 1.118 + // the frame. 1.119 + nsresult GetStartFrameAndOffset(nsRange* aRange, 1.120 + nsIFrame** aFrame, 1.121 + int32_t* aOffsetInFrame); 1.122 + // Convert the frame relative offset to the root view relative offset. 1.123 + nsresult ConvertToRootViewRelativeOffset(nsIFrame* aFrame, 1.124 + nsRect& aRect); 1.125 + // Expand aXPOffset to the nearest offset in cluster boundary. aForward is 1.126 + // true, it is expanded to forward. 1.127 + nsresult ExpandToClusterBoundary(nsIContent* aContent, bool aForward, 1.128 + uint32_t* aXPOffset); 1.129 +}; 1.130 + 1.131 +} // namespace mozilla 1.132 + 1.133 +#endif // mozilla_ContentEventHandler_h_