[Libreoffice-commits] core.git: sc/source

Caolán McNamara (via logerrit) logerrit at kemper.freedesktop.org
Tue Apr 9 07:57:05 UTC 2019


 sc/source/ui/Accessibility/AccessibleEditObject.cxx |  107 +++++++++++++++++---
 sc/source/ui/inc/AccessibleContextBase.hxx          |    2 
 sc/source/ui/inc/AccessibleEditObject.hxx           |   38 +++++++
 sc/source/ui/pagedlg/tphfedit.cxx                   |   44 +++-----
 4 files changed, 152 insertions(+), 39 deletions(-)

New commits:
commit 5bd1caf14c8e297db229e9060a584386247e62b1
Author:     Caolán McNamara <caolanm at redhat.com>
AuthorDate: Mon Apr 8 17:13:26 2019 +0100
Commit:     Caolán McNamara <caolanm at redhat.com>
CommitDate: Tue Apr 9 09:56:37 2019 +0200

    restore ScEditWindow a11y
    
    Change-Id: I425cdf3d868b37a4975f502f3cade4298f3a948a
    Reviewed-on: https://gerrit.libreoffice.org/70428
    Tested-by: Jenkins
    Reviewed-by: Caolán McNamara <caolanm at redhat.com>
    Tested-by: Caolán McNamara <caolanm at redhat.com>

diff --git a/sc/source/ui/Accessibility/AccessibleEditObject.cxx b/sc/source/ui/Accessibility/AccessibleEditObject.cxx
index 1b08297580b9..dc32e50924a0 100644
--- a/sc/source/ui/Accessibility/AccessibleEditObject.cxx
+++ b/sc/source/ui/Accessibility/AccessibleEditObject.cxx
@@ -60,13 +60,35 @@ ScAccessibleEditObject::ScAccessibleEditObject(
         const uno::Reference<XAccessible>& rxParent,
         EditView* pEditView, vcl::Window* pWin, const OUString& rName,
         const OUString& rDescription, EditObjectType eObjectType)
-    :
-    ScAccessibleContextBase(rxParent, AccessibleRole::TEXT_FRAME),
-    mpEditView(pEditView),
-    mpWindow(pWin),
-    meObjectType(eObjectType),
-    mbHasFocus(false)
+    : ScAccessibleContextBase(rxParent, AccessibleRole::TEXT_FRAME)
+    , mpEditView(pEditView)
+    , mpWindow(pWin)
+    , meObjectType(eObjectType)
+    , mbHasFocus(false)
+    , m_pScDoc(nullptr)
 {
+    InitAcc(rxParent, pEditView, pWin, rName, rDescription);
+}
+
+ScAccessibleEditObject::ScAccessibleEditObject(EditObjectType eObjectType)
+    : ScAccessibleContextBase(nullptr, AccessibleRole::TEXT_FRAME)
+    , mpEditView(nullptr)
+    , mpWindow(nullptr)
+    , meObjectType(eObjectType)
+    , mbHasFocus(false)
+    , m_pScDoc(nullptr)
+{
+}
+
+void ScAccessibleEditObject::InitAcc(
+        const uno::Reference<XAccessible>& rxParent,
+        EditView* pEditView, vcl::Window* pWin, const OUString& rName,
+        const OUString& rDescription)
+{
+    SetParent(rxParent);
+    mpEditView = pEditView;
+    mpWindow = pWin;
+
     CreateTextHelper();
     SetName(rName);
     SetDescription(rDescription);
@@ -78,13 +100,7 @@ ScAccessibleEditObject::ScAccessibleEditObject(
             m_pScDoc = pAccDoc->GetDocument();
             m_curCellAddress =pAccDoc->GetCurCellAddress();
         }
-        else
-        {
-            m_pScDoc=nullptr;
-        }
     }
-    else
-        m_pScDoc=nullptr;
 }
 
 ScAccessibleEditObject::~ScAccessibleEditObject()
@@ -331,6 +347,11 @@ bool ScAccessibleEditObject::IsDefunc(
          (rxParentStates.is() && rxParentStates->contains(AccessibleStateType::DEFUNC));
 }
 
+OutputDevice* ScAccessibleEditObject::GetOutputDeviceForView()
+{
+    return mpWindow;
+}
+
 void ScAccessibleEditObject::CreateTextHelper()
 {
     if (!mpTextHelper)
@@ -339,12 +360,12 @@ void ScAccessibleEditObject::CreateTextHelper()
         if (meObjectType == CellInEditMode || meObjectType == EditControl)
         {
             pAccessibleTextData.reset
-                (new ScAccessibleEditObjectTextData(mpEditView, mpWindow));
+                (new ScAccessibleEditObjectTextData(mpEditView, GetOutputDeviceForView()));
         }
         else
         {
             pAccessibleTextData.reset
-                (new ScAccessibleEditLineTextData(nullptr, mpWindow));
+                (new ScAccessibleEditLineTextData(nullptr, GetOutputDeviceForView()));
         }
 
         std::unique_ptr<ScAccessibilityEditSource> pEditSrc =
@@ -512,4 +533,62 @@ uno::Reference< XAccessibleRelationSet > ScAccessibleEditObject::getAccessibleRe
     return uno::Reference< XAccessibleRelationSet >();
 }
 
+tools::Rectangle ScAccessibleEditControlObject::GetBoundingBoxOnScreen() const
+{
+    tools::Rectangle aScreenBounds;
+
+    if (m_pController && m_pController->GetDrawingArea())
+    {
+        aScreenBounds = tools::Rectangle(m_pController->GetDrawingArea()->get_accessible_location(),
+                                         m_pController->GetOutputSizePixel());
+    }
+
+    return aScreenBounds;
+}
+
+tools::Rectangle ScAccessibleEditControlObject::GetBoundingBox() const
+{
+    tools::Rectangle aBounds( GetBoundingBoxOnScreen() );
+
+    uno::Reference< XAccessibleContext > xContext(const_cast<ScAccessibleEditControlObject*>(this)->getAccessibleContext());
+    if ( xContext.is() )
+    {
+        uno::Reference< XAccessible > xParent( xContext->getAccessibleParent() );
+        if ( xParent.is() )
+        {
+            uno::Reference< XAccessibleComponent > xParentComponent( xParent->getAccessibleContext(), uno::UNO_QUERY );
+            if ( xParentComponent.is() )
+            {
+                Point aScreenLoc = aBounds.TopLeft();
+                awt::Point aParentScreenLoc = xParentComponent->getLocationOnScreen();
+                Point aPos( aScreenLoc.getX() - aParentScreenLoc.X, aScreenLoc.getY() - aParentScreenLoc.Y );
+                aBounds.SetPos( aPos );
+            }
+        }
+    }
+
+    return aBounds;
+}
+
+void SAL_CALL ScAccessibleEditControlObject::disposing()
+{
+    ScAccessibleEditObject::disposing();
+    m_pController = nullptr;
+}
+
+uno::Reference< XAccessibleRelationSet > ScAccessibleEditControlObject::getAccessibleRelationSet()
+{
+    SolarMutexGuard aGuard;
+    if (!m_pController || !m_pController->GetDrawingArea())
+        return uno::Reference< XAccessibleRelationSet >();
+    return m_pController->GetDrawingArea()->get_accessible_relation_set();
+}
+
+OutputDevice* ScAccessibleEditControlObject::GetOutputDeviceForView()
+{
+    if (!m_pController || !m_pController->GetDrawingArea())
+        return nullptr;
+    return &m_pController->GetDrawingArea()->get_ref_device();
+}
+
 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/sc/source/ui/inc/AccessibleContextBase.hxx b/sc/source/ui/inc/AccessibleContextBase.hxx
index 8451169a8f70..ec2f5dae1feb 100644
--- a/sc/source/ui/inc/AccessibleContextBase.hxx
+++ b/sc/source/ui/inc/AccessibleContextBase.hxx
@@ -247,6 +247,8 @@ public:
     /// Use this method to set initial Description without notification
     void SetDescription(const OUString& rDesc) { msDescription = rDesc; }
 
+    void SetParent(const css::uno::Reference<css::accessibility::XAccessible>& rParent) { mxParent = rParent; }
+
 protected:
     /// Calls all FocusListener to tell they that the focus is gained.
     void CommitFocusGained() const;
diff --git a/sc/source/ui/inc/AccessibleEditObject.hxx b/sc/source/ui/inc/AccessibleEditObject.hxx
index 9a029e8cabf6..ebbd8c62a3a4 100644
--- a/sc/source/ui/inc/AccessibleEditObject.hxx
+++ b/sc/source/ui/inc/AccessibleEditObject.hxx
@@ -25,6 +25,7 @@
 #include <com/sun/star/accessibility/XAccessibleSelection.hpp>
 #include <address.hxx>
 #include <vcl/vclptr.hxx>
+#include <vcl/customweld.hxx>
 
 #include <memory>
 
@@ -56,9 +57,16 @@ public:
         EditView* pEditView, vcl::Window* pWin, const OUString& rName,
         const OUString& rDescription, EditObjectType eObjectType);
 
+    void InitAcc(
+        const css::uno::Reference<css::accessibility::XAccessible>& rxParent,
+        EditView* pEditView, vcl::Window* pWin, const OUString& rName,
+        const OUString& rDescription);
+
 protected:
     virtual ~ScAccessibleEditObject() override;
 
+    ScAccessibleEditObject(EditObjectType eObjectType);
+
     using ScAccessibleContextBase::IsDefunc;
 
 public:
@@ -83,6 +91,8 @@ public:
         SAL_CALL getAccessibleAtPoint(
         const css::awt::Point& rPoint ) override;
 
+    virtual OutputDevice* GetOutputDeviceForView();
+
 protected:
     /// Return the object's current bounding box relative to the desktop.
     virtual tools::Rectangle GetBoundingBoxOnScreen() const override;
@@ -182,6 +192,34 @@ private:
     sal_Int32 GetFgBgColor(  const OUString &strPropColor) ;
 };
 
+class ScAccessibleEditControlObject : public ScAccessibleEditObject
+{
+private:
+    weld::CustomWidgetController* m_pController;
+
+protected:
+    /// Return the object's current bounding box relative to the desktop.
+    virtual tools::Rectangle GetBoundingBoxOnScreen() const override;
+
+    /// Return the object's current bounding box relative to the parent object.
+    virtual tools::Rectangle GetBoundingBox() const override;
+
+public:
+    ScAccessibleEditControlObject(weld::CustomWidgetController* pController)
+        : ScAccessibleEditObject(ScAccessibleEditObject::EditControl)
+        , m_pController(pController)
+    {
+    }
+
+    virtual css::uno::Reference< css::accessibility::XAccessibleRelationSet > SAL_CALL getAccessibleRelationSet(  ) override;
+
+    // for mapping positions/sizes within the TextView to a11y
+    virtual OutputDevice* GetOutputDeviceForView() override;
+
+    using ScAccessibleContextBase::disposing;
+    virtual void SAL_CALL disposing() override;
+};
+
 #endif
 
 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/sc/source/ui/pagedlg/tphfedit.cxx b/sc/source/ui/pagedlg/tphfedit.cxx
index ca845a16d53d..c1554f4857bf 100644
--- a/sc/source/ui/pagedlg/tphfedit.cxx
+++ b/sc/source/ui/pagedlg/tphfedit.cxx
@@ -112,7 +112,24 @@ void ScEditWindow::SetDrawingArea(weld::DrawingArea* pDrawingArea)
     pDrawingArea->set_text_cursor();
 
     if (pAcc)
-        pAcc->SetDescription(pDrawingArea->get_tooltip_text());
+    {
+        OUString sName;
+        switch (eLocation)
+        {
+            case Left:
+                sName = ScResId(STR_ACC_LEFTAREA_NAME);
+                break;
+            case Center:
+                sName = ScResId(STR_ACC_CENTERAREA_NAME);
+                break;
+            case Right:
+                sName = ScResId(STR_ACC_RIGHTAREA_NAME);
+                break;
+        }
+
+        pAcc->InitAcc(nullptr, pEdView.get(), nullptr,
+                      sName, pDrawingArea->get_tooltip_text());
+    }
 }
 
 void ScEditWindow::Resize()
@@ -330,32 +347,9 @@ void ScEditWindow::LoseFocus()
 
 css::uno::Reference< css::accessibility::XAccessible > ScEditWindow::CreateAccessible()
 {
-    OUString sName;
-    switch (eLocation)
-    {
-    case Left:
-        {
-            sName = ScResId(STR_ACC_LEFTAREA_NAME);
-        }
-        break;
-    case Center:
-        {
-            sName = ScResId(STR_ACC_CENTERAREA_NAME);
-        }
-        break;
-    case Right:
-        {
-            sName = ScResId(STR_ACC_RIGHTAREA_NAME);
-        }
-        break;
-    }
-#if 0
-    //TODO
-    pAcc = new ScAccessibleEditObject(GetAccessibleParentWindow()->GetAccessible(), pEdView.get(), this,
-        sName, OUString(), ScAccessibleEditObject::EditControl);
+    pAcc = new ScAccessibleEditControlObject(this);
     css::uno::Reference< css::accessibility::XAccessible > xAccessible = pAcc;
     xAcc = xAccessible;
-#endif
     return pAcc;
 }
 


More information about the Libreoffice-commits mailing list