public float getInset(int side,
View v) {
AttributeSet a = v.getAttributes();
float inset = 0;
switch(side) {
case View.LEFT:
inset += getOrientationMargin(HorizontalMargin.LEFT,
leftMargin, a, isLeftToRight(v));
inset += binsets.left;
inset += getLength(CSS.Attribute.PADDING_LEFT, a);
break;
case View.RIGHT:
inset += getOrientationMargin(HorizontalMargin.RIGHT,
rightMargin, a, isLeftToRight(v));
inset += binsets.right;
inset += getLength(CSS.Attribute.PADDING_RIGHT, a);
break;
case View.TOP:
inset += topMargin;
inset += binsets.top;
inset += getLength(CSS.Attribute.PADDING_TOP, a);
break;
case View.BOTTOM:
inset += bottomMargin;
inset += binsets.bottom;
inset += getLength(CSS.Attribute.PADDING_BOTTOM, a);
break;
default:
throw new IllegalArgumentException("Invalid side: " + side);
}
return inset;
}
Fetches the inset needed on a given side to
account for the margin, border, and padding. |
float getOrientationMargin(StyleSheet.BoxPainter.HorizontalMargin side,
float cssMargin,
AttributeSet a,
boolean isLeftToRight) {
float margin = cssMargin;
float orientationMargin = cssMargin;
Object cssMarginValue = null;
switch (side) {
case RIGHT:
{
orientationMargin = (isLeftToRight) ?
getLength(CSS.Attribute.MARGIN_RIGHT_LTR, a) :
getLength(CSS.Attribute.MARGIN_RIGHT_RTL, a);
cssMarginValue = a.getAttribute(CSS.Attribute.MARGIN_RIGHT);
}
break;
case LEFT :
{
orientationMargin = (isLeftToRight) ?
getLength(CSS.Attribute.MARGIN_LEFT_LTR, a) :
getLength(CSS.Attribute.MARGIN_LEFT_RTL, a);
cssMarginValue = a.getAttribute(CSS.Attribute.MARGIN_LEFT);
}
break;
}
if (cssMarginValue == null
&& orientationMargin != Integer.MIN_VALUE) {
margin = orientationMargin;
}
return margin;
}
for , etc.
margins are Left-To-Right/Right-To-Left depended.
see 5088268 for more details
margin-(left|right)-(ltr|rtl) were introduced to describe it
if margin-(left|right) is present we are to use it. |
public void paint(Graphics g,
float x,
float y,
float w,
float h,
View v) {
// PENDING(prinz) implement real rendering... which would
// do full set of border and background capabilities.
// remove margin
float dx = 0;
float dy = 0;
float dw = 0;
float dh = 0;
AttributeSet a = v.getAttributes();
boolean isLeftToRight = isLeftToRight(v);
float localLeftMargin = getOrientationMargin(HorizontalMargin.LEFT,
leftMargin,
a, isLeftToRight);
float localRightMargin = getOrientationMargin(HorizontalMargin.RIGHT,
rightMargin,
a, isLeftToRight);
if (!(v instanceof HTMLEditorKit.HTMLFactory.BodyBlockView)) {
dx = localLeftMargin;
dy = topMargin;
dw = -(localLeftMargin + localRightMargin);
dh = -(topMargin + bottomMargin);
}
if (bg != null) {
g.setColor(bg);
g.fillRect((int) (x + dx),
(int) (y + dy),
(int) (w + dw),
(int) (h + dh));
}
if (bgPainter != null) {
bgPainter.paint(g, x + dx, y + dy, w + dw, h + dh, v);
}
x += localLeftMargin;
y += topMargin;
w -= localLeftMargin + localRightMargin;
h -= topMargin + bottomMargin;
if (border instanceof BevelBorder) {
//BevelBorder does not support border width
int bw = (int) getLength(CSS.Attribute.BORDER_TOP_WIDTH, a);
for (int i = bw - 1; i >= 0; i--) {
border.paintBorder(null, g, (int) x + i, (int) y + i,
(int) w - 2 * i, (int) h - 2 * i);
}
} else {
border.paintBorder(null, g, (int) x, (int) y, (int) w, (int) h);
}
}
Paints the CSS box according to the attributes
given. This should paint the border, padding,
and background. |