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 | /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ |
michael@0 | 2 | /* This Source Code Form is subject to the terms of the Mozilla Public |
michael@0 | 3 | * License, v. 2.0. If a copy of the MPL was not distributed with this |
michael@0 | 4 | * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ |
michael@0 | 5 | #ifndef nsILineIterator_h___ |
michael@0 | 6 | #define nsILineIterator_h___ |
michael@0 | 7 | |
michael@0 | 8 | #include "nscore.h" |
michael@0 | 9 | #include "nsCoord.h" |
michael@0 | 10 | |
michael@0 | 11 | class nsIFrame; |
michael@0 | 12 | struct nsRect; |
michael@0 | 13 | |
michael@0 | 14 | // Line Flags (see GetLine below) |
michael@0 | 15 | |
michael@0 | 16 | // This bit is set when the line is wrapping up a block frame. When |
michael@0 | 17 | // clear, it means that the line contains inline elements. |
michael@0 | 18 | #define NS_LINE_FLAG_IS_BLOCK 0x1 |
michael@0 | 19 | |
michael@0 | 20 | // This bit is set when the line ends in some sort of break. |
michael@0 | 21 | #define NS_LINE_FLAG_ENDS_IN_BREAK 0x4 |
michael@0 | 22 | |
michael@0 | 23 | /** |
michael@0 | 24 | * Line iterator API. |
michael@0 | 25 | * |
michael@0 | 26 | * Lines are numbered from 0 to N, where 0 is the top line and N is |
michael@0 | 27 | * the bottom line. |
michael@0 | 28 | * |
michael@0 | 29 | * Obtain this interface from frames via nsIFrame::GetLineIterator. |
michael@0 | 30 | * When you are finished using the iterator, call DisposeLineIterator() |
michael@0 | 31 | * to destroy the iterator if appropriate. |
michael@0 | 32 | */ |
michael@0 | 33 | class nsILineIterator |
michael@0 | 34 | { |
michael@0 | 35 | protected: |
michael@0 | 36 | ~nsILineIterator() { } |
michael@0 | 37 | |
michael@0 | 38 | public: |
michael@0 | 39 | virtual void DisposeLineIterator() = 0; |
michael@0 | 40 | |
michael@0 | 41 | /** |
michael@0 | 42 | * The number of lines in the block |
michael@0 | 43 | */ |
michael@0 | 44 | virtual int32_t GetNumLines() = 0; |
michael@0 | 45 | |
michael@0 | 46 | /** |
michael@0 | 47 | * The prevailing direction of lines. |
michael@0 | 48 | * |
michael@0 | 49 | * @return true if the CSS direction property for the block is |
michael@0 | 50 | * "rtl", otherwise false |
michael@0 | 51 | */ |
michael@0 | 52 | virtual bool GetDirection() = 0; |
michael@0 | 53 | |
michael@0 | 54 | // Return structural information about a line. aFirstFrameOnLine is |
michael@0 | 55 | // the first frame on the line and aNumFramesOnLine is the number of |
michael@0 | 56 | // frames that are on the line. If the line-number is invalid then |
michael@0 | 57 | // aFirstFrameOnLine will be nullptr and aNumFramesOnLine will be |
michael@0 | 58 | // zero. |
michael@0 | 59 | // |
michael@0 | 60 | // For valid line numbers, aLineBounds is set to the bounding box of |
michael@0 | 61 | // the line (which is based on the in-flow position of the frames on |
michael@0 | 62 | // the line; if a frame was moved because of relative positioning |
michael@0 | 63 | // then its coordinates may be outside the line bounds). |
michael@0 | 64 | // |
michael@0 | 65 | // In addition, aLineFlags will contain flag information about the |
michael@0 | 66 | // line. |
michael@0 | 67 | NS_IMETHOD GetLine(int32_t aLineNumber, |
michael@0 | 68 | nsIFrame** aFirstFrameOnLine, |
michael@0 | 69 | int32_t* aNumFramesOnLine, |
michael@0 | 70 | nsRect& aLineBounds, |
michael@0 | 71 | uint32_t* aLineFlags) = 0; |
michael@0 | 72 | |
michael@0 | 73 | /** |
michael@0 | 74 | * Given a frame that's a child of the block, find which line its on |
michael@0 | 75 | * and return that line index, as long as it's at least as big as |
michael@0 | 76 | * aStartLine. Returns -1 if the frame cannot be found on lines |
michael@0 | 77 | * starting with aStartLine. |
michael@0 | 78 | */ |
michael@0 | 79 | virtual int32_t FindLineContaining(nsIFrame* aFrame, |
michael@0 | 80 | int32_t aStartLine = 0) = 0; |
michael@0 | 81 | |
michael@0 | 82 | // Given a line number and an X coordinate, find the frame on the |
michael@0 | 83 | // line that is nearest to the X coordinate. The |
michael@0 | 84 | // aXIsBeforeFirstFrame and aXIsAfterLastFrame flags are updated |
michael@0 | 85 | // appropriately. |
michael@0 | 86 | NS_IMETHOD FindFrameAt(int32_t aLineNumber, |
michael@0 | 87 | nscoord aX, |
michael@0 | 88 | nsIFrame** aFrameFound, |
michael@0 | 89 | bool* aXIsBeforeFirstFrame, |
michael@0 | 90 | bool* aXIsAfterLastFrame) = 0; |
michael@0 | 91 | |
michael@0 | 92 | // Give the line iterator implementor a chance todo something more complicated than |
michael@0 | 93 | // nsIFrame::GetNextSibling() |
michael@0 | 94 | NS_IMETHOD GetNextSiblingOnLine(nsIFrame*& aFrame, int32_t aLineNumber) = 0; |
michael@0 | 95 | |
michael@0 | 96 | // Check whether visual and logical order of frames within a line are identical. |
michael@0 | 97 | // If not, return the first and last visual frames |
michael@0 | 98 | NS_IMETHOD CheckLineOrder(int32_t aLine, |
michael@0 | 99 | bool *aIsReordered, |
michael@0 | 100 | nsIFrame **aFirstVisual, |
michael@0 | 101 | nsIFrame **aLastVisual) = 0; |
michael@0 | 102 | }; |
michael@0 | 103 | |
michael@0 | 104 | class nsAutoLineIterator |
michael@0 | 105 | { |
michael@0 | 106 | public: |
michael@0 | 107 | nsAutoLineIterator() : mRawPtr(nullptr) { } |
michael@0 | 108 | nsAutoLineIterator(nsILineIterator *i) : mRawPtr(i) { } |
michael@0 | 109 | |
michael@0 | 110 | ~nsAutoLineIterator() { |
michael@0 | 111 | if (mRawPtr) |
michael@0 | 112 | mRawPtr->DisposeLineIterator(); |
michael@0 | 113 | } |
michael@0 | 114 | |
michael@0 | 115 | operator nsILineIterator*() { return mRawPtr; } |
michael@0 | 116 | nsILineIterator* operator->() { return mRawPtr; } |
michael@0 | 117 | |
michael@0 | 118 | nsILineIterator* operator=(nsILineIterator* i) { |
michael@0 | 119 | if (i == mRawPtr) |
michael@0 | 120 | return i; |
michael@0 | 121 | |
michael@0 | 122 | if (mRawPtr) |
michael@0 | 123 | mRawPtr->DisposeLineIterator(); |
michael@0 | 124 | |
michael@0 | 125 | mRawPtr = i; |
michael@0 | 126 | return i; |
michael@0 | 127 | } |
michael@0 | 128 | |
michael@0 | 129 | private: |
michael@0 | 130 | nsILineIterator* mRawPtr; |
michael@0 | 131 | }; |
michael@0 | 132 | |
michael@0 | 133 | #endif /* nsILineIterator_h___ */ |