Wed, 31 Dec 2014 06:09:35 +0100
Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.
michael@0 | 1 | /* -*- Mode: C++; tab-width: 20; indent-tabs-mode: nil; c-basic-offset: 4 -*- |
michael@0 | 2 | * This Source Code Form is subject to the terms of the Mozilla Public |
michael@0 | 3 | * License, v. 2.0. If a copy of the MPL was not distributed with this |
michael@0 | 4 | * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ |
michael@0 | 5 | |
michael@0 | 6 | #include "gfxRect.h" |
michael@0 | 7 | |
michael@0 | 8 | #include "nsMathUtils.h" |
michael@0 | 9 | |
michael@0 | 10 | static bool |
michael@0 | 11 | WithinEpsilonOfInteger(gfxFloat aX, gfxFloat aEpsilon) |
michael@0 | 12 | { |
michael@0 | 13 | return fabs(NS_round(aX) - aX) <= fabs(aEpsilon); |
michael@0 | 14 | } |
michael@0 | 15 | |
michael@0 | 16 | bool |
michael@0 | 17 | gfxRect::WithinEpsilonOfIntegerPixels(gfxFloat aEpsilon) const |
michael@0 | 18 | { |
michael@0 | 19 | NS_ASSERTION(-0.5 < aEpsilon && aEpsilon < 0.5, "Nonsense epsilon value"); |
michael@0 | 20 | return (WithinEpsilonOfInteger(x, aEpsilon) && |
michael@0 | 21 | WithinEpsilonOfInteger(y, aEpsilon) && |
michael@0 | 22 | WithinEpsilonOfInteger(width, aEpsilon) && |
michael@0 | 23 | WithinEpsilonOfInteger(height, aEpsilon)); |
michael@0 | 24 | } |
michael@0 | 25 | |
michael@0 | 26 | /* Clamp r to CAIRO_COORD_MIN .. CAIRO_COORD_MAX |
michael@0 | 27 | * these are to be device coordinates. |
michael@0 | 28 | * |
michael@0 | 29 | * Cairo is currently using 24.8 fixed point, |
michael@0 | 30 | * so -2^24 .. 2^24-1 is our valid |
michael@0 | 31 | */ |
michael@0 | 32 | |
michael@0 | 33 | #define CAIRO_COORD_MAX (16777215.0) |
michael@0 | 34 | #define CAIRO_COORD_MIN (-16777216.0) |
michael@0 | 35 | |
michael@0 | 36 | void |
michael@0 | 37 | gfxRect::Condition() |
michael@0 | 38 | { |
michael@0 | 39 | // if either x or y is way out of bounds; |
michael@0 | 40 | // note that we don't handle negative w/h here |
michael@0 | 41 | if (x > CAIRO_COORD_MAX) { |
michael@0 | 42 | x = CAIRO_COORD_MAX; |
michael@0 | 43 | width = 0.0; |
michael@0 | 44 | } |
michael@0 | 45 | |
michael@0 | 46 | if (y > CAIRO_COORD_MAX) { |
michael@0 | 47 | y = CAIRO_COORD_MAX; |
michael@0 | 48 | height = 0.0; |
michael@0 | 49 | } |
michael@0 | 50 | |
michael@0 | 51 | if (x < CAIRO_COORD_MIN) { |
michael@0 | 52 | width += x - CAIRO_COORD_MIN; |
michael@0 | 53 | if (width < 0.0) |
michael@0 | 54 | width = 0.0; |
michael@0 | 55 | x = CAIRO_COORD_MIN; |
michael@0 | 56 | } |
michael@0 | 57 | |
michael@0 | 58 | if (y < CAIRO_COORD_MIN) { |
michael@0 | 59 | height += y - CAIRO_COORD_MIN; |
michael@0 | 60 | if (height < 0.0) |
michael@0 | 61 | height = 0.0; |
michael@0 | 62 | y = CAIRO_COORD_MIN; |
michael@0 | 63 | } |
michael@0 | 64 | |
michael@0 | 65 | if (x + width > CAIRO_COORD_MAX) { |
michael@0 | 66 | width = CAIRO_COORD_MAX - x; |
michael@0 | 67 | } |
michael@0 | 68 | |
michael@0 | 69 | if (y + height > CAIRO_COORD_MAX) { |
michael@0 | 70 | height = CAIRO_COORD_MAX - y; |
michael@0 | 71 | } |
michael@0 | 72 | } |
michael@0 | 73 |