layout/generic/nsILineIterator.h

Wed, 31 Dec 2014 06:09:35 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:09:35 +0100
changeset 0
6474c204b198
permissions
-rw-r--r--

Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.

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

mercurial