Bug 1835241 - Part 3: Concatenate nested namespaces in GC code as per the coding...
[gecko.git] / widget / WidgetUtils.cpp
blob3bafdd0a4d27f91c2b5d6d4f9925143a36ea143a
1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*-
2 * vim: sw=2 ts=8 et :
3 */
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"
15 #include "nsTArray.h"
16 #include "prenv.h"
18 namespace mozilla {
20 gfx::Matrix ComputeTransformForRotation(const nsIntRect& aBounds,
21 ScreenRotation aRotation) {
22 gfx::Matrix transform;
23 static const gfx::Float floatPi = static_cast<gfx::Float>(M_PI);
25 switch (aRotation) {
26 case ROTATION_0:
27 break;
28 case ROTATION_90:
29 transform.PreTranslate(aBounds.Width(), 0);
30 transform.PreRotate(floatPi / 2);
31 break;
32 case ROTATION_180:
33 transform.PreTranslate(aBounds.Width(), aBounds.Height());
34 transform.PreRotate(floatPi);
35 break;
36 case ROTATION_270:
37 transform.PreTranslate(0, aBounds.Height());
38 transform.PreRotate(floatPi * 3 / 2);
39 break;
40 default:
41 MOZ_CRASH("Unknown rotation");
43 return transform;
46 gfx::Matrix ComputeTransformForUnRotation(const nsIntRect& aBounds,
47 ScreenRotation aRotation) {
48 gfx::Matrix transform;
49 static const gfx::Float floatPi = static_cast<gfx::Float>(M_PI);
51 switch (aRotation) {
52 case ROTATION_0:
53 break;
54 case ROTATION_90:
55 transform.PreTranslate(0, aBounds.Height());
56 transform.PreRotate(floatPi * 3 / 2);
57 break;
58 case ROTATION_180:
59 transform.PreTranslate(aBounds.Width(), aBounds.Height());
60 transform.PreRotate(floatPi);
61 break;
62 case ROTATION_270:
63 transform.PreTranslate(aBounds.Width(), 0);
64 transform.PreRotate(floatPi / 2);
65 break;
66 default:
67 MOZ_CRASH("Unknown rotation");
69 return transform;
72 nsIntRect RotateRect(nsIntRect aRect, const nsIntRect& aBounds,
73 ScreenRotation aRotation) {
74 switch (aRotation) {
75 case ROTATION_0:
76 return aRect;
77 case ROTATION_90:
78 return nsIntRect(aRect.Y(), aBounds.Width() - aRect.XMost(),
79 aRect.Height(), aRect.Width());
80 case ROTATION_180:
81 return nsIntRect(aBounds.Width() - aRect.XMost(),
82 aBounds.Height() - aRect.YMost(), aRect.Width(),
83 aRect.Height());
84 case ROTATION_270:
85 return nsIntRect(aBounds.Height() - aRect.YMost(), aRect.X(),
86 aRect.Height(), aRect.Width());
87 default:
88 MOZ_CRASH("Unknown rotation");
92 namespace widget {
94 // static
95 void WidgetUtils::SendBidiKeyboardInfoToContent() {
96 nsCOMPtr<nsIBidiKeyboard> bidiKeyboard = nsContentUtils::GetBidiKeyboard();
97 if (!bidiKeyboard) {
98 return;
101 bool rtl;
102 if (NS_FAILED(bidiKeyboard->IsLangRTL(&rtl))) {
103 return;
105 bool bidiKeyboards = false;
106 bidiKeyboard->GetHaveBidiKeyboards(&bidiKeyboards);
108 nsTArray<dom::ContentParent*> children;
109 dom::ContentParent::GetAll(children);
110 for (uint32_t i = 0; i < children.Length(); i++) {
111 Unused << children[i]->SendBidiKeyboardNotify(rtl, bidiKeyboards);
115 // static
116 void WidgetUtils::GetBrandShortName(nsAString& aBrandName) {
117 aBrandName.Truncate();
119 nsCOMPtr<nsIStringBundleService> bundleService =
120 mozilla::components::StringBundle::Service();
122 nsCOMPtr<nsIStringBundle> bundle;
123 if (bundleService) {
124 bundleService->CreateBundle("chrome://branding/locale/brand.properties",
125 getter_AddRefs(bundle));
128 if (bundle) {
129 bundle->GetStringFromName("brandShortName", aBrandName);
133 } // namespace widget
134 } // namespace mozilla