Ignore contiguous composition event.
[framework/web/webkit-efl.git] / Source / WebKit2 / Shared / WebRenderObject.cpp
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
26 #include "config.h"
27 #include "WebRenderObject.h"
28
29 #include "WebPage.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>
36
37 using namespace WebCore;
38
39 namespace WebKit {
40
41 PassRefPtr<WebRenderObject> WebRenderObject::create(WebPage* page)
42 {
43     Frame* mainFrame = page->mainFrame();
44     if (!mainFrame)
45         return 0;
46
47     if (!mainFrame->loader()->client()->hasHTMLView())
48         return 0;
49
50     RenderView* contentRenderer = mainFrame->contentRenderer();
51     if (!contentRenderer)
52         return 0;
53
54     return adoptRef(new WebRenderObject(contentRenderer, true));
55 }
56
57 WebRenderObject::WebRenderObject(RenderObject* renderer, bool shouldIncludeDescendants)
58 {
59     m_name = renderer->renderName();
60
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());
72                 }
73             }
74         }
75     }
76
77     // FIXME: broken with transforms
78     m_absolutePosition = flooredIntPoint(renderer->localToAbsolute(FloatPoint()));
79
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();
88
89     if (!shouldIncludeDescendants)
90         return;
91
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());
96     }
97
98     if (!renderer->isWidget())
99         return;
100
101     Widget* widget = toRenderWidget(renderer)->widget();
102     if (!widget || !widget->isFrameView())
103         return;
104
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());
109     }
110 }
111
112 } // namespace WebKit