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 #include "core/common/form_manager.h"
17
18 namespace OHOS::Ace {
FormManager()19 FormManager::FormManager() {}
20
~FormManager()21 FormManager::~FormManager() {}
22
AddSubContainer(int64_t formId,const RefPtr<SubContainer> & subContainer)23 void FormManager::AddSubContainer(int64_t formId, const RefPtr<SubContainer>& subContainer)
24 {
25 std::lock_guard<std::mutex> lock(mutex_);
26 subContainerMap_.insert_or_assign(formId, subContainer);
27 }
28
RemoveSubContainer(int64_t formId)29 void FormManager::RemoveSubContainer(int64_t formId)
30 {
31 std::lock_guard<std::mutex> lock(mutex_);
32 subContainerMap_.erase(formId);
33 }
34
GetSubContainer(int64_t formId)35 RefPtr<SubContainer> FormManager::GetSubContainer(int64_t formId)
36 {
37 std::lock_guard<std::mutex> lock(mutex_);
38 auto subContainer = subContainerMap_.find(formId);
39 if (subContainer != subContainerMap_.end()) {
40 return subContainer->second;
41 } else {
42 return nullptr;
43 }
44 }
45
SetFormUtils(const std::shared_ptr<FormUtils> & formUtils)46 void FormManager::SetFormUtils(const std::shared_ptr<FormUtils>& formUtils)
47 {
48 std::lock_guard<std::mutex> lock(formUtilsMutex_);
49 CHECK_NULL_VOID(formUtils);
50 formUtils_ = formUtils;
51 }
52
GetFormUtils()53 std::shared_ptr<FormUtils> FormManager::GetFormUtils()
54 {
55 std::lock_guard<std::mutex> lock(formUtilsMutex_);
56 CHECK_NULL_RETURN(formUtils_, nullptr);
57 return formUtils_;
58 }
59
NotifyIsSizeChangeByRotate(bool isRotate,const std::shared_ptr<Rosen::RSTransaction> & rsTransaction)60 void FormManager::NotifyIsSizeChangeByRotate(bool isRotate,
61 const std::shared_ptr<Rosen::RSTransaction>& rsTransaction)
62 {
63 rsTransaction_ = rsTransaction;
64 isRotate_ = isRotate;
65 }
66
67 } // namespace OHOS::Ace
68