From bc9beb1e8714fec03e91b5d7710fc23383ec0e26 Mon Sep 17 00:00:00 2001 From: daboe01 Date: Fri, 27 May 2016 21:24:30 +0200 Subject: [PATCH] new: render to dom only the visible stuff --- AppKit/CPTextView/CPLayoutManager.j | 28 ++++++---- AppKit/CPTextView/CPTextView.j | 83 +++++++++++++++++++++++++++++ 2 files changed, 100 insertions(+), 11 deletions(-) diff --git a/AppKit/CPTextView/CPLayoutManager.j b/AppKit/CPTextView/CPLayoutManager.j index 1d1d78de0..387e0fcbb 100644 --- a/AppKit/CPTextView/CPLayoutManager.j +++ b/AppKit/CPTextView/CPLayoutManager.j @@ -1170,6 +1170,7 @@ var _objectsInRange = function(aList, aRange) var color = [attributes objectForKey:CPForegroundColorAttributeName], elem = [self createDOMElementWithText:string andFont:font andColor:color], run = {_range:CPMakeRangeCopy(effectiveRange), elem:elem, string:string}; + run = {_range:CPMakeRangeCopy(effectiveRange), color:color, font:font, elem:nil, string:string}; _runs.push(run); } @@ -1257,7 +1258,12 @@ var _objectsInRange = function(aList, aRange) { var run = runs[i]; - if (run.DOMactive && !run.DOMpatched || !run.elem) + if (!run.elem && CPRectIntersectsRect([_textContainer._textView exposedRect], _fragmentRect)) + { + run.elem=[self createDOMElementWithText:run.string andFont:run.font andColor:run.color]; + } + + if (run.DOMactive && !run.DOMpatched) continue; if (!_glyphsFrames) @@ -1267,19 +1273,19 @@ var _objectsInRange = function(aList, aRange) orig.x = _glyphsFrames[loc].origin.x + aPoint.x; orig.y = _glyphsFrames[loc].origin.y + aPoint.y + _glyphsOffsets[loc]; - run.elem.style.left = (orig.x) + "px"; - run.elem.style.top = (orig.y) + "px"; + if(run.elem) + { + run.elem.style.left = (orig.x) + "px"; + run.elem.style.top = (orig.y) + "px"; - if (!run.DOMactive) - _textContainer._textView._DOMElement.appendChild(run.elem); + if (!run.DOMactive) + _textContainer._textView._DOMElement.appendChild(run.elem); + + run.DOMactive = YES; + } - run.DOMactive = YES; run.DOMpatched = NO; - if (run.underline) - { - // FIXME - } } } @@ -1324,7 +1330,7 @@ var _objectsInRange = function(aList, aRange) { _runs[i]._range.location += rangeOffset; - if (verticalOffset) + if (verticalOffset && _runs[i].elem) { _runs[i].elem.top = (_runs[i].elem.top + verticalOffset) + 'px'; _runs[i].DOMpatched = YES; diff --git a/AppKit/CPTextView/CPTextView.j b/AppKit/CPTextView/CPTextView.j index 064eacaab..e6c009c63 100644 --- a/AppKit/CPTextView/CPTextView.j +++ b/AppKit/CPTextView/CPTextView.j @@ -138,6 +138,9 @@ var kDelegateRespondsTo_textShouldBeginEditing int _stickyXLocation; CPArray _selectionSpans; + CPView _observedClipView; + CGRect _exposedRect; + CPTimer _scrollingTimer; } @@ -248,6 +251,86 @@ var kDelegateRespondsTo_textShouldBeginEditing [super _addObservers]; [self _setObserveWindowKeyNotifications:YES]; + [self _startObservingClipView]; +} +- (void)_startObservingClipView +{ + if (!_observedClipView) + return; + + var defaultCenter = [CPNotificationCenter defaultCenter]; + + [_observedClipView setPostsFrameChangedNotifications:YES]; + [_observedClipView setPostsBoundsChangedNotifications:YES]; + + [defaultCenter addObserver:self + selector:@selector(superviewFrameChanged:) + name:CPViewFrameDidChangeNotification + object:_observedClipView]; + + [defaultCenter addObserver:self + selector:@selector(superviewBoundsChanged:) + name:CPViewBoundsDidChangeNotification + object:_observedClipView]; +} +- (CGRect)exposedRect +{ + if (!_exposedRect) + { + var superview = [self superview]; + + if ([superview isKindOfClass:[CPClipView class]]) + _exposedRect = [superview bounds]; + else + _exposedRect = [self bounds]; + } + + return _exposedRect; +} + +/*! + @ignore +*/ +- (void)superviewBoundsChanged:(CPNotification)aNotification +{ + _exposedRect = nil; + [self setNeedsDisplay:YES]; +} + +/*! + @ignore +*/ +- (void)superviewFrameChanged:(CPNotification)aNotification +{ + _exposedRect = nil; +} + +- (void)viewWillMoveToSuperview:(CPView)aView +{ + if ([aView isKindOfClass:[CPClipView class]]) + _observedClipView = aView; + else + [self _stopObservingClipView]; + + [super viewWillMoveToSuperview:aView]; +} + +- (void)_stopObservingClipView +{ + if (!_observedClipView) + return; + + var defaultCenter = [CPNotificationCenter defaultCenter]; + + [defaultCenter removeObserver:self + name:CPViewFrameDidChangeNotification + object:_observedClipView]; + + [defaultCenter removeObserver:self + name:CPViewBoundsDidChangeNotification + object:_observedClipView]; + + _observedClipView = nil; } - (void)_windowDidResignKey:(CPNotification)aNotification