box.dart 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  1. import 'package:flutter/rendering.dart';
  2. import '../models/documents/nodes/container.dart';
  3. abstract class RenderContentProxyBox implements RenderBox {
  4. double getPreferredLineHeight();
  5. Offset getOffsetForCaret(TextPosition position, Rect? caretPrototype);
  6. TextPosition getPositionForOffset(Offset offset);
  7. double? getFullHeightForCaret(TextPosition position);
  8. TextRange getWordBoundary(TextPosition position);
  9. List<TextBox> getBoxesForSelection(TextSelection textSelection);
  10. }
  11. /// Base class for render boxes of editable content.
  12. ///
  13. /// Implementations of this class usually work as a wrapper around
  14. /// regular (non-editable) render boxes which implement
  15. /// [RenderContentProxyBox].
  16. abstract class RenderEditableBox extends RenderBox {
  17. /// The document node represented by this render box.
  18. Container getContainer();
  19. /// Returns preferred line height at specified `position` in text.
  20. ///
  21. /// The `position` parameter must be relative to the [node]'s content.
  22. double preferredLineHeight(TextPosition position);
  23. /// Returns the offset at which to paint the caret.
  24. ///
  25. /// The `position` parameter must be relative to the [node]'s content.
  26. ///
  27. /// Valid only after [layout].
  28. Offset getOffsetForCaret(TextPosition position);
  29. /// Returns the position within the text for the given pixel offset.
  30. ///
  31. /// The `offset` parameter must be local to this box coordinate system.
  32. ///
  33. /// Valid only after [layout].
  34. TextPosition getPositionForOffset(Offset offset);
  35. /// Returns the position relative to the [node] content
  36. ///
  37. /// The `position` must be within the [node] content
  38. TextPosition globalToLocalPosition(TextPosition position);
  39. /// Returns the position within the text which is on the line above the given
  40. /// `position`.
  41. ///
  42. /// The `position` parameter must be relative to the [node] content.
  43. ///
  44. /// Primarily used with multi-line or soft-wrapping text.
  45. ///
  46. /// Can return `null` which indicates that the `position` is at the topmost
  47. /// line in the text already.
  48. TextPosition? getPositionAbove(TextPosition position);
  49. /// Returns the position within the text which is on the line below the given
  50. /// `position`.
  51. ///
  52. /// The `position` parameter must be relative to the [node] content.
  53. ///
  54. /// Primarily used with multi-line or soft-wrapping text.
  55. ///
  56. /// Can return `null` which indicates that the `position` is at the bottommost
  57. /// line in the text already.
  58. TextPosition? getPositionBelow(TextPosition position);
  59. /// Returns the text range of the word at the given offset. Characters not
  60. /// part of a word, such as spaces, symbols, and punctuation, have word breaks
  61. /// on both sides. In such cases, this method will return a text range that
  62. /// contains the given text position.
  63. ///
  64. /// Word boundaries are defined more precisely in Unicode Standard Annex #29
  65. /// <http://www.unicode.org/reports/tr29/#Word_Boundaries>.
  66. ///
  67. /// The `position` parameter must be relative to the [node]'s content.
  68. ///
  69. /// Valid only after [layout].
  70. TextRange getWordBoundary(TextPosition position);
  71. /// Returns the text range of the line at the given offset.
  72. ///
  73. /// The newline, if any, is included in the range.
  74. ///
  75. /// The `position` parameter must be relative to the [node]'s content.
  76. ///
  77. /// Valid only after [layout].
  78. TextRange getLineBoundary(TextPosition position);
  79. /// Returns a list of rects that bound the given selection.
  80. ///
  81. /// A given selection might have more than one rect if this text painter
  82. /// contains bidirectional text because logically contiguous text might not be
  83. /// visually contiguous.
  84. ///
  85. /// Valid only after [layout].
  86. // List<TextBox> getBoxesForSelection(TextSelection selection);
  87. /// Returns a point for the base selection handle used on touch-oriented
  88. /// devices.
  89. ///
  90. /// The `selection` parameter is expected to be in local offsets to this
  91. /// render object's [node].
  92. TextSelectionPoint getBaseEndpointForSelection(TextSelection textSelection);
  93. /// Returns a point for the extent selection handle used on touch-oriented
  94. /// devices.
  95. ///
  96. /// The `selection` parameter is expected to be in local offsets to this
  97. /// render object's [node].
  98. TextSelectionPoint getExtentEndpointForSelection(TextSelection textSelection);
  99. /// Returns the [Rect] in local coordinates for the caret at the given text
  100. /// position.
  101. Rect getLocalRectForCaret(TextPosition position);
  102. }