From 5422b2965badcc41037cab313467c40d1621ccc7 Mon Sep 17 00:00:00 2001 From: openharmony_ci <120357966@qq.com> Date: Fri, 28 Apr 2023 08:25:02 +0000 Subject: [PATCH] =?UTF-8?q?=E5=9B=9E=E9=80=80=20'Pull=20Request=20!12368?= =?UTF-8?q?=20:=20select=20=E8=A7=A3=E8=80=A6'?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../bridge/declarative_frontend/BUILD.gn | 1 - .../declarative_frontend/jsview/js_select.cpp | 782 +++++++++++++----- .../declarative_frontend/jsview/js_select.h | 2 + .../jsview/models/select_model_impl.cpp | 434 ---------- .../jsview/models/select_model_impl.h | 63 -- .../core/components_ng/pattern/BUILD.gn | 2 +- .../components_ng/pattern/menu/menu_pattern.h | 2 +- .../components_ng/pattern/menu/menu_view.h | 2 +- .../pattern/navigation/navigation_view.cpp | 2 +- .../pattern/select/select_model_ng.h | 60 -- .../pattern/select/select_pattern.h | 2 +- .../{select_model_ng.cpp => select_view.cpp} | 164 +--- .../select/{select_model.h => select_view.h} | 82 +- .../test/pattern/select/BUILD.gn | 2 +- .../pattern/select/select_pattern_test_ng.cpp | 13 +- .../pattern/select/select_view_test_ng.cpp | 141 +--- 16 files changed, 676 insertions(+), 1078 deletions(-) delete mode 100644 frameworks/bridge/declarative_frontend/jsview/models/select_model_impl.cpp delete mode 100644 frameworks/bridge/declarative_frontend/jsview/models/select_model_impl.h delete mode 100644 frameworks/core/components_ng/pattern/select/select_model_ng.h rename frameworks/core/components_ng/pattern/select/{select_model_ng.cpp => select_view.cpp} (59%) rename frameworks/core/components_ng/pattern/select/{select_model.h => select_view.h} (36%) diff --git a/frameworks/bridge/declarative_frontend/BUILD.gn b/frameworks/bridge/declarative_frontend/BUILD.gn index ee0fe95637b..a7a4656f912 100644 --- a/frameworks/bridge/declarative_frontend/BUILD.gn +++ b/frameworks/bridge/declarative_frontend/BUILD.gn @@ -313,7 +313,6 @@ template("declarative_js_engine") { "jsview/models/row_model_impl.cpp", "jsview/models/scroll_model_impl.cpp", "jsview/models/search_model_impl.cpp", - "jsview/models/select_model_impl.cpp", "jsview/models/shape_abstract_model_impl.cpp", "jsview/models/shape_model_impl.cpp", "jsview/models/slider_model_impl.cpp", diff --git a/frameworks/bridge/declarative_frontend/jsview/js_select.cpp b/frameworks/bridge/declarative_frontend/jsview/js_select.cpp index 5d8e973e9b4..bba705d67da 100644 --- a/frameworks/bridge/declarative_frontend/jsview/js_select.cpp +++ b/frameworks/bridge/declarative_frontend/jsview/js_select.cpp @@ -24,50 +24,30 @@ #include "bridge/common/utils/utils.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 "bridge/declarative_frontend/jsview/js_view_common_def.h" -#include "bridge/declarative_frontend/jsview/models/select_model_impl.h" -#include "core/components_ng/pattern/select/select_model.h" -#include "core/components_ng/pattern/select/select_model_ng.h" +#include "core/components/option/option_component.h" +#include "core/components/select/select_component.h" +#include "core/components/select/select_theme.h" +#include "core/components_ng/pattern/select/select_view.h" #include "core/components_v2/inspector/inspector_constants.h" #include "core/pipeline/pipeline_base.h" -namespace OHOS::Ace { -std::unique_ptr SelectModel::instance_ = nullptr; -std::mutex SelectModel::mutex_; - -SelectModel* SelectModel::GetInstance() -{ - if (!instance_) { - std::lock_guard lock(mutex_); - if (!instance_) { -#ifdef NG_BUILD - instance_.reset(new NG::SelectModelNG()); -#else - if (Container::IsCurrentUseNewPipeline()) { - instance_.reset(new NG::SelectModelNG()); - } else { - instance_.reset(new Framework::SelectModelImpl()); - } - } -#endif - } - return instance_.get(); -} -} // namespace OHOS::Ace - namespace OHOS::Ace::Framework { void JSSelect::Create(const JSCallbackInfo& info) { if (info.Length() < 0) { return; } - if (info[0]->IsArray()) { - auto paramArray = JSRef::Cast(info[0]); - size_t size = paramArray->Length(); - std::vector params(size); - for (size_t i = 0; i < size; i++) { - std::string value; - std::string icon; + + if (Container::IsCurrentUseNewPipeline()) { + if (info[0]->IsArray()) { + auto paramArray = JSRef::Cast(info[0]); + size_t size = paramArray->Length(); + std::vector params(size); + for (size_t i = 0; i < size; i++) { + std::string value; + std::string icon; auto indexObject = JSRef::Cast(paramArray->GetValueAt(i)); auto selectValue = indexObject->GetProperty("value"); @@ -80,10 +60,61 @@ void JSSelect::Create(const JSCallbackInfo& info) LOGI("selectIcon is null"); } - params[i] = { value, icon }; + params[i] = { value, icon }; + } + NG::SelectView::Create(params); + } + return; + } + + auto selectTheme = GetTheme(); + auto selectComponent = AceType::MakeRefPtr(); + selectComponent->SetTheme(selectTheme); + + auto tipText = AceType::MakeRefPtr(""); + selectComponent->SetTipText(tipText); + + if (info[0]->IsArray()) { + auto paramArray = JSRef::Cast(info[0]); + size_t size = paramArray->Length(); + for (size_t i = 0; i < size; i++) { + std::string value; + std::string icon; + + auto indexObject = JSRef::Cast(paramArray->GetValueAt(i)); + auto selectValue = indexObject->GetProperty("value"); + auto selectIcon = indexObject->GetProperty("icon"); + if (!ParseJsString(selectValue, value)) { + LOGE("selectValue is null"); + return; + } + if (!ParseJsMedia(selectIcon, icon)) { + LOGE("selectValue is null"); + } + + auto optionTheme = GetTheme(); + if (!optionTheme) { + LOGE("JSSelect: Get option theme is null."); + continue; + } + + auto optionComponent = AceType::MakeRefPtr(optionTheme); + auto textComponent = AceType::MakeRefPtr(value); + if (!icon.empty()) { + optionComponent->SetIcon(AceType::MakeRefPtr(icon)); + } + optionComponent->SetTheme(optionTheme); + optionComponent->SetText(textComponent); + optionComponent->SetTextStyle(optionTheme->GetTitleStyle()); + optionComponent->SetSelectedTextStyle(optionTheme->GetTitleStyle()); + optionComponent->SetSelectedBackgroundColor(optionTheme->GetSelectedColor()); + optionComponent->SetValue(value); + selectComponent->AppendSelectOption(optionComponent); } - SelectModel::GetInstance()->Create(params); } + + ViewStackProcessor::GetInstance()->ClaimElementId(selectComponent); + ViewStackProcessor::GetInstance()->Push(selectComponent); } void JSSelect::JSBind(BindingTarget globalObj) @@ -130,15 +161,65 @@ void JSSelect::JSBind(BindingTarget globalObj) void JSSelect::Selected(int value) { - if (value <= 0) { + if (Container::IsCurrentUseNewPipeline()) { + if (value <= 0) { + value = 0; + } + NG::SelectView::SetSelected(value); + return; + } + + auto component = ViewStackProcessor::GetInstance()->GetMainComponent(); + auto selectComponent = AceType::DynamicCast(component); + if (!selectComponent) { + LOGE("search component error"); + return; + } + auto popup = selectComponent->GetPopup(); + if (!popup) { + LOGE("popup is null"); + return; + } + auto option = popup->GetSelectOptions(); + if (value < 0 || value >= static_cast(option.size())) { + LOGE("Input selected index error, use the default value"); value = 0; } - SelectModel::GetInstance()->SetSelected(value); + + auto tipText = selectComponent->GetTipText(); + auto optionComponent = selectComponent->GetSelectOption(value); + if (!optionComponent) { + LOGE("optionComponent is null"); + return; + } + optionComponent->SetSelected(true); + + auto optionText = optionComponent->GetText(); + if (!optionText) { + return; + } + if (!selectComponent->HasSetTipText()) { + tipText->SetData(optionText->GetData()); + } } void JSSelect::Value(const std::string& value) { - SelectModel::GetInstance()->SetValue(value); + if (Container::IsCurrentUseNewPipeline()) { + NG::SelectView::SetValue(value); + return; + } + auto component = ViewStackProcessor::GetInstance()->GetMainComponent(); + auto selectComponent = AceType::DynamicCast(component); + if (!selectComponent) { + LOGE("search component error"); + return; + } + auto tipText = selectComponent->GetTipText(); + if (!value.empty()) { + selectComponent->SetTipText(true); + } + tipText->SetData(value); } void JSSelect::Font(const JSCallbackInfo& info) @@ -148,13 +229,56 @@ void JSSelect::Font(const JSCallbackInfo& info) } auto param = JSRef::Cast(info[0]); + + if (Container::IsCurrentUseNewPipeline()) { + auto size = param->GetProperty("size"); + if (!size->IsNull()) { + Dimension fontSize; + if (ParseJsDimensionFp(size, fontSize)) { + NG::SelectView::SetFontSize(fontSize); + } + } + std::string weight; + auto fontWeight = param->GetProperty("weight"); + if (!fontWeight->IsNull()) { + if (fontWeight->IsNumber()) { + weight = std::to_string(fontWeight->ToNumber()); + } else { + ParseJsString(fontWeight, weight); + } + NG::SelectView::SetFontWeight(ConvertStrToFontWeight(weight)); + } + + auto family = param->GetProperty("family"); + if (!family->IsNull() && family->IsString()) { + auto familyVal = family->ToString(); + NG::SelectView::SetFontFamily(ConvertStrToFontFamilies(familyVal)); + } + + auto style = param->GetProperty("style"); + if (!style->IsNull() && style->IsNumber()) { + auto styleVal = static_cast(style->ToNumber()); + NG::SelectView::SetItalicFontStyle(styleVal); + } + return; + } + + auto component = ViewStackProcessor::GetInstance()->GetMainComponent(); + auto selectComponent = AceType::DynamicCast(component); + if (!selectComponent) { + LOGE("search component error"); + return; + } + auto size = param->GetProperty("size"); + TextStyle textStyle = selectComponent->GetSelectStyle(); if (!size->IsNull()) { Dimension fontSize; if (ParseJsDimensionFp(size, fontSize)) { - SelectModel::GetInstance()->SetFontSize(fontSize); + textStyle.SetFontSize(fontSize); } } + std::string weight; auto fontWeight = param->GetProperty("weight"); if (!fontWeight->IsNull()) { @@ -163,20 +287,21 @@ void JSSelect::Font(const JSCallbackInfo& info) } else { ParseJsString(fontWeight, weight); } - SelectModel::GetInstance()->SetFontWeight(ConvertStrToFontWeight(weight)); + textStyle.SetFontWeight(ConvertStrToFontWeight(weight)); } auto family = param->GetProperty("family"); if (!family->IsNull() && family->IsString()) { auto familyVal = family->ToString(); - SelectModel::GetInstance()->SetFontFamily(ConvertStrToFontFamilies(familyVal)); + textStyle.SetFontFamilies(ConvertStrToFontFamilies(familyVal)); } auto style = param->GetProperty("style"); if (!style->IsNull() && style->IsNumber()) { - auto styleVal = static_cast(style->ToNumber()); - SelectModel::GetInstance()->SetItalicFontStyle(styleVal); + FontStyle styleVal = static_cast(style->ToNumber()); + textStyle.SetFontStyle(styleVal); } + selectComponent->SetSelectStyle(std::move(textStyle)); } void JSSelect::FontColor(const JSCallbackInfo& info) @@ -199,7 +324,20 @@ void JSSelect::FontColor(const JSCallbackInfo& info) } } - SelectModel::GetInstance()->SetFontColor(textColor); + if (Container::IsCurrentUseNewPipeline()) { + NG::SelectView::SetFontColor(textColor); + return; + } + + auto component = ViewStackProcessor::GetInstance()->GetMainComponent(); + auto selectComponent = AceType::DynamicCast(component); + if (!selectComponent) { + LOGE("search component error"); + return; + } + auto textStyle = selectComponent->GetSelectStyle(); + textStyle.SetTextColor(textColor); + selectComponent->SetSelectStyle(std::move(textStyle)); } void JSSelect::SelectedOptionBgColor(const JSCallbackInfo& info) @@ -220,7 +358,29 @@ void JSSelect::SelectedOptionBgColor(const JSCallbackInfo& info) return; } } - SelectModel::GetInstance()->SetSelectedOptionBgColor(bgColor); + + if (Container::IsCurrentUseNewPipeline()) { + NG::SelectView::SetSelectedOptionBgColor(bgColor); + return; + } + + auto component = ViewStackProcessor::GetInstance()->GetMainComponent(); + auto selectComponent = AceType::DynamicCast(component); + if (!selectComponent) { + LOGE("search component error"); + return; + } + auto popup = selectComponent->GetPopup(); + if (!popup) { + LOGE("popup is null"); + return; + } + auto option = popup->GetSelectOptions(); + for (auto& optionItem : option) { + if (optionItem) { + optionItem->SetSelectedBackgroundColor(bgColor); + } + } } void JSSelect::SelectedOptionFont(const JSCallbackInfo& info) @@ -230,39 +390,90 @@ void JSSelect::SelectedOptionFont(const JSCallbackInfo& info) } auto param = JSRef::Cast(info[0]); + if (Container::IsCurrentUseNewPipeline()) { + auto size = param->GetProperty("size"); + if (!size->IsNull()) { + Dimension fontSize; + if (ParseJsDimensionFp(size, fontSize)) { + NG::SelectView::SetSelectedOptionFontSize(fontSize); + } + } + std::string weight; + auto fontWeight = param->GetProperty("weight"); + if (!fontWeight->IsNull()) { + if (fontWeight->IsNumber()) { + weight = std::to_string(fontWeight->ToNumber()); + } else { + ParseJsString(fontWeight, weight); + } + NG::SelectView::SetSelectedOptionFontWeight(ConvertStrToFontWeight(weight)); + } + + auto family = param->GetProperty("family"); + if (!family->IsNull() && family->IsString()) { + auto familyVal = family->ToString(); + NG::SelectView::SetSelectedOptionFontFamily(ConvertStrToFontFamilies(familyVal)); + } + + auto style = param->GetProperty("style"); + if (!style->IsNull() && style->IsNumber()) { + auto styleVal = static_cast(style->ToNumber()); + NG::SelectView::SetSelectedOptionItalicFontStyle(styleVal); + } + return; + } + + auto component = ViewStackProcessor::GetInstance()->GetMainComponent(); + auto selectComponent = AceType::DynamicCast(component); + if (!selectComponent) { + LOGE("search component error"); + return; + } + auto popup = selectComponent->GetPopup(); + if (!popup) { + LOGE("popup is null"); + return; + } + auto option = popup->GetSelectOptions(); if (info.Length() < 1) { LOGE("The argv is wrong, it is supposed to have at least 1 argument"); return; } + for (auto& optionItem : option) { + auto size = param->GetProperty("size"); + TextStyle textStyle = optionItem->GetSelectedTextStyle(); - auto size = param->GetProperty("size"); - if (!size->IsNull()) { - Dimension fontSize; - if (ParseJsDimensionFp(size, fontSize)) { - SelectModel::GetInstance()->SetSelectedOptionFontSize(fontSize); + if (!size->IsNull()) { + Dimension fontSize; + if (ParseJsDimensionFp(size, fontSize)) { + textStyle.SetFontSize(fontSize); + } } - } - std::string weight; - auto fontWeight = param->GetProperty("weight"); - if (!fontWeight->IsNull()) { - if (fontWeight->IsNumber()) { - weight = std::to_string(fontWeight->ToNumber()); - } else { - ParseJsString(fontWeight, weight); + + std::string weight; + auto fontWeight = param->GetProperty("weight"); + if (!fontWeight->IsNull()) { + if (fontWeight->IsNumber()) { + weight = std::to_string(fontWeight->ToNumber()); + } else { + ParseJsString(fontWeight, weight); + } + textStyle.SetFontWeight(ConvertStrToFontWeight(weight)); } - SelectModel::GetInstance()->SetSelectedOptionFontWeight(ConvertStrToFontWeight(weight)); - } - auto family = param->GetProperty("family"); - if (!family->IsNull() && family->IsString()) { - auto familyVal = family->ToString(); - SelectModel::GetInstance()->SetSelectedOptionFontFamily(ConvertStrToFontFamilies(familyVal)); - } + auto family = param->GetProperty("family"); + if (!family->IsNull() && family->IsString()) { + auto familyVal = family->ToString(); + textStyle.SetFontFamilies(ConvertStrToFontFamilies(familyVal)); + } - auto style = param->GetProperty("style"); - if (!style->IsNull() && style->IsNumber()) { - auto styleVal = static_cast(style->ToNumber()); - SelectModel::GetInstance()->SetSelectedOptionItalicFontStyle(styleVal); + auto style = param->GetProperty("style"); + if (!style->IsNull() && style->IsNumber()) { + FontStyle styleVal = static_cast(style->ToNumber()); + textStyle.SetFontStyle(styleVal); + } + + optionItem->SetSelectedTextStyle(std::move(textStyle)); } } @@ -284,7 +495,31 @@ void JSSelect::SelectedOptionFontColor(const JSCallbackInfo& info) return; } } - SelectModel::GetInstance()->SetSelectedOptionFontColor(textColor); + + if (Container::IsCurrentUseNewPipeline()) { + NG::SelectView::SetSelectedOptionFontColor(textColor); + return; + } + + auto component = ViewStackProcessor::GetInstance()->GetMainComponent(); + auto selectComponent = AceType::DynamicCast(component); + if (!selectComponent) { + LOGE("search component error"); + return; + } + auto popup = selectComponent->GetPopup(); + if (!popup) { + LOGE("popup is null"); + return; + } + auto option = popup->GetSelectOptions(); + for (auto& optionItem : option) { + if (optionItem) { + TextStyle textStyle = optionItem->GetSelectedTextStyle(); + textStyle.SetTextColor(textColor); + optionItem->SetSelectedTextStyle(textStyle); + } + } } void JSSelect::OptionBgColor(const JSCallbackInfo& info) @@ -298,7 +533,28 @@ void JSSelect::OptionBgColor(const JSCallbackInfo& info) return; } - SelectModel::GetInstance()->SetOptionBgColor(bgColor); + if (Container::IsCurrentUseNewPipeline()) { + NG::SelectView::SetOptionBgColor(bgColor); + return; + } + + auto component = ViewStackProcessor::GetInstance()->GetMainComponent(); + auto selectComponent = AceType::DynamicCast(component); + if (!selectComponent) { + LOGE("search component error"); + return; + } + auto popup = selectComponent->GetPopup(); + if (!popup) { + LOGE("popup is null"); + return; + } + auto option = popup->GetSelectOptions(); + for (auto& optionItem : option) { + if (optionItem) { + optionItem->SetBackgroundColor(bgColor); + } + } } void JSSelect::OptionFont(const JSCallbackInfo& info) @@ -308,34 +564,89 @@ void JSSelect::OptionFont(const JSCallbackInfo& info) } auto param = JSRef::Cast(info[0]); - auto size = param->GetProperty("size"); - if (!size->IsNull()) { - Dimension fontSize; - if (ParseJsDimensionFp(size, fontSize)) { - SelectModel::GetInstance()->SetOptionFontSize(fontSize); + if (Container::IsCurrentUseNewPipeline()) { + auto size = param->GetProperty("size"); + if (!size->IsNull()) { + Dimension fontSize; + if (ParseJsDimensionFp(size, fontSize)) { + NG::SelectView::SetOptionFontSize(fontSize); + } } - } - std::string weight; - auto fontWeight = param->GetProperty("weight"); - if (!fontWeight->IsNull()) { - if (fontWeight->IsNumber()) { - weight = std::to_string(fontWeight->ToNumber()); - } else { - ParseJsString(fontWeight, weight); + std::string weight; + auto fontWeight = param->GetProperty("weight"); + if (!fontWeight->IsNull()) { + if (fontWeight->IsNumber()) { + weight = std::to_string(fontWeight->ToNumber()); + } else { + ParseJsString(fontWeight, weight); + } + NG::SelectView::SetOptionFontWeight(ConvertStrToFontWeight(weight)); } - SelectModel::GetInstance()->SetOptionFontWeight(ConvertStrToFontWeight(weight)); + + auto family = param->GetProperty("family"); + if (!family->IsNull() && family->IsString()) { + auto familyVal = family->ToString(); + NG::SelectView::SetOptionFontFamily(ConvertStrToFontFamilies(familyVal)); + } + + auto style = param->GetProperty("style"); + if (!style->IsNull() && style->IsNumber()) { + auto styleVal = static_cast(style->ToNumber()); + NG::SelectView::SetOptionItalicFontStyle(styleVal); + } + return; } - auto family = param->GetProperty("family"); - if (!family->IsNull() && family->IsString()) { - auto familyVal = family->ToString(); - SelectModel::GetInstance()->SetOptionFontFamily(ConvertStrToFontFamilies(familyVal)); + auto component = ViewStackProcessor::GetInstance()->GetMainComponent(); + auto selectComponent = AceType::DynamicCast(component); + if (!selectComponent) { + LOGE("search component error"); + return; } + auto popup = selectComponent->GetPopup(); + if (!popup) { + LOGE("popup is null"); + return; + } + auto option = popup->GetSelectOptions(); + if (info.Length() < 1) { + LOGE("The argv is wrong, it is supposed to have at least 1 argument"); + return; + } + for (auto& optionItem : option) { + TextStyle textStyle = optionItem->GetTextStyle(); + auto size = param->GetProperty("size"); + if (!size->IsNull()) { + Dimension fontSize; + if (ParseJsDimensionFp(size, fontSize)) { + textStyle.SetFontSize(fontSize); + } + } - auto style = param->GetProperty("style"); - if (!style->IsNull() && style->IsNumber()) { - auto styleVal = static_cast(style->ToNumber()); - SelectModel::GetInstance()->SetOptionItalicFontStyle(styleVal); + std::string weight; + auto fontWeight = param->GetProperty("weight"); + if (!fontWeight->IsNull()) { + if (fontWeight->IsNumber()) { + weight = std::to_string(fontWeight->ToNumber()); + } else { + ParseJsString(fontWeight, weight); + } + textStyle.SetFontWeight(ConvertStrToFontWeight(weight)); + } + + auto family = param->GetProperty("family"); + if (!family->IsNull() && family->IsString()) { + auto familyVal = family->ToString(); + textStyle.SetFontFamilies(ConvertStrToFontFamilies(familyVal)); + } + + auto style = param->GetProperty("style"); + if (!style->IsNull() && style->IsNumber()) { + FontStyle styleVal = static_cast(style->ToNumber()); + textStyle.SetFontStyle(styleVal); + } + + optionItem->SetTextStyle(std::move(textStyle)); } } @@ -350,124 +661,125 @@ void JSSelect::OptionFontColor(const JSCallbackInfo& info) return; } - SelectModel::GetInstance()->SetOptionFontColor(textColor); + if (Container::IsCurrentUseNewPipeline()) { + NG::SelectView::SetOptionFontColor(textColor); + return; + } + + auto component = ViewStackProcessor::GetInstance()->GetMainComponent(); + auto selectComponent = AceType::DynamicCast(component); + if (!selectComponent) { + LOGE("search component error"); + return; + } + auto popup = selectComponent->GetPopup(); + if (!popup) { + LOGE("popup is null"); + return; + } + auto option = popup->GetSelectOptions(); + for (auto& optionItem : option) { + if (optionItem) { + TextStyle textStyle = optionItem->GetTextStyle(); + textStyle.SetTextColor(textColor); + optionItem->SetTextStyle(textStyle); + } + } } void JSSelect::OnSelected(const JSCallbackInfo& info) { - auto jsFunc = AceType::MakeRefPtr(JSRef(), JSRef::Cast(info[0])); - auto onSelect = [execCtx = info.GetExecutionContext(), func = std::move(jsFunc)]( - int32_t index, const std::string& value) { - JAVASCRIPT_EXECUTION_SCOPE_WITH_CHECK(execCtx); - ACE_SCORING_EVENT("Select.onSelect"); - JSRef params[2]; - params[0] = JSRef::Make(ToJSValue(index)); - params[1] = JSRef::Make(ToJSValue(value)); - func->ExecuteJS(2, params); - }; - SelectModel::GetInstance()->SetOnSelect(std::move(onSelect)); + if (Container::IsCurrentUseNewPipeline()) { + auto jsFunc = AceType::MakeRefPtr(JSRef(), JSRef::Cast(info[0])); + auto onSelect = [execCtx = info.GetExecutionContext(), func = std::move(jsFunc)]( + int32_t index, const std::string& value) { + JAVASCRIPT_EXECUTION_SCOPE_WITH_CHECK(execCtx); + ACE_SCORING_EVENT("Select.onSelect"); + JSRef params[2]; + params[0] = JSRef::Make(ToJSValue(index)); + params[1] = JSRef::Make(ToJSValue(value)); + func->ExecuteJS(2, params); + }; + NG::SelectView::SetOnSelect(onSelect); + } else if (!JSViewBindEvent(&SelectComponent::SetOnSelected, info)) { + LOGE("Failed to bind event"); + } info.ReturnSelf(); } void JSSelect::JsWidth(const JSCallbackInfo& info) { + if (Container::IsCurrentUseNewPipeline()) { + JSViewAbstract::JsWidth(info); + return; + } if (info.Length() < 1) { LOGE("The arg is wrong, it is supposed to have atleast 1 arguments"); return; } + + Width(info[0]); +} + +void JSSelect::Width(const JSRef& jsValue) +{ Dimension value; - if (!ParseJsDimensionVp(info[0], value)) { + if (!ParseJsDimensionVp(jsValue, value)) { return; } - - SelectModel::GetInstance()->SetWidth(value); + auto stack = ViewStackProcessor::GetInstance(); + auto selectComponent = AceType::DynamicCast(stack->GetMainComponent()); + if (selectComponent) { + selectComponent->SetWidth(value); + } } void JSSelect::JsHeight(const JSCallbackInfo& info) { - if (info.Length() < 1) { - LOGE("The arg is wrong, it is supposed to have atleast 1 arguments"); + if (Container::IsCurrentUseNewPipeline()) { + JSViewAbstract::JsHeight(info); return; } - - Dimension value; - if (!ParseJsDimensionVp(info[0], value)) { + if (info.Length() < 1) { + LOGE("The arg is wrong, it is supposed to have atleast 1 arguments"); return; } - SelectModel::GetInstance()->SetHeight(value); + Height(info[0]); } -bool CheckJSCallbackInfo( - const std::string& callerName, const JSCallbackInfo& info, std::vector& infoTypes) +void JSSelect::Height(const JSRef& jsValue) { - if (info.Length() < 1) { - LOGE("%{public}s: The arg is supposed to have at least one argument", callerName.c_str()); - return false; - } - bool typeVerified = false; - std::string unrecognizedType; - for (const auto& infoType : infoTypes) { - switch (infoType) { - case JSCallbackInfoType::STRING: - if (info[0]->IsString()) { - typeVerified = true; - } else { - unrecognizedType += "string|"; - } - break; - case JSCallbackInfoType::NUMBER: - if (info[0]->IsNumber()) { - typeVerified = true; - } else { - unrecognizedType += "number|"; - } - break; - case JSCallbackInfoType::OBJECT: - if (info[0]->IsObject()) { - typeVerified = true; - } else { - unrecognizedType += "object|"; - } - break; - case JSCallbackInfoType::FUNCTION: - if (info[0]->IsFunction()) { - typeVerified = true; - } else { - unrecognizedType += "Function|"; - } - break; - default: - break; - } + Dimension value; + if (!ParseJsDimensionVp(jsValue, value)) { + return; } - if (!typeVerified) { - LOGE("%{public}s: info[0] is not a [%{public}s]", callerName.c_str(), - unrecognizedType.substr(0, unrecognizedType.size() - 1).c_str()); + auto stack = ViewStackProcessor::GetInstance(); + auto selectComponent = AceType::DynamicCast(stack->GetMainComponent()); + if (selectComponent) { + selectComponent->SetHeight(value); } - return typeVerified || infoTypes.size() == 0; } void JSSelect::JsSize(const JSCallbackInfo& info) { - std::vector checkList { JSCallbackInfoType::OBJECT }; - if (!CheckJSCallbackInfo("JsSize", info, checkList)) { + if (Container::IsCurrentUseNewPipeline()) { + JSViewAbstract::JsSize(info); return; } - - JSRef sizeObj = JSRef::Cast(info[0]); - - Dimension width; - if (!ParseJsDimensionVp(sizeObj->GetProperty("width"), width)) { + if (info.Length() < 1) { + LOGE("The arg is wrong, it is supposed to have atleast 1 arguments"); return; } - Dimension height; - if (!ParseJsDimensionVp(sizeObj->GetProperty("height"), height)) { + if (!info[0]->IsObject()) { + LOGE("arg is not Object or String."); return; } - SelectModel::GetInstance()->SetSize(width, height); + JSRef sizeObj = JSRef::Cast(info[0]); + Width(sizeObj->GetProperty("width")); + Height(sizeObj->GetProperty("height")); } void JSSelect::JsPadding(const JSCallbackInfo& info) @@ -477,41 +789,67 @@ void JSSelect::JsPadding(const JSCallbackInfo& info) return; } - if (info[0]->IsObject()) { - std::optional left; - std::optional right; - std::optional top; - std::optional bottom; - JSRef paddingObj = JSRef::Cast(info[0]); + if (Container::IsCurrentUseNewPipeline()) { + JSViewAbstract::JsPadding(info); + return; + } - Dimension leftDimen; - if (ParseJsDimensionVp(paddingObj->GetProperty("left"), leftDimen)) { - left = leftDimen; + if (info[0]->IsObject()) { + auto stack = ViewStackProcessor::GetInstance(); + auto selectComponent = AceType::DynamicCast(stack->GetMainComponent()); + if (!selectComponent) { + LOGE("search component error"); + return; } - Dimension rightDimen; - if (ParseJsDimensionVp(paddingObj->GetProperty("right"), rightDimen)) { - right = rightDimen; + auto argsPtrItem = JsonUtil::ParseJsonString(info[0]->ToString()); + if (!argsPtrItem || argsPtrItem->IsNull()) { + LOGE("Js Parse object failed. argsPtr is null. %s", info[0]->ToString().c_str()); + return; } - Dimension topDimen; - if (ParseJsDimensionVp(paddingObj->GetProperty("top"), topDimen)) { - top = topDimen; + if (argsPtrItem->Contains("top")) { + Dimension topDimen = Dimension(0.0, DimensionUnit::VP); + if (ParseJsonDimensionVp(argsPtrItem->GetValue("top"), topDimen)) { + selectComponent->SetTopPadding(topDimen); + } } - Dimension bottomDimen; - if (ParseJsDimensionVp(paddingObj->GetProperty("bottom"), bottomDimen)) { - bottom = bottomDimen; + if (argsPtrItem->Contains("left")) { + Dimension leftDimen = Dimension(0.0, DimensionUnit::VP); + if (ParseJsonDimensionVp(argsPtrItem->GetValue("left"), leftDimen)) { + selectComponent->SetLeftPadding(leftDimen); + } + } + if (argsPtrItem->Contains("right")) { + Dimension rightDimen = Dimension(0.0, DimensionUnit::VP); + if (ParseJsonDimensionVp(argsPtrItem->GetValue("right"), rightDimen)) { + selectComponent->SetRightPadding(rightDimen); + } + } + if (argsPtrItem->Contains("bottom")) { + Dimension bottomDimen = Dimension(0.0, DimensionUnit::VP); + if (ParseJsonDimensionVp(argsPtrItem->GetValue("bottom"), bottomDimen)) { + selectComponent->SetBottomPadding(bottomDimen); + } } - SelectModel::GetInstance()->SetPaddings(top, bottom, left, right); } - - Dimension value; - if (!ParseJsDimensionVp(info[0], value)) { - value.Reset(); + Dimension length; + if (ParseJsDimensionVp(info[0], length)) { + auto stack = ViewStackProcessor::GetInstance(); + auto selectComponent = AceType::DynamicCast(stack->GetMainComponent()); + if (selectComponent) { + selectComponent->SetLeftPadding(length); + selectComponent->SetTopPadding(length); + selectComponent->SetRightPadding(length); + selectComponent->SetBottomPadding(length); + } } - SelectModel::GetInstance()->SetPadding(value); } void JSSelect::SetPaddingLeft(const JSCallbackInfo& info) { + if (Container::IsCurrentUseNewPipeline()) { + JSViewAbstract::SetPaddingLeft(info); + return; + } if (info.Length() < 1) { LOGE("The arg is wrong, it is supposed to have at least 1 argument"); return; @@ -520,11 +858,19 @@ void JSSelect::SetPaddingLeft(const JSCallbackInfo& info) if (!ParseJsDimensionVp(info[0], value)) { return; } - SelectModel::GetInstance()->SetPaddingLeft(value); + auto stack = ViewStackProcessor::GetInstance(); + auto selectComponent = AceType::DynamicCast(stack->GetMainComponent()); + if (selectComponent) { + selectComponent->SetLeftPadding(value); + } } void JSSelect::SetPaddingTop(const JSCallbackInfo& info) { + if (Container::IsCurrentUseNewPipeline()) { + JSViewAbstract::SetPaddingTop(info); + return; + } if (info.Length() < 1) { LOGE("The arg is wrong, it is supposed to have at least 1 argument"); return; @@ -533,11 +879,19 @@ void JSSelect::SetPaddingTop(const JSCallbackInfo& info) if (!ParseJsDimensionVp(info[0], value)) { return; } - SelectModel::GetInstance()->SetPaddingTop(value); + auto stack = ViewStackProcessor::GetInstance(); + auto selectComponent = AceType::DynamicCast(stack->GetMainComponent()); + if (selectComponent) { + selectComponent->SetTopPadding(value); + } } void JSSelect::SetPaddingRight(const JSCallbackInfo& info) { + if (Container::IsCurrentUseNewPipeline()) { + JSViewAbstract::SetPaddingRight(info); + return; + } if (info.Length() < 1) { LOGE("The arg is wrong, it is supposed to have at least 1 argument"); return; @@ -546,11 +900,19 @@ void JSSelect::SetPaddingRight(const JSCallbackInfo& info) if (!ParseJsDimensionVp(info[0], value)) { return; } - SelectModel::GetInstance()->SetPaddingRight(value); + auto stack = ViewStackProcessor::GetInstance(); + auto selectComponent = AceType::DynamicCast(stack->GetMainComponent()); + if (selectComponent) { + selectComponent->SetRightPadding(value); + } } void JSSelect::SetPaddingBottom(const JSCallbackInfo& info) { + if (Container::IsCurrentUseNewPipeline()) { + JSViewAbstract::SetPaddingBottom(info); + return; + } if (info.Length() < 1) { LOGE("The arg is wrong, it is supposed to have at least 1 argument"); return; @@ -559,7 +921,11 @@ void JSSelect::SetPaddingBottom(const JSCallbackInfo& info) if (!ParseJsDimensionVp(info[0], value)) { return; } - SelectModel::GetInstance()->SetPaddingBottom(value); + auto stack = ViewStackProcessor::GetInstance(); + auto selectComponent = AceType::DynamicCast(stack->GetMainComponent()); + if (selectComponent) { + selectComponent->SetBottomPadding(value); + } } void JSSelect::SetSpace(const JSCallbackInfo& info) @@ -581,7 +947,9 @@ void JSSelect::SetSpace(const JSCallbackInfo& info) value = selectTheme->GetContentSpinnerPadding(); } - SelectModel::GetInstance()->SetSpace(value); + if (Container::IsCurrentUseNewPipeline()) { + NG::SelectView::SetSpace(value); + } } void JSSelect::SetArrowPosition(const JSCallbackInfo& info) @@ -595,12 +963,14 @@ void JSSelect::SetArrowPosition(const JSCallbackInfo& info) direction = 0; } - if (static_cast(direction) != ArrowPosition::START && - static_cast(direction) != ArrowPosition::END) { + if (static_cast(direction) != NG::ArrowPosition::START && + static_cast(direction) != NG::ArrowPosition::END) { direction = 0; } - SelectModel::GetInstance()->SetArrowPosition(static_cast(direction)); + if (Container::IsCurrentUseNewPipeline()) { + NG::SelectView::SetArrowPosition(static_cast(direction)); + } } void JSSelect::SetMenuAlign(const JSCallbackInfo& info) @@ -613,8 +983,8 @@ void JSSelect::SetMenuAlign(const JSCallbackInfo& info) return; } - MenuAlign menuAlignObj; - menuAlignObj.alignType = static_cast(info[0]->ToNumber()); + NG::MenuAlign menuAlignObj; + menuAlignObj.alignType = static_cast(info[0]->ToNumber()); if (info.Length() > 1) { if (!info[1]->IsObject()) { @@ -630,6 +1000,8 @@ void JSSelect::SetMenuAlign(const JSCallbackInfo& info) menuAlignObj.offset = DimensionOffset(dx, dy); } - SelectModel::GetInstance()->SetMenuAlign(menuAlignObj); + if (Container::IsCurrentUseNewPipeline()) { + NG::SelectView::SetMenuAlign(menuAlignObj); + } } } // namespace OHOS::Ace::Framework diff --git a/frameworks/bridge/declarative_frontend/jsview/js_select.h b/frameworks/bridge/declarative_frontend/jsview/js_select.h index 9d316be68ad..aa3b950bfbe 100644 --- a/frameworks/bridge/declarative_frontend/jsview/js_select.h +++ b/frameworks/bridge/declarative_frontend/jsview/js_select.h @@ -37,6 +37,8 @@ public: static void OnSelected(const JSCallbackInfo& info); static void JsWidth(const JSCallbackInfo& info); static void JsHeight(const JSCallbackInfo& info); + static void Width(const JSRef& jsValue); + static void Height(const JSRef& jsValue); static void JsSize(const JSCallbackInfo& info); static void JsPadding(const JSCallbackInfo& info); static void SetPaddingTop(const JSCallbackInfo& info); diff --git a/frameworks/bridge/declarative_frontend/jsview/models/select_model_impl.cpp b/frameworks/bridge/declarative_frontend/jsview/models/select_model_impl.cpp deleted file mode 100644 index 0cf8ce91dba..00000000000 --- a/frameworks/bridge/declarative_frontend/jsview/models/select_model_impl.cpp +++ /dev/null @@ -1,434 +0,0 @@ -/* - * 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 "bridge/declarative_frontend/jsview/models/select_model_impl.h" - -#include "bridge/declarative_frontend/jsview/js_view_abstract.h" -#include "core/components/select/select_component.h" -#include "core/components/select/select_theme.h" -#include "frameworks/bridge/declarative_frontend/view_stack_processor.h" - -namespace OHOS::Ace::Framework { -void SelectModelImpl::Create(const std::vector& params) -{ - auto selectTheme = JSViewAbstract::GetTheme(); - auto selectComponent = AceType::MakeRefPtr(); - CHECK_NULL_VOID(selectComponent); - selectComponent->SetTheme(selectTheme); - - auto tipText = AceType::MakeRefPtr(""); - selectComponent->SetTipText(tipText); - - for (size_t i = 0; i < params.size(); i++) { - auto optionTheme = JSViewAbstract::GetTheme(); - if (!optionTheme) { - LOGE("JSSelect: Get option theme is null."); - continue; - } - auto optionComponent = AceType::MakeRefPtr(optionTheme); - auto textComponent = AceType::MakeRefPtr(params[i].first); - if (!params[i].second.empty()) { - optionComponent->SetIcon(AceType::MakeRefPtr(params[i].second)); - } - optionComponent->SetTheme(optionTheme); - optionComponent->SetText(textComponent); - optionComponent->SetTextStyle(optionTheme->GetTitleStyle()); - optionComponent->SetSelectedTextStyle(optionTheme->GetTitleStyle()); - optionComponent->SetSelectedBackgroundColor(optionTheme->GetSelectedColor()); - optionComponent->SetValue(params[i].first); - selectComponent->AppendSelectOption(optionComponent); - } - ViewStackProcessor::GetInstance()->ClaimElementId(selectComponent); - ViewStackProcessor::GetInstance()->Push(selectComponent); -} - -void SelectModelImpl::SetSelected(int32_t idx) -{ - auto component = ViewStackProcessor::GetInstance()->GetMainComponent(); - auto selectComponent = AceType::DynamicCast(component); - CHECK_NULL_VOID(selectComponent); - auto popup = selectComponent->GetPopup(); - CHECK_NULL_VOID(popup); - auto option = popup->GetSelectOptions(); - if (idx >= static_cast(option.size())) { - LOGE("Input selected index error, use the default value"); - idx = 0; - } - - auto tipText = selectComponent->GetTipText(); - auto optionComponent = selectComponent->GetSelectOption(idx); - CHECK_NULL_VOID(optionComponent); - optionComponent->SetSelected(true); - - auto optionText = optionComponent->GetText(); - CHECK_NULL_VOID(optionText); - if (!selectComponent->HasSetTipText()) { - tipText->SetData(optionText->GetData()); - } -} - -void SelectModelImpl::SetValue(const std::string& value) -{ - auto component = ViewStackProcessor::GetInstance()->GetMainComponent(); - auto selectComponent = AceType::DynamicCast(component); - CHECK_NULL_VOID(selectComponent); - auto tipText = selectComponent->GetTipText(); - if (!value.empty()) { - selectComponent->SetTipText(true); - } - tipText->SetData(value); -} - -void SelectModelImpl::SetFontSize(const Dimension& value) -{ - auto component = ViewStackProcessor::GetInstance()->GetMainComponent(); - auto selectComponent = AceType::DynamicCast(component); - CHECK_NULL_VOID(selectComponent); - - TextStyle textStyle = selectComponent->GetSelectStyle(); - textStyle.SetFontSize(value); - selectComponent->SetSelectStyle(std::move(textStyle)); -} - -void SelectModelImpl::SetFontWeight(const FontWeight& value) -{ - auto component = ViewStackProcessor::GetInstance()->GetMainComponent(); - auto selectComponent = AceType::DynamicCast(component); - CHECK_NULL_VOID(selectComponent); - - TextStyle textStyle = selectComponent->GetSelectStyle(); - textStyle.SetFontWeight(value); - selectComponent->SetSelectStyle(std::move(textStyle)); -} - -void SelectModelImpl::SetFontFamily(const std::vector& value) -{ - auto component = ViewStackProcessor::GetInstance()->GetMainComponent(); - auto selectComponent = AceType::DynamicCast(component); - CHECK_NULL_VOID(selectComponent); - - TextStyle textStyle = selectComponent->GetSelectStyle(); - textStyle.SetFontFamilies(value); - selectComponent->SetSelectStyle(std::move(textStyle)); -} - -void SelectModelImpl::SetItalicFontStyle(const Ace::FontStyle& value) -{ - auto component = ViewStackProcessor::GetInstance()->GetMainComponent(); - auto selectComponent = AceType::DynamicCast(component); - CHECK_NULL_VOID(selectComponent); - - TextStyle textStyle = selectComponent->GetSelectStyle(); - textStyle.SetFontStyle(value); - selectComponent->SetSelectStyle(std::move(textStyle)); -} - -void SelectModelImpl::SetFontColor(const Color& color) -{ - auto component = ViewStackProcessor::GetInstance()->GetMainComponent(); - auto selectComponent = AceType::DynamicCast(component); - CHECK_NULL_VOID(selectComponent); - - auto textStyle = selectComponent->GetSelectStyle(); - textStyle.SetTextColor(color); - selectComponent->SetSelectStyle(std::move(textStyle)); -} - -void SelectModelImpl::SetSelectedOptionBgColor(const Color& color) -{ - auto component = ViewStackProcessor::GetInstance()->GetMainComponent(); - auto selectComponent = AceType::DynamicCast(component); - CHECK_NULL_VOID(selectComponent); - auto popup = selectComponent->GetPopup(); - CHECK_NULL_VOID(popup); - auto option = popup->GetSelectOptions(); - for (auto& optionItem : option) { - if (optionItem) { - optionItem->SetSelectedBackgroundColor(color); - } - } -} - -void SelectModelImpl::SetSelectedOptionFontSize(const Dimension& value) -{ - auto component = ViewStackProcessor::GetInstance()->GetMainComponent(); - auto selectComponent = AceType::DynamicCast(component); - CHECK_NULL_VOID(selectComponent); - auto popup = selectComponent->GetPopup(); - CHECK_NULL_VOID(popup); - auto option = popup->GetSelectOptions(); - for (auto& optionItem : option) { - TextStyle textStyle = optionItem->GetSelectedTextStyle(); - textStyle.SetFontSize(value); - optionItem->SetSelectedTextStyle(std::move(textStyle)); - } -} - -void SelectModelImpl::SetSelectedOptionFontWeight(const FontWeight& value) -{ - auto component = ViewStackProcessor::GetInstance()->GetMainComponent(); - auto selectComponent = AceType::DynamicCast(component); - CHECK_NULL_VOID(selectComponent); - auto popup = selectComponent->GetPopup(); - CHECK_NULL_VOID(popup); - auto option = popup->GetSelectOptions(); - for (auto& optionItem : option) { - TextStyle textStyle = optionItem->GetSelectedTextStyle(); - textStyle.SetFontWeight(value); - optionItem->SetSelectedTextStyle(std::move(textStyle)); - } -} - -void SelectModelImpl::SetSelectedOptionFontFamily(const std::vector& value) -{ - auto component = ViewStackProcessor::GetInstance()->GetMainComponent(); - auto selectComponent = AceType::DynamicCast(component); - CHECK_NULL_VOID(selectComponent); - auto popup = selectComponent->GetPopup(); - CHECK_NULL_VOID(popup); - auto option = popup->GetSelectOptions(); - for (auto& optionItem : option) { - TextStyle textStyle = optionItem->GetSelectedTextStyle(); - textStyle.SetFontFamilies(value); - optionItem->SetSelectedTextStyle(std::move(textStyle)); - } -} - -void SelectModelImpl::SetSelectedOptionItalicFontStyle(const Ace::FontStyle& value) -{ - auto component = ViewStackProcessor::GetInstance()->GetMainComponent(); - auto selectComponent = AceType::DynamicCast(component); - CHECK_NULL_VOID(selectComponent); - auto popup = selectComponent->GetPopup(); - CHECK_NULL_VOID(popup); - auto option = popup->GetSelectOptions(); - for (auto& optionItem : option) { - TextStyle textStyle = optionItem->GetSelectedTextStyle(); - textStyle.SetFontStyle(value); - optionItem->SetSelectedTextStyle(std::move(textStyle)); - } -} - -void SelectModelImpl::SetSelectedOptionFontColor(const Color& color) -{ - auto component = ViewStackProcessor::GetInstance()->GetMainComponent(); - auto selectComponent = AceType::DynamicCast(component); - CHECK_NULL_VOID(selectComponent); - auto popup = selectComponent->GetPopup(); - CHECK_NULL_VOID(popup); - auto option = popup->GetSelectOptions(); - for (auto& optionItem : option) { - if (optionItem) { - TextStyle textStyle = optionItem->GetSelectedTextStyle(); - textStyle.SetTextColor(color); - optionItem->SetSelectedTextStyle(textStyle); - } - } -} - -void SelectModelImpl::SetOptionBgColor(const Color& color) -{ - auto component = ViewStackProcessor::GetInstance()->GetMainComponent(); - auto selectComponent = AceType::DynamicCast(component); - CHECK_NULL_VOID(selectComponent); - auto popup = selectComponent->GetPopup(); - CHECK_NULL_VOID(popup); - auto option = popup->GetSelectOptions(); - for (auto& optionItem : option) { - if (optionItem) { - optionItem->SetBackgroundColor(color); - } - } -} - -void SelectModelImpl::SetOptionFontSize(const Dimension& value) -{ - auto component = ViewStackProcessor::GetInstance()->GetMainComponent(); - auto selectComponent = AceType::DynamicCast(component); - CHECK_NULL_VOID(selectComponent); - auto popup = selectComponent->GetPopup(); - CHECK_NULL_VOID(popup); - auto option = popup->GetSelectOptions(); - for (auto& optionItem : option) { - TextStyle textStyle = optionItem->GetTextStyle(); - textStyle.SetFontSize(value); - optionItem->SetTextStyle(std::move(textStyle)); - } -} - -void SelectModelImpl::SetOptionFontWeight(const FontWeight& value) -{ - auto component = ViewStackProcessor::GetInstance()->GetMainComponent(); - auto selectComponent = AceType::DynamicCast(component); - CHECK_NULL_VOID(selectComponent); - auto popup = selectComponent->GetPopup(); - CHECK_NULL_VOID(popup); - auto option = popup->GetSelectOptions(); - for (auto& optionItem : option) { - TextStyle textStyle = optionItem->GetTextStyle(); - textStyle.SetFontWeight(value); - optionItem->SetTextStyle(std::move(textStyle)); - } -} - -void SelectModelImpl::SetOptionFontFamily(const std::vector& value) -{ - auto component = ViewStackProcessor::GetInstance()->GetMainComponent(); - auto selectComponent = AceType::DynamicCast(component); - CHECK_NULL_VOID(selectComponent); - auto popup = selectComponent->GetPopup(); - CHECK_NULL_VOID(popup); - auto option = popup->GetSelectOptions(); - for (auto& optionItem : option) { - TextStyle textStyle = optionItem->GetTextStyle(); - textStyle.SetFontFamilies(value); - optionItem->SetTextStyle(std::move(textStyle)); - } -} - -void SelectModelImpl::SetOptionItalicFontStyle(const Ace::FontStyle& value) -{ - auto component = ViewStackProcessor::GetInstance()->GetMainComponent(); - auto selectComponent = AceType::DynamicCast(component); - CHECK_NULL_VOID(selectComponent); - auto popup = selectComponent->GetPopup(); - CHECK_NULL_VOID(popup); - auto option = popup->GetSelectOptions(); - for (auto& optionItem : option) { - TextStyle textStyle = optionItem->GetTextStyle(); - textStyle.SetFontStyle(value); - optionItem->SetTextStyle(std::move(textStyle)); - } -} - -void SelectModelImpl::SetOptionFontColor(const Color& color) -{ - auto component = ViewStackProcessor::GetInstance()->GetMainComponent(); - auto selectComponent = AceType::DynamicCast(component); - CHECK_NULL_VOID(selectComponent); - auto popup = selectComponent->GetPopup(); - CHECK_NULL_VOID(popup); - auto option = popup->GetSelectOptions(); - for (auto& optionItem : option) { - if (optionItem) { - TextStyle textStyle = optionItem->GetTextStyle(); - textStyle.SetTextColor(color); - optionItem->SetTextStyle(textStyle); - } - } -} - -void SelectModelImpl::SetOnSelect(NG::SelectEvent&& onSelect) -{ - auto component = ViewStackProcessor::GetInstance()->GetMainComponent(); - auto selectComponent = AceType::DynamicCast(component); - CHECK_NULL_VOID(selectComponent); - selectComponent->SetOnSelected(std::move(onSelect)); -} - -void SelectModelImpl::SetWidth(Dimension& value) -{ - auto stack = ViewStackProcessor::GetInstance(); - auto selectComponent = AceType::DynamicCast(stack->GetMainComponent()); - CHECK_NULL_VOID(selectComponent); - selectComponent->SetWidth(value); -} - -void SelectModelImpl::SetHeight(Dimension& value) -{ - auto stack = ViewStackProcessor::GetInstance(); - auto selectComponent = AceType::DynamicCast(stack->GetMainComponent()); - CHECK_NULL_VOID(selectComponent); - selectComponent->SetHeight(value); -} - -void SelectModelImpl::SetSize(Dimension& width, Dimension& height) -{ - auto stack = ViewStackProcessor::GetInstance(); - auto selectComponent = AceType::DynamicCast(stack->GetMainComponent()); - CHECK_NULL_VOID(selectComponent); - selectComponent->SetWidth(width); - selectComponent->SetHeight(height); -} - -void SelectModelImpl::SetPaddings(const std::optional& top, const std::optional& bottom, - const std::optional& left, const std::optional& right) -{ - auto stack = ViewStackProcessor::GetInstance(); - auto selectComponent = AceType::DynamicCast(stack->GetMainComponent()); - CHECK_NULL_VOID(selectComponent); - Dimension topDimen; - topDimen.SetValue(top.value().Value()); - selectComponent->SetTopPadding(topDimen); - Dimension leftDimen; - leftDimen.SetValue(left.value().Value()); - selectComponent->SetLeftPadding(leftDimen); - Dimension rightDimen; - rightDimen.SetValue(right.value().Value()); - selectComponent->SetRightPadding(rightDimen); - Dimension bottomDimen; - bottomDimen.SetValue(bottom.value().Value()); - selectComponent->SetBottomPadding(bottomDimen); -} - -void SelectModelImpl::SetPadding(const Dimension& value) -{ - auto stack = ViewStackProcessor::GetInstance(); - auto selectComponent = AceType::DynamicCast(stack->GetMainComponent()); - CHECK_NULL_VOID(selectComponent); - selectComponent->SetLeftPadding(value); - selectComponent->SetTopPadding(value); - selectComponent->SetRightPadding(value); - selectComponent->SetBottomPadding(value); -} - -void SelectModelImpl::SetPaddingLeft(const Dimension& value) -{ - auto stack = ViewStackProcessor::GetInstance(); - auto selectComponent = AceType::DynamicCast(stack->GetMainComponent()); - CHECK_NULL_VOID(selectComponent); - selectComponent->SetLeftPadding(value); -} - -void SelectModelImpl::SetPaddingTop(const Dimension& value) -{ - auto stack = ViewStackProcessor::GetInstance(); - auto selectComponent = AceType::DynamicCast(stack->GetMainComponent()); - CHECK_NULL_VOID(selectComponent); - selectComponent->SetTopPadding(value); -} - -void SelectModelImpl::SetPaddingRight(const Dimension& value) -{ - auto stack = ViewStackProcessor::GetInstance(); - auto selectComponent = AceType::DynamicCast(stack->GetMainComponent()); - CHECK_NULL_VOID(selectComponent); - selectComponent->SetRightPadding(value); -} - -void SelectModelImpl::SetPaddingBottom(const Dimension& value) -{ - auto stack = ViewStackProcessor::GetInstance(); - auto selectComponent = AceType::DynamicCast(stack->GetMainComponent()); - CHECK_NULL_VOID(selectComponent); - selectComponent->SetBottomPadding(value); -} - -void SelectModelImpl::SetSpace(const Dimension& value) {} - -void SelectModelImpl::SetArrowPosition(const ArrowPosition value) {} - -void SelectModelImpl::SetMenuAlign(const MenuAlign& menuAlign) {} -} // namespace OHOS::Ace::Framework \ No newline at end of file diff --git a/frameworks/bridge/declarative_frontend/jsview/models/select_model_impl.h b/frameworks/bridge/declarative_frontend/jsview/models/select_model_impl.h deleted file mode 100644 index 90e89b18803..00000000000 --- a/frameworks/bridge/declarative_frontend/jsview/models/select_model_impl.h +++ /dev/null @@ -1,63 +0,0 @@ -/* - * 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_MODELS_SELECT_MODEL_IMPL_H -#define FRAMEWORKS_BRIDGE_DECLARATIVE_FRONTEND_JS_VIEW_MODELS_SELECT_MODEL_IMPL_H - -#include -#include - -#include "frameworks/core/components_ng/pattern/select/select_model.h" - -namespace OHOS::Ace::Framework { -class SelectModelImpl : public SelectModel { -public: - void Create(const std::vector& params) override; - void SetSelected(int32_t idx) override; - void SetValue(const std::string& value) override; - void SetFontSize(const Dimension& value) override; - void SetFontWeight(const FontWeight& value) override; - void SetFontFamily(const std::vector& value) override; - void SetItalicFontStyle(const Ace::FontStyle& value) override; - void SetFontColor(const Color& color) override; - void SetSelectedOptionBgColor(const Color& color) override; - void SetSelectedOptionFontSize(const Dimension& value) override; - void SetSelectedOptionFontWeight(const FontWeight& value) override; - void SetSelectedOptionFontFamily(const std::vector& value) override; - void SetSelectedOptionItalicFontStyle(const Ace::FontStyle& value) override; - void SetSelectedOptionFontColor(const Color& color) override; - void SetOptionBgColor(const Color& color) override; - void SetOptionFontSize(const Dimension& value) override; - void SetOptionFontWeight(const FontWeight& value) override; - void SetOptionFontFamily(const std::vector& value) override; - void SetOptionItalicFontStyle(const Ace::FontStyle& value) override; - void SetOptionFontColor(const Color& color) override; - void SetOnSelect(NG::SelectEvent&& onSelect) override; - void SetWidth(Dimension& value) override; - void SetHeight(Dimension& value) override; - void SetSize(Dimension& width, Dimension& height) override; - void SetPaddings(const std::optional& top, const std::optional& bottom, - const std::optional& left, const std::optional& right) override; - void SetPadding(const Dimension& value) override; - void SetPaddingLeft(const Dimension& value) override; - void SetPaddingTop(const Dimension& value) override; - void SetPaddingRight(const Dimension& value) override; - void SetPaddingBottom(const Dimension& value) override; - void SetSpace(const Dimension& value) override; - void SetArrowPosition(const ArrowPosition value) override; - void SetMenuAlign(const MenuAlign& menuAlign) override; -}; -} // namespace OHOS::Ace::Framework -#endif // FRAMEWORKS_BRIDGE_DECLARATIVE_FRONTEND_JS_VIEW_MODELS_SELECT_MODEL_IMPL_H diff --git a/frameworks/core/components_ng/pattern/BUILD.gn b/frameworks/core/components_ng/pattern/BUILD.gn index b91daf0a429..60a6d43d929 100644 --- a/frameworks/core/components_ng/pattern/BUILD.gn +++ b/frameworks/core/components_ng/pattern/BUILD.gn @@ -294,8 +294,8 @@ build_component_ng("pattern_ng") { "search/search_pattern.cpp", "select/select_accessibility_property.cpp", "select/select_layout_algorithm.cpp", - "select/select_model_ng.cpp", "select/select_pattern.cpp", + "select/select_view.cpp", "select_overlay/select_overlay_layout_algorithm.cpp", "select_overlay/select_overlay_modifier.cpp", "select_overlay/select_overlay_node.cpp", diff --git a/frameworks/core/components_ng/pattern/menu/menu_pattern.h b/frameworks/core/components_ng/pattern/menu/menu_pattern.h index c8c063cf8e1..fe28a82405d 100644 --- a/frameworks/core/components_ng/pattern/menu/menu_pattern.h +++ b/frameworks/core/components_ng/pattern/menu/menu_pattern.h @@ -30,7 +30,7 @@ #include "core/components_ng/pattern/menu/navigation_menu_layout_algorithm.h" #include "core/components_ng/pattern/option/option_pattern.h" #include "core/components_ng/pattern/pattern.h" -#include "core/components_ng/pattern/select/select_model.h" +#include "core/components_ng/pattern/select/select_view.h" #include "core/components_v2/inspector/inspector_constants.h" #include "core/pipeline_ng/ui_task_scheduler.h" diff --git a/frameworks/core/components_ng/pattern/menu/menu_view.h b/frameworks/core/components_ng/pattern/menu/menu_view.h index 85eb9a649c9..f370285ce4f 100644 --- a/frameworks/core/components_ng/pattern/menu/menu_view.h +++ b/frameworks/core/components_ng/pattern/menu/menu_view.h @@ -22,7 +22,7 @@ #include "core/components_ng/base/view_abstract.h" #include "core/components_ng/pattern/menu/menu_pattern.h" #include "core/components_ng/pattern/navigation/navigation_declaration.h" -#include "core/components_ng/pattern/select/select_model.h" +#include "core/components_ng/pattern/select/select_view.h" #include "core/components_ng/pattern/text/text_styles.h" namespace OHOS::Ace::NG { diff --git a/frameworks/core/components_ng/pattern/navigation/navigation_view.cpp b/frameworks/core/components_ng/pattern/navigation/navigation_view.cpp index 291d0854285..a58f32b6224 100644 --- a/frameworks/core/components_ng/pattern/navigation/navigation_view.cpp +++ b/frameworks/core/components_ng/pattern/navigation/navigation_view.cpp @@ -51,7 +51,7 @@ #include "core/components_ng/pattern/navrouter/navdestination_layout_property.h" #include "core/components_ng/pattern/navrouter/navrouter_group_node.h" #include "core/components_ng/pattern/option/option_view.h" -#include "core/components_ng/pattern/select/select_model.h" +#include "core/components_ng/pattern/select/select_view.h" #include "core/components_ng/pattern/text/text_layout_property.h" #include "core/components_ng/pattern/text/text_pattern.h" #include "core/components_v2/inspector/inspector_constants.h" diff --git a/frameworks/core/components_ng/pattern/select/select_model_ng.h b/frameworks/core/components_ng/pattern/select/select_model_ng.h deleted file mode 100644 index 248b44ea566..00000000000 --- a/frameworks/core/components_ng/pattern/select/select_model_ng.h +++ /dev/null @@ -1,60 +0,0 @@ -/* - * 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_SELECT_SELECT_MODEL_NG_H -#define FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_PATTERN_SELECT_SELECT_MODEL_NG_H - -#include "core/components_ng/pattern/select/select_model.h" - -namespace OHOS::Ace::NG { -class ACE_EXPORT SelectModelNG : public OHOS::Ace::SelectModel { -public: - void Create(const std::vector& params) override; - void SetSelected(int32_t idx) override; - void SetValue(const std::string& value) override; - void SetFontSize(const Dimension& value) override; - void SetFontWeight(const FontWeight& value) override; - void SetFontFamily(const std::vector& value) override; - void SetItalicFontStyle(const Ace::FontStyle& value) override; - void SetFontColor(const Color& color) override; - void SetSelectedOptionBgColor(const Color& color) override; - void SetSelectedOptionFontSize(const Dimension& value) override; - void SetSelectedOptionFontWeight(const FontWeight& value) override; - void SetSelectedOptionFontFamily(const std::vector& value) override; - void SetSelectedOptionItalicFontStyle(const Ace::FontStyle& value) override; - void SetSelectedOptionFontColor(const Color& color) override; - void SetOptionBgColor(const Color& color) override; - void SetOptionFontSize(const Dimension& value) override; - void SetOptionFontWeight(const FontWeight& value) override; - void SetOptionFontFamily(const std::vector& value) override; - void SetOptionItalicFontStyle(const Ace::FontStyle& value) override; - void SetOptionFontColor(const Color& color) override; - void SetOnSelect(NG::SelectEvent&& onSelect) override; - void SetWidth(Dimension& value) override; - void SetHeight(Dimension& value) override; - void SetSize(Dimension& width, Dimension& height) override; - void SetPaddings(const std::optional& top, const std::optional& bottom, - const std::optional& left, const std::optional& right) override; - void SetPadding(const Dimension& value) override; - void SetPaddingLeft(const Dimension& value) override; - void SetPaddingTop(const Dimension& value) override; - void SetPaddingRight(const Dimension& value) override; - void SetPaddingBottom(const Dimension& value) override; - void SetSpace(const Dimension& value) override; - void SetArrowPosition(const ArrowPosition value) override; - void SetMenuAlign(const MenuAlign& menuAlign) override; -}; -} // namespace OHOS::Ace::NG -#endif // FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_PATTERN_SELECT_SELECT_MODEL_NG_H diff --git a/frameworks/core/components_ng/pattern/select/select_pattern.h b/frameworks/core/components_ng/pattern/select/select_pattern.h index 8566655aa10..785935b8613 100644 --- a/frameworks/core/components_ng/pattern/select/select_pattern.h +++ b/frameworks/core/components_ng/pattern/select/select_pattern.h @@ -32,7 +32,7 @@ #include "core/components_ng/pattern/select/select_accessibility_property.h" #include "core/components_ng/pattern/select/select_event_hub.h" #include "core/components_ng/pattern/select/select_layout_algorithm.h" -#include "core/components_ng/pattern/select/select_model.h" +#include "core/components_ng/pattern/select/select_view.h" #include "core/components_ng/pattern/text/text_layout_property.h" namespace OHOS::Ace::NG { diff --git a/frameworks/core/components_ng/pattern/select/select_model_ng.cpp b/frameworks/core/components_ng/pattern/select/select_view.cpp similarity index 59% rename from frameworks/core/components_ng/pattern/select/select_model_ng.cpp rename to frameworks/core/components_ng/pattern/select/select_view.cpp index 0cc3c604e08..6257ed3cbd3 100644 --- a/frameworks/core/components_ng/pattern/select/select_model_ng.cpp +++ b/frameworks/core/components_ng/pattern/select/select_view.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2023 Huawei Device Co., Ltd. + * Copyright (c) 2022-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 @@ -13,10 +13,9 @@ * limitations under the License. */ -#include "core/components_ng/pattern/select/select_model_ng.h" +#include "core/components_ng/pattern/select/select_view.h" #include "base/utils/utils.h" -#include "core/components_ng/base/view_abstract_model.h" #include "core/components_ng/base/view_stack_processor.h" #include "core/components_ng/pattern/menu/menu_pattern.h" #include "core/components_ng/pattern/menu/menu_view.h" @@ -26,7 +25,8 @@ #include "core/pipeline_ng/pipeline_context.h" namespace OHOS::Ace::NG { -void SelectModelNG::Create(const std::vector& params) + +void SelectView::Create(const std::vector& params) { LOGI("creating select component"); auto* stack = ViewStackProcessor::GetInstance(); @@ -71,250 +71,164 @@ void SelectModelNG::Create(const std::vector& params) select->PushDestroyCallback(destructor); } -void SelectModelNG::SetSelected(int32_t idx) +void SelectView::SetSelected(int32_t idx) { auto pattern = ViewStackProcessor::GetInstance()->GetMainFrameNodePattern(); CHECK_NULL_VOID(pattern); pattern->SetSelected(idx); } -void SelectModelNG::SetValue(const std::string& value) +void SelectView::SetValue(const std::string& value) { auto pattern = ViewStackProcessor::GetInstance()->GetMainFrameNodePattern(); CHECK_NULL_VOID(pattern); pattern->SetValue(value); } -void SelectModelNG::SetFontSize(const Dimension& value) +void SelectView::SetFontSize(const Dimension& value) { auto pattern = ViewStackProcessor::GetInstance()->GetMainFrameNodePattern(); CHECK_NULL_VOID(pattern); pattern->SetFontSize(value); } -void SelectModelNG::SetFontWeight(const FontWeight& value) +void SelectView::SetFontColor(const Color& color) { auto pattern = ViewStackProcessor::GetInstance()->GetMainFrameNodePattern(); CHECK_NULL_VOID(pattern); - pattern->SetFontWeight(value); + pattern->SetFontColor(color); } -void SelectModelNG::SetFontFamily(const std::vector& value) +void SelectView::SetItalicFontStyle(const Ace::FontStyle& value) { auto pattern = ViewStackProcessor::GetInstance()->GetMainFrameNodePattern(); CHECK_NULL_VOID(pattern); - pattern->SetFontFamily(value); + pattern->SetItalicFontStyle(value); } -void SelectModelNG::SetItalicFontStyle(const Ace::FontStyle& value) +void SelectView::SetFontWeight(const FontWeight& value) { auto pattern = ViewStackProcessor::GetInstance()->GetMainFrameNodePattern(); CHECK_NULL_VOID(pattern); - pattern->SetItalicFontStyle(value); + pattern->SetFontWeight(value); } -void SelectModelNG::SetFontColor(const Color& color) +void SelectView::SetFontFamily(const std::vector& value) { auto pattern = ViewStackProcessor::GetInstance()->GetMainFrameNodePattern(); CHECK_NULL_VOID(pattern); - pattern->SetFontColor(color); + pattern->SetFontFamily(value); } -void SelectModelNG::SetSelectedOptionBgColor(const Color& color) +void SelectView::SetSelectedOptionBgColor(const Color& color) { auto pattern = ViewStackProcessor::GetInstance()->GetMainFrameNodePattern(); CHECK_NULL_VOID(pattern); pattern->SetSelectedOptionBgColor(color); } -void SelectModelNG::SetSelectedOptionFontSize(const Dimension& value) +void SelectView::SetSelectedOptionFontSize(const Dimension& value) { auto pattern = ViewStackProcessor::GetInstance()->GetMainFrameNodePattern(); CHECK_NULL_VOID(pattern); pattern->SetSelectedOptionFontSize(value); } -void SelectModelNG::SetSelectedOptionFontWeight(const FontWeight& value) +void SelectView::SetSelectedOptionFontColor(const Color& color) { auto pattern = ViewStackProcessor::GetInstance()->GetMainFrameNodePattern(); CHECK_NULL_VOID(pattern); - pattern->SetSelectedOptionFontWeight(value); + pattern->SetSelectedOptionFontColor(color); } -void SelectModelNG::SetSelectedOptionFontFamily(const std::vector& value) +void SelectView::SetSelectedOptionItalicFontStyle(const Ace::FontStyle& value) { auto pattern = ViewStackProcessor::GetInstance()->GetMainFrameNodePattern(); CHECK_NULL_VOID(pattern); - pattern->SetSelectedOptionFontFamily(value); + pattern->SetSelectedOptionItalicFontStyle(value); } -void SelectModelNG::SetSelectedOptionItalicFontStyle(const Ace::FontStyle& value) +void SelectView::SetSelectedOptionFontWeight(const FontWeight& value) { auto pattern = ViewStackProcessor::GetInstance()->GetMainFrameNodePattern(); CHECK_NULL_VOID(pattern); - pattern->SetSelectedOptionItalicFontStyle(value); + pattern->SetSelectedOptionFontWeight(value); } -void SelectModelNG::SetSelectedOptionFontColor(const Color& color) +void SelectView::SetSelectedOptionFontFamily(const std::vector& value) { auto pattern = ViewStackProcessor::GetInstance()->GetMainFrameNodePattern(); CHECK_NULL_VOID(pattern); - pattern->SetSelectedOptionFontColor(color); + pattern->SetSelectedOptionFontFamily(value); } -void SelectModelNG::SetOptionBgColor(const Color& color) +void SelectView::SetOptionBgColor(const Color& color) { auto pattern = ViewStackProcessor::GetInstance()->GetMainFrameNodePattern(); CHECK_NULL_VOID(pattern); pattern->SetOptionBgColor(color); } -void SelectModelNG::SetOptionFontSize(const Dimension& value) +void SelectView::SetOptionFontSize(const Dimension& value) { auto pattern = ViewStackProcessor::GetInstance()->GetMainFrameNodePattern(); CHECK_NULL_VOID(pattern); pattern->SetOptionFontSize(value); } -void SelectModelNG::SetOptionFontWeight(const FontWeight& value) +void SelectView::SetOptionFontColor(const Color& color) { auto pattern = ViewStackProcessor::GetInstance()->GetMainFrameNodePattern(); CHECK_NULL_VOID(pattern); - pattern->SetOptionFontWeight(value); + pattern->SetOptionFontColor(color); } -void SelectModelNG::SetOptionFontFamily(const std::vector& value) +void SelectView::SetOptionItalicFontStyle(const Ace::FontStyle& value) { auto pattern = ViewStackProcessor::GetInstance()->GetMainFrameNodePattern(); CHECK_NULL_VOID(pattern); - pattern->SetOptionFontFamily(value); + pattern->SetOptionItalicFontStyle(value); } -void SelectModelNG::SetOptionItalicFontStyle(const Ace::FontStyle& value) +void SelectView::SetOptionFontWeight(const FontWeight& value) { auto pattern = ViewStackProcessor::GetInstance()->GetMainFrameNodePattern(); CHECK_NULL_VOID(pattern); - pattern->SetOptionItalicFontStyle(value); + pattern->SetOptionFontWeight(value); } -void SelectModelNG::SetOptionFontColor(const Color& color) +void SelectView::SetOptionFontFamily(const std::vector& value) { auto pattern = ViewStackProcessor::GetInstance()->GetMainFrameNodePattern(); CHECK_NULL_VOID(pattern); - pattern->SetOptionFontColor(color); + pattern->SetOptionFontFamily(value); } -void SelectModelNG::SetOnSelect(NG::SelectEvent&& onSelect) +void SelectView::SetOnSelect(SelectEvent&& onSelect) { auto hub = ViewStackProcessor::GetInstance()->GetMainFrameNodeEventHub(); CHECK_NULL_VOID(hub); hub->SetSelectEvent(std::move(onSelect)); } -void SelectModelNG::SetWidth(Dimension& value) -{ - if (LessNotEqual(value.Value(), 0.0)) { - value.SetValue(0.0); - } - ViewAbstract::SetWidth(NG::CalcLength(value)); -} - -void SelectModelNG::SetHeight(Dimension& value) -{ - if (LessNotEqual(value.Value(), 0.0)) { - value.SetValue(0.0); - } - ViewAbstract::SetHeight(NG::CalcLength(value)); -} - -void SelectModelNG::SetSize(Dimension& width, Dimension& height) -{ - if (LessNotEqual(width.Value(), 0.0)) { - width.SetValue(0.0); - } - - if (LessNotEqual(height.Value(), 0.0)) { - height.SetValue(0.0); - } - ViewAbstract::SetWidth(NG::CalcLength(width)); - ViewAbstract::SetHeight(NG::CalcLength(height)); -} - -void SelectModelNG::SetPaddings(const std::optional& top, const std::optional& bottom, - const std::optional& left, const std::optional& right) -{ - NG::PaddingProperty paddings; - paddings.top = NG::CalcLength(top.value().IsNonNegative() ? top.value() : Dimension()); - paddings.bottom = NG::CalcLength(bottom.value().IsNonNegative() ? bottom.value() : Dimension()); - paddings.left = NG::CalcLength(left.value().IsNonNegative() ? left.value() : Dimension()); - paddings.right = NG::CalcLength(right.value().IsNonNegative() ? right.value() : Dimension()); - ViewAbstract::SetPadding(paddings); -} - -void SelectModelNG::SetPadding(const Dimension& value) -{ - ViewAbstract::SetPadding(NG::CalcLength(value.IsNonNegative() ? value : Dimension())); -} - -void SelectModelNG::SetPaddingLeft(const Dimension& leftValue) -{ - NG::PaddingProperty paddings; - paddings.top = std::nullopt; - paddings.bottom = std::nullopt; - paddings.left = NG::CalcLength(leftValue.IsNonNegative() ? leftValue : Dimension()); - paddings.right = std::nullopt; - ViewAbstract::SetPadding(paddings); -} - -void SelectModelNG::SetPaddingTop(const Dimension& topValue) -{ - NG::PaddingProperty paddings; - paddings.top = NG::CalcLength(topValue.IsNonNegative() ? topValue : Dimension()); - paddings.bottom = std::nullopt; - paddings.left = std::nullopt; - paddings.right = std::nullopt; - ViewAbstract::SetPadding(paddings); -} - -void SelectModelNG::SetPaddingRight(const Dimension& rightValue) -{ - NG::PaddingProperty paddings; - paddings.top = std::nullopt; - paddings.bottom = std::nullopt; - paddings.left = std::nullopt; - paddings.right = NG::CalcLength(rightValue.IsNonNegative() ? rightValue : Dimension()); - ViewAbstract::SetPadding(paddings); -} - -void SelectModelNG::SetPaddingBottom(const Dimension& buttomValue) -{ - NG::PaddingProperty paddings; - paddings.top = std::nullopt; - paddings.bottom = NG::CalcLength(buttomValue.IsNonNegative() ? buttomValue : Dimension()); - paddings.left = std::nullopt; - paddings.right = std::nullopt; - ViewAbstract::SetPadding(paddings); -} - -void SelectModelNG::SetSpace(const Dimension& value) +void SelectView::SetSpace(const Dimension& value) { auto pattern = ViewStackProcessor::GetInstance()->GetMainFrameNodePattern(); CHECK_NULL_VOID(pattern); pattern->SetSpace(value); } -void SelectModelNG::SetArrowPosition(const ArrowPosition value) +void SelectView::SetArrowPosition(const ArrowPosition value) { auto pattern = ViewStackProcessor::GetInstance()->GetMainFrameNodePattern(); CHECK_NULL_VOID(pattern); pattern->SetArrowPosition(value); } -void SelectModelNG::SetMenuAlign(const MenuAlign& menuAlign) +void SelectView::SetMenuAlign(const MenuAlign& menuAlign) { auto pattern = ViewStackProcessor::GetInstance()->GetMainFrameNodePattern(); CHECK_NULL_VOID(pattern); pattern->SetMenuAlign(menuAlign); } } // namespace OHOS::Ace::NG - diff --git a/frameworks/core/components_ng/pattern/select/select_model.h b/frameworks/core/components_ng/pattern/select/select_view.h similarity index 36% rename from frameworks/core/components_ng/pattern/select/select_model.h rename to frameworks/core/components_ng/pattern/select/select_view.h index 6a028265ab8..31da114f562 100644 --- a/frameworks/core/components_ng/pattern/select/select_model.h +++ b/frameworks/core/components_ng/pattern/select/select_view.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2023 Huawei Device Co., Ltd. + * Copyright (c) 2022-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 @@ -13,8 +13,8 @@ * limitations under the License. */ -#ifndef FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_PATTERN_SELECT_SELECT_MODEL_H -#define FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_PATTERN_SELECT_SELECT_MODEL_H +#ifndef FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_PATTERN_SELECT_SELECT_VIEW_H +#define FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_PATTERN_SELECT_SELECT_VIEW_H #include #include @@ -24,7 +24,8 @@ #include "core/components_ng/pattern/select/select_event_hub.h" #include "core/components_ng/pattern/text/text_styles.h" -namespace OHOS::Ace { +namespace OHOS::Ace::NG { + enum class ArrowPosition { END = 0, START, @@ -41,52 +42,41 @@ struct MenuAlign { DimensionOffset offset = DimensionOffset(Dimension(0, DimensionUnit::VP), Dimension(0, DimensionUnit::VP)); }; +// pair using SelectParam = std::pair; -class SelectModel { +class ACE_EXPORT SelectView { public: - static SelectModel* GetInstance(); - virtual ~SelectModel() = default; + static void Create(const std::vector& params); + static void SetSelected(int32_t idx); + static void SetValue(const std::string& value); + + static void SetFontSize(const Dimension& value); + static void SetItalicFontStyle(const Ace::FontStyle& value); + static void SetFontWeight(const FontWeight& value); + static void SetFontFamily(const std::vector& value); + static void SetFontColor(const Color& color); - virtual void Create(const std::vector& params); - virtual void SetSelected(int32_t idx); - virtual void SetValue(const std::string& value); - virtual void SetFontSize(const Dimension& value); - virtual void SetFontWeight(const FontWeight& value); - virtual void SetFontFamily(const std::vector& value); - virtual void SetItalicFontStyle(const Ace::FontStyle& value); - virtual void SetFontColor(const Color& color); - virtual void SetSelectedOptionBgColor(const Color& color); - virtual void SetSelectedOptionFontSize(const Dimension& value); - virtual void SetSelectedOptionFontWeight(const FontWeight& value); - virtual void SetSelectedOptionFontFamily(const std::vector& value); - virtual void SetSelectedOptionItalicFontStyle(const Ace::FontStyle& value); - virtual void SetSelectedOptionFontColor(const Color& color); - virtual void SetOptionBgColor(const Color& color); - virtual void SetOptionFontSize(const Dimension& value); - virtual void SetOptionFontWeight(const FontWeight& value); - virtual void SetOptionFontFamily(const std::vector& value); - virtual void SetOptionItalicFontStyle(const Ace::FontStyle& value); - virtual void SetOptionFontColor(const Color& color); - virtual void SetOnSelect(NG::SelectEvent&& onSelect); - virtual void SetWidth(Dimension& value); - virtual void SetHeight(Dimension& value); - virtual void SetSize(Dimension& width, Dimension& height); - virtual void SetPaddings(const std::optional& top, const std::optional& bottom, - const std::optional& left, const std::optional& right); - virtual void SetPadding(const Dimension& value); - virtual void SetPaddingLeft(const Dimension& value); - virtual void SetPaddingTop(const Dimension& value); - virtual void SetPaddingRight(const Dimension& value); - virtual void SetPaddingBottom(const Dimension& value); - virtual void SetSpace(const Dimension& value); - virtual void SetArrowPosition(const ArrowPosition value); - virtual void SetMenuAlign(const MenuAlign& menuAlign); + static void SetSelectedOptionBgColor(const Color& color); + static void SetSelectedOptionFontSize(const Dimension& value); + static void SetSelectedOptionItalicFontStyle(const Ace::FontStyle& value); + static void SetSelectedOptionFontWeight(const FontWeight& value); + static void SetSelectedOptionFontFamily(const std::vector& value); + static void SetSelectedOptionFontColor(const Color& color); -private: - static std::unique_ptr instance_; - static std::mutex mutex_; + static void SetOptionBgColor(const Color& color); + static void SetOptionFontSize(const Dimension& value); + static void SetOptionItalicFontStyle(const Ace::FontStyle& value); + static void SetOptionFontWeight(const FontWeight& value); + static void SetOptionFontFamily(const std::vector& value); + static void SetOptionFontColor(const Color& color); + + static void SetOnSelect(SelectEvent&& onSelect); + static void SetSpace(const Dimension& value); + static void SetArrowPosition(const ArrowPosition value); + static void SetMenuAlign(const MenuAlign& menuAlign); }; -} // namespace OHOS::Ace -#endif // FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_PATTERN_SELECT_SELECT_MODEL_H +} // namespace OHOS::Ace::NG + +#endif // FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_PATTERN_SELECT_SELECT_VIEW_H \ No newline at end of file diff --git a/frameworks/core/components_ng/test/pattern/select/BUILD.gn b/frameworks/core/components_ng/test/pattern/select/BUILD.gn index 597838d5257..c8d1f8bdc86 100644 --- a/frameworks/core/components_ng/test/pattern/select/BUILD.gn +++ b/frameworks/core/components_ng/test/pattern/select/BUILD.gn @@ -158,8 +158,8 @@ ohos_unittest("select_pattern_test_ng") { # self "$ace_root/frameworks/core/components_ng/pattern/select/select_accessibility_property.cpp", "$ace_root/frameworks/core/components_ng/pattern/select/select_layout_algorithm.cpp", - "$ace_root/frameworks/core/components_ng/pattern/select/select_model_ng.cpp", "$ace_root/frameworks/core/components_ng/pattern/select/select_pattern.cpp", + "$ace_root/frameworks/core/components_ng/pattern/select/select_view.cpp", "$ace_root/frameworks/core/components_ng/property/accessibility_property.cpp", "$ace_root/frameworks/core/components_v2/inspector/utils.cpp", "select_accessibility_property_test_ng.cpp", diff --git a/frameworks/core/components_ng/test/pattern/select/select_pattern_test_ng.cpp b/frameworks/core/components_ng/test/pattern/select/select_pattern_test_ng.cpp index bf3f5035878..68e7dc5956d 100644 --- a/frameworks/core/components_ng/test/pattern/select/select_pattern_test_ng.cpp +++ b/frameworks/core/components_ng/test/pattern/select/select_pattern_test_ng.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2022-2023 Huawei Device Co., Ltd. + * Copyright (c) 2022 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 @@ -26,7 +26,7 @@ #include "core/components_ng/layout/layout_wrapper.h" #include "core/components_ng/pattern/option/option_pattern.h" #include "core/components_ng/pattern/select/select_pattern.h" -#include "core/components_ng/pattern/select/select_model_ng.h" +#include "core/components_ng/pattern/select/select_view.h" #include "core/components_ng/pattern/text/text_pattern.h" #include "core/components_ng/test/mock/theme/mock_theme_manager.h" #include "core/components_v2/inspector/inspector_constants.h" @@ -75,7 +75,6 @@ void SelectPropertyTestNg::TearDownTestCase() */ HWTEST_F(SelectPropertyTestNg, SelectLayoutPropertyTest001, TestSize.Level1) { - SelectModelNG selectModelInstance; // set buttonTheme to themeManager before using themeManager to get buttonTheme auto themeManager = AceType::MakeRefPtr(); MockPipelineBase::GetCurrent()->SetThemeManager(themeManager); @@ -83,7 +82,7 @@ HWTEST_F(SelectPropertyTestNg, SelectLayoutPropertyTest001, TestSize.Level1) std::vector params = { { OPTION_TEXT, FILE_SOURCE }, { OPTION_TEXT, INTERNAL_SOURCE }, { OPTION_TEXT_2, INTERNAL_SOURCE } }; - selectModelInstance.Create(params); + SelectView::Create(params); auto select = ViewStackProcessor::GetInstance()->GetMainFrameNode(); EXPECT_TRUE(select && select->GetTag() == V2::SELECT_ETS_TAG); auto pattern = select->GetPattern(); @@ -104,7 +103,6 @@ HWTEST_F(SelectPropertyTestNg, SelectLayoutPropertyTest001, TestSize.Level1) */ HWTEST_F(SelectPropertyTestNg, SelectLayoutPropertyTest002, TestSize.Level1) { - SelectModelNG selectModelInstance; // set buttonTheme to themeManager before using themeManager to get buttonTheme auto themeManager = AceType::MakeRefPtr(); MockPipelineBase::GetCurrent()->SetThemeManager(themeManager); @@ -112,7 +110,7 @@ HWTEST_F(SelectPropertyTestNg, SelectLayoutPropertyTest002, TestSize.Level1) std::vector params = { { OPTION_TEXT, FILE_SOURCE }, { OPTION_TEXT, INTERNAL_SOURCE }, { OPTION_TEXT_2, INTERNAL_SOURCE } }; - selectModelInstance.Create(params); + SelectView::Create(params); auto select = ViewStackProcessor::GetInstance()->GetMainFrameNode(); EXPECT_TRUE(select && select->GetTag() == V2::SELECT_ETS_TAG); auto pattern = select->GetPattern(); @@ -163,14 +161,13 @@ HWTEST_F(SelectPropertyTestNg, SelectLayoutPropertyTest003, TestSize.Level1) HWTEST_F(SelectPropertyTestNg, SelectSetMenuAlign001, TestSize.Level1) { // create mock themeManager - SelectModelNG selectModelInstance; auto themeManager = AceType::MakeRefPtr(); MockPipelineBase::GetCurrent()->SetThemeManager(themeManager); EXPECT_CALL(*themeManager, GetTheme(_)).WillRepeatedly(Return(AceType::MakeRefPtr())); // create select std::vector params = { { OPTION_TEXT, FILE_SOURCE }, { OPTION_TEXT, INTERNAL_SOURCE }, { OPTION_TEXT_2, INTERNAL_SOURCE } }; - selectModelInstance.Create(params); + SelectView::Create(params); MenuAlign menuAlign; menuAlign.alignType = MenuAlignType::END; menuAlign.offset = DimensionOffset(Dimension(OFFSETX, DimensionUnit::VP), Dimension(OFFSETY, DimensionUnit::VP)); diff --git a/frameworks/core/components_ng/test/pattern/select/select_view_test_ng.cpp b/frameworks/core/components_ng/test/pattern/select/select_view_test_ng.cpp index 8c46f18c7b1..0c262409cef 100644 --- a/frameworks/core/components_ng/test/pattern/select/select_view_test_ng.cpp +++ b/frameworks/core/components_ng/test/pattern/select/select_view_test_ng.cpp @@ -27,7 +27,7 @@ #include "core/components_ng/pattern/linear_layout/linear_layout_pattern.h" #include "core/components_ng/pattern/option/option_pattern.h" #include "core/components_ng/pattern/select/select_pattern.h" -#include "core/components_ng/pattern/select/select_model_ng.h" +#include "core/components_ng/pattern/select/select_view.h" #include "core/components_ng/pattern/text/text_pattern.h" #include "core/components_ng/test/mock/theme/mock_theme_manager.h" #include "core/components_v2/inspector/inspector_constants.h" @@ -69,7 +69,6 @@ void SelectViewTestNg::TearDownTestCase() */ HWTEST_F(SelectViewTestNg, SelectSetSpaceTest001, TestSize.Level1) { - SelectModelNG selectModelInstance; auto themeManager = AceType::MakeRefPtr(); MockPipelineBase::GetCurrent()->SetThemeManager(themeManager); EXPECT_CALL(*themeManager, GetTheme(_)).WillRepeatedly(Return(AceType::MakeRefPtr())); @@ -98,7 +97,7 @@ HWTEST_F(SelectViewTestNg, SelectSetSpaceTest001, TestSize.Level1) row->MountToParent(select); ViewStackProcessor::GetInstance()->Push(select); - selectModelInstance.SetSpace(Dimension(20.00, DimensionUnit::VP)); + SelectView::SetSpace(Dimension(20.00, DimensionUnit::VP)); ASSERT_FALSE(select->GetChildren().empty()); row = FrameNode::GetFrameNode(select->GetFirstChild()->GetTag(), select->GetFirstChild()->GetId()); ASSERT_NE(row, nullptr); @@ -114,7 +113,6 @@ HWTEST_F(SelectViewTestNg, SelectSetSpaceTest001, TestSize.Level1) */ HWTEST_F(SelectViewTestNg, SelectSetArrowPositionTest001, TestSize.Level1) { - SelectModelNG selectModelInstance; auto themeManager = AceType::MakeRefPtr(); MockPipelineBase::GetCurrent()->SetThemeManager(themeManager); EXPECT_CALL(*themeManager, GetTheme(_)).WillRepeatedly(Return(AceType::MakeRefPtr())); @@ -143,7 +141,7 @@ HWTEST_F(SelectViewTestNg, SelectSetArrowPositionTest001, TestSize.Level1) row->MountToParent(select); ViewStackProcessor::GetInstance()->Push(select); - selectModelInstance.SetArrowPosition(ArrowPosition::END); + SelectView::SetArrowPosition(ArrowPosition::END); ASSERT_FALSE(select->GetChildren().empty()); row = FrameNode::GetFrameNode(select->GetFirstChild()->GetTag(), select->GetFirstChild()->GetId()); ASSERT_NE(row, nullptr); @@ -151,7 +149,7 @@ HWTEST_F(SelectViewTestNg, SelectSetArrowPositionTest001, TestSize.Level1) ASSERT_STREQ(V2::ConvertFlexDirectionToStirng(rowProps->GetFlexDirection().value()).c_str(), "FlexDirection.Row"); - selectModelInstance.SetArrowPosition(ArrowPosition::START); + SelectView::SetArrowPosition(ArrowPosition::START); ASSERT_FALSE(select->GetChildren().empty()); row = FrameNode::GetFrameNode(select->GetFirstChild()->GetTag(), select->GetFirstChild()->GetId()); ASSERT_NE(row, nullptr); @@ -167,16 +165,15 @@ HWTEST_F(SelectViewTestNg, SelectSetArrowPositionTest001, TestSize.Level1) */ HWTEST_F(SelectViewTestNg, SelectSetArrowPositionTest002, TestSize.Level1) { - SelectModelNG selectModelInstance; auto themeManager = AceType::MakeRefPtr(); MockPipelineBase::GetCurrent()->SetThemeManager(themeManager); EXPECT_CALL(*themeManager, GetTheme(_)).WillRepeatedly(Return(AceType::MakeRefPtr())); std::vector params = { { OPTION_TEXT, FILE_SOURCE }, { OPTION_TEXT, INTERNAL_SOURCE }, { OPTION_TEXT_2, INTERNAL_SOURCE } }; - selectModelInstance.Create(params); - selectModelInstance.SetArrowPosition(ArrowPosition::END); - selectModelInstance.SetSpace(Dimension(20.00, DimensionUnit::VP)); + SelectView::Create(params); + SelectView::SetArrowPosition(ArrowPosition::END); + SelectView::SetSpace(Dimension(20.00, DimensionUnit::VP)); auto select = ViewStackProcessor::GetInstance()->GetMainFrameNode(); ASSERT_TRUE(select->GetChildren().empty()); } @@ -188,14 +185,13 @@ HWTEST_F(SelectViewTestNg, SelectSetArrowPositionTest002, TestSize.Level1) */ HWTEST_F(SelectViewTestNg, CreateMenu001, TestSize.Level1) { - SelectModelNG selectModelInstance; auto themeManager = AceType::MakeRefPtr(); MockPipelineBase::GetCurrent()->SetThemeManager(themeManager); EXPECT_CALL(*themeManager, GetTheme(_)).WillRepeatedly(Return(AceType::MakeRefPtr())); std::vector params = {{ OPTION_TEXT, FILE_SOURCE }}; ViewStackProcessor::GetInstance()->StartGetAccessRecordingFor(100); - selectModelInstance.Create(params); + SelectView::Create(params); auto select = ViewStackProcessor::GetInstance()->GetMainFrameNode(); ASSERT_NE(select, nullptr); auto pattern = select->GetPattern(); @@ -204,7 +200,7 @@ HWTEST_F(SelectViewTestNg, CreateMenu001, TestSize.Level1) // Create again ViewStackProcessor::GetInstance()->StartGetAccessRecordingFor(100); - selectModelInstance.Create(params); + SelectView::Create(params); select = ViewStackProcessor::GetInstance()->GetMainFrameNode(); pattern = select->GetPattern(); ASSERT_NE(pattern, nullptr); @@ -219,134 +215,19 @@ HWTEST_F(SelectViewTestNg, CreateMenu001, TestSize.Level1) HWTEST_F(SelectViewTestNg, SelectSetMenuAlign001, TestSize.Level1) { // create mock themeManager - SelectModelNG selectModelInstance; auto themeManager = AceType::MakeRefPtr(); MockPipelineBase::GetCurrent()->SetThemeManager(themeManager); EXPECT_CALL(*themeManager, GetTheme(_)).WillRepeatedly(Return(AceType::MakeRefPtr())); // create select std::vector params = { { OPTION_TEXT, FILE_SOURCE }, { OPTION_TEXT, INTERNAL_SOURCE }, { OPTION_TEXT_2, INTERNAL_SOURCE } }; - selectModelInstance.Create(params); + SelectView::Create(params); MenuAlign menuAlign; /** * @tc.cases: case1. verify the SetMenuAlign function. */ - selectModelInstance.SetMenuAlign(menuAlign); + SelectView::SetMenuAlign(menuAlign); auto select = ViewStackProcessor::GetInstance()->GetMainFrameNode(); ASSERT_TRUE(select->GetChildren().empty()); } - -/** - * @tc.name: SelectModel001 - * @tc.desc: Test Select Model - * @tc.type: FUNC - */ -HWTEST_F(SelectViewTestNg, SelectModel001, TestSize.Level1) -{ - SelectModelNG selectModelInstance; - auto themeManager = AceType::MakeRefPtr(); - MockPipelineBase::GetCurrent()->SetThemeManager(themeManager); - EXPECT_CALL(*themeManager, GetTheme(_)).WillRepeatedly(Return(AceType::MakeRefPtr())); - - std::vector params = {{ OPTION_TEXT, FILE_SOURCE }}; - ViewStackProcessor::GetInstance()->StartGetAccessRecordingFor(100); - selectModelInstance.Create(params); - selectModelInstance.SetSelected(0); - selectModelInstance.SetValue("select"); - selectModelInstance.SetFontSize(Dimension(20.00, DimensionUnit::VP)); - selectModelInstance.SetFontWeight(FontWeight::NORMAL); - selectModelInstance.SetItalicFontStyle(Ace::FontStyle::NORMAL); - selectModelInstance.SetFontColor(Color::BLACK); - selectModelInstance.SetSelectedOptionBgColor(Color::BLACK); - selectModelInstance.SetSelectedOptionFontSize(Dimension(20.00, DimensionUnit::VP)); - selectModelInstance.SetSelectedOptionFontWeight(FontWeight::NORMAL); - selectModelInstance.SetSelectedOptionItalicFontStyle(Ace::FontStyle::NORMAL); - selectModelInstance.SetSelectedOptionFontColor(Color::BLACK); - selectModelInstance.SetOptionBgColor(Color::BLACK); - auto select = ViewStackProcessor::GetInstance()->GetMainFrameNode(); - ASSERT_NE(select, nullptr); - auto pattern = select->GetPattern(); - ASSERT_NE(pattern, nullptr); - ASSERT_NE(pattern->GetMenuNode(), nullptr); -} - -/** - * @tc.name: SelectModel002 - * @tc.desc: Test Select Model - * @tc.type: FUNC - */ -HWTEST_F(SelectViewTestNg, SelectModel002, TestSize.Level1) -{ - SelectModelNG selectModelInstance; - SelectEvent eventOnSelect = [](int32_t intValue, const std::string& isSelect) {}; - Dimension width = 20.0_vp; - Dimension height = 20.0_vp; - Dimension top = 20.0_vp; - Dimension bottom = 20.0_vp; - Dimension left = 20.0_vp; - Dimension right = 20.0_vp; - auto themeManager = AceType::MakeRefPtr(); - MockPipelineBase::GetCurrent()->SetThemeManager(themeManager); - EXPECT_CALL(*themeManager, GetTheme(_)).WillRepeatedly(Return(AceType::MakeRefPtr())); - - std::vector params = {{ OPTION_TEXT, FILE_SOURCE }}; - ViewStackProcessor::GetInstance()->StartGetAccessRecordingFor(100); - selectModelInstance.SetOptionFontSize(Dimension(20.00, DimensionUnit::VP)); - selectModelInstance.SetOptionFontWeight(FontWeight::NORMAL); - selectModelInstance.SetOptionItalicFontStyle(Ace::FontStyle::NORMAL); - selectModelInstance.SetOptionFontColor(Color::BLACK); - selectModelInstance.SetOnSelect(std::move(eventOnSelect)); - selectModelInstance.SetWidth(width); - selectModelInstance.SetHeight(height); - selectModelInstance.SetSize(width, height); - selectModelInstance.SetPaddings(top, bottom, left, right); - selectModelInstance.SetPadding(Dimension(20.00, DimensionUnit::VP)); - selectModelInstance.SetPaddingLeft(Dimension(20.00, DimensionUnit::VP)); - selectModelInstance.SetPaddingTop(Dimension(20.00, DimensionUnit::VP)); - selectModelInstance.SetPaddingRight(Dimension(20.00, DimensionUnit::VP)); - selectModelInstance.SetPaddingBottom(Dimension(20.00, DimensionUnit::VP)); - auto select = ViewStackProcessor::GetInstance()->GetMainFrameNode(); - ASSERT_NE(select, nullptr); - auto pattern = select->GetPattern(); - ASSERT_NE(pattern, nullptr); - ASSERT_NE(pattern->GetMenuNode(), nullptr); -} - -/** - * @tc.name: SelectModel003 - * @tc.desc: Test Select Model - * @tc.type: FUNC - */ -HWTEST_F(SelectViewTestNg, SelectModel003, TestSize.Level1) -{ - SelectModelNG selectModelInstance; - SelectEvent eventOnSelect = [](int32_t intValue, const std::string& isSelect) {}; - Dimension width = -20.0_vp; - Dimension height = -20.0_vp; - Dimension top = -20.0_vp; - Dimension bottom = -20.0_vp; - Dimension left = -20.0_vp; - Dimension right = -20.0_vp; - auto themeManager = AceType::MakeRefPtr(); - MockPipelineBase::GetCurrent()->SetThemeManager(themeManager); - EXPECT_CALL(*themeManager, GetTheme(_)).WillRepeatedly(Return(AceType::MakeRefPtr())); - - std::vector params = {{ OPTION_TEXT, FILE_SOURCE }}; - ViewStackProcessor::GetInstance()->StartGetAccessRecordingFor(100); - - selectModelInstance.SetWidth(width); - selectModelInstance.SetHeight(height); - selectModelInstance.SetSize(width, height); - selectModelInstance.SetPaddings(top, bottom, left, right); - selectModelInstance.SetPadding(Dimension(20.00, DimensionUnit::VP)); - selectModelInstance.SetPaddingLeft(Dimension(20.00, DimensionUnit::VP)); - selectModelInstance.SetPaddingTop(Dimension(20.00, DimensionUnit::VP)); - selectModelInstance.SetPaddingRight(Dimension(20.00, DimensionUnit::VP)); - selectModelInstance.SetPaddingBottom(Dimension(20.00, DimensionUnit::VP)); - auto select = ViewStackProcessor::GetInstance()->GetMainFrameNode(); - ASSERT_NE(select, nullptr); - auto pattern = select->GetPattern(); - ASSERT_NE(pattern, nullptr); - ASSERT_NE(pattern->GetMenuNode(), nullptr); -} } // namespace OHOS::Ace::NG \ No newline at end of file -- Gitee