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 "EditorState.h"
32 #include "NamedNodeMap.h"
33 #include "NotImplemented.h"
35 #include "WindowsKeyboardCodes.h"
36 #include <WebCore/EflKeyboardUtilities.h>
37 #include <WebCore/FocusController.h>
38 #include <WebCore/Frame.h>
39 #include <WebCore/FrameView.h>
40 #include <WebCore/KeyboardEvent.h>
41 #include <WebCore/Page.h>
42 #include <WebCore/PlatformKeyboardEvent.h>
43 #include <WebCore/RenderThemeEfl.h>
44 #include <WebCore/Settings.h>
47 #include "Arguments.h"
48 #include "GraphicsContext.h"
49 #include "WebCoreArgumentCoders.h"
52 #include "WebPageProxyMessages.h"
53 #include <WebCore/FrameView.h>
55 #if ENABLE(TIZEN_INPUT_TAG_EXTENSION)
56 #include <WebCore/HTMLInputElement.h>
57 #include <WebCore/HTMLNames.h>
60 #if ENABLE(TIZEN_MULTIPLE_SELECT)
61 #include "WebPopupMenu.h"
62 #include <WebCore/PopupMenuClient.h>
65 #if ENABLE(TIZEN_MOBILE_WEB_PRINT)
66 #include <WebCore/PlatformContextCairo.h>
69 #if ENABLE(TIZEN_CLIPBOARD) || ENABLE(TIZEN_PASTEBOARD)
70 #include <WebCore/ClipboardTizen.h>
73 #if ENABLE(TIZEN_PASTEBOARD)
74 #include <WebCore/Pasteboard.h>
77 #if ENABLE(TIZEN_REMOTE_WEB_INSPECTOR)
78 #include "WebInspectorServerTizen.h"
81 #if ENABLE(TIZEN_WEB_STORAGE)
82 #include <WebCore/GroupSettings.h>
83 #include <WebCore/PageGroup.h>
86 #if ENABLE(TIZEN_PLUGIN_SUSPEND_RESUME)
87 #include "PluginView.h"
90 #if ENABLE(TIZEN_PREFERENCE)
91 #include "WebPreferencesStore.h"
92 #include <WebCore/Settings.h>
95 #if ENABLE(TIZEN_WEBKIT2_FOCUS_RING)
96 #include <WebCore/HTMLFrameOwnerElement.h>
97 #include <WebCore/HTMLImageElement.h>
100 #if ENABLE(TIZEN_DEVICE_ORIENTATION)
101 #include "DeviceMotionClientTizen.h"
102 #include "DeviceOrientationClientTizen.h"
105 #if ENABLE(TIZEN_CSS_OVERFLOW_SCROLL_ACCELERATION_ON_UI_SIDE)
106 #include "RenderLayer.h"
107 #include "WebGraphicsLayer.h"
108 #include <WebCore/RenderView.h>
111 #if ENABLE(TIZEN_ISF_PORT)
112 #include <WebCore/Text.h>
113 #include <WebCore/EditorClient.h>
116 #if ENABLE(TIZEN_INPUT_TAG_EXTENSION) || ENABLE(TIZEN_WEBKIT2_FORM_DATABASE)
117 #include "EditorClient.h"
120 #if ENABLE(TIZEN_DATALIST_ELEMENT)
121 #include "HTMLCollection.h"
122 #include "HTMLDataListElement.h"
123 #include "HTMLOptionElement.h"
126 #if ENABLE(TIZEN_STYLE_SCOPED)
127 #include <WebCore/RuntimeEnabledFeatures.h>
130 #if ENABLE(TIZEN_WEBKIT2_TEXT_SELECTION)
131 #include "htmlediting.h"
134 #if ENABLE(TIZEN_LINK_MAGNIFIER)
135 #include "LinkMagnifier.h"
138 #if ENABLE(TIZEN_SCREEN_READER)
139 #include "WebEventConversion.h"
142 #if ENABLE(TIZEN_SCREEN_READER) || ENABLE(TIZEN_FOCUS_UI) || ENABLE(TIZEN_WEBKIT2_TEXT_SELECTION)
143 #include <WebCore/HTMLAreaElement.h>
146 #if ENABLE(TIZEN_CSP)
147 #include <WebCore/ContentSecurityPolicy.h>
150 #if ENABLE(TIZEN_OFFLINE_PAGE_SAVE)
151 #include "WebPageSerializerTizen.h"
154 #if ENABLE(TIZEN_USE_SETTINGS_FONT)
155 #include "fontconfig/fontconfig.h"
156 #include <WebCore/FontCache.h>
159 #if ENABLE(TIZEN_WEBKIT2_TEXT_SELECTION)
160 #include "visible_units.h"
162 #endif // #if OS(TIZEN)
164 using namespace WebCore;
168 void WebPage::platformInitialize()
170 #if ENABLE(TIZEN_DEVICE_ORIENTATION)
171 WebCore::provideDeviceMotionTo(m_page.get(), new DeviceMotionClientTizen);
172 WebCore::provideDeviceOrientationTo(m_page.get(), new DeviceOrientationClientTizen);
176 #if ENABLE(TIZEN_PREFERENCE)
177 void WebPage::platformPreferencesDidChange(const WebPreferencesStore& store)
179 Settings* settings = m_page->settings();
180 settings->setInteractiveFormValidationEnabled(store.getBoolValueForKey(WebPreferencesKey::interactiveFormValidationEnabledKey()));
181 settings->setUsesEncodingDetector(store.getBoolValueForKey(WebPreferencesKey::usesEncodingDetectorKey()));
182 #if ENABLE(TIZEN_LOAD_REMOTE_IMAGES)
183 settings->setLoadRemoteImages(store.getBoolValueForKey(WebPreferencesKey::loadRemoteImagesKey()));
185 #if ENABLE(TIZEN_LINK_EFFECT)
186 settings->setLinkEffectEnabled(store.getBoolValueForKey(WebPreferencesKey::linkEffectEnabledKey()));
188 #if ENABLE(TIZEN_ISF_PORT)
189 settings->setEnableDefaultKeypad(store.getBoolValueForKey(WebPreferencesKey::defaultKeypadEnabledKey()));
191 #if ENABLE(TIZEN_STYLE_SCOPED)
192 WebCore::RuntimeEnabledFeatures::setStyleScopedEnabled(store.getBoolValueForKey(WebPreferencesKey::styleScopedEnabledKey()));
194 #if ENABLE(TIZEN_WEB_AUDIO)
195 settings->setWebAudioEnabled(true);
199 void WebPage::platformPreferencesDidChange(const WebPreferencesStore&)
203 #endif // #if ENABLE(TIZEN_PREFERENCE)
205 static inline void scroll(Page* page, ScrollDirection direction, ScrollGranularity granularity)
207 page->focusController()->focusedOrMainFrame()->eventHandler()->scrollRecursively(direction, granularity);
210 bool WebPage::performDefaultBehaviorForKeyEvent(const WebKeyboardEvent& keyboardEvent)
216 bool WebPage::platformHasLocalDataForURL(const KURL&)
222 String WebPage::cachedResponseMIMETypeForURL(const KURL&)
228 bool WebPage::platformCanHandleRequest(const ResourceRequest&)
234 String WebPage::cachedSuggestedFilenameForURL(const KURL&)
240 PassRefPtr<SharedBuffer> WebPage::cachedResponseDataForURL(const KURL&)
246 const char* WebPage::interpretKeyEvent(const KeyboardEvent* event)
248 ASSERT(event->type() == eventNames().keydownEvent || event->type() == eventNames().keypressEvent);
250 if (event->type() == eventNames().keydownEvent)
251 return getKeyDownCommandName(event);
253 return getKeyPressCommandName(event);
256 void WebPage::setThemePath(const String& themePath)
258 WebCore::RenderThemeEfl* theme = static_cast<WebCore::RenderThemeEfl*>(m_page->theme());
259 theme->setThemePath(themePath);
262 static Frame* targetFrameForEditing(WebPage* page)
264 Frame* frame = page->corePage()->focusController()->focusedOrMainFrame();
268 Editor* editor = frame->editor();
269 if (!editor->canEdit())
272 if (editor->hasComposition()) {
273 // We should verify the parent node of this IME composition node are
274 // editable because JavaScript may delete a parent node of the composition
275 // node. In this case, WebKit crashes while deleting texts from the parent
276 // node, which doesn't exist any longer.
277 if (PassRefPtr<Range> range = editor->compositionRange()) {
278 Node* node = range->startContainer();
279 if (!node || !node->isContentEditable())
287 void WebPage::confirmComposition(const String& compositionString)
289 Frame* targetFrame = targetFrameForEditing(this);
293 #if ENABLE(TIZEN_ISF_PORT)
294 if (m_prepareKeyDownEvent) {
295 m_keyPressCommands.append(adoptPtr(new ConfirmCompositionKeyPressCommand(compositionString)));
300 targetFrame->editor()->confirmComposition(compositionString);
302 #if ENABLE(TIZEN_ISF_PORT)
303 m_page->editorClient()->respondToChangedSelection(targetFrame);
307 void WebPage::setComposition(const String& compositionString, const Vector<WebCore::CompositionUnderline>& underlines, uint64_t cursorPosition)
309 Frame* targetFrame = targetFrameForEditing(this);
313 #if ENABLE(TIZEN_ISF_PORT)
314 if (!targetFrame->editor()->hasComposition() && compositionString.isEmpty())
317 if (m_prepareKeyDownEvent) {
318 m_keyPressCommands.append(adoptPtr(new SetCompositionKeyPressCommand(compositionString, underlines, cursorPosition)));
322 if (targetFrame->selection()->rootEditableElement()) {
323 HTMLTextFormControlElement* textFormControl = toTextFormControl(targetFrame->selection()->rootEditableElement()->shadowAncestorNode());
324 if (textFormControl && textFormControl->maxLength() >= 0) {
325 unsigned availableLength = textFormControl->maxLength() - textFormControl->value().length();
326 if (targetFrame->editor()->hasComposition())
327 availableLength += (targetFrame->editor()->compositionEnd() - targetFrame->editor()->compositionStart());
328 if (!availableLength)
331 if (availableLength < compositionString.length()) {
332 String newCompositionString = compositionString.substring(0, availableLength);
333 Vector<CompositionUnderline> newUnderlines;
334 size_t numUnderlines = underlines.size();
335 for (size_t index = 0; index < numUnderlines; ++index) {
336 if (underlines[index].startOffset < availableLength) {
337 newUnderlines.append(underlines[index]);
338 if (newUnderlines.last().endOffset > availableLength)
339 newUnderlines.last().endOffset = availableLength;
342 targetFrame->editor()->setComposition(newCompositionString, newUnderlines, cursorPosition, 0);
349 targetFrame->editor()->setComposition(compositionString, underlines, cursorPosition, 0);
351 #if ENABLE(TIZEN_ISF_PORT)
352 m_page->editorClient()->respondToChangedSelection(targetFrame);
356 void WebPage::cancelComposition()
358 Frame* frame = m_page->focusController()->focusedOrMainFrame();
362 frame->editor()->cancelComposition();
367 #if ENABLE(TIZEN_WEBKIT2_TILED_BACKING_STORE)
368 IntSize WebPage::contentsSize() const
370 FrameView* frameView = m_page->mainFrame()->view();
372 return IntSize(0, 0);
374 return frameView->contentsSize();
378 void WebPage::scrollMainFrameBy(const IntSize& scrollOffset)
380 m_page->mainFrame()->view()->scrollBy(scrollOffset);
383 void WebPage::scrollMainFrameTo(const IntPoint& scrollPosition)
385 m_page->mainFrame()->view()->setScrollPosition(scrollPosition);
388 void WebPage::createSnapshot(const IntRect rect, float scaleFactor, ShareableBitmap::Handle& snapshotHandle)
390 FrameView* frameView = m_mainFrame->coreFrame()->view();
394 RefPtr<WebImage> snapshotImage = scaledSnapshotInViewCoordinates(rect, scaleFactor, ImageOptionsShareable);
395 if (!snapshotImage || !snapshotImage->bitmap())
398 snapshotImage->bitmap()->createHandle(snapshotHandle);
401 void WebPage::requestUpdateFormNavigation()
403 Frame* frame = m_page->focusController()->focusedOrMainFrame();
407 Document* document = frame->document();
411 Node* focusedNode = document->focusedNode();
413 Vector<RefPtr<Node> > focusableNodes;
414 document->getFocusableNodes(focusableNodes);
416 int formElementCount = 0;
417 int currentNodeIndex = -1;
418 const Vector<RefPtr<Node> >::iterator end = focusableNodes.end();
419 for (Vector<RefPtr<Node> >::iterator it = focusableNodes.begin(); it != end; ++it) {
420 AtomicString nodeName = (*it).get()->nodeName();
421 if (equalIgnoringCase(nodeName, "SELECT")
422 || (equalIgnoringCase(nodeName, "INPUT")
423 && !equalIgnoringCase((*it).get()->toInputElement()->type(), "CHECKBOX")
424 && !equalIgnoringCase((*it).get()->toInputElement()->type(), "RADIO")
425 && !equalIgnoringCase((*it).get()->toInputElement()->type(), "SUBMIT")
428 if ((*it).get() == focusedNode)
429 currentNodeIndex = formElementCount;
434 if (currentNodeIndex == -1)
437 send(Messages::WebPageProxy::UpdateFormNavigation(formElementCount, currentNodeIndex));
440 void WebPage::moveFocus(int newIndex)
442 Frame* frame = m_page->focusController()->focusedOrMainFrame();
446 Document* document = frame->document();
450 Vector<RefPtr<Node> > focusableNodes;
451 document->getFocusableNodes(focusableNodes);
454 const Vector<RefPtr<Node> >::iterator end = focusableNodes.end();
455 for (Vector<RefPtr<Node> >::iterator it = focusableNodes.begin(); it != end; ++it) {
456 AtomicString nodeName = (*it).get()->nodeName();
457 if (equalIgnoringCase(nodeName, "SELECT")) {
458 if (index == newIndex) {
459 (*it).get()->setFocus();
460 LayoutPoint position = LayoutPoint(0, 0);
461 PlatformMouseEvent event(flooredIntPoint(position), flooredIntPoint(position), LeftButton, PlatformEvent::MouseMoved, 1, false, false, false, false, 0);
462 (*it).get()->dispatchMouseEvent(event, "mousedown", 0, 0);
465 } else if (equalIgnoringCase(nodeName, "INPUT")
466 && !equalIgnoringCase((*it).get()->toInputElement()->type(), "CHECKBOX")
467 && !equalIgnoringCase((*it).get()->toInputElement()->type(), "RADIO")
469 if (index == newIndex) {
470 HTMLInputElement* elem = (*it).get()->toInputElement();
478 #if ENABLE(TIZEN_MOBILE_WEB_PRINT)
479 #define INCH_TO_MM 25.4
480 #define INCH_TO_POINTS 72.0
482 void WebPage::createPagesToPDF(const IntSize& surfaceSize, const IntSize& contentsSize, const String& fileName)
484 FrameView* frameView = m_mainFrame->coreFrame()->view();
488 RefPtr<WebImage> pageshotImage = WebImage::create(contentsSize, ImageOptionsShareable);
489 if (!pageshotImage->bitmap())
492 double pdfWidth = (double)surfaceSize.width() / INCH_TO_MM * INCH_TO_POINTS;
493 double pdfHeight = (double)surfaceSize.height() / INCH_TO_MM * INCH_TO_POINTS;
494 double scaleFactorPdf = 1.0;
495 if (contentsSize.width() > pdfWidth)
496 scaleFactorPdf = pdfWidth / (double)contentsSize.width();
498 OwnPtr<WebCore::GraphicsContext> graphicsContext = pageshotImage->bitmap()->createGraphicsContextForPdfSurface(fileName, pdfWidth, pdfHeight);
499 graphicsContext->scale(FloatSize(scaleFactorPdf, scaleFactorPdf));
501 frameView->updateLayoutAndStyleIfNeededRecursive();
503 int pageNumber = ((contentsSize.height() * scaleFactorPdf) / pdfHeight) + 1;
506 PaintBehavior oldBehavior = frameView->paintBehavior();
507 frameView->setPaintBehavior(oldBehavior | PaintBehaviorFlattenCompositingLayers);
508 for (int i = 0; i < pageNumber; i++) {
509 IntRect paintRect(0, (int)paintY, contentsSize.width(), (int)(pdfHeight / scaleFactorPdf));
511 frameView->paint(graphicsContext.get(), paintRect);
512 cairo_show_page(graphicsContext->platformContext()->cr());
513 graphicsContext->translate(0, -ceil(pdfHeight / scaleFactorPdf));
514 paintY += (pdfHeight / scaleFactorPdf);
516 frameView->setPaintBehavior(oldBehavior);
518 pageshotImage.release();
522 #if ENABLE(TIZEN_TEXT_CARET_HANDLING_WK2)
523 bool WebPage::setCaretPosition(const IntPoint& pos)
525 Frame* frame = m_page->focusController()->focusedOrMainFrame();
529 FrameSelection* controller = frame->selection();
533 FrameView* frameView = frame->view();
537 IntPoint point = m_page->mainFrame()->view()->windowToContents(pos);
538 HitTestResult result = m_page->mainFrame()->eventHandler()->hitTestResultAtPoint(point, /*allowShadowContent*/ true, /*ignoreClipping*/ true);
539 if (result.scrollbar())
542 Node* innerNode = result.innerNode();
544 if (!innerNode || !innerNode->renderer())
547 VisiblePosition visiblePos;
549 // we check if content is richly editable - because those input field behave other than plain text ones
550 // sometimes they may consists a node structure and they need special approach
551 if (innerNode->rendererIsRichlyEditable()) {
552 // point gets inner node local coordinates
553 point = flooredIntPoint(result.localPoint());
554 IntRect rect = innerNode->renderer()->absoluteBoundingBoxRect(true);
556 // it is not the best way to do this, but it is not as slow and it works - so maybe in the future someone
557 // will have a better idea how to solve it
558 // here we are getting innerNode from HitTestResult - unfortunately this is a kind of high level node
559 // in the code below I am trying to obtain low level node - #text - to get its coordinates and size
561 // all those getting nodes rects are needed to bypass WebCore's methods of positioning caret when user
562 // is clicking outside a node - and cheat WebCore telling it that actually we clicked into input field
563 // node, not outside of it
564 Node* deepInnerNode = innerNode->renderer()->positionForPoint(point).deepEquivalent().deprecatedNode();
566 if (!deepInnerNode || !deepInnerNode->renderer())
569 // so we get a base node rectange
570 IntRect deepNodeRect = deepInnerNode->renderer()->absoluteBoundingBoxRect(true);
572 // we modify our local point to adjust it to base node local coordinates
573 point.move(rect.x() - deepNodeRect.x(), rect.y() - deepNodeRect.y());
575 // if we are outside the rect we cheat, that we are just inside of it
578 else if (point.y() >= deepNodeRect.height())
579 point.setY(deepNodeRect.height() - 1);
581 // visible position created - caret ready to set
582 visiblePos = deepInnerNode->renderer()->positionForPoint(point);
583 if (visiblePos.isNull())
586 // for plain text input fields we can get only a caret bounding box
587 if (!controller->isCaret() || !controller->caretRenderer())
590 const Node* node = controller->start().deprecatedNode();
591 if (!node || !node->renderer())
594 Element* currentRootEditableElement = node->rootEditableElement();
595 Element* newRootEditableElement = innerNode->rootEditableElement();
596 if (currentRootEditableElement != newRootEditableElement)
599 IntRect rect = controller->caretRenderer()->absoluteBoundingBoxRect(true);
601 // The below wirtten code is not correct way to implement. Presntly the is no
602 // other working way. To be replaced by better logic
603 // here we also cheat input field that we actually are just inside of if
604 IntPoint focusedFramePoint = frame->view()->windowToContents(pos);
605 IntPoint oldFocusedFramePoint = focusedFramePoint;
607 const int boundariesWidth = 2;
608 if (focusedFramePoint.x() < rect.x())
609 focusedFramePoint.setX(rect.x());
610 else if (focusedFramePoint.x() > rect.maxX())
611 focusedFramePoint.setX(rect.maxX());
612 if (focusedFramePoint.y() < rect.y() + boundariesWidth)
613 focusedFramePoint.setY(rect.y() + boundariesWidth);
614 else if (focusedFramePoint.y() >= rect.maxY() - boundariesWidth)
615 focusedFramePoint.setY(rect.maxY() - boundariesWidth - 1);
617 int diffX = focusedFramePoint.x() - oldFocusedFramePoint.x();
618 int diffY = focusedFramePoint.y() - oldFocusedFramePoint.y();
619 point.setX((point.x())+diffX);
620 point.setY((point.y())+diffY);
622 // hit test with fake (adjusted) coordinates
623 IntPoint hitTestPoint = m_page->mainFrame()->view()->windowToContents(point);
624 HitTestResult newResult = m_page->mainFrame()->eventHandler()->hitTestResultAtPoint(hitTestPoint, /*allowShadowContent*/ true, /*ignoreClipping*/ true);
626 if (!newResult.isContentEditable())
629 Node* newInnerNode = newResult.innerNode();
631 if (!newInnerNode || !newInnerNode->renderer())
634 // visible position created
635 visiblePos = newInnerNode->renderer()->positionForPoint(newResult.localPoint());
636 if (visiblePos.isNull())
640 // create visible selection from visible position
641 VisibleSelection newSelection = VisibleSelection(visiblePos);
642 controller->setSelection(newSelection, CharacterGranularity);
643 // after setting selection caret blinking is suspended by default so we are unsuspedning it
644 controller->setCaretBlinkingSuspended(false);
649 void WebPage::getCaretPosition(IntRect& rect)
651 Frame* frame = m_page->focusController()->focusedOrMainFrame();
655 FrameSelection* controller = frame->selection();
659 Node* node = controller->start().deprecatedNode();
660 if (!node || !node->renderer() || !node->isContentEditable())
663 if (controller->isCaret()) {
664 FrameView* frameView = frame->view();
668 rect = frameView->contentsToWindow(controller->absoluteCaretBounds());
673 #if ENABLE(TIZEN_ISF_PORT)
674 void WebPage::didCancelComposition(Node* valueChangedNode)
676 Frame* frame = m_page->focusController()->focusedOrMainFrame();
677 if (!frame || frame->editor()->ignoreCompositionSelectionChange() || !valueChangedNode->containsIncludingShadowDOM(frame->editor()->compositionNode()))
680 frame->editor()->cancelComposition();
681 send(Messages::WebPageProxy::DidCancelComposition());
684 void WebPage::prepareKeyDownEvent()
686 m_prepareKeyDownEvent = true;
687 m_keyPressCommands.clear();
690 void WebPage::swapKeyPressCommands(Vector<OwnPtr<KeyPressCommand> >& commands)
692 m_keyPressCommands.swap(commands);
695 void WebPage::getCursorOffset(int& offset)
698 Frame* frame = m_page->focusController()->focusedOrMainFrame();
699 if (!frame || !frame->editor()->canEdit())
702 Position base = frame->selection()->base();
703 Node* baseNode = base.containerNode();
705 offset = baseNode->isTextNode() ? base.offsetInContainerNode() : 0;
708 void WebPage::getSurroundingTextAndCursorOffset(String& text, int& offset)
713 Frame* frame = m_page->focusController()->focusedOrMainFrame();
714 if (!frame || !frame->editor()->canEdit())
717 Position base = frame->selection()->base();
718 Node* baseNode = base.containerNode();
719 if (baseNode && baseNode->isTextNode()) {
720 text = baseNode->textContent();
721 offset = base.offsetInContainerNode();
725 void WebPage::getSelectionRect(bool isOnlyEditable, IntRect& rect)
729 Frame* frame = m_page->focusController()->focusedFrame();
730 if (!frame || !frame->view())
733 FrameSelection* selection = frame->selection();
734 Node* node = selection->start().deprecatedNode();
735 if (!node || !node->renderer() || (isOnlyEditable && !node->isContentEditable()))
738 if (selection->isCaret())
739 rect = frame->view()->contentsToWindow(selection->absoluteCaretBounds());
740 else if (selection->isRange())
741 rect = frame->view()->contentsToWindow(enclosingIntRect(selection->bounds(false)));
744 void WebPage::deleteSurroundingText(int offset, int count)
746 Frame* frame = m_page->focusController()->focusedOrMainFrame();
747 if (!frame || !frame->editor()->canEdit())
750 if (m_prepareKeyDownEvent) {
751 m_keyPressCommands.append(adoptPtr(new DeleteTextKeyPressCommand(offset, count)));
755 Position base(frame->selection()->base());
756 offset += base.offsetInContainerNode();
757 base.moveToOffset(offset);
758 Position extent(base);
759 extent.moveToOffset(offset + count);
760 VisibleSelection selection(base, extent);
761 if (!selection.isRange())
764 frame->selection()->setSelection(selection);
765 frame->editor()->deleteWithDirection(DirectionBackward, CharacterGranularity, false, true);
769 #if ENABLE(TIZEN_INPUT_TAG_EXTENSION) || ENABLE(TIZEN_WEBKIT2_FORM_DATABASE)
770 void WebPage::setFocusedInputElementValue(const String& inputValue)
772 Frame* frame = m_page->focusController()->focusedOrMainFrame();
773 if (!frame || !frame->document() || !frame->document()->focusedNode())
776 HTMLInputElement* inputElement = frame->document()->focusedNode()->toInputElement();
780 inputElement->toNode()->dispatchFocusEvent(0);
781 inputElement->setValue(inputValue, DispatchChangeEvent);
784 void WebPage::getFocusedInputElementValue(String& inputValue)
786 inputValue = String();
788 Frame* frame = m_page->focusController()->focusedOrMainFrame();
789 if (!frame || !frame->document() || !frame->document()->focusedNode())
792 HTMLInputElement* inputElement = frame->document()->focusedNode()->toInputElement();
796 inputValue = inputElement->value();
800 #if ENABLE(TIZEN_DATALIST_ELEMENT)
801 void WebPage::getFocusedInputElementDataList(Vector<String>& optionList)
803 Frame* frame = m_page->focusController()->focusedOrMainFrame();
804 if (!frame || !frame->document())
807 Node* node = frame->document()->focusedNode();
811 HTMLInputElement* input = node->toInputElement();
815 HTMLDataListElement* dataList = static_cast<HTMLDataListElement*>(input->list());
819 RefPtr<HTMLCollection> options = static_cast<HTMLDataListElement*>(dataList)->options();
820 for (unsigned i = 0; Node* node = options->item(i); i++) {
821 HTMLOptionElement* optionElement = static_cast<HTMLOptionElement*>(node);
822 String value = optionElement->value();
823 optionList.append(value);
828 #if ENABLE(TIZEN_WEBKIT2_FOCUS_RING)
829 static IntRect getNodeRect(Node* node, Node* focusableNode, bool isImage)
835 IntRect imageNodeRect = pixelSnappedIntRect(node->getRect());
836 if (!focusableNode->renderRect(&isReplaced).isEmpty() && imageNodeRect.contains(pixelSnappedIntRect(focusableNode->getRect()))) {
837 // If render rect of focusableNode is empty and rect of imageNode include rect of focusableNode,
838 // we have to get rect of focusableNode.
839 // for example - The rect of google logo image in www.google.com pc site's search result page is bigger than rect of focusableNode.
840 // for example - The rect of category menu image in www.gmarket.co.kr pc site is bigger than rect of focusableNode.
841 rect = pixelSnappedIntRect(focusableNode->getRect());
844 // otherwise we have to get rect of imageNode.
845 // for example - The render rect of images in www.pudelek.pl is empty.
846 // 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.
847 rect = imageNodeRect;
848 focusableNode = node;
851 // If focusedNode have multiple child nodes, we have to unite rect of child nodes.
852 // for example - links in www.google.com's search result page.
854 for (Node* childNode = focusableNode->firstChild(); childNode; childNode = childNode->traverseNextNode(focusableNode)) {
856 if (focusableNode->renderRect(&isReplaced).contains(childNode->getRect()))
857 tempRect.unite(pixelSnappedIntRect(childNode->getRect()));
860 // If tempRect is empty or rect of focusableNode include tempRect,
861 // we have to get rect of focusableNode.
862 // for example - list menu item in m.naver.com.
863 // otherwise we have to get rect of tempRect.
864 // getRect API do not return correct rect if the node is a container node,
865 // hence using absoluteBoundingBoxRect to get the correct bounding rect.
866 LayoutRect renderRect = focusableNode->renderer() ? focusableNode->renderer()->absoluteBoundingBoxRect() : focusableNode->getRect();
867 if (tempRect.isEmpty() || renderRect.contains(tempRect))
868 rect = pixelSnappedIntRect(renderRect);
873 // We have to get render rect from ancestor node if current rect is empty.
874 // for example - The rect of naver logo image in www.naver.com pc site is empty.
876 for (Node* loopNode = focusableNode; loopNode && rect.isEmpty(); loopNode = loopNode->parentNode()) {
877 RenderObject* renderer = loopNode->renderer();
878 if (renderer && renderer->isRoot())
881 rect = pixelSnappedIntRect(loopNode->renderRect(&isReplaced));
884 Frame* nodeFrame = focusableNode->document()->frame();
886 while (nodeFrame && (owner = nodeFrame->ownerElement())) {
887 rect.moveBy(owner->getRect().pixelSnappedLocation());
888 nodeFrame = owner->document()->frame();
891 // The y position of tab menu item in www.google.com is negative value,
892 // so we do not want to draw focus ring in that case.
893 if ((rect.maxX() < 0) || (rect.maxY() < 0))
900 #if ENABLE(TIZEN_WEBKIT2_HIT_TEST)
901 #if ENABLE(TIZEN_WEBKIT2_FOCUS_RING)
902 #if ENABLE(TOUCH_ADJUSTMENT)
903 static IntRect getFocusedRect(HitTestResult hitTestResult, Page* page, const IntSize& area)
905 static IntRect getFocusedRect(HitTestResult hitTestResult, Page* page)
908 Node* node = hitTestResult.innerNode();
909 #if ENABLE(TOUCH_ADJUSTMENT)
910 Node* adjustedNode = 0;
911 IntPoint adustedPoint;
912 Frame* mainFrame = page->mainFrame();
913 mainFrame->eventHandler()->bestClickableNodeForTouchPoint(hitTestResult.roundedPoint(), IntSize(area.width() / 2, area.height() / 2), adustedPoint, adjustedNode);
921 bool isFocusRingDrawable = false;
922 Node* focusableNode = node;
923 while (focusableNode) {
924 RenderObject* renderer = focusableNode->renderer();
925 if (renderer && (renderer->isBody() || renderer->isRenderView() || renderer->isRoot()))
928 if (focusableNode->isFocusable()) {
929 if (focusableNode->isLink()
930 || focusableNode->hasTagName(HTMLNames::inputTag)
931 || focusableNode->hasTagName(HTMLNames::selectTag)
932 || focusableNode->hasTagName(HTMLNames::buttonTag))
933 isFocusRingDrawable = true;
937 if (focusableNode->supportsFocus()
938 || focusableNode->hasEventListeners(eventNames().clickEvent)
939 || focusableNode->hasEventListeners(eventNames().mousedownEvent)
940 || focusableNode->hasEventListeners(eventNames().mouseupEvent)) {
941 isFocusRingDrawable = true;
945 focusableNode = focusableNode->parentNode();
948 if (!isFocusRingDrawable) {
949 if (node->hasTagName(HTMLNames::imgTag))
950 return getNodeRect(node, node, !hitTestResult.absoluteImageURL().isEmpty());
955 return getNodeRect(node, focusableNode, !hitTestResult.absoluteImageURL().isEmpty());
959 #if ENABLE(TOUCH_ADJUSTMENT)
960 void WebPage::hitTestResultAtPoint(const IntPoint& point, int hitTestMode, const IntSize& area, WebHitTestResult::Data& hitTestResultData)
962 void WebPage::hitTestResultAtPoint(const IntPoint& point, int hitTestMode, WebHitTestResult::Data& hitTestResultData)
965 Frame* frame = m_page->mainFrame();
966 FrameView* frameView = frame->view();
970 HitTestResult hitTestResult = frame->eventHandler()->hitTestResultAtPoint(frameView->windowToContents(point), false);
971 hitTestResultData.absoluteImageURL = hitTestResult.absoluteImageURL().string();
972 hitTestResultData.absoluteLinkURL = hitTestResult.absoluteLinkURL().string();
973 hitTestResultData.absoluteMediaURL = hitTestResult.absoluteMediaURL().string();
974 hitTestResultData.linkLabel = hitTestResult.textContent();
975 hitTestResultData.linkTitle = hitTestResult.titleDisplayString();
976 hitTestResultData.isContentEditable = hitTestResult.isContentEditable();
977 #if ENABLE(TIZEN_DRAG_SUPPORT)
978 hitTestResultData.isDragSupport = hitTestResult.isDragSupport();
981 int context = WebHitTestResult::HitTestResultContextDocument;
983 if (!hitTestResult.absoluteLinkURL().isEmpty())
984 context |= WebHitTestResult::HitTestResultContextLink;
985 if (!hitTestResult.absoluteImageURL().isEmpty())
986 context |= WebHitTestResult::HitTestResultContextImage;
987 if (!hitTestResult.absoluteMediaURL().isEmpty())
988 context |= WebHitTestResult::HitTestResultContextMedia;
989 if (hitTestResult.isSelected())
990 context |= WebHitTestResult::HitTestResultContextSelection;
991 if (hitTestResult.isContentEditable())
992 context |= WebHitTestResult::HitTestResultContextEditable;
993 if (hitTestResult.innerNonSharedNode() && hitTestResult.innerNonSharedNode()->isTextNode())
994 context |= WebHitTestResult::HitTestResultContextText;
996 hitTestResultData.context = context;
997 hitTestResultData.hitTestMode = hitTestMode;
999 #if ENABLE(TIZEN_WEBKIT2_FOCUS_RING)
1000 #if ENABLE(TOUCH_ADJUSTMENT)
1001 hitTestResultData.focusedRect = getFocusedRect(hitTestResult, m_page.get(), area);
1003 hitTestResultData.focusedRect = getFocusedRect(hitTestResult, m_page.get());
1005 if (hitTestResult.innerNode() && hitTestResult.innerNode()->renderer() && hitTestResult.innerNode()->renderer()->style()) {
1006 hitTestResultData.focusedColor = hitTestResult.innerNode()->renderer()->style()->tapHighlightColor();
1007 if (!hitTestResultData.focusedColor.hasAlpha())
1008 hitTestResultData.focusedColor = Color(hitTestResultData.focusedColor.red(), hitTestResultData.focusedColor.green(), hitTestResultData.focusedColor.blue(), RenderStyle::initialTapHighlightColor().alpha());
1012 if (hitTestResultData.hitTestMode & WebHitTestResult::HitTestModeNodeData) {
1013 WebCore::Node* hitNode = hitTestResult.innerNonSharedNode();
1015 hitTestResultData.nodeData.nodeValue = hitNode->nodeValue();
1017 if ((hitTestResultData.context & WebHitTestResult::HitTestResultContextText) && hitNode->parentNode())
1018 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.
1020 if (hitNode->isElementNode()) {
1021 WebCore::Element* hitElement = static_cast<WebCore::Element*>(hitNode);
1023 hitTestResultData.nodeData.tagName = hitElement->tagName();
1027 WebCore::NamedNodeMap* namedNodeMap = hitNode->attributes();
1029 for (size_t i = 0; i < namedNodeMap->length(); i++) {
1030 const WebCore::Attribute* attribute = namedNodeMap->element()->attributeItem(i);
1031 String key = attribute->name().toString();
1032 String value = attribute->value();
1033 hitTestResultData.nodeData.attributeMap.add(key, value);
1039 if ((hitTestResultData.hitTestMode & WebHitTestResult::HitTestModeImageData) && (hitTestResultData.context & WebHitTestResult::HitTestResultContextImage)) {
1040 WebCore::Image* hitImage = hitTestResult.image();
1041 if (hitImage && hitImage->data() && hitImage->data()->data()) {
1042 hitTestResultData.imageData.data.append(hitImage->data()->data(), hitImage->data()->size());
1043 hitTestResultData.imageData.fileNameExtension = hitImage->filenameExtension();
1049 #if ENABLE(TIZEN_WEB_STORAGE)
1050 void WebPage::getStorageQuotaBytes(uint64_t callbackID)
1052 uint32_t quota = m_page->group().groupSettings()->localStorageQuotaBytes();
1053 send(Messages::WebPageProxy::DidGetWebStorageQuotaBytes(quota, callbackID));
1056 void WebPage::setStorageQuotaBytes(uint32_t quota)
1058 m_page->group().groupSettings()->setLocalStorageQuotaBytes(quota);
1062 #if ENABLE(TIZEN_CLIPBOARD) || ENABLE(TIZEN_PASTEBOARD)
1063 void WebPage::setClipboardDataForPaste(const String& data, const String& type)
1065 #if ENABLE(TIZEN_PASTEBOARD)
1066 // FIXME: Should move to EditorClient like Clipboard
1067 Pasteboard::generalPasteboard()->setDataWithType(data, type);
1069 Frame* mainFrame = m_page->mainFrame();
1073 mainFrame->editor()->client()->setClipboardDataForPaste(data, type);
1078 void WebPage::suspendJavaScriptAndResources()
1080 Frame* mainFrame = m_page->mainFrame();
1084 for (Frame* frame = mainFrame; frame; frame = frame->tree()->traverseNext())
1085 frame->document()->suspendScheduledTasks(WebCore::ActiveDOMObject::PageWillBeSuspended);
1086 mainFrame->loader()->suspendAllLoaders();
1089 void WebPage::resumeJavaScriptAndResources()
1091 Frame* mainFrame = m_page->mainFrame();
1095 for (Frame* frame = mainFrame; frame; frame = frame->tree()->traverseNext())
1096 frame->document()->resumeScheduledTasks();
1097 mainFrame->loader()->resumeAllLoaders();
1100 void WebPage::suspendAnimations()
1102 Frame* mainFrame = m_page->mainFrame();
1106 for (Frame* frame = mainFrame; frame; frame = frame->tree()->traverseNext())
1107 frame->animation()->suspendAnimationsForDocument(frame->document());
1110 void WebPage::resumeAnimations()
1112 Frame* mainFrame = m_page->mainFrame();
1116 for (Frame* frame = mainFrame; frame; frame = frame->tree()->traverseNext())
1117 frame->animation()->resumeAnimationsForDocument(frame->document());
1120 #if ENABLE(TIZEN_SYNC_REQUEST_ANIMATION_FRAME)
1121 void WebPage::suspendAnimationController()
1123 if (!m_suspendedAnimationController) {
1124 Frame* mainFrame = m_page->mainFrame();
1128 for (Frame* frame = mainFrame; frame; frame = frame->tree()->traverseNext())
1129 frame->document()->suspendScriptedAnimationControllerCallbacks();
1131 m_suspendedAnimationController = true;
1135 void WebPage::resumeAnimationController()
1137 if (m_suspendedAnimationController) {
1138 Frame* mainFrame = m_page->mainFrame();
1142 for (Frame* frame = mainFrame; frame; frame = frame->tree()->traverseNext())
1143 frame->document()->resumeScriptedAnimationControllerCallbacks();
1145 m_suspendedAnimationController = false;
1150 #if ENABLE(TIZEN_REMOTE_WEB_INSPECTOR)
1151 void WebPage::startInspectorServer(uint32_t port, uint32_t& allocatedPort)
1153 bool ret = WebInspectorServerTizen::server()->startServer(port);
1155 allocatedPort = WebInspectorServerTizen::server()->getServerPort();
1160 void WebPage::stopInspectorServer(bool& result)
1162 result = WebInspectorServerTizen::server()->stopServer();
1166 #if ENABLE(TIZEN_CSS_OVERFLOW_SCROLL_ACCELERATION_ON_UI_SIDE)
1167 void WebPage::scrollOverflowWithTrajectoryVector(const WebCore::FloatPoint& trajectoryVector)
1169 Frame* frame = m_page->focusController()->focusedOrMainFrame();
1172 frame->eventHandler()->scrollOverflow(trajectoryVector);
1176 #if ENABLE(TIZEN_CSS_OVERFLOW_SCROLL_ACCELERATION)
1177 void WebPage::scrollOverflow(const WebCore::FloatPoint& delta, bool& scrolled)
1179 scrolled = m_page->focusController()->focusedOrMainFrame()->eventHandler()->scrollOverflow(delta);
1182 void WebPage::setPressedNodeAtPoint(const IntPoint& point, bool checkOverflowLayer, bool& pressed, uint32_t& id)
1184 RenderObject* renderer = 0;
1186 pressed = m_page->mainFrame()->eventHandler()->setMousePressNodeAtPoint(point, checkOverflowLayer, renderer);
1187 #if ENABLE(TIZEN_CSS_OVERFLOW_SCROLL_ACCELERATION_ON_UI_SIDE)
1188 if (pressed && renderer)
1189 id = toWebGraphicsLayer(renderer->enclosingLayer()->layerForScrollingContents())->id();
1194 void WebPage::executeEditCommandWithArgument(const String& commandName, const String& argument)
1196 executeEditingCommand(commandName, argument);
1199 #if ENABLE(TIZEN_PLUGIN_SUSPEND_RESUME)
1200 void WebPage::suspendPlugin()
1202 for (Frame* frame = m_page->mainFrame(); frame; frame = frame->tree()->traverseNext()) {
1203 FrameView* view = frame->view();
1207 const HashSet<RefPtr<Widget> >* children = view->children();
1210 HashSet<RefPtr<Widget> >::const_iterator end = children->end();
1211 for (HashSet<RefPtr<Widget> >::const_iterator it = children->begin(); it != end; ++it) {
1212 Widget* widget = (*it).get();
1213 if (widget->isPluginViewBase()) {
1214 PluginView* pluginView = static_cast<PluginView*>(widget);
1216 pluginView->suspendPlugin();
1222 void WebPage::resumePlugin()
1224 for (Frame* frame = m_page->mainFrame(); frame; frame = frame->tree()->traverseNext()) {
1225 FrameView* view = frame->view();
1229 const HashSet<RefPtr<Widget> >* children = view->children();
1232 HashSet<RefPtr<Widget> >::const_iterator end = children->end();
1233 for (HashSet<RefPtr<Widget> >::const_iterator it = children->begin(); it != end; ++it) {
1234 Widget* widget = (*it).get();
1235 if (widget->isPluginViewBase()) {
1236 PluginView* pluginView = static_cast<PluginView*>(widget);
1238 pluginView->resumePlugin();
1245 #if ENABLE(TIZEN_MULTIPLE_SELECT)
1246 void WebPage::didChangeSelectedIndexForActivePopupMenuMultiple(Vector<int32_t> newIndex)
1248 if (!m_activePopupMenu)
1251 m_activePopupMenu->client()->popupDidHide();
1253 size_t indexSize = newIndex.size();
1254 for (size_t i = 0; i < indexSize; i++)
1255 m_activePopupMenu->didChangeSelectedIndex(newIndex.at(i));
1260 #if ENABLE(TIZEN_OFFLINE_PAGE_SAVE)
1261 void WebPage::startOfflinePageSave(String subresourceFolderName)
1263 WebPageSerializerTizen::getSerializedPageContent(this, subresourceFolderName);
1267 #if ENABLE(TIZEN_WEBKIT2_TEXT_SELECTION)
1268 void WebPage::selectClosestWord(const IntPoint& point, bool& result)
1272 Frame* mainFrame = m_page->mainFrame();
1273 Frame* focusedFrame = m_page->focusController()->focusedOrMainFrame();
1275 HitTestResult hitTestResult = mainFrame->eventHandler()->hitTestResultAtPoint(m_page->mainFrame()->view()->windowToContents(point), false);
1277 Node* node = hitTestResult.innerNonSharedNode();
1281 Frame* newFocusFrame = node->document()->frame();
1282 if (focusedFrame != newFocusFrame) {
1283 m_page->focusController()->setFocusedFrame(newFocusFrame);
1284 focusedFrame = newFocusFrame;
1287 HTMLInputElement* inputElement = node->toInputElement();
1289 if (hitTestResult.isContentEditable()) {
1290 #if ENABLE(TIZEN_INPUT_TAG_EXTENSION)
1291 if (!inputElement || (inputElement
1292 && !inputElement->isDateField() && !inputElement->isDateTimeField() && !inputElement->isDateTimeLocalField()
1293 && !inputElement->isMonthField() && !inputElement->isTimeField() && !inputElement->isWeekField())) {
1294 result = setCaretPosition(point);
1298 result = setCaretPosition(point);
1303 #if ENABLE(TIZEN_INPUT_TAG_EXTENSION)
1304 if (!node->isTextNode() && !inputElement)
1306 if (!node->isTextNode())
1310 #if ENABLE(TIZEN_INPUT_TAG_EXTENSION)
1312 && (inputElement->isDateField() || inputElement->isDateTimeField() || inputElement->isDateTimeLocalField()
1313 || inputElement->isMonthField() || inputElement->isTimeField() || inputElement->isWeekField())) {
1314 if (inputElement->value().isEmpty())
1319 for (Node* node = hitTestResult.innerNonSharedNode(); node; node = node->parentNode()) {
1320 if (node->isFocusable()) {
1321 // Text selection shoud not be started when text of <button> tag is selected.
1322 if (node->hasTagName(HTMLNames::buttonTag))
1325 if (inputElement && inputElement->isTextButton())
1332 FrameSelection* frameSelection = focusedFrame->selection();
1334 VisiblePosition position = mainFrame->visiblePositionForPoint(point);
1335 VisibleSelection selection(position);
1337 // This changes just the 'start' and 'end' positions of the VisibleSelection
1338 selection.expandUsingGranularity(WordGranularity);
1340 FrameSelection::SetSelectionOptions options = FrameSelection::CloseTyping | FrameSelection::ClearTypingStyle | FrameSelection::DoNotSetFocus;
1341 frameSelection->setSelection(VisibleSelection(selection.start(), selection.end()), options);
1343 if (!frameSelection->isRange())
1346 // This changes just the 'start' and 'end' positions of the VisibleSelection
1347 // Find handlers positions
1348 IntRect leftRect, rightRect;
1349 getSelectionHandlers(leftRect, rightRect);
1350 if (leftRect.size().isZero() && rightRect.size().isZero()) {
1351 // Sometimes there is no selected text, but isNone() returns TRUE
1352 // in this case ewk_frame_selection_handlers_get() returns FALSE and handlers are invalid
1353 // Workaround - clear the selection.
1354 // Better solution would be to modify the ewk_frame_select_closest_word()
1355 // to not select anything in the first place (for example - don't call setSelection()
1356 // if there is nothing under the cursor).
1357 selectionClearAllSelection(m_page->mainFrame());
1364 void WebPage::setLeftSelection(const IntPoint& point, const int direction, int& result)
1366 result = HandleMovingDirectionNone;
1368 Frame* focusedFrame = m_page->focusController()->focusedOrMainFrame();
1369 FrameSelection* frameSelection = focusedFrame->selection();
1370 if (!frameSelection->isRange())
1373 Node* selectionEndNode = frameSelection->end().deprecatedNode();
1374 if (!selectionEndNode || !selectionEndNode->renderer())
1377 FrameView* frameView = focusedFrame->view();
1381 IntPoint pos = frameView->windowToContents(point);
1382 IntRect leftRect, rightRect;
1383 getSelectionHandlers(leftRect, rightRect);
1385 if (selectionEndNode->rendererIsEditable() && !selectionEndNode->rendererIsRichlyEditable()) {
1386 const int boundariesWidth = 2;
1388 IntRect rect = frameSelection->caretRenderer()->absoluteBoundingBoxRect(true);
1389 // here we cheat input field that we actually are just inside of if
1390 if (pos.y() < rect.y() + boundariesWidth)
1391 pos.setY(rect.y() + boundariesWidth);
1392 else if (pos.y() >= rect.maxY() - boundariesWidth)
1393 pos.setY(rect.maxY() - boundariesWidth - 1);
1396 OwnPtr<VisiblePosition> position = adoptPtr(new VisiblePosition(focusedFrame->visiblePositionForPoint(pos)));
1397 Position base = frameSelection->base();
1398 Position extent = frameSelection->extent();
1400 Node* newSelectionStartNode = position->deepEquivalent().deprecatedNode();
1402 // both start and end nodes should be in the same area type: both should be editable or both should be not editable
1403 // Check if the new position is before the extent's position
1404 if (newSelectionStartNode
1405 && selectionEndNode->isContentEditable() == newSelectionStartNode->isContentEditable()) {
1406 // Change the 'base' and 'extent' positions to 'start' and 'end' positions.
1407 // We do it, because without this, the other modification of the selection
1408 // would destroy the 'start' and/or 'end' positions and set them to
1409 // the 'base'/'extent' positions accordingly
1410 VisibleSelection sel(frameSelection->start(), frameSelection->end());
1411 frameSelection->setSelection(sel);
1413 bool oldProhibitsScrolling = focusedFrame->view()->prohibitsScrolling();
1414 focusedFrame->view()->setProhibitsScrolling(true);
1416 if (direction == HandleMovingDirectionNormal) {
1417 if (comparePositions(position->deepEquivalent(), extent) < 0) {
1418 frameSelection->setBase(*position);
1419 result = HandleMovingDirectionNormal;
1420 } else if (comparePositions(position->deepEquivalent(), extent) > 0) {
1421 frameSelection->setExtent(*position);
1422 frameSelection->setBase(extent);
1423 result = HandleMovingDirectionReverse;
1425 } else if (direction == HandleMovingDirectionReverse) {
1426 if (comparePositions(position->deepEquivalent(), base) > 0) {
1427 frameSelection->setExtent(*position);
1428 result = HandleMovingDirectionReverse;
1429 } else if (comparePositions(position->deepEquivalent(), base) < 0) {
1430 frameSelection->setBase(*position);
1431 frameSelection->setExtent(base);
1432 result = HandleMovingDirectionNormal;
1436 focusedFrame->view()->setProhibitsScrolling(oldProhibitsScrolling);
1437 // This forces webkit to show selection
1438 // m_coreFrame->invalidateSelection();
1442 void WebPage::setRightSelection(const IntPoint& point, const int direction, int& result)
1444 result = HandleMovingDirectionNone;
1446 Frame* focusedFrame = m_page->focusController()->focusedOrMainFrame();
1447 FrameSelection* frameSelection = focusedFrame->selection();
1449 if (!frameSelection->isRange())
1452 Node* selectionStartNode = frameSelection->start().deprecatedNode();
1453 if (!selectionStartNode || !selectionStartNode->renderer())
1456 FrameView* frameView = focusedFrame->view();
1460 IntPoint pos = frameView->windowToContents(point);
1461 if (selectionStartNode->rendererIsEditable() && !selectionStartNode->rendererIsRichlyEditable()) {
1462 const int boundariesWidth = 2;
1464 IntRect rect = frameSelection->caretRenderer()->absoluteBoundingBoxRect(true);
1465 // here we cheat input field that we actually are just inside of if
1466 if (pos.y() < rect.y() + boundariesWidth)
1467 pos.setY(rect.y() + boundariesWidth);
1468 else if (pos.y() >= rect.maxY() - boundariesWidth)
1469 pos.setY(rect.maxY() - boundariesWidth - 1);
1472 OwnPtr<VisiblePosition> position = adoptPtr(new VisiblePosition(focusedFrame->visiblePositionForPoint(pos)));
1473 Position base = frameSelection->base();
1474 Position extent = frameSelection->extent();
1476 Node* newSelectionEndNode = position->deepEquivalent().deprecatedNode();
1478 // both start and end nodes should be in the same area type: both should be editable or both should be not editable
1479 // Check if the new position is after the base's position
1480 if (newSelectionEndNode
1481 && selectionStartNode->isContentEditable() == newSelectionEndNode->isContentEditable()) {
1482 // Change the 'base' and 'extent' positions to 'start' and 'end' positions.
1483 // We do it, because without this, the other modifications of the selection
1484 // would destroy the 'start' and/or 'end' positions and set them to
1485 // the 'base'/'extent' positions accordingly
1487 VisibleSelection sel(frameSelection->start(), frameSelection->end());
1488 frameSelection->setSelection(sel);
1490 bool oldProhibitsScrolling = focusedFrame->view()->prohibitsScrolling();
1491 focusedFrame->view()->setProhibitsScrolling(true);
1493 if (direction == HandleMovingDirectionNormal) {
1494 if (comparePositions(position->deepEquivalent(), base) > 0) {
1495 frameSelection->setExtent(*position);
1496 result = HandleMovingDirectionNormal;
1497 } else if (comparePositions(position->deepEquivalent(), base) < 0) {
1498 frameSelection->setBase(*position);
1499 frameSelection->setExtent(base);
1500 result = HandleMovingDirectionReverse;
1502 } else if (direction == HandleMovingDirectionReverse) {
1503 if (comparePositions(position->deepEquivalent(), extent) < 0) {
1504 frameSelection->setBase(*position);
1505 result = HandleMovingDirectionReverse;
1506 } else if (comparePositions(position->deepEquivalent(), extent) > 0) {
1507 frameSelection->setExtent(*position);
1508 frameSelection->setBase(extent);
1509 result = HandleMovingDirectionNormal;
1513 focusedFrame->view()->setProhibitsScrolling(oldProhibitsScrolling);
1517 void WebPage::getSelectionHandlers(IntRect& leftRect, IntRect& rightRect)
1519 Frame* focusedFrame = m_page->focusController()->focusedOrMainFrame();
1520 if (!focusedFrame->selection()->isRange())
1523 // Is this check necessary? Leaving it for safety.
1524 RenderView* root = focusedFrame->contentRenderer();
1528 RefPtr<Range> selectedRange = focusedFrame->selection()->toNormalizedRange();
1530 Vector<IntRect> rects;
1531 selectedRange->boundingBoxEx(rects, true);
1533 unsigned size = rects.size();
1535 leftRect = rects[0];
1536 rightRect = rects[size-1];
1538 // If selection rect size is greater than editor rect size because of round operation,
1539 // selection rect size should be changed to editor rect size.
1541 Element* rootEditableElement = focusedFrame->selection()->rootEditableElement();
1542 if (rootEditableElement) {
1543 IntRect editorRect = nodeRect(rootEditableElement);
1545 #if ENABLE(TIZEN_WEBKIT2_TEXT_SELECTION)
1546 if (m_editorState.editorRect != editorRect) {
1547 EditorState state = editorState();
1548 state.updateEditorRectOnly = true;
1549 setEditorState(state);
1550 send(Messages::WebPageProxy::EditorStateChanged(state));
1554 if (leftRect.maxY() > editorRect.maxY()) {
1555 leftRect.setY(editorRect.y());
1556 leftRect.setHeight(editorRect.height());
1559 if (rightRect.maxY() > editorRect.maxY()) {
1560 rightRect.setY(editorRect.y());
1561 rightRect.setHeight(editorRect.height());
1566 // prevent from selecting zero-length selection
1567 if (leftRect.x() == rightRect.x() + rightRect.width()
1568 && leftRect.y() == rightRect.y())
1571 FrameView* frameView = focusedFrame->view();
1575 leftRect = frameView->contentsToWindow(leftRect);
1576 rightRect = frameView->contentsToWindow(rightRect);
1580 void WebPage::getSelectionText(String& result)
1582 Frame* focusedFrame = m_page->focusController()->focusedOrMainFrame();
1583 result = focusedFrame->editor()->selectedText();
1586 void WebPage::selectionRangeClear(bool& result)
1590 Frame* focusedFrame = m_page->focusController()->focusedOrMainFrame();
1591 FrameSelection* frameSelection = focusedFrame->selection();
1592 if (frameSelection && frameSelection->isRange() && frameSelection->isContentEditable()) {
1593 VisiblePosition visiblePos(frameSelection->extent());
1594 if (visiblePos.isNull())
1597 focusedFrame->editor()->setIgnoreCompositionSelectionChange(true);
1598 frameSelection->setSelection(VisibleSelection(visiblePos), CharacterGranularity);
1599 focusedFrame->editor()->setIgnoreCompositionSelectionChange(false);
1601 frameSelection->setCaretBlinkingSuspended(false);
1603 selectionClearAllSelection(m_page->mainFrame());
1608 void WebPage::selectionClearAllSelection(Frame* frame)
1613 FrameSelection* frameSelection = frame->selection();
1615 frameSelection->clear();
1620 if (frame->tree()->childCount() > 0) {
1621 if (frame->tree()->firstChild())
1622 selectionClearAllSelection(frame->tree()->firstChild());
1623 } else if (frame->tree()->nextSibling())
1624 selectionClearAllSelection(frame->tree()->nextSibling());
1627 void WebPage::scrollContentByCharacter(const IntPoint&, int direction, bool& result)
1631 Frame* focusedFrame = m_page->focusController()->focusedOrMainFrame();
1635 FrameSelection* frameSelection = focusedFrame->selection();
1636 if (!frameSelection)
1639 VisiblePosition currentPosition = frameSelection->selection().visibleStart();
1641 if (isStartOfLine(currentPosition))
1644 focusedFrame->selection()->modify(FrameSelection::AlterationMove, DirectionBackward, CharacterGranularity, UserTriggered);
1646 if (isEndOfLine(currentPosition))
1649 focusedFrame->selection()->modify(FrameSelection::AlterationMove, DirectionForward, CharacterGranularity, UserTriggered);
1653 void WebPage::scrollContentByLine(const IntPoint&, int direction, bool& result)
1657 Frame* focusedFrame = m_page->focusController()->focusedOrMainFrame();
1661 FrameSelection* frameSelection = focusedFrame->selection();
1662 if (!frameSelection)
1665 VisiblePosition currentPosition = frameSelection->selection().visibleStart();
1667 if (inSameLine(currentPosition, previousLinePosition(currentPosition, 0)))
1670 focusedFrame->selection()->modify(FrameSelection::AlterationMove, DirectionBackward, LineGranularity, UserTriggered);
1672 if (inSameLine(currentPosition, nextLinePosition(currentPosition, 0)))
1675 focusedFrame->selection()->modify(FrameSelection::AlterationMove, DirectionForward, LineGranularity, UserTriggered);
1680 #if ENABLE(TIZEN_LINK_MAGNIFIER)
1681 void WebPage::getLinkMagnifierRect(const IntPoint& position, const IntSize& size)
1683 send(Messages::WebPageProxy::DidGetLinkMagnifierRect(position, LinkMagnifier::rect(this, position, size)));
1687 #if ENABLE(TIZEN_SCREEN_READER)
1688 static void sendScreenReaderFocusRect(WebPage* page, Node* node)
1690 bool isImage = false;
1691 if (node->isElementNode()) {
1692 Element* element = static_cast<Element*>(node);
1693 isImage = !element->getAttribute(element->imageSourceAttributeName()).isEmpty();
1696 page->send(Messages::WebPageProxy::DidScreenReaderFocusRectChanged(getNodeRect(node, node, isImage)));
1699 void WebPage::moveScreenReaderFocus(bool forward, bool& result)
1701 if (!m_screenReader)
1702 m_screenReader = ScreenReader::create(this);
1704 if (!m_screenReader->moveFocus(forward)) {
1706 send(Messages::WebPageProxy::DidScreenReaderFocusRectChanged(IntRect()));
1710 sendScreenReaderFocusRect(this, m_screenReader->getFocusedNode());
1714 void WebPage::moveScreenReaderFocusByPoint(const IntPoint& point)
1716 if (!m_screenReader)
1717 m_screenReader = ScreenReader::create(this);
1719 if (!m_screenReader->moveFocus(point))
1722 sendScreenReaderFocusRect(this, m_screenReader->getFocusedNode());
1725 void WebPage::clearScreenReaderFocus()
1727 if (!m_screenReader)
1730 m_screenReader->clearFocus();
1733 void WebPage::raiseTapEvent(const IntPoint& position, const IntPoint& globalPosition, bool& result)
1737 #if ENABLE(GESTURE_EVENTS)
1738 Frame* frame = m_page->mainFrame();
1742 Vector<WebPlatformTouchPoint> touchPoints;
1743 touchPoints.append(WebPlatformTouchPoint(0, WebPlatformTouchPoint::TouchPressed, globalPosition, position));
1745 WebTouchEvent touchStartEvent(WebEvent::TouchStart, touchPoints, WebEvent::Modifiers(0), ecore_time_get());
1746 bool handled = frame->eventHandler()->handleTouchEvent(platform(touchStartEvent));
1748 touchPoints.at(0).setState(WebPlatformTouchPoint::TouchReleased);
1750 WebTouchEvent touchEndEvent(WebEvent::TouchEnd, touchPoints, WebEvent::Modifiers(0), ecore_time_get());
1751 handled |= frame->eventHandler()->handleTouchEvent(platform(touchEndEvent));
1754 WebGestureEvent gestureEvent(WebEvent::GestureSingleTap, position, globalPosition, WebEvent::Modifiers(0), ecore_time_get());
1755 frame->eventHandler()->handleGestureEvent(platform(gestureEvent));
1761 void WebPage::adjustScreenReaderFocusedObjectValue(bool up)
1763 if (!m_screenReader || !m_screenReader->getFocusedNode() || !m_screenReader->getFocusedNode()->toInputElement())
1768 m_screenReader->getFocusedNode()->toInputElement()->stepUp(ec);
1770 m_screenReader->getFocusedNode()->toInputElement()->stepDown(ec);
1773 void WebPage::recalcScreenReaderFocusRect()
1775 if (!m_screenReader || !m_screenReader->getFocusedNode())
1778 sendScreenReaderFocusRect(this, m_screenReader->getFocusedNode());
1781 void WebPage::updateScreenReaderFocus(RenderObject* object)
1783 if (!m_screenReader)
1787 m_screenReader->clearFocus();
1788 else if (!m_screenReader->rendererWillBeDestroyed(object))
1791 send(Messages::WebPageProxy::DidScreenReaderFocusRectChanged(IntRect()));
1794 void WebPage::clearScreenReader()
1796 m_screenReader.clear();
1800 #if ENABLE(TIZEN_SCREEN_READER) || ENABLE(TIZEN_FOCUS_UI) || ENABLE(TIZEN_WEBKIT2_TEXT_SELECTION)
1801 static LayoutRect rectToAbsoluteCoordinates(Frame* initialFrame, const LayoutRect& initialRect)
1803 LayoutRect rect = initialRect;
1804 for (Frame* frame = initialFrame; frame; frame = frame->tree()->parent()) {
1805 RenderBoxModelObject* renderer;
1806 if (frame->ownerElement() && (renderer = frame->ownerElement()->renderBoxModelObject())) {
1808 rect.move(renderer->offsetLeft(), renderer->offsetTop());
1809 } while ((renderer = renderer->offsetParent()));
1810 rect.move(-frame->view()->scrollOffset());
1816 IntRect WebPage::nodeRect(Node* node) const
1822 if (node->hasTagName(HTMLNames::areaTag)) {
1823 HTMLAreaElement* area = static_cast<HTMLAreaElement*>(node);
1824 HTMLImageElement* image = area->imageElement();
1825 if (!image || !image->renderer())
1828 rect = rectToAbsoluteCoordinates(area->document()->frame(), area->computeRect(area->imageElement()->renderer()));
1829 } else if (node->renderer()) {
1830 if (node->isDocumentNode())
1831 rect = rectToAbsoluteCoordinates(static_cast<Document*>(node)->frame(), static_cast<Document*>(node)->frame()->view()->visibleContentRect());
1833 rect = node->getRect();
1834 rect.intersect(node->renderer()->absoluteClippedOverflowRect());
1835 rect = rectToAbsoluteCoordinates(node->document()->frame(), rect);
1837 rect.move(node->renderer()->style()->borderLeftWidth(), node->renderer()->style()->borderTopWidth());
1838 rect.setWidth(rect.width() - node->renderer()->style()->borderLeftWidth() - node->renderer()->style()->borderRightWidth());
1839 rect.setHeight(rect.height() - node->renderer()->style()->borderTopWidth() - node->renderer()->style()->borderBottomWidth());
1843 return pixelSnappedIntRect(rect);
1847 #if ENABLE(TIZEN_WEBKIT2_POPUP_INTERNAL)
1848 // FIXME: Currently with cached pages, hiding Popup list menu is not working correctly.
1849 // This patch is a fix allowing any popup list menu to get close for any page navigation.
1850 void WebPage::notifyTransitionToCommitted(bool forNewPage)
1852 if (m_activePopupMenu) {
1854 m_activePopupMenu->hide();
1855 m_activePopupMenu = 0;
1860 #if ENABLE(TIZEN_CSP)
1861 void WebPage::setContentSecurityPolicy(const String& policy, uint32_t headerType)
1863 Frame* frame = m_page->focusController()->focusedOrMainFrame();
1867 Document* document = frame->document();
1871 document->contentSecurityPolicy()->didReceiveHeader(policy, static_cast<WebCore::ContentSecurityPolicy::HeaderType>(headerType));
1875 #if ENABLE(TIZEN_INDEXED_DATABASE)
1876 void WebPage::setIndexedDatabaseDirectory(const String& path)
1878 m_page->group().groupSettings()->setIndexedDBDatabasePath(path);
1882 #if ENABLE(TIZEN_WEB_STORAGE)
1883 void WebPage::setLocalStorageDirectory(const String& path)
1885 m_page->settings()->setLocalStorageDatabasePath(path);
1889 #if ENABLE(TIZEN_USE_SETTINGS_FONT)
1890 void WebPage::useSettingsFont()
1892 if (!WebCore::fontCache()->isFontFamliyTizen())
1895 FcInitReinitialize();
1896 WebCore::fontCache()->invalidate();
1898 FrameView* frameView = m_mainFrame->coreFrame()->view();
1902 frameView->forceLayout();
1906 void WebPage::didChangeContents(const IntRect& rect)
1911 Frame* frame = m_page->focusController()->focusedOrMainFrame();
1912 if (!frame || !frame->view() || frame->view()->needsLayout())
1915 #if ENABLE(TIZEN_ISF_PORT) || ENABLE(TIZEN_WEBKIT2_TEXT_SELECTION)
1916 if (m_editorState.isContentEditable && rect.intersects(m_editorState.editorRect) && frame->selection()->rootEditableElement()) {
1917 IntRect currentEditorRect = nodeRect(frame->selection()->rootEditableElement());
1918 if (m_editorState.editorRect != currentEditorRect) {
1919 m_editorState.editorRect = currentEditorRect;
1920 m_editorState.updateEditorRectOnly = true;
1921 send(Messages::WebPageProxy::EditorStateChanged(m_editorState));
1926 #endif // #if OS(TIZEN)
1928 } // namespace WebKit