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