• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2023 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 "bridge/declarative_frontend/jsview/models/canvas_model_impl.h"
17 
18 #include "bridge/declarative_frontend/view_stack_processor.h"
19 #include "core/components/custom_paint/custom_paint_component.h"
20 #include "core/event/ace_event_handler.h"
21 
22 namespace OHOS::Ace::Framework {
Create()23 RefPtr<AceType> CanvasModelImpl::Create()
24 {
25     auto paintChild = AceType::MakeRefPtr<OHOS::Ace::CustomPaintComponent>();
26     return paintChild;
27 }
28 
GetTaskPool(RefPtr<AceType> & pattern)29 RefPtr<AceType> CanvasModelImpl::GetTaskPool(RefPtr<AceType>& pattern)
30 {
31     auto pool = AceType::DynamicCast<OHOS::Ace::CustomPaintComponent>(pattern)->GetTaskPool();
32     return pool;
33 }
34 
PushCanvasPattern(RefPtr<AceType> & canvasParrern)35 void CanvasModelImpl::PushCanvasPattern(RefPtr<AceType>& canvasParrern)
36 {
37     auto paintChild = AceType::DynamicCast<OHOS::Ace::CustomPaintComponent>(canvasParrern);
38     ViewStackProcessor::GetInstance()->ClaimElementId(paintChild);
39     ViewStackProcessor::GetInstance()->Push(paintChild);
40 }
41 
SetOnReady(std::function<void (uint32_t)> && readyEvent)42 void CanvasModelImpl::SetOnReady(std::function<void(uint32_t)>&& readyEvent)
43 {
44     auto container = Container::Current();
45     if (!container) {
46         LOGE("No container");
47         return;
48     }
49     auto context = AceType::DynamicCast<PipelineContext>(container->GetPipelineContext());
50     if (!context) {
51         LOGE("No PipelineContext");
52         return;
53     }
54     auto component = AceType::DynamicCast<CustomPaintComponent>(ViewStackProcessor::GetInstance()->GetMainComponent());
55     if (!component) {
56         LOGE("No CustomPaintComponent");
57         return;
58     }
59 
60     auto elmtId = component->GetElementId();
61     auto fun = readyEvent;
62     auto onReadEvent = [fun, elmtId]() { fun(elmtId); };
63 
64     auto onReadyEvent = EventMarker(std::move(onReadEvent));
65 
66     component->SetOnReadyEvent(onReadyEvent, context);
67 }
68 } // namespace OHOS::Ace::Framework
69