toolkit/source/controls/svtxgridcontrol.cxx |    4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

New commits:
commit 1cc254f10bc39eb605ab442cdfac35ad41a0ebb4
Author:     Michael Weghorn <m.wegh...@posteo.de>
AuthorDate: Thu Jan 23 14:37:07 2025 +0100
Commit:     Caolán McNamara <caolan.mcnam...@collabora.com>
CommitDate: Fri Jan 24 11:40:58 2025 +0100

    tdf#164783 toolkit a11y: Only send event for current cell if there's one
    
    TableControl::commitCellEventIfAccessibleAlive sends an event
    on the currently selected/active cell. So only call it in
    SVTXGridControl::ProcessWindowEvent when there is one.
    
    Use TableControl::GetCurrentRow and TableControl::GetCurrentColumn
    to check that, which return a special value (of -2) for the case there
    is no active cell.
    
    For TableControl::GetCurrentRow:
    
            /** retrieves the current row
    
                The current row is the one which contains the active cell.
    
                @return
                    the row index of the active cell, or ->ROW_INVALID
                    if there is no active cell, e.g. because the table does
                    not contain any rows or columns.
            */
            sal_Int32 GetCurrentRow() const override;
    
    The previous check whether the table has any rows was insufficient
    and resulted in an invalid attempt to access vector elements at
    negative indices.
    
    For the tdf#164783 scenario:
    
        
/usr/lib/gcc/x86_64-linux-gnu/14/../../../../include/c++/14/debug/vector:508:
        In function:
            reference
            
std::vector<rtl::Reference<accessibility::AccessibleGridControlTableCell>>::operator[](size_type)
            [_Tp = 
rtl::Reference<accessibility::AccessibleGridControlTableCell>,
            _Allocator =
            
std::allocator<rtl::Reference<accessibility::AccessibleGridControlTableCell>>]
    
        Error: attempt to subscript container with out-of-bounds index -6, but
        container only holds 60 elements.
    
        Objects involved in the operation:
            sequence "this" @ 0x5638c74e2350 {
              type = 
std::debug::vector<rtl::Reference<accessibility::AccessibleGridControlTableCell>,
 std::allocator<rtl::Reference<accessibility::AccessibleGridControlTableCell> > 
>;
            }
        
/usr/lib/gcc/x86_64-linux-gnu/14/../../../../include/c++/14/debug/vector:508:
        In function:
            reference
            
std::vector<rtl::Reference<accessibility::AccessibleGridControlTableCell>>::operator[](size_type)
            [_Tp = 
rtl::Reference<accessibility::AccessibleGridControlTableCell>,
            _Allocator =
            
std::allocator<rtl::Reference<accessibility::AccessibleGridControlTableCell>>]
    
        Error: attempt to subscript container with out-of-bounds index -6, but
        container only holds 60 elements.
    
        Objects involved in the operation:
            sequence "this" @ 0x5638c74e2350 {
              type = 
std::debug::vector<rtl::Reference<accessibility::AccessibleGridControlTableCell>,
 std::allocator<rtl::Reference<accessibility::AccessibleGridControlTableCell> > 
>;
            }
            sequence "this" @ 0x5638c74e2350 {
              type = 
std::debug::vector<rtl::Reference<accessibility::AccessibleGridControlTableCell>,
 std::allocator<rtl::Reference<accessibility::AccessibleGridControlTableCell> > 
>;
            }
    
        Fatal exception: Signal 6
        Stack:
        #0 sal::backtrace_get(unsigned int) at 
.../libreoffice/sal/osl/unx/backtraceapi.cxx:42
        #1 (anonymous namespace)::printStack(int) at 
.../libreoffice/sal/osl/unx/signal.cxx:289
        #2 (anonymous namespace)::callSystemHandler(int, siginfo_t*, void*) at 
.../libreoffice/sal/osl/unx/signal.cxx:330
        #3 (anonymous namespace)::signalHandlerFunction(int, siginfo_t*, void*) 
at .../libreoffice/sal/osl/unx/signal.cxx:427
        #4 /lib/x86_64-linux-gnu/libc.so.6(+0x3fda0) [0x7f7544649da0]
        #5 __pthread_kill_implementation at ./nptl/pthread_kill.c:44 
(discriminator 1)
        #6 raise at ./signal/../sysdeps/posix/raise.c:27
        #7 abort at ./stdlib/abort.c:81
        #8 std::__throw_bad_exception() in /lib/x86_64-linux-gnu/libstdc++.so.6
        #9 
std::__debug::vector<rtl::Reference<accessibility::AccessibleGridControlTableCell>,
 
std::allocator<rtl::Reference<accessibility::AccessibleGridControlTableCell>>>::operator[](unsigned
 long) at 
/usr/lib/gcc/x86_64-linux-gnu/14/../../../../include/c++/14/debug/vector:508
        #10 accessibility::AccessibleGridControlTable::getAccessibleChild(long) 
at .../libreoffice/vcl/source/accessibility/AccessibleGridControlTable.cxx:66
        #11 accessibility::AccessibleGridControlTable::getAccessibleCellAt(int, 
int) at 
.../libreoffice/vcl/source/accessibility/AccessibleGridControlTable.cxx:191
        #12 accessibility::AccessibleGridControl::commitCellEvent(short, 
com::sun::star::uno::Any const&, com::sun::star::uno::Any const&) at 
.../libreoffice/vcl/source/accessibility/AccessibleGridControl.cxx:272
        #13 accessibility::AccessibleGridControlAccess::commitCellEvent(short, 
com::sun::star::uno::Any const&, com::sun::star::uno::Any const&) at 
.../libreoffice/vcl/inc/accessibility/AccessibleGridControl.hxx:197
        #14 svt::table::TableControl_Impl::commitCellEvent(short, 
com::sun::star::uno::Any const&, com::sun::star::uno::Any const&) at 
.../libreoffice/toolkit/source/controls/table/tablecontrol_impl.cxx:2304
        #15 svt::table::TableControl::commitCellEventIfAccessibleAlive(short, 
com::sun::star::uno::Any const&, com::sun::star::uno::Any const&) at 
.../libreoffice/toolkit/source/controls/table/tablecontrol.cxx:470
        #16 SVTXGridControl::ProcessWindowEvent(VclWindowEvent const&) at 
.../libreoffice/toolkit/source/controls/svtxgridcontrol.cxx:823
        #17 VCLXWindow::WindowEventListener(VclWindowEvent&) at 
.../libreoffice/toolkit/source/awt/vclxwindow.cxx:390
        #18 VCLXWindow::LinkStubWindowEventListener(void*, VclWindowEvent&) at 
.../libreoffice/toolkit/source/awt/vclxwindow.cxx:383
        #19 Link<VclWindowEvent&, void>::Call(VclWindowEvent&) const at 
.../libreoffice/include/tools/link.hxx:101
        #20 vcl::Window::CallEventListeners(VclEventId, void*) at 
.../libreoffice/vcl/source/window/event.cxx:262
        #21 Control::CallEventListeners(VclEventId, void*) at 
.../libreoffice/vcl/source/control/ctrl.cxx:298
        #22 Control::ImplCallEventListenersAndHandler(VclEventId, 
std::function<void ()> const&) at 
.../libreoffice/vcl/source/control/ctrl.cxx:305
        #23 Control::EventNotify(NotifyEvent&) at 
.../libreoffice/vcl/source/control/ctrl.cxx:247
        #24 vcl::Window::CompatNotify(NotifyEvent&) at 
.../libreoffice/vcl/source/window/window.cxx:3943
        #25 vcl::Window::LoseFocus() at 
.../libreoffice/vcl/source/window/window.cxx:1861
        #26 svt::table::TableControl::LoseFocus() at 
.../libreoffice/toolkit/source/controls/table/tablecontrol.cxx:94
        #27 vcl::Window::CompatLoseFocus() at 
.../libreoffice/vcl/source/window/window.cxx:3912
        #28 vcl::Window::ImplAsyncFocusHdl(void*) at 
.../libreoffice/vcl/source/window/winproc.cxx:2127
        #29 vcl::Window::LinkStubImplAsyncFocusHdl(void*, void*) at 
.../libreoffice/vcl/source/window/winproc.cxx:2033
        #30 Link<void*, void>::Call(void*) const at 
.../libreoffice/include/tools/link.hxx:101
        #31 ImplHandleUserEvent(ImplSVEvent*) at 
.../libreoffice/vcl/source/window/winproc.cxx:2288
        #32 ImplWindowFrameProc(vcl::Window*, SalEvent, void const*) at 
.../libreoffice/vcl/source/window/winproc.cxx:2849
        #33 SalFrame::CallCallback(SalEvent, void const*) const at 
.../libreoffice/vcl/inc/salframe.hxx:311
        #34 SalGenericDisplay::ProcessEvent(SalUserEventList::SalUserEvent) at 
.../libreoffice/vcl/unx/generic/app/gendisp.cxx:67
        #35 SalUserEventList::DispatchUserEvents(bool)::$_0::operator()() const 
at .../libreoffice/vcl/source/app/salusereventlist.cxx:119
        #36 SalUserEventList::DispatchUserEvents(bool) at 
.../libreoffice/vcl/source/app/salusereventlist.cxx:120
        #37 SalGenericDisplay::DispatchInternalEvent(bool) at 
.../libreoffice/vcl/unx/generic/app/gendisp.cxx:51
        #38 call_userEventFn(void*) at 
.../libreoffice/vcl/unx/gtk3/gtkdata.cxx:827
        #39 /lib/x86_64-linux-gnu/libglib-2.0.so.0(+0x5a81f) [0x7f7536f0b81f]
        #40 /lib/x86_64-linux-gnu/libglib-2.0.so.0(+0x5ca57) [0x7f7536f0da57]
        #41 g_main_loop_run in /lib/x86_64-linux-gnu/libglib-2.0.so.0
        ...
    
    Change-Id: Iafed90e6985cf2c05d65be5f74334f58b369d945
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/180661
    Tested-by: Jenkins
    Reviewed-by: Michael Weghorn <m.wegh...@posteo.de>
    (cherry picked from commit 57906dde339a71eee87437ae2d11c7474c03befd)
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/180681
    Reviewed-by: Caolán McNamara <caolan.mcnam...@collabora.com>

diff --git a/toolkit/source/controls/svtxgridcontrol.cxx 
b/toolkit/source/controls/svtxgridcontrol.cxx
index 0f2c3f6c1cb5..061259c5de22 100644
--- a/toolkit/source/controls/svtxgridcontrol.cxx
+++ b/toolkit/source/controls/svtxgridcontrol.cxx
@@ -791,7 +791,7 @@ void SVTXGridControl::ProcessWindowEvent( const 
VclWindowEvent& rVclWindowEvent
         {
             // TODO: this doesn't belong here. It belongs into the 
TableControl/_Impl, so A11Y also
             // works when the control is used outside the UNO context
-            if ( pTable->GetRowCount()>0 )
+            if (pTable->GetCurrentRow() !=  ROW_INVALID && 
pTable->GetCurrentColumn() != COL_INVALID)
             {
                 pTable->commitCellEventIfAccessibleAlive(
                     AccessibleEventId::STATE_CHANGED,
@@ -819,7 +819,7 @@ void SVTXGridControl::ProcessWindowEvent( const 
VclWindowEvent& rVclWindowEvent
         {
             // TODO: this doesn't belong here. It belongs into the 
TableControl/_Impl, so A11Y also
             // works when the control is used outside the UNO context
-            if ( pTable->GetRowCount()>0 )
+            if (pTable->GetCurrentRow() !=  ROW_INVALID && 
pTable->GetCurrentColumn() != COL_INVALID)
             {
                 pTable->commitCellEventIfAccessibleAlive(
                     AccessibleEventId::STATE_CHANGED,

Reply via email to