master分支withTheme新增代码

Signed-off-by: ace___H <hezhijian1@huawei.com>
This commit is contained in:
ace___H 2024-11-12 10:39:15 +08:00
parent eef011eb95
commit ccf6bff7e5
19 changed files with 0 additions and 1909 deletions

View File

@ -1,50 +0,0 @@
/*
* Copyright (c) 2024 Huawei Device Co., Ltd.
* 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.
*/
#ifndef FRAMEWORKS_BRIDGE_DECLARATIVE_FRONTEND_THEME_JS_LAZY_FOR_EACH_THEME_H
#define FRAMEWORKS_BRIDGE_DECLARATIVE_FRONTEND_THEME_JS_LAZY_FOR_EACH_THEME_H
namespace OHOS::Ace::Framework {
class JSLazyForEachTheme {
public:
static void ObtainItemGeneratorForThemeSupport(panda::ecmascript::EcmaVM* vm, JSRef<JSFunc> &itemGenerator)
{
CHECK_NULL_VOID(vm);
panda::Local<panda::ObjectRef> globalObj(JSNApi::GetGlobalObject(vm));
if (!globalObj->IsObject(vm)) {
return;
}
JSRef<JSVal> lazy4each = JSRef<JSObject>::Make(globalObj)->GetProperty("LazyForEach");
if (!lazy4each->IsObject()) {
return;
}
JSRef<JSVal> updateItemFunc = JSRef<JSObject>::Cast(lazy4each)->GetProperty("getItemGeneratorForThemeSupport");
if (!updateItemFunc->IsFunction()) {
return;
}
JSRef<JSVal> params[] = { JSRef<JSVal>::Cast(itemGenerator) };
JSRef<JSVal> retVal = JSRef<JSFunc>::Cast(updateItemFunc)->Call(JSRef<JSObject>(), ArraySize(params), params);
if (!retVal->IsFunction()) {
return;
}
itemGenerator = JSRef<JSFunc>::Cast(retVal);
}
};
} // namespace OHOS::Ace::Framework
#endif // FRAMEWORKS_BRIDGE_DECLARATIVE_FRONTEND_THEME_JS_LAZY_FOR_EACH_THEME_H

View File

@ -1,50 +0,0 @@
/*
* Copyright (c) 2024 Huawei Device Co., Ltd.
* 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.
*/
#ifndef FRAMEWORKS_BRIDGE_DECLARATIVE_FRONTEND_THEME_JS_LIST_ITEM_THEME_H
#define FRAMEWORKS_BRIDGE_DECLARATIVE_FRONTEND_THEME_JS_LIST_ITEM_THEME_H
namespace OHOS::Ace::Framework {
class JSListItemTheme {
public:
static void ObtainDeepRenderFuncForThemeSupport(panda::ecmascript::EcmaVM* vm, JSRef<JSFunc> &deepRenderFunc)
{
CHECK_NULL_VOID(vm);
panda::Local<panda::ObjectRef> globalObj(JSNApi::GetGlobalObject(vm));
if (!globalObj->IsObject(vm)) {
return;
}
JSRef<JSVal> list = JSRef<JSObject>::Make(globalObj)->GetProperty("ListItem");
if (!list->IsObject()) {
return;
}
JSRef<JSVal> updateItemFunc = JSRef<JSObject>::Cast(list)->GetProperty("getDeepRenderFuncForThemeSupport");
if (!updateItemFunc->IsFunction()) {
return;
}
JSRef<JSVal> params[] = { JSRef<JSVal>::Cast(deepRenderFunc) };
JSRef<JSVal> retVal = JSRef<JSFunc>::Cast(updateItemFunc)->Call(JSRef<JSObject>(), ArraySize(params), params);
if (!retVal->IsFunction()) {
return;
}
deepRenderFunc = JSRef<JSFunc>::Cast(retVal);
}
};
} // namespace OHOS::Ace::Framework
#endif // FRAMEWORKS_BRIDGE_DECLARATIVE_FRONTEND_THEME_JS_LIST_ITEM_THEME_H

View File

@ -1,200 +0,0 @@
/*
* Copyright (c) 2024 Huawei Device Co., Ltd.
* 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.
*/
/**
* Theme counter used to generate next theme id
*/
let themeCounter = 0;
/**
* Base ArkTheme class
*/
class ArkThemeBase implements ThemeInternal {
// Theme tokens
colors: Colors;
shapes: Shapes;
typography: Typography;
/**
* Unique theme instance id
*/
id: number
/**
* Copy of CustomTheme used to create this theme instance
*/
private customTheme: CustomThemeInternal;
/**
* Color Mode used to create this theme instance
*/
private colorMode: ThemeColorMode;
/**
* Binded theme scopes counter
*/
private scopesCounter: number = 0;
/**
* Array of ids of binded theme scopes
*/
private bindedThemeScopesIds: number[] = [];
/**
* Flag used to identify whether theme was just created or not
*/
private isJustCreated = true;
/**
* Id of theme instance which was used as baseline theme for this theme instance
*/
private parentThemeId: number = -1;
/**
* ArkThemeBase class constructor
*
* @param parentId id of theme instance which is used as baseline theme
* @param customTheme instance of CustomTheme used to create current theme
* @param colorMode local colorm mode used for current theme
* @param colors colors tokens
* @param shapes shapes tokens
* @param typography typography tokens
*/
constructor(
parentId: number,
customTheme: CustomThemeInternal,
colorMode: ThemeColorMode,
colors: Colors,
shapes: Shapes,
typography: Typography
) {
this.id = themeCounter++;
this.parentThemeId = parentId;
this.customTheme = ArkThemeBase.copyCustomTheme(customTheme);
this.colorMode = colorMode;
this.colors = colors;
this.shapes = shapes;
this.typography = typography;
}
/**
* Binds current theme instance to theme scope
*
* @param themeScopeId binded theme scope id
*/
bindToScope(themeScopeId: number) {
if (this.bindedThemeScopesIds.includes(themeScopeId)) {
// do nothing if theme scope already binded
return;
}
// increment theme scopes counter
this.scopesCounter++;
// keep theme scope id
this.bindedThemeScopesIds.push(themeScopeId);
if (this.isJustCreated) {
// if theme instance is just created keep it to the cache
ArkThemeCache.getInstance().add(this);
// mark theme instance as not just created
this.isJustCreated = false;
}
}
/**
* Unbinds current theme instance from theme scope
*
* @param themeScopeId binded theme scope id
*/
unbindFromScope(themeScopeId: number) {
const index = this.bindedThemeScopesIds.indexOf(themeScopeId);
if (index == -1) {
// do nothing if theme scope is not exist in binded scopes list
return;
}
// decrement theme scopes counter
this.scopesCounter--;
// remove theme scope id from the lisy of binded theme scopes
this.bindedThemeScopesIds.splice(index, 1);
if (this.canBeDestroyed()) {
// remove theme from cache if none theme scope binded to the current theme instance
ArkThemeCache.getInstance().remove(this);
}
}
/**
* Checks whether we can destroy existing theme instance or not
*
* @returns true if theme instance can be destroyed; false otherwise
*/
canBeDestroyed(): boolean {
// checks whether theme is no just created and binded theme scopes counter is 0
return !this.isJustCreated && this.scopesCounter === 0;
}
/**
* Return id of theme instance which was used as baseline theme for current theme instance
*
* @returns parent theme id
*/
getParentThemeId(): number {
return this.parentThemeId;
}
/**
* Returns copy of CustomTheme used to create current theme instance
*
* @returns CustomTheme instance
*/
getCustomTheme(): CustomTheme {
return this.customTheme;
}
/**
* Returns color mode used by this theme instance
*
* @returns local color mode value
*/
getColorMode(): ThemeColorMode {
return this.colorMode;
}
/**
* Makes a local copy of CustomTheme instance
*
* @param customTheme instance of CustomTheme used to create current theme
* @returns copy of custom theme instance
*/
static copyCustomTheme(customTheme: CustomThemeInternal): CustomThemeInternal {
if (!customTheme) {
// return undefined if original custom theme is undefined
return undefined;
}
const copyTheme: CustomThemeInternal = {}
if (customTheme.colors) {
copyTheme.colors = {}
Object.assign(copyTheme.colors, customTheme.colors)
}
if (customTheme.shapes) {
copyTheme.shapes = {}
Object.assign(copyTheme.shapes, customTheme.shapes)
}
if (customTheme.typography) {
copyTheme.typography = {}
Object.assign(copyTheme.typography, customTheme.typography)
}
return copyTheme
}
}

View File

@ -1,159 +0,0 @@
/*
* Copyright (c) 2024 Huawei Device Co., Ltd.
* 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.
*/
/**
* Singleton class used to keep existing theme instances which are used by theme scopes right now
*/
class ArkThemeCache {
// single instance
private static instance: ArkThemeCache;
// array of theme instances
private cache: ArkThemeBase[] = [];
private constructor() {}
static getInstance() {
if (!ArkThemeCache.instance) {
ArkThemeCache.instance = new ArkThemeCache();
}
return ArkThemeCache.instance;
}
/**
* Adds theme instance to the cache
*
* @param theme instance of theme
*/
add(theme: ArkThemeBase) {
if (this.contains(theme)) {
// do nothing if theme already contains in cache
return;
}
this.cache.push(theme);
}
/**
* Removes theme instance from the cache
*
* @param theme instance of theme
*/
remove(theme: ArkThemeBase) {
const index = this.cache.indexOf(theme);
if (index == -1) {
// do nothing if cache doesn`t contain this theme instance
return;
}
// remove theme from TS side cache
this.cache.splice(index, 1);
// remove theme from native side cache
getUINativeModule().theme.removeFromCache(theme.id);
}
/**
* Returns existing theme istance by CustomTheme and color mode
*
* @param baselineThemeId baseline theme id
* @param customTheme instance of CustomTheme used for theme
* @param colorMode local colorm mode used for theme
* @returns instance of theme if exists or undefined
*/
get(baselineThemeId: number, customTheme: CustomTheme, colorMode: ThemeColorMode): ArkThemeBase {
// check all cache items one by one
// return undefined if cache doesn`t contains theme instance with the same color mode and custom theme attributes
return this.cache.find((item) => {
return item.getParentThemeId() === baselineThemeId &&
item.getColorMode() === colorMode &&
this.isEqualsCustomThemes(item.getCustomTheme(), customTheme)
})
}
/**
* Checks whether cache contains theme instance or not
*
* @param theme instance of theme
* @returns true if theme instance contains in cache; false otherwise
*/
contains(theme: ArkThemeBase): boolean {
return this.containsByAttributes(theme.getParentThemeId(), theme.getCustomTheme(), theme.getColorMode());
}
/**
* Checks whether cache contains theme instance with the same color mode and custom theme attributes or not
*
* @param baselineThemeId baseline theme id
* @param customTheme instance of CustomTheme used for theme
* @param colorMode local colorm mode used for theme
* @returns true if theme instance contains in cache; false otherwise
*/
containsByAttributes(baselineThemeId: number, customTheme: CustomTheme, colorMode: ThemeColorMode): boolean {
return this.get(baselineThemeId, customTheme, colorMode) !== undefined;
}
/**
* Checks equality of two custom themes
*
* @param theme1 first custom theme instance
* @param theme2 second custom theme instance
* @returns true if cutom themes are equals; false otherwise
*/
private isEqualsCustomThemes(theme1: CustomTheme, theme2: CustomTheme): boolean {
if (theme1 === theme2) {
// return true if references are the same
return true;
}
if (!theme1 || !theme2) {
// return false if one of instances is undefined
return false;
}
if (theme1.colors === theme2.colors) {
// return true if colors tokens references are the same
return true;
}
if (!theme1.colors || !theme2.colors) {
// return false if one of colors instances is undefined
return false;
}
// take array of keys of color tokens used by both custom themes
let keys1 = Object.keys(theme1.colors);
let keys2 = Object.keys(theme2.colors);
if (keys1.length !== keys2.length) {
// return false if the length of the keys arrays are different
return false;
}
// go by color tokens attributes keys one by one
for (let key of keys1) {
if (!keys2.includes(key)) {
// return false if key of first custom theme colors dosn`t used by second custom theme colors
return false;
}
// take values of colors tokens by current attribute key
let value1 = theme1.colors[key];
let value2 = theme2.colors[key];
if(value1 !== value2) {
// return false if color tokens values are different
return false;
}
}
// return true because we achieved the end of the method that means that two instance of Custom Theme are the same
return true;
}
}

View File

@ -1,34 +0,0 @@
/*
* Copyright (c) 2024 Huawei Device Co., Ltd.
* 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.
*/
// @ts-ignore
globalThis.LazyForEach.getItemGeneratorForThemeSupport = function (
paramItemGenerator: (...params: any[]) => void,
): (item: any) => void {
// get actual theme scope
const themeScope = ArkThemeScopeManager.getInstance().lastLocalThemeScope()
if (themeScope === undefined) {
return paramItemGenerator
}
const itemGeneratorWrapper = (...params: any[]) => {
const result = ArkThemeScopeManager.getInstance().onDeepRenderScopeEnter(themeScope)
paramItemGenerator(...params)
if (result === true) {
ArkThemeScopeManager.getInstance().onDeepRenderScopeExit()
}
}
return itemGeneratorWrapper
}

View File

@ -1,38 +0,0 @@
/*
* Copyright (c) 2024 Huawei Device Co., Ltd.
* 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.
*/
// @ts-ignore
if (globalThis.WithTheme !== undefined) {
globalThis.ListItem.getDeepRenderFuncForThemeSupport = function (
deepRenderFunction: (elmtId: number, isInitialRender: boolean) => void
): (elmtId: number, isInitialRender: boolean) => void {
// get actual theme scope
const themeScope = ArkThemeScopeManager.getInstance().lastLocalThemeScope();
// if ListItem isn`t in theme scope we shouldn`t use any theme scope for deep render
if (themeScope === undefined) {
return deepRenderFunction;
}
// create wrapper over original deepRenderFunction to add enter/exit callbacks for ThemeScopeManager
const deepRenderFunctionWrapper = (elmtId: number, isInitialRender: boolean) => {
const result = ArkThemeScopeManager.getInstance().onDeepRenderScopeEnter(themeScope);
deepRenderFunction(elmtId, isInitialRender);
if (result === true) {
ArkThemeScopeManager.getInstance().onDeepRenderScopeExit();
}
}
return deepRenderFunctionWrapper;
}
}

View File

@ -1,171 +0,0 @@
/*
* Copyright (c) 2024 Huawei Device Co., Ltd.
* 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.
*/
#include "bridge/declarative_frontend/engine/jsi/nativeModule/arkts_native_theme_bridge.h"
#include "bridge/declarative_frontend/engine/jsi/nativeModule/arkts_native_common_bridge.h"
#include "bridge/declarative_frontend/engine/jsi/nativeModule/arkts_utils.h"
#include "core/components_ng/syntax/with_theme_node.h"
#include "core/components_ng/token_theme/token_theme_storage.h"
namespace OHOS::Ace::NG {
ArkUINativeModuleValue ThemeBridge::Create(ArkUIRuntimeCallInfo* runtimeCallInfo)
{
EcmaVM* vm = runtimeCallInfo->GetVM();
CHECK_NULL_RETURN(vm, panda::JSValueRef::Undefined(vm));
Local<JSValueRef> themeScopeIdArg = runtimeCallInfo->GetCallArgRef(0);
Local<JSValueRef> themeIdArg = runtimeCallInfo->GetCallArgRef(1);
Local<JSValueRef> colorsArg = runtimeCallInfo->GetCallArgRef(2); // 2: colorsArg index
Local<JSValueRef> colorModeArg = runtimeCallInfo->GetCallArgRef(3); // 3: colorModeArg index
Local<JSValueRef> onThemeScopeDestroyArg = runtimeCallInfo->GetCallArgRef(4); // 4: destroy callback arg index
// handle theme scope id argument
if (!themeScopeIdArg->IsNumber()) {
return panda::JSValueRef::Undefined(vm);
}
ArkUI_Int32 themeScopeId = static_cast<ArkUI_Int32>(themeScopeIdArg->Int32Value(vm));
// handle theme id argument
if (!themeIdArg->IsNumber()) {
return panda::JSValueRef::Undefined(vm);
}
ArkUI_Int32 themeId = static_cast<ArkUI_Int32>(themeIdArg->Int32Value(vm));
// handle colors argument
if (!colorsArg->IsArray(vm)) {
return panda::JSValueRef::Undefined(vm);
}
std::vector<ArkUI_Uint32> colors;
HandleThemeColorsArg(vm, colorsArg, colors);
// handle color mode argument
if (!colorModeArg->IsNumber()) {
return panda::JSValueRef::Undefined(vm);
}
ArkUI_Int32 colorMode = static_cast<ArkUI_Int32>(colorModeArg->Int32Value(vm));
// handle on theme scope destroy argument
if (!onThemeScopeDestroyArg->IsFunction(vm)) {
return panda::JSValueRef::Undefined(vm);
}
auto obj = onThemeScopeDestroyArg->ToObject(vm);
auto containerId = Container::CurrentId();
panda::Local<panda::FunctionRef> func = obj;
std::function<void()> onThemeScopeDestroy = [vm, func = panda::CopyableGlobal(vm, func), containerId]() {
panda::LocalScope pandaScope(vm);
panda::TryCatch trycatch(vm);
ContainerScope scope(containerId);
func->Call(vm, func.ToLocal(), nullptr, 0);
};
// execute C-API
auto themeModifier = GetArkUINodeModifiers()->getThemeModifier();
auto theme = themeModifier->createTheme(themeId, colors.data(), colorMode);
CHECK_NULL_RETURN(theme, panda::NativePointerRef::New(vm, nullptr));
ArkUINodeHandle node = themeModifier->getWithThemeNode(themeScopeId);
if (!node) {
node = CreateWithThemeNode(themeScopeId);
}
themeModifier->createThemeScope(node, theme);
themeModifier->setOnThemeScopeDestroy(node, reinterpret_cast<void*>(&onThemeScopeDestroy));
return panda::JSValueRef::Undefined(vm);
}
void ThemeBridge::HandleThemeColorsArg(const EcmaVM* vm, const Local<JSValueRef>& colorsArg,
std::vector<ArkUI_Uint32>& colors)
{
auto basisTheme = TokenThemeStorage::GetInstance()->GetDefaultTheme();
if (!basisTheme) {
basisTheme = TokenThemeStorage::GetInstance()->ObtainSystemTheme();
}
for (size_t i = 0; i < TokenColors::TOTAL_NUMBER; i++) {
Color color;
auto colorParams = panda::ArrayRef::GetValueAt(vm, colorsArg, i);
if (!ArkTSUtils::ParseJsColorAlpha(vm, colorParams, color)) {
color = basisTheme->Colors()->GetByIndex(i);
}
colors.push_back(static_cast<ArkUI_Uint32>(color.GetValue()));
}
}
ArkUINodeHandle ThemeBridge::CreateWithThemeNode(ArkUI_Int32 themeScopeId)
{
auto themeModifier = GetArkUINodeModifiers()->getThemeModifier();
auto node = themeModifier->createWithThemeNode(themeScopeId);
RefPtr<WithThemeNode> withThemeNode = AceType::Claim(reinterpret_cast<WithThemeNode*>(node));
withThemeNode->DecRefCount();
ViewStackProcessor::GetInstance()->Push(withThemeNode);
return node;
}
ArkUINativeModuleValue ThemeBridge::Pop(ArkUIRuntimeCallInfo* runtimeCallInfo)
{
EcmaVM* vm = runtimeCallInfo->GetVM();
CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
ViewStackProcessor::GetInstance()->PopContainer();
return panda::JSValueRef::Undefined(vm);
}
ArkUINativeModuleValue ThemeBridge::SetDefaultTheme(ArkUIRuntimeCallInfo* runtimeCallInfo)
{
EcmaVM* vm = runtimeCallInfo->GetVM();
CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
Local<JSValueRef> colorsArg = runtimeCallInfo->GetCallArgRef(0);
Local<JSValueRef> isDarkArg = runtimeCallInfo->GetCallArgRef(1);
// handle colors argument
if (!colorsArg->IsArray(vm)) {
return panda::JSValueRef::Undefined(vm);
}
std::vector<ArkUI_Uint32> colors;
auto basisTheme = TokenThemeStorage::GetInstance()->ObtainSystemTheme();
for (size_t i = 0; i < TokenColors::TOTAL_NUMBER; i++) {
Color color;
auto colorParams = panda::ArrayRef::GetValueAt(vm, colorsArg, i);
if (!ArkTSUtils::ParseJsColorAlpha(vm, colorParams, color)) {
color = basisTheme->Colors()->GetByIndex(i);
}
colors.push_back(static_cast<ArkUI_Uint32>(color.GetValue()));
}
// handle color mode argument
if (!isDarkArg->IsBoolean()) {
return panda::JSValueRef::Undefined(vm);
}
ArkUI_Bool isDark = static_cast<ArkUI_Bool>(isDarkArg->BooleaValue(vm));
// execute C-API
GetArkUINodeModifiers()->getThemeModifier()->setDefaultTheme(colors.data(), isDark);
return panda::JSValueRef::Undefined(vm);
}
ArkUINativeModuleValue ThemeBridge::RemoveFromCache(ArkUIRuntimeCallInfo* runtimeCallInfo)
{
EcmaVM* vm = runtimeCallInfo->GetVM();
CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
Local<JSValueRef> themeIdArg = runtimeCallInfo->GetCallArgRef(0);
// handle theme id argument
if (!themeIdArg->IsNumber()) {
return panda::JSValueRef::Undefined(vm);
}
ArkUI_Int32 themeId = static_cast<ArkUI_Int32>(themeIdArg->Int32Value(vm));
// execute C-API
GetArkUINodeModifiers()->getThemeModifier()->removeFromCache(themeId);
return panda::JSValueRef::Undefined(vm);
}
} // namespace OHOS::Ace::NG

View File

@ -1,35 +0,0 @@
/*
* Copyright (c) 2024 Huawei Device Co., Ltd.
* 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.
*/
#ifndef FRAMEWORKS_BRIDGE_DECLARATIVE_FRONTEND_ENGINE_JSI_NATIVEMODULE_ARKTS_NATIVE_THEME_BRIDGE_H
#define FRAMEWORKS_BRIDGE_DECLARATIVE_FRONTEND_ENGINE_JSI_NATIVEMODULE_ARKTS_NATIVE_THEME_BRIDGE_H
#include "bridge/declarative_frontend/engine/jsi/nativeModule/arkts_native_api_bridge.h"
namespace OHOS::Ace::NG {
class ThemeBridge {
public:
static ArkUINativeModuleValue Create(ArkUIRuntimeCallInfo* runtimeCallInfo);
static ArkUINativeModuleValue Pop(ArkUIRuntimeCallInfo* runtimeCallInfo);
static ArkUINativeModuleValue SetDefaultTheme(ArkUIRuntimeCallInfo* runtimeCallInfo);
static ArkUINativeModuleValue RemoveFromCache(ArkUIRuntimeCallInfo* runtimeCallInfo);
private:
static void HandleThemeColorsArg(const EcmaVM* vm, const Local<JSValueRef>& colorsArg,
std::vector<ArkUI_Uint32>& colors);
static ArkUINodeHandle CreateWithThemeNode(ArkUI_Int32 themeScopeId);
};
}
#endif // FRAMEWORKS_BRIDGE_DECLARATIVE_FRONTEND_ENGINE_JSI_NATIVEMODULE_ARKTS_NATIVE_THEME_BRIDGE_H

View File

@ -1,36 +0,0 @@
/*
* Copyright (c) 2024 Huawei Device Co., Ltd.
* 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.
*/
#ifndef FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_PAINTS_PAINT_PROPERTY_CPP
#define FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_PAINTS_PAINT_PROPERTY_CPP
#include "core/components_ng/render/paint_property.h"
#include "core/components_ng/base/frame_node.h"
namespace OHOS::Ace::NG {
void PaintProperty::SetHost(const WeakPtr<FrameNode>& host)
{
host_ = host;
}
RefPtr<FrameNode> PaintProperty::GetHost() const
{
return host_.Upgrade();
}
} // namespace OHOS::Ace::NG
#endif // FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_PAINTS_PAINT_PROPERTY_CPP

View File

@ -1,71 +0,0 @@
/*
* Copyright (c) 2024 Huawei Device Co., Ltd.
* 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.
*/
#include "core/components_ng/syntax/with_theme_node.h"
#include "core/components_ng/token_theme/token_theme_storage.h"
namespace OHOS::Ace::NG {
WithThemeNode::~WithThemeNode()
{
if (themeScopeDestroyCallback_) {
themeScopeDestroyCallback_();
}
TokenThemeStorage::GetInstance()->RemoveThemeScope(GetId());
}
RefPtr<WithThemeNode> WithThemeNode::GetWithThemeNode(int32_t nodeId)
{
return ElementRegister::GetInstance()->GetSpecificItemById<WithThemeNode>(nodeId);
}
RefPtr<WithThemeNode> WithThemeNode::CreateWithThemeNode(int32_t nodeId)
{
auto node = MakeRefPtr<WithThemeNode>(nodeId);
ElementRegister::GetInstance()->AddUINode(node);
return node;
}
RefPtr<WithThemeNode> WithThemeNode::GetOrCreateWithThemeNode(int32_t nodeId)
{
auto node = WithThemeNode::GetWithThemeNode(nodeId);
if (!node) {
node = WithThemeNode::CreateWithThemeNode(nodeId);
}
return node;
}
void WithThemeNode::NotifyThemeScopeUpdate()
{
UINode::UpdateThemeScopeUpdate(GetThemeScopeId());
}
void WithThemeNode::UpdateThemeScopeId(int32_t themeScopeId)
{
// do nothing
}
void WithThemeNode::UpdateThemeScopeUpdate(int32_t themeScopeId)
{
// do nothing
}
void WithThemeNode::SetOnThemeScopeDestroy(ThemeScopeDestroyCallback&& callback)
{
themeScopeDestroyCallback_ = std::move(callback);
}
} // namespace OHOS::Ace::NG

View File

@ -1,61 +0,0 @@
/*
* Copyright (c) 2024 Huawei Device Co., Ltd.
* 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.
*/
#ifndef FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_SYNTAX_WITH_THEME_NODE_H
#define FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_SYNTAX_WITH_THEME_NODE_H
#include <cstdint>
#include "base/utils/macros.h"
#include "core/components_ng/base/ui_node.h"
#include "core/components_ng/token_theme/token_theme.h"
#include "core/components_v2/inspector/inspector_constants.h"
namespace OHOS::Ace::NG {
using ThemeScopeDestroyCallback = std::function<void()>;
class ACE_EXPORT WithThemeNode : public UINode {
DECLARE_ACE_TYPE(WithThemeNode, UINode);
public:
static RefPtr<WithThemeNode> GetWithThemeNode(int32_t nodeId);
static RefPtr<WithThemeNode> CreateWithThemeNode(int32_t nodeId);
static RefPtr<WithThemeNode> GetOrCreateWithThemeNode(int32_t nodeId);
explicit WithThemeNode(int32_t nodeId) : UINode(V2::JS_WITH_THEME_ETS_TAG, nodeId) {
SetThemeScopeId(nodeId);
}
~WithThemeNode() override;
bool IsAtomicNode() const override
{
return false;
}
void UpdateThemeScopeId(int32_t themeScopeId) override;
void UpdateThemeScopeUpdate(int32_t themeScopeId) override;
void NotifyThemeScopeUpdate();
void SetOnThemeScopeDestroy(ThemeScopeDestroyCallback&& callback);
private:
ThemeScopeDestroyCallback themeScopeDestroyCallback_;
ACE_DISALLOW_COPY_AND_MOVE(WithThemeNode);
};
} // namespace OHOS::Ace::NG
#endif // FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_SYNTAX_WITH_THEME_NODE_H

View File

@ -1,359 +0,0 @@
/*
* Copyright (c) 2024 Huawei Device Co., Ltd.
* 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.
*/
#include "core/components_ng/token_theme/token_colors.h"
#include <vector>
namespace OHOS::Ace::NG {
static const std::vector<TokenColorData> colorData = {
{ /* BRAND = 0 */ "brand", 125830976 },
{ /* WARNING = 1; */ "warning", 125830979 },
{ /* ALERT = 2 */ "alert", 125830980 },
{ /* CONFIRM = 3 */ "confirm", 125830981 },
{ /* FONT_PRIMARY = 4 */ "fontPrimary", 125830982 },
{ /* FONT_SECONDARY = 5 */ "fontSecondary", 125830983 },
{ /* FONT_TERTIARY = 6 */ "fontTertiary", 125830984 },
{ /* FONT_FOURTH = 7 */ "fontFourth", 125830985 },
{ /* FONT_EMPHASIZE = 8 */ "fontEmphasize", 125830986 },
{ /* FONT_ON_PRIMARY = 9 */ "fontOnPrimary", 125830987 },
{ /* FONT_ON_SECONDARY = 10 */ "fontOnSecondary", 125830988 },
{ /* FONT_ON_TERTIARY = 11 */ "fontOnTertiary", 125830989 },
{ /* FONT_ON_FOURTH = 12 */ "fontOnFourth", 125830990 },
{ /* ICON_PRIMARY = 13 */ "iconPrimary", 125830991 },
{ /* ICON_SECONDARY = 14 */ "iconSecondary", 125830992 },
{ /* ICON_TERTIARY = 15 */ "iconTertiary", 125830993 },
{ /* ICON_FOURTH = 16 */ "iconFourth", 125830994 },
{ /* ICON_EMPHASIZE = 17 */ "iconEmphasize", 125830995 },
{ /* ICON_SUB_EMPHASIZE = 18 */ "iconSubEmphasize", 125830996 },
{ /* ICON_ON_PRIMARY = 19 */ "iconOnPrimary", 125831057 },
{ /* ICON_ON_SECONDARY = 20 */ "iconOnSecondary", 125831058 },
{ /* ICON_ON_TERTIARY = 21 */ "iconOnTertiary", 125831059 },
{ /* ICON_ON_FOURTH = 22 */ "iconOnFourth", 125831060 },
{ /* BACKGROUND_PRIMARY = 23 */ "backgroundPrimary", 125831061 },
{ /* BACKGROUND_SECONDARY = 24 */ "backgroundSecondary", 125831062 },
{ /* BACKGROUND_TERTIARY = 25 */ "backgroundTertiary", 125831063 },
{ /* BACKGROUND_FOURTH = 26 */ "backgroundFourth", 125831064 },
{ /* BACKGROUND_EMPHASIZE = 27 */ "backgroundEmphasize", 125831065 },
{ /* COMP_FOREGROUND_PRIMARY = 28 */ "compForegroundPrimary", 125831003 },
{ /* COMP_BACKGROUND_PRIMARY = 29 */ "compBackgroundPrimary", 125831004 },
{ /* COMP_BACKGROUND_PRIMARY_TRAN = 30 */ "compBackgroundPrimaryTran", -1 }, // not defined
{ /* COMP_BACKGROUND_PRIMARY_CONTRARY = 31 */ "compBackgroundPrimaryContrary", 125831005 },
{ /* COMP_BACKGROUND_GRAY = 32 */ "compBackgroundGray", 125831006 },
{ /* COMP_BACKGROUND_SECONDARY = 33 */ "compBackgroundSecondary", 125831007 },
{ /* COMP_BACKGROUND_TERTIARY = 34 */ "compBackgroundTertiary", 125831008 },
{ /* COMP_BACKGROUND_EMPHASIZE = 35 */ "compBackgroundEmphasize", 125831009 },
{ /* COMP_BACKGROUND_NEUTRAL = 36 */ "compBackgroundNeutral", 125831066 },
{ /* COMP_EMPHASIZE_SECONDARY = 37 */ "compEmphasizeSecondary", 125831011 },
{ /* COMP_EMPHASIZE_TERTIARY = 38 */ "compEmphasizeTertiary", 125831012 },
{ /* COMP_DIVIDER = 39 */ "compDivider", 125831013 },
{ /* COMP_COMMON_CONTRARY = 40 */ "compCommonContrary", 125831014 },
{ /* COMP_BACKGROUND_FOCUS = 41 */ "compBackgroundFocus", 125831015 },
{ /* COMP_FOCUSED_PRIMARY = 42 */ "compFocusedPrimary", 125831016 },
{ /* COMP_FOCUSED_SECONDARY = 43 */ "compFocusedSecondary", 125831017 },
{ /* COMP_FOCUSED_TERTIARY = 44 */ "compFocusedTertiary", 125831018 },
{ /* INTERACTIVE_HOVER = 45 */ "interactiveHover", 125831019 },
{ /* INTERACTIVE_PRESSED = 46 */ "interactivePressed", 125831020 },
{ /* INTERACTIVE_FOCUS = 47 */ "interactiveFocus", 125831021 },
{ /* INTERACTIVE_ACTIVE = 48 */ "interactiveActive", 125831022 },
{ /* INTERACTIVE_SELECT = 49 */ "interactiveSelect", 125831023 },
{ /* INTERACTIVE_CLICK = 50 */ "interactiveClick", 125831024 },
{ /* TOTAL_NUMBER = 51; */ nullptr, -1 }
};
void TokenColors::SetColors(const std::vector<Color>& colors)
{
colors_ = colors;
}
Color TokenColors::Brand() const
{
return colors_[BRAND];
}
Color TokenColors::Warning() const
{
return colors_[WARNING];
}
Color TokenColors::Alert() const
{
return colors_[ALERT];
}
Color TokenColors::Confirm() const
{
return colors_[CONFIRM];
}
Color TokenColors::FontPrimary() const
{
return colors_[FONT_PRIMARY];
}
Color TokenColors::FontSecondary() const
{
return colors_[FONT_SECONDARY];
}
Color TokenColors::FontTertiary() const
{
return colors_[FONT_TERTIARY];
}
Color TokenColors::FontFourth() const
{
return colors_[FONT_FOURTH];
}
Color TokenColors::FontEmphasize() const
{
return colors_[FONT_EMPHASIZE];
}
Color TokenColors::FontOnPrimary() const
{
return colors_[FONT_ON_PRIMARY];
}
Color TokenColors::FontOnSecondary() const
{
return colors_[FONT_ON_SECONDARY];
}
Color TokenColors::FontOnTertiary() const
{
return colors_[FONT_ON_TERTIARY];
}
Color TokenColors::FontOnFourth() const
{
return colors_[FONT_ON_FOURTH];
}
Color TokenColors::IconPrimary() const
{
return colors_[ICON_PRIMARY];
}
Color TokenColors::IconSecondary() const
{
return colors_[ICON_SECONDARY];
}
Color TokenColors::IconTertiary() const
{
return colors_[ICON_TERTIARY];
}
Color TokenColors::IconFourth() const
{
return colors_[ICON_FOURTH];
}
Color TokenColors::IconEmphasize() const
{
return colors_[ICON_EMPHASIZE];
}
Color TokenColors::IconSubEmphasize() const
{
return colors_[ICON_SUB_EMPHASIZE];
}
Color TokenColors::IconOnPrimary() const
{
return colors_[ICON_ON_PRIMARY];
}
Color TokenColors::IconOnSecondary() const
{
return colors_[ICON_ON_SECONDARY];
}
Color TokenColors::IconOnTertiary() const
{
return colors_[ICON_ON_TERTIARY];
}
Color TokenColors::IconOnFourth() const
{
return colors_[ICON_ON_FOURTH];
}
Color TokenColors::BackgroundPrimary() const
{
return colors_[BACKGROUND_PRIMARY];
}
Color TokenColors::BackgroundSecondary() const
{
return colors_[BACKGROUND_SECONDARY];
}
Color TokenColors::BackgroundTertiary() const
{
return colors_[BACKGROUND_TERTIARY];
}
Color TokenColors::BackgroundFourth() const
{
return colors_[BACKGROUND_FOURTH];
}
Color TokenColors::BackgroundEmphasize() const
{
return colors_[BACKGROUND_EMPHASIZE];
}
Color TokenColors::CompForegroundPrimary() const
{
return colors_[COMP_FOREGROUND_PRIMARY];
}
Color TokenColors::CompBackgroundPrimary() const
{
return colors_[COMP_BACKGROUND_PRIMARY];
}
Color TokenColors::CompBackgroundPrimaryTran() const
{
return colors_[COMP_BACKGROUND_PRIMARY_TRAN];
}
Color TokenColors::CompBackgroundPrimaryContrary() const
{
return colors_[COMP_BACKGROUND_PRIMARY_CONTRARY];
}
Color TokenColors::CompBackgroundGray() const
{
return colors_[COMP_BACKGROUND_GRAY];
}
Color TokenColors::CompBackgroundSecondary() const
{
return colors_[COMP_BACKGROUND_SECONDARY];
}
Color TokenColors::CompBackgroundTertiary() const
{
return colors_[COMP_BACKGROUND_TERTIARY];
}
Color TokenColors::CompBackgroundEmphasize() const
{
return colors_[COMP_BACKGROUND_EMPHASIZE];
}
Color TokenColors::CompBackgroundNeutral() const
{
return colors_[COMP_BACKGROUND_NEUTRAL];
}
Color TokenColors::CompEmphasizeSecondary() const
{
return colors_[COMP_EMPHASIZE_SECONDARY];
}
Color TokenColors::CompEmphasizeTertiary() const
{
return colors_[COMP_EMPHASIZE_TERTIARY];
}
Color TokenColors::CompDivider() const
{
return colors_[COMP_DIVIDER];
}
Color TokenColors::CompCommonContrary() const
{
return colors_[COMP_COMMON_CONTRARY];
}
Color TokenColors::CompBackgroundFocus() const
{
return colors_[COMP_BACKGROUND_FOCUS];
}
Color TokenColors::CompFocusedPrimary() const
{
return colors_[COMP_FOCUSED_PRIMARY];
}
Color TokenColors::CompFocusedSecondary() const
{
return colors_[COMP_FOCUSED_SECONDARY];
}
Color TokenColors::CompFocusedTertiary() const
{
return colors_[COMP_FOCUSED_TERTIARY];
}
Color TokenColors::InteractiveHover() const
{
return colors_[INTERACTIVE_HOVER];
}
Color TokenColors::InteractivePressed() const
{
return colors_[INTERACTIVE_PRESSED];
}
Color TokenColors::InteractiveFocus() const
{
return colors_[INTERACTIVE_FOCUS];
}
Color TokenColors::InteractiveActive() const
{
return colors_[INTERACTIVE_ACTIVE];
}
Color TokenColors::InteractiveSelect() const
{
return colors_[INTERACTIVE_SELECT];
}
Color TokenColors::InteractiveClick() const
{
return colors_[INTERACTIVE_CLICK];
}
const char* GetColorNameByIndex(int32_t idx)
{
return GetTokenColorDataByIndex(idx).colorName;
}
int32_t GetSystemColorResIdByIndex(int32_t idx)
{
return GetTokenColorDataByIndex(idx).systemResourceId;
}
const TokenColorData& GetTokenColorDataByIndex(int32_t idx)
{
return (idx >= 0 && idx < TokenColors::TOTAL_NUMBER) ? colorData[idx] : colorData[TokenColors::TOTAL_NUMBER];
}
} // namespace OHOS::Ace::NG

View File

@ -1,171 +0,0 @@
/*
* Copyright (c) 2024 Huawei Device Co., Ltd.
* 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.
*/
#ifndef FRAMEWORKS_CORE_COMPONENTS_NG_TOKEN_THEME_TOKEN_COLORS_H
#define FRAMEWORKS_CORE_COMPONENTS_NG_TOKEN_THEME_TOKEN_COLORS_H
#include "base/memory/ace_type.h"
#include "core/components/common/properties/color.h"
namespace OHOS::Ace::NG {
struct TokenColorData {
const char* colorName;
const int32_t systemResourceId;
};
class TokenColors : public virtual AceType {
DECLARE_ACE_TYPE(TokenColors, AceType);
public:
static constexpr int32_t BRAND = 0;
static constexpr int32_t WARNING = 1;
static constexpr int32_t ALERT = 2;
static constexpr int32_t CONFIRM = 3;
static constexpr int32_t FONT_PRIMARY = 4;
static constexpr int32_t FONT_SECONDARY = 5;
static constexpr int32_t FONT_TERTIARY = 6;
static constexpr int32_t FONT_FOURTH = 7;
static constexpr int32_t FONT_EMPHASIZE = 8;
static constexpr int32_t FONT_ON_PRIMARY = 9;
static constexpr int32_t FONT_ON_SECONDARY = 10;
static constexpr int32_t FONT_ON_TERTIARY = 11;
static constexpr int32_t FONT_ON_FOURTH = 12;
static constexpr int32_t ICON_PRIMARY = 13;
static constexpr int32_t ICON_SECONDARY = 14;
static constexpr int32_t ICON_TERTIARY = 15;
static constexpr int32_t ICON_FOURTH = 16;
static constexpr int32_t ICON_EMPHASIZE = 17;
static constexpr int32_t ICON_SUB_EMPHASIZE = 18;
static constexpr int32_t ICON_ON_PRIMARY = 19;
static constexpr int32_t ICON_ON_SECONDARY = 20;
static constexpr int32_t ICON_ON_TERTIARY = 21;
static constexpr int32_t ICON_ON_FOURTH = 22;
static constexpr int32_t BACKGROUND_PRIMARY = 23;
static constexpr int32_t BACKGROUND_SECONDARY = 24;
static constexpr int32_t BACKGROUND_TERTIARY = 25;
static constexpr int32_t BACKGROUND_FOURTH = 26;
static constexpr int32_t BACKGROUND_EMPHASIZE = 27;
static constexpr int32_t COMP_FOREGROUND_PRIMARY = 28;
static constexpr int32_t COMP_BACKGROUND_PRIMARY = 29;
static constexpr int32_t COMP_BACKGROUND_PRIMARY_TRAN = 30;
static constexpr int32_t COMP_BACKGROUND_PRIMARY_CONTRARY = 31;
static constexpr int32_t COMP_BACKGROUND_GRAY = 32;
static constexpr int32_t COMP_BACKGROUND_SECONDARY = 33;
static constexpr int32_t COMP_BACKGROUND_TERTIARY = 34;
static constexpr int32_t COMP_BACKGROUND_EMPHASIZE = 35;
static constexpr int32_t COMP_BACKGROUND_NEUTRAL = 36;
static constexpr int32_t COMP_EMPHASIZE_SECONDARY = 37;
static constexpr int32_t COMP_EMPHASIZE_TERTIARY = 38;
static constexpr int32_t COMP_DIVIDER = 39;
static constexpr int32_t COMP_COMMON_CONTRARY = 40;
static constexpr int32_t COMP_BACKGROUND_FOCUS = 41;
static constexpr int32_t COMP_FOCUSED_PRIMARY = 42;
static constexpr int32_t COMP_FOCUSED_SECONDARY = 43;
static constexpr int32_t COMP_FOCUSED_TERTIARY = 44;
static constexpr int32_t INTERACTIVE_HOVER = 45;
static constexpr int32_t INTERACTIVE_PRESSED = 46;
static constexpr int32_t INTERACTIVE_FOCUS = 47;
static constexpr int32_t INTERACTIVE_ACTIVE = 48;
static constexpr int32_t INTERACTIVE_SELECT = 49;
static constexpr int32_t INTERACTIVE_CLICK = 50;
static constexpr int32_t TOTAL_NUMBER = 51;
TokenColors() = default;
virtual ~TokenColors() = default;
void SetColors(const std::vector<Color>& colors);
Color Brand() const;
Color Warning() const;
Color Alert() const;
Color Confirm() const;
Color FontPrimary() const;
Color FontSecondary() const;
Color FontTertiary() const;
Color FontFourth() const;
Color FontEmphasize() const;
Color FontOnPrimary() const;
Color FontOnSecondary() const;
Color FontOnTertiary() const;
Color FontOnFourth() const;
Color IconPrimary() const;
Color IconSecondary() const;
Color IconTertiary() const;
Color IconFourth() const;
Color IconEmphasize() const;
Color IconSubEmphasize() const;
Color IconOnPrimary() const;
Color IconOnSecondary() const;
Color IconOnTertiary() const;
Color IconOnFourth() const;
Color BackgroundPrimary() const;
Color BackgroundSecondary() const;
Color BackgroundTertiary() const;
Color BackgroundFourth() const;
Color BackgroundEmphasize() const;
Color CompForegroundPrimary() const;
Color CompBackgroundPrimary() const;
Color CompBackgroundPrimaryTran() const;
Color CompBackgroundPrimaryContrary() const;
Color CompBackgroundGray() const;
Color CompBackgroundSecondary() const;
Color CompBackgroundTertiary() const;
Color CompBackgroundEmphasize() const;
Color CompBackgroundNeutral() const;
Color CompEmphasizeSecondary() const;
Color CompEmphasizeTertiary() const;
Color CompDivider() const;
Color CompCommonContrary() const;
Color CompBackgroundFocus() const;
Color CompFocusedPrimary() const;
Color CompFocusedSecondary() const;
Color CompFocusedTertiary() const;
Color InteractiveHover() const;
Color InteractivePressed() const;
Color InteractiveFocus() const;
Color InteractiveActive() const;
Color InteractiveSelect() const;
Color InteractiveClick() const;
static const char* GetColorNameByIndex(int32_t idx);
static int32_t GetSystemColorResIdByIndex(int32_t idx);
inline Color GetByIndex(int32_t idx)
{
return colors_[idx];
}
static const TokenColorData& GetTokenColorDataByIndex(int32_t idx);
private:
std::vector<Color> colors_;
};
} // namespace OHOS::Ace::NG
#endif // FRAMEWORKS_CORE_COMPONENTS_NG_TOKEN_THEME_TOKEN_COLORS_H

View File

@ -1,67 +0,0 @@
/*
* Copyright (c) 2024 Huawei Device Co., Ltd.
* 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.
*/
#ifndef FRAMEWORKS_CORE_COMPONENTS_NG_TOKEN_THEME_TOKEN_THEME_H
#define FRAMEWORKS_CORE_COMPONENTS_NG_TOKEN_THEME_TOKEN_THEME_H
#include "base/memory/ace_type.h"
#include "core/components_ng/token_theme/token_colors.h"
namespace OHOS::Ace::NG {
using TokenThemeScopeId = int32_t;
class TokenTheme : public virtual AceType {
DECLARE_ACE_TYPE(TokenTheme, AceType);
public:
TokenTheme(int32_t id)
{
id_ = id;
}
virtual ~TokenTheme() = default;
void SetColors(const RefPtr<TokenColors>& colors)
{
colors_ = colors;
}
const RefPtr<TokenColors>& Colors() const
{
return colors_;
}
void SetColorMode(ColorMode colorMode)
{
colorMode_ = colorMode;
}
ColorMode GetColorMode() const
{
return colorMode_;
}
int32_t GetId() const
{
return id_;
}
private:
int32_t id_;
RefPtr<TokenColors> colors_;
ColorMode colorMode_ = ColorMode::COLOR_MODE_UNDEFINED;
};
} // namespace OHOS::Ace::NG
#endif // FRAMEWORKS_CORE_COMPONENTS_NG_TOKEN_THEME_TOKEN_THEME_H

View File

@ -1,140 +0,0 @@
/*
* Copyright (c) 2024 Huawei Device Co., Ltd.
* 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.
*/
#include "core/components_ng/token_theme/token_theme_storage.h"
#include <memory>
#include "base/utils/utils.h"
#include "base/utils/system_properties.h"
#include "core/pipeline_ng/pipeline_context.h"
namespace OHOS::Ace::NG {
TokenThemeStorage* TokenThemeStorage::GetInstance()
{
static TokenThemeStorage instance;
return &instance;
}
TokenThemeStorage::TokenThemeStorage() = default;
void TokenThemeStorage::StoreThemeScope(TokenThemeScopeId themeScopeId, int32_t themeId)
{
themeScopeMap_[themeScopeId] = themeId;
}
void TokenThemeStorage::RemoveThemeScope(TokenThemeScopeId themeScopeId, bool removeToken /* = false */)
{
if (removeToken) {
CacheRemove(themeScopeMap_[themeScopeId]);
}
themeScopeMap_.erase(themeScopeId);
}
const RefPtr<TokenTheme>& TokenThemeStorage::GetTheme(TokenThemeScopeId themeScopeId)
{
if (themeScopeId == 0) {
return GetDefaultTheme();
}
auto themeId = themeScopeMap_[themeScopeId];
return CacheGet(themeId);
}
void TokenThemeStorage::SetDefaultTheme(const RefPtr<NG::TokenTheme>& theme, ColorMode colorMode)
{
(colorMode == ColorMode::DARK ? defaultDarkTheme_ : defaultLightTheme_) = theme;
}
const RefPtr<TokenTheme>& TokenThemeStorage::GetDefaultTheme()
{
return CheckLocalAndSystemColorMode() == ColorMode::DARK ? defaultDarkTheme_ : defaultLightTheme_;
}
ColorMode TokenThemeStorage::CheckLocalAndSystemColorMode()
{
auto sysColorMode = SystemProperties::GetColorMode();
auto pipelineContext = NG::PipelineContext::GetCurrentContext();
CHECK_NULL_RETURN(pipelineContext, sysColorMode);
auto colorMode = pipelineContext->GetLocalColorMode();
if (colorMode == ColorMode::COLOR_MODE_UNDEFINED) {
colorMode = sysColorMode;
}
return colorMode;
}
void TokenThemeStorage::CacheClear()
{
themeCache_.clear();
}
void TokenThemeStorage::CacheSet(const RefPtr<TokenTheme>& theme)
{
CHECK_NULL_VOID(theme);
themeCache_[theme->GetId()] = theme;
}
const RefPtr<TokenTheme>& TokenThemeStorage::CacheGet(int32_t themeId)
{
return themeCache_[themeId];
}
void TokenThemeStorage::CacheRemove(int32_t themeId)
{
themeCache_.erase(themeId);
}
RefPtr<TokenTheme> TokenThemeStorage::ObtainSystemTheme()
{
RefPtr<TokenTheme> theme = nullptr;
auto colorMode = CheckLocalAndSystemColorMode();
if (colorMode == ColorMode::DARK) {
theme = CacheGet(TokenThemeStorage::SYSTEM_THEME_DARK_ID);
} else {
theme = CacheGet(TokenThemeStorage::SYSTEM_THEME_LIGHT_ID);
}
if (!theme) {
theme = CreateSystemTokenTheme(colorMode);
CacheSet(theme);
}
return theme;
}
RefPtr<TokenTheme> TokenThemeStorage::CreateSystemTokenTheme(ColorMode colorMode)
{
auto themeId = colorMode == ColorMode::DARK ?
TokenThemeStorage::SYSTEM_THEME_DARK_ID : TokenThemeStorage::SYSTEM_THEME_LIGHT_ID;
auto tokenColors = AceType::MakeRefPtr<TokenColors>();
auto tokenTheme = AceType::MakeRefPtr<NG::TokenTheme>(themeId);
tokenTheme->SetColors(tokenColors);
auto container = Container::Current();
CHECK_NULL_RETURN(container, tokenTheme);
auto pipelineContext = container->GetPipelineContext();
CHECK_NULL_RETURN(pipelineContext, tokenTheme);
auto themeManager = pipelineContext->GetThemeManager();
CHECK_NULL_RETURN(themeManager, tokenTheme);
auto themeConstants = themeManager->GetThemeConstants();
CHECK_NULL_RETURN(themeConstants, tokenTheme);
std::vector<Color> colors;
colors.reserve(TokenColors::TOTAL_NUMBER);
for (size_t resId = 0; resId < TokenColors::TOTAL_NUMBER; ++resId) {
colors.push_back(themeConstants->GetColor(TokenColors::GetSystemColorResIdByIndex(resId)));
}
tokenColors->SetColors(std::move(colors));
return tokenTheme;
}
} // namespace OHOS::Ace::NG

View File

@ -1,69 +0,0 @@
/*
* Copyright (c) 2024 Huawei Device Co., Ltd.
* 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.
*/
#ifndef FRAMEWORKS_CORE_COMPONENTS_NG_TOKEN_THEME_TOKEN_THEME_STORAGE_H
#define FRAMEWORKS_CORE_COMPONENTS_NG_TOKEN_THEME_TOKEN_THEME_STORAGE_H
#include <map>
#include <memory>
#include <unordered_map>
#include "base/memory/referenced.h"
#include "core/components_ng/token_theme/token_theme.h"
namespace OHOS::Ace::NG {
class ACE_EXPORT TokenThemeStorage final {
public:
ACE_FORCE_EXPORT static TokenThemeStorage* GetInstance();
~TokenThemeStorage() = default;
// theme map (key: themeScopeId - value: ark theme instance)
void StoreThemeScope(TokenThemeScopeId themeScopeId, int32_t themeId);
void RemoveThemeScope(TokenThemeScopeId themeScopeId, bool removeToken = false);
const RefPtr<TokenTheme>& GetTheme(TokenThemeScopeId themeScopeId);
// default theme
void SetDefaultTheme(const RefPtr<NG::TokenTheme>& theme, ColorMode colorMode);
const RefPtr<TokenTheme>& GetDefaultTheme();
// cache (key: theme id - value: ark theme instance)
void CacheClear();
void CacheSet(const RefPtr<TokenTheme>& theme);
const RefPtr<TokenTheme>& CacheGet(int32_t themeId);
void CacheRemove(int32_t themeId);
RefPtr<TokenTheme> ObtainSystemTheme();
private:
static constexpr int32_t SYSTEM_THEME_LIGHT_ID = -1;
static constexpr int32_t SYSTEM_THEME_DARK_ID = -2;
TokenThemeStorage();
RefPtr<TokenTheme> CreateSystemTokenTheme(ColorMode colorMode);
ColorMode CheckLocalAndSystemColorMode();
// key: scope id, value: theme id
std::unordered_map<TokenThemeScopeId, int32_t> themeScopeMap_;
// key: theme id, value: theme instance
std::map<int32_t, RefPtr<TokenTheme>> themeCache_;
inline static RefPtr<TokenTheme> defaultLightTheme_ = nullptr;
inline static RefPtr<TokenTheme> defaultDarkTheme_ = nullptr;
};
} // namespace
#endif

View File

@ -1,33 +0,0 @@
/*
* Copyright (c) 2024 Huawei Device Co., Ltd.
* 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.
*/
#ifndef FRAMEWORKS_CORE_COMPONENTS_NG_TOKEN_THEME_TOKEN_THEME_WRAPPER_H
#define FRAMEWORKS_CORE_COMPONENTS_NG_TOKEN_THEME_TOKEN_THEME_WRAPPER_H
#include "base/memory/ace_type.h"
#include "core/components/theme/theme.h"
#include "core/components_ng/token_theme/token_theme.h"
namespace OHOS::Ace::NG {
class ACE_EXPORT TokenThemeWrapper : virtual public Theme {
DECLARE_ACE_TYPE(TokenThemeWrapper, Theme)
public:
TokenThemeWrapper() = default;
virtual ~TokenThemeWrapper() = default;
virtual void ApplyTokenTheme(const TokenTheme& theme) = 0;
};
} // namespace
#endif // FRAMEWORKS_CORE_COMPONENTS_NG_TOKEN_THEME_TOKEN_THEME_WRAPPER_H

View File

@ -1,140 +0,0 @@
/*
* Copyright (c) 2024 Huawei Device Co., Ltd.
* 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.
*/
#include "core/interfaces/native/node/theme_modifier.h"
#include "core/components/common/properties/color.h"
#include "core/components_ng/syntax/with_theme_node.h"
#include "core/components_ng/token_theme/token_theme.h"
#include "core/components_ng/token_theme/token_theme_storage.h"
#include "core/pipeline_ng/pipeline_context.h"
namespace OHOS::Ace::NG {
namespace ThemeModifier {
namespace {
ColorMode MapNumberToColorMode(int32_t number)
{
switch (number) {
case 1: // 1 is the ThemeColorMode.LIGHT
return ColorMode::LIGHT;
case 2: // 2 is the ThemeColorMode.DARK
return ColorMode::DARK;
default:
return ColorMode::COLOR_MODE_UNDEFINED;
}
return ColorMode::COLOR_MODE_UNDEFINED;
}
RefPtr<TokenColors> ConvertColorArrayToTokenColors(const ArkUI_Uint32* colorsArray)
{
std::vector<Color> colors;
colors.reserve(TokenColors::TOTAL_NUMBER);
for (int i = 0; i < TokenColors::TOTAL_NUMBER; i++) {
colors.push_back(Color(colorsArray[i]));
}
auto themeColors = AceType::MakeRefPtr<TokenColors>();
themeColors->SetColors(std::move(colors));
return themeColors;
}
} // namespace
ArkUINodeHandle CreateWithThemeNode(ArkUI_Int32 id)
{
auto withThemeNode = WithThemeNode::CreateWithThemeNode(id);
withThemeNode->IncRefCount();
return reinterpret_cast<ArkUINodeHandle>(OHOS::Ace::AceType::RawPtr(withThemeNode));
}
ArkUINodeHandle GetWithThemeNode(ArkUI_Int32 id)
{
auto withThemeNode = WithThemeNode::GetWithThemeNode(id);
return reinterpret_cast<ArkUINodeHandle>(OHOS::Ace::AceType::RawPtr(withThemeNode));
}
ArkUINodeHandle CreateTheme(ArkUI_Int32 themeId, const ArkUI_Uint32* colors, ArkUI_Int32 colorMode)
{
auto theme = TokenThemeStorage::GetInstance()->CacheGet(themeId);
if (!theme) {
ColorMode themeScopeColorMode = MapNumberToColorMode(colorMode);
auto themeColors = ConvertColorArrayToTokenColors(colors);
theme = AceType::MakeRefPtr<TokenTheme>(themeId);
theme->SetColors(themeColors);
theme->SetColorMode(themeScopeColorMode);
TokenThemeStorage::GetInstance()->CacheSet(theme);
}
return reinterpret_cast<ArkUINodeHandle>(OHOS::Ace::AceType::RawPtr(theme));
}
void CreateThemeScope(ArkUINodeHandle node, ArkUINodeHandle theme)
{
RefPtr<WithThemeNode> withThemeNode = AceType::Claim(reinterpret_cast<WithThemeNode*>(node));
CHECK_NULL_VOID(withThemeNode);
RefPtr<TokenTheme> tokenTheme = AceType::Claim(reinterpret_cast<TokenTheme*>(theme));
CHECK_NULL_VOID(tokenTheme);
TokenThemeStorage::GetInstance()->StoreThemeScope(withThemeNode->GetId(), tokenTheme->GetId());
withThemeNode->NotifyThemeScopeUpdate();
}
void SetDefaultTheme(const ArkUI_Uint32* colors, ArkUI_Bool isDark)
{
auto themeColors = ConvertColorArrayToTokenColors(colors);
auto theme = AceType::MakeRefPtr<TokenTheme>(0);
theme->SetColors(themeColors);
auto colorMode = isDark ? ColorMode::DARK : ColorMode::LIGHT;
TokenThemeStorage::GetInstance()->SetDefaultTheme(theme, colorMode);
// global notify if required
auto sysColorMode = SystemProperties::GetColorMode();
if (sysColorMode != colorMode) {
return;
}
auto pipelineContext = PipelineContext::GetCurrentContext();
CHECK_NULL_VOID(pipelineContext);
auto rootNode = pipelineContext->GetRootElement();
CHECK_NULL_VOID(rootNode);
rootNode->UpdateThemeScopeUpdate(0); // 0 means default theme scope id
}
void RemoveFromCache(ArkUI_Int32 themeId)
{
TokenThemeStorage::GetInstance()->CacheRemove(themeId);
}
void SetOnThemeScopeDestroy(ArkUINodeHandle node, void* callback)
{
RefPtr<WithThemeNode> withThemeNode = AceType::Claim(reinterpret_cast<WithThemeNode*>(node));
if (callback && withThemeNode) {
auto cb = reinterpret_cast<std::function<void()>*>(callback);
withThemeNode->SetOnThemeScopeDestroy(std::move(*cb));
}
}
} // namespace ThemeModifier
namespace NodeModifier {
const ArkUIThemeModifier* GetThemeModifier()
{
static const ArkUIThemeModifier modifier = {
ThemeModifier::CreateWithThemeNode,
ThemeModifier::GetWithThemeNode,
ThemeModifier::CreateTheme,
ThemeModifier::CreateThemeScope,
ThemeModifier::SetDefaultTheme,
ThemeModifier::RemoveFromCache,
ThemeModifier::SetOnThemeScopeDestroy,
};
return &modifier;
}
} // namespace NodeModifier
} // namespace OHOS::Ace::NG

View File

@ -1,25 +0,0 @@
/*
* Copyright (c) 2024 Huawei Device Co., Ltd.
* 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.
*/
#ifndef FRAMEWORKS_INTERFACE_INNER_API_NATIVE_THEME_MODIFIER_H
#define FRAMEWORKS_INTERFACE_INNER_API_NATIVE_THEME_MODIFIER_H
#include "core/interfaces/native/node/node_api.h"
namespace OHOS::Ace::NG::NodeModifier {
const ArkUIThemeModifier* GetThemeModifier();
} // namespace OHOS::Ace::NG::NodeModifier
#endif // FRAMEWORKS_INTERFACE_INNER_API_NATIVE_THEME_MODIFIER_H