Bug 1690340 - Part 5: Remove the menu separators from the developer tools menu. r...
[gecko.git] / widget / WidgetUtils.cpp
blobd3b47a5d30702869ff9e2d80f78b532a8315a411
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/Services.h"
11 #include "mozilla/Unused.h"
12 #include "nsContentUtils.h"
13 #include "nsIBidiKeyboard.h"
14 #include "nsIStringBundle.h"
15 #include "nsTArray.h"
16 #ifdef XP_WIN
17 # include "WinUtils.h"
18 #endif
19 #ifdef MOZ_WIDGET_GTK
20 # include "mozilla/WidgetUtilsGtk.h"
21 #endif
23 namespace mozilla {
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);
30 switch (aRotation) {
31 case ROTATION_0:
32 break;
33 case ROTATION_90:
34 transform.PreTranslate(aBounds.Width(), 0);
35 transform.PreRotate(floatPi / 2);
36 break;
37 case ROTATION_180:
38 transform.PreTranslate(aBounds.Width(), aBounds.Height());
39 transform.PreRotate(floatPi);
40 break;
41 case ROTATION_270:
42 transform.PreTranslate(0, aBounds.Height());
43 transform.PreRotate(floatPi * 3 / 2);
44 break;
45 default:
46 MOZ_CRASH("Unknown rotation");
48 return transform;
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);
56 switch (aRotation) {
57 case ROTATION_0:
58 break;
59 case ROTATION_90:
60 transform.PreTranslate(0, aBounds.Height());
61 transform.PreRotate(floatPi * 3 / 2);
62 break;
63 case ROTATION_180:
64 transform.PreTranslate(aBounds.Width(), aBounds.Height());
65 transform.PreRotate(floatPi);
66 break;
67 case ROTATION_270:
68 transform.PreTranslate(aBounds.Width(), 0);
69 transform.PreRotate(floatPi / 2);
70 break;
71 default:
72 MOZ_CRASH("Unknown rotation");
74 return transform;
77 nsIntRect RotateRect(nsIntRect aRect, const nsIntRect& aBounds,
78 ScreenRotation aRotation) {
79 switch (aRotation) {
80 case ROTATION_0:
81 return aRect;
82 case ROTATION_90:
83 return nsIntRect(aRect.Y(), aBounds.Width() - aRect.XMost(),
84 aRect.Height(), aRect.Width());
85 case ROTATION_180:
86 return nsIntRect(aBounds.Width() - aRect.XMost(),
87 aBounds.Height() - aRect.YMost(), aRect.Width(),
88 aRect.Height());
89 case ROTATION_270:
90 return nsIntRect(aBounds.Height() - aRect.YMost(), aRect.X(),
91 aRect.Height(), aRect.Width());
92 default:
93 MOZ_CRASH("Unknown rotation");
97 namespace widget {
99 uint32_t WidgetUtils::IsTouchDeviceSupportPresent() {
100 #ifdef XP_WIN
101 return WinUtils::IsTouchDeviceSupportPresent();
102 #elif defined(MOZ_WIDGET_GTK)
103 return WidgetUtilsGTK::IsTouchDeviceSupportPresent();
104 #else
105 return 0;
106 #endif
109 // static
110 void WidgetUtils::SendBidiKeyboardInfoToContent() {
111 nsCOMPtr<nsIBidiKeyboard> bidiKeyboard = nsContentUtils::GetBidiKeyboard();
112 if (!bidiKeyboard) {
113 return;
116 bool rtl;
117 if (NS_FAILED(bidiKeyboard->IsLangRTL(&rtl))) {
118 return;
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);
130 // static
131 void WidgetUtils::GetBrandShortName(nsAString& aBrandName) {
132 aBrandName.Truncate();
134 nsCOMPtr<nsIStringBundleService> bundleService =
135 mozilla::services::GetStringBundleService();
137 nsCOMPtr<nsIStringBundle> bundle;
138 if (bundleService) {
139 bundleService->CreateBundle("chrome://branding/locale/brand.properties",
140 getter_AddRefs(bundle));
143 if (bundle) {
144 bundle->GetStringFromName("brandShortName", aBrandName);
148 } // namespace widget
149 } // namespace mozilla