1/*
2 * Copyright (C) 2013 Apple Inc. All Rights Reserved.
3 *
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions
6 * are met:
7 * 1. Redistributions of source code must retain the above copyright
8 *    notice, this list of conditions and the following disclaimer.
9 * 2. Redistributions in binary form must reproduce the above copyright
10 *    notice, this list of conditions and the following disclaimer in the
11 *    documentation and/or other materials provided with the distribution.
12 *
13 * THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY
14 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
15 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
16 * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL APPLE INC. OR
17 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
18 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
19 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
20 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
21 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
22 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
23 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
24 */
25
26#ifndef AccessibleTextImpl_h
27#define AccessibleTextImpl_h
28
29#include "AccessibleBase.h"
30#include <WebCore/VisiblePosition.h>
31
32class AccessibleText : public AccessibleBase, public IAccessibleText2, public IAccessibleEditableText {
33public:
34    AccessibleText(WebCore::AccessibilityObject*, HWND);
35    virtual ~AccessibleText() { }
36
37    // IAccessibleText
38    virtual HRESULT STDMETHODCALLTYPE addSelection(long startOffset, long endOffset);
39    virtual HRESULT STDMETHODCALLTYPE get_attributes(long offset, long* startOffset, long* endOffset, BSTR* textAttributes);
40    virtual HRESULT STDMETHODCALLTYPE get_caretOffset(long* offset);
41    virtual HRESULT STDMETHODCALLTYPE get_characterExtents(long offset, enum IA2CoordinateType coordType, long* x, long* y, long* width, long* height);
42    virtual HRESULT STDMETHODCALLTYPE get_nSelections(long* nSelections);
43    virtual HRESULT STDMETHODCALLTYPE get_offsetAtPoint(long x, long y, enum IA2CoordinateType coordType, long* offset);
44    virtual HRESULT STDMETHODCALLTYPE get_selection(long selectionIndex, long* startOffset, long* endOffset);
45    virtual HRESULT STDMETHODCALLTYPE get_text(long startOffset, long endOffset, BSTR* text);
46    virtual HRESULT STDMETHODCALLTYPE get_textBeforeOffset(long offset, enum IA2TextBoundaryType boundaryType, long* startOffset, long* endOffset, BSTR* text);
47    virtual HRESULT STDMETHODCALLTYPE get_textAfterOffset(long offset, enum IA2TextBoundaryType boundaryType, long* startOffset, long* endOffset, BSTR* text);
48    virtual HRESULT STDMETHODCALLTYPE get_textAtOffset(long offset, enum IA2TextBoundaryType boundaryType, long* startOffset, long* endOffset, BSTR* text);
49    virtual HRESULT STDMETHODCALLTYPE removeSelection(long selectionIndex);
50    virtual HRESULT STDMETHODCALLTYPE setCaretOffset(long offset);
51    virtual HRESULT STDMETHODCALLTYPE setSelection(long selectionIndex, long startOffset, long endOffset);
52    virtual HRESULT STDMETHODCALLTYPE get_nCharacters(long* characters);
53    virtual HRESULT STDMETHODCALLTYPE scrollSubstringTo(long startIndex, long endIndex, enum IA2ScrollType scrollType);
54    virtual HRESULT STDMETHODCALLTYPE scrollSubstringToPoint(long startIndex, long endIndex, enum IA2CoordinateType coordinateType, long x, long y);
55    virtual HRESULT STDMETHODCALLTYPE get_newText(IA2TextSegment* newText);
56    virtual HRESULT STDMETHODCALLTYPE get_oldText(IA2TextSegment* oldText);
57
58    // IAccessibleText2
59    virtual HRESULT STDMETHODCALLTYPE get_attributeRange(long offset, BSTR filter, long* startOffset, long* endOffset, BSTR* attributeValues);
60
61    // IAccessibleEditableText
62    virtual HRESULT STDMETHODCALLTYPE copyText(long startOffset, long endOffset);
63    virtual HRESULT STDMETHODCALLTYPE deleteText(long startOffset, long endOffset);
64    virtual HRESULT STDMETHODCALLTYPE insertText(long offset, BSTR* text);
65    virtual HRESULT STDMETHODCALLTYPE cutText(long startOffset, long endOffset);
66    virtual HRESULT STDMETHODCALLTYPE pasteText(long offset);
67    virtual HRESULT STDMETHODCALLTYPE replaceText(long startOffset, long endOffset, BSTR* text);
68    virtual HRESULT STDMETHODCALLTYPE setAttributes(long startOffset, long endOffset, BSTR* attributes);
69
70    // IUnknown
71    virtual HRESULT STDMETHODCALLTYPE QueryInterface(REFIID riid, void** ppvObject);
72    virtual ULONG STDMETHODCALLTYPE AddRef(void) { return ++m_refCount; }
73    virtual ULONG STDMETHODCALLTYPE Release(void);
74
75    // IAccessibleBase
76    virtual HRESULT STDMETHODCALLTYPE get_attributes(BSTR* attributes);
77
78private:
79    int convertSpecialOffset(int specialOffset);
80    HRESULT initialCheck();
81    bool isInRange(WebCore::VisiblePosition& current, WebCore::VisiblePositionRange& wordRange);
82};
83
84#endif // AccessibleText_h
85