diff options
author | John Ahlroos <john@vaadin.com> | 2012-10-12 10:19:10 +0300 |
---|---|---|
committer | John Ahlroos <john@vaadin.com> | 2012-10-12 10:21:09 +0300 |
commit | f2d4abba38a8d9d3bfea780254c3f65f030f7a17 (patch) | |
tree | 537cb47bf7281ad9c4dc04b36c49e8730ab645cc | |
parent | 081d5dc14015838be5b358632474997a8b8855ba (diff) | |
download | vaadin-framework-f2d4abba38a8d9d3bfea780254c3f65f030f7a17.tar.gz vaadin-framework-f2d4abba38a8d9d3bfea780254c3f65f030f7a17.zip |
Fixed primary stylename handling for CustomLayout #9902
Change-Id: I8ec0da24e73cc182b6d7df6409c348bb61e61d47
3 files changed, 114 insertions, 6 deletions
diff --git a/client/src/com/vaadin/client/ui/customlayout/VCustomLayout.java b/client/src/com/vaadin/client/ui/customlayout/VCustomLayout.java index 7a512fac49..803b266550 100644 --- a/client/src/com/vaadin/client/ui/customlayout/VCustomLayout.java +++ b/client/src/com/vaadin/client/ui/customlayout/VCustomLayout.java @@ -21,6 +21,10 @@ import java.util.Iterator; import com.google.gwt.dom.client.ImageElement; import com.google.gwt.dom.client.NodeList; +import com.google.gwt.dom.client.Style; +import com.google.gwt.dom.client.Style.BorderStyle; +import com.google.gwt.dom.client.Style.Position; +import com.google.gwt.dom.client.Style.Unit; import com.google.gwt.user.client.DOM; import com.google.gwt.user.client.Element; import com.google.gwt.user.client.Event; @@ -75,16 +79,22 @@ public class VCustomLayout extends ComplexPanel { public VCustomLayout() { setElement(DOM.createDiv()); // Clear any unwanted styling - DOM.setStyleAttribute(getElement(), "border", "none"); - DOM.setStyleAttribute(getElement(), "margin", "0"); - DOM.setStyleAttribute(getElement(), "padding", "0"); + Style style = getElement().getStyle(); + style.setBorderStyle(BorderStyle.NONE); + style.setMargin(0, Unit.PX); + style.setPadding(0, Unit.PX); if (BrowserInfo.get().isIE()) { - DOM.setStyleAttribute(getElement(), "position", "relative"); + style.setPosition(Position.RELATIVE); } - setStyleName(StyleConstants.UI_LAYOUT); - addStyleName(CLASSNAME); + setStyleName(CLASSNAME); + } + + @Override + public void setStyleName(String style) { + super.setStyleName(style); + addStyleName(StyleConstants.UI_LAYOUT); } /** diff --git a/uitest/src/com/vaadin/tests/components/customlayout/CustomLayoutPrimaryStyleName.html b/uitest/src/com/vaadin/tests/components/customlayout/CustomLayoutPrimaryStyleName.html new file mode 100644 index 0000000000..0a5654bb1f --- /dev/null +++ b/uitest/src/com/vaadin/tests/components/customlayout/CustomLayoutPrimaryStyleName.html @@ -0,0 +1,47 @@ +<?xml version="1.0" encoding="UTF-8"?> +<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> +<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"> +<head profile="http://selenium-ide.openqa.org/profiles/test-case"> +<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /> +<link rel="selenium.base" href="http://localhost:8888/" /> +<title>New Test</title> +</head> +<body> +<table cellpadding="1" cellspacing="1" border="1"> +<thead> +<tr><td rowspan="1" colspan="3">New Test</td></tr> +</thead><tbody> +<tr> + <td>open</td> + <td>/run/com.vaadin.tests.components.customlayout.CustomLayoutPrimaryStyleName?restartApplication</td> + <td></td> +</tr> +<tr> + <td>assertNotCSSClass</td> + <td>vaadin=runcomvaadintestscomponentscustomlayoutCustomLayoutPrimaryStyleName::/VVerticalLayout[0]/VOrderedLayout$Slot[1]/VVerticalLayout[0]/VOrderedLayout$Slot[0]/VCustomLayout[0]/</td> + <td>v-customlayout</td> +</tr> +<tr> + <td>assertCSSClass</td> + <td>vaadin=runcomvaadintestscomponentscustomlayoutCustomLayoutPrimaryStyleName::/VVerticalLayout[0]/VOrderedLayout$Slot[1]/VVerticalLayout[0]/VOrderedLayout$Slot[0]/VCustomLayout[0]/</td> + <td>my-customlayout</td> +</tr> +<tr> + <td>click</td> + <td>vaadin=runcomvaadintestscomponentscustomlayoutCustomLayoutPrimaryStyleName::/VVerticalLayout[0]/VOrderedLayout$Slot[1]/VVerticalLayout[0]/VOrderedLayout$Slot[1]/VButton[0]/domChild[0]/domChild[0]</td> + <td></td> +</tr> +<tr> + <td>assertNotCSSClass</td> + <td>vaadin=runcomvaadintestscomponentscustomlayoutCustomLayoutPrimaryStyleName::/VVerticalLayout[0]/VOrderedLayout$Slot[1]/VVerticalLayout[0]/VOrderedLayout$Slot[0]/VCustomLayout[0]/</td> + <td>my-customlayout</td> +</tr> +<tr> + <td>assertCSSClass</td> + <td>vaadin=runcomvaadintestscomponentscustomlayoutCustomLayoutPrimaryStyleName::/VVerticalLayout[0]/VOrderedLayout$Slot[1]/VVerticalLayout[0]/VOrderedLayout$Slot[0]/VCustomLayout[0]/</td> + <td>my-second-customlayout</td> +</tr> + +</tbody></table> +</body> +</html> diff --git a/uitest/src/com/vaadin/tests/components/customlayout/CustomLayoutPrimaryStyleName.java b/uitest/src/com/vaadin/tests/components/customlayout/CustomLayoutPrimaryStyleName.java new file mode 100644 index 0000000000..f0dc711f48 --- /dev/null +++ b/uitest/src/com/vaadin/tests/components/customlayout/CustomLayoutPrimaryStyleName.java @@ -0,0 +1,51 @@ +package com.vaadin.tests.components.customlayout; + +import java.io.ByteArrayInputStream; +import java.io.IOException; +import java.io.InputStream; + +import com.vaadin.tests.components.TestBase; +import com.vaadin.ui.Button; +import com.vaadin.ui.Button.ClickEvent; +import com.vaadin.ui.CustomLayout; +import com.vaadin.ui.TextField; + +public class CustomLayoutPrimaryStyleName extends TestBase { + + @Override + protected void setup() { + InputStream is = new ByteArrayInputStream( + "<div location='loc1'>".getBytes()); + try { + final CustomLayout cl = new CustomLayout(is); + + cl.addComponent(new TextField("Hello world"), "loc1"); + + cl.setPrimaryStyleName("my-customlayout"); + addComponent(cl); + + addComponent(new Button("Set primary stylename", + new Button.ClickListener() { + @Override + public void buttonClick(ClickEvent event) { + cl.setPrimaryStyleName("my-second-customlayout"); + } + })); + + } catch (IOException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + } + + @Override + protected String getDescription() { + return "CustomLayout should support primary stylenames both initially and dynamically"; + } + + @Override + protected Integer getTicketNumber() { + return 9902; + } + +} |