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.
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
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.
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.
31 #include "NamedNodeMap.h"
32 #include "NotImplemented.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>
44 #include "Arguments.h"
45 #include "PlatformContextCairo.h"
46 #include "WebCoreArgumentCoders.h"
49 #include "WebPageProxyMessages.h"
50 #include <WebCore/FrameView.h>
52 #if ENABLE(TIZEN_INPUT_TAG_EXTENSION)
53 #include <WebCore/HTMLInputElement.h>
54 #include <WebCore/HTMLNames.h>
57 #if ENABLE(TIZEN_MOBILE_WEB_PRINT)
58 #include <WebCore/PlatformContextCairo.h>
61 #if ENABLE(TIZEN_SUPPORT_RSS_LINK_PARSING)
62 #include "HTMLLinkElement.h"
63 #include <WebCore/html/HTMLAllCollection.h>
64 #include <efl/RssItemEfl.h>
67 #if ENABLE(TIZEN_WEBKIT_PASTEBOARD)
68 #include <WebCore/Pasteboard.h>
71 #if ENABLE(TIZEN_WEBKIT2_REMOTE_WEB_INSPECTOR)
72 #include "WebInspectorServerEfl.h"
75 #if ENABLE(TIZEN_WEB_STORAGE)
76 #include <WebCore/GroupSettings.h>
77 #include <WebCore/PageGroup.h>
80 #if ENABLE(TIZEN_NPAPI)
81 #include "PluginView.h"
84 #if ENABLE(TIZEN_PREFERENCE)
85 #include "WebPreferencesStore.h"
86 #include <WebCore/Settings.h>
89 #if ENABLE(TIZEN_WEBKIT2_FOCUS_RING)
90 #include <WebCore/HTMLFrameOwnerElement.h>
91 #include <WebCore/HTMLImageElement.h>
94 #if ENABLE(TIZEN_DEVICE_ORIENTATION)
95 #include "DeviceMotionClientEfl.h"
96 #include "DeviceOrientationClientEfl.h"
99 #if ENABLE(TIZEN_WEBKIT2_THEME_SET)
100 #include <WebCore/RenderThemeEfl.h>
103 #if ENABLE(TIZEN_CSS_OVERFLOW_SCROLL_ACCELERATION_ON_UI_SIDE)
104 #include "RenderLayer.h"
105 #include "WebGraphicsLayer.h"
108 #if ENABLE(TIZEN_ISF_PORT)
109 #include "WebEditorClient.h"
112 #if ENABLE(TIZEN_DATALIST_ELEMENT)
113 #include "HTMLCollection.h"
114 #include "HTMLDataListElement.h"
115 #include "HTMLOptionElement.h"
118 #endif // #if OS(TIZEN)
120 using namespace WebCore;
124 void WebPage::platformInitialize()
126 #if ENABLE(TIZEN_DEVICE_ORIENTATION)
127 WebCore::provideDeviceMotionTo(m_page.get(), new DeviceMotionClientEfl);
128 WebCore::provideDeviceOrientationTo(m_page.get(), new DeviceOrientationClientEfl);
132 #if ENABLE(TIZEN_PREFERENCE)
133 void WebPage::platformPreferencesDidChange(const WebPreferencesStore& store)
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()));
143 #if ENABLE(TIZEN_ISF_PORT)
144 settings->setShowImeOnAutofocus(store.getBoolValueForKey(WebPreferencesKey::showImeOnAutofocusKey()));
145 settings->setEnableDefaultKeypad(store.getBoolValueForKey(WebPreferencesKey::defaultKeypadEnabledKey()));
147 #if ENABLE(TIZEN_WAC_DISABLE_GEOLOCATION)
148 settings->setGeolocationEnabled(store.getBoolValueForKey(WebPreferencesKey::geolocationEnabledKey()));
152 void WebPage::platformPreferencesDidChange(const WebPreferencesStore&)
156 #endif // #if ENABLE(TIZEN_PREFERENCE)
158 static inline void scroll(Page* page, ScrollDirection direction, ScrollGranularity granularity)
160 page->focusController()->focusedOrMainFrame()->eventHandler()->scrollRecursively(direction, granularity);
163 bool WebPage::performDefaultBehaviorForKeyEvent(const WebKeyboardEvent& keyboardEvent)
169 bool WebPage::platformHasLocalDataForURL(const KURL&)
175 String WebPage::cachedResponseMIMETypeForURL(const KURL&)
181 bool WebPage::platformCanHandleRequest(const ResourceRequest&)
187 String WebPage::cachedSuggestedFilenameForURL(const KURL&)
193 PassRefPtr<SharedBuffer> WebPage::cachedResponseDataForURL(const KURL&)
199 const char* WebPage::interpretKeyEvent(const KeyboardEvent* event)
201 ASSERT(event->type() == eventNames().keydownEvent || event->type() == eventNames().keypressEvent);
203 if (event->type() == eventNames().keydownEvent)
204 return getKeyDownCommandName(event);
206 return getKeyPressCommandName(event);
211 #if ENABLE(TIZEN_WEBKIT2_TILED_BACKING_STORE)
212 IntSize WebPage::contentsSize() const
214 FrameView* frameView = m_page->mainFrame()->view();
216 return IntSize(0, 0);
218 return frameView->contentsSize();
222 void WebPage::scrollMainFrameBy(const IntSize& scrollOffset)
224 m_page->mainFrame()->view()->scrollBy(scrollOffset);
227 void WebPage::scrollMainFrameTo(const IntPoint& scrollPosition)
229 m_page->mainFrame()->view()->setScrollPosition(scrollPosition);
232 void WebPage::createSnapshot(const IntRect rect, float scaleFactor, ShareableBitmap::Handle& snapshotHandle)
234 FrameView* frameView = m_mainFrame->coreFrame()->view();
238 RefPtr<WebImage> snapshotImage = scaledSnapshotInViewCoordinates(rect, scaleFactor, ImageOptionsShareable);
239 if (!snapshotImage || !snapshotImage->bitmap())
242 snapshotImage->bitmap()->createHandle(snapshotHandle);
245 void WebPage::requestUpdateFormNavigation()
247 Frame* frame = m_page->focusController()->focusedOrMainFrame();
251 Document* document = frame->document();
255 Node* focusedNode = document->focusedNode();
257 Vector<RefPtr<Node> > focusableNodes;
258 document->getFocusableNodes(focusableNodes);
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")
272 if ((*it).get() == focusedNode)
273 currentNodeIndex = formElementCount;
278 if (currentNodeIndex == -1)
281 send(Messages::WebPageProxy::UpdateFormNavigation(formElementCount, currentNodeIndex));
284 void WebPage::moveFocus(int newIndex)
286 Frame* frame = m_page->focusController()->focusedOrMainFrame();
290 Document* document = frame->document();
294 Vector<RefPtr<Node> > focusableNodes;
295 document->getFocusableNodes(focusableNodes);
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);
309 } else if (equalIgnoringCase(nodeName, "INPUT")
310 && !equalIgnoringCase((*it).get()->toInputElement()->type(), "CHECKBOX")
311 && !equalIgnoringCase((*it).get()->toInputElement()->type(), "RADIO")
313 if (index == newIndex) {
314 HTMLInputElement* elem = (*it).get()->toInputElement();
322 #if ENABLE(TIZEN_MOBILE_WEB_PRINT)
324 #define A4_HEIGHT 297
325 #define INCH_TO_MM 25.4
326 #define INCH_TO_POINTS 72.0
328 void WebPage::createPagesToPDF(const IntSize& size, const String& fileName)
330 FrameView* frameView = m_mainFrame->coreFrame()->view();
334 RefPtr<WebImage> pageshotImage = WebImage::create(size, ImageOptionsShareable);
335 if (!pageshotImage->bitmap())
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();
342 OwnPtr<WebCore::GraphicsContext> graphicsContext = pageshotImage->bitmap()->createGraphicsContextForPdfSurface(fileName, pdfWidth, pdfHeight);
343 graphicsContext->scale(FloatSize(scaleFactorPdf, scaleFactorPdf));
345 frameView->updateLayoutAndStyleIfNeededRecursive();
347 int pageNumber = ((size.height() * scaleFactorPdf) / pdfHeight) + 1;
348 IntRect paintRect(0, 0, size.width(), size.height());
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));
357 frameView->setPaintBehavior(oldBehavior);
359 pageshotImage.release();
363 void WebPage::confirmComposition(const String& compositionString)
365 Frame* frame = m_page->focusController()->focusedOrMainFrame();
366 if (!frame || !frame->editor()->canEdit())
368 frame->editor()->confirmComposition(compositionString);
371 void WebPage::setComposition(const String& compositionString, const Vector<WebCore::CompositionUnderline>& underlines, uint64_t cursorPosition)
373 Frame* frame = m_page->focusController()->focusedOrMainFrame();
374 if (!frame || !frame->editor()->canEdit())
376 frame->editor()->setComposition(compositionString, underlines, cursorPosition, 0);
379 #if ENABLE(TIZEN_TEXT_CARET_HANDLING_WK2)
380 bool WebPage::setCaretPosition(const WebCore::IntPoint& pos)
382 Frame* frame = m_page->focusController()->focusedOrMainFrame();
386 WebCore::FrameSelection* controller = frame->selection();
390 FrameView* frameView = frame->view();
394 WebCore::IntPoint point = pos;
395 WebCore::HitTestResult result = frame->eventHandler()->hitTestResultAtPoint(frameView->windowToContents(point), /*allowShadowContent*/ true, /*ignoreClipping*/ true);
396 if (result.scrollbar())
399 WebCore::Node* innerNode = result.innerNode();
401 if (!innerNode || !innerNode->renderer())
404 WebCore::VisiblePosition visiblePos;
406 const int boundariesWidth = 2;
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);
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
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();
425 if (!deepInnerNode || !deepInnerNode->renderer())
428 // so we get a base node rectange
429 WebCore::IntRect deepNodeRect = deepInnerNode->renderer()->absoluteBoundingBoxRect(true);
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());
434 // if we are outside the rect we cheat, that we are just inside of it
437 else if (point.y() >= deepNodeRect.height())
438 point.setY(deepNodeRect.height() - 1);
440 // visible position created - caret ready to set
441 visiblePos = deepInnerNode->renderer()->positionForPoint(point);
442 if (visiblePos.isNull())
445 // for plain text input fields we can get only a caret bounding box
446 if (!controller->isCaret() || !controller->caretRenderer())
449 const WebCore::Node* node = controller->start().deprecatedNode();
450 if (!node || !node->renderer())
453 WebCore::IntRect rect = controller->caretRenderer()->absoluteBoundingBoxRect(true);
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);
465 // hit test with fake (adjusted) coordinates
466 WebCore::HitTestResult newResult = frame->eventHandler()->hitTestResultAtPoint
467 (point, /*allowShadowContent*/ true, /*ignoreClipping*/ true);
469 if (!newResult.isContentEditable())
472 WebCore::Node* newInnerNode = newResult.innerNode();
474 if (!newInnerNode || !newInnerNode->renderer())
477 // visible position created
478 visiblePos = newInnerNode->renderer()->positionForPoint(newResult.localPoint());
479 if (visiblePos.isNull())
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);
492 void WebPage::getCaretPosition(WebCore::IntRect& rect)
494 Frame* frame = m_page->focusController()->focusedOrMainFrame();
498 WebCore::FrameSelection* controller = frame->selection();
502 WebCore::Node* node = controller->start().deprecatedNode();
503 if (!node || !node->renderer() || !node->isContentEditable())
506 if (controller->isCaret()) {
507 FrameView* frameView = frame->view();
511 rect = frameView->contentsToWindow(controller->absoluteCaretBounds());
516 #if ENABLE(TIZEN_ISF_PORT)
517 void WebPage::getCursorOffsetPosition(int& offset)
520 Frame* frame = m_page->focusController()->focusedOrMainFrame();
521 if (!frame || !frame->editor()->canEdit())
524 Position base = frame->selection()->base();
525 Node* baseNode = base.containerNode();
527 offset = baseNode->isTextNode() ? base.offsetInContainerNode() : 0;
530 void WebPage::getContentOfPosition(String& content)
532 Frame* frame = m_page->focusController()->focusedOrMainFrame();
533 if (!frame || !frame->editor()->canEdit())
536 Position base = frame->selection()->base();
537 Node* baseNode = base.containerNode();
538 if (baseNode && baseNode->isTextNode())
539 content = baseNode->textContent();
544 void WebPage::deleteSurroundingPosition(bool& result)
546 Frame* frame = m_page->focusController()->focusedOrMainFrame();
547 if (!frame || !frame->editor()->canEdit())
550 frame->editor()->deleteWithDirection(DirectionBackward, CharacterGranularity, false, true);
554 #if ENABLE(TIZEN_INPUT_TAG_EXTENSION)
555 void WebPage::setFocusedInputElementValue(const String& inputValue)
557 Frame* frame = m_page->focusController()->focusedOrMainFrame();
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
571 void WebPage::getFocusedInputElementValue(String& inputValue)
573 inputValue = String();
575 Frame* frame = m_page->focusController()->focusedOrMainFrame();
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();
587 #if ENABLE(TIZEN_DATALIST_ELEMENT)
588 void WebPage::getFocusedInputElementDataList(Vector<String>& optionList)
590 Frame* frame = m_page->focusController()->focusedOrMainFrame();
591 if (!frame || !frame->document())
594 Node* node = frame->document()->focusedNode();
598 HTMLInputElement* input = node->toInputElement();
602 HTMLDataListElement* dataList = static_cast<HTMLDataListElement*>(input->list());
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);
616 #if ENABLE(TIZEN_WEBKIT2_HIT_TEST)
617 #if ENABLE(TIZEN_WEBKIT2_FOCUS_RING)
618 static IntRect getFocusedRect(HitTestResult hitTestResult, Page* page)
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())
629 if (focusableNode->isFocusable()) {
630 if (focusableNode->isLink() || focusableNode->hasTagName(HTMLNames::inputTag))
631 isFocusRingDrawable = true;
635 focusableNode = focusableNode->parentNode();
638 if (!isFocusRingDrawable)
641 if (!hitTestResult.absoluteImageURL().isEmpty()) {
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());
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;
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)) {
664 if (focusableNode->renderRect(&isReplaced).contains(childNode->getRect()))
665 tempRect.unite(pixelSnappedIntRect(childNode->getRect()));
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());
675 focusedRect = tempRect;
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.
681 for (Node* loopNode = focusableNode; loopNode && focusedRect.isEmpty(); loopNode = loopNode->parentNode()) {
682 RenderObject* renderer = loopNode->renderer();
683 if (renderer && renderer->isRoot())
686 focusedRect = pixelSnappedIntRect(loopNode->renderRect(&isReplaced));
689 Frame* mainFrame = page->mainFrame();
690 Frame* nodeFrame = focusableNode->document()->frame();
692 while (nodeFrame && nodeFrame != mainFrame) {
693 owner = nodeFrame->ownerElement();
697 focusedRect.setX(focusedRect.x() + owner->getRect().x());
698 focusedRect.setY(focusedRect.y() + owner->getRect().y());
699 nodeFrame = owner->document()->frame();
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);
711 void WebPage::hitTestResultAtPoint(const IntPoint& point, int hitTestMode, WebHitTestResult::Data& hitTestResultData)
713 Frame* frame = m_page->focusController()->focusedOrMainFrame();
714 FrameView* frameView = frame->view();
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();
725 int context = WebHitTestResult::HitTestResultContextDocument;
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;
740 hitTestResultData.context = context;
741 hitTestResultData.hitTestMode = hitTestMode;
743 #if ENABLE(TIZEN_WEBKIT2_FOCUS_RING)
744 hitTestResultData.focusedRect = getFocusedRect(hitTestResult, m_page.get());
747 if (hitTestResultData.hitTestMode & WebHitTestResult::HitTestModeNodeData) {
748 WebCore::Node* hitNode = hitTestResult.innerNonSharedNode();
750 hitTestResultData.nodeData.nodeValue = hitNode->nodeValue();
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.
755 if (hitNode->isElementNode()) {
756 WebCore::Element* hitElement = static_cast<WebCore::Element*>(hitNode);
758 hitTestResultData.nodeData.tagName = hitElement->tagName();
762 WebCore::NamedNodeMap* namedNodeMap = hitNode->attributes();
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);
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;
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;
783 frame->eventHandler()->setMousePressNode(hitTestResult.innerNode());
786 renderer = renderer->parent();
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();
801 #if ENABLE(TIZEN_SUPPORT_RSS_LINK_PARSING)
802 void WebPage::getRssItems(uint64_t callbackID)
804 if (!m_page->mainFrame())
806 Document* document = m_page->mainFrame()->document();
809 RefPtr<HTMLAllCollection>collection = document->all();
811 WTF::String Rss("application/rss+xml");
812 WTF::String Atom("application/atom+xml");
813 WTF::String Alternate("alternate");
815 Vector<RssItemEfl> rssItems;
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;
828 RssItemEfl rssItem(linkElement->href(), linkElement->title(), type);
829 rssItems.append(rssItem);
832 send(Messages::WebPageProxy::GetRssItemsCallback(rssItems, callbackID));
836 #endif // #if ENABLE(TIZEN_SUPPORT_RSS_LINK_PARSING)
838 #if ENABLE(TIZEN_WEB_STORAGE)
839 void WebPage::getStorageQuotaBytes(uint64_t callbackID)
841 uint32_t quota = m_page->group().groupSettings()->localStorageQuotaBytes();
842 send(Messages::WebPageProxy::DidGetWebStorageQuotaBytes(quota, callbackID));
845 void WebPage::setStorageQuotaBytes(uint32_t quota)
847 m_page->group().groupSettings()->setLocalStorageQuotaBytes(quota);
851 #if ENABLE(TIZEN_WEBKIT2_THEME_SET)
852 void WebPage::setThemePath(const String& path)
854 Frame* mainFrame = m_page->mainFrame();
858 WebCore::FrameView* view = mainFrame->view();
860 view->setEdjeTheme(path);
861 WebCore::RenderThemeEfl* theme = static_cast<RenderThemeEfl*>(m_page->theme());
862 theme->themeChanged();
867 #if ENABLE(TIZEN_RECORDING_SURFACE_SET)
868 void WebPage::recordingSurfaceSetEnableSet(bool enable)
870 m_recordingSurfaceSetSettings = enable;
874 #if ENABLE(TIZEN_WEBKIT_PASTEBOARD)
875 void WebPage::setDataToPasteboardWithType(const String& data, uint64_t type)
877 Pasteboard::generalPasteboard()->setDataWithType(data, static_cast<Pasteboard::PasteboardDataType>(type));
881 void WebPage::suspendJavaScriptAndResources()
883 Frame* mainFrame = m_page->mainFrame();
887 for (Frame* frame = mainFrame; frame; frame = frame->tree()->traverseNext())
888 frame->document()->suspendScheduledTasks(WebCore::ActiveDOMObject::PageWillBeSuspended);
889 mainFrame->loader()->suspendAllLoaders();
892 void WebPage::resumeJavaScriptAndResources()
894 Frame* mainFrame = m_page->mainFrame();
898 for (Frame* frame = mainFrame; frame; frame = frame->tree()->traverseNext())
899 frame->document()->resumeScheduledTasks();
900 mainFrame->loader()->resumeAllLoaders();
903 #if ENABLE(TIZEN_WEBKIT2_REMOTE_WEB_INSPECTOR)
904 void WebPage::startInspectorServer(uint32_t port, uint32_t& allocatedPort)
906 bool ret = WebInspectorServerEfl::server()->startServer(port);
908 allocatedPort = WebInspectorServerEfl::server()->getServerPort();
913 void WebPage::stopInspectorServer(bool& result)
915 result = WebInspectorServerEfl::server()->stopServer();
919 #if ENABLE(TIZEN_CSS_OVERFLOW_SCROLL_ACCELERATION_ON_UI_SIDE)
920 void WebPage::scrollOverflowWithTrajectoryVector(const WebCore::FloatPoint& trajectoryVector)
922 Frame* frame = m_page->focusController()->focusedOrMainFrame();
925 frame->eventHandler()->scrollOverflow(trajectoryVector);
929 #if ENABLE(TIZEN_CSS_OVERFLOW_SCROLL)
930 void WebPage::scrollOverflow(const WebCore::FloatPoint& delta, bool& scrolled)
932 scrolled = m_page->focusController()->focusedOrMainFrame()->eventHandler()->scrollOverflow(delta);
935 void WebPage::setPressedNodeAtPoint(const IntPoint& point, bool& pressed)
937 pressed = m_page->focusController()->focusedOrMainFrame()->eventHandler()->setMousePressNodeAtPoint(point);
941 void WebPage::executeEditCommandWithArgument(const String& commandName, const String& argument)
943 executeEditingCommand(commandName, argument);
946 #if ENABLE(TIZEN_FIX_PLUGIN_DOWNLOAD)
947 void WebPage::arePluginsEnabled(bool& enabled)
949 enabled = m_page->settings()->arePluginsEnabled();
951 #endif // ENABLE(TIZEN_FIX_PLUGIN_DOWNLOAD)
953 #if ENABLE(TIZEN_NPAPI)
954 void WebPage::suspendPlugin()
956 for (Frame* frame = m_page->mainFrame(); frame; frame = frame->tree()->traverseNext()) {
957 FrameView* view = frame->view();
961 const HashSet<RefPtr<Widget> >* children = view->children();
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);
970 pluginView->suspendPlugin();
976 void WebPage::resumePlugin()
978 for (Frame* frame = m_page->mainFrame(); frame; frame = frame->tree()->traverseNext()) {
979 FrameView* view = frame->view();
983 const HashSet<RefPtr<Widget> >* children = view->children();
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);
992 pluginView->resumePlugin();
999 #if ENABLE(TIZEN_WEBKIT2_GET_TEXT_STYLE_FOR_SELECTION)
1000 void WebPage::getTextStyleStateForSelection()
1002 Frame* frame = m_page->focusController()->focusedOrMainFrame();
1004 int underlineState = frame->editor()->selectionHasStyle(CSSPropertyWebkitTextDecorationsInEffect, "underline");
1005 int italicState = frame->editor()->selectionHasStyle(CSSPropertyFontStyle, "italic");
1006 int boldState = frame->editor()->selectionHasStyle(CSSPropertyFontWeight, "bold");
1008 send(Messages::WebPageProxy::DidGetTextStyleStateForSelection(underlineState, italicState, boldState));
1012 #endif // #if OS(TIZEN)
1014 } // namespace WebKit