• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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/manifest/manifest_window.h"
17 
18 #include <regex>
19 #include "core/common/container.h"
20 #include "core/common/resource/resource_manager.h"
21 
22 namespace OHOS::Ace::Framework {
23 
WindowParse(const std::unique_ptr<JsonValue> & root)24 void ManifestWindow::WindowParse(const std::unique_ptr<JsonValue>& root)
25 {
26     if (!root) {
27         LOGE("the root manifest is nullptr");
28         return;
29     }
30     auto window = root->GetObject("window");
31     if (!window || window->IsNull()) {
32         return;
33     }
34     int32_t designWidth = 0;
35     auto designWidthValue = window->GetValue("designWidth");
36     if (designWidthValue->IsNumber()) {
37         designWidth = designWidthValue->GetInt();
38     } else if (designWidthValue->IsString()) {
39         std::string designString = window->GetString("designWidth");
40         std::regex reg("\\$(\\S+):(\\S+)");
41         std::smatch results;
42 
43         auto resourceObject = AceType::MakeRefPtr<Ace::ResourceObject>("", "", Container::CurrentIdSafely());
44         auto resourceAdapter = ResourceManager::GetInstance().GetOrCreateResourceAdapter(resourceObject);
45         if (std::regex_match(designString, results, reg) && resourceAdapter) {
46             designWidth = resourceAdapter->GetInt(StringUtils::StringToInt(results[2].str()));
47         }
48     }
49     if (designWidth <= 0) {
50         LOGW("[designWidth] of [window] in main_pages.json set error. use default value: %{public}d",
51             DEFAULT_DESIGN_WIDTH);
52         designWidth = DEFAULT_DESIGN_WIDTH;
53     }
54     windowConfig_.designWidth = designWidth;
55     windowConfig_.autoDesignWidth = window->GetBool("autoDesignWidth", false);
56 }
57 
PrintInfo()58 void ManifestWindow::PrintInfo() {}
59 
60 } // namespace OHOS::Ace::Framework
61