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_DECLARATION_COMMON_METHOD_H
17 #define FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_DECLARATION_COMMON_METHOD_H
18 
19 #include "core/components/declaration/common/controllers.h"
20 #include "frameworks/core/components/scroll/scroll_position_controller.h"
21 
22 namespace OHOS::Ace {
23 
24 enum class MethodTag {
25     COMMON_METHOD = 0,
26     SPECIALIZED_METHOD,
27     UNKNOWN,
28     DEFAULT,
29 };
30 
31 struct Method {
IsValidMethod32     bool IsValid() const
33     {
34         return tag != MethodTag::UNKNOWN;
35     }
36 
IsSharedMethod37     bool IsShared() const
38     {
39         return isShared;
40     }
41 
42     bool isShared = true;
43     MethodTag tag = MethodTag::DEFAULT;
44 };
45 
46 struct CommonMethod : Method {
FocusCommonMethod47     void Focus(const RefPtr<FocusableController>& focusableController, bool shouldFocus) const
48     {
49         if (focusableController) {
50             focusableController->RequestFocus(shouldFocus);
51         }
52     }
53 
ScrollByCommonMethod54     void ScrollBy(const RefPtr<ScrollPositionController>& positionController, double dx, double dy, bool isSmooth) const
55     {
56         if (positionController) {
57             positionController->ScrollBy(dx, dy, isSmooth);
58         }
59     }
60 };
61 
62 } // namespace OHOS::Ace
63 
64 #endif // FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_DECLARATION_COMMON_METHOD_H
65