summaryrefslogtreecommitdiffstats
path: root/client
diff options
context:
space:
mode:
authorArtur Signell <artur@vaadin.com>2012-11-29 19:12:19 +0200
committerVaadin Code Review <review@vaadin.com>2012-12-04 08:32:17 +0000
commit282632354258d722026d682805647e49ea032712 (patch)
tree3e4a8c6ce762b37c64cf0b0efba5dbffde89a5ef /client
parentcdd674899544bef4f61129c5c93c8042ae4ad717 (diff)
downloadvaadin-framework-282632354258d722026d682805647e49ea032712.tar.gz
vaadin-framework-282632354258d722026d682805647e49ea032712.zip
Fixed Accordion layouting (#10128, #9552)
* Now uses LayoutManager * Moved layout calculations to connector * No longer set incorrect width on the root element, only update tab width * Removed duplicate and dead code Some, or all, of the remaining calculations are likely unnecessary Change-Id: I3a87682d3498e55e9d4084acfde0f782b55301f2
Diffstat (limited to 'client')
-rw-r--r--client/src/com/vaadin/client/ui/VAccordion.java82
-rw-r--r--client/src/com/vaadin/client/ui/accordion/AccordionConnector.java54
2 files changed, 55 insertions, 81 deletions
diff --git a/client/src/com/vaadin/client/ui/VAccordion.java b/client/src/com/vaadin/client/ui/VAccordion.java
index 962b13e4cd..b99d170c23 100644
--- a/client/src/com/vaadin/client/ui/VAccordion.java
+++ b/client/src/com/vaadin/client/ui/VAccordion.java
@@ -44,8 +44,7 @@ public class VAccordion extends VTabsheetBase {
/** For internal use only. May be removed or replaced in the future. */
public HashMap<StackItem, UIDL> lazyUpdateMap = new HashMap<StackItem, UIDL>();
- /** For internal use only. May be removed or replaced in the future. */
- public StackItem openTab = null;
+ private StackItem openTab = null;
/** For internal use only. May be removed or replaced in the future. */
public int selectedUIDLItemIndex = -1;
@@ -191,8 +190,6 @@ public class VAccordion extends VTabsheetBase {
openTab = item;
}
- // Update the size for the open tab
- updateOpenTabSize();
}
/** For internal use only. May be removed or replaced in the future. */
@@ -217,75 +214,6 @@ public class VAccordion extends VTabsheetBase {
}
/**
- * Sets the size of the open tab.
- * <p>
- * For internal use only. May be removed or replaced in the future.
- */
- public void updateOpenTabSize() {
- if (openTab == null) {
- return;
- }
-
- // WIDTH
- if (!isDynamicWidth()) {
- openTab.setWidth("100%");
- } else {
- openTab.setWidth(null);
- }
-
- // HEIGHT
- if (!isDynamicHeight()) {
- int usedPixels = 0;
- for (Widget w : getChildren()) {
- StackItem item = (StackItem) w;
- if (item == openTab) {
- usedPixels += item.getCaptionHeight();
- } else {
- // This includes the captionNode borders
- usedPixels += item.getHeight();
- }
- }
-
- int offsetHeight = getOffsetHeight();
-
- int spaceForOpenItem = offsetHeight - usedPixels;
-
- if (spaceForOpenItem < 0) {
- spaceForOpenItem = 0;
- }
-
- openTab.setHeight(spaceForOpenItem);
- } else {
- openTab.setHeightFromWidget();
-
- }
-
- }
-
- public void iLayout() {
- if (openTab == null) {
- return;
- }
-
- if (isDynamicWidth()) {
- int maxWidth = 40;
- for (Widget w : getChildren()) {
- StackItem si = (StackItem) w;
- int captionWidth = si.getCaptionWidth();
- if (captionWidth > maxWidth) {
- maxWidth = captionWidth;
- }
- }
- int widgetWidth = openTab.getWidgetWidth();
- if (widgetWidth > maxWidth) {
- maxWidth = widgetWidth;
- }
- super.setWidth(maxWidth + "px");
- openTab.setWidth(maxWidth);
- }
- }
-
- /**
* A StackItem has always two children, Child 0 is a VCaption, Child 1 is
* the actual child widget.
*/
@@ -548,4 +476,12 @@ public class VAccordion extends VTabsheetBase {
return (StackItem) getWidget(index);
}
+ public Iterable<StackItem> getStackItems() {
+ return (Iterable) getChildren();
+ }
+
+ public StackItem getOpenStackItem() {
+ return openTab;
+ }
+
}
diff --git a/client/src/com/vaadin/client/ui/accordion/AccordionConnector.java b/client/src/com/vaadin/client/ui/accordion/AccordionConnector.java
index d5ff4f16b1..99e4ec0ffd 100644
--- a/client/src/com/vaadin/client/ui/accordion/AccordionConnector.java
+++ b/client/src/com/vaadin/client/ui/accordion/AccordionConnector.java
@@ -49,11 +49,10 @@ public class AccordionConnector extends TabsheetBaseConnector implements
getWidget().open(getWidget().selectedUIDLItemIndex);
selectedItem.setContent(selectedTabUIDL);
- } else if (isRealUpdate(uidl) && getWidget().openTab != null) {
- getWidget().close(getWidget().openTab);
+ } else if (isRealUpdate(uidl) && getWidget().getOpenStackItem() != null) {
+ getWidget().close(getWidget().getOpenStackItem());
}
- getWidget().iLayout();
// finally render possible hidden tabs
if (getWidget().lazyUpdateMap.size() > 0) {
for (Iterator iterator = getWidget().lazyUpdateMap.keySet()
@@ -78,14 +77,53 @@ public class AccordionConnector extends TabsheetBaseConnector implements
@Override
public void layout() {
- VAccordion accordion = getWidget();
+ StackItem openTab = getWidget().getOpenStackItem();
+ if (openTab == null) {
+ return;
+ }
+
+ // WIDTH
+ if (!isUndefinedWidth()) {
+ openTab.setWidth("100%");
+ } else {
+ int maxWidth = 40;
+ for (StackItem si : getWidget().getStackItems()) {
+ int captionWidth = si.getCaptionWidth();
+ if (captionWidth > maxWidth) {
+ maxWidth = captionWidth;
+ }
+ }
+ int widgetWidth = openTab.getWidgetWidth();
+ if (widgetWidth > maxWidth) {
+ maxWidth = widgetWidth;
+ }
+ openTab.setWidth(maxWidth);
+ }
+
+ // HEIGHT
+ if (!isUndefinedHeight()) {
+ int usedPixels = 0;
+ for (StackItem item : getWidget().getStackItems()) {
+ if (item == openTab) {
+ usedPixels += item.getCaptionHeight();
+ } else {
+ // This includes the captionNode borders
+ usedPixels += item.getHeight();
+ }
+ }
+ int rootElementInnerHeight = getLayoutManager().getInnerHeight(
+ getWidget().getElement());
+ int spaceForOpenItem = rootElementInnerHeight - usedPixels;
+
+ if (spaceForOpenItem < 0) {
+ spaceForOpenItem = 0;
+ }
- accordion.updateOpenTabSize();
+ openTab.setHeight(spaceForOpenItem);
+ } else {
+ openTab.setHeightFromWidget();
- if (isUndefinedHeight()) {
- accordion.openTab.setHeightFromWidget();
}
- accordion.iLayout();
}