1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
21 #include <cppuhelper/weakref.hxx>
22 #include <rtl/ref.hxx>
23 #include <osl/mutex.hxx>
24 #include <svx/IAccessibleViewForwarder.hxx>
25 #include <svx/IAccessibleParent.hxx>
27 #include <svx/AccessibleControlShape.hxx>
28 #include <o3tl/typed_flags_set.hxx>
29 #include <unotools/weakref.hxx>
32 #include <o3tl/sorted_vector.hxx>
34 class SwAccessibleParagraph
;
39 class SwAccessibleContext
;
40 class SwAccessibleContextMap_Impl
;
41 class SwAccessibleEventList_Impl
;
42 class SwAccessibleEventMap_Impl
;
44 namespace accessibility
{ class AccessibleShape
; }
45 class SwAccessibleShapeMap_Impl
;
46 struct SwAccessibleEvent_Impl
;
47 class SwAccessibleSelectedParas_Impl
;
50 class SwAccPreviewData
;
54 namespace vcl
{ class Window
; }
55 namespace com::sun::star::accessibility
{ class XAccessible
; }
57 // The shape list is filled if an accessible shape is destroyed. It
58 // simply keeps a reference to the accessible shape's XShape. These
59 // references are destroyed within the EndAction when firing events.
60 // There are two reason for this. First of all, a new accessible shape
61 // for the XShape might be created soon. It's then cheaper if the XShape
62 // still exists. The other reason are situations where an accessible shape
63 // is destroyed within an SwFrameFormat::SwClientNotify. In this case, destroying
64 // the XShape at the same time (indirectly by destroying the accessible
65 // shape) leads to an assert, because a client of the Modify is destroyed
66 // within a Modify call.
67 using SwShapeList_Impl
= std::vector
<css::uno::Reference
<css::drawing::XShape
>>;
69 enum class AccessibleStates
72 // real states for events
75 // pseudo states for events
76 TEXT_ATTRIBUTE_CHANGED
= 0x0200,
77 TEXT_SELECTION_CHANGED
= 0x0100,
79 RELATION_FROM
= 0x0040,
84 template<> struct typed_flags
<AccessibleStates
> : is_typed_flags
<AccessibleStates
, 0x3e3> {};
87 class SwAccessibleMap final
: public ::accessibility::IAccessibleViewForwarder
,
88 public ::accessibility::IAccessibleParent
89 , public std::enable_shared_from_this
<SwAccessibleMap
>
91 ::osl::Mutex maEventMutex
;
92 std::unique_ptr
<SwAccessibleContextMap_Impl
> mpFrameMap
;
93 std::unique_ptr
<SwAccessibleShapeMap_Impl
> mpShapeMap
;
94 SwShapeList_Impl mvShapes
;
95 std::unique_ptr
<SwAccessibleEventList_Impl
> mpEvents
;
96 std::unique_ptr
<SwAccessibleEventMap_Impl
> mpEventMap
;
98 // Para Container for InvalidateCursorPosition
99 o3tl::sorted_vector
<SwAccessibleParagraph
*> m_setParaAdd
;
100 o3tl::sorted_vector
<SwAccessibleParagraph
*> m_setParaRemove
;
102 // #i27301 data structure to keep information about
103 // accessible paragraph, which have a selection.
104 std::unique_ptr
<SwAccessibleSelectedParas_Impl
> mpSelectedParas
;
106 /// for page preview: store preview data, VisArea, and mapping of
107 /// preview-to-display coordinates
108 std::unique_ptr
<SwAccPreviewData
> mpPreview
;
110 unotools::WeakReference
< SwAccessibleContext
> mxCursorContext
;
112 bool mbShapeSelected
;
114 void FireEvent( const SwAccessibleEvent_Impl
& rEvent
);
116 void AppendEvent( const SwAccessibleEvent_Impl
& rEvent
);
118 void InvalidateCursorPosition( const css::uno::Reference
<css::accessibility::XAccessible
>& rAcc
);
119 void DoInvalidateShapeSelection(bool bInvalidateFocusMode
= false);
121 void InvalidateShapeSelection();
123 //mpSelectedFrameMap contains the old selected objects.
124 std::unique_ptr
<SwAccessibleContextMap_Impl
> mpSelectedFrameMap
;
128 //InvalidateShapeInParaSelection() method is responsible for the updating the selected states of the objects.
129 void InvalidateShapeInParaSelection();
131 void InvalidateRelationSet_( const SwFrame
* pFrame
, bool bFrom
);
133 rtl::Reference
<SwAccessibleContext
> GetDocumentView_(bool bPagePreview
);
135 /** method to build up a new data structure of the accessible paragraphs,
136 which have a selection
138 Important note: method has to used inside a mutual exclusive section
140 std::unique_ptr
<SwAccessibleSelectedParas_Impl
> BuildSelectedParas();
144 SwAccessibleMap( SwViewShell
*pSh
);
145 virtual ~SwAccessibleMap() override
;
147 css::uno::Reference
<css::accessibility::XAccessible
> GetDocumentView();
149 css::uno::Reference
<css::accessibility::XAccessible
> GetDocumentPreview(
150 const std::vector
<std::unique_ptr
<PreviewPage
>>& _rPreviewPages
,
151 const Fraction
& _rScale
,
152 const SwPageFrame
* _pSelectedPageFrame
,
153 const Size
& _rPreviewWinSize
);
155 ::rtl::Reference
< SwAccessibleContext
> GetContextImpl(
156 const SwFrame
*pFrame
,
157 bool bCreate
= true );
158 css::uno::Reference
<css::accessibility::XAccessible
> GetContext(
159 const SwFrame
*pFrame
,
160 bool bCreate
= true );
162 ::rtl::Reference
< ::accessibility::AccessibleShape
> GetContextImpl(
163 const SdrObject
*pObj
,
164 SwAccessibleContext
*pParentImpl
,
165 bool bCreate
= true );
166 css::uno::Reference
<css::accessibility::XAccessible
> GetContext(
167 const SdrObject
*pObj
,
168 SwAccessibleContext
*pParentImpl
,
169 bool bCreate
= true );
171 SwViewShell
* GetShell() const
175 static bool IsInSameLevel(const SdrObject
* pObj
, const SwFEShell
* pFESh
);
176 void AddShapeContext(const SdrObject
*pObj
,
177 rtl::Reference
< ::accessibility::AccessibleShape
> const & xAccShape
);
179 void AddGroupContext(const SdrObject
*pParentObj
,
180 css::uno::Reference
< css::accessibility::XAccessible
> const & xAccParent
);
181 void RemoveGroupContext(const SdrObject
*pParentObj
);
183 const SwRect
& GetVisArea() const;
185 /** get size of a dedicated preview page
187 @param _nPreviewPageNum
188 input parameter - physical page number of page visible in the page preview
190 @return an object of class <Size>
192 Size
GetPreviewPageSize( sal_uInt16 _nPreviewPageNum
) const;
194 void RemoveContext( const SwFrame
*pFrame
);
195 void RemoveContext( const SdrObject
*pObj
);
197 // Dispose frame and its children if bRecursive is set
198 void A11yDispose( const SwFrame
* pFrame
,
199 const SdrObject
* pObj
,
200 vcl::Window
* pWindow
,
201 bool bRecursive
= false,
202 bool bCanSkipInvisible
= true );
204 void InvalidatePosOrSize( const SwFrame
* pFrame
,
205 const SdrObject
* pObj
,
206 vcl::Window
* pWindow
,
207 const SwRect
& rOldFrame
);
209 void InvalidateContent( const SwFrame
*pFrame
);
211 void InvalidateAttr( const SwTextFrame
& rTextFrame
);
213 void InvalidateCursorPosition( const SwFrame
*pFrame
);
214 void InvalidateFocus();
215 void SetCursorContext(
216 const ::rtl::Reference
< SwAccessibleContext
>& rCursorContext
);
218 // Invalidate state of whole tree. If an action is open, this call
219 // is processed when the last action ends.
220 void InvalidateEditableStates( const SwFrame
* _pFrame
);
222 void InvalidateRelationSet( const SwFrame
* pMaster
, const SwFrame
* pFollow
);
224 /** invalidation CONTENT_FLOWS_FROM/_TO relation of a paragraph
227 input parameter - reference to paragraph, whose CONTENT_FLOWS_FROM/_TO
228 has to be invalidated.
231 input parameter - boolean indicating, if relation CONTENT_FLOWS_FROM
232 (value <true>) or CONTENT_FLOWS_TO (value <false>) has to be invalidated.
234 void InvalidateParaFlowRelation( const SwTextFrame
& _rTextFrame
,
237 /** invalidation of text selection of a paragraph */
238 void InvalidateParaTextSelection( const SwTextFrame
& _rTextFrame
);
240 /** invalidation of text selection of all paragraphs */
241 void InvalidateTextSelectionOfAllParas();
243 sal_Int32
GetChildIndex( const SwFrame
& rParentFrame
,
244 vcl::Window
& rChild
) const;
246 // update preview data (and fire events if necessary)
247 void UpdatePreview( const std::vector
<std::unique_ptr
<PreviewPage
>>& _rPreviewPages
,
248 const Fraction
& _rScale
,
249 const SwPageFrame
* _pSelectedPageFrame
,
250 const Size
& _rPreviewWinSize
);
252 void InvalidatePreviewSelection( sal_uInt16 nSelPage
);
253 bool IsPageSelected( const SwPageFrame
*pPageFrame
) const;
257 const OUString
& GetDocName() const { return maDocName
; }
259 // IAccessibleViewForwarder
261 virtual tools::Rectangle
GetVisibleArea() const override
;
262 virtual Point
LogicToPixel (const Point
& rPoint
) const override
;
263 virtual Size
LogicToPixel (const Size
& rSize
) const override
;
266 virtual bool ReplaceChild (
267 ::accessibility::AccessibleShape
* pCurrentChild
,
268 const css::uno::Reference
< css::drawing::XShape
>& _rxShape
,
269 const tools::Long _nIndex
,
270 const ::accessibility::AccessibleShapeTreeInfo
& _rShapeTreeInfo
272 virtual ::accessibility::AccessibleControlShape
* GetAccControlShapeFromModel
273 (css::beans::XPropertySet
* pSet
) override
;
274 virtual css::uno::Reference
< css::accessibility::XAccessible
> GetAccessibleCaption (
275 const css::uno::Reference
< css::drawing::XShape
> & xShape
) override
;
277 // additional Core/Pixel conversions for internal use; also works
279 Point
PixelToCore (const Point
& rPoint
) const;
280 tools::Rectangle
CoreToPixel (const SwRect
& rRect
) const;
282 // is there a known accessibility impl cached for the frame
283 bool Contains(const SwFrame
*pFrame
) const;
286 /** get mapping mode for LogicToPixel and PixelToLogic conversions
288 Replacement method <PreviewAdjust(..)> by new method <GetMapMode>.
289 Method returns mapping mode of current output device and adjusts it,
290 if the shell is in page/print preview.
291 Necessary, because <PreviewAdjust(..)> changes mapping mode at current
292 output device for mapping logic document positions to page preview window
293 positions and vice versa and doesn't take care to recover its changes.
296 input parameter - constant reference to point to determine the mapping
297 mode adjustments for page/print preview.
299 @return mapping mode, which is determined by the method
301 MapMode
GetMapMode(const Point
& _rPoint
) const;
303 virtual bool IsDocumentSelAll() override
;
306 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */