diff --git a/frameworks/aafwk/test/BUILD.gn b/frameworks/aafwk/test/BUILD.gn index e998b7810dd394d61ba6ce0ed288b08c877132a7..05b8896568cd672adf9eba7fc34077b37fac1b62 100755 --- a/frameworks/aafwk/test/BUILD.gn +++ b/frameworks/aafwk/test/BUILD.gn @@ -127,11 +127,7 @@ 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/test/mock/src/mock_magnification_manager.cpp", "../../../services/aams/src/window_magnification_gesture.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", @@ -144,6 +140,10 @@ ohos_unittest("accessible_ability_test") { "../../../services/aams/test/mock/src/mock_accessible_ability_connection.cpp", "../../../services/aams/test/mock/src/mock_accessible_ability_manager_service_state_observer_proxy.cpp", "../../../services/aams/test/mock/src/mock_accessible_ability_manager_service_state_observer_stub.cpp", + "../../../services/aams/test/mock/src/mock_full_screen_magnification_manager.cpp", + "../../../services/aams/test/mock/src/mock_magnification_manager.cpp", + "../../../services/aams/test/mock/src/mock_magnification_menu_manager.cpp", + "../../../services/aams/test/mock/src/mock_window_magnification_manager.cpp", "../../../services/test/mock/mock_os_account_manager.cpp", "../../../services/test/mock/mock_parameter.c", "../../common/src/accessibility_caption.cpp", diff --git a/services/aams/include/accessibility_display_manager.h b/services/aams/include/accessibility_display_manager.h index c58c60bf84c3a950ac717811ec22fd18f66525af..176cf732d419eaded9acec12c72e57450debeae0 100644 --- a/services/aams/include/accessibility_display_manager.h +++ b/services/aams/include/accessibility_display_manager.h @@ -45,10 +45,7 @@ public: void RegisterDisplayListener(const std::shared_ptr &manager); void UnregisterDisplayListener(); - - void RegisterDisplayModeListener(); - void UnregisterDisplayModeListener(); - + RotationType GetRotationType(Rosen::DisplayOrientation prev, Rosen::DisplayOrientation curr); private: class DisplayListener : public Rosen::DisplayManager::IDisplayListener { public: @@ -71,16 +68,7 @@ private: std::shared_ptr manager_ = nullptr; }; - class DisplayModeListener : public Rosen::DisplayManager::IDisplayModeListener { - public: - explicit DisplayModeListener() {} - ~DisplayModeListener() = default; - - void OnDisplayModeChanged(Rosen::FoldDisplayMode displayMode); - }; - sptr listener_ = nullptr; - sptr displayModeListener_ = nullptr; std::shared_ptr handler_ = nullptr; }; } // namespace Accessibility diff --git a/services/aams/include/full_screen_magnification_manager.h b/services/aams/include/full_screen_magnification_manager.h index cb21a736a4c266556c5411705b4ae67cfa0bc962..a4630d51d7e4856389fbb01fd4951ec9731a1f0a 100644 --- a/services/aams/include/full_screen_magnification_manager.h +++ b/services/aams/include/full_screen_magnification_manager.h @@ -35,7 +35,7 @@ public: void ShowMagnificationWithPosition(PointerPos pos); void DisableMagnification(bool needClear = false); PointerPos ConvertCoordinates(int32_t posX, int32_t posY); - void RefreshWindowParam(); + void RefreshWindowParam(RotationType type); void SetScale(float scaleSpan); void MoveMagnification(int32_t deltaX, int32_t deltaY); void PersistScale(); diff --git a/services/aams/include/magnification_def.h b/services/aams/include/magnification_def.h index f0c0418f8a8b62023d97096f1b3181d6129305fd..beea164461cdd12afad9dd2d7aeddbc1d4e9c6c3 100644 --- a/services/aams/include/magnification_def.h +++ b/services/aams/include/magnification_def.h @@ -33,6 +33,14 @@ enum class AnnounceType : uint32_t { ANNOUNCE_SWITCH_WINDOW }; +enum class RotationType : uint32_t { + LEFT_ROTATE = 0, + RIGHT_ROTATE, + FLIP_VERTICAL, + NO_CHANGE, + UNKNOWN +}; + constexpr float EPS = 1e-6; constexpr float DEFAULT_SCALE = 2.0f; constexpr float MAX_SCALE = 8.0f; diff --git a/services/aams/include/magnification_manager.h b/services/aams/include/magnification_manager.h index 5fe2c27aed8549a8d42aee9bf07d7be8e5b71cf4..a080ad43cbb24ac450a140ba364498ac71114b4d 100644 --- a/services/aams/include/magnification_manager.h +++ b/services/aams/include/magnification_manager.h @@ -36,7 +36,7 @@ public: void DisableMagnification(); void TriggerMagnification(uint32_t type, uint32_t mode); bool GetMagnificationState(); - void RefreshWindowParam(); + void RefreshWindowParam(RotationType type); void FollowFocuseElement(int32_t centerX, int32_t centerY); inline void ResetCurrentMode() { diff --git a/services/aams/include/magnification_window_proxy.h b/services/aams/include/magnification_window_proxy.h index 6a9c3a7aa7f462fb1a0d1c2d95a1afec926a1f15..13c308f11c9482c586302c86264a06c3826c0241 100644 --- a/services/aams/include/magnification_window_proxy.h +++ b/services/aams/include/magnification_window_proxy.h @@ -42,7 +42,7 @@ public: float GetScale(); bool IsMagnificationWindowShow(uint32_t magnificationType); void ShowMagnification(uint32_t magnificationType); - void RefreshWindowParam(uint32_t magnificationType); + void RefreshWindowParam(uint32_t magnificationType, RotationType type); PointerPos ConvertCoordinates(int32_t posX, int32_t posY); void InitMagnificationParam(float scale); diff --git a/services/aams/include/window_magnification_manager.h b/services/aams/include/window_magnification_manager.h index 76995c52e2b64a45fd92001c5ae1b3b7540587d3..596f878df7777f83b2297d7cbf9f215e34a461e1 100644 --- a/services/aams/include/window_magnification_manager.h +++ b/services/aams/include/window_magnification_manager.h @@ -48,7 +48,7 @@ public: PointerPos ConvertCoordinates(int32_t posX, int32_t posY); void FixSourceCenter(bool needFix); void PersistScale(); - void RefreshWindowParam(); + void RefreshWindowParam(RotationType type); void FollowFocuseElement(int32_t centerX, int32_t centerY); PointerPos GetSourceCenter(); diff --git a/services/aams/src/accessibility_display_manager.cpp b/services/aams/src/accessibility_display_manager.cpp index 53a1feb0bbfb4221a3da91c5bf2c1784f8639f47..6fac203bcbbcec0c1c6f5656b62a0854fe0ac4e3 100644 --- a/services/aams/src/accessibility_display_manager.cpp +++ b/services/aams/src/accessibility_display_manager.cpp @@ -20,10 +20,41 @@ namespace OHOS { namespace Accessibility { - -constexpr int32_t DEFAULT_DPI = 540; -constexpr int32_t DEFAULT_WIDTH = 1260; -constexpr int32_t DEFAULT_HEIGHT = 2720; +namespace { + constexpr int32_t DEFAULT_DPI = 540; + constexpr int32_t DEFAULT_WIDTH = 1260; + constexpr int32_t DEFAULT_HEIGHT = 2720; + + static const std::map, RotationType> rotationMap = { + {{Rosen::DisplayOrientation::PORTRAIT, Rosen::DisplayOrientation::LANDSCAPE}, + RotationType::RIGHT_ROTATE}, + {{Rosen::DisplayOrientation::PORTRAIT, Rosen::DisplayOrientation::LANDSCAPE_INVERTED}, + RotationType::LEFT_ROTATE}, + {{Rosen::DisplayOrientation::PORTRAIT, Rosen::DisplayOrientation::PORTRAIT_INVERTED}, + RotationType::FLIP_VERTICAL}, + + {{Rosen::DisplayOrientation::LANDSCAPE, Rosen::DisplayOrientation::PORTRAIT}, + RotationType::LEFT_ROTATE}, + {{Rosen::DisplayOrientation::LANDSCAPE, Rosen::DisplayOrientation::PORTRAIT_INVERTED}, + RotationType::RIGHT_ROTATE}, + {{Rosen::DisplayOrientation::LANDSCAPE, Rosen::DisplayOrientation::LANDSCAPE_INVERTED}, + RotationType::FLIP_VERTICAL}, + + {{Rosen::DisplayOrientation::PORTRAIT_INVERTED, Rosen::DisplayOrientation::LANDSCAPE}, + RotationType::LEFT_ROTATE}, + {{Rosen::DisplayOrientation::PORTRAIT_INVERTED, Rosen::DisplayOrientation::PORTRAIT}, + RotationType::FLIP_VERTICAL}, + {{Rosen::DisplayOrientation::PORTRAIT_INVERTED, Rosen::DisplayOrientation::LANDSCAPE_INVERTED}, + RotationType::RIGHT_ROTATE}, + + {{Rosen::DisplayOrientation::LANDSCAPE_INVERTED, Rosen::DisplayOrientation::PORTRAIT}, + RotationType::RIGHT_ROTATE}, + {{Rosen::DisplayOrientation::LANDSCAPE_INVERTED, Rosen::DisplayOrientation::LANDSCAPE}, + RotationType::FLIP_VERTICAL}, + {{Rosen::DisplayOrientation::LANDSCAPE_INVERTED, Rosen::DisplayOrientation::PORTRAIT_INVERTED}, + RotationType::LEFT_ROTATE} + }; +} AccessibilityDisplayManager::AccessibilityDisplayManager() { @@ -169,9 +200,20 @@ void AccessibilityDisplayManager::UnregisterDisplayListener() } } +RotationType AccessibilityDisplayManager::GetRotationType(Rosen::DisplayOrientation prev, + Rosen::DisplayOrientation curr) +{ + auto key = std::make_pair(prev, curr); + auto it = rotationMap.find(key); + if (it != rotationMap.end()) { + return it->second; + } + return RotationType::UNKNOWN; +} + void AccessibilityDisplayManager::DisplayListener::OnChange(Rosen::DisplayId dId) { - HILOG_INFO(); + HILOG_DEBUG(); if (manager_ == nullptr) { manager_ = Singleton::GetInstance().GetMagnificationMgr(); } @@ -185,10 +227,9 @@ void AccessibilityDisplayManager::DisplayListener::OnChange(Rosen::DisplayId dId OHOS::Rosen::DisplayOrientation currentOrientation = displayMgr.GetOrientation(); OHOS::Rosen::FoldDisplayMode currentMode = displayMgr.GetFoldDisplayMode(); if (orientation_ == currentOrientation && displayMode_ == currentMode) { - HILOG_INFO("no need fresh."); return; } - + HILOG_INFO("need fresh."); if (Utils::IsWideFold()) { OnChangeForWideFold(currentOrientation, currentMode); return; @@ -212,7 +253,7 @@ void AccessibilityDisplayManager::DisplayListener::OnChangeForWideFold( currentOrientation, currentMode); auto interceptor = AccessibilityInputInterceptor::GetInstance(); if (interceptor == nullptr) { - HILOG_INFO("interceptor is null"); + HILOG_ERROR("interceptor is null"); return; } if (currentMode == Rosen::FoldDisplayMode::MAIN) { @@ -226,9 +267,13 @@ void AccessibilityDisplayManager::DisplayListener::OnChangeForWideFold( interceptor->ShieldZoomGesture(false); displayMode_ = currentMode; if (orientation_ != currentOrientation) { - HILOG_INFO("need refresh"); + HILOG_INFO("need refresh orientation."); + RotationType type = Singleton::GetInstance().GetRotationType( + orientation_, currentOrientation); + if (manager_ != nullptr) { + manager_->RefreshWindowParam(type); + } orientation_ = currentOrientation; - manager_->RefreshWindowParam(); } } } @@ -241,14 +286,20 @@ void AccessibilityDisplayManager::DisplayListener::OnChangeForBigFold( currentOrientation, currentMode); if (displayMode_ != currentMode) { HILOG_INFO("need refresh"); - manager_->RefreshWindowParam(); + if (manager_ != nullptr) { + manager_->RefreshWindowParam(RotationType::NO_CHANGE); + } displayMode_ = currentMode; } if (orientation_ != currentOrientation) { - HILOG_INFO("need refresh"); + HILOG_INFO("need refresh orientation."); + RotationType type = Singleton::GetInstance().GetRotationType( + orientation_, currentOrientation); + if (manager_ != nullptr) { + manager_->RefreshWindowParam(type); + } orientation_ = currentOrientation; - manager_->RefreshWindowParam(); } } @@ -257,63 +308,13 @@ void AccessibilityDisplayManager::DisplayListener::OnChangeDefault( { HILOG_DEBUG("currentOrientation = %{public}d", currentOrientation); if (orientation_ != currentOrientation) { - HILOG_INFO("need refresh"); - orientation_ = currentOrientation; - manager_->RefreshWindowParam(); - } -} - -void AccessibilityDisplayManager::RegisterDisplayModeListener() -{ - HILOG_DEBUG(); - if (displayModeListener_) { - HILOG_DEBUG("Display mode listener is already registed!"); - return; - } - displayModeListener_ = new(std::nothrow) DisplayModeListener(); - if (!displayModeListener_) { - HILOG_ERROR("Create display mode listener fail!"); - return; - } - Rosen::DisplayManager::GetInstance().RegisterDisplayModeListener(displayModeListener_); -} - -void AccessibilityDisplayManager::UnregisterDisplayModeListener() -{ - HILOG_DEBUG(); - if (displayModeListener_) { - Rosen::DisplayManager::GetInstance().UnregisterDisplayModeListener(displayModeListener_); - displayModeListener_ = nullptr; - } -} - -void AccessibilityDisplayManager::DisplayModeListener::OnDisplayModeChanged(Rosen::FoldDisplayMode displayMode) -{ - if (Utils::IsWideFold()) { - auto interceptor = AccessibilityInputInterceptor::GetInstance(); - if (interceptor == nullptr) { - HILOG_ERROR("interceptior is null"); - return; - } - if (displayMode == Rosen::FoldDisplayMode::MAIN) { - interceptor->ShieldZoomGesture(true); - } else if (displayMode == Rosen::FoldDisplayMode::FULL) { - interceptor->ShieldZoomGesture(false); - } else { - HILOG_DEBUG("other display mode."); + HILOG_INFO("need refresh orientation."); + RotationType type = Singleton::GetInstance().GetRotationType( + orientation_, currentOrientation); + if (manager_ != nullptr) { + manager_->RefreshWindowParam(type); } - return; - } - - if (Utils::IsBigFold()) { - HILOG_DEBUG("IsBigFold"); - auto manager = Singleton::GetInstance().GetMagnificationMgr(); - if (manager == nullptr) { - HILOG_ERROR("manager is null"); - return; - } - manager->RefreshWindowParam(); - return; + orientation_ = currentOrientation; } } } // namespace Accessibility diff --git a/services/aams/src/accessibility_input_interceptor.cpp b/services/aams/src/accessibility_input_interceptor.cpp index 1d6fe9f901d0745eb631f79bd2faeb7515a923c9..964cef71805a925b92c47a44f3098310c0bdc853 100644 --- a/services/aams/src/accessibility_input_interceptor.cpp +++ b/services/aams/src/accessibility_input_interceptor.cpp @@ -250,11 +250,14 @@ void AccessibilityInputInterceptor::CreatZoomGesture() Singleton::GetInstance().GetFullScreenMagnificationManager(); std::shared_ptr menuManager = Singleton::GetInstance().GetMenuManager(); - if (fullScreenMagnificationManager == nullptr || menuManager == nullptr) { - HILOG_ERROR("get windowMagnification or menu manager failed."); + if (fullScreenMagnificationManager == nullptr) { + HILOG_ERROR("get windowMagnification manager failed."); + return; + } + if (menuManager == nullptr) { + HILOG_ERROR("get menu manager failed."); return; } - if (zoomGesture_ == nullptr) { sptr zoomGesture = new(std::nothrow) AccessibilityZoomGesture(fullScreenMagnificationManager, menuManager); @@ -277,11 +280,14 @@ void AccessibilityInputInterceptor::CreatWindowMagnificationGesture() Singleton::GetInstance().GetWindowMagnificationManager(); std::shared_ptr menuManager = Singleton::GetInstance().GetMenuManager(); - if (windowMagnificationManager == nullptr || menuManager == nullptr) { - HILOG_ERROR("get windowMagnification or menu manager failed."); + if (windowMagnificationManager == nullptr) { + HILOG_ERROR("get windowMagnification manager failed."); + return; + } + if (menuManager == nullptr) { + HILOG_ERROR("get menu manager failed."); return; } - if (windowMagnificationGesture_ == nullptr) { sptr windowMagnificationGesture = new(std::nothrow) WindowMagnificationGesture(windowMagnificationManager, menuManager); diff --git a/services/aams/src/accessible_ability_manager_service.cpp b/services/aams/src/accessible_ability_manager_service.cpp index a9d0bf72059076de6d1f2a2939bff373030f1d9b..bcfd964587eec4744365f6d00b3b3b30e4153341 100644 --- a/services/aams/src/accessible_ability_manager_service.cpp +++ b/services/aams/src/accessible_ability_manager_service.cpp @@ -3446,6 +3446,10 @@ void AccessibleAbilityManagerService::RegisterShortKeyEvent() void AccessibleAbilityManagerService::InitMagnification() { HILOG_INFO(); + if (magnificationManager_ != nullptr) { + HILOG_WARN("magnification already init."); + return; + } magnificationManager_ = std::make_shared(); #ifdef OHOS_BUILD_ENABLE_DISPLAY_MANAGER Singleton::GetInstance().RegisterDisplayListener(magnificationManager_); diff --git a/services/aams/src/full_screen_magnification_manager.cpp b/services/aams/src/full_screen_magnification_manager.cpp index bbdf796d624016043c6f2e6abca871fbf880d6d2..a16e2403cffa0b334210104c7413f5d6dae062e7 100644 --- a/services/aams/src/full_screen_magnification_manager.cpp +++ b/services/aams/src/full_screen_magnification_manager.cpp @@ -84,11 +84,11 @@ void FullScreenMagnificationManager::PersistScale() AnnounceType::ANNOUNCE_MAGNIFICATION_SCALE); } -void FullScreenMagnificationManager::RefreshWindowParam() +void FullScreenMagnificationManager::RefreshWindowParam(RotationType type) { HILOG_DEBUG(); CHECK_PROXY_PTR_VOID() - windowProxy_->RefreshWindowParam(FULL_SCREEN_MAGNIFICATION); + windowProxy_->RefreshWindowParam(FULL_SCREEN_MAGNIFICATION, type); } PointerPos FullScreenMagnificationManager::ConvertCoordinates(int32_t posX, int32_t posY) diff --git a/services/aams/src/magnification_manager.cpp b/services/aams/src/magnification_manager.cpp index 24ed9ed33cae681953cb6587f01a9f094aa0f593..60a350c08b4fd91da50a52e189256e1a6da94dc4 100644 --- a/services/aams/src/magnification_manager.cpp +++ b/services/aams/src/magnification_manager.cpp @@ -210,15 +210,15 @@ bool MagnificationManager::GetMagnificationState() return false; } -void MagnificationManager::RefreshWindowParam() +void MagnificationManager::RefreshWindowParam(RotationType type) { HILOG_DEBUG(); if (currentMode_ == WINDOW_MAGNIFICATION && windowMagnificationManager_ != nullptr) { - windowMagnificationManager_->RefreshWindowParam(); + windowMagnificationManager_->RefreshWindowParam(type); } if (currentMode_ == FULL_SCREEN_MAGNIFICATION && fullScreenMagnificationManager_ != nullptr) { - fullScreenMagnificationManager_->RefreshWindowParam(); + fullScreenMagnificationManager_->RefreshWindowParam(type); } if (menuManager_ != nullptr) { diff --git a/services/aams/src/magnification_window_proxy.cpp b/services/aams/src/magnification_window_proxy.cpp index ea3d32889de5b216d1fea2015abe14329c29bc6f..2ab157f11daf6dfc989d7a903aedb3724f14bf1f 100644 --- a/services/aams/src/magnification_window_proxy.cpp +++ b/services/aams/src/magnification_window_proxy.cpp @@ -203,20 +203,20 @@ void MagnificationWindowProxy::ShowMagnification(uint32_t magnificationType) showFun(magnificationType); } -void MagnificationWindowProxy::RefreshWindowParam(uint32_t magnificationType) +void MagnificationWindowProxy::RefreshWindowParam(uint32_t magnificationType, RotationType type) { if (!handle_) { HILOG_ERROR("handle is null"); return; } - using RefreshWindowParam = void (*)(uint32_t magnificationType); + using RefreshWindowParam = void (*)(uint32_t magnificationType, RotationType type); RefreshWindowParam refreshWindowParamFun = (RefreshWindowParam)GetFunc("RefreshWindowParam"); if (!refreshWindowParamFun) { HILOG_ERROR("RefreshWindowParam func is null"); return; } - refreshWindowParamFun(magnificationType); + refreshWindowParamFun(magnificationType, type); } PointerPos MagnificationWindowProxy::ConvertCoordinates(int32_t posX, int32_t posY) diff --git a/services/aams/src/window_magnification_manager.cpp b/services/aams/src/window_magnification_manager.cpp index 02c62c615f7368fba3491886a9cb7b0826087b05..fb7ababcf55574e7c6465f1a5a6f3b26e0cbb4b7 100644 --- a/services/aams/src/window_magnification_manager.cpp +++ b/services/aams/src/window_magnification_manager.cpp @@ -83,11 +83,11 @@ bool WindowMagnificationManager::IsTapOnHotArea(int32_t posX, int32_t posY) return windowProxy_->IsTapOnHotArea(posX, posY); } -void WindowMagnificationManager::RefreshWindowParam() +void WindowMagnificationManager::RefreshWindowParam(RotationType type) { HILOG_DEBUG(); CHECK_PROXY_PTR_VOID() - windowProxy_->RefreshWindowParam(WINDOW_MAGNIFICATION); + windowProxy_->RefreshWindowParam(WINDOW_MAGNIFICATION, type); } bool WindowMagnificationManager::IsTapOnMagnificationWindow(int32_t posX, int32_t posY) 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 3e36e7978688d97e941a965c93f7c8cddacad10c..03f9da80803766506123092f11ae4f45ae06ca0f 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 @@ -63,8 +63,9 @@ void FullScreenMagnificationManager::PersistScale() { } -void FullScreenMagnificationManager::RefreshWindowParam() +void FullScreenMagnificationManager::RefreshWindowParam(RotationType type) { + (void)type; } PointerPos FullScreenMagnificationManager::ConvertCoordinates(int32_t posX, int32_t posY) diff --git a/services/aams/test/mock/src/mock_magnification_manager.cpp b/services/aams/test/mock/src/mock_magnification_manager.cpp index 2b4697aea492f2f76cffd311945d7d292d83b8c4..61fce1ddb20fb37a4f037314f364eab7e9ee80a2 100644 --- a/services/aams/test/mock/src/mock_magnification_manager.cpp +++ b/services/aams/test/mock/src/mock_magnification_manager.cpp @@ -62,8 +62,9 @@ bool MagnificationManager::GetMagnificationState() return false; } -void MagnificationManager::RefreshWindowParam() +void MagnificationManager::RefreshWindowParam(RotationType type) { + (void)type; } void MagnificationManager::FollowFocuseElement(int32_t centerX, int32_t centerY) diff --git a/services/aams/test/mock/src/mock_window_magnification_manager.cpp b/services/aams/test/mock/src/mock_window_magnification_manager.cpp index 46a3cdbf7927da2351cce289c9b4ba2c148d1465..c39406856981bff94ef3b9c3615142ce017e662e 100644 --- a/services/aams/test/mock/src/mock_window_magnification_manager.cpp +++ b/services/aams/test/mock/src/mock_window_magnification_manager.cpp @@ -66,8 +66,9 @@ bool WindowMagnificationManager::IsTapOnHotArea(int32_t posX, int32_t posY) return false; } -void WindowMagnificationManager::RefreshWindowParam() +void WindowMagnificationManager::RefreshWindowParam(RotationType type) { + (void)type; } bool WindowMagnificationManager::IsTapOnMagnificationWindow(int32_t posX, int32_t posY) diff --git a/services/aams_ext/include/magnification_window.h b/services/aams_ext/include/magnification_window.h index 1f2d3fff618b18ed570ffe760d70925016e6b891..7532dcc1eb1ed96ad9a6f774dd569c28fa32cc3b 100644 --- a/services/aams_ext/include/magnification_window.h +++ b/services/aams_ext/include/magnification_window.h @@ -35,10 +35,17 @@ namespace Accessibility { class MagnificationWindow { public: // common - float GetScale(); PointerPos GetSourceCenter(); PointerPos ConvertCoordinates(int32_t posX, int32_t posY); - void InitMagnificationParam(float scale); + inline float GetScale() + { + return scale_; + } + + inline void InitMagnificationParam(float scale) + { + scale_ = scale; + } // full magnification void EnableMagnificationFull(int32_t centerX, int32_t centerY); @@ -49,7 +56,7 @@ public: uint32_t CheckTapOnHotArea(int32_t posX, int32_t posY); void FollowFocuseElementFull(int32_t centerX, int32_t centerY); void ShowMagnificationFull(); - void RefreshWindowParamFull(); + void RefreshWindowParamFull(RotationType type); bool IsMagnificationShowFull(); // window magnification @@ -62,7 +69,7 @@ public: void FixSourceCenter(bool needFix); void FollowFocuseElementPart(int32_t centerX, int32_t centerY); void ShowMagnificationPart(); - void RefreshWindowParamPart(); + void RefreshWindowParamPart(RotationType type); bool IsMagnificationShowPart(); private: @@ -72,6 +79,7 @@ private: PointerPos GetRectCenter(Rosen::Rect rect); void FlushImplicitTransaction(); void DisableMagnification(bool needClear = false); + PointerPos TransferCenter(RotationType type, PointerPos center); // full magnification Rosen::Rect GetSourceRectFromPointer(int32_t centerX, int32_t centerY); diff --git a/services/aams_ext/src/magnification_menu.cpp b/services/aams_ext/src/magnification_menu.cpp index f2a3703b96977ce107c332fe5ea6de650dcb7d7a..9ee350e0b6ab91146b80a32be0dfd79d077a7b80 100644 --- a/services/aams_ext/src/magnification_menu.cpp +++ b/services/aams_ext/src/magnification_menu.cpp @@ -95,6 +95,10 @@ void MagnificationMenu::LoadMenuBgImage(uint32_t mode) rosenImage_->SetPixelMap(bgpixelmap_); rosenImage_->SetImageFit(static_cast(Rosen::ImageFit::FILL)); canvasNode_->SetBgImage(rosenImage_); + if (menuWindow_ == nullptr) { + HILOG_ERROR("create failed"); + return; + } menuWindow_->Show(); } diff --git a/services/aams_ext/src/magnification_window.cpp b/services/aams_ext/src/magnification_window.cpp index bf5b60af6504847f5ebfb2df0aefa9904ad764ff..fdc25a947b98433f2c5459b8f495bb0e4743b1a8 100644 --- a/services/aams_ext/src/magnification_window.cpp +++ b/services/aams_ext/src/magnification_window.cpp @@ -27,11 +27,6 @@ namespace { static MagnificationWindow instance; //common -float MagnificationWindow::GetScale() -{ - return scale_; -} - PointerPos MagnificationWindow::GetSourceCenter() { PointerPos point = {0, 0}; @@ -105,11 +100,6 @@ void MagnificationWindow::GetWindowParam() #endif } -void MagnificationWindow::InitMagnificationParam(float scale) -{ - scale_ = scale; -} - void MagnificationWindow::FlushImplicitTransaction() { if (rsUIContext_ != nullptr) { @@ -268,6 +258,10 @@ void MagnificationWindow::DrawRuoundRectFrameFull() canvasNode_->SetRotation(0); auto canvas = canvasNode_->BeginRecording(screenWidth_, screenHeight_); + if (canvas == nullptr) { + HILOG_ERROR("get canvas fail"); + return; + } Rosen::Drawing::Pen pen; pen.SetAntiAlias(true); pen.SetColor(ORANGE_COLOR); @@ -411,12 +405,13 @@ void MagnificationWindow::ShowMagnificationFull() EnableMagnificationFull(centerX, centerY); } -void MagnificationWindow::RefreshWindowParamFull() +void MagnificationWindow::RefreshWindowParamFull(RotationType type) { HILOG_DEBUG(); PointerPos center = GetRectCenter(sourceRect_); if (isMagnificationShowFull_) { DisableMagnificationFull(false); + center = TransferCenter(type, center); EnableMagnificationFull(center.posX, center.posY); } else { GetWindowParam(); @@ -585,6 +580,10 @@ void MagnificationWindow::DrawRuoundRectFramePart() canvasNode_->SetRotation(0); auto canvas = canvasNode_->BeginRecording(windowWidth_, windowHeight_); + if (canvas == nullptr) { + HILOG_ERROR("get canvas fail"); + return; + } Rosen::Drawing::Pen pen; pen.SetAntiAlias(true); pen.SetColor(ORANGE_COLOR); @@ -763,19 +762,38 @@ void MagnificationWindow::FollowFocuseElementPart(int32_t centerX, int32_t cente CalculateAnchorOffset(); } -void MagnificationWindow::RefreshWindowParamPart() +void MagnificationWindow::RefreshWindowParamPart(RotationType type) { HILOG_DEBUG(); if (isMagnificationShowPart_) { PointerPos center = GetRectCenter(windowRect_); HILOG_INFO("need refresh window param."); DisableMagnificationPart(); + center = TransferCenter(type, center); EnableMagnificationPart(center.posX, center.posY); } else { GetWindowParam(); } } +PointerPos MagnificationWindow::TransferCenter(RotationType type, PointerPos center) +{ + if (type == RotationType::NO_CHANGE || type == RotationType::UNKNOWN) { + return center; + } + GetWindowParam(); + if (type == RotationType::LEFT_ROTATE) { + return {center.posY, screenHeight_ - center.posX}; + } + if (type == RotationType::RIGHT_ROTATE) { + return {screenWidth_ - center.posY, center.posX}; + } + if (type == RotationType::FLIP_VERTICAL) { + return {screenWidth_ - center.posX, screenHeight_ - center.posY}; + } + return center; +} + extern "C" API_EXPORT void EnableMagnification(uint32_t magnificationType, int32_t posX, int32_t posY) { if (magnificationType == FULL_SCREEN_MAGNIFICATION) { @@ -891,14 +909,14 @@ extern "C" API_EXPORT void ShowMagnification(uint32_t magnificationType) HILOG_DEBUG("invalid type = %{public}d", magnificationType); } -extern "C" API_EXPORT void RefreshWindowParam(uint32_t magnificationType) +extern "C" API_EXPORT void RefreshWindowParam(uint32_t magnificationType, RotationType type) { if (magnificationType == FULL_SCREEN_MAGNIFICATION) { - instance.RefreshWindowParamFull(); + instance.RefreshWindowParamFull(type); return; } if (magnificationType == WINDOW_MAGNIFICATION) { - instance.RefreshWindowParamPart(); + instance.RefreshWindowParamPart(type); return; } HILOG_DEBUG("invalid type = %{public}d", magnificationType);