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