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_NG_EVENT_FOCUS_STATE_H 17 #define FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_EVENT_FOCUS_STATE_H 18 19 #include <string> 20 #include "base/memory/ace_type.h" 21 22 namespace OHOS::Ace::NG { 23 class FocusHub; 24 class FrameNode; 25 class EventHub; 26 class GeometryNode; 27 28 enum class FocusType : int32_t { 29 DISABLE = 0, 30 NODE = 1, 31 SCOPE = 2, 32 }; 33 34 class FocusState : public virtual AceType { 35 DECLARE_ACE_TYPE(FocusState, AceType) 36 37 public: 38 FocusState() = default; 39 explicit FocusState(const WeakPtr<EventHub>& eventHub, FocusType type = FocusType::DISABLE) eventHub_(eventHub)40 : eventHub_(eventHub), focusType_(type) 41 {} 42 virtual ~FocusState() = default; 43 SetLastWeakFocusNode(const WeakPtr<FocusHub> & focusHub)44 void SetLastWeakFocusNode(const WeakPtr<FocusHub>& focusHub) 45 { 46 lastWeakFocusNode_ = focusHub; 47 } GetLastWeakFocusNode()48 WeakPtr<FocusHub> GetLastWeakFocusNode() const 49 { 50 return lastWeakFocusNode_; 51 } IsCurrentFocus()52 bool IsCurrentFocus() const 53 { 54 return currentFocus_; 55 } SetCurrentFocus(bool currentFocus)56 void SetCurrentFocus(bool currentFocus) 57 { 58 currentFocus_ = currentFocus; 59 } SetTabStop(bool tabStop)60 void SetTabStop(bool tabStop) 61 { 62 tabStop_ = tabStop; 63 } IsTabStop()64 bool IsTabStop() const 65 { 66 return tabStop_; 67 } 68 RefPtr<FrameNode> GetFrameNode() const; 69 std::string GetFrameName() const; 70 int32_t GetFrameId() const; 71 RefPtr<GeometryNode> GetGeometryNode() const; 72 73 bool currentFocus_ { false }; 74 WeakPtr<EventHub> eventHub_; 75 FocusType focusType_ = FocusType::DISABLE; 76 WeakPtr<FocusHub> lastWeakFocusNode_ { nullptr }; 77 bool tabStop_ { false }; 78 }; 79 } // namespace OHOS::Ace::NG 80 81 #endif