1 /* 2 * Copyright (c) 2024 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_MANAGER_FOCUS_FOCUS_VIEW_H 17 #define FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_MANAGER_FOCUS_FOCUS_VIEW_H 18 19 #include <list> 20 21 #include "base/memory/ace_type.h" 22 #include "base/memory/referenced.h" 23 #include "base/utils/utils.h" 24 #include "core/components_ng/event/focus_hub.h" 25 26 namespace OHOS::Ace::NG { 27 28 const char ENTRY_ANY_FOCUSVIEW[] = "entry_any_view"; 29 30 class FocusView : public virtual AceType { 31 DECLARE_ACE_TYPE(FocusView, AceType); 32 33 public: 34 FocusView() = default; 35 ~FocusView() override = default; 36 37 virtual std::list<int32_t> GetRouteOfFirstScope() = 0; IsEntryFocusView()38 virtual bool IsEntryFocusView() 39 { 40 return true; 41 } IsFocusViewLegal()42 virtual bool IsFocusViewLegal() 43 { 44 return true; 45 } 46 47 RefPtr<FrameNode> GetFrameNode(); 48 std::string GetFrameName(); 49 int32_t GetFrameId(); 50 51 void FocusViewShow(bool isTriggerByStep = false); 52 void FocusViewHide(); 53 void FocusViewClose(bool isDetachFromTree = false); 54 55 virtual void LostViewFocus(); 56 57 RefPtr<FocusHub> GetFocusHub(); 58 59 static RefPtr<FocusView> GetCurrentFocusView(); 60 RefPtr<FocusView> GetEntryFocusView(); 61 RefPtr<FocusHub> GetViewRootScope(); 62 bool IsViewRootScopeHasLastFocus(); 63 bool IsRootScopeCurrentFocus(); 64 bool IsChildFocusViewOf(const RefPtr<FocusView>& parent); 65 bool HasParentFocusHub(); 66 67 bool RequestDefaultFocus(); 68 bool TriggerFocusMove(); 69 70 void SetIsViewRootScopeFocused(bool isViewRootScopeFocused); GetIsViewRootScopeFocused()71 bool GetIsViewRootScopeFocused() const 72 { 73 return isViewRootScopeFocused_; 74 } 75 SetIsViewHasFocused(bool isViewHasFocused)76 void SetIsViewHasFocused(bool isViewHasFocused) 77 { 78 isViewHasFocused_ = isViewHasFocused; 79 } GetIsViewHasFocused()80 bool GetIsViewHasFocused() const 81 { 82 return isViewHasFocused_; 83 } 84 SetViewRootScope(const RefPtr<FocusHub> & viewRootScope)85 void SetViewRootScope(const RefPtr<FocusHub>& viewRootScope) 86 { 87 if (!viewRootScope) { 88 rootScopeSpecified_ = nullptr; 89 return; 90 } 91 rootScopeSpecified_ = AceType::WeakClaim(AceType::RawPtr(viewRootScope)); 92 } 93 SetIsViewHasShow(bool isViewHasShow)94 void SetIsViewHasShow(bool isViewHasShow) 95 { 96 isViewHasShow_ = isViewHasShow; 97 } 98 GetIsViewHasShow()99 bool GetIsViewHasShow() const 100 { 101 return isViewHasShow_; 102 } 103 104 std::pair<bool, bool> HandleDefaultFocusNode( 105 const RefPtr<FocusHub>& defaultFocusNode, bool isViewRootScopeHasChildFocused); 106 107 void FocusViewDidShow(const RefPtr<FocusHub>& focusHub); 108 109 private: 110 bool neverShown_ = true; 111 bool isViewRootScopeFocused_ = true; 112 bool isViewHasFocused_ = false; 113 bool isViewHasShow_ = false; 114 bool firstFlush_ = true; 115 116 WeakPtr<FocusHub> rootScopeSpecified_; 117 bool GetFocusViewFocusable(); 118 119 ACE_DISALLOW_COPY_AND_MOVE(FocusView); 120 }; 121 } // namespace OHOS::Ace::NG 122 123 #endif // FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_MANAGER_FOCUS_FOCUS_VIEW_H 124