Remove deprecated old Reader code
[profile/ivi/webkit-efl.git] / Source / WebKit2 / WebProcess / WebPage / efl / WebPageEfl.cpp
1 /*
2  * Copyright (C) 2010 Apple Inc. All rights reserved.
3  * Portions Copyright (c) 2010 Motorola Mobility, Inc.  All rights reserved.
4  * Copyright (C) 2011 Igalia S.L.
5  *
6  * Redistribution and use in source and binary forms, with or without
7  * modification, are permitted provided that the following conditions
8  * are met:
9  * 1. Redistributions of source code must retain the above copyright
10  *    notice, this list of conditions and the following disclaimer.
11  * 2. Redistributions in binary form must reproduce the above copyright
12  *    notice, this list of conditions and the following disclaimer in the
13  *    documentation and/or other materials provided with the distribution.
14  *
15  * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
16  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
17  * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
18  * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
19  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
20  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
21  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
22  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
23  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
24  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
25  * THE POSSIBILITY OF SUCH DAMAGE.
26  */
27
28 #include "config.h"
29 #include "WebPage.h"
30
31 #include "NamedNodeMap.h"
32 #include "NotImplemented.h"
33 #include "WebEvent.h"
34 #include "WindowsKeyboardCodes.h"
35 #include <WebCore/EflKeyboardUtilities.h>
36 #include <WebCore/FocusController.h>
37 #include <WebCore/Frame.h>
38 #include <WebCore/KeyboardEvent.h>
39 #include <WebCore/Page.h>
40 #include <WebCore/PlatformKeyboardEvent.h>
41 #include <WebCore/Settings.h>
42
43 #if OS(TIZEN)
44 #include "Arguments.h"
45 #include "PlatformContextCairo.h"
46 #include "WebCoreArgumentCoders.h"
47 #include "WebFrame.h"
48 #include "WebImage.h"
49 #include "WebPageProxyMessages.h"
50 #include <WebCore/FrameView.h>
51
52 #if ENABLE(TIZEN_INPUT_TAG_EXTENSION)
53 #include <WebCore/HTMLInputElement.h>
54 #include <WebCore/HTMLNames.h>
55 #endif
56
57 #if ENABLE(TIZEN_MOBILE_WEB_PRINT)
58 #include <WebCore/PlatformContextCairo.h>
59 #endif
60
61 #if ENABLE(TIZEN_SUPPORT_RSS_LINK_PARSING)
62 #include "HTMLLinkElement.h"
63 #include <WebCore/html/HTMLAllCollection.h>
64 #include <efl/RssItemEfl.h>
65 #endif
66
67 #if ENABLE(TIZEN_WEBKIT_PASTEBOARD)
68 #include <WebCore/Pasteboard.h>
69 #endif
70
71 #if ENABLE(TIZEN_WEBKIT2_REMOTE_WEB_INSPECTOR)
72 #include "WebInspectorServerEfl.h"
73 #endif
74
75 #if ENABLE(TIZEN_WEB_STORAGE)
76 #include <WebCore/GroupSettings.h>
77 #include <WebCore/PageGroup.h>
78 #endif
79
80 #if ENABLE(TIZEN_NPAPI)
81 #include "PluginView.h"
82 #endif
83
84 #if ENABLE(TIZEN_PREFERENCE)
85 #include "WebPreferencesStore.h"
86 #include <WebCore/Settings.h>
87 #endif
88
89 #if ENABLE(TIZEN_WEBKIT2_FOCUS_RING)
90 #include <WebCore/HTMLFrameOwnerElement.h>
91 #include <WebCore/HTMLImageElement.h>
92 #endif
93
94 #if ENABLE(TIZEN_DEVICE_ORIENTATION)
95 #include "DeviceMotionClientEfl.h"
96 #include "DeviceOrientationClientEfl.h"
97 #endif
98
99 #if ENABLE(TIZEN_WEBKIT2_THEME_SET)
100 #include <WebCore/RenderThemeEfl.h>
101 #endif
102
103 #if ENABLE(TIZEN_CSS_OVERFLOW_SCROLL_ACCELERATION_ON_UI_SIDE)
104 #include "RenderLayer.h"
105 #include "WebGraphicsLayer.h"
106 #endif
107
108 #if ENABLE(TIZEN_ISF_PORT)
109 #include "WebEditorClient.h"
110 #endif
111
112 #if ENABLE(TIZEN_DATALIST_ELEMENT)
113 #include "HTMLCollection.h"
114 #include "HTMLDataListElement.h"
115 #include "HTMLOptionElement.h"
116 #endif
117
118 #endif // #if OS(TIZEN)
119
120 using namespace WebCore;
121
122 namespace WebKit {
123
124 void WebPage::platformInitialize()
125 {
126 #if ENABLE(TIZEN_DEVICE_ORIENTATION)
127     WebCore::provideDeviceMotionTo(m_page.get(), new DeviceMotionClientEfl);
128     WebCore::provideDeviceOrientationTo(m_page.get(), new DeviceOrientationClientEfl);
129 #endif
130 }
131
132 #if ENABLE(TIZEN_PREFERENCE)
133 void WebPage::platformPreferencesDidChange(const WebPreferencesStore& store)
134 {
135     Settings* settings = m_page->settings();
136     settings->setInteractiveFormValidationEnabled(store.getBoolValueForKey(WebPreferencesKey::interactiveFormValidationEnabledKey()));
137     settings->setViewWidth(store.getUInt32ValueForKey(WebPreferencesKey::viewWidthKey()));
138     settings->setViewHeight(store.getUInt32ValueForKey(WebPreferencesKey::viewHeightKey()));
139     settings->setUsesEncodingDetector(store.getBoolValueForKey(WebPreferencesKey::usesEncodingDetectorKey()));
140 #if ENABLE(TIZEN_LOAD_REMOTE_IMAGES)
141     settings->setLoadRemoteImages(store.getBoolValueForKey(WebPreferencesKey::loadRemoteImagesKey()));
142 #endif
143 #if ENABLE(TIZEN_ISF_PORT)
144     settings->setShowImeOnAutofocus(store.getBoolValueForKey(WebPreferencesKey::showImeOnAutofocusKey()));
145     settings->setEnableDefaultKeypad(store.getBoolValueForKey(WebPreferencesKey::defaultKeypadEnabledKey()));
146 #endif
147 #if ENABLE(TIZEN_WAC_DISABLE_GEOLOCATION)
148     settings->setGeolocationEnabled(store.getBoolValueForKey(WebPreferencesKey::geolocationEnabledKey()));
149 #endif
150 }
151 #else
152 void WebPage::platformPreferencesDidChange(const WebPreferencesStore&)
153 {
154     notImplemented();
155 }
156 #endif // #if ENABLE(TIZEN_PREFERENCE)
157
158 static inline void scroll(Page* page, ScrollDirection direction, ScrollGranularity granularity)
159 {
160     page->focusController()->focusedOrMainFrame()->eventHandler()->scrollRecursively(direction, granularity);
161 }
162
163 bool WebPage::performDefaultBehaviorForKeyEvent(const WebKeyboardEvent& keyboardEvent)
164 {
165     notImplemented();
166     return false;
167 }
168
169 bool WebPage::platformHasLocalDataForURL(const KURL&)
170 {
171     notImplemented();
172     return false;
173 }
174
175 String WebPage::cachedResponseMIMETypeForURL(const KURL&)
176 {
177     notImplemented();
178     return String();
179 }
180
181 bool WebPage::platformCanHandleRequest(const ResourceRequest&)
182 {
183     notImplemented();
184     return true;
185 }
186
187 String WebPage::cachedSuggestedFilenameForURL(const KURL&)
188 {
189     notImplemented();
190     return String();
191 }
192
193 PassRefPtr<SharedBuffer> WebPage::cachedResponseDataForURL(const KURL&)
194 {
195     notImplemented();
196     return 0;
197 }
198
199 const char* WebPage::interpretKeyEvent(const KeyboardEvent* event)
200 {
201     ASSERT(event->type() == eventNames().keydownEvent || event->type() == eventNames().keypressEvent);
202
203     if (event->type() == eventNames().keydownEvent)
204         return getKeyDownCommandName(event);
205
206     return getKeyPressCommandName(event);
207 }
208
209 #if OS(TIZEN)
210
211 #if ENABLE(TIZEN_WEBKIT2_TILED_BACKING_STORE)
212 IntSize WebPage::contentsSize() const
213 {
214     FrameView* frameView = m_page->mainFrame()->view();
215     if (!frameView)
216         return IntSize(0, 0);
217
218     return frameView->contentsSize();
219 }
220 #endif
221
222 void WebPage::scrollMainFrameBy(const IntSize& scrollOffset)
223 {
224     m_page->mainFrame()->view()->scrollBy(scrollOffset);
225 }
226
227 void WebPage::scrollMainFrameTo(const IntPoint& scrollPosition)
228 {
229     m_page->mainFrame()->view()->setScrollPosition(scrollPosition);
230 }
231
232 void WebPage::createSnapshot(const IntRect rect, float scaleFactor, ShareableBitmap::Handle& snapshotHandle)
233 {
234     FrameView* frameView = m_mainFrame->coreFrame()->view();
235     if (!frameView)
236         return;
237
238     RefPtr<WebImage> snapshotImage = scaledSnapshotInViewCoordinates(rect, scaleFactor, ImageOptionsShareable);
239     if (!snapshotImage || !snapshotImage->bitmap())
240         return;
241
242     snapshotImage->bitmap()->createHandle(snapshotHandle);
243 }
244
245 void WebPage::requestUpdateFormNavigation()
246 {
247     Frame* frame = m_page->focusController()->focusedOrMainFrame();
248     if (!frame)
249         return;
250
251     Document* document = frame->document();
252     if (!document)
253         return;
254
255     Node* focusedNode = document->focusedNode();
256
257     Vector<RefPtr<Node> > focusableNodes;
258     document->getFocusableNodes(focusableNodes);
259
260     int formElementCount = 0;
261     int currentNodeIndex = -1;
262     const Vector<RefPtr<Node> >::iterator end = focusableNodes.end();
263     for (Vector<RefPtr<Node> >::iterator it = focusableNodes.begin(); it != end; ++it) {
264         AtomicString nodeName = (*it).get()->nodeName();
265         if (equalIgnoringCase(nodeName, "SELECT")
266             || (equalIgnoringCase(nodeName, "INPUT")
267                 && !equalIgnoringCase((*it).get()->toInputElement()->type(), "CHECKBOX")
268                 && !equalIgnoringCase((*it).get()->toInputElement()->type(), "RADIO")
269                 && !equalIgnoringCase((*it).get()->toInputElement()->type(), "SUBMIT")
270                 )
271             ) {
272             if ((*it).get() == focusedNode)
273                 currentNodeIndex = formElementCount;
274             formElementCount++;
275         }
276     }
277
278     if (currentNodeIndex == -1)
279         return;
280
281     send(Messages::WebPageProxy::UpdateFormNavigation(formElementCount, currentNodeIndex));
282 }
283
284 void WebPage::moveFocus(int newIndex)
285 {
286     Frame* frame = m_page->focusController()->focusedOrMainFrame();
287     if (!frame)
288         return;
289
290     Document* document = frame->document();
291     if (!document)
292         return;
293
294     Vector<RefPtr<Node> > focusableNodes;
295     document->getFocusableNodes(focusableNodes);
296
297     int index = 0;
298     const Vector<RefPtr<Node> >::iterator end = focusableNodes.end();
299     for (Vector<RefPtr<Node> >::iterator it = focusableNodes.begin(); it != end; ++it) {
300         AtomicString nodeName = (*it).get()->nodeName();
301         if (equalIgnoringCase(nodeName, "SELECT")) {
302             if (index == newIndex) {
303                 (*it).get()->setFocus();
304                 LayoutPoint position = LayoutPoint(0, 0);
305                 PlatformMouseEvent event(flooredIntPoint(position), flooredIntPoint(position), LeftButton, PlatformEvent::MouseMoved, 1, false, false, false, false, 0);
306                 (*it).get()->dispatchMouseEvent(event, "mousedown", 0, 0);
307             }
308             index++;
309         } else if (equalIgnoringCase(nodeName, "INPUT")
310             && !equalIgnoringCase((*it).get()->toInputElement()->type(), "CHECKBOX")
311             && !equalIgnoringCase((*it).get()->toInputElement()->type(), "RADIO")
312             ) {
313             if (index == newIndex) {
314                 HTMLInputElement* elem = (*it).get()->toInputElement();
315                 elem->focus();
316             }
317             index++;
318         }
319     }
320 }
321
322 #if ENABLE(TIZEN_MOBILE_WEB_PRINT)
323 #define A4_WIDTH 210
324 #define A4_HEIGHT 297
325 #define INCH_TO_MM 25.4
326 #define INCH_TO_POINTS 72.0
327
328 void WebPage::createPagesToPDF(const IntSize& size, const String& fileName)
329 {
330     FrameView* frameView = m_mainFrame->coreFrame()->view();
331     if (!frameView)
332         return;
333
334     RefPtr<WebImage> pageshotImage = WebImage::create(size, ImageOptionsShareable);
335     if (!pageshotImage->bitmap())
336         return;
337
338     double pdfWidth = A4_WIDTH / INCH_TO_MM * INCH_TO_POINTS;
339     double pdfHeight = A4_HEIGHT / INCH_TO_MM * INCH_TO_POINTS;
340     double scaleFactorPdf = pdfWidth / (double)size.width();
341
342     OwnPtr<WebCore::GraphicsContext> graphicsContext = pageshotImage->bitmap()->createGraphicsContextForPdfSurface(fileName, pdfWidth, pdfHeight);
343     graphicsContext->scale(FloatSize(scaleFactorPdf, scaleFactorPdf));
344
345     frameView->updateLayoutAndStyleIfNeededRecursive();
346
347     int pageNumber = ((size.height() * scaleFactorPdf) / pdfHeight) + 1;
348     IntRect paintRect(0, 0, size.width(), size.height());
349
350     PaintBehavior oldBehavior = frameView->paintBehavior();
351     frameView->setPaintBehavior(oldBehavior | PaintBehaviorFlattenCompositingLayers);
352     for (int i = 0; i < pageNumber; i++) {
353         frameView->paint(graphicsContext.get(), paintRect);
354         cairo_show_page(graphicsContext->platformContext()->cr());
355         graphicsContext->translate(0, -ceil(pdfHeight / scaleFactorPdf));
356     }
357     frameView->setPaintBehavior(oldBehavior);
358
359     pageshotImage.release();
360 }
361 #endif
362
363 void WebPage::confirmComposition(const String& compositionString)
364 {
365     Frame* frame = m_page->focusController()->focusedOrMainFrame();
366     if (!frame || !frame->editor()->canEdit())
367         return;
368     frame->editor()->confirmComposition(compositionString);
369 }
370
371 void WebPage::setComposition(const String& compositionString, const Vector<WebCore::CompositionUnderline>& underlines, uint64_t cursorPosition)
372 {
373     Frame* frame = m_page->focusController()->focusedOrMainFrame();
374     if (!frame || !frame->editor()->canEdit())
375         return;
376     frame->editor()->setComposition(compositionString, underlines, cursorPosition, 0);
377 }
378
379 #if ENABLE(TIZEN_TEXT_CARET_HANDLING_WK2)
380 bool WebPage::setCaretPosition(const WebCore::IntPoint& pos)
381 {
382     Frame* frame = m_page->focusController()->focusedOrMainFrame();
383     if (!frame)
384         return false;
385
386     WebCore::FrameSelection* controller = frame->selection();
387     if (!controller)
388         return false;
389
390     FrameView* frameView = frame->view();
391     if (!frameView)
392         return false;
393
394     WebCore::IntPoint point = pos;
395     WebCore::HitTestResult result = frame->eventHandler()->hitTestResultAtPoint(frameView->windowToContents(point), /*allowShadowContent*/ true, /*ignoreClipping*/ true);
396     if (result.scrollbar())
397         return false;
398
399     WebCore::Node* innerNode = result.innerNode();
400
401     if (!innerNode || !innerNode->renderer())
402         return false;
403
404     WebCore::VisiblePosition visiblePos;
405
406     const int boundariesWidth = 2;
407
408     // we check if content is richly editable - because those input field behave other than plain text ones
409     // sometimes they may consists a node structure and they need special approach
410     if (innerNode->rendererIsRichlyEditable()) {
411         // point gets inner node local coordinates
412         point = flooredIntPoint(result.localPoint());
413         WebCore::IntRect rect = innerNode->renderer()->absoluteBoundingBoxRect(true);
414
415         // it is not the best way to do this, but it is not as slow and it works - so maybe in the future someone
416         // will have a better idea how to solve it
417         // here we are getting innerNode from HitTestResult - unfortunately this is a kind of high level node
418         // in the code below I am trying to obtain low level node - #text - to get its coordinates and size
419
420         // all those getting nodes rects are needed to bypass WebCore's methods of positioning caret when user
421         // is clicking outside a node - and cheat WebCore telling it that actually we clicked into input field
422         // node, not outside of it
423         WebCore::Node* deepInnerNode = innerNode->renderer()->positionForPoint(point).deepEquivalent().deprecatedNode();
424
425         if (!deepInnerNode || !deepInnerNode->renderer())
426             return false;
427
428         // so we get a base node rectange
429         WebCore::IntRect deepNodeRect = deepInnerNode->renderer()->absoluteBoundingBoxRect(true);
430
431         // we modify our local point to adjust it to base node local coordinates
432         point.move(rect.x() - deepNodeRect.x(), rect.y() - deepNodeRect.y());
433
434         // if we are outside the rect we cheat, that we are just inside of it
435         if (point.y() < 0)
436             point.setY(0);
437         else if (point.y() >= deepNodeRect.height())
438             point.setY(deepNodeRect.height() - 1);
439
440         // visible position created - caret ready to set
441         visiblePos = deepInnerNode->renderer()->positionForPoint(point);
442         if (visiblePos.isNull())
443             return false;
444     } else {
445         // for plain text input fields we can get only a caret bounding box
446         if (!controller->isCaret() || !controller->caretRenderer())
447             return false;
448
449         const WebCore::Node* node = controller->start().deprecatedNode();
450         if (!node || !node->renderer())
451             return false;
452
453         WebCore::IntRect rect = controller->caretRenderer()->absoluteBoundingBoxRect(true);
454
455         // here we also cheat input field that we actually are just inside of if
456         if (point.x() < rect.x())
457             point.setX(rect.x());
458         else if (point.x() > rect.maxX())
459             point.setX(rect.maxX());
460         if (point.y() < rect.y() + boundariesWidth)
461             point.setY(rect.y() + boundariesWidth);
462         else if (point.y() >= rect.maxY() - boundariesWidth)
463             point.setY(rect.maxY() - boundariesWidth - 1);
464
465         // hit test with fake (adjusted) coordinates
466         WebCore::HitTestResult newResult = frame->eventHandler()->hitTestResultAtPoint
467                 (point, /*allowShadowContent*/ true, /*ignoreClipping*/ true);
468
469         if (!newResult.isContentEditable())
470             return false;
471
472         WebCore::Node* newInnerNode = newResult.innerNode();
473
474         if (!newInnerNode || !newInnerNode->renderer())
475             return false;
476
477         // visible position created
478         visiblePos = newInnerNode->renderer()->positionForPoint(newResult.localPoint());
479         if (visiblePos.isNull())
480             return false;
481     }
482
483     // create visible selection from visible position
484     WebCore::VisibleSelection newSelection = WebCore::VisibleSelection(visiblePos);
485     controller->setSelection(newSelection, WebCore::CharacterGranularity);
486     // after setting selection caret blinking is suspended by default so we are unsuspedning it
487     controller->setCaretBlinkingSuspended(false);
488
489     return true;
490 }
491
492 void WebPage::getCaretPosition(WebCore::IntRect& rect)
493 {
494     Frame* frame = m_page->focusController()->focusedOrMainFrame();
495     if (!frame)
496         return;
497
498     WebCore::FrameSelection* controller = frame->selection();
499     if (!controller)
500         return;
501
502     WebCore::Node* node = controller->start().deprecatedNode();
503     if (!node || !node->renderer() || !node->isContentEditable())
504         return;
505
506     if (controller->isCaret()) {
507         FrameView* frameView = frame->view();
508         if (!frameView)
509             return;
510
511         rect = frameView->contentsToWindow(controller->absoluteCaretBounds());
512     }
513 }
514 #endif
515
516 #if ENABLE(TIZEN_ISF_PORT)
517 void WebPage::getCursorOffsetPosition(int& offset)
518 {
519     offset = 0;
520     Frame* frame = m_page->focusController()->focusedOrMainFrame();
521     if (!frame || !frame->editor()->canEdit())
522         return;
523
524     Position base = frame->selection()->base();
525     Node* baseNode = base.containerNode();
526     if (baseNode)
527         offset = baseNode->isTextNode() ? base.offsetInContainerNode() : 0;
528 }
529
530 void WebPage::getContentOfPosition(String& content)
531 {
532     Frame* frame = m_page->focusController()->focusedOrMainFrame();
533     if (!frame || !frame->editor()->canEdit())
534         return;
535
536     Position base = frame->selection()->base();
537     Node* baseNode = base.containerNode();
538     if (baseNode && baseNode->isTextNode())
539         content = baseNode->textContent();
540     else
541         content = String();
542 }
543
544 void WebPage::deleteSurroundingPosition(bool& result)
545 {
546     Frame* frame = m_page->focusController()->focusedOrMainFrame();
547     if (!frame || !frame->editor()->canEdit())
548         return;
549
550     frame->editor()->deleteWithDirection(DirectionBackward, CharacterGranularity, false, true);
551 }
552 #endif
553
554 #if ENABLE(TIZEN_INPUT_TAG_EXTENSION)
555 void WebPage::setFocusedInputElementValue(const String& inputValue)
556 {
557     Frame* frame = m_page->focusController()->focusedOrMainFrame();
558     if (frame
559         && frame->document()
560         && frame->document()->focusedNode()) {
561         Node* node = frame->document()->focusedNode();
562         if (node->nodeType() == Node::ELEMENT_NODE) {
563             if (node->hasTagName(HTMLNames::inputTag)) {
564                 static_cast<HTMLInputElement*>(node)->setValue(inputValue, DispatchChangeEvent);
565                 static_cast<HTMLInputElement*>(node)->blur(); //  unfocus input element after set the value
566             }
567         }
568     }
569 }
570
571 void  WebPage::getFocusedInputElementValue(String& inputValue)
572 {
573     inputValue = String();
574
575     Frame* frame = m_page->focusController()->focusedOrMainFrame();
576     if (frame
577         && frame->document()
578         && frame->document()->focusedNode()) {
579         Node* node = frame->document()->focusedNode();
580         if (node->nodeType() == WebCore::Node::ELEMENT_NODE)
581             if (node->hasTagName(WebCore::HTMLNames::inputTag))
582                 inputValue = (static_cast<WebCore::HTMLInputElement*>(node))->value();
583     }
584 }
585 #endif
586
587 #if ENABLE(TIZEN_DATALIST_ELEMENT)
588 void WebPage::getFocusedInputElementDataList(Vector<String>& optionList)
589 {
590     Frame* frame = m_page->focusController()->focusedOrMainFrame();
591     if (!frame || !frame->document())
592         return;
593
594     Node* node = frame->document()->focusedNode();
595     if (!node)
596         return;
597
598     HTMLInputElement* input = node->toInputElement();
599     if (!input)
600         return;
601
602     HTMLDataListElement* dataList = static_cast<HTMLDataListElement*>(input->list());
603     if (!dataList)
604         return;
605
606     RefPtr<HTMLCollection> options = static_cast<HTMLDataListElement*>(dataList)->options();
607     for (unsigned i = 0; Node* node = options->item(i); i++) {
608         ASSERT(node->hasTagName(optionTag));
609         HTMLOptionElement* optionElement = static_cast<HTMLOptionElement*>(node);
610         String value = optionElement->value();
611         optionList.append(value);
612     }
613 }
614 #endif
615
616 #if ENABLE(TIZEN_WEBKIT2_HIT_TEST)
617 #if ENABLE(TIZEN_WEBKIT2_FOCUS_RING)
618 static IntRect getFocusedRect(HitTestResult hitTestResult, Page* page)
619 {
620     IntRect focusedRect = IntRect(0, 0, 0, 0);
621     Node* node = hitTestResult.innerNode();
622     bool isFocusRingDrawable = false;
623     Node* focusableNode = node;
624     while (focusableNode) {
625         RenderObject* renderer = focusableNode->renderer();
626         if (renderer && renderer->isRoot())
627             break;
628
629         if (focusableNode->isFocusable()) {
630             if (focusableNode->isLink() || focusableNode->hasTagName(HTMLNames::inputTag))
631                 isFocusRingDrawable = true;
632             break;
633         }
634
635         focusableNode = focusableNode->parentNode();
636     }
637
638     if (!isFocusRingDrawable)
639         return focusedRect;
640
641     if (!hitTestResult.absoluteImageURL().isEmpty()) {
642         bool isReplaced;
643         IntRect imageNodeRect = pixelSnappedIntRect(node->getRect());
644         if (!focusableNode->renderRect(&isReplaced).isEmpty() && imageNodeRect.contains(pixelSnappedIntRect(focusableNode->getRect()))) {
645             // If render rect of focusableNode is empty and rect of imageNode include rect of focusableNode,
646             // we have to get rect of focusableNode.
647             // for example - The rect of google logo image in www.google.com pc site's search result page is bigger than rect of focusableNode.
648             // for example - The rect of category menu image in www.gmarket.co.kr pc site is bigger than rect of focusableNode.
649             focusedRect = pixelSnappedIntRect(focusableNode->getRect());
650         }
651         else {
652             // otherwise we have to get rect of imageNode.
653             // for example - The render rect of images in www.pudelek.pl is empty.
654             // for example - The rect of focusableNode of 'Test your browser GO' image in peacekeeper.futuremark.com is bigger than rect of 'Test your browser GO' image.
655             focusedRect = imageNodeRect;
656             focusableNode = node;
657         }
658     } else {
659         // If focusedNode have multiple child nodes, we have to unite rect of child nodes.
660         // for example - links in www.google.com's search result page.
661         IntRect tempRect = IntRect(0, 0, 0, 0);
662         for (Node* childNode = focusableNode->firstChild(); childNode; childNode = childNode->traverseNextNode(focusableNode)) {
663             bool isReplaced;
664             if (focusableNode->renderRect(&isReplaced).contains(childNode->getRect()))
665                 tempRect.unite(pixelSnappedIntRect(childNode->getRect()));
666         }
667
668         // If tempRect is empty or rect of focusableNode include tempRect,
669         // we have to get rect of focusableNode.
670         // for example - list menu item in m.naver.com.
671         // otherwise we have to get rect of tempRect.
672         if (tempRect.isEmpty() || focusableNode->getRect().contains(tempRect))
673             focusedRect = pixelSnappedIntRect(focusableNode->getRect());
674         else
675             focusedRect = tempRect;
676     }
677
678     // We have to get render rect from ancestor node if current focusedRect is empty.
679     // for example - The rect of naver logo image in www.naver.com pc site is empty.
680     bool isReplaced;
681     for (Node* loopNode = focusableNode; loopNode && focusedRect.isEmpty(); loopNode = loopNode->parentNode()) {
682         RenderObject* renderer = loopNode->renderer();
683         if (renderer && renderer->isRoot())
684             break;
685
686         focusedRect = pixelSnappedIntRect(loopNode->renderRect(&isReplaced));
687     }
688
689     Frame* mainFrame = page->mainFrame();
690     Frame* nodeFrame = focusableNode->document()->frame();
691     Node* owner;
692     while (nodeFrame && nodeFrame != mainFrame) {
693         owner = nodeFrame->ownerElement();
694         if (!owner)
695             break;
696
697         focusedRect.setX(focusedRect.x() + owner->getRect().x());
698         focusedRect.setY(focusedRect.y() + owner->getRect().y());
699         nodeFrame = owner->document()->frame();
700     }
701
702     // The y position of tab menu item in www.google.com is negative value,
703     // so we do not want to draw focus ring in that case.
704     if ((focusedRect.x() < 0) || (focusedRect.y() < 0))
705         focusedRect = IntRect(0, 0, 0, 0);
706
707     return focusedRect;
708 }
709 #endif
710
711 void WebPage::hitTestResultAtPoint(const IntPoint& point, int hitTestMode, WebHitTestResult::Data& hitTestResultData)
712 {
713     Frame* frame = m_page->focusController()->focusedOrMainFrame();
714     FrameView* frameView = frame->view();
715     if (!frameView)
716         return;
717
718     HitTestResult hitTestResult = frame->eventHandler()->hitTestResultAtPoint(frameView->windowToContents(point), false);
719     hitTestResultData.absoluteImageURL = hitTestResult.absoluteImageURL().string();
720     hitTestResultData.absoluteLinkURL = hitTestResult.absoluteLinkURL().string();
721     hitTestResultData.absoluteMediaURL = hitTestResult.absoluteMediaURL().string();
722     hitTestResultData.linkLabel = hitTestResult.textContent();
723     hitTestResultData.linkTitle = hitTestResult.titleDisplayString();
724
725     int context = WebHitTestResult::HitTestResultContextDocument;
726
727     if (!hitTestResult.absoluteLinkURL().isEmpty())
728         context |= WebHitTestResult::HitTestResultContextLink;
729     if (!hitTestResult.absoluteImageURL().isEmpty())
730         context |= WebHitTestResult::HitTestResultContextImage;
731     if (!hitTestResult.absoluteMediaURL().isEmpty())
732         context |= WebHitTestResult::HitTestResultContextMedia;
733     if (hitTestResult.isSelected())
734         context |= WebHitTestResult::HitTestResultContextSelection;
735     if (hitTestResult.isContentEditable())
736         context |= WebHitTestResult::HitTestResultContextEditable;
737     if (hitTestResult.innerNonSharedNode() && hitTestResult.innerNonSharedNode()->isTextNode())
738         context |= WebHitTestResult::HitTestResultContextText;
739
740     hitTestResultData.context = context;
741     hitTestResultData.hitTestMode = hitTestMode;
742
743 #if ENABLE(TIZEN_WEBKIT2_FOCUS_RING)
744     hitTestResultData.focusedRect = getFocusedRect(hitTestResult, m_page.get());
745 #endif
746
747     if (hitTestResultData.hitTestMode & WebHitTestResult::HitTestModeNodeData) {
748         WebCore::Node* hitNode = hitTestResult.innerNonSharedNode();
749         if (hitNode) {
750             hitTestResultData.nodeData.nodeValue = hitNode->nodeValue();
751
752             if ((hitTestResultData.context & WebHitTestResult::HitTestResultContextText) && hitNode->parentNode())
753                 hitNode = hitNode->parentNode(); // if hittest inner node is Text node, fill tagName with parent node's info and fill attributeMap with parent node's attributes.
754
755             if (hitNode->isElementNode()) {
756                 WebCore::Element* hitElement = static_cast<WebCore::Element*>(hitNode);
757                 if (hitElement) {
758                     hitTestResultData.nodeData.tagName = hitElement->tagName();
759                 }
760             }
761
762             WebCore::NamedNodeMap* namedNodeMap = hitNode->attributes();
763             if (namedNodeMap) {
764                 for (size_t i = 0; i < namedNodeMap->length(); i++) {
765                     WebCore::Attribute* attribute = namedNodeMap->element()->attributeItem(i);
766                     String key = attribute->name().toString();
767                     String value = attribute->value();
768                     hitTestResultData.nodeData.attributeMap.add(key, value);
769                 }
770             }
771         }
772
773 #if ENABLE(TIZEN_CSS_OVERFLOW_SCROLL_ACCELERATION_ON_UI_SIDE)
774         hitTestResultData.nodeData.isScrollableNodeFocused = false;
775         hitTestResultData.nodeData.enclosingWebLayerID = 0;
776         WebCore::RenderObject* renderer = hitTestResult.innerNode() ? hitTestResult.innerNode()->renderer() : 0;
777         while (renderer) {
778             if (renderer->isBoxModelObject() && renderer->hasLayer() && toRenderBoxModelObject(renderer)->layer()->hasAcceleratedTouchScrolling()) {
779                 hitTestResultData.nodeData.isScrollableNodeFocused = true;
780                 WebCore::GraphicsLayer* scrollingContentsLayer = renderer->enclosingLayer()->layerForScrollingContents();
781                 hitTestResultData.nodeData.enclosingWebLayerID = scrollingContentsLayer ? toWebGraphicsLayer(scrollingContentsLayer)->id() : 0;
782
783                 frame->eventHandler()->setMousePressNode(hitTestResult.innerNode());
784                 break;
785             }
786             renderer = renderer->parent();
787         }
788 #endif
789     }
790
791     if ((hitTestResultData.hitTestMode & WebHitTestResult::HitTestModeImageData) && (hitTestResultData.context & WebHitTestResult::HitTestResultContextImage)) {
792         WebCore::Image* hitImage = hitTestResult.image();
793         if (hitImage && hitImage->data() && hitImage->data()->data()) {
794             hitTestResultData.imageData.dataReference = CoreIPC::DataReference(reinterpret_cast<const uint8_t*>(hitImage->data()->data()), hitImage->data()->size());
795             hitTestResultData.imageData.fileNameExtension = hitImage->filenameExtension();
796         }
797     }
798 }
799 #endif
800
801 #if ENABLE(TIZEN_SUPPORT_RSS_LINK_PARSING)
802 void WebPage::getRssItems(uint64_t callbackID)
803 {
804     if (!m_page->mainFrame())
805         return;
806     Document* document = m_page->mainFrame()->document();
807     if (!document)
808         return;
809     RefPtr<HTMLAllCollection>collection = document->all();
810
811     WTF::String Rss("application/rss+xml");
812     WTF::String Atom("application/atom+xml");
813     WTF::String Alternate("alternate");
814
815     Vector<RssItemEfl> rssItems;
816
817     for (Node* node = collection->firstItem(); node; node = collection->nextItem()) {
818         HTMLLinkElement* linkElement = static_cast<HTMLLinkElement*>(node);
819         if (linkElement->rel() == Alternate) {
820             RssItemEfl::LinkTypeEfl type;
821             if (linkElement->type() == Rss)
822                 type = RssItemEfl::LINK_TYPE_EFL_RSS;
823             else if (linkElement->type() == Atom)
824                 type = RssItemEfl::LINK_TYPE_EFL_ATOM;
825             else
826                 continue;
827
828             RssItemEfl rssItem(linkElement->href(), linkElement->title(), type);
829             rssItems.append(rssItem);
830         }
831     }
832     send(Messages::WebPageProxy::GetRssItemsCallback(rssItems, callbackID));
833
834     return;
835 }
836 #endif // #if ENABLE(TIZEN_SUPPORT_RSS_LINK_PARSING)
837
838 #if ENABLE(TIZEN_WEB_STORAGE)
839 void WebPage::getStorageQuotaBytes(uint64_t callbackID)
840 {
841     uint32_t quota = m_page->group().groupSettings()->localStorageQuotaBytes();
842     send(Messages::WebPageProxy::DidGetWebStorageQuotaBytes(quota, callbackID));
843 }
844
845 void WebPage::setStorageQuotaBytes(uint32_t quota)
846 {
847     m_page->group().groupSettings()->setLocalStorageQuotaBytes(quota);
848 }
849 #endif
850
851 #if ENABLE(TIZEN_WEBKIT2_THEME_SET)
852 void WebPage::setThemePath(const String& path)
853 {
854     Frame* mainFrame = m_page->mainFrame();
855     if (!mainFrame)
856         return;
857
858     WebCore::FrameView* view = mainFrame->view();
859     if (view) {
860         view->setEdjeTheme(path);
861         WebCore::RenderThemeEfl* theme = static_cast<RenderThemeEfl*>(m_page->theme());
862         theme->themeChanged();
863     }
864 }
865 #endif
866
867 #if ENABLE(TIZEN_RECORDING_SURFACE_SET)
868 void WebPage::recordingSurfaceSetEnableSet(bool enable)
869 {
870     m_recordingSurfaceSetSettings = enable;
871 }
872 #endif
873
874 #if ENABLE(TIZEN_WEBKIT_PASTEBOARD)
875 void WebPage::setDataToPasteboardWithType(const String& data, uint64_t type)
876 {
877     Pasteboard::generalPasteboard()->setDataWithType(data, static_cast<Pasteboard::PasteboardDataType>(type));
878 }
879 #endif
880
881 void WebPage::suspendJavaScriptAndResources()
882 {
883     Frame* mainFrame = m_page->mainFrame();
884     if (!mainFrame)
885         return;
886
887     for (Frame* frame = mainFrame; frame; frame = frame->tree()->traverseNext())
888         frame->document()->suspendScheduledTasks(WebCore::ActiveDOMObject::PageWillBeSuspended);
889     mainFrame->loader()->suspendAllLoaders();
890 }
891
892 void WebPage::resumeJavaScriptAndResources()
893 {
894     Frame* mainFrame = m_page->mainFrame();
895     if (!mainFrame)
896         return;
897
898     for (Frame* frame = mainFrame; frame; frame = frame->tree()->traverseNext())
899         frame->document()->resumeScheduledTasks();
900     mainFrame->loader()->resumeAllLoaders();
901 }
902
903 #if ENABLE(TIZEN_WEBKIT2_REMOTE_WEB_INSPECTOR)
904 void WebPage::startInspectorServer(uint32_t port,  uint32_t& allocatedPort)
905 {
906     bool ret = WebInspectorServerEfl::server()->startServer(port);
907     if (ret)
908         allocatedPort = WebInspectorServerEfl::server()->getServerPort();
909     else
910         allocatedPort = 0;
911 }
912
913 void WebPage::stopInspectorServer(bool& result)
914 {
915     result = WebInspectorServerEfl::server()->stopServer();
916 }
917 #endif
918
919 #if ENABLE(TIZEN_CSS_OVERFLOW_SCROLL_ACCELERATION_ON_UI_SIDE)
920 void WebPage::scrollOverflowWithTrajectoryVector(const WebCore::FloatPoint& trajectoryVector)
921 {
922     Frame* frame = m_page->focusController()->focusedOrMainFrame();
923     if (!frame)
924         return;
925     frame->eventHandler()->scrollOverflow(trajectoryVector);
926 }
927 #endif
928
929 #if ENABLE(TIZEN_CSS_OVERFLOW_SCROLL)
930 void WebPage::scrollOverflow(const WebCore::FloatPoint& delta, bool& scrolled)
931 {
932     scrolled = m_page->focusController()->focusedOrMainFrame()->eventHandler()->scrollOverflow(delta);
933 }
934
935 void WebPage::setPressedNodeAtPoint(const IntPoint& point, bool& pressed)
936 {
937     pressed = m_page->focusController()->focusedOrMainFrame()->eventHandler()->setMousePressNodeAtPoint(point);
938 }
939 #endif
940
941 void WebPage::executeEditCommandWithArgument(const String& commandName, const String& argument)
942 {
943     executeEditingCommand(commandName, argument);
944 }
945
946 #if ENABLE(TIZEN_FIX_PLUGIN_DOWNLOAD)
947 void WebPage::arePluginsEnabled(bool& enabled)
948 {
949     enabled = m_page->settings()->arePluginsEnabled();
950 }
951 #endif // ENABLE(TIZEN_FIX_PLUGIN_DOWNLOAD)
952
953 #if ENABLE(TIZEN_NPAPI)
954 void WebPage::suspendPlugin()
955 {
956     for (Frame* frame = m_page->mainFrame(); frame; frame = frame->tree()->traverseNext()) {
957         FrameView* view = frame->view();
958         if (!view)
959             continue;
960
961         const HashSet<RefPtr<Widget> >* children = view->children();
962         ASSERT(children);
963
964         HashSet<RefPtr<Widget> >::const_iterator end = children->end();
965         for (HashSet<RefPtr<Widget> >::const_iterator it = children->begin(); it != end; ++it) {
966             Widget* widget = (*it).get();
967             if (widget->isPluginViewBase()) {
968                 PluginView* pluginView = static_cast<PluginView*>(widget);
969                 if (pluginView)
970                     pluginView->suspendPlugin();
971             }
972         }
973     }
974 }
975
976 void WebPage::resumePlugin()
977 {
978     for (Frame* frame = m_page->mainFrame(); frame; frame = frame->tree()->traverseNext()) {
979         FrameView* view = frame->view();
980         if (!view)
981             continue;
982
983         const HashSet<RefPtr<Widget> >* children = view->children();
984         ASSERT(children);
985
986         HashSet<RefPtr<Widget> >::const_iterator end = children->end();
987         for (HashSet<RefPtr<Widget> >::const_iterator it = children->begin(); it != end; ++it) {
988             Widget* widget = (*it).get();
989             if (widget->isPluginViewBase()) {
990                 PluginView* pluginView = static_cast<PluginView*>(widget);
991                 if (pluginView)
992                     pluginView->resumePlugin();
993             }
994         }
995     }
996 }
997 #endif
998
999 #if ENABLE(TIZEN_WEBKIT2_GET_TEXT_STYLE_FOR_SELECTION)
1000 void WebPage::getTextStyleStateForSelection()
1001 {
1002     Frame* frame = m_page->focusController()->focusedOrMainFrame();
1003
1004     int underlineState = frame->editor()->selectionHasStyle(CSSPropertyWebkitTextDecorationsInEffect, "underline");
1005     int italicState = frame->editor()->selectionHasStyle(CSSPropertyFontStyle, "italic");
1006     int boldState = frame->editor()->selectionHasStyle(CSSPropertyFontWeight, "bold");
1007
1008     send(Messages::WebPageProxy::DidGetTextStyleStateForSelection(underlineState, italicState, boldState));
1009 }
1010 #endif
1011
1012 #endif // #if OS(TIZEN)
1013
1014 } // namespace WebKit