[M108 Migration] Segregate InputPicker into ewk independent base classes
[platform/framework/web/chromium-efl.git] / tizen_src / chromium_impl / content / browser / input_picker / input_picker_base.h
1 // Copyright 2022 Samsung Electronics. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #ifndef CONTENT_BROWSER_INPUT_PICKER_INPUT_PICKER_BASE_H_
6 #define CONTENT_BROWSER_INPUT_PICKER_INPUT_PICKER_BASE_H_
7
8 #include <Evas.h>
9 #include <memory>
10
11 #include "build/build_config.h"
12 #include "ui/base/ime/text_input_type.h"
13
14 #if BUILDFLAG(IS_TIZEN)
15 #include <efl_extension.h>
16 #endif
17
18 namespace content {
19
20 class DateTimeChooserEfl;
21 class WebContents;
22
23 class InputPickerBase {
24  public:
25   InputPickerBase(WebContents* web_contents,
26                   Evas_Object* evas_object,
27                   DateTimeChooserEfl* date_time_chooser);
28   InputPickerBase() = default;
29   virtual ~InputPickerBase() = default;
30
31   InputPickerBase(const InputPickerBase&) = delete;
32   InputPickerBase& operator=(const InputPickerBase&) = delete;
33
34   void ShowColorPicker(int r, int g, int b, int a);
35   void ShowDatePicker(ui::TextInputType input_type, double input_date);
36
37  private:
38   class Layout {
39    public:
40     static Layout* CreateAndShowColorPickerLayout(InputPickerBase* parent,
41                                                   int r,
42                                                   int g,
43                                                   int b);
44     static Layout* CreateAndShowDateLayout(InputPickerBase* parent,
45                                            struct tm* currentTime,
46                                            ui::TextInputType type);
47     static Layout* CreateAndShowDateTimeLayout(InputPickerBase* parent,
48                                                struct tm* currentTime,
49                                                ui::TextInputType type);
50     static Layout* CreateAndShowTimeLayout(InputPickerBase* parent,
51                                            struct tm* currentTime);
52
53     virtual ~Layout();
54
55    private:
56     explicit Layout(InputPickerBase* parent);
57
58     Layout(const Layout&) = delete;
59     Layout& operator=(const Layout&) = delete;
60
61     bool AddBaseLayout(const char* title, const char* layout_group);
62     bool AddButtons();
63     bool AddColorSelector(int r, int g, int b);
64     void AddColorPickerCallbacks();
65     void DeleteColorPickerCallbacks();
66     void AddDatePickerCallbacks();
67     void DeleteDatePickerCallbacks();
68
69     bool SetDatetimePicker(Evas_Object* picker, const char* style);
70
71     static void ColorPickerSelectFinishedCallback(void* data,
72                                                   Evas_Object* obj,
73                                                   void* event_info);
74     static void ColorPickerItemSelectedCallback(void* data,
75                                                 Evas_Object* obj,
76                                                 void* event_info);
77     static void DatePickerSelectFinishedCallback(void* data,
78                                                  Evas_Object* obj,
79                                                  void* event_info);
80     static void DatePickerItemChangedCallback(void* data,
81                                               Evas_Object* obj,
82                                               void* event_info);
83
84     static void ColorPickerBackKeyCallback(void* data,
85                                            Evas_Object* obj,
86                                            void* event_info);
87     static void DatePickerBackKeyCallback(void* data,
88                                           Evas_Object* obj,
89                                           void* event_info);
90
91     InputPickerBase* parent_;
92
93     Evas_Object* conformant_ = nullptr;
94     Evas_Object* popup_ = nullptr;
95     Evas_Object* layout_ = nullptr;
96     Evas_Object* set_button_ = nullptr;
97     Evas_Object* cancel_button_ = nullptr;
98     Evas_Object* color_picker_ = nullptr;
99     Evas_Object* color_rect_ = nullptr;
100     Evas_Object* date_picker_ = nullptr;
101     Evas_Object* time_picker_ = nullptr;
102 #if BUILDFLAG(IS_TIZEN) && !BUILDFLAG(IS_TIZEN_TV)
103     Eext_Circle_Surface* circle_surface_ = nullptr;
104 #endif
105     ui::TextInputType input_type_ = ui::TEXT_INPUT_TYPE_NONE;
106     bool is_color_picker_ = false;
107     int red_ = 0;
108     int green_ = 0;
109     int blue_ = 0;
110   };
111
112   void RemoveColorPicker();
113   void RemoveDatePicker(bool cancel);
114   Evas_Object* GetElmWindow() const;
115
116   virtual void ExecuteEditCommand(const char*, const char*) = 0;
117
118   std::unique_ptr<Layout> picker_layout_;
119   WebContents* web_contents_;
120   Evas_Object* evas_object_;
121   DateTimeChooserEfl* date_time_chooser_;
122 };
123
124 }  // namespace content
125
126 #endif  // CONTENT_BROWSER_INPUT_PICKER_INPUT_PICKER_BASE_H_