1 /* 2 * Copyright (c) 2021 Huawei Device Co., Ltd. 3 * Licensed under the Apache License, Version 2.0 (the "License"); 4 * you may not use this file except in compliance with the License. 5 * You may obtain a copy of the License at 6 * 7 * http://www.apache.org/licenses/LICENSE-2.0 8 * 9 * Unless required by applicable law or agreed to in writing, software 10 * distributed under the License is distributed on an "AS IS" BASIS, 11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 * See the License for the specific language governing permissions and 13 * limitations under the License. 14 */ 15 16 #ifndef OHOS_ACELITE_JS_DIALOG_H 17 #define OHOS_ACELITE_JS_DIALOG_H 18 19 #include "acelite_config.h" 20 #if (FEATURE_MODULE_DIALOG == 1) 21 #include "jsi.h" 22 #include "js_fwk_common.h" 23 #include "non_copyable.h" 24 #include "dialog/js_dialog.h" 25 #include "event_listener.h" 26 #include "ui_dialog.h" 27 28 namespace OHOS { 29 namespace ACELite { 30 class DialogListener; 31 class DismissListener; 32 /** 33 * @brief: The module of dialog, show dialog in window 34 */ 35 class JSDialog final : public MemoryHeap { 36 public: 37 ACE_DISALLOW_COPY_AND_MOVE(JSDialog); 38 JSDialog(); 39 ~JSDialog(); 40 void ReleaseResource(); 41 42 void SetTitle(char *title); 43 void SetMessage(char *message); 44 45 bool ShowDialog(JSIValue thisVal, 46 JSIValue buttons, 47 JSIValue successFunc, 48 JSIValue cancelFunc, 49 JSIValue completeFunc); 50 static void DispatchReleaseRequest(const JSDialog *jsDialog); 51 GetUIDialog()52 const UIDialog *GetUIDialog() const 53 { 54 return dialog_; 55 } 56 57 private: 58 UIDialog *dialog_; 59 DialogListener *dialogListener_; 60 DismissListener *dismissListener_; 61 char *title_; 62 char *message_; 63 64 bool ParseButton(JSDialog *jsDialog, 65 JSIValue buttonArrayObject, 66 JSIValue successFuncObject, 67 JSIValue completeFuncObject, 68 JSIValue context); 69 ColorType ParseButtonColor(const char * const buttonColorText); 70 }; 71 72 class DialogListener final: public UIView::OnClickListener { 73 public: 74 ACE_DISALLOW_COPY_AND_MOVE(DialogListener); 75 DialogListener(JSDialog *jsDialog, uint8_t index, JSIValue successFunc, JSIValue completeFunc, JSIValue context); 76 ~DialogListener(); 77 bool OnClick(UIView &view, const ClickEvent &event) override; 78 79 private: 80 JSDialog *jsDialog_; 81 uint8_t buttonIndex_; 82 JSIValue jsSuccessFunc_; 83 JSIValue jsCompleteFunc_; 84 JSIValue jsContext_; 85 }; 86 87 class DismissListener final : public UIView::OnClickListener { 88 public: 89 ACE_DISALLOW_COPY_AND_MOVE(DismissListener); 90 DismissListener(JSDialog *jsDialog, JSIValue cancelFunc, JSIValue completeFunc, JSIValue context); 91 ~DismissListener(); 92 bool OnClick(UIView &view, const ClickEvent &event) override; 93 94 private: 95 JSDialog *jsDialog_; 96 JSIValue jsCancelFunc_; 97 JSIValue jsCompleteFunc_; 98 JSIValue jsContext_; 99 }; 100 } // namespace ACELite 101 } // namespace OHOS 102 #endif // FEATURE_MODULE_DIALOG 103 #endif // OHOS_ACELITE_DIALOG_MODULE_H 104