[WRTjs] Enable WRTjs
[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 #include <Evas.h>
22
23 #include <string>
24
25 #include "base/callback.h"
26
27 #if defined(OS_TIZEN_TV_PRODUCT)
28 #include "base/timer/timer.h"
29 #endif
30
31 namespace wrt {
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 std::unique_ptr<Popup> CreatePopup(Evas_Object* window);
48   static void Show(std::unique_ptr<Popup> popup);
49   static void ForceCloseAllPopup();
50
51   ~Popup();
52
53   void SetButtonType(ButtonType type);
54   void SetFirstEntry(const std::string& id, EntryType type);
55   void SetSecondEntry(const std::string& id, EntryType type);
56   void SetCheckBox(const std::string& id);
57   void SetTitle(const std::string& id);
58   void SetBody(const std::string& id);
59
60   typedef base::OnceCallback<void(
61       bool is_positive, bool is_checked,
62       const std::string& entry1, const std::string& entry2)>
63       ResultHandler;
64
65   void SetResultHandler(ResultHandler handler);
66
67 #if defined(OS_TIZEN_TV_PRODUCT)
68   static void ShowVoiceRecognitionToast(const std::string& app_title);
69   static void HideVoiceRecognitionToast();
70
71   void HandleEntryKeyDownEvent(const std::string& key);
72 #endif
73
74  private:
75   Popup(Evas_Object* popup, Evas_Object* box);
76
77   Evas_Object* AddButton(const char* id, const char* content,
78                          const char* button_style);
79   Evas_Object* AddEntry(const char* id, Popup::EntryType type);
80
81   void HandleButtonClickEvent(Evas_Object* button);
82
83   void Hide();
84
85 #if defined(OS_TIZEN_TV_PRODUCT)
86   void Timeout();
87
88   base::OneShotTimer timeout_timer_;
89 #endif
90
91   Evas_Object* popup_;
92   Evas_Object* box_;
93   Evas_Object* button1_ = nullptr;
94   Evas_Object* button2_ = nullptr;
95   Evas_Object* entry1_ = nullptr;
96   Evas_Object* entry2_ = nullptr;
97   Evas_Object* check_box_ = nullptr;
98
99   ResultHandler handler_;
100
101 #ifdef OS_TIZEN_WEARABLE_PRODUCT
102   Evas_Object* layout_ = nullptr;
103 #endif
104 };
105
106 }  // namespace wrt
107
108 #endif  // BROWSER_POPUP_H_