Line data Source code
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/. */
7 :
8 : #include "mozilla/WidgetUtils.h"
9 : #include "mozilla/dom/ContentParent.h"
10 : #include "mozilla/Unused.h"
11 : #include "nsContentUtils.h"
12 : #include "nsIBidiKeyboard.h"
13 : #include "nsTArray.h"
14 : #ifdef XP_WIN
15 : #include "WinUtils.h"
16 : #endif
17 : #if MOZ_WIDGET_GTK == 3
18 : #include "mozilla/WidgetUtilsGtk.h"
19 : #endif
20 :
21 : namespace mozilla {
22 :
23 : gfx::Matrix
24 29 : ComputeTransformForRotation(const nsIntRect& aBounds,
25 : ScreenRotation aRotation)
26 : {
27 29 : gfx::Matrix transform;
28 : static const gfx::Float floatPi = static_cast<gfx::Float>(M_PI);
29 :
30 29 : switch (aRotation) {
31 : case ROTATION_0:
32 29 : break;
33 : case ROTATION_90:
34 0 : transform.PreTranslate(aBounds.width, 0);
35 0 : transform.PreRotate(floatPi / 2);
36 0 : break;
37 : case ROTATION_180:
38 0 : transform.PreTranslate(aBounds.width, aBounds.height);
39 0 : transform.PreRotate(floatPi);
40 0 : break;
41 : case ROTATION_270:
42 0 : transform.PreTranslate(0, aBounds.height);
43 0 : transform.PreRotate(floatPi * 3 / 2);
44 0 : break;
45 : default:
46 0 : MOZ_CRASH("Unknown rotation");
47 : }
48 29 : return transform;
49 : }
50 :
51 : gfx::Matrix
52 0 : ComputeTransformForUnRotation(const nsIntRect& aBounds,
53 : ScreenRotation aRotation)
54 : {
55 0 : gfx::Matrix transform;
56 : static const gfx::Float floatPi = static_cast<gfx::Float>(M_PI);
57 :
58 0 : switch (aRotation) {
59 : case ROTATION_0:
60 0 : break;
61 : case ROTATION_90:
62 0 : transform.PreTranslate(0, aBounds.height);
63 0 : transform.PreRotate(floatPi * 3 / 2);
64 0 : break;
65 : case ROTATION_180:
66 0 : transform.PreTranslate(aBounds.width, aBounds.height);
67 0 : transform.PreRotate(floatPi);
68 0 : break;
69 : case ROTATION_270:
70 0 : transform.PreTranslate(aBounds.width, 0);
71 0 : transform.PreRotate(floatPi / 2);
72 0 : break;
73 : default:
74 0 : MOZ_CRASH("Unknown rotation");
75 : }
76 0 : return transform;
77 : }
78 :
79 0 : nsIntRect RotateRect(nsIntRect aRect,
80 : const nsIntRect& aBounds,
81 : ScreenRotation aRotation)
82 : {
83 0 : switch (aRotation) {
84 : case ROTATION_0:
85 0 : return aRect;
86 : case ROTATION_90:
87 0 : return nsIntRect(aRect.y,
88 0 : aBounds.width - aRect.x - aRect.width,
89 0 : aRect.height, aRect.width);
90 : case ROTATION_180:
91 0 : return nsIntRect(aBounds.width - aRect.x - aRect.width,
92 0 : aBounds.height - aRect.y - aRect.height,
93 0 : aRect.width, aRect.height);
94 : case ROTATION_270:
95 0 : return nsIntRect(aBounds.height - aRect.y - aRect.height,
96 : aRect.x,
97 0 : aRect.height, aRect.width);
98 : default:
99 0 : MOZ_CRASH("Unknown rotation");
100 : }
101 : }
102 :
103 : namespace widget {
104 :
105 : uint32_t
106 4 : WidgetUtils::IsTouchDeviceSupportPresent()
107 : {
108 : #ifdef XP_WIN
109 : return WinUtils::IsTouchDeviceSupportPresent();
110 : #elif MOZ_WIDGET_GTK == 3
111 4 : return WidgetUtilsGTK::IsTouchDeviceSupportPresent();
112 : #else
113 : return 0;
114 : #endif
115 : }
116 :
117 : // static
118 : void
119 0 : WidgetUtils::SendBidiKeyboardInfoToContent()
120 : {
121 0 : nsCOMPtr<nsIBidiKeyboard> bidiKeyboard = nsContentUtils::GetBidiKeyboard();
122 0 : if (!bidiKeyboard) {
123 0 : return;
124 : }
125 :
126 : bool rtl;
127 0 : if (NS_FAILED(bidiKeyboard->IsLangRTL(&rtl))) {
128 0 : return;
129 : }
130 0 : bool bidiKeyboards = false;
131 0 : bidiKeyboard->GetHaveBidiKeyboards(&bidiKeyboards);
132 :
133 0 : nsTArray<dom::ContentParent*> children;
134 0 : dom::ContentParent::GetAll(children);
135 0 : for (uint32_t i = 0; i < children.Length(); i++) {
136 0 : Unused << children[i]->SendBidiKeyboardNotify(rtl, bidiKeyboards);
137 : }
138 : }
139 :
140 : } // namespace widget
141 : } // namespace mozilla
|