michael@0: /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ michael@0: /* This Source Code Form is subject to the terms of the Mozilla Public michael@0: * License, v. 2.0. If a copy of the MPL was not distributed with this michael@0: * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ michael@0: #ifndef nsILineIterator_h___ michael@0: #define nsILineIterator_h___ michael@0: michael@0: #include "nscore.h" michael@0: #include "nsCoord.h" michael@0: michael@0: class nsIFrame; michael@0: struct nsRect; michael@0: michael@0: // Line Flags (see GetLine below) michael@0: michael@0: // This bit is set when the line is wrapping up a block frame. When michael@0: // clear, it means that the line contains inline elements. michael@0: #define NS_LINE_FLAG_IS_BLOCK 0x1 michael@0: michael@0: // This bit is set when the line ends in some sort of break. michael@0: #define NS_LINE_FLAG_ENDS_IN_BREAK 0x4 michael@0: michael@0: /** michael@0: * Line iterator API. michael@0: * michael@0: * Lines are numbered from 0 to N, where 0 is the top line and N is michael@0: * the bottom line. michael@0: * michael@0: * Obtain this interface from frames via nsIFrame::GetLineIterator. michael@0: * When you are finished using the iterator, call DisposeLineIterator() michael@0: * to destroy the iterator if appropriate. michael@0: */ michael@0: class nsILineIterator michael@0: { michael@0: protected: michael@0: ~nsILineIterator() { } michael@0: michael@0: public: michael@0: virtual void DisposeLineIterator() = 0; michael@0: michael@0: /** michael@0: * The number of lines in the block michael@0: */ michael@0: virtual int32_t GetNumLines() = 0; michael@0: michael@0: /** michael@0: * The prevailing direction of lines. michael@0: * michael@0: * @return true if the CSS direction property for the block is michael@0: * "rtl", otherwise false michael@0: */ michael@0: virtual bool GetDirection() = 0; michael@0: michael@0: // Return structural information about a line. aFirstFrameOnLine is michael@0: // the first frame on the line and aNumFramesOnLine is the number of michael@0: // frames that are on the line. If the line-number is invalid then michael@0: // aFirstFrameOnLine will be nullptr and aNumFramesOnLine will be michael@0: // zero. michael@0: // michael@0: // For valid line numbers, aLineBounds is set to the bounding box of michael@0: // the line (which is based on the in-flow position of the frames on michael@0: // the line; if a frame was moved because of relative positioning michael@0: // then its coordinates may be outside the line bounds). michael@0: // michael@0: // In addition, aLineFlags will contain flag information about the michael@0: // line. michael@0: NS_IMETHOD GetLine(int32_t aLineNumber, michael@0: nsIFrame** aFirstFrameOnLine, michael@0: int32_t* aNumFramesOnLine, michael@0: nsRect& aLineBounds, michael@0: uint32_t* aLineFlags) = 0; michael@0: michael@0: /** michael@0: * Given a frame that's a child of the block, find which line its on michael@0: * and return that line index, as long as it's at least as big as michael@0: * aStartLine. Returns -1 if the frame cannot be found on lines michael@0: * starting with aStartLine. michael@0: */ michael@0: virtual int32_t FindLineContaining(nsIFrame* aFrame, michael@0: int32_t aStartLine = 0) = 0; michael@0: michael@0: // Given a line number and an X coordinate, find the frame on the michael@0: // line that is nearest to the X coordinate. The michael@0: // aXIsBeforeFirstFrame and aXIsAfterLastFrame flags are updated michael@0: // appropriately. michael@0: NS_IMETHOD FindFrameAt(int32_t aLineNumber, michael@0: nscoord aX, michael@0: nsIFrame** aFrameFound, michael@0: bool* aXIsBeforeFirstFrame, michael@0: bool* aXIsAfterLastFrame) = 0; michael@0: michael@0: // Give the line iterator implementor a chance todo something more complicated than michael@0: // nsIFrame::GetNextSibling() michael@0: NS_IMETHOD GetNextSiblingOnLine(nsIFrame*& aFrame, int32_t aLineNumber) = 0; michael@0: michael@0: // Check whether visual and logical order of frames within a line are identical. michael@0: // If not, return the first and last visual frames michael@0: NS_IMETHOD CheckLineOrder(int32_t aLine, michael@0: bool *aIsReordered, michael@0: nsIFrame **aFirstVisual, michael@0: nsIFrame **aLastVisual) = 0; michael@0: }; michael@0: michael@0: class nsAutoLineIterator michael@0: { michael@0: public: michael@0: nsAutoLineIterator() : mRawPtr(nullptr) { } michael@0: nsAutoLineIterator(nsILineIterator *i) : mRawPtr(i) { } michael@0: michael@0: ~nsAutoLineIterator() { michael@0: if (mRawPtr) michael@0: mRawPtr->DisposeLineIterator(); michael@0: } michael@0: michael@0: operator nsILineIterator*() { return mRawPtr; } michael@0: nsILineIterator* operator->() { return mRawPtr; } michael@0: michael@0: nsILineIterator* operator=(nsILineIterator* i) { michael@0: if (i == mRawPtr) michael@0: return i; michael@0: michael@0: if (mRawPtr) michael@0: mRawPtr->DisposeLineIterator(); michael@0: michael@0: mRawPtr = i; michael@0: return i; michael@0: } michael@0: michael@0: private: michael@0: nsILineIterator* mRawPtr; michael@0: }; michael@0: michael@0: #endif /* nsILineIterator_h___ */