1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
|
/*******************************************************************************
* Copyright (c) 2004, 2008 John Krasnay and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* John Krasnay - initial API and implementation
* Igor Jacy Lino Campista - Java 5 warnings fixed (bug 311325)
*******************************************************************************/
package org.eclipse.vex.core.internal.layout;
import java.util.List;
import org.eclipse.vex.core.internal.css.Styles;
import org.eclipse.vex.core.provisional.dom.ContentPosition;
import org.eclipse.vex.core.provisional.dom.IElement;
import org.eclipse.vex.core.provisional.dom.INode;
/**
* Implements a Block
*
* XXX REMOVE THIS HACK!!!
*/
public class BlockPseudoElementBox extends AbstractBox implements BlockBox {
private final IElement pseudoElement;
private final BlockBox parent;
private final ParagraphBox para;
private final int marginTop;
private final int marginBottom;
public BlockPseudoElementBox(final LayoutContext context, final IElement pseudoElement, final BlockBox parent, final int width) {
this.pseudoElement = pseudoElement;
this.parent = parent;
final Styles styles = context.getStyleSheet().getStyles(pseudoElement);
marginTop = styles.getMarginTop().get(width);
marginBottom = styles.getMarginBottom().get(width);
final int leftInset = styles.getMarginLeft().get(width) + styles.getBorderLeftWidth() + styles.getPaddingLeft().get(width);
final int rightInset = styles.getMarginRight().get(width) + styles.getBorderRightWidth() + styles.getPaddingRight().get(width);
final int childWidth = width - leftInset - rightInset;
final List<InlineBox> inlines = LayoutUtils.createGeneratedInlines(context, pseudoElement);
para = ParagraphBox.create(context, pseudoElement, inlines, childWidth);
para.setX(0);
para.setY(0);
setWidth(width - leftInset - rightInset);
setHeight(para.getHeight());
}
/**
* Provide children for {@link AbstractBox#paint}.
*
* @see org.eclipse.vex.core.internal.layout.Box#getChildren()
*/
@Override
public Box[] getChildren() {
return new Box[] { para };
}
/**
* @see org.eclipse.vex.core.internal.layout.Box#getNode()
*/
@Override
public INode getNode() {
return pseudoElement;
}
/**
* @see org.eclipse.vex.core.internal.layout.BlockBox#getFirstLine()
*/
@Override
public LineBox getFirstLine() {
throw new IllegalStateException();
}
/**
* @see org.eclipse.vex.core.internal.layout.BlockBox#getLastLine()
*/
@Override
public LineBox getLastLine() {
throw new IllegalStateException();
}
/**
* @see org.eclipse.vex.core.internal.layout.BlockBox#getLineEndOffset(int)
*/
@Override
public ContentPosition getLineEndPosition(final ContentPosition position) {
throw new IllegalStateException();
}
/**
* @see org.eclipse.vex.core.internal.layout.BlockBox#getLineStartOffset(int)
*/
@Override
public ContentPosition getLineStartPosition(final ContentPosition position) {
throw new IllegalStateException();
}
@Override
public int getMarginBottom() {
return marginBottom;
}
@Override
public int getMarginTop() {
return marginTop;
}
/**
* @see org.eclipse.vex.core.internal.layout.BlockBox#getNextLineOffset(org.eclipse.vex.core.internal.layout.LayoutContext,
* int, int)
*/
@Override
public ContentPosition getNextLinePosition(final LayoutContext context, final ContentPosition position, final int x) {
throw new IllegalStateException();
}
/**
* Returns this box's parent.
*/
@Override
public BlockBox getParent() {
return parent;
}
/**
* @see org.eclipse.vex.core.internal.layout.BlockBox#getPreviousLineOffset(org.eclipse.vex.core.internal.layout.LayoutContext,
* int, int)
*/
@Override
public ContentPosition getPreviousLinePosition(final LayoutContext context, final ContentPosition position, final int x) {
throw new IllegalStateException();
}
@Override
public VerticalRange layout(final LayoutContext context, final int top, final int bottom) {
return null;
}
@Override
public void invalidate(final boolean direct) {
throw new IllegalStateException("invalidate called on a non-element BlockBox");
}
/**
* Draw boxes before painting our child.
*
* @see org.eclipse.vex.core.internal.layout.Box#paint(org.eclipse.vex.core.internal.layout.LayoutContext, int, int)
*/
@Override
public void paint(final LayoutContext context, final int x, final int y) {
this.drawBox(context, x, y, getParent().getWidth(), true);
super.paint(context, x, y);
}
@Override
public void setInitialSize(final LayoutContext context) {
// NOP - size calculated in the ctor
}
}
|