diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-07 19:33:14 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-07 19:33:14 +0000 |
commit | 36d22d82aa202bb199967e9512281e9a53db42c9 (patch) | |
tree | 105e8c98ddea1c1e4784a60a5a6410fa416be2de /accessible/generic/ApplicationAccessible.cpp | |
parent | Initial commit. (diff) | |
download | firefox-esr-36d22d82aa202bb199967e9512281e9a53db42c9.tar.xz firefox-esr-36d22d82aa202bb199967e9512281e9a53db42c9.zip |
Adding upstream version 115.7.0esr.upstream/115.7.0esrupstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'accessible/generic/ApplicationAccessible.cpp')
-rw-r--r-- | accessible/generic/ApplicationAccessible.cpp | 144 |
1 files changed, 144 insertions, 0 deletions
diff --git a/accessible/generic/ApplicationAccessible.cpp b/accessible/generic/ApplicationAccessible.cpp new file mode 100644 index 0000000000..8e3baa29e5 --- /dev/null +++ b/accessible/generic/ApplicationAccessible.cpp @@ -0,0 +1,144 @@ +/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ +/* vim:expandtab:shiftwidth=2:tabstop=2: + */ +/* 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/. */ + +#include "ApplicationAccessible.h" + +#include "AccAttributes.h" +#include "LocalAccessible-inl.h" +#include "nsAccessibilityService.h" +#include "nsAccUtils.h" +#include "Relation.h" +#include "Role.h" +#include "States.h" + +#include "nsServiceManagerUtils.h" +#include "mozilla/dom/Document.h" +#include "mozilla/Components.h" +#include "nsGlobalWindow.h" +#include "nsIStringBundle.h" + +using namespace mozilla::a11y; + +ApplicationAccessible::ApplicationAccessible() + : AccessibleWrap(nullptr, nullptr) { + mType = eApplicationType; + mAppInfo = do_GetService("@mozilla.org/xre/app-info;1"); + MOZ_ASSERT(mAppInfo, "no application info"); +} + +//////////////////////////////////////////////////////////////////////////////// +// nsIAccessible + +ENameValueFlag ApplicationAccessible::Name(nsString& aName) const { + aName.Truncate(); + + nsCOMPtr<nsIStringBundleService> bundleService = + mozilla::components::StringBundle::Service(); + + NS_ASSERTION(bundleService, "String bundle service must be present!"); + if (!bundleService) return eNameOK; + + nsCOMPtr<nsIStringBundle> bundle; + nsresult rv = bundleService->CreateBundle( + "chrome://branding/locale/brand.properties", getter_AddRefs(bundle)); + if (NS_FAILED(rv)) return eNameOK; + + nsAutoString appName; + rv = bundle->GetStringFromName("brandShortName", appName); + if (NS_FAILED(rv) || appName.IsEmpty()) { + NS_WARNING("brandShortName not found, using default app name"); + appName.AssignLiteral("Gecko based application"); + } + + aName.Assign(appName); + return eNameOK; +} + +void ApplicationAccessible::Description(nsString& aDescription) const { + aDescription.Truncate(); +} + +void ApplicationAccessible::Value(nsString& aValue) const { aValue.Truncate(); } + +uint64_t ApplicationAccessible::State() { + return IsDefunct() ? states::DEFUNCT : 0; +} + +already_AddRefed<AccAttributes> ApplicationAccessible::NativeAttributes() { + RefPtr<AccAttributes> attributes = new AccAttributes(); + return attributes.forget(); +} + +GroupPos ApplicationAccessible::GroupPosition() { return GroupPos(); } + +LocalAccessible* ApplicationAccessible::LocalChildAtPoint( + int32_t aX, int32_t aY, EWhichChildAtPoint aWhichChild) { + return nullptr; +} + +Accessible* ApplicationAccessible::FocusedChild() { + LocalAccessible* focus = FocusMgr()->FocusedLocalAccessible(); + if (focus && focus->LocalParent() == this) { + return focus; + } + + return nullptr; +} + +Relation ApplicationAccessible::RelationByType( + RelationType aRelationType) const { + return Relation(); +} + +mozilla::LayoutDeviceIntRect ApplicationAccessible::Bounds() const { + return mozilla::LayoutDeviceIntRect(); +} + +nsRect ApplicationAccessible::BoundsInAppUnits() const { return nsRect(); } + +//////////////////////////////////////////////////////////////////////////////// +// LocalAccessible public methods + +void ApplicationAccessible::Shutdown() { mAppInfo = nullptr; } + +void ApplicationAccessible::ApplyARIAState(uint64_t* aState) const {} + +role ApplicationAccessible::NativeRole() const { return roles::APP_ROOT; } + +uint64_t ApplicationAccessible::NativeState() const { return 0; } + +KeyBinding ApplicationAccessible::AccessKey() const { return KeyBinding(); } + +void ApplicationAccessible::Init() { + // Basically children are kept updated by Append/RemoveChild method calls. + // However if there are open windows before accessibility was started + // then we need to make sure root accessibles for open windows are created so + // that all root accessibles are stored in application accessible children + // array. + + nsGlobalWindowOuter::OuterWindowByIdTable* windowsById = + nsGlobalWindowOuter::GetWindowsTable(); + + if (!windowsById) { + return; + } + + for (const auto& window : windowsById->Values()) { + if (window->GetDocShell() && window->IsRootOuterWindow()) { + if (RefPtr<dom::Document> docNode = window->GetExtantDoc()) { + GetAccService()->GetDocAccessible(docNode); // ensure creation + } + } + } +} + +LocalAccessible* ApplicationAccessible::GetSiblingAtOffset( + int32_t aOffset, nsresult* aError) const { + if (aError) *aError = NS_OK; // fail peacefully + + return nullptr; +} |