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.

LayoutManagerIE8.java 3.4KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. /*
  2. * Copyright 2000-2013 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;
  17. import java.util.HashMap;
  18. import java.util.Iterator;
  19. import java.util.Map;
  20. import com.google.gwt.dom.client.Element;
  21. import com.google.gwt.dom.client.Node;
  22. import com.google.gwt.user.client.ui.RootPanel;
  23. /**
  24. * Alternative MeasuredSize storage for IE8. Storing any information in a DOM
  25. * element in IE8 seems to make the browser think the element has changed in a
  26. * way that requires a reflow. To work around that, the MeasureData is instead
  27. * stored in Map for IE8.
  28. *
  29. * This implementation is injected for IE8 by a replace-with definition in the
  30. * GWT module.
  31. *
  32. * @author Vaadin Ltd
  33. * @since 7.0.0
  34. */
  35. public class LayoutManagerIE8 extends LayoutManager {
  36. private Map<Element, MeasuredSize> measuredSizes = new HashMap<Element, MeasuredSize>();
  37. // this method is needed to test for memory leaks (see
  38. // LayoutMemoryUsageIE8ExtensionConnector) but can be private
  39. private int getMeasuredSizesMapSize() {
  40. return measuredSizes.size();
  41. }
  42. @Override
  43. protected void setMeasuredSize(Element element, MeasuredSize measuredSize) {
  44. if (measuredSize != null) {
  45. measuredSizes.put(element, measuredSize);
  46. } else {
  47. measuredSizes.remove(element);
  48. }
  49. }
  50. @Override
  51. protected MeasuredSize getMeasuredSize(Element element,
  52. MeasuredSize defaultSize) {
  53. MeasuredSize measured = measuredSizes.get(element);
  54. if (measured != null) {
  55. return measured;
  56. } else {
  57. return defaultSize;
  58. }
  59. }
  60. @Override
  61. protected void cleanMeasuredSizes() {
  62. Profiler.enter("LayoutManager.cleanMeasuredSizes");
  63. // #12688: IE8 was leaking memory when adding&removing components.
  64. // Uses IE specific logic to figure if an element has been removed from
  65. // DOM or not. For this the parent element of the current UI is needed.
  66. // For removed elements the measured size is discarded.
  67. Node rootNode = getConnection().getUIConnector().getWidget()
  68. .getElement().getParentNode();
  69. Iterator<Element> i = measuredSizes.keySet().iterator();
  70. while (i.hasNext()) {
  71. Element e = i.next();
  72. if (!rootNode.isOrHasChild(e)) {
  73. i.remove();
  74. }
  75. }
  76. Profiler.leave("LayoutManager.cleanMeasuredSizes");
  77. }
  78. @Override
  79. protected void performBrowserLayoutHacks() {
  80. Profiler.enter("LayoutManagerIE8.performBrowserLayoutHacks");
  81. /*
  82. * Fixes IE8 issues where IE8 sometimes forgets to update the size of
  83. * the containing element. To force a reflow by modifying the magical
  84. * zoom property.
  85. */
  86. Util.forceIE8Redraw(RootPanel.get().getElement());
  87. Profiler.leave("LayoutManagerIE8.performBrowserLayoutHacks");
  88. }
  89. }