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 FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_MENU_MENU_ELEMENT_H
17 #define FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_MENU_MENU_ELEMENT_H
18 
19 #include "core/components/box/render_box.h"
20 #include "core/components/menu/menu_component.h"
21 #include "core/components/select_popup/select_popup_component.h"
22 #include "core/pipeline/base/composed_element.h"
23 
24 namespace OHOS::Ace {
25 
26 class MenuElement : public ComposedElement {
27     DECLARE_ACE_TYPE(MenuElement, ComposedElement);
28 
29 public:
MenuElement(const ComposeId & id)30     explicit MenuElement(const ComposeId& id) : ComposedElement(id) {}
31     ~MenuElement() override = default;
32 
33     void PerformBuild() override;
34 
SetMenuShow(bool status)35     void SetMenuShow(bool status)
36     {
37         menuShow_ = status;
38     }
39 
GetMenuShow()40     bool GetMenuShow()
41     {
42         return menuShow_;
43     }
44 
GetSelectOptions()45     std::vector<RefPtr<OptionComponent>> GetSelectOptions()
46     {
47         if (data_) {
48             return data_->GetOptions();
49         }
50         return std::vector<RefPtr<OptionComponent>>();
51     }
52 
53 private:
54     void OnTargetCallback(const ComposeId& id, const Offset& point);
55     void OnTargetContextCallback(const ComposeId& id, const Offset& point);
56     void OnOptionCallback(std::size_t index);
57     void OnCanceledCallback();
58     RefPtr<RenderBox> GetBoxRenderChild(const RefPtr<Element>& element);
59 
60     RefPtr<SelectPopupComponent> popup_;
61     RefPtr<MenuComponent> data_;
62     std::function<void(const std::string&)> jsSuccessCallback_;
63     std::function<void(const std::string&)> jsCancelCallback_;
64     bool menuShow_ = false;
65 };
66 
67 } // namespace OHOS::Ace
68 
69 #endif // FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_MENU_MENU_ELEMENT_H
70