/*
- * Copyright (c) 2021 Samsung Electronics Co., Ltd.
+ * Copyright (c) 2022 Samsung Electronics Co., Ltd.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
using namespace Dali;
-ImageView::ImageView()
-: Control(ControlBehaviour(CONTROL_BEHAVIOUR_DEFAULT)),
+ImageView::ImageView(ControlBehaviour additionalBehaviour)
+: Control(ControlBehaviour(CONTROL_BEHAVIOUR_DEFAULT | additionalBehaviour)),
mImageSize(),
mImageVisualPaddingSetByTransform(false),
mImageViewPixelAreaSetByFittingMode(false)
{
}
-Toolkit::ImageView ImageView::New()
+Toolkit::ImageView ImageView::New(ControlBehaviour additionalBehaviour)
{
- ImageView* impl = new ImageView();
+ ImageView* impl = new ImageView(additionalBehaviour);
Toolkit::ImageView handle = Toolkit::ImageView(*impl);
Dali::Toolkit::Control handle(GetOwner());
handle.ResourceReadySignal().Connect(this, &ImageView::OnResourceReady);
- DevelControl::SetAccessibilityConstructor(Self(), [](Dali::Actor actor) {
- return std::unique_ptr<Dali::Accessibility::Accessible>(
- new DevelControl::ControlAccessible(actor, Dali::Accessibility::Role::IMAGE));
- });
+ Self().SetProperty(DevelControl::Property::ACCESSIBILITY_ROLE, Dali::Accessibility::Role::IMAGE);
}
void ImageView::SetImage(const Property::Map& map)
// Signal that a Relayout may be needed
}
+void ImageView::ClearImageVisual()
+{
+ // Clear cached properties
+ mPropertyMap.Clear();
+ mUrl.clear();
+
+ // Unregister the exsiting visual
+ DevelControl::UnregisterVisual(*this, Toolkit::ImageView::Property::IMAGE);
+
+ // Trigger a size negotiation request that may be needed when unregistering a visual.
+ RelayoutRequest();
+}
+
void ImageView::EnablePreMultipliedAlpha(bool preMultipled)
{
if(mVisual)
else
{
map = value.GetMap();
- if(map)
+ if(DALI_LIKELY(map))
{
- Property::Value* shaderValue = map->Find(Toolkit::Visual::Property::SHADER, CUSTOM_SHADER);
- // set image only if property map contains image information other than custom shader
- if(map->Count() > 1u || !shaderValue)
+ // the property map is emtpy map. Unregister visual.
+ if(DALI_UNLIKELY(map->Count() == 0u))
{
- impl.SetImage(*map);
+ impl.ClearImageVisual();
}
- // the property map contains only the custom shader
- else if((map->Count() == 1u) && (shaderValue))
+ else
{
- Property::Map* shaderMap = shaderValue->GetMap();
- if(shaderMap)
+ Property::Value* shaderValue = map->Find(Toolkit::Visual::Property::SHADER, CUSTOM_SHADER);
+ // set image only if property map contains image information other than custom shader
+ if(map->Count() > 1u || !shaderValue)
{
- impl.mShaderMap = *shaderMap;
-
- if(!impl.mUrl.empty())
- {
- impl.SetImage(impl.mUrl, impl.mImageSize);
- }
- else if(!impl.mPropertyMap.Empty())
+ impl.SetImage(*map);
+ }
+ // the property map contains only the custom shader
+ else if((map->Count() == 1u) && (shaderValue))
+ {
+ Property::Map* shaderMap = shaderValue->GetMap();
+ if(shaderMap)
{
- impl.SetImage(impl.mPropertyMap);
+ impl.mShaderMap = *shaderMap;
+
+ if(!impl.mUrl.empty())
+ {
+ impl.SetImage(impl.mUrl, impl.mImageSize);
+ }
+ else if(!impl.mPropertyMap.Empty())
+ {
+ impl.SetImage(impl.mPropertyMap);
+ }
}
}
}
}
+ else
+ {
+ // invalid property value comes. Unregister visual.
+ impl.ClearImageVisual();
+ }
}
break;
}