private int clickShortcut = 0;
+ /**
+ * If caption should be rendered in HTML
+ */
+ protected boolean htmlCaption = false;
+
public VButton() {
super(DOM.createDiv());
setTabIndex(0);
this.client = client;
id = uidl.getId();
+ // Update HTML value before setting text
+ htmlCaption = uidl.hasAttribute("html-caption")
+ && uidl.getBooleanAttribute("html-caption");
+
// Set text
setText(uidl.getStringAttribute("caption"));
}
public void setText(String text) {
- captionElement.setInnerText(text);
+ if (htmlCaption) {
+ captionElement.setInnerHTML(text);
+ } else {
+ captionElement.setInnerText(text);
+ }
}
@SuppressWarnings("deprecation")
private boolean disableOnClick = false;
+ /**
+ * If caption should be rendered in HTML
+ */
+ protected boolean htmlCaption = false;
+
public VNativeButton() {
setStyleName(CLASSNAME);
this.client = client;
id = uidl.getId();
+ // Update HTML value before setting text
+ htmlCaption = uidl.hasAttribute("html-caption")
+ && uidl.getBooleanAttribute("html-caption");
+
// Set text
setText(uidl.getStringAttribute("caption"));
@Override
public void setText(String text) {
- captionElement.setInnerText(text);
+ if (htmlCaption) {
+ captionElement.setInnerHTML(text);
+ } else {
+ captionElement.setInnerText(text);
+ }
}
@Override
boolean disableOnClick = false;
+ /**
+ * If caption is rendered as HTML
+ */
+ private boolean htmlContentAllowed = false;
+
/**
* Creates a new push button. The value of the push button is false and it
* is immediate by default.
if (clickShortcut != null) {
target.addAttribute("keycode", clickShortcut.getKeyCode());
}
+
+ if (isHtmlContentAllowed()) {
+ target.addAttribute("html-caption", true);
+ }
}
/**
requestRepaint();
}
+ /**
+ * Set whether the caption text is rendered as HTML or not. You might need
+ * to retheme button to allow higher content than the original text style.
+ *
+ * If set to true, the captions are passed to the browser as html and the
+ * developer is responsible for ensuring no harmful html is used. If set to
+ * false, the content is passed to the browser as plain text.
+ *
+ * @param htmlContentAllowed
+ * <code>true</code> if caption is rendered as HTML,
+ * <code>false</code> otherwise
+ */
+ public void setHtmlContentAllowed(boolean htmlContentAllowed) {
+ if (this.htmlContentAllowed != htmlContentAllowed) {
+ this.htmlContentAllowed = htmlContentAllowed;
+ requestRepaint();
+ }
+ }
+
+ /**
+ * Return HTML rendering setting
+ *
+ * @return <code>true</code> if the caption text is to be rendered as HTML,
+ * <code>false</code> otherwise
+ */
+ public boolean isHtmlContentAllowed() {
+ return htmlContentAllowed;
+ }
+
}
--- /dev/null
+<?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="" />
+<title>ButtonHtml</title>
+</head>
+<body>
+<table cellpadding="1" cellspacing="1" border="1">
+<thead>
+<tr><td rowspan="1" colspan="3">ButtonHtml</td></tr>
+</thead><tbody>
+<tr>
+ <td>open</td>
+ <td>/run/com.vaadin.tests.components.button.ButtonHtml?restartApplication</td>
+ <td></td>
+</tr>
+<tr>
+ <td>screenCapture</td>
+ <td></td>
+ <td>initial</td>
+</tr>
+<tr>
+ <td>click</td>
+ <td>vaadin=runcomvaadintestscomponentsbuttonButtonHtml::/VVerticalLayout[0]/ChildComponentContainer[1]/VVerticalLayout[0]/ChildComponentContainer[2]/VButton[0]/domChild[0]/domChild[0]</td>
+ <td></td>
+</tr>
+<tr>
+ <td>screenCapture</td>
+ <td></td>
+ <td>after_1_click</td>
+</tr>
+<tr>
+ <td>click</td>
+ <td>vaadin=runcomvaadintestscomponentsbuttonButtonHtml::/VVerticalLayout[0]/ChildComponentContainer[1]/VVerticalLayout[0]/ChildComponentContainer[2]/VButton[0]/domChild[0]/domChild[0]/domChild[0]</td>
+ <td></td>
+</tr>
+<tr>
+ <td>screenCapture</td>
+ <td></td>
+ <td>after_2_clicks</td>
+</tr>
+
+</tbody></table>
+</body>
+</html>
--- /dev/null
+package com.vaadin.tests.components.button;
+
+import com.vaadin.tests.components.TestBase;
+import com.vaadin.ui.Button;
+import com.vaadin.ui.Button.ClickEvent;
+
+public class ButtonHtml extends TestBase {
+
+ @Override
+ protected void setup() {
+ Button b = new Button("<b>Plain text button</b>");
+ addComponent(b);
+
+ b = new Button(
+ "<span style=\"color: red; font-weight: bold;\">HTML</span> button");
+ b.setHtmlContentAllowed(true);
+ addComponent(b);
+
+ final Button swapButton = new Button("<i>Swap button<i>");
+ swapButton.addListener(new Button.ClickListener() {
+
+ public void buttonClick(ClickEvent event) {
+ swapButton.setHtmlContentAllowed(!swapButton
+ .isHtmlContentAllowed());
+ }
+ });
+ addComponent(swapButton);
+ }
+
+ @Override
+ protected String getDescription() {
+ return "Verify that Button HTML rendering works";
+ }
+
+ @Override
+ protected Integer getTicketNumber() {
+ return 8663;
+ }
+}
--- /dev/null
+<?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="" />
+<title>NativeButtonHtml</title>
+</head>
+<body>
+<table cellpadding="1" cellspacing="1" border="1">
+<thead>
+<tr><td rowspan="1" colspan="3">NativeButtonHtml</td></tr>
+</thead><tbody>
+<tr>
+ <td>open</td>
+ <td>/run/com.vaadin.tests.components.nativebutton.NativeButtonHtml?restartApplication</td>
+ <td></td>
+</tr>
+<tr>
+ <td>screenCapture</td>
+ <td></td>
+ <td>initial</td>
+</tr>
+<tr>
+ <td>mouseClick</td>
+ <td>vaadin=runcomvaadintestscomponentsnativebuttonNativeButtonHtml::/VVerticalLayout[0]/ChildComponentContainer[1]/VVerticalLayout[0]/ChildComponentContainer[2]/VNativeButton[0]</td>
+ <td>116,9</td>
+</tr>
+<tr>
+ <td>screenCapture</td>
+ <td></td>
+ <td>after_1_click</td>
+</tr>
+<tr>
+ <td>mouseClick</td>
+ <td>vaadin=runcomvaadintestscomponentsnativebuttonNativeButtonHtml::/VVerticalLayout[0]/ChildComponentContainer[1]/VVerticalLayout[0]/ChildComponentContainer[2]/VNativeButton[0]</td>
+ <td>74,10</td>
+</tr>
+<tr>
+ <td>screenCapture</td>
+ <td></td>
+ <td>after_2_clicks</td>
+</tr>
+
+</tbody></table>
+</body>
+</html>
--- /dev/null
+package com.vaadin.tests.components.nativebutton;
+
+import com.vaadin.tests.components.TestBase;
+import com.vaadin.ui.Button;
+import com.vaadin.ui.Button.ClickEvent;
+import com.vaadin.ui.NativeButton;
+
+public class NativeButtonHtml extends TestBase {
+
+ @Override
+ protected void setup() {
+ NativeButton b = new NativeButton("<b>Plain text button</b>");
+ addComponent(b);
+
+ b = new NativeButton(
+ "<span style=\"color: red; font-weight: bold;\">HTML</span> button");
+ b.setHtmlContentAllowed(true);
+ addComponent(b);
+
+ final NativeButton swapButton = new NativeButton("<i>Swap button<i>");
+ swapButton.addListener(new Button.ClickListener() {
+
+ public void buttonClick(ClickEvent event) {
+ swapButton.setHtmlContentAllowed(!swapButton
+ .isHtmlContentAllowed());
+ }
+ });
+ addComponent(swapButton);
+ }
+
+ @Override
+ protected String getDescription() {
+ return "Verify that NativeButton HTML rendering works";
+ }
+
+ @Override
+ protected Integer getTicketNumber() {
+ // 8663 was for normal button (see ButtonHtml test)
+ return null;
+ }
+}