Bumping gaia.json for 1 gaia revision(s) a=gaia-bump
[gecko.git] / widget / WidgetUtils.cpp
blob6d6d05fbc328d1c81203f3ec85b721d985dbae40
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"
10 namespace mozilla {
12 gfx::Matrix
13 ComputeTransformForRotation(const nsIntRect& aBounds,
14 ScreenRotation aRotation)
16 gfx::Matrix transform;
17 static const gfx::Float floatPi = static_cast<gfx::Float>(M_PI);
19 switch (aRotation) {
20 case ROTATION_0:
21 break;
22 case ROTATION_90:
23 transform.PreTranslate(aBounds.width, 0);
24 transform.PreRotate(floatPi / 2);
25 break;
26 case ROTATION_180:
27 transform.PreTranslate(aBounds.width, aBounds.height);
28 transform.PreRotate(floatPi);
29 break;
30 case ROTATION_270:
31 transform.PreTranslate(0, aBounds.height);
32 transform.PreRotate(floatPi * 3 / 2);
33 break;
34 default:
35 MOZ_CRASH("Unknown rotation");
37 return transform;
40 gfx::Matrix
41 ComputeTransformForUnRotation(const nsIntRect& aBounds,
42 ScreenRotation aRotation)
44 gfx::Matrix transform;
45 static const gfx::Float floatPi = static_cast<gfx::Float>(M_PI);
47 switch (aRotation) {
48 case ROTATION_0:
49 break;
50 case ROTATION_90:
51 transform.PreTranslate(0, aBounds.height);
52 transform.PreRotate(floatPi * 3 / 2);
53 break;
54 case ROTATION_180:
55 transform.PreTranslate(aBounds.width, aBounds.height);
56 transform.PreRotate(floatPi);
57 break;
58 case ROTATION_270:
59 transform.PreTranslate(aBounds.width, 0);
60 transform.PreRotate(floatPi / 2);
61 break;
62 default:
63 MOZ_CRASH("Unknown rotation");
65 return transform;
68 nsIntRect RotateRect(nsIntRect aRect,
69 const nsIntRect& aBounds,
70 ScreenRotation aRotation)
72 switch (aRotation) {
73 case ROTATION_0:
74 return aRect;
75 case ROTATION_90:
76 return nsIntRect(aRect.y,
77 aBounds.width - aRect.x - aRect.width,
78 aRect.height, aRect.width);
79 case ROTATION_180:
80 return nsIntRect(aBounds.width - aRect.x - aRect.width,
81 aBounds.height - aRect.y - aRect.height,
82 aRect.width, aRect.height);
83 case ROTATION_270:
84 return nsIntRect(aBounds.height - aRect.y - aRect.height,
85 aRect.x,
86 aRect.height, aRect.width);
87 default:
88 MOZ_CRASH("Unknown rotation");
89 return aRect;
92 } // namespace mozilla