DSWaylandTextInput: fix error and invalid methods to prevent crash 21/242021/1
authorjeon <jhyuni.kang@samsung.com>
Fri, 21 Aug 2020 05:13:06 +0000 (14:13 +0900)
committerSung-Jin Park <sj76.park@samsung.com>
Fri, 21 Aug 2020 10:11:25 +0000 (19:11 +0900)
Change-Id: I4e5f2d2a07e70bfde455417090564644f4aa9ea9

src/DSWaylandServer/DSWaylandInputMethod.cpp
src/DSWaylandServer/DSWaylandInputMethodPrivate.h
src/DSWaylandServer/DSWaylandInputPanel.cpp
src/DSWaylandServer/DSWaylandTextInput.cpp
src/DSWaylandServer/DSWaylandTextInput.h
src/DSWaylandServer/DSWaylandTextInputManager.h
src/DSWaylandServer/DSWaylandTextInputPrivate.h

index 96248dd..fc79bf1 100644 (file)
@@ -495,11 +495,11 @@ DSWaylandInputMethodPrivate::~DSWaylandInputMethodPrivate()
 {
 }
 
-int DSWaylandInputMethodPrivate::getResourceId(Resource *resource)
+int DSWaylandInputMethodPrivate::getResourceId(DSWaylandInputMethodContextPrivate::Resource *resource)
 {
        int id = -1;
 
-       std::multimap<Resource*, int>::iterator it;
+       std::multimap<DSWaylandInputMethodContextPrivate::Resource*, int>::iterator it;
        for (it = __contextMap.begin(); it != __contextMap.end(); it++)
        {
                if (resource == (*it).first)
@@ -512,11 +512,12 @@ int DSWaylandInputMethodPrivate::getResourceId(Resource *resource)
        return id;
 }
 
-DSWaylandServer::wl_input_method::Resource* DSWaylandInputMethodPrivate::getResource(int id)
+DSWaylandInputMethodContextPrivate::Resource* DSWaylandInputMethodPrivate::getResource(int id)
 {
-       Resource *resource = nullptr;
+       DSWaylandInputMethodContextPrivate::Resource *resource = nullptr;
 
-       std::multimap<Resource*, int>::iterator it;
+
+       std::multimap<DSWaylandInputMethodContextPrivate::Resource*, int>::iterator it;
        for (it = __contextMap.begin(); it != __contextMap.end(); it++)
        {
                if (id == (*it).second)
@@ -531,26 +532,28 @@ DSWaylandServer::wl_input_method::Resource* DSWaylandInputMethodPrivate::getReso
 
 void DSWaylandInputMethodPrivate::sendActivate(void *contextResource, int textInputId, bool focusInEvent)
 {
-       Resource *resource = Resource::fromResource((struct ::wl_resource *)contextResource);
-       __contextMap.insert(std::pair<Resource*, int>(resource, textInputId));
+       DSWaylandInputMethodContextPrivate::Resource *resource = DSWaylandInputMethodContextPrivate::Resource::fromResource((struct ::wl_resource *)contextResource);
+       __contextMap.insert(std::pair<DSWaylandInputMethodContextPrivate::Resource*, int>(resource, textInputId));
        send_activate(__resource->handle, (struct ::wl_resource *)contextResource, textInputId, focusInEvent);
 }
 
 void DSWaylandInputMethodPrivate::sendDeactivate(void *contextResource, bool focusInEvent)
 {
-       Resource *resource = Resource::fromResource((struct ::wl_resource *)contextResource);
+       DSWaylandInputMethodContextPrivate::Resource *resource = DSWaylandInputMethodContextPrivate::Resource::fromResource((struct ::wl_resource *)contextResource);
        __contextMap.erase(resource);
        send_deactivate(__resource->handle, (struct ::wl_resource *)contextResource, focusInEvent);
 }
 
-void DSWaylandInputMethodPrivate::showInputPanel(void *contextResource)
+void DSWaylandInputMethodPrivate::showInputPanel(void *contextResource, int textInputId)
 {
-       send_show_input_panel((struct ::wl_resource *)contextResource);
+       //Resource *resource = getResource(textInputId);
+       send_show_input_panel(__resource->handle, (struct ::wl_resource *)contextResource);
 }
 
-void DSWaylandInputMethodPrivate::hideInputPanel(void *contextResource)
+void DSWaylandInputMethodPrivate::hideInputPanel(void *contextResource, int textInputId)
 {
-       send_hide_input_panel((struct ::wl_resource *)contextResource);
+       //Resource *resource = getResource(textInputId);
+       send_hide_input_panel(__resource->handle, (struct ::wl_resource *)contextResource);
 }
 
 void DSWaylandInputMethodPrivate::input_method_bind_resource(Resource *resource)
@@ -631,15 +634,20 @@ void DSWaylandInputMethod::showInputPanel(int textInputId)
        DS_GET_PRIV(DSWaylandInputMethod);
 
        if (__activateContext)
-          priv->showInputPanel(__activateContext);
+          priv->showInputPanel(__activateContext, textInputId);
 }
 
 void DSWaylandInputMethod::hideInputPanel(int textInputId)
 {
        DS_GET_PRIV(DSWaylandInputMethod);
 
+       if (textInputId < 0)
+       {
+               textInputId = priv->getResourceId(DSWaylandInputMethodContextPrivate::Resource::fromResource((struct ::wl_resource *)__activateContext));
+       }
+
        if (__activateContext)
-          priv->hideInputPanel(__activateContext);
+          priv->hideInputPanel(__activateContext, textInputId);
 }
 
 void DSWaylandInputMethod::resetTextInput()
@@ -814,7 +822,7 @@ void DSWaylandInputMethod::contextHideInputPanel(unsigned int serial)
 
        if (__activateContext)
        {
-               priv->hideInputPanel(__activateContext);
+               priv->hideInputPanel(__activateContext, -1);
        }
 }
 
index 1b9cf3d..49a86cf 100644 (file)
@@ -33,6 +33,8 @@
 namespace display_server
 {
 
+class DSWaylandInputMethodContextPrivate;
+
 class DS_DECL_EXPORT DSWaylandInputMethodPrivate : public DSObjectPrivate, public DSWaylandServer::wl_input_method
 {
 DS_PIMPL_USE_PUBLIC(DSWaylandInputMethod);
@@ -42,10 +44,10 @@ public:
 
        void sendActivate(void *contextResource, int textInputId, bool focusInEvent);
        void sendDeactivate(void *contextResource, bool focusInEvent);
-       void showInputPanel(void *contextResource);
-       void hideInputPanel(void *contextResource);
-       int getResourceId(Resource *resource);
-       Resource* getResource(int id);
+       void showInputPanel(void *contextResource, int textInputId);
+       void hideInputPanel(void *contextResource, int textInputId);
+       int getResourceId(DSWaylandInputMethodContextPrivate::Resource *resource);
+       DSWaylandInputMethodContextPrivate::Resource* getResource(int id);
 
 protected:
        void input_method_bind_resource(Resource *resource);
@@ -54,7 +56,7 @@ protected:
 private:
        DSWaylandCompositor *__compositor;
        Resource *__resource;
-       std::multimap<Resource*, int> __contextMap;
+       std::multimap<DSWaylandInputMethodContextPrivate::Resource*, int> __contextMap;
 };
 
 }
index c1f99b0..dc35b73 100644 (file)
@@ -418,6 +418,7 @@ void DSWaylandInputPanelSurfacePrivate::setFloatingPosition(int x, int y)
 
        inputPanelFloating = pub->__inputPanel->getFloatingData();
        (void) inputPanelFloating;
+       (void) floatingData;
 
 #if 0//Unreachable code ! Thus, disable temporarily.
        if (!floatingData || !inputPanelFloating) return;
index a865654..fdfc2dd 100644 (file)
@@ -47,7 +47,7 @@ void DSWaylandTextInputManagerPrivate::text_input_manager_create_text_input(Reso
 {
        DS_GET_PUB(DSWaylandTextInputManager);
 
-       pub->createTextInput((void *)(resource->client()));
+       pub->createTextInput((void *)(resource->client()), id);
 }
 
 
@@ -73,9 +73,9 @@ DSWaylandTextInputManager::~DSWaylandTextInputManager()
 {
 }
 
-void DSWaylandTextInputManager::createTextInput(void *client)
+void DSWaylandTextInputManager::createTextInput(void *client, unsigned int managerId)
 {
-       __textInput->createGlobal(client, allocTextInputId());
+       __textInput->createGlobal(client, managerId, allocTextInputId());
 }
 
 int DSWaylandTextInputManager::allocTextInputId()
@@ -208,9 +208,9 @@ DSWaylandTextInputPrivate::~DSWaylandTextInputPrivate()
 {
 }
 
-void DSWaylandTextInputPrivate::createGlobal(void *client, int id)
+void DSWaylandTextInputPrivate::createGlobal(void *client, unsigned int managerId, int id)
 {
-       Resource *resource = add((struct ::wl_client *)client, 1);
+       Resource *resource = add((struct ::wl_client *)client, managerId, 1);
        __resourceIdMap.insert(std::pair<Resource*, int>(resource, id));
 }
 
@@ -860,11 +860,11 @@ DSWaylandTextInput::~DSWaylandTextInput()
 {
 }
 
-void DSWaylandTextInput::createGlobal(void *client, int id)
+void DSWaylandTextInput::createGlobal(void *client, unsigned int managerId, int id)
 {
        DS_GET_PRIV(DSWaylandTextInput);
 
-       priv->createGlobal(client, id);
+       priv->createGlobal(client, managerId, id);
 }
 
 void DSWaylandTextInput::showInputPanel()
index c40c922..7648814 100644 (file)
@@ -42,7 +42,7 @@ public:
        DSWaylandTextInput(DSWaylandCompositor *compositor, DSWaylandTextInputManager *textInputManager, DSTextInputPrivate *dsTextInputPrivate);
        ~DSWaylandTextInput() override;
 
-       void createGlobal(void *client, int id);
+       void createGlobal(void *client, unsigned int managerId, int id);
        void showInputPanel();
        void hideInputPanel();
 
index 7a314e5..da94210 100644 (file)
@@ -43,7 +43,7 @@ public:
        DSWaylandTextInputManager(DSWaylandCompositor *compositor, DSTextInputPrivate *dsTextInputPrivate);
        ~DSWaylandTextInputManager() override;
 
-       void createTextInput(void *client);
+       void createTextInput(void *client, unsigned int managerId);
        int allocTextInputId();
 
        void contextCommitString(unsigned int serial, std::string text);
index 7d98454..2d168d6 100644 (file)
@@ -40,7 +40,7 @@ public:
        DSWaylandTextInputPrivate(DSWaylandTextInput *p_ptr, DSWaylandCompositor *compositor);
        ~DSWaylandTextInputPrivate() override;
 
-       void createGlobal(void *client, int id);
+       void createGlobal(void *client, unsigned int managerId, int id);
        int getResourceId(Resource *resource);
        void showInputPanel(void *resource);
        void hideInputPanel(Resource *resource, bool forceHide);