4137c4429e55a6bd79b8629b1b224f56c792d66b
[platform/framework/web/chromium-efl.git] / wrt / src / browser / wrt_input_picker.cc
1 // Copyright 2019 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 #if !defined(WRT_JS_BRINGUP)
6 #include "wrt/src/browser/wrt_input_picker.h"
7
8 #include "content/browser/web_contents/web_contents_impl.h"
9 #include "wrt/src/browser/wrt_native_window.h"
10
11 namespace wrt {
12
13 WRTInputPicker::WRTInputPicker(content::WebContents* web_contents,
14                                Evas_Object* evas_object,
15                                content::DateTimeChooserEfl* date_time_chooser)
16     : content::InputPickerBase(web_contents, evas_object, date_time_chooser),
17       web_contents_(web_contents) {}
18
19 Evas_Object* WRTInputPicker::GetElmWindow() {
20   auto* window = WRTNativeWindow::FromWebContents(web_contents_);
21   return static_cast<Evas_Object*>(window->GetNativeWindow());
22 }
23
24 void WRTInputPicker::ExecuteEditCommand(const char* command,
25                                         const char* value) {
26   if (!command)
27     return;
28
29   content::WebContentsImpl* wc =
30       static_cast<content::WebContentsImpl*>(web_contents_);
31   if (!wc)
32     return;
33
34   if (auto* input_handler = wc->GetFocusedFrameWidgetInputHandler()) {
35     absl::optional<std::u16string> optional_value;
36     optional_value = value ? absl::make_optional(base::ASCIIToUTF16(value))
37                            : absl::nullopt;
38     input_handler->ExecuteEditCommand(std::string(command), optional_value);
39   }
40 }
41
42 Evas_Object* WRTInputPicker::GetWebView() {
43   return static_cast<Evas_Object*>(web_contents_->GetNativeView());
44 }
45
46 }  // namespace wrt
47 #endif