Thu, 22 Jan 2015 13:21:57 +0100
Incorporate requested changes from Mozilla in review:
https://bugzilla.mozilla.org/show_bug.cgi?id=1123480#c6
1 /* This Source Code Form is subject to the terms of the Mozilla Public
2 * License, v. 2.0. If a copy of the MPL was not distributed with this
3 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
5 #ifndef nsFrameSelection_h___
6 #define nsFrameSelection_h___
8 #include "mozilla/Attributes.h"
9 #include "mozilla/EventForwards.h"
10 #include "mozilla/dom/Selection.h"
11 #include "mozilla/TextRange.h"
12 #include "nsIFrame.h"
13 #include "nsIContent.h"
14 #include "nsISelectionController.h"
15 #include "nsITableCellLayout.h"
16 #include "nsIDOMElement.h"
17 #include "nsRange.h"
19 class nsTableOuterFrame;
21 // IID for the nsFrameSelection interface
22 // 3c6ae2d0-4cf1-44a1-9e9d-2411867f19c6
23 #define NS_FRAME_SELECTION_IID \
24 { 0x3c6ae2d0, 0x4cf1, 0x44a1, \
25 { 0x9e, 0x9d, 0x24, 0x11, 0x86, 0x7f, 0x19, 0xc6 } }
27 #define BIDI_LEVEL_UNDEFINED 0x80
29 //----------------------------------------------------------------------
31 // Selection interface
33 struct SelectionDetails
34 {
35 #ifdef NS_BUILD_REFCNT_LOGGING
36 SelectionDetails() {
37 MOZ_COUNT_CTOR(SelectionDetails);
38 }
39 ~SelectionDetails() {
40 MOZ_COUNT_DTOR(SelectionDetails);
41 }
42 #endif
43 int32_t mStart;
44 int32_t mEnd;
45 SelectionType mType;
46 mozilla::TextRangeStyle mTextRangeStyle;
47 SelectionDetails *mNext;
48 };
50 class nsIPresShell;
51 class nsIScrollableFrame;
53 enum EWordMovementType { eStartWord, eEndWord, eDefaultBehavior };
55 /** PeekOffsetStruct is used to group various arguments (both input and output)
56 * that are passed to nsFrame::PeekOffset(). See below for the description of
57 * individual arguments.
58 */
59 struct MOZ_STACK_CLASS nsPeekOffsetStruct
60 {
61 nsPeekOffsetStruct(nsSelectionAmount aAmount,
62 nsDirection aDirection,
63 int32_t aStartOffset,
64 nscoord aDesiredX,
65 bool aJumpLines,
66 bool aScrollViewStop,
67 bool aIsKeyboardSelect,
68 bool aVisual,
69 EWordMovementType aWordMovementType = eDefaultBehavior)
70 : mAmount(aAmount)
71 , mDirection(aDirection)
72 , mStartOffset(aStartOffset)
73 , mDesiredX(aDesiredX)
74 , mWordMovementType(aWordMovementType)
75 , mJumpLines(aJumpLines)
76 , mScrollViewStop(aScrollViewStop)
77 , mIsKeyboardSelect(aIsKeyboardSelect)
78 , mVisual(aVisual)
79 , mResultContent()
80 , mResultFrame(nullptr)
81 , mContentOffset(0)
82 , mAttachForward(false)
83 {
84 }
86 // Note: Most arguments (input and output) are only used with certain values
87 // of mAmount. These values are indicated for each argument below.
88 // Arguments with no such indication are used with all values of mAmount.
90 /*** Input arguments ***/
91 // Note: The value of some of the input arguments may be changed upon exit.
93 // mAmount: The type of movement requested (by character, word, line, etc.)
94 nsSelectionAmount mAmount;
96 // mDirection: eDirPrevious or eDirNext.
97 // * Note for visual bidi movement:
98 // eDirPrevious means 'left-then-up' if the containing block is LTR,
99 // 'right-then-up' if it is RTL.
100 // eDirNext means 'right-then-down' if the containing block is LTR,
101 // 'left-then-down' if it is RTL.
102 // Between paragraphs, eDirPrevious means "go to the visual end of the
103 // previous paragraph", and eDirNext means "go to the visual beginning
104 // of the next paragraph".
105 // Used with: eSelectCharacter, eSelectWord, eSelectLine, eSelectParagraph.
106 nsDirection mDirection;
108 // mStartOffset: Offset into the content of the current frame where the peek starts.
109 // Used with: eSelectCharacter, eSelectWord
110 int32_t mStartOffset;
112 // mDesiredX: The desired x coordinate for the caret.
113 // Used with: eSelectLine.
114 nscoord mDesiredX;
116 // mWordMovementType: An enum that determines whether to prefer the start or end of a word
117 // or to use the default beahvior, which is a combination of
118 // direction and the platform-based pref
119 // "layout.word_select.eat_space_to_next_word"
120 EWordMovementType mWordMovementType;
122 // mJumpLines: Whether to allow jumping across line boundaries.
123 // Used with: eSelectCharacter, eSelectWord.
124 bool mJumpLines;
126 // mScrollViewStop: Whether to stop when reaching a scroll view boundary.
127 // Used with: eSelectCharacter, eSelectWord, eSelectLine.
128 bool mScrollViewStop;
130 // mIsKeyboardSelect: Whether the peeking is done in response to a keyboard action.
131 // Used with: eSelectWord.
132 bool mIsKeyboardSelect;
134 // mVisual: Whether bidi caret behavior is visual (true) or logical (false).
135 // Used with: eSelectCharacter, eSelectWord, eSelectBeginLine, eSelectEndLine.
136 bool mVisual;
138 /*** Output arguments ***/
140 // mResultContent: Content reached as a result of the peek.
141 nsCOMPtr<nsIContent> mResultContent;
143 // mResultFrame: Frame reached as a result of the peek.
144 // Used with: eSelectCharacter, eSelectWord.
145 nsIFrame *mResultFrame;
147 // mContentOffset: Offset into content reached as a result of the peek.
148 int32_t mContentOffset;
150 // mAttachForward: When the result position is between two frames,
151 // indicates which of the two frames the caret should be painted in.
152 // false means "the end of the frame logically before the caret",
153 // true means "the beginning of the frame logically after the caret".
154 // Used with: eSelectLine, eSelectBeginLine, eSelectEndLine.
155 bool mAttachForward;
156 };
158 struct nsPrevNextBidiLevels
159 {
160 void SetData(nsIFrame* aFrameBefore,
161 nsIFrame* aFrameAfter,
162 uint8_t aLevelBefore,
163 uint8_t aLevelAfter)
164 {
165 mFrameBefore = aFrameBefore;
166 mFrameAfter = aFrameAfter;
167 mLevelBefore = aLevelBefore;
168 mLevelAfter = aLevelAfter;
169 }
170 nsIFrame* mFrameBefore;
171 nsIFrame* mFrameAfter;
172 uint8_t mLevelBefore;
173 uint8_t mLevelAfter;
174 };
176 namespace mozilla {
177 namespace dom {
178 class Selection;
179 }
180 }
181 class nsIScrollableFrame;
183 /**
184 * Methods which are marked with *unsafe* should be handled with special care.
185 * They may cause nsFrameSelection to be deleted, if strong pointer isn't used,
186 * or they may cause other objects to be deleted.
187 */
189 class nsFrameSelection MOZ_FINAL {
190 public:
191 enum HINT { HINTLEFT = 0, HINTRIGHT = 1}; //end of this line or beginning of next
192 /*interfaces for addref and release and queryinterface*/
194 NS_INLINE_DECL_CYCLE_COLLECTING_NATIVE_REFCOUNTING(nsFrameSelection)
195 NS_DECL_CYCLE_COLLECTION_NATIVE_CLASS(nsFrameSelection)
197 /** Init will initialize the frame selector with the necessary pres shell to
198 * be used by most of the methods
199 * @param aShell is the parameter to be used for most of the other calls for callbacks etc
200 * @param aLimiter limits the selection to nodes with aLimiter parents
201 */
202 void Init(nsIPresShell *aShell, nsIContent *aLimiter);
204 /** HandleClick will take the focus to the new frame at the new offset and
205 * will either extend the selection from the old anchor, or replace the old anchor.
206 * the old anchor and focus position may also be used to deselect things
207 * @param aNewfocus is the content that wants the focus
208 * @param aContentOffset is the content offset of the parent aNewFocus
209 * @param aContentOffsetEnd is the content offset of the parent aNewFocus and is specified different
210 * when you need to select to and include both start and end points
211 * @param aContinueSelection is the flag that tells the selection to keep the old anchor point or not.
212 * @param aMultipleSelection will tell the frame selector to replace /or not the old selection.
213 * cannot coexist with aContinueSelection
214 * @param aHint will tell the selection which direction geometrically to actually show the caret on.
215 * 1 = end of this line 0 = beginning of this line
216 */
217 /*unsafe*/
218 nsresult HandleClick(nsIContent *aNewFocus,
219 uint32_t aContentOffset,
220 uint32_t aContentEndOffset,
221 bool aContinueSelection,
222 bool aMultipleSelection,
223 bool aHint);
225 /** HandleDrag extends the selection to contain the frame closest to aPoint.
226 * @param aPresContext is the context to use when figuring out what frame contains the point.
227 * @param aFrame is the parent of all frames to use when searching for the closest frame to the point.
228 * @param aPoint is relative to aFrame
229 */
230 /*unsafe*/
231 void HandleDrag(nsIFrame *aFrame, nsPoint aPoint);
233 /** HandleTableSelection will set selection to a table, cell, etc
234 * depending on information contained in aFlags
235 * @param aParentContent is the paretent of either a table or cell that user clicked or dragged the mouse in
236 * @param aContentOffset is the offset of the table or cell
237 * @param aTarget indicates what to select (defined in nsISelectionPrivate.idl/nsISelectionPrivate.h):
238 * TABLESELECTION_CELL We should select a cell (content points to the cell)
239 * TABLESELECTION_ROW We should select a row (content points to any cell in row)
240 * TABLESELECTION_COLUMN We should select a row (content points to any cell in column)
241 * TABLESELECTION_TABLE We should select a table (content points to the table)
242 * TABLESELECTION_ALLCELLS We should select all cells (content points to any cell in table)
243 * @param aMouseEvent passed in so we can get where event occurred and what keys are pressed
244 */
245 /*unsafe*/
246 nsresult HandleTableSelection(nsINode* aParentContent,
247 int32_t aContentOffset,
248 int32_t aTarget,
249 mozilla::WidgetMouseEvent* aMouseEvent);
251 /**
252 * Add cell to the selection.
253 *
254 * @param aCell [in] HTML td element.
255 */
256 virtual nsresult SelectCellElement(nsIContent *aCell);
258 /**
259 * Add cells to the selection inside of the given cells range.
260 *
261 * @param aTable [in] HTML table element
262 * @param aStartRowIndex [in] row index where the cells range starts
263 * @param aStartColumnIndex [in] column index where the cells range starts
264 * @param aEndRowIndex [in] row index where the cells range ends
265 * @param aEndColumnIndex [in] column index where the cells range ends
266 */
267 virtual nsresult AddCellsToSelection(nsIContent *aTable,
268 int32_t aStartRowIndex,
269 int32_t aStartColumnIndex,
270 int32_t aEndRowIndex,
271 int32_t aEndColumnIndex);
273 /**
274 * Remove cells from selection inside of the given cell range.
275 *
276 * @param aTable [in] HTML table element
277 * @param aStartRowIndex [in] row index where the cells range starts
278 * @param aStartColumnIndex [in] column index where the cells range starts
279 * @param aEndRowIndex [in] row index where the cells range ends
280 * @param aEndColumnIndex [in] column index where the cells range ends
281 */
282 virtual nsresult RemoveCellsFromSelection(nsIContent *aTable,
283 int32_t aStartRowIndex,
284 int32_t aStartColumnIndex,
285 int32_t aEndRowIndex,
286 int32_t aEndColumnIndex);
288 /**
289 * Remove cells from selection outside of the given cell range.
290 *
291 * @param aTable [in] HTML table element
292 * @param aStartRowIndex [in] row index where the cells range starts
293 * @param aStartColumnIndex [in] column index where the cells range starts
294 * @param aEndRowIndex [in] row index where the cells range ends
295 * @param aEndColumnIndex [in] column index where the cells range ends
296 */
297 virtual nsresult RestrictCellsToSelection(nsIContent *aTable,
298 int32_t aStartRowIndex,
299 int32_t aStartColumnIndex,
300 int32_t aEndRowIndex,
301 int32_t aEndColumnIndex);
303 /** StartAutoScrollTimer is responsible for scrolling frames so that
304 * aPoint is always visible, and for selecting any frame that contains
305 * aPoint. The timer will also reset itself to fire again if we have
306 * not scrolled to the end of the document.
307 * @param aFrame is the outermost frame to use when searching for
308 * the closest frame for the point, i.e. the frame that is capturing
309 * the mouse
310 * @param aPoint is relative to aFrame.
311 * @param aDelay is the timer's interval.
312 */
313 /*unsafe*/
314 nsresult StartAutoScrollTimer(nsIFrame *aFrame,
315 nsPoint aPoint,
316 uint32_t aDelay);
318 /** StopAutoScrollTimer stops any active auto scroll timer.
319 */
320 void StopAutoScrollTimer();
322 /** Lookup Selection
323 * returns in frame coordinates the selection beginning and ending with the type of selection given
324 * @param aContent is the content asking
325 * @param aContentOffset is the starting content boundary
326 * @param aContentLength is the length of the content piece asking
327 * @param aReturnDetails linkedlist of return values for the selection.
328 * @param aSlowCheck will check using slow method with no shortcuts
329 */
330 SelectionDetails* LookUpSelection(nsIContent *aContent,
331 int32_t aContentOffset,
332 int32_t aContentLength,
333 bool aSlowCheck) const;
335 /** SetMouseDownState(bool);
336 * sets the mouse state to aState for resons of drag state.
337 * @param aState is the new state of mousedown
338 */
339 /*unsafe*/
340 void SetMouseDownState(bool aState);
342 /** GetMouseDownState(bool *);
343 * gets the mouse state to aState for resons of drag state.
344 * @param aState will hold the state of mousedown
345 */
346 bool GetMouseDownState() const { return mMouseDownState; }
348 /**
349 if we are in table cell selection mode. aka ctrl click in table cell
350 */
351 bool GetTableCellSelection() const { return mSelectingTableCellMode != 0; }
352 void ClearTableCellSelection() { mSelectingTableCellMode = 0; }
354 /** GetSelection
355 * no query interface for selection. must use this method now.
356 * @param aSelectionType enum value defined in nsISelection for the seleciton you want.
357 */
358 mozilla::dom::Selection* GetSelection(SelectionType aType) const;
360 /**
361 * ScrollSelectionIntoView scrolls a region of the selection,
362 * so that it is visible in the scrolled view.
363 *
364 * @param aType the selection to scroll into view.
365 * @param aRegion the region inside the selection to scroll into view.
366 * @param aFlags the scroll flags. Valid bits include:
367 * SCROLL_SYNCHRONOUS: when set, scrolls the selection into view
368 * before returning. If not set, posts a request which is processed
369 * at some point after the method returns.
370 * SCROLL_FIRST_ANCESTOR_ONLY: if set, only the first ancestor will be scrolled
371 * into view.
372 */
373 /*unsafe*/
374 nsresult ScrollSelectionIntoView(SelectionType aType,
375 SelectionRegion aRegion,
376 int16_t aFlags) const;
378 /** RepaintSelection repaints the selected frames that are inside the selection
379 * specified by aSelectionType.
380 * @param aSelectionType enum value defined in nsISelection for the seleciton you want.
381 */
382 nsresult RepaintSelection(SelectionType aType) const;
384 /** GetFrameForNodeOffset given a node and its child offset, return the nsIFrame and
385 * the offset into that frame.
386 * @param aNode input parameter for the node to look at
387 * @param aOffset offset into above node.
388 * @param aReturnOffset will contain offset into frame.
389 */
390 virtual nsIFrame* GetFrameForNodeOffset(nsIContent *aNode,
391 int32_t aOffset,
392 HINT aHint,
393 int32_t *aReturnOffset) const;
395 /**
396 * Scrolling then moving caret placement code in common to text areas and
397 * content areas should be located in the implementer
398 * This method will accept the following parameters and perform the scroll
399 * and caret movement. It remains for the caller to call the final
400 * ScrollCaretIntoView if that called wants to be sure the caret is always
401 * visible.
402 *
403 * @param aForward if true, scroll forward if not scroll backward
404 * @param aExtend if true, extend selection to the new point
405 * @param aScrollableFrame the frame to scroll
406 */
407 /*unsafe*/
408 void CommonPageMove(bool aForward,
409 bool aExtend,
410 nsIScrollableFrame* aScrollableFrame);
412 void SetHint(HINT aHintRight) { mHint = aHintRight; }
413 HINT GetHint() const { return mHint; }
415 /** SetCaretBidiLevel sets the caret bidi level
416 * @param aLevel the caret bidi level
417 * This method is virtual since it gets called from outside of layout.
418 */
419 virtual void SetCaretBidiLevel (uint8_t aLevel);
420 /** GetCaretBidiLevel gets the caret bidi level
421 * This method is virtual since it gets called from outside of layout.
422 */
423 virtual uint8_t GetCaretBidiLevel() const;
424 /** UndefineCaretBidiLevel sets the caret bidi level to "undefined"
425 * This method is virtual since it gets called from outside of layout.
426 */
427 virtual void UndefineCaretBidiLevel();
429 /** CharacterMove will generally be called from the nsiselectioncontroller implementations.
430 * the effect being the selection will move one character left or right.
431 * @param aForward move forward in document.
432 * @param aExtend continue selection
433 */
434 /*unsafe*/
435 nsresult CharacterMove(bool aForward, bool aExtend);
437 /** CharacterExtendForDelete extends the selection forward (logically) to
438 * the next character cell, so that the selected cell can be deleted.
439 */
440 /*unsafe*/
441 nsresult CharacterExtendForDelete();
443 /** CharacterExtendForBackspace extends the selection backward (logically) to
444 * the previous character cell, so that the selected cell can be deleted.
445 */
446 /*unsafe*/
447 nsresult CharacterExtendForBackspace();
449 /** WordMove will generally be called from the nsiselectioncontroller implementations.
450 * the effect being the selection will move one word left or right.
451 * @param aForward move forward in document.
452 * @param aExtend continue selection
453 */
454 /*unsafe*/
455 nsresult WordMove(bool aForward, bool aExtend);
457 /** WordExtendForDelete extends the selection backward or forward (logically) to the
458 * next word boundary, so that the selected word can be deleted.
459 * @param aForward select forward in document.
460 */
461 /*unsafe*/
462 nsresult WordExtendForDelete(bool aForward);
464 /** LineMove will generally be called from the nsiselectioncontroller implementations.
465 * the effect being the selection will move one line up or down.
466 * @param aForward move forward in document.
467 * @param aExtend continue selection
468 */
469 /*unsafe*/
470 nsresult LineMove(bool aForward, bool aExtend);
472 /** IntraLineMove will generally be called from the nsiselectioncontroller implementations.
473 * the effect being the selection will move to beginning or end of line
474 * @param aForward move forward in document.
475 * @param aExtend continue selection
476 */
477 /*unsafe*/
478 nsresult IntraLineMove(bool aForward, bool aExtend);
480 /** Select All will generally be called from the nsiselectioncontroller implementations.
481 * it will select the whole doc
482 */
483 /*unsafe*/
484 nsresult SelectAll();
486 /** Sets/Gets The display selection enum.
487 */
488 void SetDisplaySelection(int16_t aState) { mDisplaySelection = aState; }
489 int16_t GetDisplaySelection() const { return mDisplaySelection; }
491 /** This method can be used to store the data received during a MouseDown
492 * event so that we can place the caret during the MouseUp event.
493 * @aMouseEvent the event received by the selection MouseDown
494 * handling method. A nullptr value can be use to tell this method
495 * that any data is storing is no longer valid.
496 */
497 void SetDelayedCaretData(mozilla::WidgetMouseEvent* aMouseEvent);
499 /** Get the delayed MouseDown event data necessary to place the
500 * caret during MouseUp processing.
501 * @return a pointer to the event received
502 * by the selection during MouseDown processing. It can be nullptr
503 * if the data is no longer valid.
504 */
505 bool HasDelayedCaretData() { return mDelayedMouseEventValid; }
506 bool IsShiftDownInDelayedCaretData()
507 {
508 NS_ASSERTION(mDelayedMouseEventValid, "No valid delayed caret data");
509 return mDelayedMouseEventIsShift;
510 }
511 uint32_t GetClickCountInDelayedCaretData()
512 {
513 NS_ASSERTION(mDelayedMouseEventValid, "No valid delayed caret data");
514 return mDelayedMouseEventClickCount;
515 }
517 /** Get the content node that limits the selection
518 * When searching up a nodes for parents, as in a text edit field
519 * in an browser page, we must stop at this node else we reach into the
520 * parent page, which is very bad!
521 */
522 nsIContent* GetLimiter() const { return mLimiter; }
524 nsIContent* GetAncestorLimiter() const { return mAncestorLimiter; }
525 /*unsafe*/
526 void SetAncestorLimiter(nsIContent *aLimiter);
528 /** This will tell the frame selection that a double click has been pressed
529 * so it can track abort future drags if inside the same selection
530 * @aDoubleDown has the double click down happened
531 */
532 void SetMouseDoubleDown(bool aDoubleDown) { mMouseDoubleDownState = aDoubleDown; }
534 /** This will return whether the double down flag was set.
535 * @return whether the double down flag was set
536 */
537 bool GetMouseDoubleDown() const { return mMouseDoubleDownState; }
539 /** GetPrevNextBidiLevels will return the frames and associated Bidi levels of the characters
540 * logically before and after a (collapsed) selection.
541 * @param aNode is the node containing the selection
542 * @param aContentOffset is the offset of the selection in the node
543 * @param aJumpLines If true, look across line boundaries.
544 * If false, behave as if there were base-level frames at line edges.
545 *
546 * @return A struct holding the before/after frame and the before/after level.
547 *
548 * At the beginning and end of each line there is assumed to be a frame with
549 * Bidi level equal to the paragraph embedding level.
550 * In these cases the before frame and after frame respectively will be
551 * nullptr.
552 *
553 * This method is virtual since it gets called from outside of layout.
554 */
555 virtual nsPrevNextBidiLevels GetPrevNextBidiLevels(nsIContent *aNode,
556 uint32_t aContentOffset,
557 bool aJumpLines) const;
559 /** GetFrameFromLevel will scan in a given direction
560 * until it finds a frame with a Bidi level less than or equal to a given level.
561 * It will return the last frame before this.
562 * @param aPresContext is the context to use
563 * @param aFrameIn is the frame to start from
564 * @param aDirection is the direction to scan
565 * @param aBidiLevel is the level to search for
566 * @param aFrameOut will hold the frame returned
567 */
568 nsresult GetFrameFromLevel(nsIFrame *aFrameIn,
569 nsDirection aDirection,
570 uint8_t aBidiLevel,
571 nsIFrame **aFrameOut) const;
573 /**
574 * MaintainSelection will track the current selection as being "sticky".
575 * Dragging or extending selection will never allow for a subset
576 * (or the whole) of the maintained selection to become unselected.
577 * Primary use: double click selecting then dragging on second click
578 * @param aAmount the initial amount of text selected (word, line or paragraph).
579 * For "line", use eSelectBeginLine.
580 */
581 nsresult MaintainSelection(nsSelectionAmount aAmount = eSelectNoAmount);
583 nsFrameSelection();
585 void StartBatchChanges();
586 void EndBatchChanges();
587 /*unsafe*/
588 nsresult DeleteFromDocument();
590 nsIPresShell *GetShell()const { return mShell; }
592 void DisconnectFromPresShell();
593 nsresult ClearNormalSelection();
594 private:
595 nsresult TakeFocus(nsIContent *aNewFocus,
596 uint32_t aContentOffset,
597 uint32_t aContentEndOffset,
598 HINT aHint,
599 bool aContinueSelection,
600 bool aMultipleSelection);
602 void BidiLevelFromMove(nsIPresShell* aPresShell,
603 nsIContent *aNode,
604 uint32_t aContentOffset,
605 uint32_t aKeycode,
606 HINT aHint);
607 void BidiLevelFromClick(nsIContent *aNewFocus, uint32_t aContentOffset);
608 nsPrevNextBidiLevels GetPrevNextBidiLevels(nsIContent *aNode,
609 uint32_t aContentOffset,
610 HINT aHint,
611 bool aJumpLines) const;
613 bool AdjustForMaintainedSelection(nsIContent *aContent, int32_t aOffset);
615 // post and pop reasons for notifications. we may stack these later
616 void PostReason(int16_t aReason) { mSelectionChangeReason = aReason; }
617 int16_t PopReason()
618 {
619 int16_t retval = mSelectionChangeReason;
620 mSelectionChangeReason = 0;
621 return retval;
622 }
624 friend class mozilla::dom::Selection;
625 #ifdef DEBUG
626 void printSelection(); // for debugging
627 #endif /* DEBUG */
629 void ResizeBuffer(uint32_t aNewBufSize);
630 /*HELPER METHODS*/
631 nsresult MoveCaret(uint32_t aKeycode, bool aContinueSelection,
632 nsSelectionAmount aAmount);
633 nsresult MoveCaret(uint32_t aKeycode, bool aContinueSelection,
634 nsSelectionAmount aAmount,
635 bool aVisualMovement);
637 nsresult FetchDesiredX(nscoord &aDesiredX); //the x position requested by the Key Handling for up down
638 void InvalidateDesiredX(); //do not listen to mDesiredX you must get another.
639 void SetDesiredX(nscoord aX); //set the mDesiredX
641 nsresult ConstrainFrameAndPointToAnchorSubtree(nsIFrame *aFrame, nsPoint& aPoint, nsIFrame **aRetFrame, nsPoint& aRetPoint);
643 uint32_t GetBatching() const {return mBatching; }
644 bool GetNotifyFrames() const { return mNotifyFrames; }
645 void SetDirty(bool aDirty=true){if (mBatching) mChangesDuringBatching = aDirty;}
647 // nsFrameSelection may get deleted when calling this,
648 // so remember to use nsCOMPtr when needed.
649 nsresult NotifySelectionListeners(SelectionType aType); // add parameters to say collapsed etc?
651 nsRefPtr<mozilla::dom::Selection> mDomSelections[nsISelectionController::NUM_SELECTIONTYPES];
653 // Table selection support.
654 nsITableCellLayout* GetCellLayout(nsIContent *aCellContent) const;
656 nsresult SelectBlockOfCells(nsIContent *aStartNode, nsIContent *aEndNode);
657 nsresult SelectRowOrColumn(nsIContent *aCellContent, uint32_t aTarget);
658 nsresult UnselectCells(nsIContent *aTable,
659 int32_t aStartRowIndex, int32_t aStartColumnIndex,
660 int32_t aEndRowIndex, int32_t aEndColumnIndex,
661 bool aRemoveOutsideOfCellRange);
663 nsresult GetCellIndexes(nsIContent *aCell, int32_t &aRowIndex, int32_t &aColIndex);
665 // Get our first range, if its first selected node is a cell. If this does
666 // not return null, then the first node in the returned range is a cell
667 // (according to GetFirstCellNodeInRange).
668 nsRange* GetFirstCellRange();
669 // Get our next range, if its first selected node is a cell. If this does
670 // not return null, then the first node in the returned range is a cell
671 // (according to GetFirstCellNodeInRange).
672 nsRange* GetNextCellRange();
673 nsIContent* GetFirstCellNodeInRange(nsRange *aRange) const;
674 // Returns non-null table if in same table, null otherwise
675 nsIContent* IsInSameTable(nsIContent *aContent1, nsIContent *aContent2) const;
676 // Might return null
677 nsIContent* GetParentTable(nsIContent *aCellNode) const;
678 nsresult CreateAndAddRange(nsINode *aParentNode, int32_t aOffset);
680 nsCOMPtr<nsINode> mCellParent; //used to snap to table selection
681 nsCOMPtr<nsIContent> mStartSelectedCell;
682 nsCOMPtr<nsIContent> mEndSelectedCell;
683 nsCOMPtr<nsIContent> mAppendStartSelectedCell;
684 nsCOMPtr<nsIContent> mUnselectCellOnMouseUp;
685 int32_t mSelectingTableCellMode;
686 int32_t mSelectedCellIndex;
688 // maintain selection
689 nsRefPtr<nsRange> mMaintainRange;
690 nsSelectionAmount mMaintainedAmount;
692 //batching
693 int32_t mBatching;
695 // Limit selection navigation to a child of this node.
696 nsCOMPtr<nsIContent> mLimiter;
697 // Limit selection navigation to a descendant of this node.
698 nsCOMPtr<nsIContent> mAncestorLimiter;
700 nsIPresShell *mShell;
702 int16_t mSelectionChangeReason; // reason for notifications of selection changing
703 int16_t mDisplaySelection; //for visual display purposes.
705 HINT mHint; //hint to tell if the selection is at the end of this line or beginning of next
706 uint8_t mCaretBidiLevel;
708 int32_t mDesiredX;
709 uint32_t mDelayedMouseEventClickCount;
710 bool mDelayedMouseEventIsShift;
711 bool mDelayedMouseEventValid;
713 bool mChangesDuringBatching;
714 bool mNotifyFrames;
715 bool mDragSelectingCells;
716 bool mMouseDownState; //for drag purposes
717 bool mMouseDoubleDownState; //has the doubleclick down happened
718 bool mDesiredXSet;
720 int8_t mCaretMovementStyle;
721 };
723 #endif /* nsFrameSelection_h___ */