[WRTjs] Refactor popup
[platform/framework/web/chromium-efl.git] / wrt / src / browser / popup.h
1 /*
2  * Copyright (c) 2019 Samsung Electronics Co., Ltd All Rights Reserved
3  *
4  *    Licensed under the Apache License, Version 2.0 (the "License");
5  *    you may not use this file except in compliance with the License.
6  *    You may obtain a copy of the License at
7  *
8  *        http://www.apache.org/licenses/LICENSE-2.0
9  *
10  *    Unless required by applicable law or agreed to in writing, software
11  *    distributed under the License is distributed on an "AS IS" BASIS,
12  *    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  *    See the License for the specific language governing permissions and
14  *    limitations under the License.
15  */
16
17 #ifndef BROWSER_POPUP_H_
18 #define BROWSER_POPUP_H_
19
20 #include <Elementary.h>
21
22 #include <string>
23
24 #include "base/functional/callback.h"
25
26 namespace wrt {
27
28 class Popup {
29  public:
30   enum class ButtonType {
31     OkButton,
32     OkCancelButton,
33     LoginCancelButton,
34     AllowDenyButton
35   };
36
37   enum class EntryType {
38     Edit,
39     PwEdit
40   };
41
42   static std::unique_ptr<Popup> CreatePopup(Evas_Object* window);
43   static void Show(std::unique_ptr<Popup> popup);
44   static void ForceCloseAllPopup();
45
46   virtual ~Popup();
47
48   virtual void SetButtonType(ButtonType type);
49   virtual void SetCheckBox(const std::string& id);
50
51   void SetFirstEntry(const std::string& id, EntryType type);
52   void SetSecondEntry(const std::string& id, EntryType type);
53   void SetTitle(const std::string& id);
54   void SetBody(const std::string& id);
55
56   typedef base::OnceCallback<void(
57       bool is_positive, bool is_checked,
58       const std::string& entry1, const std::string& entry2)>
59       ResultHandler;
60
61   void SetResultHandler(ResultHandler handler);
62
63  protected:
64   Popup(Evas_Object* popup, Evas_Object* box);
65
66   virtual Evas_Object* AddEntry(const char* id, Popup::EntryType type);
67   virtual void ShowInternal(std::unique_ptr<Popup> popup);
68
69   Evas_Object* popup_;
70   Evas_Object* button2_ = nullptr;
71   Evas_Object* button1_ = nullptr;
72
73   std::string edjeFilePath_ = std::string();
74   std::string checkStyle_ = std::string();
75
76   static std::vector<std::unique_ptr<Popup>> opened_popups_;
77
78  private:
79   Evas_Object* AddButton(const char* id, const char* content,
80                          const char* button_style);
81
82   void HandleButtonClickEvent(Evas_Object* button);
83
84   void Hide();
85
86   Evas_Object* box_;
87   Evas_Object* entry1_ = nullptr;
88   Evas_Object* entry2_ = nullptr;
89   Evas_Object* check_box_ = nullptr;
90
91   ResultHandler handler_;
92 };
93
94 }  // namespace wrt
95
96 #endif  // BROWSER_POPUP_H_