new: render to dom only the visible stuff

This commit is contained in:
daboe01
2016-05-27 21:24:30 +02:00
parent f161f723d7
commit bc9beb1e87
2 changed files with 100 additions and 11 deletions
+17 -11
View File
@@ -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;
+83
View File
@@ -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