add SecLoctionButton component

Signed-off-by: libing23 <libing23@huawei.com>
This commit is contained in:
libing23 2023-05-04 15:23:41 +08:00
parent a18bcd1013
commit 30bcd98b19
34 changed files with 1815 additions and 8 deletions

View File

@ -204,6 +204,14 @@ if (defined(global_parts_info)) {
}
}
if (!defined(global_parts_info) ||
defined(global_parts_info.security_security_component)) {
security_component_enable = true
ace_common_defines += [ "SECURITY_COMPONENT_ENABLE" ]
} else {
security_component_enable = false
}
ace_platforms = []
_ace_adapter_dir = rebase_path("$ace_root/adapter", root_build_dir)

View File

@ -85,6 +85,7 @@ const char* PATTERN_MAP[] = {
THEME_PATTERN_INDEXER,
THEME_PATTERN_APP_BAR,
THEME_PATTERN_ADVANCED_PATTERN,
THEME_PATTERN_SECURITY_COMPONENT,
};
bool IsDirExist(const std::string& path)

View File

@ -70,8 +70,20 @@ void ResourceThemeStyle::ParseContent()
{
static const std::set<std::string> stringAttrs = {
"attribute_text_font_family_regular",
"attribute_text_font_family_medium"
"attribute_text_font_family_medium",
"description_current_location",
"description_add_location",
"description_select_location",
"description_share_location",
"description_send_location",
"description_locating",
"description_location",
"description_send_current_location",
"description_relocation",
"description_punch_in",
"description_current_position"
};
for (auto& [attrName, attrValue] : rawAttrs_) {
if (attrName.empty() || attrValue.empty()) {
LOGD("theme attr name:%{public}s or value:%{public}s is empty", attrName.c_str(), attrValue.c_str());

View File

@ -86,6 +86,7 @@ const char* PATTERN_MAP[] = {
THEME_PATTERN_ICON,
THEME_PATTERN_INDEXER,
THEME_PATTERN_APP_BAR,
THEME_PATTERN_SECURITY_COMPONENT,
};
} // namespace

View File

@ -27,7 +27,7 @@
"skip":"跳过",
"back":"返回",
"next":"下一步"
}
},
},
"en-US":{
"common":{
@ -57,7 +57,7 @@
"skip":"SKIP",
"back":"BACK",
"next":"NEXT"
}
},
},
"ml":{
"common":{

View File

@ -93,6 +93,8 @@ public:
APP_BAR_FA_SVG,
MENU_OK_SVG,
SPINNER_DISABLE,
LOCATION_BUTTON_FILLED_SVG,
LOCATION_BUTTON_LINE_SVG,
SVG_END = 20000,
// 20001 - 30000 is reserved for i18n resource.

View File

@ -227,6 +227,7 @@ template("declarative_js_engine") {
"jsview/js_scroll.cpp",
"jsview/js_scroller.cpp",
"jsview/js_search.cpp",
"jsview/js_sec_location_button.cpp",
"jsview/js_select.cpp",
"jsview/js_shape.cpp",
"jsview/js_shape_abstract.cpp",

View File

@ -1367,7 +1367,7 @@ class NavPathInfo {
class NavPathStack {
constructor() {
this.pathArray = [];
this.pathArray = [];
// indicate class has changed.
this.changeFlag = 0;
this.type = this.constructor.name;
@ -1503,4 +1503,52 @@ var ToolbarItemStatus;
ToolbarItemStatus[ToolbarItemStatus["ENABLE_TOOLBAR_ITEM"] = 0] = "ENABLE_TOOLBAR_ITEM";
ToolbarItemStatus[ToolbarItemStatus["DISABLE_TOOLBAR_ITEM"] = 1] = "DISABLE_TOOLBAR_ITEM";
ToolbarItemStatus[ToolbarItemStatus["ACTIVATE_TOOLBAR_ITEM"] = 2] = "ACTIVATE_TOOLBAR_ITEM";
})(ToolbarItemStatus || (ToolbarItemStatus = {}));
})(ToolbarItemStatus || (ToolbarItemStatus = {}));
var LocationIconStyle ;
(function (LocationIconStyle ) {
LocationIconStyle[LocationIconStyle["FULL_FILLED"] = 0] = "FULL_FILLED";
LocationIconStyle[LocationIconStyle["LINES"] = 1] = "LINES";
})(LocationIconStyle || (LocationIconStyle = {}));
var BackgroundButtonType;
(function (BackgroundButtonType) {
BackgroundButtonType[BackgroundButtonType["CAPSULE_BACKGROUND"] = 0] = "CAPSULE_BACKGROUND";
BackgroundButtonType[BackgroundButtonType["CIRCLE_BACKGROUND"] = 1] = "CIRCLE_BACKGROUND";
BackgroundButtonType[BackgroundButtonType["NORMAL_BACKGROUND"] = 2] = "NORMAL_BACKGROUND";
})(BackgroundButtonType || (BackgroundButtonType = {}));
var LocationDescription;
(function (LocationDescription) {
LocationDescription[LocationDescription["CURRENT_LOCATION"] = 0] = "CURRENT_LOCATION";
LocationDescription[LocationDescription["ADD_LOCATION"] = 1] = "ADD_LOCATION";
LocationDescription[LocationDescription["SELECT_LOCATION"] = 2] = "SELECT_LOCATION";
LocationDescription[LocationDescription["SHARE_LOCATION"] = 3] = "SHARE_LOCATION";
LocationDescription[LocationDescription["SEND_LOCATION"] = 4] = "SEND_LOCATION";
LocationDescription[LocationDescription["LOCATING"] = 5] = "LOCATING";
LocationDescription[LocationDescription["LOCATION"] = 6] = "LOCATION";
LocationDescription[LocationDescription["SEND_CURRENT_LOCATION"] = 7] = "SEND_CURRENT_LOCATION";
LocationDescription[LocationDescription["RELOCATION"] = 8] = "RELOCATION";
LocationDescription[LocationDescription["PUNCH_IN"] = 9] = "PUNCH_IN";
LocationDescription[LocationDescription["CURRENT_POSITION"] = 10] = "CURRENT_POSITION";
})(LocationDescription || (LocationDescription = {}));
var SecLocationButtonLayoutDirection;
(function (SecLocationButtonLayoutDirection) {
SecLocationButtonLayoutDirection[SecLocationButtonLayoutDirection["HORIZONTAL"] = 0] = "HORIZONTAL";
SecLocationButtonLayoutDirection[SecLocationButtonLayoutDirection["VERTICAL"] = 1] = "VERTICAL";
})(SecLocationButtonLayoutDirection || (SecLocationButtonLayoutDirection = {}));
var SecLocationButtonLayoutOrder;
(function (SecLocationButtonLayoutOrder) {
SecLocationButtonLayoutOrder[SecLocationButtonLayoutOrder["ICON_FIRST"] = 0] = "ICON_FIRST";
SecLocationButtonLayoutOrder[SecLocationButtonLayoutOrder["TEXT_FIRST"] = 1] = "TEXT_FIRST ";
})(SecLocationButtonLayoutOrder || (SecLocationButtonLayoutOrder = {}));
var SecLocationButtonOnClickResult;
(function (SecLocationButtonOnClickResult) {
SecLocationButtonOnClickResult[SecLocationButtonOnClickResult["LOCATION_BUTTON_CLICK_SUCCESS"] = 0] =
"LOCATION_BUTTON_CLICK_SUCCESS";
SecLocationButtonOnClickResult[SecLocationButtonOnClickResult["LOCATION_BUTTON_CLICK_GRANT_FAILED"] = 1] =
"LOCATION_BUTTON_CLICK_GRANT_FAILED ";
})(SecLocationButtonOnClickResult || (SecLocationButtonOnClickResult = {}));

View File

@ -108,6 +108,7 @@
#include "bridge/declarative_frontend/jsview/js_scroll.h"
#include "bridge/declarative_frontend/jsview/js_scroller.h"
#include "bridge/declarative_frontend/jsview/js_search.h"
#include "bridge/declarative_frontend/jsview/js_sec_location_button.h"
#include "bridge/declarative_frontend/jsview/js_select.h"
#include "bridge/declarative_frontend/jsview/js_shape.h"
#include "bridge/declarative_frontend/jsview/js_shape_abstract.h"
@ -502,6 +503,7 @@ static const std::unordered_map<std::string, std::function<void(BindingTarget)>>
#ifdef WINDOW_SCENE_SUPPORTED
{ "UIExtensionComponent", JSUIExtension::JSBind },
#endif
{ "SecLocationButton", JSSecLocationButton::JSBind },
#ifdef ABILITY_COMPONENT_SUPPORTED
{ "AbilityComponent", JSAbilityComponent::JSBind },
#endif

View File

@ -0,0 +1,480 @@
/*
* Copyright (c) 2023 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 "frameworks/bridge/declarative_frontend/jsview/js_sec_location_button.h"
#include "base/log/ace_scoring_log.h"
#include "bridge/common/utils/utils.h"
#include "core/common/container.h"
#include "core/components/common/properties/text_style.h"
#include "core/components_ng/base/view_abstract_model.h"
#include "core/components_ng/pattern/security_component/location_button/location_button_model_ng.h"
#include "core/components_ng/pattern/security_component/security_component_theme.h"
using OHOS::Ace::NG::LocationButtonModelNG;
using OHOS::Ace::NG::SecurityComponentTheme;
namespace {
static constexpr int TWO_PARAMS = 2;
}
namespace OHOS::Ace::Framework {
void JSSecLocationButton::SetIconSize(const JSCallbackInfo& info)
{
if (info.Length() < 1) {
LOGE("The arg is wrong, it is supposed to have at least 1 argument");
return;
}
auto theme = GetTheme<SecurityComponentTheme>();
CHECK_NULL_VOID_NOLOG(theme);
CalcDimension value;
if (!ParseJsDimensionVp(info[0], value)) {
LocationButtonModelNG::GetInstance()->SetIconSize(theme->GetIconSize());
} else {
LocationButtonModelNG::GetInstance()->SetIconSize(value);
}
}
void JSSecLocationButton::SetIconColor(const JSCallbackInfo& info)
{
if (info.Length() < 1) {
LOGE("The arg is wrong, it is supposed to have at least 1 argument");
return;
}
auto theme = GetTheme<SecurityComponentTheme>();
CHECK_NULL_VOID_NOLOG(theme);
Color color;
if (!ParseJsColor(info[0], color)) {
color = theme->GetIconColor();
}
LocationButtonModelNG::GetInstance()->SetIconColor(color);
}
void JSSecLocationButton::SetFontSize(const JSCallbackInfo& info)
{
if (info.Length() < 1) {
LOGE("The arg is wrong, it is supposed to have at least 1 argument");
return;
}
auto theme = GetTheme<SecurityComponentTheme>();
CHECK_NULL_VOID_NOLOG(theme);
CalcDimension value;
if (!ParseJsDimensionVp(info[0], value)) {
LocationButtonModelNG::GetInstance()->SetFontSize(theme->GetFontSize());
} else {
LocationButtonModelNG::GetInstance()->SetFontSize(value);
}
}
void JSSecLocationButton::SetFontStyle(const JSCallbackInfo& info)
{
if (info.Length() < 1) {
LOGE("The arg is wrong, it is supposed to have at least 1 argument");
return;
}
if (!info[0]->IsNumber()) {
LocationButtonModelNG::GetInstance()->SetFontStyle(Ace::FontStyle::NORMAL);
return;
}
uint32_t value = info[0]->ToNumber<uint32_t>();
if (value < static_cast<uint32_t>(Ace::FontStyle::NORMAL) ||
value > static_cast<uint32_t>(Ace::FontStyle::ITALIC)) {
LocationButtonModelNG::GetInstance()->SetFontStyle(Ace::FontStyle::NORMAL);
return;
}
LocationButtonModelNG::GetInstance()->SetFontStyle(static_cast<Ace::FontStyle>(value));
}
void JSSecLocationButton::SetFontWeight(const JSCallbackInfo& info)
{
if (info.Length() < 1) {
LOGE("The arg is wrong, it is supposed to have at least 1 argument");
return;
}
if (!info[0]->IsString()) {
LocationButtonModelNG::GetInstance()->SetFontWeight(FontWeight::NORMAL);
return;
}
std::string value = info[0]->ToString();
LocationButtonModelNG::GetInstance()->SetFontWeight(ConvertStrToFontWeight(value));
}
void JSSecLocationButton::SetFontFamily(const JSCallbackInfo& info)
{
if (info.Length() < 1) {
LOGI("The argv is wrong, it is supposed to have at least 1 argument");
return;
}
std::vector<std::string> fontFamilies;
if (!ParseJsFontFamilies(info[0], fontFamilies)) {
fontFamilies.emplace_back("HarmonyOS Sans");
LocationButtonModelNG::GetInstance()->SetFontFamily(fontFamilies);
return;
}
LocationButtonModelNG::GetInstance()->SetFontFamily(fontFamilies);
}
void JSSecLocationButton::SetFontColor(const JSCallbackInfo& info)
{
if (info.Length() < 1) {
LOGE("The arg is wrong, it is supposed to have at least 1 argument");
return;
}
auto theme = GetTheme<SecurityComponentTheme>();
CHECK_NULL_VOID_NOLOG(theme);
Color color;
if (!ParseJsColor(info[0], color)) {
color = theme->GetFontColor();
}
LocationButtonModelNG::GetInstance()->SetFontColor(color);
}
void JSSecLocationButton::SetLayoutDirection(const JSCallbackInfo& info)
{
if (info.Length() < 1) {
LOGE("The arg is wrong, it is supposed to have at least 1 argument");
return;
}
if (!info[0]->IsNumber()) {
LocationButtonModelNG::GetInstance()->SetTextIconLayoutDirection(
SecurityComponentLayoutDirection::HORIZONTAL);
return;
}
int32_t value = info[0]->ToNumber<int32_t>();
if ((value < static_cast<int32_t>(SecurityComponentLayoutDirection::HORIZONTAL)) ||
(value > static_cast<int32_t>(SecurityComponentLayoutDirection::VERTICAL))) {
LocationButtonModelNG::GetInstance()->SetTextIconLayoutDirection(
SecurityComponentLayoutDirection::HORIZONTAL);
return;
}
LocationButtonModelNG::GetInstance()->SetTextIconLayoutDirection(
static_cast<SecurityComponentLayoutDirection>(value));
}
void JSSecLocationButton::SetlayoutOrder(const JSCallbackInfo& info)
{
if (info.Length() < 1) {
LOGE("The arg is wrong, it is supposed to have at least 1 argument");
return;
}
if (!info[0]->IsNumber()) {
LocationButtonModelNG::GetInstance()->SetlayoutOrder(
SecSecurityComponentLayoutOrder::ICON_FIRST);
return;
}
int32_t value = info[0]->ToNumber<int32_t>();
if ((value < static_cast<int32_t>(SecSecurityComponentLayoutOrder::ICON_FIRST)) ||
(value > static_cast<int32_t>(SecSecurityComponentLayoutOrder::TEXT_FIRST))) {
LocationButtonModelNG::GetInstance()->SetlayoutOrder(
SecSecurityComponentLayoutOrder::ICON_FIRST);
return;
}
LocationButtonModelNG::GetInstance()->SetlayoutOrder(static_cast<SecSecurityComponentLayoutOrder>(value));
}
void JSSecLocationButton::SetBackgroundColor(const JSCallbackInfo& info)
{
if (info.Length() < 1) {
LOGE("The arg is wrong, it is supposed to have at least 1 argument");
return;
}
auto theme = GetTheme<SecurityComponentTheme>();
CHECK_NULL_VOID_NOLOG(theme);
Color color;
if (!ParseJsColor(info[0], color)) {
color = theme->GetBackgroundColor();
}
LocationButtonModelNG::GetInstance()->SetBackgroundColor(color);
}
void JSSecLocationButton::SetBackgroundBorderStyle(const JSCallbackInfo& info)
{
if (info.Length() < 1) {
LOGE("The arg is wrong, it is supposed to have at least 1 argument");
return;
}
if (!info[0]->IsNumber()) {
LocationButtonModelNG::GetInstance()->SetBackgroundBorderStyle(BorderStyle::NONE);
return;
}
int32_t value = info[0]->ToNumber<int32_t>();
if ((value < static_cast<int32_t>(BorderStyle::SOLID)) ||
(value > static_cast<int32_t>(BorderStyle::NONE))) {
LocationButtonModelNG::GetInstance()->SetBackgroundBorderStyle(BorderStyle::NONE);
return;
}
LocationButtonModelNG::GetInstance()->SetBackgroundBorderStyle(static_cast<BorderStyle>(value));
}
void JSSecLocationButton::SetBackgroundBorderWidth(const JSCallbackInfo& info)
{
if (info.Length() < 1) {
LOGE("The arg is wrong, it is supposed to have at least 1 argument");
return;
}
auto theme = GetTheme<SecurityComponentTheme>();
CHECK_NULL_VOID_NOLOG(theme);
CalcDimension value;
if (!ParseJsDimensionVp(info[0], value)) {
LocationButtonModelNG::GetInstance()->SetBackgroundBorderWidth(theme->GetBorderWidth());
} else {
LocationButtonModelNG::GetInstance()->SetBackgroundBorderWidth(value);
}
}
void JSSecLocationButton::SetBackgroundBorderColor(const JSCallbackInfo& info)
{
if (info.Length() < 1) {
LOGE("The arg is wrong, it is supposed to have at least 1 argument");
return;
}
auto theme = GetTheme<SecurityComponentTheme>();
CHECK_NULL_VOID_NOLOG(theme);
Color borderColor;
if (!ParseJsColor(info[0], borderColor)) {
borderColor = theme->GetBorderColor();
}
LocationButtonModelNG::GetInstance()->SetBackgroundBorderColor(borderColor);
}
void JSSecLocationButton::SetBackgroundBorderRadius(const JSCallbackInfo& info)
{
if (info.Length() < 1) {
LOGE("The arg is wrong, it is supposed to have at least 1 argument");
return;
}
auto theme = GetTheme<SecurityComponentTheme>();
CHECK_NULL_VOID_NOLOG(theme);
CalcDimension value;
if (!ParseJsDimensionVp(info[0], value)) {
LocationButtonModelNG::GetInstance()->SetBackgroundBorderRadius(theme->GetBorderRadius());
} else {
LocationButtonModelNG::GetInstance()->SetBackgroundBorderRadius(value);
}
}
void JSSecLocationButton::SetBackgroundPadding(const JSCallbackInfo& info)
{
if (info[0]->IsObject()) {
std::optional<CalcDimension> left;
std::optional<CalcDimension> right;
std::optional<CalcDimension> top;
std::optional<CalcDimension> bottom;
JSRef<JSObject> paddingObj = JSRef<JSObject>::Cast(info[0]);
CalcDimension leftDimen;
if (ParseJsDimensionVp(paddingObj->GetProperty("left"), leftDimen)) {
left = leftDimen;
}
CalcDimension rightDimen;
if (ParseJsDimensionVp(paddingObj->GetProperty("right"), rightDimen)) {
right = rightDimen;
}
CalcDimension topDimen;
if (ParseJsDimensionVp(paddingObj->GetProperty("top"), topDimen)) {
top = topDimen;
}
CalcDimension bottomDimen;
if (ParseJsDimensionVp(paddingObj->GetProperty("bottom"), bottomDimen)) {
bottom = bottomDimen;
}
if (left.has_value() || right.has_value() || top.has_value() || bottom.has_value()) {
LocationButtonModelNG::GetInstance()->SetBackgroundPadding(left, right, top, bottom);
return;
}
}
CalcDimension length;
if (!ParseJsDimensionVp(info[0], length)) {
LocationButtonModelNG::GetInstance()->SetBackgroundPadding(std::nullopt);
} else {
LocationButtonModelNG::GetInstance()->SetBackgroundPadding(length);
}
}
void JSSecLocationButton::SetTextIconPadding(const JSCallbackInfo& info)
{
if ((info.Length() < 1)) {
LOGE("The arg is wrong, it is supposed to have at least 1 argument");
return;
}
auto theme = GetTheme<SecurityComponentTheme>();
CHECK_NULL_VOID_NOLOG(theme);
CalcDimension length;
if (!ParseJsDimensionVp(info[0], length)) {
LocationButtonModelNG::GetInstance()->SetTextIconPadding(theme->GetTextIconPadding());
} else {
LocationButtonModelNG::GetInstance()->SetTextIconPadding(length);
}
}
bool JSSecLocationButton::ParseComponentStyle(const JSCallbackInfo& info,
LocationButtonLocationDescription& text, LocationButtonIconStyle& icon, SecurityComponentBackgroundType& bg)
{
if ((info.Length() < 1) || !info[0]->IsObject()) {
return false;
}
auto paramObject = JSRef<JSObject>::Cast(info[0]);
auto value = paramObject->GetProperty("text");
if (value->IsNumber()) {
text = static_cast<LocationButtonLocationDescription>(value->ToNumber<int32_t>());
if ((text < LocationButtonLocationDescription::CURRENT_LOCATION) ||
(text > LocationButtonLocationDescription::CURRENT_POSITION)) {
LOGE("The arg is wrong, text type invalid");
return false;
}
} else {
text = LocationButtonLocationDescription::TEXT_NULL;
}
value = paramObject->GetProperty("icon");
if (value->IsNumber()) {
icon = static_cast<LocationButtonIconStyle>(value->ToNumber<int32_t>());
if ((icon < LocationButtonIconStyle::ICON_FULL_FILLED) ||
(icon > LocationButtonIconStyle::ICON_LINE)) {
LOGE("The arg is wrong, icon type invalid");
return false;
}
} else {
icon = LocationButtonIconStyle::ICON_NULL;
}
if ((text == LocationButtonLocationDescription::TEXT_NULL) &&
(icon == LocationButtonIconStyle::ICON_NULL)) {
LOGE("The arg is wrong, at least one of icon and text must exist");
return false;
}
value = paramObject->GetProperty("background");
if (value->IsNumber()) {
bg = static_cast<SecurityComponentBackgroundType>(value->ToNumber<int32_t>());
if ((bg < SecurityComponentBackgroundType::CAPSULE) ||
(bg > SecurityComponentBackgroundType::NORMAL)) {
LOGE("The arg is wrong, background type invalid");
return false;
}
} else {
bg = SecurityComponentBackgroundType::BACKGROUND_NULL;
}
return true;
}
void JSSecLocationButton::Create(const JSCallbackInfo& info)
{
LocationButtonLocationDescription textDesc;
LocationButtonIconStyle iconType;
SecurityComponentBackgroundType backgroundType;
if (!ParseComponentStyle(info, textDesc, iconType, backgroundType)) {
LocationButtonModelNG::GetInstance()->Create(
static_cast<int32_t>(LocationButtonLocationDescription::CURRENT_LOCATION),
static_cast<int32_t>(LocationButtonIconStyle::ICON_FULL_FILLED),
SecurityComponentBackgroundType::CAPSULE);
} else {
LocationButtonModelNG::GetInstance()->Create(static_cast<int32_t>(textDesc),
static_cast<int32_t>(iconType), backgroundType);
}
}
void JsSecLocationButtonClickFunction::Execute(GestureEvent& info)
{
JSRef<JSObject> clickEventParam = JSRef<JSObject>::New();
Offset globalOffset = info.GetGlobalLocation();
Offset localOffset = info.GetLocalLocation();
clickEventParam->SetProperty<double>("screenX", SystemProperties::Px2Vp(globalOffset.GetX()));
clickEventParam->SetProperty<double>("screenY", SystemProperties::Px2Vp(globalOffset.GetY()));
clickEventParam->SetProperty<double>("x", SystemProperties::Px2Vp(localOffset.GetX()));
clickEventParam->SetProperty<double>("y", SystemProperties::Px2Vp(localOffset.GetY()));
clickEventParam->SetProperty<double>("timestamp",
static_cast<double>(info.GetTimeStamp().time_since_epoch().count()));
clickEventParam->SetProperty<double>("source", static_cast<int32_t>(info.GetSourceDevice()));
clickEventParam->SetProperty<double>("pressure", info.GetForce());
if (info.GetTiltX().has_value()) {
clickEventParam->SetProperty<double>("tiltX", info.GetTiltX().value());
}
if (info.GetTiltY().has_value()) {
clickEventParam->SetProperty<double>("tiltY", info.GetTiltY().value());
}
clickEventParam->SetProperty<double>("sourceTool", static_cast<int32_t>(info.GetSourceTool()));
auto target = CreateEventTargetObject(info);
clickEventParam->SetPropertyObject("target", target);
int32_t res = static_cast<int32_t>(SecurityComponentHandleResult::CLICK_GRANT_FAILED);
#ifdef SECURITY_COMPONENT_ENABLE
auto& secEventValue = info.GetSecCompHandleEvent();
res = secEventValue.GetInt("handleRes", res);
#endif
JSRef<JSVal> errorParam = JSRef<JSVal>::Make(ToJSValue(res));
JSRef<JSVal> params[] = { errorParam, clickEventParam };
JsFunction::ExecuteJS(TWO_PARAMS, params);
}
void JSSecLocationButton::JsOnClick(const JSCallbackInfo& info)
{
if (!info[0]->IsFunction()) {
LOGW("the info is not click function");
return;
}
auto jsOnClickFunc = AceType::MakeRefPtr<JsSecLocationButtonClickFunction>(JSRef<JSFunc>::Cast(info[0]));
auto onTap = [execCtx = info.GetExecutionContext(), func = jsOnClickFunc](GestureEvent& info) {
JAVASCRIPT_EXECUTION_SCOPE_WITH_CHECK(execCtx);
ACE_SCORING_EVENT("onClick");
func->Execute(info);
};
NG::ViewAbstract::SetOnClick(std::move(onTap));
}
void JSSecLocationButton::JSBind(BindingTarget globalObj)
{
JSClass<JSSecLocationButton>::Declare("SecLocationButton");
MethodOptions opt = MethodOptions::NONE;
JSClass<JSSecLocationButton>::StaticMethod("create", &JSSecLocationButton::Create, opt);
JSClass<JSSecLocationButton>::StaticMethod("iconSize", &JSSecLocationButton::SetIconSize);
JSClass<JSSecLocationButton>::StaticMethod("layoutDirection", &JSSecLocationButton::SetLayoutDirection);
JSClass<JSSecLocationButton>::StaticMethod("layoutOrder", &JSSecLocationButton::SetlayoutOrder);
JSClass<JSSecLocationButton>::StaticMethod("fontSize", &JSSecLocationButton::SetFontSize);
JSClass<JSSecLocationButton>::StaticMethod("fontStyle", &JSSecLocationButton::SetFontStyle);
JSClass<JSSecLocationButton>::StaticMethod("iconColor", &JSSecLocationButton::SetIconColor);
JSClass<JSSecLocationButton>::StaticMethod("fontWeight", &JSSecLocationButton::SetFontWeight);
JSClass<JSSecLocationButton>::StaticMethod("fontFamily", &JSSecLocationButton::SetFontFamily);
JSClass<JSSecLocationButton>::StaticMethod("fontColor", &JSSecLocationButton::SetFontColor);
JSClass<JSSecLocationButton>::StaticMethod("backgroundColor", &JSSecLocationButton::SetBackgroundColor);
JSClass<JSSecLocationButton>::StaticMethod("borderStyle", &JSSecLocationButton::SetBackgroundBorderStyle);
JSClass<JSSecLocationButton>::StaticMethod("borderWidth", &JSSecLocationButton::SetBackgroundBorderWidth);
JSClass<JSSecLocationButton>::StaticMethod("borderColor", &JSSecLocationButton::SetBackgroundBorderColor);
JSClass<JSSecLocationButton>::StaticMethod("borderRadius", &JSSecLocationButton::SetBackgroundBorderRadius);
JSClass<JSSecLocationButton>::StaticMethod("backgroundPadding", &JSSecLocationButton::SetBackgroundPadding);
JSClass<JSSecLocationButton>::StaticMethod("textIconPadding", &JSSecLocationButton::SetTextIconPadding);
JSClass<JSSecLocationButton>::StaticMethod("onClick", &JSSecLocationButton::JsOnClick);
JSClass<JSSecLocationButton>::StaticMethod("position", &JSViewAbstract::JsPosition);
JSClass<JSSecLocationButton>::StaticMethod("markAnchor", &JSViewAbstract::JsMarkAnchor);
JSClass<JSSecLocationButton>::StaticMethod("offset", &JSViewAbstract::JsOffset);
JSClass<JSSecLocationButton>::StaticMethod("pop", &JSViewAbstract::Pop, opt);
#if defined(PREVIEW)
JSClass<JSSecLocationButton>::StaticMethod("debugLine", &JSViewAbstract::JsDebugLine);
#endif
JSClass<JSSecLocationButton>::Bind<>(globalObj);
}
} // namespace OHOS::Ace::Framework

View File

@ -0,0 +1,69 @@
/*
* Copyright (c) 2023 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_JS_VIEW_JS_SEC_LOCATION_BUTTON_H
#define FRAMEWORKS_BRIDGE_DECLARATIVE_FRONTEND_JS_VIEW_JS_SEC_LOCATION_BUTTON_H
#include "bridge/declarative_frontend/engine/bindings.h"
#include "bridge/declarative_frontend/engine/functions/js_function.h"
#include "bridge/declarative_frontend/jsview/js_interactable_view.h"
#include "bridge/declarative_frontend/jsview/js_view_abstract.h"
#include "core/components_ng/pattern/security_component/location_button/location_button_common.h"
#include "core/event/mouse_event.h"
#include "core/gestures/click_recognizer.h"
namespace OHOS::Ace::Framework {
class JsSecLocationButtonClickFunction : public JsFunction {
DECLARE_ACE_TYPE(JsSecLocationButtonClickFunction, JsFunction)
public:
explicit JsSecLocationButtonClickFunction(const JSRef<JSFunc>& jsFunction) :
JsFunction(JSRef<JSObject>(), jsFunction) {}
~JsSecLocationButtonClickFunction() override {};
void Execute() override
{
JsFunction::ExecuteJS();
};
void Execute(GestureEvent& info);
};
class JSSecLocationButton : public JSViewAbstract, public JSInteractableView {
public:
static void SetIconSize(const JSCallbackInfo& info);
static void SetIconColor(const JSCallbackInfo& info);
static void SetFontSize(const JSCallbackInfo& info);
static void SetFontStyle(const JSCallbackInfo& info);
static void SetFontWeight(const JSCallbackInfo& info);
static void SetFontFamily(const JSCallbackInfo& info);
static void SetFontColor(const JSCallbackInfo& info);
static void SetLayoutDirection(const JSCallbackInfo& info);
static void SetlayoutOrder(const JSCallbackInfo& info);
static void SetBackgroundColor(const JSCallbackInfo& info);
static void SetBackgroundPadding(const JSCallbackInfo& info);
static void SetTextIconPadding(const JSCallbackInfo& info);
static void SetBackgroundBorderStyle(const JSCallbackInfo& info);
static void SetBackgroundBorderWidth(const JSCallbackInfo& info);
static void SetBackgroundBorderColor(const JSCallbackInfo& info);
static void SetBackgroundBorderRadius(const JSCallbackInfo& info);
static void JSBind(BindingTarget globalObj);
static bool ParseComponentStyle(const JSCallbackInfo& info, LocationButtonLocationDescription& text,
LocationButtonIconStyle& icon, SecurityComponentBackgroundType& bg);
static void Create(const JSCallbackInfo& info);
static void JsOnClick(const JSCallbackInfo& info);
};
} // namespace OHOS::Ace::Framework
#endif // FRAMEWORKS_BRIDGE_DECLARATIVE_FRONTEND_JS_VIEW_JS_SEC_LOCATION_BUTTON_H

View File

@ -435,6 +435,8 @@ template("ace_core_source_set") {
"$ace_root/frameworks/core/components_ng/pattern/text_field:ace_core_components_text_field_pattern_ng_$platform",
]
deps += [ "$ace_root/frameworks/core/components_ng/pattern/security_component:ace_core_components_security_component_pattern_ng_$platform" ]
# xcomponent components supports phone, TV and wearable except PC Preview
if (defined(config.xcomponent_components_support) &&
config.xcomponent_components_support) {

View File

@ -75,7 +75,9 @@ static std::unordered_map<InternalResource::ResourceId, std::string> RESOURCE_IC
{ InternalResource::ResourceId::INPUT_SEARCH_SVG, "ic_public_input_search" },
{ InternalResource::ResourceId::APP_BAR_BACK_SVG, "app_bar_back" },
{ InternalResource::ResourceId::APP_BAR_FA_SVG, "app_bar_fa" },
{ InternalResource::ResourceId::MENU_OK_SVG, "ic_public_ok" }
{ InternalResource::ResourceId::MENU_OK_SVG, "ic_public_ok" },
{ InternalResource::ResourceId::LOCATION_BUTTON_FILLED_SVG, "location_button_filled"},
{ InternalResource::ResourceId::LOCATION_BUTTON_LINE_SVG, "location_button_line"}
};
}

View File

@ -67,6 +67,7 @@ const char THEME_PATTERN_VIDEO[] = "video_pattern";
const char THEME_PATTERN_INDEXER[] = "indexer_pattern";
const char THEME_PATTERN_APP_BAR[] = "app_bar_pattern";
const char THEME_PATTERN_ADVANCED_PATTERN[] = "advanced_pattern";
const char THEME_PATTERN_SECURITY_COMPONENT[] = "security_component_pattern";
// pattern general attributes
const char PATTERN_FG_COLOR[] = "fg_color";
@ -148,4 +149,4 @@ const char BADGE_BORDER_WIDTH[] = "border_width";
// swiper attributes
const char INDICATOR_TEXT_FONT_SIZE[] = "indicator_text_font_size";
const char INDICATOR_TEXT_FONT_COLOR[] = "indicator_text_font_color";
} // namespace OHOS::Ace
} // namespace OHOS::Ace

View File

@ -70,6 +70,7 @@ extern const char THEME_PATTERN_VIDEO[];
extern const char THEME_PATTERN_INDEXER[];
extern const char THEME_PATTERN_APP_BAR[];
extern const char THEME_PATTERN_ADVANCED_PATTERN[];
extern const char THEME_PATTERN_SECURITY_COMPONENT[];
// pattern general attributes
extern const char PATTERN_FG_COLOR[];

View File

@ -59,6 +59,7 @@
#include "core/components/tool_bar/tool_bar_theme.h"
#include "core/components/video/video_theme.h"
#include "core/components_ng/pattern/app_bar/app_bar_theme.h"
#include "core/components_ng/pattern/security_component/security_component_theme.h"
#include "core/components_v2/pattern_lock/pattern_lock_theme.h"
#include "core/components/theme/advanced_pattern_theme.h"
@ -118,7 +119,8 @@ const std::unordered_map<ThemeType, RefPtr<Theme>(*)(const RefPtr<ThemeConstants
{ V2::PatternLockTheme::TypeId(), &ThemeBuildFunc<V2::PatternLockTheme::Builder> },
{ IndexerTheme::TypeId(), &ThemeBuildFunc<IndexerTheme::Builder> },
{ NG::AppBarTheme::TypeId(), &ThemeBuildFunc<NG::AppBarTheme::Builder> },
{ AdvancedPatternTheme::TypeId(), &ThemeBuildFunc<AdvancedPatternTheme::Builder> }
{ AdvancedPatternTheme::TypeId(), &ThemeBuildFunc<AdvancedPatternTheme::Builder> },
{ NG::SecurityComponentTheme::TypeId(), &ThemeBuildFunc<NG::SecurityComponentTheme::Builder> }
};
} // namespace

View File

@ -300,6 +300,10 @@ void ClickRecognizer::SendCallbackMsg(const std::unique_ptr<GestureEventFunc>& o
info.SetTiltY(touchPoint.tiltY.value());
}
info.SetSourceTool(touchPoint.sourceTool);
#ifdef SECURITY_COMPONENT_ENABLE
info.SetDisplayX(touchPoint.screenX);
info.SetDisplayY(touchPoint.screenY);
#endif
(*onAction)(info);
}
}

View File

@ -0,0 +1,40 @@
# Copyright (c) 2023 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.
import("../../components.gni")
if (is_standard_system) {
config("ohos_security_component_config") {
include_dirs = [ "//third_party/json/include" ]
}
}
build_component_ng("security_component_pattern_ng") {
sources = [
"location_button/location_button_model_ng.cpp",
"security_component_accessibility_property.cpp",
"security_component_model_ng.cpp",
"security_component_pattern.cpp",
]
if (is_standard_system) {
configs = [ ":ohos_security_component_config" ]
external_deps = []
if (security_component_enable) {
external_deps += [
"security_component:libsecurity_component_framework",
"security_component:libsecurity_component_sdk",
]
}
}
}

View File

@ -0,0 +1,46 @@
/*
* Copyright (c) 2023 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_PATTERN_LOCATION_BUTTON_LOCATION_COMMON_H
#define FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_PATTERN_LOCATION_BUTTON_LOCATION_COMMON_H
#include <cstdint>
#include "base/geometry/dimension.h"
#include "core/components_ng/pattern/security_component/security_component_common.h"
namespace OHOS::Ace {
enum class LocationButtonIconStyle : int32_t {
ICON_NULL = -1,
ICON_FULL_FILLED = 0,
ICON_LINE = 1
};
enum class LocationButtonLocationDescription : int32_t {
TEXT_NULL = -1,
CURRENT_LOCATION = 0,
ADD_LOCATION,
SELECT_LOCATION,
SHARE_LOCATION,
SEND_LOCATION,
LOCATING,
LOCATION,
SEND_CURRENT_LOCATION,
RELOCATION,
PUNCHIN,
CURRENT_POSITION
};
} // namespace OHOS::Ace
#endif // FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_PATTERN_LOCATION_BUTTON_LOCATION_COMMON_H

View File

@ -0,0 +1,67 @@
/*
* Copyright (c) 2023 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/pattern/security_component/location_button/location_button_model_ng.h"
#include "base/log/ace_scoring_log.h"
#include "base/resource/internal_resource.h"
#include "core/components_ng/pattern/security_component/location_button/location_button_common.h"
#include "core/components_ng/pattern/security_component/security_component_pattern.h"
#include "core/components_v2/inspector/inspector_constants.h"
namespace OHOS::Ace::NG {
std::unique_ptr<LocationButtonModelNG> LocationButtonModelNG::instance_ = nullptr;
static const std::vector<uint32_t> ICON_RESOURCE_TABLE = {
static_cast<uint32_t>(InternalResource::ResourceId::LOCATION_BUTTON_FILLED_SVG),
static_cast<uint32_t>(InternalResource::ResourceId::LOCATION_BUTTON_LINE_SVG)
};
LocationButtonModelNG* LocationButtonModelNG::GetInstance()
{
if (!instance_) {
instance_.reset(new LocationButtonModelNG());
}
return instance_.get();
}
void LocationButtonModelNG::Create(int32_t text, int32_t icon,
SecurityComponentBackgroundType backgroundType)
{
SecurityComponentModelNG::CreateCommon(V2::SEC_LOCATION_BUTTON_ETS_TAG,
text, icon, backgroundType, []() { return AceType::MakeRefPtr<SecurityComponentPattern>(); });
}
bool LocationButtonModelNG::GetIconResource(int32_t iconStyle, InternalResource::ResourceId& id)
{
if ((iconStyle < 0) || (static_cast<uint32_t>(iconStyle) >= ICON_RESOURCE_TABLE.size())) {
LOGE("Icon type is invalid, can not get resource id");
return false;
}
id = static_cast<InternalResource::ResourceId>(ICON_RESOURCE_TABLE[iconStyle]);
return true;
}
bool LocationButtonModelNG::GetTextResource(int32_t textStyle, std::string& text)
{
auto theme = GetTheme();
if (theme == nullptr) {
LOGE("theme in null");
return false;
}
text = theme->GetLocationDescriptions(textStyle);
return true;
}
} // namespace OHOS::Ace::NG

View File

@ -0,0 +1,33 @@
/*
* Copyright (c) 2023 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_PATTERN_LOCATION_BUTTON_LOCATION_BUTTON_MODEL_NG_H
#define FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_PATTERN_LOCATION_BUTTON_LOCATION_BUTTON_MODEL_NG_H
#include "core/components_ng/pattern/security_component/security_component_model_ng.h"
namespace OHOS::Ace::NG {
class ACE_EXPORT LocationButtonModelNG : public SecurityComponentModelNG {
public:
static LocationButtonModelNG* GetInstance();
void Create(int32_t text, int32_t icon,
SecurityComponentBackgroundType backgroundType) override;
virtual bool GetIconResource(int32_t iconStyle, InternalResource::ResourceId& id) override;
virtual bool GetTextResource(int32_t textStyle, std::string& text) override;
private:
static std::unique_ptr<LocationButtonModelNG> instance_;
};
} // namespace OHOS::Ace::NG
#endif // FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_PATTERN_LOCATION_BUTTON_LOCATION_BUTTON_MODEL_NG_H

View File

@ -0,0 +1,40 @@
/*
* Copyright (c) 2023 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/pattern/security_component/security_component_accessibility_property.h"
#include "base/utils/utils.h"
#include "core/components_ng/base/frame_node.h"
#include "core/components_ng/pattern/text/text_pattern.h"
namespace OHOS::Ace::NG {
std::string SecurityComponentAccessibilityProperty::GetText() const
{
std::string value = "";
auto frameNode = host_.Upgrade();
CHECK_NULL_RETURN(frameNode, value);
for (const auto& child : frameNode->GetChildren()) {
auto node = AceType::DynamicCast<FrameNode, UINode>(child);
CHECK_NULL_RETURN(node, value);
if (node->GetTag() == V2::TEXT_ETS_TAG) {
auto textLayoutProperty = node->GetLayoutProperty<TextLayoutProperty>();
CHECK_NULL_RETURN(textLayoutProperty, value);
value = textLayoutProperty->GetContentValue(value);
break;
}
}
return value;
}
} // namespace OHOS::Ace::NG

View File

@ -0,0 +1,36 @@
/*
* Copyright (c) 2023 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_PATTERNS_SECURITY_COMPONENT_ACCESSIBILITY_PROPERTY_H
#define FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_PATTERNS_SECURITY_COMPONENT_ACCESSIBILITY_PROPERTY_H
#include "core/components_ng/property/accessibility_property.h"
namespace OHOS::Ace::NG {
class SecurityComponentAccessibilityProperty : public AccessibilityProperty {
DECLARE_ACE_TYPE(SecurityComponentAccessibilityProperty, AccessibilityProperty);
public:
SecurityComponentAccessibilityProperty() = default;
~SecurityComponentAccessibilityProperty() override = default;
std::string GetText() const override;
private:
ACE_DISALLOW_COPY_AND_MOVE(SecurityComponentAccessibilityProperty);
};
} // namespace OHOS::Ace::NG
#endif

View File

@ -0,0 +1,55 @@
/*
* Copyright (c) 2023 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_PATTERN_SECURITY_COMPONENT_COMMON_H
#define FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_PATTERN_SECURITY_COMPONENT_COMMON_H
#include <cstdint>
#include "base/geometry/dimension.h"
#include "core/components/common/layout/constants.h"
namespace OHOS::Ace {
enum class SecurityComponentHandleResult : int32_t {
CLICK_SUCCESS = 0,
CLICK_GRANT_FAILED = 1,
};
enum class SecurityComponentIconStyle : int32_t {
ICON_NULL = -1,
};
enum class SecurityComponentDescription : int32_t {
TEXT_NULL = -1,
};
enum class SecurityComponentBackgroundType : int32_t {
BACKGROUND_NULL = -1,
CAPSULE = 0,
CIRCLE = 1,
NORMAL = 2
};
enum class SecurityComponentLayoutDirection : int32_t {
HORIZONTAL = 0,
VERTICAL = 1,
};
enum class SecSecurityComponentLayoutOrder : int32_t {
ICON_FIRST = 0,
TEXT_FIRST = 1,
};
} // namespace OHOS::Ace
#endif // FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_PATTERN_SECURITY_COMPONENT_COMMON_H

View File

@ -0,0 +1,81 @@
/*
* Copyright (c) 2023 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_PATTERN_MYCIRCLE_SECURITY_COMPONENT_LAYOUT_PROPERTY_H
#define FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_PATTERN_MYCIRCLE_SECURITY_COMPONENT_LAYOUT_PROPERTY_H
#include "base/geometry/dimension.h"
#include "core/components_ng/layout/layout_property.h"
#include "core/components_ng/pattern/security_component/security_component_common.h"
#include "core/components_ng/property/property.h"
#include "core/components/common/properties/text_style.h"
namespace OHOS::Ace::NG {
class ACE_EXPORT SecurityComponentLayoutProperty : public LayoutProperty {
DECLARE_ACE_TYPE(SecurityComponentLayoutProperty, LayoutProperty);
public:
SecurityComponentLayoutProperty() = default;
~SecurityComponentLayoutProperty() override = default;
RefPtr<LayoutProperty> Clone() const override
{
auto value = MakeRefPtr<SecurityComponentLayoutProperty>();
value->LayoutProperty::UpdateLayoutProperty(DynamicCast<LayoutProperty>(this));
value->propBackgroundLeftPadding_ = CloneBackgroundLeftPadding();
value->propBackgroundRightPadding_ = CloneBackgroundRightPadding();
value->propBackgroundTopPadding_ = CloneBackgroundTopPadding();
value->propBackgroundBottomPadding_ = CloneBackgroundBottomPadding();
value->propTextIconPadding_ = CloneTextIconPadding();
value->propSecurityComponentDescription_ = CloneSecurityComponentDescription();
value->propIconStyle_ = CloneIconStyle();
value->propBackgroundType_ = CloneBackgroundType();
value->propTextIconLayoutDirection_ = CloneTextIconLayoutDirection();
value->propLayoutOrder_ = CloneLayoutOrder();
return value;
}
void Reset() override
{
LayoutProperty::Reset();
ResetBackgroundLeftPadding();
ResetBackgroundRightPadding();
ResetBackgroundTopPadding();
ResetBackgroundBottomPadding();
ResetTextIconPadding();
ResetSecurityComponentDescription();
ResetIconStyle();
ResetBackgroundType();
ResetTextIconLayoutDirection();
ResetLayoutOrder();
}
ACE_DEFINE_PROPERTY_ITEM_WITHOUT_GROUP(BackgroundLeftPadding, Dimension, PROPERTY_UPDATE_MEASURE);
ACE_DEFINE_PROPERTY_ITEM_WITHOUT_GROUP(BackgroundRightPadding, Dimension, PROPERTY_UPDATE_MEASURE);
ACE_DEFINE_PROPERTY_ITEM_WITHOUT_GROUP(BackgroundTopPadding, Dimension, PROPERTY_UPDATE_MEASURE);
ACE_DEFINE_PROPERTY_ITEM_WITHOUT_GROUP(BackgroundBottomPadding, Dimension, PROPERTY_UPDATE_MEASURE);
ACE_DEFINE_PROPERTY_ITEM_WITHOUT_GROUP(TextIconPadding, Dimension, PROPERTY_UPDATE_MEASURE);
ACE_DEFINE_PROPERTY_ITEM_WITHOUT_GROUP(SecurityComponentDescription, int32_t, PROPERTY_UPDATE_NORMAL);
ACE_DEFINE_PROPERTY_ITEM_WITHOUT_GROUP(IconStyle, int32_t, PROPERTY_UPDATE_NORMAL);
ACE_DEFINE_PROPERTY_ITEM_WITHOUT_GROUP(BackgroundType, SecurityComponentBackgroundType, PROPERTY_UPDATE_NORMAL);
ACE_DEFINE_PROPERTY_ITEM_WITHOUT_GROUP(TextIconLayoutDirection,
SecurityComponentLayoutDirection, PROPERTY_UPDATE_MEASURE);
ACE_DEFINE_PROPERTY_ITEM_WITHOUT_GROUP(LayoutOrder, SecSecurityComponentLayoutOrder, PROPERTY_UPDATE_MEASURE);
ACE_DISALLOW_COPY_AND_MOVE(SecurityComponentLayoutProperty);
};
} // namespace OHOS::Ace::NG
#endif // FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_PATTERN_MYCIRCLE_SECURITY_COMPONENT_LAYOUT_PROPERTY_H

View File

@ -0,0 +1,343 @@
/*
* Copyright (c) 2023 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/pattern/security_component/security_component_model_ng.h"
#include "base/i18n/localization.h"
#include "base/log/ace_scoring_log.h"
#include "core/components/common/properties/text_style.h"
#include "core/components_ng/base/frame_node.h"
#include "core/components_ng/base/view_stack_processor.h"
#include "core/components_ng/pattern/button/button_layout_property.h"
#include "core/components_ng/pattern/button/button_pattern.h"
#include "core/components_ng/pattern/image/image_pattern.h"
#include "core/components_ng/pattern/security_component/security_component_pattern.h"
#include "core/components_ng/pattern/security_component/security_component_theme.h"
#include "core/components_ng/pattern/text/text_pattern.h"
#include "core/components_v2/inspector/inspector_constants.h"
#include "core/pipeline_ng/pipeline_context.h"
namespace OHOS::Ace::NG {
RefPtr<SecurityComponentTheme> SecurityComponentModelNG::GetTheme()
{
auto pipeline = PipelineContext::GetCurrentContext();
CHECK_NULL_RETURN(pipeline, nullptr);
return pipeline->GetTheme<SecurityComponentTheme>();
}
void SecurityComponentModelNG::InitLayoutProperty(RefPtr<FrameNode>& node, int32_t text, int32_t icon,
SecurityComponentBackgroundType backgroundType)
{
auto property = node->GetLayoutProperty<SecurityComponentLayoutProperty>();
CHECK_NULL_VOID(property);
auto secCompTheme = GetTheme();
CHECK_NULL_VOID(secCompTheme);
property->UpdateSecurityComponentDescription(text);
property->UpdateIconStyle(icon);
property->UpdateBackgroundType(backgroundType);
if ((text != static_cast<int32_t>(SecurityComponentDescription::TEXT_NULL)) &&
(icon != static_cast<int32_t>(SecurityComponentIconStyle::ICON_NULL))) {
property->UpdateTextIconPadding(secCompTheme->GetTextIconPadding());
} else {
property->UpdateTextIconPadding(Dimension(0.0F));
}
if (backgroundType == SecurityComponentBackgroundType::BACKGROUND_NULL) {
property->UpdateBackgroundLeftPadding(secCompTheme->GetPaddingWithoutBg());
property->UpdateBackgroundRightPadding(secCompTheme->GetPaddingWithoutBg());
property->UpdateBackgroundTopPadding(secCompTheme->GetPaddingWithoutBg());
property->UpdateBackgroundBottomPadding(secCompTheme->GetPaddingWithoutBg());
} else {
property->UpdateBackgroundLeftPadding(secCompTheme->GetBackgroundLeftPadding());
property->UpdateBackgroundRightPadding(secCompTheme->GetBackgroundRightPadding());
property->UpdateBackgroundTopPadding(secCompTheme->GetBackgroundTopPadding());
property->UpdateBackgroundBottomPadding(secCompTheme->GetBackgroundBottomPadding());
}
property->UpdateTextIconLayoutDirection(SecurityComponentLayoutDirection::HORIZONTAL);
property->UpdateLayoutOrder(SecSecurityComponentLayoutOrder::ICON_FIRST);
}
void SecurityComponentModelNG::CreateCommon(const std::string& tag, int32_t text, int32_t icon,
SecurityComponentBackgroundType backgroundType, const std::function<RefPtr<Pattern>(void)>& patternCreator)
{
auto stack = ViewStackProcessor::GetInstance();
auto nodeId = stack->ClaimNodeId();
auto frameNode = FrameNode::GetOrCreateFrameNode(tag, nodeId, patternCreator);
CHECK_NULL_VOID(frameNode);
if (frameNode->GetChildren().empty()) {
if (backgroundType != SecurityComponentBackgroundType::BACKGROUND_NULL) {
auto buttonNode = FrameNode::CreateFrameNode(
V2::BUTTON_ETS_TAG, ElementRegister::GetInstance()->MakeUniqueId(),
AceType::MakeRefPtr<ButtonPattern>());
buttonNode->SetInternal();
SetDefaultBackgroundButton(buttonNode, backgroundType);
frameNode->AddChild(buttonNode);
}
if (icon != static_cast<int32_t>(SecurityComponentIconStyle::ICON_NULL)) {
auto imageIcon = FrameNode::CreateFrameNode(
V2::IMAGE_ETS_TAG, ElementRegister::GetInstance()->MakeUniqueId(), AceType::MakeRefPtr<ImagePattern>());
imageIcon->SetInternal();
InternalResource::ResourceId iconId;
if (GetIconResource(icon, iconId)) {
SetDefaultIconStyle(imageIcon, iconId);
}
frameNode->AddChild(imageIcon);
}
if (text != static_cast<int32_t>(SecurityComponentDescription::TEXT_NULL)) {
auto textNode = FrameNode::CreateFrameNode(
V2::TEXT_ETS_TAG, ElementRegister::GetInstance()->MakeUniqueId(), AceType::MakeRefPtr<TextPattern>());
textNode->SetInternal();
std::string textStr = "";
GetTextResource(text, textStr);
SetDefaultTextStyle(textNode, textStr);
frameNode->AddChild(textNode);
}
}
InitLayoutProperty(frameNode, text, icon, backgroundType);
stack->Push(frameNode);
}
void SecurityComponentModelNG::SetDefaultTextStyle(const RefPtr<FrameNode>& textNode, const std::string& text)
{
auto secCompTheme = GetTheme();
CHECK_NULL_VOID(secCompTheme);
auto textLayoutProperty = textNode->GetLayoutProperty<TextLayoutProperty>();
CHECK_NULL_VOID(textLayoutProperty);
textLayoutProperty->UpdateContent(text);
textLayoutProperty->UpdateMaxLines(1);
textLayoutProperty->UpdateFontSize(secCompTheme->GetFontSize());
textLayoutProperty->UpdateTextColor(secCompTheme->GetFontColor());
textLayoutProperty->UpdateItalicFontStyle(Ace::FontStyle::NORMAL);
textLayoutProperty->UpdateFontWeight(FontWeight::NORMAL);
std::vector<std::string> defaultFontFamily = { "HarmonyOS Sans" };
textLayoutProperty->UpdateFontFamily(defaultFontFamily);
}
void SecurityComponentModelNG::SetDefaultIconStyle(const RefPtr<FrameNode>& imageNode, InternalResource::ResourceId id)
{
auto secCompTheme = GetTheme();
CHECK_NULL_VOID(secCompTheme);
ImageSourceInfo imageSourceInfo;
imageSourceInfo.SetResourceId(id);
imageSourceInfo.SetFillColor(secCompTheme->GetIconColor());
auto iconProp = imageNode->GetLayoutProperty<ImageLayoutProperty>();
CHECK_NULL_VOID(iconProp);
iconProp->UpdateImageSourceInfo(imageSourceInfo);
iconProp->UpdateUserDefinedIdealSize(
CalcSize(NG::CalcLength(secCompTheme->GetIconSize()), NG::CalcLength(secCompTheme->GetIconSize())));
}
static ButtonType TransformSecCompBgType(SecurityComponentBackgroundType type)
{
ButtonType buttonType = ButtonType::CAPSULE;
switch (type) {
case SecurityComponentBackgroundType::CAPSULE:
buttonType = ButtonType::CAPSULE;
break;
case SecurityComponentBackgroundType::CIRCLE:
buttonType = ButtonType::CIRCLE;
break;
case SecurityComponentBackgroundType::NORMAL:
buttonType = ButtonType::NORMAL;
break;
default:
LOGE("Unknown button type");
break;
}
return buttonType;
}
void SecurityComponentModelNG::SetDefaultBackgroundButton(const RefPtr<FrameNode>& buttonNode,
SecurityComponentBackgroundType type)
{
auto buttonLayoutProperty = buttonNode->GetLayoutProperty<ButtonLayoutProperty>();
CHECK_NULL_VOID(buttonLayoutProperty);
const auto& renderContext = buttonNode->GetRenderContext();
CHECK_NULL_VOID(renderContext);
auto secCompTheme = GetTheme();
CHECK_NULL_VOID(secCompTheme);
BorderColorProperty borderColor;
borderColor.SetColor(secCompTheme->GetBorderColor());
renderContext->UpdateBorderColor(borderColor);
BorderWidthProperty widthProp;
widthProp.SetBorderWidth(secCompTheme->GetBorderWidth());
buttonLayoutProperty->UpdateBorderWidth(widthProp);
BorderStyleProperty style;
style.SetBorderStyle(BorderStyle::NONE);
renderContext->UpdateBorderStyle(style);
buttonLayoutProperty->UpdateBorderRadius(secCompTheme->GetBorderRadius());
renderContext->UpdateBackgroundColor(secCompTheme->GetBackgroundColor());
buttonLayoutProperty->UpdateType(TransformSecCompBgType(type));
}
template<typename T>
RefPtr<T> GetChildLayoutProprty(const std::string& tag)
{
auto node = GetCurSecCompChildNode(tag);
CHECK_NULL_RETURN(node, nullptr);
return node->GetLayoutProperty<T>();
}
void SecurityComponentModelNG::SetIconSize(const Dimension& value)
{
auto iconProp = GetChildLayoutProprty<ImageLayoutProperty>(V2::IMAGE_ETS_TAG);
CHECK_NULL_VOID(iconProp);
iconProp->UpdateUserDefinedIdealSize(CalcSize(NG::CalcLength(value), NG::CalcLength(value)));
}
void SecurityComponentModelNG::SetIconColor(const Color& value)
{
auto iconProp = GetChildLayoutProprty<ImageLayoutProperty>(V2::IMAGE_ETS_TAG);
CHECK_NULL_VOID(iconProp);
auto iconSrcInfo = iconProp->GetImageSourceInfo().value();
iconSrcInfo.SetFillColor(value);
iconProp->UpdateImageSourceInfo(iconSrcInfo);
}
void SecurityComponentModelNG::SetFontSize(const Dimension& value)
{
auto textProp = GetChildLayoutProprty<TextLayoutProperty>(V2::TEXT_ETS_TAG);
CHECK_NULL_VOID(textProp);
textProp->UpdateFontSize(value);
}
void SecurityComponentModelNG::SetFontStyle(const Ace::FontStyle& value)
{
auto textProp = GetChildLayoutProprty<TextLayoutProperty>(V2::TEXT_ETS_TAG);
CHECK_NULL_VOID(textProp);
textProp->UpdateItalicFontStyle(value);
}
void SecurityComponentModelNG::SetFontWeight(const FontWeight& value)
{
auto textProp = GetChildLayoutProprty<TextLayoutProperty>(V2::TEXT_ETS_TAG);
CHECK_NULL_VOID(textProp);
textProp->UpdateFontWeight(value);
}
void SecurityComponentModelNG::SetFontFamily(const std::vector<std::string>& fontFamilies)
{
auto textProp = GetChildLayoutProprty<TextLayoutProperty>(V2::TEXT_ETS_TAG);
CHECK_NULL_VOID(textProp);
textProp->UpdateFontFamily(fontFamilies);
}
void SecurityComponentModelNG::SetFontColor(const Color& value)
{
auto textProp = GetChildLayoutProprty<TextLayoutProperty>(V2::TEXT_ETS_TAG);
CHECK_NULL_VOID(textProp);
textProp->UpdateTextColor(value);
}
void SecurityComponentModelNG::SetBackgroundColor(const Color& value)
{
auto bgNode = GetCurSecCompChildNode(V2::BUTTON_ETS_TAG);
CHECK_NULL_VOID(bgNode);
const auto& renderContext = bgNode->GetRenderContext();
CHECK_NULL_VOID(renderContext);
renderContext->UpdateBackgroundColor(value);
}
void SecurityComponentModelNG::SetBackgroundBorderWidth(const Dimension& value)
{
auto bgProp = GetChildLayoutProprty<ButtonLayoutProperty>(V2::BUTTON_ETS_TAG);
CHECK_NULL_VOID(bgProp);
BorderWidthProperty widthProp;
widthProp.SetBorderWidth(value);
bgProp->UpdateBorderWidth(widthProp);
}
void SecurityComponentModelNG::SetBackgroundBorderColor(const Color& value)
{
auto bgNode = GetCurSecCompChildNode(V2::BUTTON_ETS_TAG);
CHECK_NULL_VOID(bgNode);
const auto& renderContext = bgNode->GetRenderContext();
CHECK_NULL_VOID(renderContext);
BorderColorProperty borderColor;
borderColor.SetColor(value);
renderContext->UpdateBorderColor(borderColor);
}
void SecurityComponentModelNG::SetBackgroundBorderStyle(const BorderStyle& value)
{
auto bgNode = GetCurSecCompChildNode(V2::BUTTON_ETS_TAG);
CHECK_NULL_VOID(bgNode);
const auto& renderContext = bgNode->GetRenderContext();
CHECK_NULL_VOID(renderContext);
BorderStyleProperty style;
style.SetBorderStyle(value);
renderContext->UpdateBorderStyle(style);
}
void SecurityComponentModelNG::SetBackgroundBorderRadius(const Dimension& value)
{
auto bgProp = GetChildLayoutProprty<ButtonLayoutProperty>(V2::BUTTON_ETS_TAG);
CHECK_NULL_VOID(bgProp);
bgProp->UpdateBorderRadius(value);
}
void SecurityComponentModelNG::SetBackgroundPadding(const std::optional<Dimension>& left,
const std::optional<Dimension>& right, const std::optional<Dimension>& top,
const std::optional<Dimension>& bottom)
{
if (GetCurSecCompChildNode(V2::BUTTON_ETS_TAG) == nullptr) {
LOGE("Can not set background padding without background");
return;
}
auto secCompTheme = GetTheme();
CHECK_NULL_VOID(secCompTheme);
ACE_UPDATE_LAYOUT_PROPERTY(SecurityComponentLayoutProperty,
BackgroundLeftPadding, left.value_or(secCompTheme->GetBackgroundLeftPadding()));
ACE_UPDATE_LAYOUT_PROPERTY(SecurityComponentLayoutProperty,
BackgroundRightPadding, right.value_or(secCompTheme->GetBackgroundRightPadding()));
ACE_UPDATE_LAYOUT_PROPERTY(SecurityComponentLayoutProperty,
BackgroundTopPadding, top.value_or(secCompTheme->GetBackgroundTopPadding()));
ACE_UPDATE_LAYOUT_PROPERTY(SecurityComponentLayoutProperty,
BackgroundBottomPadding, bottom.value_or(secCompTheme->GetBackgroundBottomPadding()));
}
void SecurityComponentModelNG::SetBackgroundPadding(const std::optional<Dimension>& padding)
{
SetBackgroundPadding(padding, padding, padding, padding);
}
void SecurityComponentModelNG::SetTextIconPadding(const Dimension& value)
{
if ((GetCurSecCompChildNode(V2::TEXT_ETS_TAG) == nullptr) ||
(GetCurSecCompChildNode(V2::IMAGE_ETS_TAG) == nullptr)) {
LOGE("Can not set text icon padding without text and icon");
return;
}
ACE_UPDATE_LAYOUT_PROPERTY(SecurityComponentLayoutProperty, TextIconPadding, value);
}
void SecurityComponentModelNG::SetTextIconLayoutDirection(const SecurityComponentLayoutDirection& value)
{
ACE_UPDATE_LAYOUT_PROPERTY(SecurityComponentLayoutProperty, TextIconLayoutDirection, value);
}
void SecurityComponentModelNG::SetlayoutOrder(const SecSecurityComponentLayoutOrder& value)
{
ACE_UPDATE_LAYOUT_PROPERTY(SecurityComponentLayoutProperty, LayoutOrder, value);
}
} // namespace OHOS::Ace::NG

View File

@ -0,0 +1,77 @@
/*
* Copyright (c) 2023 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_PATTERN_SECURITY_COMPONENT_SECURITY_COMPONENT_MODEL_NG_H
#define FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_PATTERN_SECURITY_COMPONENT_SECURITY_COMPONENT_MODEL_NG_H
#include "core/components_ng/base/frame_node.h"
#include "core/components_ng/base/view_abstract_model.h"
#include "core/components_ng/pattern/security_component/security_component_common.h"
#include "core/components_ng/pattern/security_component/security_component_theme.h"
#include "core/components/common/layout/constants.h"
#include "core/components/common/properties/text_style.h"
#include "core/gestures/gesture_info.h"
namespace OHOS::Ace::NG {
class ACE_EXPORT SecurityComponentModelNG {
public:
virtual ~SecurityComponentModelNG() = default;
virtual void Create(int32_t text, int32_t icon,
SecurityComponentBackgroundType backgroundType) = 0;
void CreateCommon(const std::string& tag, int32_t text, int32_t icon,
SecurityComponentBackgroundType backgroundType,
const std::function<RefPtr<Pattern>(void)>& patternCreator);
virtual void SetIconSize(const Dimension& value);
virtual void SetIconColor(const Color& value);
virtual void SetFontSize(const Dimension& value);
virtual void SetFontStyle(const Ace::FontStyle& value);
virtual void SetFontWeight(const FontWeight& value);
virtual void SetFontFamily(const std::vector<std::string>& fontFamilies);
virtual void SetFontColor(const Color& value);
virtual void SetBackgroundColor(const Color& value);
virtual void SetBackgroundBorderWidth(const Dimension& value);
virtual void SetBackgroundBorderColor(const Color& value);
virtual void SetBackgroundBorderStyle(const BorderStyle& value);
virtual void SetBackgroundBorderRadius(const Dimension& value);
virtual void SetBackgroundPadding(const std::optional<Dimension>& left, const std::optional<Dimension>& right,
const std::optional<Dimension>& top, const std::optional<Dimension>& bottom);
virtual void SetBackgroundPadding(const std::optional<Dimension>& padding);
virtual void SetTextIconPadding(const Dimension& value);
virtual void SetTextIconLayoutDirection(const SecurityComponentLayoutDirection& value);
virtual void SetlayoutOrder(const SecSecurityComponentLayoutOrder& value);
virtual bool GetIconResource(int32_t iconStyle, InternalResource::ResourceId& id)
{
return false;
}
virtual bool GetTextResource(int32_t textStyle, std::string& text)
{
return false;
}
protected:
RefPtr<SecurityComponentTheme> GetTheme();
private:
void SetDefaultIconStyle(const RefPtr<FrameNode>& imageNode, InternalResource::ResourceId id);
void SetDefaultBackgroundButton(const RefPtr<FrameNode>& buttonNode,
SecurityComponentBackgroundType type);
void SetDefaultTextStyle(const RefPtr<FrameNode>& textNode, const std::string& text);
void InitLayoutProperty(RefPtr<FrameNode>& node, int32_t text, int32_t icon,
SecurityComponentBackgroundType backgroundType);
};
} // namespace OHOS::Ace::NG
#endif // FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_PATTERN_SECURITY_COMPONENT_SECURITY_COMPONENT_MODEL_NG_H

View File

@ -0,0 +1,31 @@
/*
* Copyright (c) 2023 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/pattern/security_component/security_component_pattern.h"
#include "base/log/ace_scoring_log.h"
#include "core/components_ng/pattern/button/button_layout_property.h"
#include "core/components_ng/pattern/image/image_pattern.h"
#include "core/components_ng/pattern/security_component/security_component_theme.h"
#include "core/components_ng/pattern/text/text_layout_property.h"
#include "core/components/common/layout/constants.h"
#include "core/components_v2/inspector/inspector_constants.h"
namespace OHOS::Ace::NG {
bool SecurityComponentPattern::OnDirtyLayoutWrapperSwap(const RefPtr<LayoutWrapper>& dirty,
const DirtySwapConfig& config)
{
return !(config.skipMeasure || dirty->SkipMeasureContent());
}
} // namespace OHOS::Ace::NG

View File

@ -0,0 +1,72 @@
/*
* Copyright (c) 2023 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_PATTERNS_SECURITY_COMPONENT_SECURITY_COMPONENT_PATTERN_H
#define FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_PATTERNS_SECURITY_COMPONENT_SECURITY_COMPONENT_PATTERN_H
#include "core/components_ng/base/view_stack_processor.h"
#include "core/components_ng/pattern/image/image_layout_property.h"
#include "core/components_ng/pattern/security_component/security_component_accessibility_property.h"
#include "core/components_ng/pattern/security_component/security_component_layout_property.h"
#include "core/components_ng/pattern/pattern.h"
namespace OHOS::Ace::NG {
static inline RefPtr<FrameNode> GetSecCompChildNode(RefPtr<FrameNode>& parent, const std::string& tag)
{
for (const auto& child : parent->GetChildren()) {
auto node = AceType::DynamicCast<FrameNode, UINode>(child);
CHECK_NULL_RETURN(node, nullptr);
if (node->GetTag() == tag) {
return node;
}
}
return nullptr;
}
static inline RefPtr<FrameNode> GetCurSecCompChildNode(const std::string& tag)
{
auto frameNode = ViewStackProcessor::GetInstance()->GetMainFrameNode();
CHECK_NULL_RETURN(frameNode, nullptr);
return GetSecCompChildNode(frameNode, tag);
}
class SecurityComponentPattern : public Pattern {
DECLARE_ACE_TYPE(SecurityComponentPattern, Pattern);
public:
SecurityComponentPattern() {};
~SecurityComponentPattern() override = default;
RefPtr<LayoutProperty> CreateLayoutProperty() override
{
return MakeRefPtr<SecurityComponentLayoutProperty>();
}
RefPtr<AccessibilityProperty> CreateAccessibilityProperty() override
{
return MakeRefPtr<SecurityComponentAccessibilityProperty>();
}
int32_t scId_ = -1;
protected:
bool OnDirtyLayoutWrapperSwap(const RefPtr<LayoutWrapper>& dirty, const DirtySwapConfig& config) override;
private:
RefPtr<ClickEvent> clickListener_;
ACE_DISALLOW_COPY_AND_MOVE(SecurityComponentPattern);
};
} // namespace OHOS::Ace::NG
#endif // FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_PATTERNS_SECURITY_COMPONENT_SECURITY_COMPONENT_PATTERN_H

View File

@ -0,0 +1,212 @@
/*
* Copyright (c) 2023 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_SECURITY_COMPONENT_THEME_H
#define FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_SECURITY_COMPONENT_THEME_H
#include "base/geometry/dimension.h"
#include "base/log/ace_scoring_log.h"
#include "base/memory/ace_type.h"
#include "base/memory/referenced.h"
#include "core/components/common/properties/color.h"
#include "core/components/theme/theme.h"
#include "core/components/theme/theme_attributes.h"
#include "core/components/theme/theme_constants.h"
#include "core/components/theme/theme_style.h"
namespace OHOS::Ace::NG {
class SecurityComponentTheme : public virtual Theme {
DECLARE_ACE_TYPE(SecurityComponentTheme, Theme);
public:
~SecurityComponentTheme() = default;
class Builder {
public:
Builder() = default;
~Builder() = default;
RefPtr<SecurityComponentTheme> Build(const RefPtr<ThemeConstants>& themeConstants)
{
RefPtr<SecurityComponentTheme> theme = AceType::Claim(new SecurityComponentTheme());
if (!themeConstants) {
LOGE("Build SecurityComponentTheme error, themeConstants is null!");
return theme;
}
ParsePattern(themeConstants->GetThemeStyle(), theme);
return theme;
}
};
const Dimension& GetIconSize() const
{
return iconSize_;
}
const Dimension& GetFontSize() const
{
return fontSize_;
}
const Dimension& GetBackgroundTopPadding() const
{
return backgroundTopPadding_;
}
const Dimension& GetBackgroundRightPadding() const
{
return backgroundRightPadding_;
}
const Dimension& GetBackgroundBottomPadding() const
{
return backgroundBottomPadding_;
}
const Dimension& GetBackgroundLeftPadding() const
{
return backgroundLeftPadding_;
}
const Dimension& GetTextIconPadding() const
{
return textIconPadding_;
}
const Dimension& GetPaddingWithoutBg() const
{
return paddingWithoutBg_;
}
const Dimension& GetBorderRadius() const
{
return borderRadius_;
}
const Dimension& GetBorderWidth() const
{
return borderWidth_;
}
const Color& GetIconColor() const
{
return iconColor_;
}
const Color& GetFontColor() const
{
return fontColor_;
}
const Color& GetBackgroundColor() const
{
return backgroundColor_;
}
const Color& GetBorderColor() const
{
return borderColor_;
}
const std::string& GetLocationDescriptions(int32_t index)
{
if (index < 0 || index > static_cast<int32_t>(locationDescriptions_.size())) {
LOGE("deciprtions index %{public}d is invalid", static_cast<int>(index));
return emptyString_;
}
return locationDescriptions_[index];
}
private:
SecurityComponentTheme() = default;
static void ParseLocationDescriptions(RefPtr<ThemeStyle> securityComponentPattern,
const RefPtr<SecurityComponentTheme>& theme)
{
theme->locationDescriptions_.emplace_back(
securityComponentPattern->GetAttr<std::string>("description_current_location", ""));
theme->locationDescriptions_.emplace_back(
securityComponentPattern->GetAttr<std::string>("description_add_location", ""));
theme->locationDescriptions_.emplace_back(
securityComponentPattern->GetAttr<std::string>("description_select_location", ""));
theme->locationDescriptions_.emplace_back(
securityComponentPattern->GetAttr<std::string>("description_share_location", ""));
theme->locationDescriptions_.emplace_back(
securityComponentPattern->GetAttr<std::string>("description_send_location", ""));
theme->locationDescriptions_.emplace_back(
securityComponentPattern->GetAttr<std::string>("description_locating", ""));
theme->locationDescriptions_.emplace_back(
securityComponentPattern->GetAttr<std::string>("description_location", ""));
theme->locationDescriptions_.emplace_back(
securityComponentPattern->GetAttr<std::string>("description_send_current_location", ""));
theme->locationDescriptions_.emplace_back(
securityComponentPattern->GetAttr<std::string>("description_relocation", ""));
theme->locationDescriptions_.emplace_back(
securityComponentPattern->GetAttr<std::string>("description_punch_in", ""));
theme->locationDescriptions_.emplace_back(
securityComponentPattern->GetAttr<std::string>("description_current_position", ""));
}
static void ParsePattern(const RefPtr<ThemeStyle>& themeStyle, const RefPtr<SecurityComponentTheme>& theme)
{
if (!themeStyle) {
return;
}
auto securityComponentPattern =
themeStyle->GetAttr<RefPtr<ThemeStyle>>(THEME_PATTERN_SECURITY_COMPONENT, nullptr);
if (!securityComponentPattern) {
LOGE("Pattern of security component is null, please check!");
return;
}
theme->iconSize_ = securityComponentPattern->GetAttr<Dimension>("icon_size", 0.0_vp);
theme->fontSize_ = securityComponentPattern->GetAttr<Dimension>("font_size", 0.0_vp);
theme->backgroundTopPadding_ =
securityComponentPattern->GetAttr<Dimension>("background_top_padding", 0.0_vp);
theme->backgroundRightPadding_ =
securityComponentPattern->GetAttr<Dimension>("background_right_padding", 0.0_vp);
theme->backgroundBottomPadding_ =
securityComponentPattern->GetAttr<Dimension>("background_bottom_padding", 0.0_vp);
theme->backgroundLeftPadding_ =
securityComponentPattern->GetAttr<Dimension>("background_left_padding", 0.0_vp);
theme->textIconPadding_ = securityComponentPattern->GetAttr<Dimension>("text_icon_padding", 0.0_vp);
theme->paddingWithoutBg_ = securityComponentPattern->GetAttr<Dimension>("padding_without_background", 0.0_vp);
theme->borderRadius_ = securityComponentPattern->GetAttr<Dimension>("border_radius", 0.0_vp);
theme->borderWidth_ = securityComponentPattern->GetAttr<Dimension>("border_width", 0.0_vp);
theme->iconColor_ = securityComponentPattern->GetAttr<Color>("icon_color", Color());
theme->fontColor_ = securityComponentPattern->GetAttr<Color>("font_color", Color());
theme->backgroundColor_ = securityComponentPattern->GetAttr<Color>("background_color", Color());
theme->borderColor_ = securityComponentPattern->GetAttr<Color>("border_color", Color());
ParseLocationDescriptions(securityComponentPattern, theme);
}
Dimension iconSize_;
Dimension fontSize_;
Dimension backgroundTopPadding_;
Dimension backgroundRightPadding_;
Dimension backgroundBottomPadding_;
Dimension backgroundLeftPadding_;
Dimension textIconPadding_;
Dimension borderRadius_;
Dimension borderWidth_;
Dimension paddingWithoutBg_;
Color iconColor_;
Color fontColor_;
Color backgroundColor_;
Color borderColor_;
std::vector<std::string> locationDescriptions_;
std::string emptyString_;
};
} // namespace OHOS::Ace::NG
#endif // FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_APP_BAR_THEME_H

View File

@ -339,6 +339,7 @@ const std::unordered_map<std::string, std::string> COMPONENT_TAG_TO_ETS_TAG_MAP
{ JS_VIEW_COMPONENT_TAG, JS_VIEW_ETS_TAG },
{ RELATIVE_CONTAINER_COMPONENT_TAG, RELATIVE_CONTAINER_ETS_TAG },
{ UI_EXTENSION_COMPONENT_TAG, UI_EXTENSION_COMPONENT_ETS_TAG },
{ SEC_LOCATION_BUTTON_COMPONENT_TAG, SEC_LOCATION_BUTTON_ETS_TAG },
};
thread_local int32_t InspectorComposedComponent::composedElementId_ = 1;

View File

@ -489,4 +489,8 @@ const char WINDOW_SCENE_ETS_TAG[] = "WindowScene";
const char UI_EXTENSION_COMPONENT_TAG[] = "UIExtensionComponent";
const char UI_EXTENSION_COMPONENT_ETS_TAG[] = "UIExtensionComponent";
// SecLocationButton
const char SEC_LOCATION_BUTTON_COMPONENT_TAG[] = "SecLocationButtonComponent";
const char SEC_LOCATION_BUTTON_ETS_TAG[] = "SecLocationButton";
} // namespace OHOS::Ace::V2

View File

@ -500,5 +500,9 @@ ACE_EXPORT extern const char WINDOW_SCENE_ETS_TAG[];
ACE_EXPORT extern const char UI_EXTENSION_COMPONENT_TAG[];
ACE_EXPORT extern const char UI_EXTENSION_COMPONENT_ETS_TAG[];
// LocationButton
ACE_EXPORT extern const char SEC_LOCATION_BUTTON_COMPONENT_TAG[];
ACE_EXPORT extern const char SEC_LOCATION_BUTTON_ETS_TAG[];
} // namespace OHOS::Ace::V2
#endif // FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_V2_INSPECTOR_INSPECTOR_CONSTANTS_H

View File

@ -609,7 +609,31 @@ public:
return pointerId_;
}
#endif // ENABLE_DRAG_FRAMEWORK
#ifdef SECURITY_COMPONENT_ENABLE
void SetDisplayX(double displayX)
{
displayX_ = displayX;
}
double GetDisplayX()
{
return displayX_;
}
void SetDisplayY(double displayY)
{
displayY_ = displayY;
}
double GetDisplayY()
{
return displayY_;
}
JsonValue& GetSecCompHandleEvent()
{
return secCompHandleEvent_;
}
#endif
private:
bool repeat_ = false;
bool pressed_ = false;
@ -625,6 +649,11 @@ private:
#ifdef ENABLE_DRAG_FRAMEWORK
int32_t pointerId_ = 0;
#endif // ENABLE_DRAG_FRAMEWORK
#ifdef SECURITY_COMPONENT_ENABLE
float displayX_ = 0.0;
float displayY_ = 0.0;
JsonValue secCompHandleEvent_;
#endif
Point globalPoint_;
// global position at which the touch point contacts the screen.
Offset globalLocation_;