• 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 "core/components_ng/pattern/web/web_layout_algorithm.h"
17 
18 #if !defined(ANDROID_PLATFORM) && !defined(IOS_PLATFORM)
19 #include "core/components_ng/pattern/web/web_pattern.h"
20 #else
21 #include "core/components_ng/pattern/web/cross_platform/web_pattern.h"
22 #endif
23 
24 constexpr int32_t MAX_TEXTURE_SIZE = 500000;
25 constexpr int32_t MAX_SURFACE_SIZE = 8000;
26 
27 namespace OHOS::Ace::NG {
28 WebLayoutAlgorithm::WebLayoutAlgorithm() = default;
29 
Measure(LayoutWrapper * layoutWrapper)30 void WebLayoutAlgorithm::Measure(LayoutWrapper* layoutWrapper)
31 {
32     CHECK_NULL_VOID(layoutWrapper);
33     auto host = layoutWrapper->GetHostNode();
34     CHECK_NULL_VOID(host);
35     auto pattern = DynamicCast<WebPattern>(host->GetPattern());
36     CHECK_NULL_VOID(pattern);
37     auto geometryNode = layoutWrapper->GetGeometryNode();
38     CHECK_NULL_VOID(geometryNode);
39     BoxLayoutAlgorithm::Measure(layoutWrapper);
40     int frameWidth = geometryNode->GetFrameSize().Width();
41     int rootLayerHeight = pattern->GetRootLayerHeight();
42     auto renderMode = pattern->GetRenderMode();
43     if (pattern->GetLayoutMode() == WebLayoutMode::FIT_CONTENT && IsValidRootLayer(frameWidth, renderMode) &&
44         IsValidRootLayer(rootLayerHeight, renderMode)) {
45         auto drawSize = SizeF(frameWidth, rootLayerHeight);
46         TAG_LOGD(AceLogTag::ACE_WEB, "WebLayoutAlgorithm::Measure,drawSize : %{public}s", drawSize.ToString().c_str());
47         layoutWrapper->GetGeometryNode()->SetFrameSize(drawSize);
48     }
49 }
50 
IsValidRootLayer(int32_t x,RenderMode renderMode)51 bool WebLayoutAlgorithm::IsValidRootLayer(int32_t x, RenderMode renderMode)
52 {
53     int32_t maxSize = 0;
54     if (renderMode == RenderMode::SYNC_RENDER) {
55         maxSize = MAX_TEXTURE_SIZE;
56     } else {
57         maxSize = MAX_SURFACE_SIZE;
58     }
59     return x > 0 && x <= maxSize;
60 }
61 } // namespace OHOS::Ace::NG
62