DSWindowShell/DSWindow : handle set/get Parent 99/242099/1
authorDoyoun Kang <doyoun.kang@samsung.com>
Sat, 22 Aug 2020 07:49:29 +0000 (16:49 +0900)
committerSung-Jin Park <sj76.park@samsung.com>
Mon, 24 Aug 2020 06:32:28 +0000 (15:32 +0900)
Change-Id: I99f21cf923b640213e48fc8c9c186f9fa213ddc6

src/DSWindow/DSWindow.cpp
src/DSWindow/DSWindow.h
src/DSWindow/DSWindowPrivate.h
src/DSWindowShell/DSWindowShell.cpp
src/DSWindowShell/DSWindowShell.h
src/DSWindowShell/DSWindowShellPrivate.cpp
src/DSWindowShell/DSWindowShellPrivate.h
tests/DSWindow-test.cpp
tests/DSWindowShell-test.cpp

index 4f063fc..1657a07 100644 (file)
@@ -32,6 +32,7 @@ namespace display_server
 DSWindowPrivate::DSWindowPrivate(DSWindow *p_ptr)
        : DSObjectPrivate(p_ptr),
          __p_ptr(p_ptr),
+         __parent(nullptr),
          __x(0),
          __y(0),
          __w(0),
@@ -68,6 +69,16 @@ void DSWindowPrivate::destroy(void)
 {
 }
 
+void DSWindowPrivate::setParent(DSWindow *parent)
+{
+       __parent = parent;
+}
+
+DSWindow *DSWindowPrivate::getParent(void)
+{
+       return __parent;
+}
+
 bool DSWindowPrivate::show(void)
 {
        return true;
@@ -252,6 +263,20 @@ void DSWindow::destroy(void)
        priv->destroy();
 }
 
+void DSWindow::setParent(DSWindow *parent)
+{
+       if (parent == this) return;
+
+       DS_GET_PRIV(DSWindow);
+       priv->setParent(parent);
+}
+
+DSWindow *DSWindow::getParent(void)
+{
+       DS_GET_PRIV(DSWindow);
+       return priv->getParent();
+}
+
 bool DSWindow::show(void)
 {
        DS_GET_PRIV(DSWindow);
index 9024dbc..2907456 100644 (file)
@@ -49,6 +49,9 @@ public:
        bool create(std::shared_ptr<DSWaylandSurface> waylandSurface);
        void destroy(void);
 
+       void setParent(DSWindow *parent);
+       DSWindow *getParent(void);
+
        bool show(void);
        bool hide(bool autoFocus = true);
        int  showState(void);
index 8b429e6..b8be9ee 100644 (file)
@@ -46,6 +46,9 @@ public:
        bool create(std::shared_ptr<DSWaylandSurface> waylandSurface);
        void destroy(void);
 
+       void setParent(DSWindow *parent);
+       DSWindow *getParent(void);
+
        bool show(void);
        bool hide(bool autoFocus);
        int  showState(void);
@@ -75,6 +78,8 @@ public:
 private:
        void __onSurfaceCommitted(std::shared_ptr<DSWaylandSurfaceCommitInfo> waylandSurfaceCommitInfo);
 
+       DSWindow *__parent;
+       std::list<DSWindow*> __childList;
        int __x, __y;
        unsigned int __w;
        unsigned int __h;
index 357f5d1..c6a0e7c 100644 (file)
@@ -67,6 +67,39 @@ IDSWaylandShellSurface *DSWindowShell::getShellSurface(void)
        return priv->getShellSurface();
 }
 
+DSWindow *DSWindowShell::getWindow(void)
+{
+       DS_GET_PRIV(DSWindowShell);
+       return priv->getWindow();
+}
+
+bool DSWindowShell::setParent(DSWindowShell *parentWinShell)
+{
+       if (parentWinShell == this)
+               return false;
+
+       DS_GET_PRIV(DSWindowShell);
+       return priv->setParent(parentWinShell);
+}
+
+DSWindowShell *DSWindowShell::getParent(void)
+{
+       DS_GET_PRIV(DSWindowShell);
+       return priv->getParent();
+}
+
+bool DSWindowShell::addChild(DSWindowShell *childWinShell)
+{
+       DS_GET_PRIV(DSWindowShell);
+       return priv->addChild(childWinShell);
+}
+
+void DSWindowShell::removeChild(DSWindowShell *childWinShell)
+{
+       DS_GET_PRIV(DSWindowShell);
+       priv->removeChild(childWinShell);
+}
+
 bool DSWindowShell::setTitle(const std::string &title)
 {
        DS_GET_PRIV(DSWindowShell);
@@ -137,7 +170,8 @@ int  DSWindowShell::showState(void)
 
 bool DSWindowShell::setLayer(int layer)
 {
-       return true;
+       DS_GET_PRIV(DSWindowShell);
+       return priv->setLayer(layer);
 }
 
 int  DSWindowShell::getLayer(void)
index c0aa944..0fe1f6d 100644 (file)
@@ -50,6 +50,14 @@ public:
        void setShellSurface(IDSWaylandShellSurface *zxdgSurface);
        IDSWaylandShellSurface *getShellSurface(void);
 
+       DSWindow *getWindow(void);
+
+       bool setParent(DSWindowShell *parentWinShell);
+       DSWindowShell *getParent(void);
+
+       bool addChild(DSWindowShell *childWinShell);
+       void removeChild(DSWindowShell *childWinShell);
+
        bool setTitle(const std::string &title);
 
        bool setSkipFocus(bool set);
index 62dcd98..1b766c9 100644 (file)
@@ -38,7 +38,8 @@ DSWindowShellPrivate::DSWindowShellPrivate(DSWindowShell *p_ptr, DSWindow *windo
          __x(0), __y(0),
          __w(0), __h(0),
          __reqX(0), __reqY(0),
-         __reqW(0), __reqH(0)
+         __reqW(0), __reqH(0),
+         __parent(nullptr)
 {
 }
 
@@ -47,6 +48,56 @@ DSWindowShellPrivate::~DSWindowShellPrivate()
 
 }
 
+bool DSWindowShellPrivate::__findInChildList(DSWindowShell *parentWinShell)
+{
+       for (auto ws : __childList)
+       {
+               if (ws == parentWinShell)
+                       return true;
+       }
+
+       return false;
+}
+
+bool DSWindowShellPrivate::__setParent(DSWindowShell *parentWinShell)
+{
+       DS_GET_PUB(DSWindowShell);
+
+       if (__parent == parentWinShell)
+               return true;
+
+       if (__findInChildList(parentWinShell))
+       {
+               DSLOG_ERR("DSWindowShell", "Fatal error. Set parent each other. winShell:%p, parentWinShell:%p", pub, parentWinShell);
+               return false;
+       }
+
+       if (__parent)
+       {
+               // remove this from old parent's child list
+               __parent->removeChild(pub);
+       }
+
+       __parent = parentWinShell;
+       if (__parent)
+       {
+               __parent->addChild(pub);
+       }
+
+       if (__window)
+       {
+               if (__parent)
+               {
+                       DSWindow *parentWin = __parent->getWindow();
+                       __window->setParent(parentWin);
+               }
+               else
+                       __window->setParent(nullptr);
+       }
+
+       return true;
+}
+
 
 bool DSWindowShellPrivate::create(DSWindowShell *pParent)
 {
@@ -86,6 +137,32 @@ IDSWaylandShellSurface *DSWindowShellPrivate::getShellSurface(void)
        return __shellSurface;
 }
 
+DSWindow *DSWindowShellPrivate::getWindow(void)
+{
+       return __window;
+}
+
+bool DSWindowShellPrivate::setParent(DSWindowShell *parentWinShell)
+{
+       return __setParent(parentWinShell);
+}
+
+DSWindowShell *DSWindowShellPrivate::getParent(void)
+{
+       return __parent;
+}
+
+bool DSWindowShellPrivate::addChild(DSWindowShell *childWinShell)
+{
+       __childList.push_back(childWinShell);
+       return true;
+}
+
+void DSWindowShellPrivate::removeChild(DSWindowShell *childWinShell)
+{
+       __childList.remove(childWinShell);
+}
+
 bool DSWindowShellPrivate::setTitle(const std::string &title)
 {
        if (__window)
@@ -184,12 +261,13 @@ int  DSWindowShellPrivate::showState(void)
 
 bool DSWindowShellPrivate::setLayer(int layer)
 {
+       __layer = layer;
        return true;
 }
 
 int  DSWindowShellPrivate::getLayer(void)
 {
-       return 0;
+       return __layer;
 }
 
 
index 77582d1..3340a31 100644 (file)
@@ -46,6 +46,14 @@ public:
        void setShellSurface(IDSWaylandShellSurface *shellSurface);
        IDSWaylandShellSurface *getShellSurface(void);
 
+       DSWindow *getWindow(void);
+
+       bool setParent(DSWindowShell *parentWinShell);
+       DSWindowShell *getParent(void);
+
+       bool addChild(DSWindowShell *childWinShell);
+       void removeChild(DSWindowShell *childWinShell);
+
        bool setTitle(const std::string &title);
 
        bool setSkipFocus(bool set);
@@ -100,14 +108,19 @@ public:
 
 private:
        bool __create(int x, int y, unsigned int w, unsigned int h, DSWindowShell *pWin, DSWindowShell *pParent);
+       bool __findInChildList(DSWindowShell *parentWinShell);
+       bool __setParent(DSWindowShell *parentWinShell);
 
 private:
        DSWindow *__window;
        IDSWaylandShellSurface *__shellSurface;
        int __x, __y;
        unsigned int __w, __h;
+       int __layer;
        int __reqX, __reqY;
        unsigned int __reqW, __reqH;
+       DSWindowShell *__parent;
+       std::list<DSWindowShell*> __childList;
 };
 
 }
index c037f6d..d591563 100644 (file)
@@ -164,3 +164,23 @@ TEST_F(DSWindowTest, SkipFocusTest)
        EXPECT_TRUE(skip == false);
 }
 
+TEST_F(DSWindowTest, ParentTest)
+{
+       auto parent = std::make_shared<DSWindow>();
+       EXPECT_TRUE(parent != nullptr);
+       EXPECT_TRUE(parent->getParent() == nullptr);
+
+       auto child = std::make_shared<DSWindow>();
+       EXPECT_TRUE(child != nullptr);
+       EXPECT_TRUE(child->getParent() == nullptr);
+
+       child->setParent(parent.get());
+       EXPECT_TRUE(child->getParent() == parent.get());
+
+       child->setParent(nullptr);
+       EXPECT_TRUE(child->getParent() == nullptr);
+
+       child->setParent(child.get());
+       EXPECT_TRUE(child->getParent() == nullptr);
+}
+
index 73af28c..01fba49 100644 (file)
@@ -62,6 +62,31 @@ TEST_F(DSWindowShellTest, create_P2)
        EXPECT_TRUE(shell->create(0, 0, 720, 1280, nullptr) == true);
 }
 
+TEST_F(DSWindowShellTest, parent_P1)
+{
+       auto window = std::make_shared<DSWindow>();
+       std::unique_ptr<DSWindowShell> shell = std::make_unique<DSWindowShell>(window.get());
+       EXPECT_TRUE(shell != nullptr);
+
+       EXPECT_TRUE(shell->getParent() == nullptr);
+
+       auto childWindow = std::make_shared<DSWindow>();
+       std::unique_ptr<DSWindowShell> childShell = std::make_unique<DSWindowShell>(childWindow.get());
+       EXPECT_TRUE(childShell != nullptr);
+
+       EXPECT_TRUE(childShell->setParent(shell.get()) == true);
+       EXPECT_TRUE(childShell->getParent() == shell.get());
+
+       // test for set parent each other
+       EXPECT_TRUE(shell->setParent(childShell.get()) == false);
+
+       // test for set parent itself
+       EXPECT_TRUE(childShell->setParent(childShell.get()) == false);
+
+       EXPECT_TRUE(childShell->setParent(nullptr) == true);
+       EXPECT_TRUE(childShell->getParent() == nullptr);
+}
+
 TEST_F(DSWindowShellTest, setPosition_P1)
 {
        auto window = std::make_shared<DSWindow>();