Added a dependent style name to the MenuBarPopup based on the primary style name of the MenuBar. This allows users to style MenuBar popups differently from each other. Currently, all MenuBar popups look identical.
Patch by: jlabanca
Review by: ajr
Issue: 1169
git-svn-id: https://google-web-toolkit.googlecode.com/svn/trunk@3060 8db76d5a-ed1c-0410-87a9-c151d255dfc7
diff --git a/reference/code-museum/src/com/google/gwt/museum/client/defaultmuseum/DefaultMuseum.java b/reference/code-museum/src/com/google/gwt/museum/client/defaultmuseum/DefaultMuseum.java
index 84231ce..46a22be 100644
--- a/reference/code-museum/src/com/google/gwt/museum/client/defaultmuseum/DefaultMuseum.java
+++ b/reference/code-museum/src/com/google/gwt/museum/client/defaultmuseum/DefaultMuseum.java
@@ -35,6 +35,7 @@
addIssue(new Issue2331());
addIssue(new Issue2338());
addIssue(new Issue2339());
+ addIssue(new Issue1169());
addIssue(new Issue2392());
addIssue(new Issue2443());
addIssue(new TestFireEvents());
diff --git a/reference/code-museum/src/com/google/gwt/museum/client/defaultmuseum/Issue1169.java b/reference/code-museum/src/com/google/gwt/museum/client/defaultmuseum/Issue1169.java
new file mode 100644
index 0000000..d3cbbe6
--- /dev/null
+++ b/reference/code-museum/src/com/google/gwt/museum/client/defaultmuseum/Issue1169.java
@@ -0,0 +1,76 @@
+/*
+ * Copyright 2008 Google Inc.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not
+ * use this file except in compliance with the License. You may obtain a copy of
+ * the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+ * License for the specific language governing permissions and limitations under
+ * the License.
+ */
+package com.google.gwt.museum.client.defaultmuseum;
+
+import com.google.gwt.museum.client.common.AbstractIssue;
+import com.google.gwt.user.client.Command;
+import com.google.gwt.user.client.ui.MenuBar;
+import com.google.gwt.user.client.ui.PopupPanel;
+import com.google.gwt.user.client.ui.Widget;
+
+/**
+ * The {@link PopupPanel} used to display sub menus in a {@link MenuBar} is not
+ * accessible, nor is it under the {@link MenuBar MenuBar's} DOM structure, so
+ * it cannot be uniquely styled.
+ */
+public class Issue1169 extends AbstractIssue {
+ /**
+ * A command that does not do anything.
+ */
+ private static Command emptyCommand = new Command() {
+ public void execute() {
+ }
+ };
+
+ @Override
+ public Widget createIssue() {
+ // Create the main menu bar
+ MenuBar menuBar = new MenuBar();
+ menuBar.setAutoOpen(true);
+
+ // Change the primary style name
+ menuBar.setStylePrimaryName("myMenuBar");
+
+ // Add the original style names so the default styles apply
+ menuBar.addStyleName("gwt-MenuBar gwt-MenuBar-horizontal");
+
+ // Add some sub menus, each with a unique style name
+ for (int i = 0; i < 3; i++) {
+ MenuBar subMenu = new MenuBar(true);
+ subMenu.addItem("Item 1", emptyCommand);
+ subMenu.addItem("Item 2", emptyCommand);
+ subMenu.addItem("Item 3", emptyCommand);
+ menuBar.addItem("Option " + i, subMenu);
+ }
+
+ return menuBar;
+ }
+
+ @Override
+ public String getInstructions() {
+ return "Verify that each submenu has a red border, but no shadow.";
+ }
+
+ @Override
+ public String getSummary() {
+ return "Cannot apply unique styles to MenuBar popups";
+ }
+
+ @Override
+ public boolean hasCSS() {
+ return true;
+ }
+}
diff --git a/reference/code-museum/src/com/google/gwt/museum/public/issues/Issue1169.css b/reference/code-museum/src/com/google/gwt/museum/public/issues/Issue1169.css
new file mode 100644
index 0000000..ae45b38
--- /dev/null
+++ b/reference/code-museum/src/com/google/gwt/museum/public/issues/Issue1169.css
@@ -0,0 +1,14 @@
+@import url("Default.css");
+
+.myMenuBar {
+ width: 300px;
+}
+.myMenuBarPopup {
+ border: 1px solid red;
+}
+.myMenuBarPopup .menuPopupTopLeft,
+.myMenuBarPopup .menuPopupTopRight,
+.myMenuBarPopup .menuPopupBottomLeft,
+.myMenuBarPopup .menuPopupBottomRight {
+ display: none;
+}
diff --git a/user/src/com/google/gwt/user/client/ui/MenuBar.java b/user/src/com/google/gwt/user/client/ui/MenuBar.java
index a668c9e..1b3d77e 100644
--- a/user/src/com/google/gwt/user/client/ui/MenuBar.java
+++ b/user/src/com/google/gwt/user/client/ui/MenuBar.java
@@ -48,24 +48,32 @@
* </li>
* <li>.gwt-MenuBar .gwt-MenuItemSeparator .menuSeparatorInner { inner component of
* section separators } </li>
- * <li>.gwt-MenuBar .menuPopupTopLeft { the top left cell }</li>
- * <li>.gwt-MenuBar .menuPopupTopLeftInner { the inner element of the cell }</li>
- * <li>.gwt-MenuBar .menuPopupTopCenter { the top center cell }</li>
- * <li>.gwt-MenuBar .menuPopupTopCenterInner { the inner element of the cell }</li>
- * <li>.gwt-MenuBar .menuPopupTopRight { the top right cell }</li>
- * <li>.gwt-MenuBar .menuPopupTopRightInner { the inner element of the cell }</li>
- * <li>.gwt-MenuBar .menuPopupMiddleLeft { the middle left cell }</li>
- * <li>.gwt-MenuBar .menuPopupMiddleLeftInner { the inner element of the cell }</li>
- * <li>.gwt-MenuBar .menuPopupMiddleCenter { the middle center cell }</li>
- * <li>.gwt-MenuBar .menuPopupMiddleCenterInner { the inner element of the cell }</li>
- * <li>.gwt-MenuBar .menuPopupMiddleRight { the middle right cell }</li>
- * <li>.gwt-MenuBar .menuPopupMiddleRightInner { the inner element of the cell }</li>
- * <li>.gwt-MenuBar .menuPopupBottomLeft { the bottom left cell }</li>
- * <li>.gwt-MenuBar .menuPopupBottomLeftInner { the inner element of the cell }</li>
- * <li>.gwt-MenuBar .menuPopupBottomCenter { the bottom center cell }</li>
- * <li>.gwt-MenuBar .menuPopupBottomCenterInner { the inner element of the cell }</li>
- * <li>.gwt-MenuBar .menuPopupBottomRight { the bottom right cell }</li>
- * <li>.gwt-MenuBar .menuPopupBottomRightInner { the inner element of the cell }</li>
+ * <li>.gwt-MenuBarPopup .menuPopupTopLeft { the top left cell }</li>
+ * <li>.gwt-MenuBarPopup .menuPopupTopLeftInner { the inner element of the cell }</li>
+ * <li>.gwt-MenuBarPopup .menuPopupTopCenter { the top center cell }</li>
+ * <li>.gwt-MenuBarPopup .menuPopupTopCenterInner { the inner element of the
+ * cell }</li>
+ * <li>.gwt-MenuBarPopup .menuPopupTopRight { the top right cell }</li>
+ * <li>.gwt-MenuBarPopup .menuPopupTopRightInner { the inner element of the
+ * cell }</li>
+ * <li>.gwt-MenuBarPopup .menuPopupMiddleLeft { the middle left cell }</li>
+ * <li>.gwt-MenuBarPopup .menuPopupMiddleLeftInner { the inner element of the
+ * cell }</li>
+ * <li>.gwt-MenuBarPopup .menuPopupMiddleCenter { the middle center cell }</li>
+ * <li>.gwt-MenuBarPopup .menuPopupMiddleCenterInner { the inner element of the
+ * cell }</li>
+ * <li>.gwt-MenuBarPopup .menuPopupMiddleRight { the middle right cell }</li>
+ * <li>.gwt-MenuBarPopup .menuPopupMiddleRightInner { the inner element of the
+ * cell }</li>
+ * <li>.gwt-MenuBarPopup .menuPopupBottomLeft { the bottom left cell }</li>
+ * <li>.gwt-MenuBarPopup .menuPopupBottomLeftInner { the inner element of the
+ * cell }</li>
+ * <li>.gwt-MenuBarPopup .menuPopupBottomCenter { the bottom center cell }</li>
+ * <li>.gwt-MenuBarPopup .menuPopupBottomCenterInner { the inner element of the
+ * cell }</li>
+ * <li>.gwt-MenuBarPopup .menuPopupBottomRight { the bottom right cell }</li>
+ * <li>.gwt-MenuBarPopup .menuPopupBottomRightInner { the inner element of the
+ * cell }</li>
* </ul>
*
* <p>
@@ -74,6 +82,8 @@
* </p>
*/
public class MenuBar extends Widget implements PopupListener, HasAnimation {
+ private static final String STYLENAME_DEFAULT = "gwt-MenuBar";
+
/**
* An {@link ImageBundle} that provides images for {@link MenuBar}.
*/
@@ -562,7 +572,11 @@
};
popup.setAnimationType(AnimationType.ONE_WAY_CORNER);
popup.setAnimationEnabled(isAnimationEnabled);
- popup.setStyleName("gwt-MenuBarPopup");
+ popup.setStyleName(STYLENAME_DEFAULT + "Popup");
+ String primaryStyleName = getStylePrimaryName();
+ if (!STYLENAME_DEFAULT.equals(primaryStyleName)) {
+ popup.addStyleName(primaryStyleName + "Popup");
+ }
popup.addPopupListener(this);
shownChildMenu = item.getSubMenu();
@@ -777,7 +791,7 @@
sinkEvents(Event.ONCLICK | Event.ONMOUSEOVER | Event.ONMOUSEOUT
| Event.ONFOCUS | Event.ONKEYDOWN);
- setStyleName("gwt-MenuBar");
+ setStyleName(STYLENAME_DEFAULT);
if (vertical) {
addStyleDependentName("vertical");
} else {