Coverage Report

Created: 2018-09-25 14:53

/src/mozilla-central/widget/WidgetUtils.cpp
Line
Count
Source (jump to first uncovered line)
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/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
22
23
namespace mozilla {
24
25
gfx::Matrix
26
ComputeTransformForRotation(const nsIntRect& aBounds,
27
                              ScreenRotation aRotation)
28
0
{
29
0
    gfx::Matrix transform;
30
0
    static const gfx::Float floatPi = static_cast<gfx::Float>(M_PI);
31
0
32
0
    switch (aRotation) {
33
0
    case ROTATION_0:
34
0
        break;
35
0
    case ROTATION_90:
36
0
        transform.PreTranslate(aBounds.Width(), 0);
37
0
        transform.PreRotate(floatPi / 2);
38
0
        break;
39
0
    case ROTATION_180:
40
0
        transform.PreTranslate(aBounds.Width(), aBounds.Height());
41
0
        transform.PreRotate(floatPi);
42
0
        break;
43
0
    case ROTATION_270:
44
0
        transform.PreTranslate(0, aBounds.Height());
45
0
        transform.PreRotate(floatPi * 3 / 2);
46
0
        break;
47
0
    default:
48
0
        MOZ_CRASH("Unknown rotation");
49
0
    }
50
0
    return transform;
51
0
}
52
53
gfx::Matrix
54
ComputeTransformForUnRotation(const nsIntRect& aBounds,
55
                              ScreenRotation aRotation)
56
0
{
57
0
    gfx::Matrix transform;
58
0
    static const gfx::Float floatPi = static_cast<gfx::Float>(M_PI);
59
0
60
0
    switch (aRotation) {
61
0
    case ROTATION_0:
62
0
        break;
63
0
    case ROTATION_90:
64
0
        transform.PreTranslate(0, aBounds.Height());
65
0
        transform.PreRotate(floatPi * 3 / 2);
66
0
        break;
67
0
    case ROTATION_180:
68
0
        transform.PreTranslate(aBounds.Width(), aBounds.Height());
69
0
        transform.PreRotate(floatPi);
70
0
        break;
71
0
    case ROTATION_270:
72
0
        transform.PreTranslate(aBounds.Width(), 0);
73
0
        transform.PreRotate(floatPi / 2);
74
0
        break;
75
0
    default:
76
0
        MOZ_CRASH("Unknown rotation");
77
0
    }
78
0
    return transform;
79
0
}
80
81
nsIntRect RotateRect(nsIntRect aRect,
82
                     const nsIntRect& aBounds,
83
                     ScreenRotation aRotation)
84
0
{
85
0
  switch (aRotation) {
86
0
    case ROTATION_0:
87
0
      return aRect;
88
0
    case ROTATION_90:
89
0
      return nsIntRect(aRect.Y(),
90
0
                       aBounds.Width() - aRect.XMost(),
91
0
                       aRect.Height(), aRect.Width());
92
0
    case ROTATION_180:
93
0
      return nsIntRect(aBounds.Width() - aRect.XMost(),
94
0
                       aBounds.Height() - aRect.YMost(),
95
0
                       aRect.Width(), aRect.Height());
96
0
    case ROTATION_270:
97
0
      return nsIntRect(aBounds.Height() - aRect.YMost(),
98
0
                       aRect.X(),
99
0
                       aRect.Height(), aRect.Width());
100
0
    default:
101
0
      MOZ_CRASH("Unknown rotation");
102
0
  }
103
0
}
104
105
namespace widget {
106
107
uint32_t
108
WidgetUtils::IsTouchDeviceSupportPresent()
109
0
{
110
#ifdef XP_WIN
111
  return WinUtils::IsTouchDeviceSupportPresent();
112
#elif defined(MOZ_WIDGET_GTK)
113
  return WidgetUtilsGTK::IsTouchDeviceSupportPresent();
114
#else
115
  return 0;
116
#endif
117
}
118
119
// static
120
void
121
WidgetUtils::SendBidiKeyboardInfoToContent()
122
0
{
123
0
  nsCOMPtr<nsIBidiKeyboard> bidiKeyboard = nsContentUtils::GetBidiKeyboard();
124
0
  if (!bidiKeyboard) {
125
0
    return;
126
0
  }
127
0
128
0
  bool rtl;
129
0
  if (NS_FAILED(bidiKeyboard->IsLangRTL(&rtl))) {
130
0
    return;
131
0
  }
132
0
  bool bidiKeyboards = false;
133
0
  bidiKeyboard->GetHaveBidiKeyboards(&bidiKeyboards);
134
0
135
0
  nsTArray<dom::ContentParent*> children;
136
0
  dom::ContentParent::GetAll(children);
137
0
  for (uint32_t i = 0; i < children.Length(); i++) {
138
0
    Unused << children[i]->SendBidiKeyboardNotify(rtl, bidiKeyboards);
139
0
  }
140
0
}
141
142
// static
143
void
144
WidgetUtils::GetBrandShortName(nsAString& aBrandName)
145
0
{
146
0
    aBrandName.Truncate();
147
0
148
0
    nsCOMPtr<nsIStringBundleService> bundleService =
149
0
        mozilla::services::GetStringBundleService();
150
0
151
0
    nsCOMPtr<nsIStringBundle> bundle;
152
0
    if (bundleService) {
153
0
        bundleService->CreateBundle(
154
0
            "chrome://branding/locale/brand.properties",
155
0
            getter_AddRefs(bundle));
156
0
    }
157
0
158
0
    if (bundle) {
159
0
        bundle->GetStringFromName("brandShortName", aBrandName);
160
0
    }
161
0
}
162
163
} // namespace widget
164
} // namespace mozilla