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"
13 ComputeTransformForRotation(const nsIntRect
& aBounds
,
14 ScreenRotation aRotation
)
16 gfx::Matrix transform
;
17 static const gfx::Float floatPi
= static_cast<gfx::Float
>(M_PI
);
23 transform
.PreTranslate(aBounds
.width
, 0);
24 transform
.PreRotate(floatPi
/ 2);
27 transform
.PreTranslate(aBounds
.width
, aBounds
.height
);
28 transform
.PreRotate(floatPi
);
31 transform
.PreTranslate(0, aBounds
.height
);
32 transform
.PreRotate(floatPi
* 3 / 2);
35 MOZ_CRASH("Unknown rotation");
41 ComputeTransformForUnRotation(const nsIntRect
& aBounds
,
42 ScreenRotation aRotation
)
44 gfx::Matrix transform
;
45 static const gfx::Float floatPi
= static_cast<gfx::Float
>(M_PI
);
51 transform
.PreTranslate(0, aBounds
.height
);
52 transform
.PreRotate(floatPi
* 3 / 2);
55 transform
.PreTranslate(aBounds
.width
, aBounds
.height
);
56 transform
.PreRotate(floatPi
);
59 transform
.PreTranslate(aBounds
.width
, 0);
60 transform
.PreRotate(floatPi
/ 2);
63 MOZ_CRASH("Unknown rotation");
68 nsIntRect
RotateRect(nsIntRect aRect
,
69 const nsIntRect
& aBounds
,
70 ScreenRotation aRotation
)
76 return nsIntRect(aRect
.y
,
77 aBounds
.width
- aRect
.x
- aRect
.width
,
78 aRect
.height
, aRect
.width
);
80 return nsIntRect(aBounds
.width
- aRect
.x
- aRect
.width
,
81 aBounds
.height
- aRect
.y
- aRect
.height
,
82 aRect
.width
, aRect
.height
);
84 return nsIntRect(aBounds
.height
- aRect
.y
- aRect
.height
,
86 aRect
.height
, aRect
.width
);
88 MOZ_CRASH("Unknown rotation");
92 } // namespace mozilla