aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorStefan Winkler2014-04-01 14:49:00 (EDT)
committerBrian de Alwis2014-04-03 09:33:29 (EDT)
commit9564a09045e4238087997be55f9e6603f8e47806 (patch)
tree203cd0604c3f8c57ba37619d4cf1ef02e8db61be
parent29bb58b693e30bc43d9847eb42a2a82182d34ba1 (diff)
downloadeclipse.platform.ui-9564a09045e4238087997be55f9e6603f8e47806.zip
eclipse.platform.ui-9564a09045e4238087997be55f9e6603f8e47806.tar.gz
eclipse.platform.ui-9564a09045e4238087997be55f9e6603f8e47806.tar.bz2
Bug 431742 - [CSS] Provide support for inner-class selectorsrefs/changes/81/24281/2
Change-Id: I31907396a92520744806ffcaa8a25be8d0a668ee Signed-off-by: Stefan Winkler <stefan@winklerweb.net>
-rw-r--r--bundles/org.eclipse.e4.ui.css.core/src/org/eclipse/e4/ui/css/core/utils/ClassUtils.java5
-rw-r--r--bundles/org.eclipse.e4.ui.css.swt/src/org/eclipse/e4/ui/css/swt/dom/WidgetElement.java29
-rw-r--r--tests/org.eclipse.e4.ui.tests.css.swt/src/org/eclipse/e4/ui/tests/css/swt/CssSwtTestSuite.java3
-rw-r--r--tests/org.eclipse.e4.ui.tests.css.swt/src/org/eclipse/e4/ui/tests/css/swt/InnerClassElementTest.java60
4 files changed, 83 insertions, 14 deletions
diff --git a/bundles/org.eclipse.e4.ui.css.core/src/org/eclipse/e4/ui/css/core/utils/ClassUtils.java b/bundles/org.eclipse.e4.ui.css.core/src/org/eclipse/e4/ui/css/core/utils/ClassUtils.java
index a90896b..0735a96 100644
--- a/bundles/org.eclipse.e4.ui.css.core/src/org/eclipse/e4/ui/css/core/utils/ClassUtils.java
+++ b/bundles/org.eclipse.e4.ui.css.core/src/org/eclipse/e4/ui/css/core/utils/ClassUtils.java
@@ -27,6 +27,11 @@ public class ClassUtils {
if (index > 0) {
name = name.substring(index + 1, name.length());
}
+
+ // inner classes contain a "$" as in Outer$Inner. As "$" is not allowed
+ // as part of a CSS selector
+ // we translate a "$" into a "-" here.
+ name = name.replace('$', '-');
return name;
}
diff --git a/bundles/org.eclipse.e4.ui.css.swt/src/org/eclipse/e4/ui/css/swt/dom/WidgetElement.java b/bundles/org.eclipse.e4.ui.css.swt/src/org/eclipse/e4/ui/css/swt/dom/WidgetElement.java
index ea7b72e..4dfc928 100644
--- a/bundles/org.eclipse.e4.ui.css.swt/src/org/eclipse/e4/ui/css/swt/dom/WidgetElement.java
+++ b/bundles/org.eclipse.e4.ui.css.swt/src/org/eclipse/e4/ui/css/swt/dom/WidgetElement.java
@@ -24,7 +24,7 @@ import org.w3c.dom.NodeList;
/**
* {@link CSSStylableElement} implementation which wrap SWT {@link Widget}.
- *
+ *
*/
public class WidgetElement extends ElementAdapter implements NodeList {
@@ -33,7 +33,7 @@ public class WidgetElement extends ElementAdapter implements NodeList {
/**
* Convenience method for getting the CSS class of a widget.
- *
+ *
* @param widget
* SWT widget with associated CSS class name
* @return CSS class name
@@ -44,7 +44,7 @@ public class WidgetElement extends ElementAdapter implements NodeList {
/**
* Convenience method for getting the CSS ID of a widget.
- *
+ *
* @param widget
* SWT widget with associated CSS id
* @return CSS ID
@@ -55,7 +55,7 @@ public class WidgetElement extends ElementAdapter implements NodeList {
/**
* Convenience method for setting the CSS class of a widget.
- *
+ *
* @param widget
* SWT widget with associated CSS class name
* @param className
@@ -67,7 +67,7 @@ public class WidgetElement extends ElementAdapter implements NodeList {
/**
* Convenience method for setting the CSS ID of a widget.
- *
+ *
* @param widget
* SWT widget with associated CSS id
* @param id
@@ -87,7 +87,7 @@ public class WidgetElement extends ElementAdapter implements NodeList {
/**
* Convenience method for getting the CSS engine responsible for a widget.
- *
+ *
* @param display
* SWT display which is styled by an engine
*/
@@ -120,7 +120,7 @@ public class WidgetElement extends ElementAdapter implements NodeList {
/**
* Compute local name.
- *
+ *
* @return
*/
protected String computeLocalName() {
@@ -130,6 +130,9 @@ public class WidgetElement extends ElementAdapter implements NodeList {
// localName is Label
// CSS selector will use this localName
// ex : Label {background-color:red;}
+
+ // for inner classes, the hyphen is used, e.g., for Outer$Inner,
+ // the selector is Outer-Inner {background-color:red;}
Widget widget = getWidget();
Class clazz = widget.getClass();
return ClassUtils.getSimpleName(clazz);
@@ -137,7 +140,7 @@ public class WidgetElement extends ElementAdapter implements NodeList {
/**
* Compute namespaceURI.
- *
+ *
* @return
*/
protected String computeNamespaceURI() {
@@ -155,7 +158,7 @@ public class WidgetElement extends ElementAdapter implements NodeList {
/**
* Compute static pseudo instances.
- *
+ *
*/
protected void computeStaticPseudoInstances() {
@@ -163,7 +166,7 @@ public class WidgetElement extends ElementAdapter implements NodeList {
/**
* Compute attribute SWT style.
- *
+ *
* @return
*/
protected String computeAttributeSWTStyle() {
@@ -172,7 +175,7 @@ public class WidgetElement extends ElementAdapter implements NodeList {
/*
* (non-Javadoc)
- *
+ *
* @see
* org.eclipse.e4.ui.css.core.dom.ElementAdapter#getAttribute(java.lang.
* String)
@@ -261,7 +264,7 @@ public class WidgetElement extends ElementAdapter implements NodeList {
/*
* (non-Javadoc)
- *
+ *
* @see org.eclipse.e4.ui.css.core.dom.CSSStylableElement#getCSSClass()
*/
@Override
@@ -276,7 +279,7 @@ public class WidgetElement extends ElementAdapter implements NodeList {
/*
* (non-Javadoc)
- *
+ *
* @see org.eclipse.e4.ui.css.core.dom.CSSStylableElement#getCSSStyle()
*/
@Override
diff --git a/tests/org.eclipse.e4.ui.tests.css.swt/src/org/eclipse/e4/ui/tests/css/swt/CssSwtTestSuite.java b/tests/org.eclipse.e4.ui.tests.css.swt/src/org/eclipse/e4/ui/tests/css/swt/CssSwtTestSuite.java
index 2dea086..f070201 100644
--- a/tests/org.eclipse.e4.ui.tests.css.swt/src/org/eclipse/e4/ui/tests/css/swt/CssSwtTestSuite.java
+++ b/tests/org.eclipse.e4.ui.tests.css.swt/src/org/eclipse/e4/ui/tests/css/swt/CssSwtTestSuite.java
@@ -3,7 +3,7 @@
* program and the accompanying materials are made available under the terms of
* the Eclipse Public License v1.0 which accompanies this distribution, and is
* available at http://www.eclipse.org/legal/epl-v10.html
- *
+ *
* Contributors:
* IBM Corporation - initial API and implementation
*******************************************************************************/
@@ -50,6 +50,7 @@ public class CssSwtTestSuite extends TestSuite {
// addTestSuite(ShellActiveTest.class); //TODO see bug #273582
addTestSuite(GradientTest.class);
addTestSuite(MarginTest.class);
+ addTestSuite(InnerClassElementTest.class);
// text-transform tests
addTestSuite(ButtonTextTransformTest.class);
diff --git a/tests/org.eclipse.e4.ui.tests.css.swt/src/org/eclipse/e4/ui/tests/css/swt/InnerClassElementTest.java b/tests/org.eclipse.e4.ui.tests.css.swt/src/org/eclipse/e4/ui/tests/css/swt/InnerClassElementTest.java
new file mode 100644
index 0000000..96c6063
--- /dev/null
+++ b/tests/org.eclipse.e4.ui.tests.css.swt/src/org/eclipse/e4/ui/tests/css/swt/InnerClassElementTest.java
@@ -0,0 +1,60 @@
+/*******************************************************************************
+ * Copyright (c) 2014 Stefan Winkler and others. All rights reserved. This
+ * program and the accompanying materials are made available under the terms of
+ * the Eclipse Public License v1.0 which accompanies this distribution, and is
+ * available at http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Stefan Winkler <stefan@winklerweb.net> - initial API and implementation
+ *******************************************************************************/
+
+package org.eclipse.e4.ui.tests.css.swt;
+
+import org.eclipse.e4.ui.css.core.engine.CSSEngine;
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.layout.FillLayout;
+import org.eclipse.swt.widgets.Composite;
+import org.eclipse.swt.widgets.Display;
+import org.eclipse.swt.widgets.Label;
+import org.eclipse.swt.widgets.Shell;
+
+public class InnerClassElementTest extends CSSSWTTestCase {
+
+ CSSEngine engine;
+
+ // create an inner class to address via CSS
+ class CustomComposite extends Composite {
+ public CustomComposite(Composite parent, int style) {
+ super(parent, style);
+ }
+ }
+
+ protected Label createTestLabel(String styleSheet) {
+ Display display = Display.getDefault();
+ engine = createEngine(styleSheet, display);
+
+ // Create widgets
+ Shell shell = new Shell(display, SWT.SHELL_TRIM);
+ FillLayout layout = new FillLayout();
+ shell.setLayout(layout);
+
+ CustomComposite composite = new CustomComposite(shell, SWT.NONE);
+ composite.setLayout(new FillLayout());
+
+ Label labelToTest = new Label(composite, SWT.NONE);
+ labelToTest.setText("Some label text");
+
+ // Apply styles
+ engine.applyStyles(labelToTest, true);
+
+ return labelToTest;
+ }
+
+ public void testInnerClassElement() throws Exception {
+ Label label = createTestLabel("InnerClassElementTest-CustomComposite Label { color: #00ffa0; }");
+
+ assertEquals(0x00, label.getForeground().getRed());
+ assertEquals(0xff, label.getForeground().getGreen());
+ assertEquals(0xa0, label.getForeground().getBlue());
+ }
+}