Skip to main content
aboutsummaryrefslogtreecommitdiffstats
blob: ef573ee78ca018ff9586ef50f7902f7c2bcb55f3 (plain) (blame)
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
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
/*******************************************************************************
 * Copyright (c) 2006 Sybase, Inc. 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:
 *     Sybase, Inc. - initial API and implementation
 *******************************************************************************/
package org.eclipse.jst.pagedesigner.css2.layout;

import org.eclipse.draw2d.Graphics;
import org.eclipse.draw2d.geometry.Dimension;
import org.eclipse.draw2d.geometry.Rectangle;
import org.eclipse.jst.pagedesigner.css2.provider.DimensionInfo;
import org.eclipse.jst.pagedesigner.css2.provider.ICSSWidgetProvider;

/**
 * @author mengbo
 */
public class CSSWidgetLayout extends CSSBlockFlowLayout implements ICSSPainter {
	private WidgetBox _widgetBox;

	private ICSSWidgetProvider _provider;

	/**
	 * @param flowfigure
	 */
	public CSSWidgetLayout(CSSFigure flowfigure, ICSSWidgetProvider provider) {
		super(flowfigure);
		_provider = provider;
	}

	/**
	 * normally this method is called directly after constructor
	 * 
	 * @param provider
	 */
	public void setProvider(ICSSWidgetProvider provider) {
		_provider = provider;
	}

	public ICSSWidgetProvider getProvider() {
		// return ((CSSWidgetFigure)this.getFlowFigure()).getProvider();
		return _provider;
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see org.eclipse.jst.pagedesigner.css2.layout.CSSBlockFlowLayout#isInlineBlock()
	 */
	public boolean isInlineBlock() {
		ICSSWidgetProvider provider = getProvider();
		return provider.isInline();
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see org.eclipse.jst.pagedesigner.css2.layout.FlowFigureLayout#layout()
	 */
	protected void layoutChildren() {
		ICSSWidgetProvider provider = getProvider();

		// if we did endLine, then will result in context create a new line, so
		// we may in the new line now.
		// passing in the top margin, and context will consider that when
		// creating the new line.

		int suggestedWith = _blockBox.getContentWidth();
		int suggestedHeight = _blockBox.getContentHeight();
		// int suggestedWith = getSuggestedWidth(line, style, provider);
		// int suggestedHeight = getSuggestedHeight(line, style, provider);

		DimensionInfo resultInfo = provider.getPreferredDimension(
				suggestedWith, suggestedHeight);
		Dimension resultSize = resultInfo.getDimension();

		_widgetBox = new WidgetBox(); // ((CSSWidgetFigure)getFlowFigure()).getWidgetBox();
		// if (provider.isHandlingBorder() || style == null)
		// {
		_widgetBox.setWidth(resultSize.width);
		_widgetBox.setHeight(resultSize.height);
		_widgetBox.setAscent(resultInfo.getAscent());
		// }
		// else
		// {
		// widgetBox.setWidth(resultSize.width +
		// style.getBorderInsets().getWidth());
		// widgetBox.setHeight(resultSize.height +
		// style.getBorderInsets().getHeight());
		// widgetBox.setAscent(resultInfo.getAscent()+style.getBorderInsets().top);
		// }
		this.addToCurrentLine(_widgetBox);
		// if (!provider.isInline())
		// {
		// context.endLine();
		// }
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see org.eclipse.jst.pagedesigner.css2.layout.FlowFigureLayout#dispose()
	 */
	public void dispose() {
        // TODO: anything to dispose?
	}

	// public int getSuggestedWidth(LineBox line, ICSSStyle style,
	// ICSSWidgetProvider provider)
	// {
	// if (style == null) return -1;
	//
	// Object width = style.getStyleProperty(ICSSPropertyID.ATTR_WIDTH);
	// Length recommendedWidth = (width instanceof Length) ? (Length) width :
	// null;
	//
	// int rw = 0;
	// if (recommendedWidth == null || recommendedWidth.getValue() <= 0)
	// {
	// return -1;
	// }
	// else
	// {
	// if (recommendedWidth.isPercentage())
	// {
	// rw = line.getAvailableWidth() * recommendedWidth.getValue() / 100;
	// }
	// else
	// {
	// rw = recommendedWidth.getValue();
	// }
	//
	// if (!style.isSizeIncludeBorderPadding() && provider.isHandlingBorder())
	// {
	// rw += style.getBorderInsets().getWidth() +
	// style.getPaddingInsets().getWidth();
	// }
	// else if (style.isSizeIncludeBorderPadding() &&
	// !provider.isHandlingBorder())
	// {
	// rw -= style.getBorderInsets().getWidth() +
	// style.getPaddingInsets().getWidth();
	// }
	// }
	//
	// return rw;
	// }
	//
	// public int getSuggestedHeight(LineBox line, ICSSStyle style,
	// ICSSWidgetProvider provider)
	// {
	// if (style == null) return -1;
	//
	// Object height = style.getStyleProperty(ICSSPropertyID.ATTR_HEIGHT);
	// Length recommendedHeight = (height instanceof Length) ? (Length) height :
	// null;
	//
	// int rh = 0;
	// if (recommendedHeight == null || recommendedHeight.getValue() <= 0)
	// {
	// return -1;
	// }
	// else
	// {
	// if (recommendedHeight.isPercentage())
	// {
	// // we don't support percentage height for this version, ignore
	// return -1;
	// }
	// else
	// {
	// rh = recommendedHeight.getValue();
	// }
	//
	// if (!style.isSizeIncludeBorderPadding() && provider.isHandlingBorder())
	// {
	// rh += style.getBorderInsets().getHeight() +
	// style.getPaddingInsets().getHeight();
	// }
	// else if (style.isSizeIncludeBorderPadding() &&
	// !provider.isHandlingBorder())
	// {
	// rh -= style.getBorderInsets().getHeight() +
	// style.getPaddingInsets().getHeight();
	// }
	// }
	//
	// return rh;
	// }

	/*
	 * (non-Javadoc)
	 * 
	 * @see org.eclipse.jst.pagedesigner.css2.layout.ICSSPainter#paintFigure(org.eclipse.draw2d.Graphics)
	 */
	public void paintFigure(Graphics g) {
		ICSSWidgetProvider provider = this.getProvider();
		if (provider != null && _widgetBox != null) {
			provider.paintFigure(g, new Rectangle(_widgetBox._x, _widgetBox._y,
					_widgetBox.getWidth(), _widgetBox.getHeight()));
		}
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see org.eclipse.jst.pagedesigner.css2.layout.CSSLayout#handlingBorderForBlock()
	 */
	public boolean handlingBorderForBlock() {
		ICSSWidgetProvider provider = this.getProvider();
		if (provider != null) {
			return provider.isHandlingBorder();
		}
		return super.handlingBorderForBlock();
	}
}

Back to the top