Coverage Report

Created: 2018-09-25 14:53

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