Skip to content

Commit

Permalink
[layout] staple position:fixed elements to the screen
Browse files Browse the repository at this point in the history
  • Loading branch information
hrj committed Aug 10, 2015
1 parent 57235ca commit 3631ce7
Show file tree
Hide file tree
Showing 7 changed files with 70 additions and 37 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@
import org.lobobrowser.html.renderer.DelayedPair;
import org.lobobrowser.html.renderer.FrameContext;
import org.lobobrowser.html.renderer.NodeRenderer;
import org.lobobrowser.html.renderer.PositionedRenderable;
import org.lobobrowser.html.renderer.RBlock;
import org.lobobrowser.html.renderer.RCollection;
import org.lobobrowser.html.renderer.RElement;
Expand Down Expand Up @@ -288,7 +289,8 @@ private Rectangle scanNodeBounds(final RCollection root, final Node node, final
BoundableRenderable prevBoundable = null;
if (i != null) {
while (i.hasNext()) {
final Renderable r = i.next();
final Renderable rn = i.next();
final Renderable r = rn instanceof PositionedRenderable ? (((PositionedRenderable)rn).renderable) : rn;
Rectangle subBounds = null;
if (r instanceof RCollection) {
final RCollection rc = (RCollection) r;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,8 @@ public final void invalidateLayoutDeep() {
final Iterator<? extends Renderable> i = this.getRenderables();
if (i != null) {
while (i.hasNext()) {
final Object r = i.next();
final Renderable rn = i.next();
final Renderable r = (rn instanceof PositionedRenderable) ? ((PositionedRenderable) rn).renderable : rn;
if (r instanceof RCollection) {
((RCollection) r).invalidateLayoutDeep();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,8 @@ public void updateWidgetBounds(final int guiX, final int guiY) {
final Iterator<? extends Renderable> i = this.getRenderables();
if (i != null) {
while (i.hasNext()) {
final Object r = i.next();
final Renderable rn = i.next();
final Renderable r = (rn instanceof PositionedRenderable) ? ((PositionedRenderable) rn).renderable : rn;
if (r instanceof RCollection) {
// RUIControl is a RCollection too.
final RCollection rc = (RCollection) r;
Expand Down Expand Up @@ -161,7 +162,8 @@ public boolean extractSelectionText(final StringBuffer buffer, boolean inSelecti
final Iterator<? extends Renderable> i = this.getRenderables();
if (i != null) {
while (i.hasNext()) {
final Object robj = i.next();
final Renderable rn = i.next();
final Renderable robj = (rn instanceof PositionedRenderable) ? ((PositionedRenderable) rn).renderable : rn;
if (robj instanceof BoundableRenderable) {
final BoundableRenderable renderable = (BoundableRenderable) robj;
if (!inSelection) {
Expand Down Expand Up @@ -209,7 +211,8 @@ public void invalidateLayoutDeep() {
final Iterator<? extends Renderable> renderables = this.getRenderables();
if (renderables != null) {
while (renderables.hasNext()) {
final Object r = renderables.next();
final Renderable rn = renderables.next();
final Renderable r = (rn instanceof PositionedRenderable) ? ((PositionedRenderable) rn).renderable : rn;
if (r instanceof RCollection) {
((RCollection) r).invalidateLayoutDeep();
}
Expand Down Expand Up @@ -264,7 +267,8 @@ public BoundableRenderable getRenderable(final int x, final int y) {
final Iterator<? extends Renderable> i = this.getRenderables();
if (i != null) {
while (i.hasNext()) {
final Object r = i.next();
final Renderable rn = i.next();
final Renderable r = (rn instanceof PositionedRenderable) ? ((PositionedRenderable) rn).renderable : rn;
if (r instanceof BoundableRenderable) {
final BoundableRenderable br = (BoundableRenderable) r;
if (br instanceof RBlockViewport) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,17 @@
*/
package org.lobobrowser.html.renderer;

class PositionedRenderable {
import java.awt.Graphics;

import org.lobobrowser.html.domimpl.ModelNode;

public class PositionedRenderable implements Renderable {
public static final PositionedRenderable[] EMPTY_ARRAY = new PositionedRenderable[0];
public final BoundableRenderable renderable;
public final boolean verticalAlignable;
public final int ordinal;
public final boolean isFloat;
public final boolean isFixed;
private final boolean isFixed;

public PositionedRenderable(final BoundableRenderable renderable, final boolean verticalAlignable, final int ordinal,
final boolean isFloat, final boolean isFixed) {
Expand All @@ -37,4 +41,19 @@ public PositionedRenderable(final BoundableRenderable renderable, final boolean
this.isFloat = isFloat;
this.isFixed = isFixed;
}

@Override
public void paint(final Graphics g) {
this.renderable.paintTranslated(g);
}

@Override
public ModelNode getModelNode() {
return this.renderable.getModelNode();
}

@Override
public boolean isFixed() {
return isFixed;
}
}
12 changes: 2 additions & 10 deletions src/HTML_Renderer/org/lobobrowser/html/renderer/RBlock.java
Original file line number Diff line number Diff line change
Expand Up @@ -244,23 +244,15 @@ public void paint(final Graphics gIn) {
final int overflowY = this.overflowY;
if (((overflowX == RenderState.OVERFLOW_NONE) || (overflowX == RenderState.OVERFLOW_VISIBLE))
&& ((overflowY == RenderState.OVERFLOW_NONE) || (overflowY == RenderState.OVERFLOW_VISIBLE))) {
// Simply translate.
final int bx = bodyLayout.x;
final int by = bodyLayout.y;
g.translate(bx, by);
try {
bodyLayout.paint(g);
} finally {
g.translate(-bx, -by);
}
bodyLayout.paint(g);
} else {
// Clip when there potential scrolling or hidden overflow
// was requested.
final Graphics newG = g.create(insets.left, insets.top, this.width - insets.left - insets.right, this.height - insets.top
- insets.bottom);
try {
// Second, translate
newG.translate(bodyLayout.x - insets.left, bodyLayout.y - insets.top);
newG.translate(-insets.left, -insets.top);
// Third, paint in clipped + translated region.
bodyLayout.paint(newG);
} finally {
Expand Down
49 changes: 30 additions & 19 deletions src/HTML_Renderer/org/lobobrowser/html/renderer/RBlockViewport.java
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,6 @@
import org.lobobrowser.html.domimpl.NodeImpl;
import org.lobobrowser.html.domimpl.UINode;
import org.lobobrowser.html.style.HtmlInsets;
import org.lobobrowser.html.style.HtmlValues;
import org.lobobrowser.html.style.JStyleProperties;
import org.lobobrowser.html.style.RenderState;
import org.lobobrowser.ua.UserAgentContext;
Expand Down Expand Up @@ -1261,10 +1260,10 @@ private static void populateZIndexGroups(final Collection<PositionedRenderable>
final PositionedRenderable pr = i1.next();
final BoundableRenderable r = pr.renderable;
if (r.getZIndex() >= 0) {
pending = r;
pending = pr;
break;
}
destination.add(r);
destination.add(pr);
}

// Second, sequential renderables
Expand All @@ -1280,8 +1279,7 @@ private static void populateZIndexGroups(final Collection<PositionedRenderable>
destination.add(pending);
while (i1.hasNext()) {
final PositionedRenderable pr = i1.next();
final Renderable r = pr.renderable;
destination.add(r);
destination.add(pr);
}
}
}
Expand Down Expand Up @@ -1332,7 +1330,7 @@ private Iterator<Renderable> getRenderables(final Rectangle clipBounds) {
final Iterator<PositionedRenderable> i = others.iterator();
while (i.hasNext()) {
final PositionedRenderable pr = i.next();
if (pr.isFixed || clipBounds.intersects(pr.renderable.getBounds())) {
if (pr.isFixed() || clipBounds.intersects(pr.renderable.getBounds())) {
matches.add(pr);
}
}
Expand Down Expand Up @@ -1800,21 +1798,34 @@ public boolean onMouseReleased(final MouseEvent event, final int x, final int y)
return true;
}

public void paint(final Graphics g) {
final Rectangle clipBounds = g.getClipBounds();
final Iterator<Renderable> i = this.getRenderables(clipBounds);
if (i != null) {
while (i.hasNext()) {
final Renderable robj = i.next();
// The expected behavior in HTML is for boxes
// not to be clipped unless overflow=hidden.
if (robj instanceof BoundableRenderable) {
final BoundableRenderable renderable = (BoundableRenderable) robj;
renderable.paintTranslated(g);
} else {
robj.paint(g);
public void paint(final Graphics gIn) {
final boolean translationRequired = (x | y) != 0;
final Graphics g = translationRequired ? gIn.create() : gIn;
if (translationRequired) {
g.translate(x, y);
}
try {
final Rectangle clipBounds = g.getClipBounds();
final Iterator<Renderable> i = this.getRenderables(clipBounds);
if (i != null) {
while (i.hasNext()) {
final Renderable robj = i.next();
// The expected behavior in HTML is for boxes
// not to be clipped unless overflow=hidden.
if (robj instanceof BoundableRenderable) {
final BoundableRenderable renderable = (BoundableRenderable) robj;
renderable.paintTranslated(g);
} else {
// PositionedRenderable, etc because they don't inherit from BoundableRenderable
final Graphics selectedG = robj.isFixed() ? gIn : g;
robj.paint(selectedG);
}
}
}
} finally {
if (translationRequired) {
g.dispose();
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,4 +36,8 @@ public interface Renderable {
public void paint(Graphics g);

public ModelNode getModelNode();

default public boolean isFixed() {
return false;
}
}

0 comments on commit 3631ce7

Please sign in to comment.