From 81e4a52a83f29e8ac9164553e16808be4fa419bc Mon Sep 17 00:00:00 2001 From: fanzexuan Date: Thu, 24 Jul 2025 22:27:50 +0800 Subject: [PATCH] =?UTF-8?q?=E6=94=BE=E5=A4=A7=E6=89=8B=E5=8A=BF=E6=8B=86?= =?UTF-8?q?=E8=A7=A3=E7=AA=97=E5=8F=A3=E7=9A=84=E4=BE=9D=E8=B5=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: fanzexuan --- bundle.json | 3 +- frameworks/aafwk/test/BUILD.gn | 8 +- services/aams/BUILD.gn | 1 + .../include/accessibility_input_interceptor.h | 2 + .../aams/include/accessibility_zoom_gesture.h | 5 +- .../accessible_ability_manager_service.h | 3 + .../full_screen_magnification_manager.h | 47 +- services/aams/include/magnification_def.h | 10 + services/aams/include/magnification_manager.h | 5 + .../aams/include/magnification_menu_manager.h | 53 +- .../aams/include/magnification_window_proxy.h | 76 ++ .../include/window_magnification_gesture.h | 6 +- .../include/window_magnification_manager.h | 66 +- .../src/accessibility_input_interceptor.cpp | 97 +- .../aams/src/accessibility_zoom_gesture.cpp | 45 +- .../accessible_ability_manager_service.cpp | 31 +- .../src/full_screen_magnification_manager.cpp | 388 ++------ services/aams/src/magnification_manager.cpp | 43 +- .../aams/src/magnification_menu_manager.cpp | 304 +----- .../aams/src/magnification_window_proxy.cpp | 485 +++++++++ .../aams/src/window_magnification_gesture.cpp | 42 +- .../aams/src/window_magnification_manager.cpp | 497 +--------- services/aams/test/BUILD.gn | 15 +- ...ock_accessible_ability_manager_service.cpp | 16 + ...mock_full_screen_magnification_manager.cpp | 34 +- .../mock/src/mock_magnification_manager.cpp | 5 + .../src/mock_magnification_menu_manager.cpp | 64 ++ .../src/mock_window_magnification_manager.cpp | 120 +++ .../accessibility_zoom_gesture_test.cpp | 4 +- services/aams_ext/BUILD.gn | 77 ++ .../aams_ext/include/magnification_menu.h | 84 ++ .../aams_ext/include/magnification_window.h | 121 +++ services/aams_ext/include/visibility.h | 22 + services/aams_ext/src/magnification_menu.cpp | 345 +++++++ .../aams_ext/src/magnification_window.cpp | 921 ++++++++++++++++++ services/test/BUILD.gn | 6 + 36 files changed, 2730 insertions(+), 1321 deletions(-) create mode 100644 services/aams/include/magnification_window_proxy.h create mode 100644 services/aams/src/magnification_window_proxy.cpp create mode 100644 services/aams/test/mock/src/mock_magnification_menu_manager.cpp create mode 100644 services/aams/test/mock/src/mock_window_magnification_manager.cpp create mode 100644 services/aams_ext/BUILD.gn create mode 100644 services/aams_ext/include/magnification_menu.h create mode 100644 services/aams_ext/include/magnification_window.h create mode 100644 services/aams_ext/include/visibility.h create mode 100644 services/aams_ext/src/magnification_menu.cpp create mode 100644 services/aams_ext/src/magnification_window.cpp diff --git a/bundle.json b/bundle.json index 14cc859b..79cc1bf2 100644 --- a/bundle.json +++ b/bundle.json @@ -92,7 +92,8 @@ "//foundation/barrierfree/accessibility/sa_profile:aams_sa_profile", "//foundation/barrierfree/accessibility/sa_profile:accessibility_cfg", "//foundation/barrierfree/accessibility/services/aams:accessibleabilityms", - "//foundation/barrierfree/accessibility/services/etc:ohos.para.dac" + "//foundation/barrierfree/accessibility/services/etc:ohos.para.dac", + "//foundation/barrierfree/accessibility/services/aams_ext:aams_ext" ] }, "inner_api": [ diff --git a/frameworks/aafwk/test/BUILD.gn b/frameworks/aafwk/test/BUILD.gn index 7ec22b12..b5aa4833 100755 --- a/frameworks/aafwk/test/BUILD.gn +++ b/frameworks/aafwk/test/BUILD.gn @@ -127,11 +127,11 @@ ohos_unittest("accessible_ability_test") { "../../../services/aams/src/accessible_ability_manager_service.cpp", "../../../services/aams/src/accessible_ability_manager_service_event_handler.cpp", "../../../services/aams/src/utils.cpp", - "../../../services/aams/src/magnification_manager.cpp", + "../../../services/aams/test/mock/src/mock_magnification_manager.cpp", "../../../services/aams/src/window_magnification_gesture.cpp", - "../../../services/aams/src/magnification_menu_manager.cpp", - "../../../services/aams/src/full_screen_magnification_manager.cpp", - "../../../services/aams/src/window_magnification_manager.cpp", + "../../../services/aams/test/mock/src/mock_magnification_menu_manager.cpp", + "../../../services/aams/test/mock/src/mock_full_screen_magnification_manager.cpp", + "../../../services/aams/test/mock/src/mock_window_magnification_manager.cpp", "../../../services/aams/test/mock/src/mock_accessibility_account_data.cpp", "../../../services/aams/test/mock/src/mock_accessibility_common_event.cpp", "../../../services/aams/test/mock/src/mock_accessibility_event_transmission.cpp", diff --git a/services/aams/BUILD.gn b/services/aams/BUILD.gn index a070c39d..a296d4d8 100644 --- a/services/aams/BUILD.gn +++ b/services/aams/BUILD.gn @@ -81,6 +81,7 @@ accessibleabilityms_files = [ "${services_path}/src/window_magnification_gesture.cpp", "${services_path}/src/magnification_menu_manager.cpp", "${services_path}/src/full_screen_magnification_manager.cpp", + "${services_path}/src/magnification_window_proxy.cpp", ] ohos_shared_library("accessibleabilityms") { diff --git a/services/aams/include/accessibility_input_interceptor.h b/services/aams/include/accessibility_input_interceptor.h index 7d608e85..be03c69a 100644 --- a/services/aams/include/accessibility_input_interceptor.h +++ b/services/aams/include/accessibility_input_interceptor.h @@ -99,6 +99,8 @@ private: void UpdateInterceptor(); void DestroyInterceptor(); void CreateMagnificationGesture(sptr &header, sptr ¤t); + void CreatZoomGesture(); + void CreatWindowMagnificationGesture(); void ClearMagnificationGesture(); sptr pointerEventTransmitters_ = nullptr; diff --git a/services/aams/include/accessibility_zoom_gesture.h b/services/aams/include/accessibility_zoom_gesture.h index e084f001..afc856a5 100644 --- a/services/aams/include/accessibility_zoom_gesture.h +++ b/services/aams/include/accessibility_zoom_gesture.h @@ -21,6 +21,7 @@ #include "pointer_event.h" #include "dm_common.h" #include "full_screen_magnification_manager.h" +#include "magnification_menu_manager.h" namespace OHOS { namespace Accessibility { @@ -43,7 +44,8 @@ struct ZOOM_FOCUS_COORDINATE { class AccessibilityZoomGesture : public EventTransmission { public: - AccessibilityZoomGesture(std::shared_ptr fullScreenManager); + AccessibilityZoomGesture(std::shared_ptr fullScreenManager, + std::shared_ptr menuManager); ~AccessibilityZoomGesture() = default; virtual bool OnPointerEvent(MMI::PointerEvent &event) override; @@ -137,6 +139,7 @@ private: std::shared_ptr zoomGestureEventHandler_ = nullptr; std::vector> cacheEvents_; std::shared_ptr fullScreenManager_ = nullptr; + std::shared_ptr menuManager_ = nullptr; std::atomic shieldZoomGestureFlag_ = false; bool isTapOnMenu_ = false; diff --git a/services/aams/include/accessible_ability_manager_service.h b/services/aams/include/accessible_ability_manager_service.h index 820ff537..b9035a5e 100644 --- a/services/aams/include/accessible_ability_manager_service.h +++ b/services/aams/include/accessible_ability_manager_service.h @@ -343,11 +343,14 @@ public: std::shared_ptr GetMagnificationMgr(); std::shared_ptr GetWindowMagnificationManager(); std::shared_ptr GetFullScreenMagnificationManager(); + std::shared_ptr GetMenuManager(); ErrCode AnnouncedForAccessibility(const std::string &announcedText); void InitResource(bool needReInit); std::string &GetResource(const std::string &resourceName); void AnnouncedForMagnification(AnnounceType announceType); void OffZoomGesture(); + void InitMagnification(); + void OnModeChanged(uint32_t mode); RetError UpdateUITestConfigureEvents(std::vector needEvents); diff --git a/services/aams/include/full_screen_magnification_manager.h b/services/aams/include/full_screen_magnification_manager.h index 309cbcce..cb21a736 100644 --- a/services/aams/include/full_screen_magnification_manager.h +++ b/services/aams/include/full_screen_magnification_manager.h @@ -16,18 +16,10 @@ #ifndef FULL_SCREEN_MAGNIFICATION_MANAGER_H #define FULL_SCREEN_MAGNIFICATION_MANAGER_H -#include "window.h" -#include "window_option.h" -#include -#include -#include -#include "ui/rs_ui_context.h" -#include "ui/rs_ui_director.h" -#include "ui/rs_root_node.h" -#include "recording/recording_canvas.h" #include "hilog_wrapper.h" #include "magnification_def.h" #include "ffrt.h" +#include "magnification_window_proxy.h" namespace OHOS { namespace Accessibility { @@ -35,10 +27,9 @@ namespace Accessibility { class FullScreenMagnificationManager { public: FullScreenMagnificationManager(); + explicit FullScreenMagnificationManager(std::shared_ptr proxy); ~FullScreenMagnificationManager() = default; - void CreateMagnificationWindow(); - void DrawRuoundRectFrame(); void EnableMagnification(int32_t centerX, int32_t centerY); void ShowMagnification(); void ShowMagnificationWithPosition(PointerPos pos); @@ -52,39 +43,11 @@ public: uint32_t CheckTapOnHotArea(int32_t posX, int32_t posY); void FollowFocuseElement(int32_t centerX, int32_t centerY); PointerPos GetSourceCenter(); - inline bool IsMagnificationWindowShow() - { - return isMagnificationWindowShow_; - } - inline float GetScale() - { - return scale_; - } + bool IsMagnificationWindowShow(); + float GetScale(); private: - void GetWindowParam(); - void InitMagnificationParam(); - Rosen::Rect GetSourceRectFromPointer(int32_t centerX, int32_t centerY); - void UpdateAnchor(); - PointerPos GetRectCenter(Rosen::Rect rect); - void FlushImplicitTransaction(); - sptr window_ = nullptr; - std::shared_ptr surfaceNode_ = nullptr; - std::shared_ptr canvasNode_ = nullptr; - std::shared_ptr rsUIContext_ = nullptr; - bool isMagnificationWindowShow_ = false; - - Rosen::Rect sourceRect_ = {0, 0, 0, 0}; - Rosen::Rect windowRect_ = {0, 0, 0, 0}; - Rosen::Rect screenRect_ = {0, 0, 0, 0}; - uint32_t screenWidth_ = 0; - uint32_t screenHeight_ = 0; - float screenSpan_ = 0.0f; - uint64_t screenId_ = 0; - Rosen::DisplayOrientation orientation_ = Rosen::DisplayOrientation::UNKNOWN; - int32_t centerX_ = 0; - int32_t centerY_ = 0; - float scale_ = 2.0f; ffrt::mutex mutex_; + std::shared_ptr windowProxy_ = nullptr; }; } // namespace Accessibility } // namespace OHOS diff --git a/services/aams/include/magnification_def.h b/services/aams/include/magnification_def.h index fb99f251..c6ea42d1 100644 --- a/services/aams/include/magnification_def.h +++ b/services/aams/include/magnification_def.h @@ -16,6 +16,8 @@ #ifndef MAGNIFICATION_MANAGER_DEF_H #define MAGNIFICATION_MANAGER_DEF_H +#include + namespace OHOS { namespace Accessibility { @@ -47,6 +49,14 @@ constexpr int32_t SCROLL_SHOT_POINTER_ID = 20001; constexpr int32_t DEFAULT_POINTER_ID = 0; constexpr uint32_t TAP_COUNT_TWO = 2; +constexpr uint32_t MAGNIFY_WINDOW_WIDTH = 940; +constexpr uint32_t MAGNIFY_WINDOW_HEIGHT = 550; +constexpr uint32_t BAR_MARGIN = 40; +constexpr uint32_t HOT_AREA_WIDTH = 60; +constexpr int32_t GESTURE_OFFSET = 100; +constexpr int32_t BAR_START = 400; +constexpr int32_t BAR_END = 550; + const std::string WINDOW_NAME = "magnification_window"; const std::string MENU_NAME = "magnification_menu"; diff --git a/services/aams/include/magnification_manager.h b/services/aams/include/magnification_manager.h index d44e1cd4..5fe2c27a 100644 --- a/services/aams/include/magnification_manager.h +++ b/services/aams/include/magnification_manager.h @@ -18,6 +18,8 @@ #include "window_magnification_manager.h" #include "full_screen_magnification_manager.h" +#include "magnification_menu_manager.h" +#include "magnification_window_proxy.h" namespace OHOS { namespace Accessibility { @@ -28,6 +30,7 @@ public: std::shared_ptr GetWindowMagnificationManager(); std::shared_ptr GetFullScreenMagnificationManager(); + std::shared_ptr GetMenuManager(); void OnMagnificationTypeChanged(uint32_t magnificationType); void OnModeChanged(uint32_t mode); void DisableMagnification(); @@ -42,7 +45,9 @@ public: private: std::shared_ptr windowMagnificationManager_ = nullptr; std::shared_ptr fullScreenMagnificationManager_ = nullptr; + std::shared_ptr menuManager_ = nullptr; uint32_t currentMode_ = 0; + std::shared_ptr windowProxy_ = nullptr; }; } // namespace Accessibility } // namespace OHOS diff --git a/services/aams/include/magnification_menu_manager.h b/services/aams/include/magnification_menu_manager.h index 95c5dc19..14a05412 100644 --- a/services/aams/include/magnification_menu_manager.h +++ b/services/aams/include/magnification_menu_manager.h @@ -17,32 +17,17 @@ #define MAGNIFICATION_MENU_MANAGER_H #include "hilog_wrapper.h" -#include "window.h" -#include "window_option.h" -#include -#include -#include -#include "ui/rs_ui_context.h" -#include "ui/rs_ui_director.h" -#include "ui/rs_root_node.h" -#include "recording/recording_canvas.h" -#include "image_source.h" -#include "pixel_map.h" -#include "magnification_manager.h" #include "ffrt.h" +#include "magnification_window_proxy.h" namespace OHOS { namespace Accessibility { class MagnificationMenuManager { public: - static std::shared_ptr menuMgr_; - static std::shared_ptr GetInstance(); - static void DeleteInstance(); - MagnificationMenuManager(); - DISALLOW_COPY_AND_MOVE(MagnificationMenuManager); - ~MagnificationMenuManager(); + explicit MagnificationMenuManager(std::shared_ptr proxy); + ~MagnificationMenuManager() = default; void ShowMenuWindow(uint32_t mode); void DisableMenuWindow(); @@ -54,38 +39,8 @@ public: void RefreshWindowParam(); private: - void GetWindowParam(); - void CreateMenuWindow(); - void LoadMenuBgImage(uint32_t mode); - void ChangeMode(); - void AdjustMenuPosition(); - void FlushImplicitTransaction(); - std::shared_ptr DecodePixelMap(const std::string& pathName, - const Media::AllocatorType& allocatorType); - //menu window - sptr menuWindow_ = nullptr; - std::shared_ptr surfaceNode_ = nullptr; - std::shared_ptr canvasNode_ = nullptr; - std::shared_ptr rsUIContext_ = nullptr; - Media::AllocatorType allocatorType_ = Media::AllocatorType::DMA_ALLOC; - std::shared_ptr bgpixelmap_ = nullptr; - std::shared_ptr rosenImage_ = nullptr; - std::shared_ptr manager_ = nullptr; - - Rosen::Rect menuRect_ = {0, 0, 0, 0}; - Rosen::Rect screenRect_ = {0, 0, 0, 0}; - - uint32_t menuSize_ = 150; - int32_t margin_ = 50; - uint64_t screenId_ = 0; - uint32_t screenWidth_ = 0; - uint32_t screenHeight_ = 0; - Rosen::DisplayOrientation orientation_ = Rosen::DisplayOrientation::UNKNOWN; - - uint32_t menuMode_ = 0; - uint32_t currentType_ = 0; - bool isMenuShown_ = false; ffrt::mutex mutex_; + std::shared_ptr windowProxy_ = nullptr; }; } // namespace Accessibility diff --git a/services/aams/include/magnification_window_proxy.h b/services/aams/include/magnification_window_proxy.h new file mode 100644 index 00000000..6a9c3a7a --- /dev/null +++ b/services/aams/include/magnification_window_proxy.h @@ -0,0 +1,76 @@ +/* + * Copyright (C) 2025-2025 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef MAGNIFICATION_WINDOW_PROXY_H +#define MAGNIFICATION_WINDOW_PROXY_H + +#include "hilog_wrapper.h" +#include "magnification_def.h" + +namespace OHOS { +namespace Accessibility { +#define CHECK_PROXY_PTR_VOID() \ + if (windowProxy_ == nullptr) { \ + HILOG_ERROR("windowProxy_ is nullptr."); \ + return; \ + } + +class MagnificationWindowProxy { +public: + MagnificationWindowProxy(); + ~MagnificationWindowProxy(); + + // common + void EnableMagnification(uint32_t magnificationType, int32_t centerX, int32_t centerY); + void DisableMagnification(uint32_t magnificationType, bool needClear = false); + void SetScale(uint32_t magnificationType, float scaleSpan); + void MoveMagnification(uint32_t magnificationType, int32_t deltaX, int32_t deltaY); + PointerPos GetSourceCenter(); + void FollowFocuseElement(uint32_t magnificationType, int32_t centerX, int32_t centerY); + float GetScale(); + bool IsMagnificationWindowShow(uint32_t magnificationType); + void ShowMagnification(uint32_t magnificationType); + void RefreshWindowParam(uint32_t magnificationType); + PointerPos ConvertCoordinates(int32_t posX, int32_t posY); + void InitMagnificationParam(float scale); + + // full magnification + PointerPos ConvertGesture(uint32_t type, PointerPos coordinates); + uint32_t CheckTapOnHotArea(int32_t posX, int32_t posY); + + // window magnification + bool IsTapOnHotArea(int32_t posX, int32_t posY); + bool IsTapOnMagnificationWindow(int32_t posX, int32_t posY); + void FixSourceCenter(bool needFix); + + // menu + void ShowMenuWindow(uint32_t mode); + void DisableMenuWindow(); + bool IsTapOnMenu(int32_t posX, int32_t posY); + void MoveMenuWindow(int32_t deltaX, int32_t deltaY); + void SetCurrentType(uint32_t type); + void AttachToEdge(); + void RefreshWindowParamMenu(); + uint32_t ChangeMode(); + bool IsMenuShown(); + +private: + void* GetFunc(const std::string& funcName); + const std::string windowLibName_ = "libaams_ext.z.so"; + void* handle_ = nullptr; +}; +} // namespace Accessibility +} // namespace OHOS +#endif // MAGNIFICATION_WINDOW_PROXY_H \ No newline at end of file diff --git a/services/aams/include/window_magnification_gesture.h b/services/aams/include/window_magnification_gesture.h index 4ebc2d1e..3bae3bb2 100644 --- a/services/aams/include/window_magnification_gesture.h +++ b/services/aams/include/window_magnification_gesture.h @@ -19,6 +19,8 @@ #include "accessibility_event_transmission.h" #include "window_magnification_manager.h" #include "hilog_wrapper.h" +#include "event_handler.h" +#include "magnification_menu_manager.h" namespace OHOS { namespace Accessibility { @@ -85,7 +87,8 @@ private: class WindowMagnificationGesture : public EventTransmission { public: WindowMagnificationGesture(); - explicit WindowMagnificationGesture(std::shared_ptr windowMagnificationManager); + explicit WindowMagnificationGesture(std::shared_ptr windowMagnificationManager, + std::shared_ptr menuManager); ~WindowMagnificationGesture() = default; bool OnPointerEvent(MMI::PointerEvent &event) override; @@ -193,6 +196,7 @@ private: std::shared_ptr handler_ = nullptr; std::shared_ptr runner_ = nullptr; std::shared_ptr windowMagnificationManager_ = nullptr; + std::shared_ptr menuManager_ = nullptr; MagnificationState magnificationState_ = MagnificationState::MAGNIFICATION_READY_STATE; MagnificationGestureState gestureState_ = MagnificationGestureState::READY_STATE; diff --git a/services/aams/include/window_magnification_manager.h b/services/aams/include/window_magnification_manager.h index 0acc6c22..76995c52 100644 --- a/services/aams/include/window_magnification_manager.h +++ b/services/aams/include/window_magnification_manager.h @@ -16,18 +16,10 @@ #ifndef WINDOW_MAGNIFICATION_MANAGER_H #define WINDOW_MAGNIFICATION_MANAGER_H -#include "window.h" -#include "window_option.h" -#include -#include -#include -#include "ui/rs_ui_context.h" -#include "ui/rs_ui_director.h" -#include "ui/rs_root_node.h" -#include "recording/recording_canvas.h" #include "hilog_wrapper.h" #include "magnification_def.h" #include "ffrt.h" +#include "magnification_window_proxy.h" namespace OHOS { namespace Accessibility { @@ -40,28 +32,17 @@ struct RectBound { class WindowMagnificationManager { public: WindowMagnificationManager(); + explicit WindowMagnificationManager(std::shared_ptr proxy); ~WindowMagnificationManager() = default; - void OnMagnificationModeChanged(uint32_t magnificationMode); - - inline bool IsMagnificationWindowShow() - { - return isMagnificationWindowShow_; - } - inline float GetScale() - { - return scale_; - } - - void CreateMagnificationWindow(int32_t posX, int32_t posY); - void DrawRuoundRectFrame(); + bool IsMagnificationWindowShow(); + float GetScale(); void EnableWindowMagnification(int32_t centerX, int32_t centerY); void ShowWindowMagnification(); void ShowWindowMagnificationWithPosition(PointerPos pos); void DisableWindowMagnification(bool needClear = false); void SetScale(float deltaSpan); void MoveMagnificationWindow(int32_t deltaX, int32_t deltaY); - void InitMagnificationParam(); bool IsTapOnHotArea(int32_t posX, int32_t posY); bool IsTapOnMagnificationWindow(int32_t posX, int32_t posY); PointerPos ConvertCoordinates(int32_t posX, int32_t posY); @@ -72,45 +53,8 @@ public: PointerPos GetSourceCenter(); private: - PointerPos ConvertCenterToTopLeft(int32_t centerX, int32_t centerY); - RectBound GenRectBound(uint32_t width, uint32_t height); - Rosen::Rect GetSourceRectFromPointer(int32_t centerX, int32_t centerY); - Rosen::Rect GetWindowRectFromPointer(int32_t centerX, int32_t centerY); - void AdjustMagnificationWindowPosition(); - void AdjustSourceWindowPosition(); - void CalculateAnchorOffset(); - void GetWindowParam(); - PointerPos GetRectCenter(Rosen::Rect rect); - void UpdateRelativeRect(); - void FlushImplicitTransaction(); - - Rosen::Rect sourceRect_ = {0, 0, 0, 0}; - Rosen::Rect windowRect_ = {0, 0, 0, 0}; - Rosen::Rect screenRect_ = {0, 0, 0, 0}; - Rosen::Rect relativeRect_ = {0, 0, 0, 0}; //The relative position of sourceRect_ in windowRect_ - - sptr window_ = nullptr; - std::shared_ptr surfaceNode_ = nullptr; - std::shared_ptr canvasNode_ = nullptr; - std::shared_ptr rsUIContext_ = nullptr; - bool isMagnificationWindowShow_ = false; - - uint32_t windowWidth_ = 940; - uint32_t windowHeight_ = 550; - uint32_t barMargin_ = 40; - float scale_ = 2.0f; - uint32_t hotAreaWidth_ = 60; - int32_t anchorOffsetX_ = 0; // windowRect_'s centerX - sourceRect_'s centerX - int32_t anchorOffsetY_ = 0; // windowRect_'s centerY - sourceRect_'s centerY - - uint32_t screenWidth_ = 0; - uint32_t screenHeight_ = 0; - float screenSpan_ = 0.0f; - uint64_t screenId_ = 0; - Rosen::DisplayOrientation orientation_ = Rosen::DisplayOrientation::UNKNOWN; - bool isFixSourceCenter_ = false; - PointerPos fixedSourceCenter_ = {0, 0}; ffrt::mutex mutex_; + std::shared_ptr windowProxy_ = nullptr; }; } // namespace Accessibility } // namespace OHOS diff --git a/services/aams/src/accessibility_input_interceptor.cpp b/services/aams/src/accessibility_input_interceptor.cpp index 1acec5ee..1d6fe9f9 100644 --- a/services/aams/src/accessibility_input_interceptor.cpp +++ b/services/aams/src/accessibility_input_interceptor.cpp @@ -220,52 +220,22 @@ void AccessibilityInputInterceptor::CreatePointerEventTransmitters() void AccessibilityInputInterceptor::CreateMagnificationGesture(sptr &header, sptr ¤t) { + Singleton::GetInstance().InitMagnification(); uint32_t magnificationMode = Singleton::GetInstance().GetMagnificationMode(); if (magnificationMode == FULL_SCREEN_MAGNIFICATION) { HILOG_INFO("create zoomGesture"); - std::shared_ptr fullScreenMagnificationManager = - Singleton::GetInstance().GetFullScreenMagnificationManager(); - if (fullScreenMagnificationManager == nullptr) { - HILOG_ERROR("get windowMagnification manager failed."); - return; - } - + CreatZoomGesture(); if (zoomGesture_ == nullptr) { - sptr zoomGesture = - new(std::nothrow) AccessibilityZoomGesture(fullScreenMagnificationManager); - if (zoomGesture == nullptr) { - HILOG_ERROR("zoomGesture create error."); - return; - } - zoomGesture_ = zoomGesture; - } - - if (needInteractMagnification_) { - zoomGesture_->StartMagnificationInteract(); - needInteractMagnification_ = false; + HILOG_ERROR("zoomGesture create error."); + return; } SetNextEventTransmitter(header, current, zoomGesture_); } else if (magnificationMode == WINDOW_MAGNIFICATION) { HILOG_INFO("create windowMagnificationGesture"); - std::shared_ptr windowMagnificationManager = - Singleton::GetInstance().GetWindowMagnificationManager(); - if (windowMagnificationManager == nullptr) { - HILOG_ERROR("get windowMagnification manager failed."); - return; - } - + CreatWindowMagnificationGesture(); if (windowMagnificationGesture_ == nullptr) { - sptr windowMagnificationGesture = - new(std::nothrow) WindowMagnificationGesture(windowMagnificationManager); - if (windowMagnificationGesture == nullptr) { - HILOG_ERROR("windowMagnificationGesture create error."); - return; - } - windowMagnificationGesture_ = windowMagnificationGesture; - } - if (needInteractMagnification_) { - windowMagnificationGesture_->StartMagnificationInteract(); - needInteractMagnification_ = false; + HILOG_ERROR("windowMagnificationGesture create error."); + return; } SetNextEventTransmitter(header, current, windowMagnificationGesture_); } else { @@ -274,6 +244,59 @@ void AccessibilityInputInterceptor::CreateMagnificationGesture(sptr fullScreenMagnificationManager = + Singleton::GetInstance().GetFullScreenMagnificationManager(); + std::shared_ptr menuManager = + Singleton::GetInstance().GetMenuManager(); + if (fullScreenMagnificationManager == nullptr || menuManager == nullptr) { + HILOG_ERROR("get windowMagnification or menu manager failed."); + return; + } + + if (zoomGesture_ == nullptr) { + sptr zoomGesture = + new(std::nothrow) AccessibilityZoomGesture(fullScreenMagnificationManager, menuManager); + if (zoomGesture == nullptr) { + HILOG_ERROR("zoomGesture create error."); + return; + } + zoomGesture_ = zoomGesture; + } + + if (needInteractMagnification_) { + zoomGesture_->StartMagnificationInteract(); + needInteractMagnification_ = false; + } +} + +void AccessibilityInputInterceptor::CreatWindowMagnificationGesture() +{ + std::shared_ptr windowMagnificationManager = + Singleton::GetInstance().GetWindowMagnificationManager(); + std::shared_ptr menuManager = + Singleton::GetInstance().GetMenuManager(); + if (windowMagnificationManager == nullptr || menuManager == nullptr) { + HILOG_ERROR("get windowMagnification or menu manager failed."); + return; + } + + if (windowMagnificationGesture_ == nullptr) { + sptr windowMagnificationGesture = + new(std::nothrow) WindowMagnificationGesture(windowMagnificationManager, menuManager); + if (windowMagnificationGesture == nullptr) { + HILOG_ERROR("windowMagnificationGesture create error."); + return; + } + windowMagnificationGesture_ = windowMagnificationGesture; + } + if (needInteractMagnification_) { + windowMagnificationGesture_->StartMagnificationInteract(); + needInteractMagnification_ = false; + } +} + void AccessibilityInputInterceptor::ClearMagnificationGesture() { zoomGesture_ = nullptr; diff --git a/services/aams/src/accessibility_zoom_gesture.cpp b/services/aams/src/accessibility_zoom_gesture.cpp index 6871494b..56cb0967 100755 --- a/services/aams/src/accessibility_zoom_gesture.cpp +++ b/services/aams/src/accessibility_zoom_gesture.cpp @@ -22,7 +22,6 @@ #ifdef OHOS_BUILD_ENABLE_POWER_MANAGER #include "accessibility_power_manager.h" #endif -#include "magnification_menu_manager.h" namespace OHOS { namespace Accessibility { @@ -43,7 +42,9 @@ namespace { } // namespace AccessibilityZoomGesture::AccessibilityZoomGesture( - std::shared_ptr fullScreenManager) : fullScreenManager_(fullScreenManager) + std::shared_ptr fullScreenManager, + std::shared_ptr menuManager) + : fullScreenManager_(fullScreenManager), menuManager_(menuManager) { HILOG_DEBUG(); zoomGestureEventHandler_ = std::make_shared( @@ -304,12 +305,14 @@ void AccessibilityZoomGesture::RecognizeInReadyState(MMI::PointerEvent &event) void AccessibilityZoomGesture::RecognizeInZoomStateDownEvent(MMI::PointerEvent &event) { - HILOG_DEBUG(); - if (fullScreenManager_ == nullptr) { HILOG_ERROR("fullScreenManager_ is nullptr."); return; } + if (menuManager_ == nullptr) { + HILOG_ERROR("menuManager_ is nullptr."); + return; + } gestureType_ = INVALID_GESTURE_TYPE; std::vector pointerIdList = event.GetPointerIds(); size_t pointerCount = pointerIdList.size(); @@ -319,8 +322,7 @@ void AccessibilityZoomGesture::RecognizeInZoomStateDownEvent(MMI::PointerEvent & MMI::PointerEvent::PointerItem pointerItem; event.GetPointerItem(event.GetPointerId(), pointerItem); gestureType_ = fullScreenManager_->CheckTapOnHotArea(pointerItem.GetDisplayX(), pointerItem.GetDisplayY()); - isTapOnMenu_ = Singleton::GetInstance().IsTapOnMenu(pointerItem.GetDisplayX(), - pointerItem.GetDisplayY()); + isTapOnMenu_ = menuManager_->IsTapOnMenu(pointerItem.GetDisplayX(), pointerItem.GetDisplayY()); std::shared_ptr pointerEvent = std::make_shared(event); longPressDownEvent_ = pointerEvent; downPid_ = event.GetPointerId(); @@ -389,8 +391,8 @@ void AccessibilityZoomGesture::RecognizeInZoomState(MMI::PointerEvent &event) isLongPress_ = false; } if ((pointerCount == POINTER_COUNT_1) && IsUpValid() && !(IsTapOnInputMethod(event))) { - if (isTapOnMenu_) { - Singleton::GetInstance().OnMenuTap(); + if (isTapOnMenu_ && menuManager_ != nullptr) { + menuManager_->OnMenuTap(); ClearCacheEventsAndMsg(); } else { isTripleTaps = IsTripleTaps(); @@ -458,6 +460,10 @@ void AccessibilityZoomGesture::RecognizeInSlidingState(MMI::PointerEvent &event) void AccessibilityZoomGesture::RecognizeInMenuSlidingState(MMI::PointerEvent &event) { HILOG_INFO(); + if (menuManager_ == nullptr) { + HILOG_ERROR("menuManager_ is nullptr."); + return; + } int32_t action = event.GetPointerAction(); switch (action) { case MMI::PointerEvent::POINTER_ACTION_MOVE: @@ -474,7 +480,7 @@ void AccessibilityZoomGesture::RecognizeInMenuSlidingState(MMI::PointerEvent &ev int32_t deltaX = currentItem.GetDisplayX() - lastSlidingItem.GetDisplayX(); int32_t deltaY = currentItem.GetDisplayY() - lastSlidingItem.GetDisplayY(); - Singleton::GetInstance().MoveMenuWindow(deltaX, deltaY); + menuManager_->MoveMenuWindow(deltaX, deltaY); lastSlidingEvent_ = std::make_shared(event); } else { @@ -486,7 +492,7 @@ void AccessibilityZoomGesture::RecognizeInMenuSlidingState(MMI::PointerEvent &ev case MMI::PointerEvent::POINTER_ACTION_UP: lastSlidingEvent_ = nullptr; isTapOnMenu_ = false; - Singleton::GetInstance().AttachToEdge(); + menuManager_->AttachToEdge(); TransferState(ZOOMIN_STATE); ClearCacheEventsAndMsg(); break; @@ -953,9 +959,8 @@ void AccessibilityZoomGesture::OnZoom(int32_t anchorX, int32_t anchorY, bool sho fullScreenManager_->EnableMagnification(anchorX, anchorY); Singleton::GetInstance().AnnouncedForMagnification( AnnounceType::ANNOUNCE_MAGNIFICATION_SCALE); - if (showMenu) { - Singleton::GetInstance().ShowMenuWindow( - FULL_SCREEN_MAGNIFICATION); + if (showMenu && menuManager_ != nullptr) { + menuManager_->ShowMenuWindow(FULL_SCREEN_MAGNIFICATION); } } @@ -966,10 +971,14 @@ void AccessibilityZoomGesture::OffZoom() HILOG_ERROR("fullScreenManager_ is nullptr."); return; } + if (menuManager_ == nullptr) { + HILOG_ERROR("menuManager_ is nullptr."); + return; + } if (fullScreenManager_->IsMagnificationWindowShow()) { HILOG_INFO("full magnification disable."); - fullScreenManager_->DisableMagnification(); - Singleton::GetInstance().DisableMenuWindow(); + fullScreenManager_->DisableMagnification(false); + menuManager_->DisableMenuWindow(); Singleton::GetInstance().AnnouncedForMagnification( AnnounceType::ANNOUNCE_MAGNIFICATION_DISABLE); } @@ -1019,10 +1028,14 @@ void AccessibilityZoomGesture::DestroyEvents() void AccessibilityZoomGesture::ShieldZoomGesture(bool state) { shieldZoomGestureFlag_ = state; + if (menuManager_ == nullptr) { + HILOG_ERROR("menuManager_ is nullptr."); + return; + } HILOG_INFO("ShieldZoomGesture state = %{public}d", state); if (state) { Clear(); - Singleton::GetInstance().DisableMenuWindow(); + menuManager_->DisableMenuWindow(); if (fullScreenManager_ == nullptr) { HILOG_ERROR("fullScreenManager_ is nullptr."); return; diff --git a/services/aams/src/accessible_ability_manager_service.cpp b/services/aams/src/accessible_ability_manager_service.cpp index 2a7a4fe2..64102138 100644 --- a/services/aams/src/accessible_ability_manager_service.cpp +++ b/services/aams/src/accessible_ability_manager_service.cpp @@ -159,7 +159,6 @@ AccessibleAbilityManagerService::AccessibleAbilityManagerService() accessibilitySettings_ = std::make_shared(); accessibilityShortKey_ = std::make_shared(); - magnificationManager_ = std::make_shared(); } AccessibleAbilityManagerService::~AccessibleAbilityManagerService() @@ -1807,7 +1806,6 @@ bool AccessibleAbilityManagerService::Init() { HILOG_DEBUG(); Singleton::GetInstance().SubscriberEvent(handler_); - Singleton::GetInstance().RegisterDisplayListener(magnificationManager_); Singleton::GetInstance().RegisterWindowListener(handler_); bool result = Singleton::GetInstance().Init(); HILOG_DEBUG("wms init result is %{public}d", result); @@ -1831,7 +1829,6 @@ bool AccessibleAbilityManagerService::Init() HILOG_DEBUG("Query account information success, account id:%{public}d", accountIds[0]); SwitchedUser(accountIds[0]); } - SubscribeOsAccount(); return true; } @@ -3438,6 +3435,14 @@ void AccessibleAbilityManagerService::RegisterShortKeyEvent() }, "REGISTER_SHORTKEY_OBSERVER"); } +void AccessibleAbilityManagerService::InitMagnification() +{ + HILOG_INFO(); + magnificationManager_ = std::make_shared(); + Singleton::GetInstance().RegisterDisplayListener(magnificationManager_); + SubscribeOsAccount(); +} + void AccessibleAbilityManagerService::OffZoomGesture() { HILOG_INFO(); @@ -4080,6 +4085,26 @@ std::shared_ptr AccessibleAbilityManagerService: return magnificationManager_->GetFullScreenMagnificationManager(); } +std::shared_ptr AccessibleAbilityManagerService::GetMenuManager() +{ + HILOG_DEBUG(); + if (magnificationManager_ == nullptr) { + HILOG_ERROR("magnificationManager_ is nullptr."); + return nullptr; + } + return magnificationManager_->GetMenuManager(); +} + +void AccessibleAbilityManagerService::OnModeChanged(uint32_t mode) +{ + HILOG_DEBUG(); + if (magnificationManager_ == nullptr) { + HILOG_ERROR("magnificationManager_ is nullptr."); + return; + } + return magnificationManager_->OnModeChanged(mode); +} + int32_t AccessibleAbilityManagerService::SetEnhanceConfig(const AccessibilitySecCompRawdata& rawData) { HILOG_INFO(); diff --git a/services/aams/src/full_screen_magnification_manager.cpp b/services/aams/src/full_screen_magnification_manager.cpp index d736c006..bbdf796d 100644 --- a/services/aams/src/full_screen_magnification_manager.cpp +++ b/services/aams/src/full_screen_magnification_manager.cpp @@ -15,7 +15,6 @@ // LCOV_EXCL_START #include "full_screen_magnification_manager.h" -#include "accessibility_display_manager.h" #include "accessible_ability_manager_service.h" #include "magnification_menu_manager.h" #include "utils.h" @@ -23,108 +22,26 @@ namespace OHOS { namespace Accessibility { namespace { - int32_t GESTURE_OFFSET = 100; } -FullScreenMagnificationManager::FullScreenMagnificationManager() +FullScreenMagnificationManager::FullScreenMagnificationManager( + std::shared_ptr proxy) : windowProxy_(proxy) { - GetWindowParam(); - InitMagnificationParam(); -} - -void FullScreenMagnificationManager::CreateMagnificationWindow() -{ - HILOG_DEBUG(); - sptr windowOption = new(std::nothrow) Rosen::WindowOption(); - if (windowOption == nullptr) { - HILOG_ERROR("windowOption is null."); - return; - } - windowOption->SetWindowType(Rosen::WindowType::WINDOW_TYPE_MAGNIFICATION); - windowOption->SetWindowMode(Rosen::WindowMode::WINDOW_MODE_FLOATING); - windowOption->SetWindowRect(windowRect_); - windowOption->SetFocusable(false); - window_ = Rosen::Window::Create(WINDOW_NAME, windowOption); - if (window_ == nullptr) { - HILOG_ERROR("window create failed."); - return; - } - window_->SetCornerRadius(CORNER_RADIUS); - surfaceNode_ = window_->GetSurfaceNode(); - if (surfaceNode_ == nullptr) { - HILOG_ERROR("get surfaceNode_ failed."); - return; - } - rsUIContext_ = surfaceNode_->GetRSUIContext(); - canvasNode_ = Rosen::RSCanvasNode::Create(false, false, rsUIContext_); - if (canvasNode_ == nullptr) { - HILOG_ERROR("canvasNode_ is nullptr."); - return; - } - canvasNode_->SetSkipCheckInMultiInstance(true); -} - -void FullScreenMagnificationManager::DrawRuoundRectFrame() -{ - if (surfaceNode_ == nullptr) { - HILOG_ERROR("get surfaceNode_ failed."); - return; - } - - if (canvasNode_ == nullptr) { - HILOG_ERROR("create canvasNode_ fail"); - return; - } - surfaceNode_->SetAbilityBGAlpha(BG_ALPHA); - surfaceNode_->AddChild(canvasNode_, -1); - canvasNode_->SetBounds(0, 0, screenWidth_, screenHeight_); - canvasNode_->SetFrame(0, 0, screenWidth_, screenHeight_); - canvasNode_->SetPositionZ(Rosen::RSSurfaceNode::POINTER_WINDOW_POSITION_Z); - canvasNode_->SetRotation(0); - - auto canvas = canvasNode_->BeginRecording(screenWidth_, screenHeight_); - Rosen::Drawing::Pen pen; - pen.SetAntiAlias(true); - pen.SetColor(ORANGE_COLOR); - pen.SetWidth(PEN_WIDTH); - canvas->AttachPen(pen); - Rosen::Drawing::Path path; - path.AddRoundRect({ROUND_RECT_MARGIN, ROUND_RECT_MARGIN, - screenWidth_ - ROUND_RECT_MARGIN, screenHeight_ - ROUND_RECT_MARGIN}, - CORNER_RADIUS, CORNER_RADIUS, Rosen::Drawing::PathDirection::CW_DIRECTION); - canvas->DrawPath(path); - canvas->DetachPen(); - canvasNode_->FinishRecording(); } void FullScreenMagnificationManager::EnableMagnification(int32_t centerX, int32_t centerY) { HILOG_INFO("centerX = %{public}d, centerY = %{public}d.", centerX, centerY); - GetWindowParam(); - InitMagnificationParam(); - if (window_ == nullptr) { - HILOG_ERROR("window is null. need create."); - CreateMagnificationWindow(); - } - - if (window_ == nullptr) { - HILOG_ERROR("create window failed."); - return; - } - sourceRect_ = GetSourceRectFromPointer(centerX, centerY); - UpdateAnchor(); - DrawRuoundRectFrame(); - window_->SetFrameRectForPartialZoomIn(sourceRect_); - window_->Show(); - FlushImplicitTransaction(); - isMagnificationWindowShow_ = true; + CHECK_PROXY_PTR_VOID() + float scale = Singleton::GetInstance().GetMagnificationScale(); + windowProxy_->InitMagnificationParam(scale); + windowProxy_->EnableMagnification(FULL_SCREEN_MAGNIFICATION, centerX, centerY); } void FullScreenMagnificationManager::ShowMagnification() { - int32_t centerX = static_cast(screenWidth_ / DIVISOR_TWO); - int32_t centerY = static_cast(screenHeight_ / DIVISOR_TWO); - EnableMagnification(centerX, centerY); + CHECK_PROXY_PTR_VOID() + windowProxy_->ShowMagnification(FULL_SCREEN_MAGNIFICATION); } void FullScreenMagnificationManager::ShowMagnificationWithPosition(PointerPos pos) @@ -139,297 +56,102 @@ void FullScreenMagnificationManager::ShowMagnificationWithPosition(PointerPos po void FullScreenMagnificationManager::DisableMagnification(bool needClear) { HILOG_INFO(); + CHECK_PROXY_PTR_VOID() std::lock_guard lock(mutex_); - if (needClear && surfaceNode_ != nullptr) { - HILOG_DEBUG("claer surfaceNode"); - surfaceNode_->SetVisible(false); - surfaceNode_->ClearChildren(); - FlushImplicitTransaction(); - } - - if (window_ != nullptr) { - window_->Hide(); - window_->Destroy(); - window_ = nullptr; - } - surfaceNode_ = nullptr; - canvasNode_ = nullptr; - rsUIContext_ = nullptr; - isMagnificationWindowShow_ = false; + windowProxy_->DisableMagnification(FULL_SCREEN_MAGNIFICATION, needClear); } void FullScreenMagnificationManager::SetScale(float scaleSpan) { HILOG_DEBUG(); - if (window_ == nullptr) { - HILOG_ERROR("window_ is nullptr."); - return; - } - if (screenWidth_ == 0 || screenHeight_ == 0 || abs(screenSpan_) < EPS) { - HILOG_ERROR("screen param invalid."); - return; - } - - float ratio = scaleSpan / screenSpan_; - float tmpScale = scale_ + ratio * scale_; - - if (tmpScale > MAX_SCALE) { - tmpScale = MAX_SCALE; - } - if (tmpScale < DEFAULT_SCALE) { - tmpScale = DEFAULT_SCALE; - } - - uint32_t newWidth = static_cast(windowRect_.width_ / tmpScale); - uint32_t newHeight = static_cast(windowRect_.height_ / tmpScale); - int32_t newPosX = centerX_ - static_cast(newWidth / DIVISOR_TWO); - int32_t newPosY = centerY_ - static_cast(newHeight / DIVISOR_TWO); - - if (newPosX < 0) { - centerX_ -= newPosX; - newPosX = 0; - } - - if (newPosY < 0) { - centerY_ -= newPosY; - newPosY = 0; - } - - if (newPosX + static_cast(newWidth) > static_cast(screenWidth_)) { - centerX_ -= (newPosX + static_cast(newWidth) - static_cast(screenWidth_)); - newPosX = static_cast(screenWidth_) - static_cast(newWidth); - } - - if (newPosY + static_cast(newHeight) > static_cast(screenHeight_)) { - centerY_ -= (newPosY + static_cast(newHeight) - static_cast(screenHeight_)); - newPosY = static_cast(screenHeight_) - static_cast(newHeight); - } - - sourceRect_ = {newPosX, newPosY, newWidth, newHeight}; - scale_ = tmpScale; - HILOG_DEBUG("scale_ = %{public}f", scale_); - window_->SetFrameRectForPartialZoomIn(sourceRect_); - DrawRuoundRectFrame(); - FlushImplicitTransaction(); - UpdateAnchor(); + CHECK_PROXY_PTR_VOID() + windowProxy_->SetScale(FULL_SCREEN_MAGNIFICATION, scaleSpan); } void FullScreenMagnificationManager::MoveMagnification(int32_t deltaX, int32_t deltaY) { - if (window_ == nullptr) { - HILOG_ERROR("window_ is nullptr."); - return; - } - int32_t sourcePosX = sourceRect_.posX_ - deltaX; - int32_t sourcePosY = sourceRect_.posY_ - deltaY; - - if (sourcePosX < 0) { - sourcePosX = 0; - } - - if (sourcePosY < 0) { - sourcePosY = 0; - } - - if (sourcePosX + static_cast(sourceRect_.width_) > static_cast(screenWidth_)) { - sourcePosX = static_cast(screenWidth_) - static_cast(sourceRect_.width_); - } - - if (sourcePosY + static_cast(sourceRect_.height_) > static_cast(screenHeight_)) { - sourcePosY = static_cast(screenHeight_) - static_cast(sourceRect_.height_); - } - sourceRect_.posX_ = sourcePosX; - sourceRect_.posY_ = sourcePosY; - window_->SetFrameRectForPartialZoomIn(sourceRect_); - DrawRuoundRectFrame(); - FlushImplicitTransaction(); - UpdateAnchor(); + CHECK_PROXY_PTR_VOID() + windowProxy_->MoveMagnification(FULL_SCREEN_MAGNIFICATION, deltaX, deltaY); } void FullScreenMagnificationManager::PersistScale() { - HILOG_DEBUG("scale_ = %{public}f", scale_); - Singleton::GetInstance().SetMagnificationScale(scale_); + CHECK_PROXY_PTR_VOID() + float scale = windowProxy_->GetScale(); + HILOG_DEBUG("scale = %{public}f", scale); + Singleton::GetInstance().SetMagnificationScale(scale); Singleton::GetInstance().AnnouncedForMagnification( AnnounceType::ANNOUNCE_MAGNIFICATION_SCALE); } -void FullScreenMagnificationManager::GetWindowParam() -{ - HILOG_INFO(); -#ifdef OHOS_BUILD_ENABLE_DISPLAY_MANAGER - AccessibilityDisplayManager &displayMgr = Singleton::GetInstance(); - screenId_ = displayMgr.GetDefaultDisplayId(); - OHOS::Rosen::DisplayOrientation currentOrientation = displayMgr.GetOrientation(); - orientation_ = currentOrientation; - sptr display = displayMgr.GetDisplay(screenId_); - if (display == nullptr) { - HILOG_ERROR("display is nullptr."); - return; - } - screenWidth_ = static_cast(display->GetWidth()); - screenHeight_ = static_cast(display->GetHeight()); - HILOG_INFO("screenWidth_ = %{public}d, screenHeight_ = %{public}d.", screenWidth_, screenHeight_); - - screenSpan_ = hypot(screenWidth_, screenHeight_); - screenRect_ = {0, 0, screenWidth_, screenHeight_}; - windowRect_ = {0, 0, screenWidth_, screenHeight_}; -#else - HILOG_INFO("not support"); -#endif -} - void FullScreenMagnificationManager::RefreshWindowParam() { - HILOG_INFO(); - PointerPos center = GetRectCenter(sourceRect_); - if (isMagnificationWindowShow_) { - DisableMagnification(); - EnableMagnification(center.posX, center.posY); - } else { - GetWindowParam(); - } + HILOG_DEBUG(); + CHECK_PROXY_PTR_VOID() + windowProxy_->RefreshWindowParam(FULL_SCREEN_MAGNIFICATION); } PointerPos FullScreenMagnificationManager::ConvertCoordinates(int32_t posX, int32_t posY) { - PointerPos sourcePoint = {0, 0}; - if ((abs(scale_) < EPS)) { - return sourcePoint; + PointerPos pos = {posX, posY}; + if (windowProxy_ == nullptr) { + HILOG_ERROR("windowProxy_ is nullptr."); + return pos; } - int32_t windowDeltaX = posX - windowRect_.posX_; - int32_t windowDeltaY = posY - windowRect_.posY_; - sourcePoint.posX = sourceRect_.posX_ + static_cast(windowDeltaX / scale_); - sourcePoint.posY = sourceRect_.posY_ + static_cast(windowDeltaY / scale_); - return sourcePoint; + return windowProxy_->ConvertCoordinates(posX, posY); } PointerPos FullScreenMagnificationManager::ConvertGesture(uint32_t type, PointerPos coordinates) { - int32_t posX = coordinates.posX; - int32_t posY = coordinates.posY; - PointerPos point = {posX, posY}; - - if (type == BOTTOM_BACK_GESTURE) { - int32_t offsetY = static_cast(screenHeight_) - - (sourceRect_.posY_ + static_cast(sourceRect_.height_)); - point.posY = posY + offsetY; - return point; - } - if (type == LEFT_BACK_GESTURE) { - int32_t offsetX = sourceRect_.posX_; - point.posX = posX - offsetX; - return point; - } - - if (type == RIGHT_BACK_GESTURE) { - int32_t offsetX = static_cast(screenWidth_) - - (sourceRect_.posX_ + static_cast(sourceRect_.width_)); - point.posX = posX + offsetX; - return point; + if (windowProxy_ == nullptr) { + HILOG_ERROR("windowProxy_ is nullptr."); + return coordinates; } - - return point; + return windowProxy_->ConvertGesture(type, coordinates); } uint32_t FullScreenMagnificationManager::CheckTapOnHotArea(int32_t posX, int32_t posY) { - bool isTapOnBottom = posY <= static_cast(screenHeight_) && - posY >= static_cast(screenHeight_) - GESTURE_OFFSET; - if (isTapOnBottom) { - HILOG_DEBUG("Tap On Bottom"); - return BOTTOM_BACK_GESTURE; - } - bool isTapOnLeftSide = posX >= 0 && posX <= GESTURE_OFFSET; - if (isTapOnLeftSide) { - HILOG_DEBUG("Tap On Left Side"); - return LEFT_BACK_GESTURE; + if (windowProxy_ == nullptr) { + HILOG_ERROR("windowProxy_ is nullptr."); + return INVALID_GESTURE_TYPE; } - bool isTapOnRightSide = posX >= static_cast(screenWidth_) - GESTURE_OFFSET && - posX <= static_cast(screenWidth_); - if (isTapOnRightSide) { - HILOG_DEBUG("Tap On Right Side"); - return RIGHT_BACK_GESTURE; - } - return INVALID_GESTURE_TYPE; + return windowProxy_->CheckTapOnHotArea(posX, posY); } -void FullScreenMagnificationManager::InitMagnificationParam() -{ - scale_ = Singleton::GetInstance().GetMagnificationScale(); -} - -Rosen::Rect FullScreenMagnificationManager::GetSourceRectFromPointer(int32_t centerX, int32_t centerY) -{ - Rosen::Rect sourceRect = {0, 0, 0, 0}; - sourceRect.width_ = static_cast(static_cast(screenWidth_) / scale_); - sourceRect.height_ = static_cast(static_cast(screenHeight_) / scale_); - - int32_t x = centerX - static_cast(sourceRect.width_ / DIVISOR_TWO); - int32_t y = centerY - static_cast(sourceRect.height_ / DIVISOR_TWO); - - x = (x < 0) ? 0 : x; - x = (x + static_cast(sourceRect.width_)) > static_cast( - screenWidth_) ? static_cast(screenWidth_ - sourceRect.width_) : x; - - y = (y < 0) ? 0 : y; - y = (y + static_cast(sourceRect.height_)) > static_cast( - screenHeight_) ? static_cast(screenHeight_ - sourceRect.height_) : y; - - sourceRect.posX_ = x; - sourceRect.posY_ = y; - - return sourceRect; -} - -void FullScreenMagnificationManager::UpdateAnchor() -{ - centerX_ = static_cast((sourceRect_.posX_ + sourceRect_.posX_ + - static_cast(sourceRect_.width_)) / DIVISOR_TWO); - centerY_ = static_cast((sourceRect_.posY_ + sourceRect_.posY_ + - static_cast(sourceRect_.height_)) / DIVISOR_TWO); -} - -PointerPos FullScreenMagnificationManager::GetRectCenter(Rosen::Rect rect) +PointerPos FullScreenMagnificationManager::GetSourceCenter() { - PointerPos point = {0, 0}; - point.posX = rect.posX_ + static_cast(rect.width_ / DIVISOR_TWO); - point.posY = rect.posY_ + static_cast(rect.height_ / DIVISOR_TWO); - return point; + PointerPos pos = {0, 0}; + if (windowProxy_ == nullptr) { + HILOG_ERROR("windowProxy_ is nullptr."); + return pos; + } + return windowProxy_->GetSourceCenter(); } -PointerPos FullScreenMagnificationManager::GetSourceCenter() +void FullScreenMagnificationManager::FollowFocuseElement(int32_t centerX, int32_t centerY) { - PointerPos point = {0, 0}; - point.posX = sourceRect_.posX_ + static_cast(sourceRect_.width_ / DIVISOR_TWO); - point.posY = sourceRect_.posY_ + static_cast(sourceRect_.height_ / DIVISOR_TWO); - return point; + HILOG_DEBUG(); + CHECK_PROXY_PTR_VOID() + windowProxy_->FollowFocuseElement(FULL_SCREEN_MAGNIFICATION, centerX, centerY); } -void FullScreenMagnificationManager::FollowFocuseElement(int32_t centerX, int32_t centerY) +bool FullScreenMagnificationManager::IsMagnificationWindowShow() { - HILOG_INFO(); - if (window_ == nullptr) { - HILOG_ERROR("window_ is nullptr."); - return; + if (windowProxy_ == nullptr) { + HILOG_ERROR("windowProxy_ is nullptr."); + return false; } - sourceRect_ = GetSourceRectFromPointer(centerX, centerY); - window_->SetFrameRectForPartialZoomIn(sourceRect_); - DrawRuoundRectFrame(); - FlushImplicitTransaction(); - UpdateAnchor(); + return windowProxy_->IsMagnificationWindowShow(FULL_SCREEN_MAGNIFICATION); } -void FullScreenMagnificationManager::FlushImplicitTransaction() +float FullScreenMagnificationManager::GetScale() { - if (rsUIContext_ != nullptr) { - auto rsTransaction = rsUIContext_->GetRSTransaction(); - if (rsTransaction != nullptr) { - rsTransaction->FlushImplicitTransaction(); - } - } else { - Rosen::RSTransaction::FlushImplicitTransaction(); + if (windowProxy_ == nullptr) { + HILOG_ERROR("windowProxy_ is nullptr."); + return DEFAULT_SCALE; } + return windowProxy_->GetScale(); } } // namespace Accessibility } // namespace OHOS diff --git a/services/aams/src/magnification_manager.cpp b/services/aams/src/magnification_manager.cpp index 2ca2d3e0..24ed9ed3 100644 --- a/services/aams/src/magnification_manager.cpp +++ b/services/aams/src/magnification_manager.cpp @@ -24,7 +24,7 @@ namespace OHOS { namespace Accessibility { MagnificationManager::MagnificationManager() { - HILOG_DEBUG(); + windowProxy_ = std::make_shared(); } std::shared_ptr MagnificationManager::GetWindowMagnificationManager() @@ -32,7 +32,7 @@ std::shared_ptr MagnificationManager::GetWindowMagni HILOG_DEBUG(); currentMode_ = Singleton::GetInstance().GetMagnificationMode(); if (windowMagnificationManager_ == nullptr) { - windowMagnificationManager_ = std::make_shared(); + windowMagnificationManager_ = std::make_shared(windowProxy_); } return windowMagnificationManager_; } @@ -42,11 +42,20 @@ std::shared_ptr MagnificationManager::GetFullScr HILOG_DEBUG(); currentMode_ = Singleton::GetInstance().GetMagnificationMode(); if (fullScreenMagnificationManager_ == nullptr) { - fullScreenMagnificationManager_ = std::make_shared(); + fullScreenMagnificationManager_ = std::make_shared(windowProxy_); } return fullScreenMagnificationManager_; } +std::shared_ptr MagnificationManager::GetMenuManager() +{ + HILOG_DEBUG(); + if (menuManager_ == nullptr) { + menuManager_ = std::make_shared(windowProxy_); + } + return menuManager_; +} + void MagnificationManager::OnMagnificationTypeChanged(uint32_t magnificationType) { HILOG_INFO("magnificationType = %{public}d, currentMode_ = %{public}d", magnificationType, currentMode_); @@ -59,24 +68,28 @@ void MagnificationManager::OnMagnificationTypeChanged(uint32_t magnificationType GetFullScreenMagnificationManager(); } + if (menuManager_ == nullptr) { + HILOG_ERROR("menuManager_ is nullptr."); + return; + } currentMode_ = Singleton::GetInstance().GetMagnificationMode(); - Singleton::GetInstance().SetCurrentType(magnificationType); + menuManager_->SetCurrentType(magnificationType); if (magnificationType == SWITCH_MAGNIFICATION) { if (windowMagnificationManager_ != nullptr && windowMagnificationManager_->IsMagnificationWindowShow()) { - Singleton::GetInstance().DisableMenuWindow(); - Singleton::GetInstance().ShowMenuWindow(currentMode_); + menuManager_->DisableMenuWindow(); + menuManager_->ShowMenuWindow(currentMode_); return; } if (fullScreenMagnificationManager_ != nullptr && fullScreenMagnificationManager_->IsMagnificationWindowShow()) { - Singleton::GetInstance().DisableMenuWindow(); - Singleton::GetInstance().ShowMenuWindow(currentMode_); + menuManager_->DisableMenuWindow(); + menuManager_->ShowMenuWindow(currentMode_); return; } } - Singleton::GetInstance().DisableMenuWindow(); + menuManager_->DisableMenuWindow(); HILOG_INFO("magnificationType = %{public}d, currentMode_ = %{public}d", magnificationType, currentMode_); if (currentMode_ == magnificationType) { @@ -147,7 +160,9 @@ void MagnificationManager::DisableMagnification() { HILOG_INFO(); auto interceptor = AccessibilityInputInterceptor::GetInstance(); - Singleton::GetInstance().DisableMenuWindow(); + if (menuManager_ != nullptr) { + menuManager_->DisableMenuWindow(); + } if (windowMagnificationManager_ != nullptr && windowMagnificationManager_->IsMagnificationWindowShow()) { HILOG_INFO("disable window"); windowMagnificationManager_->DisableWindowMagnification(); @@ -175,8 +190,8 @@ void MagnificationManager::TriggerMagnification(uint32_t type, uint32_t mode) } } - if (type == SWITCH_MAGNIFICATION) { - Singleton::GetInstance().ShowMenuWindow(mode); + if (type == SWITCH_MAGNIFICATION && menuManager_ != nullptr) { + menuManager_->ShowMenuWindow(mode); } auto interceptor = AccessibilityInputInterceptor::GetInstance(); @@ -206,7 +221,9 @@ void MagnificationManager::RefreshWindowParam() fullScreenMagnificationManager_->RefreshWindowParam(); } - Singleton::GetInstance().RefreshWindowParam(); + if (menuManager_ != nullptr) { + menuManager_->RefreshWindowParam(); + } } void MagnificationManager::FollowFocuseElement(int32_t centerX, int32_t centerY) diff --git a/services/aams/src/magnification_menu_manager.cpp b/services/aams/src/magnification_menu_manager.cpp index ee142733..fb80ced9 100644 --- a/services/aams/src/magnification_menu_manager.cpp +++ b/services/aams/src/magnification_menu_manager.cpp @@ -18,7 +18,6 @@ #include "accessibility_def.h" #include "accessibility_display_manager.h" #include "accessible_ability_manager_service.h" -#include "utils.h" namespace OHOS { namespace Accessibility { @@ -26,321 +25,82 @@ namespace { const std::string FULL_SCREEN_PATH = "/system/etc/accessibility/fullScreen.png"; const std::string WINDOW_PATH = "/system/etc/accessibility/window.png"; } - -std::shared_ptr MagnificationMenuManager::menuMgr_ = nullptr; - -std::shared_ptr MagnificationMenuManager::GetInstance() -{ - HILOG_DEBUG(); - if (menuMgr_ == nullptr) { - menuMgr_ = std::make_shared(); - } - return menuMgr_; -} - -void MagnificationMenuManager::DeleteInstance() -{ - HILOG_DEBUG(); - if (menuMgr_ == nullptr) { - HILOG_ERROR("menuMgr_ is nullptr."); - return; - } - menuMgr_ = nullptr; -} - -MagnificationMenuManager::MagnificationMenuManager() -{ - HILOG_DEBUG(); - manager_ = Singleton::GetInstance().GetMagnificationMgr(); -} - -MagnificationMenuManager::~MagnificationMenuManager() +MagnificationMenuManager::MagnificationMenuManager(std::shared_ptr proxy) + : windowProxy_(proxy) { - if (menuWindow_ != nullptr) { - menuWindow_->Hide(); - menuWindow_->Destroy(); - menuWindow_ = nullptr; - } - surfaceNode_ = nullptr; - canvasNode_ = nullptr; - bgpixelmap_ = nullptr; - rosenImage_ = nullptr; -} - -void MagnificationMenuManager::CreateMenuWindow() -{ - HILOG_DEBUG(); - GetWindowParam(); - menuRect_ = {(static_cast(screenWidth_ - menuSize_) - margin_), ( - static_cast(screenHeight_ - menuSize_) - margin_), menuSize_, menuSize_}; - sptr windowOption = new(std::nothrow) Rosen::WindowOption(); - if (windowOption == nullptr) { - HILOG_ERROR("windowOption is null"); - return; - } - windowOption->SetWindowType(Rosen::WindowType::WINDOW_TYPE_MAGNIFICATION_MENU); - windowOption->SetWindowMode(Rosen::WindowMode::WINDOW_MODE_FLOATING); - windowOption->SetWindowRect(menuRect_); - menuWindow_ = Rosen::Window::Create(MENU_NAME, windowOption); - if (menuWindow_ == nullptr) { - HILOG_ERROR("create failed"); - return; - } - menuWindow_->SetCornerRadius(MENU_CORNER_RADIUS); - surfaceNode_ = menuWindow_->GetSurfaceNode(); - if (surfaceNode_ == nullptr) { - HILOG_ERROR("surfaceNode_ is nullptr."); - return; - } - rsUIContext_ = surfaceNode_->GetRSUIContext(); - canvasNode_ = Rosen::RSCanvasNode::Create(false, false, rsUIContext_); - if (canvasNode_ == nullptr) { - HILOG_ERROR("create canvasNode_ fail."); - return; - } - canvasNode_->SetSkipCheckInMultiInstance(true); - surfaceNode_->SetAbilityBGAlpha(BG_ALPHA); - surfaceNode_->AddChild(canvasNode_, -1); - canvasNode_->SetBounds(0, 0, menuSize_, menuSize_); - canvasNode_->SetFrame(0, 0, menuSize_, menuSize_); - canvasNode_->SetPositionZ(Rosen::RSSurfaceNode::POINTER_WINDOW_POSITION_Z); - canvasNode_->SetRotation(0); - rosenImage_ = std::make_shared(); -} - -void MagnificationMenuManager::LoadMenuBgImage(uint32_t mode) -{ - HILOG_DEBUG(); - std::string path = FULL_SCREEN_PATH; - if (mode == WINDOW_MAGNIFICATION) { - path = WINDOW_PATH; - } - bgpixelmap_ = DecodePixelMap(path, allocatorType_); - if (bgpixelmap_ == nullptr) { - HILOG_ERROR("DecodePixelMap failed."); - return; - } - if (canvasNode_ == nullptr) { - HILOG_ERROR("canvasNode_ is nullptr."); - return; - } - canvasNode_->SetBgImageWidth(menuSize_); - canvasNode_->SetBgImageHeight(menuSize_); - canvasNode_->SetBgImagePositionX(0); - canvasNode_->SetBgImagePositionY(0); - if (rosenImage_ == nullptr) { - HILOG_ERROR("rosenImage_ is nullptr."); - return; - } - rosenImage_->SetPixelMap(bgpixelmap_); - rosenImage_->SetImageFit(static_cast(Rosen::ImageFit::FILL)); - canvasNode_->SetBgImage(rosenImage_); - menuWindow_->Show(); } void MagnificationMenuManager::ShowMenuWindow(uint32_t mode) { HILOG_INFO(); - GetWindowParam(); - currentType_ = Singleton::GetInstance().GetMagnificationType(); - menuMode_ = Singleton::GetInstance().GetMagnificationMode(); - if (currentType_ != SWITCH_MAGNIFICATION) { - HILOG_WARN("no need show menu."); + CHECK_PROXY_PTR_VOID() + if (windowProxy_->IsMenuShown()) { + HILOG_INFO("no need show menu."); return; } - - if (menuWindow_ == nullptr) { - HILOG_ERROR("window is null. need create."); - CreateMenuWindow(); - } - - if (menuWindow_ == nullptr) { - HILOG_ERROR("create window failed."); + uint32_t currentType = Singleton::GetInstance().GetMagnificationType(); + if (currentType != SWITCH_MAGNIFICATION) { + HILOG_INFO("no need show menu."); return; } - - LoadMenuBgImage(mode); - FlushImplicitTransaction(); - isMenuShown_ = true; + windowProxy_->SetCurrentType(currentType); + windowProxy_->ShowMenuWindow(mode); } void MagnificationMenuManager::DisableMenuWindow() { HILOG_INFO(); + CHECK_PROXY_PTR_VOID() std::lock_guard lock(mutex_); - if (!isMenuShown_) { - HILOG_INFO("menu not shown."); - return; - } - if (surfaceNode_ != nullptr) { - surfaceNode_->SetVisible(false); - surfaceNode_->ClearChildren(); - FlushImplicitTransaction(); - } - - isMenuShown_ = false; - if (menuWindow_ != nullptr) { - menuWindow_->Hide(); - menuWindow_->Destroy(); - menuWindow_ = nullptr; - } - surfaceNode_ = nullptr; - canvasNode_ = nullptr; - rsUIContext_ = nullptr; - bgpixelmap_ = nullptr; - rosenImage_ = nullptr; + windowProxy_->DisableMenuWindow(); } void MagnificationMenuManager::MoveMenuWindow(int32_t deltaX, int32_t deltaY) { HILOG_DEBUG(); - if (menuWindow_ == nullptr) { - HILOG_ERROR("menuWindow_ is null."); - return; - } - int32_t menuPosX = menuRect_.posX_ + deltaX; - int32_t menuPosY = menuRect_.posY_ + deltaY; - - menuRect_.posX_ = menuPosX; - menuRect_.posY_ = menuPosY; - - AdjustMenuPosition(); - menuWindow_->MoveTo(menuRect_.posX_, menuRect_.posY_); + CHECK_PROXY_PTR_VOID() + windowProxy_->MoveMenuWindow(deltaX, deltaY); } void MagnificationMenuManager::AttachToEdge() { - if (menuWindow_ == nullptr) { - HILOG_ERROR("menuWindow_ is null."); - return; - } - - if (menuRect_.posX_ < static_cast(screenWidth_ / DIVISOR_TWO)) { - menuRect_.posX_ = margin_; - } else { - menuRect_.posX_ = static_cast(screenWidth_ - menuSize_) - margin_; - } - menuWindow_->MoveTo(menuRect_.posX_, menuRect_.posY_); + HILOG_DEBUG(); + CHECK_PROXY_PTR_VOID() + windowProxy_->AttachToEdge(); } void MagnificationMenuManager::SetCurrentType(uint32_t type) { - currentType_ = type; + HILOG_DEBUG(); + CHECK_PROXY_PTR_VOID() + windowProxy_->SetCurrentType(type); } bool MagnificationMenuManager::IsTapOnMenu(int32_t posX, int32_t posY) { - if (!isMenuShown_) { + HILOG_DEBUG(); + if (windowProxy_ == nullptr) { + HILOG_ERROR("windowProxy_ is nullptr."); return false; } - return Utils::IsInRect(posX, posY, menuRect_); + return windowProxy_->IsTapOnMenu(posX, posY); } void MagnificationMenuManager::OnMenuTap() { - if (manager_ == nullptr) { - HILOG_ERROR("manager_ is null."); - return; - } - DisableMenuWindow(); - ChangeMode(); - manager_->OnModeChanged(menuMode_); - ShowMenuWindow(menuMode_); -} - -void MagnificationMenuManager::ChangeMode() -{ - if (menuMode_ == WINDOW_MAGNIFICATION) { - menuMode_ = FULL_SCREEN_MAGNIFICATION; - return; - } - if (menuMode_ == FULL_SCREEN_MAGNIFICATION) { - menuMode_ = WINDOW_MAGNIFICATION; - return; - } -} - -void MagnificationMenuManager::AdjustMenuPosition() -{ - if (menuRect_.posX_ < margin_) { - menuRect_.posX_ = margin_; - } - - if (menuRect_.posY_ < margin_) { - menuRect_.posY_ = margin_; - } - - if (menuRect_.posX_ + static_cast(menuRect_.width_) + margin_ > static_cast(screenWidth_)) { - menuRect_.posX_ = static_cast(screenWidth_) - static_cast(menuRect_.width_) - margin_; - } - - if (menuRect_.posY_ + static_cast(menuRect_.height_) + margin_ > static_cast(screenHeight_)) { - menuRect_.posY_ = static_cast(screenHeight_) - static_cast(menuRect_.height_) - margin_; - } -} - -std::shared_ptr MagnificationMenuManager::DecodePixelMap( - const std::string& pathName, const Media::AllocatorType& allocatorType) -{ - uint32_t errCode = 0; - std::unique_ptr imageSource = - Media::ImageSource::CreateImageSource(pathName, Media::SourceOptions(), errCode); - if (imageSource == nullptr || errCode != 0) { - HILOG_ERROR("CreateImageSource failed."); - return nullptr; - } - - Media::DecodeOptions decodeOpt; - decodeOpt.allocatorType = allocatorType; - std::shared_ptr pixelmap = imageSource->CreatePixelMap(decodeOpt, errCode); - if (pixelmap == nullptr || errCode != 0) { - HILOG_ERROR("CreatePixelMap failed."); - return nullptr; - } - return pixelmap; -} - -void MagnificationMenuManager::GetWindowParam() -{ -#ifdef OHOS_BUILD_ENABLE_DISPLAY_MANAGER - AccessibilityDisplayManager &displayMgr = Singleton::GetInstance(); - uint64_t screenId_ = displayMgr.GetDefaultDisplayId(); - OHOS::Rosen::DisplayOrientation currentOrientation = displayMgr.GetOrientation(); - orientation_ = currentOrientation; - sptr display = displayMgr.GetDisplay(screenId_); - if (display == nullptr) { - HILOG_ERROR("display is nullptr."); - return; - } - screenWidth_ = static_cast(display->GetWidth()); - screenHeight_ = static_cast(display->GetHeight()); - screenRect_ = {0, 0, screenWidth_, screenHeight_}; -#else - HILOG_INFO("not support"); -#endif + HILOG_DEBUG(); + CHECK_PROXY_PTR_VOID() + windowProxy_->DisableMenuWindow(); + uint32_t mode = windowProxy_->ChangeMode(); + Singleton::GetInstance().OnModeChanged(mode); + ShowMenuWindow(mode); } void MagnificationMenuManager::RefreshWindowParam() { HILOG_DEBUG(); - if (isMenuShown_) { - DisableMenuWindow(); - ShowMenuWindow(menuMode_); - } else { - GetWindowParam(); - } -} - -void MagnificationMenuManager::FlushImplicitTransaction() -{ - if (rsUIContext_ != nullptr) { - auto rsTransaction = rsUIContext_->GetRSTransaction(); - if (rsTransaction != nullptr) { - rsTransaction->FlushImplicitTransaction(); - } - } else { - Rosen::RSTransaction::FlushImplicitTransaction(); - } + CHECK_PROXY_PTR_VOID() + windowProxy_->RefreshWindowParamMenu(); } } // namespace Accessibility } // namespace OHOS diff --git a/services/aams/src/magnification_window_proxy.cpp b/services/aams/src/magnification_window_proxy.cpp new file mode 100644 index 00000000..ea3d3288 --- /dev/null +++ b/services/aams/src/magnification_window_proxy.cpp @@ -0,0 +1,485 @@ +/* + * Copyright (C) 2025-2025 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +// LCOV_EXCL_START +#include "magnification_window_proxy.h" +#include + +namespace OHOS { +namespace Accessibility { + +MagnificationWindowProxy::MagnificationWindowProxy() +{ + handle_ = dlopen(windowLibName_.c_str(), RTLD_LAZY | RTLD_NOW); + if (!handle_) { + HILOG_ERROR("dlopen error: %{public}s", dlerror()); + } +} + +MagnificationWindowProxy::~MagnificationWindowProxy() +{ + if (!handle_) { + return; + } + + int ret = dlclose(handle_); + HILOG_DEBUG("dlclose ret: %{public}d", ret); + char* error = dlerror(); + if (error) { + HILOG_ERROR("dlclose error: %{public}s", error); + } + handle_ = nullptr; +} + +void* MagnificationWindowProxy::GetFunc(const std::string& funcName) +{ + HILOG_DEBUG("Get func start, %{public}s", funcName.c_str()); + void* func = dlsym(handle_, funcName.c_str()); + char* error = dlerror(); + if (error != nullptr) { + HILOG_ERROR(" %{public}s", error); + return nullptr; + } + + HILOG_DEBUG("Get func end, %{public}s", funcName.c_str()); + return func; +} + +// common +void MagnificationWindowProxy::EnableMagnification(uint32_t magnificationType, int32_t posX, int32_t posY) +{ + if (!handle_) { + HILOG_ERROR("handle is null"); + return; + } + + using Enabel = void (*)(uint32_t magnificationType, int32_t posX, int32_t posY); + Enabel enabelFun = (Enabel)GetFunc("EnableMagnification"); + if (!enabelFun) { + HILOG_ERROR("EnableMagnification func is null"); + return; + } + enabelFun(magnificationType, posX, posY); +} + +void MagnificationWindowProxy::DisableMagnification(uint32_t magnificationType, bool needClear) +{ + if (!handle_) { + HILOG_ERROR("handle is null"); + return; + } + + using Disable = void (*)(uint32_t magnificationType, bool needClear); + Disable disableFun = (Disable)GetFunc("DisableMagnification"); + if (!disableFun) { + HILOG_ERROR("DisableMagnification func is null"); + return; + } + disableFun(magnificationType, needClear); +} + +void MagnificationWindowProxy::SetScale(uint32_t magnificationType, float scaleSpan) +{ + if (!handle_) { + HILOG_ERROR("handle is null"); + return; + } + + using SetScale = void (*)(uint32_t magnificationType, float scaleSpan); + SetScale setScaleFun = (SetScale)GetFunc("SetScale"); + if (!setScaleFun) { + HILOG_ERROR("SetScale func is null"); + return; + } + setScaleFun(magnificationType, scaleSpan); +} + +void MagnificationWindowProxy::MoveMagnification(uint32_t magnificationType, int32_t deltaX, int32_t deltaY) +{ + if (!handle_) { + HILOG_ERROR("handle is null"); + return; + } + + using MoveMagnification = void (*)(uint32_t magnificationType, int32_t deltaX, int32_t deltaY); + MoveMagnification moveFun = (MoveMagnification)GetFunc("MoveMagnification"); + if (!moveFun) { + HILOG_ERROR("MoveMagnification func is null"); + return; + } + moveFun(magnificationType, deltaX, deltaY); +} + +PointerPos MagnificationWindowProxy::GetSourceCenter() +{ + PointerPos pos = {0, 0}; + if (!handle_) { + HILOG_ERROR("handle is null"); + return pos; + } + + using GetSourceCenter = PointerPos (*)(); + GetSourceCenter getSourceCenterFun = (GetSourceCenter)GetFunc("GetSourceCenter"); + if (!getSourceCenterFun) { + HILOG_ERROR("GetSourceCenter func is null"); + return pos; + } + return getSourceCenterFun(); +} + +void MagnificationWindowProxy::FollowFocuseElement(uint32_t magnificationType, int32_t centerX, int32_t centerY) +{ + if (!handle_) { + HILOG_ERROR("handle is null"); + return; + } + + using FollowFocuseElement = void (*)(uint32_t magnificationType, int32_t deltaX, int32_t deltaY); + FollowFocuseElement followFocuseElementFun = (FollowFocuseElement)GetFunc("FollowFocuseElement"); + if (!followFocuseElementFun) { + HILOG_ERROR("FollowFocuseElement func is null"); + return; + } + followFocuseElementFun(magnificationType, centerX, centerY); +} + +void MagnificationWindowProxy::InitMagnificationParam(float scale) +{ + if (!handle_) { + HILOG_ERROR("handle is null"); + return; + } + + using InitMagnificationParam = void (*)(float scale); + InitMagnificationParam initParamFun = (InitMagnificationParam)GetFunc("InitMagnificationParam"); + if (!initParamFun) { + HILOG_ERROR("InitMagnificationParam func is null"); + return; + } + initParamFun(scale); +} + +float MagnificationWindowProxy::GetScale() +{ + if (!handle_) { + HILOG_ERROR("handle is null"); + return DEFAULT_SCALE; + } + + using GetScale = float (*)(); + GetScale getScaleFun = (GetScale)GetFunc("GetScale"); + if (!getScaleFun) { + HILOG_ERROR("GetScale func is null"); + return DEFAULT_SCALE; + } + return getScaleFun(); +} + +void MagnificationWindowProxy::ShowMagnification(uint32_t magnificationType) +{ + if (!handle_) { + HILOG_ERROR("handle is null"); + return; + } + + using ShowMagnification = void (*)(uint32_t magnificationType); + ShowMagnification showFun = (ShowMagnification)GetFunc("ShowMagnification"); + if (!showFun) { + HILOG_ERROR("ShowMagnification func is null"); + return; + } + showFun(magnificationType); +} + +void MagnificationWindowProxy::RefreshWindowParam(uint32_t magnificationType) +{ + if (!handle_) { + HILOG_ERROR("handle is null"); + return; + } + + using RefreshWindowParam = void (*)(uint32_t magnificationType); + RefreshWindowParam refreshWindowParamFun = (RefreshWindowParam)GetFunc("RefreshWindowParam"); + if (!refreshWindowParamFun) { + HILOG_ERROR("RefreshWindowParam func is null"); + return; + } + refreshWindowParamFun(magnificationType); +} + +PointerPos MagnificationWindowProxy::ConvertCoordinates(int32_t posX, int32_t posY) +{ + PointerPos pos = {posX, posY}; + if (!handle_) { + HILOG_ERROR("handle is null"); + return pos; + } + + using ConvertCoordinates = PointerPos (*)(int32_t posX, int32_t posY); + ConvertCoordinates convertCoordinatesFun = (ConvertCoordinates)GetFunc("ConvertCoordinates"); + if (!convertCoordinatesFun) { + HILOG_ERROR("ConvertCoordinates func is null"); + return pos; + } + return convertCoordinatesFun(posX, posY); +} + +bool MagnificationWindowProxy::IsMagnificationWindowShow(uint32_t magnificationType) +{ + if (!handle_) { + HILOG_ERROR("handle is null"); + return false; + } + + using IsMagnificationWindowShow = bool (*)(uint32_t magnificationType); + IsMagnificationWindowShow isShowFun = (IsMagnificationWindowShow)GetFunc("IsMagnificationWindowShow"); + if (!isShowFun) { + HILOG_ERROR("IsMagnificationWindowShow func is null"); + return false; + } + return isShowFun(magnificationType); +} + +// full magnification +PointerPos MagnificationWindowProxy::ConvertGesture(uint32_t type, PointerPos coordinates) +{ + if (!handle_) { + HILOG_ERROR("handle is null"); + return coordinates; + } + + using ConvertGesture = PointerPos (*)(uint32_t type, PointerPos coordinates); + ConvertGesture convertGestureFun = (ConvertGesture)GetFunc("ConvertGesture"); + if (!convertGestureFun) { + HILOG_ERROR("ConvertGesture func is null"); + return coordinates; + } + return convertGestureFun(type, coordinates); +} + +uint32_t MagnificationWindowProxy::CheckTapOnHotArea(int32_t posX, int32_t posY) +{ + if (!handle_) { + HILOG_ERROR("handle is null"); + return INVALID_GESTURE_TYPE; + } + + using CheckTapOnHotArea = uint32_t (*)(int32_t posX, int32_t posY); + CheckTapOnHotArea checkTapOnHotAreaFun = (CheckTapOnHotArea)GetFunc("CheckTapOnHotArea"); + if (!checkTapOnHotAreaFun) { + HILOG_ERROR("CheckTapOnHotArea func is null"); + return INVALID_GESTURE_TYPE; + } + return checkTapOnHotAreaFun(posX, posY); +} + +// window magnification +bool MagnificationWindowProxy::IsTapOnHotArea(int32_t posX, int32_t posY) +{ + if (!handle_) { + HILOG_ERROR("handle is null"); + return false; + } + + using IsTapOnHotArea = bool (*)(int32_t posX, int32_t posY); + IsTapOnHotArea isTapOnHotAreaFun = (IsTapOnHotArea)GetFunc("IsTapOnHotArea"); + if (!isTapOnHotAreaFun) { + HILOG_ERROR("IsTapOnHotArea func is null"); + return false; + } + return isTapOnHotAreaFun(posX, posY); +} + +bool MagnificationWindowProxy::IsTapOnMagnificationWindow(int32_t posX, int32_t posY) +{ + if (!handle_) { + HILOG_ERROR("handle is null"); + return false; + } + + using IsTapOnMagnificationWindow = bool (*)(int32_t posX, int32_t posY); + IsTapOnMagnificationWindow isTapOnMagnificationWindowFun = + (IsTapOnMagnificationWindow)GetFunc("IsTapOnMagnificationWindow"); + if (!isTapOnMagnificationWindowFun) { + HILOG_ERROR("IsTapOnMagnificationWindow func is null"); + return false; + } + return isTapOnMagnificationWindowFun(posX, posY); +} + +void MagnificationWindowProxy::FixSourceCenter(bool needFix) +{ + if (!handle_) { + HILOG_ERROR("handle is null"); + return; + } + + using FixSourceCenter = void (*)(bool needFix); + FixSourceCenter fixSourceCenterFun = (FixSourceCenter)GetFunc("FixSourceCenter"); + if (!fixSourceCenterFun) { + HILOG_ERROR("FixSourceCenter func is null"); + return; + } + fixSourceCenterFun(needFix); +} + +// menu +void MagnificationWindowProxy::ShowMenuWindow(uint32_t mode) +{ + if (!handle_) { + HILOG_ERROR("handle is null"); + return; + } + + using ShowMenuWindow = void (*)(uint32_t mode); + ShowMenuWindow showMenuFun = (ShowMenuWindow)GetFunc("ShowMenuWindow"); + if (!showMenuFun) { + HILOG_ERROR("ShowMenuWindow func is null"); + return; + } + showMenuFun(mode); +} + +void MagnificationWindowProxy::DisableMenuWindow() +{ + if (!handle_) { + HILOG_ERROR("handle is null"); + return; + } + + using DisableMenuWindow = void (*)(); + DisableMenuWindow disableMenuFun = (DisableMenuWindow)GetFunc("DisableMenuWindow"); + if (!disableMenuFun) { + HILOG_ERROR("DisableMenuWindow func is null"); + return; + } + disableMenuFun(); +} + +bool MagnificationWindowProxy::IsTapOnMenu(int32_t posX, int32_t posY) +{ + if (!handle_) { + HILOG_ERROR("handle is null"); + return false; + } + + using IsTapOnMenu = bool (*)(int32_t posX, int32_t posY); + IsTapOnMenu isTapOnMenuFun = (IsTapOnMenu)GetFunc("IsTapOnMenu"); + if (!isTapOnMenuFun) { + HILOG_ERROR("IsTapOnMenu func is null"); + return false; + } + return isTapOnMenuFun(posX, posY); +} + +void MagnificationWindowProxy::MoveMenuWindow(int32_t deltaX, int32_t deltaY) +{ + if (!handle_) { + HILOG_ERROR("handle is null"); + return; + } + + using MoveMenuWindow = void (*)(int32_t deltaX, int32_t deltaY); + MoveMenuWindow moveMenuFun = (MoveMenuWindow)GetFunc("MoveMenuWindow"); + if (!moveMenuFun) { + HILOG_ERROR("MoveMenuWindow func is null"); + return; + } + moveMenuFun(deltaX, deltaY); +} + +void MagnificationWindowProxy::SetCurrentType(uint32_t type) +{ + if (!handle_) { + HILOG_ERROR("handle is null"); + return; + } + + using SetCurrentType = void (*)(uint32_t type); + SetCurrentType setTypeFun = (SetCurrentType)GetFunc("SetCurrentType"); + if (!setTypeFun) { + HILOG_ERROR("SetCurrentType func is null"); + return; + } + setTypeFun(type); +} + +void MagnificationWindowProxy::AttachToEdge() +{ + if (!handle_) { + HILOG_ERROR("handle is null"); + return; + } + + using AttachToEdge = void (*)(); + AttachToEdge attachToEdgeFun = (AttachToEdge)GetFunc("AttachToEdge"); + if (!attachToEdgeFun) { + HILOG_ERROR("AttachToEdge func is null"); + return; + } + attachToEdgeFun(); +} + +void MagnificationWindowProxy::RefreshWindowParamMenu() +{ + if (!handle_) { + HILOG_ERROR("handle is null"); + return; + } + + using RefreshWindowParamMenu = void (*)(); + RefreshWindowParamMenu refreshMenuParamFun = + (RefreshWindowParamMenu)GetFunc("RefreshWindowParamMenu"); + if (!refreshMenuParamFun) { + HILOG_ERROR("RefreshWindowParamMenu func is null"); + return; + } + refreshMenuParamFun(); +} + +uint32_t MagnificationWindowProxy::ChangeMode() +{ + if (!handle_) { + HILOG_ERROR("handle is null"); + return 0; + } + + using ChangeMode = uint32_t (*)(); + ChangeMode changeModeFun = (ChangeMode)GetFunc("ChangeMode"); + if (!changeModeFun) { + HILOG_ERROR("ChangeMode func is null"); + return 0; + } + return changeModeFun(); +} + +bool MagnificationWindowProxy::IsMenuShown() +{ + if (!handle_) { + HILOG_ERROR("handle is null"); + return false; + } + + using IsMenuShown = bool (*)(); + IsMenuShown isMenuShownFun = (IsMenuShown)GetFunc("IsMenuShown"); + if (!isMenuShownFun) { + HILOG_ERROR("IsTapOnMenu func is null"); + return false; + } + return isMenuShownFun(); +} +} // namespace Accessibility +} // namespace OHOS +// LCOV_EXCL_STOP \ No newline at end of file diff --git a/services/aams/src/window_magnification_gesture.cpp b/services/aams/src/window_magnification_gesture.cpp index 3cf6fd10..0ddf1982 100644 --- a/services/aams/src/window_magnification_gesture.cpp +++ b/services/aams/src/window_magnification_gesture.cpp @@ -141,8 +141,9 @@ void MagnificationGestureEventHandler::ProcessEvent(const AppExecFwk::InnerEvent } WindowMagnificationGesture::WindowMagnificationGesture( - std::shared_ptr windowMagnificationManager) - : windowMagnificationManager_(windowMagnificationManager) + std::shared_ptr windowMagnificationManager, + std::shared_ptr menuManager) + : windowMagnificationManager_(windowMagnificationManager), menuManager_(menuManager) { HILOG_DEBUG(); runner_ = Singleton::GetInstance().GetInputManagerRunner(); @@ -234,9 +235,11 @@ void WindowMagnificationGesture::DestroyEvents() SetGestureState(MagnificationGestureState::READY_STATE, HANDLER); if (windowMagnificationManager_ != nullptr && windowMagnificationManager_->IsMagnificationWindowShow()) { - HILOG_INFO("window gesture disable."); + HILOG_DEBUG("window gesture disable."); windowMagnificationManager_->DisableWindowMagnification(); - Singleton::GetInstance().DisableMenuWindow(); + if (menuManager_ != nullptr) { + menuManager_->DisableMenuWindow(); + } isSingleTapOnWindow_ = false; isTapOnHotArea_ = false; Singleton::GetInstance().AnnouncedForMagnification( @@ -457,9 +460,9 @@ void WindowMagnificationGesture::HandleZoomInStateDown(MMI::PointerEvent &event) if (size != static_cast(PointerCountSize::POINTER_SIZE_1)) { return; } - - isTapOnMenu_ = Singleton::GetInstance().IsTapOnMenu(pointerItem.GetDisplayX(), - pointerItem.GetDisplayY()); + if (menuManager_ != nullptr) { + isTapOnMenu_ = menuManager_->IsTapOnMenu(pointerItem.GetDisplayX(), pointerItem.GetDisplayY()); + } if (isTapOnMenu_) { isTapOnHotArea_ = false; isSingleTapOnWindow_ = false; @@ -567,8 +570,8 @@ void WindowMagnificationGesture::HandleZoomInStateOneFingerDownStateUp(MMI::Poin Clear(); SetGestureState(MagnificationGestureState::READY_STATE, event.GetPointerAction()); } else { - if (isTapOnMenu_) { - Singleton::GetInstance().OnMenuTap(); + if (isTapOnMenu_ && menuManager_ != nullptr) { + menuManager_->OnMenuTap(); } else { handler_->SendEvent(static_cast(MagnificationGestureMsg::TRIPLE_TAP_FAIL_MSG), static_cast(MagnificationGestureState::ZOOMIN_STATE), @@ -801,7 +804,7 @@ void WindowMagnificationGesture::HandleMenuSlidingStateMove(MMI::PointerEvent &e return; } - if (isTapOnMenu_) { + if (isTapOnMenu_ && menuManager_ != nullptr) { if (lastSlidingEvent_ == nullptr) { lastSlidingEvent_ = std::make_shared(event); } @@ -813,7 +816,7 @@ void WindowMagnificationGesture::HandleMenuSlidingStateMove(MMI::PointerEvent &e int32_t deltaX = currentItem.GetDisplayX() - lastSlidingItem.GetDisplayX(); int32_t deltaY = currentItem.GetDisplayY() - lastSlidingItem.GetDisplayY(); - Singleton::GetInstance().MoveMenuWindow(deltaX, deltaY); + menuManager_->MoveMenuWindow(deltaX, deltaY); lastSlidingEvent_ = std::make_shared(event); } else { @@ -831,7 +834,9 @@ void WindowMagnificationGesture::HandleMenuSlidingStateUp(MMI::PointerEvent &eve lastSlidingEvent_ = nullptr; isTapOnMenu_ = false; Clear(); - Singleton::GetInstance().AttachToEdge(); + if (menuManager_ != nullptr) { + menuManager_->AttachToEdge(); + } SetGestureState(MagnificationGestureState::ZOOMIN_STATE, event.GetPointerAction()); } @@ -908,10 +913,13 @@ void WindowMagnificationGesture::OnTripleTap(int32_t centerX, int32_t centerY) HILOG_ERROR("windowMagnificationManager_ is nullptr."); return; } - + if (menuManager_ == nullptr) { + HILOG_ERROR("menuManager_ is nullptr."); + return; + } if (windowMagnificationManager_->IsMagnificationWindowShow()) { windowMagnificationManager_->DisableWindowMagnification(); - Singleton::GetInstance().DisableMenuWindow(); + menuManager_->DisableMenuWindow(); Singleton::GetInstance().AnnouncedForMagnification( AnnounceType::ANNOUNCE_MAGNIFICATION_DISABLE); isSingleTapOnWindow_ = false; @@ -920,7 +928,7 @@ void WindowMagnificationGesture::OnTripleTap(int32_t centerX, int32_t centerY) windowMagnificationManager_->EnableWindowMagnification(centerX, centerY); Singleton::GetInstance().AnnouncedForMagnification( AnnounceType::ANNOUNCE_MAGNIFICATION_SCALE); - Singleton::GetInstance().ShowMenuWindow(WINDOW_MAGNIFICATION); + menuManager_->ShowMenuWindow(WINDOW_MAGNIFICATION); } } @@ -969,7 +977,9 @@ void WindowMagnificationGesture::ShieldZoomGesture(bool state) Singleton::GetInstance().AnnouncedForMagnification( AnnounceType::ANNOUNCE_MAGNIFICATION_DISABLE); } - Singleton::GetInstance().DisableMenuWindow(); + if (menuManager_ != nullptr) { + menuManager_->DisableMenuWindow(); + } isSingleTapOnWindow_ = false; isTapOnHotArea_ = false; } diff --git a/services/aams/src/window_magnification_manager.cpp b/services/aams/src/window_magnification_manager.cpp index d93322d4..02c62c61 100644 --- a/services/aams/src/window_magnification_manager.cpp +++ b/services/aams/src/window_magnification_manager.cpp @@ -23,131 +23,25 @@ namespace OHOS { namespace Accessibility { -namespace { - constexpr int32_t BAR_START = 400; - constexpr int32_t BAR_END = 550; -} - -WindowMagnificationManager::WindowMagnificationManager() -{ - HILOG_INFO(); - GetWindowParam(); - InitMagnificationParam(); -} -void WindowMagnificationManager::CreateMagnificationWindow(int32_t posX, int32_t posY) +WindowMagnificationManager::WindowMagnificationManager( + std::shared_ptr proxy) : windowProxy_(proxy) { - HILOG_DEBUG(); - windowRect_ = GetWindowRectFromPointer(posX, posY); - sptr windowOption = new(std::nothrow) Rosen::WindowOption(); - if (windowOption == nullptr) { - HILOG_ERROR("windowOption is null."); - return; - } - windowOption->SetWindowType(Rosen::WindowType::WINDOW_TYPE_MAGNIFICATION); - windowOption->SetWindowMode(Rosen::WindowMode::WINDOW_MODE_FLOATING); - windowOption->SetWindowRect(windowRect_); - windowOption->SetFocusable(false); - window_ = Rosen::Window::Create(WINDOW_NAME, windowOption); - if (window_ == nullptr) { - HILOG_ERROR("create failed."); - return; - } - window_->SetCornerRadius(CORNER_RADIUS); - surfaceNode_ = window_->GetSurfaceNode(); - if (surfaceNode_ == nullptr) { - HILOG_ERROR("surfaceNode_ is nullptr."); - return; - } - rsUIContext_ = surfaceNode_->GetRSUIContext(); - canvasNode_ = Rosen::RSCanvasNode::Create(false, false, rsUIContext_); - if (canvasNode_ == nullptr) { - HILOG_ERROR("canvasNode_ is nullptr."); - return; - } - canvasNode_->SetSkipCheckInMultiInstance(true); -} - -void WindowMagnificationManager::DrawRuoundRectFrame() -{ - if (surfaceNode_ == nullptr) { - HILOG_ERROR("get surfaceNode_ failed."); - return; - } - - if (canvasNode_ == nullptr) { - HILOG_ERROR("create canvasNode_ fail"); - return; - } - surfaceNode_->SetAbilityBGAlpha(BG_ALPHA); - surfaceNode_->AddChild(canvasNode_, -1); - canvasNode_->SetBounds(0, 0, windowWidth_, windowHeight_); - canvasNode_->SetFrame(0, 0, windowWidth_, windowHeight_); - canvasNode_->SetPositionZ(Rosen::RSSurfaceNode::POINTER_WINDOW_POSITION_Z); - canvasNode_->SetRotation(0); - - auto canvas = canvasNode_->BeginRecording(windowWidth_, windowHeight_); - Rosen::Drawing::Pen pen; - pen.SetAntiAlias(true); - pen.SetColor(ORANGE_COLOR); - pen.SetWidth(PEN_WIDTH); - canvas->AttachPen(pen); - Rosen::Drawing::Path path; - path.AddRoundRect({ROUND_RECT_MARGIN, ROUND_RECT_MARGIN, - windowWidth_ - ROUND_RECT_MARGIN, windowHeight_ - ROUND_RECT_MARGIN}, - CORNER_RADIUS, CORNER_RADIUS, Rosen::Drawing::PathDirection::CW_DIRECTION); - canvas->DrawPath(path); - canvas->DetachPen(); - - Rosen::Drawing::Pen linePen; - linePen.SetAntiAlias(true); - linePen.SetColor(ORANGE_COLOR); - linePen.SetWidth(PEN_WIDTH); - canvas->AttachPen(linePen); - auto p1 = Rosen::Drawing::Point(BAR_START, windowHeight_ - barMargin_); - auto p2 = Rosen::Drawing::Point(BAR_END, windowHeight_ - barMargin_); - canvas->DrawLine(p1, p2); - canvas->DetachPen(); - - Rosen::Drawing::Brush brush; - brush.SetAntiAlias(true); - brush.SetColor(ORANGE_COLOR); - canvas->AttachBrush(brush); - canvas->DrawCircle(p1, static_cast(PEN_WIDTH / DIVISOR_TWO)); - canvas->DrawCircle(p2, static_cast(PEN_WIDTH / DIVISOR_TWO)); - canvas->DetachBrush(); - canvasNode_->FinishRecording(); } void WindowMagnificationManager::EnableWindowMagnification(int32_t centerX, int32_t centerY) { HILOG_INFO("centerX = %{public}d, centerY = %{public}d.", centerX, centerY); - GetWindowParam(); - InitMagnificationParam(); - if (window_ == nullptr) { - HILOG_ERROR("window is null. need create."); - CreateMagnificationWindow(centerX, centerY); - } - - if (window_ == nullptr) { - HILOG_ERROR("create window failed."); - return; - } - sourceRect_ = GetSourceRectFromPointer(centerX, centerY); - CalculateAnchorOffset(); - UpdateRelativeRect(); - window_->SetFrameRectForPartialZoomIn(relativeRect_); - DrawRuoundRectFrame(); - window_->Show(); - FlushImplicitTransaction(); - isMagnificationWindowShow_ = true; + CHECK_PROXY_PTR_VOID() + float scale = Singleton::GetInstance().GetMagnificationScale(); + windowProxy_->InitMagnificationParam(scale); + windowProxy_->EnableMagnification(WINDOW_MAGNIFICATION, centerX, centerY); } void WindowMagnificationManager::ShowWindowMagnification() { - int32_t centerX = static_cast(screenWidth_ / DIVISOR_TWO); - int32_t centerY = static_cast(screenHeight_ / DIVISOR_TWO); - EnableWindowMagnification(centerX, centerY); + CHECK_PROXY_PTR_VOID() + windowProxy_->ShowMagnification(WINDOW_MAGNIFICATION); } void WindowMagnificationManager::ShowWindowMagnificationWithPosition(PointerPos pos) @@ -162,393 +56,108 @@ void WindowMagnificationManager::ShowWindowMagnificationWithPosition(PointerPos void WindowMagnificationManager::DisableWindowMagnification(bool needClear) { HILOG_INFO(); + CHECK_PROXY_PTR_VOID() std::lock_guard lock(mutex_); - if (needClear && surfaceNode_ != nullptr) { - HILOG_DEBUG("claer surfaceNode"); - surfaceNode_->SetVisible(false); - surfaceNode_->ClearChildren(); - FlushImplicitTransaction(); - } - - if (window_ != nullptr) { - window_->Hide(); - window_->Destroy(); - window_ = nullptr; - } - surfaceNode_ = nullptr; - canvasNode_ = nullptr; - rsUIContext_ = nullptr; - isMagnificationWindowShow_ = false; - int32_t anchorOffsetX_ = 0; - int32_t anchorOffsetY_ = 0; + windowProxy_->DisableMagnification(WINDOW_MAGNIFICATION, needClear); } void WindowMagnificationManager::SetScale(float deltaSpan) { HILOG_DEBUG(); - if (screenWidth_ == 0 || screenHeight_ == 0 || abs(screenSpan_) < EPS) { - HILOG_ERROR("screen param invalid."); - return; - } - - float ratio = deltaSpan / screenSpan_; - float tmpScale = scale_ + ratio * scale_; - if (tmpScale > MAX_SCALE) { - tmpScale = MAX_SCALE; - } - if (tmpScale < DEFAULT_SCALE) { - tmpScale = DEFAULT_SCALE; - } - - uint32_t newWidth = static_cast(windowRect_.width_ / tmpScale); - uint32_t newHeight = static_cast(windowRect_.height_ / tmpScale); - int32_t newPosX = fixedSourceCenter_.posX - static_cast(newWidth / DIVISOR_TWO); - int32_t newPosY = fixedSourceCenter_.posY - static_cast(newHeight / DIVISOR_TWO); - - Rosen::Rect tmpRect = {newPosX, newPosY, newWidth, newHeight}; - if (!tmpRect.IsInsideOf(screenRect_)) { - HILOG_ERROR("sourceRect out of screenRect."); - return; - } - - if (window_ == nullptr) { - HILOG_ERROR("window_ is nullptr."); - return; - } - - sourceRect_ = tmpRect; - scale_ = tmpScale; - UpdateRelativeRect(); - window_->SetFrameRectForPartialZoomIn(relativeRect_); - DrawRuoundRectFrame(); - FlushImplicitTransaction(); - CalculateAnchorOffset(); + CHECK_PROXY_PTR_VOID() + windowProxy_->SetScale(WINDOW_MAGNIFICATION, deltaSpan); } void WindowMagnificationManager::MoveMagnificationWindow(int32_t deltaX, int32_t deltaY) { - if (window_ == nullptr) { - HILOG_ERROR("window is null."); - return; - } - - int32_t windowPosX = windowRect_.posX_; - int32_t sourcePosX = sourceRect_.posX_; - - if (abs(anchorOffsetX_) <= ANCHOR_OFFSET) { - windowPosX += deltaX; - } - sourcePosX += deltaX; - - int32_t windowPosY = windowRect_.posY_; - int32_t sourcePosY = sourceRect_.posY_; - - if (abs(anchorOffsetY_) <= ANCHOR_OFFSET) { - windowPosY += deltaY; - } - sourcePosY += deltaY; - - windowRect_.posX_ = windowPosX; - windowRect_.posY_ = windowPosY; - AdjustMagnificationWindowPosition(); - - window_->MoveTo(windowRect_.posX_, windowRect_.posY_); - - sourceRect_.posX_ = sourcePosX; - sourceRect_.posY_ = sourcePosY; - AdjustSourceWindowPosition(); - UpdateRelativeRect(); - window_->SetFrameRectForPartialZoomIn(relativeRect_); - DrawRuoundRectFrame(); - FlushImplicitTransaction(); - CalculateAnchorOffset(); -} - -void WindowMagnificationManager::GetWindowParam() -{ - HILOG_INFO(); -#ifdef OHOS_BUILD_ENABLE_DISPLAY_MANAGER - AccessibilityDisplayManager &displayMgr = Singleton::GetInstance(); - screenId_ = displayMgr.GetDefaultDisplayId(); - orientation_ = displayMgr.GetOrientation(); - sptr display = displayMgr.GetDisplay(screenId_); - if (display == nullptr) { - HILOG_ERROR("display is nullptr."); - return; - } - screenWidth_ = static_cast(display->GetWidth()); - screenHeight_ = static_cast(display->GetHeight()); - HILOG_INFO("screenWidth_ = %{public}d, screenHeight_ = %{public}d.", screenWidth_, screenHeight_); - - screenSpan_ = hypot(screenWidth_, screenHeight_); - screenRect_ = {0, 0, screenWidth_, screenHeight_}; -#else - HILOG_INFO("not support"); -#endif -} - -void WindowMagnificationManager::InitMagnificationParam() -{ - scale_ = Singleton::GetInstance().GetMagnificationScale(); + CHECK_PROXY_PTR_VOID() + windowProxy_->MoveMagnification(WINDOW_MAGNIFICATION, deltaX, deltaY); } bool WindowMagnificationManager::IsTapOnHotArea(int32_t posX, int32_t posY) { - if (!isMagnificationWindowShow_) { + if (windowProxy_ == nullptr) { + HILOG_ERROR("windowProxy_ is nullptr."); return false; } - Rosen::Rect innerRect = {windowRect_.posX_ + static_cast(hotAreaWidth_), - windowRect_.posY_ + static_cast(hotAreaWidth_), - windowRect_.width_ - static_cast(2 * hotAreaWidth_), - windowRect_.height_ - static_cast(2 * hotAreaWidth_)}; - Rosen::Rect outRect = {windowRect_.posX_ - static_cast(hotAreaWidth_), - windowRect_.posY_ - static_cast(hotAreaWidth_), - windowRect_.width_ + static_cast(2 * hotAreaWidth_), - windowRect_.height_ + static_cast(2 * hotAreaWidth_)}; - return Utils::IsInRect(posX, posY, outRect) && !(Utils::IsInRect(posX, posY, innerRect)); + return windowProxy_->IsTapOnHotArea(posX, posY); } void WindowMagnificationManager::RefreshWindowParam() { HILOG_DEBUG(); - if (isMagnificationWindowShow_) { - PointerPos center = GetRectCenter(windowRect_); - HILOG_INFO("need refresh window param."); - DisableWindowMagnification(); - EnableWindowMagnification(center.posX, center.posY); - } else { - GetWindowParam(); - } + CHECK_PROXY_PTR_VOID() + windowProxy_->RefreshWindowParam(WINDOW_MAGNIFICATION); } bool WindowMagnificationManager::IsTapOnMagnificationWindow(int32_t posX, int32_t posY) { - return Utils::IsInRect(posX, posY, windowRect_); + if (windowProxy_ == nullptr) { + HILOG_ERROR("windowProxy_ is nullptr."); + return false; + } + return windowProxy_->IsTapOnMagnificationWindow(posX, posY); } PointerPos WindowMagnificationManager::ConvertCoordinates(int32_t posX, int32_t posY) { - PointerPos sourcePoint = {0, 0}; - if ((abs(scale_) < EPS)) { - return sourcePoint; + PointerPos pos = {posX, posY}; + if (windowProxy_ == nullptr) { + HILOG_ERROR("windowProxy_ is nullptr."); + return pos; } - int32_t windowDeltaX = posX - windowRect_.posX_; - int32_t windowDeltaY = posY - windowRect_.posY_; - sourcePoint.posX = sourceRect_.posX_ + static_cast(windowDeltaX / scale_); - sourcePoint.posY = sourceRect_.posY_ + static_cast(windowDeltaY / scale_); - return sourcePoint; + return windowProxy_->ConvertCoordinates(posX, posY); } void WindowMagnificationManager::FixSourceCenter(bool needFix) { - HILOG_DEBUG(); - if (needFix == isFixSourceCenter_) { - return; - } - - isFixSourceCenter_ = needFix; - if (needFix) { - isFixSourceCenter_ = needFix; - float sourceCenterX = (sourceRect_.posX_ + sourceRect_.posX_ + - static_cast(sourceRect_.width_)) / static_cast(DIVISOR_TWO); - float sourceCenterY = (sourceRect_.posY_ + sourceRect_.posY_ + - static_cast(sourceRect_.height_)) / static_cast(DIVISOR_TWO); - fixedSourceCenter_ = {static_cast(sourceCenterX), static_cast(sourceCenterY)}; - } else { - fixedSourceCenter_ = {0, 0}; - } + CHECK_PROXY_PTR_VOID() + windowProxy_->FixSourceCenter(needFix); } void WindowMagnificationManager::PersistScale() { - HILOG_DEBUG(); - Singleton::GetInstance().SetMagnificationScale(scale_); + CHECK_PROXY_PTR_VOID() + float scale = windowProxy_->GetScale(); + HILOG_DEBUG("scale = %{public}f", scale); + Singleton::GetInstance().SetMagnificationScale(scale); Singleton::GetInstance().AnnouncedForMagnification( AnnounceType::ANNOUNCE_MAGNIFICATION_SCALE); } -PointerPos WindowMagnificationManager::ConvertCenterToTopLeft(int32_t centerX, int32_t centerY) -{ - PointerPos point = {0, 0}; - point.posX = centerX - static_cast(windowWidth_ / static_cast(DIVISOR_TWO)); - point.posY = centerY - static_cast(windowHeight_ / static_cast(DIVISOR_TWO)); - return point; -} - -PointerPos WindowMagnificationManager::GetRectCenter(Rosen::Rect rect) -{ - PointerPos point = {0, 0}; - point.posX = rect.posX_ + static_cast(rect.width_ / DIVISOR_TWO); - point.posY = rect.posY_ + static_cast(rect.height_ / DIVISOR_TWO); - return point; -} - PointerPos WindowMagnificationManager::GetSourceCenter() { - PointerPos point = {0, 0}; - point.posX = sourceRect_.posX_ + static_cast(sourceRect_.width_ / DIVISOR_TWO); - point.posY = sourceRect_.posY_ + static_cast(sourceRect_.height_ / DIVISOR_TWO); - return point; -} - -RectBound WindowMagnificationManager::GenRectBound(uint32_t width, uint32_t height) -{ - RectBound bound = {0, 0}; - if ((abs(scale_) < EPS)) { - return bound; - } - bound.width = static_cast(static_cast(width) / scale_); - bound.height = static_cast(static_cast(height) / scale_); - return bound; -} - -Rosen::Rect WindowMagnificationManager::GetSourceRectFromPointer(int32_t centerX, int32_t centerY) -{ - Rosen::Rect sourceRect = {0, 0, 0, 0}; - RectBound bound = GenRectBound(windowWidth_, windowHeight_); - sourceRect.width_ = bound.width; - sourceRect.height_ = bound.height; - - int32_t x = centerX - static_cast(sourceRect.width_ / DIVISOR_TWO); - int32_t y = centerY - static_cast(sourceRect.height_ / DIVISOR_TWO); - - x = (x < 0) ? 0 : x; - x = (x + static_cast(bound.width)) > static_cast(screenWidth_) ? - static_cast(screenWidth_ - bound.width) : x; - - y = (y < 0) ? 0 : y; - y = (y + static_cast(bound.height)) > static_cast(screenHeight_) ? - static_cast(screenHeight_ - bound.height) : y; - - sourceRect.posX_ = x; - sourceRect.posY_ = y; - return sourceRect; -} - -Rosen::Rect WindowMagnificationManager::GetWindowRectFromPointer(int32_t centerX, int32_t centerY) -{ - Rosen::Rect windowRect = {0, 0, windowWidth_, windowHeight_}; - int32_t x = centerX - static_cast(windowWidth_ / DIVISOR_TWO); - int32_t y = centerY - static_cast(windowHeight_ / DIVISOR_TWO); - - x = (x < 0) ? 0 : x; - x = (x + static_cast(windowWidth_)) > static_cast( - screenWidth_) ? static_cast(screenWidth_ - windowWidth_) : x; - - y = (y < 0) ? 0 : y; - y = (y + static_cast(windowHeight_)) > static_cast( - screenHeight_) ? static_cast(screenHeight_ - windowHeight_) : y; - - windowRect.posX_ = x; - windowRect.posY_ = y; - return windowRect; -} - -void WindowMagnificationManager::AdjustMagnificationWindowPosition() -{ - if (windowRect_.posX_ < 0) { - windowRect_.posX_ = 0; - } - - if (windowRect_.posY_ < 0) { - windowRect_.posY_ = 0; - } - - if (windowRect_.posX_ + static_cast(windowRect_.width_) > static_cast(screenWidth_)) { - windowRect_.posX_ = static_cast(screenWidth_) - static_cast(windowRect_.width_); - } - - if (windowRect_.posY_ + static_cast(windowRect_.height_) > static_cast(screenHeight_)) { - windowRect_.posY_ = static_cast(screenHeight_) - static_cast(windowRect_.height_); - } -} - -void WindowMagnificationManager::AdjustSourceWindowPosition() -{ - if (sourceRect_.posX_ < windowRect_.posX_) { - sourceRect_.posX_ = windowRect_.posX_; - } - - if (sourceRect_.posY_ < windowRect_.posY_) { - sourceRect_.posY_ = windowRect_.posY_; - } - - int32_t windowX = windowRect_.posX_ + static_cast(windowRect_.width_); - if (sourceRect_.posX_ + static_cast(sourceRect_.width_) > windowX) { - sourceRect_.posX_ = windowX - static_cast(sourceRect_.width_); - } - - int32_t windowY = windowRect_.posY_ + static_cast(windowRect_.height_); - if (sourceRect_.posY_ + static_cast(sourceRect_.height_) > windowY) { - sourceRect_.posY_ = windowY - static_cast(sourceRect_.height_); + PointerPos pos = {0, 0}; + if (windowProxy_ == nullptr) { + HILOG_ERROR("windowProxy_ is nullptr."); + return pos; } -} - -void WindowMagnificationManager::CalculateAnchorOffset() -{ - int32_t windowCenterX = windowRect_.posX_ + windowRect_.posX_ + static_cast(windowRect_.width_); - int32_t sourceCenterX = sourceRect_.posX_ + sourceRect_.posX_ + static_cast(sourceRect_.width_); - anchorOffsetX_ = static_cast((windowCenterX - sourceCenterX) * HALF); - - int32_t windowCenterY = windowRect_.posY_ + windowRect_.posY_ + static_cast(windowRect_.height_); - int32_t sourceCenterY = sourceRect_.posY_ + sourceRect_.posY_ + static_cast(sourceRect_.height_); - anchorOffsetY_ = static_cast((windowCenterY - sourceCenterY) * HALF); + return windowProxy_->GetSourceCenter(); } void WindowMagnificationManager::FollowFocuseElement(int32_t centerX, int32_t centerY) { - HILOG_INFO(); - if (window_ == nullptr) { - HILOG_ERROR("window_ is nullptr."); - return; - } - windowRect_ = GetWindowRectFromPointer(centerX, centerY); - sourceRect_ = GetSourceRectFromPointer(centerX, centerY); - window_->MoveTo(windowRect_.posX_, windowRect_.posY_); - UpdateRelativeRect(); - window_->SetFrameRectForPartialZoomIn(relativeRect_); - DrawRuoundRectFrame(); - FlushImplicitTransaction(); - CalculateAnchorOffset(); + HILOG_DEBUG(); + CHECK_PROXY_PTR_VOID() + windowProxy_->FollowFocuseElement(WINDOW_MAGNIFICATION, centerX, centerY); } -void WindowMagnificationManager::UpdateRelativeRect() +bool WindowMagnificationManager::IsMagnificationWindowShow() { - int32_t posX = sourceRect_.posX_ - windowRect_.posX_; - if (posX < 0) { - posX = 0; - } - - int32_t deltaX = static_cast(windowRect_.width_) - static_cast(sourceRect_.width_); - if (posX > deltaX) { - posX = deltaX; - } - relativeRect_.posX_ = posX; - - int32_t posY = sourceRect_.posY_ - windowRect_.posY_; - if (posY < 0) { - posY = 0; - } - - int32_t deltaY = static_cast(windowRect_.height_) - static_cast(sourceRect_.height_); - if (posY > deltaY) { - posY = deltaY; + if (windowProxy_ == nullptr) { + HILOG_ERROR("windowProxy_ is nullptr."); + return false; } - relativeRect_.posY_ = posY; - relativeRect_.width_ = sourceRect_.width_; - relativeRect_.height_ = sourceRect_.height_; + return windowProxy_->IsMagnificationWindowShow(WINDOW_MAGNIFICATION); } -void WindowMagnificationManager::FlushImplicitTransaction() +float WindowMagnificationManager::GetScale() { - if (rsUIContext_ != nullptr) { - auto rsTransaction = rsUIContext_->GetRSTransaction(); - if (rsTransaction != nullptr) { - rsTransaction->FlushImplicitTransaction(); - } - } else { - Rosen::RSTransaction::FlushImplicitTransaction(); + if (windowProxy_ == nullptr) { + HILOG_ERROR("windowProxy_ is nullptr."); + return DEFAULT_SCALE; } + return windowProxy_->GetScale(); } } // namespace Accessibility } // namespace OHOS diff --git a/services/aams/test/BUILD.gn b/services/aams/test/BUILD.gn index 90ed8931..a59af61a 100644 --- a/services/aams/test/BUILD.gn +++ b/services/aams/test/BUILD.gn @@ -141,6 +141,7 @@ ohos_unittest("accessibility_account_data_test") { "../src/magnification_menu_manager.cpp", "../src/full_screen_magnification_manager.cpp", "../src/window_magnification_manager.cpp", + "../src/magnification_window_proxy.cpp", "mock/src/mock_accessibility_setting_provider.cpp", "mock/src/mock_accessibility_settings_config.cpp", "mock/src/mock_accessible_ability_client_stub_impl.cpp", @@ -221,6 +222,7 @@ ohos_unittest("accessible_ability_manager_service_test") { "../src/magnification_menu_manager.cpp", "../src/full_screen_magnification_manager.cpp", "../src/window_magnification_manager.cpp", + "../src/magnification_window_proxy.cpp", "mock/src/aafwk/mock_bundle_manager.cpp", "mock/src/mock_accessibility_element_operator_callback_stub.cpp", "mock/src/mock_accessibility_short_key_dialog.cpp", @@ -349,6 +351,7 @@ ohos_unittest("accessibility_common_event_registry_test") { "../src/magnification_menu_manager.cpp", "../src/full_screen_magnification_manager.cpp", "../src/window_magnification_manager.cpp", + "../src/magnification_window_proxy.cpp", "mock/src/mock_accessibility_account_data.cpp", "mock/src/mock_accessible_ability_manager_service.cpp", "mock/src/mock_magnification_manager.cpp", @@ -414,6 +417,7 @@ ohos_unittest("accessibility_input_interceptor_test") { "../src/magnification_menu_manager.cpp", "../src/full_screen_magnification_manager.cpp", "../src/window_magnification_manager.cpp", + "../src/magnification_window_proxy.cpp", "mock/src/aafwk/mock_bundle_manager.cpp", "mock/src/mock_accessibility_account_data.cpp", "mock/src/mock_accessibility_keyevent_filter.cpp", @@ -483,6 +487,7 @@ ohos_unittest("accessibility_window_manager_test") { "../src/magnification_menu_manager.cpp", "../src/full_screen_magnification_manager.cpp", "../src/window_magnification_manager.cpp", + "../src/magnification_window_proxy.cpp", "mock/src/aafwk/mock_bundle_manager.cpp", "mock/src/mock_accessibility_account_data.cpp", "mock/src/mock_accessibility_common_event.cpp", @@ -542,6 +547,7 @@ ohos_unittest("accessibility_keyevent_filter_test") { "../src/magnification_menu_manager.cpp", "../src/full_screen_magnification_manager.cpp", "../src/window_magnification_manager.cpp", + "../src/magnification_window_proxy.cpp", "../src/accessibility_resource_bundle_manager.cpp", "./mock/src/mock_accessibility_account_data.cpp", "./mock/src/mock_accessibility_event_transmission.cpp", @@ -613,6 +619,7 @@ ohos_unittest("accessible_ability_connection_test") { "../src/magnification_menu_manager.cpp", "../src/full_screen_magnification_manager.cpp", "../src/window_magnification_manager.cpp", + "../src/magnification_window_proxy.cpp", "mock/src/aafwk/mock_bundle_manager.cpp", "mock/src/mock_accessibility_element_operator_callback_stub.cpp", "mock/src/mock_accessibility_element_operator_stub.cpp", @@ -763,6 +770,7 @@ ohos_unittest("accessibility_touchevent_injector_test") { "../src/magnification_menu_manager.cpp", "../src/full_screen_magnification_manager.cpp", "../src/window_magnification_manager.cpp", + "../src/magnification_window_proxy.cpp", "mock/src/mock_accessibility_common_event.cpp", "mock/src/mock_accessibility_event_transmission.cpp", "mock/src/mock_accessible_ability_client_stub_impl.cpp", @@ -889,6 +897,7 @@ ohos_unittest("accessibility_mouse_autoclick_test") { "../src/magnification_menu_manager.cpp", "../src/full_screen_magnification_manager.cpp", "../src/window_magnification_manager.cpp", + "../src/magnification_window_proxy.cpp", "mock/src/mock_accessibility_common_event.cpp", "mock/src/mock_accessibility_event_transmission.cpp", "mock/src/mock_accessibility_settings_config.cpp", @@ -953,6 +962,7 @@ ohos_unittest("accessibility_screen_touch_test") { "../src/magnification_menu_manager.cpp", "../src/full_screen_magnification_manager.cpp", "../src/window_magnification_manager.cpp", + "../src/magnification_window_proxy.cpp", "mock/src/mock_accessibility_account_data.cpp", "mock/src/mock_accessibility_common_event.cpp", "mock/src/mock_accessibility_event_transmission.cpp", @@ -1050,6 +1060,7 @@ ohos_unittest("accessibility_short_key_test") { "../src/magnification_menu_manager.cpp", "../src/full_screen_magnification_manager.cpp", "../src/window_magnification_manager.cpp", + "../src/magnification_window_proxy.cpp", "mock/src/mock_accessibility_common_event.cpp", "mock/src/mock_accessibility_event_transmission.cpp", "mock/src/mock_accessible_ability_client_stub_impl.cpp", @@ -1177,6 +1188,7 @@ ohos_unittest("accessibility_settings_config_test") { "../src/magnification_menu_manager.cpp", "../src/full_screen_magnification_manager.cpp", "../src/window_magnification_manager.cpp", + "../src/magnification_window_proxy.cpp", "mock/src/mock_magnification_manager.cpp", "unittest/accessibility_settings_config_test.cpp", ] @@ -1233,14 +1245,15 @@ ohos_unittest("accessibility_zoom_gesture_test") { "../src/utils.cpp", "../src/magnification_manager.cpp", "../src/window_magnification_gesture.cpp", - "../src/magnification_menu_manager.cpp", "../src/window_magnification_manager.cpp", + "../src/magnification_window_proxy.cpp", "mock/src/mock_accessibility_common_event.cpp", "mock/src/mock_accessibility_display_manager.cpp", "mock/src/mock_accessibility_event_transmission.cpp", "mock/src/mock_accessible_ability_client_stub_impl.cpp", "mock/src/mock_accessible_ability_manager_service.cpp", "mock/src/mock_full_screen_magnification_manager.cpp", + "mock/src/mock_magnification_menu_manager.cpp", "mock/src/mock_system_ability.cpp", "unittest/accessibility_zoom_gesture_test.cpp", ] diff --git a/services/aams/test/mock/src/mock_accessible_ability_manager_service.cpp b/services/aams/test/mock/src/mock_accessible_ability_manager_service.cpp index 98c57879..67bc0f07 100644 --- a/services/aams/test/mock/src/mock_accessible_ability_manager_service.cpp +++ b/services/aams/test/mock/src/mock_accessible_ability_manager_service.cpp @@ -733,6 +733,11 @@ std::shared_ptr AccessibleAbilityManagerService: return nullptr; } +std::shared_ptr AccessibleAbilityManagerService::GetMenuManager() +{ + return nullptr; +} + int32_t AccessibleAbilityManagerService::SetEnhanceConfig(const AccessibilitySecCompRawdata& rawData) { return 0; @@ -775,5 +780,16 @@ void AccessibleAbilityManagerService::OffZoomGesture() { return; } + +void AccessibleAbilityManagerService::InitMagnification() +{ + return; +} + +void AccessibleAbilityManagerService::OnModeChanged(uint32_t mode) +{ + (void)mode; + return; +} } // namespace Accessibility } // namespace OHOS \ No newline at end of file diff --git a/services/aams/test/mock/src/mock_full_screen_magnification_manager.cpp b/services/aams/test/mock/src/mock_full_screen_magnification_manager.cpp index 4a14520a..3e36e797 100644 --- a/services/aams/test/mock/src/mock_full_screen_magnification_manager.cpp +++ b/services/aams/test/mock/src/mock_full_screen_magnification_manager.cpp @@ -24,14 +24,6 @@ FullScreenMagnificationManager::FullScreenMagnificationManager() { } -void FullScreenMagnificationManager::CreateMagnificationWindow() -{ -} - -void FullScreenMagnificationManager::DrawRuoundRectFrame() -{ -} - void FullScreenMagnificationManager::EnableMagnification(int32_t centerX, int32_t centerY) { (void)centerX; @@ -71,10 +63,6 @@ void FullScreenMagnificationManager::PersistScale() { } -void FullScreenMagnificationManager::GetWindowParam() -{ -} - void FullScreenMagnificationManager::RefreshWindowParam() { } @@ -102,32 +90,26 @@ uint32_t FullScreenMagnificationManager::CheckTapOnHotArea(int32_t posX, int32_t return INVALID_GESTURE_TYPE; } -void FullScreenMagnificationManager::InitMagnificationParam() -{ -} - -Rosen::Rect FullScreenMagnificationManager::GetSourceRectFromPointer(int32_t centerX, int32_t centerY) +void FullScreenMagnificationManager::FollowFocuseElement(int32_t centerX, int32_t centerY) { (void)centerX; (void)centerY; - Rosen::Rect rect = {0, 0, 800, 500}; - return rect; } -void FullScreenMagnificationManager::UpdateAnchor() +PointerPos FullScreenMagnificationManager::GetSourceCenter() { + PointerPos pos = {300, 400}; + return pos; } -void FullScreenMagnificationManager::FollowFocuseElement(int32_t centerX, int32_t centerY) +bool FullScreenMagnificationManager::IsMagnificationWindowShow() { - (void)centerX; - (void)centerY; + return Accessibility::AccessibilityAbilityHelper::GetInstance().GetZoomState(); } -PointerPos FullScreenMagnificationManager::GetSourceCenter() +float FullScreenMagnificationManager::GetScale() { - PointerPos pos = {300, 400}; - return pos; + return DEFAULT_SCALE; } } // namespace Accessibility } // namespace OHOS \ No newline at end of file diff --git a/services/aams/test/mock/src/mock_magnification_manager.cpp b/services/aams/test/mock/src/mock_magnification_manager.cpp index 73ccb559..2b4697ae 100644 --- a/services/aams/test/mock/src/mock_magnification_manager.cpp +++ b/services/aams/test/mock/src/mock_magnification_manager.cpp @@ -32,6 +32,11 @@ std::shared_ptr MagnificationManager::GetFullScr return nullptr; } +std::shared_ptr MagnificationManager::GetMenuManager() +{ + return nullptr; +} + void MagnificationManager::OnMagnificationTypeChanged(uint32_t magnificationType) { (void)magnificationType; diff --git a/services/aams/test/mock/src/mock_magnification_menu_manager.cpp b/services/aams/test/mock/src/mock_magnification_menu_manager.cpp new file mode 100644 index 00000000..5bd75768 --- /dev/null +++ b/services/aams/test/mock/src/mock_magnification_menu_manager.cpp @@ -0,0 +1,64 @@ +/* + * Copyright (C) 2025 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "magnification_menu_manager.h" + +namespace OHOS { +namespace Accessibility { + +MagnificationMenuManager::MagnificationMenuManager() +{ +} + +void MagnificationMenuManager::ShowMenuWindow(uint32_t mode) +{ + (void)mode; +} + +void MagnificationMenuManager::DisableMenuWindow() +{ +} + +void MagnificationMenuManager::MoveMenuWindow(int32_t deltaX, int32_t deltaY) +{ + (void)deltaX; + (void)deltaY; +} + +void MagnificationMenuManager::AttachToEdge() +{ +} + +void MagnificationMenuManager::SetCurrentType(uint32_t type) +{ + (void)type; +} + +bool MagnificationMenuManager::IsTapOnMenu(int32_t posX, int32_t posY) +{ + (void)posX; + (void)posY; + return false; +} + +void MagnificationMenuManager::OnMenuTap() +{ +} + +void MagnificationMenuManager::RefreshWindowParam() +{ +} +} // namespace Accessibility +} // namespace OHOS \ No newline at end of file diff --git a/services/aams/test/mock/src/mock_window_magnification_manager.cpp b/services/aams/test/mock/src/mock_window_magnification_manager.cpp new file mode 100644 index 00000000..46a3cdbf --- /dev/null +++ b/services/aams/test/mock/src/mock_window_magnification_manager.cpp @@ -0,0 +1,120 @@ +/* + * Copyright (C) 2025-2025 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +// LCOV_EXCL_START +#include "window_magnification_manager.h" +#include "accessibility_ut_helper.h" + +namespace OHOS { +namespace Accessibility { + +WindowMagnificationManager::WindowMagnificationManager() +{ +} + +void WindowMagnificationManager::EnableWindowMagnification(int32_t centerX, int32_t centerY) +{ + (void)centerX; + (void)centerY; + Accessibility::AccessibilityAbilityHelper::GetInstance().SetZoomState(true); +} + +void WindowMagnificationManager::ShowWindowMagnification() +{ + Accessibility::AccessibilityAbilityHelper::GetInstance().SetZoomState(true); +} + +void WindowMagnificationManager::ShowWindowMagnificationWithPosition(PointerPos pos) +{ + (void)pos; + Accessibility::AccessibilityAbilityHelper::GetInstance().SetZoomState(true); +} + +void WindowMagnificationManager::DisableWindowMagnification(bool needClear) +{ + (void)needClear; + Accessibility::AccessibilityAbilityHelper::GetInstance().SetZoomState(false); +} + +void WindowMagnificationManager::SetScale(float deltaSpan) +{ + (void)deltaSpan; +} + +void WindowMagnificationManager::MoveMagnificationWindow(int32_t deltaX, int32_t deltaY) +{ + (void)deltaX; + (void)deltaY; +} + +bool WindowMagnificationManager::IsTapOnHotArea(int32_t posX, int32_t posY) +{ + (void)posX; + (void)posY; + return false; +} + +void WindowMagnificationManager::RefreshWindowParam() +{ +} + +bool WindowMagnificationManager::IsTapOnMagnificationWindow(int32_t posX, int32_t posY) +{ + (void)posX; + (void)posY; + return false; +} + +PointerPos WindowMagnificationManager::ConvertCoordinates(int32_t posX, int32_t posY) +{ + (void)posX; + (void)posY; + PointerPos pos = {0, 0}; + return pos; +} + +void WindowMagnificationManager::FixSourceCenter(bool needFix) +{ + (void)needFix; +} + +void WindowMagnificationManager::PersistScale() +{ +} + +PointerPos WindowMagnificationManager::GetSourceCenter() +{ + PointerPos pos = {300, 400}; + return pos; +} + +void WindowMagnificationManager::FollowFocuseElement(int32_t centerX, int32_t centerY) +{ + (void)centerX; + (void)centerY; +} + +bool WindowMagnificationManager::IsMagnificationWindowShow() +{ + return false; +} + +float WindowMagnificationManager::GetScale() +{ + return DEFAULT_SCALE; +} +} // namespace Accessibility +} // namespace OHOS +// LCOV_EXCL_STOP \ No newline at end of file diff --git a/services/aams/test/unittest/accessibility_zoom_gesture_test.cpp b/services/aams/test/unittest/accessibility_zoom_gesture_test.cpp index d1cb2ee4..b484c17e 100644 --- a/services/aams/test/unittest/accessibility_zoom_gesture_test.cpp +++ b/services/aams/test/unittest/accessibility_zoom_gesture_test.cpp @@ -20,6 +20,7 @@ #include "accessibility_zoom_gesture.h" #include "accessible_ability_manager_service.h" #include "full_screen_magnification_manager.h" +#include "magnification_menu_manager.h" using namespace testing; using namespace testing::ext; @@ -62,7 +63,8 @@ void AccessibilityZoomGestureUnitTest::SetUp() { GTEST_LOG_(INFO) << "SetUp"; std::shared_ptr manager = std::make_shared(); - zoomGesture_ = std::make_shared(manager); + std::shared_ptr menuManager = std::make_shared(); + zoomGesture_ = std::make_shared(manager, menuManager); } void AccessibilityZoomGestureUnitTest::TearDown() diff --git a/services/aams_ext/BUILD.gn b/services/aams_ext/BUILD.gn new file mode 100644 index 00000000..a39aa30c --- /dev/null +++ b/services/aams_ext/BUILD.gn @@ -0,0 +1,77 @@ +# Copyright (C) 2025 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 +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +import("//build/ohos.gni") +import("../../accessibility_manager_service.gni") + +services_ext_path = "./" + +config("aams_ext_config") { + visibility = [ ":*" ] + + include_dirs = [ + "include", + "../../common/log/include", + "../aams/include", + ] + + defines = [ + "AAMS_LOG_TAG = \"accessibility\"", + "AAMS_LOG_DOMAIN = 0xD001D00", + ] + + if (build_variant == "user") { + defines += [ "RELEASE_VERSION" ] + } + + defines += accessibility_default_defines +} + +aams_ext_files = [ + "${services_ext_path}/src/magnification_window.cpp", + "${services_ext_path}/src/magnification_menu.cpp", +] + +ohos_shared_library("aams_ext") { + branch_protector_ret = "pac_ret" + sanitize = { + integer_overflow = true + ubsan = true + boundary_sanitize = true + cfi = true + cfi_cross_dso = true + debug = false + } + + sources = aams_ext_files + + configs = [ + ":aams_ext_config", + "../../resources/config/build:coverage_flags", + ] + + external_deps = [ + "c_utils:utils", + "display_manager:displaymgr", + "graphic_2d:2d_graphics", + "graphic_2d:librender_service_client", + "graphic_2d:librender_service_base", + "window_manager:libdm", + "window_manager:libwm", + ] + + install_enable = true + + subsystem_name = "barrierfree" + part_name = "accessibility" +} diff --git a/services/aams_ext/include/magnification_menu.h b/services/aams_ext/include/magnification_menu.h new file mode 100644 index 00000000..85de15cf --- /dev/null +++ b/services/aams_ext/include/magnification_menu.h @@ -0,0 +1,84 @@ +/* + * Copyright (C) 2025-2025 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef MAGNIFICATION_MENU_H +#define MAGNIFICATION_MENU_H + +#include "hilog_wrapper.h" +#include "wm/window.h" +#include "window_option.h" +#include +#include +#include +#include "ui/rs_ui_context.h" +#include "ui/rs_ui_director.h" +#include "ui/rs_root_node.h" +#include "recording/recording_canvas.h" +#include "image_source.h" +#include "pixel_map.h" +#include "magnification_def.h" +#include "display_manager.h" + +namespace OHOS { +namespace Accessibility { + +class MagnificationMenu { +public: + // magnification menu + void ShowMenuWindow(uint32_t mode); + void DisableMenuWindow(); + bool IsTapOnMenu(int32_t posX, int32_t posY); + void MoveMenuWindow(int32_t deltaX, int32_t deltaY); + void SetCurrentType(uint32_t type); + void AttachToEdge(); + void RefreshWindowParam(); + uint32_t ChangeMode(); + bool IsMenuShown(); + +private: + void GetWindowParam(); + void CreateMenuWindow(); + void LoadMenuBgImage(uint32_t mode); + void AdjustMenuPosition(); + void FlushImplicitTransaction(); + bool IsInRect(int32_t posX, int32_t posY, Rosen::Rect rect); + std::shared_ptr DecodePixelMap(const std::string& pathName, + const Media::AllocatorType& allocatorType); + //menu window + sptr menuWindow_ = nullptr; + std::shared_ptr surfaceNode_ = nullptr; + std::shared_ptr canvasNode_ = nullptr; + std::shared_ptr rsUIContext_ = nullptr; + Media::AllocatorType allocatorType_ = Media::AllocatorType::DMA_ALLOC; + std::shared_ptr bgpixelmap_ = nullptr; + std::shared_ptr rosenImage_ = nullptr; + + Rosen::Rect menuRect_ = {0, 0, 0, 0}; + Rosen::Rect screenRect_ = {0, 0, 0, 0}; + + uint32_t menuSize_ = 150; + int32_t margin_ = 50; + uint64_t screenId_ = 0; + uint32_t screenWidth_ = 0; + uint32_t screenHeight_ = 0; + + uint32_t menuMode_ = 0; + uint32_t currentType_ = 0; + bool isMenuShown_ = false; +}; + +} // namespace Accessibility +} // namespace OHOS +#endif // MAGNIFICATION_MENU_H \ No newline at end of file diff --git a/services/aams_ext/include/magnification_window.h b/services/aams_ext/include/magnification_window.h new file mode 100644 index 00000000..bcfb88da --- /dev/null +++ b/services/aams_ext/include/magnification_window.h @@ -0,0 +1,121 @@ +/* + * Copyright (C) 2025-2025 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef MAGNIFICATION_WINDOW_H +#define MAGNIFICATION_WINDOW_H + +#include "hilog_wrapper.h" +#include "wm/window.h" +#include "window_option.h" +#include +#include +#include +#include "ui/rs_ui_context.h" +#include "ui/rs_ui_director.h" +#include "ui/rs_root_node.h" +#include "recording/recording_canvas.h" +#include "magnification_def.h" +#include "display_manager.h" + +namespace OHOS { +namespace Accessibility { +class MagnificationWindow { +public: + // common + float GetScale(); + PointerPos GetSourceCenter(); + PointerPos ConvertCoordinates(int32_t posX, int32_t posY); + void InitMagnificationParam(float scale); + + // full magnification + void EnableMagnificationFull(int32_t centerX, int32_t centerY); + void DisableMagnificationFull(bool needClear = false); + void SetScaleFull(float scaleSpan); + void MoveMagnificationFull(int32_t deltaX, int32_t deltaY); + PointerPos ConvertGesture(uint32_t type, PointerPos coordinates); + uint32_t CheckTapOnHotArea(int32_t posX, int32_t posY); + void FollowFocuseElementFull(int32_t centerX, int32_t centerY); + void ShowMagnificationFull(); + void RefreshWindowParamFull(); + bool IsMagnificationShowFull(); + + // window magnification + void EnableMagnificationPart(int32_t centerX, int32_t centerY); + void DisableMagnificationPart(bool needClear = false); + void SetScalePart(float scaleSpan); + void MoveMagnificationPart(int32_t deltaX, int32_t deltaY); + bool IsTapOnHotArea(int32_t posX, int32_t posY); + bool IsTapOnMagnificationWindow(int32_t posX, int32_t posY); + void FixSourceCenter(bool needFix); + void FollowFocuseElementPart(int32_t centerX, int32_t centerY); + void ShowMagnificationPart(); + void RefreshWindowParamPart(); + bool IsMagnificationShowPart(); + +private: + // common + void CreateMagnificationWindow(); + void GetWindowParam(); + PointerPos GetRectCenter(Rosen::Rect rect); + void FlushImplicitTransaction(); + void DisableMagnification(bool needClear = false); + bool IsInRect(int32_t posX, int32_t posY, Rosen::Rect rect); + + // full magnification + Rosen::Rect GetSourceRectFromPointer(int32_t centerX, int32_t centerY); + void UpdateAnchor(); + void DrawRuoundRectFrameFull(); + + // window magnification + Rosen::Rect GetWindowRectFromPointer(int32_t centerX, int32_t centerY); + void DrawRuoundRectFramePart(); + void CalculateAnchorOffset(); + void UpdateRelativeRect(); + void AdjustMagnificationWindowPosition(); + void AdjustSourceWindowPosition(); + + // common + sptr window_ = nullptr; + std::shared_ptr surfaceNode_ = nullptr; + std::shared_ptr canvasNode_ = nullptr; + std::shared_ptr rsUIContext_ = nullptr; + Rosen::Rect sourceRect_ = {0, 0, 0, 0}; + Rosen::Rect windowRect_ = {0, 0, 0, 0}; + Rosen::Rect screenRect_ = {0, 0, 0, 0}; + Rosen::Rect relativeRect_ = {0, 0, 0, 0}; //The relative position of sourceRect_ in windowRect_ + uint32_t screenWidth_ = 0; + uint32_t screenHeight_ = 0; + float screenSpan_ = 0.0f; + uint64_t screenId_ = 0; + int32_t centerX_ = 0; + int32_t centerY_ = 0; + float scale_ = DEFAULT_SCALE; + + uint32_t windowWidth_ = MAGNIFY_WINDOW_WIDTH; + uint32_t windowHeight_ = MAGNIFY_WINDOW_HEIGHT; + uint32_t barMargin_ = BAR_MARGIN; + + uint32_t hotAreaWidth_ = HOT_AREA_WIDTH; + int32_t anchorOffsetX_ = 0; // windowRect_'s centerX - sourceRect_'s centerX + int32_t anchorOffsetY_ = 0; // windowRect_'s centerY - sourceRect_'s centerY + + bool isFixSourceCenter_ = false; + PointerPos fixedSourceCenter_ = {0, 0}; + bool isMagnificationShowPart_ = false; + bool isMagnificationShowFull_ = false; +}; +} // namespace Accessibility +} // namespace OHOS +#endif // MAGNIFICATION_WINDOW_H \ No newline at end of file diff --git a/services/aams_ext/include/visibility.h b/services/aams_ext/include/visibility.h new file mode 100644 index 00000000..5074d23b --- /dev/null +++ b/services/aams_ext/include/visibility.h @@ -0,0 +1,22 @@ +/* + * Copyright (C) 2025-2025 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef VISIBILITY_H +#define VISIBILITY_H + +#ifndef API_EXPORT +#define API_EXPORT __attribute__((visibility("default"))) +#endif +#endif // VISIBILITY_H \ No newline at end of file diff --git a/services/aams_ext/src/magnification_menu.cpp b/services/aams_ext/src/magnification_menu.cpp new file mode 100644 index 00000000..7eb1b8de --- /dev/null +++ b/services/aams_ext/src/magnification_menu.cpp @@ -0,0 +1,345 @@ +/* + * Copyright (C) 2025-2025 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +// LCOV_EXCL_START +#include "magnification_menu.h" +#include "visibility.h" + +namespace OHOS { +namespace Accessibility { +namespace { + const std::string FULL_SCREEN_PATH = "/system/etc/accessibility/fullScreen.png"; + const std::string WINDOW_PATH = "/system/etc/accessibility/window.png"; +} +static MagnificationMenu instance; + +void MagnificationMenu::CreateMenuWindow() +{ + HILOG_DEBUG(); + GetWindowParam(); + menuRect_ = {(static_cast(screenWidth_ - menuSize_) - margin_), ( + static_cast(screenHeight_ - menuSize_) - margin_), menuSize_, menuSize_}; + sptr windowOption = new(std::nothrow) Rosen::WindowOption(); + if (windowOption == nullptr) { + HILOG_ERROR("windowOption is null"); + return; + } + windowOption->SetWindowType(Rosen::WindowType::WINDOW_TYPE_MAGNIFICATION_MENU); + windowOption->SetWindowMode(Rosen::WindowMode::WINDOW_MODE_FLOATING); + windowOption->SetWindowRect(menuRect_); + menuWindow_ = Rosen::Window::Create(MENU_NAME, windowOption); + if (menuWindow_ == nullptr) { + HILOG_ERROR("create failed"); + return; + } + menuWindow_->SetCornerRadius(MENU_CORNER_RADIUS); + surfaceNode_ = menuWindow_->GetSurfaceNode(); + if (surfaceNode_ == nullptr) { + HILOG_ERROR("surfaceNode_ is nullptr."); + return; + } + rsUIContext_ = surfaceNode_->GetRSUIContext(); + canvasNode_ = Rosen::RSCanvasNode::Create(false, false, rsUIContext_); + if (canvasNode_ == nullptr) { + HILOG_ERROR("create canvasNode_ fail."); + return; + } + canvasNode_->SetSkipCheckInMultiInstance(true); + surfaceNode_->SetAbilityBGAlpha(BG_ALPHA); + surfaceNode_->AddChild(canvasNode_, -1); + canvasNode_->SetBounds(0, 0, menuSize_, menuSize_); + canvasNode_->SetFrame(0, 0, menuSize_, menuSize_); + canvasNode_->SetPositionZ(Rosen::RSSurfaceNode::POINTER_WINDOW_POSITION_Z); + canvasNode_->SetRotation(0); + rosenImage_ = std::make_shared(); +} + +void MagnificationMenu::LoadMenuBgImage(uint32_t mode) +{ + HILOG_DEBUG(); + std::string path = FULL_SCREEN_PATH; + if (mode == WINDOW_MAGNIFICATION) { + path = WINDOW_PATH; + } + bgpixelmap_ = DecodePixelMap(path, allocatorType_); + if (bgpixelmap_ == nullptr) { + HILOG_ERROR("DecodePixelMap failed."); + return; + } + if (canvasNode_ == nullptr) { + HILOG_ERROR("canvasNode_ is nullptr."); + return; + } + canvasNode_->SetBgImageWidth(menuSize_); + canvasNode_->SetBgImageHeight(menuSize_); + canvasNode_->SetBgImagePositionX(0); + canvasNode_->SetBgImagePositionY(0); + if (rosenImage_ == nullptr) { + HILOG_ERROR("rosenImage_ is nullptr."); + return; + } + rosenImage_->SetPixelMap(bgpixelmap_); + rosenImage_->SetImageFit(static_cast(Rosen::ImageFit::FILL)); + canvasNode_->SetBgImage(rosenImage_); + menuWindow_->Show(); +} + +void MagnificationMenu::ShowMenuWindow(uint32_t mode) +{ + HILOG_INFO(); + menuMode_ = mode; + if (currentType_ != SWITCH_MAGNIFICATION) { + HILOG_WARN("no need show menu."); + return; + } + + if (menuWindow_ == nullptr) { + HILOG_ERROR("window is null. need create."); + CreateMenuWindow(); + } + + if (menuWindow_ == nullptr) { + HILOG_ERROR("create window failed."); + return; + } + + LoadMenuBgImage(mode); + FlushImplicitTransaction(); + isMenuShown_ = true; +} + +void MagnificationMenu::DisableMenuWindow() +{ + HILOG_INFO(); + if (!isMenuShown_) { + HILOG_INFO("menu not shown."); + return; + } + if (surfaceNode_ != nullptr) { + surfaceNode_->SetVisible(false); + surfaceNode_->ClearChildren(); + FlushImplicitTransaction(); + } + + isMenuShown_ = false; + if (menuWindow_ != nullptr) { + menuWindow_->Hide(); + menuWindow_->Destroy(); + menuWindow_ = nullptr; + } + surfaceNode_ = nullptr; + canvasNode_ = nullptr; + rsUIContext_ = nullptr; + bgpixelmap_ = nullptr; + rosenImage_ = nullptr; +} + +void MagnificationMenu::MoveMenuWindow(int32_t deltaX, int32_t deltaY) +{ + HILOG_DEBUG(); + if (menuWindow_ == nullptr) { + HILOG_ERROR("menuWindow_ is null."); + return; + } + int32_t menuPosX = menuRect_.posX_ + deltaX; + int32_t menuPosY = menuRect_.posY_ + deltaY; + + menuRect_.posX_ = menuPosX; + menuRect_.posY_ = menuPosY; + + AdjustMenuPosition(); + menuWindow_->MoveTo(menuRect_.posX_, menuRect_.posY_); +} + +void MagnificationMenu::AttachToEdge() +{ + if (menuWindow_ == nullptr) { + HILOG_ERROR("menuWindow_ is null."); + return; + } + + if (menuRect_.posX_ < static_cast(screenWidth_ / DIVISOR_TWO)) { + menuRect_.posX_ = margin_; + } else { + menuRect_.posX_ = static_cast(screenWidth_ - menuSize_) - margin_; + } + menuWindow_->MoveTo(menuRect_.posX_, menuRect_.posY_); +} + +void MagnificationMenu::SetCurrentType(uint32_t type) +{ + currentType_ = type; +} + +bool MagnificationMenu::IsInRect(int32_t posX, int32_t posY, Rosen::Rect rect) +{ + return (posX >= rect.posX_ && posY >= rect.posY_ && posX <= rect.posX_ + static_cast(rect.width_) && + posY <= rect.posY_ + static_cast(rect.height_)); +} + +bool MagnificationMenu::IsTapOnMenu(int32_t posX, int32_t posY) +{ + if (!isMenuShown_) { + return false; + } + return IsInRect(posX, posY, menuRect_); +} + +uint32_t MagnificationMenu::ChangeMode() +{ + if (menuMode_ == WINDOW_MAGNIFICATION) { + menuMode_ = FULL_SCREEN_MAGNIFICATION; + return menuMode_; + } + if (menuMode_ == FULL_SCREEN_MAGNIFICATION) { + menuMode_ = WINDOW_MAGNIFICATION; + return menuMode_; + } + return 0; +} + +void MagnificationMenu::AdjustMenuPosition() +{ + if (menuRect_.posX_ < margin_) { + menuRect_.posX_ = margin_; + } + + if (menuRect_.posY_ < margin_) { + menuRect_.posY_ = margin_; + } + + if (menuRect_.posX_ + static_cast(menuRect_.width_) + margin_ > static_cast(screenWidth_)) { + menuRect_.posX_ = static_cast(screenWidth_) - static_cast(menuRect_.width_) - margin_; + } + + if (menuRect_.posY_ + static_cast(menuRect_.height_) + margin_ > static_cast(screenHeight_)) { + menuRect_.posY_ = static_cast(screenHeight_) - static_cast(menuRect_.height_) - margin_; + } +} + +std::shared_ptr MagnificationMenu::DecodePixelMap( + const std::string& pathName, const Media::AllocatorType& allocatorType) +{ + uint32_t errCode = 0; + std::unique_ptr imageSource = + Media::ImageSource::CreateImageSource(pathName, Media::SourceOptions(), errCode); + if (imageSource == nullptr || errCode != 0) { + HILOG_ERROR("CreateImageSource failed."); + return nullptr; + } + + Media::DecodeOptions decodeOpt; + decodeOpt.allocatorType = allocatorType; + std::shared_ptr pixelmap = imageSource->CreatePixelMap(decodeOpt, errCode); + if (pixelmap == nullptr || errCode != 0) { + HILOG_ERROR("CreatePixelMap failed."); + return nullptr; + } + return pixelmap; +} + +void MagnificationMenu::GetWindowParam() +{ + HILOG_DEBUG(); +#ifdef OHOS_BUILD_ENABLE_DISPLAY_MANAGER + screenId_ = Rosen::DisplayManager::GetInstance().GetDefaultDisplayId(); + sptr display = Rosen::DisplayManager::GetInstance().GetDisplayById(screenId_); + if (display == nullptr) { + HILOG_ERROR("display is nullptr."); + return; + } + screenWidth_ = static_cast(display->GetWidth()); + screenHeight_ = static_cast(display->GetHeight()); + screenRect_ = {0, 0, screenWidth_, screenHeight_}; +#else + HILOG_INFO("not support"); +#endif +} + +void MagnificationMenu::RefreshWindowParam() +{ + HILOG_DEBUG(); + if (isMenuShown_) { + DisableMenuWindow(); + ShowMenuWindow(menuMode_); + } else { + GetWindowParam(); + } +} + +void MagnificationMenu::FlushImplicitTransaction() +{ + if (rsUIContext_ != nullptr) { + auto rsTransaction = rsUIContext_->GetRSTransaction(); + if (rsTransaction != nullptr) { + rsTransaction->FlushImplicitTransaction(); + } + } else { + Rosen::RSTransaction::FlushImplicitTransaction(); + } +} + +bool MagnificationMenu::IsMenuShown() +{ + return isMenuShown_; +} + +extern "C" API_EXPORT void ShowMenuWindow(uint32_t mode) +{ + instance.ShowMenuWindow(mode); +} + +extern "C" API_EXPORT void DisableMenuWindow() +{ + instance.DisableMenuWindow(); +} + +extern "C" API_EXPORT void MoveMenuWindow(int32_t deltaX, int32_t deltaY) +{ + instance.MoveMenuWindow(deltaX, deltaY); +} + +extern "C" API_EXPORT bool IsTapOnMenu(int32_t posX, int32_t posY) +{ + return instance.IsTapOnMenu(posX, posY); +} + +extern "C" API_EXPORT void AttachToEdge() +{ + instance.AttachToEdge(); +} + +extern "C" API_EXPORT void RefreshWindowParamMenu() +{ + instance.RefreshWindowParam(); +} + +extern "C" API_EXPORT void SetCurrentType(uint32_t type) +{ + instance.SetCurrentType(type); +} + +extern "C" API_EXPORT uint32_t ChangeMode() +{ + return instance.ChangeMode(); +} + +extern "C" API_EXPORT bool IsMenuShown() +{ + return instance.IsMenuShown(); +} +} +} +// LCOV_EXCL_STOP \ No newline at end of file diff --git a/services/aams_ext/src/magnification_window.cpp b/services/aams_ext/src/magnification_window.cpp new file mode 100644 index 00000000..04749600 --- /dev/null +++ b/services/aams_ext/src/magnification_window.cpp @@ -0,0 +1,921 @@ +/* + * Copyright (C) 2025-2025 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +// LCOV_EXCL_START +#include "magnification_window.h" +#include "visibility.h" + +namespace OHOS { +namespace Accessibility { +static MagnificationWindow instance; + +//common +float MagnificationWindow::GetScale() +{ + return scale_; +} + +PointerPos MagnificationWindow::GetSourceCenter() +{ + PointerPos point = {0, 0}; + point.posX = sourceRect_.posX_ + static_cast(sourceRect_.width_ / DIVISOR_TWO); + point.posY = sourceRect_.posY_ + static_cast(sourceRect_.height_ / DIVISOR_TWO); + return point; +} + +PointerPos MagnificationWindow::ConvertCoordinates(int32_t posX, int32_t posY) +{ + PointerPos sourcePoint = {0, 0}; + if ((abs(scale_) < EPS)) { + return sourcePoint; + } + int32_t windowDeltaX = posX - windowRect_.posX_; + int32_t windowDeltaY = posY - windowRect_.posY_; + sourcePoint.posX = sourceRect_.posX_ + static_cast(windowDeltaX / scale_); + sourcePoint.posY = sourceRect_.posY_ + static_cast(windowDeltaY / scale_); + return sourcePoint; +} + +void MagnificationWindow::CreateMagnificationWindow() +{ + HILOG_DEBUG(); + sptr windowOption = new(std::nothrow) Rosen::WindowOption(); + if (windowOption == nullptr) { + HILOG_ERROR("windowOption is null."); + return; + } + windowOption->SetWindowType(Rosen::WindowType::WINDOW_TYPE_MAGNIFICATION); + windowOption->SetWindowMode(Rosen::WindowMode::WINDOW_MODE_FLOATING); + windowOption->SetWindowRect(windowRect_); + windowOption->SetFocusable(false); + window_ = OHOS::Rosen::Window::Create(WINDOW_NAME, windowOption); + if (window_ == nullptr) { + HILOG_ERROR("window create failed."); + return; + } + window_->SetCornerRadius(CORNER_RADIUS); + surfaceNode_ = window_->GetSurfaceNode(); + if (surfaceNode_ == nullptr) { + HILOG_ERROR("get surfaceNode_ failed."); + return; + } + rsUIContext_ = surfaceNode_->GetRSUIContext(); + canvasNode_ = Rosen::RSCanvasNode::Create(false, false, rsUIContext_); + if (canvasNode_ == nullptr) { + HILOG_ERROR("canvasNode_ is nullptr."); + return; + } + canvasNode_->SetSkipCheckInMultiInstance(true); +} + +void MagnificationWindow::GetWindowParam() +{ + HILOG_DEBUG(); +#ifdef OHOS_BUILD_ENABLE_DISPLAY_MANAGER + screenId_ = Rosen::DisplayManager::GetInstance().GetDefaultDisplayId(); + sptr display = Rosen::DisplayManager::GetInstance().GetDisplayById(screenId_); + if (display == nullptr) { + HILOG_ERROR("display is nullptr."); + return; + } + screenWidth_ = static_cast(display->GetWidth()); + screenHeight_ = static_cast(display->GetHeight()); + screenSpan_ = hypot(screenWidth_, screenHeight_); + screenRect_ = {0, 0, screenWidth_, screenHeight_}; +#else + HILOG_INFO("not support"); +#endif +} + +void MagnificationWindow::InitMagnificationParam(float scale) +{ + scale_ = scale; +} + +void MagnificationWindow::FlushImplicitTransaction() +{ + if (rsUIContext_ != nullptr) { + auto rsTransaction = rsUIContext_->GetRSTransaction(); + if (rsTransaction != nullptr) { + rsTransaction->FlushImplicitTransaction(); + } + } else { + Rosen::RSTransaction::FlushImplicitTransaction(); + } +} + +PointerPos MagnificationWindow::GetRectCenter(Rosen::Rect rect) +{ + PointerPos point = {0, 0}; + point.posX = rect.posX_ + static_cast(rect.width_ / DIVISOR_TWO); + point.posY = rect.posY_ + static_cast(rect.height_ / DIVISOR_TWO); + return point; +} + +Rosen::Rect MagnificationWindow::GetSourceRectFromPointer(int32_t centerX, int32_t centerY) +{ + Rosen::Rect sourceRect = {0, 0, 0, 0}; + if ((abs(scale_) < EPS)) { + return sourceRect; + } + sourceRect.width_ = static_cast(static_cast(windowRect_.width_) / scale_); + sourceRect.height_ = static_cast(static_cast(windowRect_.height_) / scale_); + + int32_t x = centerX - static_cast(sourceRect.width_ / DIVISOR_TWO); + int32_t y = centerY - static_cast(sourceRect.height_ / DIVISOR_TWO); + + x = (x < 0) ? 0 : x; + x = (x + static_cast(sourceRect.width_)) > static_cast( + screenWidth_) ? static_cast(screenWidth_ - sourceRect.width_) : x; + + y = (y < 0) ? 0 : y; + y = (y + static_cast(sourceRect.height_)) > static_cast( + screenHeight_) ? static_cast(screenHeight_ - sourceRect.height_) : y; + + sourceRect.posX_ = x; + sourceRect.posY_ = y; + HILOG_WARN("sourceRect_ = %{public}s", sourceRect_.ToString().c_str()); + return sourceRect; +} + +void MagnificationWindow::DisableMagnification(bool needClear) +{ + HILOG_INFO(); + if (needClear && surfaceNode_ != nullptr) { + HILOG_DEBUG("claer surfaceNode"); + surfaceNode_->SetVisible(false); + surfaceNode_->ClearChildren(); + FlushImplicitTransaction(); + } + + if (window_ != nullptr) { + window_->Hide(); + window_->Destroy(); + window_ = nullptr; + } + surfaceNode_ = nullptr; + canvasNode_ = nullptr; + rsUIContext_ = nullptr; +} + +bool MagnificationWindow::IsInRect(int32_t posX, int32_t posY, Rosen::Rect rect) +{ + return (posX >= rect.posX_ && posY >= rect.posY_ && posX <= rect.posX_ + static_cast(rect.width_) && + posY <= rect.posY_ + static_cast(rect.height_)); +} + +// full magnification ================================================================================== + +PointerPos MagnificationWindow::ConvertGesture(uint32_t type, PointerPos coordinates) +{ + int32_t posX = coordinates.posX; + int32_t posY = coordinates.posY; + PointerPos point = {posX, posY}; + + if (type == BOTTOM_BACK_GESTURE) { + int32_t offsetY = static_cast(screenHeight_) - + (sourceRect_.posY_ + static_cast(sourceRect_.height_)); + point.posY = posY + offsetY; + return point; + } + if (type == LEFT_BACK_GESTURE) { + int32_t offsetX = sourceRect_.posX_; + point.posX = posX - offsetX; + return point; + } + + if (type == RIGHT_BACK_GESTURE) { + int32_t offsetX = static_cast(screenWidth_) - + (sourceRect_.posX_ + static_cast(sourceRect_.width_)); + point.posX = posX + offsetX; + return point; + } + + return point; +} + +uint32_t MagnificationWindow::CheckTapOnHotArea(int32_t posX, int32_t posY) +{ + bool isTapOnBottom = posY <= static_cast(screenHeight_) && + posY >= static_cast(screenHeight_) - GESTURE_OFFSET; + if (isTapOnBottom) { + HILOG_DEBUG("Tap On Bottom"); + return BOTTOM_BACK_GESTURE; + } + bool isTapOnLeftSide = posX >= 0 && posX <= GESTURE_OFFSET; + if (isTapOnLeftSide) { + HILOG_DEBUG("Tap On Left Side"); + return LEFT_BACK_GESTURE; + } + bool isTapOnRightSide = posX >= static_cast(screenWidth_) - GESTURE_OFFSET && + posX <= static_cast(screenWidth_); + if (isTapOnRightSide) { + HILOG_DEBUG("Tap On Right Side"); + return RIGHT_BACK_GESTURE; + } + return INVALID_GESTURE_TYPE; +} + +void MagnificationWindow::FollowFocuseElementFull(int32_t centerX, int32_t centerY) +{ + HILOG_DEBUG(); + if (window_ == nullptr) { + HILOG_ERROR("window_ is nullptr."); + return; + } + sourceRect_ = GetSourceRectFromPointer(centerX, centerY); + window_->SetFrameRectForPartialZoomIn(sourceRect_); + DrawRuoundRectFrameFull(); + FlushImplicitTransaction(); + UpdateAnchor(); +} + +void MagnificationWindow::UpdateAnchor() +{ + centerX_ = static_cast((sourceRect_.posX_ + sourceRect_.posX_ + + static_cast(sourceRect_.width_)) / DIVISOR_TWO); + centerY_ = static_cast((sourceRect_.posY_ + sourceRect_.posY_ + + static_cast(sourceRect_.height_)) / DIVISOR_TWO); +} + +void MagnificationWindow::DrawRuoundRectFrameFull() +{ + if (surfaceNode_ == nullptr) { + HILOG_ERROR("get surfaceNode_ failed."); + return; + } + + if (canvasNode_ == nullptr) { + HILOG_ERROR("create canvasNode_ fail"); + return; + } + surfaceNode_->SetAbilityBGAlpha(BG_ALPHA); + surfaceNode_->AddChild(canvasNode_, -1); + canvasNode_->SetBounds(0, 0, screenWidth_, screenHeight_); + canvasNode_->SetFrame(0, 0, screenWidth_, screenHeight_); + canvasNode_->SetPositionZ(Rosen::RSSurfaceNode::POINTER_WINDOW_POSITION_Z); + canvasNode_->SetRotation(0); + + auto canvas = canvasNode_->BeginRecording(screenWidth_, screenHeight_); + Rosen::Drawing::Pen pen; + pen.SetAntiAlias(true); + pen.SetColor(ORANGE_COLOR); + pen.SetWidth(PEN_WIDTH); + canvas->AttachPen(pen); + Rosen::Drawing::Path path; + path.AddRoundRect({ROUND_RECT_MARGIN, ROUND_RECT_MARGIN, + screenWidth_ - ROUND_RECT_MARGIN, screenHeight_ - ROUND_RECT_MARGIN}, + CORNER_RADIUS, CORNER_RADIUS, Rosen::Drawing::PathDirection::CW_DIRECTION); + canvas->DrawPath(path); + canvas->DetachPen(); + canvasNode_->FinishRecording(); +} + +void MagnificationWindow::EnableMagnificationFull(int32_t centerX, int32_t centerY) +{ + HILOG_INFO("centerX = %{public}d, centerY = %{public}d.", centerX, centerY); + GetWindowParam(); + if (window_ == nullptr) { + HILOG_DEBUG("window is null. need create."); + windowRect_ = {0, 0, screenWidth_, screenHeight_}; + CreateMagnificationWindow(); + } + + if (window_ == nullptr) { + HILOG_ERROR("create window failed."); + return; + } + sourceRect_ = GetSourceRectFromPointer(centerX, centerY); + UpdateAnchor(); + DrawRuoundRectFrameFull(); + window_->SetFrameRectForPartialZoomIn(sourceRect_); + window_->Show(); + FlushImplicitTransaction(); + isMagnificationShowFull_ = true; +} + +void MagnificationWindow::DisableMagnificationFull(bool needClear) +{ + HILOG_INFO(); + DisableMagnification(); + isMagnificationShowFull_ = false; +} + +void MagnificationWindow::SetScaleFull(float scaleSpan) +{ + HILOG_DEBUG(); + if (window_ == nullptr) { + HILOG_ERROR("window_ is nullptr."); + return; + } + if (screenWidth_ == 0 || screenHeight_ == 0 || abs(screenSpan_) < EPS) { + HILOG_ERROR("screen param invalid."); + return; + } + + float ratio = scaleSpan / screenSpan_; + float tmpScale = scale_ + ratio * scale_; + + if (tmpScale > MAX_SCALE) { + tmpScale = MAX_SCALE; + } + if (tmpScale < DEFAULT_SCALE) { + tmpScale = DEFAULT_SCALE; + } + + uint32_t newWidth = static_cast(windowRect_.width_ / tmpScale); + uint32_t newHeight = static_cast(windowRect_.height_ / tmpScale); + int32_t newPosX = centerX_ - static_cast(newWidth / DIVISOR_TWO); + int32_t newPosY = centerY_ - static_cast(newHeight / DIVISOR_TWO); + + if (newPosX < 0) { + centerX_ -= newPosX; + newPosX = 0; + } + + if (newPosY < 0) { + centerY_ -= newPosY; + newPosY = 0; + } + + if (newPosX + static_cast(newWidth) > static_cast(screenWidth_)) { + centerX_ -= (newPosX + static_cast(newWidth) - static_cast(screenWidth_)); + newPosX = static_cast(screenWidth_) - static_cast(newWidth); + } + + if (newPosY + static_cast(newHeight) > static_cast(screenHeight_)) { + centerY_ -= (newPosY + static_cast(newHeight) - static_cast(screenHeight_)); + newPosY = static_cast(screenHeight_) - static_cast(newHeight); + } + + sourceRect_ = {newPosX, newPosY, newWidth, newHeight}; + scale_ = tmpScale; + window_->SetFrameRectForPartialZoomIn(sourceRect_); + DrawRuoundRectFrameFull(); + FlushImplicitTransaction(); + UpdateAnchor(); +} + +void MagnificationWindow::MoveMagnificationFull(int32_t deltaX, int32_t deltaY) +{ + HILOG_DEBUG(); + if (window_ == nullptr) { + HILOG_ERROR("window_ is nullptr."); + return; + } + int32_t sourcePosX = sourceRect_.posX_ - deltaX; + int32_t sourcePosY = sourceRect_.posY_ - deltaY; + + if (sourcePosX < 0) { + sourcePosX = 0; + } + + if (sourcePosY < 0) { + sourcePosY = 0; + } + + if (sourcePosX + static_cast(sourceRect_.width_) > static_cast(screenWidth_)) { + sourcePosX = static_cast(screenWidth_) - static_cast(sourceRect_.width_); + } + + if (sourcePosY + static_cast(sourceRect_.height_) > static_cast(screenHeight_)) { + sourcePosY = static_cast(screenHeight_) - static_cast(sourceRect_.height_); + } + sourceRect_.posX_ = sourcePosX; + sourceRect_.posY_ = sourcePosY; + window_->SetFrameRectForPartialZoomIn(sourceRect_); + DrawRuoundRectFrameFull(); + FlushImplicitTransaction(); + UpdateAnchor(); +} + +void MagnificationWindow::ShowMagnificationFull() +{ + int32_t centerX = static_cast(screenWidth_ / DIVISOR_TWO); + int32_t centerY = static_cast(screenHeight_ / DIVISOR_TWO); + EnableMagnificationFull(centerX, centerY); +} + +void MagnificationWindow::RefreshWindowParamFull() +{ + HILOG_DEBUG(); + PointerPos center = GetRectCenter(sourceRect_); + if (isMagnificationShowFull_) { + DisableMagnificationFull(false); + EnableMagnificationFull(center.posX, center.posY); + } else { + GetWindowParam(); + } +} + +bool MagnificationWindow::IsMagnificationShowFull() +{ + return isMagnificationShowFull_; +} + +// window magnification ============================================================================= +Rosen::Rect MagnificationWindow::GetWindowRectFromPointer(int32_t centerX, int32_t centerY) +{ + Rosen::Rect windowRect = {0, 0, windowWidth_, windowHeight_}; + int32_t x = centerX - static_cast(windowWidth_ / DIVISOR_TWO); + int32_t y = centerY - static_cast(windowHeight_ / DIVISOR_TWO); + + x = (x < 0) ? 0 : x; + x = (x + static_cast(windowWidth_)) > static_cast( + screenWidth_) ? static_cast(screenWidth_ - windowWidth_) : x; + + y = (y < 0) ? 0 : y; + y = (y + static_cast(windowHeight_)) > static_cast( + screenHeight_) ? static_cast(screenHeight_ - windowHeight_) : y; + + windowRect.posX_ = x; + windowRect.posY_ = y; + return windowRect; +} + +void MagnificationWindow::CalculateAnchorOffset() +{ + int32_t windowCenterX = windowRect_.posX_ + windowRect_.posX_ + static_cast(windowRect_.width_); + int32_t sourceCenterX = sourceRect_.posX_ + sourceRect_.posX_ + static_cast(sourceRect_.width_); + anchorOffsetX_ = static_cast((windowCenterX - sourceCenterX) * HALF); + + int32_t windowCenterY = windowRect_.posY_ + windowRect_.posY_ + static_cast(windowRect_.height_); + int32_t sourceCenterY = sourceRect_.posY_ + sourceRect_.posY_ + static_cast(sourceRect_.height_); + anchorOffsetY_ = static_cast((windowCenterY - sourceCenterY) * HALF); +} + +void MagnificationWindow::UpdateRelativeRect() +{ + int32_t posX = sourceRect_.posX_ - windowRect_.posX_; + if (posX < 0) { + posX = 0; + } + + int32_t deltaX = static_cast(windowRect_.width_) - static_cast(sourceRect_.width_); + if (posX > deltaX) { + posX = deltaX; + } + relativeRect_.posX_ = posX; + + int32_t posY = sourceRect_.posY_ - windowRect_.posY_; + if (posY < 0) { + posY = 0; + } + + int32_t deltaY = static_cast(windowRect_.height_) - static_cast(sourceRect_.height_); + if (posY > deltaY) { + posY = deltaY; + } + relativeRect_.posY_ = posY; + relativeRect_.width_ = sourceRect_.width_; + relativeRect_.height_ = sourceRect_.height_; +} + +void MagnificationWindow::AdjustMagnificationWindowPosition() +{ + if (windowRect_.posX_ < 0) { + windowRect_.posX_ = 0; + } + + if (windowRect_.posY_ < 0) { + windowRect_.posY_ = 0; + } + + if (windowRect_.posX_ + static_cast(windowRect_.width_) > static_cast(screenWidth_)) { + windowRect_.posX_ = static_cast(screenWidth_) - static_cast(windowRect_.width_); + } + + if (windowRect_.posY_ + static_cast(windowRect_.height_) > static_cast(screenHeight_)) { + windowRect_.posY_ = static_cast(screenHeight_) - static_cast(windowRect_.height_); + } +} + +void MagnificationWindow::AdjustSourceWindowPosition() +{ + if (sourceRect_.posX_ < windowRect_.posX_) { + sourceRect_.posX_ = windowRect_.posX_; + } + + if (sourceRect_.posY_ < windowRect_.posY_) { + sourceRect_.posY_ = windowRect_.posY_; + } + + int32_t windowX = windowRect_.posX_ + static_cast(windowRect_.width_); + if (sourceRect_.posX_ + static_cast(sourceRect_.width_) > windowX) { + sourceRect_.posX_ = windowX - static_cast(sourceRect_.width_); + } + + int32_t windowY = windowRect_.posY_ + static_cast(windowRect_.height_); + if (sourceRect_.posY_ + static_cast(sourceRect_.height_) > windowY) { + sourceRect_.posY_ = windowY - static_cast(sourceRect_.height_); + } +} + +bool MagnificationWindow::IsTapOnHotArea(int32_t posX, int32_t posY) +{ + if (!isMagnificationShowPart_) { + return false; + } + Rosen::Rect innerRect = {windowRect_.posX_ + static_cast(hotAreaWidth_), + windowRect_.posY_ + static_cast(hotAreaWidth_), + windowRect_.width_ - static_cast(2 * hotAreaWidth_), + windowRect_.height_ - static_cast(2 * hotAreaWidth_)}; + Rosen::Rect outRect = {windowRect_.posX_ - static_cast(hotAreaWidth_), + windowRect_.posY_ - static_cast(hotAreaWidth_), + windowRect_.width_ + static_cast(2 * hotAreaWidth_), + windowRect_.height_ + static_cast(2 * hotAreaWidth_)}; + return IsInRect(posX, posY, outRect) && !(IsInRect(posX, posY, innerRect)); +} + +bool MagnificationWindow::IsTapOnMagnificationWindow(int32_t posX, int32_t posY) +{ + return IsInRect(posX, posY, windowRect_); +} +void MagnificationWindow::FixSourceCenter(bool needFix) +{ + HILOG_DEBUG(); + if (needFix == isFixSourceCenter_) { + return; + } + + isFixSourceCenter_ = needFix; + if (needFix) { + isFixSourceCenter_ = needFix; + float sourceCenterX = (sourceRect_.posX_ + sourceRect_.posX_ + + static_cast(sourceRect_.width_)) / static_cast(DIVISOR_TWO); + float sourceCenterY = (sourceRect_.posY_ + sourceRect_.posY_ + + static_cast(sourceRect_.height_)) / static_cast(DIVISOR_TWO); + fixedSourceCenter_ = {static_cast(sourceCenterX), static_cast(sourceCenterY)}; + } else { + fixedSourceCenter_ = {0, 0}; + } +} + +void MagnificationWindow::DrawRuoundRectFramePart() +{ + if (surfaceNode_ == nullptr) { + HILOG_ERROR("get surfaceNode_ failed."); + return; + } + + if (canvasNode_ == nullptr) { + HILOG_ERROR("create canvasNode_ fail"); + return; + } + surfaceNode_->SetAbilityBGAlpha(BG_ALPHA); + surfaceNode_->AddChild(canvasNode_, -1); + canvasNode_->SetBounds(0, 0, windowWidth_, windowHeight_); + canvasNode_->SetFrame(0, 0, windowWidth_, windowHeight_); + canvasNode_->SetPositionZ(Rosen::RSSurfaceNode::POINTER_WINDOW_POSITION_Z); + canvasNode_->SetRotation(0); + + auto canvas = canvasNode_->BeginRecording(windowWidth_, windowHeight_); + Rosen::Drawing::Pen pen; + pen.SetAntiAlias(true); + pen.SetColor(ORANGE_COLOR); + pen.SetWidth(PEN_WIDTH); + canvas->AttachPen(pen); + Rosen::Drawing::Path path; + path.AddRoundRect({ROUND_RECT_MARGIN, ROUND_RECT_MARGIN, + windowWidth_ - ROUND_RECT_MARGIN, windowHeight_ - ROUND_RECT_MARGIN}, + CORNER_RADIUS, CORNER_RADIUS, Rosen::Drawing::PathDirection::CW_DIRECTION); + canvas->DrawPath(path); + canvas->DetachPen(); + + Rosen::Drawing::Pen linePen; + linePen.SetAntiAlias(true); + linePen.SetColor(ORANGE_COLOR); + linePen.SetWidth(PEN_WIDTH); + canvas->AttachPen(linePen); + auto p1 = Rosen::Drawing::Point(BAR_START, windowHeight_ - barMargin_); + auto p2 = Rosen::Drawing::Point(BAR_END, windowHeight_ - barMargin_); + canvas->DrawLine(p1, p2); + canvas->DetachPen(); + + Rosen::Drawing::Brush brush; + brush.SetAntiAlias(true); + brush.SetColor(ORANGE_COLOR); + canvas->AttachBrush(brush); + canvas->DrawCircle(p1, static_cast(PEN_WIDTH / DIVISOR_TWO)); + canvas->DrawCircle(p2, static_cast(PEN_WIDTH / DIVISOR_TWO)); + canvas->DetachBrush(); + canvasNode_->FinishRecording(); +} + +void MagnificationWindow::EnableMagnificationPart(int32_t centerX, int32_t centerY) +{ + HILOG_INFO("centerX = %{public}d, centerY = %{public}d.", centerX, centerY); + GetWindowParam(); + if (window_ == nullptr) { + HILOG_DEBUG("window is null. need create."); + windowRect_ = GetWindowRectFromPointer(centerX, centerY); + CreateMagnificationWindow(); + } + + if (window_ == nullptr) { + HILOG_ERROR("create window failed."); + return; + } + sourceRect_ = GetSourceRectFromPointer(centerX, centerY); + CalculateAnchorOffset(); + UpdateRelativeRect(); + window_->SetFrameRectForPartialZoomIn(relativeRect_); + DrawRuoundRectFramePart(); + window_->Show(); + FlushImplicitTransaction(); + isMagnificationShowPart_ = true; +} + +void MagnificationWindow::DisableMagnificationPart(bool needClear) +{ + DisableMagnification(needClear); + anchorOffsetX_ = 0; + anchorOffsetY_ = 0; + isMagnificationShowPart_ = false; +} + +bool MagnificationWindow::IsMagnificationShowPart() +{ + return isMagnificationShowPart_; +} + +void MagnificationWindow::SetScalePart(float scaleSpan) +{ + HILOG_DEBUG(); + if (screenWidth_ == 0 || screenHeight_ == 0 || abs(screenSpan_) < EPS) { + HILOG_ERROR("screen param invalid."); + return; + } + + float ratio = scaleSpan / screenSpan_; + float tmpScale = scale_ + ratio * scale_; + if (tmpScale > MAX_SCALE) { + tmpScale = MAX_SCALE; + } + if (tmpScale < DEFAULT_SCALE) { + tmpScale = DEFAULT_SCALE; + } + + uint32_t newWidth = static_cast(windowRect_.width_ / tmpScale); + uint32_t newHeight = static_cast(windowRect_.height_ / tmpScale); + int32_t newPosX = fixedSourceCenter_.posX - static_cast(newWidth / DIVISOR_TWO); + int32_t newPosY = fixedSourceCenter_.posY - static_cast(newHeight / DIVISOR_TWO); + + Rosen::Rect tmpRect = {newPosX, newPosY, newWidth, newHeight}; + if (!tmpRect.IsInsideOf(screenRect_)) { + HILOG_ERROR("sourceRect out of screenRect."); + return; + } + + if (window_ == nullptr) { + HILOG_ERROR("window_ is nullptr."); + return; + } + + sourceRect_ = tmpRect; + scale_ = tmpScale; + UpdateRelativeRect(); + window_->SetFrameRectForPartialZoomIn(relativeRect_); + DrawRuoundRectFramePart(); + FlushImplicitTransaction(); + CalculateAnchorOffset(); +} + +void MagnificationWindow::MoveMagnificationPart(int32_t deltaX, int32_t deltaY) +{ + if (window_ == nullptr) { + HILOG_ERROR("window is null."); + return; + } + + int32_t windowPosX = windowRect_.posX_; + int32_t sourcePosX = sourceRect_.posX_; + + if (abs(anchorOffsetX_) <= ANCHOR_OFFSET) { + windowPosX += deltaX; + } + sourcePosX += deltaX; + + int32_t windowPosY = windowRect_.posY_; + int32_t sourcePosY = sourceRect_.posY_; + + if (abs(anchorOffsetY_) <= ANCHOR_OFFSET) { + windowPosY += deltaY; + } + sourcePosY += deltaY; + + windowRect_.posX_ = windowPosX; + windowRect_.posY_ = windowPosY; + AdjustMagnificationWindowPosition(); + + window_->MoveTo(windowRect_.posX_, windowRect_.posY_); + + sourceRect_.posX_ = sourcePosX; + sourceRect_.posY_ = sourcePosY; + AdjustSourceWindowPosition(); + UpdateRelativeRect(); + window_->SetFrameRectForPartialZoomIn(relativeRect_); + DrawRuoundRectFramePart(); + FlushImplicitTransaction(); + CalculateAnchorOffset(); +} + +void MagnificationWindow::ShowMagnificationPart() +{ + int32_t centerX = static_cast(screenWidth_ / DIVISOR_TWO); + int32_t centerY = static_cast(screenHeight_ / DIVISOR_TWO); + EnableMagnificationPart(centerX, centerY); +} + +void MagnificationWindow::FollowFocuseElementPart(int32_t centerX, int32_t centerY) +{ + HILOG_DEBUG(); + if (window_ == nullptr) { + HILOG_ERROR("window_ is nullptr."); + return; + } + windowRect_ = GetWindowRectFromPointer(centerX, centerY); + sourceRect_ = GetSourceRectFromPointer(centerX, centerY); + window_->MoveTo(windowRect_.posX_, windowRect_.posY_); + UpdateRelativeRect(); + window_->SetFrameRectForPartialZoomIn(relativeRect_); + DrawRuoundRectFramePart(); + FlushImplicitTransaction(); + CalculateAnchorOffset(); +} + +void MagnificationWindow::RefreshWindowParamPart() +{ + HILOG_DEBUG(); + if (isMagnificationShowPart_) { + PointerPos center = GetRectCenter(windowRect_); + HILOG_INFO("need refresh window param."); + DisableMagnificationPart(); + EnableMagnificationPart(center.posX, center.posY); + } else { + GetWindowParam(); + } +} + +extern "C" API_EXPORT void EnableMagnification(uint32_t magnificationType, int32_t posX, int32_t posY) +{ + if (magnificationType == FULL_SCREEN_MAGNIFICATION) { + instance.EnableMagnificationFull(posX, posY); + return; + } + if (magnificationType == WINDOW_MAGNIFICATION) { + instance.EnableMagnificationPart(posX, posY); + return; + } + HILOG_DEBUG("invalid type = %{public}d", magnificationType); +} + +extern "C" API_EXPORT void DisableMagnification(uint32_t magnificationType, bool needClear) +{ + if (magnificationType == FULL_SCREEN_MAGNIFICATION) { + instance.DisableMagnificationFull(needClear); + return; + } + if (magnificationType == WINDOW_MAGNIFICATION) { + instance.DisableMagnificationPart(needClear); + return; + } + HILOG_DEBUG("invalid type = %{public}d", magnificationType); +} + +extern "C" API_EXPORT void SetScale(uint32_t magnificationType, float scaleSpan) +{ + if (magnificationType == FULL_SCREEN_MAGNIFICATION) { + instance.SetScaleFull(scaleSpan); + return; + } + if (magnificationType == WINDOW_MAGNIFICATION) { + instance.SetScalePart(scaleSpan); + return; + } + HILOG_DEBUG("invalid type = %{public}d", magnificationType); +} + +extern "C" API_EXPORT void MoveMagnification(uint32_t magnificationType, int32_t deltaX, int32_t deltaY) +{ + if (magnificationType == FULL_SCREEN_MAGNIFICATION) { + instance.MoveMagnificationFull(deltaX, deltaY); + return; + } + if (magnificationType == WINDOW_MAGNIFICATION) { + instance.MoveMagnificationPart(deltaX, deltaY); + return; + } + HILOG_DEBUG("invalid type = %{public}d", magnificationType); +} + +extern "C" API_EXPORT PointerPos ConvertGesture(uint32_t type, PointerPos coordinates) +{ + return instance.ConvertGesture(type, coordinates); +} + +extern "C" API_EXPORT PointerPos ConvertCoordinates(int32_t posX, int32_t posY) +{ + return instance.ConvertCoordinates(posX, posY); +} + +extern "C" API_EXPORT uint32_t CheckTapOnHotArea(int32_t posX, int32_t posY) +{ + return instance.CheckTapOnHotArea(posX, posY); +} + +extern "C" API_EXPORT float GetScale() +{ + return instance.GetScale(); +} + +extern "C" API_EXPORT bool IsMagnificationWindowShow(uint32_t magnificationType) +{ + if (magnificationType == FULL_SCREEN_MAGNIFICATION) { + return instance.IsMagnificationShowFull(); + } + if (magnificationType == WINDOW_MAGNIFICATION) { + return instance.IsMagnificationShowPart(); + } + HILOG_DEBUG("invalid type = %{public}d", magnificationType); + return false; +} + +extern "C" API_EXPORT void FollowFocuseElement(uint32_t magnificationType, int32_t centerX, int32_t centerY) +{ + if (magnificationType == FULL_SCREEN_MAGNIFICATION) { + instance.FollowFocuseElementFull(centerX, centerY); + return; + } + if (magnificationType == WINDOW_MAGNIFICATION) { + instance.FollowFocuseElementPart(centerX, centerY); + return; + } + HILOG_DEBUG("invalid type = %{public}d", magnificationType); +} + +extern "C" API_EXPORT PointerPos GetSourceCenter() +{ + return instance.GetSourceCenter(); +} + +extern "C" API_EXPORT void ShowMagnification(uint32_t magnificationType) +{ + if (magnificationType == FULL_SCREEN_MAGNIFICATION) { + instance.ShowMagnificationFull(); + return; + } + if (magnificationType == WINDOW_MAGNIFICATION) { + instance.ShowMagnificationPart(); + return; + } + HILOG_DEBUG("invalid type = %{public}d", magnificationType); +} + +extern "C" API_EXPORT void RefreshWindowParam(uint32_t magnificationType) +{ + if (magnificationType == FULL_SCREEN_MAGNIFICATION) { + instance.RefreshWindowParamFull(); + return; + } + if (magnificationType == WINDOW_MAGNIFICATION) { + instance.RefreshWindowParamPart(); + return; + } + HILOG_DEBUG("invalid type = %{public}d", magnificationType); +} + +extern "C" API_EXPORT bool IsTapOnHotArea(int32_t posX, int32_t posY) +{ + return instance.IsTapOnHotArea(posX, posY); +} + +extern "C" API_EXPORT bool IsTapOnMagnificationWindow(int32_t posX, int32_t posY) +{ + return instance.IsTapOnMagnificationWindow(posX, posY); +} + +extern "C" API_EXPORT void FixSourceCenter(bool needFix) +{ + instance.FixSourceCenter(needFix); +} + +extern "C" API_EXPORT void InitMagnificationParam(float scale) +{ + instance.InitMagnificationParam(scale); +} +} +} +// LCOV_EXCL_STOP \ No newline at end of file diff --git a/services/test/BUILD.gn b/services/test/BUILD.gn index db415787..8612d9ae 100644 --- a/services/test/BUILD.gn +++ b/services/test/BUILD.gn @@ -90,6 +90,7 @@ ohos_moduletest("aams_accessibility_touch_exploration_test") { "../aams/src/magnification_menu_manager.cpp", "../aams/src/full_screen_magnification_manager.cpp", "../aams/src/window_magnification_manager.cpp", + "../aams/src/magnification_window_proxy.cpp", "../aams/src/accessible_ability_channel.cpp", "../aams/src/accessible_ability_connection.cpp", "../aams/src/accessible_ability_manager_service.cpp", @@ -222,6 +223,7 @@ ohos_moduletest("aams_accessibility_touchEvent_injector_test") { "../aams/src/magnification_menu_manager.cpp", "../aams/src/full_screen_magnification_manager.cpp", "../aams/src/window_magnification_manager.cpp", + "../aams/src/magnification_window_proxy.cpp", "../aams/src/accessible_ability_channel.cpp", "../aams/src/accessible_ability_connection.cpp", "../aams/src/accessible_ability_manager_service.cpp", @@ -355,6 +357,7 @@ ohos_moduletest("aams_accessible_ability_channel_test") { "../aams/src/magnification_menu_manager.cpp", "../aams/src/full_screen_magnification_manager.cpp", "../aams/src/window_magnification_manager.cpp", + "../aams/src/magnification_window_proxy.cpp", "../aams/src/accessible_ability_channel.cpp", "../aams/src/accessible_ability_connection.cpp", "../aams/src/accessible_ability_manager_service.cpp", @@ -487,6 +490,7 @@ ohos_moduletest("aams_server_test") { "../aams/src/magnification_menu_manager.cpp", "../aams/src/full_screen_magnification_manager.cpp", "../aams/src/window_magnification_manager.cpp", + "../aams/src/magnification_window_proxy.cpp", "../aams/src/accessible_ability_channel.cpp", "../aams/src/accessible_ability_connection.cpp", "../aams/src/accessible_ability_manager_service.cpp", @@ -617,6 +621,7 @@ ohos_moduletest("aams_accessibility_keyevent_filter_test") { "../aams/src/magnification_menu_manager.cpp", "../aams/src/full_screen_magnification_manager.cpp", "../aams/src/window_magnification_manager.cpp", + "../aams/src/magnification_window_proxy.cpp", "../aams/src/accessible_ability_channel.cpp", "../aams/src/accessible_ability_connection.cpp", "../aams/src/accessible_ability_manager_service.cpp", @@ -748,6 +753,7 @@ ohos_moduletest("aams_common_event_registry_test") { "../aams/src/magnification_menu_manager.cpp", "../aams/src/full_screen_magnification_manager.cpp", "../aams/src/window_magnification_manager.cpp", + "../aams/src/magnification_window_proxy.cpp", "../aams/src/accessible_ability_channel.cpp", "../aams/src/accessible_ability_connection.cpp", "../aams/src/accessible_ability_manager_service.cpp", -- Gitee