1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*-
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 file,
6 * You can obtain one at http://mozilla.org/MPL/2.0/. */
8 #include "mozilla/WidgetUtils.h"
9 #include "mozilla/dom/ContentParent.h"
10 #include "mozilla/Components.h"
11 #include "mozilla/Unused.h"
12 #include "nsContentUtils.h"
13 #include "nsIBidiKeyboard.h"
14 #include "nsIStringBundle.h"
18 # include "WinUtils.h"
21 # include "mozilla/WidgetUtilsGtk.h"
26 gfx::Matrix
ComputeTransformForRotation(const nsIntRect
& aBounds
,
27 ScreenRotation aRotation
) {
28 gfx::Matrix transform
;
29 static const gfx::Float floatPi
= static_cast<gfx::Float
>(M_PI
);
35 transform
.PreTranslate(aBounds
.Width(), 0);
36 transform
.PreRotate(floatPi
/ 2);
39 transform
.PreTranslate(aBounds
.Width(), aBounds
.Height());
40 transform
.PreRotate(floatPi
);
43 transform
.PreTranslate(0, aBounds
.Height());
44 transform
.PreRotate(floatPi
* 3 / 2);
47 MOZ_CRASH("Unknown rotation");
52 gfx::Matrix
ComputeTransformForUnRotation(const nsIntRect
& aBounds
,
53 ScreenRotation aRotation
) {
54 gfx::Matrix transform
;
55 static const gfx::Float floatPi
= static_cast<gfx::Float
>(M_PI
);
61 transform
.PreTranslate(0, aBounds
.Height());
62 transform
.PreRotate(floatPi
* 3 / 2);
65 transform
.PreTranslate(aBounds
.Width(), aBounds
.Height());
66 transform
.PreRotate(floatPi
);
69 transform
.PreTranslate(aBounds
.Width(), 0);
70 transform
.PreRotate(floatPi
/ 2);
73 MOZ_CRASH("Unknown rotation");
78 nsIntRect
RotateRect(nsIntRect aRect
, const nsIntRect
& aBounds
,
79 ScreenRotation aRotation
) {
84 return nsIntRect(aRect
.Y(), aBounds
.Width() - aRect
.XMost(),
85 aRect
.Height(), aRect
.Width());
87 return nsIntRect(aBounds
.Width() - aRect
.XMost(),
88 aBounds
.Height() - aRect
.YMost(), aRect
.Width(),
91 return nsIntRect(aBounds
.Height() - aRect
.YMost(), aRect
.X(),
92 aRect
.Height(), aRect
.Width());
94 MOZ_CRASH("Unknown rotation");
100 uint32_t WidgetUtils::IsTouchDeviceSupportPresent() {
102 return WinUtils::IsTouchDeviceSupportPresent();
103 #elif defined(MOZ_WIDGET_GTK)
104 return WidgetUtilsGTK::IsTouchDeviceSupportPresent();
111 void WidgetUtils::SendBidiKeyboardInfoToContent() {
112 nsCOMPtr
<nsIBidiKeyboard
> bidiKeyboard
= nsContentUtils::GetBidiKeyboard();
118 if (NS_FAILED(bidiKeyboard
->IsLangRTL(&rtl
))) {
121 bool bidiKeyboards
= false;
122 bidiKeyboard
->GetHaveBidiKeyboards(&bidiKeyboards
);
124 nsTArray
<dom::ContentParent
*> children
;
125 dom::ContentParent::GetAll(children
);
126 for (uint32_t i
= 0; i
< children
.Length(); i
++) {
127 Unused
<< children
[i
]->SendBidiKeyboardNotify(rtl
, bidiKeyboards
);
132 void WidgetUtils::GetBrandShortName(nsAString
& aBrandName
) {
133 aBrandName
.Truncate();
135 nsCOMPtr
<nsIStringBundleService
> bundleService
=
136 mozilla::components::StringBundle::Service();
138 nsCOMPtr
<nsIStringBundle
> bundle
;
140 bundleService
->CreateBundle("chrome://branding/locale/brand.properties",
141 getter_AddRefs(bundle
));
145 bundle
->GetStringFromName("brandShortName", aBrandName
);
149 const char* WidgetUtils::GetSnapInstanceName() {
150 char* instanceName
= PR_GetEnv("SNAP_INSTANCE_NAME");
151 if (instanceName
!= nullptr) {
154 // Compatibility for snapd <= 2.35:
155 return PR_GetEnv("SNAP_NAME");
158 } // namespace widget
159 } // namespace mozilla