Implement that a text selection handle can be moved over another text selection handle.
[framework/web/webkit-efl.git] / Source / WebKit2 / WebProcess / WebPage / efl / WebPageEfl.cpp
1 /*
2  * Copyright (C) 2010 Apple Inc. All rights reserved.
3  * Portions Copyright (c) 2010 Motorola Mobility, Inc.  All rights reserved.
4  * Copyright (C) 2011 Igalia S.L.
5  *
6  * Redistribution and use in source and binary forms, with or without
7  * modification, are permitted provided that the following conditions
8  * are met:
9  * 1. Redistributions of source code must retain the above copyright
10  *    notice, this list of conditions and the following disclaimer.
11  * 2. Redistributions in binary form must reproduce the above copyright
12  *    notice, this list of conditions and the following disclaimer in the
13  *    documentation and/or other materials provided with the distribution.
14  *
15  * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
16  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
17  * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
18  * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
19  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
20  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
21  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
22  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
23  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
24  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
25  * THE POSSIBILITY OF SUCH DAMAGE.
26  */
27
28 #include "config.h"
29 #include "WebPage.h"
30
31 #include "EditorState.h"
32 #include "NamedNodeMap.h"
33 #include "NotImplemented.h"
34 #include "WebEvent.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>
45
46 #if OS(TIZEN)
47 #include "Arguments.h"
48 #include "GraphicsContext.h"
49 #include "WebCoreArgumentCoders.h"
50 #include "WebFrame.h"
51 #include "WebImage.h"
52 #include "WebPageProxyMessages.h"
53 #include <WebCore/FrameView.h>
54
55 #if ENABLE(TIZEN_INPUT_TAG_EXTENSION)
56 #include <WebCore/HTMLInputElement.h>
57 #include <WebCore/HTMLNames.h>
58 #endif
59
60 #if ENABLE(TIZEN_MULTIPLE_SELECT)
61 #include "WebPopupMenu.h"
62 #include <WebCore/PopupMenuClient.h>
63 #endif
64
65 #if ENABLE(TIZEN_MOBILE_WEB_PRINT)
66 #include <WebCore/PlatformContextCairo.h>
67 #endif
68
69 #if ENABLE(TIZEN_CLIPBOARD) || ENABLE(TIZEN_PASTEBOARD)
70 #include <WebCore/ClipboardTizen.h>
71 #endif
72
73 #if ENABLE(TIZEN_PASTEBOARD)
74 #include <WebCore/Pasteboard.h>
75 #endif
76
77 #if ENABLE(TIZEN_REMOTE_WEB_INSPECTOR)
78 #include "WebInspectorServerTizen.h"
79 #endif
80
81 #if ENABLE(TIZEN_WEB_STORAGE)
82 #include <WebCore/GroupSettings.h>
83 #include <WebCore/PageGroup.h>
84 #endif
85
86 #if ENABLE(TIZEN_PLUGIN_SUSPEND_RESUME)
87 #include "PluginView.h"
88 #endif
89
90 #if ENABLE(TIZEN_PREFERENCE)
91 #include "WebPreferencesStore.h"
92 #include <WebCore/Settings.h>
93 #endif
94
95 #if ENABLE(TIZEN_WEBKIT2_FOCUS_RING)
96 #include <WebCore/HTMLFrameOwnerElement.h>
97 #include <WebCore/HTMLImageElement.h>
98 #endif
99
100 #if ENABLE(TIZEN_DEVICE_ORIENTATION)
101 #include "DeviceMotionClientTizen.h"
102 #include "DeviceOrientationClientTizen.h"
103 #endif
104
105 #if ENABLE(TIZEN_CSS_OVERFLOW_SCROLL_ACCELERATION_ON_UI_SIDE)
106 #include "RenderLayer.h"
107 #include "WebGraphicsLayer.h"
108 #include <WebCore/RenderView.h>
109 #endif
110
111 #if ENABLE(TIZEN_ISF_PORT)
112 #include <WebCore/Text.h>
113 #include <WebCore/EditorClient.h>
114 #endif
115
116 #if ENABLE(TIZEN_INPUT_TAG_EXTENSION) || ENABLE(TIZEN_WEBKIT2_FORM_DATABASE)
117 #include "EditorClient.h"
118 #endif
119
120 #if ENABLE(TIZEN_DATALIST_ELEMENT)
121 #include "HTMLCollection.h"
122 #include "HTMLDataListElement.h"
123 #include "HTMLOptionElement.h"
124 #endif
125
126 #if ENABLE(TIZEN_STYLE_SCOPED)
127 #include <WebCore/RuntimeEnabledFeatures.h>
128 #endif
129
130 #if ENABLE(TIZEN_WEBKIT2_TEXT_SELECTION)
131 #include "htmlediting.h"
132 #endif
133
134 #if ENABLE(TIZEN_LINK_MAGNIFIER)
135 #include "LinkMagnifier.h"
136 #endif
137
138 #if ENABLE(TIZEN_SCREEN_READER)
139 #include "WebEventConversion.h"
140 #endif
141
142 #if ENABLE(TIZEN_SCREEN_READER) || ENABLE(TIZEN_FOCUS_UI) || ENABLE(TIZEN_WEBKIT2_TEXT_SELECTION)
143 #include <WebCore/HTMLAreaElement.h>
144 #endif
145
146 #if ENABLE(TIZEN_CSP)
147 #include <WebCore/ContentSecurityPolicy.h>
148 #endif
149
150 #if ENABLE(TIZEN_OFFLINE_PAGE_SAVE)
151 #include "WebPageSerializerTizen.h"
152 #endif
153
154 #if ENABLE(TIZEN_USE_SETTINGS_FONT)
155 #include "fontconfig/fontconfig.h"
156 #include <WebCore/FontCache.h>
157 #endif
158
159 #if ENABLE(TIZEN_WEBKIT2_TEXT_SELECTION)
160 #include "visible_units.h"
161 #endif
162 #endif // #if OS(TIZEN)
163
164 using namespace WebCore;
165
166 namespace WebKit {
167
168 void WebPage::platformInitialize()
169 {
170 #if ENABLE(TIZEN_DEVICE_ORIENTATION)
171     WebCore::provideDeviceMotionTo(m_page.get(), new DeviceMotionClientTizen);
172     WebCore::provideDeviceOrientationTo(m_page.get(), new DeviceOrientationClientTizen);
173 #endif
174 }
175
176 #if ENABLE(TIZEN_PREFERENCE)
177 void WebPage::platformPreferencesDidChange(const WebPreferencesStore& store)
178 {
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()));
184 #endif
185 #if ENABLE(TIZEN_LINK_EFFECT)
186     settings->setLinkEffectEnabled(store.getBoolValueForKey(WebPreferencesKey::linkEffectEnabledKey()));
187 #endif
188 #if ENABLE(TIZEN_ISF_PORT)
189     settings->setEnableDefaultKeypad(store.getBoolValueForKey(WebPreferencesKey::defaultKeypadEnabledKey()));
190 #endif
191 #if ENABLE(TIZEN_STYLE_SCOPED)
192     WebCore::RuntimeEnabledFeatures::setStyleScopedEnabled(store.getBoolValueForKey(WebPreferencesKey::styleScopedEnabledKey()));
193 #endif
194 #if ENABLE(TIZEN_WEB_AUDIO)
195     settings->setWebAudioEnabled(true);
196 #endif
197 }
198 #else
199 void WebPage::platformPreferencesDidChange(const WebPreferencesStore&)
200 {
201     notImplemented();
202 }
203 #endif // #if ENABLE(TIZEN_PREFERENCE)
204
205 static inline void scroll(Page* page, ScrollDirection direction, ScrollGranularity granularity)
206 {
207     page->focusController()->focusedOrMainFrame()->eventHandler()->scrollRecursively(direction, granularity);
208 }
209
210 bool WebPage::performDefaultBehaviorForKeyEvent(const WebKeyboardEvent& keyboardEvent)
211 {
212     notImplemented();
213     return false;
214 }
215
216 bool WebPage::platformHasLocalDataForURL(const KURL&)
217 {
218     notImplemented();
219     return false;
220 }
221
222 String WebPage::cachedResponseMIMETypeForURL(const KURL&)
223 {
224     notImplemented();
225     return String();
226 }
227
228 bool WebPage::platformCanHandleRequest(const ResourceRequest&)
229 {
230     notImplemented();
231     return true;
232 }
233
234 String WebPage::cachedSuggestedFilenameForURL(const KURL&)
235 {
236     notImplemented();
237     return String();
238 }
239
240 PassRefPtr<SharedBuffer> WebPage::cachedResponseDataForURL(const KURL&)
241 {
242     notImplemented();
243     return 0;
244 }
245
246 const char* WebPage::interpretKeyEvent(const KeyboardEvent* event)
247 {
248     ASSERT(event->type() == eventNames().keydownEvent || event->type() == eventNames().keypressEvent);
249
250     if (event->type() == eventNames().keydownEvent)
251         return getKeyDownCommandName(event);
252
253     return getKeyPressCommandName(event);
254 }
255
256 void WebPage::setThemePath(const String& themePath)
257 {
258     WebCore::RenderThemeEfl* theme = static_cast<WebCore::RenderThemeEfl*>(m_page->theme());
259     theme->setThemePath(themePath);
260 }
261
262 static Frame* targetFrameForEditing(WebPage* page)
263 {
264     Frame* frame = page->corePage()->focusController()->focusedOrMainFrame();
265     if (!frame)
266         return 0;
267
268     Editor* editor = frame->editor();
269     if (!editor->canEdit())
270         return 0;
271
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())
280                 return 0;
281         }
282     }
283
284     return frame;
285 }
286
287 void WebPage::confirmComposition(const String& compositionString)
288 {
289     Frame* targetFrame = targetFrameForEditing(this);
290     if (!targetFrame)
291         return;
292
293 #if ENABLE(TIZEN_ISF_PORT)
294     if (m_prepareKeyDownEvent) {
295         m_keyPressCommands.append(adoptPtr(new ConfirmCompositionKeyPressCommand(compositionString)));
296         return;
297     }
298 #endif
299
300     targetFrame->editor()->confirmComposition(compositionString);
301
302 #if ENABLE(TIZEN_ISF_PORT)
303     m_page->editorClient()->respondToChangedSelection(targetFrame);
304 #endif
305 }
306
307 void WebPage::setComposition(const String& compositionString, const Vector<WebCore::CompositionUnderline>& underlines, uint64_t cursorPosition)
308 {
309     Frame* targetFrame = targetFrameForEditing(this);
310     if (!targetFrame)
311         return;
312
313 #if ENABLE(TIZEN_ISF_PORT)
314     if (!targetFrame->editor()->hasComposition() && compositionString.isEmpty())
315         return;
316
317     if (m_prepareKeyDownEvent) {
318         m_keyPressCommands.append(adoptPtr(new SetCompositionKeyPressCommand(compositionString, underlines, cursorPosition)));
319         return;
320     }
321
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)
329                 return;
330
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;
340                     }
341                 }
342                 targetFrame->editor()->setComposition(newCompositionString, newUnderlines, cursorPosition, 0);
343                 return;
344             }
345         }
346     }
347 #endif
348
349     targetFrame->editor()->setComposition(compositionString, underlines, cursorPosition, 0);
350
351 #if ENABLE(TIZEN_ISF_PORT)
352     m_page->editorClient()->respondToChangedSelection(targetFrame);
353 #endif
354 }
355
356 void WebPage::cancelComposition()
357 {
358     Frame* frame = m_page->focusController()->focusedOrMainFrame();
359     if (!frame)
360         return;
361
362     frame->editor()->cancelComposition();
363 }
364
365 #if OS(TIZEN)
366
367 #if ENABLE(TIZEN_WEBKIT2_TILED_BACKING_STORE)
368 IntSize WebPage::contentsSize() const
369 {
370     FrameView* frameView = m_page->mainFrame()->view();
371     if (!frameView)
372         return IntSize(0, 0);
373
374     return frameView->contentsSize();
375 }
376 #endif
377
378 void WebPage::scrollMainFrameBy(const IntSize& scrollOffset)
379 {
380     m_page->mainFrame()->view()->scrollBy(scrollOffset);
381 }
382
383 void WebPage::scrollMainFrameTo(const IntPoint& scrollPosition)
384 {
385     m_page->mainFrame()->view()->setScrollPosition(scrollPosition);
386 }
387
388 void WebPage::createSnapshot(const IntRect rect, float scaleFactor, ShareableBitmap::Handle& snapshotHandle)
389 {
390     FrameView* frameView = m_mainFrame->coreFrame()->view();
391     if (!frameView)
392         return;
393
394     RefPtr<WebImage> snapshotImage = scaledSnapshotInViewCoordinates(rect, scaleFactor, ImageOptionsShareable);
395     if (!snapshotImage || !snapshotImage->bitmap())
396         return;
397
398     snapshotImage->bitmap()->createHandle(snapshotHandle);
399 }
400
401 void WebPage::requestUpdateFormNavigation()
402 {
403     Frame* frame = m_page->focusController()->focusedOrMainFrame();
404     if (!frame)
405         return;
406
407     Document* document = frame->document();
408     if (!document)
409         return;
410
411     Node* focusedNode = document->focusedNode();
412
413     Vector<RefPtr<Node> > focusableNodes;
414     document->getFocusableNodes(focusableNodes);
415
416     int formElementCount = 0;
417     int currentNodeIndex = -1;
418     const Vector<RefPtr<Node> >::iterator end = focusableNodes.end();
419     for (Vector<RefPtr<Node> >::iterator it = focusableNodes.begin(); it != end; ++it) {
420         AtomicString nodeName = (*it).get()->nodeName();
421         if (equalIgnoringCase(nodeName, "SELECT")
422             || (equalIgnoringCase(nodeName, "INPUT")
423                 && !equalIgnoringCase((*it).get()->toInputElement()->type(), "CHECKBOX")
424                 && !equalIgnoringCase((*it).get()->toInputElement()->type(), "RADIO")
425                 && !equalIgnoringCase((*it).get()->toInputElement()->type(), "SUBMIT")
426                 )
427             ) {
428             if ((*it).get() == focusedNode)
429                 currentNodeIndex = formElementCount;
430             formElementCount++;
431         }
432     }
433
434     if (currentNodeIndex == -1)
435         return;
436
437     send(Messages::WebPageProxy::UpdateFormNavigation(formElementCount, currentNodeIndex));
438 }
439
440 void WebPage::moveFocus(int newIndex)
441 {
442     Frame* frame = m_page->focusController()->focusedOrMainFrame();
443     if (!frame)
444         return;
445
446     Document* document = frame->document();
447     if (!document)
448         return;
449
450     Vector<RefPtr<Node> > focusableNodes;
451     document->getFocusableNodes(focusableNodes);
452
453     int index = 0;
454     const Vector<RefPtr<Node> >::iterator end = focusableNodes.end();
455     for (Vector<RefPtr<Node> >::iterator it = focusableNodes.begin(); it != end; ++it) {
456         AtomicString nodeName = (*it).get()->nodeName();
457         if (equalIgnoringCase(nodeName, "SELECT")) {
458             if (index == newIndex) {
459                 (*it).get()->setFocus();
460                 LayoutPoint position = LayoutPoint(0, 0);
461                 PlatformMouseEvent event(flooredIntPoint(position), flooredIntPoint(position), LeftButton, PlatformEvent::MouseMoved, 1, false, false, false, false, 0);
462                 (*it).get()->dispatchMouseEvent(event, "mousedown", 0, 0);
463             }
464             index++;
465         } else if (equalIgnoringCase(nodeName, "INPUT")
466             && !equalIgnoringCase((*it).get()->toInputElement()->type(), "CHECKBOX")
467             && !equalIgnoringCase((*it).get()->toInputElement()->type(), "RADIO")
468             ) {
469             if (index == newIndex) {
470                 HTMLInputElement* elem = (*it).get()->toInputElement();
471                 elem->focus();
472             }
473             index++;
474         }
475     }
476 }
477
478 #if ENABLE(TIZEN_MOBILE_WEB_PRINT)
479 #define INCH_TO_MM 25.4
480 #define INCH_TO_POINTS 72.0
481
482 void WebPage::createPagesToPDF(const IntSize& surfaceSize, const IntSize& contentsSize, const String& fileName)
483 {
484     FrameView* frameView = m_mainFrame->coreFrame()->view();
485     if (!frameView)
486         return;
487
488     RefPtr<WebImage> pageshotImage = WebImage::create(contentsSize, ImageOptionsShareable);
489     if (!pageshotImage->bitmap())
490         return;
491
492     double pdfWidth = (double)surfaceSize.width() / INCH_TO_MM * INCH_TO_POINTS;
493     double pdfHeight = (double)surfaceSize.height() / INCH_TO_MM * INCH_TO_POINTS;
494     double scaleFactorPdf = 1.0;
495     if (contentsSize.width() > pdfWidth)
496         scaleFactorPdf = pdfWidth / (double)contentsSize.width();
497
498     OwnPtr<WebCore::GraphicsContext> graphicsContext = pageshotImage->bitmap()->createGraphicsContextForPdfSurface(fileName, pdfWidth, pdfHeight);
499     graphicsContext->scale(FloatSize(scaleFactorPdf, scaleFactorPdf));
500
501     frameView->updateLayoutAndStyleIfNeededRecursive();
502
503     int pageNumber = ((contentsSize.height() * scaleFactorPdf) / pdfHeight) + 1;
504     float paintY = 0.0;
505
506     PaintBehavior oldBehavior = frameView->paintBehavior();
507     frameView->setPaintBehavior(oldBehavior | PaintBehaviorFlattenCompositingLayers);
508     for (int i = 0; i < pageNumber; i++) {
509         IntRect paintRect(0, (int)paintY, contentsSize.width(), (int)(pdfHeight / scaleFactorPdf));
510
511         frameView->paint(graphicsContext.get(), paintRect);
512         cairo_show_page(graphicsContext->platformContext()->cr());
513         graphicsContext->translate(0, -ceil(pdfHeight / scaleFactorPdf));
514         paintY += (pdfHeight / scaleFactorPdf);
515     }
516     frameView->setPaintBehavior(oldBehavior);
517
518     pageshotImage.release();
519 }
520 #endif
521
522 #if ENABLE(TIZEN_TEXT_CARET_HANDLING_WK2)
523 bool WebPage::setCaretPosition(const IntPoint& pos)
524 {
525     Frame* frame = m_page->focusController()->focusedOrMainFrame();
526     if (!frame)
527         return false;
528
529     FrameSelection* controller = frame->selection();
530     if (!controller)
531         return false;
532
533     FrameView* frameView = frame->view();
534     if (!frameView)
535         return false;
536
537     IntPoint point = m_page->mainFrame()->view()->windowToContents(pos);
538     HitTestResult result = m_page->mainFrame()->eventHandler()->hitTestResultAtPoint(point, /*allowShadowContent*/ true, /*ignoreClipping*/ true);
539     if (result.scrollbar())
540         return false;
541
542     Node* innerNode = result.innerNode();
543
544     if (!innerNode || !innerNode->renderer())
545         return false;
546
547     VisiblePosition visiblePos;
548
549     // we check if content is richly editable - because those input field behave other than plain text ones
550     // sometimes they may consists a node structure and they need special approach
551     if (innerNode->rendererIsRichlyEditable()) {
552         // point gets inner node local coordinates
553         point = flooredIntPoint(result.localPoint());
554         IntRect rect = innerNode->renderer()->absoluteBoundingBoxRect(true);
555
556         // it is not the best way to do this, but it is not as slow and it works - so maybe in the future someone
557         // will have a better idea how to solve it
558         // here we are getting innerNode from HitTestResult - unfortunately this is a kind of high level node
559         // in the code below I am trying to obtain low level node - #text - to get its coordinates and size
560
561         // all those getting nodes rects are needed to bypass WebCore's methods of positioning caret when user
562         // is clicking outside a node - and cheat WebCore telling it that actually we clicked into input field
563         // node, not outside of it
564         Node* deepInnerNode = innerNode->renderer()->positionForPoint(point).deepEquivalent().deprecatedNode();
565
566         if (!deepInnerNode || !deepInnerNode->renderer())
567             return false;
568
569         // so we get a base node rectange
570         IntRect deepNodeRect = deepInnerNode->renderer()->absoluteBoundingBoxRect(true);
571
572         // we modify our local point to adjust it to base node local coordinates
573         point.move(rect.x() - deepNodeRect.x(), rect.y() - deepNodeRect.y());
574
575         // if we are outside the rect we cheat, that we are just inside of it
576         if (point.y() < 0)
577             point.setY(0);
578         else if (point.y() >= deepNodeRect.height())
579             point.setY(deepNodeRect.height() - 1);
580
581         // visible position created - caret ready to set
582         visiblePos = deepInnerNode->renderer()->positionForPoint(point);
583         if (visiblePos.isNull())
584             return false;
585     } else {
586         // for plain text input fields we can get only a caret bounding box
587         if (!controller->isCaret() || !controller->caretRenderer())
588             return false;
589
590         const Node* node = controller->start().deprecatedNode();
591         if (!node || !node->renderer())
592             return false;
593
594         Element* currentRootEditableElement = node->rootEditableElement();
595         Element* newRootEditableElement = innerNode->rootEditableElement();
596         if (currentRootEditableElement != newRootEditableElement)
597             return false;
598
599         IntRect rect = controller->caretRenderer()->absoluteBoundingBoxRect(true);
600
601         // The below wirtten code is not correct way to implement. Presntly the is no
602         // other working way. To be replaced by better logic
603         // here we also cheat input field that we actually are just inside of if
604         IntPoint focusedFramePoint = frame->view()->windowToContents(pos);
605         IntPoint oldFocusedFramePoint = focusedFramePoint;
606
607         const int boundariesWidth = 2;
608         if (focusedFramePoint.x() < rect.x())
609             focusedFramePoint.setX(rect.x());
610         else if (focusedFramePoint.x() > rect.maxX())
611             focusedFramePoint.setX(rect.maxX());
612         if (focusedFramePoint.y() < rect.y() + boundariesWidth)
613             focusedFramePoint.setY(rect.y() + boundariesWidth);
614         else if (focusedFramePoint.y() >= rect.maxY() - boundariesWidth)
615             focusedFramePoint.setY(rect.maxY() - boundariesWidth - 1);
616
617         int diffX = focusedFramePoint.x() - oldFocusedFramePoint.x();
618         int diffY = focusedFramePoint.y() - oldFocusedFramePoint.y();
619         point.setX((point.x())+diffX);
620         point.setY((point.y())+diffY);
621
622         // hit test with fake (adjusted) coordinates
623         IntPoint hitTestPoint = m_page->mainFrame()->view()->windowToContents(point);
624         HitTestResult newResult = m_page->mainFrame()->eventHandler()->hitTestResultAtPoint(hitTestPoint, /*allowShadowContent*/ true, /*ignoreClipping*/ true);
625
626         if (!newResult.isContentEditable())
627             return false;
628
629         Node* newInnerNode = newResult.innerNode();
630
631         if (!newInnerNode || !newInnerNode->renderer())
632             return false;
633
634         // visible position created
635         visiblePos = newInnerNode->renderer()->positionForPoint(newResult.localPoint());
636         if (visiblePos.isNull())
637             return false;
638     }
639
640     // create visible selection from visible position
641     VisibleSelection newSelection = VisibleSelection(visiblePos);
642     controller->setSelection(newSelection, CharacterGranularity);
643     // after setting selection caret blinking is suspended by default so we are unsuspedning it
644     controller->setCaretBlinkingSuspended(false);
645
646     return true;
647 }
648
649 void WebPage::getCaretPosition(IntRect& rect)
650 {
651     Frame* frame = m_page->focusController()->focusedOrMainFrame();
652     if (!frame)
653         return;
654
655     FrameSelection* controller = frame->selection();
656     if (!controller)
657         return;
658
659     Node* node = controller->start().deprecatedNode();
660     if (!node || !node->renderer() || !node->isContentEditable())
661         return;
662
663     if (controller->isCaret()) {
664         FrameView* frameView = frame->view();
665         if (!frameView)
666             return;
667
668         rect = frameView->contentsToWindow(controller->absoluteCaretBounds());
669     }
670 }
671 #endif
672
673 #if ENABLE(TIZEN_ISF_PORT)
674 void WebPage::didCancelComposition(Node* valueChangedNode)
675 {
676     Frame* frame = m_page->focusController()->focusedOrMainFrame();
677     if (!frame || frame->editor()->ignoreCompositionSelectionChange() || !valueChangedNode->containsIncludingShadowDOM(frame->editor()->compositionNode()))
678         return;
679
680     frame->editor()->cancelComposition();
681     send(Messages::WebPageProxy::DidCancelComposition());
682 }
683
684 void WebPage::prepareKeyDownEvent()
685 {
686     m_prepareKeyDownEvent = true;
687     m_keyPressCommands.clear();
688 }
689
690 void WebPage::swapKeyPressCommands(Vector<OwnPtr<KeyPressCommand> >& commands)
691 {
692     m_keyPressCommands.swap(commands);
693 }
694
695 void WebPage::getCursorOffset(int& offset)
696 {
697     offset = 0;
698     Frame* frame = m_page->focusController()->focusedOrMainFrame();
699     if (!frame || !frame->editor()->canEdit())
700         return;
701
702     Position base = frame->selection()->base();
703     Node* baseNode = base.containerNode();
704     if (baseNode)
705         offset = baseNode->isTextNode() ? base.offsetInContainerNode() : 0;
706 }
707
708 void WebPage::getSurroundingTextAndCursorOffset(String& text, int& offset)
709 {
710     text = String();
711     offset = 0;
712
713     Frame* frame = m_page->focusController()->focusedOrMainFrame();
714     if (!frame || !frame->editor()->canEdit())
715         return;
716
717     Position base = frame->selection()->base();
718     Node* baseNode = base.containerNode();
719     if (baseNode && baseNode->isTextNode()) {
720         text = baseNode->textContent();
721         offset = base.offsetInContainerNode();
722     }
723 }
724
725 void WebPage::getSelectionRect(bool isOnlyEditable, IntRect& rect)
726 {
727     rect = IntRect();
728
729     Frame* frame = m_page->focusController()->focusedFrame();
730     if (!frame || !frame->view())
731         return;
732
733     FrameSelection* selection = frame->selection();
734     Node* node = selection->start().deprecatedNode();
735     if (!node || !node->renderer() || (isOnlyEditable && !node->isContentEditable()))
736         return;
737
738     if (selection->isCaret())
739         rect = frame->view()->contentsToWindow(selection->absoluteCaretBounds());
740     else if (selection->isRange())
741         rect = frame->view()->contentsToWindow(enclosingIntRect(selection->bounds(false)));
742 }
743
744 void WebPage::deleteSurroundingText(int offset, int count)
745 {
746     Frame* frame = m_page->focusController()->focusedOrMainFrame();
747     if (!frame || !frame->editor()->canEdit())
748         return;
749
750     if (m_prepareKeyDownEvent) {
751         m_keyPressCommands.append(adoptPtr(new DeleteTextKeyPressCommand(offset, count)));
752         return;
753     }
754
755     Position base(frame->selection()->base());
756     offset += base.offsetInContainerNode();
757     base.moveToOffset(offset);
758     Position extent(base);
759     extent.moveToOffset(offset + count);
760     VisibleSelection selection(base, extent);
761     if (!selection.isRange())
762         return;
763
764     frame->selection()->setSelection(selection);
765     frame->editor()->deleteWithDirection(DirectionBackward, CharacterGranularity, false, true);
766 }
767 #endif
768
769 #if ENABLE(TIZEN_INPUT_TAG_EXTENSION) || ENABLE(TIZEN_WEBKIT2_FORM_DATABASE)
770 void WebPage::setFocusedInputElementValue(const String& inputValue)
771 {
772     Frame* frame = m_page->focusController()->focusedOrMainFrame();
773     if (!frame || !frame->document() || !frame->document()->focusedNode())
774         return;
775
776     HTMLInputElement* inputElement = frame->document()->focusedNode()->toInputElement();
777     if (!inputElement)
778         return;
779
780     inputElement->toNode()->dispatchFocusEvent(0);
781     inputElement->setValue(inputValue, DispatchChangeEvent);
782 }
783
784 void  WebPage::getFocusedInputElementValue(String& inputValue)
785 {
786     inputValue = String();
787
788     Frame* frame = m_page->focusController()->focusedOrMainFrame();
789     if (!frame || !frame->document() || !frame->document()->focusedNode())
790         return;
791
792     HTMLInputElement* inputElement = frame->document()->focusedNode()->toInputElement();
793     if (!inputElement)
794         return;
795
796     inputValue = inputElement->value();
797 }
798 #endif
799
800 #if ENABLE(TIZEN_DATALIST_ELEMENT)
801 void WebPage::getFocusedInputElementDataList(Vector<String>& optionList)
802 {
803     Frame* frame = m_page->focusController()->focusedOrMainFrame();
804     if (!frame || !frame->document())
805         return;
806
807     Node* node = frame->document()->focusedNode();
808     if (!node)
809         return;
810
811     HTMLInputElement* input = node->toInputElement();
812     if (!input)
813         return;
814
815     HTMLDataListElement* dataList = static_cast<HTMLDataListElement*>(input->list());
816     if (!dataList)
817         return;
818
819     RefPtr<HTMLCollection> options = static_cast<HTMLDataListElement*>(dataList)->options();
820     for (unsigned i = 0; Node* node = options->item(i); i++) {
821         HTMLOptionElement* optionElement = static_cast<HTMLOptionElement*>(node);
822         String value = optionElement->value();
823         optionList.append(value);
824     }
825 }
826 #endif
827
828 #if ENABLE(TIZEN_WEBKIT2_FOCUS_RING)
829 static IntRect getNodeRect(Node* node, Node* focusableNode, bool isImage)
830 {
831     IntRect rect;
832
833     if (isImage) {
834         bool isReplaced;
835         IntRect imageNodeRect = pixelSnappedIntRect(node->getRect());
836         if (!focusableNode->renderRect(&isReplaced).isEmpty() && imageNodeRect.contains(pixelSnappedIntRect(focusableNode->getRect()))) {
837             // If render rect of focusableNode is empty and rect of imageNode include rect of focusableNode,
838             // we have to get rect of focusableNode.
839             // for example - The rect of google logo image in www.google.com pc site's search result page is bigger than rect of focusableNode.
840             // for example - The rect of category menu image in www.gmarket.co.kr pc site is bigger than rect of focusableNode.
841             rect = pixelSnappedIntRect(focusableNode->getRect());
842         }
843         else {
844             // otherwise we have to get rect of imageNode.
845             // for example - The render rect of images in www.pudelek.pl is empty.
846             // for example - The rect of focusableNode of 'Test your browser GO' image in peacekeeper.futuremark.com is bigger than rect of 'Test your browser GO' image.
847             rect = imageNodeRect;
848             focusableNode = node;
849         }
850     } else {
851         // If focusedNode have multiple child nodes, we have to unite rect of child nodes.
852         // for example - links in www.google.com's search result page.
853         IntRect tempRect;
854         for (Node* childNode = focusableNode->firstChild(); childNode; childNode = childNode->traverseNextNode(focusableNode)) {
855             bool isReplaced;
856             if (focusableNode->renderRect(&isReplaced).contains(childNode->getRect()))
857                 tempRect.unite(pixelSnappedIntRect(childNode->getRect()));
858         }
859
860         // If tempRect is empty or rect of focusableNode include tempRect,
861         // we have to get rect of focusableNode.
862         // for example - list menu item in m.naver.com.
863         // otherwise we have to get rect of tempRect.
864         // getRect API do not return correct rect if the node is a container node,
865         // hence using absoluteBoundingBoxRect to get the correct bounding rect.
866         LayoutRect renderRect = focusableNode->renderer() ? focusableNode->renderer()->absoluteBoundingBoxRect() : focusableNode->getRect();
867         if (tempRect.isEmpty() || renderRect.contains(tempRect))
868             rect = pixelSnappedIntRect(renderRect);
869         else
870             rect = tempRect;
871     }
872
873     // We have to get render rect from ancestor node if current rect is empty.
874     // for example - The rect of naver logo image in www.naver.com pc site is empty.
875     bool isReplaced;
876     for (Node* loopNode = focusableNode; loopNode && rect.isEmpty(); loopNode = loopNode->parentNode()) {
877         RenderObject* renderer = loopNode->renderer();
878         if (renderer && renderer->isRoot())
879             break;
880
881         rect = pixelSnappedIntRect(loopNode->renderRect(&isReplaced));
882     }
883
884     Frame* nodeFrame = focusableNode->document()->frame();
885     Node* owner;
886     while (nodeFrame && (owner = nodeFrame->ownerElement())) {
887         rect.moveBy(owner->getRect().pixelSnappedLocation());
888         nodeFrame = owner->document()->frame();
889     }
890
891     // The y position of tab menu item in www.google.com is negative value,
892     // so we do not want to draw focus ring in that case.
893     if ((rect.maxX() < 0) || (rect.maxY() < 0))
894         rect = IntRect();
895
896     return rect;
897 }
898 #endif
899
900 #if ENABLE(TIZEN_WEBKIT2_HIT_TEST)
901 #if ENABLE(TIZEN_WEBKIT2_FOCUS_RING)
902 static IntRect getFocusedRect(HitTestResult hitTestResult, Page* page)
903 {
904     Node* node = hitTestResult.innerNode();
905     if (!node)
906         return IntRect();
907
908     bool isFocusRingDrawable = false;
909     Node* focusableNode = node;
910     while (focusableNode) {
911         RenderObject* renderer = focusableNode->renderer();
912         if (renderer && renderer->isRoot())
913             break;
914
915         if (focusableNode->isFocusable()) {
916             if (focusableNode->isLink()
917                 || focusableNode->hasTagName(HTMLNames::inputTag)
918                 || focusableNode->hasTagName(HTMLNames::selectTag)
919                 || focusableNode->hasTagName(HTMLNames::buttonTag))
920                 isFocusRingDrawable = true;
921             break;
922         }
923
924         focusableNode = focusableNode->parentNode();
925     }
926
927     if (!isFocusRingDrawable) {
928         if (node->hasTagName(HTMLNames::imgTag))
929             return getNodeRect(node, node, !hitTestResult.absoluteImageURL().isEmpty());
930
931         return IntRect();
932     }
933
934     return getNodeRect(node, focusableNode, !hitTestResult.absoluteImageURL().isEmpty());
935 }
936 #endif
937
938 void WebPage::hitTestResultAtPoint(const IntPoint& point, int hitTestMode, WebHitTestResult::Data& hitTestResultData)
939 {
940     Frame* frame = m_page->mainFrame();
941     FrameView* frameView = frame->view();
942     if (!frameView)
943         return;
944
945     HitTestResult hitTestResult = frame->eventHandler()->hitTestResultAtPoint(frameView->windowToContents(point), false);
946     hitTestResultData.absoluteImageURL = hitTestResult.absoluteImageURL().string();
947     hitTestResultData.absoluteLinkURL = hitTestResult.absoluteLinkURL().string();
948     hitTestResultData.absoluteMediaURL = hitTestResult.absoluteMediaURL().string();
949     hitTestResultData.linkLabel = hitTestResult.textContent();
950     hitTestResultData.linkTitle = hitTestResult.titleDisplayString();
951     hitTestResultData.isContentEditable = hitTestResult.isContentEditable();
952 #if ENABLE(TIZEN_DRAG_SUPPORT)
953     hitTestResultData.isDragSupport = hitTestResult.isDragSupport();
954 #endif
955
956     int context = WebHitTestResult::HitTestResultContextDocument;
957
958     if (!hitTestResult.absoluteLinkURL().isEmpty())
959         context |= WebHitTestResult::HitTestResultContextLink;
960     if (!hitTestResult.absoluteImageURL().isEmpty())
961         context |= WebHitTestResult::HitTestResultContextImage;
962     if (!hitTestResult.absoluteMediaURL().isEmpty())
963         context |= WebHitTestResult::HitTestResultContextMedia;
964     if (hitTestResult.isSelected())
965         context |= WebHitTestResult::HitTestResultContextSelection;
966     if (hitTestResult.isContentEditable())
967         context |= WebHitTestResult::HitTestResultContextEditable;
968     if (hitTestResult.innerNonSharedNode() && hitTestResult.innerNonSharedNode()->isTextNode())
969         context |= WebHitTestResult::HitTestResultContextText;
970
971     hitTestResultData.context = context;
972     hitTestResultData.hitTestMode = hitTestMode;
973
974 #if ENABLE(TIZEN_WEBKIT2_FOCUS_RING)
975     hitTestResultData.focusedRect = getFocusedRect(hitTestResult, m_page.get());
976     if (hitTestResult.innerNode() && hitTestResult.innerNode()->renderer() && hitTestResult.innerNode()->renderer()->style()) {
977         hitTestResultData.focusedColor = hitTestResult.innerNode()->renderer()->style()->tapHighlightColor();
978         if (!hitTestResultData.focusedColor.hasAlpha())
979             hitTestResultData.focusedColor = Color(hitTestResultData.focusedColor.red(), hitTestResultData.focusedColor.green(), hitTestResultData.focusedColor.blue(), RenderStyle::initialTapHighlightColor().alpha());
980     }
981 #endif
982
983     if (hitTestResultData.hitTestMode & WebHitTestResult::HitTestModeNodeData) {
984         WebCore::Node* hitNode = hitTestResult.innerNonSharedNode();
985         if (hitNode) {
986             hitTestResultData.nodeData.nodeValue = hitNode->nodeValue();
987
988             if ((hitTestResultData.context & WebHitTestResult::HitTestResultContextText) && hitNode->parentNode())
989                 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.
990
991             if (hitNode->isElementNode()) {
992                 WebCore::Element* hitElement = static_cast<WebCore::Element*>(hitNode);
993                 if (hitElement) {
994                     hitTestResultData.nodeData.tagName = hitElement->tagName();
995                 }
996             }
997
998             WebCore::NamedNodeMap* namedNodeMap = hitNode->attributes();
999             if (namedNodeMap) {
1000                 for (size_t i = 0; i < namedNodeMap->length(); i++) {
1001                     const WebCore::Attribute* attribute = namedNodeMap->element()->attributeItem(i);
1002                     String key = attribute->name().toString();
1003                     String value = attribute->value();
1004                     hitTestResultData.nodeData.attributeMap.add(key, value);
1005                 }
1006             }
1007         }
1008     }
1009
1010     if ((hitTestResultData.hitTestMode & WebHitTestResult::HitTestModeImageData) && (hitTestResultData.context & WebHitTestResult::HitTestResultContextImage)) {
1011         WebCore::Image* hitImage = hitTestResult.image();
1012         if (hitImage && hitImage->data() && hitImage->data()->data()) {
1013             hitTestResultData.imageData.data.append(hitImage->data()->data(), hitImage->data()->size());
1014             hitTestResultData.imageData.fileNameExtension = hitImage->filenameExtension();
1015         }
1016     }
1017 }
1018 #endif
1019
1020 #if ENABLE(TIZEN_WEB_STORAGE)
1021 void WebPage::getStorageQuotaBytes(uint64_t callbackID)
1022 {
1023     uint32_t quota = m_page->group().groupSettings()->localStorageQuotaBytes();
1024     send(Messages::WebPageProxy::DidGetWebStorageQuotaBytes(quota, callbackID));
1025 }
1026
1027 void WebPage::setStorageQuotaBytes(uint32_t quota)
1028 {
1029     m_page->group().groupSettings()->setLocalStorageQuotaBytes(quota);
1030 }
1031 #endif
1032
1033 #if ENABLE(TIZEN_CLIPBOARD) || ENABLE(TIZEN_PASTEBOARD)
1034 void WebPage::setClipboardDataForPaste(const String& data, const String& type)
1035 {
1036 #if ENABLE(TIZEN_PASTEBOARD)
1037     // FIXME: Should move to EditorClient like Clipboard
1038     Pasteboard::generalPasteboard()->setDataWithType(data, type);
1039 #else
1040     Frame* mainFrame = m_page->mainFrame();
1041     if (!mainFrame)
1042         return;
1043
1044     mainFrame->editor()->client()->setClipboardDataForPaste(data, type);
1045 #endif
1046 }
1047 #endif
1048
1049 void WebPage::suspendJavaScriptAndResources()
1050 {
1051     Frame* mainFrame = m_page->mainFrame();
1052     if (!mainFrame)
1053         return;
1054
1055     for (Frame* frame = mainFrame; frame; frame = frame->tree()->traverseNext())
1056         frame->document()->suspendScheduledTasks(WebCore::ActiveDOMObject::PageWillBeSuspended);
1057     mainFrame->loader()->suspendAllLoaders();
1058 }
1059
1060 void WebPage::resumeJavaScriptAndResources()
1061 {
1062     Frame* mainFrame = m_page->mainFrame();
1063     if (!mainFrame)
1064         return;
1065
1066     for (Frame* frame = mainFrame; frame; frame = frame->tree()->traverseNext())
1067         frame->document()->resumeScheduledTasks();
1068     mainFrame->loader()->resumeAllLoaders();
1069 }
1070
1071 void WebPage::suspendAnimations()
1072 {
1073     Frame* mainFrame = m_page->mainFrame();
1074     if (!mainFrame)
1075         return;
1076
1077     for (Frame* frame = mainFrame; frame; frame = frame->tree()->traverseNext())
1078         frame->animation()->suspendAnimationsForDocument(frame->document());
1079 }
1080
1081 void WebPage::resumeAnimations()
1082 {
1083     Frame* mainFrame = m_page->mainFrame();
1084     if (!mainFrame)
1085         return;
1086
1087     for (Frame* frame = mainFrame; frame; frame = frame->tree()->traverseNext())
1088         frame->animation()->resumeAnimationsForDocument(frame->document());
1089 }
1090
1091 #if ENABLE(TIZEN_SYNC_REQUEST_ANIMATION_FRAME)
1092 void WebPage::suspendAnimationController()
1093 {
1094     if (!m_suspendedAnimationController) {
1095         Frame* mainFrame = m_page->mainFrame();
1096         if (!mainFrame)
1097             return;
1098
1099         for (Frame* frame = mainFrame; frame; frame = frame->tree()->traverseNext())
1100             frame->document()->suspendScriptedAnimationControllerCallbacks();
1101
1102         m_suspendedAnimationController = true;
1103     }
1104 }
1105
1106 void WebPage::resumeAnimationController()
1107 {
1108     if (m_suspendedAnimationController) {
1109         Frame* mainFrame = m_page->mainFrame();
1110         if (!mainFrame)
1111             return;
1112
1113         for (Frame* frame = mainFrame; frame; frame = frame->tree()->traverseNext())
1114             frame->document()->resumeScriptedAnimationControllerCallbacks();
1115
1116         m_suspendedAnimationController = false;
1117     }
1118 }
1119 #endif
1120
1121 #if ENABLE(TIZEN_REMOTE_WEB_INSPECTOR)
1122 void WebPage::startInspectorServer(uint32_t port,  uint32_t& allocatedPort)
1123 {
1124     bool ret = WebInspectorServerTizen::server()->startServer(port);
1125     if (ret)
1126         allocatedPort = WebInspectorServerTizen::server()->getServerPort();
1127     else
1128         allocatedPort = 0;
1129 }
1130
1131 void WebPage::stopInspectorServer(bool& result)
1132 {
1133     result = WebInspectorServerTizen::server()->stopServer();
1134 }
1135 #endif
1136
1137 #if ENABLE(TIZEN_CSS_OVERFLOW_SCROLL_ACCELERATION_ON_UI_SIDE)
1138 void WebPage::scrollOverflowWithTrajectoryVector(const WebCore::FloatPoint& trajectoryVector)
1139 {
1140     Frame* frame = m_page->focusController()->focusedOrMainFrame();
1141     if (!frame)
1142         return;
1143     frame->eventHandler()->scrollOverflow(trajectoryVector);
1144 }
1145 #endif
1146
1147 #if ENABLE(TIZEN_CSS_OVERFLOW_SCROLL_ACCELERATION)
1148 void WebPage::scrollOverflow(const WebCore::FloatPoint& delta, bool& scrolled)
1149 {
1150     scrolled = m_page->focusController()->focusedOrMainFrame()->eventHandler()->scrollOverflow(delta);
1151 }
1152
1153 void WebPage::setPressedNodeAtPoint(const IntPoint& point, bool checkOverflowLayer, bool& pressed, uint32_t& id)
1154 {
1155     RenderObject* renderer = 0;
1156     id = 0;
1157     pressed = m_page->mainFrame()->eventHandler()->setMousePressNodeAtPoint(point, checkOverflowLayer, renderer);
1158 #if ENABLE(TIZEN_CSS_OVERFLOW_SCROLL_ACCELERATION_ON_UI_SIDE)
1159     if (pressed && renderer)
1160         id = toWebGraphicsLayer(renderer->enclosingLayer()->layerForScrollingContents())->id();
1161 #endif
1162 }
1163 #endif
1164
1165 void WebPage::executeEditCommandWithArgument(const String& commandName, const String& argument)
1166 {
1167     executeEditingCommand(commandName, argument);
1168 }
1169
1170 #if ENABLE(TIZEN_PLUGIN_SUSPEND_RESUME)
1171 void WebPage::suspendPlugin()
1172 {
1173     for (Frame* frame = m_page->mainFrame(); frame; frame = frame->tree()->traverseNext()) {
1174         FrameView* view = frame->view();
1175         if (!view)
1176             continue;
1177
1178         const HashSet<RefPtr<Widget> >* children = view->children();
1179         ASSERT(children);
1180
1181         HashSet<RefPtr<Widget> >::const_iterator end = children->end();
1182         for (HashSet<RefPtr<Widget> >::const_iterator it = children->begin(); it != end; ++it) {
1183             Widget* widget = (*it).get();
1184             if (widget->isPluginViewBase()) {
1185                 PluginView* pluginView = static_cast<PluginView*>(widget);
1186                 if (pluginView)
1187                     pluginView->suspendPlugin();
1188             }
1189         }
1190     }
1191 }
1192
1193 void WebPage::resumePlugin()
1194 {
1195     for (Frame* frame = m_page->mainFrame(); frame; frame = frame->tree()->traverseNext()) {
1196         FrameView* view = frame->view();
1197         if (!view)
1198             continue;
1199
1200         const HashSet<RefPtr<Widget> >* children = view->children();
1201         ASSERT(children);
1202
1203         HashSet<RefPtr<Widget> >::const_iterator end = children->end();
1204         for (HashSet<RefPtr<Widget> >::const_iterator it = children->begin(); it != end; ++it) {
1205             Widget* widget = (*it).get();
1206             if (widget->isPluginViewBase()) {
1207                 PluginView* pluginView = static_cast<PluginView*>(widget);
1208                 if (pluginView)
1209                     pluginView->resumePlugin();
1210             }
1211         }
1212     }
1213 }
1214 #endif
1215
1216 #if ENABLE(TIZEN_MULTIPLE_SELECT)
1217 void WebPage::didChangeSelectedIndexForActivePopupMenuMultiple(Vector<int32_t> newIndex)
1218 {
1219     if (!m_activePopupMenu)
1220         return;
1221
1222     m_activePopupMenu->client()->popupDidHide();
1223
1224     size_t indexSize = newIndex.size();
1225     for (size_t i = 0; i < indexSize; i++)
1226         m_activePopupMenu->didChangeSelectedIndex(newIndex.at(i));
1227
1228 }
1229 #endif
1230
1231 #if ENABLE(TIZEN_OFFLINE_PAGE_SAVE)
1232 void WebPage::startOfflinePageSave(String subresourceFolderName)
1233 {
1234     WebPageSerializerTizen::getSerializedPageContent(this, subresourceFolderName);
1235 }
1236 #endif
1237
1238 #if ENABLE(TIZEN_WEBKIT2_TEXT_SELECTION)
1239 void WebPage::selectClosestWord(const IntPoint& point, bool& result)
1240 {
1241     result = false;
1242
1243     Frame* mainFrame = m_page->mainFrame();
1244     Frame* focusedFrame = m_page->focusController()->focusedOrMainFrame();
1245
1246     HitTestResult hitTestResult = mainFrame->eventHandler()->hitTestResultAtPoint(m_page->mainFrame()->view()->windowToContents(point), false);
1247
1248     Node* node = hitTestResult.innerNonSharedNode();
1249     if (!node)
1250         return;
1251
1252      Frame* newFocusFrame = node->document()->frame();
1253      if (focusedFrame != newFocusFrame) {
1254          m_page->focusController()->setFocusedFrame(newFocusFrame);
1255          focusedFrame = newFocusFrame;
1256      }
1257
1258     HTMLInputElement* inputElement = node->toInputElement();
1259
1260     if (hitTestResult.isContentEditable()) {
1261 #if ENABLE(TIZEN_INPUT_TAG_EXTENSION)
1262         if (!inputElement || (inputElement
1263             && !inputElement->isDateField() && !inputElement->isDateTimeField() && !inputElement->isDateTimeLocalField()
1264             && !inputElement->isMonthField() && !inputElement->isTimeField() && !inputElement->isWeekField())) {
1265             result = setCaretPosition(point);
1266             return;
1267         }
1268 #else
1269         result = setCaretPosition(point);
1270         return;
1271 #endif
1272     }
1273
1274 #if ENABLE(TIZEN_INPUT_TAG_EXTENSION)
1275     if (!node->isTextNode() && !inputElement)
1276 #else
1277     if (!node->isTextNode())
1278 #endif
1279         return;
1280
1281 #if ENABLE(TIZEN_INPUT_TAG_EXTENSION)
1282     if (inputElement
1283         && (inputElement->isDateField() || inputElement->isDateTimeField() || inputElement->isDateTimeLocalField()
1284         || inputElement->isMonthField() || inputElement->isTimeField() || inputElement->isWeekField())) {
1285         if (inputElement->value().isEmpty())
1286             return;
1287     }
1288 #endif
1289
1290     for (Node* node = hitTestResult.innerNonSharedNode(); node; node = node->parentNode()) {
1291         if (node->isFocusable()) {
1292             // Text selection shoud not be started when text of <button> tag is selected.
1293             if (node->hasTagName(HTMLNames::buttonTag))
1294                 return;
1295
1296             if (inputElement && inputElement->isTextButton())
1297                 return;
1298
1299             break;
1300         }
1301     }
1302
1303     FrameSelection* frameSelection = focusedFrame->selection();
1304
1305     VisiblePosition position = mainFrame->visiblePositionForPoint(point);
1306     VisibleSelection selection(position);
1307
1308     // This changes just the 'start' and 'end' positions of the VisibleSelection
1309     selection.expandUsingGranularity(WordGranularity);
1310
1311     FrameSelection::SetSelectionOptions options = FrameSelection::CloseTyping | FrameSelection::ClearTypingStyle | FrameSelection::DoNotSetFocus;
1312     frameSelection->setSelection(VisibleSelection(selection.start(), selection.end()), options);
1313
1314     if (!frameSelection->isRange())
1315         return;
1316
1317     // This changes just the 'start' and 'end' positions of the VisibleSelection
1318     // Find handlers positions
1319     IntRect leftRect, rightRect;
1320     getSelectionHandlers(leftRect, rightRect);
1321     if (leftRect.size().isZero() && rightRect.size().isZero()) {
1322         // Sometimes there is no selected text, but isNone() returns TRUE
1323         // in this case ewk_frame_selection_handlers_get() returns FALSE and handlers are invalid
1324         // Workaround - clear the selection.
1325         // Better solution would be to modify the ewk_frame_select_closest_word()
1326         // to not select anything in the first place (for example - don't call setSelection()
1327         // if there is nothing under the cursor).
1328         selectionClearAllSelection(m_page->mainFrame());
1329         return;
1330     }
1331
1332     result = true;
1333 }
1334
1335 void WebPage::setLeftSelection(const IntPoint& point, const int direction, int& result)
1336 {
1337     result = HandleMovingDirectionNone;
1338
1339     Frame* focusedFrame = m_page->focusController()->focusedOrMainFrame();
1340     FrameSelection* frameSelection = focusedFrame->selection();
1341     if (!frameSelection->isRange())
1342         return;
1343
1344     Node* selectionEndNode = frameSelection->end().deprecatedNode();
1345     if (!selectionEndNode || !selectionEndNode->renderer())
1346         return;
1347
1348     FrameView* frameView = focusedFrame->view();
1349     if (!frameView)
1350         return;
1351
1352     IntPoint pos = frameView->windowToContents(point);
1353     IntRect leftRect, rightRect;
1354     getSelectionHandlers(leftRect, rightRect);
1355
1356     if (selectionEndNode->rendererIsEditable() && !selectionEndNode->rendererIsRichlyEditable()) {
1357         const int boundariesWidth = 2;
1358
1359         IntRect rect = frameSelection->caretRenderer()->absoluteBoundingBoxRect(true);
1360         // here we cheat input field that we actually are just inside of if
1361         if (pos.y() < rect.y() + boundariesWidth)
1362             pos.setY(rect.y() + boundariesWidth);
1363         else if (pos.y() >= rect.maxY() - boundariesWidth)
1364             pos.setY(rect.maxY() - boundariesWidth - 1);
1365     }
1366
1367     OwnPtr<VisiblePosition> position = adoptPtr(new VisiblePosition(focusedFrame->visiblePositionForPoint(pos)));
1368     Position base = frameSelection->base();
1369     Position extent = frameSelection->extent();
1370
1371     Node* newSelectionStartNode = position->deepEquivalent().deprecatedNode();
1372
1373     // both start and end nodes should be in the same area type: both should be editable or both should be not editable
1374     // Check if the new position is before the extent's position
1375     if (newSelectionStartNode
1376         && selectionEndNode->isContentEditable() == newSelectionStartNode->isContentEditable()) {
1377         // Change the 'base' and 'extent' positions to 'start' and 'end' positions.
1378         // We do it, because without this, the other modification of the selection
1379         // would destroy the 'start' and/or 'end' positions and set them to
1380         // the 'base'/'extent' positions accordingly
1381         VisibleSelection sel(frameSelection->start(), frameSelection->end());
1382         frameSelection->setSelection(sel);
1383
1384         bool oldProhibitsScrolling = focusedFrame->view()->prohibitsScrolling();
1385         focusedFrame->view()->setProhibitsScrolling(true);
1386
1387         if (direction == HandleMovingDirectionNormal) {
1388             if (comparePositions(position->deepEquivalent(), extent) < 0) {
1389                 frameSelection->setBase(*position);
1390                 result = HandleMovingDirectionNormal;
1391             } else if (comparePositions(position->deepEquivalent(), extent) > 0) {
1392                 frameSelection->setExtent(*position);
1393                 frameSelection->setBase(extent);
1394                 result = HandleMovingDirectionReverse;
1395             }
1396         } else if (direction == HandleMovingDirectionReverse) {
1397             if (comparePositions(position->deepEquivalent(), base) > 0) {
1398                 frameSelection->setExtent(*position);
1399                 result = HandleMovingDirectionReverse;
1400             } else if (comparePositions(position->deepEquivalent(), base) < 0) {
1401                 frameSelection->setBase(*position);
1402                 frameSelection->setExtent(base);
1403                 result = HandleMovingDirectionNormal;
1404             }
1405         }
1406
1407         focusedFrame->view()->setProhibitsScrolling(oldProhibitsScrolling);
1408         // This forces webkit to show selection
1409         // m_coreFrame->invalidateSelection();
1410     }
1411 }
1412
1413 void WebPage::setRightSelection(const IntPoint& point, const int direction, int& result)
1414 {
1415     result = HandleMovingDirectionNone;
1416
1417     Frame* focusedFrame = m_page->focusController()->focusedOrMainFrame();
1418     FrameSelection* frameSelection = focusedFrame->selection();
1419
1420     if (!frameSelection->isRange())
1421         return;
1422
1423     Node* selectionStartNode = frameSelection->start().deprecatedNode();
1424     if (!selectionStartNode || !selectionStartNode->renderer())
1425         return;
1426
1427     FrameView* frameView = focusedFrame->view();
1428     if (!frameView)
1429         return;
1430
1431     IntPoint pos = frameView->windowToContents(point);
1432     if (selectionStartNode->rendererIsEditable() && !selectionStartNode->rendererIsRichlyEditable()) {
1433         const int boundariesWidth = 2;
1434
1435         IntRect rect = frameSelection->caretRenderer()->absoluteBoundingBoxRect(true);
1436         // here we cheat input field that we actually are just inside of if
1437         if (pos.y() < rect.y() + boundariesWidth)
1438             pos.setY(rect.y() + boundariesWidth);
1439         else if (pos.y() >= rect.maxY() - boundariesWidth)
1440             pos.setY(rect.maxY() - boundariesWidth - 1);
1441     }
1442
1443     OwnPtr<VisiblePosition> position = adoptPtr(new VisiblePosition(focusedFrame->visiblePositionForPoint(pos)));
1444     Position base = frameSelection->base();
1445     Position extent = frameSelection->extent();
1446
1447     Node* newSelectionEndNode = position->deepEquivalent().deprecatedNode();
1448
1449     // both start and end nodes should be in the same area type: both should be editable or both should be not editable
1450     // Check if the new position is after the base's position
1451     if (newSelectionEndNode
1452         && selectionStartNode->isContentEditable() == newSelectionEndNode->isContentEditable()) {
1453         // Change the 'base' and 'extent' positions to 'start' and 'end' positions.
1454         // We do it, because without this, the other modifications of the selection
1455         // would destroy the 'start' and/or 'end' positions and set them to
1456         // the 'base'/'extent' positions accordingly
1457
1458         VisibleSelection sel(frameSelection->start(), frameSelection->end());
1459         frameSelection->setSelection(sel);
1460
1461         bool oldProhibitsScrolling = focusedFrame->view()->prohibitsScrolling();
1462         focusedFrame->view()->setProhibitsScrolling(true);
1463
1464         if (direction == HandleMovingDirectionNormal) {
1465             if (comparePositions(position->deepEquivalent(), base) > 0) {
1466                 frameSelection->setExtent(*position);
1467                 result = HandleMovingDirectionNormal;
1468             } else if (comparePositions(position->deepEquivalent(), base) < 0) {
1469                 frameSelection->setBase(*position);
1470                 frameSelection->setExtent(base);
1471                 result = HandleMovingDirectionReverse;
1472             }
1473         } else if (direction == HandleMovingDirectionReverse) {
1474             if (comparePositions(position->deepEquivalent(), extent) < 0) {
1475                 frameSelection->setBase(*position);
1476                 result = HandleMovingDirectionReverse;
1477             } else if (comparePositions(position->deepEquivalent(), extent) > 0) {
1478                 frameSelection->setExtent(*position);
1479                 frameSelection->setBase(extent);
1480                 result = HandleMovingDirectionNormal;
1481             }
1482         }
1483
1484         focusedFrame->view()->setProhibitsScrolling(oldProhibitsScrolling);
1485     }
1486 }
1487
1488 void WebPage::getSelectionHandlers(IntRect& leftRect, IntRect& rightRect)
1489 {
1490     Frame* focusedFrame = m_page->focusController()->focusedOrMainFrame();
1491     if (!focusedFrame->selection()->isRange())
1492         return;
1493
1494     // Is this check necessary? Leaving it for safety.
1495     RenderView* root = focusedFrame->contentRenderer();
1496     if (!root)
1497         return;
1498
1499     RefPtr<Range> selectedRange = focusedFrame->selection()->toNormalizedRange();
1500
1501     Vector<IntRect> rects;
1502     selectedRange->boundingBoxEx(rects, true);
1503
1504     unsigned size = rects.size();
1505     if (size > 0) {
1506         leftRect = rects[0];
1507         rightRect = rects[size-1];
1508
1509         // If selection rect size is greater than editor rect size because of round operation,
1510         // selection rect size should be changed to editor rect size.
1511         if (size == 1) {
1512             Element* rootEditableElement = focusedFrame->selection()->rootEditableElement();
1513             if (rootEditableElement) {
1514                 IntRect editorRect = nodeRect(rootEditableElement);
1515
1516 #if ENABLE(TIZEN_WEBKIT2_TEXT_SELECTION)
1517                 if (m_editorState.editorRect != editorRect) {
1518                     EditorState state = editorState();
1519                     state.updateEditorRectOnly = true;
1520                     setEditorState(state);
1521                     send(Messages::WebPageProxy::EditorStateChanged(state));
1522                 }
1523 #endif
1524
1525                 if (leftRect.maxY() > editorRect.maxY()) {
1526                     leftRect.setY(editorRect.y());
1527                     leftRect.setHeight(editorRect.height());
1528                 }
1529
1530                 if (rightRect.maxY() > editorRect.maxY()) {
1531                     rightRect.setY(editorRect.y());
1532                     rightRect.setHeight(editorRect.height());
1533                 }
1534             }
1535         }
1536
1537         // prevent from selecting zero-length selection
1538         if (leftRect.x() == rightRect.x() + rightRect.width()
1539             && leftRect.y() == rightRect.y())
1540             return;
1541
1542         FrameView* frameView = focusedFrame->view();
1543         if (!frameView)
1544             return;
1545
1546         leftRect = frameView->contentsToWindow(leftRect);
1547         rightRect = frameView->contentsToWindow(rightRect);
1548      }
1549 }
1550
1551 void WebPage::getSelectionText(String& result)
1552 {
1553     Frame* focusedFrame = m_page->focusController()->focusedOrMainFrame();
1554     result = focusedFrame->editor()->selectedText();
1555 }
1556
1557 void WebPage::selectionRangeClear(bool& result)
1558 {
1559     result = false;
1560
1561     Frame* focusedFrame = m_page->focusController()->focusedOrMainFrame();
1562     FrameSelection* frameSelection = focusedFrame->selection();
1563     if (frameSelection && frameSelection->isRange() && frameSelection->isContentEditable()) {
1564         VisiblePosition visiblePos(frameSelection->extent());
1565         if (visiblePos.isNull())
1566             return;
1567
1568         focusedFrame->editor()->setIgnoreCompositionSelectionChange(true);
1569         frameSelection->setSelection(VisibleSelection(visiblePos), CharacterGranularity);
1570         focusedFrame->editor()->setIgnoreCompositionSelectionChange(false);
1571
1572         frameSelection->setCaretBlinkingSuspended(false);
1573     } else
1574         selectionClearAllSelection(m_page->mainFrame());
1575
1576     result = true;
1577 }
1578
1579 void WebPage::selectionClearAllSelection(Frame* frame)
1580 {
1581     if (!frame)
1582         return;
1583
1584     FrameSelection* frameSelection = frame->selection();
1585     if (frameSelection)
1586         frameSelection->clear();
1587
1588     if (!frame->tree())
1589         return;
1590
1591     if (frame->tree()->childCount() > 0) {
1592         if (frame->tree()->firstChild())
1593             selectionClearAllSelection(frame->tree()->firstChild());
1594     } else if (frame->tree()->nextSibling())
1595         selectionClearAllSelection(frame->tree()->nextSibling());
1596 }
1597
1598 void WebPage::scrollContentByCharacter(const IntPoint&, int direction, bool& result)
1599 {
1600     result = false;
1601
1602     Frame* focusedFrame = m_page->focusController()->focusedOrMainFrame();
1603     if (!focusedFrame)
1604         return;
1605
1606     FrameSelection* frameSelection = focusedFrame->selection();
1607     if (!frameSelection)
1608         return;
1609
1610     VisiblePosition currentPosition = frameSelection->selection().visibleStart();
1611     if (direction) {
1612         if (isStartOfLine(currentPosition))
1613             return;
1614
1615         focusedFrame->selection()->modify(FrameSelection::AlterationMove, DirectionBackward, CharacterGranularity, UserTriggered);
1616     } else {
1617         if (isEndOfLine(currentPosition))
1618             return;
1619
1620         focusedFrame->selection()->modify(FrameSelection::AlterationMove, DirectionForward, CharacterGranularity, UserTriggered);
1621     }
1622 }
1623
1624 void WebPage::scrollContentByLine(const IntPoint&, int direction, bool& result)
1625 {
1626     result = false;
1627
1628     Frame* focusedFrame = m_page->focusController()->focusedOrMainFrame();
1629     if (!focusedFrame)
1630         return;
1631
1632     FrameSelection* frameSelection = focusedFrame->selection();
1633     if (!frameSelection)
1634         return;
1635
1636     VisiblePosition currentPosition = frameSelection->selection().visibleStart();
1637     if (direction) {
1638         if (inSameLine(currentPosition, previousLinePosition(currentPosition, 0)))
1639             return;
1640
1641         focusedFrame->selection()->modify(FrameSelection::AlterationMove, DirectionBackward, LineGranularity, UserTriggered);
1642     } else {
1643         if (inSameLine(currentPosition, nextLinePosition(currentPosition, 0)))
1644             return;
1645
1646         focusedFrame->selection()->modify(FrameSelection::AlterationMove, DirectionForward, LineGranularity, UserTriggered);
1647     }
1648 }
1649 #endif
1650
1651 #if ENABLE(TIZEN_LINK_MAGNIFIER)
1652 void WebPage::getLinkMagnifierRect(const IntPoint& position, const IntSize& size)
1653 {
1654     send(Messages::WebPageProxy::DidGetLinkMagnifierRect(position, LinkMagnifier::rect(this, position, size)));
1655 }
1656 #endif
1657
1658 #if ENABLE(TIZEN_SCREEN_READER)
1659 static void sendScreenReaderFocusRect(WebPage* page, Node* node)
1660 {
1661     bool isImage = false;
1662     if (node->isElementNode()) {
1663         Element* element = static_cast<Element*>(node);
1664         isImage = !element->getAttribute(element->imageSourceAttributeName()).isEmpty();
1665     }
1666
1667     page->send(Messages::WebPageProxy::DidScreenReaderFocusRectChanged(getNodeRect(node, node, isImage)));
1668 }
1669
1670 void WebPage::moveScreenReaderFocus(bool forward, bool& result)
1671 {
1672     if (!m_screenReader)
1673         m_screenReader = ScreenReader::create(this);
1674
1675     if (!m_screenReader->moveFocus(forward)) {
1676         result = false;
1677         send(Messages::WebPageProxy::DidScreenReaderFocusRectChanged(IntRect()));
1678         return;
1679     } else {
1680         result = true;
1681         sendScreenReaderFocusRect(this, m_screenReader->getFocusedNode());
1682     }
1683 }
1684
1685 void WebPage::moveScreenReaderFocusByPoint(const IntPoint& point)
1686 {
1687     if (!m_screenReader)
1688         m_screenReader = ScreenReader::create(this);
1689
1690     if (!m_screenReader->moveFocus(point))
1691         return;
1692
1693     sendScreenReaderFocusRect(this, m_screenReader->getFocusedNode());
1694 }
1695
1696 void WebPage::clearScreenReaderFocus()
1697 {
1698     if (!m_screenReader)
1699         return;
1700
1701     m_screenReader->clearFocus();
1702 }
1703
1704 void WebPage::raiseTapEvent(const IntPoint& position, const IntPoint& globalPosition, bool& result)
1705 {
1706     result = false;
1707
1708 #if ENABLE(GESTURE_EVENTS)
1709     Frame* frame = m_page->mainFrame();
1710     if (!frame->view())
1711         return;
1712
1713     Vector<WebPlatformTouchPoint> touchPoints;
1714     touchPoints.append(WebPlatformTouchPoint(0, WebPlatformTouchPoint::TouchPressed, globalPosition, position));
1715
1716     WebTouchEvent touchStartEvent(WebEvent::TouchStart, touchPoints, WebEvent::Modifiers(0), ecore_time_get());
1717     bool handled = frame->eventHandler()->handleTouchEvent(platform(touchStartEvent));
1718
1719     touchPoints.at(0).setState(WebPlatformTouchPoint::TouchReleased);
1720
1721     WebTouchEvent touchEndEvent(WebEvent::TouchEnd, touchPoints, WebEvent::Modifiers(0), ecore_time_get());
1722     handled |= frame->eventHandler()->handleTouchEvent(platform(touchEndEvent));
1723
1724     if (!handled) {
1725         WebGestureEvent gestureEvent(WebEvent::GestureSingleTap, position, globalPosition, WebEvent::Modifiers(0), ecore_time_get());
1726         frame->eventHandler()->handleGestureEvent(platform(gestureEvent));
1727         result = true;
1728     }
1729 #endif
1730 }
1731
1732 void WebPage::adjustScreenReaderFocusedObjectValue(bool up)
1733 {
1734     if (!m_screenReader || !m_screenReader->getFocusedNode() || !m_screenReader->getFocusedNode()->toInputElement())
1735         return;
1736
1737     ExceptionCode ec;
1738     if (up)
1739         m_screenReader->getFocusedNode()->toInputElement()->stepUp(ec);
1740     else
1741         m_screenReader->getFocusedNode()->toInputElement()->stepDown(ec);
1742 }
1743
1744 void WebPage::recalcScreenReaderFocusRect()
1745 {
1746     if (!m_screenReader || !m_screenReader->getFocusedNode())
1747         return;
1748
1749     sendScreenReaderFocusRect(this, m_screenReader->getFocusedNode());
1750 }
1751
1752 void WebPage::updateScreenReaderFocus(RenderObject* object)
1753 {
1754     if (!m_screenReader)
1755         return;
1756
1757     if (!object)
1758         m_screenReader->clearFocus();
1759     else if (!m_screenReader->rendererWillBeDestroyed(object))
1760         return;
1761
1762     send(Messages::WebPageProxy::DidScreenReaderFocusRectChanged(IntRect()));
1763 }
1764
1765 void WebPage::clearScreenReader()
1766 {
1767     m_screenReader.clear();
1768 }
1769 #endif
1770
1771 #if ENABLE(TIZEN_SCREEN_READER) || ENABLE(TIZEN_FOCUS_UI) || ENABLE(TIZEN_WEBKIT2_TEXT_SELECTION)
1772 static LayoutRect rectToAbsoluteCoordinates(Frame* initialFrame, const LayoutRect& initialRect)
1773 {
1774     LayoutRect rect = initialRect;
1775     for (Frame* frame = initialFrame; frame; frame = frame->tree()->parent()) {
1776         RenderBoxModelObject* renderer;
1777         if (frame->ownerElement() && (renderer = frame->ownerElement()->renderBoxModelObject())) {
1778             do {
1779                 rect.move(renderer->offsetLeft(), renderer->offsetTop());
1780             } while ((renderer = renderer->offsetParent()));
1781             rect.move(-frame->view()->scrollOffset());
1782         }
1783     }
1784     return rect;
1785 }
1786
1787 IntRect WebPage::nodeRect(Node* node) const
1788 {
1789     if (!node)
1790         return IntRect();
1791
1792     LayoutRect rect;
1793     if (node->hasTagName(HTMLNames::areaTag)) {
1794         HTMLAreaElement* area = static_cast<HTMLAreaElement*>(node);
1795         HTMLImageElement* image = area->imageElement();
1796         if (!image || !image->renderer())
1797             return IntRect();
1798
1799         rect = rectToAbsoluteCoordinates(area->document()->frame(), area->computeRect(area->imageElement()->renderer()));
1800     } else if (node->renderer()) {
1801         if (node->isDocumentNode())
1802             rect = rectToAbsoluteCoordinates(static_cast<Document*>(node)->frame(), static_cast<Document*>(node)->frame()->view()->visibleContentRect());
1803         else {
1804             rect = node->getRect();
1805             rect.intersect(node->renderer()->absoluteClippedOverflowRect());
1806             rect = rectToAbsoluteCoordinates(node->document()->frame(), rect);
1807
1808             rect.move(node->renderer()->style()->borderLeftWidth(), node->renderer()->style()->borderTopWidth());
1809             rect.setWidth(rect.width() - node->renderer()->style()->borderLeftWidth() - node->renderer()->style()->borderRightWidth());
1810             rect.setHeight(rect.height() - node->renderer()->style()->borderTopWidth() - node->renderer()->style()->borderBottomWidth());
1811         }
1812     }
1813
1814     return pixelSnappedIntRect(rect);
1815 }
1816 #endif
1817
1818 #if ENABLE(TIZEN_WEBKIT2_POPUP_INTERNAL)
1819 // FIXME: Currently with cached pages, hiding Popup list menu is not working correctly.
1820 // This patch is a fix allowing any popup list menu to get close for any page navigation.
1821 void WebPage::notifyTransitionToCommitted(bool forNewPage)
1822 {
1823     if (m_activePopupMenu) {
1824         TIZEN_LOGI("");
1825         m_activePopupMenu->hide();
1826         m_activePopupMenu = 0;
1827     }
1828 }
1829 #endif
1830
1831 #if ENABLE(TIZEN_CSP)
1832 void WebPage::setContentSecurityPolicy(const String& policy, uint32_t headerType)
1833 {
1834     Frame* frame = m_page->focusController()->focusedOrMainFrame();
1835     if (!frame)
1836         return;
1837
1838     Document* document = frame->document();
1839     if (!document)
1840         return;
1841
1842     document->contentSecurityPolicy()->didReceiveHeader(policy, static_cast<WebCore::ContentSecurityPolicy::HeaderType>(headerType));
1843 }
1844 #endif
1845
1846 #if ENABLE(TIZEN_INDEXED_DATABASE)
1847 void WebPage::setIndexedDatabaseDirectory(const String& path)
1848 {
1849     m_page->group().groupSettings()->setIndexedDBDatabasePath(path);
1850 }
1851 #endif
1852
1853 #if ENABLE(TIZEN_WEB_STORAGE)
1854 void WebPage::setLocalStorageDirectory(const String& path)
1855 {
1856     m_page->settings()->setLocalStorageDatabasePath(path);
1857 }
1858 #endif
1859
1860 #if ENABLE(TIZEN_USE_SETTINGS_FONT)
1861 void WebPage::useSettingsFont()
1862 {
1863     if (!WebCore::fontCache()->isFontFamliyTizen())
1864         return;
1865
1866     FcInitReinitialize();
1867     WebCore::fontCache()->invalidate();
1868
1869     FrameView* frameView = m_mainFrame->coreFrame()->view();
1870     if (!frameView)
1871         return;
1872
1873     frameView->forceLayout();
1874 }
1875 #endif
1876
1877 void WebPage::didChangeContents(const IntRect& rect)
1878 {
1879     if (!m_page)
1880         return;
1881
1882     Frame* frame = m_page->focusController()->focusedOrMainFrame();
1883     if (!frame || !frame->view() || frame->view()->needsLayout())
1884         return;
1885
1886 #if ENABLE(TIZEN_ISF_PORT) || ENABLE(TIZEN_WEBKIT2_TEXT_SELECTION)
1887     if (m_editorState.isContentEditable && rect.intersects(m_editorState.editorRect) && frame->selection()->rootEditableElement()) {
1888         IntRect currentEditorRect = nodeRect(frame->selection()->rootEditableElement());
1889         if (m_editorState.editorRect != currentEditorRect) {
1890             m_editorState.editorRect = currentEditorRect;
1891             m_editorState.updateEditorRectOnly = true;
1892             send(Messages::WebPageProxy::EditorStateChanged(m_editorState));
1893         }
1894     }
1895 #endif
1896 }
1897 #endif // #if OS(TIZEN)
1898
1899 } // namespace WebKit