1 /*
2 * Copyright (c) 2024-2025 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 "utils/window_options_utils.h"
17
18 #include "ability_record.h"
19 #include "app_utils.h"
20
21 namespace OHOS {
22 namespace AAFwk {
SetWindowPositionAndSize(Want & want,const sptr<IRemoteObject> & callerToken,const StartOptions & startOptions)23 void WindowOptionsUtils::SetWindowPositionAndSize(Want& want,
24 const sptr<IRemoteObject>& callerToken, const StartOptions& startOptions)
25 {
26 if (!AppUtils::GetInstance().IsStartOptionsWithAnimation()) {
27 return;
28 }
29 if (startOptions.windowLeftUsed_) {
30 want.SetParam(Want::PARAM_RESV_WINDOW_LEFT, startOptions.GetWindowLeft());
31 }
32 if (startOptions.windowTopUsed_) {
33 want.SetParam(Want::PARAM_RESV_WINDOW_TOP, startOptions.GetWindowTop());
34 }
35 if (startOptions.windowWidthUsed_) {
36 want.SetParam(Want::PARAM_RESV_WINDOW_WIDTH, startOptions.GetWindowWidth());
37 }
38 if (startOptions.windowHeightUsed_) {
39 want.SetParam(Want::PARAM_RESV_WINDOW_HEIGHT, startOptions.GetWindowHeight());
40 }
41 if (startOptions.minWindowWidthUsed_) {
42 want.SetParam(Want::PARAM_RESV_MIN_WINDOW_WIDTH, startOptions.GetMinWindowWidth());
43 }
44 if (startOptions.minWindowHeightUsed_) {
45 want.SetParam(Want::PARAM_RESV_MIN_WINDOW_HEIGHT, startOptions.GetMinWindowHeight());
46 }
47 if (startOptions.maxWindowWidthUsed_) {
48 want.SetParam(Want::PARAM_RESV_MAX_WINDOW_WIDTH, startOptions.GetMaxWindowWidth());
49 }
50 if (startOptions.maxWindowHeightUsed_) {
51 want.SetParam(Want::PARAM_RESV_MAX_WINDOW_HEIGHT, startOptions.GetMaxWindowHeight());
52 }
53 bool withAnimation = startOptions.GetWithAnimation();
54 auto abilityRecord = Token::GetAbilityRecordByToken(callerToken);
55 if (!withAnimation && abilityRecord != nullptr &&
56 abilityRecord->GetAbilityInfo().bundleName == want.GetBundle()) {
57 want.SetParam(Want::PARAM_RESV_WITH_ANIMATION, withAnimation);
58 }
59 }
60
WindowModeMap(int32_t windowMode)61 std::pair<bool, AppExecFwk::SupportWindowMode> WindowOptionsUtils::WindowModeMap(int32_t windowMode)
62 {
63 std::pair<bool, AppExecFwk::SupportWindowMode> result(false, AppExecFwk::SupportWindowMode::FULLSCREEN);
64
65 if (windowMode == MULTI_WINDOW_DISPLAY_FULLSCREEN) {
66 result.first = true;
67 result.second = AppExecFwk::SupportWindowMode::FULLSCREEN;
68 } else if (windowMode == MULTI_WINDOW_DISPLAY_PRIMARY) {
69 result.first = true;
70 result.second = AppExecFwk::SupportWindowMode::SPLIT;
71 } else if (windowMode == MULTI_WINDOW_DISPLAY_SECONDARY) {
72 result.first = true;
73 result.second = AppExecFwk::SupportWindowMode::SPLIT;
74 } else if (windowMode == MULTI_WINDOW_DISPLAY_FLOATING) {
75 result.first = true;
76 result.second = AppExecFwk::SupportWindowMode::FLOATING;
77 }
78 return result;
79 }
80 } // namespace AAFwk
81 } // namespace OHOS
82