This issue might offer more insight into what's happening:
https://code.google.com/p/google-web-toolkit/issues/detail?id=6848
(As you can see from the comments, I ran afoul of IE when I first got
started with Canvas.)
On Sunday, May 12, 2013 10:19:01 AM UTC-4, Joachim Nielandt wrote:
>
> Ok, silly, after toiling hours on the problem and posting the question, I
> find the answer more or less directly:
>
> put: this.getElement().getStyle().setDisplay(Display.BLOCK);
> before any dimension call and :
> this.getElement().getStyle().setDisplay(Display.NONE);
> after it if necessary, IE is then able to retrieve the correct width.
>
> On Sunday, 12 May 2013 16:11:34 UTC+2, Joachim Nielandt wrote:
>>
>> I've created a website that displays a numbers of images and draws them
>> on a canvas. Those images are PreloadedImage instances, and fire the draw
>> method on their load event. This works fine in Chrome but in Internet
>> Explorer their width are 0 when asked for (in Chrome, their width is
>> correct) using PreloadedImage.getWidth(), or getOffsetWidth(), or via
>> getElement().getStyle().getWidth()...
>>
>> When inspecting the instance of the PreloadedImage in Eclipse, i can see
>> that the element does have the correct width and height, but when it's
>> requested by GWT, the result is zero, resulting in incorrect drawing.
>>
>> Any ideas?
>>
>> - edit 1: tried it by waiting for the load to finish using a Timer:
>>
>> I did a quick try to wait for the image to render but it seems not to be
>> loading at all:
>>
>> currentImage = new PreloadedImage();
>> currentImage.addLoadHandler(new LoadHandler() {
>> @Override
>> public void onLoad(LoadEvent event) {
>> Timer timer = new Timer() {
>> @Override
>> public void run() {
>> System.out.println("timer check: width: "
>> +currentImage.getWidth());
>> if(currentImage.getWidth()>0) {
>> //draw the image
>> this.cancel();
>> }
>> }
>> };
>> timer.scheduleRepeating(100);
>> }
>> });
>>
>>
>> - edit 2: some more information:
>>
>> When the image is loaded, before drawing, I request its dimensions. When
>> inspecting currentImage (instance of PreloadedImage), the toString method
>> returns the following:
>>
>> <img aria-hidden="true"
>> style="display: none; visibility: hidden;"
>> class="PRELOADEDIMAGE"
>> src="/imageservlet?filename=1368280253128&height=1000" width="1505"
>> height="1000">
>>
>> Note that width and height are set correctly. However, when requesting
>> the following:
>>
>> currentImage.getWidth()
>> currentImage.getOffsetWidth()
>> String heightattr = e.getAttribute("height");
>>
>> I get consistently zero results. I suspected the encoding of the
>> ampersand to be a problem, but Internet Explorer deals with it the same way
>> as Chrome does (in the end, the same url is used to fetch the image, and it
>> is correct).
>>
>
--
You received this message because you are subscribed to the Google Groups
"Google Web Toolkit" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/google-web-toolkit?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.