1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/layout/generic/nsILineIterator.h Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,133 @@ 1.4 +/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ 1.5 +/* This Source Code Form is subject to the terms of the Mozilla Public 1.6 + * License, v. 2.0. If a copy of the MPL was not distributed with this 1.7 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ 1.8 +#ifndef nsILineIterator_h___ 1.9 +#define nsILineIterator_h___ 1.10 + 1.11 +#include "nscore.h" 1.12 +#include "nsCoord.h" 1.13 + 1.14 +class nsIFrame; 1.15 +struct nsRect; 1.16 + 1.17 +// Line Flags (see GetLine below) 1.18 + 1.19 +// This bit is set when the line is wrapping up a block frame. When 1.20 +// clear, it means that the line contains inline elements. 1.21 +#define NS_LINE_FLAG_IS_BLOCK 0x1 1.22 + 1.23 +// This bit is set when the line ends in some sort of break. 1.24 +#define NS_LINE_FLAG_ENDS_IN_BREAK 0x4 1.25 + 1.26 +/** 1.27 + * Line iterator API. 1.28 + * 1.29 + * Lines are numbered from 0 to N, where 0 is the top line and N is 1.30 + * the bottom line. 1.31 + * 1.32 + * Obtain this interface from frames via nsIFrame::GetLineIterator. 1.33 + * When you are finished using the iterator, call DisposeLineIterator() 1.34 + * to destroy the iterator if appropriate. 1.35 + */ 1.36 +class nsILineIterator 1.37 +{ 1.38 +protected: 1.39 + ~nsILineIterator() { } 1.40 + 1.41 +public: 1.42 + virtual void DisposeLineIterator() = 0; 1.43 + 1.44 + /** 1.45 + * The number of lines in the block 1.46 + */ 1.47 + virtual int32_t GetNumLines() = 0; 1.48 + 1.49 + /** 1.50 + * The prevailing direction of lines. 1.51 + * 1.52 + * @return true if the CSS direction property for the block is 1.53 + * "rtl", otherwise false 1.54 + */ 1.55 + virtual bool GetDirection() = 0; 1.56 + 1.57 + // Return structural information about a line. aFirstFrameOnLine is 1.58 + // the first frame on the line and aNumFramesOnLine is the number of 1.59 + // frames that are on the line. If the line-number is invalid then 1.60 + // aFirstFrameOnLine will be nullptr and aNumFramesOnLine will be 1.61 + // zero. 1.62 + // 1.63 + // For valid line numbers, aLineBounds is set to the bounding box of 1.64 + // the line (which is based on the in-flow position of the frames on 1.65 + // the line; if a frame was moved because of relative positioning 1.66 + // then its coordinates may be outside the line bounds). 1.67 + // 1.68 + // In addition, aLineFlags will contain flag information about the 1.69 + // line. 1.70 + NS_IMETHOD GetLine(int32_t aLineNumber, 1.71 + nsIFrame** aFirstFrameOnLine, 1.72 + int32_t* aNumFramesOnLine, 1.73 + nsRect& aLineBounds, 1.74 + uint32_t* aLineFlags) = 0; 1.75 + 1.76 + /** 1.77 + * Given a frame that's a child of the block, find which line its on 1.78 + * and return that line index, as long as it's at least as big as 1.79 + * aStartLine. Returns -1 if the frame cannot be found on lines 1.80 + * starting with aStartLine. 1.81 + */ 1.82 + virtual int32_t FindLineContaining(nsIFrame* aFrame, 1.83 + int32_t aStartLine = 0) = 0; 1.84 + 1.85 + // Given a line number and an X coordinate, find the frame on the 1.86 + // line that is nearest to the X coordinate. The 1.87 + // aXIsBeforeFirstFrame and aXIsAfterLastFrame flags are updated 1.88 + // appropriately. 1.89 + NS_IMETHOD FindFrameAt(int32_t aLineNumber, 1.90 + nscoord aX, 1.91 + nsIFrame** aFrameFound, 1.92 + bool* aXIsBeforeFirstFrame, 1.93 + bool* aXIsAfterLastFrame) = 0; 1.94 + 1.95 + // Give the line iterator implementor a chance todo something more complicated than 1.96 + // nsIFrame::GetNextSibling() 1.97 + NS_IMETHOD GetNextSiblingOnLine(nsIFrame*& aFrame, int32_t aLineNumber) = 0; 1.98 + 1.99 + // Check whether visual and logical order of frames within a line are identical. 1.100 + // If not, return the first and last visual frames 1.101 + NS_IMETHOD CheckLineOrder(int32_t aLine, 1.102 + bool *aIsReordered, 1.103 + nsIFrame **aFirstVisual, 1.104 + nsIFrame **aLastVisual) = 0; 1.105 +}; 1.106 + 1.107 +class nsAutoLineIterator 1.108 +{ 1.109 +public: 1.110 + nsAutoLineIterator() : mRawPtr(nullptr) { } 1.111 + nsAutoLineIterator(nsILineIterator *i) : mRawPtr(i) { } 1.112 + 1.113 + ~nsAutoLineIterator() { 1.114 + if (mRawPtr) 1.115 + mRawPtr->DisposeLineIterator(); 1.116 + } 1.117 + 1.118 + operator nsILineIterator*() { return mRawPtr; } 1.119 + nsILineIterator* operator->() { return mRawPtr; } 1.120 + 1.121 + nsILineIterator* operator=(nsILineIterator* i) { 1.122 + if (i == mRawPtr) 1.123 + return i; 1.124 + 1.125 + if (mRawPtr) 1.126 + mRawPtr->DisposeLineIterator(); 1.127 + 1.128 + mRawPtr = i; 1.129 + return i; 1.130 + } 1.131 + 1.132 +private: 1.133 + nsILineIterator* mRawPtr; 1.134 +}; 1.135 + 1.136 +#endif /* nsILineIterator_h___ */