1 /*
2  * Copyright (c) 2021-2022 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_SELECT_RENDER_SELECT_H
17 #define FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_SELECT_RENDER_SELECT_H
18 
19 #include "core/components/common/properties/color.h"
20 #include "core/components/select/select_component.h"
21 #include "core/components/touch_listener/render_touch_listener.h"
22 #include "core/gestures/click_recognizer.h"
23 #include "core/gestures/raw_recognizer.h"
24 #include "core/pipeline/base/render_node.h"
25 
26 namespace OHOS::Ace {
27 
28 class RenderSelect : public RenderNode {
29     DECLARE_ACE_TYPE(RenderSelect, RenderNode);
30 
31 public:
32     void Update(const RefPtr<Component>& component) override;
33     void PerformLayout() override;
34 
OnPaintFinish()35     void OnPaintFinish() override
36     {
37         if (onFocusCallback_) {
38             onFocusCallback_();
39         }
40     }
41 
GetSelectComponent()42     RefPtr<SelectComponent> GetSelectComponent() const
43     {
44         return data_;
45     }
46 
SetFocusCallback(const std::function<void ()> & value)47     void SetFocusCallback(const std::function<void()>& value)
48     {
49         onFocusCallback_ = value;
50     }
51 
SetClickRecognizer(const RefPtr<ClickRecognizer> & clickRecognizer)52     void SetClickRecognizer(const RefPtr<ClickRecognizer>& clickRecognizer)
53     {
54         clickRecognizer_ = clickRecognizer;
55     }
56 
SetRawRecognizer(const RefPtr<RawRecognizer> & rawRecognizer)57     void SetRawRecognizer(const RefPtr<RawRecognizer>& rawRecognizer)
58     {
59         rawRecognizer_ = rawRecognizer;
60     }
61 
62     std::string ProvideRestoreInfo() override;
63 
64 protected:
65     void OnTouchTestHit(
66         const Offset& coordinateOffset, const TouchRestrict& touchRestrict, TouchTestResult& result) override;
67 
68     Size selectSize_;
69     RefPtr<ClickRecognizer> clickRecognizer_;
70     RefPtr<RawRecognizer> rawRecognizer_;
71     RefPtr<SelectComponent> data_;
72     std::function<void()> onFocusCallback_;
73     std::size_t index_ = 0;
74 private:
75     void ApplyRestoreInfo();
76 };
77 
78 } // namespace OHOS::Ace
79 
80 #endif // FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_SELECT_RENDER_SELECT_H
81