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 #ifndef FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENT_FORM_FORM_WINDOW_H
17 #define FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENT_FORM_FORM_WINDOW_H
18 
19 #include <memory>
20 
21 #include "base/utils/macros.h"
22 #include "base/utils/noncopyable.h"
23 #include "core/common/ace_page.h"
24 #include "core/common/window.h"
25 #include "core/pipeline/pipeline_context.h"
26 
27 namespace OHOS::Ace {
28 class ACE_EXPORT FormWindow : public Window {
29 public:
FormWindow(const WeakPtr<PipelineBase> & context)30     explicit FormWindow(const WeakPtr<PipelineBase>& context) : Window(nullptr), outSidePipelineContext_(context) {}
~FormWindow()31     ~FormWindow()
32     {
33         auto context = outSidePipelineContext_.Upgrade();
34         if (!context) {
35             LOGE("form remove vsync callback fail due to null context");
36             return;
37         }
38         context->RemoveJsFormVsyncCallback(formWindowId_);
39     };
40 
41     void RequestFrame() override;
42 
Destroy()43     void Destroy() override {}
44 
SetRootRenderNode(const RefPtr<RenderNode> & root)45     void SetRootRenderNode(const RefPtr<RenderNode>& root) override {}
46 
47     void SetVsyncCallback(AceVsyncCallback&& callback) override;
48 
SetFormWindowId(int64_t formWindowId)49     void SetFormWindowId(int64_t formWindowId)
50     {
51         formWindowId_ = formWindowId;
52     };
53 
SetId(int32_t instanceId)54     void SetId(int32_t instanceId)
55     {
56         instanceId_ = instanceId;
57     };
58 
59 private:
60     WeakPtr<PipelineBase> outSidePipelineContext_;
61     int64_t formWindowId_ = -1;
62     int32_t instanceId_ = -1;
63 
64     AceVsyncCallback callback_ = nullptr;
65     ACE_DISALLOW_COPY_AND_MOVE(FormWindow);
66 };
67 
68 } // namespace OHOS::Ace
69 #endif // FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENT_FORM_FORM_WINDOW_H
70