!2120 新增窗口内容裁剪边角

Merge pull request !2120 from jiangdayuan/master
This commit is contained in:
openharmony_ci
2022-03-31 10:57:42 +00:00
committed by Gitee
9 changed files with 73 additions and 84 deletions
+12 -20
View File
@@ -571,6 +571,10 @@ void AceAbility::OnRemoteTerminated()
void AceAbility::OnSizeChange(OHOS::Rosen::Rect rect, OHOS::Rosen::WindowSizeChangeReason reason)
{
LOGI("AceAbility::OnSizeChange width: %{public}u, height: %{public}u, left: %{public}d, top: %{public}d",
rect.width_, rect.height_, rect.posX_, rect.posY_);
SystemProperties::SetDeviceOrientation(rect.height_ >= rect.width_ ? 0 : 1);
SystemProperties::SetWindowPos(rect.posX_, rect.posY_);
auto container = Platform::AceContainer::GetContainer(abilityId_);
if (!container) {
LOGE("OnSizeChange: container is null.");
@@ -581,33 +585,20 @@ void AceAbility::OnSizeChange(OHOS::Rosen::Rect rect, OHOS::Rosen::WindowSizeCha
LOGE("OnSizeChange: taskExecutor is null.");
return;
}
taskExecutor->PostTask(
[rect, abilityId = abilityId_, density = density_, reason]() {
uint32_t width = rect.width_;
uint32_t height = rect.height_;
LOGI("AceAbility::OnSizeChange width: %{public}u, height: %{public}u, left: %{public}d, top: %{public}d",
width, height, rect.posX_, rect.posY_);
SystemProperties::SetDeviceOrientation(height >= width ? 0 : 1);
SystemProperties::SetWindowPos(rect.posX_, rect.posY_);
auto container = Platform::AceContainer::GetContainer(abilityId);
if (!container) {
LOGE("container may be destroyed.");
return;
}
taskExecutor->PostTask([rect, density = density_, reason, container]() {
auto flutterAceView = static_cast<Platform::FlutterAceView*>(container->GetView());
if (!flutterAceView) {
LOGE("flutterAceView is null");
LOGE("OnSizeChange: flutterAceView is null.");
return;
}
flutter::ViewportMetrics metrics;
metrics.physical_width = width;
metrics.physical_height = height;
metrics.physical_width = rect.width_;
metrics.physical_height = rect.height_;
metrics.device_pixel_ratio = density;
Platform::FlutterAceView::SetViewportMetrics(flutterAceView, metrics);
Platform::FlutterAceView::SurfaceChanged(
flutterAceView, width, height, 0, static_cast<WindowSizeChangeReason>(reason));
},
TaskExecutor::TaskType::PLATFORM);
Platform::FlutterAceView::SurfaceChanged(flutterAceView, rect.width_, rect.height_,
rect.height_ >= rect.width_ ? 0 : 1, static_cast<WindowSizeChangeReason>(reason));
}, TaskExecutor::TaskType::PLATFORM);
}
void AceAbility::OnModeChange(OHOS::Rosen::WindowMode mode)
@@ -623,6 +614,7 @@ void AceAbility::OnModeChange(OHOS::Rosen::WindowMode mode)
LOGE("OnModeChange failed: taskExecutor is null.");
return;
}
ContainerScope scope(abilityId_);
taskExecutor->PostTask([container, mode]() {
auto pipelineContext = container->GetPipelineContext();
if (!pipelineContext) {
+7 -13
View File
@@ -511,6 +511,7 @@ void UIContentImpl::Focus()
LOGE("Window focus failed: taskExecutor is null.");
return;
}
ContainerScope scope(instanceId_);
taskExecutor->PostTask([container]() {
auto pipelineContext = container->GetPipelineContext();
if (!pipelineContext) {
@@ -535,6 +536,7 @@ void UIContentImpl::UnFocus()
LOGE("Window unFocus failed: taskExecutor is null.");
return;
}
ContainerScope scope(instanceId_);
taskExecutor->PostTask([container]() {
auto pipelineContext = container->GetPipelineContext();
if (!pipelineContext) {
@@ -607,7 +609,6 @@ void UIContentImpl::UpdateViewportConfig(const ViewportConfig& config, OHOS::Ros
{
LOGI("UIContent UpdateViewportConfig %{public}s", config.ToString().c_str());
SystemProperties::SetResolution(config.Density());
SystemProperties::SetColorMode(ColorMode::LIGHT);
SystemProperties::SetDeviceOrientation(config.Height() >= config.Width() ? 0 : 1);
SystemProperties::SetWindowPos(config.Left(), config.Top());
auto container = Platform::AceContainer::GetContainer(instanceId_);
@@ -620,17 +621,10 @@ void UIContentImpl::UpdateViewportConfig(const ViewportConfig& config, OHOS::Ros
LOGE("UpdateViewportConfig: taskExecutor is null.");
return;
}
taskExecutor->PostTask(
[config, instanceId = instanceId_, reason]() {
auto container = Platform::AceContainer::GetContainer(instanceId);
if (!container) {
LOGE("container may be destroyed.");
return;
}
taskExecutor->PostTask([config, container, reason]() {
auto aceView = static_cast<Platform::FlutterAceView*>(container->GetAceView());
if (!aceView) {
LOGE("aceView is null");
LOGE("UpdateViewportConfig: aceView is null.");
return;
}
flutter::ViewportMetrics metrics;
@@ -640,8 +634,7 @@ void UIContentImpl::UpdateViewportConfig(const ViewportConfig& config, OHOS::Ros
Platform::FlutterAceView::SetViewportMetrics(aceView, metrics);
Platform::FlutterAceView::SurfaceChanged(aceView, config.Width(), config.Height(), config.Orientation(),
static_cast<WindowSizeChangeReason>(reason));
},
TaskExecutor::TaskType::PLATFORM);
}, TaskExecutor::TaskType::PLATFORM);
}
void UIContentImpl::UpdateWindowMode(OHOS::Rosen::WindowMode mode)
@@ -657,6 +650,7 @@ void UIContentImpl::UpdateWindowMode(OHOS::Rosen::WindowMode mode)
LOGE("UpdateWindowMode failed: taskExecutor is null.");
return;
}
ContainerScope scope(instanceId_);
taskExecutor->PostTask([container, mode]() {
auto pipelineContext = container->GetPipelineContext();
if (!pipelineContext) {
@@ -764,7 +758,7 @@ void UIContentImpl::InitializeSubWindow(OHOS::Rosen::Window* window)
std::weak_ptr<OHOS::AbilityRuntime::Context> runtimeContext;
container = AceType::MakeRefPtr<Platform::AceContainer>(instanceId_, FrontendType::DECLARATIVE_JS, true,
runtimeContext, abilityInfo, std::make_unique<ContentEventCallback>([] {
// Subwindow ,just return.
// Sub-window ,just return.
LOGI("Content event callback");
}),
false, true);
@@ -73,6 +73,14 @@ public:
offsetY_ = offsetY;
}
void SetClipRadius(const Radius& clipRadius)
{
topLeftRadius_ = clipRadius;
topRightRadius_ = clipRadius;
bottomLeftRadius_ = clipRadius;
bottomRightRadius_ = clipRadius;
}
const Radius& GetTopLeftRadius() const
{
return topLeftRadius_;
@@ -74,7 +74,6 @@ FloatPropertyAnimatable::SetterMap RenderClip::GetFloatPropertySetterMap()
return;
}
clip->SetWidth(value);
clip->MarkNeedRender();
};
map[PropertyAnimatableType::PROPERTY_HEIGHT] = [weak](float value) {
auto clip = weak.Upgrade();
@@ -83,7 +82,6 @@ FloatPropertyAnimatable::SetterMap RenderClip::GetFloatPropertySetterMap()
return;
}
clip->SetHeight(value);
clip->MarkNeedRender();
};
map[PropertyAnimatableType::PROPERTY_OFFSET_X] = [weak](float value) {
auto clip = weak.Upgrade();
@@ -93,7 +91,6 @@ FloatPropertyAnimatable::SetterMap RenderClip::GetFloatPropertySetterMap()
}
clip->SetOffsetX(value);
clip->UpdateBoxForShadowAnimation();
clip->MarkNeedRender();
};
map[PropertyAnimatableType::PROPERTY_OFFSET_Y] = [weak](float value) {
auto clip = weak.Upgrade();
@@ -103,7 +100,6 @@ FloatPropertyAnimatable::SetterMap RenderClip::GetFloatPropertySetterMap()
}
clip->SetOffsetY(value);
clip->UpdateBoxForShadowAnimation();
clip->MarkNeedRender();
};
map[PropertyAnimatableType::PROPERTY_BORDER_RADIUS] = [weak](float value) {
auto clip = weak.Upgrade();
@@ -111,11 +107,7 @@ FloatPropertyAnimatable::SetterMap RenderClip::GetFloatPropertySetterMap()
LOGE("set border radius failed. clip is null.");
return;
}
clip->topLeftRadius_ = Radius(value);
clip->topRightRadius_ = Radius(value);
clip->bottomLeftRadius_ = Radius(value);
clip->bottomRightRadius_ = Radius(value);
clip->MarkNeedRender();
clip->SetClipRadius(Radius(value));
};
return map;
};
@@ -191,7 +183,7 @@ void RenderClip::UpdateBoxForShadowAnimation()
return;
}
// If clip if used for animation, then there will be exist display and transform.
// If clip is used for animation, then there will be existed display and transform.
auto renderTransform = AceType::DynamicCast<RenderTransform>(GetParent().Upgrade());
if (!renderTransform) {
return;
@@ -43,6 +43,7 @@ public:
return;
}
offsetX_ = offsetX;
MarkNeedRender();
}
virtual void SetOffsetY(double offsetY)
@@ -51,6 +52,7 @@ public:
return;
}
offsetY_ = offsetY;
MarkNeedRender();
}
Rect GetClipRect(const Offset& offset) const;
@@ -61,6 +63,7 @@ public:
return;
}
width_ = width;
MarkNeedRender();
}
virtual void SetHeight(double height)
@@ -69,6 +72,7 @@ public:
return;
}
height_ = height;
MarkNeedRender();
}
double GetHeight() const
@@ -83,6 +87,15 @@ public:
void Dump() override;
void SetClipRadius(const Radius& clipRadius)
{
topLeftRadius_ = clipRadius;
topRightRadius_ = clipRadius;
bottomLeftRadius_ = clipRadius;
bottomRightRadius_ = clipRadius;
MarkNeedRender();
}
protected:
double width_ = 0.0;
double height_ = 0.0;
@@ -22,23 +22,6 @@
namespace OHOS::Ace {
void RosenRenderClip::Update(const RefPtr<Component>& component)
{
RenderClip::Update(component);
auto rsNode = GetRSNode();
if (!rsNode) {
return;
}
auto context = context_.Upgrade();
if (!context) {
return;
}
double dipScale = context->GetDipScale();
rsNode->SetCornerRadius(topLeftRadius_.GetX().ConvertToPx(dipScale));
rsNode->SetClipToBounds(true);
}
void RosenRenderClip::SetOffsetX(double offsetX)
{
RenderClip::SetOffsetX(offsetX);
@@ -69,6 +52,14 @@ void RosenRenderClip::SyncGeometryProperties()
if (!rsNode) {
return;
}
auto context = context_.Upgrade();
if (!context) {
return;
}
double dipScale = context->GetDipScale();
rsNode->SetCornerRadius(topLeftRadius_.GetX().ConvertToPx(dipScale));
rsNode->SetClipToBounds(true);
Rect paintSize = GetTransitionPaintRect();
Offset paintOffset = GetPaintOffset();
Offset clipOffset = paintOffset + Offset(offsetX_, offsetY_);
@@ -27,8 +27,6 @@ public:
RosenRenderClip() = default;
~RosenRenderClip() override = default;
void Update(const RefPtr<Component>& component) override;
bool HasGeometryProperties() const override
{
return true;
@@ -39,9 +37,6 @@ public:
void SetOffsetY(double offsetY) override;
void SetWidth(double width) override;
void SetHeight(double height) override;
private:
void UpdateClipSize();
};
} // namespace OHOS::Ace
@@ -17,6 +17,7 @@
#include "core/components/box/box_component.h"
#include "core/components/button/button_component.h"
#include "core/components/clip/clip_component.h"
#include "core/components/container_modal/container_modal_constants.h"
#include "core/components/container_modal/container_modal_element.h"
#include "core/components/container_modal/render_container_modal.h"
@@ -95,16 +96,14 @@ RefPtr<Component> ContainerModalComponent::BuildContent()
{
auto contentBox = AceType::MakeRefPtr<BoxComponent>();
contentBox->SetChild(GetChild());
Border contentBorder;
contentBorder.SetBorderRadius(Radius(CONTAINER_INNER_RADIUS));
auto contentDecoration = AceType::MakeRefPtr<Decoration>();
contentDecoration->SetBackgroundColor(CONTENT_BACKGROUND_COLOR);
contentDecoration->SetBorder(contentBorder);
contentBox->SetBackDecoration(contentDecoration);
// adaptive height
contentBox->SetFlexWeight(1.0);
return contentBox;
auto clip = AceType::MakeRefPtr<ClipComponent>(contentBox);
clip->SetClipRadius(Radius(CONTAINER_INNER_RADIUS));
clip->SetFlexWeight(1.0);
return clip;
}
RefPtr<ButtonComponent> ContainerModalComponent::BuildControlButton(
@@ -16,10 +16,11 @@
#include "core/components/container_modal/container_modal_element.h"
#include "core/components/box/box_element.h"
#include "core/components/clip/clip_element.h"
#include "core/components/clip/render_clip.h"
#include "core/components/container_modal/container_modal_constants.h"
#include "core/components/container_modal/render_container_modal.h"
#include "core/components/flex/flex_element.h"
#include "core/components/flex/flex_item_element.h"
#include "core/components/padding/render_padding.h"
#include "core/gestures/tap_gesture.h"
@@ -60,7 +61,13 @@ RefPtr<StackElement> ContainerModalElement::GetStackElement() const
}
// Get second child : content
auto contentBox = AceType::DynamicCast<BoxElement>(column->GetLastChild());
auto clip = AceType::DynamicCast<ClipElement>(column->GetLastChild());
if (!clip) {
LOGE("Get stack element failed, clip element is null!");
return {};
}
auto contentBox = AceType::DynamicCast<BoxElement>(clip->GetFirstChild());
if (!contentBox) {
LOGE("Get stack element failed, content box element is null!");
return {};
@@ -153,17 +160,15 @@ void ContainerModalElement::ShowTitle(bool isShow)
return;
}
// full screen need to hide border.
auto contentRenderBox = AceType::DynamicCast<RenderBox>(column->GetLastChild()->GetRenderNode());
if (contentRenderBox) {
auto contentDecoration = AceType::MakeRefPtr<Decoration>();
contentDecoration->SetBackgroundColor(CONTENT_BACKGROUND_COLOR);
if (isShow) {
Border contentBorder;
contentBorder.SetBorderRadius(Radius(CONTAINER_INNER_RADIUS));
contentDecoration->SetBorder(contentBorder);
}
contentRenderBox->SetBackDecoration(contentDecoration);
// full screen need to hide content border radius.
auto clip = AceType::DynamicCast<ClipElement>(column->GetLastChild());
if (!clip) {
LOGE("ContainerModalElement showTitle failed, clip element is null!");
return;
}
auto renderClip = AceType::DynamicCast<RenderClip>(clip->GetRenderNode());
if (renderClip) {
isShow ? renderClip->SetClipRadius(Radius(CONTAINER_INNER_RADIUS)) : renderClip->SetClipRadius(Radius(0.0));
}
// Get first child : title