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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741
  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.get(widget);
  191. removeSlot(slot);
  192. }
  193. /**
  194. * Remove a slot from the layout.
  195. *
  196. * This method is called automatically by {@link #removeWidget(Widget)} and
  197. * should not be called directly by the user. When overridden, the super
  198. * method must be called.
  199. *
  200. * @since 7.6
  201. * @param Slot
  202. * to remove
  203. */
  204. protected void removeSlot(Slot slot) {
  205. remove(slot);
  206. widgetToSlot.remove(slot.getWidget());
  207. }
  208. /**
  209. * Get the containing slot for a widget. If no slot is found a new slot is
  210. * created and returned.
  211. *
  212. * @param widget
  213. * The widget whose slot you want to get
  214. *
  215. * @return
  216. */
  217. public Slot getSlot(Widget widget) {
  218. Slot slot = widgetToSlot.get(widget);
  219. if (slot == null) {
  220. slot = createSlot(widget);
  221. widgetToSlot.put(widget, slot);
  222. }
  223. return slot;
  224. }
  225. /**
  226. * Create a slot to be added to the layout.
  227. *
  228. * This method is called automatically by {@link #getSlot(Widget)} when a
  229. * new slot is needed. It should not be called directly by the user, but can
  230. * be overridden to customize slot creation.
  231. *
  232. * @since 7.6
  233. * @param widget
  234. * the widget for which a slot is being created
  235. * @return created Slot
  236. */
  237. protected Slot createSlot(Widget widget) {
  238. Slot slot = GWT.create(Slot.class);
  239. slot.setLayout(this);
  240. slot.setWidget(widget);
  241. return slot;
  242. }
  243. /**
  244. * Gets a slot based on the widget element. If no slot is found then null is
  245. * returned.
  246. *
  247. * @param widgetElement
  248. * The element of the widget ( Same as getWidget().getElement() )
  249. * @return
  250. * @deprecated As of 7.2, call or override {@link #getSlot(Element)} instead
  251. */
  252. @Deprecated
  253. public Slot getSlot(com.google.gwt.user.client.Element widgetElement) {
  254. for (Map.Entry<Widget, Slot> entry : widgetToSlot.entrySet()) {
  255. if (entry.getKey().getElement() == widgetElement) {
  256. return entry.getValue();
  257. }
  258. }
  259. return null;
  260. }
  261. /**
  262. * Gets a slot based on the widget element. If no slot is found then null is
  263. * returned.
  264. *
  265. * @param widgetElement
  266. * The element of the widget ( Same as getWidget().getElement() )
  267. * @return
  268. *
  269. * @since 7.2
  270. */
  271. public Slot getSlot(Element widgetElement) {
  272. return getSlot(DOM.asOld(widgetElement));
  273. }
  274. /**
  275. * Set the layout manager for the layout
  276. *
  277. * @param manager
  278. * The layout manager to use
  279. */
  280. public void setLayoutManager(LayoutManager manager) {
  281. layoutManager = manager;
  282. }
  283. /**
  284. * Get the layout manager used by this layout
  285. *
  286. */
  287. public LayoutManager getLayoutManager() {
  288. return layoutManager;
  289. }
  290. /**
  291. * Deducts the caption position by examining the wrapping element.
  292. * <p>
  293. * For internal use only. May be removed or replaced in the future.
  294. *
  295. * @param captionWrap
  296. * The wrapping element
  297. *
  298. * @return The caption position
  299. * @deprecated As of 7.2, call or override
  300. * {@link #getCaptionPositionFromElement(Element)} instead
  301. */
  302. @Deprecated
  303. public CaptionPosition getCaptionPositionFromElement(
  304. com.google.gwt.user.client.Element captionWrap) {
  305. RegExp captionPositionRegexp = RegExp.compile("v-caption-on-(\\S+)");
  306. // Get caption position from the classname
  307. MatchResult matcher = captionPositionRegexp.exec(captionWrap
  308. .getClassName());
  309. if (matcher == null || matcher.getGroupCount() < 2) {
  310. return CaptionPosition.TOP;
  311. }
  312. String captionClass = matcher.getGroup(1);
  313. CaptionPosition captionPosition = CaptionPosition.valueOf(
  314. CaptionPosition.class, captionClass.toUpperCase());
  315. return captionPosition;
  316. }
  317. /**
  318. * Deducts the caption position by examining the wrapping element.
  319. * <p>
  320. * For internal use only. May be removed or replaced in the future.
  321. *
  322. * @param captionWrap
  323. * The wrapping element
  324. *
  325. * @return The caption position
  326. * @since 7.2
  327. */
  328. public CaptionPosition getCaptionPositionFromElement(Element captionWrap) {
  329. return getCaptionPositionFromElement(DOM.asOld(captionWrap));
  330. }
  331. /**
  332. * Update the offset off the caption relative to the slot
  333. * <p>
  334. * For internal use only. May be removed or replaced in the future.
  335. *
  336. * @param caption
  337. * The caption element
  338. * @deprecated As of 7.2, call or override
  339. * {@link #updateCaptionOffset(Element)} instead
  340. */
  341. @Deprecated
  342. public void updateCaptionOffset(com.google.gwt.user.client.Element caption) {
  343. Element captionWrap = caption.getParentElement();
  344. Style captionWrapStyle = captionWrap.getStyle();
  345. captionWrapStyle.clearPaddingTop();
  346. captionWrapStyle.clearPaddingRight();
  347. captionWrapStyle.clearPaddingBottom();
  348. captionWrapStyle.clearPaddingLeft();
  349. Style captionStyle = caption.getStyle();
  350. captionStyle.clearMarginTop();
  351. captionStyle.clearMarginRight();
  352. captionStyle.clearMarginBottom();
  353. captionStyle.clearMarginLeft();
  354. // Get caption position from the classname
  355. CaptionPosition captionPosition = getCaptionPositionFromElement(captionWrap);
  356. if (captionPosition == CaptionPosition.LEFT
  357. || captionPosition == CaptionPosition.RIGHT) {
  358. int captionWidth;
  359. if (layoutManager != null) {
  360. captionWidth = layoutManager.getOuterWidth(caption)
  361. - layoutManager.getMarginWidth(caption);
  362. } else {
  363. captionWidth = caption.getOffsetWidth();
  364. }
  365. if (captionWidth > 0) {
  366. if (captionPosition == CaptionPosition.LEFT) {
  367. captionWrapStyle.setPaddingLeft(captionWidth, Unit.PX);
  368. captionStyle.setMarginLeft(-captionWidth, Unit.PX);
  369. } else {
  370. captionWrapStyle.setPaddingRight(captionWidth, Unit.PX);
  371. captionStyle.setMarginRight(-captionWidth, Unit.PX);
  372. }
  373. }
  374. }
  375. if (captionPosition == CaptionPosition.TOP
  376. || captionPosition == CaptionPosition.BOTTOM) {
  377. int captionHeight;
  378. if (layoutManager != null) {
  379. captionHeight = layoutManager.getOuterHeight(caption)
  380. - layoutManager.getMarginHeight(caption);
  381. } else {
  382. captionHeight = caption.getOffsetHeight();
  383. }
  384. if (captionHeight > 0) {
  385. if (captionPosition == CaptionPosition.TOP) {
  386. captionWrapStyle.setPaddingTop(captionHeight, Unit.PX);
  387. captionStyle.setMarginTop(-captionHeight, Unit.PX);
  388. } else {
  389. captionWrapStyle.setPaddingBottom(captionHeight, Unit.PX);
  390. captionStyle.setMarginBottom(-captionHeight, Unit.PX);
  391. }
  392. }
  393. }
  394. }
  395. /**
  396. * Update the offset off the caption relative to the slot
  397. * <p>
  398. * For internal use only. May be removed or replaced in the future.
  399. *
  400. * @param caption
  401. * The caption element
  402. * @since 7.2
  403. */
  404. public void updateCaptionOffset(Element caption) {
  405. updateCaptionOffset(DOM.asOld(caption));
  406. }
  407. /**
  408. * Set the margin of the layout
  409. *
  410. * @param marginInfo
  411. * The margin information
  412. */
  413. public void setMargin(MarginInfo marginInfo) {
  414. if (marginInfo != null) {
  415. setStyleName("v-margin-top", marginInfo.hasTop());
  416. setStyleName("v-margin-right", marginInfo.hasRight());
  417. setStyleName("v-margin-bottom", marginInfo.hasBottom());
  418. setStyleName("v-margin-left", marginInfo.hasLeft());
  419. }
  420. }
  421. /**
  422. * Turn on or off spacing in the layout
  423. *
  424. * @param spacing
  425. * True if spacing should be used, false if not
  426. */
  427. public void setSpacing(boolean spacing) {
  428. Profiler.enter("VAOL.onConnectorHierarchyChange setSpacing");
  429. this.spacing = spacing;
  430. // first widget does not have spacing on
  431. // optimization to avoid looking up widget indices on every iteration
  432. Widget firstSlot = null;
  433. if (getWidgetCount() > 0) {
  434. firstSlot = getWidget(0);
  435. }
  436. for (Slot slot : widgetToSlot.values()) {
  437. slot.setSpacing(spacing && firstSlot != slot);
  438. }
  439. Profiler.leave("VAOL.onConnectorHierarchyChange setSpacing");
  440. }
  441. /**
  442. * Assigns relative sizes to the children that should expand based on their
  443. * expand ratios.
  444. */
  445. public void updateExpandedSizes() {
  446. // Ensure the expand wrapper is in place
  447. if (expandWrapper == null) {
  448. expandWrapper = DOM.createDiv();
  449. expandWrapper.setClassName("v-expand");
  450. // Detach all widgets before modifying DOM
  451. for (Widget widget : getChildren()) {
  452. orphan(widget);
  453. }
  454. while (getElement().getChildCount() > 0) {
  455. Node el = getElement().getChild(0);
  456. expandWrapper.appendChild(el);
  457. }
  458. getElement().appendChild(expandWrapper);
  459. // Attach all widgets again
  460. for (Widget widget : getChildren()) {
  461. adopt(widget);
  462. }
  463. }
  464. // Sum up expand ratios to get the denominator
  465. double total = 0;
  466. for (Slot slot : widgetToSlot.values()) {
  467. // FIXME expandRatio might be <0
  468. total += slot.getExpandRatio();
  469. }
  470. // Give each expanded child its own share
  471. for (Slot slot : widgetToSlot.values()) {
  472. Element slotElement = slot.getElement();
  473. slotElement.removeAttribute("aria-hidden");
  474. Style slotStyle = slotElement.getStyle();
  475. slotStyle.clearVisibility();
  476. slotStyle.clearMarginLeft();
  477. slotStyle.clearMarginTop();
  478. if (slot.getExpandRatio() != 0) {
  479. // FIXME expandRatio might be <0
  480. double size = 100 * (slot.getExpandRatio() / total);
  481. if (vertical) {
  482. slot.setHeight(size + "%");
  483. if (slot.hasRelativeHeight()) {
  484. Util.notifyParentOfSizeChange(this, true);
  485. }
  486. } else {
  487. slot.setWidth(size + "%");
  488. if (slot.hasRelativeWidth()) {
  489. Util.notifyParentOfSizeChange(this, true);
  490. }
  491. }
  492. } else if (slot.isRelativeInDirection(vertical)) {
  493. // Relative child without expansion gets no space at all
  494. if (vertical) {
  495. slot.setHeight("0");
  496. } else {
  497. slot.setWidth("0");
  498. }
  499. slotStyle.setVisibility(Visibility.HIDDEN);
  500. slotElement.setAttribute("aria-hidden", "true");
  501. } else {
  502. // Non-relative child without expansion should be unconstrained
  503. if (BrowserInfo.get().isIE8()) {
  504. // unconstrained in IE8 is auto
  505. if (vertical) {
  506. slot.setHeight("auto");
  507. } else {
  508. slot.setWidth("auto");
  509. }
  510. } else {
  511. if (vertical) {
  512. slotStyle.clearHeight();
  513. } else {
  514. slotStyle.clearWidth();
  515. }
  516. }
  517. }
  518. }
  519. }
  520. /**
  521. * Removes elements used to expand a slot.
  522. * <p>
  523. * For internal use only. May be removed or replaced in the future.
  524. */
  525. public void clearExpand() {
  526. if (expandWrapper != null) {
  527. // Detach all widgets before modifying DOM
  528. for (Widget widget : getChildren()) {
  529. orphan(widget);
  530. }
  531. lastExpandSize = -1;
  532. while (expandWrapper.getChildCount() > 0) {
  533. Element el = expandWrapper.getChild(0).cast();
  534. getElement().appendChild(el);
  535. if (vertical) {
  536. el.getStyle().clearHeight();
  537. el.getStyle().clearMarginTop();
  538. } else {
  539. el.getStyle().clearWidth();
  540. el.getStyle().clearMarginLeft();
  541. }
  542. }
  543. expandWrapper.removeFromParent();
  544. expandWrapper = null;
  545. // Attach children again
  546. for (Widget widget : getChildren()) {
  547. adopt(widget);
  548. }
  549. }
  550. }
  551. /**
  552. * Updates the expand compensation based on the measured sizes of children
  553. * without expand.
  554. */
  555. public void updateExpandCompensation() {
  556. boolean isExpanding = false;
  557. for (Widget slot : getChildren()) {
  558. // FIXME expandRatio might be <0
  559. if (((Slot) slot).getExpandRatio() != 0) {
  560. isExpanding = true;
  561. break;
  562. }
  563. }
  564. if (isExpanding) {
  565. /*
  566. * Expanded slots have relative sizes that together add up to 100%.
  567. * To make room for slots without expand, we will add padding that
  568. * is not considered for relative sizes and a corresponding negative
  569. * margin for the unexpanded slots. We calculate the size by summing
  570. * the size of all non-expanded non-relative slots.
  571. *
  572. * Relatively sized slots without expansion are considered to get
  573. * 0px, but we still keep them visible (causing overflows) to help
  574. * the developer see what's happening. Forcing them to only get 0px
  575. * would make them disappear which would avoid overflows but would
  576. * instead cause confusion as they would then just disappear without
  577. * any obvious reason.
  578. */
  579. int totalSize = 0;
  580. for (Widget w : getChildren()) {
  581. Slot slot = (Slot) w;
  582. if (slot.getExpandRatio() == 0
  583. && !slot.isRelativeInDirection(vertical)) {
  584. if (layoutManager != null) {
  585. // TODO check caption position
  586. if (vertical) {
  587. int size = layoutManager.getOuterHeight(slot
  588. .getWidget().getElement());
  589. if (slot.hasCaption()) {
  590. size += layoutManager.getOuterHeight(slot
  591. .getCaptionElement());
  592. }
  593. if (size > 0) {
  594. totalSize += size;
  595. }
  596. } else {
  597. int max = -1;
  598. max = layoutManager.getOuterWidth(slot.getWidget()
  599. .getElement());
  600. if (slot.hasCaption()) {
  601. int max2 = layoutManager.getOuterWidth(slot
  602. .getCaptionElement());
  603. max = Math.max(max, max2);
  604. }
  605. if (max > 0) {
  606. totalSize += max;
  607. }
  608. }
  609. } else {
  610. // FIXME expandRatio might be <0
  611. totalSize += vertical ? slot.getOffsetHeight() : slot
  612. .getOffsetWidth();
  613. }
  614. }
  615. // TODO fails in Opera, always returns 0
  616. int spacingSize = vertical ? slot.getVerticalSpacing() : slot
  617. .getHorizontalSpacing();
  618. if (spacingSize > 0) {
  619. totalSize += spacingSize;
  620. }
  621. }
  622. // When we set the margin to the first child, we don't need
  623. // overflow:hidden in the layout root element, since the wrapper
  624. // would otherwise be placed outside of the layout root element
  625. // and block events on elements below it.
  626. if (vertical) {
  627. expandWrapper.getStyle().setPaddingTop(totalSize, Unit.PX);
  628. expandWrapper.getFirstChildElement().getStyle()
  629. .setMarginTop(-totalSize, Unit.PX);
  630. } else {
  631. expandWrapper.getStyle().setPaddingLeft(totalSize, Unit.PX);
  632. expandWrapper.getFirstChildElement().getStyle()
  633. .setMarginLeft(-totalSize, Unit.PX);
  634. }
  635. // Measure expanded children again if their size might have changed
  636. if (totalSize != lastExpandSize) {
  637. lastExpandSize = totalSize;
  638. for (Widget w : getChildren()) {
  639. Slot slot = (Slot) w;
  640. // FIXME expandRatio might be <0
  641. if (slot.getExpandRatio() != 0) {
  642. if (layoutManager != null) {
  643. layoutManager.setNeedsMeasure(Util
  644. .findConnectorFor(slot.getWidget()));
  645. } else if (slot.getWidget() instanceof RequiresResize) {
  646. ((RequiresResize) slot.getWidget()).onResize();
  647. }
  648. }
  649. }
  650. }
  651. }
  652. WidgetUtil.forceIE8Redraw(getElement());
  653. }
  654. /**
  655. * {@inheritDoc}
  656. */
  657. @Override
  658. public void setHeight(String height) {
  659. super.setHeight(height);
  660. definedHeight = (height != null && !"".equals(height));
  661. }
  662. /**
  663. * Sets the slots style names. The style names will be prefixed with the
  664. * v-slot prefix.
  665. *
  666. * @param stylenames
  667. * The style names of the slot.
  668. */
  669. public void setSlotStyleNames(Widget widget, String... stylenames) {
  670. Slot slot = getSlot(widget);
  671. if (slot == null) {
  672. throw new IllegalArgumentException(
  673. "A slot for the widget could not be found. Has the widget been added to the layout?");
  674. }
  675. slot.setStyleNames(stylenames);
  676. }
  677. }