• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2025 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 #include "core/components_ng/event/focus_hub.h"
17 #include "core/pipeline_ng/pipeline_context.h"
18 
19 namespace OHOS::Ace::NG {
RemoveSelfMultiThread(BlurReason reason)20 void FocusHub::RemoveSelfMultiThread(BlurReason reason)
21 {
22     auto frameNode = GetFrameNode();
23     CHECK_NULL_VOID(frameNode);
24     frameNode->PostAfterAttachMainTreeTask([weak = WeakClaim(this), reason]() {
25         auto focusHub = weak.Upgrade();
26         CHECK_NULL_VOID(focusHub);
27         focusHub->RemoveSelfExecuteFunction(reason);
28     });
29 }
30 
RemoveSelfExecuteFunction(BlurReason reason)31 void FocusHub::RemoveSelfExecuteFunction(BlurReason reason)
32 {
33     if (SystemProperties::GetDebugEnabled()) {
34         TAG_LOGD(AceLogTag::ACE_FOCUS, "%{public}s/" SEC_PLD(%{public}d) " remove self focus.",
35             GetFrameName().c_str(), SEC_PARAM(GetFrameId()));
36     }
37     auto frameNode = GetFrameNode();
38     CHECK_NULL_VOID(frameNode);
39     auto focusHub = frameNode->GetOrCreateFocusHub();
40     CHECK_NULL_VOID(focusHub);
41     auto focusView = frameNode->GetPattern<FocusView>();
42     auto* pipeline = frameNode->GetContext();
43     auto screenNode = pipeline ? pipeline->GetScreenNode() : nullptr;
44     auto screenFocusHub = screenNode ? screenNode->GetFocusHub() : nullptr;
45     auto parent = GetParentFocusHub();
46     if (parent && parent != screenFocusHub && !focusView) {
47         parent->RemoveChild(AceType::Claim(this), reason);
48     } else if (IsCurrentFocus()) {
49         FocusManager::FocusGuard guard(parent, SwitchingStartReason::REMOVE_SELF);
50         LostFocus(reason);
51     }
52     if (!focusScopeId_.empty()) {
53         RemoveFocusScopeIdAndPriority();
54     }
55 }
56 } // namespace OHOS::Ace::NG
57