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