Fix lockup issue when key event was occurs frequently by host keyboard
authorSangYong Park <sy302.park@samsung.com>
Wed, 14 Aug 2013 01:45:50 +0000 (10:45 +0900)
committerSangYong Park <sy302.park@samsung.com>
Wed, 14 Aug 2013 02:06:31 +0000 (11:06 +0900)
[Title] Fix lockup issue when key event occurs frequently by host keyboard
[Issue#] N_SE-48592 N_SE-48638
[Problem] App lockup occurs
[Cause] IPC is no reaction by when IPC occurs freqently by key event.
[Solution] Reduce the occurrence of the IPC.

Change-Id: I7995f7e3dfb52c30c4a15a1635b267418833f32e

Source/WebKit2/Shared/EditorState.cpp
Source/WebKit2/Shared/EditorState.h
Source/WebKit2/UIProcess/API/efl/ewk_view.cpp
Source/WebKit2/UIProcess/API/efl/tizen/TextSelection.cpp
Source/WebKit2/UIProcess/WebPageProxy.h
Source/WebKit2/UIProcess/efl/InputMethodContextEfl.cpp
Source/WebKit2/UIProcess/efl/WebPageProxyEfl.cpp
Source/WebKit2/WebProcess/WebPage/WebPage.cpp
Source/WebKit2/WebProcess/WebPage/WebPage.h
Source/WebKit2/WebProcess/WebPage/WebPage.messages.in
Source/WebKit2/WebProcess/WebPage/efl/WebPageEfl.cpp

index b79afda..2a0185c 100755 (executable)
@@ -46,6 +46,7 @@ void EditorState::encode(CoreIPC::ArgumentEncoder* encoder) const
     encoder->encode(inputMethodHints);
     encoder->encode(surroundingText);
     encoder->encode(cursorPosition);
+    encoder->encode(selectionRect);
 #endif
 
 #if ENABLE(TIZEN_WEBKIT2_TEXT_SELECTION)
@@ -108,6 +109,9 @@ bool EditorState::decode(CoreIPC::ArgumentDecoder* decoder, EditorState& result)
 
     if (!decoder->decode(result.cursorPosition))
         return false;
+
+    if (!decoder->decode(result.selectionRect))
+        return false;
 #endif
 
 #if ENABLE(TIZEN_WEBKIT2_TEXT_SELECTION)
index 3248fa2..32c84ef 100755 (executable)
@@ -73,6 +73,7 @@ struct EditorState {
     WTF::String inputMethodHints;
     WTF::String surroundingText;
     unsigned cursorPosition;
+    WebCore::IntRect selectionRect;
 #endif
 #if ENABLE(TIZEN_WEBKIT2_TEXT_SELECTION)
     WebCore::IntRect editorRect;
index cc62359..66868ef 100755 (executable)
@@ -2523,7 +2523,7 @@ bool ewk_view_focused_node_adjust(Evas_Object* ewkView, Eina_Bool adjustForExter
 
     // caret position can be outside of visible rect.
     // we need to consider it.
-    IntRect selectionRect = impl->pageProxy->getSelectionRect(true);
+    IntRect selectionRect = impl->pageProxy->editorState().selectionRect;
     IntRect focusedNodeRect = impl->pageClient->focusedNodeRect();
 #if ENABLE(TIZEN_WEBKIT2_TILED_BACKING_STORE)
     selectionRect.scale(newScaleFactor);
index d7fff1f..980da1f 100644 (file)
@@ -108,8 +108,11 @@ void TextSelection::update()
     if (isTextSelectionMode()) {
         if (!editorState.selectionIsRange) {
             if (editorState.isContentEditable && !evas_object_focus_get(m_viewImpl->view())) {
-                WebCore::IntRect caretRect;
-                m_viewImpl->page()->getCaretPosition(caretRect);
+                const EditorState& editor = m_viewImpl->page()->editorState();
+                IntRect caretRect;
+                if (!editor.selectionIsNone && !editor.selectionIsRange)
+                    caretRect = editor.selectionRect;
+
                 if (!caretRect.isEmpty())
                     return;
             } else {
@@ -295,8 +298,10 @@ void TextSelection::showContextMenu()
         point = leftRect.center();
 #endif
     } else if (editorState.isContentEditable) {
-        WebCore::IntRect caretRect;
-        m_viewImpl->page()->getCaretPosition(caretRect);
+        const EditorState& editor = m_viewImpl->page()->editorState();
+        IntRect caretRect;
+        if (!editor.selectionIsNone && !editor.selectionIsRange)
+            caretRect = editor.selectionRect;
 
         if (caretRect.isEmpty())
             return;
@@ -725,8 +730,11 @@ void TextSelection::informTextStyleState()
     WebCore::IntPoint startPoint, endPoint;
     WebCore::IntRect leftRect, rightRect;
 
-    WebCore::IntRect caretRect;
-    m_viewImpl->page()->getCaretPosition(caretRect);
+    const EditorState& editor = m_viewImpl->page()->editorState();
+    IntRect caretRect;
+    if (!editor.selectionIsNone && !editor.selectionIsRange)
+        caretRect = editor.selectionRect;
+
     if (!caretRect.isEmpty()) {
         startPoint.setX(caretRect.x());
         startPoint.setY(caretRect.y() + caretRect.height());
index 0625414..771a444 100755 (executable)
@@ -497,7 +497,6 @@ public:
 #endif
 #if ENABLE(TIZEN_TEXT_CARET_HANDLING_WK2)
     void setCaretPosition(const WebCore::IntPoint&);
-    void getCaretPosition(WebCore::IntRect&);
 #endif
     bool scrollMainFrameBy(const WebCore::IntSize&);
     void scrollMainFrameTo(const WebCore::IntPoint&);
@@ -959,9 +958,6 @@ public:
 
 #if ENABLE(TIZEN_ISF_PORT)
     void prepareKeyDownEvent();
-    int getCursorOffset();
-    void getSurroundingTextAndCursorOffset(String&, int&);
-    WebCore::IntRect getSelectionRect(bool);
     void deleteSurroundingText(int, int);
 
     void didCancelComposition();
index fab2b9e..731f3c4 100755 (executable)
@@ -167,12 +167,10 @@ Eina_Bool InputMethodContextEfl::onIMFRetrieveSurrounding(void* data, Ecore_IMF_
     if (!inputMethodContext->m_viewImpl->page()->focusedFrame() || !inputMethodContext->m_focused || (!text && !offset))
         return false;
 
-    String surroundingText;
-    int cursorOffset;
-    inputMethodContext->m_viewImpl->page()->getSurroundingTextAndCursorOffset(surroundingText, cursorOffset);
+    const EditorState& editor = inputMethodContext->m_viewImpl->page()->editorState();
 
     if (text) {
-        CString utf8Text(surroundingText.utf8());
+        CString utf8Text(editor.surroundingText.utf8());
         size_t length = utf8Text.length();
 
         *text = static_cast<char*>(malloc((length + 1) * sizeof(char)));
@@ -185,7 +183,7 @@ Eina_Bool InputMethodContextEfl::onIMFRetrieveSurrounding(void* data, Ecore_IMF_
     }
 
     if (offset)
-        *offset = cursorOffset;
+        *offset = editor.cursorPosition;
 
     return true;
 }
@@ -259,10 +257,13 @@ void InputMethodContextEfl::onIMFPreeditSequenceChanged(void* data, Ecore_IMF_Co
 
     inputMethodContext->requestFakeKeyEvent();
 
+    const EditorState& editor = inputMethodContext->m_viewImpl->page()->editorState();
     PageClientImpl* pageClient = inputMethodContext->m_viewImpl->pageClient.get();
     IntRect caretRect;
-    page->getCaretPosition(caretRect);
-    caretRect.scale(pageClient->scaleFactor());
+    if (!editor.selectionIsNone && !editor.selectionIsRange) {
+        caretRect = editor.selectionRect;
+        caretRect.scale(pageClient->scaleFactor());
+    }
 
     int viewX, viewY;
     evas_object_geometry_get(inputMethodContext->m_viewImpl->view(), &viewX, &viewY, 0, 0);
index e4b88c9..e64439f 100755 (executable)
@@ -285,31 +285,6 @@ void WebPageProxy::prepareKeyDownEvent()
     process()->send(Messages::WebPage::PrepareKeyDownEvent(), m_pageID);
 }
 
-int WebPageProxy::getCursorOffset()
-{
-    if (!isValid())
-        return 0;
-
-    int offset = 0;
-    process()->sendSync(Messages::WebPage::GetCursorOffset(), Messages::WebPage::GetCursorOffset::Reply(offset), m_pageID);
-    return offset;
-}
-
-void WebPageProxy::getSurroundingTextAndCursorOffset(String& text, int& offset)
-{
-    if (!isValid())
-        return;
-
-    process()->sendSync(Messages::WebPage::GetSurroundingTextAndCursorOffset(), Messages::WebPage::GetSurroundingTextAndCursorOffset::Reply(text, offset), m_pageID);
-}
-
-IntRect WebPageProxy::getSelectionRect(bool isOnlyEditable)
-{
-    IntRect rect;
-    process()->sendSync(Messages::WebPage::GetSelectionRect(isOnlyEditable), Messages::WebPage::GetSelectionRect::Reply(rect), m_pageID);
-    return rect;
-}
-
 void WebPageProxy::deleteSurroundingText(int offset, int count)
 {
     if (!isValid())
@@ -375,14 +350,6 @@ void WebPageProxy::setCaretPosition(const WebCore::IntPoint& pos)
 
     process()->send(Messages::WebPage::SetCaretPosition(pos), m_pageID);
 }
-
-void WebPageProxy::getCaretPosition(WebCore::IntRect& rect)
-{
-    if (!isValid())
-        return;
-
-    process()->sendSync(Messages::WebPage::GetCaretPosition(), Messages::WebPage::GetCaretPosition::Reply(rect), m_pageID);
-}
 #endif
 
 #if ENABLE(TIZEN_PLUGIN_CUSTOM_REQUEST)
index ee89990..7ab2bf8 100755 (executable)
@@ -571,15 +571,13 @@ EditorState WebPage::editorState() const
     }
 #endif
 
-#if ENABLE(TIZEN_ISF_PORT) || ENABLE(TIZEN_WEBKIT2_TEXT_SELECTION)
+#if ENABLE(TIZEN_ISF_PORT)
     Element* rootEditableElement = frame->selection()->rootEditableElement();
     if (!rootEditableElement)
         return result;
 
-    result.editorRect = nodeRect(rootEditableElement);
-#endif
+    updateEditorStateRect(frame, result);
 
-#if ENABLE(TIZEN_ISF_PORT)
     if (!result.shouldIgnoreCompositionSelectionChange && result.isContentEditable) {
         result.inputMethodContextID = reinterpret_cast<uintptr_t>(rootEditableElement);
 
@@ -608,14 +606,14 @@ EditorState WebPage::editorState() const
                 result.inputMethodHints = "search";
             else
                 result.inputMethodHints = type;
-
-            result.surroundingText = formControl->value();
         }
 
         Position base = frame->selection()->base();
         Node* baseNode = base.containerNode();
-        if (baseNode)
-            result.cursorPosition = baseNode->isTextNode() ? base.offsetInContainerNode() : 0;
+        if (baseNode && baseNode->isTextNode()) {
+            result.surroundingText = baseNode->nodeValue();
+            result.cursorPosition = base.offsetInContainerNode();
+        }
     }
 #endif
 
index 42bb838..fdd52cc 100755 (executable)
@@ -267,7 +267,6 @@ public:
 #if PLATFORM(EFL)
 #if ENABLE(TIZEN_TEXT_CARET_HANDLING_WK2)
     bool setCaretPosition(const WebCore::IntPoint&);
-    void getCaretPosition(WebCore::IntRect&);
 #endif
 #if ENABLE(TIZEN_ISF_PORT)
     void didCancelComposition(WebCore::Node*);
@@ -275,9 +274,6 @@ public:
     void prepareKeyDownEvent();
     void swapKeyPressCommands(Vector<OwnPtr<KeyPressCommand> >&);
 
-    void getCursorOffset(int&);
-    void getSurroundingTextAndCursorOffset(String&, int&);
-    void getSelectionRect(bool, WebCore::IntRect&);
     void deleteSurroundingText(int, int);
 #endif
     void scrollMainFrameBy(const WebCore::IntSize&);
@@ -1036,6 +1032,11 @@ private:
 #if ENABLE(TIZEN_NATIVE_MEMORY_SNAPSHOT)
     void dumpMemorySnapshot();
 #endif
+
+#if ENABLE(TIZEN_ISF_PORT)
+    void updateEditorStateRect(const WebCore::Frame*, EditorState&) const;
+#endif
+
     OwnPtr<WebCore::Page> m_page;
     RefPtr<WebFrame> m_mainFrame;
     RefPtr<InjectedBundleBackForwardList> m_backForwardList;
index 11b2b47..acf5324 100755 (executable)
@@ -346,13 +346,9 @@ messages -> WebPage {
 #if PLATFORM(EFL) && OS(TIZEN)
 #if ENABLE(TIZEN_TEXT_CARET_HANDLING_WK2)
     SetCaretPosition(WebCore::IntPoint pos)
-    GetCaretPosition() -> (WebCore::IntRect rect)
 #endif
 #if ENABLE(TIZEN_ISF_PORT)
     PrepareKeyDownEvent()
-    GetCursorOffset() -> (int offset)
-    GetSurroundingTextAndCursorOffset() -> (String text, int offset)
-    GetSelectionRect(bool isOnlyEditable) -> (WebCore::IntRect rect)
     DeleteSurroundingText(int offset, int count)
 #endif
 #endif
index 785697b..82101ef 100755 (executable)
@@ -645,29 +645,6 @@ bool WebPage::setCaretPosition(const IntPoint& pos)
 
     return true;
 }
-
-void WebPage::getCaretPosition(IntRect& rect)
-{
-    Frame* frame = m_page->focusController()->focusedOrMainFrame();
-    if (!frame)
-        return;
-
-    FrameSelection* controller = frame->selection();
-    if (!controller)
-        return;
-
-    Node* node = controller->start().deprecatedNode();
-    if (!node || !node->renderer() || !node->isContentEditable())
-        return;
-
-    if (controller->isCaret()) {
-        FrameView* frameView = frame->view();
-        if (!frameView)
-            return;
-
-        rect = frameView->contentsToWindow(controller->absoluteCaretBounds());
-    }
-}
 #endif
 
 #if ENABLE(TIZEN_ISF_PORT)
@@ -692,55 +669,6 @@ void WebPage::swapKeyPressCommands(Vector<OwnPtr<KeyPressCommand> >& commands)
     m_keyPressCommands.swap(commands);
 }
 
-void WebPage::getCursorOffset(int& offset)
-{
-    offset = 0;
-    Frame* frame = m_page->focusController()->focusedOrMainFrame();
-    if (!frame || !frame->editor()->canEdit())
-        return;
-
-    Position base = frame->selection()->base();
-    Node* baseNode = base.containerNode();
-    if (baseNode)
-        offset = baseNode->isTextNode() ? base.offsetInContainerNode() : 0;
-}
-
-void WebPage::getSurroundingTextAndCursorOffset(String& text, int& offset)
-{
-    text = String();
-    offset = 0;
-
-    Frame* frame = m_page->focusController()->focusedOrMainFrame();
-    if (!frame || !frame->editor()->canEdit())
-        return;
-
-    Position base = frame->selection()->base();
-    Node* baseNode = base.containerNode();
-    if (baseNode && baseNode->isTextNode()) {
-        text = baseNode->textContent();
-        offset = base.offsetInContainerNode();
-    }
-}
-
-void WebPage::getSelectionRect(bool isOnlyEditable, IntRect& rect)
-{
-    rect = IntRect();
-
-    Frame* frame = m_page->focusController()->focusedFrame();
-    if (!frame || !frame->view())
-        return;
-
-    FrameSelection* selection = frame->selection();
-    Node* node = selection->start().deprecatedNode();
-    if (!node || !node->renderer() || (isOnlyEditable && !node->isContentEditable()))
-        return;
-
-    if (selection->isCaret())
-        rect = frame->view()->contentsToWindow(selection->absoluteCaretBounds());
-    else if (selection->isRange())
-        rect = frame->view()->contentsToWindow(enclosingIntRect(selection->bounds(false)));
-}
-
 void WebPage::deleteSurroundingText(int offset, int count)
 {
     Frame* frame = m_page->focusController()->focusedOrMainFrame();
@@ -764,6 +692,20 @@ void WebPage::deleteSurroundingText(int offset, int count)
     frame->selection()->setSelection(selection);
     frame->editor()->deleteWithDirection(DirectionBackward, CharacterGranularity, false, true);
 }
+
+void WebPage::updateEditorStateRect(const Frame* frame, EditorState& state) const
+{
+    ASSERT(frame->selection()->rootEditableElement());
+
+#if ENABLE(TIZEN_WEBKIT2_TEXT_SELECTION)
+    state.editorRect = nodeRect(frame->selection()->rootEditableElement());
+#endif
+
+    if (frame->selection()->isCaret())
+        state.selectionRect = frame->view()->contentsToWindow(frame->selection()->absoluteCaretBounds());
+    else if (frame->selection()->isRange())
+        state.selectionRect = frame->view()->contentsToWindow(enclosingIntRect(frame->selection()->bounds(false)));
+}
 #endif
 
 #if ENABLE(TIZEN_INPUT_TAG_EXTENSION) || ENABLE(TIZEN_WEBKIT2_FORM_DATABASE)
@@ -1944,9 +1886,10 @@ void WebPage::didChangeContents(const IntRect& rect)
 
 #if ENABLE(TIZEN_ISF_PORT) || ENABLE(TIZEN_WEBKIT2_TEXT_SELECTION)
     if (m_editorState.isContentEditable && rect.intersects(m_editorState.editorRect) && frame->selection()->rootEditableElement()) {
-        IntRect currentEditorRect = nodeRect(frame->selection()->rootEditableElement());
-        if (m_editorState.editorRect != currentEditorRect) {
-            m_editorState.editorRect = currentEditorRect;
+        IntRect previousEditorRect = m_editorState.editorRect;
+        updateEditorStateRect(frame, m_editorState);
+
+        if (m_editorState.editorRect != previousEditorRect) {
             m_editorState.updateEditorRectOnly = true;
             send(Messages::WebPageProxy::EditorStateChanged(m_editorState));
         }