use of org.loboevolution.html.renderstate.RenderState in project LoboEvolution by LoboEvolution.
the class ElementImpl method getBoundingClientRect.
/**
* {@inheritDoc}
*/
@Override
public DOMRect getBoundingClientRect() {
AbstractCSSProperties currentStyle = ((HTMLElementImpl) this).getCurrentStyle();
final HTMLDocumentImpl doc = (HTMLDocumentImpl) this.document;
final Window win = doc.getDefaultView();
final RenderState rs = doc.getRenderState();
int width = calculateWidth(true, true);
int height = calculateHeight(true, true);
int top = HtmlValues.getPixelSize(currentStyle.getTop(), rs, win, 0);
int left = HtmlValues.getPixelSize(currentStyle.getLeft(), rs, win, 0);
for (Node n = getParentNode(); n != null; n = n.getParentNode()) {
if (!(n instanceof HTMLBodyElement) && !(n instanceof TextImpl) && !(n instanceof HTMLDocumentImpl)) {
HTMLElementImpl p = (HTMLElementImpl) n;
AbstractCSSProperties pCurrentStyle = p.getCurrentStyle();
String topTxt = pCurrentStyle.getTop();
String leftTxt = pCurrentStyle.getLeft();
int scrollTop = (int) p.getScrollTop();
int scrollLeft = (int) p.getScrollLeft();
if (Strings.isNotBlank(topTxt)) {
top += HtmlValues.getPixelSize(topTxt, rs, win, 0);
}
if (Strings.isNotBlank(leftTxt)) {
left += HtmlValues.getPixelSize(leftTxt, rs, win, 0);
}
top -= scrollTop;
left -= scrollLeft;
}
}
return new DOMRectImpl(width, height, top, 0, 0, left);
}
use of org.loboevolution.html.renderstate.RenderState in project LoboEvolution by LoboEvolution.
the class RUIControl method paint.
/**
* {@inheritDoc}
*/
@Override
public final void paint(final Graphics g) {
final RenderState rs = this.modelNode.getRenderState();
if ((rs != null) && (rs.getVisibility() == RenderState.VISIBILITY_VISIBLE)) {
// Prepaint borders, background images, etc.
this.prePaint(g);
// We need to paint the GUI component.
// For various reasons, we need to do that
// instead of letting AWT do it.
final Insets insets = this.getBorderInsets();
g.translate(insets.left, insets.top);
try {
this.widget.paint(g);
} finally {
g.translate(-insets.left, -insets.top);
}
}
}
use of org.loboevolution.html.renderstate.RenderState in project LoboEvolution by LoboEvolution.
the class RUIControl method doLayout.
/**
* {@inheritDoc}
*/
@Override
public void doLayout(final int availWidth, final int availHeight, final boolean sizeOnly) {
final Map<LayoutKey, LayoutValue> cachedLayout = this.cachedLayout;
final RenderState rs = this.modelNode.getRenderState();
final int whitespace = rs == null ? RenderState.WS_NORMAL : rs.getWhiteSpace();
final Font font = rs == null ? null : rs.getFont();
final LayoutKey layoutKey = new LayoutKey(availWidth, availHeight, whitespace, font);
LayoutValue layoutValue;
if (sizeOnly) {
layoutValue = cachedLayout.get(layoutKey);
} else {
if (Objects.equals(this.lastLayoutKey, layoutKey)) {
layoutValue = this.lastLayoutValue;
} else {
layoutValue = null;
}
}
if (layoutValue == null) {
this.applyStyle(availWidth, availHeight);
final RenderState renderState = this.modelNode.getRenderState();
Insets paddingInsets = this.paddingInsets == null ? RBlockViewport.ZERO_INSETS : this.paddingInsets;
Insets borderInsets = this.borderInsets == null ? RBlockViewport.ZERO_INSETS : this.borderInsets;
Insets marginInsets = this.marginInsets == null ? RBlockViewport.ZERO_INSETS : this.marginInsets;
final int paddingWidth = paddingInsets.left - paddingInsets.right;
final int borderWidth = borderInsets.left - borderInsets.right;
final int marginWidth = marginInsets.left - marginInsets.right;
final int paddingHeight = paddingInsets.top - paddingInsets.bottom;
final int borderHeight = borderInsets.top - borderInsets.bottom;
final int marginHeight = marginInsets.top - marginInsets.bottom;
final int actualAvailWidth = availWidth - paddingWidth - borderWidth - marginWidth;
final int actualAvailHeight = availHeight - paddingHeight - borderHeight - marginHeight;
final Integer dw = this.getDeclaredWidth(renderState, actualAvailWidth);
final Integer dh = this.getDeclaredHeight(renderState, actualAvailHeight);
final int declaredWidth = dw == null ? -1 : dw;
final int declaredHeight = dh == null ? -1 : dh;
this.declaredWidth = declaredWidth;
this.declaredHeight = declaredHeight;
final UIControl widget = this.widget;
widget.reset(availWidth, availHeight);
final Insets insets = this.getInsets(false, false);
int finalWidth = declaredWidth == -1 ? -1 : declaredWidth + insets.left + insets.right;
int finalHeight = declaredHeight == -1 ? -1 : declaredHeight + insets.top + insets.bottom;
final Dimension size = widget.getPreferredSize();
if (finalWidth == -1) {
finalWidth = size.width + insets.left + insets.right;
}
if (finalHeight == -1) {
finalHeight = size.height + insets.top + insets.bottom;
}
layoutValue = new LayoutValue(finalWidth, finalHeight);
if (sizeOnly) {
if (cachedLayout.size() > MAX_CACHE_SIZE) {
cachedLayout.clear();
}
cachedLayout.put(layoutKey, layoutValue);
this.lastLayoutKey = null;
this.lastLayoutValue = null;
} else {
this.lastLayoutKey = layoutKey;
this.lastLayoutValue = layoutValue;
}
}
this.width = layoutValue.width;
this.height = layoutValue.height;
}
use of org.loboevolution.html.renderstate.RenderState in project LoboEvolution by LoboEvolution.
the class BaseElementRenderable method applyStyle.
/**
* <p>applyStyle.</p>
*
* @param availWidth a int.
* @param availHeight a int.
*/
protected void applyStyle(int availWidth, int availHeight) {
final Object rootNode = this.modelNode;
HTMLElementImpl rootElement;
boolean isRootBlock;
if (rootNode instanceof HTMLDocumentImpl) {
isRootBlock = true;
final HTMLDocumentImpl doc = (HTMLDocumentImpl) rootNode;
rootElement = (HTMLElementImpl) doc.getBody();
} else {
isRootBlock = false;
rootElement = (HTMLElementImpl) rootNode;
}
if (rootElement == null) {
clearStyle(isRootBlock);
return;
}
final RenderState rs = rootElement.getRenderState();
if (rs == null) {
throw new IllegalStateException("Element without render state: " + rootElement + "; parent=" + rootElement.getParentNode());
}
backgroundApplyStyle(rs);
final AbstractCSSProperties props = rootElement.getCurrentStyle();
if (props == null) {
clearStyle(isRootBlock);
} else {
insetsApplyStyle(rs, availWidth, availHeight, isRootBlock);
zIndexApplyStyle(props);
this.overflowX = rs.getOverflowX();
this.overflowY = rs.getOverflowY();
}
}
use of org.loboevolution.html.renderstate.RenderState in project LoboEvolution by LoboEvolution.
the class BaseElementRenderable method getCollapsibleMarginTop.
/**
* {@inheritDoc}
*/
@Override
public int getCollapsibleMarginTop() {
int cm;
final Insets paddingInsets = this.paddingInsets;
if (paddingInsets != null && paddingInsets.top > 0) {
cm = 0;
} else {
final Insets borderInsets = this.borderInsets;
if (borderInsets != null && borderInsets.top > 0) {
cm = 0;
} else {
cm = getMarginTop();
}
}
if (isMarginBoundary()) {
final RenderState rs = this.modelNode.getRenderState();
if (rs != null) {
final FontMetrics fm = rs.getFontMetrics();
final int fontHeight = fm.getHeight();
if (fontHeight > cm) {
cm = fontHeight;
}
}
}
return cm;
}
Aggregations