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