You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

VAbstractOrderedLayout.java 25KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742
  1. /*
  2. * Copyright 2000-2014 Vaadin Ltd.
  3. *
  4. * Licensed under the Apache License, Version 2.0 (the "License"); you may not
  5. * use this file except in compliance with the License. You may obtain a copy of
  6. * the License at
  7. *
  8. * http://www.apache.org/licenses/LICENSE-2.0
  9. *
  10. * Unless required by applicable law or agreed to in writing, software
  11. * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
  12. * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
  13. * License for the specific language governing permissions and limitations under
  14. * the License.
  15. */
  16. package com.vaadin.client.ui.orderedlayout;
  17. import java.util.HashMap;
  18. import java.util.Map;
  19. import com.google.gwt.core.client.GWT;
  20. import com.google.gwt.dom.client.Element;
  21. import com.google.gwt.dom.client.Node;
  22. import com.google.gwt.dom.client.Style;
  23. import com.google.gwt.dom.client.Style.Unit;
  24. import com.google.gwt.dom.client.Style.Visibility;
  25. import com.google.gwt.regexp.shared.MatchResult;
  26. import com.google.gwt.regexp.shared.RegExp;
  27. import com.google.gwt.user.client.DOM;
  28. import com.google.gwt.user.client.ui.FlowPanel;
  29. import com.google.gwt.user.client.ui.RequiresResize;
  30. import com.google.gwt.user.client.ui.Widget;
  31. import com.vaadin.client.BrowserInfo;
  32. import com.vaadin.client.LayoutManager;
  33. import com.vaadin.client.Profiler;
  34. import com.vaadin.client.Util;
  35. import com.vaadin.client.WidgetUtil;
  36. import com.vaadin.shared.ui.MarginInfo;
  37. /**
  38. * Base class for ordered layouts
  39. */
  40. public class VAbstractOrderedLayout extends FlowPanel {
  41. protected boolean spacing = false;
  42. /** For internal use only. May be removed or replaced in the future. */
  43. public boolean vertical = true;
  44. protected boolean definedHeight = false;
  45. private Map<Widget, Slot> widgetToSlot = new HashMap<Widget, Slot>();
  46. private Element expandWrapper;
  47. private LayoutManager layoutManager;
  48. /**
  49. * Keep track of the last allocated expand size to help detecting when it
  50. * changes.
  51. */
  52. private int lastExpandSize = -1;
  53. public VAbstractOrderedLayout(boolean vertical) {
  54. this.vertical = vertical;
  55. }
  56. /**
  57. * See the method {@link #addOrMoveSlot(Slot, int, boolean)}.
  58. *
  59. * <p>
  60. * This method always adjusts spacings for the whole layout.
  61. *
  62. * @param slot
  63. * The slot to move or add
  64. * @param index
  65. * The index where the slot should be placed.
  66. * @deprecated since 7.1.4, use {@link #addOrMoveSlot(Slot, int, boolean)}
  67. */
  68. @Deprecated
  69. public void addOrMoveSlot(Slot slot, int index) {
  70. addOrMoveSlot(slot, index, true);
  71. }
  72. /**
  73. * Add or move a slot to another index.
  74. * <p>
  75. * For internal use only. May be removed or replaced in the future.
  76. * <p>
  77. * You should note that the index does not refer to the DOM index if
  78. * spacings are used. If spacings are used then the index will be adjusted
  79. * to include the spacings when inserted.
  80. * <p>
  81. * For instance when using spacing the index converts to DOM index in the
  82. * following way:
  83. *
  84. * <pre>
  85. * index : 0 -> DOM index: 0
  86. * index : 1 -> DOM index: 1
  87. * index : 2 -> DOM index: 3
  88. * index : 3 -> DOM index: 5
  89. * index : 4 -> DOM index: 7
  90. * </pre>
  91. *
  92. * When using this method never account for spacings.
  93. * <p>
  94. * The caller should remove all spacings before calling this method and
  95. * re-add them (if necessary) after this method. This can be done before and
  96. * after all slots have been added/moved.
  97. * </p>
  98. *
  99. * @since 7.1.4
  100. *
  101. * @param slot
  102. * The slot to move or add
  103. * @param index
  104. * The index where the slot should be placed.
  105. * @param adjustSpacing
  106. * true to recalculate spacings for the whole layout after the
  107. * operation
  108. */
  109. public void addOrMoveSlot(Slot slot, int index, boolean adjustSpacing) {
  110. Profiler.enter("VAOL.onConnectorHierarchyChange addOrMoveSlot find index");
  111. if (slot.getParent() == this) {
  112. int currentIndex = getWidgetIndex(slot);
  113. if (index == currentIndex) {
  114. Profiler.leave("VAOL.onConnectorHierarchyChange addOrMoveSlot find index");
  115. return;
  116. }
  117. }
  118. Profiler.leave("VAOL.onConnectorHierarchyChange addOrMoveSlot find index");
  119. Profiler.enter("VAOL.onConnectorHierarchyChange addOrMoveSlot insert");
  120. insert(slot, index);
  121. Profiler.leave("VAOL.onConnectorHierarchyChange addOrMoveSlot insert");
  122. if (adjustSpacing) {
  123. Profiler.enter("VAOL.onConnectorHierarchyChange addOrMoveSlot setSpacing");
  124. setSpacing(spacing);
  125. Profiler.leave("VAOL.onConnectorHierarchyChange addOrMoveSlot setSpacing");
  126. }
  127. }
  128. /**
  129. * {@inheritDoc}
  130. *
  131. * @deprecated As of 7.2, use or override
  132. * {@link #insert(Widget, Element, int, boolean)} instead.
  133. */
  134. @Override
  135. @Deprecated
  136. protected void insert(Widget child,
  137. com.google.gwt.user.client.Element container, int beforeIndex,
  138. boolean domInsert) {
  139. // Validate index; adjust if the widget is already a child of this
  140. // panel.
  141. beforeIndex = adjustIndex(child, beforeIndex);
  142. // Detach new child.
  143. child.removeFromParent();
  144. // Logical attach.
  145. getChildren().insert(child, beforeIndex);
  146. // Physical attach.
  147. container = expandWrapper != null ? DOM.asOld(expandWrapper)
  148. : getElement();
  149. if (domInsert) {
  150. if (spacing) {
  151. if (beforeIndex != 0) {
  152. /*
  153. * Since the spacing elements are located at the same DOM
  154. * level as the slots we need to take them into account when
  155. * calculating the slot position.
  156. *
  157. * The spacing elements are always located before the actual
  158. * slot except for the first slot which do not have a
  159. * spacing element like this
  160. *
  161. * |<slot1><spacing2><slot2><spacing3><slot3>...|
  162. */
  163. beforeIndex = beforeIndex * 2 - 1;
  164. }
  165. }
  166. DOM.insertChild(container, child.getElement(), beforeIndex);
  167. } else {
  168. DOM.appendChild(container, child.getElement());
  169. }
  170. // Adopt.
  171. adopt(child);
  172. }
  173. /**
  174. * {@inheritDoc}
  175. *
  176. * @since 7.2
  177. */
  178. @Override
  179. protected void insert(Widget child, Element container, int beforeIndex,
  180. boolean domInsert) {
  181. insert(child, DOM.asOld(container), beforeIndex, domInsert);
  182. }
  183. /**
  184. * Remove a slot from the layout
  185. *
  186. * @param widget
  187. * @return
  188. */
  189. public void removeWidget(Widget widget) {
  190. Slot slot = widgetToSlot.remove(widget);
  191. if (slot != null) {
  192. removeSlot(slot);
  193. }
  194. }
  195. /**
  196. * Remove a slot from the layout.
  197. *
  198. * This method is called automatically by {@link #removeWidget(Widget)} and
  199. * should not be called directly by the user. When overridden, the super
  200. * method must be called.
  201. *
  202. * @since 7.6
  203. * @param Slot
  204. * to remove
  205. */
  206. protected void removeSlot(Slot slot) {
  207. remove(slot);
  208. }
  209. /**
  210. * Get the containing slot for a widget. If no slot is found a new slot is
  211. * created and returned.
  212. *
  213. * @param widget
  214. * The widget whose slot you want to get
  215. *
  216. * @return
  217. */
  218. public Slot getSlot(Widget widget) {
  219. Slot slot = widgetToSlot.get(widget);
  220. if (slot == null) {
  221. slot = createSlot(widget);
  222. widgetToSlot.put(widget, slot);
  223. }
  224. return slot;
  225. }
  226. /**
  227. * Create a slot to be added to the layout.
  228. *
  229. * This method is called automatically by {@link #getSlot(Widget)} when a
  230. * new slot is needed. It should not be called directly by the user, but can
  231. * be overridden to customize slot creation.
  232. *
  233. * @since 7.6
  234. * @param widget
  235. * the widget for which a slot is being created
  236. * @return created Slot
  237. */
  238. protected Slot createSlot(Widget widget) {
  239. Slot slot = GWT.create(Slot.class);
  240. slot.setLayout(this);
  241. slot.setWidget(widget);
  242. return slot;
  243. }
  244. /**
  245. * Gets a slot based on the widget element. If no slot is found then null is
  246. * returned.
  247. *
  248. * @param widgetElement
  249. * The element of the widget ( Same as getWidget().getElement() )
  250. * @return
  251. * @deprecated As of 7.2, call or override {@link #getSlot(Element)} instead
  252. */
  253. @Deprecated
  254. public Slot getSlot(com.google.gwt.user.client.Element widgetElement) {
  255. for (Map.Entry<Widget, Slot> entry : widgetToSlot.entrySet()) {
  256. if (entry.getKey().getElement() == widgetElement) {
  257. return entry.getValue();
  258. }
  259. }
  260. return null;
  261. }
  262. /**
  263. * Gets a slot based on the widget element. If no slot is found then null is
  264. * returned.
  265. *
  266. * @param widgetElement
  267. * The element of the widget ( Same as getWidget().getElement() )
  268. * @return
  269. *
  270. * @since 7.2
  271. */
  272. public Slot getSlot(Element widgetElement) {
  273. return getSlot(DOM.asOld(widgetElement));
  274. }
  275. /**
  276. * Set the layout manager for the layout
  277. *
  278. * @param manager
  279. * The layout manager to use
  280. */
  281. public void setLayoutManager(LayoutManager manager) {
  282. layoutManager = manager;
  283. }
  284. /**
  285. * Get the layout manager used by this layout
  286. *
  287. */
  288. public LayoutManager getLayoutManager() {
  289. return layoutManager;
  290. }
  291. /**
  292. * Deducts the caption position by examining the wrapping element.
  293. * <p>
  294. * For internal use only. May be removed or replaced in the future.
  295. *
  296. * @param captionWrap
  297. * The wrapping element
  298. *
  299. * @return The caption position
  300. * @deprecated As of 7.2, call or override
  301. * {@link #getCaptionPositionFromElement(Element)} instead
  302. */
  303. @Deprecated
  304. public CaptionPosition getCaptionPositionFromElement(
  305. com.google.gwt.user.client.Element captionWrap) {
  306. RegExp captionPositionRegexp = RegExp.compile("v-caption-on-(\\S+)");
  307. // Get caption position from the classname
  308. MatchResult matcher = captionPositionRegexp.exec(captionWrap
  309. .getClassName());
  310. if (matcher == null || matcher.getGroupCount() < 2) {
  311. return CaptionPosition.TOP;
  312. }
  313. String captionClass = matcher.getGroup(1);
  314. CaptionPosition captionPosition = CaptionPosition.valueOf(
  315. CaptionPosition.class, captionClass.toUpperCase());
  316. return captionPosition;
  317. }
  318. /**
  319. * Deducts the caption position by examining the wrapping element.
  320. * <p>
  321. * For internal use only. May be removed or replaced in the future.
  322. *
  323. * @param captionWrap
  324. * The wrapping element
  325. *
  326. * @return The caption position
  327. * @since 7.2
  328. */
  329. public CaptionPosition getCaptionPositionFromElement(Element captionWrap) {
  330. return getCaptionPositionFromElement(DOM.asOld(captionWrap));
  331. }
  332. /**
  333. * Update the offset off the caption relative to the slot
  334. * <p>
  335. * For internal use only. May be removed or replaced in the future.
  336. *
  337. * @param caption
  338. * The caption element
  339. * @deprecated As of 7.2, call or override
  340. * {@link #updateCaptionOffset(Element)} instead
  341. */
  342. @Deprecated
  343. public void updateCaptionOffset(com.google.gwt.user.client.Element caption) {
  344. Element captionWrap = caption.getParentElement();
  345. Style captionWrapStyle = captionWrap.getStyle();
  346. captionWrapStyle.clearPaddingTop();
  347. captionWrapStyle.clearPaddingRight();
  348. captionWrapStyle.clearPaddingBottom();
  349. captionWrapStyle.clearPaddingLeft();
  350. Style captionStyle = caption.getStyle();
  351. captionStyle.clearMarginTop();
  352. captionStyle.clearMarginRight();
  353. captionStyle.clearMarginBottom();
  354. captionStyle.clearMarginLeft();
  355. // Get caption position from the classname
  356. CaptionPosition captionPosition = getCaptionPositionFromElement(captionWrap);
  357. if (captionPosition == CaptionPosition.LEFT
  358. || captionPosition == CaptionPosition.RIGHT) {
  359. int captionWidth;
  360. if (layoutManager != null) {
  361. captionWidth = layoutManager.getOuterWidth(caption)
  362. - layoutManager.getMarginWidth(caption);
  363. } else {
  364. captionWidth = caption.getOffsetWidth();
  365. }
  366. if (captionWidth > 0) {
  367. if (captionPosition == CaptionPosition.LEFT) {
  368. captionWrapStyle.setPaddingLeft(captionWidth, Unit.PX);
  369. captionStyle.setMarginLeft(-captionWidth, Unit.PX);
  370. } else {
  371. captionWrapStyle.setPaddingRight(captionWidth, Unit.PX);
  372. captionStyle.setMarginRight(-captionWidth, Unit.PX);
  373. }
  374. }
  375. }
  376. if (captionPosition == CaptionPosition.TOP
  377. || captionPosition == CaptionPosition.BOTTOM) {
  378. int captionHeight;
  379. if (layoutManager != null) {
  380. captionHeight = layoutManager.getOuterHeight(caption)
  381. - layoutManager.getMarginHeight(caption);
  382. } else {
  383. captionHeight = caption.getOffsetHeight();
  384. }
  385. if (captionHeight > 0) {
  386. if (captionPosition == CaptionPosition.TOP) {
  387. captionWrapStyle.setPaddingTop(captionHeight, Unit.PX);
  388. captionStyle.setMarginTop(-captionHeight, Unit.PX);
  389. } else {
  390. captionWrapStyle.setPaddingBottom(captionHeight, Unit.PX);
  391. captionStyle.setMarginBottom(-captionHeight, Unit.PX);
  392. }
  393. }
  394. }
  395. }
  396. /**
  397. * Update the offset off the caption relative to the slot
  398. * <p>
  399. * For internal use only. May be removed or replaced in the future.
  400. *
  401. * @param caption
  402. * The caption element
  403. * @since 7.2
  404. */
  405. public void updateCaptionOffset(Element caption) {
  406. updateCaptionOffset(DOM.asOld(caption));
  407. }
  408. /**
  409. * Set the margin of the layout
  410. *
  411. * @param marginInfo
  412. * The margin information
  413. */
  414. public void setMargin(MarginInfo marginInfo) {
  415. if (marginInfo != null) {
  416. setStyleName("v-margin-top", marginInfo.hasTop());
  417. setStyleName("v-margin-right", marginInfo.hasRight());
  418. setStyleName("v-margin-bottom", marginInfo.hasBottom());
  419. setStyleName("v-margin-left", marginInfo.hasLeft());
  420. }
  421. }
  422. /**
  423. * Turn on or off spacing in the layout
  424. *
  425. * @param spacing
  426. * True if spacing should be used, false if not
  427. */
  428. public void setSpacing(boolean spacing) {
  429. Profiler.enter("VAOL.onConnectorHierarchyChange setSpacing");
  430. this.spacing = spacing;
  431. // first widget does not have spacing on
  432. // optimization to avoid looking up widget indices on every iteration
  433. Widget firstSlot = null;
  434. if (getWidgetCount() > 0) {
  435. firstSlot = getWidget(0);
  436. }
  437. for (Slot slot : widgetToSlot.values()) {
  438. slot.setSpacing(spacing && firstSlot != slot);
  439. }
  440. Profiler.leave("VAOL.onConnectorHierarchyChange setSpacing");
  441. }
  442. /**
  443. * Assigns relative sizes to the children that should expand based on their
  444. * expand ratios.
  445. */
  446. public void updateExpandedSizes() {
  447. // Ensure the expand wrapper is in place
  448. if (expandWrapper == null) {
  449. expandWrapper = DOM.createDiv();
  450. expandWrapper.setClassName("v-expand");
  451. // Detach all widgets before modifying DOM
  452. for (Widget widget : getChildren()) {
  453. orphan(widget);
  454. }
  455. while (getElement().getChildCount() > 0) {
  456. Node el = getElement().getChild(0);
  457. expandWrapper.appendChild(el);
  458. }
  459. getElement().appendChild(expandWrapper);
  460. // Attach all widgets again
  461. for (Widget widget : getChildren()) {
  462. adopt(widget);
  463. }
  464. }
  465. // Sum up expand ratios to get the denominator
  466. double total = 0;
  467. for (Slot slot : widgetToSlot.values()) {
  468. // FIXME expandRatio might be <0
  469. total += slot.getExpandRatio();
  470. }
  471. // Give each expanded child its own share
  472. for (Slot slot : widgetToSlot.values()) {
  473. Element slotElement = slot.getElement();
  474. slotElement.removeAttribute("aria-hidden");
  475. Style slotStyle = slotElement.getStyle();
  476. slotStyle.clearVisibility();
  477. slotStyle.clearMarginLeft();
  478. slotStyle.clearMarginTop();
  479. if (slot.getExpandRatio() != 0) {
  480. // FIXME expandRatio might be <0
  481. double size = 100 * (slot.getExpandRatio() / total);
  482. if (vertical) {
  483. slot.setHeight(size + "%");
  484. if (slot.hasRelativeHeight()) {
  485. Util.notifyParentOfSizeChange(this, true);
  486. }
  487. } else {
  488. slot.setWidth(size + "%");
  489. if (slot.hasRelativeWidth()) {
  490. Util.notifyParentOfSizeChange(this, true);
  491. }
  492. }
  493. } else if (slot.isRelativeInDirection(vertical)) {
  494. // Relative child without expansion gets no space at all
  495. if (vertical) {
  496. slot.setHeight("0");
  497. } else {
  498. slot.setWidth("0");
  499. }
  500. slotStyle.setVisibility(Visibility.HIDDEN);
  501. slotElement.setAttribute("aria-hidden", "true");
  502. } else {
  503. // Non-relative child without expansion should be unconstrained
  504. if (BrowserInfo.get().isIE8()) {
  505. // unconstrained in IE8 is auto
  506. if (vertical) {
  507. slot.setHeight("auto");
  508. } else {
  509. slot.setWidth("auto");
  510. }
  511. } else {
  512. if (vertical) {
  513. slotStyle.clearHeight();
  514. } else {
  515. slotStyle.clearWidth();
  516. }
  517. }
  518. }
  519. }
  520. }
  521. /**
  522. * Removes elements used to expand a slot.
  523. * <p>
  524. * For internal use only. May be removed or replaced in the future.
  525. */
  526. public void clearExpand() {
  527. if (expandWrapper != null) {
  528. // Detach all widgets before modifying DOM
  529. for (Widget widget : getChildren()) {
  530. orphan(widget);
  531. }
  532. lastExpandSize = -1;
  533. while (expandWrapper.getChildCount() > 0) {
  534. Element el = expandWrapper.getChild(0).cast();
  535. getElement().appendChild(el);
  536. if (vertical) {
  537. el.getStyle().clearHeight();
  538. el.getStyle().clearMarginTop();
  539. } else {
  540. el.getStyle().clearWidth();
  541. el.getStyle().clearMarginLeft();
  542. }
  543. }
  544. expandWrapper.removeFromParent();
  545. expandWrapper = null;
  546. // Attach children again
  547. for (Widget widget : getChildren()) {
  548. adopt(widget);
  549. }
  550. }
  551. }
  552. /**
  553. * Updates the expand compensation based on the measured sizes of children
  554. * without expand.
  555. */
  556. public void updateExpandCompensation() {
  557. boolean isExpanding = false;
  558. for (Widget slot : getChildren()) {
  559. // FIXME expandRatio might be <0
  560. if (((Slot) slot).getExpandRatio() != 0) {
  561. isExpanding = true;
  562. break;
  563. }
  564. }
  565. if (isExpanding) {
  566. /*
  567. * Expanded slots have relative sizes that together add up to 100%.
  568. * To make room for slots without expand, we will add padding that
  569. * is not considered for relative sizes and a corresponding negative
  570. * margin for the unexpanded slots. We calculate the size by summing
  571. * the size of all non-expanded non-relative slots.
  572. *
  573. * Relatively sized slots without expansion are considered to get
  574. * 0px, but we still keep them visible (causing overflows) to help
  575. * the developer see what's happening. Forcing them to only get 0px
  576. * would make them disappear which would avoid overflows but would
  577. * instead cause confusion as they would then just disappear without
  578. * any obvious reason.
  579. */
  580. int totalSize = 0;
  581. for (Widget w : getChildren()) {
  582. Slot slot = (Slot) w;
  583. if (slot.getExpandRatio() == 0
  584. && !slot.isRelativeInDirection(vertical)) {
  585. if (layoutManager != null) {
  586. // TODO check caption position
  587. if (vertical) {
  588. int size = layoutManager.getOuterHeight(slot
  589. .getWidget().getElement());
  590. if (slot.hasCaption()) {
  591. size += layoutManager.getOuterHeight(slot
  592. .getCaptionElement());
  593. }
  594. if (size > 0) {
  595. totalSize += size;
  596. }
  597. } else {
  598. int max = -1;
  599. max = layoutManager.getOuterWidth(slot.getWidget()
  600. .getElement());
  601. if (slot.hasCaption()) {
  602. int max2 = layoutManager.getOuterWidth(slot
  603. .getCaptionElement());
  604. max = Math.max(max, max2);
  605. }
  606. if (max > 0) {
  607. totalSize += max;
  608. }
  609. }
  610. } else {
  611. // FIXME expandRatio might be <0
  612. totalSize += vertical ? slot.getOffsetHeight() : slot
  613. .getOffsetWidth();
  614. }
  615. }
  616. // TODO fails in Opera, always returns 0
  617. int spacingSize = vertical ? slot.getVerticalSpacing() : slot
  618. .getHorizontalSpacing();
  619. if (spacingSize > 0) {
  620. totalSize += spacingSize;
  621. }
  622. }
  623. // When we set the margin to the first child, we don't need
  624. // overflow:hidden in the layout root element, since the wrapper
  625. // would otherwise be placed outside of the layout root element
  626. // and block events on elements below it.
  627. if (vertical) {
  628. expandWrapper.getStyle().setPaddingTop(totalSize, Unit.PX);
  629. expandWrapper.getFirstChildElement().getStyle()
  630. .setMarginTop(-totalSize, Unit.PX);
  631. } else {
  632. expandWrapper.getStyle().setPaddingLeft(totalSize, Unit.PX);
  633. expandWrapper.getFirstChildElement().getStyle()
  634. .setMarginLeft(-totalSize, Unit.PX);
  635. }
  636. // Measure expanded children again if their size might have changed
  637. if (totalSize != lastExpandSize) {
  638. lastExpandSize = totalSize;
  639. for (Widget w : getChildren()) {
  640. Slot slot = (Slot) w;
  641. // FIXME expandRatio might be <0
  642. if (slot.getExpandRatio() != 0) {
  643. if (layoutManager != null) {
  644. layoutManager.setNeedsMeasure(Util
  645. .findConnectorFor(slot.getWidget()));
  646. } else if (slot.getWidget() instanceof RequiresResize) {
  647. ((RequiresResize) slot.getWidget()).onResize();
  648. }
  649. }
  650. }
  651. }
  652. }
  653. WidgetUtil.forceIE8Redraw(getElement());
  654. }
  655. /**
  656. * {@inheritDoc}
  657. */
  658. @Override
  659. public void setHeight(String height) {
  660. super.setHeight(height);
  661. definedHeight = (height != null && !"".equals(height));
  662. }
  663. /**
  664. * Sets the slots style names. The style names will be prefixed with the
  665. * v-slot prefix.
  666. *
  667. * @param stylenames
  668. * The style names of the slot.
  669. */
  670. public void setSlotStyleNames(Widget widget, String... stylenames) {
  671. Slot slot = getSlot(widget);
  672. if (slot == null) {
  673. throw new IllegalArgumentException(
  674. "A slot for the widget could not be found. Has the widget been added to the layout?");
  675. }
  676. slot.setStyleNames(stylenames);
  677. }
  678. }