Fix trival typos related to the word "coordinate".
[WebKit-https.git] / Source / WebKit2 / Shared / WebHitTestResult.cpp
1 /*
2  * Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies)
3  *
4  * This library is free software; you can redistribute it and/or
5  * modify it under the terms of the GNU Library General Public
6  * License as published by the Free Software Foundation; either
7  * version 2 of the License, or (at your option) any later version.
8  *
9  * This library is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
12  * Library General Public License for more details.
13  *
14  * You should have received a copy of the GNU Library General Public License
15  * along with this library; see the file COPYING.LIB.  If not, write to
16  * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
17  * Boston, MA 02110-1301, USA.
18  */
19
20 #include "config.h"
21 #include "WebHitTestResult.h"
22
23 #include "WebCoreArgumentCoders.h"
24 #include <WebCore/Document.h>
25 #include <WebCore/Frame.h>
26 #include <WebCore/FrameView.h>
27 #include <WebCore/HitTestResult.h>
28 #include <WebCore/RenderObject.h>
29 #include <WebCore/URL.h>
30 #include <WebCore/Node.h>
31 #include <wtf/text/WTFString.h>
32
33 using namespace WebCore;
34
35 namespace WebKit {
36
37 PassRefPtr<WebHitTestResult> WebHitTestResult::create(const WebHitTestResult::Data& hitTestResultData)
38 {
39     return adoptRef(new WebHitTestResult(hitTestResultData));
40 }
41
42 WebHitTestResult::Data::Data()
43 {
44 }
45
46 WebHitTestResult::Data::Data(const HitTestResult& hitTestResult)
47     : absoluteImageURL(hitTestResult.absoluteImageURL().string())
48     , absolutePDFURL(hitTestResult.absolutePDFURL().string())
49     , absoluteLinkURL(hitTestResult.absoluteLinkURL().string())
50     , absoluteMediaURL(hitTestResult.absoluteMediaURL().string())
51     , linkLabel(hitTestResult.textContent())
52     , linkTitle(hitTestResult.titleDisplayString())
53     , isContentEditable(hitTestResult.isContentEditable())
54     , elementBoundingBox(elementBoundingBoxInWindowCoordinates(hitTestResult))
55     , isScrollbar(hitTestResult.scrollbar())
56     , isSelected(hitTestResult.isSelected())
57     , isTextNode(hitTestResult.innerNode() && hitTestResult.innerNode()->isTextNode())
58     , isOverTextInsideFormControlElement(hitTestResult.isOverTextInsideFormControlElement())
59     , allowsCopy(hitTestResult.allowsCopy())
60     , isDownloadableMedia(hitTestResult.isDownloadableMedia())
61     , imageSize(0)
62 {
63 }
64
65 WebHitTestResult::Data::Data(const WebCore::HitTestResult& hitTestResult, bool includeImage)
66     : absoluteImageURL(hitTestResult.absoluteImageURL().string())
67     , absolutePDFURL(hitTestResult.absolutePDFURL().string())
68     , absoluteLinkURL(hitTestResult.absoluteLinkURL().string())
69     , absoluteMediaURL(hitTestResult.absoluteMediaURL().string())
70     , linkLabel(hitTestResult.textContent())
71     , linkTitle(hitTestResult.titleDisplayString())
72     , isContentEditable(hitTestResult.isContentEditable())
73     , elementBoundingBox(elementBoundingBoxInWindowCoordinates(hitTestResult))
74     , isScrollbar(hitTestResult.scrollbar())
75     , isSelected(hitTestResult.isSelected())
76     , isTextNode(hitTestResult.innerNode() && hitTestResult.innerNode()->isTextNode())
77     , isOverTextInsideFormControlElement(hitTestResult.isOverTextInsideFormControlElement())
78     , allowsCopy(hitTestResult.allowsCopy())
79     , isDownloadableMedia(hitTestResult.isDownloadableMedia())
80     , imageSize(0)
81 {
82     if (!includeImage)
83         return;
84
85     if (Image* image = hitTestResult.image()) {
86         RefPtr<SharedBuffer> buffer = image->data();
87         String filenameExtension = image->filenameExtension();
88         if (!filenameExtension.isEmpty() && buffer) {
89             imageSharedMemory = SharedMemory::create(buffer->size());
90             memcpy(imageSharedMemory->data(), buffer->data(), buffer->size());
91             imageExtension = filenameExtension;
92             imageSize = buffer->size();
93         }
94     }
95 }
96
97 WebHitTestResult::Data::~Data()
98 {
99 }
100
101 void WebHitTestResult::Data::encode(IPC::ArgumentEncoder& encoder) const
102 {
103     encoder << absoluteImageURL;
104     encoder << absolutePDFURL;
105     encoder << absoluteLinkURL;
106     encoder << absoluteMediaURL;
107     encoder << linkLabel;
108     encoder << linkTitle;
109     encoder << isContentEditable;
110     encoder << elementBoundingBox;
111     encoder << isScrollbar;
112     encoder << isSelected;
113     encoder << isTextNode;
114     encoder << isOverTextInsideFormControlElement;
115     encoder << allowsCopy;
116     encoder << isDownloadableMedia;
117     encoder << hitTestLocationInViewCoordinates;
118     encoder << lookupText;
119     encoder << dictionaryPopupInfo;
120
121     SharedMemory::Handle imageHandle;
122     if (imageSharedMemory && imageSharedMemory->data())
123         imageSharedMemory->createHandle(imageHandle, SharedMemory::ReadOnly);
124     encoder << imageHandle;
125     encoder << imageSize;
126     encoder << imageExtension;
127
128     bool hasLinkTextIndicator = linkTextIndicator;
129     encoder << hasLinkTextIndicator;
130     if (hasLinkTextIndicator)
131         encoder << linkTextIndicator->data();
132
133     platformEncode(encoder);
134 }
135
136 bool WebHitTestResult::Data::decode(IPC::ArgumentDecoder& decoder, WebHitTestResult::Data& hitTestResultData)
137 {
138     if (!decoder.decode(hitTestResultData.absoluteImageURL)
139         || !decoder.decode(hitTestResultData.absolutePDFURL)
140         || !decoder.decode(hitTestResultData.absoluteLinkURL)
141         || !decoder.decode(hitTestResultData.absoluteMediaURL)
142         || !decoder.decode(hitTestResultData.linkLabel)
143         || !decoder.decode(hitTestResultData.linkTitle)
144         || !decoder.decode(hitTestResultData.isContentEditable)
145         || !decoder.decode(hitTestResultData.elementBoundingBox)
146         || !decoder.decode(hitTestResultData.isScrollbar)
147         || !decoder.decode(hitTestResultData.isSelected)
148         || !decoder.decode(hitTestResultData.isTextNode)
149         || !decoder.decode(hitTestResultData.isOverTextInsideFormControlElement)
150         || !decoder.decode(hitTestResultData.allowsCopy)
151         || !decoder.decode(hitTestResultData.isDownloadableMedia)
152         || !decoder.decode(hitTestResultData.hitTestLocationInViewCoordinates)
153         || !decoder.decode(hitTestResultData.lookupText)
154         || !decoder.decode(hitTestResultData.dictionaryPopupInfo))
155         return false;
156
157     SharedMemory::Handle imageHandle;
158     if (!decoder.decode(imageHandle))
159         return false;
160
161     if (!imageHandle.isNull())
162         hitTestResultData.imageSharedMemory = SharedMemory::create(imageHandle, SharedMemory::ReadOnly);
163
164     if (!decoder.decode(hitTestResultData.imageSize))
165         return false;
166
167     if (!decoder.decode(hitTestResultData.imageExtension))
168         return false;
169
170     bool hasLinkTextIndicator;
171     if (!decoder.decode(hasLinkTextIndicator))
172         return false;
173
174     if (hasLinkTextIndicator) {
175         WebCore::TextIndicatorData indicatorData;
176         if (!decoder.decode(indicatorData))
177             return false;
178
179         hitTestResultData.linkTextIndicator = WebCore::TextIndicator::create(indicatorData);
180     }
181
182     return platformDecode(decoder, hitTestResultData);
183 }
184
185 #if !PLATFORM(MAC)
186 void WebHitTestResult::Data::platformEncode(IPC::ArgumentEncoder& encoder) const
187 {
188 }
189
190 bool WebHitTestResult::Data::platformDecode(IPC::ArgumentDecoder& decoder, WebHitTestResult::Data& hitTestResultData)
191 {
192     return true;
193 }
194 #endif // !PLATFORM(MAC)
195
196 IntRect WebHitTestResult::Data::elementBoundingBoxInWindowCoordinates(const HitTestResult& hitTestResult)
197 {
198     Node* node = hitTestResult.innerNonSharedNode();
199     if (!node)
200         return IntRect();
201
202     Frame* frame = node->document().frame();
203     if (!frame)
204         return IntRect();
205
206     FrameView* view = frame->view();
207     if (!view)
208         return IntRect();
209
210     RenderObject* renderer = node->renderer();
211     if (!renderer)
212         return IntRect();
213
214     return view->contentsToWindow(renderer->absoluteBoundingBoxRect());
215 }
216
217 } // WebKit