display: inline-block;
zoom: 1;
}
-.v-menubar .v-menubar-menuitem-caption * {
+.v-menubar .v-menubar-menuitem-caption .v-icon {
vertical-align: middle;
white-space: nowrap;
}
padding: 1px 26px 1px 10px;
line-height: 16px;
}
-.v-menubar-submenu .v-menubar-menuitem-caption * {
+.v-menubar-submenu .v-menubar-menuitem-caption .v-icon {
vertical-align: middle;
}
.v-menubar .v-menubar-menuitem-selected,
line-height: 16px;
padding-left: 10px;
}
-.v-menubar-submenu .v-menubar-menuitem-caption * {
+.v-menubar-submenu .v-menubar-menuitem-caption .v-icon {
vertical-align: middle;
}
\ No newline at end of file
public static final String ATTRIBUTE_CHECKED = "checked";
+ public static final String HTML_CONTENT_ALLOWED = "usehtml";
+
/** Widget fields **/
protected boolean subMenu;
protected ArrayList<CustomMenuItem> items;
private boolean openRootOnHover;
+ private boolean htmlContentAllowed;
+
public VMenuBar() {
// Create an empty horizontal menubar
this(false, null);
return;
}
+ htmlContentAllowed = uidl.hasAttribute(HTML_CONTENT_ALLOWED);
+
openRootOnHover = uidl.getBooleanAttribute(OPEN_ROOT_MENU_ON_HOWER);
enabled = !uidl.getBooleanAttribute("disabled");
+ Icon.CLASSNAME + "\" alt=\"\" />");
}
String itemText = item.getStringAttribute("text");
- itemHTML.append(Util.escapeHTML(itemText));
+ if (!htmlContentAllowed) {
+ itemText = Util.escapeHTML(itemText);
+ }
+ itemHTML.append(itemText);
itemHTML.append("</span>");
}
return itemHTML.toString();
private boolean openRootOnHover;
+ private boolean htmlContentAllowed;
+
/** Paint (serialise) the component for the client. */
@Override
public void paintContent(PaintTarget target) throws PaintException {
target.addAttribute(VMenuBar.OPEN_ROOT_MENU_ON_HOWER, openRootOnHover);
+ if (isHtmlContentAllowed()) {
+ target.addAttribute(VMenuBar.HTML_CONTENT_ALLOWED, true);
+ }
+
target.startTag("options");
if (submenuIcon != null) {
return openRootOnHover;
}
+ /**
+ * Sets whether html is allowed in the item captions. 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
+ * true if the captions are used as html, false if used as plain
+ * text
+ */
+ public void setHtmlContentAllowed(boolean htmlContentAllowed) {
+ this.htmlContentAllowed = htmlContentAllowed;
+ requestRepaint();
+ }
+
+ /**
+ * Checks whether item captions are interpreted as html or plain text.
+ *
+ * @return true if the captions are used as html, false if used as plain
+ * text
+ * @see #setHtmlContentAllowed(boolean)
+ */
+ public boolean isHtmlContentAllowed() {
+ return htmlContentAllowed;
+ }
+
/**
* This interface contains the layer for menu commands of the
* {@link com.vaadin.ui.MenuBar} class. It's method will fire when the user
--- /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>New Test</title>
+</head>
+<body>
+<table cellpadding="1" cellspacing="1" border="1">
+<thead>
+<tr><td rowspan="1" colspan="3">MenuBarHtmlItems</td></tr>
+</thead><tbody>
+<tr>
+ <td>open</td>
+ <td>/run/com.vaadin.tests.components.menubar.MenuBarHtmlItems?restartApplication</td>
+ <td></td>
+</tr>
+<tr>
+ <td>mouseClick</td>
+ <td>vaadin=runcomvaadintestscomponentsmenubarMenuBarHtmlItems::PID_Scheckboxaction-Html content allowed/domChild[0]</td>
+ <td>44,1</td>
+</tr>
+<tr>
+ <td>mouseClick</td>
+ <td>vaadin=runcomvaadintestscomponentsmenubarMenuBarHtmlItems::/VVerticalLayout[0]/ChildComponentContainer[1]/VVerticalLayout[0]/ChildComponentContainer[1]/VMenuBar[0]#item0</td>
+ <td>7,6</td>
+</tr>
+<tr>
+ <td>pressSpecialKey</td>
+ <td>vaadin=runcomvaadintestscomponentsmenubarMenuBarHtmlItems::/VVerticalLayout[0]/ChildComponentContainer[1]/VVerticalLayout[0]/ChildComponentContainer[1]/VMenuBar[0]</td>
+ <td>down</td>
+</tr>
+<tr>
+ <td>pressSpecialKey</td>
+ <td>vaadin=runcomvaadintestscomponentsmenubarMenuBarHtmlItems::/VVerticalLayout[0]/ChildComponentContainer[1]/VVerticalLayout[0]/ChildComponentContainer[1]/VMenuBar[0]</td>
+ <td>right</td>
+</tr>
+<tr>
+ <td>screenCapture</td>
+ <td></td>
+ <td>html</td>
+</tr>
+<tr>
+ <td>mouseClick</td>
+ <td>vaadin=runcomvaadintestscomponentsmenubarMenuBarHtmlItems::PID_Scheckboxaction-Html content allowed/domChild[0]</td>
+ <td>37,1</td>
+</tr>
+<tr>
+ <td>mouseClick</td>
+ <td>vaadin=runcomvaadintestscomponentsmenubarMenuBarHtmlItems::/VVerticalLayout[0]/ChildComponentContainer[1]/VVerticalLayout[0]/ChildComponentContainer[1]/VMenuBar[0]#item0</td>
+ <td>13,6</td>
+</tr>
+<tr>
+ <td>pressSpecialKey</td>
+ <td>vaadin=runcomvaadintestscomponentsmenubarMenuBarHtmlItems::/VVerticalLayout[0]/ChildComponentContainer[1]/VVerticalLayout[0]/ChildComponentContainer[1]/VMenuBar[0]</td>
+ <td>down</td>
+</tr>
+<tr>
+ <td>pressSpecialKey</td>
+ <td>vaadin=runcomvaadintestscomponentsmenubarMenuBarHtmlItems::/VVerticalLayout[0]/ChildComponentContainer[1]/VVerticalLayout[0]/ChildComponentContainer[1]/VMenuBar[0]</td>
+ <td>right</td>
+</tr>
+<tr>
+ <td>screenCapture</td>
+ <td></td>
+ <td>plain</td>
+</tr>
+
+</tbody></table>
+</body>
+</html>
--- /dev/null
+package com.vaadin.tests.components.menubar;
+
+import java.util.Arrays;
+import java.util.List;
+
+import com.vaadin.terminal.Resource;
+import com.vaadin.terminal.ThemeResource;
+import com.vaadin.tests.components.ComponentTestCase;
+import com.vaadin.ui.Component;
+import com.vaadin.ui.MenuBar;
+import com.vaadin.ui.MenuBar.MenuItem;
+
+public class MenuBarHtmlItems extends ComponentTestCase<MenuBar> {
+
+ @Override
+ protected Class<MenuBar> getTestClass() {
+ return MenuBar.class;
+ }
+
+ @Override
+ protected void initializeComponents() {
+ MenuBar m = new MenuBar();
+ MenuItem submenu = m.addItem("Item <u>1</u>", getIcon(), null);
+ MenuItem subsubmenu = submenu.addItem("<b>Bold</b> item", null);
+ subsubmenu.addItem("<i><u>I</u>talic</i> item", getIcon(), null);
+ submenu.addItem(
+ "<span style='font-size: 30px'>Big</span> <span style='font-size: 8px'>disabled</span> item",
+ null).setEnabled(false);
+
+ m.addItem("<span style='font-size: 30px'>Big</span> item", null);
+
+ addTestComponent(m);
+ }
+
+ private Resource getIcon() {
+ return new ThemeResource("../runo/icons/16/user.png");
+ }
+
+ @Override
+ protected List<Component> createActions() {
+ return Arrays.asList(createSwitchHtmlAction());
+ }
+
+ private Component createSwitchHtmlAction() {
+ return createBooleanAction("Html content allowed", false,
+ new Command<MenuBar, Boolean>() {
+ public void execute(MenuBar c, Boolean value, Object data) {
+ c.setHtmlContentAllowed(value.booleanValue());
+ }
+ });
+ }
+
+ @Override
+ protected Integer getTicketNumber() {
+ return 7187;
+ }
+
+ @Override
+ protected String getDescription() {
+ return "A menu containing items with embedded html. Items should chould either render the html or show it as plain text depending on the setting.";
+ }
+
+}
<body>
<table cellpadding="1" cellspacing="1" border="1">
<thead>
-<tr><td rowspan="1" colspan="3">New Test</td></tr>
+<tr><td rowspan="1" colspan="3">HtmlOptionGroupItems</td></tr>
</thead><tbody>
<tr>
<td>open</td>