LCOV - code coverage report
Current view: top level - muse/framework/accessibility - accessibilitymodule.cpp Coverage Total Hit
Test: filtered_coverage.info Lines: 55.6 % 45 25
Test Date: 2026-11-05 04:07:02

            Line data    Source code
       1              : /*
       2              :  * SPDX-License-Identifier: GPL-3.0-only
       3              :  * MuseScore-CLA-applies
       4              :  *
       5              :  * MuseScore Studio
       6              :  * Music Composition & Notation
       7              :  *
       8              :  * Copyright (C) 2021 MuseScore Limited and others
       9              :  *
      10              :  * This program is free software: you can redistribute it and/or modify
      11              :  * it under the terms of the GNU General Public License version 3 as
      12              :  * published by the Free Software Foundation.
      13              :  *
      14              :  * This program is distributed in the hope that it will be useful,
      15              :  * but WITHOUT ANY WARRANTY; without even the implied warranty of
      16              :  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
      17              :  * GNU General Public License for more details.
      18              :  *
      19              :  * You should have received a copy of the GNU General Public License
      20              :  * along with this program.  If not, see <https://www.gnu.org/licenses/>.
      21              :  */
      22              : #include "accessibilitymodule.h"
      23              : 
      24              : #include <QAccessible>
      25              : 
      26              : #include "modularity/ioc.h"
      27              : 
      28              : #include "iaccessibleapprootobject.h"
      29              : #include "internal/accessibilitycontroller.h"
      30              : #include "internal/accessibleapprootobject.h"
      31              : #include "internal/accessiblestub.h"
      32              : #include "internal/qaccessibleinterfaceregister.h"
      33              : #include "iqaccessibleinterfaceregister.h"
      34              : 
      35              : #include "global/api/iapiregister.h"
      36              : #include "api/accessibilityapi.h"
      37              : 
      38              : using namespace muse::accessibility;
      39              : using namespace muse::modularity;
      40              : 
      41              : static const std::string mname("accessibility");
      42              : 
      43            0 : std::string AccessibilityModule::moduleName() const
      44              : {
      45            0 :     return mname;
      46              : }
      47              : 
      48            1 : void AccessibilityModule::registerExports()
      49              : {
      50            1 :     globalIoc()->registerExport<IQAccessibleInterfaceRegister>(mname, new QAccessibleInterfaceRegister());
      51            1 :     globalIoc()->registerExport<IAccessibleAppRootObject>(mname, new AccessibleAppRootObject());
      52            1 : }
      53              : 
      54            1 : void AccessibilityModule::resolveImports()
      55              : {
      56            1 :     auto accr = globalIoc()->resolve<IQAccessibleInterfaceRegister>(mname);
      57            1 :     if (accr) {
      58            1 :         accr->registerInterfaceGetter("QQuickWindow", AccessibilityController::accessibleInterface);
      59            1 :         accr->registerInterfaceGetter("muse::accessibility::AccessibleObject", AccessibleObject::accessibleInterface);
      60            1 :         accr->registerInterfaceGetter("muse::accessibility::AccessibleAppRootObject", AccessibleAppRootObject::accessibleInterface);
      61              :     }
      62            1 : }
      63              : 
      64            0 : void AccessibilityModule::registerApi()
      65              : {
      66              :     using namespace muse::api;
      67              : 
      68            0 :     auto api = globalIoc()->resolve<IApiRegister>(mname);
      69            0 :     if (api) {
      70            0 :         api->regApiCreator(mname, "MuseInternal.Accessibility", new ApiCreator<api::AccessibilityApi>());
      71              :     }
      72            0 : }
      73              : 
      74           10 : static QAccessibleInterface* accessibleFactory(const QString& classname, QObject* object)
      75              : {
      76           10 :     auto accr = globalIoc()->resolve<IQAccessibleInterfaceRegister>("accessibility");
      77           10 :     if (accr) {
      78           10 :         auto interfaceGetter = accr->interfaceGetter(classname);
      79           10 :         if (interfaceGetter) {
      80           10 :             return interfaceGetter(object);
      81              :         }
      82           10 :     }
      83              : 
      84            0 :     return AccessibleStub::accessibleInterface(object);
      85           10 : }
      86              : 
      87            1 : void AccessibilityModule::onInit(const IApplication::RunMode&)
      88              : {
      89            1 :     QAccessible::installFactory(accessibleFactory);
      90              : 
      91            1 :     auto appRoot = globalIoc()->resolve<IAccessibleAppRootObject>(mname);
      92            1 :     if (appRoot) {
      93            1 :         appRoot->init();
      94              :     }
      95            1 : }
      96              : 
      97            0 : IContextSetup* AccessibilityModule::newContext(const muse::modularity::ContextPtr& ctx) const
      98              : {
      99            0 :     return new AccessibilityContext(ctx);
     100              : }
     101              : 
     102              : // Context
     103            0 : void AccessibilityContext::registerExports()
     104              : {
     105              :     //! FIXME AccessibilityController has a global component and a contextual component.
     106              :     // It probably needs to be split into two separate classes.
     107            0 :     m_controller = std::make_shared<AccessibilityController>(iocContext());
     108            0 :     ioc()->registerExport<IAccessibilityController>(mname, m_controller);
     109            0 : }
     110              : 
     111            0 : void AccessibilityContext::onPreInit(const IApplication::RunMode&)
     112              : {
     113            0 :     m_controller->setAccessibilityEnabled(true);
     114            0 : }
     115              : 
     116            0 : void AccessibilityContext::onDeinit()
     117              : {
     118            0 :     m_controller->deinit();
     119            0 : }
        

Generated by: LCOV version 2.0-1