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"
20 #include "mozilla/WidgetUtilsGtk.h"
26 ComputeTransformForRotation(const nsIntRect
& aBounds
,
27 ScreenRotation aRotation
)
29 gfx::Matrix transform
;
30 static const gfx::Float floatPi
= static_cast<gfx::Float
>(M_PI
);
36 transform
.PreTranslate(aBounds
.Width(), 0);
37 transform
.PreRotate(floatPi
/ 2);
40 transform
.PreTranslate(aBounds
.Width(), aBounds
.Height());
41 transform
.PreRotate(floatPi
);
44 transform
.PreTranslate(0, aBounds
.Height());
45 transform
.PreRotate(floatPi
* 3 / 2);
48 MOZ_CRASH("Unknown rotation");
54 ComputeTransformForUnRotation(const nsIntRect
& aBounds
,
55 ScreenRotation aRotation
)
57 gfx::Matrix transform
;
58 static const gfx::Float floatPi
= static_cast<gfx::Float
>(M_PI
);
64 transform
.PreTranslate(0, aBounds
.Height());
65 transform
.PreRotate(floatPi
* 3 / 2);
68 transform
.PreTranslate(aBounds
.Width(), aBounds
.Height());
69 transform
.PreRotate(floatPi
);
72 transform
.PreTranslate(aBounds
.Width(), 0);
73 transform
.PreRotate(floatPi
/ 2);
76 MOZ_CRASH("Unknown rotation");
81 nsIntRect
RotateRect(nsIntRect aRect
,
82 const nsIntRect
& aBounds
,
83 ScreenRotation aRotation
)
89 return nsIntRect(aRect
.Y(),
90 aBounds
.Width() - aRect
.XMost(),
91 aRect
.Height(), aRect
.Width());
93 return nsIntRect(aBounds
.Width() - aRect
.XMost(),
94 aBounds
.Height() - aRect
.YMost(),
95 aRect
.Width(), aRect
.Height());
97 return nsIntRect(aBounds
.Height() - aRect
.YMost(),
99 aRect
.Height(), aRect
.Width());
101 MOZ_CRASH("Unknown rotation");
108 WidgetUtils::IsTouchDeviceSupportPresent()
111 return WinUtils::IsTouchDeviceSupportPresent();
112 #elif defined(MOZ_WIDGET_GTK)
113 return WidgetUtilsGTK::IsTouchDeviceSupportPresent();
121 WidgetUtils::SendBidiKeyboardInfoToContent()
123 nsCOMPtr
<nsIBidiKeyboard
> bidiKeyboard
= nsContentUtils::GetBidiKeyboard();
129 if (NS_FAILED(bidiKeyboard
->IsLangRTL(&rtl
))) {
132 bool bidiKeyboards
= false;
133 bidiKeyboard
->GetHaveBidiKeyboards(&bidiKeyboards
);
135 nsTArray
<dom::ContentParent
*> children
;
136 dom::ContentParent::GetAll(children
);
137 for (uint32_t i
= 0; i
< children
.Length(); i
++) {
138 Unused
<< children
[i
]->SendBidiKeyboardNotify(rtl
, bidiKeyboards
);
144 WidgetUtils::GetBrandShortName(nsAString
& aBrandName
)
146 aBrandName
.Truncate();
148 nsCOMPtr
<nsIStringBundleService
> bundleService
=
149 mozilla::services::GetStringBundleService();
151 nsCOMPtr
<nsIStringBundle
> bundle
;
153 bundleService
->CreateBundle(
154 "chrome://branding/locale/brand.properties",
155 getter_AddRefs(bundle
));
159 bundle
->GetStringFromName("brandShortName", aBrandName
);
163 } // namespace widget
164 } // namespace mozilla