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"
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
);
29 transform
.PreTranslate(aBounds
.Width(), 0);
30 transform
.PreRotate(floatPi
/ 2);
33 transform
.PreTranslate(aBounds
.Width(), aBounds
.Height());
34 transform
.PreRotate(floatPi
);
37 transform
.PreTranslate(0, aBounds
.Height());
38 transform
.PreRotate(floatPi
* 3 / 2);
41 MOZ_CRASH("Unknown rotation");
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
);
55 transform
.PreTranslate(0, aBounds
.Height());
56 transform
.PreRotate(floatPi
* 3 / 2);
59 transform
.PreTranslate(aBounds
.Width(), aBounds
.Height());
60 transform
.PreRotate(floatPi
);
63 transform
.PreTranslate(aBounds
.Width(), 0);
64 transform
.PreRotate(floatPi
/ 2);
67 MOZ_CRASH("Unknown rotation");
72 nsIntRect
RotateRect(nsIntRect aRect
, const nsIntRect
& aBounds
,
73 ScreenRotation aRotation
) {
78 return nsIntRect(aRect
.Y(), aBounds
.Width() - aRect
.XMost(),
79 aRect
.Height(), aRect
.Width());
81 return nsIntRect(aBounds
.Width() - aRect
.XMost(),
82 aBounds
.Height() - aRect
.YMost(), aRect
.Width(),
85 return nsIntRect(aBounds
.Height() - aRect
.YMost(), aRect
.X(),
86 aRect
.Height(), aRect
.Width());
88 MOZ_CRASH("Unknown rotation");
95 void WidgetUtils::SendBidiKeyboardInfoToContent() {
96 nsCOMPtr
<nsIBidiKeyboard
> bidiKeyboard
= nsContentUtils::GetBidiKeyboard();
102 if (NS_FAILED(bidiKeyboard
->IsLangRTL(&rtl
))) {
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
);
116 void WidgetUtils::GetBrandShortName(nsAString
& aBrandName
) {
117 aBrandName
.Truncate();
119 nsCOMPtr
<nsIStringBundleService
> bundleService
=
120 mozilla::components::StringBundle::Service();
122 nsCOMPtr
<nsIStringBundle
> bundle
;
124 bundleService
->CreateBundle("chrome://branding/locale/brand.properties",
125 getter_AddRefs(bundle
));
129 bundle
->GetStringFromName("brandShortName", aBrandName
);
133 } // namespace widget
134 } // namespace mozilla