From: John Ahlroos Date: Fri, 12 Oct 2012 07:19:10 +0000 (+0300) Subject: Fixed primary stylename handling for CustomLayout #9902 X-Git-Tag: 7.0.0.beta6~47^2 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=f2d4abba38a8d9d3bfea780254c3f65f030f7a17;p=vaadin-framework.git Fixed primary stylename handling for CustomLayout #9902 Change-Id: I8ec0da24e73cc182b6d7df6409c348bb61e61d47 --- 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 @@ + + + + + + +New Test + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
New Test
open/run/com.vaadin.tests.components.customlayout.CustomLayoutPrimaryStyleName?restartApplication
assertNotCSSClassvaadin=runcomvaadintestscomponentscustomlayoutCustomLayoutPrimaryStyleName::/VVerticalLayout[0]/VOrderedLayout$Slot[1]/VVerticalLayout[0]/VOrderedLayout$Slot[0]/VCustomLayout[0]/v-customlayout
assertCSSClassvaadin=runcomvaadintestscomponentscustomlayoutCustomLayoutPrimaryStyleName::/VVerticalLayout[0]/VOrderedLayout$Slot[1]/VVerticalLayout[0]/VOrderedLayout$Slot[0]/VCustomLayout[0]/my-customlayout
clickvaadin=runcomvaadintestscomponentscustomlayoutCustomLayoutPrimaryStyleName::/VVerticalLayout[0]/VOrderedLayout$Slot[1]/VVerticalLayout[0]/VOrderedLayout$Slot[1]/VButton[0]/domChild[0]/domChild[0]
assertNotCSSClassvaadin=runcomvaadintestscomponentscustomlayoutCustomLayoutPrimaryStyleName::/VVerticalLayout[0]/VOrderedLayout$Slot[1]/VVerticalLayout[0]/VOrderedLayout$Slot[0]/VCustomLayout[0]/my-customlayout
assertCSSClassvaadin=runcomvaadintestscomponentscustomlayoutCustomLayoutPrimaryStyleName::/VVerticalLayout[0]/VOrderedLayout$Slot[1]/VVerticalLayout[0]/VOrderedLayout$Slot[0]/VCustomLayout[0]/my-second-customlayout
+ + 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( + "
".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; + } + +}