1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/layout/generic/nsFrameSelection.h Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,723 @@ 1.4 +/* This Source Code Form is subject to the terms of the Mozilla Public 1.5 + * License, v. 2.0. If a copy of the MPL was not distributed with this 1.6 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ 1.7 + 1.8 +#ifndef nsFrameSelection_h___ 1.9 +#define nsFrameSelection_h___ 1.10 + 1.11 +#include "mozilla/Attributes.h" 1.12 +#include "mozilla/EventForwards.h" 1.13 +#include "mozilla/dom/Selection.h" 1.14 +#include "mozilla/TextRange.h" 1.15 +#include "nsIFrame.h" 1.16 +#include "nsIContent.h" 1.17 +#include "nsISelectionController.h" 1.18 +#include "nsITableCellLayout.h" 1.19 +#include "nsIDOMElement.h" 1.20 +#include "nsRange.h" 1.21 + 1.22 +class nsTableOuterFrame; 1.23 + 1.24 +// IID for the nsFrameSelection interface 1.25 +// 3c6ae2d0-4cf1-44a1-9e9d-2411867f19c6 1.26 +#define NS_FRAME_SELECTION_IID \ 1.27 +{ 0x3c6ae2d0, 0x4cf1, 0x44a1, \ 1.28 + { 0x9e, 0x9d, 0x24, 0x11, 0x86, 0x7f, 0x19, 0xc6 } } 1.29 + 1.30 +#define BIDI_LEVEL_UNDEFINED 0x80 1.31 + 1.32 +//---------------------------------------------------------------------- 1.33 + 1.34 +// Selection interface 1.35 + 1.36 +struct SelectionDetails 1.37 +{ 1.38 +#ifdef NS_BUILD_REFCNT_LOGGING 1.39 + SelectionDetails() { 1.40 + MOZ_COUNT_CTOR(SelectionDetails); 1.41 + } 1.42 + ~SelectionDetails() { 1.43 + MOZ_COUNT_DTOR(SelectionDetails); 1.44 + } 1.45 +#endif 1.46 + int32_t mStart; 1.47 + int32_t mEnd; 1.48 + SelectionType mType; 1.49 + mozilla::TextRangeStyle mTextRangeStyle; 1.50 + SelectionDetails *mNext; 1.51 +}; 1.52 + 1.53 +class nsIPresShell; 1.54 +class nsIScrollableFrame; 1.55 + 1.56 +enum EWordMovementType { eStartWord, eEndWord, eDefaultBehavior }; 1.57 + 1.58 +/** PeekOffsetStruct is used to group various arguments (both input and output) 1.59 + * that are passed to nsFrame::PeekOffset(). See below for the description of 1.60 + * individual arguments. 1.61 + */ 1.62 +struct MOZ_STACK_CLASS nsPeekOffsetStruct 1.63 +{ 1.64 + nsPeekOffsetStruct(nsSelectionAmount aAmount, 1.65 + nsDirection aDirection, 1.66 + int32_t aStartOffset, 1.67 + nscoord aDesiredX, 1.68 + bool aJumpLines, 1.69 + bool aScrollViewStop, 1.70 + bool aIsKeyboardSelect, 1.71 + bool aVisual, 1.72 + EWordMovementType aWordMovementType = eDefaultBehavior) 1.73 + : mAmount(aAmount) 1.74 + , mDirection(aDirection) 1.75 + , mStartOffset(aStartOffset) 1.76 + , mDesiredX(aDesiredX) 1.77 + , mWordMovementType(aWordMovementType) 1.78 + , mJumpLines(aJumpLines) 1.79 + , mScrollViewStop(aScrollViewStop) 1.80 + , mIsKeyboardSelect(aIsKeyboardSelect) 1.81 + , mVisual(aVisual) 1.82 + , mResultContent() 1.83 + , mResultFrame(nullptr) 1.84 + , mContentOffset(0) 1.85 + , mAttachForward(false) 1.86 + { 1.87 + } 1.88 + 1.89 + // Note: Most arguments (input and output) are only used with certain values 1.90 + // of mAmount. These values are indicated for each argument below. 1.91 + // Arguments with no such indication are used with all values of mAmount. 1.92 + 1.93 + /*** Input arguments ***/ 1.94 + // Note: The value of some of the input arguments may be changed upon exit. 1.95 + 1.96 + // mAmount: The type of movement requested (by character, word, line, etc.) 1.97 + nsSelectionAmount mAmount; 1.98 + 1.99 + // mDirection: eDirPrevious or eDirNext. 1.100 + // * Note for visual bidi movement: 1.101 + // eDirPrevious means 'left-then-up' if the containing block is LTR, 1.102 + // 'right-then-up' if it is RTL. 1.103 + // eDirNext means 'right-then-down' if the containing block is LTR, 1.104 + // 'left-then-down' if it is RTL. 1.105 + // Between paragraphs, eDirPrevious means "go to the visual end of the 1.106 + // previous paragraph", and eDirNext means "go to the visual beginning 1.107 + // of the next paragraph". 1.108 + // Used with: eSelectCharacter, eSelectWord, eSelectLine, eSelectParagraph. 1.109 + nsDirection mDirection; 1.110 + 1.111 + // mStartOffset: Offset into the content of the current frame where the peek starts. 1.112 + // Used with: eSelectCharacter, eSelectWord 1.113 + int32_t mStartOffset; 1.114 + 1.115 + // mDesiredX: The desired x coordinate for the caret. 1.116 + // Used with: eSelectLine. 1.117 + nscoord mDesiredX; 1.118 + 1.119 + // mWordMovementType: An enum that determines whether to prefer the start or end of a word 1.120 + // or to use the default beahvior, which is a combination of 1.121 + // direction and the platform-based pref 1.122 + // "layout.word_select.eat_space_to_next_word" 1.123 + EWordMovementType mWordMovementType; 1.124 + 1.125 + // mJumpLines: Whether to allow jumping across line boundaries. 1.126 + // Used with: eSelectCharacter, eSelectWord. 1.127 + bool mJumpLines; 1.128 + 1.129 + // mScrollViewStop: Whether to stop when reaching a scroll view boundary. 1.130 + // Used with: eSelectCharacter, eSelectWord, eSelectLine. 1.131 + bool mScrollViewStop; 1.132 + 1.133 + // mIsKeyboardSelect: Whether the peeking is done in response to a keyboard action. 1.134 + // Used with: eSelectWord. 1.135 + bool mIsKeyboardSelect; 1.136 + 1.137 + // mVisual: Whether bidi caret behavior is visual (true) or logical (false). 1.138 + // Used with: eSelectCharacter, eSelectWord, eSelectBeginLine, eSelectEndLine. 1.139 + bool mVisual; 1.140 + 1.141 + /*** Output arguments ***/ 1.142 + 1.143 + // mResultContent: Content reached as a result of the peek. 1.144 + nsCOMPtr<nsIContent> mResultContent; 1.145 + 1.146 + // mResultFrame: Frame reached as a result of the peek. 1.147 + // Used with: eSelectCharacter, eSelectWord. 1.148 + nsIFrame *mResultFrame; 1.149 + 1.150 + // mContentOffset: Offset into content reached as a result of the peek. 1.151 + int32_t mContentOffset; 1.152 + 1.153 + // mAttachForward: When the result position is between two frames, 1.154 + // indicates which of the two frames the caret should be painted in. 1.155 + // false means "the end of the frame logically before the caret", 1.156 + // true means "the beginning of the frame logically after the caret". 1.157 + // Used with: eSelectLine, eSelectBeginLine, eSelectEndLine. 1.158 + bool mAttachForward; 1.159 +}; 1.160 + 1.161 +struct nsPrevNextBidiLevels 1.162 +{ 1.163 + void SetData(nsIFrame* aFrameBefore, 1.164 + nsIFrame* aFrameAfter, 1.165 + uint8_t aLevelBefore, 1.166 + uint8_t aLevelAfter) 1.167 + { 1.168 + mFrameBefore = aFrameBefore; 1.169 + mFrameAfter = aFrameAfter; 1.170 + mLevelBefore = aLevelBefore; 1.171 + mLevelAfter = aLevelAfter; 1.172 + } 1.173 + nsIFrame* mFrameBefore; 1.174 + nsIFrame* mFrameAfter; 1.175 + uint8_t mLevelBefore; 1.176 + uint8_t mLevelAfter; 1.177 +}; 1.178 + 1.179 +namespace mozilla { 1.180 +namespace dom { 1.181 +class Selection; 1.182 +} 1.183 +} 1.184 +class nsIScrollableFrame; 1.185 + 1.186 +/** 1.187 + * Methods which are marked with *unsafe* should be handled with special care. 1.188 + * They may cause nsFrameSelection to be deleted, if strong pointer isn't used, 1.189 + * or they may cause other objects to be deleted. 1.190 + */ 1.191 + 1.192 +class nsFrameSelection MOZ_FINAL { 1.193 +public: 1.194 + enum HINT { HINTLEFT = 0, HINTRIGHT = 1}; //end of this line or beginning of next 1.195 + /*interfaces for addref and release and queryinterface*/ 1.196 + 1.197 + NS_INLINE_DECL_CYCLE_COLLECTING_NATIVE_REFCOUNTING(nsFrameSelection) 1.198 + NS_DECL_CYCLE_COLLECTION_NATIVE_CLASS(nsFrameSelection) 1.199 + 1.200 + /** Init will initialize the frame selector with the necessary pres shell to 1.201 + * be used by most of the methods 1.202 + * @param aShell is the parameter to be used for most of the other calls for callbacks etc 1.203 + * @param aLimiter limits the selection to nodes with aLimiter parents 1.204 + */ 1.205 + void Init(nsIPresShell *aShell, nsIContent *aLimiter); 1.206 + 1.207 + /** HandleClick will take the focus to the new frame at the new offset and 1.208 + * will either extend the selection from the old anchor, or replace the old anchor. 1.209 + * the old anchor and focus position may also be used to deselect things 1.210 + * @param aNewfocus is the content that wants the focus 1.211 + * @param aContentOffset is the content offset of the parent aNewFocus 1.212 + * @param aContentOffsetEnd is the content offset of the parent aNewFocus and is specified different 1.213 + * when you need to select to and include both start and end points 1.214 + * @param aContinueSelection is the flag that tells the selection to keep the old anchor point or not. 1.215 + * @param aMultipleSelection will tell the frame selector to replace /or not the old selection. 1.216 + * cannot coexist with aContinueSelection 1.217 + * @param aHint will tell the selection which direction geometrically to actually show the caret on. 1.218 + * 1 = end of this line 0 = beginning of this line 1.219 + */ 1.220 + /*unsafe*/ 1.221 + nsresult HandleClick(nsIContent *aNewFocus, 1.222 + uint32_t aContentOffset, 1.223 + uint32_t aContentEndOffset, 1.224 + bool aContinueSelection, 1.225 + bool aMultipleSelection, 1.226 + bool aHint); 1.227 + 1.228 + /** HandleDrag extends the selection to contain the frame closest to aPoint. 1.229 + * @param aPresContext is the context to use when figuring out what frame contains the point. 1.230 + * @param aFrame is the parent of all frames to use when searching for the closest frame to the point. 1.231 + * @param aPoint is relative to aFrame 1.232 + */ 1.233 + /*unsafe*/ 1.234 + void HandleDrag(nsIFrame *aFrame, nsPoint aPoint); 1.235 + 1.236 + /** HandleTableSelection will set selection to a table, cell, etc 1.237 + * depending on information contained in aFlags 1.238 + * @param aParentContent is the paretent of either a table or cell that user clicked or dragged the mouse in 1.239 + * @param aContentOffset is the offset of the table or cell 1.240 + * @param aTarget indicates what to select (defined in nsISelectionPrivate.idl/nsISelectionPrivate.h): 1.241 + * TABLESELECTION_CELL We should select a cell (content points to the cell) 1.242 + * TABLESELECTION_ROW We should select a row (content points to any cell in row) 1.243 + * TABLESELECTION_COLUMN We should select a row (content points to any cell in column) 1.244 + * TABLESELECTION_TABLE We should select a table (content points to the table) 1.245 + * TABLESELECTION_ALLCELLS We should select all cells (content points to any cell in table) 1.246 + * @param aMouseEvent passed in so we can get where event occurred and what keys are pressed 1.247 + */ 1.248 + /*unsafe*/ 1.249 + nsresult HandleTableSelection(nsINode* aParentContent, 1.250 + int32_t aContentOffset, 1.251 + int32_t aTarget, 1.252 + mozilla::WidgetMouseEvent* aMouseEvent); 1.253 + 1.254 + /** 1.255 + * Add cell to the selection. 1.256 + * 1.257 + * @param aCell [in] HTML td element. 1.258 + */ 1.259 + virtual nsresult SelectCellElement(nsIContent *aCell); 1.260 + 1.261 + /** 1.262 + * Add cells to the selection inside of the given cells range. 1.263 + * 1.264 + * @param aTable [in] HTML table element 1.265 + * @param aStartRowIndex [in] row index where the cells range starts 1.266 + * @param aStartColumnIndex [in] column index where the cells range starts 1.267 + * @param aEndRowIndex [in] row index where the cells range ends 1.268 + * @param aEndColumnIndex [in] column index where the cells range ends 1.269 + */ 1.270 + virtual nsresult AddCellsToSelection(nsIContent *aTable, 1.271 + int32_t aStartRowIndex, 1.272 + int32_t aStartColumnIndex, 1.273 + int32_t aEndRowIndex, 1.274 + int32_t aEndColumnIndex); 1.275 + 1.276 + /** 1.277 + * Remove cells from selection inside of the given cell range. 1.278 + * 1.279 + * @param aTable [in] HTML table element 1.280 + * @param aStartRowIndex [in] row index where the cells range starts 1.281 + * @param aStartColumnIndex [in] column index where the cells range starts 1.282 + * @param aEndRowIndex [in] row index where the cells range ends 1.283 + * @param aEndColumnIndex [in] column index where the cells range ends 1.284 + */ 1.285 + virtual nsresult RemoveCellsFromSelection(nsIContent *aTable, 1.286 + int32_t aStartRowIndex, 1.287 + int32_t aStartColumnIndex, 1.288 + int32_t aEndRowIndex, 1.289 + int32_t aEndColumnIndex); 1.290 + 1.291 + /** 1.292 + * Remove cells from selection outside of the given cell range. 1.293 + * 1.294 + * @param aTable [in] HTML table element 1.295 + * @param aStartRowIndex [in] row index where the cells range starts 1.296 + * @param aStartColumnIndex [in] column index where the cells range starts 1.297 + * @param aEndRowIndex [in] row index where the cells range ends 1.298 + * @param aEndColumnIndex [in] column index where the cells range ends 1.299 + */ 1.300 + virtual nsresult RestrictCellsToSelection(nsIContent *aTable, 1.301 + int32_t aStartRowIndex, 1.302 + int32_t aStartColumnIndex, 1.303 + int32_t aEndRowIndex, 1.304 + int32_t aEndColumnIndex); 1.305 + 1.306 + /** StartAutoScrollTimer is responsible for scrolling frames so that 1.307 + * aPoint is always visible, and for selecting any frame that contains 1.308 + * aPoint. The timer will also reset itself to fire again if we have 1.309 + * not scrolled to the end of the document. 1.310 + * @param aFrame is the outermost frame to use when searching for 1.311 + * the closest frame for the point, i.e. the frame that is capturing 1.312 + * the mouse 1.313 + * @param aPoint is relative to aFrame. 1.314 + * @param aDelay is the timer's interval. 1.315 + */ 1.316 + /*unsafe*/ 1.317 + nsresult StartAutoScrollTimer(nsIFrame *aFrame, 1.318 + nsPoint aPoint, 1.319 + uint32_t aDelay); 1.320 + 1.321 + /** StopAutoScrollTimer stops any active auto scroll timer. 1.322 + */ 1.323 + void StopAutoScrollTimer(); 1.324 + 1.325 + /** Lookup Selection 1.326 + * returns in frame coordinates the selection beginning and ending with the type of selection given 1.327 + * @param aContent is the content asking 1.328 + * @param aContentOffset is the starting content boundary 1.329 + * @param aContentLength is the length of the content piece asking 1.330 + * @param aReturnDetails linkedlist of return values for the selection. 1.331 + * @param aSlowCheck will check using slow method with no shortcuts 1.332 + */ 1.333 + SelectionDetails* LookUpSelection(nsIContent *aContent, 1.334 + int32_t aContentOffset, 1.335 + int32_t aContentLength, 1.336 + bool aSlowCheck) const; 1.337 + 1.338 + /** SetMouseDownState(bool); 1.339 + * sets the mouse state to aState for resons of drag state. 1.340 + * @param aState is the new state of mousedown 1.341 + */ 1.342 + /*unsafe*/ 1.343 + void SetMouseDownState(bool aState); 1.344 + 1.345 + /** GetMouseDownState(bool *); 1.346 + * gets the mouse state to aState for resons of drag state. 1.347 + * @param aState will hold the state of mousedown 1.348 + */ 1.349 + bool GetMouseDownState() const { return mMouseDownState; } 1.350 + 1.351 + /** 1.352 + if we are in table cell selection mode. aka ctrl click in table cell 1.353 + */ 1.354 + bool GetTableCellSelection() const { return mSelectingTableCellMode != 0; } 1.355 + void ClearTableCellSelection() { mSelectingTableCellMode = 0; } 1.356 + 1.357 + /** GetSelection 1.358 + * no query interface for selection. must use this method now. 1.359 + * @param aSelectionType enum value defined in nsISelection for the seleciton you want. 1.360 + */ 1.361 + mozilla::dom::Selection* GetSelection(SelectionType aType) const; 1.362 + 1.363 + /** 1.364 + * ScrollSelectionIntoView scrolls a region of the selection, 1.365 + * so that it is visible in the scrolled view. 1.366 + * 1.367 + * @param aType the selection to scroll into view. 1.368 + * @param aRegion the region inside the selection to scroll into view. 1.369 + * @param aFlags the scroll flags. Valid bits include: 1.370 + * SCROLL_SYNCHRONOUS: when set, scrolls the selection into view 1.371 + * before returning. If not set, posts a request which is processed 1.372 + * at some point after the method returns. 1.373 + * SCROLL_FIRST_ANCESTOR_ONLY: if set, only the first ancestor will be scrolled 1.374 + * into view. 1.375 + */ 1.376 + /*unsafe*/ 1.377 + nsresult ScrollSelectionIntoView(SelectionType aType, 1.378 + SelectionRegion aRegion, 1.379 + int16_t aFlags) const; 1.380 + 1.381 + /** RepaintSelection repaints the selected frames that are inside the selection 1.382 + * specified by aSelectionType. 1.383 + * @param aSelectionType enum value defined in nsISelection for the seleciton you want. 1.384 + */ 1.385 + nsresult RepaintSelection(SelectionType aType) const; 1.386 + 1.387 + /** GetFrameForNodeOffset given a node and its child offset, return the nsIFrame and 1.388 + * the offset into that frame. 1.389 + * @param aNode input parameter for the node to look at 1.390 + * @param aOffset offset into above node. 1.391 + * @param aReturnOffset will contain offset into frame. 1.392 + */ 1.393 + virtual nsIFrame* GetFrameForNodeOffset(nsIContent *aNode, 1.394 + int32_t aOffset, 1.395 + HINT aHint, 1.396 + int32_t *aReturnOffset) const; 1.397 + 1.398 + /** 1.399 + * Scrolling then moving caret placement code in common to text areas and 1.400 + * content areas should be located in the implementer 1.401 + * This method will accept the following parameters and perform the scroll 1.402 + * and caret movement. It remains for the caller to call the final 1.403 + * ScrollCaretIntoView if that called wants to be sure the caret is always 1.404 + * visible. 1.405 + * 1.406 + * @param aForward if true, scroll forward if not scroll backward 1.407 + * @param aExtend if true, extend selection to the new point 1.408 + * @param aScrollableFrame the frame to scroll 1.409 + */ 1.410 + /*unsafe*/ 1.411 + void CommonPageMove(bool aForward, 1.412 + bool aExtend, 1.413 + nsIScrollableFrame* aScrollableFrame); 1.414 + 1.415 + void SetHint(HINT aHintRight) { mHint = aHintRight; } 1.416 + HINT GetHint() const { return mHint; } 1.417 + 1.418 + /** SetCaretBidiLevel sets the caret bidi level 1.419 + * @param aLevel the caret bidi level 1.420 + * This method is virtual since it gets called from outside of layout. 1.421 + */ 1.422 + virtual void SetCaretBidiLevel (uint8_t aLevel); 1.423 + /** GetCaretBidiLevel gets the caret bidi level 1.424 + * This method is virtual since it gets called from outside of layout. 1.425 + */ 1.426 + virtual uint8_t GetCaretBidiLevel() const; 1.427 + /** UndefineCaretBidiLevel sets the caret bidi level to "undefined" 1.428 + * This method is virtual since it gets called from outside of layout. 1.429 + */ 1.430 + virtual void UndefineCaretBidiLevel(); 1.431 + 1.432 + /** CharacterMove will generally be called from the nsiselectioncontroller implementations. 1.433 + * the effect being the selection will move one character left or right. 1.434 + * @param aForward move forward in document. 1.435 + * @param aExtend continue selection 1.436 + */ 1.437 + /*unsafe*/ 1.438 + nsresult CharacterMove(bool aForward, bool aExtend); 1.439 + 1.440 + /** CharacterExtendForDelete extends the selection forward (logically) to 1.441 + * the next character cell, so that the selected cell can be deleted. 1.442 + */ 1.443 + /*unsafe*/ 1.444 + nsresult CharacterExtendForDelete(); 1.445 + 1.446 + /** CharacterExtendForBackspace extends the selection backward (logically) to 1.447 + * the previous character cell, so that the selected cell can be deleted. 1.448 + */ 1.449 + /*unsafe*/ 1.450 + nsresult CharacterExtendForBackspace(); 1.451 + 1.452 + /** WordMove will generally be called from the nsiselectioncontroller implementations. 1.453 + * the effect being the selection will move one word left or right. 1.454 + * @param aForward move forward in document. 1.455 + * @param aExtend continue selection 1.456 + */ 1.457 + /*unsafe*/ 1.458 + nsresult WordMove(bool aForward, bool aExtend); 1.459 + 1.460 + /** WordExtendForDelete extends the selection backward or forward (logically) to the 1.461 + * next word boundary, so that the selected word can be deleted. 1.462 + * @param aForward select forward in document. 1.463 + */ 1.464 + /*unsafe*/ 1.465 + nsresult WordExtendForDelete(bool aForward); 1.466 + 1.467 + /** LineMove will generally be called from the nsiselectioncontroller implementations. 1.468 + * the effect being the selection will move one line up or down. 1.469 + * @param aForward move forward in document. 1.470 + * @param aExtend continue selection 1.471 + */ 1.472 + /*unsafe*/ 1.473 + nsresult LineMove(bool aForward, bool aExtend); 1.474 + 1.475 + /** IntraLineMove will generally be called from the nsiselectioncontroller implementations. 1.476 + * the effect being the selection will move to beginning or end of line 1.477 + * @param aForward move forward in document. 1.478 + * @param aExtend continue selection 1.479 + */ 1.480 + /*unsafe*/ 1.481 + nsresult IntraLineMove(bool aForward, bool aExtend); 1.482 + 1.483 + /** Select All will generally be called from the nsiselectioncontroller implementations. 1.484 + * it will select the whole doc 1.485 + */ 1.486 + /*unsafe*/ 1.487 + nsresult SelectAll(); 1.488 + 1.489 + /** Sets/Gets The display selection enum. 1.490 + */ 1.491 + void SetDisplaySelection(int16_t aState) { mDisplaySelection = aState; } 1.492 + int16_t GetDisplaySelection() const { return mDisplaySelection; } 1.493 + 1.494 + /** This method can be used to store the data received during a MouseDown 1.495 + * event so that we can place the caret during the MouseUp event. 1.496 + * @aMouseEvent the event received by the selection MouseDown 1.497 + * handling method. A nullptr value can be use to tell this method 1.498 + * that any data is storing is no longer valid. 1.499 + */ 1.500 + void SetDelayedCaretData(mozilla::WidgetMouseEvent* aMouseEvent); 1.501 + 1.502 + /** Get the delayed MouseDown event data necessary to place the 1.503 + * caret during MouseUp processing. 1.504 + * @return a pointer to the event received 1.505 + * by the selection during MouseDown processing. It can be nullptr 1.506 + * if the data is no longer valid. 1.507 + */ 1.508 + bool HasDelayedCaretData() { return mDelayedMouseEventValid; } 1.509 + bool IsShiftDownInDelayedCaretData() 1.510 + { 1.511 + NS_ASSERTION(mDelayedMouseEventValid, "No valid delayed caret data"); 1.512 + return mDelayedMouseEventIsShift; 1.513 + } 1.514 + uint32_t GetClickCountInDelayedCaretData() 1.515 + { 1.516 + NS_ASSERTION(mDelayedMouseEventValid, "No valid delayed caret data"); 1.517 + return mDelayedMouseEventClickCount; 1.518 + } 1.519 + 1.520 + /** Get the content node that limits the selection 1.521 + * When searching up a nodes for parents, as in a text edit field 1.522 + * in an browser page, we must stop at this node else we reach into the 1.523 + * parent page, which is very bad! 1.524 + */ 1.525 + nsIContent* GetLimiter() const { return mLimiter; } 1.526 + 1.527 + nsIContent* GetAncestorLimiter() const { return mAncestorLimiter; } 1.528 + /*unsafe*/ 1.529 + void SetAncestorLimiter(nsIContent *aLimiter); 1.530 + 1.531 + /** This will tell the frame selection that a double click has been pressed 1.532 + * so it can track abort future drags if inside the same selection 1.533 + * @aDoubleDown has the double click down happened 1.534 + */ 1.535 + void SetMouseDoubleDown(bool aDoubleDown) { mMouseDoubleDownState = aDoubleDown; } 1.536 + 1.537 + /** This will return whether the double down flag was set. 1.538 + * @return whether the double down flag was set 1.539 + */ 1.540 + bool GetMouseDoubleDown() const { return mMouseDoubleDownState; } 1.541 + 1.542 + /** GetPrevNextBidiLevels will return the frames and associated Bidi levels of the characters 1.543 + * logically before and after a (collapsed) selection. 1.544 + * @param aNode is the node containing the selection 1.545 + * @param aContentOffset is the offset of the selection in the node 1.546 + * @param aJumpLines If true, look across line boundaries. 1.547 + * If false, behave as if there were base-level frames at line edges. 1.548 + * 1.549 + * @return A struct holding the before/after frame and the before/after level. 1.550 + * 1.551 + * At the beginning and end of each line there is assumed to be a frame with 1.552 + * Bidi level equal to the paragraph embedding level. 1.553 + * In these cases the before frame and after frame respectively will be 1.554 + * nullptr. 1.555 + * 1.556 + * This method is virtual since it gets called from outside of layout. 1.557 + */ 1.558 + virtual nsPrevNextBidiLevels GetPrevNextBidiLevels(nsIContent *aNode, 1.559 + uint32_t aContentOffset, 1.560 + bool aJumpLines) const; 1.561 + 1.562 + /** GetFrameFromLevel will scan in a given direction 1.563 + * until it finds a frame with a Bidi level less than or equal to a given level. 1.564 + * It will return the last frame before this. 1.565 + * @param aPresContext is the context to use 1.566 + * @param aFrameIn is the frame to start from 1.567 + * @param aDirection is the direction to scan 1.568 + * @param aBidiLevel is the level to search for 1.569 + * @param aFrameOut will hold the frame returned 1.570 + */ 1.571 + nsresult GetFrameFromLevel(nsIFrame *aFrameIn, 1.572 + nsDirection aDirection, 1.573 + uint8_t aBidiLevel, 1.574 + nsIFrame **aFrameOut) const; 1.575 + 1.576 + /** 1.577 + * MaintainSelection will track the current selection as being "sticky". 1.578 + * Dragging or extending selection will never allow for a subset 1.579 + * (or the whole) of the maintained selection to become unselected. 1.580 + * Primary use: double click selecting then dragging on second click 1.581 + * @param aAmount the initial amount of text selected (word, line or paragraph). 1.582 + * For "line", use eSelectBeginLine. 1.583 + */ 1.584 + nsresult MaintainSelection(nsSelectionAmount aAmount = eSelectNoAmount); 1.585 + 1.586 + nsFrameSelection(); 1.587 + 1.588 + void StartBatchChanges(); 1.589 + void EndBatchChanges(); 1.590 + /*unsafe*/ 1.591 + nsresult DeleteFromDocument(); 1.592 + 1.593 + nsIPresShell *GetShell()const { return mShell; } 1.594 + 1.595 + void DisconnectFromPresShell(); 1.596 + nsresult ClearNormalSelection(); 1.597 +private: 1.598 + nsresult TakeFocus(nsIContent *aNewFocus, 1.599 + uint32_t aContentOffset, 1.600 + uint32_t aContentEndOffset, 1.601 + HINT aHint, 1.602 + bool aContinueSelection, 1.603 + bool aMultipleSelection); 1.604 + 1.605 + void BidiLevelFromMove(nsIPresShell* aPresShell, 1.606 + nsIContent *aNode, 1.607 + uint32_t aContentOffset, 1.608 + uint32_t aKeycode, 1.609 + HINT aHint); 1.610 + void BidiLevelFromClick(nsIContent *aNewFocus, uint32_t aContentOffset); 1.611 + nsPrevNextBidiLevels GetPrevNextBidiLevels(nsIContent *aNode, 1.612 + uint32_t aContentOffset, 1.613 + HINT aHint, 1.614 + bool aJumpLines) const; 1.615 + 1.616 + bool AdjustForMaintainedSelection(nsIContent *aContent, int32_t aOffset); 1.617 + 1.618 +// post and pop reasons for notifications. we may stack these later 1.619 + void PostReason(int16_t aReason) { mSelectionChangeReason = aReason; } 1.620 + int16_t PopReason() 1.621 + { 1.622 + int16_t retval = mSelectionChangeReason; 1.623 + mSelectionChangeReason = 0; 1.624 + return retval; 1.625 + } 1.626 + 1.627 + friend class mozilla::dom::Selection; 1.628 +#ifdef DEBUG 1.629 + void printSelection(); // for debugging 1.630 +#endif /* DEBUG */ 1.631 + 1.632 + void ResizeBuffer(uint32_t aNewBufSize); 1.633 +/*HELPER METHODS*/ 1.634 + nsresult MoveCaret(uint32_t aKeycode, bool aContinueSelection, 1.635 + nsSelectionAmount aAmount); 1.636 + nsresult MoveCaret(uint32_t aKeycode, bool aContinueSelection, 1.637 + nsSelectionAmount aAmount, 1.638 + bool aVisualMovement); 1.639 + 1.640 + nsresult FetchDesiredX(nscoord &aDesiredX); //the x position requested by the Key Handling for up down 1.641 + void InvalidateDesiredX(); //do not listen to mDesiredX you must get another. 1.642 + void SetDesiredX(nscoord aX); //set the mDesiredX 1.643 + 1.644 + nsresult ConstrainFrameAndPointToAnchorSubtree(nsIFrame *aFrame, nsPoint& aPoint, nsIFrame **aRetFrame, nsPoint& aRetPoint); 1.645 + 1.646 + uint32_t GetBatching() const {return mBatching; } 1.647 + bool GetNotifyFrames() const { return mNotifyFrames; } 1.648 + void SetDirty(bool aDirty=true){if (mBatching) mChangesDuringBatching = aDirty;} 1.649 + 1.650 + // nsFrameSelection may get deleted when calling this, 1.651 + // so remember to use nsCOMPtr when needed. 1.652 + nsresult NotifySelectionListeners(SelectionType aType); // add parameters to say collapsed etc? 1.653 + 1.654 + nsRefPtr<mozilla::dom::Selection> mDomSelections[nsISelectionController::NUM_SELECTIONTYPES]; 1.655 + 1.656 + // Table selection support. 1.657 + nsITableCellLayout* GetCellLayout(nsIContent *aCellContent) const; 1.658 + 1.659 + nsresult SelectBlockOfCells(nsIContent *aStartNode, nsIContent *aEndNode); 1.660 + nsresult SelectRowOrColumn(nsIContent *aCellContent, uint32_t aTarget); 1.661 + nsresult UnselectCells(nsIContent *aTable, 1.662 + int32_t aStartRowIndex, int32_t aStartColumnIndex, 1.663 + int32_t aEndRowIndex, int32_t aEndColumnIndex, 1.664 + bool aRemoveOutsideOfCellRange); 1.665 + 1.666 + nsresult GetCellIndexes(nsIContent *aCell, int32_t &aRowIndex, int32_t &aColIndex); 1.667 + 1.668 + // Get our first range, if its first selected node is a cell. If this does 1.669 + // not return null, then the first node in the returned range is a cell 1.670 + // (according to GetFirstCellNodeInRange). 1.671 + nsRange* GetFirstCellRange(); 1.672 + // Get our next range, if its first selected node is a cell. If this does 1.673 + // not return null, then the first node in the returned range is a cell 1.674 + // (according to GetFirstCellNodeInRange). 1.675 + nsRange* GetNextCellRange(); 1.676 + nsIContent* GetFirstCellNodeInRange(nsRange *aRange) const; 1.677 + // Returns non-null table if in same table, null otherwise 1.678 + nsIContent* IsInSameTable(nsIContent *aContent1, nsIContent *aContent2) const; 1.679 + // Might return null 1.680 + nsIContent* GetParentTable(nsIContent *aCellNode) const; 1.681 + nsresult CreateAndAddRange(nsINode *aParentNode, int32_t aOffset); 1.682 + 1.683 + nsCOMPtr<nsINode> mCellParent; //used to snap to table selection 1.684 + nsCOMPtr<nsIContent> mStartSelectedCell; 1.685 + nsCOMPtr<nsIContent> mEndSelectedCell; 1.686 + nsCOMPtr<nsIContent> mAppendStartSelectedCell; 1.687 + nsCOMPtr<nsIContent> mUnselectCellOnMouseUp; 1.688 + int32_t mSelectingTableCellMode; 1.689 + int32_t mSelectedCellIndex; 1.690 + 1.691 + // maintain selection 1.692 + nsRefPtr<nsRange> mMaintainRange; 1.693 + nsSelectionAmount mMaintainedAmount; 1.694 + 1.695 + //batching 1.696 + int32_t mBatching; 1.697 + 1.698 + // Limit selection navigation to a child of this node. 1.699 + nsCOMPtr<nsIContent> mLimiter; 1.700 + // Limit selection navigation to a descendant of this node. 1.701 + nsCOMPtr<nsIContent> mAncestorLimiter; 1.702 + 1.703 + nsIPresShell *mShell; 1.704 + 1.705 + int16_t mSelectionChangeReason; // reason for notifications of selection changing 1.706 + int16_t mDisplaySelection; //for visual display purposes. 1.707 + 1.708 + HINT mHint; //hint to tell if the selection is at the end of this line or beginning of next 1.709 + uint8_t mCaretBidiLevel; 1.710 + 1.711 + int32_t mDesiredX; 1.712 + uint32_t mDelayedMouseEventClickCount; 1.713 + bool mDelayedMouseEventIsShift; 1.714 + bool mDelayedMouseEventValid; 1.715 + 1.716 + bool mChangesDuringBatching; 1.717 + bool mNotifyFrames; 1.718 + bool mDragSelectingCells; 1.719 + bool mMouseDownState; //for drag purposes 1.720 + bool mMouseDoubleDownState; //has the doubleclick down happened 1.721 + bool mDesiredXSet; 1.722 + 1.723 + int8_t mCaretMovementStyle; 1.724 +}; 1.725 + 1.726 +#endif /* nsFrameSelection_h___ */