1/*
2 * Copyright (C) 2009 Google 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 are
6 * met:
7 *
8 *     * Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 *     * Redistributions in binary form must reproduce the above
11 * copyright notice, this list of conditions and the following disclaimer
12 * in the documentation and/or other materials provided with the
13 * distribution.
14 *     * Neither the name of Google Inc. nor the names of its
15 * contributors may be used to endorse or promote products derived from
16 * this software without specific prior written permission.
17 *
18 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
19 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
20 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
21 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
22 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
23 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
24 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29 */
30
31#include "config.h"
32#include "WebDocument.h"
33
34#include "AXObjectCache.h"
35#include "Document.h"
36#include "DocumentType.h"
37#include "Element.h"
38#include "HTMLAllCollection.h"
39#include "HTMLBodyElement.h"
40#include "HTMLCollection.h"
41#include "HTMLElement.h"
42#include "HTMLHeadElement.h"
43#include "NodeList.h"
44
45#include "WebAccessibilityObject.h"
46#include "WebDocumentType.h"
47#include "WebElement.h"
48#include "WebFrameImpl.h"
49#include "WebNodeCollection.h"
50#include "WebNodeList.h"
51#include "WebURL.h"
52
53#include <wtf/PassRefPtr.h>
54
55using namespace WebCore;
56
57namespace WebKit {
58
59WebFrame* WebDocument::frame() const
60{
61    return WebFrameImpl::fromFrame(constUnwrap<Document>()->frame());
62}
63
64bool WebDocument::isHTMLDocument() const
65{
66    return constUnwrap<Document>()->isHTMLDocument();
67}
68
69bool WebDocument::isXHTMLDocument() const
70{
71    return constUnwrap<Document>()->isXHTMLDocument();
72}
73
74bool WebDocument::isPluginDocument() const
75{
76    return constUnwrap<Document>()->isPluginDocument();
77}
78
79WebURL WebDocument::baseURL() const
80{
81    return constUnwrap<Document>()->baseURL();
82}
83
84WebURL WebDocument::firstPartyForCookies() const
85{
86    return constUnwrap<Document>()->firstPartyForCookies();
87}
88
89WebElement WebDocument::documentElement() const
90{
91    return WebElement(constUnwrap<Document>()->documentElement());
92}
93
94WebElement WebDocument::body() const
95{
96    return WebElement(constUnwrap<Document>()->body());
97}
98
99WebElement WebDocument::head()
100{
101    return WebElement(unwrap<Document>()->head());
102}
103
104WebString WebDocument::title() const
105{
106    return WebString(constUnwrap<Document>()->title());
107}
108
109WebNodeCollection WebDocument::all()
110{
111    return WebNodeCollection(unwrap<Document>()->all());
112}
113
114WebURL WebDocument::completeURL(const WebString& partialURL) const
115{
116    return constUnwrap<Document>()->completeURL(partialURL);
117}
118
119WebElement WebDocument::getElementById(const WebString& id) const
120{
121    return WebElement(constUnwrap<Document>()->getElementById(id));
122}
123
124WebNode WebDocument::focusedNode() const
125{
126    return WebNode(constUnwrap<Document>()->focusedNode());
127}
128
129WebDocumentType WebDocument::doctype() const
130{
131    return WebDocumentType(constUnwrap<Document>()->doctype());
132}
133
134WebAccessibilityObject WebDocument::accessibilityObject() const
135{
136    const Document* document = constUnwrap<Document>();
137    return WebAccessibilityObject(
138        document->axObjectCache()->getOrCreate(document->renderer()));
139}
140
141WebDocument::WebDocument(const PassRefPtr<Document>& elem)
142    : WebNode(elem)
143{
144}
145
146WebDocument& WebDocument::operator=(const PassRefPtr<Document>& elem)
147{
148    m_private = elem;
149    return *this;
150}
151
152WebDocument::operator PassRefPtr<Document>() const
153{
154    return static_cast<Document*>(m_private.get());
155}
156
157} // namespace WebKit
158