Commit 69ebd508 authored by Colm Bennett's avatar Colm Bennett Committed by josmas

Fix for Image mock component issue where doing a Pixel size didn't show a...

Fix for Image mock component issue where doing a Pixel size didn't show a resize for the image in Designer.

Change-Id: Ie1d66f1997b60b2e9f82ba500c3c2e42d36386a5
parent 43d46d20
......@@ -209,7 +209,7 @@ public final class MockComponentsUtil {
* @return the previous size style attributes as an array with width at index
* 0 and height at index 1.
*/
private static String[] clearSizeStyle(Widget w) {
static String[] clearSizeStyle(Widget w) {
Element element = w.getElement();
String widthStyle = DOM.getStyleAttribute(element, "width");
String heightStyle = DOM.getStyleAttribute(element, "height");
......@@ -229,7 +229,7 @@ public final class MockComponentsUtil {
* @param style the size style attributes as an array with width at index 0
* and height at index 1.
*/
private static void restoreSizeStyle(Widget w, String[] style) {
static void restoreSizeStyle(Widget w, String[] style) {
Element element = w.getElement();
if (style[0] != null) {
DOM.setStyleAttribute(element, "width", style[0]);
......
......@@ -46,6 +46,8 @@ abstract class MockImageBase extends MockVisibleComponent {
image.addLoadHandler(new LoadHandler() {
@Override
public void onLoad(LoadEvent event) {
// Resize to outer container, fixes issue with setting precise size in designer
image.setSize("100%", "100%");
refreshForm();
}
});
......@@ -75,13 +77,21 @@ abstract class MockImageBase extends MockVisibleComponent {
@Override
public int getPreferredWidth() {
// The superclass uses getOffsetWidth, which won't work for us.
return image.getWidth();
// Hide away the current 100% size so we can get at the actual size, otherwise automatic size doesn't work
String[] style = MockComponentsUtil.clearSizeStyle(image);
int width = image.getWidth();
MockComponentsUtil.restoreSizeStyle(image, style);
return width;
}
@Override
public int getPreferredHeight() {
// The superclass uses getOffsetHeight, which won't work for us.
return image.getHeight();
// Hide away the current 100% size so we can get at the actual size, otherwise automatic size doesn't work
String[] style = MockComponentsUtil.clearSizeStyle(image);
int height = image.getHeight();
MockComponentsUtil.restoreSizeStyle(image, style);
return height;
}
// PropertyChangeListener implementation
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment