WebRenderLayer.cpp 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  1. /*
  2. * Copyright (C) 2012 Apple Inc. All rights reserved.
  3. *
  4. * Redistribution and use in source and binary forms, with or without
  5. * modification, are permitted provided that the following conditions
  6. * are met:
  7. * 1. Redistributions of source code must retain the above copyright
  8. * notice, this list of conditions and the following disclaimer.
  9. * 2. Redistributions in binary form must reproduce the above copyright
  10. * notice, this list of conditions and the following disclaimer in the
  11. * documentation and/or other materials provided with the distribution.
  12. *
  13. * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
  14. * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
  15. * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
  16. * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
  17. * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
  18. * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
  19. * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
  20. * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
  21. * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
  22. * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
  23. * THE POSSIBILITY OF SUCH DAMAGE.
  24. */
  25. #include "config.h"
  26. #include "WebRenderLayer.h"
  27. #include "WebPage.h"
  28. #include "WebString.h"
  29. #include <WebCore/Frame.h>
  30. #include <WebCore/FrameLoader.h>
  31. #include <WebCore/FrameLoaderClient.h>
  32. #include <WebCore/RenderLayer.h>
  33. #include <WebCore/RenderLayerBacking.h>
  34. #include <WebCore/RenderView.h>
  35. #include <WebCore/StyledElement.h>
  36. using namespace WebCore;
  37. namespace WebKit {
  38. PassRefPtr<WebRenderLayer> WebRenderLayer::create(WebPage* page)
  39. {
  40. Frame* mainFrame = page->mainFrame();
  41. if (!mainFrame)
  42. return 0;
  43. if (!mainFrame->loader()->client()->hasHTMLView())
  44. return 0;
  45. RenderView* contentRenderer = mainFrame->contentRenderer();
  46. if (!contentRenderer)
  47. return 0;
  48. RenderLayer* rootLayer = contentRenderer->layer();
  49. if (!rootLayer)
  50. return 0;
  51. return adoptRef(new WebRenderLayer(rootLayer));
  52. }
  53. PassRefPtr<MutableArray> WebRenderLayer::createArrayFromLayerList(Vector<RenderLayer*>* list)
  54. {
  55. if (!list || !list->size())
  56. return 0;
  57. RefPtr<MutableArray> array = MutableArray::create();
  58. for (size_t i = 0; i < list->size(); ++i) {
  59. RefPtr<WebRenderLayer> layer = adoptRef(new WebRenderLayer(list->at(i)));
  60. array->append(layer.get());
  61. }
  62. return array.release();
  63. }
  64. WebRenderLayer::WebRenderLayer(RenderLayer* layer)
  65. {
  66. m_renderer = WebRenderObject::create(layer->renderer());
  67. m_isReflection = layer->isReflection();
  68. #if USE(ACCELERATED_COMPOSITING)
  69. if (layer->isComposited()) {
  70. RenderLayerBacking* backing = layer->backing();
  71. m_isClipping = backing->hasClippingLayer();
  72. m_isClipped = backing->hasAncestorClippingLayer();
  73. switch (backing->compositingLayerType()) {
  74. case NormalCompositingLayer:
  75. m_compositingLayerType = Normal;
  76. break;
  77. case TiledCompositingLayer:
  78. m_compositingLayerType = Tiled;
  79. break;
  80. case MediaCompositingLayer:
  81. m_compositingLayerType = Media;
  82. break;
  83. case ContainerCompositingLayer:
  84. m_compositingLayerType = Container;
  85. break;
  86. }
  87. } else {
  88. #endif
  89. m_isClipping = false;
  90. m_isClipped = false;
  91. m_compositingLayerType = None;
  92. #if USE(ACCELERATED_COMPOSITING)
  93. }
  94. #endif
  95. m_absoluteBoundingBox = layer->absoluteBoundingBox();
  96. m_negativeZOrderList = createArrayFromLayerList(layer->negZOrderList());
  97. m_normalFlowList = createArrayFromLayerList(layer->normalFlowList());
  98. m_positiveZOrderList = createArrayFromLayerList(layer->posZOrderList());
  99. }
  100. } // namespace WebKit