aboutsummaryrefslogtreecommitdiffhomepage
path: root/cocoa
diff options
context:
space:
mode:
authorNeil Hodgson <nyamatongwe@gmail.com>2014-03-27 16:15:21 +1100
committerNeil Hodgson <nyamatongwe@gmail.com>2014-03-27 16:15:21 +1100
commitc7062988fae7ef98dc94b4b4956d01cbd4c6226c (patch)
treeb1ae114e1758ffa8a46f9346ef23185373df1986 /cocoa
parentaefef213c2343b1e753664b2e606b91ed68db57b (diff)
downloadscintilla-mirror-c7062988fae7ef98dc94b4b4956d01cbd4c6226c.tar.gz
Improve scrolling by performing styling in methods called before drawing instead of inside drawing
which then caused the drawing to be abandoned, and black blocks to appear on-screen. Discard responsive scrolling overdraw when that overdrawn content is invalid. Style just the visible area instead of the whole document when styling changes run beyond painting area.
Diffstat (limited to 'cocoa')
-rw-r--r--cocoa/ScintillaCocoa.h3
-rw-r--r--cocoa/ScintillaCocoa.mm51
-rw-r--r--cocoa/ScintillaView.mm31
3 files changed, 85 insertions, 0 deletions
diff --git a/cocoa/ScintillaCocoa.h b/cocoa/ScintillaCocoa.h
index 9098d2000..415094c35 100644
--- a/cocoa/ScintillaCocoa.h
+++ b/cocoa/ScintillaCocoa.h
@@ -113,8 +113,10 @@ private:
protected:
Point GetVisibleOriginInMain();
PRectangle GetClientRectangle();
+ virtual PRectangle GetClientDrawingRectangle();
Point ConvertPoint(NSPoint point);
virtual void RedrawRect(PRectangle rc);
+ virtual void DiscardOverdraw();
virtual void Redraw();
virtual void Initialise();
@@ -144,6 +146,7 @@ public:
bool SetIdle(bool on);
void SetMouseCapture(bool on);
bool HaveMouseCapture();
+ void WillDraw(NSRect rect);
void ScrollText(int linesToMove);
void SetVerticalScrollPos();
void SetHorizontalScrollPos();
diff --git a/cocoa/ScintillaCocoa.mm b/cocoa/ScintillaCocoa.mm
index f9e67f7b4..c5f24fcd6 100644
--- a/cocoa/ScintillaCocoa.mm
+++ b/cocoa/ScintillaCocoa.mm
@@ -714,6 +714,22 @@ PRectangle ScintillaCocoa::GetClientRectangle()
//--------------------------------------------------------------------------------------------------
/**
+ * Allow for prepared rectangle
+ */
+PRectangle ScintillaCocoa::GetClientDrawingRectangle() {
+ SCIContentView *content = ContentView();
+ if ([content respondsToSelector: @selector(setPreparedContentRect:)]) {
+ NSRect rcPrepared = [content preparedContentRect];
+ if (!NSIsEmptyRect(rcPrepared))
+ return PRectangle(rcPrepared.origin.x, rcPrepared.origin.y,
+ rcPrepared.origin.x+rcPrepared.size.width, rcPrepared.origin.y + rcPrepared.size.height);
+ }
+ return ScintillaCocoa::GetClientRectangle();
+}
+
+//--------------------------------------------------------------------------------------------------
+
+/**
* Converts the given point from base coordinates to local coordinates and at the same time into
* a native Point structure. Base coordinates are used for the top window used in the view hierarchy.
* Returned value is in view coordinates.
@@ -739,12 +755,24 @@ void ScintillaCocoa::RedrawRect(PRectangle rc)
//--------------------------------------------------------------------------------------------------
+void ScintillaCocoa::DiscardOverdraw()
+{
+ // If running on 10.9, reset prepared area to visible area
+ SCIContentView *content = ContentView();
+ if ([content respondsToSelector: @selector(setPreparedContentRect:)]) {
+ content.preparedContentRect = [content visibleRect];
+ }
+}
+
+//--------------------------------------------------------------------------------------------------
+
/**
* Ensure all of prepared content is also redrawn.
*/
void ScintillaCocoa::Redraw()
{
wMargin.InvalidateAll();
+ DiscardOverdraw();
wMain.InvalidateAll();
}
@@ -1563,6 +1591,29 @@ void ScintillaCocoa::PaintMargin(NSRect aRect)
//--------------------------------------------------------------------------------------------------
/**
+ * Prepare for drawing.
+ *
+ * @param rect The area that will be drawn, given in the sender's coordinate system.
+ */
+void ScintillaCocoa::WillDraw(NSRect rect)
+{
+ RefreshStyleData();
+ PRectangle rcWillDraw = NSRectToPRectangle(rect);
+ int positionAfterRect = PositionAfterArea(rcWillDraw);
+ pdoc->EnsureStyledTo(positionAfterRect);
+ NotifyUpdateUI();
+ if (WrapLines(wsVisible)) {
+ // Wrap may have reduced number of lines so more lines may need to be styled
+ positionAfterRect = PositionAfterArea(rcWillDraw);
+ pdoc->EnsureStyledTo(positionAfterRect);
+ // The wrapping process has changed the height of some lines so redraw all.
+ Redraw();
+ }
+}
+
+//--------------------------------------------------------------------------------------------------
+
+/**
* ScrollText is empty because scrolling is handled by the NSScrollView.
*/
void ScintillaCocoa::ScrollText(int linesToMove)
diff --git a/cocoa/ScintillaView.mm b/cocoa/ScintillaView.mm
index 7769d87ef..222fcdc8f 100644
--- a/cocoa/ScintillaView.mm
+++ b/cocoa/ScintillaView.mm
@@ -228,6 +228,37 @@ static NSCursor *cursorFromEnum(Window::Cursor cursor)
//--------------------------------------------------------------------------------------------------
/**
+ * Called before repainting.
+ */
+- (void) viewWillDraw
+{
+ const NSRect *rects;
+ NSInteger nRects = 0;
+ [self getRectsBeingDrawn:&rects count:&nRects];
+ if (nRects > 0) {
+ NSRect rectUnion = rects[0];
+ for (int i=0;i<nRects;i++) {
+ rectUnion = NSUnionRect(rectUnion, rects[i]);
+ }
+ mOwner.backend->WillDraw(rectUnion);
+ }
+ [super viewWillDraw];
+}
+
+//--------------------------------------------------------------------------------------------------
+
+/**
+ * Called before responsive scrolling overdraw.
+ */
+- (void) prepareContentInRect: (NSRect) rect
+{
+ mOwner.backend->WillDraw(rect);
+ [super prepareContentInRect: rect];
+}
+
+//--------------------------------------------------------------------------------------------------
+
+/**
* Gets called by the runtime when the view needs repainting.
*/
- (void) drawRect: (NSRect) rect