1 /* 2 * Copyright (c) 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 #include "components/ui_tree_manager.h" 17 18 namespace OHOS { GetInstance()19UITreeManager& UITreeManager::GetInstance() 20 { 21 static UITreeManager manager; 22 return manager; 23 } 24 RegistViewLifeEvent(ViewFunc * func)25void UITreeManager::RegistViewLifeEvent(ViewFunc* func) 26 { 27 auto p = lifeEvents_.Begin(); 28 if (func == nullptr) { 29 return; 30 } 31 while (p != lifeEvents_.End()) { 32 if (p->data_ == func) { 33 return; 34 } 35 p = p->next_; 36 } 37 lifeEvents_.PushBack(func); 38 } 39 UnregistViewLifeEvent(ViewFunc * func)40void UITreeManager::UnregistViewLifeEvent(ViewFunc* func) 41 { 42 auto p = lifeEvents_.Begin(); 43 while (p != lifeEvents_.End()) { 44 if (p->data_ == func) { 45 lifeEvents_.Remove(p); 46 return; 47 } 48 p = p->next_; 49 } 50 } 51 GetLastEvent(UIView * & view,ViewLifeEvent & event)52void UITreeManager::GetLastEvent(UIView*& view, ViewLifeEvent& event) 53 { 54 view = lastEventView_; 55 event = lastEvent_; 56 } 57 OnLifeEvent(UIView * view,ViewLifeEvent event)58void UITreeManager::OnLifeEvent(UIView* view, ViewLifeEvent event) 59 { 60 lastEventView_ = view; 61 lastEvent_ = event; 62 auto p = lifeEvents_.Begin(); 63 while (p != lifeEvents_.End()) { 64 p->data_(); 65 p = p->next_; 66 } 67 } 68 69 } // namespace OHOS 70