nsILineIterator.h 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  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___
  7. #include "nscore.h"
  8. #include "nsPoint.h"
  9. #include "mozilla/Attributes.h"
  10. class nsIFrame;
  11. struct nsRect;
  12. /**
  13. * Line iterator API.
  14. *
  15. * Lines are numbered from 0 to N, where 0 is the top line and N is
  16. * the bottom line.
  17. *
  18. * Obtain this interface from frames via nsIFrame::GetLineIterator.
  19. * When you are finished using the iterator, call DisposeLineIterator()
  20. * to destroy the iterator if appropriate.
  21. */
  22. class nsILineIterator
  23. {
  24. protected:
  25. ~nsILineIterator() { }
  26. public:
  27. virtual void DisposeLineIterator() = 0;
  28. /**
  29. * The number of lines in the block
  30. */
  31. virtual int32_t GetNumLines() = 0;
  32. /**
  33. * The prevailing direction of lines.
  34. *
  35. * @return true if the CSS direction property for the block is
  36. * "rtl", otherwise false
  37. *
  38. *XXX after bug 924851 change this to return a UBiDiDirection
  39. */
  40. virtual bool GetDirection() = 0;
  41. // Return structural information about a line. aFirstFrameOnLine is
  42. // the first frame on the line and aNumFramesOnLine is the number of
  43. // frames that are on the line. If the line-number is invalid then
  44. // aFirstFrameOnLine will be nullptr and aNumFramesOnLine will be
  45. // zero.
  46. //
  47. // For valid line numbers, aLineBounds is set to the bounding box of
  48. // the line (which is based on the in-flow position of the frames on
  49. // the line; if a frame was moved because of relative positioning
  50. // then its coordinates may be outside the line bounds).
  51. NS_IMETHOD GetLine(int32_t aLineNumber,
  52. nsIFrame** aFirstFrameOnLine,
  53. int32_t* aNumFramesOnLine,
  54. nsRect& aLineBounds) = 0;
  55. /**
  56. * Given a frame that's a child of the block, find which line its on
  57. * and return that line index, as long as it's at least as big as
  58. * aStartLine. Returns -1 if the frame cannot be found on lines
  59. * starting with aStartLine.
  60. */
  61. virtual int32_t FindLineContaining(nsIFrame* aFrame,
  62. int32_t aStartLine = 0) = 0;
  63. // Given a line number and a coordinate, find the frame on the line
  64. // that is nearest to aPos along the inline axis. (The block-axis coord
  65. // of aPos is irrelevant.)
  66. // The aPosIsBeforeFirstFrame and aPosIsAfterLastFrame flags are updated
  67. // appropriately.
  68. NS_IMETHOD FindFrameAt(int32_t aLineNumber,
  69. nsPoint aPos,
  70. nsIFrame** aFrameFound,
  71. bool* aPosIsBeforeFirstFrame,
  72. bool* aPosIsAfterLastFrame) = 0;
  73. // Give the line iterator implementor a chance todo something more complicated than
  74. // nsIFrame::GetNextSibling()
  75. NS_IMETHOD GetNextSiblingOnLine(nsIFrame*& aFrame, int32_t aLineNumber) = 0;
  76. // Check whether visual and logical order of frames within a line are identical.
  77. // If not, return the first and last visual frames
  78. NS_IMETHOD CheckLineOrder(int32_t aLine,
  79. bool *aIsReordered,
  80. nsIFrame **aFirstVisual,
  81. nsIFrame **aLastVisual) = 0;
  82. };
  83. class nsAutoLineIterator
  84. {
  85. public:
  86. nsAutoLineIterator() : mRawPtr(nullptr) { }
  87. MOZ_IMPLICIT nsAutoLineIterator(nsILineIterator *i) : mRawPtr(i) { }
  88. ~nsAutoLineIterator() {
  89. if (mRawPtr)
  90. mRawPtr->DisposeLineIterator();
  91. }
  92. operator nsILineIterator*() { return mRawPtr; }
  93. nsILineIterator* operator->() { return mRawPtr; }
  94. nsILineIterator* operator=(nsILineIterator* i) {
  95. if (i == mRawPtr)
  96. return i;
  97. if (mRawPtr)
  98. mRawPtr->DisposeLineIterator();
  99. mRawPtr = i;
  100. return i;
  101. }
  102. private:
  103. nsILineIterator* mRawPtr;
  104. };
  105. #endif /* nsILineIterator_h___ */