1 21 package org.lobobrowser.html.renderer; 22 23 import java.awt.*; 24 25 class OffsetFloatingBounds implements FloatingBounds { 26 private final FloatingBounds ancestorFloatingBounds; 27 private final RBlockViewport ancestor; 28 private final RBlockViewport target; 29 private final Insets ancestorPadding; 30 private final Insets targetPadding; 31 32 public OffsetFloatingBounds(final FloatingBounds ancestorFloatingBounds, final RBlockViewport ancestor, Insets ancestorPadding, final RBlockViewport target, Insets targetPadding) { 33 this.ancestorFloatingBounds = ancestorFloatingBounds; 34 this.ancestor = ancestor; 35 this.target = target; 36 this.ancestorPadding = ancestorPadding; 37 this.targetPadding = targetPadding; 38 } 39 40 public int getClearY(int y) { 41 int ancestorY = this.translateToAncestorY(y); 42 int ancestorClearY = this.ancestorFloatingBounds.getClearY(ancestorY); 43 return this.translateAncestorY(ancestorClearY); 44 } 45 46 public int getLeft(int y) { 47 int ancestorY = this.translateToAncestorY(y); 48 Insets ap = this.ancestorPadding; 49 int aleft = ap == null ? 0 : ap.left; 50 int ancestorX = this.ancestorFloatingBounds.getLeft(ancestorY) + aleft; 51 Insets tp = this.targetPadding; 52 int tleft = tp == null ? 0 : tp.left; 53 int localX = this.translateAncestorX(ancestorX) - tleft; 54 return localX > 0 ? localX : 0; 55 } 56 57 public int getRight(int y) { 58 int ancestorY = this.translateToAncestorY(y); 59 Insets ancestorPadding = this.ancestorPadding; 60 Insets targetPadding = this.targetPadding; 61 int aleft = ancestorPadding == null ? 0 : ancestorPadding.left; 62 int tleft = targetPadding == null ? 0 : targetPadding.left; 63 int ancestorX = aleft + this.ancestor.getAvailContentWidth() - this.ancestorFloatingBounds.getRight(ancestorY); 64 int right = tleft + this.target.getAvailContentWidth() - this.translateAncestorX(ancestorX); 65 return right > 0 ? right : 0; 66 } 67 68 private final int translateToAncestorY(int y) { 69 RBlockViewport ancestor = this.ancestor; 71 BoundableRenderable current = this.target; 72 while(current != null && current != ancestor) { 73 y += current.getY(); 74 current = current.getParent(); 75 } 76 return y; 77 } 78 79 private final int translateAncestorY(int y) { 80 RBlockViewport ancestor = this.ancestor; 82 BoundableRenderable current = this.target; 83 while(current != null && current != ancestor) { 84 y -= current.getY(); 85 current = current.getParent(); 86 } 87 return y; 88 } 89 90 private final int translateAncestorX(int x) { 91 RBlockViewport ancestor = this.ancestor; 93 BoundableRenderable current = this.target; 94 while(current != null && current != ancestor) { 95 x -= current.getX(); 96 current = current.getParent(); 97 } 98 return x; 99 } 100 101 public boolean equals(Object other) { 102 if(!(other instanceof OffsetFloatingBounds)) { 103 return false; 104 } 105 OffsetFloatingBounds ofb = (OffsetFloatingBounds) other; 106 return ofb.ancestor == this.ancestor && 107 ofb.target == this.target && 108 org.lobobrowser.util.Objects.equals(ofb.ancestorFloatingBounds, this.ancestorFloatingBounds); 109 } 110 } 111 | Popular Tags |