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/Services.h"
11 #include "mozilla/Unused.h"
12 #include "nsContentUtils.h"
13 #include "nsIBidiKeyboard.h"
14 #include "nsIStringBundle.h"
17 # include "WinUtils.h"
20 # include "mozilla/WidgetUtilsGtk.h"
25 gfx::Matrix
ComputeTransformForRotation(const nsIntRect
& aBounds
,
26 ScreenRotation aRotation
) {
27 gfx::Matrix transform
;
28 static const gfx::Float floatPi
= static_cast<gfx::Float
>(M_PI
);
34 transform
.PreTranslate(aBounds
.Width(), 0);
35 transform
.PreRotate(floatPi
/ 2);
38 transform
.PreTranslate(aBounds
.Width(), aBounds
.Height());
39 transform
.PreRotate(floatPi
);
42 transform
.PreTranslate(0, aBounds
.Height());
43 transform
.PreRotate(floatPi
* 3 / 2);
46 MOZ_CRASH("Unknown rotation");
51 gfx::Matrix
ComputeTransformForUnRotation(const nsIntRect
& aBounds
,
52 ScreenRotation aRotation
) {
53 gfx::Matrix transform
;
54 static const gfx::Float floatPi
= static_cast<gfx::Float
>(M_PI
);
60 transform
.PreTranslate(0, aBounds
.Height());
61 transform
.PreRotate(floatPi
* 3 / 2);
64 transform
.PreTranslate(aBounds
.Width(), aBounds
.Height());
65 transform
.PreRotate(floatPi
);
68 transform
.PreTranslate(aBounds
.Width(), 0);
69 transform
.PreRotate(floatPi
/ 2);
72 MOZ_CRASH("Unknown rotation");
77 nsIntRect
RotateRect(nsIntRect aRect
, const nsIntRect
& aBounds
,
78 ScreenRotation aRotation
) {
83 return nsIntRect(aRect
.Y(), aBounds
.Width() - aRect
.XMost(),
84 aRect
.Height(), aRect
.Width());
86 return nsIntRect(aBounds
.Width() - aRect
.XMost(),
87 aBounds
.Height() - aRect
.YMost(), aRect
.Width(),
90 return nsIntRect(aBounds
.Height() - aRect
.YMost(), aRect
.X(),
91 aRect
.Height(), aRect
.Width());
93 MOZ_CRASH("Unknown rotation");
99 uint32_t WidgetUtils::IsTouchDeviceSupportPresent() {
101 return WinUtils::IsTouchDeviceSupportPresent();
102 #elif defined(MOZ_WIDGET_GTK)
103 return WidgetUtilsGTK::IsTouchDeviceSupportPresent();
110 void WidgetUtils::SendBidiKeyboardInfoToContent() {
111 nsCOMPtr
<nsIBidiKeyboard
> bidiKeyboard
= nsContentUtils::GetBidiKeyboard();
117 if (NS_FAILED(bidiKeyboard
->IsLangRTL(&rtl
))) {
120 bool bidiKeyboards
= false;
121 bidiKeyboard
->GetHaveBidiKeyboards(&bidiKeyboards
);
123 nsTArray
<dom::ContentParent
*> children
;
124 dom::ContentParent::GetAll(children
);
125 for (uint32_t i
= 0; i
< children
.Length(); i
++) {
126 Unused
<< children
[i
]->SendBidiKeyboardNotify(rtl
, bidiKeyboards
);
131 void WidgetUtils::GetBrandShortName(nsAString
& aBrandName
) {
132 aBrandName
.Truncate();
134 nsCOMPtr
<nsIStringBundleService
> bundleService
=
135 mozilla::services::GetStringBundleService();
137 nsCOMPtr
<nsIStringBundle
> bundle
;
139 bundleService
->CreateBundle("chrome://branding/locale/brand.properties",
140 getter_AddRefs(bundle
));
144 bundle
->GetStringFromName("brandShortName", aBrandName
);
148 } // namespace widget
149 } // namespace mozilla