dom/events/ContentEventHandler.h

Tue, 06 Jan 2015 21:39:09 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Tue, 06 Jan 2015 21:39:09 +0100
branch
TOR_BUG_9701
changeset 8
97036ab72558
permissions
-rw-r--r--

Conditionally force memory storage according to privacy.thirdparty.isolate;
This solves Tor bug #9701, complying with disk avoidance documented in
https://www.torproject.org/projects/torbrowser/design/#disk-avoidance.

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

mercurial