You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@pivot.apache.org by tv...@apache.org on 2009/11/06 18:49:32 UTC
svn commit: r833495 - in
/incubator/pivot/trunk/wtk/src/org/apache/pivot/wtk: ./ content/ skin/
Author: tvolkert
Date: Fri Nov 6 17:49:31 2009
New Revision: 833495
URL: http://svn.apache.org/viewvc?rev=833495&view=rev
Log:
PIVOT-254 :: Fix ScrollPane optimization in the case of nested scroll panes
Modified:
incubator/pivot/trunk/wtk/src/org/apache/pivot/wtk/Component.java
incubator/pivot/trunk/wtk/src/org/apache/pivot/wtk/content/ListViewItemEditor.java
incubator/pivot/trunk/wtk/src/org/apache/pivot/wtk/content/TableViewCellEditor.java
incubator/pivot/trunk/wtk/src/org/apache/pivot/wtk/content/TableViewRowEditor.java
incubator/pivot/trunk/wtk/src/org/apache/pivot/wtk/content/TreeViewNodeEditor.java
incubator/pivot/trunk/wtk/src/org/apache/pivot/wtk/skin/ScrollPaneSkin.java
incubator/pivot/trunk/wtk/src/org/apache/pivot/wtk/skin/TextAreaSkin.java
Modified: incubator/pivot/trunk/wtk/src/org/apache/pivot/wtk/Component.java
URL: http://svn.apache.org/viewvc/incubator/pivot/trunk/wtk/src/org/apache/pivot/wtk/Component.java?rev=833495&r1=833494&r2=833495&view=diff
==============================================================================
--- incubator/pivot/trunk/wtk/src/org/apache/pivot/wtk/Component.java (original)
+++ incubator/pivot/trunk/wtk/src/org/apache/pivot/wtk/Component.java Fri Nov 6 17:49:31 2009
@@ -1665,7 +1665,7 @@
* ancestors, or, in the case of a Viewport, the viewport bounds.
*
* @return
- * The visible area of the component in display coordinates, or
+ * The visible area of the component in the component's coordinate space, or
* <tt>null</tt> if the component is either not showing or not part of the
* component hierarchy.
*/
@@ -1681,7 +1681,7 @@
* @param area
*
* @return
- * The visible area of the component in display coordinates, or
+ * The visible area of the component in the component's coordinate space, or
* <tt>null</tt> if the component is either not showing or not part of the
* component hierarchy.
*/
@@ -1704,7 +1704,7 @@
* @param height
*
* @return
- * The visible area of the component in display coordinates, or
+ * The visible area of the component in the component's coordinate space, or
* <tt>null</tt> if the component is either not showing or not part of the
* component hierarchy.
*/
@@ -1718,6 +1718,9 @@
int bottom = y + height - 1;
int right = x + width - 1;
+ int xOffset = 0;
+ int yOffset = 0;
+
while (component != null
&& component.isVisible()) {
int minTop = 0;
@@ -1739,8 +1742,12 @@
bottom = component.y + Math.max(Math.min(bottom, maxBottom), -1);
right = component.x + Math.max(Math.min(right, maxRight), -1);
+ xOffset += component.x;
+ yOffset += component.y;
+
if (component instanceof Display) {
- visibleArea = new Bounds(left, top, right - left + 1, bottom - top + 1);
+ visibleArea = new Bounds(left - xOffset, top - yOffset, right - left + 1,
+ bottom - top + 1);
}
component = component.getParent();
Modified: incubator/pivot/trunk/wtk/src/org/apache/pivot/wtk/content/ListViewItemEditor.java
URL: http://svn.apache.org/viewvc/incubator/pivot/trunk/wtk/src/org/apache/pivot/wtk/content/ListViewItemEditor.java?rev=833495&r1=833494&r2=833495&view=diff
==============================================================================
--- incubator/pivot/trunk/wtk/src/org/apache/pivot/wtk/content/ListViewItemEditor.java (original)
+++ incubator/pivot/trunk/wtk/src/org/apache/pivot/wtk/content/ListViewItemEditor.java Fri Nov 6 17:49:31 2009
@@ -33,6 +33,7 @@
import org.apache.pivot.wtk.ListViewItemListener;
import org.apache.pivot.wtk.ListViewListener;
import org.apache.pivot.wtk.Mouse;
+import org.apache.pivot.wtk.Point;
import org.apache.pivot.wtk.TextInput;
import org.apache.pivot.wtk.Window;
import org.apache.pivot.wtk.WindowStateListener;
@@ -239,9 +240,11 @@
// Constrain the bounds by what is visible through Viewport ancestors
editBounds = listView.getVisibleArea(editBounds);
+ Point displayCoordinates = listView.mapPointToAncestor(listView.getDisplay(),
+ editBounds.x, editBounds.y);
textInput.setPreferredWidth(editBounds.width);
- popup.setLocation(editBounds.x, editBounds.y
+ popup.setLocation(displayCoordinates.x, displayCoordinates.y
+ (editBounds.height - textInput.getPreferredHeight(-1)) / 2);
}
Modified: incubator/pivot/trunk/wtk/src/org/apache/pivot/wtk/content/TableViewCellEditor.java
URL: http://svn.apache.org/viewvc/incubator/pivot/trunk/wtk/src/org/apache/pivot/wtk/content/TableViewCellEditor.java?rev=833495&r1=833494&r2=833495&view=diff
==============================================================================
--- incubator/pivot/trunk/wtk/src/org/apache/pivot/wtk/content/TableViewCellEditor.java (original)
+++ incubator/pivot/trunk/wtk/src/org/apache/pivot/wtk/content/TableViewCellEditor.java Fri Nov 6 17:49:31 2009
@@ -32,6 +32,7 @@
import org.apache.pivot.wtk.Display;
import org.apache.pivot.wtk.Keyboard;
import org.apache.pivot.wtk.Mouse;
+import org.apache.pivot.wtk.Point;
import org.apache.pivot.wtk.TableView;
import org.apache.pivot.wtk.TableViewListener;
import org.apache.pivot.wtk.TableViewRowListener;
@@ -258,10 +259,12 @@
Bounds cellBounds = tableView.getCellBounds(rowIndex, columnIndex);
tableView.scrollAreaToVisible(cellBounds);
cellBounds = tableView.getVisibleArea(cellBounds);
+ Point displayCoordinates = tableView.mapPointToAncestor(tableView.getDisplay(),
+ cellBounds.x, cellBounds.y);
// Position the popup/editor to fit over the cell bounds
textInput.setPreferredWidth(cellBounds.width);
- popup.setLocation(cellBounds.x, cellBounds.y
+ popup.setLocation(displayCoordinates.x, displayCoordinates.y
+ (cellBounds.height - textInput.getPreferredHeight(-1)) / 2);
}
Modified: incubator/pivot/trunk/wtk/src/org/apache/pivot/wtk/content/TableViewRowEditor.java
URL: http://svn.apache.org/viewvc/incubator/pivot/trunk/wtk/src/org/apache/pivot/wtk/content/TableViewRowEditor.java?rev=833495&r1=833494&r2=833495&view=diff
==============================================================================
--- incubator/pivot/trunk/wtk/src/org/apache/pivot/wtk/content/TableViewRowEditor.java (original)
+++ incubator/pivot/trunk/wtk/src/org/apache/pivot/wtk/content/TableViewRowEditor.java Fri Nov 6 17:49:31 2009
@@ -41,6 +41,7 @@
import org.apache.pivot.wtk.Keyboard;
import org.apache.pivot.wtk.MenuHandler;
import org.apache.pivot.wtk.Mouse;
+import org.apache.pivot.wtk.Point;
import org.apache.pivot.wtk.ScrollPane;
import org.apache.pivot.wtk.TablePane;
import org.apache.pivot.wtk.TableView;
@@ -381,9 +382,11 @@
Bounds bounds = tableView.getRowBounds(rowIndex);
tableView.scrollAreaToVisible(bounds);
bounds = tableView.getVisibleArea(bounds);
+ Point displayCoordinates = tableView.mapPointToAncestor(tableView.getDisplay(),
+ bounds.x, bounds.y);
// Open this popup over the row
- setLocation(bounds.x, bounds.y);
+ setLocation(displayCoordinates.x, displayCoordinates.y);
setPreferredSize(bounds.width, bounds.height + 1);
// Match the table pane's columns to the table view's
Modified: incubator/pivot/trunk/wtk/src/org/apache/pivot/wtk/content/TreeViewNodeEditor.java
URL: http://svn.apache.org/viewvc/incubator/pivot/trunk/wtk/src/org/apache/pivot/wtk/content/TreeViewNodeEditor.java?rev=833495&r1=833494&r2=833495&view=diff
==============================================================================
--- incubator/pivot/trunk/wtk/src/org/apache/pivot/wtk/content/TreeViewNodeEditor.java (original)
+++ incubator/pivot/trunk/wtk/src/org/apache/pivot/wtk/content/TreeViewNodeEditor.java Fri Nov 6 17:49:31 2009
@@ -32,6 +32,7 @@
import org.apache.pivot.wtk.Insets;
import org.apache.pivot.wtk.Keyboard;
import org.apache.pivot.wtk.Mouse;
+import org.apache.pivot.wtk.Point;
import org.apache.pivot.wtk.TextInput;
import org.apache.pivot.wtk.TreeView;
import org.apache.pivot.wtk.TreeViewListener;
@@ -270,9 +271,11 @@
// Constrain the bounds by what is visible through Viewport ancestors
editBounds = treeView.getVisibleArea(editBounds);
+ Point displayCoordinates = treeView.mapPointToAncestor(treeView.getDisplay(),
+ editBounds.x, editBounds.y);
textInput.setPreferredWidth(editBounds.width);
- popup.setLocation(editBounds.x, editBounds.y
+ popup.setLocation(displayCoordinates.x, displayCoordinates.y
+ (editBounds.height - textInput.getPreferredHeight(-1)) / 2);
}
Modified: incubator/pivot/trunk/wtk/src/org/apache/pivot/wtk/skin/ScrollPaneSkin.java
URL: http://svn.apache.org/viewvc/incubator/pivot/trunk/wtk/src/org/apache/pivot/wtk/skin/ScrollPaneSkin.java?rev=833495&r1=833494&r2=833495&view=diff
==============================================================================
--- incubator/pivot/trunk/wtk/src/org/apache/pivot/wtk/skin/ScrollPaneSkin.java (original)
+++ incubator/pivot/trunk/wtk/src/org/apache/pivot/wtk/skin/ScrollPaneSkin.java Fri Nov 6 17:49:31 2009
@@ -840,6 +840,31 @@
this.verticalReveal = verticalReveal;
}
+ @SuppressWarnings("deprecation")
+ private boolean isOptimizeScrolling() {
+ boolean optimizeScrolling = this.optimizeScrolling;
+
+ if (optimizeScrolling) {
+ // Due to Sun bug #6293145, we cannot call copyArea if scaling is
+ // applied to the graphics context.
+
+ // Due to Sun bug #4033851, we cannot call copyArea if the display
+ // host is obscured. For a full description of why this is the case,
+ // see http://people.apache.org/~tvolkert/tests/scrolling/
+
+ ScrollPane scrollPane = (ScrollPane)getComponent();
+ ApplicationContext.DisplayHost displayHost = scrollPane.getDisplay().getDisplayHost();
+ ApplicationContext applicationContext = displayHost.getApplicationContext();
+
+ optimizeScrolling = (displayHost.getScale() == 1
+ && (applicationContext instanceof DesktopApplicationContext
+ || (displayHost.getPeer().canDetermineObscurity()
+ && !displayHost.getPeer().isObscured())));
+ }
+
+ return optimizeScrolling;
+ }
+
// Viewport.Skin methods
@Override
@@ -909,81 +934,68 @@
// ViewportListener methods
- @SuppressWarnings("deprecation")
@Override
public void scrollTopChanged(Viewport viewport, int previousScrollTop) {
// NOTE we don't invalidate the component here because we need only
// reposition the view and row header. Invalidating would yield
// the correct positioning, but it would do much more work than needed.
- int width = getWidth();
- int height = getHeight();
-
ScrollPane scrollPane = (ScrollPane)viewport;
- Graphics2D graphics = scrollPane.getGraphics();
Component view = scrollPane.getView();
Component rowHeader = scrollPane.getRowHeader();
Component columnHeader = scrollPane.getColumnHeader();
- int scrollTop = scrollPane.getScrollTop();
- int deltaScrollTop = scrollTop - previousScrollTop;
-
int columnHeaderHeight = 0;
- int horizontalScrollBarHeight = horizontalScrollBar.isVisible() ?
- horizontalScrollBar.getHeight() : 0;
-
if (columnHeader != null) {
columnHeaderHeight = columnHeader.getHeight();
}
- int blitX = 0;
- int blitY = columnHeaderHeight + Math.max(deltaScrollTop, 0);
- int blitWidth = width - verticalScrollBar.getWidth();
- int blitHeight = height - horizontalScrollBarHeight -
- columnHeaderHeight - Math.abs(deltaScrollTop);
+ int scrollTop = scrollPane.getScrollTop();
- boolean optimizeScrolling = this.optimizeScrolling;
+ if (view != null
+ && isOptimizeScrolling()) {
+ Bounds blitArea = view.getVisibleArea();
+
+ int blitX = blitArea.x + view.getX();
+ int blitY = blitArea.y + view.getY();
+ int blitWidth = blitArea.width;
+ int blitHeight = blitArea.height;
+
+ if (rowHeader != null) {
+ // Blit the row header as well
+ int rowHeaderWidth = rowHeader.getWidth();
+ blitX -= rowHeaderWidth;
+ blitWidth += rowHeaderWidth;
+ }
- // TODO Remove this check when we can. Sun bug 4033851 causes paint
- // artifacts while scrolling. For a full description of why this is
- // needed, see http://people.apache.org/~tvolkert/tests/scrolling/
- // There seems to be no workaround, so we have to turn the optimization
- // completely off if we're not sure that we're unobscured.
- if (optimizeScrolling) {
- ApplicationContext.DisplayHost displayHost = viewport.getDisplay().getDisplayHost();
- ApplicationContext applicationContext = displayHost.getApplicationContext();
+ int deltaScrollTop = scrollTop - previousScrollTop;
+ blitY += Math.max(deltaScrollTop, 0);
+ blitHeight -= Math.abs(deltaScrollTop);
- optimizeScrolling = (applicationContext instanceof DesktopApplicationContext
- || (displayHost.getPeer().canDetermineObscurity()
- && !displayHost.getPeer().isObscured()));
- }
+ Graphics2D graphics = scrollPane.getGraphics();
+ graphics.copyArea(blitX, blitY, blitWidth, blitHeight, 0, -deltaScrollTop);
- if (optimizeScrolling) {
- try {
- graphics.copyArea(blitX, blitY, blitWidth, blitHeight, 0, -deltaScrollTop);
- } catch (Throwable throwable) {
- // Due to Sun bug #6293145, we cannot call copyArea if scaling is
- // applied to the graphics context, so we fall back gracefully here
- optimizeScrolling = false;
- }
- }
-
- if (optimizeScrolling) {
scrollPane.setConsumeRepaint(true);
- }
-
- if (view != null) {
- view.setLocation(view.getX(), columnHeaderHeight - scrollTop);
- }
+ try {
+ view.setLocation(view.getX(), columnHeaderHeight - scrollTop);
- if (rowHeader != null) {
- rowHeader.setLocation(0, columnHeaderHeight - scrollTop);
- }
+ if (rowHeader != null) {
+ rowHeader.setLocation(0, columnHeaderHeight - scrollTop);
+ }
+ } finally {
+ scrollPane.setConsumeRepaint(false);
+ }
- if (optimizeScrolling) {
- scrollPane.setConsumeRepaint(false);
scrollPane.repaint(blitX, columnHeaderHeight + (deltaScrollTop > 0 ? blitHeight : 0),
blitWidth, Math.abs(deltaScrollTop), true);
+ } else {
+ if (view != null) {
+ view.setLocation(view.getX(), columnHeaderHeight - scrollTop);
+ }
+
+ if (rowHeader != null) {
+ rowHeader.setLocation(0, columnHeaderHeight - scrollTop);
+ }
}
if (scrollTop >= 0 && scrollTop <= getMaxScrollTop()) {
@@ -991,81 +1003,68 @@
}
}
- @SuppressWarnings("deprecation")
@Override
public void scrollLeftChanged(Viewport viewport, int previousScrollLeft) {
// NOTE we don't invalidate the component here because we need only
// reposition the view and column header. Invalidating would yield
// the correct positioning, but it would do much more work than needed.
- int width = getWidth();
- int height = getHeight();
-
ScrollPane scrollPane = (ScrollPane)viewport;
- Graphics2D graphics = scrollPane.getGraphics();
Component view = scrollPane.getView();
Component rowHeader = scrollPane.getRowHeader();
Component columnHeader = scrollPane.getColumnHeader();
- int scrollLeft = scrollPane.getScrollLeft();
- int deltaScrollLeft = scrollLeft - previousScrollLeft;
-
int rowHeaderWidth = 0;
- int verticalScrollBarWidth = verticalScrollBar.isVisible() ?
- verticalScrollBar.getWidth() : 0;
-
if (rowHeader != null) {
rowHeaderWidth = rowHeader.getWidth();
}
- int blitX = rowHeaderWidth + Math.max(deltaScrollLeft, 0);
- int blitY = 0;
- int blitWidth = width - verticalScrollBarWidth -
- rowHeaderWidth - Math.abs(deltaScrollLeft);
- int blitHeight = height - horizontalScrollBar.getHeight();
-
- boolean optimizeScrolling = this.optimizeScrolling;
+ int scrollLeft = scrollPane.getScrollLeft();
- // TODO Remove this check when we can. Sun bug 4033851 causes paint
- // artifacts while scrolling. For a full description of why this is s
- // needed, see http://people.apache.org/~tvolkert/tests/scrolling/.
- // There seems to be no workaround, so we have to turn the optimization
- // completely off if we're not sure that we're unobscured.
- if (optimizeScrolling) {
- ApplicationContext.DisplayHost displayHost = viewport.getDisplay().getDisplayHost();
- ApplicationContext applicationContext = displayHost.getApplicationContext();
+ if (view != null
+ && isOptimizeScrolling()) {
+ Bounds blitArea = view.getVisibleArea();
+
+ int blitX = blitArea.x + view.getX();
+ int blitY = blitArea.y + view.getY();
+ int blitWidth = blitArea.width;
+ int blitHeight = blitArea.height;
+
+ if (columnHeader != null) {
+ // Blit the column header as well
+ int columnHeaderHeight = columnHeader.getHeight();
+ blitY -= columnHeaderHeight;
+ blitHeight += columnHeaderHeight;
+ }
- optimizeScrolling = (applicationContext instanceof DesktopApplicationContext
- || (displayHost.getPeer().canDetermineObscurity()
- && !displayHost.getPeer().isObscured()));
- }
+ int deltaScrollLeft = scrollLeft - previousScrollLeft;
+ blitX += Math.max(deltaScrollLeft, 0);
+ blitWidth -= Math.abs(deltaScrollLeft);
- if (optimizeScrolling) {
- try {
- graphics.copyArea(blitX, blitY, blitWidth, blitHeight, -deltaScrollLeft, 0);
- } catch (Throwable throwable) {
- // Due to Sun bug #6293145, we cannot call copyArea if scaling is
- // applied to the graphics context, so we fall back gracefully here
- optimizeScrolling = false;
- }
- }
+ Graphics2D graphics = scrollPane.getGraphics();
+ graphics.copyArea(blitX, blitY, blitWidth, blitHeight, -deltaScrollLeft, 0);
- if (optimizeScrolling) {
scrollPane.setConsumeRepaint(true);
- }
-
- if (view != null) {
- view.setLocation(rowHeaderWidth - scrollLeft, view.getY());
- }
+ try {
+ view.setLocation(rowHeaderWidth - scrollLeft, view.getY());
- if (columnHeader != null) {
- columnHeader.setLocation(rowHeaderWidth - scrollLeft, 0);
- }
+ if (columnHeader != null) {
+ columnHeader.setLocation(rowHeaderWidth - scrollLeft, 0);
+ }
+ } finally {
+ scrollPane.setConsumeRepaint(false);
+ }
- if (optimizeScrolling) {
- scrollPane.setConsumeRepaint(false);
scrollPane.repaint(rowHeaderWidth + (deltaScrollLeft > 0 ? blitWidth : 0), blitY,
Math.abs(deltaScrollLeft), blitHeight, true);
+ } else {
+ if (view != null) {
+ view.setLocation(rowHeaderWidth - scrollLeft, view.getY());
+ }
+
+ if (columnHeader != null) {
+ columnHeader.setLocation(rowHeaderWidth - scrollLeft, 0);
+ }
}
if (scrollLeft >= 0 && scrollLeft <= getMaxScrollLeft()) {
Modified: incubator/pivot/trunk/wtk/src/org/apache/pivot/wtk/skin/TextAreaSkin.java
URL: http://svn.apache.org/viewvc/incubator/pivot/trunk/wtk/src/org/apache/pivot/wtk/skin/TextAreaSkin.java?rev=833495&r1=833494&r2=833495&view=diff
==============================================================================
--- incubator/pivot/trunk/wtk/src/org/apache/pivot/wtk/skin/TextAreaSkin.java (original)
+++ incubator/pivot/trunk/wtk/src/org/apache/pivot/wtk/skin/TextAreaSkin.java Fri Nov 6 17:49:31 2009
@@ -1845,9 +1845,7 @@
TextArea textArea = (TextArea)getComponent();
Bounds visibleArea = textArea.getVisibleArea();
- Point viewportOrigin = textArea.mapPointFromAncestor(textArea.getDisplay(),
- visibleArea.x, visibleArea.y);
- visibleArea = new Bounds(viewportOrigin.x, viewportOrigin.y,
+ visibleArea = new Bounds(visibleArea.x, visibleArea.y,
visibleArea.width, visibleArea.height);
if (y >= visibleArea.y