Merge branch 'master' of gitee.com:openharmony/arkui_ace_engine into pr_accessibility_event_TDD

Signed-off-by: limeng <limeng208@huawei.com>
This commit is contained in:
limeng 2023-05-25 08:46:45 +00:00 committed by Gitee
commit 4aea8391fd
322 changed files with 7430 additions and 3089 deletions

View File

@ -63,6 +63,12 @@ config("ace_config") {
cflags_cc += [ "-std=c++17" ]
defines += [ "_USE_MATH_DEFINES" ]
}
ldflags = []
if (ace_engine_feature_enable_coverage) {
cflags += [ "--coverage" ]
ldflags += [ "--coverage" ]
}
}
config("ace_test_config") {

View File

@ -492,6 +492,7 @@ void AceAbility::OnStart(const Want& want, sptr<AAFwk::SessionInfo> sessionInfo)
KeyboardAnimationConfig config = { rsConfig.curveType_, rsConfig.curveParams_, rsConfig.durationIn_,
rsConfig.durationOut_ };
context->SetKeyboardAnimationConfig(config);
context->SetMinPlatformVersion(apiCompatibleVersion);
}
// get url

View File

@ -14,6 +14,7 @@
*/
#include "page_url_checker_ohos.h"
#include <string>
#include "ability_runtime/context/context.h"
@ -219,7 +220,7 @@ void PageUrlCheckerOhos::LoadPageUrl(const std::string& url, const std::function
sptr<AtomicServiceStatusCallback> routerCallback = new AtomicServiceStatusCallback();
routerCallback->SetActionEventHandler(callback);
routerCallback->SetErrorEventHandler(silentInstallErrorCallBack);
if (bms->SilentInstall(want, appInfo->uid, routerCallback)) {
if (bms->SilentInstall(want, appInfo->uid / AppExecFwk::Constants::BASE_USER_RANGE, routerCallback)) {
LOGI("Begin to silent install");
}
} else {

View File

@ -465,6 +465,7 @@ std::shared_ptr<Media::PixelMap> ResourceAdapterImpl::GetPixelMap(uint32_t resId
LOGE("Failed to Create drawableDescriptor by %{public}d", resId);
return nullptr;
}
CHECK_NULL_RETURN(drawableDescriptor, nullptr);
return drawableDescriptor->GetPixelMap();
}

View File

@ -72,7 +72,7 @@ const char LOCALE_KEY[] = "locale";
} // namespace
std::once_flag AceContainer::onceFlag_;
bool AceContainer::isComponentMode_ = false;
AceContainer::AceContainer(int32_t instanceId, FrontendType type, RefPtr<Context> context, bool useCurrentEventRunner)
: instanceId_(instanceId), messageBridge_(AceType::MakeRefPtr<PlatformBridge>()), type_(type), context_(context)
{
@ -939,7 +939,7 @@ void AceContainer::AttachView(std::unique_ptr<Window> window, AceViewPreview* vi
pipelineContext_->SetWindowModal(windowModal_);
pipelineContext_->SetDrawDelegate(aceView_->GetDrawDelegate());
pipelineContext_->SetIsJsCard(type_ == FrontendType::JS_CARD);
if (installationFree_) {
if (installationFree_ && !isComponentMode_) {
LOGD("installationFree:%{public}d, labelId:%{public}d", installationFree_, labelId_);
pipelineContext_->SetInstallationFree(installationFree_);
pipelineContext_->SetAppLabelId(labelId_);
@ -1033,6 +1033,7 @@ void AceContainer::InitDeviceInfo(int32_t instanceId, const AceRunArgs& runArgs)
config.SetColorMode(runArgs.deviceConfig.colorMode);
config.SetFontRatio(runArgs.deviceConfig.fontRatio);
container->SetResourceConfiguration(config);
isComponentMode_ = runArgs.isComponentMode;
}
RefPtr<AceContainer> AceContainer::GetContainerInstance(int32_t instanceId)

View File

@ -287,6 +287,7 @@ private:
// app bar to use
bool installationFree_ = false;
int32_t labelId_;
static bool isComponentMode_;
ACE_DISALLOW_COPY_AND_MOVE(AceContainer);
};

View File

@ -92,6 +92,7 @@ struct ACE_FORCE_EXPORT_WITH_PREVIEW AceRunArgs {
// Container sdk path.
std::string containerSdkPath = "";
bool isComponentMode = false;
};
} // namespace OHOS::Ace::Platform

View File

@ -160,7 +160,7 @@ common_bin = [
if (defined(use_new_skia) && use_new_skia) {
common_bin += [
{
label = "//third_party/skia:new_skia"
label = "//third_party/skia:skia_canvaskit_0310"
subsystem_name = "thirdparty"
part_name = "third_party_skia"
},

View File

@ -95,6 +95,7 @@ foreach(item, ace_platforms) {
deps = [ "$ace_root/build:libace_static_ohos" ]
version_script = "libace.map"
innerapi_tags = [ "platformsdk" ]
part_name = ace_engine_part
subsystem_name = ace_engine_subsystem
configs = [ "$ace_root/test/unittest:ace_coverage_config" ]
@ -120,7 +121,10 @@ foreach(item, ace_platforms) {
]
}
configs = [ "$ace_root:ace_test_config" ]
configs = [
"$ace_root:ace_test_config",
"$ace_root/test/unittest:ace_coverage_config",
]
deps = [
"$ace_root/adapter/ohos/osal:ace_osal_ohos",

View File

@ -31,8 +31,6 @@ struct CalcDimensionParam {
float fpScale = 0.0f;
float lpxScale = 0.0f;
float parentLength = 0.0f;
float rootWidth = 0.0f;
float rootHeight = 0.0f;
};
using CalcDimensionFunc = std::function<bool(const CalcDimensionParam& param, double& result)>;
@ -84,31 +82,10 @@ bool CalcDimensionLpx(const CalcDimensionParam& param, double& result)
return false;
}
bool CalcDimensionVw(const CalcDimensionParam& param, double& result)
{
if (NearZero(param.rootWidth)) {
LOGE("PipelineContext's RootWidth is 0");
return false;
}
result = param.value * param.rootWidth;
return true;
}
bool CalcDimensionVh(const CalcDimensionParam& param, double& result)
{
if (NearZero(param.rootHeight)) {
LOGE("PipelineContext's RootHeight is 0");
return false;
}
result = param.value * param.rootHeight;
return true;
}
std::unordered_map<DimensionUnit, CalcDimensionFunc> calcDimensionFuncMap_ = {
{ DimensionUnit::NONE, &CalcDimensionNone }, { DimensionUnit::PX, &CalcDimensionPx },
{ DimensionUnit::PERCENT, &CalcDimensionPercent }, { DimensionUnit::VP, &CalcDimensionVp },
{ DimensionUnit::FP, &CalcDimensionFp }, { DimensionUnit::LPX, &CalcDimensionLpx },
{ DimensionUnit::VW, &CalcDimensionVw }, { DimensionUnit::VH, &CalcDimensionVh }
{ DimensionUnit::FP, &CalcDimensionFp }, { DimensionUnit::LPX, &CalcDimensionLpx }
};
} // namespace
@ -170,10 +147,10 @@ double Dimension::ConvertToPxWithSize(double size) const
std::string Dimension::ToString() const
{
static const int32_t unitsNum = 8;
static const int32_t unitsNum = 6;
static const int32_t percentIndex = 3;
static const int32_t percentUnit = 100;
static std::array<std::string, unitsNum> units = { "px", "vp", "fp", "%", "lpx", "auto", "vw", "vh" };
static std::array<std::string, unitsNum> units = { "px", "vp", "fp", "%", "lpx", "auto" };
if (units[static_cast<int>(unit_)] == units[percentIndex]) {
return StringUtils::DoubleToString(value_ * percentUnit).append(units[static_cast<int>(unit_)]);
}
@ -219,11 +196,7 @@ bool Dimension::NormalizeToPx(
{
auto func = calcDimensionFuncMap_.find(unit_);
if (func != calcDimensionFuncMap_.end()) {
auto pipeline = PipelineBase::GetCurrentContext();
CHECK_NULL_RETURN(pipeline, false);
auto rootWidth = pipeline->GetRootWidth();
auto rootHeight = pipeline->GetRootHeight();
CalcDimensionParam param = { value_, vpScale, fpScale, lpxScale, parentLength, rootWidth, rootHeight };
CalcDimensionParam param = { value_, vpScale, fpScale, lpxScale, parentLength };
return func->second(param, result);
}
return false;

View File

@ -67,14 +67,6 @@ enum class DimensionUnit {
* The value is expression.
*/
CALC,
/*
* The value is viewport width.
*/
VW,
/*
* The value is viewport height.
*/
VH,
};
/*

View File

@ -98,7 +98,7 @@ void ReplaceSignNumber(std::string& formula)
void ReplaceSignNumberWithUnit(std::string& formula)
{
std::regex pattern("(\\-|\\+)\\d+(\\.\\d+)?(px|vp|%|vw|vh|fp|lpx)");
std::regex pattern("(\\-|\\+)\\d+(\\.\\d+)?(px|vp|%|fp|lpx)");
std::smatch result;
std::string matchStr;
std::string catStr;

View File

@ -194,12 +194,6 @@ inline bool StringToDouble(const std::string& value, double& result)
if (std::strcmp(pEnd, "%") == 0) {
result = res / PERCENT_VALUE;
return true;
} else if (std::strcmp(pEnd, "vw") == 0) {
result = res / PERCENT_VALUE;
return true;
} else if (std::strcmp(pEnd, "vh") == 0) {
result = res / PERCENT_VALUE;
return true;
} else if (std::strcmp(pEnd, "") == 0) {
result = res;
return true;
@ -248,12 +242,6 @@ static Dimension StringToDimensionWithUnit(const std::string& value, DimensionUn
if (std::strcmp(pEnd, "lpx") == 0) {
return Dimension(result, DimensionUnit::LPX);
}
if (std::strcmp(pEnd, "vw") == 0) {
return Dimension(result / PERCENT_VALUE, DimensionUnit::VW);
}
if (std::strcmp(pEnd, "vh") == 0) {
return Dimension(result / PERCENT_VALUE, DimensionUnit::VH);
}
if ((std::strcmp(pEnd, "\0") == 0) && isCalc) {
return Dimension(result, DimensionUnit::NONE);
}

View File

@ -582,6 +582,7 @@ template("declarative_js_engine_ng") {
"sharedata/js_share_data.cpp",
# jsviews
"jsview/js_button.cpp",
"jsview/js_column.cpp",
"jsview/js_container_base.cpp",
"jsview/js_counter.cpp",

View File

@ -960,7 +960,8 @@ void JsiDeclarativeEngine::RegisterInitWorkerFunc()
auto workerPostTask = [nativeEngine](std::function<void()>&& callback) {
nativeEngine->CallDebuggerPostTaskFunc(std::move(callback));
};
panda::JSNApi::StartDebugger(libraryPath.c_str(), vm, debugMode, gettid(), workerPostTask);
panda::JSNApi::DebugOption debugOption = {libraryPath.c_str(), debugMode};
panda::JSNApi::StartDebugger(vm, debugOption, gettid(), workerPostTask);
#endif
instance->InitConsoleModule(arkNativeEngine);

View File

@ -17,18 +17,15 @@
#include "base/i18n/localization.h"
#include "base/log/log.h"
#include "base/memory/ace_type.h"
#ifdef VIDEO_SUPPORTED
#include "bridge/declarative_frontend/jsview/js_video.h"
#endif
#include "core/components_ng/base/ui_node.h"
#include "core/components_ng/base/view_stack_processor.h"
#include "core/components_ng/pattern/custom/custom_node.h"
#include "core/components_ng/pattern/stage/page_pattern.h"
#include "frameworks/bridge/card_frontend/card_frontend_declarative.h"
#include "frameworks/bridge/common/utils/engine_helper.h"
#include "frameworks/bridge/declarative_frontend/engine/functions/js_drag_function.h"
#include "frameworks/bridge/declarative_frontend/engine/js_object_template.h"
#include "frameworks/bridge/declarative_frontend/engine/jsi/jsi_view_register.h"
#include "frameworks/bridge/declarative_frontend/jsview/js_button.h"
#include "frameworks/bridge/declarative_frontend/jsview/js_column.h"
#include "frameworks/bridge/declarative_frontend/jsview/js_container_base.h"
#include "frameworks/bridge/declarative_frontend/jsview/js_counter.h"
@ -60,13 +57,15 @@
#include "frameworks/bridge/declarative_frontend/jsview/js_text.h"
#include "frameworks/bridge/declarative_frontend/jsview/js_textinput.h"
#include "frameworks/bridge/declarative_frontend/jsview/js_toggle.h"
#include "frameworks/bridge/declarative_frontend/jsview/js_view.h"
#include "frameworks/bridge/declarative_frontend/jsview/js_view_stack_processor.h"
#include "frameworks/bridge/declarative_frontend/jsview/scroll_bar/js_scroll_bar.h"
#include "frameworks/bridge/declarative_frontend/ng/declarative_frontend_ng.h"
#include "frameworks/bridge/declarative_frontend/ng/frontend_delegate_declarative_ng.h"
#ifdef VIDEO_SUPPORTED
#include "frameworks/bridge/declarative_frontend/jsview/js_video.h"
#endif
#include "frameworks/bridge/declarative_frontend/jsview/js_view.h"
#include "frameworks/bridge/declarative_frontend/jsview/js_view_stack_processor.h"
#include "frameworks/bridge/declarative_frontend/ng/frontend_delegate_declarative_ng.h"
namespace OHOS::Ace::Framework {
@ -188,6 +187,7 @@ void JsBindViews(BindingTarget globalObj)
JSImageSpan::JSBind(globalObj);
JSScroller::JSBind(globalObj);
JSScrollBar::JSBind(globalObj);
JSButton::JSBind(globalObj);
}
} // namespace OHOS::Ace::Framework

View File

@ -256,6 +256,7 @@ void JSButton::SetLableStyle(const JSCallbackInfo& info)
void JSButton::JsRemoteMessage(const JSCallbackInfo& info)
{
#ifndef NG_BUILD
RemoteCallback remoteCallback;
JSInteractableView::JsRemoteMessage(info, remoteCallback);
EventMarker remoteMessageEventId(std::move(remoteCallback));
@ -264,6 +265,7 @@ void JSButton::JsRemoteMessage(const JSCallbackInfo& info)
if (buttonComponent) {
buttonComponent->SetRemoteMessageEventId(remoteMessageEventId);
}
#endif
}
void JSButton::JSBind(BindingTarget globalObj)

View File

@ -286,14 +286,24 @@ void JSCanvasRenderer::JsFillText(const JSCallbackInfo& info)
JSViewAbstract::ParseJsDouble(info[2], y);
x = SystemProperties::Vp2Px(x);
y = SystemProperties::Vp2Px(y);
std::optional<double> maxWidth;
if (info.Length() >= 4) {
double width = 0.0;
if (info[3]->IsUndefined()) {
width = FLT_MAX;
} else if (info[3]->IsNumber()) {
JSViewAbstract::ParseJsDouble(info[3], width);
width = SystemProperties::Vp2Px(width);
}
maxWidth = width;
}
if (Container::IsCurrentUseNewPipeline()) {
if (isOffscreen_ && offscreenCanvasPattern_) {
offscreenCanvasPattern_->FillText(text, x, y, paintState_);
offscreenCanvasPattern_->FillText(text, x, y, maxWidth, paintState_);
return;
}
if (!isOffscreen_ && customPaintPattern_) {
customPaintPattern_->FillText(text, x, y);
customPaintPattern_->FillText(text, x, y, maxWidth);
}
return;
}
@ -323,14 +333,24 @@ void JSCanvasRenderer::JsStrokeText(const JSCallbackInfo& info)
JSViewAbstract::ParseJsDouble(info[2], y);
x = SystemProperties::Vp2Px(x);
y = SystemProperties::Vp2Px(y);
std::optional<double> maxWidth;
if (info.Length() >= 4) {
double width = 0.0;
if (info[3]->IsUndefined()) {
width = FLT_MAX;
} else if (info[3]->IsNumber()) {
JSViewAbstract::ParseJsDouble(info[3], width);
width = SystemProperties::Vp2Px(width);
}
maxWidth = width;
}
if (Container::IsCurrentUseNewPipeline()) {
if (isOffscreen_ && offscreenCanvasPattern_) {
offscreenCanvasPattern_->StrokeText(text, x, y, paintState_);
offscreenCanvasPattern_->StrokeText(text, x, y, maxWidth, paintState_);
return;
}
if (!isOffscreen_ && customPaintPattern_) {
customPaintPattern_->StrokeText(text, x, y);
customPaintPattern_->StrokeText(text, x, y, maxWidth);
}
return;
}
@ -663,9 +683,10 @@ void JSCanvasRenderer::JsSetFillStyle(const JSCallbackInfo& info)
return;
}
if (info[0]->IsString()) {
std::string colorStr = "";
JSViewAbstract::ParseJsString(info[0], colorStr);
auto color = Color::FromString(colorStr);
Color color;
if (!JSViewAbstract::CheckColor(info[0], color, "CanvasRenderer", "fillStyle")) {
return;
}
if (Container::IsCurrentUseNewPipeline()) {
if (isOffscreen_ && offscreenCanvasPattern_) {
@ -769,9 +790,10 @@ void JSCanvasRenderer::JsSetStrokeStyle(const JSCallbackInfo& info)
return;
}
if (info[0]->IsString()) {
std::string colorStr;
JSViewAbstract::ParseJsString(info[0], colorStr);
auto color = Color::FromString(colorStr);
Color color;
if (!JSViewAbstract::CheckColor(info[0], color, "CanvasRenderer", "strokeStyle")) {
return;
}
if (Container::IsCurrentUseNewPipeline()) {
if (isOffscreen_ && offscreenCanvasPattern_) {
offscreenCanvasPattern_->SetStrokeColor(color);
@ -2567,7 +2589,20 @@ void JSCanvasRenderer::JsScale(const JSCallbackInfo& info)
void JSCanvasRenderer::JsGetTransform(const JSCallbackInfo& info)
{
return;
JSRef<JSObject> obj = JSClass<JSMatrix2d>::NewInstance();
obj->SetProperty("__type", "Matrix2D");
if (Container::IsCurrentUseNewPipeline()) {
TransformParam param;
if (isOffscreen_ && offscreenCanvasPattern_) {
param = offscreenCanvasPattern_->GetTransform();
} else if (!isOffscreen_ && customPaintPattern_) {
param = customPaintPattern_->GetTransform();
}
auto matrix = Referenced::Claim(obj->Unwrap<JSMatrix2d>());
CHECK_NULL_VOID(matrix);
matrix->SetTransform(param);
}
info.SetReturnValue(obj);
}
void JSCanvasRenderer::JsSetTransform(const JSCallbackInfo& info)

View File

@ -57,27 +57,20 @@ void JSCircle::Create(const JSCallbackInfo& info)
void JSCircle::ConstructorCallback(const JSCallbackInfo& info)
{
if (info.Length() < 1) {
LOGE("The arg is wrong, it is supposed to have at least 1 argument");
return;
}
if (!info[0]->IsObject()) {
LOGE("The arg is not Object");
return;
}
auto circle = AceType::MakeRefPtr<Circle>();
JSRef<JSObject> params = JSRef<JSObject>::Cast(info[0]);
JSRef<JSVal> width = params->GetProperty("width");
CalcDimension dimWidth;
if (ParseJsDimensionVp(width, dimWidth)) {
circle->SetWidth(dimWidth);
if (info.Length() == 1 && info[0]->IsObject()) {
JSRef<JSObject> params = JSRef<JSObject>::Cast(info[0]);
JSRef<JSVal> width = params->GetProperty("width");
CalcDimension dimWidth;
if (ParseJsDimensionVp(width, dimWidth)) {
circle->SetWidth(dimWidth);
}
JSRef<JSVal> height = params->GetProperty("height");
CalcDimension dimHeight;
if (ParseJsDimensionVp(height, dimHeight)) {
circle->SetHeight(dimHeight);
}
}
JSRef<JSVal> height = params->GetProperty("height");
CalcDimension dimHeight;
if (ParseJsDimensionVp(height, dimHeight)) {
circle->SetHeight(dimHeight);
}
auto jsCircle = AceType::MakeRefPtr<JSCircle>();
jsCircle->SetBasicShape(circle);
jsCircle->IncRefCount();

View File

@ -56,27 +56,20 @@ void JSEllipse::Create(const JSCallbackInfo& info)
void JSEllipse::ConstructorCallback(const JSCallbackInfo& info)
{
if (info.Length() < 1) {
LOGE("The arg is wrong, it is supposed to have at least 1 argument");
return;
}
if (!info[0]->IsObject()) {
LOGE("The arg is not Object");
return;
}
auto ellipse = AceType::MakeRefPtr<Ellipse>();
JSRef<JSObject> params = JSRef<JSObject>::Cast(info[0]);
JSRef<JSVal> width = params->GetProperty("width");
CalcDimension dimWidth;
if (ParseJsDimensionVp(width, dimWidth)) {
ellipse->SetWidth(dimWidth);
if (info.Length() == 1 && info[0]->IsObject()) {
JSRef<JSObject> params = JSRef<JSObject>::Cast(info[0]);
JSRef<JSVal> width = params->GetProperty("width");
CalcDimension dimWidth;
if (ParseJsDimensionVp(width, dimWidth)) {
ellipse->SetWidth(dimWidth);
}
JSRef<JSVal> height = params->GetProperty("height");
CalcDimension dimHeight;
if (ParseJsDimensionVp(height, dimHeight)) {
ellipse->SetHeight(dimHeight);
}
}
JSRef<JSVal> height = params->GetProperty("height");
CalcDimension dimHeight;
if (ParseJsDimensionVp(height, dimHeight)) {
ellipse->SetHeight(dimHeight);
}
auto jsEllipse = AceType::MakeRefPtr<JSEllipse>();
jsEllipse->SetBasicShape(ellipse);
jsEllipse->IncRefCount();

View File

@ -87,6 +87,11 @@ public:
return transform_;
}
void SetTransform(const TransformParam& param)
{
transform_ = param;
}
std::string ToString() const;
ACE_DISALLOW_COPY_AND_MOVE(JSMatrix2d);

View File

@ -213,34 +213,17 @@ void JSOffscreenCanvas::JsSetHeight(const JSCallbackInfo& info)
void JSOffscreenCanvas::JsTransferToImageBitmap(const JSCallbackInfo& info)
{
if (Container::IsCurrentUseNewPipeline() && !offscreenCanvasPattern_) {
std::unique_ptr<ImageData> imageData =
offscreenCanvasPattern_->GetImageData(0.0, 0.0, GetWidth(), GetHeight());
if (imageData.get() == nullptr) {
return;
}
double final_height = static_cast<uint32_t>(imageData->dirtyHeight);
double final_width = static_cast<uint32_t>(imageData->dirtyWidth);
JSRef<JSArray> colorArray = JSRef<JSArray>::New();
uint32_t count = 0;
for (uint32_t i = 0; i < final_height; i++) {
for (uint32_t j = 0; j < final_width; j++) {
int32_t idx = i * imageData->dirtyWidth + j;
auto pixel = imageData->data[idx];
colorArray->SetValueAt(count, JSRef<JSVal>::Make(ToJSValue(pixel.GetRed())));
colorArray->SetValueAt(count + 1, JSRef<JSVal>::Make(ToJSValue(pixel.GetGreen())));
colorArray->SetValueAt(count + 2, JSRef<JSVal>::Make(ToJSValue(pixel.GetBlue())));
colorArray->SetValueAt(count + 3, JSRef<JSVal>::Make(ToJSValue(pixel.GetAlpha())));
count += 4;
}
}
auto retObj = JSRef<JSObject>::New();
retObj->SetProperty("width", final_width);
retObj->SetProperty("height", final_height);
retObj->SetPropertyObject("data", colorArray);
info.SetReturnValue(retObj);
if (Container::IsCurrentUseNewPipeline()) {
CHECK_NULL_VOID(offscreenCanvasContext_);
CHECK_NULL_VOID(offscreenCanvasPattern_);
auto final_height = static_cast<uint32_t>(GetHeight());
auto final_width = static_cast<uint32_t>(GetWidth());
JSRef<JSObject> renderImage = JSRef<JSObject>::New();
renderImage->SetProperty("__type", "ImageBitmap");
renderImage->SetProperty("__id", offscreenCanvasContext_->GetId());
renderImage->SetProperty("height", final_height);
renderImage->SetProperty("width", final_width);
info.SetReturnValue(renderImage);
}
}

View File

@ -60,7 +60,7 @@ void JSPersistent::Set(const JSCallbackInfo& args)
"emulator or a real device instead.");
return;
#endif
if (args.Length() < 2 || !args[0]->IsString() || !args[1]->IsString()) {
if (args.Length() < 2 || !args[0]->IsString() || args[1]->IsUndefined() || args[1]->IsNull()) {
LOGW("JSPersistent: Fail to set persistent data, args too few");
return;
}
@ -73,6 +73,7 @@ void JSPersistent::Set(const JSCallbackInfo& args)
}
auto executor = container->GetTaskExecutor();
if(!StorageProxy::GetInstance()->GetStorage(executor)) {
LOGW("no storage available");
return;
}
StorageProxy::GetInstance()->GetStorage(executor)->SetString(key, value);

View File

@ -104,14 +104,20 @@ void JSScroller::ScrollTo(const JSCallbackInfo& args)
ConvertFromJSValue(animationObj->GetProperty("duration"), duration);
std::string curveName;
if (ConvertFromJSValue(animationObj->GetProperty("curve"), curveName)) {
auto curveArgs = animationObj->GetProperty("curve");
if (ConvertFromJSValue(curveArgs, curveName)) {
auto index = BinarySearchFindIndex(CURVE_MAP, ArraySize(CURVE_MAP), curveName.c_str());
if (index >= 0) {
curve = CURVE_MAP[index].value;
}
} else if (curveArgs->IsObject()) {
ParseCustomCurveParams(curve, curveArgs);
}
}
bool smooth = false;
ConvertFromJSValue(obj->GetProperty("smooth"), smooth);
if (GreatNotEqual(duration, 0.0)) {
LOGD("ScrollTo(%lf, %lf, %lf)", xOffset.Value(), yOffset.Value(), duration);
} else {
@ -124,7 +130,16 @@ void JSScroller::ScrollTo(const JSCallbackInfo& args)
}
auto direction = scrollController->GetScrollDirection();
auto position = direction == Axis::VERTICAL ? yOffset : xOffset;
scrollController->AnimateTo(position, static_cast<float>(duration), curve);
scrollController->AnimateTo(position, static_cast<float>(duration), curve, smooth);
}
void JSScroller::ParseCustomCurveParams(RefPtr<Curve>& curve, const JSRef<JSVal>& jsValue)
{
auto icurveArgs = JsonUtil::ParseJsonString(jsValue->ToString());
if (icurveArgs->IsObject()) {
auto curveString = icurveArgs->GetValue("__curveString");
curve = CreateCurve(curveString->GetString());
}
}
void JSScroller::ScrollEdge(const JSCallbackInfo& args)

View File

@ -60,6 +60,8 @@ public:
}
private:
void ParseCustomCurveParams(RefPtr<Curve>& curve, const JSRef<JSVal>& jsValue);
WeakPtr<ScrollControllerBase> controllerWeak_;
WeakPtr<ScrollProxy> scrollBarProxyWeak_;

View File

@ -125,15 +125,18 @@ void JSSearch::Create(const JSCallbackInfo& info)
}
std::string text;
key = "";
if (param->GetProperty("value")->IsObject()) {
JSRef<JSObject> valueObj = JSRef<JSObject>::Cast(param->GetProperty("value"));
JSRef<JSVal> textValue = param->GetProperty("value");
if (textValue->IsObject()) {
JSRef<JSObject> valueObj = JSRef<JSObject>::Cast(textValue);
changeEventVal = valueObj->GetProperty("changeEvent");
auto valueProperty = valueObj->GetProperty("value");
if (ParseJsString(valueProperty, text)) {
if (changeEventVal->IsFunction()) {
textValue = valueObj->GetProperty("value");
}
if (ParseJsString(textValue, text)) {
key = text;
}
} else {
if (ParseJsString(param->GetProperty("value"), text)) {
if (ParseJsString(textValue, text)) {
key = text;
}
}

View File

@ -96,15 +96,18 @@ void JSTextField::CreateTextInput(const JSCallbackInfo& info)
placeholderSrc = placeholder;
}
std::string text;
if (paramObject->GetProperty("text")->IsObject()) {
JSRef<JSObject> valueObj = JSRef<JSObject>::Cast(paramObject->GetProperty("text"));
JSRef<JSVal> textValue = paramObject->GetProperty("text");
if (textValue->IsObject()) {
JSRef<JSObject> valueObj = JSRef<JSObject>::Cast(textValue);
changeEventVal = valueObj->GetProperty("changeEvent");
auto valueProperty = valueObj->GetProperty("value");
if (ParseJsString(valueProperty, text)) {
if (changeEventVal->IsFunction()) {
textValue = valueObj->GetProperty("value");
}
if (ParseJsString(textValue, text)) {
value = text;
}
} else {
if (ParseJsString(paramObject->GetProperty("text"), text)) {
if (ParseJsString(textValue, text)) {
value = text;
}
}
@ -130,7 +133,7 @@ void JSTextField::CreateTextArea(const JSCallbackInfo& info)
std::optional<std::string> placeholderSrc;
std::optional<std::string> value;
JSTextAreaController* jsController = nullptr;
JSRef<JSVal> changeEventVal;
JSRef<JSVal> changeEventVal = JSRef<JSVal>::Make();
if (info[0]->IsObject()) {
auto paramObject = JSRef<JSObject>::Cast(info[0]);
std::string placeholder;
@ -138,15 +141,18 @@ void JSTextField::CreateTextArea(const JSCallbackInfo& info)
placeholderSrc = placeholder;
}
std::string text;
if (paramObject->GetProperty("text")->IsObject()) {
JSRef<JSObject> valueObj = JSRef<JSObject>::Cast(paramObject->GetProperty("text"));
JSRef<JSVal> textValue = paramObject->GetProperty("text");
if (textValue->IsObject()) {
JSRef<JSObject> valueObj = JSRef<JSObject>::Cast(textValue);
changeEventVal = valueObj->GetProperty("changeEvent");
auto valueProperty = valueObj->GetProperty("value");
if (ParseJsString(valueProperty, text)) {
if (changeEventVal->IsFunction()) {
textValue = valueObj->GetProperty("value");
}
if (ParseJsString(textValue, text)) {
value = text;
}
} else {
if (ParseJsString(paramObject->GetProperty("text"), text)) {
if (ParseJsString(textValue, text)) {
value = text;
}
}

View File

@ -544,9 +544,13 @@ bool JSTextPickerParser::ParseInternalArray(const JSRef<JSArray>& jsRangeValue,
values.emplace_back("");
}
} else {
auto valueIterator = std::find(resultStr.begin(), resultStr.end(), values[index]);
if (valueIterator == resultStr.end()) {
values[index] = resultStr.front();
if (resultStr.size() > 0) {
auto valueIterator = std::find(resultStr.begin(), resultStr.end(), values[index]);
if (valueIterator == resultStr.end()) {
values[index] = resultStr.front();
}
} else {
values[index] = "";
}
}
@ -638,7 +642,9 @@ bool JSTextPickerParser::ParseTextArray(const JSRef<JSObject>& paramObject, Pars
if (getValue->IsObject()) {
JSRef<JSObject> valueObj = JSRef<JSObject>::Cast(getValue);
param.valueChangeEventVal = valueObj->GetProperty("changeEvent");
getValue = valueObj->GetProperty("value");
if (param.valueChangeEventVal->IsFunction()) {
getValue = valueObj->GetProperty("value");
}
}
if (!ParseJsString(getValue, param.value)) {
param.value = getRangeVector.front();
@ -646,7 +652,9 @@ bool JSTextPickerParser::ParseTextArray(const JSRef<JSObject>& paramObject, Pars
if (getSelected->IsObject()) {
JSRef<JSObject> selectedObj = JSRef<JSObject>::Cast(getSelected);
param.selectedChangeEventVal = selectedObj->GetProperty("changeEvent");
getSelected = selectedObj->GetProperty("value");
if (param.selectedChangeEventVal->IsFunction()) {
getSelected = selectedObj->GetProperty("value");
}
}
if (!ParseJsInteger(getSelected, param.selected) && !param.value.empty()) {
auto valueIterator = std::find(getRangeVector.begin(), getRangeVector.end(), param.value);

View File

@ -111,6 +111,7 @@ constexpr int32_t PARAMETER_LENGTH_SECOND = 2;
constexpr int32_t PARAMETER_LENGTH_THIRD = 3;
constexpr float DEFAULT_SCALE_LIGHT = 0.9f;
constexpr float DEFAULT_SCALE_MIDDLE_OR_HEAVY = 0.95f;
const std::vector<FontStyle> FONT_STYLES = { FontStyle::NORMAL, FontStyle::ITALIC };
bool CheckJSCallbackInfo(
const std::string& callerName, const JSCallbackInfo& info, std::vector<JSCallbackInfoType>& infoTypes)
@ -611,6 +612,19 @@ void SetPopupMessageOptions(const JSRef<JSObject> messageOptionsObj, const RefPt
LOGI("Empty popup.");
}
}
auto fontStyleValue = fontObj->GetProperty("style");
if (fontStyleValue->IsNumber()) {
int32_t value = fontStyleValue->ToNumber<int32_t>();
if (value < 0 || value >= static_cast<int32_t>(FONT_STYLES.size())) {
LOGI("Text fontStyle(%d) is invalid value", value);
return;
}
if (popupParam) {
popupParam->SetFontStyle(FONT_STYLES[value]);
} else {
LOGI("Empty popup.");
}
}
}
}
@ -5210,7 +5224,7 @@ void JSViewAbstract::SetPaddingRight(const JSCallbackInfo& info)
void JSViewAbstract::SetBlur(float radius)
{
CalcDimension dimensionRadius(radius, DimensionUnit::PX);
CalcDimension dimensionRadius(radius, DimensionUnit::VP);
ViewAbstractModel::GetInstance()->SetFrontBlur(dimensionRadius);
}
@ -5221,7 +5235,7 @@ void JSViewAbstract::SetColorBlend(Color color)
void JSViewAbstract::SetBackdropBlur(float radius)
{
CalcDimension dimensionRadius(radius, DimensionUnit::PX);
CalcDimension dimensionRadius(radius, DimensionUnit::VP);
ViewAbstractModel::GetInstance()->SetBackdropBlur(dimensionRadius);
}

View File

@ -216,6 +216,10 @@ void JSViewContext::JSAnimation(const JSCallbackInfo& info)
CHECK_NULL_VOID(container);
auto pipelineContextBase = container->GetPipelineContext();
CHECK_NULL_VOID(pipelineContextBase);
if (!pipelineContextBase->GetEnableImplicitAnimation() && pipelineContextBase->IsFormRender()) {
LOGW("Form need enable implicit animation in finish callback.");
return;
}
if (info[0]->IsNull() || !info[0]->IsObject()) {
ViewContextModel::GetInstance()->closeAnimation(option, true);
return;
@ -269,6 +273,15 @@ void JSViewContext::JSAnimateTo(const JSCallbackInfo& info)
return;
}
auto container = Container::Current();
CHECK_NULL_VOID(container);
auto pipelineContext = container->GetPipelineContext();
CHECK_NULL_VOID(pipelineContext);
if (!pipelineContext->GetEnableImplicitAnimation() && pipelineContext->IsFormRender()) {
LOGW("Form need enable implicit animation in finish callback.");
return;
}
JSRef<JSObject> obj = JSRef<JSObject>::Cast(info[0]);
JSRef<JSVal> onFinish = obj->GetProperty("onFinish");
std::function<void()> onFinishEvent;
@ -288,11 +301,6 @@ void JSViewContext::JSAnimateTo(const JSCallbackInfo& info)
return;
}
auto container = Container::Current();
CHECK_NULL_VOID(container);
auto pipelineContext = container->GetPipelineContext();
CHECK_NULL_VOID(pipelineContext);
AnimationOption option = CreateAnimation(animationArgs, pipelineContext->IsFormRender());
if (SystemProperties::GetRosenBackendEnabled()) {
bool usingSharedRuntime = container->GetSettings().usingSharedRuntime;

View File

@ -24,6 +24,7 @@
#include "core/components_ng/base/view_stack_model_ng.h"
#include "core/components_ng/base/view_stack_processor.h"
#include "frameworks/core/pipeline/base/element_register.h"
#include "foundation/arkui/ace_engine/frameworks/core/common/ace_application_info.h"
namespace OHOS::Ace {
@ -88,6 +89,7 @@ void JSViewStackProcessor::JSBind(BindingTarget globalObj)
JSClass<JSViewStackProcessor>::StaticMethod("visualState", JSVisualState, opt);
JSClass<JSViewStackProcessor>::StaticMethod("MakeUniqueId", &JSViewStackProcessor::JSMakeUniqueId, opt);
JSClass<JSViewStackProcessor>::StaticMethod("UsesNewPipeline", &JSViewStackProcessor::JsUsesNewPipeline, opt);
JSClass<JSViewStackProcessor>::StaticMethod("getApiVersion", &JSViewStackProcessor::JsGetApiVersion, opt);
JSClass<JSViewStackProcessor>::Bind<>(globalObj);
}
@ -142,6 +144,7 @@ void JSViewStackProcessor::JSMakeUniqueId(const JSCallbackInfo& info)
const auto result = ElementRegister::GetInstance()->MakeUniqueId();
info.SetReturnValue(JSRef<JSVal>::Make(ToJSValue(result)));
}
/**
* return true of current Container uses new Pipeline
*/
@ -150,4 +153,12 @@ bool JSViewStackProcessor::JsUsesNewPipeline()
return Container::IsCurrentUseNewPipeline();
}
/**
* return the API version specified in the manifest.json
*/
int32_t JSViewStackProcessor::JsGetApiVersion()
{
return AceApplicationInfo::GetInstance().GetApiTargetVersion();
}
} // namespace OHOS::Ace::Framework

View File

@ -76,8 +76,16 @@ public:
return it->second;
}
/**
* return true of current Container uses new Pipeline
*/
static bool JsUsesNewPipeline();
/**
* return the API version specified in the manifest.json
*/
static int32_t JsGetApiVersion();
private:
static void JSVisualState(const JSCallbackInfo& info);
static std::map<std::string, JSRef<JSObject>> viewMap_;

View File

@ -242,6 +242,10 @@ class SynchedPropertyObjectOneWayPU<C extends Object>
// ViewStackProcessor.getApiVersion function is not present in API9
// therefore shallowCopyObject will always be used in API version 9 and before
// but the code in this file is the same regardless of API version
stateMgmtConsole.debug(`targetApiVersion: \
${(typeof ViewStackProcessor["getApiVersion"] == "function") ? ViewStackProcessor["getApiVersion"]() : 'unknown'}, \
will use ${((typeof ViewStackProcessor["getApiVersion"] == "function") && (ViewStackProcessor["getApiVersion"]() >= 10)) ? 'deep copy' : 'shallow copy'} .`);
return ((typeof ViewStackProcessor["getApiVersion"] == "function") &&
(ViewStackProcessor["getApiVersion"]() >= 10))
? this.deepCopyObject(value, propName)

View File

@ -108,15 +108,17 @@ bool ArkJSRuntime::StartDebugger()
bool ret = false;
#if !defined(PREVIEW)
if (!libPath_.empty()) {
JSNApi::DebugOption debugOption = {libPath_.c_str(), isDebugMode_};
#if !defined(ANDROID_PLATFORM) && !defined(IOS_PLATFORM)
ConnectServerManager::Get().AddInstance(instanceId_, language_);
ret = JSNApi::StartDebugger(libPath_.c_str(), vm_, isDebugMode_, instanceId_, debuggerPostTask_);
ret = JSNApi::StartDebugger(vm_, debugOption, instanceId_, debuggerPostTask_);
#elif defined(ANDROID_PLATFORM)
ret = JSNApi::StartDebugger(libPath_.c_str(), vm_, isDebugMode_, instanceId_, debuggerPostTask_);
ret = JSNApi::StartDebugger(vm_, debugOption, instanceId_, debuggerPostTask_);
#endif
}
#if defined(IOS_PLATFORM)
ret = JSNApi::StartDebugger(nullptr, vm_, isDebugMode_, instanceId_, debuggerPostTask_);
JSNApi::DebugOption debugOption = {nullptr, isDebugMode_};
ret = JSNApi::StartDebugger(vm_, debugOption, instanceId_, debuggerPostTask_);
#endif
#endif
return ret;

View File

@ -3237,7 +3237,8 @@ void JsiEngine::RegisterInitWorkerFunc()
auto workerPostTask = [nativeEngine](std::function<void()>&& callback) {
nativeEngine->CallDebuggerPostTaskFunc(std::move(callback));
};
panda::JSNApi::StartDebugger(libraryPath.c_str(), vm, debugMode, gettid(), workerPostTask);
panda::JSNApi::DebugOption debugOption = {libraryPath.c_str(), debugMode};
panda::JSNApi::StartDebugger(vm, debugOption, gettid(), workerPostTask);
#endif
instance->RegisterConsoleModule(arkNativeEngine);
// load jsfwk

View File

@ -692,15 +692,10 @@ template("ace_core_ng_source_set") {
"pipeline/pipeline_base.cpp",
# image
"image/animated_image_player.cpp",
"image/flutter_image_cache.cpp",
"image/image_cache.cpp",
"image/image_compressor.cpp",
"image/image_loader.cpp",
"image/image_object.cpp",
"image/image_object_animated.cpp",
"image/image_object_svg.cpp",
"image/image_provider.cpp",
"image/image_source_info.cpp",
# textfield

View File

@ -60,8 +60,12 @@ void Scheduler::OnFrame(uint64_t nanoTimestamp)
}
// Refresh the startup time every frame.
uint64_t elapsedTimeMs = (nanoTimestamp - startupTimestamp_) / 1000000;
startupTimestamp_ += elapsedTimeMs * 1000000;
uint64_t elapsedTimeMs = 0;
if (nanoTimestamp > startupTimestamp_) {
static const uint64_t milliToNano = 1000000;
elapsedTimeMs = (nanoTimestamp - startupTimestamp_) / milliToNano;
startupTimestamp_ += elapsedTimeMs * milliToNano;
}
// Consume previous schedule as default.
scheduleId_ = 0;

View File

@ -21,6 +21,7 @@
#include "base/utils/utils.h"
#include "core/common/container.h"
#include "core/components_ng/base/frame_node.h"
#include "core/components_ng/manager/select_overlay/select_overlay_manager.h"
#include "core/event/ace_events.h"
#include "core/event/key_event.h"
#include "core/event/touch_event.h"
@ -150,6 +151,19 @@ void EventManager::HandleGlobalEvent(const TouchEvent& touchPoint, const RefPtr<
inSelectedRect_ = false;
}
void EventManager::HandleGlobalEventNG(
const TouchEvent& touchPoint, const RefPtr<NG::SelectOverlayManager>& selectOverlayManager)
{
if (touchPoint.type != TouchType::DOWN || touchPoint.sourceType != SourceType::MOUSE) {
return;
}
const NG::PointF point { touchPoint.x, touchPoint.y };
CHECK_NULL_VOID_NOLOG(selectOverlayManager);
if (!selectOverlayManager->IsInSelectedOrSelectOverlayArea(point)) {
selectOverlayManager->DestroySelectOverlay();
}
}
void EventManager::HandleOutOfRectCallback(const Point& point, std::vector<RectCallback>& rectCallbackList)
{
for (auto iter = rectCallbackList.begin(); iter != rectCallbackList.end();) {

View File

@ -34,7 +34,8 @@ namespace OHOS::Ace {
namespace NG {
class FrameNode;
}
class SelectOverlayManager;
} // namespace NG
class RenderNode;
class Element;
class TextOverlayManager;
@ -125,6 +126,7 @@ public:
return instanceId_;
}
void HandleGlobalEvent(const TouchEvent& touchPoint, const RefPtr<TextOverlayManager>& textOverlayManager);
void HandleGlobalEventNG(const TouchEvent& touchPoint, const RefPtr<NG::SelectOverlayManager>& selectOverlayManager);
void CollectTabIndexNodes(const RefPtr<FocusNode>& rootNode);

View File

@ -50,7 +50,7 @@ build_component("camera") {
"c_utils:utils",
"ipc:ipc_core",
"multimedia_camera_framework:camera_framework",
"multimedia_player_framework:media_client",
"player_framework:media_client",
]
} else {
sources += [ "large_system/camera.cpp" ]

View File

@ -319,6 +319,16 @@ public:
return fontWeight_;
}
void SetFontStyle(const FontStyle& fontStyle)
{
fontStyle_ = fontStyle;
}
const std::optional<FontStyle>& GetFontStyle() const
{
return fontStyle_;
}
private:
bool isShow_ = true;
bool hasAction_ = false;
@ -345,6 +355,7 @@ private:
std::optional<FontWeight> fontWeight_;
std::optional<Color> textColor_;
std::optional<Dimension> fontSize_;
std::optional<FontStyle> fontStyle_;
// Used in NG mode
StateChangeFunc onStateChange_;

View File

@ -378,7 +378,7 @@ void SubContainer::ProcessSharedImage(const std::map<std::string, sptr<AppExecFw
if (!imageDataMap.empty()) {
for (auto& imageData : imageDataMap) {
if (!imageData.second) {
LOGE("the point of FormAshmem about %{private}s is null, continue", imageData.first.c_str());
LOGI("the point of FormAshmem about %{private}s is null, continue", imageData.first.c_str());
continue;
}
picNameArray.push_back(imageData.first);

View File

@ -64,7 +64,7 @@ public:
return Axis::NONE;
}
virtual bool AnimateTo(const Dimension& position, float duration, const RefPtr<Curve>& curve)
virtual bool AnimateTo(const Dimension& position, float duration, const RefPtr<Curve>& curve, bool smooth)
{
return true;
}

View File

@ -84,7 +84,8 @@ bool ScrollPositionController::AnimateTo(double position, float duration, const
return false;
}
bool ScrollPositionController::AnimateTo(const Dimension& position, float duration, const RefPtr<Curve>& curve)
bool ScrollPositionController::AnimateTo(
const Dimension& position, float duration, const RefPtr<Curve>& curve, bool smooth)
{
RefPtr<RenderNode> node = scroll_.Upgrade();
if (node) {

View File

@ -111,7 +111,7 @@ public:
void JumpTo(int32_t index, int32_t source) override;
void JumpTo(double position);
bool AnimateTo(const Dimension& position, float duration, const RefPtr<Curve>& curve) override;
bool AnimateTo(const Dimension& position, float duration, const RefPtr<Curve>& curve, bool smooth) override;
bool AnimateTo(double position, float duration, const RefPtr<Curve>& curve, bool limitDuration = true,
const std::function<void()>& onFinish = nullptr);
bool AnimateToTarget(const ComposeId& targetId, float duration, const RefPtr<Curve>& curve,

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2021 Huawei Device Co., Ltd.
* Copyright (c) 2021-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
@ -15,7 +15,9 @@
#include "core/components/search/rosen_render_search.h"
#ifndef USE_ROSEN_DRAWING
#include "include/core/SkRRect.h"
#endif
#include "core/pipeline/base/rosen_render_context.h"
@ -41,6 +43,7 @@ void RosenRenderSearch::Paint(RenderContext& context, const Offset& offset)
// Paint divider.
if (renderSearchBox_) {
#ifndef USE_ROSEN_DRAWING
SkCanvas* canvas = GetSkCanvas(context);
SkPaint paint;
if (canvas != nullptr) {
@ -56,6 +59,25 @@ void RosenRenderSearch::Paint(RenderContext& context, const Offset& offset)
paint.setColor(SEARCH_DIVIDER_COLOR.GetValue());
canvas->drawRect(SkRect::MakeXYWH(rect.Left(), rect.Top(), rect.Width(), rect.Height()), paint);
canvas->restore();
#else
RSCanvas* canvas = GetDrawingCanvas(context);
RSPen pen;
if (canvas != nullptr) {
double dividerVerticalOffset = (GetLayoutSize().Height() - NormalizeToPx(ICON_HEIGHT)) / 2.0;
Offset dividerOffset = Offset(searchTextRect_.GetOffset().GetX(), dividerVerticalOffset);
if (needReverse_) {
dividerOffset = searchTextRect_.GetOffset() +
Offset(searchTextRect_.Width() - SEARCH_DIVIDER_WIDTH, dividerVerticalOffset);
}
dividerOffset += offset;
Rect rect(dividerOffset, Size(SEARCH_DIVIDER_WIDTH, NormalizeToPx(ICON_HEIGHT)));
canvas->Save();
pen.SetColor(SEARCH_DIVIDER_COLOR.GetValue());
canvas->AttachPen(pen);
canvas->DrawRect(RSRect(rect.Left(), rect.Top(), rect.Width() + rect.Left(), rect.Height() + rect.Top()));
canvas->DetachPen();
canvas->Restore();
#endif
}
// Paint search text.
@ -118,6 +140,7 @@ void RosenRenderSearch::PaintOverlayForHoverAndPress(RenderContext& context, con
return;
}
#ifndef USE_ROSEN_DRAWING
SkCanvas* canvas = GetSkCanvas(context);
if (canvas == nullptr) {
LOGE("canvas is null!");
@ -127,6 +150,17 @@ void RosenRenderSearch::PaintOverlayForHoverAndPress(RenderContext& context, con
SkPaint paint;
// Background overlay 10% opacity black when hover.
paint.setColor(overlayColor_.GetValue());
#else
RSCanvas* canvas = GetDrawingCanvas(context);
if (canvas == nullptr) {
LOGE("canvas is null!");
return;
}
canvas->Save();
RSPen pen;
// Background overlay 10% opacity black when hover.
pen.SetColor(overlayColor_.GetValue());
#endif
Offset rectOffset;
Size rectSize;
@ -141,10 +175,18 @@ void RosenRenderSearch::PaintOverlayForHoverAndPress(RenderContext& context, con
Border border;
border.SetBorderRadius(Radius(rectSize.Height() / 2.0));
#ifndef USE_ROSEN_DRAWING
canvas->drawRRect(MakeRRect(rectOffset + offset, rectSize, border), paint);
canvas->restore();
#else
canvas->AttachPen(pen);
canvas->DrawRoundRect(MakeRRect(rectOffset + offset, rectSize, border));
canvas->DetachPen();
canvas->Restore();
#endif
}
#ifndef USE_ROSEN_DRAWING
SkRRect RosenRenderSearch::MakeRRect(const Offset& offset, const Size& size, const Border& border)
{
SkRect rect = SkRect::MakeXYWH(offset.GetX(), offset.GetY(), size.Width(), size.Height());
@ -161,8 +203,32 @@ SkRRect RosenRenderSearch::MakeRRect(const Offset& offset, const Size& size, con
rrect.setRectRadii(rect, rectRadii);
return rrect;
}
#else
RSRoundRect RosenRenderSearch::MakeRRect(const Offset& offset, const Size& size, const Border& border)
{
RSRect rect(
offset.GetX(), offset.GetY(), offset.GetX() + size.Width(), offset.GetY() + size.Height());
std::vector<RSPoint> rectRadii(4);
rectRadii.at(RSRoundRect::CornerPos::TOP_LEFT_POS) = RSPoint(
NormalizeToPx(border.TopLeftRadius().GetX()), NormalizeToPx(border.TopLeftRadius().GetY()));
rectRadii.at(RSRoundRect::CornerPos::TOP_RIGHT_POS) = RSPoint(
NormalizeToPx(border.TopRightRadius().GetX()), NormalizeToPx(border.TopRightRadius().GetY()));
rectRadii.at(RSRoundRect::CornerPos::BOTTOM_RIGHT_POS) = RSPoint(
NormalizeToPx(border.BottomRightRadius().GetX()), NormalizeToPx(border.BottomRightRadius().GetY()));
rectRadii.at(RSRoundRect::CornerPos::BOTTOM_LEFT_POS) = RSPoint(
NormalizeToPx(border.BottomLeftRadius().GetX()), NormalizeToPx(border.BottomLeftRadius().GetY()));
RSRoundRect rrect(rect, rectRadii);
return rrect;
}
#endif
#ifndef USE_ROSEN_DRAWING
SkCanvas* RosenRenderSearch::GetSkCanvas(RenderContext& context)
#else
RSCanvas* RosenRenderSearch::GetDrawingCanvas(RenderContext& context)
#endif
{
auto renderContext = AceType::DynamicCast<RosenRenderContext>(&context);
if (!renderContext) {
@ -176,4 +242,4 @@ SkCanvas* RosenRenderSearch::GetSkCanvas(RenderContext& context)
return canvas;
}
} // namespace OHOS::Ace
} // namespace OHOS::Ace

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2021 Huawei Device Co., Ltd.
* Copyright (c) 2021-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
@ -16,7 +16,9 @@
#ifndef FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_SEARCH_ROSEN_RENDER_SEARCH_H
#define FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_SEARCH_ROSEN_RENDER_SEARCH_H
#ifndef USE_ROSEN_DRAWING
#include "include/core/SkCanvas.h"
#endif
#include "core/components/search/render_search.h"
#include "core/pipeline/base/rosen_render_context.h"
@ -32,8 +34,13 @@ public:
private:
void PaintFocus();
void PaintOverlayForHoverAndPress(RenderContext& context, const Offset& offset);
#ifndef USE_ROSEN_DRAWING
SkRRect MakeRRect(const Offset& offset, const Size& size, const Border& border);
SkCanvas* GetSkCanvas(RenderContext& context);
#else
RSRoundRect MakeRRect(const Offset& offset, const Size& size, const Border& border);
RSCanvas* GetDrawingCanvas(RenderContext& context);
#endif
};
} // namespace OHOS::Ace

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2021-2022 Huawei Device Co., Ltd.
* Copyright (c) 2021-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
@ -15,10 +15,12 @@
#include "core/components/shadow/rosen_render_shadow.h"
#ifndef USE_ROSEN_DRAWING
#include "include/core/SkCanvas.h"
#include "include/core/SkColor.h"
#include "include/core/SkMaskFilter.h"
#include "include/core/SkRRect.h"
#endif
#include "core/pipeline/base/rosen_render_context.h"
@ -44,15 +46,25 @@ void RosenRenderShadow::Paint(RenderContext& context, const Offset& offset)
}
if (isNeedClip_) {
#ifndef USE_ROSEN_DRAWING
canvas->clipRect(SkRect::MakeXYWH(clipRect_.GetOffset().GetX() - NormalizeToPx(SHADOW_OFFSET) / 2,
clipRect_.GetOffset().GetY(), clipRect_.Width() + NormalizeToPx(SHADOW_OFFSET),
clipRect_.Height() + NormalizeToPx(SHADOW_OFFSET)),
true);
#else
canvas->ClipRect(
RSRect(clipRect_.GetOffset().GetX() - NormalizeToPx(SHADOW_OFFSET) / 2,
clipRect_.GetOffset().GetY(),
clipRect_.Width() - NormalizeToPx(SHADOW_OFFSET) / 2 + clipRect_.GetOffset().GetX(),
clipRect_.Height() + NormalizeToPx(SHADOW_OFFSET) + clipRect_.GetOffset().GetY(),),
true);
#endif
}
double radiusX = NormalizeToPx(rrect_.GetCorner().bottomLeftRadius.GetX());
double radiusY = NormalizeToPx(rrect_.GetCorner().bottomLeftRadius.GetY());
#ifndef USE_ROSEN_DRAWING
SkPaint paint;
paint.setColor(SkColorSetARGB(SHADOW_COLOR_ALPHA, 0, 0, 0));
paint.setStyle(SkPaint::Style::kStrokeAndFill_Style);
@ -62,6 +74,27 @@ void RosenRenderShadow::Paint(RenderContext& context, const Offset& offset)
rect = SkRect::MakeXYWH(
offset_.GetX(), offset_.GetY() + NormalizeToPx(SHADOW_OFFSET), rrect_.Width(), rrect_.Height());
canvas->drawRRect(SkRRect::MakeRectXY(rect, radiusX, radiusY), paint);
#else
RSPen pen;
RSBrush brush;
pen.SetColor(RSColor::ColorQuadSetARGB(SHADOW_COLOR_ALPHA, 0, 0, 0));
brush.SetColor(RSColor::ColorQuadSetARGB(SHADOW_COLOR_ALPHA, 0, 0, 0));
RSFilter filter;
filter.SetMaskFilter(
RSMaskFilter::CreateBlurMaskFilter(RSBlurType::NORMAL, SHADOW_BLUR_RADIUS));
pen.SetFilter(filter);
brush.SetFilter(filter);
RSRect rect(
offset_.GetX(), offset_.GetY(), offset_.GetX() + rrect_.Width(), offset_.GetY() + rrect_.Height());
canvas->ClipRoundRect(RSRoundRect(rect, radiusX, radiusY), RSClipOp::DIFFERENCE, true);
rect = RSRect(offset_.GetX(), offset_.GetY() + NormalizeToPx(SHADOW_OFFSET),
rrect_.Width() + offset_.GetX(), rrect_.Height() + offset_.GetY() + NormalizeToPx(SHADOW_OFFSET));
canvas->AttachPen(pen);
canvas->AttachBrush(brush);
canvas->DrawRoundRect(RSRoundRect(rect, radiusX, radiusY));
canvas->DetachPen();
canvas->DetachBrush();
#endif
}
} // namespace OHOS::Ace

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2021-2022 Huawei Device Co., Ltd.
* Copyright (c) 2021-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
@ -15,9 +15,11 @@
#include "core/components/shape/rosen_render_shape.h"
#ifndef USE_ROSEN_DRAWING
#include "include/core/SkPaint.h"
#include "include/effects/SkDashPathEffect.h"
#include "include/utils/SkParsePath.h"
#endif
#include "core/pipeline/base/rosen_render_context.h"
#include "frameworks/core/components/common/painter/rosen_svg_painter.h"
@ -34,9 +36,15 @@ Size RosenRenderShape::CalcSize()
case ShapeType::ELLIPSE:
return CreateEllipse();
case ShapeType::LINE:
#ifndef USE_ROSEN_DRAWING
path_.reset();
path_.moveTo(NormalizePercentToPx(start_.first, false), NormalizePercentToPx(start_.second, true));
path_.lineTo(NormalizePercentToPx(end_.first, false), NormalizePercentToPx(end_.second, true));
#else
path_.Reset();
path_.MoveTo(NormalizePercentToPx(start_.first, false), NormalizePercentToPx(start_.second, true));
path_.LineTo(NormalizePercentToPx(end_.first, false), NormalizePercentToPx(end_.second, true));
#endif
break;
case ShapeType::POLYLINE:
return CreatePolygon(false);
@ -48,11 +56,19 @@ Size RosenRenderShape::CalcSize()
LOGE("invalid shapeType");
return Size();
}
#ifndef USE_ROSEN_DRAWING
auto skRect = path_.getBounds();
if (width_.IsValid() && height_.IsValid()) {
return Size(NormalizePercentToPx(width_, false), NormalizePercentToPx(height_, true));
}
return Size(skRect.right(), skRect.bottom());
#else
auto rect = path_.GetBounds();
if (width_.IsValid() && height_.IsValid()) {
return Size(NormalizePercentToPx(width_, false), NormalizePercentToPx(height_, true));
}
return Size(rect.GetRight(), rect.GetBottom());
#endif
}
Size RosenRenderShape::CreateRect()
@ -60,8 +76,13 @@ Size RosenRenderShape::CreateRect()
if (!GetLayoutParam().GetMaxSize().IsValid()) {
return Size();
}
#ifndef USE_ROSEN_DRAWING
SkRect rect =
SkRect::MakeLTRB(0.0f, 0.0f, NormalizePercentToPx(width_, false), NormalizePercentToPx(height_, true));
#else
RSRect rect =
RSRect(0.0f, 0.0f, NormalizePercentToPx(width_, false), NormalizePercentToPx(height_, true));
#endif
float topLeftRadiusX = GetFloatRadiusValue(topLeftRadius_.GetX(), topLeftRadius_.GetY(), false);
float topLeftRadiusY = GetFloatRadiusValue(topLeftRadius_.GetY(), topLeftRadius_.GetX(), true);
float topRightRadiusX = GetFloatRadiusValue(topRightRadius_.GetX(), topRightRadius_.GetY(), false);
@ -70,6 +91,7 @@ Size RosenRenderShape::CreateRect()
float bottomRightRadiusY = GetFloatRadiusValue(bottomRightRadius_.GetY(), bottomRightRadius_.GetX(), true);
float bottomLeftRadiusX = GetFloatRadiusValue(bottomLeftRadius_.GetX(), bottomLeftRadius_.GetY(), false);
float bottomLeftRadiusY = GetFloatRadiusValue(bottomLeftRadius_.GetY(), bottomLeftRadius_.GetX(), true);
#ifndef USE_ROSEN_DRAWING
const SkVector fRadii[4] = { { topLeftRadiusX, topLeftRadiusY }, { topRightRadiusX, topRightRadiusY },
{ bottomRightRadiusX, bottomRightRadiusY }, { bottomLeftRadiusX, bottomLeftRadiusY } };
path_.reset();
@ -78,6 +100,16 @@ Size RosenRenderShape::CreateRect()
path_.addRRect(roundRect);
auto skRect = path_.getBounds();
return Size(skRect.right(), skRect.bottom());
#else
std::vector<RSPoint> fRadii = { { topLeftRadiusX, topLeftRadiusY }, { topRightRadiusX, topRightRadiusY },
{ bottomRightRadiusX, bottomRightRadiusY }, { bottomLeftRadiusX, bottomLeftRadiusY } };
path_.Reset();
RSRoundRect roundRect;
roundRect.SetRectRadii(rect, fRadii);
path_.AddRoundRect(roundRect);
auto drRect = path_.GetBounds();
return Size(drRect.GetRight(), drRect.GetBottom());
#endif
}
float RosenRenderShape::GetFloatRadiusValue(const Dimension& src, const Dimension& dest, bool isVertical)
@ -93,10 +125,18 @@ Size RosenRenderShape::CreateCircle()
if (!GetLayoutParam().GetMaxSize().IsValid()) {
return Size();
}
#ifndef USE_ROSEN_DRAWING
path_.reset();
#else
path_.Reset();
#endif
double width = NormalizePercentToPx(width_, false);
double height = NormalizePercentToPx(height_, true);
#ifndef USE_ROSEN_DRAWING
path_.addCircle(width * 0.5, height * 0.5, std::min(width, height) * 0.5);
#else
path_.AddCircle(width * 0.5, height * 0.5, std::min(width, height) * 0.5);
#endif
return Size(width, height);
}
@ -105,16 +145,25 @@ Size RosenRenderShape::CreateEllipse()
if (!GetLayoutParam().GetMaxSize().IsValid()) {
return Size();
}
#ifndef USE_ROSEN_DRAWING
path_.reset();
auto width = NormalizePercentToPx(width_, false);
auto height = NormalizePercentToPx(height_, true);
SkRect rect = SkRect::MakeXYWH(0.0f, 0.0f, width, height);
path_.addOval(rect);
#else
path_.Reset();
auto width = NormalizePercentToPx(width_, false);
auto height = NormalizePercentToPx(height_, true);
auto rect = RSRect(0.0f, 0.0f, width, height);
path_.AddOval(rect);
#endif
return Size(width, height);
}
Size RosenRenderShape::CreatePolygon(bool needClose)
{
#ifndef USE_ROSEN_DRAWING
path_.reset();
std::vector<SkPoint> skPoints;
for (auto point : points_) {
@ -130,6 +179,23 @@ Size RosenRenderShape::CreatePolygon(bool needClose)
return Size(NormalizePercentToPx(width_, false), NormalizePercentToPx(height_, true));
}
return Size(skRect.right(), skRect.bottom());
#else
path_.Reset();
std::vector<RSPoint> points;
for (auto point : points_) {
points.emplace_back(
RSPoint(NormalizePercentToPx(point.first, false), NormalizePercentToPx(point.second, true)));
}
if (points.empty()) {
return Size();
}
path_.AddPoly(points, points.size(), needClose);
auto rect = path_.GetBounds();
if (width_.IsValid() && height_.IsValid()) {
return Size(NormalizePercentToPx(width_, false), NormalizePercentToPx(height_, true));
}
return Size(rect.GetRight(), rect.GetBottom());
#endif
}
Size RosenRenderShape::CreatePath()
@ -137,8 +203,13 @@ Size RosenRenderShape::CreatePath()
if (pathCmd_.GetValue().empty()) {
return Size();
}
#ifndef USE_ROSEN_DRAWING
path_.reset();
bool ret = SkParsePath::FromSVGString(pathCmd_.GetValue().c_str(), &path_);
#else
path_.Reset();
bool ret = path_.BuildFromSVGString(pathCmd_.GetValue());
#endif
if (width_.IsValid() && height_.IsValid()) {
return Size(NormalizePercentToPx(width_, false), NormalizePercentToPx(height_, true));
}
@ -146,6 +217,7 @@ Size RosenRenderShape::CreatePath()
LOGW("path value is invalid");
return Size();
}
#ifndef USE_ROSEN_DRAWING
auto skRect = path_.getBounds();
auto right = skRect.right();
auto bottom = skRect.bottom();
@ -160,6 +232,22 @@ Size RosenRenderShape::CreatePath()
bottom = lineWidth.ConvertToPx();
}
return Size(right, bottom);
#else
auto rect = path_.GetBounds();
auto right = rect.GetRight();
auto bottom = rect.GetBottom();
if (NearZero(right) && NearZero(bottom)) {
return Size();
}
auto lineWidth = strokeState_.GetLineWidth();
if (NearZero(right)) {
right = lineWidth.ConvertToPx();
}
if (NearZero(bottom)) {
bottom = lineWidth.ConvertToPx();
}
return Size(right, bottom);
#endif
}
void RosenRenderShape::Paint(RenderContext& context, const Offset& offset)
@ -173,6 +261,7 @@ void RosenRenderShape::Paint(RenderContext& context, const Offset& offset)
PaintOnCanvas(canvas, offset);
}
#ifndef USE_ROSEN_DRAWING
void RosenRenderShape::PaintOnCanvas(SkCanvas* skCanvas, const Offset& offset)
{
SkPath path = path_;
@ -180,7 +269,17 @@ void RosenRenderShape::PaintOnCanvas(SkCanvas* skCanvas, const Offset& offset)
RosenSvgPainter::SetFillStyle(skCanvas, path, fillState_, UINT8_MAX, antiAlias_.second);
DrawStroke(skCanvas, path);
}
#else
void RosenRenderShape::PaintOnCanvas(RSCanvas* canvas, const Offset& offset)
{
RSPath path = path_;
path_.Offset(offset.GetX(), offset.GetY());
RosenSvgPainter::SetFillStyle(canvas, path, fillState_, UINT8_MAX, antiAlias_.second);
DrawStroke(canvas, path);
}
#endif
#ifndef USE_ROSEN_DRAWING
void RosenRenderShape::DrawStroke(SkCanvas* skCanvas, const SkPath& path)
{
if (strokeState_.GetColor() != Color::TRANSPARENT && GreatNotEqual(strokeState_.GetLineWidth().Value(), 0.0)) {
@ -199,5 +298,27 @@ void RosenRenderShape::DrawStroke(SkCanvas* skCanvas, const SkPath& path)
skCanvas->drawPath(path, strokePaint);
}
}
#else
void RosenRenderShape::DrawStroke(RSCanvas* canvas, const RSPath& path)
{
if (strokeState_.GetColor() != Color::TRANSPARENT && GreatNotEqual(strokeState_.GetLineWidth().Value(), 0.0)) {
RSPen strokePen;
RosenSvgPainter::SetStrokeStyle(strokePen, strokeState_, UINT8_MAX, antiAlias_.second);
strokePen.SetWidth(NormalizePercentToPx(strokeState_.GetLineWidth(), false));
if (!strokeState_.GetStrokeDashArray().empty()) {
auto lineDashState = strokeState_.GetStrokeDashArray();
RSscalar intervals[lineDashState.size()];
for (size_t i = 0; i < lineDashState.size(); ++i) {
intervals[i] = DoubleToScalar(NormalizePercentToPx(lineDashState[i], false));
}
RSscalar phase = DoubleToScalar(NormalizePercentToPx(strokeState_.GetStrokeDashOffset(), false));
strokePen.SetPathEffect(RSPathEffect::CreateDashPathEffect(intervals, lineDashState.size(), phase));
}
canvas->AttachPen(strokePen);
canvas->DrawPath(path);
canvas->DetachPen();
}
}
#endif
} // namespace OHOS::Ace
} // namespace OHOS::Ace

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2021-2022 Huawei Device Co., Ltd.
* Copyright (c) 2021-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
@ -16,8 +16,10 @@
#ifndef FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_SHAPE_ROSEN_RENDER_SHAPE_H
#define FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_SHAPE_ROSEN_RENDER_SHAPE_H
#ifndef USE_ROSEN_DRAWING
#include "include/core/SkCanvas.h"
#include "include/core/SkPath.h"
#endif
#include "core/components/shape/render_shape.h"
@ -29,7 +31,11 @@ class RosenRenderShape : public RenderShape {
public:
void Paint(RenderContext& context, const Offset& offset) override;
Size CalcSize() override;
#ifndef USE_ROSEN_DRAWING
void PaintOnCanvas(SkCanvas* skCanvas, const Offset& offset);
#else
void PaintOnCanvas(Rosen::RSCanvas* canvas, const Offset& offset);
#endif
private:
Size CreateRect();
@ -37,10 +43,18 @@ private:
Size CreateEllipse();
Size CreatePolygon(bool needClose);
Size CreatePath();
#ifndef USE_ROSEN_DRAWING
void DrawStroke(SkCanvas* skCanvas, const SkPath& path);
#else
void DrawStroke(Rosen::RSCanvas* canvas, const Rosen::RSPath& path);
#endif
float GetFloatRadiusValue(const Dimension& src, const Dimension& dest, bool isVertical);
#ifndef USE_ROSEN_DRAWING
SkPath path_;
#else
Rosen::RSRecordingPath path_;
#endif
};
} // namespace OHOS::Ace

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2021-2022 Huawei Device Co., Ltd.
* Copyright (c) 2021-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
@ -497,7 +497,11 @@ void RenderSideBarContainer::UpdateRenderImage()
imageComponent->SetSrc(sideBar_->GetSwitchIcon());
}
}
#ifndef USE_ROSEN_DRAWING
imageComponent->SetUseSkiaSvg(false);
#else
imageComponent->SetUseDrawingSvg(false);
#endif
imageComponent->SetImageFit(ImageFit::FILL);
renderImage->Update(imageComponent);
}

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2022 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
@ -15,7 +15,9 @@
#include "core/components/side_bar/rosen_render_side_bar_container.h"
#ifndef USE_ROSEN_DRAWING
#include "include/core/SkPath.h"
#endif
#include "render_service_client/core/ui/rs_node.h"
#include "core/pipeline/base/rosen_render_context.h"
@ -31,9 +33,16 @@ void RosenRenderSideBarContainer::Paint(RenderContext& context, const Offset& of
rsNode->SetClipToBounds(true);
auto paintRect = GetPaintRect();
#ifndef USE_ROSEN_DRAWING
SkPath skPath;
skPath.addRect(SkRect::MakeXYWH(paintRect.Left(), paintRect.Top(), paintRect.Width(), paintRect.Height()));
rsNode->SetClipBounds(Rosen::RSPath::CreateRSPath(skPath));
#else
RSRecordingPath dPath;
dPath.AddRect(RSRect(paintRect.GetLeft(), paintRect.GetTop(),
paintRect.GetWidth() + paintRect.GetLeft(), paintRect.GetHeight()));
rsNode->SetClipBounds(Rosen::RSPath::CreateRSPath(dPath));
#endif
RenderNode::Paint(context, offset);
}

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2021-2022 Huawei Device Co., Ltd.
* Copyright (c) 2021-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
@ -61,7 +61,11 @@ RefPtr<Component> SideBarContainerComponent::BuildButton()
imageComponent->SetSrc(GetHiddenIcon());
}
}
#ifndef USE_ROSEN_DRAWING
imageComponent->SetUseSkiaSvg(false);
#else
imageComponent->SetUseDrawingSvg(false);
#endif
imageComponent->SetImageFit(ImageFit::FILL);
return imageComponent;
}

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2021-2022 Huawei Device Co., Ltd.
* Copyright (c) 2021-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
@ -15,9 +15,11 @@
#include "core/components/slider/rosen_render_circle_block.h"
#ifndef USE_ROSEN_DRAWING
#include "include/core/SkMaskFilter.h"
#include "include/core/SkPath.h"
#include "include/core/SkRRect.h"
#endif
#include "base/utils/system_properties.h"
#include "core/components/common/painter/rosen_decoration_painter.h"
@ -57,6 +59,7 @@ void RosenRenderCircleBlock::SyncGeometryProperties()
double radius = NormalizeToPx(blockSize_) * HALF * radiusScale_;
double diameter = radius * 2.0;
auto frame = rsNode->GetStagingProperties().GetFrame();
#ifndef USE_ROSEN_DRAWING
SkRect rect = SkRect::MakeXYWH(frame.x_ - radius, frame.y_ - radius, diameter, diameter);
float elevationOfDefaultShadowXS = 4.0f;
@ -88,6 +91,50 @@ void RosenRenderCircleBlock::SyncGeometryProperties()
offsetX = shadowRect.width() * HALF;
offsetY = shadowRect.height() * HALF;
}
#else
RSRect rect =
RSRect(frame.x_ - radius, frame.y_ - radius,
diameter + frame.x_ - radius, diameter + frame.y_ - radius);
float elevationOfDefaultShadowXS = 4.0f;
float transRatio = elevationOfDefaultShadowXS / (LIGHT_HEIGHT - elevationOfDefaultShadowXS);
float spotRatio = LIGHT_HEIGHT / (LIGHT_HEIGHT - elevationOfDefaultShadowXS);
auto spotRect = RSRect(rect.GetLeft() * spotRatio, rect.GetTop() * spotRatio,
rect.GetRight() * spotRatio, rect.GetBottom() * spotRatio);
spotRect.Offset(-transRatio * LIGHT_POSITION_X, -transRatio * LIGHT_POSITION_Y);
spotRect.SetLeft(spotRect.GetLeft() - transRatio * LIGHT_RADIUS);
spotRect.SetTop(spotRect.GetTop() - transRatio * LIGHT_RADIUS);
spotRect.SetRight(spotRect.GetRight() + transRatio * LIGHT_RADIUS);
spotRect.SetBottom(shadspotRectowRect.GetBottom() + transRatio * LIGHT_RADIUS);
RSRect shadowRect(rect);
float ambientBlur = 2.0f;
shadowRect.SetLeft(shadowRect.GetLeft() - ambientBlur);
shadowRect.SetTop(shadowRect.GetTop() - ambientBlur);
shadowRect.SetRight(shadowRect.GetRight() + ambientBlur);
shadowRect.SetBottom(shadowRect.GetBottom() + ambientBlur);
shadowRect.Join(spotRect);
shadowRect.SetLeft(shadowRect.GetLeft() - 1);
shadowRect.SetTop(shadowRect.GetTop() - 1);
shadowRect.SetRight(shadowRect.GetRight() + 1);
shadowRect.SetBottom(shadowRect.GetBottom() + 1);
float offsetX = 0.0f;
float offsetY = 0.0f;
if (isHover_) {
double hoverRadius = NormalizeToPx(HOVER_RADIUS);
offsetX = hoverRadius > shadowRect.GetWidth() * HALF ? hoverRadius : shadowRect.GetWidth() * HALF;
offsetY = hoverRadius > shadowRect.GetHeight() * HALF ? hoverRadius : shadowRect.GetHeight() * HALF;
} else if (isPress_) {
double pressRadius = NormalizeToPx(PRESS_RADIUS);
offsetX = pressRadius > shadowRect.GetWidth() * HALF ? pressRadius : shadowRect.GetWidth() * HALF;
offsetY = pressRadius > shadowRect.GetHeight() * HALF ? pressRadius : shadowRect.GetHeight() * HALF;
} else {
offsetX = shadowRect.GetWidth() * HALF;
offsetY = shadowRect.GetHeight() * HALF;
}
#endif
rsNode->SetFrame(frame.x_ - offsetX, frame.y_ - offsetY, frame.z_ + offsetX, frame.w_ + offsetY);
}
@ -101,6 +148,7 @@ void RosenRenderCircleBlock::Paint(RenderContext& context, const Offset& offset)
return;
}
#ifndef USE_ROSEN_DRAWING
if (isHover_) {
SkPaint hoverPaint;
hoverPaint.setColor(HOVER_BORDER_COLOR);
@ -114,11 +162,31 @@ void RosenRenderCircleBlock::Paint(RenderContext& context, const Offset& offset)
double pressRadius = NormalizeToPx(PRESS_RADIUS);
canvas->drawCircle(offset.GetX(), offset.GetY(), pressRadius, pressPaint);
}
#else
if (isHover_) {
RSPen hoverPen;
hoverPen.SetColor(HOVER_BORDER_COLOR);
double hoverRadius = NormalizeToPx(HOVER_RADIUS);
canvas->AttachPen(hoverPen);
canvas->DrawCircle(RSPoint(offset.GetX(), offset.GetY()), hoverRadius);
canvas->DetachPen();
}
if (isPress_) {
RSPen pressPen;
pressPen.SetColor(PRESS_BORDER_COLOR);
double pressRadius = NormalizeToPx(PRESS_RADIUS);
canvas->AttachPen(pressPen);
canvas->DrawCircle(RSPoint(offset.GetX(), offset.GetY()), pressRadius);
canvas->DetachPen();
}
#endif
double radius = NormalizeToPx(blockSize_) * HALF * radiusScale_;
PaintShadow(context, offset, radius);
#ifndef USE_ROSEN_DRAWING
if (GetFocus() && GetMode() == SliderMode::OUTSET) {
SkPaint focusPaint;
focusPaint.setColor(FOCUS_BORDER_COLOR);
@ -148,14 +216,61 @@ void RosenRenderCircleBlock::Paint(RenderContext& context, const Offset& offset)
borderPaint.setAntiAlias(true);
borderPaint.setStrokeWidth(BORDER_WEIGHT);
canvas->drawCircle(offset.GetX(), offset.GetY(), radius, borderPaint);
#else
if (GetFocus() && GetMode() == SliderMode::OUTSET) {
RSPen focusPen;
focusPen.SetColor(FOCUS_BORDER_COLOR);
focusPen.SetWidth(NormalizeToPx(FOCUS_BORDER_PADDING));
focusPen.SetAntiAlias(true);
canvas->AttachPen(focusPen);
canvas->DrawCircle(RSPoint(offset.GetX(), offset.GetY()), radius + RADIUS_PADDING);
canvas->DetachPen();
RSPen blockPen;
blockPen.SetColor(RSColor::ColorQuadSetARGB(GetBlockColor().GetAlpha(),
GetBlockColor().GetRed(), GetBlockColor().GetGreen(), GetBlockColor().GetBlue()));
blockPen.SetAntiAlias(true);
canvas->AttachPen(blockPen);
canvas->DrawCircle(RSPoint(offset.GetX(), offset.GetY()), radius);
canvas->DetachPen();
} else {
RSPen blockPen;
blockPen.SetColor(RSColor::ColorQuadSetARGB(GetBlockColor().GetAlpha(),
GetBlockColor().GetRed(), GetBlockColor().GetGreen(), GetBlockColor().GetBlue()));
blockPen.SetAntiAlias(true);
canvas->AttachPen(blockPen);
canvas->DrawCircle(RSPoint(offset.GetX(), offset.GetY()), radius);
canvas->DetachPen();
}
// Draw block border
RSPen blockPen;
// use this color to reduce the loss at corner.
static const uint8_t alpha = 13;
blockPen.SetColor(RSColor::ColorQuadSetARGB(alpha, 0, 0, 0));
blockPen.SetAntiAlias(true);
blockPen.SetWidth(BORDER_WEIGHT);
canvas->AttachPen(blockPen);
canvas->DrawCircle(RSPoint(offset.GetX(), offset.GetY()), radius);
canvas->DetachPen();
#endif
}
void RosenRenderCircleBlock::PaintShadow(RenderContext& context, const Offset& offset, double radius)
{
double diameter = radius * 2.0;
#ifndef USE_ROSEN_DRAWING
SkRect rect = SkRect::MakeXYWH(offset.GetX() - radius, offset.GetY() - radius, diameter, diameter);
RosenDecorationPainter::PaintShadow(SkPath().addRRect(SkRRect::MakeRectXY(rect, radius, radius)),
ShadowConfig::DefaultShadowXS, static_cast<RosenRenderContext*>(&context)->GetCanvas());
#else
RSRect rect =
RSRect(offset.GetX() - radius, offset.GetY() - radius,
diameter + offset.GetX() - radius, diameter + offset.GetY() - radius);
RSRecordingPath path;
path.AddRoundRect(rect, radius, radius);
RosenDecorationPainter::PaintShadow(
path, ShadowConfig::DefaultShadowXS, static_cast<RosenRenderContext*>(&context)->GetCanvas());
#endif
}
} // namespace OHOS::Ace
} // namespace OHOS::Ace

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2021-2022 Huawei Device Co., Ltd.
* Copyright (c) 2021-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
@ -16,7 +16,9 @@
#ifndef FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_SLIDER_ROSEN_RENDER_CIRCLE_BLOCK_H
#define FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_SLIDER_ROSEN_RENDER_CIRCLE_BLOCK_H
#ifndef USE_ROSEN_DRAWING
#include "include/core/SkCanvas.h"
#endif
#include "core/components/slider/render_block.h"

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2021-2022 Huawei Device Co., Ltd.
* Copyright (c) 2021-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
@ -356,6 +356,7 @@ void RosenRenderSlider::PaintTrackFocus(RenderContext& context, const Offset& of
trackFocusHeight = track->GetTrackThickness() + NormalizeToPx(FOCUS_PADDING * 2 + FOCUS_BORDER_WIDTH);
trackFocusRadius = trackFocusHeight * HALF;
}
#ifndef USE_ROSEN_DRAWING
SkPaint paint;
paint.setColor(FOCUS_BORDER_COLOR);
paint.setStrokeWidth(NormalizeToPx(FOCUS_BORDER_WIDTH));
@ -371,6 +372,26 @@ void RosenRenderSlider::PaintTrackFocus(RenderContext& context, const Offset& of
track->GetTrackThickness() * HALF - NormalizeToPx(FOCUS_PADDING + FOCUS_BORDER_WIDTH * HALF));
}
canvas->drawRRect(rRect, paint);
#else
RSPen pen;
pen.SetColor(FOCUS_BORDER_COLOR);
pen.SetWidth(NormalizeToPx(FOCUS_BORDER_WIDTH));
pen.SetAntiAlias(true);
RSRoundRect rRect(
RSRect(0, 0, trackFocusWidth, trackFocusHeight), trackFocusRadius, trackFocusRadius);
if (direction_ == Axis::VERTICAL) {
rRect.Offset(offset.GetX() + track->GetTrackThickness() * HALF -
NormalizeToPx(FOCUS_PADDING + FOCUS_BORDER_WIDTH * HALF),
offset.GetY() + NormalizeToPx(FOCUS_BORDER_WIDTH * HALF * HALF));
} else {
rRect.Offset(offset.GetX() + NormalizeToPx(FOCUS_BORDER_WIDTH * HALF * HALF),
offset.GetY() + track->GetTrackThickness() * HALF -
NormalizeToPx(FOCUS_PADDING + FOCUS_BORDER_WIDTH * HALF));
}
canvas->AttachPen(pen);
canvas->DrawRoundRect(rRect);
canvas->DetachPen();
#endif
}
} // namespace OHOS::Ace

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2021 Huawei Device Co., Ltd.
* Copyright (c) 2021-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
@ -15,7 +15,9 @@
#include "core/components/split_container/rosen_render_column_split.h"
#ifndef USE_ROSEN_DRAWING
#include "include/core/SkPaint.h"
#endif
#include "core/pipeline/base/constants.h"
#include "core/pipeline/base/rosen_render_context.h"
@ -57,6 +59,7 @@ void RosenRenderColumnSplit::PaintDivider(RenderContext& context, const Offset&
double startPointY = offset.GetY();
double endPointX = startPointX + width;
double endPointY = startPointY;
#ifndef USE_ROSEN_DRAWING
SkPaint paint;
auto canvas = static_cast<RosenRenderContext*>(&context)->GetCanvas();
if (!canvas) {
@ -66,6 +69,19 @@ void RosenRenderColumnSplit::PaintDivider(RenderContext& context, const Offset&
paint.setColor(COLUMN_SPLIT_COLOR);
paint.setStrokeWidth(DEFAULT_SPLIT_HEIGHT);
canvas->drawLine(startPointX, startPointY, endPointX, endPointY, paint);
#else
RSPen pen;
auto canvas = static_cast<RosenRenderContext*>(&context)->GetCanvas();
if (!canvas) {
LOGE("Paint canvas is null");
return;
}
pen.SetColor(COLUMN_SPLIT_COLOR);
pen.SetWidth(DEFAULT_SPLIT_HEIGHT);
canvas->AttachPen(pen);
canvas->DrawLine(RSPoint(startPointX, startPointY), RSPoint(endPointX, endPointY));
canvas->DetachPen();
#endif
}
} // namespace OHOS::Ace

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2021 Huawei Device Co., Ltd.
* Copyright (c) 2021-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
@ -15,7 +15,9 @@
#include "core/components/split_container/rosen_render_row_split.h"
#ifndef USE_ROSEN_DRAWING
#include "include/core/SkPaint.h"
#endif
#include "core/pipeline/base/constants.h"
#include "core/pipeline/base/rosen_render_context.h"
@ -57,6 +59,7 @@ void RosenRenderRowSplit::PaintDivider(RenderContext& context, const Offset& off
double startPointY = offset.GetY();
double endPointX = startPointX;
double endPointY = startPointY + height;
#ifndef USE_ROSEN_DRAWING
SkPaint paint;
auto canvas = static_cast<RosenRenderContext*>(&context)->GetCanvas();
if (!canvas) {
@ -66,6 +69,19 @@ void RosenRenderRowSplit::PaintDivider(RenderContext& context, const Offset& off
paint.setColor(ROW_SPLIT_COLOR);
paint.setStrokeWidth(DEFAULT_SPLIT_HEIGHT);
canvas->drawLine(startPointX, startPointY, endPointX, endPointY, paint);
#else
RSPen pen;
auto canvas = static_cast<RosenRenderContext*>(&context)->GetCanvas();
if (!canvas) {
LOGE("Paint canvas is null");
return;
}
pen.SetColor(ROW_SPLIT_COLOR);
pen.SetWidth(DEFAULT_SPLIT_HEIGHT);
canvas->AttachPen(pen);
canvas->DrawLine(RSPoint(startPointX, startPointY), RSPoint(endPointX, endPointY));
canvas->DetachPen();
#endif
}
} // namespace OHOS::Ace

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2021 Huawei Device Co., Ltd.
* Copyright (c) 2021-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
@ -15,10 +15,12 @@
#include "core/components/track/rosen_render_arc_track.h"
#ifndef USE_ROSEN_DRAWING
#include "include/core/SkCanvas.h"
#include "include/core/SkClipOp.h"
#include "include/core/SkPaint.h"
#include "include/core/SkPath.h"
#endif
#include "txt/paragraph_builder.h"
#include "txt/paragraph_txt.h"
@ -41,6 +43,7 @@ void DrawGauge(RenderContext& context, const RenderRingInfo& trackInfo)
return;
}
double thickness = trackInfo.thickness;
#ifndef USE_ROSEN_DRAWING
SkPaint paint;
paint.setAntiAlias(true);
paint.setColor(trackInfo.color.GetValue());
@ -53,6 +56,22 @@ void DrawGauge(RenderContext& context, const RenderRingInfo& trackInfo)
trackInfo.center.GetX() + trackInfo.radius - (thickness / 2),
trackInfo.center.GetY() + trackInfo.radius - (thickness / 2) },
trackInfo.startDegree - 90, trackInfo.sweepDegree, false, paint);
#else
RSPen pen;
pen.SetAntiAlias(true);
pen.SetColor(trackInfo.color.GetValue());
pen.SetWidth(thickness);
pen.SetCapStyle(RSPen::CapStyle::ROUND_CAP);
canvas->AttachPen(pen);
canvas->DrawArc(
RSRect(trackInfo.center.GetX() + (thickness / 2) - trackInfo.radius,
trackInfo.center.GetY() + (thickness / 2) - trackInfo.radius,
trackInfo.center.GetX() + trackInfo.radius - (thickness / 2),
trackInfo.center.GetY() + trackInfo.radius - (thickness / 2)),
trackInfo.startDegree - 90, trackInfo.sweepDegree);
canvas->DetachPen();
#endif
}
bool ShouldHighLight(const double start, const double interval, const double percent)
@ -63,8 +82,13 @@ bool ShouldHighLight(const double start, const double interval, const double per
return false;
}
#ifndef USE_ROSEN_DRAWING
void SetTextStyle(SkCanvas* canvas, const RenderRingInfo& trackInfo, const std::string& markedText,
const Color markedColor, const Rect dataRegion)
#else
void SetTextStyle(RSCanvas* canvas, const RenderRingInfo& trackInfo, const std::string& markedText,
const Color markedColor, const Rect dataRegion)
#endif
{
if (!canvas) {
LOGE("Paint canvas is null");
@ -89,7 +113,12 @@ void SetTextStyle(SkCanvas* canvas, const RenderRingInfo& trackInfo, const std::
builder->AddText(StringUtils::Str8ToStr16(markedText));
auto paragraph = builder->Build();
paragraph->Layout(dataRegion.Width());
#ifndef USE_ROSEN_DRAWING
paragraph->Paint(canvas, pathStartVertexX - txtStyle.font_size, pathStartVertexY + EDGE + HEIGHT_OFFSET * 2);
#else
paragraph->Paint(canvas->GetCanvasData()->ExportSkCanvas(), pathStartVertexX - txtStyle.font_size,
pathStartVertexY + EDGE + HEIGHT_OFFSET * 2);
#endif
}
void DrawIndicator(RenderContext& context, const RenderRingInfo& trackInfo, const std::string& markedText,
@ -100,6 +129,7 @@ void DrawIndicator(RenderContext& context, const RenderRingInfo& trackInfo, cons
LOGE("Paint canvas is null");
return;
}
#ifndef USE_ROSEN_DRAWING
canvas->save();
SkPath path;
@ -125,6 +155,38 @@ void DrawIndicator(RenderContext& context, const RenderRingInfo& trackInfo, cons
paint.setColor(Color::BLACK.GetValue());
canvas->drawPath(path, paint);
canvas->restore();
#else
canvas->Save();
RSRecordingPath path;
double pathStartVertexX = trackInfo.center.GetX();
double pathStartVertexY = trackInfo.center.GetY() - trackInfo.radius + (trackInfo.thickness / 2);
path.MoveTo(pathStartVertexX, pathStartVertexY);
path.LineTo(pathStartVertexX - EDGE, pathStartVertexY + EDGE);
path.LineTo(pathStartVertexX - EDGE, pathStartVertexY + EDGE + HEIGHT_OFFSET);
path.LineTo(pathStartVertexX + EDGE, pathStartVertexY + EDGE + HEIGHT_OFFSET);
path.LineTo(pathStartVertexX + EDGE, pathStartVertexY + EDGE);
path.LineTo(pathStartVertexX, pathStartVertexY);
canvas->Rotate(trackInfo.startDegree + trackInfo.sweepDegree, trackInfo.center.GetX(), trackInfo.center.GetY());
RSBrush brush;
RSPen pen;
brush.SetColor(Color::WHITE.GetValue());
canvas->AttachBrush(brush);
canvas->DrawPath(path);
canvas->DetachBrush();
SetTextStyle(canvas, trackInfo, markedText, markedColor, dataRegion);
pen.SetCapStyle(RSPen::CapStyle::SQUARE_CAP);
pen.SetWidth(INDICATOR_STROKE_WIDTH);
pen.SetColor(Color::BLACK.GetValue());
canvas->AttachPen(pen);
canvas->DrawPath(path);
canvas->DetachPen();
canvas->Restore();
#endif
}
} // namespace

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2021-2022 Huawei Device Co., Ltd.
* Copyright (c) 2021-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
@ -15,9 +15,11 @@
#include "rosen_render_capsule_track.h"
#ifndef USE_ROSEN_DRAWING
#include "include/core/SkCanvas.h"
#include "include/core/SkPaint.h"
#include "include/core/SkPath.h"
#endif
#include "core/pipeline/base/rosen_render_context.h"
@ -36,6 +38,7 @@ void RosenRenderCapsuleTrack::DrawShape(RenderContext& context, const Offset& of
Size progressSize = Size(progressWidth, progressHeight);
double rrectRadius = progressSize.Height() / 2.0;
#ifndef USE_ROSEN_DRAWING
SkPaint paint;
paint.setColor(GetBackgroundColor().GetValue());
paint.setStyle(SkPaint::Style::kFill_Style);
@ -46,6 +49,20 @@ void RosenRenderCapsuleTrack::DrawShape(RenderContext& context, const Offset& of
rRect.offset(offset.GetX(), offset.GetY());
canvas->drawRRect(rRect, paint);
#else
RSBrush brush;
brush.SetColor(GetBackgroundColor().GetValue());
brush.SetAntiAlias(true);
RSRoundRect rRect(
RSRect(0, 0, static_cast<RSScalar>(progressSize.Width()),
static_cast<RSScalar>(progressSize.Height())),
rrectRadius, rrectRadius);
rRect.Offset(offset.GetX(), offset.GetY());
canvas->AttachBrush(brush);
canvas->DrawRoundRect(rRect);
canvas->DetachBrush();
#endif
}
void RosenRenderCapsuleTrack::DrawCapsuleProgressAnimation(RenderContext& context,
@ -69,6 +86,7 @@ void RosenRenderCapsuleTrack::DrawCapsuleProgressAnimation(RenderContext& contex
double progressWidth = progressSize.Width()*GetTotalRatio();
#ifndef USE_ROSEN_DRAWING
SkPath path;
path.addArc({ offsetX, offsetY, progressSize.Height() + offsetX, progressSize.Height() + offsetY }, 90, 180);
if (LessNotEqual(progressWidth, radius)) {
@ -90,6 +108,31 @@ void RosenRenderCapsuleTrack::DrawCapsuleProgressAnimation(RenderContext& contex
paint.setStyle(SkPaint::Style::kFill_Style);
paint.setAntiAlias(true);
canvas->drawPath(path, paint);
#else
RSRecordingPath path;
path.AddArc(RSRect(
offsetX, offsetY, progressSize.Height() + offsetX, progressSize.Height() + offsetY), 90, 180);
if (LessNotEqual(progressWidth, radius)) {
path.AddArc(RSRect(
progressWidth + offsetX, offsetY, progressSize.Height() - progressWidth + offsetX,
progressSize.Height() + offsetY), 270, -180);
} else if (GreatNotEqual(progressWidth, progressSize.Width() - radius)) {
path.AddRect(radius + offsetX, offsetY, progressSize.Width() - radius + offsetX,
progressSize.Height() + offsetY, RSPathDirection::CW_DIRECTION);
path.AddArc(RSRect(
(progressSize.Width() - radius) * 2.0 - progressWidth + offsetX, offsetY,
progressWidth + offsetX, progressSize.Height() + offsetY), 270, 180);
} else {
path.AddRect(radius + offsetX, offsetY, progressWidth + offsetX, progressSize.Height() + offsetY);
}
RSBrush brush;
brush.SetColor(GetSelectColor().GetValue());
brush.SetAntiAlias(true);
canvas->AttachBrush(brush);
canvas->DrawPath(path);
canvas->DetachBrush();
#endif
}
void RosenRenderCapsuleTrack::DrawCapsuleProgressVerticalAnimation(RenderContext& context, const Offset& offset)
@ -111,6 +154,7 @@ void RosenRenderCapsuleTrack::DrawCapsuleProgressVerticalAnimation(RenderContext
double radius = progressSize.Width() / 2.0;
double progressWidth = progressSize.Height()*GetTotalRatio();
#ifndef USE_ROSEN_DRAWING
SkPath path;
path.addArc({ offsetX, offsetY, progressSize.Width() + offsetX, progressSize.Width() + offsetY }, 0, -180);
if (LessNotEqual(progressWidth, radius)) {
@ -132,6 +176,33 @@ void RosenRenderCapsuleTrack::DrawCapsuleProgressVerticalAnimation(RenderContext
paint.setStyle(SkPaint::Style::kFill_Style);
paint.setAntiAlias(true);
canvas->drawPath(path, paint);
#else
RSRecordingPath path;
path.AddArc(RSRect(
offsetX, offsetY, progressSize.Width() + offsetX,
progressSize.Width() + offsetY), 0, -180);
if (LessNotEqual(progressWidth, radius)) {
path.AddArc(RSRect(
offsetX, offsetY + progressWidth, progressSize.Width() + offsetX,
progressSize.Width() - progressWidth + offsetY), 180, 180);
} else if (GreatNotEqual(progressWidth, progressSize.Height() - radius)) {
path.AddRect(
offsetX, offsetY + radius, progressSize.Width() + offsetX, progressSize.Height() - radius + offsetY);
path.AddArc(RSRect(
offsetX, offsetY + (progressSize.Height() - radius) * 2.0 - progressWidth,
progressSize.Width() + offsetX, progressWidth + offsetY), 180, -180);
} else {
path.AddRect(RSRect(
offsetX, radius + offsetY, offsetX + progressSize.Width(), progressWidth + offsetY));
}
RSBrush brush;
brush.SetColor(GetSelectColor().GetValue());
brush.SetAntiAlias(true);
canvas->AttachBrush(brush);
canvas->DrawPath(path);
canvas->DetachBrush();
#endif
}
void RosenRenderCapsuleTrack::Paint(RenderContext& context, const Offset& offset)
@ -146,4 +217,4 @@ void RosenRenderCapsuleTrack::Paint(RenderContext& context, const Offset& offset
DrawCapsuleProgressVerticalAnimation(context, offset);
}
}
} // namespace OHOS::Ace
} // namespace OHOS::Ace

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2021 Huawei Device Co., Ltd.
* Copyright (c) 2021-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
@ -15,10 +15,12 @@
#include "core/components/track/rosen_render_circular_track.h"
#ifndef USE_ROSEN_DRAWING
#include "include/core/SkCanvas.h"
#include "include/core/SkColor.h"
#include "include/core/SkPaint.h"
#include "include/effects/SkGradientShader.h"
#endif
#include "core/pipeline/base/rosen_render_context.h"
@ -36,6 +38,7 @@ void DrawArc(RenderContext& context, const RenderRingInfo& trackInfo)
return;
}
double thickness = trackInfo.thickness;
#ifndef USE_ROSEN_DRAWING
SkPaint paint;
paint.setAntiAlias(true);
if (trackInfo.gradient.IsValid()) {
@ -67,6 +70,40 @@ void DrawArc(RenderContext& context, const RenderRingInfo& trackInfo)
trackInfo.center.GetY() + trackInfo.radius - (thickness / 2) },
trackInfo.clockwise * trackInfo.startDegree + degreeOffset,
trackInfo.clockwise * trackInfo.sweepDegree, false, paint);
#else
RSPen pen;
pen.SetAntiAlias(true);
if (trackInfo.gradient.IsValid()) {
RSColorQuad colors[trackInfo.gradient.GetColors().size() + 1];
// size cannot be larger than uint32_t.
for (uint32_t index = 0; index < trackInfo.gradient.GetColors().size(); index++) {
colors[index] = trackInfo.gradient.GetColors()[index].GetColor().GetValue();
}
colors[trackInfo.gradient.GetColors().size()] = trackInfo.gradient.GetColors()[0].GetColor().GetValue();
float position[] = { COLOR_STOP, 2.0 * COLOR_STOP, 1.0 };
std::vector<RSColorQuad> vecColor(colors, colors + sizeof(colors));
std::vector<RSScalar> vecPos(position, position + sizeof(position));
pen.SetShaderEffect(RSShaderEffect::CreateSweepGradientByMatrix(
RSPoint(trackInfo.center.GetX(), trackInfo.center.GetY()), vecColor, vecPos,
RSTileMode::CLAMP, trackInfo.startDegree, trackInfo.startDegree + 360, true, nullptr));
} else {
pen.SetColor(trackInfo.color.GetValue());
}
pen.SetWidth(thickness);
pen.SetCapStyle(RSPen::CapStyle::ROUND_CAP);
canvas->AttachPen(pen);
canvas->DrawArc(
RSRect(trackInfo.center.GetX() + (thickness / 2) - trackInfo.radius,
trackInfo.center.GetY() + (thickness / 2) - trackInfo.radius,
trackInfo.center.GetX() + trackInfo.radius - (thickness / 2),
trackInfo.center.GetY() + trackInfo.radius - (thickness / 2)),
trackInfo.clockwise * trackInfo.startDegree, trackInfo.clockwise * trackInfo.sweepDegree);
canvas->DetachPen();
#endif
}
} // namespace
@ -81,7 +118,11 @@ void RosenRenderCircularTrack::Paint(RenderContext& context, const Offset& offse
LOGE("Paint canvas is null");
return;
}
#ifndef USE_ROSEN_DRAWING
canvas->save();
#else
canvas->Save();
#endif
// draw background
data.color = GetBackgroundColor();
@ -98,7 +139,11 @@ void RosenRenderCircularTrack::Paint(RenderContext& context, const Offset& offse
data.sweepDegree = paintData_.sweepDegree * GetTotalRatio();
DrawArc(context, data);
#ifndef USE_ROSEN_DRAWING
canvas->restore();
#else
canvas->Restore();
#endif
}
} // namespace OHOS::Ace
} // namespace OHOS::Ace

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2021-2022 Huawei Device Co., Ltd.
* Copyright (c) 2021-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
@ -15,6 +15,7 @@
#include "core/components/track/rosen_render_linear_track.h"
#ifndef USE_ROSEN_DRAWING
#include "include/core/SkCanvas.h"
#include "include/core/SkMaskFilter.h"
#include "include/core/SkPaint.h"
@ -22,6 +23,7 @@
#include "include/core/SkRRect.h"
#include "include/core/SkShader.h"
#include "include/effects/SkGradientShader.h"
#endif
#include "core/components/slider/render_slider.h"
#include "core/components/track/render_track.h"
@ -29,6 +31,7 @@
namespace OHOS::Ace {
#ifndef USE_ROSEN_DRAWING
sk_sp<SkShader> RosenRenderLinearTrack::BlendSkShader(const SkPoint pts, const SkColor color, bool useAnimator)
{
const double scanLeftOffset = NormalizeToPx(Dimension(75, DimensionUnit::VP));
@ -60,6 +63,34 @@ sk_sp<SkShader> RosenRenderLinearTrack::BlendSkShader(const SkPoint pts, const S
#endif
return blendShader;
}
#else
std::shared_ptr<RSShaderEffect> RosenRenderLinearTrack::BlendSkShader(
const RSPoint pts, const RSColorQuad color, bool useAnimator)
{
const double scanLeftOffset = NormalizeToPx(Dimension(75, DimensionUnit::VP));
const double scanRightOffset = NormalizeToPx(Dimension(5, DimensionUnit::VP));
const Color hightLight = Color::FromString("#88ffffff");
const Color shadow = Color::FromString("#00ffffff");
std::vector<RSColorQuad> scanColors = { shadow.GetValue(), hightLight.GetValue(), shadow.GetValue() };
std::vector<RSScalar> scanPos = { 0, 0.94, 1 };
std::shared_ptr<RSShaderEffect> scanShader;
std::shared_ptr<RSShaderEffect> backgroundShader;
std::shared_ptr<RSShaderEffect> blendShader;
const RSPoint gradientPoints[2] = { { pts.GetX() - scanLeftOffset, pts.GetY() },
{ pts.GetX() + scanRightOffset, pts.GetY() } };
backgroundShader = RSShaderEffect::CreateColorShader(color);
scanShader = RSShaderEffect::CreateLinearGradient(
gradientPoints[0], gradientPoints[1], scanColors, scanPos, RSTileMode::DECAL);
if (useAnimator) {
blendShader = RSShaderEffect::CreateBlendShader(
*backgroundShader, *scanShader, RSBlendMode::SRC_OVER);
} else {
blendShader = backgroundShader;
}
return blendShader;
}
#endif
void RosenRenderLinearTrack::Paint(RenderContext& context, const Offset& offset)
{
@ -90,6 +121,7 @@ void RosenRenderLinearTrack::Paint(RenderContext& context, const Offset& offset)
trackLength = GetLayoutSize().Width();
}
trackLength = trackLength - trackHeight;
#ifndef USE_ROSEN_DRAWING
if (!NearEqual(GetCachedRatio(), 0.0)) {
SkPaint cachedPaint;
cachedPaint.setAntiAlias(true);
@ -133,6 +165,60 @@ void RosenRenderLinearTrack::Paint(RenderContext& context, const Offset& offset)
GetSelectColor().GetValue(), playAnimation_));
canvas->drawRRect(selectRect, selectPaint);
}
#else
if (!NearEqual(GetCachedRatio(), 0.0)) {
RSPen cachedPen;
cachedPen.SetAntiAlias(true);
cachedPen.SetColor(GetCachedColor().GetValue());
const double startRect = leftToRight_ ? offset.GetX() : offset.GetX() + GetLayoutSize().Width();
const double endRect = leftToRight_ ? startRect + trackHeight + trackLength * GetCachedRatio()
: startRect - trackHeight - trackLength * GetCachedRatio();
RSRoundRect cachedRect(
RSRect(startRect, offset.GetY(), endRect, offset.GetY() + trackHeight), trackHeight * HALF,
trackHeight * HALF);
RSRoundRect cachedRectRosen(cachedRect);
canvas->AttachPen(cachedPen);
canvas->DrawRoundRect(cachedRectRosen);
canvas->DetachPen();
}
// Draw selected region
if (!NearEqual(GetTotalRatio(), 0.0)) {
RSPen selectPen;
selectPen.SetAntiAlias(true);
double startRect = 0.0;
double endRect = 0.0;
if (direction_ == Axis::VERTICAL) {
startRect = isReverse_ ? offset.GetY() + GetLayoutSize().Height() : offset.GetY();
endRect = isReverse_ ? startRect - trackHeight - trackLength * GetTotalRatio()
: startRect + trackHeight + trackLength * GetTotalRatio();
RSRoundRect selectRect(
RSRect(offset.GetX(), startRect, offset.GetX() + trackHeight, endRect),
trackHeight * HALF, trackHeight * HALF);
selectPen.SetShaderEffect(BlendSkShader(
RSPoint(offset.GetX(), startRect), GetSelectColor().GetValue(), playAnimation_));
canvas->AttachPen(selectPen);
canvas->DrawRoundRect(selectRect);
canvas->DetachPen();
return;
}
if ((leftToRight_ && !isReverse_) || (!leftToRight_ && isReverse_)) {
startRect = offset.GetX();
endRect = startRect + trackHeight + trackLength * GetTotalRatio();
} else {
startRect = offset.GetX() + GetLayoutSize().Width();
endRect = startRect - trackHeight - trackLength * GetTotalRatio();
}
RSRoundRect selectRect(
RSRect(startRect, offset.GetY(), endRect, offset.GetY() + trackHeight), trackHeight * HALF,
trackHeight * HALF);
selectPen.SetShaderEffect(
BlendSkShader(RSPoint(startRect + scanHighLightValue_ * trackLength, offset.GetY()),
GetSelectColor().GetValue(), playAnimation_));
canvas->AttachPen(selectPen);
canvas->DrawRoundRect(selectRect);
canvas->DetachPen();
}
#endif
}
void RosenRenderLinearTrack::PaintSliderSteps(RenderContext& context, const Offset& offset)
@ -159,6 +245,7 @@ void RosenRenderLinearTrack::PaintSliderSteps(RenderContext& context, const Offs
if (!NearEqual(GetTrackThickness(), 0.0)) {
trackHeight = GetTrackThickness();
}
#ifndef USE_ROSEN_DRAWING
if (direction_ == Axis::VERTICAL) {
const double trackLength = GetLayoutSize().Height();
const double dxOffset = offset.GetX() + trackHeight * HALF;
@ -204,6 +291,55 @@ void RosenRenderLinearTrack::PaintSliderSteps(RenderContext& context, const Offs
}
canvas->drawPath(path, skPaint);
}
#else
if (direction_ == Axis::VERTICAL) {
const double trackLength = GetLayoutSize().Height();
const double dxOffset = offset.GetX() + trackHeight * HALF;
double current = offset.GetY();
RSPen pen;
pen.SetColor(color.GetValue());
pen.SetWidth(size);
pen.SetCapStyle(RSPen::CapStyle::ROUND_CAP);
RSPath path;
while (LessOrEqual(current, offset.GetY() + trackLength)) {
double dyOffset;
if (GetSliderMode() == SliderMode::OUTSET) {
dyOffset = std::clamp(current, offset.GetY() + size * HALF, offset.GetY() + trackLength - size * HALF);
} else {
dyOffset = std::clamp(current, offset.GetY(), offset.GetY() + trackLength);
}
path.MoveTo(static_cast<RSScalar>(dxOffset), static_cast<RSScalar>(dyOffset));
path.LineTo(static_cast<RSScalar>(dxOffset), static_cast<RSScalar>(dyOffset));
current += GetSliderSteps();
}
canvas->AttachPen(pen);
canvas->DrawPath(path);
canvas->DetachPen();
} else {
const double trackLength = GetLayoutSize().Width();
const double dyOffset = offset.GetY() + trackHeight * HALF;
double current = offset.GetX();
RSPen pen;
pen.SetColor(color.GetValue());
pen.SetWidth(size);
pen.SetCapStyle(RSPen::CapStyle::ROUND_CAP);
RSPath path;
while (LessOrEqual(current, offset.GetY() + trackLength)) {
double dxOffset;
if (GetSliderMode() == SliderMode::OUTSET) {
dxOffset = std::clamp(current, offset.GetX() + size * HALF, offset.GetX() + trackLength - size * HALF);
} else {
dxOffset = std::clamp(current, offset.GetX(), offset.GetX() + trackLength);
}
path.MoveTo(static_cast<float>(dxOffset), static_cast<float>(dyOffset));
path.LineTo(static_cast<float>(dxOffset), static_cast<float>(dyOffset));
current += GetSliderSteps();
}
canvas->AttachPen(pen);
canvas->DrawPath(path);
canvas->DetachPen();
}
#endif
}
void RosenRenderLinearTrack::PaintSliderTrack(RenderContext& context, const Offset& offset)
@ -229,6 +365,7 @@ void RosenRenderLinearTrack::PaintSliderTrack(RenderContext& context, const Offs
}
// Draw background
#ifndef USE_ROSEN_DRAWING
SkPaint railPaint;
railPaint.setAntiAlias(true);
railPaint.setColor(GetBackgroundColor().GetValue());
@ -240,11 +377,28 @@ void RosenRenderLinearTrack::PaintSliderTrack(RenderContext& context, const Offs
} else {
canvas->drawLine(offset.GetX(), dyOffset, offset.GetX() + trackLength, dyOffset, railPaint);
}
#else
RSPen railPen;
railPen.SetAntiAlias(true);
railPen.SetColor(GetBackgroundColor().GetValue());
railPen.SetWidth(trackHeight);
railPen.SetCapStyle(RSPen::CapStyle::ROUND_CAP);
canvas->AttachPen(railPen);
if (direction_ == Axis::VERTICAL) {
canvas->DrawLine(RSPoint(dxOffset, offset.GetY()),
RSPoint(dxOffset, offset.GetY() + trackLength));
} else {
canvas->DrawLine(RSPoint(offset.GetX(), dyOffset),
RSPoint(offset.GetX() + trackLength, dyOffset));
}
canvas->DetachBrush();
#endif
// draw steps
PaintSliderSteps(context, offset);
// Draw selected region
#ifndef USE_ROSEN_DRAWING
if (!NearEqual(GetTotalRatio(), 0.0)) {
SkPaint selectPaint;
selectPaint.setAntiAlias(true);
@ -270,8 +424,40 @@ void RosenRenderLinearTrack::PaintSliderTrack(RenderContext& context, const Offs
}
canvas->drawLine(fromOffset, dyOffset, toOffset, dyOffset, selectPaint);
}
#else
if (!NearEqual(GetTotalRatio(), 0.0)) {
RSPen selectPen;
selectPen.SetAntiAlias(true);
selectPen.SetColor(GetSelectColor().GetValue());
selectPen.SetWidth(trackHeight);
selectPen.SetCapStyle(RSPen::CapStyle::ROUND_CAP);
canvas->AttachPen(selectPen);
double fromOffset = 0.0;
double toOffset = 0.0;
if (direction_ == Axis::VERTICAL) {
fromOffset = isReverse_ ? offset.GetY() + trackLength : offset.GetY();
toOffset = isReverse_ ?
fromOffset - trackLength * GetTotalRatio() : fromOffset + trackLength * GetTotalRatio();
canvas->AttachPen(selectPen);
canvas->DrawLine(RSPoint(dxOffset, fromOffset), RSPoint(dxOffset, toOffset));
canvas->DetachPen();
return;
}
if (((leftToRight_ && !isReverse_)) || ((!leftToRight_ && isReverse_))) {
fromOffset = offset.GetX();
toOffset = fromOffset + trackLength * GetTotalRatio();
} else {
fromOffset = offset.GetX() + trackLength;
toOffset = fromOffset - trackLength * GetTotalRatio();
}
canvas->AttachPen(selectPen);
canvas->DrawLine(RSPoint(fromOffset, dyOffset), RSPoint(toOffset, dyOffset));
canvas->DetachPen();
}
#endif
}
#ifndef USE_ROSEN_DRAWING
void RosenRenderLinearTrack::PaintBackgroundTrack(SkCanvas* canvas, const Offset& offset, double trackHeight) const
{
SkPaint railPaint;
@ -290,5 +476,28 @@ void RosenRenderLinearTrack::PaintBackgroundTrack(SkCanvas* canvas, const Offset
canvas->drawRRect(rrect, railPaint);
}
#else
void RosenRenderLinearTrack::PaintBackgroundTrack(
RSCanvas* canvas, const Offset& offset, double trackHeight) const
{
RSPen railPen;
railPen.SetAntiAlias(true);
railPen.SetColor(GetBackgroundColor().GetValue());
RSRoundRect rrect;
if (direction_ == Axis::VERTICAL) {
rrect = RSRoundRect(RSRect(offset.GetX(), offset.GetY(),
offset.GetX() + trackHeight, offset.GetY() + GetLayoutSize().Height()),
trackHeight * HALF, trackHeight * HALF);
} else {
rrect = RSRoundRect(RSRect(offset.GetX(), offset.GetY(),
offset.GetX() + GetLayoutSize().Width(), offset.GetY() + trackHeight),
trackHeight * HALF, trackHeight * HALF);
}
} // namespace OHOS::Ace
canvas->AttachPen(railPen);
canvas->DrawRoundRect(rrect);
canvas->DetachPen();
}
#endif
} // namespace OHOS::Ace

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2021 Huawei Device Co., Ltd.
* Copyright (c) 2021-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
@ -16,10 +16,12 @@
#ifndef FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_TRACK_ROSEN_RENDER_LINEAR_TRACK_H
#define FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_TRACK_ROSEN_RENDER_LINEAR_TRACK_H
#ifndef USE_ROSEN_DRAWING
#include "include/core/SkCanvas.h"
#include "include/core/SkColor.h"
#include "include/core/SkPoint.h"
#include "include/core/SkShader.h"
#endif
#include "base/geometry/offset.h"
#include "core/components/track/render_track.h"
@ -36,10 +38,19 @@ public:
void Paint(RenderContext& context, const Offset& offset) override;
void PaintSliderTrack(RenderContext& context, const Offset& offset);
void PaintSliderSteps(RenderContext& context, const Offset& offset);
#ifndef USE_ROSEN_DRAWING
void PaintBackgroundTrack(SkCanvas* canvas, const Offset& offset, double trackHeight) const;
#else
void PaintBackgroundTrack(RSCanvas* canvas, const Offset& offset, double trackHeight) const;
#endif
private:
#ifndef USE_ROSEN_DRAWING
sk_sp<SkShader> BlendSkShader(const SkPoint pts, const SkColor color, bool useAnimator = false);
#else
std::shared_ptr<RSShaderEffect> BlendSkShader(const RSPoint pts,
const RSColorQuad color, bool useAnimator = false);
#endif
};
} // namespace OHOS::Ace

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2021 Huawei Device Co., Ltd.
* Copyright (c) 2021-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
@ -15,9 +15,11 @@
#include "rosen_render_moon_track.h"
#ifndef USE_ROSEN_DRAWING
#include "include/core/SkCanvas.h"
#include "include/core/SkPaint.h"
#include "include/core/SkPath.h"
#endif
#include "core/pipeline/base/rosen_render_context.h"
@ -28,15 +30,22 @@ void RosenRenderMoonTrack::Paint(RenderContext& context, const Offset& offset)
Size canvasSize = GetLayoutSize();
Offset center = offset + Offset(canvasSize.Width() / 2, canvasSize.Height() / 2);
double radius = std::min(canvasSize.Width(), canvasSize.Height()) / 2;
#ifndef USE_ROSEN_DRAWING
SkPaint paint;
paint.setAntiAlias(true);
paint.setColor(GetSelectColor().GetValue());
paint.setStyle(SkPaint::kFill_Style);
#else
RSBrush brush;
brush.SetAntiAlias(true);
brush.SetColor(GetSelectColor().GetValue());
#endif
auto canvas = static_cast<RosenRenderContext*>(&context)->GetCanvas();
if (canvas == nullptr) {
LOGE("Paint canvas is null");
return;
}
#ifndef USE_ROSEN_DRAWING
SkPath path;
SkPaint backgroundPaint;
@ -65,6 +74,42 @@ void RosenRenderMoonTrack::Paint(RenderContext& context, const Offset& offset)
270, 180);
canvas->drawPath(path, paint);
}
#else
RSRecordingPath path;
RSBrush backgroundBrush;
backgroundBrush.SetAntiAlias(true);
backgroundBrush.SetColor(GetBackgroundColor().GetValue());
canvas->AttachBrush(backgroundBrush);
canvas->DrawCircle(RSPoint(center.GetX(), center.GetY()), radius);
canvas->DetachBrush();
if (GetTotalRatio() <= 0.5) {
path.MoveTo(center.GetX(), center.GetY() - radius);
path.AddArc(RSRect(
center.GetX() - radius, center.GetY() - radius, center.GetX() + radius, center.GetY() + radius),
90, 180);
double progressOffset = radius - radius * GetTotalRatio() / 0.5;
path.AddArc(RSRect(center.GetX() - progressOffset,
center.GetY() - radius, center.GetX() + progressOffset, center.GetY() + radius),
270, -180);
canvas->AttachBrush(brush);
canvas->DrawPath(path);
canvas->DetachBrush();
} else {
double progressOffset = radius * (GetTotalRatio() - 0.5) / 0.5;
path.MoveTo(center.GetX(), center.GetY() - radius);
path.AddArc(RSRect(
center.GetX() - radius, center.GetY() - radius, center.GetX() + radius, center.GetY() + radius),
90, 180);
path.AddArc(RSRect(center.GetX() - progressOffset,
center.GetY() - radius, center.GetX() + progressOffset, center.GetY() + radius),
270, 180);
canvas->AttachBrush(brush);
canvas->DrawPath(path);
canvas->DetachBrush();
}
#endif
}
} // namespace OHOS::Ace
} // namespace OHOS::Ace

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2021 Huawei Device Co., Ltd.
* Copyright (c) 2021-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
@ -15,9 +15,11 @@
#include "core/components/track/rosen_render_scale_ring_track.h"
#ifndef USE_ROSEN_DRAWING
#include "include/core/SkCanvas.h"
#include "include/core/SkPaint.h"
#include "include/effects/Sk1DPathEffect.h"
#endif
#include "core/components/theme/theme_constants.h"
#include "core/components/theme/theme_constants_defines.h"
@ -33,6 +35,7 @@ void DrawScaleArc(RenderContext& context, const RenderRingInfo& trackInfo)
LOGE("Paint canvas is null");
return;
}
#ifndef USE_ROSEN_DRAWING
SkPaint paint;
SkPath path;
path.addRRect(SkRRect::MakeRectXY(SkRect::MakeWH(trackInfo.scaleStrokeWidth, trackInfo.thickness),
@ -46,18 +49,44 @@ void DrawScaleArc(RenderContext& context, const RenderRingInfo& trackInfo)
paint.setStrokeWidth(trackInfo.thickness);
paint.setAntiAlias(true);
paint.setColor(trackInfo.color.GetValue());
#else
RSPen pen;
RSRecordingPath path;
path.AddRoundRect(RSRect(0, 0, trackInfo.scaleStrokeWidth, trackInfo.thickness),
trackInfo.thickness / 2.0, trackInfo.thickness / 2.0);
double pathDistance = 2.0 * M_PI *
(trackInfo.radius + (NearEqual(trackInfo.clockwise, 1.0) ? trackInfo.thickness : 0.0)) /
trackInfo.totalScaleNumber;
pen.SetPathEffect(RSPathEffect::CreatePathDashEffect(
path, static_cast<RSScalar>(pathDistance), 0.0f, RSPathDashStyle::ROTATE));
pen.SetWidth(trackInfo.thickness);
pen.SetAntiAlias(true);
pen.SetColor(trackInfo.color.GetValue());
#endif
static int32_t totalDegree = 360;
double radiusPrecision = trackInfo.thickness;
if (trackInfo.clockwise != 1) {
radiusPrecision = 0.0;
}
#ifndef USE_ROSEN_DRAWING
canvas->drawArc({ trackInfo.center.GetX() - trackInfo.radius - radiusPrecision,
trackInfo.center.GetY() - trackInfo.radius - radiusPrecision,
trackInfo.center.GetX() + trackInfo.radius + radiusPrecision,
trackInfo.center.GetY() + trackInfo.radius + radiusPrecision },
180 * (trackInfo.clockwise * (trackInfo.startDegree / (totalDegree / 2.0)) - 0.5),
360 * (trackInfo.clockwise * trackInfo.sweepDegree / totalDegree), false, paint);
#else
canvas->AttachPen(pen);
canvas->DrawArc(
RSRect(trackInfo.center.GetX() - trackInfo.radius - radiusPrecision,
trackInfo.center.GetY() - trackInfo.radius - radiusPrecision,
trackInfo.center.GetX() + trackInfo.radius + radiusPrecision,
trackInfo.center.GetY() + trackInfo.radius + radiusPrecision),
180 * (trackInfo.clockwise * (trackInfo.startDegree / (totalDegree / 2.0)) - 0.5),
360 * (trackInfo.clockwise * trackInfo.sweepDegree / totalDegree));
canvas->DetachPen();
#endif
}
} // namespace

View File

@ -13,8 +13,8 @@
* limitations under the License.
*/
#ifndef FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_MEDIA_PLAYER_CALLBACK_H
#define FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_MEDIA_PLAYER_CALLBACK_H
#ifndef FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_VIDEO_PLAYER_CALLBACK_H
#define FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_VIDEO_PLAYER_CALLBACK_H
#include "base/log/log.h"
@ -88,40 +88,42 @@ public:
void OnInfo(Media::PlayerOnInfoType type, int32_t extra, const Media::Format &InfoBody = {}) override
{
LOGI("OnInfo type: %{public}d, extra: %{public}d", type, extra);
LOGD("video OnInfo type: %{public}d, extra: %{public}d", type, extra);
ContainerScope scope(instanceId_);
switch (type) {
case OHOS::Media::INFO_TYPE_SEEKDONE:
LOGI("OnSeekDone callback");
LOGD("video OnSeekDone callback");
if (positionUpdatedEvent_) {
positionUpdatedEvent_(extra / MILLISECONDS_TO_SECONDS);
}
break;
case OHOS::Media::INFO_TYPE_EOS:
LOGI("OnEndOfStream callback");
LOGD("video OnEndOfStream callback");
if (endOfStreamEvent_) {
endOfStreamEvent_();
}
break;
case OHOS::Media::INFO_TYPE_STATE_CHANGE:
LOGI("OnStateChanged callback");
LOGD("video OnStateChanged callback");
PrintState(static_cast<OHOS::Media::PlayerStates>(extra));
if (stateChangedEvent_) {
stateChangedEvent_(ConvertToPlaybackStatus(extra));
}
break;
case OHOS::Media::INFO_TYPE_POSITION_UPDATE:
LOGD("video INFO_TYPE_POSITION_UPDATE callback");
if (positionUpdatedEvent_) {
positionUpdatedEvent_(extra / MILLISECONDS_TO_SECONDS);
}
break;
case OHOS::Media::INFO_TYPE_RESOLUTION_CHANGE:
LOGD("video INFO_TYPE_RESOLUTION_CHANGE callback");
if (resolutionChangeEvent_) {
resolutionChangeEvent_();
}
break;
case OHOS::Media::INFO_TYPE_MESSAGE:
LOGI("OnMessage callback type: %{public}d", extra);
LOGD("OnMessage callback type: %{public}d", extra);
break;
default:
break;
@ -185,4 +187,4 @@ private:
} // namespace OHOS::Ace
#endif // FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_MEDIA_PLAYER_CALLBACK_H
#endif // FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_VIDEO_PLAYER_CALLBACK_H

View File

@ -64,6 +64,7 @@ build_component("web") {
"ability_base:configuration",
"ability_runtime:app_manager",
"c_utils:utils",
"init:libbegetutil",
"ipc:ipc_core",
"webview:libnweb",
]

View File

@ -45,6 +45,7 @@
#include "application_env.h"
#include "nweb_adapter_helper.h"
#include "nweb_handler.h"
#include "parameters.h"
#include "web_configuration_observer.h"
#include "web_javascript_execute_callback.h"
#include "web_javascript_result_callback.h"
@ -84,6 +85,10 @@ const std::string RESOURCE_VIDEO_CAPTURE = "TYPE_VIDEO_CAPTURE";
const std::string RESOURCE_AUDIO_CAPTURE = "TYPE_AUDIO_CAPTURE";
const std::string RESOURCE_PROTECTED_MEDIA_ID = "TYPE_PROTECTED_MEDIA_ID";
const std::string RESOURCE_MIDI_SYSEX = "TYPE_MIDI_SYSEX";
// web parameters
const std::string MULTI_RENDER_PROCESS = "persist.web.multiple_render_processes_enable";
const std::string BACKGROUMD_MEDIA_SUSPEND = "persist.web.background_media_should_suspend";
} // namespace
#define EGLCONFIG_VERSION 3
@ -2362,7 +2367,7 @@ void WebDelegate::InitWebViewWithSurface()
rosenWindowId_ = window->GetWindowId();
LOGI("Init WebView With Surface");
context->GetTaskExecutor()->PostTask(
[weak = WeakClaim(this)]() {
[weak = WeakClaim(this), context = context_]() {
auto delegate = weak.Upgrade();
CHECK_NULL_VOID(delegate);
OHOS::NWeb::NWebInitArgs initArgs;
@ -2390,6 +2395,10 @@ void WebDelegate::InitWebViewWithSurface()
}
initArgs.web_engine_args_to_add.push_back(
std::string("--init-background-color=").append(std::to_string(delegate->backgroundColor_)));
if (!system::GetBoolParameter(BACKGROUMD_MEDIA_SUSPEND, true)) {
initArgs.web_engine_args_to_add.emplace_back(std::string("--disable-background-media-suspend"));
}
initArgs.multi_renderer_process = system::GetBoolParameter(MULTI_RENDER_PROCESS, false);
if (isEnhanceSurface) {
LOGI("Create webview with isEnhanceSurface");
delegate->nweb_ = OHOS::NWeb::NWebAdapterHelper::Instance().CreateNWeb(
@ -2418,10 +2427,13 @@ void WebDelegate::InitWebViewWithSurface()
delegate->nweb_->SetNWebHandler(nweb_handler);
delegate->nweb_->PutDownloadCallback(downloadListenerImpl);
#ifdef OHOS_STANDARD_SYSTEM
delegate->nweb_->RegisterScreenLockFunction(delegate->GetRosenWindowId(), [weak](bool key) {
auto delegate = weak.Upgrade();
CHECK_NULL_VOID(delegate);
delegate->SetKeepScreenOn(key);
delegate->nweb_->RegisterScreenLockFunction(delegate->GetRosenWindowId(), [context](bool key) {
LOGD("SetKeepScreenOn %{public}d", key);
auto weakContext = context.Upgrade();
CHECK_NULL_VOID(weakContext);
auto window = weakContext->GetWindow();
CHECK_NULL_VOID(window);
window->SetKeepScreenOn(key);
});
#endif
auto findListenerImpl = std::make_shared<FindListenerImpl>(Container::CurrentId());
@ -4833,4 +4845,4 @@ void WebDelegate::OnResizeNotWork()
CHECK_NULL_VOID(webPattern);
webPattern->OnResizeNotWork();
}
} // namespace OHOS::Ace
} // namespace OHOS::Ace

View File

@ -424,7 +424,6 @@ void ViewAbstract::SetBorderRadius(const Dimension& value)
}
BorderRadiusProperty borderRadius;
borderRadius.SetRadius(value);
borderRadius.SetRadiusFlag(true);
ACE_UPDATE_RENDER_CONTEXT(BorderRadius, borderRadius);
}

View File

@ -135,7 +135,7 @@ public:
{
ViewAbstract::SetForegroundBlurStyle(fgBlurStyle);
}
void SetSphericalEffect(double radio) override
{
ViewAbstract::SetSphericalEffect(radio);
@ -257,6 +257,7 @@ public:
borderRadius.radiusTopRight = radiusTopRight;
borderRadius.radiusBottomLeft = radiusBottomLeft;
borderRadius.radiusBottomRight = radiusBottomRight;
borderRadius.multiValued = true;
ViewAbstract::SetBorderRadius(borderRadius);
}
@ -272,6 +273,7 @@ public:
borderColors.rightColor = colorRight;
borderColors.topColor = colorTop;
borderColors.bottomColor = colorBottom;
borderColors.multiValued = true;
ViewAbstract::SetBorderColor(borderColors);
}
@ -288,6 +290,7 @@ public:
borderWidth.rightDimen = right;
borderWidth.topDimen = top;
borderWidth.bottomDimen = bottom;
borderWidth.multiValued = true;
ViewAbstract::SetBorderWidth(borderWidth);
}
@ -304,6 +307,7 @@ public:
borderStyles.styleRight = styleRight.value_or(BorderStyle::SOLID);
borderStyles.styleTop = styleTop.value_or(BorderStyle::SOLID);
borderStyles.styleBottom = styleBottom.value_or(BorderStyle::SOLID);
borderStyles.multiValued = true;
ViewAbstract::SetBorderStyle(borderStyles);
}
@ -821,6 +825,7 @@ public:
{
ViewAbstract::SetForegroundColorStrategy(strategy);
}
private:
void RegisterMenuAppearCallback(
std::vector<NG::OptionParam>& params, std::function<void()>&& buildFunc, const MenuParam& menuParam);

View File

@ -198,7 +198,10 @@ void DragEventActuator::OnCollectTouchTarget(const OffsetF& coordinateOffset, co
CHECK_NULL_VOID(gestureHub);
auto frameNode = gestureHub->GetFrameNode();
CHECK_NULL_VOID(frameNode);
if (!longPressRecognizer_->HasThumbnailCallback()) {
auto eventHub = frameNode->GetEventHub<EventHub>();
CHECK_NULL_VOID(eventHub);
bool isAllowedDrag = gestureHub->IsAllowedDrag(eventHub);
if (!longPressRecognizer_->HasThumbnailCallback() && isAllowedDrag) {
auto callback = [weakPtr = gestureEventHub_](Offset point) {
auto gestureHub = weakPtr.Upgrade();
CHECK_NULL_VOID(gestureHub);

View File

@ -354,8 +354,11 @@ bool GestureEventHub::IsAllowedDrag(RefPtr<EventHub> eventHub)
{
auto frameNode = GetFrameNode();
CHECK_NULL_RETURN(frameNode, false);
auto pattern = frameNode->GetPattern();
CHECK_NULL_RETURN(pattern, false);
if (frameNode->IsDraggable()) {
if (!eventHub->HasOnDragStart()) {
if (!eventHub->HasOnDragStart() && !pattern->DefaultSupportDrag()) {
LOGE("Default support for drag and drop, but there is no onDragStart function.");
return false;
}
@ -364,7 +367,7 @@ bool GestureEventHub::IsAllowedDrag(RefPtr<EventHub> eventHub)
LOGE("User settings cannot be dragged");
return false;
}
if (!eventHub->HasOnDragStart()) {
if (!eventHub->HasOnDragStart() && !pattern->DefaultSupportDrag()) {
LOGE("The default does not support drag and drop, and there is no onDragStart function.");
return false;
}

View File

@ -63,15 +63,15 @@ sk_sp<SkData> SkiaImageData::GetSkData() const
RefPtr<SvgDomBase> SkiaImageData::MakeSvgDom(const std::optional<Color>& svgFillColor)
{
// TODO: svg support in ng build
#ifdef NG_BUILD
return nullptr;
#else
const auto svgStream = std::make_unique<SkMemoryStream>(skData_);
CHECK_NULL_RETURN(svgStream, nullptr);
if (SystemProperties::GetSvgMode() <= 0) {
return SkiaSvgDom::CreateSkiaSvgDom(*svgStream, svgFillColor);
}
#ifdef NG_BUILD
LOGE("NG SvgDom not support!");
return nullptr;
#else
auto svgDom_ = SvgDom::CreateSvgDom(*svgStream, svgFillColor);
if (!svgDom_) {
return nullptr;

View File

@ -66,6 +66,20 @@ void SelectOverlayManager::DestroySelectOverlay(int32_t overlayId)
}
}
void SelectOverlayManager::DestroySelectOverlay()
{
auto rootNode = rootNodeWeak_.Upgrade();
CHECK_NULL_VOID(rootNode);
auto current = selectOverlayItem_.Upgrade();
if (current) {
LOGD("destroy overlay, id is %{public}d.", current->GetId());
rootNode->RemoveChild(current);
rootNode->MarkNeedSyncRenderTree();
rootNode->RebuildRenderContextTree();
selectOverlayItem_.Reset();
}
}
bool SelectOverlayManager::HasSelectOverlay(int32_t overlayId)
{
auto current = selectOverlayItem_.Upgrade();
@ -73,6 +87,22 @@ bool SelectOverlayManager::HasSelectOverlay(int32_t overlayId)
return current->GetId() == overlayId;
}
bool SelectOverlayManager::IsInSelectedOrSelectOverlayArea(const PointF& point)
{
auto current = selectOverlayItem_.Upgrade();
CHECK_NULL_RETURN_NOLOG(current, false);
auto selectOverlayNode = DynamicCast<SelectOverlayNode>(current);
if (selectOverlayNode) {
return selectOverlayNode->IsInSelectedOrSelectOverlayArea(point);
} else {
auto menuRect = current->GetGeometryNode()->GetFrameRect();
if (menuRect.IsInRegion(point)) {
return true;
}
}
return false;
}
RefPtr<SelectOverlayNode> SelectOverlayManager::GetSelectOverlayNode(int32_t overlayId)
{
auto current = selectOverlayItem_.Upgrade();

View File

@ -44,9 +44,12 @@ public:
// Destroy the pop-up interface and delete the pop-up information.
void DestroySelectOverlay(const RefPtr<SelectOverlayProxy>& proxy);
void DestroySelectOverlay(int32_t overlayId);
void DestroySelectOverlay();
bool HasSelectOverlay(int32_t overlayId);
bool IsInSelectedOrSelectOverlayArea(const PointF& point);
RefPtr<SelectOverlayNode> GetSelectOverlayNode(int32_t overlayId);
bool IsSameSelectOverlayInfo(const SelectOverlayInfo& info);

View File

@ -190,7 +190,6 @@ build_component_ng("pattern_ng") {
"menu/menu_pattern.cpp",
"menu/menu_view.cpp",
"menu/multi_menu_layout_algorithm.cpp",
"menu/navigation_menu_layout_algorithm.cpp",
"menu/sub_menu_layout_algorithm.cpp",
"menu/wrapper/menu_wrapper_layout_algorithm.cpp",
"menu/wrapper/menu_wrapper_paint_method.cpp",
@ -425,6 +424,7 @@ build_component_ng("pattern_ng") {
"video/video_accessibility_property.cpp",
"video/video_layout_algorithm.cpp",
"video/video_model_ng.cpp",
"video/video_node.cpp",
"video/video_pattern.cpp",
"view_context/view_context_model_ng.cpp",
"waterflow/water_flow_accessibility_property.cpp",

View File

@ -125,10 +125,10 @@ void BubbleLayoutAlgorithm::Layout(LayoutWrapper* layoutWrapper)
if (children.empty()) {
return;
}
selfSize_ = layoutWrapper->GetGeometryNode()->GetFrameSize(); // bubble's size
selfSize_ = layoutWrapper->GetGeometryNode()->GetFrameSize(); // window's size
auto child = children.front();
childSize_ = child->GetGeometryNode()->GetMarginFrameSize(); // bubble's child's size
childOffset_ = GetChildPosition(childSize_, bubbleProp); // bubble's child's offset
childSize_ = child->GetGeometryNode()->GetMarginFrameSize(); // bubble's size
childOffset_ = GetChildPosition(childSize_, bubbleProp); // bubble's offset
bool useCustom = bubbleProp->GetUseCustom().value_or(false);
UpdateChildPosition(bubbleProp);
UpdateTouchRegion();
@ -179,6 +179,8 @@ OffsetF BubbleLayoutAlgorithm::GetChildPosition(const SizeF& childSize, const Re
targetOffset_.GetY() - childSize.Height() - targetSpace - arrowHeight_);
OffsetF topArrowPosition;
OffsetF bottomArrowPosition;
OffsetF oppositePosition;
OffsetF fitPosition;
InitArrowTopAndBottomPosition(topArrowPosition, bottomArrowPosition, topPosition, bottomPosition, childSize);
OffsetF originOffset =
@ -191,38 +193,65 @@ OffsetF BubbleLayoutAlgorithm::GetChildPosition(const SizeF& childSize, const Re
if (errorType == ErrorPositionType::NORMAL) {
return childPosition;
}
// If childPosition is error, adjust bubble to bottom.
if (placement_ != Placement::TOP || errorType == ErrorPositionType::TOP_LEFT_ERROR) {
childPosition = FitToScreen(bottomPosition, childSize);
if (placement_ == Placement::TOP || placement_ == Placement::TOP_LEFT || placement_ == Placement::TOP_RIGHT) {
fitPosition = topPosition;
arrowPosition_ = topArrowPosition;
arrowPlacement_ = Placement::TOP;
} else {
fitPosition = bottomPosition;
arrowPosition_ = bottomArrowPosition;
arrowPlacement_ = Placement::BOTTOM;
if (GetErrorPositionType(childPosition, childSize) == ErrorPositionType::NORMAL) {
return childPosition;
}
}
// If childPosition is error, adjust bubble to top.
childPosition = FitToScreen(topPosition, childSize);
arrowPosition_ = topArrowPosition;
arrowPlacement_ = Placement::TOP;
childPosition = FitToScreen(fitPosition, childSize);
if (GetErrorPositionType(childPosition, childSize) == ErrorPositionType::NORMAL) {
return childPosition;
}
oppositePosition = fitPosition == topPosition ? bottomPosition : topPosition;
arrowPosition_ = arrowPosition_ == topArrowPosition ? bottomArrowPosition : topArrowPosition;
arrowPlacement_ = arrowPlacement_ == Placement::TOP ? Placement::BOTTOM : Placement::TOP;
childPosition = FitToScreen(fitPosition, childSize);
if (GetErrorPositionType(childPosition, childSize) == ErrorPositionType::NORMAL) {
return childPosition;
}
// If childPosition is error, adjust bubble to origin position.
arrowPlacement_ = placement_;
arrowPosition_ = arrowPlacement_ == Placement::TOP ? topArrowPosition : bottomArrowPosition;
// Todo arrowPositom may need to adjust
return originOffset;
}
void BubbleLayoutAlgorithm::InitArrowTopAndBottomPosition(OffsetF& topArrowPosition, OffsetF& bottomArrowPosition,
OffsetF& topPosition, OffsetF& bottomPosition, const SizeF& childSize)
{
auto arrowCenter = targetOffset_.GetX() + targetSize_.Width() / 2.0;
auto horizonSpacing = static_cast<float>(HORIZON_SPACING_WITH_SCREEN.ConvertToPx());
double arrowWidth = ARROW_WIDTH.ConvertToPx();
float radius = borderRadius_.ConvertToPx();
auto safePosition = horizonSpacing + radius + arrowWidth / 2.0;
topArrowPosition =
topPosition + OffsetF(std::max(padding_.Left().ConvertToPx(), border_.TopLeftRadius().GetX().ConvertToPx()) +
BEZIER_WIDTH_HALF.ConvertToPx(),
childSize.Height() + arrowHeight_);
bottomArrowPosition = bottomPosition + OffsetF(std::max(padding_.Left().ConvertToPx(),
border_.BottomLeftRadius().GetX().ConvertToPx()) +
BEZIER_WIDTH_HALF.ConvertToPx(), -arrowHeight_);
BEZIER_WIDTH_HALF.ConvertToPx(),
-arrowHeight_);
// move the arrow to safe position while arrow too close to window
// In order not to separate the bubble from the arrow
if (arrowCenter < safePosition) {
topArrowPosition = topArrowPosition + OffsetF(safePosition - arrowCenter, 0);
bottomArrowPosition = bottomArrowPosition + OffsetF(safePosition - arrowCenter, 0);
}
if (arrowCenter > selfSize_.Width() - safePosition) {
topArrowPosition = topArrowPosition - OffsetF(arrowCenter + safePosition - selfSize_.Width(), 0);
bottomArrowPosition = bottomArrowPosition - OffsetF(arrowCenter + safePosition - selfSize_.Width(), 0);
}
}
OffsetF BubbleLayoutAlgorithm::GetPositionWithPlacement(const SizeF& childSize, const OffsetF& topPosition,

View File

@ -88,6 +88,10 @@ void UpdateTextProperties(const RefPtr<PopupParam>& param, const RefPtr<TextLayo
if (fontWeight.has_value()) {
textLayoutProps->UpdateFontWeight(fontWeight.value());
}
auto fontStyle = param->GetFontStyle();
if (fontStyle.has_value()) {
textLayoutProps->UpdateItalicFontStyle(fontStyle.value());
}
}
} // namespace

View File

@ -43,7 +43,6 @@ void ButtonPattern::OnAttachToFrameNode()
auto renderContext = host->GetRenderContext();
CHECK_NULL_VOID(renderContext);
renderContext->SetClipToFrame(true);
renderContext->UpdateClipEdge(true);
auto buttonTheme = pipeline->GetTheme<ButtonTheme>();
CHECK_NULL_VOID(buttonTheme);
clickedColor_ = buttonTheme->GetClickedColor();

View File

@ -36,7 +36,6 @@ void ToggleButtonPattern::OnAttachToFrameNode()
auto renderContext = host->GetRenderContext();
CHECK_NULL_VOID(renderContext);
renderContext->SetClipToFrame(true);
renderContext->UpdateClipEdge(true);
}
void ToggleButtonPattern::InitParameters()

View File

@ -197,6 +197,10 @@ void CanvasPaintMethod::DrawImage(
PaintShadow(path, *imageShadow_, skCanvas);
}
if (globalState_.HasGlobalAlpha()) {
imagePaint_.setAlphaf(globalState_.GetAlpha());
}
switch (canvasImage.flag) {
case 0:
skCanvas_->drawImage(image, canvasImage.dx, canvasImage.dy);
@ -353,7 +357,8 @@ void CanvasPaintMethod::TransferFromImageBitmap(PaintWrapper* paintWrapper,
PutImageData(paintWrapper, *imageData);
}
void CanvasPaintMethod::FillText(PaintWrapper* paintWrapper, const std::string& text, double x, double y)
void CanvasPaintMethod::FillText(
PaintWrapper* paintWrapper, const std::string& text, double x, double y, std::optional<double> maxWidth)
{
CHECK_NULL_VOID(paintWrapper);
auto offset = paintWrapper->GetContentOffset();
@ -361,10 +366,11 @@ void CanvasPaintMethod::FillText(PaintWrapper* paintWrapper, const std::string&
auto success = UpdateParagraph(offset, text, false, HasShadow());
CHECK_NULL_VOID(success);
PaintText(offset, frameSize, x, y, false, HasShadow());
PaintText(offset, frameSize, x, y, maxWidth, false, HasShadow());
}
void CanvasPaintMethod::StrokeText(PaintWrapper* paintWrapper, const std::string& text, double x, double y)
void CanvasPaintMethod::StrokeText(
PaintWrapper* paintWrapper, const std::string& text, double x, double y, std::optional<double> maxWidth)
{
CHECK_NULL_VOID(paintWrapper);
auto offset = paintWrapper->GetContentOffset();
@ -373,12 +379,12 @@ void CanvasPaintMethod::StrokeText(PaintWrapper* paintWrapper, const std::string
if (HasShadow()) {
auto success = UpdateParagraph(offset, text, true, true);
CHECK_NULL_VOID(success);
PaintText(offset, frameSize, x, y, true, true);
PaintText(offset, frameSize, x, y, maxWidth, true, true);
}
auto success = UpdateParagraph(offset, text, true);
CHECK_NULL_VOID(success);
PaintText(offset, frameSize, x, y, true);
PaintText(offset, frameSize, x, y, maxWidth, true);
}
double CanvasPaintMethod::MeasureText(const std::string& text, const PaintState& state)
@ -458,10 +464,10 @@ TextMetrics CanvasPaintMethod::MeasureTextMetrics(const std::string& text, const
return textMetrics;
}
void CanvasPaintMethod::PaintText(
const OffsetF& offset, const SizeF& frameSize, double x, double y, bool isStroke, bool hasShadow)
void CanvasPaintMethod::PaintText(const OffsetF& offset, const SizeF& frameSize, double x, double y,
std::optional<double> maxWidth, bool isStroke, bool hasShadow)
{
paragraph_->Layout(frameSize.Width());
paragraph_->Layout(FLT_MAX);
auto width = paragraph_->GetMaxIntrinsicWidth();
if (frameSize.Width() > width) {
paragraph_->Layout(std::ceil(width));
@ -472,16 +478,33 @@ void CanvasPaintMethod::PaintText(
isStroke ? strokeState_.GetTextStyle().GetTextBaseline() : fillState_.GetTextStyle().GetTextBaseline();
double dy = offset.GetY() + y + GetBaselineOffset(baseline, paragraph_);
std::optional<double> scale = CalcTextScale(paragraph_->GetMaxIntrinsicWidth(), maxWidth);
if (hasShadow) {
skCanvas_->save();
auto shadowOffsetX = shadow_.GetOffset().GetX();
auto shadowOffsetY = shadow_.GetOffset().GetY();
if (scale.has_value()) {
if (!NearZero(scale.value())) {
dx /= scale.value();
shadowOffsetX /= scale.value();
}
skCanvas_->scale(scale.value(), 1.0);
}
paragraph_->Paint(skCanvas_.get(), dx + shadowOffsetX, dy + shadowOffsetY);
skCanvas_->restore();
return;
}
paragraph_->Paint(skCanvas_.get(), dx, dy);
if (scale.has_value()) {
if (!NearZero(scale.value())) {
dx /= scale.value();
}
skCanvas_->save();
skCanvas_->scale(scale.value(), 1.0);
paragraph_->Paint(skCanvas_.get(), dx, dy);
skCanvas_->restore();
} else {
paragraph_->Paint(skCanvas_.get(), dx, dy);
}
}
double CanvasPaintMethod::GetBaselineOffset(TextBaseline baseline, std::unique_ptr<txt::Paragraph>& paragraph)

View File

@ -65,8 +65,10 @@ public:
std::string ToDataURL(const std::string& args);
std::string GetJsonData(const std::string& path);
void FillText(PaintWrapper* paintWrapper, const std::string& text, double x, double y);
void StrokeText(PaintWrapper* paintWrapper, const std::string& text, double x, double y);
void FillText(
PaintWrapper* paintWrapper, const std::string& text, double x, double y, std::optional<double> maxWidth);
void StrokeText(
PaintWrapper* paintWrapper, const std::string& text, double x, double y, std::optional<double> maxWidth);
double MeasureText(const std::string& text, const PaintState& state);
double MeasureTextHeight(const std::string& text, const PaintState& state);
TextMetrics MeasureTextMetrics(const std::string& text, const PaintState& state);
@ -80,8 +82,8 @@ private:
void ImageObjFailed() override;
sk_sp<SkImage> GetImage(const std::string& src) override;
void PaintText(
const OffsetF& offset, const SizeF& contentSize, double x, double y, bool isStroke, bool hasShadow = false);
void PaintText(const OffsetF& offset, const SizeF& contentSize, double x, double y, std::optional<double> maxWidth,
bool isStroke, bool hasShadow = false);
double GetBaselineOffset(TextBaseline baseline, std::unique_ptr<txt::Paragraph>& paragraph);
bool UpdateParagraph(const OffsetF& offset, const std::string& text, bool isStroke, bool hasShadow = false);
void UpdateTextStyleForeground(const OffsetF& offset, bool isStroke, txt::TextStyle& txtStyle, bool hasShadow);

View File

@ -379,7 +379,9 @@ void CustomPaintPaintMethod::GetStrokePaint(SkPaint& paint, SkSamplingOptions& o
{ LineCapStyle::SQUARE, SkPaint::Cap::kSquare_Cap },
};
InitImagePaint(paint, options);
paint.setColor(strokeState_.GetColor().GetValue());
if (strokeState_.GetPaintStyle() == PaintStyle::Color) {
paint.setColor(strokeState_.GetColor().GetValue());
}
paint.setStyle(SkPaint::Style::kStroke_Style);
paint.setStrokeJoin(ConvertEnumToSkEnum(
strokeState_.GetLineJoin(), skLineJoinTable, ArraySize(skLineJoinTable), SkPaint::Join::kMiter_Join));
@ -528,7 +530,9 @@ void CustomPaintPaintMethod::FillRect(PaintWrapper* paintWrapper, const Rect& re
InitImagePaint(paint, options);
#endif
paint.setAntiAlias(antiAlias_);
paint.setColor(fillState_.GetColor().GetValue());
if (fillState_.GetPaintStyle() == OHOS::Ace::PaintStyle::Color) {
paint.setColor(fillState_.GetColor().GetValue());
}
paint.setStyle(SkPaint::Style::kFill_Style);
SkRect skRect = SkRect::MakeLTRB(rect.Left() + offset.GetX(), rect.Top() + offset.GetY(),
rect.Right() + offset.GetX(), offset.GetY() + rect.Bottom());
@ -660,7 +664,9 @@ void CustomPaintPaintMethod::Fill(PaintWrapper* paintWrapper)
InitImagePaint(paint, options);
#endif
paint.setAntiAlias(antiAlias_);
paint.setColor(fillState_.GetColor().GetValue());
if (fillState_.GetPaintStyle() == OHOS::Ace::PaintStyle::Color) {
paint.setColor(fillState_.GetColor().GetValue());
}
paint.setStyle(SkPaint::Style::kFill_Style);
if (HasShadow()) {
PaintShadow(skPath_, shadow_, skCanvas_.get());
@ -707,7 +713,9 @@ void CustomPaintPaintMethod::Path2DFill(const OffsetF& offset)
InitImagePaint(paint, options);
#endif
paint.setAntiAlias(antiAlias_);
paint.setColor(fillState_.GetColor().GetValue());
if (fillState_.GetPaintStyle() == OHOS::Ace::PaintStyle::Color) {
paint.setColor(fillState_.GetColor().GetValue());
}
paint.setStyle(SkPaint::Style::kFill_Style);
if (HasShadow()) {
PaintShadow(skPath2d_, shadow_, skCanvas_.get());
@ -1628,4 +1636,35 @@ bool CustomPaintPaintMethod::HasImageShadow() const
return !(NearZero(imageShadow_->GetOffset().GetX()) && NearZero(imageShadow_->GetOffset().GetY()) &&
NearZero(imageShadow_->GetBlurRadius()));
}
std::optional<double> CustomPaintPaintMethod::CalcTextScale(double maxIntrinsicWidth, std::optional<double> maxWidth)
{
std::optional<double> scale;
if (NearZero(maxIntrinsicWidth) || !maxWidth.has_value()) {
return scale;
}
if (Negative(maxWidth.value())) {
maxWidth = 0.0f;
}
double maxWidthValue = maxWidth.value();
if (GreatNotEqual(maxIntrinsicWidth, maxWidthValue)) {
scale = maxWidthValue / maxIntrinsicWidth;
}
return scale;
}
TransformParam CustomPaintPaintMethod::GetTransform() const
{
TransformParam param;
if (skCanvas_ != nullptr) {
SkMatrix matrix = skCanvas_->getTotalMatrix();
param.scaleX = matrix.getScaleX();
param.scaleY = matrix.getScaleY();
param.skewX = matrix.getSkewX();
param.skewY = matrix.getSkewY();
param.translateX = matrix.getTranslateX();
param.translateY = matrix.getTranslateY();
}
return param;
}
} // namespace OHOS::Ace::NG

View File

@ -89,6 +89,7 @@ public:
void Scale(double x, double y);
void Rotate(double angle);
virtual void SetTransform(const TransformParam& param) = 0;
virtual TransformParam GetTransform() const;
void ResetTransform();
void Transform(const TransformParam& param);
void Translate(double x, double y);
@ -293,6 +294,7 @@ public:
}
protected:
std::optional<double> CalcTextScale(double maxIntrinsicWidth, std::optional<double> maxWidth);
bool HasShadow() const;
void UpdateLineDash(SkPaint& paint);
void UpdatePaintShader(const OffsetF& offset, SkPaint& paint, const Ace::Gradient& gradient);

View File

@ -281,10 +281,10 @@ void CustomPaintPattern::QuadraticCurveTo(const QuadraticCurveParam& param)
host->MarkDirtyNode(PROPERTY_UPDATE_RENDER);
}
void CustomPaintPattern::FillText(const std::string& text, double x, double y)
void CustomPaintPattern::FillText(const std::string& text, double x, double y, std::optional<double> maxWidth)
{
auto task = [text, x, y](CanvasPaintMethod& paintMethod, PaintWrapper* paintWrapper) {
paintMethod.FillText(paintWrapper, text, x, y);
auto task = [text, x, y, maxWidth](CanvasPaintMethod& paintMethod, PaintWrapper* paintWrapper) {
paintMethod.FillText(paintWrapper, text, x, y, maxWidth);
};
paintMethod_->PushTask(task);
auto host = GetHost();
@ -292,10 +292,10 @@ void CustomPaintPattern::FillText(const std::string& text, double x, double y)
host->MarkDirtyNode(PROPERTY_UPDATE_RENDER);
}
void CustomPaintPattern::StrokeText(const std::string& text, double x, double y)
void CustomPaintPattern::StrokeText(const std::string& text, double x, double y, std::optional<double> maxWidth)
{
auto task = [text, x, y](CanvasPaintMethod& paintMethod, PaintWrapper* paintWrapper) {
paintMethod.StrokeText(paintWrapper, text, x, y);
auto task = [text, x, y, maxWidth](CanvasPaintMethod& paintMethod, PaintWrapper* paintWrapper) {
paintMethod.StrokeText(paintWrapper, text, x, y, maxWidth);
};
paintMethod_->PushTask(task);
auto host = GetHost();
@ -550,8 +550,6 @@ void CustomPaintPattern::UpdateStrokePattern(const std::weak_ptr<Ace::Pattern>&
{
auto task = [pattern](CanvasPaintMethod& paintMethod, PaintWrapper* paintWrapper) {
paintMethod.SetStrokePatternNG(pattern);
paintMethod.SetStrokeGradient(Ace::Gradient());
paintMethod.SetStrokeColor(Color());
};
paintMethod_->PushTask(task);
auto host = GetHost();
@ -563,8 +561,6 @@ void CustomPaintPattern::UpdateStrokeColor(const Color& color)
{
auto task = [color](CanvasPaintMethod& paintMethod, PaintWrapper* paintWrapper) {
paintMethod.SetStrokeColor(color);
paintMethod.SetStrokePattern(Ace::Pattern());
paintMethod.SetStrokeGradient(Ace::Gradient());
};
paintMethod_->PushTask(task);
auto host = GetHost();
@ -576,8 +572,6 @@ void CustomPaintPattern::UpdateStrokeGradient(const Ace::Gradient& grad)
{
auto task = [grad](CanvasPaintMethod& paintMethod, PaintWrapper* paintWrapper) {
paintMethod.SetStrokeGradient(grad);
paintMethod.SetStrokeColor(Color());
paintMethod.SetStrokePattern(Ace::Pattern());
};
paintMethod_->PushTask(task);
auto host = GetHost();
@ -842,4 +836,9 @@ void CustomPaintPattern::SetFilterParam(const std::string& filterStr)
CHECK_NULL_VOID(host);
host->MarkDirtyNode(PROPERTY_UPDATE_RENDER);
}
TransformParam CustomPaintPattern::GetTransform() const
{
return paintMethod_->GetTransform();
}
} // namespace OHOS::Ace::NG

View File

@ -73,8 +73,8 @@ public:
void BezierCurveTo(const BezierCurveParam& param);
void QuadraticCurveTo(const QuadraticCurveParam& param);
void FillText(const std::string& text, double x, double y);
void StrokeText(const std::string& text, double x, double y);
void FillText(const std::string& text, double x, double y, std::optional<double> maxWidth);
void StrokeText(const std::string& text, double x, double y, std::optional<double> maxWidth);
double MeasureText(const std::string& text, const PaintState& state);
double MeasureTextHeight(const std::string& text, const PaintState& state);
TextMetrics MeasureTextMetrics(const std::string& text, const PaintState& state);
@ -133,6 +133,7 @@ public:
void SetTextDirection(TextDirection direction);
void SetFilterParam(const std::string& filterStr);
TransformParam GetTransform() const;
private:
void OnAttachToFrameNode() override;

View File

@ -145,6 +145,10 @@ void OffscreenCanvasPaintMethod::DrawImage(
path.addRect(skRect);
RosenDecorationPainter::PaintShadow(path, *imageShadow_, skCanvas);
}
if (globalState_.HasGlobalAlpha()) {
imagePaint_.setAlphaf(globalState_.GetAlpha());
}
switch (canvasImage.flag) {
case 0:
skCanvas->drawImage(image, canvasImage.dx, canvasImage.dy);
@ -287,27 +291,29 @@ std::unique_ptr<Ace::ImageData> OffscreenCanvasPaintMethod::GetImageData(
return imageData;
}
void OffscreenCanvasPaintMethod::FillText(const std::string& text, double x, double y, const PaintState& state)
void OffscreenCanvasPaintMethod::FillText(
const std::string& text, double x, double y, std::optional<double> maxWidth, const PaintState& state)
{
if (!UpdateOffParagraph(text, false, state, HasShadow())) {
return;
}
PaintText(text, x, y, false, HasShadow());
PaintText(text, x, y, maxWidth, false, HasShadow());
}
void OffscreenCanvasPaintMethod::StrokeText(const std::string& text, double x, double y, const PaintState& state)
void OffscreenCanvasPaintMethod::StrokeText(
const std::string& text, double x, double y, std::optional<double> maxWidth, const PaintState& state)
{
if (HasShadow()) {
if (!UpdateOffParagraph(text, true, state, true)) {
return;
}
PaintText(text, x, y, true, true);
PaintText(text, x, y, maxWidth, true, true);
}
if (!UpdateOffParagraph(text, true, state)) {
return;
}
PaintText(text, x, y, true);
PaintText(text, x, y, maxWidth, true);
}
double OffscreenCanvasPaintMethod::MeasureText(const std::string& text, const PaintState& state)
@ -378,9 +384,9 @@ TextMetrics OffscreenCanvasPaintMethod::MeasureTextMetrics(const std::string& te
}
void OffscreenCanvasPaintMethod::PaintText(
const std::string& text, double x, double y, bool isStroke, bool hasShadow)
const std::string& text, double x, double y, std::optional<double> maxWidth, bool isStroke, bool hasShadow)
{
paragraph_->Layout(width_);
paragraph_->Layout(FLT_MAX);
if (width_ > paragraph_->GetMaxIntrinsicWidth()) {
paragraph_->Layout(std::ceil(paragraph_->GetMaxIntrinsicWidth()));
}
@ -390,15 +396,33 @@ void OffscreenCanvasPaintMethod::PaintText(
isStroke ? strokeState_.GetTextStyle().GetTextBaseline() : fillState_.GetTextStyle().GetTextBaseline();
double dy = y + GetBaselineOffset(baseline, paragraph_);
std::optional<double> scale = CalcTextScale(paragraph_->GetMaxIntrinsicWidth(), maxWidth);
if (hasShadow) {
skCanvas_->save();
auto shadowOffsetX = shadow_.GetOffset().GetX();
auto shadowOffsetY = shadow_.GetOffset().GetY();
if (scale.has_value()) {
if (!NearZero(scale.value())) {
dx /= scale.value();
shadowOffsetX /= scale.value();
}
skCanvas_->scale(scale.value(), 1.0);
}
paragraph_->Paint(skCanvas_.get(), dx + shadowOffsetX, dy + shadowOffsetY);
skCanvas_->restore();
return;
}
paragraph_->Paint(skCanvas_.get(), dx, dy);
if (scale.has_value()) {
if (!NearZero(scale.value())) {
dx /= scale.value();
}
skCanvas_->save();
skCanvas_->scale(scale.value(), 1.0);
paragraph_->Paint(skCanvas_.get(), dx, dy);
skCanvas_->restore();
} else {
paragraph_->Paint(skCanvas_.get(), dx, dy);
}
}
double OffscreenCanvasPaintMethod::GetBaselineOffset(TextBaseline baseline, std::unique_ptr<txt::Paragraph>& paragraph)

View File

@ -33,8 +33,9 @@ public:
std::unique_ptr<Ace::ImageData> GetImageData(double left, double top, double width, double height);
std::string ToDataURL(const std::string& type, const double quality);
void FillText(const std::string& text, double x, double y, const PaintState& state);
void StrokeText(const std::string& text, double x, double y, const PaintState& state);
void FillText(const std::string& text, double x, double y, std::optional<double> maxWidth, const PaintState& state);
void StrokeText(
const std::string& text, double x, double y, std::optional<double> maxWidth, const PaintState& state);
double MeasureText(const std::string& text, const PaintState& state);
double MeasureTextHeight(const std::string& text, const PaintState& state);
TextMetrics MeasureTextMetrics(const std::string& text, const PaintState& state);
@ -54,7 +55,8 @@ private:
sk_sp<SkImage> GetImage(const std::string& src) override { return sk_sp<SkImage>(); }
void PaintText(const std::string& text, double x, double y, bool isStroke, bool hasShadow = false);
void PaintText(const std::string& text, double x, double y, std::optional<double> maxWidth, bool isStroke,
bool hasShadow = false);
double GetBaselineOffset(TextBaseline baseline, std::unique_ptr<txt::Paragraph>& paragraph);
bool UpdateOffParagraph(const std::string& text, bool isStroke, const PaintState& state, bool hasShadow = false);
void UpdateTextStyleForeground(bool isStroke, txt::TextStyle& txtStyle, bool hasShadow);

View File

@ -129,14 +129,16 @@ void OffscreenCanvasPattern::QuadraticCurveTo(const QuadraticCurveParam& param)
offscreenPaintMethod_->QuadraticCurveTo(nullptr, param);
}
void OffscreenCanvasPattern::FillText(const std::string& text, double x, double y, const PaintState& state)
void OffscreenCanvasPattern::FillText(
const std::string& text, double x, double y, std::optional<double> maxWidth, const PaintState& state)
{
offscreenPaintMethod_->FillText(text, x, y, state);
offscreenPaintMethod_->FillText(text, x, y, maxWidth, state);
}
void OffscreenCanvasPattern::StrokeText(const std::string& text, double x, double y, const PaintState& state)
void OffscreenCanvasPattern::StrokeText(
const std::string& text, double x, double y, std::optional<double> maxWidth, const PaintState& state)
{
offscreenPaintMethod_->StrokeText(text, x, y, state);
offscreenPaintMethod_->StrokeText(text, x, y, maxWidth, state);
}
double OffscreenCanvasPattern::MeasureText(const std::string& text, const PaintState& state)
@ -392,4 +394,9 @@ std::string OffscreenCanvasPattern::ToDataURL(const std::string& type, const dou
{
return offscreenPaintMethod_->ToDataURL(type, quality);
}
TransformParam OffscreenCanvasPattern::GetTransform() const
{
return offscreenPaintMethod_->GetTransform();
}
} // namespace OHOS::Ace::NG

View File

@ -51,8 +51,9 @@ public:
void BezierCurveTo(const BezierCurveParam& param);
void QuadraticCurveTo(const QuadraticCurveParam& param);
void FillText(const std::string& text, double x, double y, const PaintState& state);
void StrokeText(const std::string& text, double x, double y, const PaintState& state);
void FillText(const std::string& text, double x, double y, std::optional<double> maxWidth, const PaintState& state);
void StrokeText(
const std::string& text, double x, double y, std::optional<double> maxWidth, const PaintState& state);
double MeasureText(const std::string& text, const PaintState& state);
double MeasureTextHeight(const std::string& text, const PaintState& state);
TextMetrics MeasureTextMetrics(const std::string& text, const PaintState& state);
@ -107,6 +108,7 @@ public:
void ResetTransform();
void Transform(const TransformParam& param);
void Translate(double x, double y);
TransformParam GetTransform() const;
std::string ToDataURL(const std::string& type, const double quality);
private:

View File

@ -57,6 +57,7 @@ namespace OHOS::Ace::NG {
namespace {
constexpr int32_t SHEET_INFO_IDX = -2;
constexpr Dimension SHEET_IMAGE_MARGIN = 16.0_vp;
constexpr Dimension SHEET_DIVIDER_WIDTH = 1.0_px;
constexpr Dimension SHEET_LIST_PADDING = 24.0_vp;
@ -531,7 +532,7 @@ RefPtr<FrameNode> DialogPattern::BuildSheetItem(const ActionSheetInfo& item)
hub->AddClickEvent(item.action);
}
// close dialog when clicked
BindCloseCallBack(hub, -1);
BindCloseCallBack(hub, SHEET_INFO_IDX);
itemRow->MountToParent(itemNode);
return itemNode;

View File

@ -42,11 +42,11 @@ void GridLayoutProperty::ToJsonValue(std::unique_ptr<JsonValue>& json) const
json->Put("columnsGap", propColumnsGap_.value_or(0.0_vp).ToString().c_str());
json->Put("rowsGap", propRowsGap_.value_or(0.0_vp).ToString().c_str());
json->Put("cachedCount", propCachedCount_.value_or(1));
json->Put("editMode ", propEditable_.value_or(false) ? "true" : "false");
json->Put("layoutDirection ", GetGridDirectionStr().c_str());
json->Put("maxCount ", propMaxCount_.value_or(Infinity<int32_t>()));
json->Put("minCount ", propMinCount_.value_or(1));
json->Put("cellLength ", propCellLength_.value_or(0));
json->Put("editMode", propEditable_.value_or(false) ? "true" : "false");
json->Put("layoutDirection", GetGridDirectionStr().c_str());
json->Put("maxCount", propMaxCount_.value_or(Infinity<int32_t>()));
json->Put("minCount", propMinCount_.value_or(1));
json->Put("cellLength", propCellLength_.value_or(0));
auto edgeEffect = propEdgeEffect_.value_or(EdgeEffect::NONE);
if (edgeEffect == EdgeEffect::SPRING) {
json->Put("edgeEffect", "EdgeEffect.Spring");

View File

@ -1003,7 +1003,7 @@ void GridPattern::UpdateScrollBarOffset()
continue;
}
auto lineStart = line->second.begin()->second;
auto lineEnd = line->second.end()->second;
auto lineEnd = line->second.rbegin()->second;
itemCount += (lineEnd - lineStart + 1);
heightSum += item.second + mainGap;
}

View File

@ -30,7 +30,8 @@ void GridPositionController::JumpTo(int32_t index, int32_t /* source */)
gridPattern->UpdateStartIndex(index);
}
bool GridPositionController::AnimateTo(const Dimension& position, float duration, const RefPtr<Curve>& curve)
bool GridPositionController::AnimateTo(
const Dimension& position, float duration, const RefPtr<Curve>& curve, bool smooth)
{
auto pattern = scroll_.Upgrade();
CHECK_NULL_RETURN(pattern, false);

View File

@ -33,7 +33,7 @@ public:
void ScrollToEdge(ScrollEdgeType scrollEdgeType, bool smooth) override;
void ScrollPage(bool reverse, bool smooth) override;
void JumpTo(int32_t index, int32_t source) override;
bool AnimateTo(const Dimension& position, float duration, const RefPtr<Curve>& curve) override;
bool AnimateTo(const Dimension& position, float duration, const RefPtr<Curve>& curve, bool smooth) override;
};
} // namespace OHOS::Ace::NG

View File

@ -227,6 +227,8 @@ void GridScrollLayoutAlgorithm::InitialItemsCrossSize(
ConvertToPx(layoutProperty->GetColumnsGap().value_or(0.0_vp), scale, frameSize.Width()).value_or(0);
mainGap_ = axis_ == Axis::HORIZONTAL ? columnsGap : rowsGap;
crossGap_ = axis_ == Axis::VERTICAL ? columnsGap : rowsGap;
auto padding = layoutProperty->CreatePaddingAndBorder();
crossPaddingOffset_ = axis_ == Axis::HORIZONTAL ? padding.top.value_or(0) : padding.left.value_or(0);
auto crossSize = frameSize.CrossSize(axis_);
std::vector<double> crossLens;

View File

@ -47,6 +47,11 @@ public:
return draggable_;
}
bool DefaultSupportDrag() override
{
return true;
}
private:
void LinkToAddress();
void OnAttachToFrameNode() override;

View File

@ -50,12 +50,6 @@ void ImageModelNG::Create(const std::string& src, bool noPixMap, RefPtr<PixelMap
V2::IMAGE_ETS_TAG, nodeId, []() { return AceType::MakeRefPtr<ImagePattern>(); });
stack->Push(frameNode);
ACE_UPDATE_LAYOUT_PROPERTY(ImageLayoutProperty, ImageSourceInfo, createSourceInfoFunc());
auto pipeline = PipelineContext::GetCurrentContext();
CHECK_NULL_VOID(pipeline);
auto theme = pipeline->GetTheme<ImageTheme>();
CHECK_NULL_VOID(theme);
SetDraggable(theme->GetDraggable());
}
void ImageModelNG::SetAlt(const std::string& src)

View File

@ -80,6 +80,11 @@ public:
void EnableDrag();
bool DefaultSupportDrag() override
{
return true;
}
void SetCopyOption(CopyOptions value)
{
copyOption_ = value;

View File

@ -783,8 +783,6 @@ void IndexerPattern::ChangeListItemsSelectedStyle(int32_t clickIndex)
popupClickedIndex_ = clickIndex;
auto host = GetHost();
CHECK_NULL_VOID(popupNode_);
auto context = PipelineContext::GetCurrentContext();
CHECK_NULL_VOID(context);
auto pipeline = PipelineContext::GetCurrentContext();
CHECK_NULL_VOID(pipeline);
auto indexerTheme = pipeline->GetTheme<IndexerTheme>();
@ -796,7 +794,7 @@ void IndexerPattern::ChangeListItemsSelectedStyle(int32_t clickIndex)
auto popupSelectedTextColor =
paintProperty->GetPopupSelectedColor().value_or(indexerTheme->GetPopupDefaultColor());
auto popupUnselectedTextColor =
paintProperty->GetPopupUnselectedColor().value_or(indexerTheme->GetPopupDefaultColor());
paintProperty->GetPopupUnselectedColor().value_or(indexerTheme->GetDefaultTextColor());
auto popupItemBackground =
paintProperty->GetPopupItemBackground().value_or(indexerTheme->GetPopupBackgroundColor());
auto listNode = popupNode_->GetLastChild();

Some files were not shown because too many files have changed in this diff Show More