tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

RootAccessibleWrap.mm (1579B)


      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 "MUIRootAccessible.h"
     11 
     12 #include "gfxPlatform.h"
     13 #include "nsCOMPtr.h"
     14 #include "nsObjCExceptions.h"
     15 #include "nsIFrame.h"
     16 #include "nsIWidget.h"
     17 
     18 using namespace mozilla;
     19 using namespace mozilla::a11y;
     20 
     21 RootAccessibleWrap::RootAccessibleWrap(dom::Document* aDocument,
     22                                       PresShell* aPresShell)
     23    : RootAccessible(aDocument, aPresShell) {}
     24 
     25 void RootAccessibleWrap::GetNativeWidget(void** aOutView) {
     26  if (nsIFrame* frame = GetFrame()) {
     27    if (nsIWidget* widget = frame->GetOwnWidget()) {
     28      *aOutView = (void**)widget->GetNativeData(NS_NATIVE_WIDGET);
     29      MOZ_DIAGNOSTIC_ASSERT(*aOutView, "Couldn't get the native UIView!");
     30    }
     31  }
     32 }
     33 
     34 CGRect RootAccessibleWrap::DevPixelsRectToUIKit(
     35    const LayoutDeviceIntRect& aRect) {
     36  UIView* nativeWidget = nil;
     37  GetNativeWidget((void**)&nativeWidget);
     38  CGRect rootFrame = [nativeWidget accessibilityFrame];
     39  CGFloat scale = [nativeWidget contentScaleFactor];
     40  return CGRectMake(((CGFloat)aRect.x / scale) + rootFrame.origin.x,
     41                    ((CGFloat)aRect.y / scale) + rootFrame.origin.y,
     42                    (CGFloat)aRect.width / scale,
     43                    (CGFloat)aRect.height / scale);
     44 }