From badecc9d791cfc37242a692da21f85a3f4bde6f5 Mon Sep 17 00:00:00 2001 From: jiangdayuan Date: Thu, 10 Feb 2022 15:22:03 +0800 Subject: [PATCH] add window move Signed-off-by: jiangdayuan Change-Id: Ibcdb6e3f8919c58081633fa37480ce04132a77e4 --- adapter/ohos/entrance/ui_content_impl.cpp | 7 +++++++ .../core/components/box/box_component.h | 12 ++++++++++++ frameworks/core/components/box/render_box.cpp | 1 + .../container_modal_component.cpp | 19 +++++++++++++++++-- .../container_modal_component.h | 2 +- .../unittest/mock/container_modal_mock.cpp | 3 ++- frameworks/core/pipeline/pipeline_context.h | 19 ++++++++++++++++--- 7 files changed, 56 insertions(+), 7 deletions(-) diff --git a/adapter/ohos/entrance/ui_content_impl.cpp b/adapter/ohos/entrance/ui_content_impl.cpp index 4df749a08ce..60ac1273ed5 100644 --- a/adapter/ohos/entrance/ui_content_impl.cpp +++ b/adapter/ohos/entrance/ui_content_impl.cpp @@ -537,6 +537,13 @@ void UIContentImpl::InitWindowCallback(const std::shared_ptrClose()); }); + pipelineContext->SetWindowStartMoveCallBack([&window]() { + if (!window) { + return; + } + window->StartMove(); + }); + pipelineContext->SetWindowSplitCallBack([&window]() -> bool { if (!window) { return false; diff --git a/frameworks/core/components/box/box_component.h b/frameworks/core/components/box/box_component.h index 040e11ac366..ddea04d06ee 100644 --- a/frameworks/core/components/box/box_component.h +++ b/frameworks/core/components/box/box_component.h @@ -21,6 +21,7 @@ #include "core/components/common/properties/color.h" #include "core/components/common/properties/decoration.h" #include "core/gestures/gesture_info.h" +#include "core/gestures/raw_recognizer.h" namespace OHOS::Ace { @@ -146,6 +147,16 @@ public: return onMouseId_; } + void SetOnTouchMoveId(const OnTouchEventCallback& onTouchMoveId) + { + onTouchMoveId_ = onTouchMoveId; + } + + const OnTouchEventCallback& GetOnTouchMoveId() const + { + return onTouchMoveId_; + } + RefPtr GetOnClick() const { return onClickId_; @@ -311,6 +322,7 @@ private: OnDropFunc onDropId_; OnHoverCallback onHoverId_; OnMouseCallback onMouseId_; + OnTouchEventCallback onTouchMoveId_; RefPtr onClickId_; RefPtr onLongPressId_; std::array, 3> gestures_; diff --git a/frameworks/core/components/box/render_box.cpp b/frameworks/core/components/box/render_box.cpp index 0d75dd653a0..7deb27fdd77 100644 --- a/frameworks/core/components/box/render_box.cpp +++ b/frameworks/core/components/box/render_box.cpp @@ -158,6 +158,7 @@ void RenderBox::Update(const RefPtr& component) box->HandleTouchEvent(false); } }); + touchRecognizer_->SetOnTouchMove(box->GetOnTouchMoveId()); } // In each update, the extensions will be updated with new one. if (eventExtensions_ && eventExtensions_->HasOnAreaChangeExtension()) { diff --git a/frameworks/core/components/container_modal/container_modal_component.cpp b/frameworks/core/components/container_modal/container_modal_component.cpp index 57c84ea461b..94d47847c40 100644 --- a/frameworks/core/components/container_modal/container_modal_component.cpp +++ b/frameworks/core/components/container_modal/container_modal_component.cpp @@ -52,7 +52,7 @@ const Color TITLE_BUTTON_CLICKED_COLOR = Color(0x33000000); } // namespace RefPtr ContainerModalComponent::Create(const WeakPtr& context, - RefPtr child) + const RefPtr& child) { auto component = AceType::MakeRefPtr(context); component->SetChild(child); @@ -160,8 +160,23 @@ RefPtr ContainerModalComponent::BuildTitle() titleBox->SetHeight(CONTAINER_TITLE_HEIGHT); titleBox->SetBackDecoration(titleDecoration); auto row = AceType::MakeRefPtr(FlexAlign::FLEX_START, FlexAlign::CENTER, titleChildren); - titleBox->SetChild(row); + // handle mouse move + titleBox->SetOnMouseId([contextWptr](MouseInfo& info) { + auto context = contextWptr.Upgrade(); + if (context && info.GetButton() == MouseButton::LEFT_BUTTON && info.GetAction() == MouseAction::MOVE) { + context->FireWindowStartMoveCallBack(); + } + }); + + // handle touch move + titleBox->SetOnTouchMoveId([contextWptr](const TouchEventInfo&) { + auto context = contextWptr.Upgrade(); + if (context) { + context->FireWindowStartMoveCallBack(); + } + }); + titleBox->SetChild(row); return titleBox; } diff --git a/frameworks/core/components/container_modal/container_modal_component.h b/frameworks/core/components/container_modal/container_modal_component.h index 8330f0c3e5d..56be995678d 100644 --- a/frameworks/core/components/container_modal/container_modal_component.h +++ b/frameworks/core/components/container_modal/container_modal_component.h @@ -30,7 +30,7 @@ public: } ~ContainerModalComponent() override = default; - static RefPtr Create(const WeakPtr& context, RefPtr child); + static RefPtr Create(const WeakPtr& context, const RefPtr& child); RefPtr CreateElement() override; RefPtr CreateRenderNode() override; void BuildInnerChild(); diff --git a/frameworks/core/components/test/unittest/mock/container_modal_mock.cpp b/frameworks/core/components/test/unittest/mock/container_modal_mock.cpp index a3ebf4d3557..3303ffcb348 100644 --- a/frameworks/core/components/test/unittest/mock/container_modal_mock.cpp +++ b/frameworks/core/components/test/unittest/mock/container_modal_mock.cpp @@ -18,7 +18,8 @@ namespace OHOS::Ace { -RefPtr ContainerModalComponent::Create(const WeakPtr& context, RefPtr child) +RefPtr ContainerModalComponent::Create(const WeakPtr& context, + const RefPtr& child) { return nullptr; } diff --git a/frameworks/core/pipeline/pipeline_context.h b/frameworks/core/pipeline/pipeline_context.h index 61df8a53260..2e13d185d65 100644 --- a/frameworks/core/pipeline/pipeline_context.h +++ b/frameworks/core/pipeline/pipeline_context.h @@ -1009,7 +1009,7 @@ public: return isShiftDown_; } - void MarkIsShiftDown(bool isShiftDown) + void MarkIsShiftDown(bool isShiftDown) { isShiftDown_ = isShiftDown; } @@ -1019,7 +1019,7 @@ public: return isCtrlDown_; } - void MarkIsCtrlDown(bool isCtrlDown) + void MarkIsCtrlDown(bool isCtrlDown) { isCtrlDown_ = isCtrlDown; } @@ -1029,7 +1029,7 @@ public: return isKeyboardA_; } - void MarkIsKeyboardA(bool isKeyboardA) + void MarkIsKeyboardA(bool isKeyboardA) { isKeyboardA_ = isKeyboardA; } @@ -1076,6 +1076,11 @@ public: windowGetModeCallback_ = std::move(callback); } + void SetWindowStartMoveCallBack(std::function&& callback) + { + windowStartMoveCallback_ = std::move(callback); + } + bool FireWindowMinimizeCallBack() const { if (windowMinimizeCallback_) { @@ -1116,6 +1121,13 @@ public: return false; } + void FireWindowStartMoveCallBack() const + { + if (windowStartMoveCallback_) { + windowStartMoveCallback_(); + } + } + WindowMode FireWindowGetModeCallBack() const { if (windowGetModeCallback_) { @@ -1369,6 +1381,7 @@ private: std::function windowRecoverCallback_ = nullptr; std::function windowCloseCallback_ = nullptr; std::function windowSplitCallback_ = nullptr; + std::function windowStartMoveCallback_ = nullptr; std::function windowGetModeCallback_ = nullptr; ACE_DISALLOW_COPY_AND_MOVE(PipelineContext); -- Gitee