WebRenderObject.cpp 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  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 "WebRenderObject.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/RenderText.h>
  33. #include <WebCore/RenderView.h>
  34. #include <WebCore/RenderWidget.h>
  35. using namespace WebCore;
  36. namespace WebKit {
  37. PassRefPtr<WebRenderObject> WebRenderObject::create(WebPage* page)
  38. {
  39. Frame* mainFrame = page->mainFrame();
  40. if (!mainFrame)
  41. return 0;
  42. if (!mainFrame->loader()->client()->hasHTMLView())
  43. return 0;
  44. RenderView* contentRenderer = mainFrame->contentRenderer();
  45. if (!contentRenderer)
  46. return 0;
  47. return adoptRef(new WebRenderObject(contentRenderer, true));
  48. }
  49. WebRenderObject::WebRenderObject(RenderObject* renderer, bool shouldIncludeDescendants)
  50. {
  51. m_name = renderer->renderName();
  52. if (Node* node = renderer->node()) {
  53. if (node->isElementNode()) {
  54. Element* element = toElement(node);
  55. m_elementTagName = element->tagName();
  56. m_elementID = element->getIdAttribute();
  57. if (element->isStyledElement() && element->hasClass()) {
  58. if (size_t classNameCount = element->classNames().size()) {
  59. m_elementClassNames = MutableArray::create();
  60. for (size_t i = 0; i < classNameCount; ++i)
  61. m_elementClassNames->append(WebString::create(element->classNames()[i]).get());
  62. }
  63. }
  64. }
  65. }
  66. // FIXME: broken with transforms
  67. m_absolutePosition = flooredIntPoint(renderer->localToAbsolute());
  68. if (renderer->isBox())
  69. m_frameRect = toRenderBox(renderer)->pixelSnappedFrameRect();
  70. else if (renderer->isText()) {
  71. m_frameRect = toRenderText(renderer)->linesBoundingBox();
  72. m_frameRect.setX(toRenderText(renderer)->firstRunX());
  73. m_frameRect.setY(toRenderText(renderer)->firstRunY());
  74. } else if (renderer->isRenderInline())
  75. m_frameRect = toRenderBoxModelObject(renderer)->borderBoundingBox();
  76. if (!shouldIncludeDescendants)
  77. return;
  78. m_children = MutableArray::create();
  79. for (RenderObject* coreChild = renderer->firstChild(); coreChild; coreChild = coreChild->nextSibling()) {
  80. RefPtr<WebRenderObject> child = adoptRef(new WebRenderObject(coreChild, shouldIncludeDescendants));
  81. m_children->append(child.get());
  82. }
  83. if (!renderer->isWidget())
  84. return;
  85. Widget* widget = toRenderWidget(renderer)->widget();
  86. if (!widget || !widget->isFrameView())
  87. return;
  88. FrameView* frameView = toFrameView(widget);
  89. if (RenderView* coreContentRenderer = frameView->frame()->contentRenderer()) {
  90. RefPtr<WebRenderObject> contentRenderer = adoptRef(new WebRenderObject(coreContentRenderer, shouldIncludeDescendants));
  91. m_children->append(contentRenderer.get());
  92. }
  93. }
  94. } // namespace WebKit