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 "frameworks/bridge/common/dom/dom_canvas.h"
17
18 #include "frameworks/core/components/declaration/canvas/canvas_declaration.h"
19
20 namespace OHOS::Ace::Framework {
21 namespace {
22
23 constexpr Dimension DEFAULT_WIDTH = 300.0_px;
24 constexpr Dimension DEFAULT_HEIGHT = 150.0_px;
25
26 } // namespace
27
DOMCanvas(NodeId nodeId,const std::string & nodeName)28 DOMCanvas::DOMCanvas(NodeId nodeId, const std::string& nodeName) : DOMNode(nodeId, nodeName)
29 {
30 paintChild_ = AceType::MakeRefPtr<CustomPaintComponent>();
31 ResetInitializedStyle();
32 }
33
PrepareSpecializedComponent()34 void DOMCanvas::PrepareSpecializedComponent()
35 {
36 paintChild_->SetTextDirection(IsRightToLeft() ? TextDirection::RTL : TextDirection::LTR);
37 // This Func will be triggered when style/attr updated.
38 auto declaration = AceType::DynamicCast<CanvasDeclaration>(declaration_);
39 if (!declaration) {
40 return;
41 }
42 }
43
ResetInitializedStyle()44 void DOMCanvas::ResetInitializedStyle()
45 {
46 SetWidth(DEFAULT_WIDTH);
47 SetHeight(DEFAULT_HEIGHT);
48 boxComponent_->SetWidth(DEFAULT_WIDTH.Value(), DEFAULT_WIDTH.Unit());
49 boxComponent_->SetHeight(DEFAULT_HEIGHT.Value(), DEFAULT_HEIGHT.Unit());
50 }
51
52 } // namespace OHOS::Ace::Framework
53