6c5257b680
Changes:
* drop the optional `maxNum` param for the
constructor, it's never set to anything
different than the default value
* store negative number in member (renamed
from `max` to `m_nMin`) instead of storing
positive number and inverting that when returning
it in `ResIDGenerator::GenerateNewResID`
* Use -1 as the first resource ID instead of -2.
Also, add a comment that negative child IDs
are used because it's common to use such ones
to indicate unique resource IDs in
IAccessible2.
Quoting James Teh's comment on an NVDA
pull request of mine [1]:
> The use of negative child ids doesn't fit well into the IAccessible
> spec, but it has been done by IAccessible2 for a very long time and
> should be considered standard for all intents and purposes. A negative
> child id should be treated as a unique id, while a positive child id
> should be treated as a child index.
>
> That said, as noted in #13277 (comment), IAccessible2 elements are
> always full IAccessible objects, not "simple elements". Thus, anything
> that returns an accessible (including accSelection) really should return
> an object pointer. In the case of accSelection, this means VT_DISPATCH
> for a single selection or VT_UNKNOWN and iEnumVARIANT (with VT_DISPATCH
> elements) for multiple selection.
>
> In short, NVDA supporting negative child ids returned from accSelection
> isn't necessarily "wrong", but ideally, LibreOffice would be fixed to
> return full objects.
The latter (returning full objects) has already been addressed in
commit 00c0ee8cf0
Author: Michael Weghorn <m.weghorn@posteo.de>
Date: Mon Jan 31 07:41:14 2022 +0000
tdf#147083 wina11y: Return a11y object instead of child ID
but a unique ID is still relevant, s. e.g. the documentation
of `IAccessible2::uniqueID` [2], which also mentions potential
ways to implement unique IDs:
> One means of implementing this would be to create a factory with a 32
> bit number generator and a reuse pool. The number generator would emit
> numbers starting at 1. Each time an object's life cycle ended, its
> number would be saved into a reuse pool. The number generator would be
> used whenever the reuse pool was empty.
>
> Another way to create a unique ID is to generate it from a pointer
> value, e.g. an object's address. That would be unique because no two
> active objects can use the same allocated memory space.
The first approach is what the LO implementation currently does,
except that negative numbers are used.
[1] https://github.com/nvaccess/nvda/pull/13277#issuecomment-1024622871
[2] https://accessibility.linuxfoundation.org/a11yspecs/ia2/docs/html/interface_i_accessible2.html#aac1342376cf195a6a6e9ee3b7e30ae3b
Change-Id: I6c0a6c4a4e3a69396205fe2d69cd66af6525a273
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/131927
Tested-by: Jenkins
Reviewed-by: Michael Weghorn <m.weghorn@posteo.de>
45 lines
1.4 KiB
C++
45 lines
1.4 KiB
C++
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
|
|
/*
|
|
* This file is part of the LibreOffice project.
|
|
*
|
|
* This Source Code Form is subject to the terms of the Mozilla Public
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
|
*
|
|
* This file incorporates work covered by the following license notice:
|
|
*
|
|
* Licensed to the Apache Software Foundation (ASF) under one or more
|
|
* contributor license agreements. See the NOTICE file distributed
|
|
* with this work for additional information regarding copyright
|
|
* ownership. The ASF licenses this file to you under the Apache
|
|
* License, Version 2.0 (the "License"); you may not use this file
|
|
* except in compliance with the License. You may obtain a copy of
|
|
* the License at http://www.apache.org/licenses/LICENSE-2.0 .
|
|
*/
|
|
|
|
#pragma once
|
|
|
|
#include <deque>
|
|
|
|
//ResID i.e. MSAA child ID,
|
|
//this class is responsible for generating a child ID
|
|
//
|
|
// In IAccessible2, negative child IDs are commonly used to
|
|
// indicate unique resource IDs.
|
|
class ResIDGenerator
|
|
{
|
|
private:
|
|
long m_nMin;
|
|
std::deque<long> subList;
|
|
|
|
public:
|
|
ResIDGenerator()
|
|
: m_nMin(-1)
|
|
{
|
|
}
|
|
~ResIDGenerator();
|
|
long GenerateNewResID();
|
|
void SetSub(long number) { subList.push_back(number); };
|
|
};
|
|
|
|
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|