Flutter Engine
The Flutter Engine
Instance Methods | Protected Attributes | Properties | List of all members
FlutterMutatorView Class Reference

#import <FlutterMutatorView.h>

Inheritance diagram for FlutterMutatorView:

Instance Methods

(nonnull instancetype) - initWithPlatformView:cursorCoordiator:
 Designated initializer. More...
 
(nonnull instancetype) - initWithPlatformView:
 
(void) - applyFlutterLayer:
 
(void) - resetHitTestRegion
 Resets hit hit testing region for this mutator view. More...
 
(void) - addHitTestIgnoreRegion:
 
(NSMutableArray *) - pathClipViews [implementation]
 
(NSView *) - platformViewContainer [implementation]
 
(instancetype) - initWithPlatformView: [implementation]
 
(instancetype) - initWithPlatformView:cursorCoordiator: [implementation]
 
(void) - mouseMoved: [implementation]
 
(NSView *) - hitTest: [implementation]
 
(BOOL- isFlipped [implementation]
 
(CGFloat) - contentsScale [implementation]
 Returns the scale factor to translate logical pixels to physical pixels for this view. More...
 
(void) - updatePathClipViewsWithPaths: [implementation]
 Updates the nested stack of clip views that host the platform view. More...
 
(void) - updatePlatformViewWithBounds:transformedBounds:transform:clipRect: [implementation]
 
(void) - applyFlutterLayer: [implementation]
 

Protected Attributes

NSMutableArray * _pathClipViews
 
NSView * _platformViewContainer
 
NSView * _platformView
 
FlutterCursorCoordinator_cursorCoordinator
 
NSView * _trackingAreaContainer
 
NSTrackingArea * _trackingArea
 
std::vector< CGRect > _hitTestIgnoreRegion
 

Properties

NSView * platformView
 Returns wrapped platform view. More...
 

Detailed Description

FlutterMutatorView contains platform view and is responsible for applying FlutterLayer mutations to it.

Definition at line 63 of file FlutterMutatorView.h.

Method Documentation

◆ addHitTestIgnoreRegion:

- (void) addHitTestIgnoreRegion: (CGRect)  region

Adds rectangle (in local vie coordinates) to hit test ignore region (part of view obscured by Flutter contents).

Definition at line 417 of file FlutterMutatorView.mm.

530 :(CGRect)region {
531 self->_hitTestIgnoreRegion.push_back(region);
532}
ClipOpAndAA opAA SkRegion region
Definition: SkRecords.h:238

◆ applyFlutterLayer: [1/2]

- (void) applyFlutterLayer: (const flutter::PlatformViewLayer*)  layer
implementation

Whenever possible view will be clipped using layer bounds. If clipping to path is needed, CAShapeLayer(s) will be used as mask. Clipping to round rect only clips to path if round corners are intersected.

Paths in global logical coordinates that need to be clipped to.

Update PlatformViewContainer, PlatformView, and apply transforms and axis-aligned clip rect.

Definition at line 417 of file FlutterMutatorView.mm.

642 :(const flutter::PlatformViewLayer*)layer {
643 // Compute the untransformed bounding rect for the platform view in logical pixels.
644 // FlutterLayer.size is in physical pixels but Cocoa uses logical points.
645 CGFloat scale = [self contentsScale];
646 MutationVector mutations = MutationsForPlatformView(layer->mutations(), scale);
647
648 CATransform3D finalTransform = CATransformFromMutations(mutations);
649
650 // Compute the untransformed bounding rect for the platform view in logical pixels.
651 // FlutterLayer.size is in physical pixels but Cocoa uses logical points.
652 CGRect untransformedBoundingRect =
653 CGRectMake(0, 0, layer->size().width / scale, layer->size().height / scale);
654 CGRect finalBoundingRect = CGRectApplyAffineTransform(
655 untransformedBoundingRect, CATransform3DGetAffineTransform(finalTransform));
656 self.frame = finalBoundingRect;
657
658 // Compute the layer opacity.
659 self.layer.opacity = OpacityFromMutations(mutations);
660
661 // Compute the master clip in global logical coordinates.
662 CGRect masterClip = MasterClipFromMutations(finalBoundingRect, mutations);
663 if (CGRectIsNull(masterClip)) {
664 self.hidden = YES;
665 return;
666 }
667 self.hidden = NO;
668
669 /// Paths in global logical coordinates that need to be clipped to.
670 NSMutableArray* paths = ClipPathFromMutations(masterClip, mutations);
671 [self updatePathClipViewsWithPaths:paths];
672
673 /// Update PlatformViewContainer, PlatformView, and apply transforms and axis-aligned clip rect.
674 [self updatePlatformViewWithBounds:untransformedBoundingRect
675 transformedBounds:finalBoundingRect
676 transform:finalTransform
677 clipRect:masterClip];
678
679 [self addSubview:_trackingAreaContainer positioned:(NSWindowAbove)relativeTo:nil];
680 _trackingAreaContainer.frame = self.bounds;
681}
Represents a platform view layer, including all mutations.
const std::vector< FlutterPlatformViewMutation > & mutations() const
const Scalar scale
double height
Definition: embedder.h:425
double width
Definition: embedder.h:424

◆ applyFlutterLayer: [2/2]

- (void) applyFlutterLayer: (nonnull const flutter::PlatformViewLayer *)  layer

Applies mutations from FlutterLayer to the platform view. This may involve creating or removing intermediate subviews depending on current state and requested mutations.

◆ contentsScale

- (CGFloat) contentsScale
implementation

Returns the scale factor to translate logical pixels to physical pixels for this view.

Definition at line 417 of file FlutterMutatorView.mm.

557 {
558 return self.superview != nil ? self.superview.layer.contentsScale : 1.0;
559}

◆ hitTest:

- (NSView *) hitTest: (NSPoint)  point
implementation

Definition at line 417 of file FlutterMutatorView.mm.

540 :(NSPoint)point {
541 CGPoint localPoint = point;
542 localPoint.x -= self.frame.origin.x;
543 localPoint.y -= self.frame.origin.y;
544 for (const auto& region : _hitTestIgnoreRegion) {
545 if (CGRectContainsPoint(region, localPoint)) {
546 return nil;
547 }
548 }
549 return [super hitTest:point];
550}
double frame
Definition: examples.cpp:31
std::vector< CGRect > _hitTestIgnoreRegion
double y
double x

◆ initWithPlatformView: [1/2]

- (nonnull instancetype) initWithPlatformView: (nonnull NSView *)  platformView

◆ initWithPlatformView: [2/2]

- (instancetype) initWithPlatformView: (NSView*)  platformView
implementation

Definition at line 417 of file FlutterMutatorView.mm.

499 :(NSView*)platformView {
500 return [self initWithPlatformView:platformView cursorCoordiator:nil];
501}
NSView * platformView
Returns wrapped platform view.

◆ initWithPlatformView:cursorCoordiator: [1/2]

- (nonnull instancetype) initWithPlatformView: (nonnull NSView *)  platformView
cursorCoordiator: (nullable FlutterCursorCoordinator *)  coordinator 

Designated initializer.

◆ initWithPlatformView:cursorCoordiator: [2/2]

- (instancetype) initWithPlatformView: (NSView*)  platformView
cursorCoordiator: (FlutterCursorCoordinator*)  coordinator 
implementation

Definition at line 417 of file FlutterMutatorView.mm.

503 :(NSView*)platformView
504 cursorCoordiator:(FlutterCursorCoordinator*)coordinator {
505 if (self = [super initWithFrame:NSZeroRect]) {
507 _pathClipViews = [NSMutableArray array];
508 _cursorCoordinator = coordinator;
509 self.wantsLayer = YES;
510 self.clipsToBounds = YES;
511
512 _trackingAreaContainer = [[FlutterTrackingAreaContainer alloc] initWithFrame:NSZeroRect];
513 [self addSubview:_trackingAreaContainer];
514
515 NSTrackingAreaOptions options = NSTrackingMouseMoved | NSTrackingInVisibleRect |
516 NSTrackingEnabledDuringMouseDrag | NSTrackingActiveAlways;
517 _trackingArea = [[NSTrackingArea alloc] initWithRect:NSZeroRect
518 options:options
519 owner:self
520 userInfo:nil];
521 [_trackingAreaContainer addTrackingArea:_trackingArea];
522 }
523 return self;
524}
const char * options
NSTrackingArea * _trackingArea
FlutterCursorCoordinator * _cursorCoordinator
NSMutableArray * _pathClipViews
instancetype initWithFrame

◆ isFlipped

- (BOOL) isFlipped
implementation

Definition at line 417 of file FlutterMutatorView.mm.

552 {
553 return YES;
554}

◆ mouseMoved:

- (void) mouseMoved: (NSEvent*)  event
implementation

Definition at line 417 of file FlutterMutatorView.mm.

534 :(NSEvent*)event {
535 [_cursorCoordinator processMouseMoveEvent:event
536 forMutatorView:self
537 overlayRegion:_hitTestIgnoreRegion];
538}
FlKeyEvent * event

◆ pathClipViews

- (NSMutableArray *) pathClipViews
implementation

Provided by category FlutterMutatorView(Private).

Definition at line 417 of file FlutterMutatorView.mm.

491 {
492 return _pathClipViews;
493}

◆ platformViewContainer

- (NSView *) platformViewContainer
implementation

Provided by category FlutterMutatorView(Private).

Definition at line 417 of file FlutterMutatorView.mm.

495 {
497}

◆ resetHitTestRegion

- (void) resetHitTestRegion

Resets hit hit testing region for this mutator view.

Definition at line 417 of file FlutterMutatorView.mm.

526 {
527 self->_hitTestIgnoreRegion.clear();
528}

◆ updatePathClipViewsWithPaths:

- (void) updatePathClipViewsWithPaths: (NSArray*)  paths
implementation

Updates the nested stack of clip views that host the platform view.

Definition at line 417 of file FlutterMutatorView.mm.

562 :(NSArray*)paths {
563 // Remove path clip views depending on the number of paths.
564 while (_pathClipViews.count > paths.count) {
565 NSView* view = _pathClipViews.lastObject;
566 [view removeFromSuperview];
567 [_pathClipViews removeLastObject];
568 }
569 // Otherwise, add path clip views to the end.
570 for (size_t i = _pathClipViews.count; i < paths.count; ++i) {
571 NSView* superView = _pathClipViews.count == 0 ? self : _pathClipViews.lastObject;
572 FlutterPathClipView* pathClipView = [[FlutterPathClipView alloc] initWithFrame:self.bounds];
573 [_pathClipViews addObject:pathClipView];
574 [superView addSubview:pathClipView];
575 }
576 // Update bounds and apply clip paths.
577 for (size_t i = 0; i < _pathClipViews.count; ++i) {
578 FlutterPathClipView* pathClipView = _pathClipViews[i];
579 pathClipView.frame = self.bounds;
580 [pathClipView maskToPath:(__bridge CGPathRef)[paths objectAtIndex:i]
581 withOrigin:self.frame.origin];
582 }
583}
void maskToPath:withOrigin:(CGPathRef path, [withOrigin] CGPoint origin)

◆ updatePlatformViewWithBounds:transformedBounds:transform:clipRect:

- (void) updatePlatformViewWithBounds: (CGRect)  untransformedBounds
transformedBounds: (CGRect)  transformedBounds
transform: (CATransform3D)  transform
clipRect: (CGRect)  clipRect 
implementation

Updates the PlatformView and PlatformView container views.

Re-nests _platformViewContainer in the innermost clip view, applies transforms to the underlying CALayer, adds the platform view as a subview of the container, and sets the axis-aligned clip rect around the tranformed view.

Definition at line 417 of file FlutterMutatorView.mm.

590 :(CGRect)untransformedBounds
591 transformedBounds:(CGRect)transformedBounds
592 transform:(CATransform3D)transform
593 clipRect:(CGRect)clipRect {
594 // Create the PlatformViewContainer view if necessary.
595 if (_platformViewContainer == nil) {
596 _platformViewContainer = [[FlutterPlatformViewContainer alloc] initWithFrame:self.bounds];
597 _platformViewContainer.wantsLayer = YES;
598 }
599
600 // Nest the PlatformViewContainer view in the innermost path clip view.
601 NSView* containerSuperview = _pathClipViews.count == 0 ? self : _pathClipViews.lastObject;
602 [containerSuperview addSubview:_platformViewContainer];
603 _platformViewContainer.frame = self.bounds;
604
605 // Nest the platform view in the PlatformViewContainer, but only if the view doesn't have a
606 // superview yet. Sometimes the platform view reparents itself (WKWebView entering FullScreen)
607 // in which case do not forcefully move it back.
608 if (_platformView.superview == nil) {
609 [_platformViewContainer addSubview:_platformView];
610 }
611
612 // Originally first subview would be the _platformView. However during WKWebView full screen
613 // the platform view gets replaced with a placeholder. Given that _platformViewContainer does
614 // not contain any other views it is safe to assume that any subview found can be treated
615 // as the platform view.
616 _platformViewContainer.subviews.firstObject.frame = untransformedBounds;
617
618 // Transform for the platform view is finalTransform adjusted for bounding rect origin.
619 CATransform3D translation =
620 CATransform3DMakeTranslation(-transformedBounds.origin.x, -transformedBounds.origin.y, 0);
621 transform = CATransform3DConcat(transform, translation);
622 _platformViewContainer.layer.sublayerTransform = transform;
623
624 // By default NSView clips children to frame. If masterClip is tighter than mutator view frame,
625 // the frame is set to masterClip and child offset adjusted to compensate for the difference.
626 if (!CGRectEqualToRect(clipRect, transformedBounds)) {
627 NSMutableArray<NSView*>* subviews = [NSMutableArray arrayWithArray:self.subviews];
628 [subviews removeObject:_trackingAreaContainer];
629 FML_DCHECK(subviews.count == 1);
630 auto subview = subviews.firstObject;
631 FML_DCHECK(subview.frame.origin.x == 0 && subview.frame.origin.y == 0);
632 subview.frame = CGRectMake(transformedBounds.origin.x - clipRect.origin.x,
633 transformedBounds.origin.y - clipRect.origin.y,
634 subview.frame.size.width, subview.frame.size.height);
635 self.frame = clipRect;
636 }
637}
#define FML_DCHECK(condition)
Definition: logging.h:103
Superview container for platform views, to which sublayer transforms are applied.
clipRect(r.rect, r.opAA.op(), r.opAA.aa())) template<> void Draw
static SkColor4f transform(SkColor4f c, SkColorSpace *src, SkColorSpace *dst)
Definition: p3.cpp:47

Member Data Documentation

◆ _cursorCoordinator

- (FlutterCursorCoordinator*) _cursorCoordinator
protected

Definition at line 104 of file FlutterMutatorView.mm.

◆ _hitTestIgnoreRegion

- (vector<CGRect> FlutterMutatorView()):
protected

Definition at line 114 of file FlutterMutatorView.mm.

◆ _pathClipViews

- (NSMutableArray*) _pathClipViews
protected

Definition at line 96 of file FlutterMutatorView.mm.

◆ _platformView

- (NSView*) _platformView
protected

Definition at line 102 of file FlutterMutatorView.mm.

◆ _platformViewContainer

- (NSView*) _platformViewContainer
protected

Definition at line 100 of file FlutterMutatorView.mm.

◆ _trackingArea

- (NSTrackingArea*) _trackingArea
protected

Definition at line 111 of file FlutterMutatorView.mm.

◆ _trackingAreaContainer

- (NSView*) _trackingAreaContainer
protected

Definition at line 108 of file FlutterMutatorView.mm.

Property Documentation

◆ platformView

- (NSView *) platformView
readatomicassign

Returns wrapped platform view.

Definition at line 72 of file FlutterMutatorView.h.


The documentation for this class was generated from the following files: