1/* clang-format off */
2/* -*- Mode: Objective-C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
3/* clang-format on */
4/* This Source Code Form is subject to the terms of the Mozilla Public
5 * License, v. 2.0. If a copy of the MPL was not distributed with this
6 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
7
8#include "RootAccessibleWrap.h"
9
10#include "mozRootAccessible.h"
11
12#include "gfxPlatform.h"
13#include "nsCOMPtr.h"
14#include "nsObjCExceptions.h"
15#include "nsIFrame.h"
16#include "nsView.h"
17#include "nsIWidget.h"
18
19using namespace mozilla;
20using namespace mozilla::a11y;
21
22RootAccessibleWrap::RootAccessibleWrap(dom::Document* aDocument,
23                                       PresShell* aPresShell)
24    : RootAccessible(aDocument, aPresShell) {}
25
26RootAccessibleWrap::~RootAccessibleWrap() {}
27
28Class RootAccessibleWrap::GetNativeType() {
29  NS_OBJC_BEGIN_TRY_BLOCK_RETURN;
30
31  return [mozRootAccessible class];
32
33  NS_OBJC_END_TRY_BLOCK_RETURN(nil);
34}
35
36void RootAccessibleWrap::GetNativeWidget(void** aOutView) {
37  nsIFrame* frame = GetFrame();
38  if (frame) {
39    nsView* view = frame->GetView();
40    if (view) {
41      nsIWidget* widget = view->GetWidget();
42      if (widget) {
43        *aOutView = (void**)widget->GetNativeData(NS_NATIVE_WIDGET);
44        MOZ_ASSERT(
45            *aOutView || gfxPlatform::IsHeadless(),
46            "Couldn't get the native NSView parent we need to connect the "
47            "accessibility hierarchy!");
48      }
49    }
50  }
51}
52