Skip to content

Commit

Permalink
feat: Support Text Selection
Browse files Browse the repository at this point in the history
  • Loading branch information
devjiangzhou committed Apr 11, 2023
1 parent 903596e commit 3b3fb86
Show file tree
Hide file tree
Showing 6 changed files with 824 additions and 32 deletions.
29 changes: 20 additions & 9 deletions webf/lib/src/dom/text_node.dart
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@ const String TAB_CHAR = '\t';
class TextNode extends CharacterData {
static const String NORMAL_SPACE = '\u0020';

TextNode(this._data, [BindingContext? context]) : super(NodeType.TEXT_NODE, context);
TextNode(this._data, [BindingContext? context])
: super(NodeType.TEXT_NODE, context);

// Must be existed after text node is attached, and all text update will after text attached.
RenderTextBox? _renderTextBox;
Expand Down Expand Up @@ -58,12 +59,16 @@ class TextNode extends CharacterData {
_renderTextBox!.renderStyle = _parentElement.renderStyle;
_renderTextBox!.data = data;

WebFRenderParagraph renderParagraph = _renderTextBox!.child as WebFRenderParagraph;
WebFRenderParagraph renderParagraph =
_renderTextBox!.child as WebFRenderParagraph;
renderParagraph.markNeedsLayout();

RenderLayoutBox parentRenderLayoutBox = _parentElement.renderBoxModel as RenderLayoutBox;
parentRenderLayoutBox = parentRenderLayoutBox.renderScrollingContent ?? parentRenderLayoutBox;
_setTextSizeType(parentRenderLayoutBox.widthSizeType, parentRenderLayoutBox.heightSizeType);
RenderLayoutBox parentRenderLayoutBox =
_parentElement.renderBoxModel as RenderLayoutBox;
parentRenderLayoutBox =
parentRenderLayoutBox.renderScrollingContent ?? parentRenderLayoutBox;
_setTextSizeType(parentRenderLayoutBox.widthSizeType,
parentRenderLayoutBox.heightSizeType);
}
}

Expand All @@ -84,8 +89,10 @@ class TextNode extends CharacterData {
// If element attach WidgetElement, render object should be attach to render tree when mount.
if (parent.renderObjectManagerType == RenderObjectManagerType.WEBF_NODE &&
parent.renderBoxModel is RenderLayoutBox) {
RenderLayoutBox parentRenderLayoutBox = parent.renderBoxModel as RenderLayoutBox;
parentRenderLayoutBox = parentRenderLayoutBox.renderScrollingContent ?? parentRenderLayoutBox;
RenderLayoutBox parentRenderLayoutBox =
parent.renderBoxModel as RenderLayoutBox;
parentRenderLayoutBox =
parentRenderLayoutBox.renderScrollingContent ?? parentRenderLayoutBox;
parentRenderLayoutBox.insert(_renderTextBox!, after: after);
}

Expand All @@ -96,7 +103,8 @@ class TextNode extends CharacterData {
void _detachRenderTextBox() {
if (isRendererAttached) {
RenderTextBox renderTextBox = _renderTextBox!;
ContainerRenderObjectMixin parent = renderTextBox.parent as ContainerRenderObjectMixin;
ContainerRenderObjectMixin parent =
renderTextBox.parent as ContainerRenderObjectMixin;
parent.remove(renderTextBox);
}
}
Expand All @@ -115,7 +123,10 @@ class TextNode extends CharacterData {

@override
RenderBox createRenderer() {
return _renderTextBox = RenderTextBox(data, renderStyle: parentElement!.renderStyle);
return _renderTextBox = RenderTextBox(data,
renderStyle: parentElement!.renderStyle,
registrar: ownerDocument.controller.registrar,
selectionColor: ownerDocument.controller.selectionColor);
}

@override
Expand Down
2 changes: 1 addition & 1 deletion webf/lib/src/gesture/scroll_position.dart
Original file line number Diff line number Diff line change
Expand Up @@ -487,7 +487,7 @@ abstract class ScrollPosition extends ViewportOffset with ScrollMetrics {
ScrollPositionAlignmentPolicy alignmentPolicy = ScrollPositionAlignmentPolicy.explicit,
}) {
assert(object.attached);
final RenderAbstractViewport viewport = RenderAbstractViewport.of(object)!;
final RenderAbstractViewport viewport = RenderAbstractViewport.of(object);

double? target;
switch (alignmentPolicy) {
Expand Down
6 changes: 6 additions & 0 deletions webf/lib/src/launcher/controller.dart
Original file line number Diff line number Diff line change
Expand Up @@ -767,6 +767,10 @@ class WebFController {
_name = value;
}

final SelectionRegistrar? registrar;

late Color? selectionColor;

final GestureListener? _gestureListener;

// The kraken view entrypoint bundle.
Expand All @@ -793,6 +797,8 @@ class WebFController {
this.devToolsService,
this.uriParser,
this.initialCookies,
this.registrar,
this.selectionColor
}) : _name = name,
_entrypoint = entrypoint,
_gestureListener = gestureListener {
Expand Down
Loading

0 comments on commit 3b3fb86

Please sign in to comment.