mirror of
https://gitee.com/openharmony/arkui_ace_engine
synced 2024-11-27 09:12:41 +00:00
!13 Update width and height for Image onload
Merge pull request !13 from Sunfei/upload
This commit is contained in:
commit
0eacf573f8
@ -1227,29 +1227,10 @@ void FrontendDelegateDeclarative::RegisterFont(const std::string& familyName, co
|
||||
pipelineContextHolder_.Get()->RegisterFont(familyName, familySrc);
|
||||
}
|
||||
|
||||
void FrontendDelegateDeclarative::HandleImage(
|
||||
const std::string& src, std::function<void(int32_t)>&& callback, const std::set<std::string>& callbacks)
|
||||
void FrontendDelegateDeclarative::HandleImage(const std::string& src,
|
||||
std::function<void(bool, int32_t, int32_t)>&& callback)
|
||||
{
|
||||
if (src.empty() || !callback) {
|
||||
return;
|
||||
}
|
||||
std::map<std::string, EventMarker> callbackMarkers;
|
||||
if (callbacks.find("success") != callbacks.end()) {
|
||||
auto successEventMarker = BackEndEventManager<void()>::GetInstance().GetAvailableMarker();
|
||||
successEventMarker.SetPreFunction([callback, taskExecutor = taskExecutor_]() {
|
||||
taskExecutor->PostTask([callback] { callback(0); }, TaskExecutor::TaskType::JS);
|
||||
});
|
||||
callbackMarkers.emplace("success", successEventMarker);
|
||||
}
|
||||
|
||||
if (callbacks.find("fail") != callbacks.end()) {
|
||||
auto failEventMarker = BackEndEventManager<void()>::GetInstance().GetAvailableMarker();
|
||||
failEventMarker.SetPreFunction([callback, taskExecutor = taskExecutor_]() {
|
||||
taskExecutor->PostTask([callback] { callback(1); }, TaskExecutor::TaskType::JS);
|
||||
});
|
||||
callbackMarkers.emplace("fail", failEventMarker);
|
||||
}
|
||||
pipelineContextHolder_.Get()->CanLoadImage(src, callbackMarkers);
|
||||
LOGW("Not implement in declarative frontend.");
|
||||
}
|
||||
|
||||
void FrontendDelegateDeclarative::RequestAnimationFrame(const std::string& callbackId)
|
||||
|
@ -138,8 +138,7 @@ public:
|
||||
|
||||
void RegisterFont(const std::string& familyName, const std::string& familySrc) override;
|
||||
|
||||
void HandleImage(const std::string& src, std::function<void(int32_t)>&& callback,
|
||||
const std::set<std::string>& callbacks) override;
|
||||
void HandleImage(const std::string& src, std::function<void(bool, int32_t, int32_t)>&& callback) override;
|
||||
|
||||
void RequestAnimationFrame(const std::string& callbackId) override;
|
||||
|
||||
|
@ -995,32 +995,20 @@ JSValue JsHandleImage(JSContext* ctx, JSValueConst argv)
|
||||
auto success = JsParseRouteUrl(ctx, argv, "success");
|
||||
auto fail = JsParseRouteUrl(ctx, argv, "fail");
|
||||
|
||||
std::set<std::string> callbacks;
|
||||
if (!success.empty()) {
|
||||
callbacks.emplace("success");
|
||||
}
|
||||
if (!fail.empty()) {
|
||||
callbacks.emplace("fail");
|
||||
}
|
||||
|
||||
auto instance = static_cast<QjsEngineInstance*>(JS_GetContextOpaque(ctx));
|
||||
if (instance == nullptr) {
|
||||
return JS_NULL;
|
||||
}
|
||||
|
||||
auto&& callback = [instance, success, fail](int32_t callbackType) {
|
||||
switch (callbackType) {
|
||||
case 0:
|
||||
instance->CallJs(success.c_str(), std::string("\"success\",null").c_str(), false);
|
||||
break;
|
||||
case 1:
|
||||
auto&& callback = [instance, success, fail](bool callbackType, int32_t width, int32_t height) {
|
||||
if (callbackType) {
|
||||
instance->CallJs(success.c_str(), std::string("{\"width\":").append(std::to_string(width))
|
||||
.append(", \"height\":").append(std::to_string(height)).append("}").c_str(), false);
|
||||
} else {
|
||||
instance->CallJs(fail.c_str(), std::string("\"fail\",null").c_str(), false);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
};
|
||||
instance->GetDelegate()->HandleImage(src, callback, callbacks);
|
||||
instance->GetDelegate()->HandleImage(src, callback);
|
||||
return JS_NULL;
|
||||
}
|
||||
|
||||
|
@ -92,8 +92,7 @@ public:
|
||||
// ----------------
|
||||
// system.image
|
||||
// ----------------
|
||||
virtual void HandleImage(
|
||||
const std::string& src, std::function<void(int32_t)>&& callback, const std::set<std::string>& callbacks) = 0;
|
||||
virtual void HandleImage(const std::string& src, std::function<void(bool, int32_t, int32_t)>&& callback) = 0;
|
||||
|
||||
// ----------------
|
||||
// internal.jsResult
|
||||
|
@ -1294,29 +1294,19 @@ void FrontendDelegateImpl::RegisterFont(const std::string& familyName, const std
|
||||
pipelineContextHolder_.Get()->RegisterFont(familyName, familySrc);
|
||||
}
|
||||
|
||||
void FrontendDelegateImpl::HandleImage(
|
||||
const std::string& src, std::function<void(int32_t)>&& callback, const std::set<std::string>& callbacks)
|
||||
void FrontendDelegateImpl::HandleImage(const std::string& src, std::function<void(bool, int32_t, int32_t)>&& callback)
|
||||
{
|
||||
if (src.empty() || !callback) {
|
||||
return;
|
||||
}
|
||||
std::map<std::string, EventMarker> callbackMarkers;
|
||||
if (callbacks.find("success") != callbacks.end()) {
|
||||
auto successEventMarker = BackEndEventManager<void()>::GetInstance().GetAvailableMarker();
|
||||
successEventMarker.SetPreFunction([callback, taskExecutor = taskExecutor_]() {
|
||||
taskExecutor->PostTask([callback] { callback(0); }, TaskExecutor::TaskType::JS);
|
||||
});
|
||||
callbackMarkers.emplace("success", successEventMarker);
|
||||
}
|
||||
|
||||
if (callbacks.find("fail") != callbacks.end()) {
|
||||
auto failEventMarker = BackEndEventManager<void()>::GetInstance().GetAvailableMarker();
|
||||
failEventMarker.SetPreFunction([callback, taskExecutor = taskExecutor_]() {
|
||||
taskExecutor->PostTask([callback] { callback(1); }, TaskExecutor::TaskType::JS);
|
||||
});
|
||||
callbackMarkers.emplace("fail", failEventMarker);
|
||||
}
|
||||
pipelineContextHolder_.Get()->CanLoadImage(src, callbackMarkers);
|
||||
auto loadCallback = [jsCallback = std::move(callback),taskExecutor = taskExecutor_](bool success,
|
||||
int32_t width, int32_t height) {
|
||||
taskExecutor->PostTask([callback = std::move(jsCallback), success, width, height] {
|
||||
callback(success, width, height);
|
||||
}, TaskExecutor::TaskType::JS);
|
||||
};
|
||||
pipelineContextHolder_.Get()->TryLoadImageInfo(src, std::move(loadCallback));
|
||||
}
|
||||
|
||||
void FrontendDelegateImpl::RequestAnimationFrame(const std::string& callbackId)
|
||||
|
@ -196,8 +196,7 @@ public:
|
||||
|
||||
void RegisterFont(const std::string& familyName, const std::string& familySrc) override;
|
||||
|
||||
void HandleImage(const std::string& src, std::function<void(int32_t)>&& callback,
|
||||
const std::set<std::string>& callbacks) override;
|
||||
void HandleImage(const std::string& src, std::function<void(bool, int32_t, int32_t)>&& callback) override;
|
||||
|
||||
void RequestAnimationFrame(const std::string& callbackId) override;
|
||||
|
||||
|
@ -501,25 +501,20 @@ sk_sp<SkImage> ImageProvider::GetSkImage(
|
||||
return image;
|
||||
}
|
||||
|
||||
void RenderImageProvider::CanLoadImage(
|
||||
const RefPtr<PipelineContext>& context, const std::string& src, const std::map<std::string, EventMarker>& callbacks)
|
||||
void RenderImageProvider::TryLoadImageInfo(const RefPtr<PipelineContext>& context, const std::string& src,
|
||||
std::function<void(bool, int32_t, int32_t)>&& loadCallback)
|
||||
{
|
||||
if (callbacks.find("success") == callbacks.end() || callbacks.find("fail") == callbacks.end()) {
|
||||
return;
|
||||
}
|
||||
auto onSuccess = AceAsyncEvent<void()>::Create(callbacks.at("success"), context);
|
||||
auto onFail = AceAsyncEvent<void()>::Create(callbacks.at("fail"), context);
|
||||
auto imageProvider = ImageProvider::Create(src, nullptr);
|
||||
if (imageProvider) {
|
||||
auto assetManager = context->GetAssetManager();
|
||||
BackgroundTaskExecutor::GetInstance().PostTask(
|
||||
[src, imageProvider, onSuccess, onFail, assetManager]() {
|
||||
[src, imageProvider, callback = std::move(loadCallback), assetManager]() {
|
||||
auto image = imageProvider->GetSkImage(src, assetManager);
|
||||
if (image) {
|
||||
onSuccess();
|
||||
callback(true, image->width(), image->height());
|
||||
return;
|
||||
}
|
||||
onFail();
|
||||
callback(false, 0, 0);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
@ -29,8 +29,8 @@ class RenderImageProvider : public virtual AceType {
|
||||
DECLARE_ACE_TYPE(RenderImageProvider, AceType);
|
||||
|
||||
public:
|
||||
static void CanLoadImage(const RefPtr<PipelineContext>& context, const std::string& src,
|
||||
const std::map<std::string, EventMarker>& callbacks);
|
||||
static void TryLoadImageInfo(const RefPtr<PipelineContext>& context, const std::string& src,
|
||||
std::function<void(bool, int32_t, int32_t)>&& loadCallback);
|
||||
};
|
||||
|
||||
} // namespace OHOS::Ace
|
||||
|
@ -1563,9 +1563,10 @@ void PipelineContext::RegisterFont(const std::string& familyName, const std::str
|
||||
fontManager_->RegisterFont(familyName, familySrc, AceType::Claim(this));
|
||||
}
|
||||
|
||||
void PipelineContext::CanLoadImage(const std::string& src, const std::map<std::string, EventMarker>& callbacks)
|
||||
void PipelineContext::TryLoadImageInfo(const std::string& src,
|
||||
std::function<void(bool, int32_t, int32_t)>&& loadCallback)
|
||||
{
|
||||
RenderImageProvider::CanLoadImage(AceType::Claim(this), src, callbacks);
|
||||
RenderImageProvider::TryLoadImageInfo(AceType::Claim(this), src, std::move(loadCallback));
|
||||
}
|
||||
|
||||
void PipelineContext::SetAnimationCallback(AnimationCallback&& callback)
|
||||
|
@ -397,7 +397,7 @@ public:
|
||||
|
||||
void RegisterFont(const std::string& familyName, const std::string& familySrc);
|
||||
|
||||
void CanLoadImage(const std::string& src, const std::map<std::string, EventMarker>& callbacks);
|
||||
void TryLoadImageInfo(const std::string& src, std::function<void(bool, int32_t, int32_t)>&& loadCallback);
|
||||
|
||||
void SetAnimationCallback(AnimationCallback&& callback);
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user