Prevent duplicated call of |Terminate|
[platform/framework/web/crosswalk-tizen.git] / runtime / browser / popup.h
1 /*
2  * Copyright (c) 2015 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
18 #ifndef XWALK_RUNTIME_BROWSER_POPUP_H_
19 #define XWALK_RUNTIME_BROWSER_POPUP_H_
20
21 #include <Elementary.h>
22 #include <Evas.h>
23
24 #include <functional>
25 #include <set>
26 #include <string>
27 #include <vector>
28
29 namespace runtime {
30
31 class NativeWindow;
32
33 class Popup {
34  public:
35   enum class ButtonType {
36     OkButton,
37     OkCancelButton,
38     LoginCancelButton,
39     AllowDenyButton
40   };
41
42   enum class EntryType {
43     Edit,
44     PwEdit
45   };
46
47   static Popup* CreatePopup(NativeWindow* window);
48   static void ForceCloseAllPopup();
49
50   // button
51   void SetButtonType(ButtonType type);
52   bool IsPositiveButton(Evas_Object* button);
53   bool GetButtonResult() const;  // yes/allow/ok: true, the others: false
54
55   void SetFirstEntry(const std::string& str_id, EntryType type);
56   void SetSecondEntry(const std::string& str_id, EntryType type);
57   std::string GetFirstEntryResult() const;
58   std::string GetSecondEntryResult() const;
59
60   // check box
61   void SetCheckBox(const std::string& str_id = std::string());
62   bool GetCheckBoxResult() const;
63
64   // etc.
65   void SetTitle(const std::string& str_id);
66   void SetBody(const std::string& str_id);
67   void SetResultHandler(std::function
68       <void(Popup* popup, void* user_data)> handler, void* user_data);
69
70   // Popup's actions
71   void Show();
72   void Hide();
73   void Result(bool is_positive);
74
75   // getter
76   Evas_Object* popup() { return popup_; }
77
78  private:
79   Popup(Evas_Object* popup, Evas_Object* layout, Evas_Object* box);
80   ~Popup();
81
82   Evas_Object* popup_;
83   Evas_Object* layout_;
84   Evas_Object* box_;
85   Evas_Object* button1_;
86   Evas_Object* button2_;
87   Evas_Object* entry1_;
88   Evas_Object* entry2_;
89   Evas_Object* check_box_;
90
91   std::function<void(Popup* popup, void* user_data)> handler_;
92   void* user_data_;
93
94   bool enable_button_;
95   bool result_button_;
96   bool enable_entry_;
97   std::string result_entry1_;
98   std::string result_entry2_;
99   bool enable_check_box_;
100   bool result_check_box_;
101   static std::set<Popup*> opened_popups_;
102 };
103
104 }  // namespace runtime
105
106 #endif  // XWALK_RUNTIME_BROWSER_POPUP_H_