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