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"
132 #include "RenderIFrame.h"
135 #if ENABLE(TIZEN_LINK_MAGNIFIER)
136 #include "LinkMagnifier.h"
139 #if ENABLE(TIZEN_SCREEN_READER)
140 #include "WebEventConversion.h"
143 #if ENABLE(TIZEN_SCREEN_READER) || ENABLE(TIZEN_FOCUS_UI) || ENABLE(TIZEN_WEBKIT2_TEXT_SELECTION)
144 #include <WebCore/HTMLAreaElement.h>
147 #if ENABLE(TIZEN_CSP)
148 #include <WebCore/ContentSecurityPolicy.h>
151 #if ENABLE(TIZEN_OFFLINE_PAGE_SAVE)
152 #include "WebPageSerializerTizen.h"
155 #if ENABLE(TIZEN_USE_SETTINGS_FONT)
156 #include "fontconfig/fontconfig.h"
157 #include <WebCore/FontCache.h>
158 #include <WebCore/PageCache.h>
161 #if ENABLE(TIZEN_WEBKIT2_TEXT_SELECTION)
162 #include "visible_units.h"
164 #endif // #if OS(TIZEN)
166 using namespace WebCore;
170 void WebPage::platformInitialize()
172 #if ENABLE(TIZEN_DEVICE_ORIENTATION)
173 WebCore::provideDeviceMotionTo(m_page.get(), new DeviceMotionClientTizen);
174 WebCore::provideDeviceOrientationTo(m_page.get(), new DeviceOrientationClientTizen);
178 #if ENABLE(TIZEN_PREFERENCE)
179 void WebPage::platformPreferencesDidChange(const WebPreferencesStore& store)
181 Settings* settings = m_page->settings();
182 settings->setInteractiveFormValidationEnabled(store.getBoolValueForKey(WebPreferencesKey::interactiveFormValidationEnabledKey()));
183 settings->setUsesEncodingDetector(store.getBoolValueForKey(WebPreferencesKey::usesEncodingDetectorKey()));
184 #if ENABLE(TIZEN_LOAD_REMOTE_IMAGES)
185 settings->setLoadRemoteImages(store.getBoolValueForKey(WebPreferencesKey::loadRemoteImagesKey()));
187 #if ENABLE(TIZEN_LINK_EFFECT)
188 settings->setLinkEffectEnabled(store.getBoolValueForKey(WebPreferencesKey::linkEffectEnabledKey()));
190 #if ENABLE(TIZEN_ISF_PORT)
191 settings->setEnableDefaultKeypad(store.getBoolValueForKey(WebPreferencesKey::defaultKeypadEnabledKey()));
193 #if ENABLE(TIZEN_STYLE_SCOPED)
194 WebCore::RuntimeEnabledFeatures::setStyleScopedEnabled(store.getBoolValueForKey(WebPreferencesKey::styleScopedEnabledKey()));
196 #if ENABLE(TIZEN_WEB_AUDIO)
197 settings->setWebAudioEnabled(true);
201 void WebPage::platformPreferencesDidChange(const WebPreferencesStore&)
205 #endif // #if ENABLE(TIZEN_PREFERENCE)
207 static inline void scroll(Page* page, ScrollDirection direction, ScrollGranularity granularity)
209 page->focusController()->focusedOrMainFrame()->eventHandler()->scrollRecursively(direction, granularity);
212 bool WebPage::performDefaultBehaviorForKeyEvent(const WebKeyboardEvent& keyboardEvent)
218 bool WebPage::platformHasLocalDataForURL(const KURL&)
224 String WebPage::cachedResponseMIMETypeForURL(const KURL&)
230 bool WebPage::platformCanHandleRequest(const ResourceRequest&)
236 String WebPage::cachedSuggestedFilenameForURL(const KURL&)
242 PassRefPtr<SharedBuffer> WebPage::cachedResponseDataForURL(const KURL&)
248 const char* WebPage::interpretKeyEvent(const KeyboardEvent* event)
250 ASSERT(event->type() == eventNames().keydownEvent || event->type() == eventNames().keypressEvent);
252 if (event->type() == eventNames().keydownEvent)
253 return getKeyDownCommandName(event);
255 return getKeyPressCommandName(event);
258 void WebPage::setThemePath(const String& themePath)
260 WebCore::RenderThemeEfl* theme = static_cast<WebCore::RenderThemeEfl*>(m_page->theme());
261 theme->setThemePath(themePath);
264 static Frame* targetFrameForEditing(WebPage* page)
266 Frame* frame = page->corePage()->focusController()->focusedOrMainFrame();
270 Editor* editor = frame->editor();
271 if (!editor->canEdit())
274 if (editor->hasComposition()) {
275 // We should verify the parent node of this IME composition node are
276 // editable because JavaScript may delete a parent node of the composition
277 // node. In this case, WebKit crashes while deleting texts from the parent
278 // node, which doesn't exist any longer.
279 if (PassRefPtr<Range> range = editor->compositionRange()) {
280 Node* node = range->startContainer();
281 if (!node || !node->isContentEditable())
289 void WebPage::confirmComposition(const String& compositionString)
291 Frame* targetFrame = targetFrameForEditing(this);
295 #if ENABLE(TIZEN_ISF_PORT)
296 if (m_prepareKeyDownEvent) {
297 m_keyPressCommands.append(adoptPtr(new ConfirmCompositionKeyPressCommand(compositionString)));
302 targetFrame->editor()->confirmComposition(compositionString);
304 #if ENABLE(TIZEN_ISF_PORT)
305 m_page->editorClient()->respondToChangedSelection(targetFrame);
309 void WebPage::setComposition(const String& compositionString, const Vector<WebCore::CompositionUnderline>& underlines, uint64_t cursorPosition)
311 Frame* targetFrame = targetFrameForEditing(this);
315 #if ENABLE(TIZEN_ISF_PORT)
316 if (!targetFrame->editor()->hasComposition() && compositionString.isEmpty())
319 if (m_prepareKeyDownEvent) {
320 m_keyPressCommands.append(adoptPtr(new SetCompositionKeyPressCommand(compositionString, underlines, cursorPosition)));
324 if (targetFrame->selection()->rootEditableElement()) {
325 HTMLTextFormControlElement* textFormControl = toTextFormControl(targetFrame->selection()->rootEditableElement()->shadowAncestorNode());
326 if (textFormControl && textFormControl->maxLength() >= 0) {
327 unsigned availableLength = textFormControl->maxLength() - textFormControl->value().length();
328 if (targetFrame->editor()->hasComposition())
329 availableLength += (targetFrame->editor()->compositionEnd() - targetFrame->editor()->compositionStart());
330 if (!availableLength)
333 if (availableLength < compositionString.length()) {
334 String newCompositionString = compositionString.substring(0, availableLength);
335 Vector<CompositionUnderline> newUnderlines;
336 size_t numUnderlines = underlines.size();
337 for (size_t index = 0; index < numUnderlines; ++index) {
338 if (underlines[index].startOffset < availableLength) {
339 newUnderlines.append(underlines[index]);
340 if (newUnderlines.last().endOffset > availableLength)
341 newUnderlines.last().endOffset = availableLength;
345 m_page->editorClient()->lockRespondToChangedSelection();
346 targetFrame->editor()->setComposition(newCompositionString, newUnderlines, cursorPosition, 0);
347 m_page->editorClient()->unlockRespondToChangedSelection();
354 m_page->editorClient()->lockRespondToChangedSelection();
357 targetFrame->editor()->setComposition(compositionString, underlines, cursorPosition, 0);
359 #if ENABLE(TIZEN_ISF_PORT)
360 m_page->editorClient()->unlockRespondToChangedSelection();
364 void WebPage::cancelComposition()
366 Frame* frame = m_page->focusController()->focusedOrMainFrame();
370 frame->editor()->cancelComposition();
375 #if ENABLE(TIZEN_WEBKIT2_TILED_BACKING_STORE)
376 IntSize WebPage::contentsSize() const
378 FrameView* frameView = m_page->mainFrame()->view();
380 return IntSize(0, 0);
382 return frameView->contentsSize();
386 void WebPage::scrollMainFrameBy(const IntSize& scrollOffset)
388 m_page->mainFrame()->view()->scrollBy(scrollOffset);
391 void WebPage::scrollMainFrameTo(const IntPoint& scrollPosition)
393 m_page->mainFrame()->view()->setScrollPosition(scrollPosition);
396 void WebPage::createSnapshot(const IntRect rect, float scaleFactor, ShareableBitmap::Handle& snapshotHandle)
398 FrameView* frameView = m_mainFrame->coreFrame()->view();
402 RefPtr<WebImage> snapshotImage = scaledSnapshotInViewCoordinates(rect, scaleFactor, ImageOptionsShareable);
403 if (!snapshotImage || !snapshotImage->bitmap())
406 snapshotImage->bitmap()->createHandle(snapshotHandle);
409 void WebPage::requestUpdateFormNavigation()
411 Frame* frame = m_page->focusController()->focusedOrMainFrame();
415 Document* document = frame->document();
419 Node* focusedNode = document->focusedNode();
421 Vector<RefPtr<Node> > focusableNodes;
422 document->getFocusableNodes(focusableNodes);
424 int formElementCount = 0;
425 int currentNodeIndex = -1;
426 const Vector<RefPtr<Node> >::iterator end = focusableNodes.end();
427 for (Vector<RefPtr<Node> >::iterator it = focusableNodes.begin(); it != end; ++it) {
428 AtomicString nodeName = (*it).get()->nodeName();
429 if (equalIgnoringCase(nodeName, "SELECT")
430 || (equalIgnoringCase(nodeName, "INPUT")
431 && !equalIgnoringCase((*it).get()->toInputElement()->type(), "CHECKBOX")
432 && !equalIgnoringCase((*it).get()->toInputElement()->type(), "RADIO")
433 && !equalIgnoringCase((*it).get()->toInputElement()->type(), "SUBMIT")
436 if ((*it).get() == focusedNode)
437 currentNodeIndex = formElementCount;
442 if (currentNodeIndex == -1)
445 send(Messages::WebPageProxy::UpdateFormNavigation(formElementCount, currentNodeIndex));
448 void WebPage::moveFocus(int newIndex)
450 Frame* frame = m_page->focusController()->focusedOrMainFrame();
454 Document* document = frame->document();
458 Vector<RefPtr<Node> > focusableNodes;
459 document->getFocusableNodes(focusableNodes);
462 const Vector<RefPtr<Node> >::iterator end = focusableNodes.end();
463 for (Vector<RefPtr<Node> >::iterator it = focusableNodes.begin(); it != end; ++it) {
464 AtomicString nodeName = (*it).get()->nodeName();
465 if (equalIgnoringCase(nodeName, "SELECT")) {
466 if (index == newIndex) {
467 (*it).get()->setFocus();
468 LayoutPoint position = LayoutPoint(0, 0);
469 PlatformMouseEvent event(flooredIntPoint(position), flooredIntPoint(position), LeftButton, PlatformEvent::MouseMoved, 1, false, false, false, false, 0);
470 (*it).get()->dispatchMouseEvent(event, "mousedown", 0, 0);
473 } else if (equalIgnoringCase(nodeName, "INPUT")
474 && !equalIgnoringCase((*it).get()->toInputElement()->type(), "CHECKBOX")
475 && !equalIgnoringCase((*it).get()->toInputElement()->type(), "RADIO")
477 if (index == newIndex) {
478 HTMLInputElement* elem = (*it).get()->toInputElement();
486 #if ENABLE(TIZEN_MOBILE_WEB_PRINT)
487 #define INCH_TO_MM 25.4
488 #define INCH_TO_POINTS 72.0
490 void WebPage::createPagesToPDF(const IntSize& surfaceSize, const IntSize& contentsSize, const String& fileName)
492 FrameView* frameView = m_mainFrame->coreFrame()->view();
496 RefPtr<WebImage> pageshotImage = WebImage::create(contentsSize, ImageOptionsShareable);
497 if (!pageshotImage->bitmap())
500 double pdfWidth = (double)surfaceSize.width() / INCH_TO_MM * INCH_TO_POINTS;
501 double pdfHeight = (double)surfaceSize.height() / INCH_TO_MM * INCH_TO_POINTS;
502 double scaleFactorPdf = 1.0;
503 if (contentsSize.width() > pdfWidth)
504 scaleFactorPdf = pdfWidth / (double)contentsSize.width();
506 OwnPtr<WebCore::GraphicsContext> graphicsContext = pageshotImage->bitmap()->createGraphicsContextForPdfSurface(fileName, pdfWidth, pdfHeight);
507 graphicsContext->scale(FloatSize(scaleFactorPdf, scaleFactorPdf));
509 frameView->updateLayoutAndStyleIfNeededRecursive();
511 int pageNumber = ((contentsSize.height() * scaleFactorPdf) / pdfHeight) + 1;
514 PaintBehavior oldBehavior = frameView->paintBehavior();
515 frameView->setPaintBehavior(oldBehavior | PaintBehaviorFlattenCompositingLayers);
516 for (int i = 0; i < pageNumber; i++) {
517 IntRect paintRect(0, (int)paintY, contentsSize.width(), (int)(pdfHeight / scaleFactorPdf));
519 frameView->paint(graphicsContext.get(), paintRect);
520 cairo_show_page(graphicsContext->platformContext()->cr());
521 graphicsContext->translate(0, -ceil(pdfHeight / scaleFactorPdf));
522 paintY += (pdfHeight / scaleFactorPdf);
524 frameView->setPaintBehavior(oldBehavior);
526 pageshotImage.release();
530 #if ENABLE(TIZEN_TEXT_CARET_HANDLING_WK2)
531 bool WebPage::setCaretPosition(const IntPoint& pos)
533 Frame* frame = m_page->focusController()->focusedOrMainFrame();
537 FrameSelection* controller = frame->selection();
541 FrameView* frameView = frame->view();
545 IntPoint point = m_page->mainFrame()->view()->windowToContents(pos);
546 HitTestResult result = m_page->mainFrame()->eventHandler()->hitTestResultAtPoint(point, /*allowShadowContent*/ true, /*ignoreClipping*/ true);
547 if (result.scrollbar())
550 Node* innerNode = result.innerNode();
552 if (!innerNode || !innerNode->renderer())
555 VisiblePosition visiblePos;
557 // we check if content is richly editable - because those input field behave other than plain text ones
558 // sometimes they may consists a node structure and they need special approach
559 if (innerNode->rendererIsRichlyEditable()) {
560 // point gets inner node local coordinates
561 point = flooredIntPoint(result.localPoint());
562 IntRect rect = innerNode->renderer()->absoluteBoundingBoxRect(true);
564 // it is not the best way to do this, but it is not as slow and it works - so maybe in the future someone
565 // will have a better idea how to solve it
566 // here we are getting innerNode from HitTestResult - unfortunately this is a kind of high level node
567 // in the code below I am trying to obtain low level node - #text - to get its coordinates and size
569 // all those getting nodes rects are needed to bypass WebCore's methods of positioning caret when user
570 // is clicking outside a node - and cheat WebCore telling it that actually we clicked into input field
571 // node, not outside of it
572 Node* deepInnerNode = innerNode->renderer()->positionForPoint(point).deepEquivalent().deprecatedNode();
574 if (!deepInnerNode || !deepInnerNode->renderer())
577 // so we get a base node rectange
578 IntRect deepNodeRect = deepInnerNode->renderer()->absoluteBoundingBoxRect(true);
580 // we modify our local point to adjust it to base node local coordinates
581 point.move(rect.x() - deepNodeRect.x(), rect.y() - deepNodeRect.y());
583 // if we are outside the rect we cheat, that we are just inside of it
586 else if (point.y() >= deepNodeRect.height())
587 point.setY(deepNodeRect.height() - 1);
589 // visible position created - caret ready to set
590 visiblePos = deepInnerNode->renderer()->positionForPoint(point);
591 if (visiblePos.isNull())
594 // for plain text input fields we can get only a caret bounding box
595 if (!controller->isCaret() || !controller->caretRenderer())
598 const Node* node = controller->start().deprecatedNode();
599 if (!node || !node->renderer())
602 Element* currentRootEditableElement = node->rootEditableElement();
603 Element* newRootEditableElement = innerNode->rootEditableElement();
604 if (currentRootEditableElement != newRootEditableElement)
607 IntRect rect = controller->caretRenderer()->absoluteBoundingBoxRect(true);
609 // The below wirtten code is not correct way to implement. Presntly the is no
610 // other working way. To be replaced by better logic
611 // here we also cheat input field that we actually are just inside of if
612 IntPoint focusedFramePoint = frame->view()->windowToContents(pos);
613 IntPoint oldFocusedFramePoint = focusedFramePoint;
615 const int boundariesWidth = 2;
616 if (focusedFramePoint.x() < rect.x())
617 focusedFramePoint.setX(rect.x());
618 else if (focusedFramePoint.x() > rect.maxX())
619 focusedFramePoint.setX(rect.maxX());
620 if (focusedFramePoint.y() < rect.y() + boundariesWidth)
621 focusedFramePoint.setY(rect.y() + boundariesWidth);
622 else if (focusedFramePoint.y() >= rect.maxY() - boundariesWidth)
623 focusedFramePoint.setY(rect.maxY() - boundariesWidth - 1);
625 int diffX = focusedFramePoint.x() - oldFocusedFramePoint.x();
626 int diffY = focusedFramePoint.y() - oldFocusedFramePoint.y();
627 point.setX((point.x())+diffX);
628 point.setY((point.y())+diffY);
630 // hit test with fake (adjusted) coordinates
631 IntPoint hitTestPoint = m_page->mainFrame()->view()->windowToContents(point);
632 HitTestResult newResult = m_page->mainFrame()->eventHandler()->hitTestResultAtPoint(hitTestPoint, /*allowShadowContent*/ true, /*ignoreClipping*/ true);
634 if (!newResult.isContentEditable())
637 Node* newInnerNode = newResult.innerNode();
639 if (!newInnerNode || !newInnerNode->renderer())
642 // visible position created
643 visiblePos = newInnerNode->renderer()->positionForPoint(newResult.localPoint());
644 if (visiblePos.isNull())
648 // create visible selection from visible position
649 VisibleSelection newSelection = VisibleSelection(visiblePos);
650 controller->setSelection(newSelection, CharacterGranularity);
651 // after setting selection caret blinking is suspended by default so we are unsuspedning it
652 controller->setCaretBlinkingSuspended(false);
658 #if ENABLE(TIZEN_ISF_PORT)
659 void WebPage::didCancelComposition(Node* valueChangedNode)
661 Frame* frame = m_page->focusController()->focusedOrMainFrame();
662 if (!frame || frame->editor()->ignoreCompositionSelectionChange() || !valueChangedNode->containsIncludingShadowDOM(frame->editor()->compositionNode()))
665 frame->editor()->cancelComposition();
666 send(Messages::WebPageProxy::DidCancelComposition());
669 void WebPage::prepareKeyDownEvent()
671 m_prepareKeyDownEvent = true;
674 void WebPage::swapKeyPressCommands(Vector<OwnPtr<KeyPressCommand> >& commands)
676 m_keyPressCommands.swap(commands);
679 void WebPage::deleteSurroundingText(int offset, int count)
681 Frame* frame = m_page->focusController()->focusedOrMainFrame();
682 if (!frame || !frame->editor()->canEdit())
685 if (m_prepareKeyDownEvent) {
686 m_keyPressCommands.append(adoptPtr(new DeleteTextKeyPressCommand(offset, count)));
690 Position base(frame->selection()->base());
691 offset += base.offsetInContainerNode();
692 base.moveToOffset(offset);
693 Position extent(base);
694 extent.moveToOffset(offset + count);
695 VisibleSelection selection(base, extent);
696 if (!selection.isRange())
699 frame->selection()->setSelection(selection);
700 frame->editor()->deleteWithDirection(DirectionBackward, CharacterGranularity, false, true);
703 bool WebPage::updateEditorStateRect(const Frame* frame, EditorState& state) const
705 ASSERT(frame->selection()->rootEditableElement());
707 #if ENABLE(TIZEN_WEBKIT2_TEXT_SELECTION)
708 Vector<IntRect> rects;
709 calcFocusedRects(frame->selection()->rootEditableElement(), rects);
710 IntRect rect = unionRect(rects);
711 if (state.editorRect == rect)
714 state.editorRect = rect;
717 if (frame->selection()->isCaret())
718 state.selectionRect = frame->view()->contentsToWindow(frame->selection()->absoluteCaretBounds());
719 else if (frame->selection()->isRange())
720 state.selectionRect = frame->view()->contentsToWindow(enclosingIntRect(frame->selection()->bounds(false)));
726 #if ENABLE(TIZEN_INPUT_TAG_EXTENSION) || ENABLE(TIZEN_WEBKIT2_FORM_DATABASE)
727 void WebPage::setFocusedInputElementValue(const String& inputValue)
729 Frame* frame = m_page->focusController()->focusedOrMainFrame();
730 if (!frame || !frame->document() || !frame->document()->focusedNode())
733 HTMLInputElement* inputElement = frame->document()->focusedNode()->toInputElement();
737 inputElement->toNode()->dispatchFocusEvent(0);
738 inputElement->setValue(inputValue, DispatchChangeEvent);
741 void WebPage::getFocusedInputElementValue(String& inputValue)
743 inputValue = String();
745 Frame* frame = m_page->focusController()->focusedOrMainFrame();
746 if (!frame || !frame->document() || !frame->document()->focusedNode())
749 HTMLInputElement* inputElement = frame->document()->focusedNode()->toInputElement();
753 inputValue = inputElement->value();
757 #if ENABLE(TIZEN_DATALIST_ELEMENT)
758 void WebPage::getFocusedInputElementDataList(Vector<String>& optionList)
760 Frame* frame = m_page->focusController()->focusedOrMainFrame();
761 if (!frame || !frame->document())
764 Node* node = frame->document()->focusedNode();
768 HTMLInputElement* input = node->toInputElement();
772 HTMLDataListElement* dataList = static_cast<HTMLDataListElement*>(input->list());
776 RefPtr<HTMLCollection> options = static_cast<HTMLDataListElement*>(dataList)->options();
777 for (unsigned i = 0; Node* node = options->item(i); i++) {
778 HTMLOptionElement* optionElement = static_cast<HTMLOptionElement*>(node);
779 String value = optionElement->value();
780 optionList.append(value);
785 #if ENABLE(TIZEN_WEBKIT2_FOCUS_RING)
786 static IntRect getNodeRect(Node* node, Node* focusableNode, bool isImage)
792 IntRect imageNodeRect = pixelSnappedIntRect(node->getRect());
793 if (!focusableNode->renderRect(&isReplaced).isEmpty() && imageNodeRect.contains(pixelSnappedIntRect(focusableNode->getRect()))) {
794 // If render rect of focusableNode is empty and rect of imageNode include rect of focusableNode,
795 // we have to get rect of focusableNode.
796 // for example - The rect of google logo image in www.google.com pc site's search result page is bigger than rect of focusableNode.
797 // for example - The rect of category menu image in www.gmarket.co.kr pc site is bigger than rect of focusableNode.
798 rect = pixelSnappedIntRect(focusableNode->getRect());
801 // otherwise we have to get rect of imageNode.
802 // for example - The render rect of images in www.pudelek.pl is empty.
803 // 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.
804 rect = imageNodeRect;
805 focusableNode = node;
808 // If focusedNode have multiple child nodes, we have to unite rect of child nodes.
809 // for example - links in www.google.com's search result page.
811 for (Node* childNode = focusableNode->firstChild(); childNode; childNode = childNode->traverseNextNode(focusableNode)) {
813 if (focusableNode->renderRect(&isReplaced).contains(childNode->getRect()))
814 tempRect.unite(pixelSnappedIntRect(childNode->getRect()));
817 // If tempRect is empty or rect of focusableNode include tempRect,
818 // we have to get rect of focusableNode.
819 // for example - list menu item in m.naver.com.
820 // otherwise we have to get rect of tempRect.
821 // getRect API do not return correct rect if the node is a container node,
822 // hence using absoluteBoundingBoxRect to get the correct bounding rect.
823 LayoutRect renderRect = focusableNode->renderer() ? focusableNode->renderer()->absoluteBoundingBoxRect() : focusableNode->getRect();
824 if (tempRect.isEmpty() || renderRect.contains(tempRect))
825 rect = pixelSnappedIntRect(renderRect);
830 // We have to get render rect from ancestor node if current rect is empty.
831 // for example - The rect of naver logo image in www.naver.com pc site is empty.
833 for (Node* loopNode = focusableNode; loopNode && rect.isEmpty(); loopNode = loopNode->parentNode()) {
834 RenderObject* renderer = loopNode->renderer();
835 if (renderer && renderer->isRoot())
838 rect = pixelSnappedIntRect(loopNode->renderRect(&isReplaced));
841 Frame* nodeFrame = focusableNode->document()->frame();
843 while (nodeFrame && (owner = nodeFrame->ownerElement())) {
844 rect.moveBy(owner->getRect().pixelSnappedLocation());
845 nodeFrame = owner->document()->frame();
848 // The y position of tab menu item in www.google.com is negative value,
849 // so we do not want to draw focus ring in that case.
850 if ((rect.maxX() < 0) || (rect.maxY() < 0))
857 #if ENABLE(TIZEN_WEBKIT2_HIT_TEST)
858 #if ENABLE(TIZEN_WEBKIT2_FOCUS_RING)
859 static bool isClickableOrFocusable(Node* focusableNode)
864 if (focusableNode->disabled())
866 if (!focusableNode->inDocument())
868 if (!focusableNode->renderer() || focusableNode->renderer()->style()->visibility() != VISIBLE)
870 if (focusableNode->isFocusable()) {
871 if (focusableNode->isLink()
872 || focusableNode->hasTagName(HTMLNames::inputTag)
873 || focusableNode->hasTagName(HTMLNames::selectTag)
874 || focusableNode->hasTagName(HTMLNames::buttonTag))
877 if (focusableNode->supportsFocus()
878 || focusableNode->hasEventListeners(eventNames().clickEvent)
879 || focusableNode->hasEventListeners(eventNames().mousedownEvent)
880 || focusableNode->hasEventListeners(eventNames().mouseupEvent)) {
886 #if ENABLE(TOUCH_ADJUSTMENT)
887 void WebPage::getFocusedRect(HitTestResult hitTestResult, Page* page, bool setFocus, Vector<IntRect>& rects, const IntPoint& point, const IntSize& area)
889 void WebPage::getFocusedRect(HitTestResult hitTestResult, Page* page, bool setFocus, Vector<IntRect>& rects)
892 Node* node = hitTestResult.innerNode();
893 #if ENABLE(TOUCH_ADJUSTMENT)
894 IntPoint adustedPoint;
895 Frame* mainFrame = page->mainFrame();
896 Node* adjustedNode = 0;
897 mainFrame->eventHandler()->bestClickableNodeForTouchPoint(point, IntSize(area.width() / 2, area.height() / 2), adustedPoint, adjustedNode);
898 if (!isClickableOrFocusable(node))
899 mainFrame->eventHandler()->bestClickableNodeForTouchPoint(point, IntSize(area.width() / 2, area.height() / 2), adustedPoint, adjustedNode);
907 bool isFocusRingDrawable = false;
908 Node* focusableNode = node;
909 while (focusableNode) {
910 RenderObject* renderer = focusableNode->renderer();
911 if (renderer && (renderer->isBody() || renderer->isRenderView() || renderer->isRoot()))
914 if (isClickableOrFocusable(focusableNode)) {
915 isFocusRingDrawable = true;
919 focusableNode = focusableNode->parentNode();
922 // Don't draw focus ring if child is focusable or has trigger
923 if (focusableNode && focusableNode->isContainerNode() && !focusableNode->isLink()) {
924 WebCore::Node *child = static_cast<const ContainerNode*>(focusableNode)->firstChild();
926 if( child->supportsFocus()
927 || child->hasEventListeners(eventNames().clickEvent)
928 || child->hasEventListeners(eventNames().mousedownEvent)
929 || child->hasEventListeners(eventNames().mouseupEvent)) {
932 child = child->traverseNextNode(focusableNode);
936 if (!isFocusRingDrawable) {
937 if (!node->hasTagName(HTMLNames::imgTag))
939 focusableNode = node;
943 setFocusedNode(focusableNode);
945 calcFocusedRects(focusableNode, rects);
949 #if ENABLE(TOUCH_ADJUSTMENT)
950 void WebPage::hitTestResultAtPoint(const IntPoint& point, int hitTestMode, const IntSize& area, WebHitTestResult::Data& hitTestResultData)
952 void WebPage::hitTestResultAtPoint(const IntPoint& point, int hitTestMode, WebHitTestResult::Data& hitTestResultData)
955 Frame* frame = m_page->mainFrame();
956 FrameView* frameView = frame->view();
960 HitTestResult hitTestResult = frame->eventHandler()->hitTestResultAtPoint(frameView->windowToContents(point), false);
961 hitTestResultData.absoluteImageURL = hitTestResult.absoluteImageURL().string();
962 hitTestResultData.absoluteLinkURL = hitTestResult.absoluteLinkURL().string();
963 hitTestResultData.absoluteMediaURL = hitTestResult.absoluteMediaURL().string();
964 hitTestResultData.linkLabel = hitTestResult.textContent();
965 hitTestResultData.linkTitle = hitTestResult.titleDisplayString();
966 hitTestResultData.isContentEditable = hitTestResult.isContentEditable();
967 #if ENABLE(TIZEN_DRAG_SUPPORT)
968 hitTestResultData.isDragSupport = hitTestResult.isDragSupport();
971 int context = WebHitTestResult::HitTestResultContextDocument;
973 if (!hitTestResult.absoluteLinkURL().isEmpty())
974 context |= WebHitTestResult::HitTestResultContextLink;
975 if (!hitTestResult.absoluteImageURL().isEmpty())
976 context |= WebHitTestResult::HitTestResultContextImage;
977 if (!hitTestResult.absoluteMediaURL().isEmpty())
978 context |= WebHitTestResult::HitTestResultContextMedia;
979 if (hitTestResult.isSelected())
980 context |= WebHitTestResult::HitTestResultContextSelection;
981 if (hitTestResult.isContentEditable())
982 context |= WebHitTestResult::HitTestResultContextEditable;
983 if (hitTestResult.innerNonSharedNode() && hitTestResult.innerNonSharedNode()->isTextNode())
984 context |= WebHitTestResult::HitTestResultContextText;
986 hitTestResultData.context = context;
987 hitTestResultData.hitTestMode = hitTestMode;
989 #if ENABLE(TIZEN_WEBKIT2_FOCUS_RING)
990 bool setFocus = hitTestResultData.hitTestMode & WebHitTestResult::HitTestModeSetFocus;
991 #if ENABLE(TOUCH_ADJUSTMENT)
992 getFocusedRect(hitTestResult, m_page.get(), setFocus, hitTestResultData.focusedRects, point, area);
994 getFocusedRect(hitTestResult, m_page.get(), setFocus, hitTestResultData.focusedRects);
997 // Don't display FocusRect if the size is too big..
998 IntRect framerect = frameView->visibleContentRect(true);
999 for (size_t i = 0; i < hitTestResultData.focusedRects.size(); ++i) {
1000 if (hitTestResultData.focusedRects[i].width() > (0.8 * framerect.width())
1001 && hitTestResultData.focusedRects[i].height() > (0.8 * framerect.height()))
1002 hitTestResultData.focusedRects.clear();
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);
1036 #if ENABLE(TIZEN_WEBKIT2_TEXT_SELECTION)
1037 hitTestResultData.nodeData.zIndex = 0;
1038 for (Node* node = hitNode; node; node = node->parentNode()) {
1039 RenderStyle* computedStyle = node->computedStyle();
1040 if (computedStyle && !(computedStyle->hasAutoZIndex()) && hitTestResultData.nodeData.zIndex < computedStyle->zIndex())
1041 hitTestResultData.nodeData.zIndex = computedStyle->zIndex();
1047 if ((hitTestResultData.hitTestMode & WebHitTestResult::HitTestModeImageData) && (hitTestResultData.context & WebHitTestResult::HitTestResultContextImage)) {
1048 WebCore::Image* hitImage = hitTestResult.image();
1049 if (hitImage && hitImage->data() && hitImage->data()->data()) {
1050 hitTestResultData.imageData.data.append(hitImage->data()->data(), hitImage->data()->size());
1051 hitTestResultData.imageData.fileNameExtension = hitImage->filenameExtension();
1057 #if ENABLE(TIZEN_WEB_STORAGE)
1058 void WebPage::getStorageQuotaBytes(uint64_t callbackID)
1060 uint32_t quota = m_page->group().groupSettings()->localStorageQuotaBytes();
1061 send(Messages::WebPageProxy::DidGetWebStorageQuotaBytes(quota, callbackID));
1064 void WebPage::setStorageQuotaBytes(uint32_t quota)
1066 m_page->group().groupSettings()->setLocalStorageQuotaBytes(quota);
1070 #if ENABLE(TIZEN_CLIPBOARD) || ENABLE(TIZEN_PASTEBOARD)
1071 void WebPage::setClipboardDataForPaste(const String& data, const String& type)
1073 #if ENABLE(TIZEN_PASTEBOARD)
1074 // FIXME: Should move to EditorClient like Clipboard
1075 Pasteboard::generalPasteboard()->setDataWithType(data, type);
1077 Frame* mainFrame = m_page->mainFrame();
1081 mainFrame->editor()->client()->setClipboardDataForPaste(data, type);
1086 void WebPage::suspendJavaScriptAndResources()
1088 Frame* mainFrame = m_page->mainFrame();
1092 for (Frame* frame = mainFrame; frame; frame = frame->tree()->traverseNext())
1093 frame->document()->suspendScheduledTasks(WebCore::ActiveDOMObject::PageWillBeSuspended);
1094 mainFrame->loader()->suspendAllLoaders();
1097 void WebPage::resumeJavaScriptAndResources()
1099 Frame* mainFrame = m_page->mainFrame();
1103 for (Frame* frame = mainFrame; frame; frame = frame->tree()->traverseNext())
1104 frame->document()->resumeScheduledTasks();
1105 mainFrame->loader()->resumeAllLoaders();
1108 void WebPage::suspendAnimations()
1110 Frame* mainFrame = m_page->mainFrame();
1114 for (Frame* frame = mainFrame; frame; frame = frame->tree()->traverseNext())
1115 frame->animation()->suspendAnimationsForDocument(frame->document());
1118 void WebPage::resumeAnimations()
1120 Frame* mainFrame = m_page->mainFrame();
1124 for (Frame* frame = mainFrame; frame; frame = frame->tree()->traverseNext())
1125 frame->animation()->resumeAnimationsForDocument(frame->document());
1128 #if ENABLE(TIZEN_SYNC_REQUEST_ANIMATION_FRAME)
1129 void WebPage::suspendAnimationController()
1131 if (!m_suspendedAnimationController) {
1132 Frame* mainFrame = m_page->mainFrame();
1136 for (Frame* frame = mainFrame; frame; frame = frame->tree()->traverseNext())
1137 frame->document()->suspendScriptedAnimationControllerCallbacks();
1139 m_suspendedAnimationController = true;
1143 void WebPage::resumeAnimationController()
1145 if (m_suspendedAnimationController) {
1146 Frame* mainFrame = m_page->mainFrame();
1150 for (Frame* frame = mainFrame; frame; frame = frame->tree()->traverseNext())
1151 frame->document()->resumeScriptedAnimationControllerCallbacks();
1153 m_suspendedAnimationController = false;
1158 #if ENABLE(TIZEN_REMOTE_WEB_INSPECTOR)
1159 void WebPage::startInspectorServer(uint32_t port, uint32_t& allocatedPort)
1161 bool ret = WebInspectorServerTizen::server()->startServer(port);
1163 allocatedPort = WebInspectorServerTizen::server()->getServerPort();
1168 void WebPage::stopInspectorServer(bool& result)
1170 result = WebInspectorServerTizen::server()->stopServer();
1174 #if ENABLE(TIZEN_CSS_OVERFLOW_SCROLL_ACCELERATION_ON_UI_SIDE)
1175 void WebPage::scrollOverflowWithTrajectoryVector(const WebCore::FloatPoint& trajectoryVector)
1177 Frame* frame = m_page->focusController()->focusedOrMainFrame();
1180 frame->eventHandler()->scrollOverflow(trajectoryVector);
1184 #if ENABLE(TIZEN_CSS_OVERFLOW_SCROLL_ACCELERATION)
1185 void WebPage::scrollOverflow(const WebCore::FloatPoint& delta, bool& scrolled)
1187 scrolled = m_page->focusController()->focusedOrMainFrame()->eventHandler()->scrollOverflow(delta);
1190 void WebPage::setPressedNodeAtPoint(const IntPoint& point, bool checkOverflowLayer, bool& pressed, uint32_t& id)
1192 RenderObject* renderer = 0;
1194 pressed = m_page->mainFrame()->eventHandler()->setMousePressNodeAtPoint(point, checkOverflowLayer, renderer);
1195 #if ENABLE(TIZEN_CSS_OVERFLOW_SCROLL_ACCELERATION_ON_UI_SIDE)
1196 if (pressed && renderer)
1197 id = toWebGraphicsLayer(renderer->enclosingLayer()->layerForScrollingContents())->id();
1202 void WebPage::executeEditCommandWithArgument(const String& commandName, const String& argument)
1204 executeEditingCommand(commandName, argument);
1207 #if ENABLE(TIZEN_PLUGIN_SUSPEND_RESUME)
1208 void WebPage::suspendPlugin()
1210 for (Frame* frame = m_page->mainFrame(); frame; frame = frame->tree()->traverseNext()) {
1211 FrameView* view = frame->view();
1215 const HashSet<RefPtr<Widget> >* children = view->children();
1218 HashSet<RefPtr<Widget> >::const_iterator end = children->end();
1219 for (HashSet<RefPtr<Widget> >::const_iterator it = children->begin(); it != end; ++it) {
1220 Widget* widget = (*it).get();
1221 if (widget->isPluginViewBase()) {
1222 PluginView* pluginView = static_cast<PluginView*>(widget);
1224 pluginView->suspendPlugin();
1230 void WebPage::resumePlugin()
1232 for (Frame* frame = m_page->mainFrame(); frame; frame = frame->tree()->traverseNext()) {
1233 FrameView* view = frame->view();
1237 const HashSet<RefPtr<Widget> >* children = view->children();
1240 HashSet<RefPtr<Widget> >::const_iterator end = children->end();
1241 for (HashSet<RefPtr<Widget> >::const_iterator it = children->begin(); it != end; ++it) {
1242 Widget* widget = (*it).get();
1243 if (widget->isPluginViewBase()) {
1244 PluginView* pluginView = static_cast<PluginView*>(widget);
1246 pluginView->resumePlugin();
1253 #if ENABLE(TIZEN_MULTIPLE_SELECT)
1254 void WebPage::didChangeSelectedIndexForActivePopupMenuMultiple(Vector<int32_t> newIndex)
1256 if (!m_activePopupMenu)
1259 m_activePopupMenu->client()->popupDidHide();
1261 size_t indexSize = newIndex.size();
1262 for (size_t i = 0; i < indexSize; i++)
1263 m_activePopupMenu->didChangeSelectedIndex(newIndex.at(i));
1268 #if ENABLE(TIZEN_OFFLINE_PAGE_SAVE)
1269 void WebPage::startOfflinePageSave(String subresourceFolderName)
1271 WebPageSerializerTizen::getSerializedPageContent(this, subresourceFolderName);
1275 #if ENABLE(TIZEN_WEBKIT2_TEXT_SELECTION)
1276 void WebPage::selectClosestWord(const IntPoint& point, bool isAutoWordSelection, bool& result)
1280 Frame* mainFrame = m_page->mainFrame();
1281 Frame* focusedFrame = m_page->focusController()->focusedOrMainFrame();
1283 HitTestResult hitTestResult = mainFrame->eventHandler()->hitTestResultAtPoint(m_page->mainFrame()->view()->windowToContents(point), false);
1285 Node* node = hitTestResult.innerNonSharedNode();
1289 if (node->renderer() && node->renderer()->style() && (node->renderer()->style()->userSelect() == SELECT_NONE))
1292 Frame* newFocusFrame = node->document()->frame();
1293 if (focusedFrame != newFocusFrame) {
1294 m_page->focusController()->setFocusedFrame(newFocusFrame);
1295 focusedFrame = newFocusFrame;
1298 HTMLInputElement* inputElement = node->toInputElement();
1300 if (hitTestResult.isContentEditable()) {
1301 #if ENABLE(TIZEN_INPUT_TAG_EXTENSION)
1302 if (!inputElement || (inputElement
1303 && !inputElement->isDateField() && !inputElement->isDateTimeField() && !inputElement->isDateTimeLocalField()
1304 && !inputElement->isMonthField() && !inputElement->isTimeField() && !inputElement->isWeekField())) {
1305 result = setCaretPosition(point);
1306 if (!isAutoWordSelection)
1310 result = setCaretPosition(point);
1311 if (!isAutoWordSelection)
1316 #if ENABLE(TIZEN_INPUT_TAG_EXTENSION)
1317 if (!node->isTextNode() && !inputElement)
1319 if (!node->isTextNode())
1323 #if ENABLE(TIZEN_INPUT_TAG_EXTENSION)
1325 && (inputElement->isDateField() || inputElement->isDateTimeField() || inputElement->isDateTimeLocalField()
1326 || inputElement->isMonthField() || inputElement->isTimeField() || inputElement->isWeekField())) {
1327 if (inputElement->value().isEmpty())
1332 for (Node* node = hitTestResult.innerNonSharedNode(); node; node = node->parentNode()) {
1333 if (node->isFocusable()) {
1334 // Text selection shoud not be started when text of <button> tag is selected.
1335 if (node->hasTagName(HTMLNames::buttonTag))
1338 if (inputElement && (inputElement->isTextButton() || inputElement->isCheckbox()))
1345 FrameSelection* frameSelection = focusedFrame->selection();
1347 VisiblePosition position = mainFrame->visiblePositionForPoint(point);
1348 VisibleSelection selection(position);
1350 // This changes just the 'start' and 'end' positions of the VisibleSelection
1351 selection.expandUsingGranularity(WordGranularity);
1353 FrameSelection::SetSelectionOptions options = FrameSelection::CloseTyping | FrameSelection::ClearTypingStyle | FrameSelection::DoNotSetFocus;
1354 frameSelection->setSelection(VisibleSelection(selection.start(), selection.end()), options);
1356 if (!frameSelection->isRange())
1359 // This changes just the 'start' and 'end' positions of the VisibleSelection
1360 // Find handlers positions
1361 IntRect leftRect, rightRect, updatedEditorRect;
1362 int selectionDirection = 0;
1363 getSelectionHandlers(leftRect, rightRect, selectionDirection, updatedEditorRect);
1364 if (leftRect.size().isZero() && rightRect.size().isZero()) {
1365 // Sometimes there is no selected text, but isNone() returns TRUE
1366 // in this case ewk_frame_selection_handlers_get() returns FALSE and handlers are invalid
1367 // Workaround - clear the selection.
1368 // Better solution would be to modify the ewk_frame_select_closest_word()
1369 // to not select anything in the first place (for example - don't call setSelection()
1370 // if there is nothing under the cursor).
1371 selectionClearAllSelection(m_page->mainFrame());
1378 void WebPage::setLeftSelection(const IntPoint& point, const int direction, int& result)
1380 result = HandleMovingDirectionNone;
1382 Frame* focusedFrame = m_page->focusController()->focusedOrMainFrame();
1383 FrameSelection* frameSelection = focusedFrame->selection();
1384 if (!frameSelection->isRange())
1387 Node* selectionEndNode = frameSelection->end().deprecatedNode();
1388 if (!selectionEndNode || !selectionEndNode->renderer())
1391 FrameView* frameView = focusedFrame->view();
1395 IntPoint pos = frameView->windowToContents(point);
1396 IntRect leftRect, rightRect, updatedEditorRect;
1397 int selectionDirection = 0;
1398 getSelectionHandlers(leftRect, rightRect, selectionDirection, updatedEditorRect);
1400 if (selectionEndNode->rendererIsEditable() && !selectionEndNode->rendererIsRichlyEditable()) {
1401 const int boundariesWidth = 2;
1403 IntRect rect = frameSelection->caretRenderer()->absoluteBoundingBoxRect(true);
1404 // here we cheat input field that we actually are just inside of if
1405 if (pos.y() < rect.y() + boundariesWidth)
1406 pos.setY(rect.y() + boundariesWidth);
1407 else if (pos.y() >= rect.maxY() - boundariesWidth)
1408 pos.setY(rect.maxY() - boundariesWidth - 1);
1411 OwnPtr<VisiblePosition> position = adoptPtr(new VisiblePosition(focusedFrame->visiblePositionForPoint(pos)));
1412 Position base = frameSelection->base();
1413 Position extent = frameSelection->extent();
1415 Node* newSelectionStartNode = position->deepEquivalent().deprecatedNode();
1417 // both start and end nodes should be in the same area type: both should be editable or both should be not editable
1418 // Check if the new position is before the extent's position
1419 if (newSelectionStartNode
1420 && selectionEndNode->isContentEditable() == newSelectionStartNode->isContentEditable()) {
1421 // Change the 'base' and 'extent' positions to 'start' and 'end' positions.
1422 // We do it, because without this, the other modification of the selection
1423 // would destroy the 'start' and/or 'end' positions and set them to
1424 // the 'base'/'extent' positions accordingly
1425 VisibleSelection sel(frameSelection->start(), frameSelection->end());
1426 frameSelection->setSelection(sel);
1428 bool oldProhibitsScrolling = focusedFrame->view()->prohibitsScrolling();
1429 focusedFrame->view()->setProhibitsScrolling(true);
1431 if (direction == HandleMovingDirectionNormal) {
1432 if (comparePositions(position->deepEquivalent(), extent) < 0) {
1433 frameSelection->setBase(*position);
1434 result = HandleMovingDirectionNormal;
1435 } else if (comparePositions(position->deepEquivalent(), extent) > 0) {
1436 frameSelection->setExtent(*position);
1437 frameSelection->setBase(extent);
1438 result = HandleMovingDirectionReverse;
1440 } else if (direction == HandleMovingDirectionReverse) {
1441 if (comparePositions(position->deepEquivalent(), base) > 0) {
1442 frameSelection->setExtent(*position);
1443 result = HandleMovingDirectionReverse;
1444 } else if (comparePositions(position->deepEquivalent(), base) < 0) {
1445 frameSelection->setBase(*position);
1446 frameSelection->setExtent(base);
1447 result = HandleMovingDirectionNormal;
1451 focusedFrame->view()->setProhibitsScrolling(oldProhibitsScrolling);
1452 // This forces webkit to show selection
1453 // m_coreFrame->invalidateSelection();
1457 void WebPage::setRightSelection(const IntPoint& point, const int direction, int& result)
1459 result = HandleMovingDirectionNone;
1461 Frame* focusedFrame = m_page->focusController()->focusedOrMainFrame();
1462 FrameSelection* frameSelection = focusedFrame->selection();
1464 if (!frameSelection->isRange())
1467 Node* selectionStartNode = frameSelection->start().deprecatedNode();
1468 if (!selectionStartNode || !selectionStartNode->renderer())
1471 FrameView* frameView = focusedFrame->view();
1475 IntPoint pos = frameView->windowToContents(point);
1476 if (selectionStartNode->rendererIsEditable() && !selectionStartNode->rendererIsRichlyEditable()) {
1477 const int boundariesWidth = 2;
1479 IntRect rect = frameSelection->caretRenderer()->absoluteBoundingBoxRect(true);
1480 // here we cheat input field that we actually are just inside of if
1481 if (pos.y() < rect.y() + boundariesWidth)
1482 pos.setY(rect.y() + boundariesWidth);
1483 else if (pos.y() >= rect.maxY() - boundariesWidth)
1484 pos.setY(rect.maxY() - boundariesWidth - 1);
1487 OwnPtr<VisiblePosition> position = adoptPtr(new VisiblePosition(focusedFrame->visiblePositionForPoint(pos)));
1488 Position base = frameSelection->base();
1489 Position extent = frameSelection->extent();
1491 Node* newSelectionEndNode = position->deepEquivalent().deprecatedNode();
1493 // both start and end nodes should be in the same area type: both should be editable or both should be not editable
1494 // Check if the new position is after the base's position
1495 if (newSelectionEndNode
1496 && selectionStartNode->isContentEditable() == newSelectionEndNode->isContentEditable()) {
1497 // Change the 'base' and 'extent' positions to 'start' and 'end' positions.
1498 // We do it, because without this, the other modifications of the selection
1499 // would destroy the 'start' and/or 'end' positions and set them to
1500 // the 'base'/'extent' positions accordingly
1502 VisibleSelection sel(frameSelection->start(), frameSelection->end());
1503 frameSelection->setSelection(sel);
1505 bool oldProhibitsScrolling = focusedFrame->view()->prohibitsScrolling();
1506 focusedFrame->view()->setProhibitsScrolling(true);
1508 if (direction == HandleMovingDirectionNormal) {
1509 if (comparePositions(position->deepEquivalent(), base) > 0) {
1510 frameSelection->setExtent(*position);
1511 result = HandleMovingDirectionNormal;
1512 } else if (comparePositions(position->deepEquivalent(), base) < 0) {
1513 frameSelection->setBase(*position);
1514 frameSelection->setExtent(base);
1515 result = HandleMovingDirectionReverse;
1517 } else if (direction == HandleMovingDirectionReverse) {
1518 if (comparePositions(position->deepEquivalent(), extent) < 0) {
1519 frameSelection->setBase(*position);
1520 result = HandleMovingDirectionReverse;
1521 } else if (comparePositions(position->deepEquivalent(), extent) > 0) {
1522 frameSelection->setExtent(*position);
1523 frameSelection->setBase(extent);
1524 result = HandleMovingDirectionNormal;
1528 focusedFrame->view()->setProhibitsScrolling(oldProhibitsScrolling);
1532 bool WebPage::isSelectionOnlyImage() const
1534 bool isImage = false;
1535 Frame* focusedFrame = m_page->focusController()->focusedOrMainFrame();
1536 if (!focusedFrame->selection()->isRange())
1539 RefPtr<Range> selectedRange = focusedFrame->selection()->toNormalizedRange();
1540 Vector<IntRect> rects;
1541 selectedRange->boundingBoxEx(rects, true);
1542 unsigned size = rects.size();
1544 Node* startNode = selectedRange->startContainer();
1545 Node* endNode = selectedRange->endContainer();
1546 if(startNode == endNode) {
1547 if(endNode && endNode->isContainerNode() && !(endNode->hasTagName(HTMLNames::imgTag))) {
1548 WebCore::Node *child = static_cast<const ContainerNode*>(endNode)->firstChild();
1550 if(child->hasTagName(HTMLNames::imgTag)) {
1554 child = child->traverseNextNode(endNode);
1558 if(endNode->hasTagName(HTMLNames::imgTag))
1566 void WebPage::getSelectionHandlers(IntRect& leftRect, IntRect& rightRect, int& selectionDirection, WebCore::IntRect& updatedEditorRect)
1568 Frame* focusedFrame = m_page->focusController()->focusedOrMainFrame();
1569 updatedEditorRect = m_editorState.editorRect;
1570 if (!focusedFrame->selection()->isRange())
1573 // Is this check necessary? Leaving it for safety.
1574 RenderView* root = focusedFrame->contentRenderer();
1578 RefPtr<Range> selectedRange = focusedFrame->selection()->toNormalizedRange();
1580 Vector<IntRect> rects;
1581 selectedRange->boundingBoxEx(rects, true);
1583 unsigned size = rects.size();
1585 leftRect = rects[0];
1586 rightRect = rects[size-1];
1588 // If selection rect size is greater than editor rect size because of round operation,
1589 // selection rect size should be changed to editor rect size.
1591 Element* rootEditableElement = focusedFrame->selection()->rootEditableElement();
1592 if (rootEditableElement) {
1593 Vector<IntRect> rects;
1594 calcFocusedRects(rootEditableElement, rects);
1595 IntRect editorRect = unionRect(rects);
1597 if (m_editorState.editorRect != editorRect)
1598 updatedEditorRect = editorRect;
1599 if (leftRect.maxY() > editorRect.maxY()) {
1600 leftRect.setY(editorRect.y());
1601 leftRect.setHeight(editorRect.height());
1604 if (rightRect.maxY() > editorRect.maxY()) {
1605 rightRect.setY(editorRect.y());
1606 rightRect.setHeight(editorRect.height());
1610 // prevent from selecting zero-length selection
1611 if (leftRect.x() == rightRect.x() + rightRect.width()
1612 && leftRect.y() == rightRect.y())
1615 FrameView* frameView = focusedFrame->view();
1619 leftRect = frameView->contentsToWindow(leftRect);
1620 rightRect = frameView->contentsToWindow(rightRect);
1621 selectionDirection = focusedFrame->selection()->getSelectionTextDirection();
1625 void WebPage::getSelectionText(String& result)
1627 Frame* focusedFrame = m_page->focusController()->focusedOrMainFrame();
1628 result = focusedFrame->editor()->selectedText();
1631 void WebPage::selectionRangeClear(bool& result)
1635 Frame* focusedFrame = m_page->focusController()->focusedOrMainFrame();
1636 FrameSelection* frameSelection = focusedFrame->selection();
1637 if (frameSelection && frameSelection->isRange() && frameSelection->isContentEditable()) {
1638 VisiblePosition visiblePos(frameSelection->extent());
1639 if (visiblePos.isNull())
1642 focusedFrame->editor()->setIgnoreCompositionSelectionChange(true);
1643 frameSelection->setSelection(VisibleSelection(visiblePos), CharacterGranularity);
1644 focusedFrame->editor()->setIgnoreCompositionSelectionChange(false);
1646 frameSelection->setCaretBlinkingSuspended(false);
1648 selectionClearAllSelection(m_page->mainFrame());
1653 void WebPage::selectionClearAllSelection(Frame* frame)
1658 FrameSelection* frameSelection = frame->selection();
1660 frameSelection->clear();
1665 if (frame->tree()->childCount() > 0) {
1666 if (frame->tree()->firstChild())
1667 selectionClearAllSelection(frame->tree()->firstChild());
1668 } else if (frame->tree()->nextSibling())
1669 selectionClearAllSelection(frame->tree()->nextSibling());
1672 void WebPage::scrollContentByCharacter(const IntPoint&, int direction, bool& result)
1676 Frame* focusedFrame = m_page->focusController()->focusedOrMainFrame();
1680 FrameSelection* frameSelection = focusedFrame->selection();
1681 if (!frameSelection)
1684 VisiblePosition currentPosition = frameSelection->selection().visibleStart();
1686 if (isStartOfLine(currentPosition))
1689 focusedFrame->selection()->modify(FrameSelection::AlterationMove, DirectionBackward, CharacterGranularity, UserTriggered);
1691 if (isEndOfLine(currentPosition))
1694 focusedFrame->selection()->modify(FrameSelection::AlterationMove, DirectionForward, CharacterGranularity, UserTriggered);
1698 void WebPage::scrollContentByLine(const IntPoint&, int direction, bool& result)
1702 Frame* focusedFrame = m_page->focusController()->focusedOrMainFrame();
1706 FrameSelection* frameSelection = focusedFrame->selection();
1707 if (!frameSelection)
1710 VisiblePosition currentPosition = frameSelection->selection().visibleStart();
1712 if (inSameLine(currentPosition, previousLinePosition(currentPosition, 0)))
1715 focusedFrame->selection()->modify(FrameSelection::AlterationMove, DirectionBackward, LineGranularity, UserTriggered);
1717 if (inSameLine(currentPosition, nextLinePosition(currentPosition, 0)))
1720 focusedFrame->selection()->modify(FrameSelection::AlterationMove, DirectionForward, LineGranularity, UserTriggered);
1724 void WebPage::getFocusedSubFrameRect(IntRect& focusedFrameRect, bool& isFocusedSubFrame)
1726 isFocusedSubFrame = false;
1728 Frame* focusedFrame = m_page->focusController()->focusedOrMainFrame();
1732 if (focusedFrame != m_page->mainFrame()) {
1733 FrameView* frameView = focusedFrame->view();
1734 HTMLFrameOwnerElement* ownerElement = focusedFrame->ownerElement();
1739 if (ownerElement && ownerElement->hasTagName(HTMLNames::iframeTag)){
1740 RenderIFrame* renderIframe = static_cast<RenderIFrame*>(ownerElement->renderer());
1742 focusedFrameRect = renderIframe->windowClipRect();
1743 isFocusedSubFrame = true;
1750 #if ENABLE(TIZEN_LINK_MAGNIFIER)
1751 void WebPage::getLinkMagnifierRect(const IntPoint& position, const IntSize& size)
1753 send(Messages::WebPageProxy::DidGetLinkMagnifierRect(position, LinkMagnifier::rect(this, position, size)));
1757 #if ENABLE(TIZEN_SCREEN_READER)
1758 void WebPage::moveScreenReaderFocus(bool forward, bool& result)
1760 if (!m_screenReader)
1761 m_screenReader = ScreenReader::create(this);
1763 result = m_screenReader->moveFocus(forward);
1766 void WebPage::moveScreenReaderFocusByPoint(const IntPoint& point)
1768 if (!m_screenReader)
1769 m_screenReader = ScreenReader::create(this);
1771 if (!m_screenReader->moveFocus(point))
1775 void WebPage::clearScreenReaderFocus()
1777 if (!m_screenReader)
1780 m_screenReader->clearFocus();
1783 void WebPage::raiseTapEvent(const IntPoint& position, const IntPoint& globalPosition, bool& result)
1787 #if ENABLE(GESTURE_EVENTS)
1788 Frame* frame = m_page->mainFrame();
1792 Vector<WebPlatformTouchPoint> touchPoints;
1793 touchPoints.append(WebPlatformTouchPoint(0, WebPlatformTouchPoint::TouchPressed, globalPosition, position));
1795 WebTouchEvent touchStartEvent(WebEvent::TouchStart, touchPoints, WebEvent::Modifiers(0), ecore_time_get());
1796 bool handled = frame->eventHandler()->handleTouchEvent(platform(touchStartEvent));
1798 touchPoints.at(0).setState(WebPlatformTouchPoint::TouchReleased);
1800 WebTouchEvent touchEndEvent(WebEvent::TouchEnd, touchPoints, WebEvent::Modifiers(0), ecore_time_get());
1801 handled |= frame->eventHandler()->handleTouchEvent(platform(touchEndEvent));
1804 WebGestureEvent gestureEvent(WebEvent::GestureSingleTap, position, globalPosition, WebEvent::Modifiers(0), ecore_time_get());
1805 frame->eventHandler()->handleGestureEvent(platform(gestureEvent));
1811 void WebPage::adjustScreenReaderFocusedObjectValue(bool up)
1813 if (!m_screenReader || !m_focusedNode || !m_focusedNode->toInputElement())
1818 m_focusedNode->toInputElement()->stepUp(ec);
1820 m_focusedNode->toInputElement()->stepDown(ec);
1823 void WebPage::updateScreenReaderFocus(RenderObject* object)
1825 if (!m_screenReader)
1829 m_screenReader->clearFocus();
1830 else if (!m_screenReader->rendererWillBeDestroyed(object))
1834 void WebPage::clearScreenReader()
1836 m_screenReader.clear();
1840 #if ENABLE(TIZEN_WEBKIT2_FOCUS_RING) || ENABLE(TIZEN_WEBKIT2_TEXT_SELECTION)
1841 static LayoutRect rectToAbsoluteCoordinates(Frame* initialFrame, const LayoutRect& initialRect)
1843 LayoutRect rect = initialRect;
1844 for (Frame* frame = initialFrame; frame; frame = frame->tree()->parent()) {
1845 RenderBoxModelObject* renderer;
1846 if (frame->ownerElement() && (renderer = frame->ownerElement()->renderBoxModelObject())) {
1848 rect.move(renderer->offsetLeft(), renderer->offsetTop());
1849 } while ((renderer = renderer->offsetParent()));
1850 rect.move(-frame->view()->scrollOffset());
1856 void WebPage::calcFocusedRects(Node* node, Vector<IntRect>& rects) const
1858 if (!node || !node->renderer())
1861 RenderObject* renderer = node->renderer();
1862 FrameView* view = node->document()->frame()->view();
1865 if (node->hasTagName(HTMLNames::areaTag)) {
1866 HTMLAreaElement* area = static_cast<HTMLAreaElement*>(node);
1867 HTMLImageElement* image = area->imageElement();
1868 if (image && image->renderer())
1869 rect = rectToAbsoluteCoordinates(area->document()->frame(), area->computeRect(area->imageElement()->renderer()));
1870 } else if (node->renderer()) {
1871 if (node->isDocumentNode())
1872 rect = rectToAbsoluteCoordinates(static_cast<Document*>(node)->frame(), static_cast<Document*>(node)->frame()->view()->visibleContentRect());
1874 rect = rectToAbsoluteCoordinates(node->document()->frame(), node->renderer()->absoluteClippedOverflowRect());
1877 if (rect.pixelSnappedX() < 0)
1878 rect.shiftXEdgeTo(0);
1879 if (rect.pixelSnappedY() < 0)
1880 rect.shiftYEdgeTo(0);
1885 IntRect focusedNodeRect(pixelSnappedIntRect(rect));
1886 IntPoint absolutePoint;
1887 absolutePoint = view->convertToContainingWindow(view->convertFromRenderer(renderer, absolutePoint));
1888 Vector<IntRect> candidateRects;
1889 renderer->addFocusRingRects(candidateRects, absolutePoint);
1891 for (size_t i = 0; i < candidateRects.size(); ++i) {
1892 IntRect candidate(candidateRects[i]);
1893 candidate.intersect(focusedNodeRect);
1894 if (!candidate.isEmpty())
1895 rects.append(candidate);
1898 if (rects.isEmpty())
1899 rects.append(focusedNodeRect);
1903 #if ENABLE(TIZEN_WEBKIT2_FOCUS_RING)
1904 void WebPage::setFocusedNode(Node* node)
1906 m_focusedNode = node;
1907 didChangeFocusedRects();
1910 void WebPage::didChangeFocusedRects()
1912 Vector<IntRect> rects;
1913 calcFocusedRects(m_focusedNode.get(), rects);
1914 m_focusedRects = rects;
1915 send(Messages::WebPageProxy::DidChangeFocusedRects(m_focusedRects));
1918 void WebPage::recalcFocusedRects()
1923 didChangeFocusedRects();
1927 #if ENABLE(TIZEN_WEBKIT2_POPUP_INTERNAL)
1928 // FIXME: Currently with cached pages, hiding Popup list menu is not working correctly.
1929 // This patch is a fix allowing any popup list menu to get close for any page navigation.
1930 void WebPage::notifyTransitionToCommitted(bool forNewPage)
1932 if (m_activePopupMenu) {
1934 m_activePopupMenu->hide();
1935 m_activePopupMenu = 0;
1940 #if ENABLE(TIZEN_CSP)
1941 void WebPage::setContentSecurityPolicy(const String& policy, uint32_t headerType)
1943 Frame* frame = m_page->focusController()->focusedOrMainFrame();
1947 Document* document = frame->document();
1951 document->contentSecurityPolicy()->didReceiveHeader(policy, static_cast<WebCore::ContentSecurityPolicy::HeaderType>(headerType));
1955 #if ENABLE(TIZEN_INDEXED_DATABASE)
1956 void WebPage::setIndexedDatabaseDirectory(const String& path)
1958 m_page->group().groupSettings()->setIndexedDBDatabasePath(path);
1962 #if ENABLE(TIZEN_WEB_STORAGE)
1963 void WebPage::setLocalStorageDirectory(const String& path)
1965 m_page->settings()->setLocalStorageDatabasePath(path);
1969 #if ENABLE(TIZEN_USE_SETTINGS_FONT)
1970 void WebPage::useSettingsFont()
1972 if (!WebCore::fontCache()->isFontFamliyTizen())
1975 FcInitReinitialize();
1976 WebCore::fontCache()->invalidate();
1978 int pageCapacity = WebCore::pageCache()->capacity();
1979 // Setting size to 0, makes all pages be released.
1980 WebCore::pageCache()->setCapacity(0);
1981 WebCore::pageCache()->releaseAutoreleasedPagesNow();
1982 WebCore::pageCache()->setCapacity(pageCapacity);
1984 Frame* frame = m_mainFrame->coreFrame();
1988 if (frame->document())
1989 frame->document()->dispatchWindowEvent(Event::create(eventNames().resizeEvent, false, false));
1991 FrameView* frameView = frame->view();
1995 frameView->forceLayout();
1999 void WebPage::didChangeContents()
2004 Frame* frame = m_page->focusController()->focusedOrMainFrame();
2005 if (!frame || !frame->view() || frame->view()->needsLayout())
2008 #if ENABLE(TIZEN_ISF_PORT) || ENABLE(TIZEN_WEBKIT2_TEXT_SELECTION)
2009 if (m_editorState.isContentEditable && frame->selection()->rootEditableElement() && updateEditorStateRect(frame, m_editorState)) {
2010 m_editorState.updateEditorRectOnly = true;
2011 send(Messages::WebPageProxy::EditorStateChanged(m_editorState));
2015 #if ENABLE(TIZEN_WEBKIT2_FOCUS_RING)
2016 didChangeFocusedRects();
2020 #if ENABLE(TIZEN_FOCUS_UI)
2021 void WebPage::setFocusUIEnabled(bool enabled)
2023 m_page->settings()->setSpatialNavigationEnabled(enabled);
2025 if (m_focusedNode && m_focusedNode->renderer())
2026 m_focusedNode->renderer()->repaint();
2029 Frame* frame = m_page->focusController()->focusedOrMainFrame();
2031 PlatformMouseEvent fakeMouseMove(IntPoint(-1, -1), IntPoint(-1, -1), NoButton, PlatformEvent::MouseMoved, 0, false, false, false, false, currentTime());
2032 frame->eventHandler()->mouseMoved(fakeMouseMove);
2034 setFocusedNode(frame && frame->document() ? frame->document()->focusedNode() : 0);
2039 #endif // #if OS(TIZEN)
2041 } // namespace WebKit