2 * Copyright (C) 2012 Apple Inc. All rights reserved.
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions
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.
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.
27 #include "WebRenderObject.h"
30 #include "WebString.h"
31 #include <WebCore/Frame.h>
32 #include <WebCore/FrameLoaderClient.h>
33 #include <WebCore/RenderText.h>
34 #include <WebCore/RenderView.h>
35 #include <WebCore/RenderWidget.h>
37 using namespace WebCore;
41 PassRefPtr<WebRenderObject> WebRenderObject::create(WebPage* page)
43 Frame* mainFrame = page->mainFrame();
47 if (!mainFrame->loader()->client()->hasHTMLView())
50 RenderView* contentRenderer = mainFrame->contentRenderer();
54 return adoptRef(new WebRenderObject(contentRenderer, true));
57 WebRenderObject::WebRenderObject(RenderObject* renderer, bool shouldIncludeDescendants)
59 m_name = renderer->renderName();
61 if (Node* node = renderer->node()) {
62 if (node->isElementNode()) {
63 Element* element = toElement(node);
64 m_elementTagName = element->tagName();
65 m_elementID = element->getIdAttribute();
66 if (element->isStyledElement() && element->hasClass()) {
67 StyledElement* styledElement = static_cast<StyledElement*>(element);
68 if (size_t classNameCount = styledElement->classNames().size()) {
69 m_elementClassNames = MutableArray::create();
70 for (size_t i = 0; i < classNameCount; ++i)
71 m_elementClassNames->append(WebString::create(styledElement->classNames()[i]).get());
77 // FIXME: broken with transforms
78 m_absolutePosition = flooredIntPoint(renderer->localToAbsolute(FloatPoint()));
80 if (renderer->isBox())
81 m_frameRect = toRenderBox(renderer)->pixelSnappedFrameRect();
82 else if (renderer->isText()) {
83 m_frameRect = toRenderText(renderer)->linesBoundingBox();
84 m_frameRect.setX(toRenderText(renderer)->firstRunX());
85 m_frameRect.setY(toRenderText(renderer)->firstRunY());
86 } else if (renderer->isRenderInline())
87 m_frameRect = toRenderBoxModelObject(renderer)->borderBoundingBox();
89 if (!shouldIncludeDescendants)
92 m_children = MutableArray::create();
93 for (RenderObject* coreChild = renderer->firstChild(); coreChild; coreChild = coreChild->nextSibling()) {
94 RefPtr<WebRenderObject> child = adoptRef(new WebRenderObject(coreChild, shouldIncludeDescendants));
95 m_children->append(child.get());
98 if (!renderer->isWidget())
101 Widget* widget = toRenderWidget(renderer)->widget();
102 if (!widget || !widget->isFrameView())
105 FrameView* frameView = static_cast<FrameView*>(widget);
106 if (RenderView* coreContentRenderer = frameView->frame()->contentRenderer()) {
107 RefPtr<WebRenderObject> contentRenderer = adoptRef(new WebRenderObject(coreContentRenderer, shouldIncludeDescendants));
108 m_children->append(contentRenderer.get());
112 } // namespace WebKit