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.3KB

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