Open GoogleCodeExporter opened 9 years ago
I added this one-line comment that, if un-commented, makes
everything work correctly, even in IE:
// If you uncomment this line, IE7 works as it should:
// DOM.setElementAttribute(gwtCanvas.getElement(), "align", "left");
Here's the revised code-to-reproduce, including the above line:
public class TestGChart46 extends Grid {
final int CANVAS_SIZE = 100;
final int CELL_SIZE = 4*CANVAS_SIZE;
/* To reproduce, add an instance of this class to root panel.
* In FF, you get the red, green, blue squares forming the
* expected top-to-bottom, left-to-right,pattern. In IE7, only the
* red square is where it should be, the green is shifted
* too far right (and thus half clipped off) and the
* blue is shifted right off the entire canvas, and thus
* not visible at all.
*
* See commented out line below for a workaround.
*
*/
// fixed size canvas entirely occupied by a solid fill rectangle
GWTCanvas makeCanvasRectangle(String color) {
GWTCanvas gwtCanvas = new GWTCanvas();
gwtCanvas.resize(CANVAS_SIZE, CANVAS_SIZE);
gwtCanvas.setFillStyle(new Color(color));
gwtCanvas.fillRect(0, 0, CANVAS_SIZE, CANVAS_SIZE);
// Workaround: if you uncomment the next line, IE7 works as it should
// DOM.setElementAttribute(gwtCanvas.getElement(), "align", "left");
return gwtCanvas;
}
TestGChart46() {
super(3,1);
// the left aligned cell
int iRow = 0;
setWidget(iRow, 0, makeCanvasRectangle("red"));
getCellFormatter().setAlignment(iRow, 0,
HasHorizontalAlignment.ALIGN_LEFT,
HasVerticalAlignment.ALIGN_MIDDLE);
getCellFormatter().setWidth(iRow, 0, CELL_SIZE + "px");
// the center aligned cell
iRow++;
setWidget(iRow, 0, makeCanvasRectangle("green"));
getCellFormatter().setAlignment(iRow, 0,
HasHorizontalAlignment.ALIGN_CENTER,
HasVerticalAlignment.ALIGN_MIDDLE);
getCellFormatter().setWidth(iRow, 0,CELL_SIZE + "px");
// the right aligned cell
iRow++;
setWidget(iRow, 0, makeCanvasRectangle("blue"));
getCellFormatter().setAlignment(iRow, 0,
HasHorizontalAlignment.ALIGN_RIGHT,
HasVerticalAlignment.ALIGN_MIDDLE);
getCellFormatter().setWidth(iRow, 0, CELL_SIZE + "px");
}
}
With this workaround I finally have an explanation that kind of
makes sense for this IE behavior: the alignment property of the
table cell gets inherited by the div that GWTCanvas uses to hold the
VML element, and then that alignment gets inherited by the VML element(s)
within that div. I can't imagine a scenario where having the VML
inherit the alignment would be helpful (it's very un-vector-
graphics-like) but I guess, if shapes are elements, it kind of
makes sense from the VML perspective.
The behavior of this test implies that, for horizontal alignment
purposes, the VML element is horizonally positioned by it's left edge,
as if it had zero width (sounds strange, until you
realize that it can be kind of hard to compute the actual width
of a complex VML element, and so this may have just been the easiest way for
the VML guys code it).
If you buy the above argument it means that other inherited
attributes/properties might "bleed through" the div into the VML
elements, wreaking unknown havoc for the innocent GWTCanvas user.
Thus maybe worthwhile to come up with a list of other likely bad
actors and, if they make the VML shift in incorrect ways, etc.,
to short-circuit any similar problems via appropriate properties
added to the parent div that holds the VML. Maybe there is a
single VML switch that says "enough already, just ignore the
parent alignment, etc. and position things like a vector-graphics
package would"?
Big picture: Even though they are elements and apparently subject
to at least one inherited attributes/properties, they must be
positioned as they would have had they been instead part of a
simple, pixel-based, vector graphics system, regardless of the
properties/attributes in the parent container. Some insulation
required.
Original comment by johncurt...@gmail.com
on 8 May 2009 at 3:09
Original comment by jaime...@google.com
on 5 Aug 2009 at 12:05
Original issue reported on code.google.com by
johncurt...@gmail.com
on 7 May 2009 at 2:33