Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorFlorian Thienel2016-07-16 15:19:36 -0400
committerFlorian Thienel2016-07-16 15:19:36 -0400
commitfd1a4d23c2bd41c061780df6ce2785d1562ab9b4 (patch)
treef66ef7975ea5988c96964048d7a03e466d9db907
parent347b27fe1021f84f86ef135aec140aeb24c1f5c4 (diff)
downloadorg.eclipse.mylyn.docs.vex-fd1a4d23c2bd41c061780df6ce2785d1562ab9b4.tar.gz
org.eclipse.mylyn.docs.vex-fd1a4d23c2bd41c061780df6ce2785d1562ab9b4.tar.xz
org.eclipse.mylyn.docs.vex-fd1a4d23c2bd41c061780df6ce2785d1562ab9b4.zip
optimize reconciling layout by taking box structure into account
Signed-off-by: Florian Thienel <florian@thienel.org>
-rw-r--r--org.eclipse.vex.core/src/org/eclipse/vex/core/internal/widget/BoxView.java64
1 files changed, 54 insertions, 10 deletions
diff --git a/org.eclipse.vex.core/src/org/eclipse/vex/core/internal/widget/BoxView.java b/org.eclipse.vex.core/src/org/eclipse/vex/core/internal/widget/BoxView.java
index fc0d8106..8c87c3e0 100644
--- a/org.eclipse.vex.core/src/org/eclipse/vex/core/internal/widget/BoxView.java
+++ b/org.eclipse.vex.core/src/org/eclipse/vex/core/internal/widget/BoxView.java
@@ -12,8 +12,10 @@ package org.eclipse.vex.core.internal.widget;
import java.util.Collection;
import java.util.LinkedList;
+import java.util.ListIterator;
import org.eclipse.vex.core.internal.boxes.IBox;
+import org.eclipse.vex.core.internal.boxes.IChildBox;
import org.eclipse.vex.core.internal.boxes.RootBox;
import org.eclipse.vex.core.internal.core.Graphics;
import org.eclipse.vex.core.internal.core.Rectangle;
@@ -111,20 +113,62 @@ public class BoxView {
return new IRenderStep() {
@Override
public void render(final Graphics graphics) {
- final LinkedList<IBox> invalidatedBoxes = new LinkedList<IBox>();
- invalidatedBoxes.add(box);
+ reconcileBoxLayout(graphics, box);
+ reconcileViewPort();
+ }
+ };
+ }
- while (!invalidatedBoxes.isEmpty()) {
- final IBox invalidatedBox = invalidatedBoxes.pollFirst();
- final Collection<IBox> nextBoxes = invalidatedBox.reconcileLayout(graphics);
+ private static void reconcileBoxLayout(final Graphics graphics, final IBox box) {
+ final LinkedList<IBox> invalidatedBoxes = new LinkedList<IBox>();
+ invalidatedBoxes.add(box);
- invalidatedBoxes.addAll(nextBoxes); // TODO add only required boxes
- // TODO remove unneccessary boxes
- }
+ while (!invalidatedBoxes.isEmpty()) {
+ final IBox invalidatedBox = invalidatedBoxes.pollFirst();
+ final Collection<IBox> nextBoxes = invalidatedBox.reconcileLayout(graphics);
+ cover(invalidatedBoxes, nextBoxes);
+ }
+ }
- reconcileViewPort();
+ private static void cover(final LinkedList<IBox> queue, final Collection<IBox> newBoxes) {
+ for (final IBox box : newBoxes) {
+ cover(queue, box);
+ }
+ }
+
+ private static void cover(final LinkedList<IBox> queue, final IBox box) {
+ final ListIterator<IBox> iterator = queue.listIterator();
+ while (iterator.hasNext()) {
+ final IBox queuedBox = iterator.next();
+ if (isCovered(queuedBox, box)) {
+ iterator.set(box);
+ return;
+ } else if (isCovered(box, queuedBox)) {
+ return;
}
- };
+ }
+ queue.add(box);
+ }
+
+ private static boolean isCovered(final IBox box, final IBox cover) {
+ return isAncestor(box, cover);
+ }
+
+ private static boolean isAncestor(final IBox box, final IBox ancestor) {
+ if (ancestor == null) {
+ return false;
+ }
+ if (box == ancestor) {
+ return true;
+ }
+ return isAncestor(box, getParent(ancestor));
+ }
+
+ private static IBox getParent(final IBox box) {
+ if (box instanceof IChildBox) {
+ return ((IChildBox) box).getParent();
+ }
+ return null;
}
private void reconcileViewPort() {

Back to the top