blob: d7f08df329bd6750083e0819a0148678e1df571d [file] [log] [blame]
/*
* Copyright 2020, The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import { getWMPropertiesForDisplay, shortenName } from '../mixin'
import {
Configuration,
ConfigurationContainer,
toRect,
WindowConfiguration,
WindowContainer,
WindowContainerChild,
} from "../common"
import Activity from "./Activity"
import DisplayArea from "./DisplayArea"
import DisplayContent from "./DisplayContent"
import ActivityTask from "./ActivityTask"
import WindowState from "./WindowState"
import WindowToken from "./WindowToken"
WindowContainer.fromProto = function ({
proto,
nameOverride = null,
identifierOverride = null,
tokenOverride = null
}): WindowContainer {
if (proto == null) {
return null
} else {
const identifier = identifierOverride ?? proto.identifier
var name = nameOverride ?? identifier?.title ?? ""
var token = tokenOverride?.toString(16) ?? identifier?.hashCode?.toString(16) ?? ""
const entry = new WindowContainer(
name,
token,
proto.orientation,
proto.visible,
newConfigurationContainer(proto.configurationContainer)
)
// we remove the children property from the object to avoid it showing the
// the properties view of the element as we can always see those elements'
// properties by changing the target element in the hierarchy tree view.
entry.obj = getWMPropertiesForDisplay(proto)
entry.shortName = shortenName(entry.name)
return entry
}
}
WindowContainer.childrenFromProto = function(parent: WindowContainer, proto, isActivityInTree: Boolean): WindowContainerChild {
return new WindowContainerChild(
DisplayContent.fromProto(proto.displayContent, isActivityInTree),
DisplayArea.fromProto(proto.displayArea, isActivityInTree),
ActivityTask.fromProto(proto.task, isActivityInTree),
Activity.fromProto(proto.activity, parent),
WindowToken.fromProto(proto.windowToken, isActivityInTree),
WindowState.fromProto(proto.window, isActivityInTree),
WindowContainer.fromProto({proto: proto.windowContainer})
)
}
function newConfigurationContainer(proto): ConfigurationContainer {
const entry = new ConfigurationContainer(
newConfiguration(proto?.overrideConfiguration ?? null),
newConfiguration(proto?.fullConfiguration ?? null),
newConfiguration(proto?.mergedOverrideConfiguration ?? null)
)
entry.kind = "ConfigurationContainer"
entry.obj = entry
return entry
}
function newConfiguration(proto): Configuration {
var windowConfiguration = null
if (proto != null && proto.windowConfiguration != null) {
windowConfiguration = newWindowConfiguration(proto.windowConfiguration)
}
return new Configuration(
windowConfiguration,
proto?.densityDpi ?? 0,
proto?.orientation ?? 0,
proto?.screenHeightDp ?? 0,
proto?.screenHeightDp ?? 0,
proto?.smallestScreenWidthDp ?? 0,
proto?.screenLayout ?? 0,
proto?.uiMode ?? 0
)
}
function newWindowConfiguration(proto): WindowConfiguration {
return new WindowConfiguration(
toRect(proto.appBounds),
toRect(proto.bounds),
toRect(proto.maxBounds),
proto.windowingMode,
proto.activityType
)
}
export default WindowContainer