diff options
author | Leif Åstrand <leif@vaadin.com> | 2011-08-10 07:04:37 +0000 |
---|---|---|
committer | Leif Åstrand <leif@vaadin.com> | 2011-08-10 07:04:37 +0000 |
commit | 35887c66f84f0ca4f0b5d5803f24bbcc32cca15a (patch) | |
tree | 7cb57050db06a9e5e709bfa000a5bde783e2c829 | |
parent | a41fbd0e685cc8f63b79805a5171777b2153807f (diff) | |
download | vaadin-framework-35887c66f84f0ca4f0b5d5803f24bbcc32cca15a.tar.gz vaadin-framework-35887c66f84f0ca4f0b5d5803f24bbcc32cca15a.zip |
#7187 Allow HTML content in an MenuItem
svn changeset:20245/svn branch:6.7
8 files changed, 181 insertions, 5 deletions
diff --git a/WebContent/VAADIN/themes/base/menubar/menubar.css b/WebContent/VAADIN/themes/base/menubar/menubar.css index 042ec15d1d..8b44085c28 100644 --- a/WebContent/VAADIN/themes/base/menubar/menubar.css +++ b/WebContent/VAADIN/themes/base/menubar/menubar.css @@ -10,7 +10,7 @@ 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; } diff --git a/WebContent/VAADIN/themes/reindeer/menubar/menubar.css b/WebContent/VAADIN/themes/reindeer/menubar/menubar.css index e5e337725e..165eacc840 100644 --- a/WebContent/VAADIN/themes/reindeer/menubar/menubar.css +++ b/WebContent/VAADIN/themes/reindeer/menubar/menubar.css @@ -28,7 +28,7 @@ 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, diff --git a/WebContent/VAADIN/themes/runo/menubar/menubar.css b/WebContent/VAADIN/themes/runo/menubar/menubar.css index 7c1a4036b3..91cf78189d 100644 --- a/WebContent/VAADIN/themes/runo/menubar/menubar.css +++ b/WebContent/VAADIN/themes/runo/menubar/menubar.css @@ -30,6 +30,6 @@ 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 diff --git a/src/com/vaadin/terminal/gwt/client/ui/VMenuBar.java b/src/com/vaadin/terminal/gwt/client/ui/VMenuBar.java index 4d43b7c346..f74ff4a1f5 100644 --- a/src/com/vaadin/terminal/gwt/client/ui/VMenuBar.java +++ b/src/com/vaadin/terminal/gwt/client/ui/VMenuBar.java @@ -69,6 +69,8 @@ public class VMenuBar extends SimpleFocusablePanel implements Paintable, public static final String ATTRIBUTE_CHECKED = "checked"; + public static final String HTML_CONTENT_ALLOWED = "usehtml"; + /** Widget fields **/ protected boolean subMenu; protected ArrayList<CustomMenuItem> items; @@ -93,6 +95,8 @@ public class VMenuBar extends SimpleFocusablePanel implements Paintable, private boolean openRootOnHover; + private boolean htmlContentAllowed; + public VMenuBar() { // Create an empty horizontal menubar this(false, null); @@ -191,6 +195,8 @@ public class VMenuBar extends SimpleFocusablePanel implements Paintable, return; } + htmlContentAllowed = uidl.hasAttribute(HTML_CONTENT_ALLOWED); + openRootOnHover = uidl.getBooleanAttribute(OPEN_ROOT_MENU_ON_HOWER); enabled = !uidl.getBooleanAttribute("disabled"); @@ -342,7 +348,10 @@ public class VMenuBar extends SimpleFocusablePanel implements Paintable, + 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(); diff --git a/src/com/vaadin/ui/MenuBar.java b/src/com/vaadin/ui/MenuBar.java index f8fbf91712..4aae9b2621 100644 --- a/src/com/vaadin/ui/MenuBar.java +++ b/src/com/vaadin/ui/MenuBar.java @@ -51,6 +51,8 @@ public class MenuBar extends AbstractComponent { private boolean openRootOnHover; + private boolean htmlContentAllowed; + /** Paint (serialise) the component for the client. */ @Override public void paintContent(PaintTarget target) throws PaintException { @@ -60,6 +62,10 @@ public class MenuBar extends AbstractComponent { target.addAttribute(VMenuBar.OPEN_ROOT_MENU_ON_HOWER, openRootOnHover); + if (isHtmlContentAllowed()) { + target.addAttribute(VMenuBar.HTML_CONTENT_ALLOWED, true); + } + target.startTag("options"); if (submenuIcon != null) { @@ -411,6 +417,32 @@ public class MenuBar extends AbstractComponent { } /** + * 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 * clicks on the containing {@link com.vaadin.ui.MenuBar.MenuItem}. The diff --git a/tests/src/com/vaadin/tests/components/menubar/MenuBarHtmlItems.html b/tests/src/com/vaadin/tests/components/menubar/MenuBarHtmlItems.html new file mode 100644 index 0000000000..2878018752 --- /dev/null +++ b/tests/src/com/vaadin/tests/components/menubar/MenuBarHtmlItems.html @@ -0,0 +1,72 @@ +<?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> diff --git a/tests/src/com/vaadin/tests/components/menubar/MenuBarHtmlItems.java b/tests/src/com/vaadin/tests/components/menubar/MenuBarHtmlItems.java new file mode 100644 index 0000000000..ba22bcb7a4 --- /dev/null +++ b/tests/src/com/vaadin/tests/components/menubar/MenuBarHtmlItems.java @@ -0,0 +1,63 @@ +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."; + } + +} diff --git a/tests/src/com/vaadin/tests/components/optiongroup/HtmlOptionGroupItems.html b/tests/src/com/vaadin/tests/components/optiongroup/HtmlOptionGroupItems.html index af6f74b3df..d74354299d 100644 --- a/tests/src/com/vaadin/tests/components/optiongroup/HtmlOptionGroupItems.html +++ b/tests/src/com/vaadin/tests/components/optiongroup/HtmlOptionGroupItems.html @@ -9,7 +9,7 @@ <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> |