Bug 366471 - [Cocoa] Slow scrolling in editor on Mac OS X

When overlay scroll bars are used, Control.isObscured() always returns
true, causing isOpaque to return false. This causes performance problems
while redraw/scrolling. To avoid this, don't check for isObscured() in
isOpaque() if the object is StyledText.

See Bug 292281 for details of why isObscured() is tested in isOpaque().

Change-Id: I9d2684138ee6577d5cdd75b13fc6d99b873e3cfb
diff --git a/bundles/org.eclipse.swt/Eclipse SWT Custom Widgets/common/org/eclipse/swt/custom/StyledText.java b/bundles/org.eclipse.swt/Eclipse SWT Custom Widgets/common/org/eclipse/swt/custom/StyledText.java
index b601f84..7f6cbe3 100644
--- a/bundles/org.eclipse.swt/Eclipse SWT Custom Widgets/common/org/eclipse/swt/custom/StyledText.java
+++ b/bundles/org.eclipse.swt/Eclipse SWT Custom Widgets/common/org/eclipse/swt/custom/StyledText.java
@@ -93,6 +93,8 @@
 	static final int PREVIOUS_OFFSET_TRAILING = 0;
 	static final int OFFSET_LEADING = 1;
 
+	static final String STYLEDTEXT_KEY = "org.eclipse.swt.internal.cocoa.styledtext"; //$NON-NLS-1$
+
 	Color selectionBackground;	// selection background color
 	Color selectionForeground;	// selection foreground color
 	StyledTextContent content;			// native content (default or user specified)
@@ -1275,6 +1277,7 @@
 	installListeners();
 	initializeAccessible();
 	setData("DEFAULT_DROP_TARGET_EFFECT", new StyledTextDropTargetEffect(this));
+	if (IS_MAC) setData(STYLEDTEXT_KEY);
 }
 /**
  * Adds an extended modify listener. An ExtendedModify event is sent by the
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/cocoa/org/eclipse/swt/widgets/Composite.java b/bundles/org.eclipse.swt/Eclipse SWT/cocoa/org/eclipse/swt/widgets/Composite.java
index 3799c2d..1a3fac2 100644
--- a/bundles/org.eclipse.swt/Eclipse SWT/cocoa/org/eclipse/swt/widgets/Composite.java
+++ b/bundles/org.eclipse.swt/Eclipse SWT/cocoa/org/eclipse/swt/widgets/Composite.java
@@ -50,6 +50,7 @@
 	Layout layout;
 	Control[] tabList;
 	int layoutCount, backgroundMode;
+	private boolean isStyledText; // This field is set to true if Object is StyledText
 
 Composite () {
 	/* Do nothing */
@@ -564,12 +565,26 @@
 boolean isOpaque (long /*int*/ id, long /*int*/ sel) {
 	if ((state & CANVAS) != 0) {
 		if (id == view.id) {
-			return region == null && background != null && background[3] == 1 && !isObscured ();
+			return region == null && isOpaque();
 		}
 	}
 	return super.isOpaque (id, sel);
 }
 
+boolean isOpaque() {
+	if (isStyledText) {
+		System.out.println("is here");
+		/*
+		 * When overlay scroll bars are used, Control.isObscured() always returns true,
+		 * causing isOpaque to return false. This causes performance problems while
+		 * redraw/scrolling. To workaround this, don't check for isObscured() here if the
+		 * object is StyledText.
+		 */
+		return background == null || backgroundAlpha == 255;
+	}
+	return background != null && background[3] == 1 && !isObscured ();
+}
+
 @Override
 boolean isTabGroup () {
 	if ((state & CANVAS) != 0) return true;
@@ -1075,6 +1090,11 @@
 	return super.setFocus ();
 }
 
+@Override
+void setIsStyledText() {
+	isStyledText = true;
+}
+
 /**
  * Sets the layout which is associated with the receiver to be
  * the argument which may be null.
@@ -1252,4 +1272,5 @@
 		}
 	}
 }
+
 }
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/cocoa/org/eclipse/swt/widgets/Widget.java b/bundles/org.eclipse.swt/Eclipse SWT/cocoa/org/eclipse/swt/widgets/Widget.java
index a3b4c0e..4f72e1b 100644
--- a/bundles/org.eclipse.swt/Eclipse SWT/cocoa/org/eclipse/swt/widgets/Widget.java
+++ b/bundles/org.eclipse.swt/Eclipse SWT/cocoa/org/eclipse/swt/widgets/Widget.java
@@ -84,6 +84,7 @@
 	static final int WEBKIT_EVENTS_FIX = 1<<20;
 	static final String WEBKIT_EVENTS_FIX_KEY = "org.eclipse.swt.internal.webKitEventsFix"; //$NON-NLS-1$
 	static final String GLCONTEXT_KEY = "org.eclipse.swt.internal.cocoa.glcontext"; //$NON-NLS-1$
+	static final String STYLEDTEXT_KEY = "org.eclipse.swt.internal.cocoa.styledtext"; //$NON-NLS-1$
 
 	static final String IS_ACTIVE = "org.eclipse.swt.internal.isActive"; //$NON-NLS-1$
 
@@ -1605,6 +1606,10 @@
 		state |= WEBKIT_EVENTS_FIX;
 		return;
 	}
+	if (STYLEDTEXT_KEY.equals(data)) {
+		setIsStyledText();
+		return;
+	}
 	if ((state & KEYED_DATA) != 0) {
 		((Object []) this.data) [0] = data;
 	} else {
@@ -1612,6 +1617,9 @@
 	}
 }
 
+void setIsStyledText() {
+}
+
 /**
  * Sets the application defined property of the receiver
  * with the specified name to the given value.