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;
343 m_page->editorClient()->lockRespondToChangedSelection();
344 targetFrame->editor()->setComposition(newCompositionString, newUnderlines, cursorPosition, 0);
345 m_page->editorClient()->unlockRespondToChangedSelection();
352 m_page->editorClient()->lockRespondToChangedSelection();
355 targetFrame->editor()->setComposition(compositionString, underlines, cursorPosition, 0);
357 #if ENABLE(TIZEN_ISF_PORT)
358 m_page->editorClient()->unlockRespondToChangedSelection();
362 void WebPage::cancelComposition()
364 Frame* frame = m_page->focusController()->focusedOrMainFrame();
368 frame->editor()->cancelComposition();
373 #if ENABLE(TIZEN_WEBKIT2_TILED_BACKING_STORE)
374 IntSize WebPage::contentsSize() const
376 FrameView* frameView = m_page->mainFrame()->view();
378 return IntSize(0, 0);
380 return frameView->contentsSize();
384 void WebPage::scrollMainFrameBy(const IntSize& scrollOffset)
386 m_page->mainFrame()->view()->scrollBy(scrollOffset);
389 void WebPage::scrollMainFrameTo(const IntPoint& scrollPosition)
391 m_page->mainFrame()->view()->setScrollPosition(scrollPosition);
394 void WebPage::createSnapshot(const IntRect rect, float scaleFactor, ShareableBitmap::Handle& snapshotHandle)
396 FrameView* frameView = m_mainFrame->coreFrame()->view();
400 RefPtr<WebImage> snapshotImage = scaledSnapshotInViewCoordinates(rect, scaleFactor, ImageOptionsShareable);
401 if (!snapshotImage || !snapshotImage->bitmap())
404 snapshotImage->bitmap()->createHandle(snapshotHandle);
407 void WebPage::requestUpdateFormNavigation()
409 Frame* frame = m_page->focusController()->focusedOrMainFrame();
413 Document* document = frame->document();
417 Node* focusedNode = document->focusedNode();
419 Vector<RefPtr<Node> > focusableNodes;
420 document->getFocusableNodes(focusableNodes);
422 int formElementCount = 0;
423 int currentNodeIndex = -1;
424 const Vector<RefPtr<Node> >::iterator end = focusableNodes.end();
425 for (Vector<RefPtr<Node> >::iterator it = focusableNodes.begin(); it != end; ++it) {
426 AtomicString nodeName = (*it).get()->nodeName();
427 if (equalIgnoringCase(nodeName, "SELECT")
428 || (equalIgnoringCase(nodeName, "INPUT")
429 && !equalIgnoringCase((*it).get()->toInputElement()->type(), "CHECKBOX")
430 && !equalIgnoringCase((*it).get()->toInputElement()->type(), "RADIO")
431 && !equalIgnoringCase((*it).get()->toInputElement()->type(), "SUBMIT")
434 if ((*it).get() == focusedNode)
435 currentNodeIndex = formElementCount;
440 if (currentNodeIndex == -1)
443 send(Messages::WebPageProxy::UpdateFormNavigation(formElementCount, currentNodeIndex));
446 void WebPage::moveFocus(int newIndex)
448 Frame* frame = m_page->focusController()->focusedOrMainFrame();
452 Document* document = frame->document();
456 Vector<RefPtr<Node> > focusableNodes;
457 document->getFocusableNodes(focusableNodes);
460 const Vector<RefPtr<Node> >::iterator end = focusableNodes.end();
461 for (Vector<RefPtr<Node> >::iterator it = focusableNodes.begin(); it != end; ++it) {
462 AtomicString nodeName = (*it).get()->nodeName();
463 if (equalIgnoringCase(nodeName, "SELECT")) {
464 if (index == newIndex) {
465 (*it).get()->setFocus();
466 LayoutPoint position = LayoutPoint(0, 0);
467 PlatformMouseEvent event(flooredIntPoint(position), flooredIntPoint(position), LeftButton, PlatformEvent::MouseMoved, 1, false, false, false, false, 0);
468 (*it).get()->dispatchMouseEvent(event, "mousedown", 0, 0);
471 } else if (equalIgnoringCase(nodeName, "INPUT")
472 && !equalIgnoringCase((*it).get()->toInputElement()->type(), "CHECKBOX")
473 && !equalIgnoringCase((*it).get()->toInputElement()->type(), "RADIO")
475 if (index == newIndex) {
476 HTMLInputElement* elem = (*it).get()->toInputElement();
484 #if ENABLE(TIZEN_MOBILE_WEB_PRINT)
485 #define INCH_TO_MM 25.4
486 #define INCH_TO_POINTS 72.0
488 void WebPage::createPagesToPDF(const IntSize& surfaceSize, const IntSize& contentsSize, const String& fileName)
490 FrameView* frameView = m_mainFrame->coreFrame()->view();
494 RefPtr<WebImage> pageshotImage = WebImage::create(contentsSize, ImageOptionsShareable);
495 if (!pageshotImage->bitmap())
498 double pdfWidth = (double)surfaceSize.width() / INCH_TO_MM * INCH_TO_POINTS;
499 double pdfHeight = (double)surfaceSize.height() / INCH_TO_MM * INCH_TO_POINTS;
500 double scaleFactorPdf = 1.0;
501 if (contentsSize.width() > pdfWidth)
502 scaleFactorPdf = pdfWidth / (double)contentsSize.width();
504 OwnPtr<WebCore::GraphicsContext> graphicsContext = pageshotImage->bitmap()->createGraphicsContextForPdfSurface(fileName, pdfWidth, pdfHeight);
505 graphicsContext->scale(FloatSize(scaleFactorPdf, scaleFactorPdf));
507 frameView->updateLayoutAndStyleIfNeededRecursive();
509 int pageNumber = ((contentsSize.height() * scaleFactorPdf) / pdfHeight) + 1;
512 PaintBehavior oldBehavior = frameView->paintBehavior();
513 frameView->setPaintBehavior(oldBehavior | PaintBehaviorFlattenCompositingLayers);
514 for (int i = 0; i < pageNumber; i++) {
515 IntRect paintRect(0, (int)paintY, contentsSize.width(), (int)(pdfHeight / scaleFactorPdf));
517 frameView->paint(graphicsContext.get(), paintRect);
518 cairo_show_page(graphicsContext->platformContext()->cr());
519 graphicsContext->translate(0, -ceil(pdfHeight / scaleFactorPdf));
520 paintY += (pdfHeight / scaleFactorPdf);
522 frameView->setPaintBehavior(oldBehavior);
524 pageshotImage.release();
528 #if ENABLE(TIZEN_TEXT_CARET_HANDLING_WK2)
529 bool WebPage::setCaretPosition(const IntPoint& pos)
531 Frame* frame = m_page->focusController()->focusedOrMainFrame();
535 FrameSelection* controller = frame->selection();
539 FrameView* frameView = frame->view();
543 IntPoint point = m_page->mainFrame()->view()->windowToContents(pos);
544 HitTestResult result = m_page->mainFrame()->eventHandler()->hitTestResultAtPoint(point, /*allowShadowContent*/ true, /*ignoreClipping*/ true);
545 if (result.scrollbar())
548 Node* innerNode = result.innerNode();
550 if (!innerNode || !innerNode->renderer())
553 VisiblePosition visiblePos;
555 // we check if content is richly editable - because those input field behave other than plain text ones
556 // sometimes they may consists a node structure and they need special approach
557 if (innerNode->rendererIsRichlyEditable()) {
558 // point gets inner node local coordinates
559 point = flooredIntPoint(result.localPoint());
560 IntRect rect = innerNode->renderer()->absoluteBoundingBoxRect(true);
562 // it is not the best way to do this, but it is not as slow and it works - so maybe in the future someone
563 // will have a better idea how to solve it
564 // here we are getting innerNode from HitTestResult - unfortunately this is a kind of high level node
565 // in the code below I am trying to obtain low level node - #text - to get its coordinates and size
567 // all those getting nodes rects are needed to bypass WebCore's methods of positioning caret when user
568 // is clicking outside a node - and cheat WebCore telling it that actually we clicked into input field
569 // node, not outside of it
570 Node* deepInnerNode = innerNode->renderer()->positionForPoint(point).deepEquivalent().deprecatedNode();
572 if (!deepInnerNode || !deepInnerNode->renderer())
575 // so we get a base node rectange
576 IntRect deepNodeRect = deepInnerNode->renderer()->absoluteBoundingBoxRect(true);
578 // we modify our local point to adjust it to base node local coordinates
579 point.move(rect.x() - deepNodeRect.x(), rect.y() - deepNodeRect.y());
581 // if we are outside the rect we cheat, that we are just inside of it
584 else if (point.y() >= deepNodeRect.height())
585 point.setY(deepNodeRect.height() - 1);
587 // visible position created - caret ready to set
588 visiblePos = deepInnerNode->renderer()->positionForPoint(point);
589 if (visiblePos.isNull())
592 // for plain text input fields we can get only a caret bounding box
593 if (!controller->isCaret() || !controller->caretRenderer())
596 const Node* node = controller->start().deprecatedNode();
597 if (!node || !node->renderer())
600 Element* currentRootEditableElement = node->rootEditableElement();
601 Element* newRootEditableElement = innerNode->rootEditableElement();
602 if (currentRootEditableElement != newRootEditableElement)
605 IntRect rect = controller->caretRenderer()->absoluteBoundingBoxRect(true);
607 // The below wirtten code is not correct way to implement. Presntly the is no
608 // other working way. To be replaced by better logic
609 // here we also cheat input field that we actually are just inside of if
610 IntPoint focusedFramePoint = frame->view()->windowToContents(pos);
611 IntPoint oldFocusedFramePoint = focusedFramePoint;
613 const int boundariesWidth = 2;
614 if (focusedFramePoint.x() < rect.x())
615 focusedFramePoint.setX(rect.x());
616 else if (focusedFramePoint.x() > rect.maxX())
617 focusedFramePoint.setX(rect.maxX());
618 if (focusedFramePoint.y() < rect.y() + boundariesWidth)
619 focusedFramePoint.setY(rect.y() + boundariesWidth);
620 else if (focusedFramePoint.y() >= rect.maxY() - boundariesWidth)
621 focusedFramePoint.setY(rect.maxY() - boundariesWidth - 1);
623 int diffX = focusedFramePoint.x() - oldFocusedFramePoint.x();
624 int diffY = focusedFramePoint.y() - oldFocusedFramePoint.y();
625 point.setX((point.x())+diffX);
626 point.setY((point.y())+diffY);
628 // hit test with fake (adjusted) coordinates
629 IntPoint hitTestPoint = m_page->mainFrame()->view()->windowToContents(point);
630 HitTestResult newResult = m_page->mainFrame()->eventHandler()->hitTestResultAtPoint(hitTestPoint, /*allowShadowContent*/ true, /*ignoreClipping*/ true);
632 if (!newResult.isContentEditable())
635 Node* newInnerNode = newResult.innerNode();
637 if (!newInnerNode || !newInnerNode->renderer())
640 // visible position created
641 visiblePos = newInnerNode->renderer()->positionForPoint(newResult.localPoint());
642 if (visiblePos.isNull())
646 // create visible selection from visible position
647 VisibleSelection newSelection = VisibleSelection(visiblePos);
648 controller->setSelection(newSelection, CharacterGranularity);
649 // after setting selection caret blinking is suspended by default so we are unsuspedning it
650 controller->setCaretBlinkingSuspended(false);
656 #if ENABLE(TIZEN_ISF_PORT)
657 void WebPage::didCancelComposition(Node* valueChangedNode)
659 Frame* frame = m_page->focusController()->focusedOrMainFrame();
660 if (!frame || frame->editor()->ignoreCompositionSelectionChange() || !valueChangedNode->containsIncludingShadowDOM(frame->editor()->compositionNode()))
663 frame->editor()->cancelComposition();
664 send(Messages::WebPageProxy::DidCancelComposition());
667 void WebPage::prepareKeyDownEvent()
669 m_prepareKeyDownEvent = true;
672 void WebPage::swapKeyPressCommands(Vector<OwnPtr<KeyPressCommand> >& commands)
674 m_keyPressCommands.swap(commands);
677 void WebPage::deleteSurroundingText(int offset, int count)
679 Frame* frame = m_page->focusController()->focusedOrMainFrame();
680 if (!frame || !frame->editor()->canEdit())
683 if (m_prepareKeyDownEvent) {
684 m_keyPressCommands.append(adoptPtr(new DeleteTextKeyPressCommand(offset, count)));
688 Position base(frame->selection()->base());
689 offset += base.offsetInContainerNode();
690 base.moveToOffset(offset);
691 Position extent(base);
692 extent.moveToOffset(offset + count);
693 VisibleSelection selection(base, extent);
694 if (!selection.isRange())
697 frame->selection()->setSelection(selection);
698 frame->editor()->deleteWithDirection(DirectionBackward, CharacterGranularity, false, true);
701 void WebPage::updateEditorStateRect(const Frame* frame, EditorState& state) const
703 ASSERT(frame->selection()->rootEditableElement());
705 #if ENABLE(TIZEN_WEBKIT2_TEXT_SELECTION)
706 Vector<IntRect> rects;
707 calcFocusedRects(frame->selection()->rootEditableElement(), rects);
708 state.editorRect = unionRect(rects);
711 if (frame->selection()->isCaret())
712 state.selectionRect = frame->view()->contentsToWindow(frame->selection()->absoluteCaretBounds());
713 else if (frame->selection()->isRange())
714 state.selectionRect = frame->view()->contentsToWindow(enclosingIntRect(frame->selection()->bounds(false)));
718 #if ENABLE(TIZEN_INPUT_TAG_EXTENSION) || ENABLE(TIZEN_WEBKIT2_FORM_DATABASE)
719 void WebPage::setFocusedInputElementValue(const String& inputValue)
721 Frame* frame = m_page->focusController()->focusedOrMainFrame();
722 if (!frame || !frame->document() || !frame->document()->focusedNode())
725 HTMLInputElement* inputElement = frame->document()->focusedNode()->toInputElement();
729 inputElement->toNode()->dispatchFocusEvent(0);
730 inputElement->setValue(inputValue, DispatchChangeEvent);
733 void WebPage::getFocusedInputElementValue(String& inputValue)
735 inputValue = String();
737 Frame* frame = m_page->focusController()->focusedOrMainFrame();
738 if (!frame || !frame->document() || !frame->document()->focusedNode())
741 HTMLInputElement* inputElement = frame->document()->focusedNode()->toInputElement();
745 inputValue = inputElement->value();
749 #if ENABLE(TIZEN_DATALIST_ELEMENT)
750 void WebPage::getFocusedInputElementDataList(Vector<String>& optionList)
752 Frame* frame = m_page->focusController()->focusedOrMainFrame();
753 if (!frame || !frame->document())
756 Node* node = frame->document()->focusedNode();
760 HTMLInputElement* input = node->toInputElement();
764 HTMLDataListElement* dataList = static_cast<HTMLDataListElement*>(input->list());
768 RefPtr<HTMLCollection> options = static_cast<HTMLDataListElement*>(dataList)->options();
769 for (unsigned i = 0; Node* node = options->item(i); i++) {
770 HTMLOptionElement* optionElement = static_cast<HTMLOptionElement*>(node);
771 String value = optionElement->value();
772 optionList.append(value);
777 #if ENABLE(TIZEN_WEBKIT2_FOCUS_RING)
778 static IntRect getNodeRect(Node* node, Node* focusableNode, bool isImage)
784 IntRect imageNodeRect = pixelSnappedIntRect(node->getRect());
785 if (!focusableNode->renderRect(&isReplaced).isEmpty() && imageNodeRect.contains(pixelSnappedIntRect(focusableNode->getRect()))) {
786 // If render rect of focusableNode is empty and rect of imageNode include rect of focusableNode,
787 // we have to get rect of focusableNode.
788 // for example - The rect of google logo image in www.google.com pc site's search result page is bigger than rect of focusableNode.
789 // for example - The rect of category menu image in www.gmarket.co.kr pc site is bigger than rect of focusableNode.
790 rect = pixelSnappedIntRect(focusableNode->getRect());
793 // otherwise we have to get rect of imageNode.
794 // for example - The render rect of images in www.pudelek.pl is empty.
795 // 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.
796 rect = imageNodeRect;
797 focusableNode = node;
800 // If focusedNode have multiple child nodes, we have to unite rect of child nodes.
801 // for example - links in www.google.com's search result page.
803 for (Node* childNode = focusableNode->firstChild(); childNode; childNode = childNode->traverseNextNode(focusableNode)) {
805 if (focusableNode->renderRect(&isReplaced).contains(childNode->getRect()))
806 tempRect.unite(pixelSnappedIntRect(childNode->getRect()));
809 // If tempRect is empty or rect of focusableNode include tempRect,
810 // we have to get rect of focusableNode.
811 // for example - list menu item in m.naver.com.
812 // otherwise we have to get rect of tempRect.
813 // getRect API do not return correct rect if the node is a container node,
814 // hence using absoluteBoundingBoxRect to get the correct bounding rect.
815 LayoutRect renderRect = focusableNode->renderer() ? focusableNode->renderer()->absoluteBoundingBoxRect() : focusableNode->getRect();
816 if (tempRect.isEmpty() || renderRect.contains(tempRect))
817 rect = pixelSnappedIntRect(renderRect);
822 // We have to get render rect from ancestor node if current rect is empty.
823 // for example - The rect of naver logo image in www.naver.com pc site is empty.
825 for (Node* loopNode = focusableNode; loopNode && rect.isEmpty(); loopNode = loopNode->parentNode()) {
826 RenderObject* renderer = loopNode->renderer();
827 if (renderer && renderer->isRoot())
830 rect = pixelSnappedIntRect(loopNode->renderRect(&isReplaced));
833 Frame* nodeFrame = focusableNode->document()->frame();
835 while (nodeFrame && (owner = nodeFrame->ownerElement())) {
836 rect.moveBy(owner->getRect().pixelSnappedLocation());
837 nodeFrame = owner->document()->frame();
840 // The y position of tab menu item in www.google.com is negative value,
841 // so we do not want to draw focus ring in that case.
842 if ((rect.maxX() < 0) || (rect.maxY() < 0))
849 #if ENABLE(TIZEN_WEBKIT2_HIT_TEST)
850 #if ENABLE(TIZEN_WEBKIT2_FOCUS_RING)
851 static bool isClickableOrFocusable(Node* focusableNode)
856 if (focusableNode->disabled())
858 if (!focusableNode->inDocument())
860 if (!focusableNode->renderer() || focusableNode->renderer()->style()->visibility() != VISIBLE)
862 if (focusableNode->isFocusable()) {
863 if (focusableNode->isLink()
864 || focusableNode->hasTagName(HTMLNames::inputTag)
865 || focusableNode->hasTagName(HTMLNames::selectTag)
866 || focusableNode->hasTagName(HTMLNames::buttonTag))
869 if (focusableNode->supportsFocus()
870 || focusableNode->hasEventListeners(eventNames().clickEvent)
871 || focusableNode->hasEventListeners(eventNames().mousedownEvent)
872 || focusableNode->hasEventListeners(eventNames().mouseupEvent)) {
878 #if ENABLE(TOUCH_ADJUSTMENT)
879 void WebPage::getFocusedRect(HitTestResult hitTestResult, Page* page, bool setFocus, Vector<IntRect>& rects, const IntPoint& point, const IntSize& area)
881 void WebPage::getFocusedRect(HitTestResult hitTestResult, Page* page, bool setFocus, Vector<IntRect>& rects)
884 Node* node = hitTestResult.innerNode();
885 #if ENABLE(TOUCH_ADJUSTMENT)
886 IntPoint adustedPoint;
887 Frame* mainFrame = page->mainFrame();
888 Node* adjustedNode = 0;
889 mainFrame->eventHandler()->bestClickableNodeForTouchPoint(point, IntSize(area.width() / 2, area.height() / 2), adustedPoint, adjustedNode);
890 if (!isClickableOrFocusable(node))
891 mainFrame->eventHandler()->bestClickableNodeForTouchPoint(point, IntSize(area.width() / 2, area.height() / 2), adustedPoint, adjustedNode);
899 bool isFocusRingDrawable = false;
900 Node* focusableNode = node;
901 while (focusableNode) {
902 RenderObject* renderer = focusableNode->renderer();
903 if (renderer && (renderer->isBody() || renderer->isRenderView() || renderer->isRoot()))
906 if (isClickableOrFocusable(focusableNode)) {
907 isFocusRingDrawable = true;
911 focusableNode = focusableNode->parentNode();
914 // Don't draw focus ring if child is focusable or has trigger
915 if (focusableNode && focusableNode->isContainerNode() && !focusableNode->isLink()) {
916 WebCore::Node *child = static_cast<const ContainerNode*>(focusableNode)->firstChild();
918 if( child->supportsFocus()
919 || child->hasEventListeners(eventNames().clickEvent)
920 || child->hasEventListeners(eventNames().mousedownEvent)
921 || child->hasEventListeners(eventNames().mouseupEvent)) {
924 child = child->traverseNextNode(focusableNode);
928 if (!isFocusRingDrawable) {
929 if (!node->hasTagName(HTMLNames::imgTag))
931 focusableNode = node;
935 setFocusedNode(focusableNode);
937 calcFocusedRects(focusableNode, rects);
941 #if ENABLE(TOUCH_ADJUSTMENT)
942 void WebPage::hitTestResultAtPoint(const IntPoint& point, int hitTestMode, const IntSize& area, WebHitTestResult::Data& hitTestResultData)
944 void WebPage::hitTestResultAtPoint(const IntPoint& point, int hitTestMode, WebHitTestResult::Data& hitTestResultData)
947 Frame* frame = m_page->mainFrame();
948 FrameView* frameView = frame->view();
952 HitTestResult hitTestResult = frame->eventHandler()->hitTestResultAtPoint(frameView->windowToContents(point), false);
953 hitTestResultData.absoluteImageURL = hitTestResult.absoluteImageURL().string();
954 hitTestResultData.absoluteLinkURL = hitTestResult.absoluteLinkURL().string();
955 hitTestResultData.absoluteMediaURL = hitTestResult.absoluteMediaURL().string();
956 hitTestResultData.linkLabel = hitTestResult.textContent();
957 hitTestResultData.linkTitle = hitTestResult.titleDisplayString();
958 hitTestResultData.isContentEditable = hitTestResult.isContentEditable();
959 #if ENABLE(TIZEN_DRAG_SUPPORT)
960 hitTestResultData.isDragSupport = hitTestResult.isDragSupport();
963 int context = WebHitTestResult::HitTestResultContextDocument;
965 if (!hitTestResult.absoluteLinkURL().isEmpty())
966 context |= WebHitTestResult::HitTestResultContextLink;
967 if (!hitTestResult.absoluteImageURL().isEmpty())
968 context |= WebHitTestResult::HitTestResultContextImage;
969 if (!hitTestResult.absoluteMediaURL().isEmpty())
970 context |= WebHitTestResult::HitTestResultContextMedia;
971 if (hitTestResult.isSelected())
972 context |= WebHitTestResult::HitTestResultContextSelection;
973 if (hitTestResult.isContentEditable())
974 context |= WebHitTestResult::HitTestResultContextEditable;
975 if (hitTestResult.innerNonSharedNode() && hitTestResult.innerNonSharedNode()->isTextNode())
976 context |= WebHitTestResult::HitTestResultContextText;
978 hitTestResultData.context = context;
979 hitTestResultData.hitTestMode = hitTestMode;
981 #if ENABLE(TIZEN_WEBKIT2_FOCUS_RING)
982 bool setFocus = hitTestResultData.hitTestMode & WebHitTestResult::HitTestModeSetFocus;
983 #if ENABLE(TOUCH_ADJUSTMENT)
984 getFocusedRect(hitTestResult, m_page.get(), setFocus, hitTestResultData.focusedRects, point, area);
986 getFocusedRect(hitTestResult, m_page.get(), setFocus, hitTestResultData.focusedRects);
989 // Don't display FocusRect if the size is too big..
990 IntRect framerect = frameView->visibleContentRect(true);
991 for (size_t i = 0; i < hitTestResultData.focusedRects.size(); ++i) {
992 if (hitTestResultData.focusedRects[i].width() > (0.8 * framerect.width())
993 && hitTestResultData.focusedRects[i].height() > (0.8 * framerect.height()))
994 hitTestResultData.focusedRects.clear();
997 if (hitTestResult.innerNode() && hitTestResult.innerNode()->renderer() && hitTestResult.innerNode()->renderer()->style()) {
998 hitTestResultData.focusedColor = hitTestResult.innerNode()->renderer()->style()->tapHighlightColor();
999 if (!hitTestResultData.focusedColor.hasAlpha())
1000 hitTestResultData.focusedColor = Color(hitTestResultData.focusedColor.red(), hitTestResultData.focusedColor.green(), hitTestResultData.focusedColor.blue(), RenderStyle::initialTapHighlightColor().alpha());
1004 if (hitTestResultData.hitTestMode & WebHitTestResult::HitTestModeNodeData) {
1005 WebCore::Node* hitNode = hitTestResult.innerNonSharedNode();
1007 hitTestResultData.nodeData.nodeValue = hitNode->nodeValue();
1009 if ((hitTestResultData.context & WebHitTestResult::HitTestResultContextText) && hitNode->parentNode())
1010 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.
1012 if (hitNode->isElementNode()) {
1013 WebCore::Element* hitElement = static_cast<WebCore::Element*>(hitNode);
1015 hitTestResultData.nodeData.tagName = hitElement->tagName();
1019 WebCore::NamedNodeMap* namedNodeMap = hitNode->attributes();
1021 for (size_t i = 0; i < namedNodeMap->length(); i++) {
1022 const WebCore::Attribute* attribute = namedNodeMap->element()->attributeItem(i);
1023 String key = attribute->name().toString();
1024 String value = attribute->value();
1025 hitTestResultData.nodeData.attributeMap.add(key, value);
1031 if ((hitTestResultData.hitTestMode & WebHitTestResult::HitTestModeImageData) && (hitTestResultData.context & WebHitTestResult::HitTestResultContextImage)) {
1032 WebCore::Image* hitImage = hitTestResult.image();
1033 if (hitImage && hitImage->data() && hitImage->data()->data()) {
1034 hitTestResultData.imageData.data.append(hitImage->data()->data(), hitImage->data()->size());
1035 hitTestResultData.imageData.fileNameExtension = hitImage->filenameExtension();
1041 #if ENABLE(TIZEN_WEB_STORAGE)
1042 void WebPage::getStorageQuotaBytes(uint64_t callbackID)
1044 uint32_t quota = m_page->group().groupSettings()->localStorageQuotaBytes();
1045 send(Messages::WebPageProxy::DidGetWebStorageQuotaBytes(quota, callbackID));
1048 void WebPage::setStorageQuotaBytes(uint32_t quota)
1050 m_page->group().groupSettings()->setLocalStorageQuotaBytes(quota);
1054 #if ENABLE(TIZEN_CLIPBOARD) || ENABLE(TIZEN_PASTEBOARD)
1055 void WebPage::setClipboardDataForPaste(const String& data, const String& type)
1057 #if ENABLE(TIZEN_PASTEBOARD)
1058 // FIXME: Should move to EditorClient like Clipboard
1059 Pasteboard::generalPasteboard()->setDataWithType(data, type);
1061 Frame* mainFrame = m_page->mainFrame();
1065 mainFrame->editor()->client()->setClipboardDataForPaste(data, type);
1070 void WebPage::suspendJavaScriptAndResources()
1072 Frame* mainFrame = m_page->mainFrame();
1076 for (Frame* frame = mainFrame; frame; frame = frame->tree()->traverseNext())
1077 frame->document()->suspendScheduledTasks(WebCore::ActiveDOMObject::PageWillBeSuspended);
1078 mainFrame->loader()->suspendAllLoaders();
1081 void WebPage::resumeJavaScriptAndResources()
1083 Frame* mainFrame = m_page->mainFrame();
1087 for (Frame* frame = mainFrame; frame; frame = frame->tree()->traverseNext())
1088 frame->document()->resumeScheduledTasks();
1089 mainFrame->loader()->resumeAllLoaders();
1092 void WebPage::suspendAnimations()
1094 Frame* mainFrame = m_page->mainFrame();
1098 for (Frame* frame = mainFrame; frame; frame = frame->tree()->traverseNext())
1099 frame->animation()->suspendAnimationsForDocument(frame->document());
1102 void WebPage::resumeAnimations()
1104 Frame* mainFrame = m_page->mainFrame();
1108 for (Frame* frame = mainFrame; frame; frame = frame->tree()->traverseNext())
1109 frame->animation()->resumeAnimationsForDocument(frame->document());
1112 #if ENABLE(TIZEN_SYNC_REQUEST_ANIMATION_FRAME)
1113 void WebPage::suspendAnimationController()
1115 if (!m_suspendedAnimationController) {
1116 Frame* mainFrame = m_page->mainFrame();
1120 for (Frame* frame = mainFrame; frame; frame = frame->tree()->traverseNext())
1121 frame->document()->suspendScriptedAnimationControllerCallbacks();
1123 m_suspendedAnimationController = true;
1127 void WebPage::resumeAnimationController()
1129 if (m_suspendedAnimationController) {
1130 Frame* mainFrame = m_page->mainFrame();
1134 for (Frame* frame = mainFrame; frame; frame = frame->tree()->traverseNext())
1135 frame->document()->resumeScriptedAnimationControllerCallbacks();
1137 m_suspendedAnimationController = false;
1142 #if ENABLE(TIZEN_REMOTE_WEB_INSPECTOR)
1143 void WebPage::startInspectorServer(uint32_t port, uint32_t& allocatedPort)
1145 bool ret = WebInspectorServerTizen::server()->startServer(port);
1147 allocatedPort = WebInspectorServerTizen::server()->getServerPort();
1152 void WebPage::stopInspectorServer(bool& result)
1154 result = WebInspectorServerTizen::server()->stopServer();
1158 #if ENABLE(TIZEN_CSS_OVERFLOW_SCROLL_ACCELERATION_ON_UI_SIDE)
1159 void WebPage::scrollOverflowWithTrajectoryVector(const WebCore::FloatPoint& trajectoryVector)
1161 Frame* frame = m_page->focusController()->focusedOrMainFrame();
1164 frame->eventHandler()->scrollOverflow(trajectoryVector);
1168 #if ENABLE(TIZEN_CSS_OVERFLOW_SCROLL_ACCELERATION)
1169 void WebPage::scrollOverflow(const WebCore::FloatPoint& delta, bool& scrolled)
1171 scrolled = m_page->focusController()->focusedOrMainFrame()->eventHandler()->scrollOverflow(delta);
1174 void WebPage::setPressedNodeAtPoint(const IntPoint& point, bool checkOverflowLayer, bool& pressed, uint32_t& id)
1176 RenderObject* renderer = 0;
1178 pressed = m_page->mainFrame()->eventHandler()->setMousePressNodeAtPoint(point, checkOverflowLayer, renderer);
1179 #if ENABLE(TIZEN_CSS_OVERFLOW_SCROLL_ACCELERATION_ON_UI_SIDE)
1180 if (pressed && renderer)
1181 id = toWebGraphicsLayer(renderer->enclosingLayer()->layerForScrollingContents())->id();
1186 void WebPage::executeEditCommandWithArgument(const String& commandName, const String& argument)
1188 executeEditingCommand(commandName, argument);
1191 #if ENABLE(TIZEN_PLUGIN_SUSPEND_RESUME)
1192 void WebPage::suspendPlugin()
1194 for (Frame* frame = m_page->mainFrame(); frame; frame = frame->tree()->traverseNext()) {
1195 FrameView* view = frame->view();
1199 const HashSet<RefPtr<Widget> >* children = view->children();
1202 HashSet<RefPtr<Widget> >::const_iterator end = children->end();
1203 for (HashSet<RefPtr<Widget> >::const_iterator it = children->begin(); it != end; ++it) {
1204 Widget* widget = (*it).get();
1205 if (widget->isPluginViewBase()) {
1206 PluginView* pluginView = static_cast<PluginView*>(widget);
1208 pluginView->suspendPlugin();
1214 void WebPage::resumePlugin()
1216 for (Frame* frame = m_page->mainFrame(); frame; frame = frame->tree()->traverseNext()) {
1217 FrameView* view = frame->view();
1221 const HashSet<RefPtr<Widget> >* children = view->children();
1224 HashSet<RefPtr<Widget> >::const_iterator end = children->end();
1225 for (HashSet<RefPtr<Widget> >::const_iterator it = children->begin(); it != end; ++it) {
1226 Widget* widget = (*it).get();
1227 if (widget->isPluginViewBase()) {
1228 PluginView* pluginView = static_cast<PluginView*>(widget);
1230 pluginView->resumePlugin();
1237 #if ENABLE(TIZEN_MULTIPLE_SELECT)
1238 void WebPage::didChangeSelectedIndexForActivePopupMenuMultiple(Vector<int32_t> newIndex)
1240 if (!m_activePopupMenu)
1243 m_activePopupMenu->client()->popupDidHide();
1245 size_t indexSize = newIndex.size();
1246 for (size_t i = 0; i < indexSize; i++)
1247 m_activePopupMenu->didChangeSelectedIndex(newIndex.at(i));
1252 #if ENABLE(TIZEN_OFFLINE_PAGE_SAVE)
1253 void WebPage::startOfflinePageSave(String subresourceFolderName)
1255 WebPageSerializerTizen::getSerializedPageContent(this, subresourceFolderName);
1259 #if ENABLE(TIZEN_WEBKIT2_TEXT_SELECTION)
1260 void WebPage::selectClosestWord(const IntPoint& point, bool& result)
1264 Frame* mainFrame = m_page->mainFrame();
1265 Frame* focusedFrame = m_page->focusController()->focusedOrMainFrame();
1267 HitTestResult hitTestResult = mainFrame->eventHandler()->hitTestResultAtPoint(m_page->mainFrame()->view()->windowToContents(point), false);
1269 Node* node = hitTestResult.innerNonSharedNode();
1273 Frame* newFocusFrame = node->document()->frame();
1274 if (focusedFrame != newFocusFrame) {
1275 m_page->focusController()->setFocusedFrame(newFocusFrame);
1276 focusedFrame = newFocusFrame;
1279 HTMLInputElement* inputElement = node->toInputElement();
1281 if (hitTestResult.isContentEditable()) {
1282 result = setCaretPosition(point);
1286 #if ENABLE(TIZEN_INPUT_TAG_EXTENSION)
1287 if (!node->isTextNode() && !inputElement)
1289 if (!node->isTextNode())
1293 #if ENABLE(TIZEN_INPUT_TAG_EXTENSION)
1295 && (inputElement->isDateField() || inputElement->isDateTimeField() || inputElement->isDateTimeLocalField()
1296 || inputElement->isMonthField() || inputElement->isTimeField() || inputElement->isWeekField())) {
1297 if (inputElement->value().isEmpty())
1302 for (Node* node = hitTestResult.innerNonSharedNode(); node; node = node->parentNode()) {
1303 if (node->isFocusable()) {
1304 // Text selection shoud not be started when text of <button> tag is selected.
1305 if (node->hasTagName(HTMLNames::buttonTag))
1308 if (inputElement && inputElement->isTextButton())
1315 FrameSelection* frameSelection = focusedFrame->selection();
1317 VisiblePosition position = mainFrame->visiblePositionForPoint(point);
1318 VisibleSelection selection(position);
1320 // This changes just the 'start' and 'end' positions of the VisibleSelection
1321 selection.expandUsingGranularity(WordGranularity);
1323 FrameSelection::SetSelectionOptions options = FrameSelection::CloseTyping | FrameSelection::ClearTypingStyle | FrameSelection::DoNotSetFocus;
1324 frameSelection->setSelection(VisibleSelection(selection.start(), selection.end()), options);
1326 if (!frameSelection->isRange())
1329 // This changes just the 'start' and 'end' positions of the VisibleSelection
1330 // Find handlers positions
1331 IntRect leftRect, rightRect;
1332 getSelectionHandlers(leftRect, rightRect);
1333 if (leftRect.size().isZero() && rightRect.size().isZero()) {
1334 // Sometimes there is no selected text, but isNone() returns TRUE
1335 // in this case ewk_frame_selection_handlers_get() returns FALSE and handlers are invalid
1336 // Workaround - clear the selection.
1337 // Better solution would be to modify the ewk_frame_select_closest_word()
1338 // to not select anything in the first place (for example - don't call setSelection()
1339 // if there is nothing under the cursor).
1340 selectionClearAllSelection(m_page->mainFrame());
1347 void WebPage::setLeftSelection(const IntPoint& point, const int direction, int& result)
1349 result = HandleMovingDirectionNone;
1351 Frame* focusedFrame = m_page->focusController()->focusedOrMainFrame();
1352 FrameSelection* frameSelection = focusedFrame->selection();
1353 if (!frameSelection->isRange())
1356 Node* selectionEndNode = frameSelection->end().deprecatedNode();
1357 if (!selectionEndNode || !selectionEndNode->renderer())
1360 FrameView* frameView = focusedFrame->view();
1364 IntPoint pos = frameView->windowToContents(point);
1365 IntRect leftRect, rightRect;
1366 getSelectionHandlers(leftRect, rightRect);
1368 if (selectionEndNode->rendererIsEditable() && !selectionEndNode->rendererIsRichlyEditable()) {
1369 const int boundariesWidth = 2;
1371 IntRect rect = frameSelection->caretRenderer()->absoluteBoundingBoxRect(true);
1372 // here we cheat input field that we actually are just inside of if
1373 if (pos.y() < rect.y() + boundariesWidth)
1374 pos.setY(rect.y() + boundariesWidth);
1375 else if (pos.y() >= rect.maxY() - boundariesWidth)
1376 pos.setY(rect.maxY() - boundariesWidth - 1);
1379 OwnPtr<VisiblePosition> position = adoptPtr(new VisiblePosition(focusedFrame->visiblePositionForPoint(pos)));
1380 Position base = frameSelection->base();
1381 Position extent = frameSelection->extent();
1383 Node* newSelectionStartNode = position->deepEquivalent().deprecatedNode();
1385 // both start and end nodes should be in the same area type: both should be editable or both should be not editable
1386 // Check if the new position is before the extent's position
1387 if (newSelectionStartNode
1388 && selectionEndNode->isContentEditable() == newSelectionStartNode->isContentEditable()) {
1389 // Change the 'base' and 'extent' positions to 'start' and 'end' positions.
1390 // We do it, because without this, the other modification of the selection
1391 // would destroy the 'start' and/or 'end' positions and set them to
1392 // the 'base'/'extent' positions accordingly
1393 VisibleSelection sel(frameSelection->start(), frameSelection->end());
1394 frameSelection->setSelection(sel);
1396 bool oldProhibitsScrolling = focusedFrame->view()->prohibitsScrolling();
1397 focusedFrame->view()->setProhibitsScrolling(true);
1399 if (direction == HandleMovingDirectionNormal) {
1400 if (comparePositions(position->deepEquivalent(), extent) < 0) {
1401 frameSelection->setBase(*position);
1402 result = HandleMovingDirectionNormal;
1403 } else if (comparePositions(position->deepEquivalent(), extent) > 0) {
1404 frameSelection->setExtent(*position);
1405 frameSelection->setBase(extent);
1406 result = HandleMovingDirectionReverse;
1408 } else if (direction == HandleMovingDirectionReverse) {
1409 if (comparePositions(position->deepEquivalent(), base) > 0) {
1410 frameSelection->setExtent(*position);
1411 result = HandleMovingDirectionReverse;
1412 } else if (comparePositions(position->deepEquivalent(), base) < 0) {
1413 frameSelection->setBase(*position);
1414 frameSelection->setExtent(base);
1415 result = HandleMovingDirectionNormal;
1419 focusedFrame->view()->setProhibitsScrolling(oldProhibitsScrolling);
1420 // This forces webkit to show selection
1421 // m_coreFrame->invalidateSelection();
1425 void WebPage::setRightSelection(const IntPoint& point, const int direction, int& result)
1427 result = HandleMovingDirectionNone;
1429 Frame* focusedFrame = m_page->focusController()->focusedOrMainFrame();
1430 FrameSelection* frameSelection = focusedFrame->selection();
1432 if (!frameSelection->isRange())
1435 Node* selectionStartNode = frameSelection->start().deprecatedNode();
1436 if (!selectionStartNode || !selectionStartNode->renderer())
1439 FrameView* frameView = focusedFrame->view();
1443 IntPoint pos = frameView->windowToContents(point);
1444 if (selectionStartNode->rendererIsEditable() && !selectionStartNode->rendererIsRichlyEditable()) {
1445 const int boundariesWidth = 2;
1447 IntRect rect = frameSelection->caretRenderer()->absoluteBoundingBoxRect(true);
1448 // here we cheat input field that we actually are just inside of if
1449 if (pos.y() < rect.y() + boundariesWidth)
1450 pos.setY(rect.y() + boundariesWidth);
1451 else if (pos.y() >= rect.maxY() - boundariesWidth)
1452 pos.setY(rect.maxY() - boundariesWidth - 1);
1455 OwnPtr<VisiblePosition> position = adoptPtr(new VisiblePosition(focusedFrame->visiblePositionForPoint(pos)));
1456 Position base = frameSelection->base();
1457 Position extent = frameSelection->extent();
1459 Node* newSelectionEndNode = position->deepEquivalent().deprecatedNode();
1461 // both start and end nodes should be in the same area type: both should be editable or both should be not editable
1462 // Check if the new position is after the base's position
1463 if (newSelectionEndNode
1464 && selectionStartNode->isContentEditable() == newSelectionEndNode->isContentEditable()) {
1465 // Change the 'base' and 'extent' positions to 'start' and 'end' positions.
1466 // We do it, because without this, the other modifications of the selection
1467 // would destroy the 'start' and/or 'end' positions and set them to
1468 // the 'base'/'extent' positions accordingly
1470 VisibleSelection sel(frameSelection->start(), frameSelection->end());
1471 frameSelection->setSelection(sel);
1473 bool oldProhibitsScrolling = focusedFrame->view()->prohibitsScrolling();
1474 focusedFrame->view()->setProhibitsScrolling(true);
1476 if (direction == HandleMovingDirectionNormal) {
1477 if (comparePositions(position->deepEquivalent(), base) > 0) {
1478 frameSelection->setExtent(*position);
1479 result = HandleMovingDirectionNormal;
1480 } else if (comparePositions(position->deepEquivalent(), base) < 0) {
1481 frameSelection->setBase(*position);
1482 frameSelection->setExtent(base);
1483 result = HandleMovingDirectionReverse;
1485 } else if (direction == HandleMovingDirectionReverse) {
1486 if (comparePositions(position->deepEquivalent(), extent) < 0) {
1487 frameSelection->setBase(*position);
1488 result = HandleMovingDirectionReverse;
1489 } else if (comparePositions(position->deepEquivalent(), extent) > 0) {
1490 frameSelection->setExtent(*position);
1491 frameSelection->setBase(extent);
1492 result = HandleMovingDirectionNormal;
1496 focusedFrame->view()->setProhibitsScrolling(oldProhibitsScrolling);
1500 void WebPage::getSelectionHandlers(IntRect& leftRect, IntRect& rightRect)
1502 Frame* focusedFrame = m_page->focusController()->focusedOrMainFrame();
1503 if (!focusedFrame->selection()->isRange())
1506 // Is this check necessary? Leaving it for safety.
1507 RenderView* root = focusedFrame->contentRenderer();
1511 RefPtr<Range> selectedRange = focusedFrame->selection()->toNormalizedRange();
1513 Vector<IntRect> rects;
1514 selectedRange->boundingBoxEx(rects, true);
1516 unsigned size = rects.size();
1518 leftRect = rects[0];
1519 rightRect = rects[size-1];
1521 // If selection rect size is greater than editor rect size because of round operation,
1522 // selection rect size should be changed to editor rect size.
1524 Element* rootEditableElement = focusedFrame->selection()->rootEditableElement();
1525 if (rootEditableElement) {
1526 Vector<IntRect> rects;
1527 calcFocusedRects(rootEditableElement, rects);
1528 IntRect editorRect = unionRect(rects);
1530 #if ENABLE(TIZEN_WEBKIT2_TEXT_SELECTION)
1531 if (m_editorState.editorRect != editorRect) {
1532 EditorState state = editorState();
1533 state.updateEditorRectOnly = true;
1534 setEditorState(state);
1535 send(Messages::WebPageProxy::EditorStateChanged(state));
1539 if (leftRect.maxY() > editorRect.maxY()) {
1540 leftRect.setY(editorRect.y());
1541 leftRect.setHeight(editorRect.height());
1544 if (rightRect.maxY() > editorRect.maxY()) {
1545 rightRect.setY(editorRect.y());
1546 rightRect.setHeight(editorRect.height());
1551 // prevent from selecting zero-length selection
1552 if (leftRect.x() == rightRect.x() + rightRect.width()
1553 && leftRect.y() == rightRect.y())
1556 FrameView* frameView = focusedFrame->view();
1560 leftRect = frameView->contentsToWindow(leftRect);
1561 rightRect = frameView->contentsToWindow(rightRect);
1565 void WebPage::getSelectionText(String& result)
1567 Frame* focusedFrame = m_page->focusController()->focusedOrMainFrame();
1568 result = focusedFrame->editor()->selectedText();
1571 void WebPage::selectionRangeClear(bool& result)
1575 Frame* focusedFrame = m_page->focusController()->focusedOrMainFrame();
1576 FrameSelection* frameSelection = focusedFrame->selection();
1577 if (frameSelection && frameSelection->isRange() && frameSelection->isContentEditable()) {
1578 VisiblePosition visiblePos(frameSelection->extent());
1579 if (visiblePos.isNull())
1582 focusedFrame->editor()->setIgnoreCompositionSelectionChange(true);
1583 frameSelection->setSelection(VisibleSelection(visiblePos), CharacterGranularity);
1584 focusedFrame->editor()->setIgnoreCompositionSelectionChange(false);
1586 frameSelection->setCaretBlinkingSuspended(false);
1588 selectionClearAllSelection(m_page->mainFrame());
1593 void WebPage::selectionClearAllSelection(Frame* frame)
1598 FrameSelection* frameSelection = frame->selection();
1600 frameSelection->clear();
1605 if (frame->tree()->childCount() > 0) {
1606 if (frame->tree()->firstChild())
1607 selectionClearAllSelection(frame->tree()->firstChild());
1608 } else if (frame->tree()->nextSibling())
1609 selectionClearAllSelection(frame->tree()->nextSibling());
1612 void WebPage::scrollContentByCharacter(const IntPoint&, int direction, bool& result)
1616 Frame* focusedFrame = m_page->focusController()->focusedOrMainFrame();
1620 FrameSelection* frameSelection = focusedFrame->selection();
1621 if (!frameSelection)
1624 VisiblePosition currentPosition = frameSelection->selection().visibleStart();
1626 if (isStartOfLine(currentPosition))
1629 focusedFrame->selection()->modify(FrameSelection::AlterationMove, DirectionBackward, CharacterGranularity, UserTriggered);
1631 if (isEndOfLine(currentPosition))
1634 focusedFrame->selection()->modify(FrameSelection::AlterationMove, DirectionForward, CharacterGranularity, UserTriggered);
1638 void WebPage::scrollContentByLine(const IntPoint&, int direction, bool& result)
1642 Frame* focusedFrame = m_page->focusController()->focusedOrMainFrame();
1646 FrameSelection* frameSelection = focusedFrame->selection();
1647 if (!frameSelection)
1650 VisiblePosition currentPosition = frameSelection->selection().visibleStart();
1652 if (inSameLine(currentPosition, previousLinePosition(currentPosition, 0)))
1655 focusedFrame->selection()->modify(FrameSelection::AlterationMove, DirectionBackward, LineGranularity, UserTriggered);
1657 if (inSameLine(currentPosition, nextLinePosition(currentPosition, 0)))
1660 focusedFrame->selection()->modify(FrameSelection::AlterationMove, DirectionForward, LineGranularity, UserTriggered);
1665 #if ENABLE(TIZEN_LINK_MAGNIFIER)
1666 void WebPage::getLinkMagnifierRect(const IntPoint& position, const IntSize& size)
1668 send(Messages::WebPageProxy::DidGetLinkMagnifierRect(position, LinkMagnifier::rect(this, position, size)));
1672 #if ENABLE(TIZEN_SCREEN_READER)
1673 void WebPage::moveScreenReaderFocus(bool forward, bool& result)
1675 if (!m_screenReader)
1676 m_screenReader = ScreenReader::create(this);
1678 result = m_screenReader->moveFocus(forward);
1681 void WebPage::moveScreenReaderFocusByPoint(const IntPoint& point)
1683 if (!m_screenReader)
1684 m_screenReader = ScreenReader::create(this);
1686 if (!m_screenReader->moveFocus(point))
1690 void WebPage::clearScreenReaderFocus()
1692 if (!m_screenReader)
1695 m_screenReader->clearFocus();
1698 void WebPage::raiseTapEvent(const IntPoint& position, const IntPoint& globalPosition, bool& result)
1702 #if ENABLE(GESTURE_EVENTS)
1703 Frame* frame = m_page->mainFrame();
1707 Vector<WebPlatformTouchPoint> touchPoints;
1708 touchPoints.append(WebPlatformTouchPoint(0, WebPlatformTouchPoint::TouchPressed, globalPosition, position));
1710 WebTouchEvent touchStartEvent(WebEvent::TouchStart, touchPoints, WebEvent::Modifiers(0), ecore_time_get());
1711 bool handled = frame->eventHandler()->handleTouchEvent(platform(touchStartEvent));
1713 touchPoints.at(0).setState(WebPlatformTouchPoint::TouchReleased);
1715 WebTouchEvent touchEndEvent(WebEvent::TouchEnd, touchPoints, WebEvent::Modifiers(0), ecore_time_get());
1716 handled |= frame->eventHandler()->handleTouchEvent(platform(touchEndEvent));
1719 WebGestureEvent gestureEvent(WebEvent::GestureSingleTap, position, globalPosition, WebEvent::Modifiers(0), ecore_time_get());
1720 frame->eventHandler()->handleGestureEvent(platform(gestureEvent));
1726 void WebPage::adjustScreenReaderFocusedObjectValue(bool up)
1728 if (!m_screenReader || !m_focusedNode || !m_focusedNode->toInputElement())
1733 m_focusedNode->toInputElement()->stepUp(ec);
1735 m_focusedNode->toInputElement()->stepDown(ec);
1738 void WebPage::updateScreenReaderFocus(RenderObject* object)
1740 if (!m_screenReader)
1744 m_screenReader->clearFocus();
1745 else if (!m_screenReader->rendererWillBeDestroyed(object))
1749 void WebPage::clearScreenReader()
1751 m_screenReader.clear();
1755 #if ENABLE(TIZEN_WEBKIT2_FOCUS_RING) || ENABLE(TIZEN_WEBKIT2_TEXT_SELECTION)
1756 static LayoutRect rectToAbsoluteCoordinates(Frame* initialFrame, const LayoutRect& initialRect)
1758 LayoutRect rect = initialRect;
1759 for (Frame* frame = initialFrame; frame; frame = frame->tree()->parent()) {
1760 RenderBoxModelObject* renderer;
1761 if (frame->ownerElement() && (renderer = frame->ownerElement()->renderBoxModelObject())) {
1763 rect.move(renderer->offsetLeft(), renderer->offsetTop());
1764 } while ((renderer = renderer->offsetParent()));
1765 rect.move(-frame->view()->scrollOffset());
1771 void WebPage::calcFocusedRects(Node* node, Vector<IntRect>& rects) const
1773 if (!node || !node->renderer())
1776 RenderObject* renderer = node->renderer();
1777 FrameView* view = node->document()->frame()->view();
1779 IntPoint absolutePoint;
1780 absolutePoint = view->convertToContainingWindow(view->convertFromRenderer(renderer, absolutePoint));
1781 renderer->addFocusRingRects(rects, absolutePoint);
1783 if (!rects.isEmpty())
1787 if (node->hasTagName(HTMLNames::areaTag)) {
1788 HTMLAreaElement* area = static_cast<HTMLAreaElement*>(node);
1789 HTMLImageElement* image = area->imageElement();
1790 if (!image || !image->renderer())
1793 rect = rectToAbsoluteCoordinates(area->document()->frame(), area->computeRect(area->imageElement()->renderer()));
1794 } else if (node->renderer()) {
1795 if (node->isDocumentNode())
1796 rect = rectToAbsoluteCoordinates(static_cast<Document*>(node)->frame(), static_cast<Document*>(node)->frame()->view()->visibleContentRect());
1798 rect = node->getRect();
1799 rect.intersect(node->renderer()->absoluteClippedOverflowRect());
1800 rect = rectToAbsoluteCoordinates(node->document()->frame(), rect);
1802 rect.move(node->renderer()->style()->borderLeftWidth(), node->renderer()->style()->borderTopWidth());
1803 rect.setWidth(rect.width() - node->renderer()->style()->borderLeftWidth() - node->renderer()->style()->borderRightWidth());
1804 rect.setHeight(rect.height() - node->renderer()->style()->borderTopWidth() - node->renderer()->style()->borderBottomWidth());
1808 rects.append(pixelSnappedIntRect(rect));
1812 #if ENABLE(TIZEN_WEBKIT2_FOCUS_RING)
1813 void WebPage::setFocusedNode(Node* node)
1815 m_focusedNode = node;
1816 didChangeFocusedRects();
1819 void WebPage::didChangeFocusedRects()
1821 Vector<IntRect> rects;
1822 calcFocusedRects(m_focusedNode.get(), rects);
1823 if (m_focusedRects == rects)
1826 m_focusedRects = rects;
1827 send(Messages::WebPageProxy::DidChangeFocusedRects(m_focusedRects));
1830 void WebPage::recalcFocusedRects()
1835 didChangeFocusedRects();
1839 #if ENABLE(TIZEN_WEBKIT2_POPUP_INTERNAL)
1840 // FIXME: Currently with cached pages, hiding Popup list menu is not working correctly.
1841 // This patch is a fix allowing any popup list menu to get close for any page navigation.
1842 void WebPage::notifyTransitionToCommitted(bool forNewPage)
1844 if (m_activePopupMenu) {
1846 m_activePopupMenu->hide();
1847 m_activePopupMenu = 0;
1852 #if ENABLE(TIZEN_CSP)
1853 void WebPage::setContentSecurityPolicy(const String& policy, uint32_t headerType)
1855 Frame* frame = m_page->focusController()->focusedOrMainFrame();
1859 Document* document = frame->document();
1863 document->contentSecurityPolicy()->didReceiveHeader(policy, static_cast<WebCore::ContentSecurityPolicy::HeaderType>(headerType));
1867 #if ENABLE(TIZEN_INDEXED_DATABASE)
1868 void WebPage::setIndexedDatabaseDirectory(const String& path)
1870 m_page->group().groupSettings()->setIndexedDBDatabasePath(path);
1874 #if ENABLE(TIZEN_WEB_STORAGE)
1875 void WebPage::setLocalStorageDirectory(const String& path)
1877 m_page->settings()->setLocalStorageDatabasePath(path);
1881 #if ENABLE(TIZEN_USE_SETTINGS_FONT)
1882 void WebPage::useSettingsFont()
1884 if (!WebCore::fontCache()->isFontFamliyTizen())
1887 FcInitReinitialize();
1888 WebCore::fontCache()->invalidate();
1890 FrameView* frameView = m_mainFrame->coreFrame()->view();
1894 frameView->forceLayout();
1898 void WebPage::didChangeContents(const IntRect& rect)
1903 Frame* frame = m_page->focusController()->focusedOrMainFrame();
1904 if (!frame || !frame->view() || frame->view()->needsLayout())
1907 #if ENABLE(TIZEN_ISF_PORT) || ENABLE(TIZEN_WEBKIT2_TEXT_SELECTION)
1908 if (m_editorState.isContentEditable && rect.intersects(m_editorState.editorRect) && frame->selection()->rootEditableElement()) {
1909 IntRect previousEditorRect = m_editorState.editorRect;
1910 updateEditorStateRect(frame, m_editorState);
1912 if (m_editorState.editorRect != previousEditorRect) {
1913 m_editorState.updateEditorRectOnly = true;
1914 send(Messages::WebPageProxy::EditorStateChanged(m_editorState));
1919 #if ENABLE(TIZEN_WEBKIT2_FOCUS_RING)
1920 didChangeFocusedRects();
1924 #if ENABLE(TIZEN_FOCUS_UI)
1925 void WebPage::setSpatialNavigationEnabled(bool enabled)
1927 m_page->settings()->setSpatialNavigationEnabled(enabled);
1929 if (m_focusedNode && m_focusedNode->renderer())
1930 m_focusedNode->renderer()->repaint();
1936 #endif // #if OS(TIZEN)
1938 } // namespace WebKit