Bumping manifests a=b2g-bump
[gecko.git] / layout / generic / nsILineIterator.h
blobeac426b376296ded336b21eaf134a5a1689e96e4
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___
8 #include "nscore.h"
9 #include "nsCoord.h"
10 #include "mozilla/Attributes.h"
12 class nsIFrame;
13 struct nsRect;
15 // Line Flags (see GetLine below)
17 // This bit is set when the line is wrapping up a block frame. When
18 // clear, it means that the line contains inline elements.
19 #define NS_LINE_FLAG_IS_BLOCK 0x1
21 // This bit is set when the line ends in some sort of break.
22 #define NS_LINE_FLAG_ENDS_IN_BREAK 0x4
24 /**
25 * Line iterator API.
27 * Lines are numbered from 0 to N, where 0 is the top line and N is
28 * the bottom line.
30 * Obtain this interface from frames via nsIFrame::GetLineIterator.
31 * When you are finished using the iterator, call DisposeLineIterator()
32 * to destroy the iterator if appropriate.
34 class nsILineIterator
36 protected:
37 ~nsILineIterator() { }
39 public:
40 virtual void DisposeLineIterator() = 0;
42 /**
43 * The number of lines in the block
45 virtual int32_t GetNumLines() = 0;
47 /**
48 * The prevailing direction of lines.
50 * @return true if the CSS direction property for the block is
51 * "rtl", otherwise false
53 virtual bool GetDirection() = 0;
55 // Return structural information about a line. aFirstFrameOnLine is
56 // the first frame on the line and aNumFramesOnLine is the number of
57 // frames that are on the line. If the line-number is invalid then
58 // aFirstFrameOnLine will be nullptr and aNumFramesOnLine will be
59 // zero.
61 // For valid line numbers, aLineBounds is set to the bounding box of
62 // the line (which is based on the in-flow position of the frames on
63 // the line; if a frame was moved because of relative positioning
64 // then its coordinates may be outside the line bounds).
66 // In addition, aLineFlags will contain flag information about the
67 // line.
68 NS_IMETHOD GetLine(int32_t aLineNumber,
69 nsIFrame** aFirstFrameOnLine,
70 int32_t* aNumFramesOnLine,
71 nsRect& aLineBounds,
72 uint32_t* aLineFlags) = 0;
74 /**
75 * Given a frame that's a child of the block, find which line its on
76 * and return that line index, as long as it's at least as big as
77 * aStartLine. Returns -1 if the frame cannot be found on lines
78 * starting with aStartLine.
80 virtual int32_t FindLineContaining(nsIFrame* aFrame,
81 int32_t aStartLine = 0) = 0;
83 // Given a line number and an X coordinate, find the frame on the
84 // line that is nearest to the X coordinate. The
85 // aXIsBeforeFirstFrame and aXIsAfterLastFrame flags are updated
86 // appropriately.
87 NS_IMETHOD FindFrameAt(int32_t aLineNumber,
88 nscoord aX,
89 nsIFrame** aFrameFound,
90 bool* aXIsBeforeFirstFrame,
91 bool* aXIsAfterLastFrame) = 0;
93 // Give the line iterator implementor a chance todo something more complicated than
94 // nsIFrame::GetNextSibling()
95 NS_IMETHOD GetNextSiblingOnLine(nsIFrame*& aFrame, int32_t aLineNumber) = 0;
97 // Check whether visual and logical order of frames within a line are identical.
98 // If not, return the first and last visual frames
99 NS_IMETHOD CheckLineOrder(int32_t aLine,
100 bool *aIsReordered,
101 nsIFrame **aFirstVisual,
102 nsIFrame **aLastVisual) = 0;
105 class nsAutoLineIterator
107 public:
108 nsAutoLineIterator() : mRawPtr(nullptr) { }
109 MOZ_IMPLICIT nsAutoLineIterator(nsILineIterator *i) : mRawPtr(i) { }
111 ~nsAutoLineIterator() {
112 if (mRawPtr)
113 mRawPtr->DisposeLineIterator();
116 operator nsILineIterator*() { return mRawPtr; }
117 nsILineIterator* operator->() { return mRawPtr; }
119 nsILineIterator* operator=(nsILineIterator* i) {
120 if (i == mRawPtr)
121 return i;
123 if (mRawPtr)
124 mRawPtr->DisposeLineIterator();
126 mRawPtr = i;
127 return i;
130 private:
131 nsILineIterator* mRawPtr;
134 #endif /* nsILineIterator_h___ */