LCOV - code coverage report
Current view: directory - gfx/thebes - gfxRect.h (source / functions) Found Hit Coverage
Test: app.info Lines: 25 0 0.0 %
Date: 2012-06-02 Functions: 7 0 0.0 %

       1                 : /* -*- Mode: C++; tab-width: 20; indent-tabs-mode: nil; c-basic-offset: 4 -*-
       2                 :  * ***** BEGIN LICENSE BLOCK *****
       3                 :  * Version: MPL 1.1/GPL 2.0/LGPL 2.1
       4                 :  *
       5                 :  * The contents of this file are subject to the Mozilla Public License Version
       6                 :  * 1.1 (the "License"); you may not use this file except in compliance with
       7                 :  * the License. You may obtain a copy of the License at
       8                 :  * http://www.mozilla.org/MPL/
       9                 :  *
      10                 :  * Software distributed under the License is distributed on an "AS IS" basis,
      11                 :  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
      12                 :  * for the specific language governing rights and limitations under the
      13                 :  * License.
      14                 :  *
      15                 :  * The Original Code is Oracle Corporation code.
      16                 :  *
      17                 :  * The Initial Developer of the Original Code is Oracle Corporation.
      18                 :  * Portions created by the Initial Developer are Copyright (C) 2005
      19                 :  * the Initial Developer. All Rights Reserved.
      20                 :  *
      21                 :  * Contributor(s):
      22                 :  *   Stuart Parmenter <pavlov@pavlov.net>
      23                 :  *
      24                 :  * Alternatively, the contents of this file may be used under the terms of
      25                 :  * either the GNU General Public License Version 2 or later (the "GPL"), or
      26                 :  * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
      27                 :  * in which case the provisions of the GPL or the LGPL are applicable instead
      28                 :  * of those above. If you wish to allow use of your version of this file only
      29                 :  * under the terms of either the GPL or the LGPL, and not to allow others to
      30                 :  * use your version of this file under the terms of the MPL, indicate your
      31                 :  * decision by deleting the provisions above and replace them with the notice
      32                 :  * and other provisions required by the GPL or the LGPL. If you do not delete
      33                 :  * the provisions above, a recipient may use your version of this file under
      34                 :  * the terms of any one of the MPL, the GPL or the LGPL.
      35                 :  *
      36                 :  * ***** END LICENSE BLOCK ***** */
      37                 : 
      38                 : #ifndef GFX_RECT_H
      39                 : #define GFX_RECT_H
      40                 : 
      41                 : #include "nsAlgorithm.h"
      42                 : #include "gfxTypes.h"
      43                 : #include "gfxPoint.h"
      44                 : #include "gfxCore.h"
      45                 : #include "nsDebug.h"
      46                 : #include "mozilla/gfx/BaseMargin.h"
      47                 : #include "mozilla/gfx/BaseRect.h"
      48                 : #include "mozilla/Assertions.h"
      49                 : #include "nsRect.h"
      50                 : 
      51                 : struct gfxMargin : public mozilla::gfx::BaseMargin<gfxFloat, gfxMargin> {
      52                 :   typedef mozilla::gfx::BaseMargin<gfxFloat, gfxMargin> Super;
      53                 : 
      54                 :   // Constructors
      55                 :   gfxMargin() : Super() {}
      56                 :   gfxMargin(const gfxMargin& aMargin) : Super(aMargin) {}
      57                 :   gfxMargin(gfxFloat aLeft,  gfxFloat aTop, gfxFloat aRight, gfxFloat aBottom)
      58                 :     : Super(aLeft, aTop, aRight, aBottom) {}
      59                 : };
      60                 : 
      61                 : namespace mozilla {
      62                 :     namespace css {
      63                 :         enum Corner {
      64                 :             // this order is important!
      65                 :             eCornerTopLeft = 0,
      66                 :             eCornerTopRight = 1,
      67                 :             eCornerBottomRight = 2,
      68                 :             eCornerBottomLeft = 3,
      69                 :             eNumCorners = 4
      70                 :         };
      71                 :     }
      72                 : }
      73                 : #define NS_CORNER_TOP_LEFT mozilla::css::eCornerTopLeft
      74                 : #define NS_CORNER_TOP_RIGHT mozilla::css::eCornerTopRight
      75                 : #define NS_CORNER_BOTTOM_RIGHT mozilla::css::eCornerBottomRight
      76                 : #define NS_CORNER_BOTTOM_LEFT mozilla::css::eCornerBottomLeft
      77                 : #define NS_NUM_CORNERS mozilla::css::eNumCorners
      78                 : 
      79                 : #define NS_FOR_CSS_CORNERS(var_)                         \
      80                 :     for (mozilla::css::Corner var_ = NS_CORNER_TOP_LEFT; \
      81                 :          var_ <= NS_CORNER_BOTTOM_LEFT;                  \
      82                 :          var_++)
      83                 : 
      84               0 : static inline mozilla::css::Corner operator++(mozilla::css::Corner& corner, int) {
      85               0 :     NS_PRECONDITION(corner >= NS_CORNER_TOP_LEFT &&
      86                 :                     corner < NS_NUM_CORNERS, "Out of range corner");
      87               0 :     corner = mozilla::css::Corner(corner + 1);
      88               0 :     return corner;
      89                 : }
      90                 : 
      91                 : struct THEBES_API gfxRect :
      92                 :     public mozilla::gfx::BaseRect<gfxFloat, gfxRect, gfxPoint, gfxSize, gfxMargin> {
      93                 :     typedef mozilla::gfx::BaseRect<gfxFloat, gfxRect, gfxPoint, gfxSize, gfxMargin> Super;
      94                 : 
      95               0 :     gfxRect() : Super() {}
      96               0 :     gfxRect(const gfxPoint& aPos, const gfxSize& aSize) :
      97               0 :         Super(aPos, aSize) {}
      98               0 :     gfxRect(gfxFloat aX, gfxFloat aY, gfxFloat aWidth, gfxFloat aHeight) :
      99               0 :         Super(aX, aY, aWidth, aHeight) {}
     100                 :     gfxRect(const nsIntRect& aRect) :
     101                 :         Super(aRect.x, aRect.y, aRect.width, aRect.height) {}
     102                 : 
     103                 :     /**
     104                 :      * Return true if all components of this rect are within
     105                 :      * aEpsilon of integer coordinates, defined as
     106                 :      *   |round(coord) - coord| <= |aEpsilon|
     107                 :      * for x,y,width,height.
     108                 :      */
     109                 :     bool WithinEpsilonOfIntegerPixels(gfxFloat aEpsilon) const;
     110                 : 
     111               0 :     gfxPoint AtCorner(mozilla::css::Corner corner) const {
     112               0 :         switch (corner) {
     113               0 :             case NS_CORNER_TOP_LEFT: return TopLeft();
     114               0 :             case NS_CORNER_TOP_RIGHT: return TopRight();
     115               0 :             case NS_CORNER_BOTTOM_RIGHT: return BottomRight();
     116               0 :             case NS_CORNER_BOTTOM_LEFT: return BottomLeft();
     117                 :             default:
     118               0 :                 NS_ERROR("Invalid corner!");
     119                 :                 break;
     120                 :         }
     121               0 :         return gfxPoint(0.0, 0.0);
     122                 :     }
     123                 : 
     124                 :     gfxPoint CCWCorner(mozilla::css::Side side) const {
     125                 :         switch (side) {
     126                 :             case NS_SIDE_TOP: return TopLeft();
     127                 :             case NS_SIDE_RIGHT: return TopRight();
     128                 :             case NS_SIDE_BOTTOM: return BottomRight();
     129                 :             case NS_SIDE_LEFT: return BottomLeft();
     130                 :         }
     131                 :         MOZ_NOT_REACHED("Incomplet switch");
     132                 :     }
     133                 : 
     134                 :     gfxPoint CWCorner(mozilla::css::Side side) const {
     135                 :         switch (side) {
     136                 :             case NS_SIDE_TOP: return TopRight();
     137                 :             case NS_SIDE_RIGHT: return BottomRight();
     138                 :             case NS_SIDE_BOTTOM: return BottomLeft();
     139                 :             case NS_SIDE_LEFT: return TopLeft();
     140                 :         }
     141                 :         MOZ_NOT_REACHED("Incomplet switch");
     142                 :     }
     143                 : 
     144                 :     /* Conditions this border to Cairo's max coordinate space.
     145                 :      * The caller can check IsEmpty() after Condition() -- if it's TRUE,
     146                 :      * the caller can possibly avoid doing any extra rendering.
     147                 :      */
     148                 :     void Condition();
     149                 : 
     150                 :     void Scale(gfxFloat k) {
     151                 :         NS_ASSERTION(k >= 0.0, "Invalid (negative) scale factor");
     152                 :         x *= k;
     153                 :         y *= k;
     154                 :         width *= k;
     155                 :         height *= k;
     156                 :     }
     157                 : 
     158                 :     void Scale(gfxFloat sx, gfxFloat sy) {
     159                 :         NS_ASSERTION(sx >= 0.0, "Invalid (negative) scale factor");
     160                 :         NS_ASSERTION(sy >= 0.0, "Invalid (negative) scale factor");
     161                 :         x *= sx;
     162                 :         y *= sy;
     163                 :         width *= sx;
     164                 :         height *= sy;
     165                 :     }
     166                 : 
     167                 :     void ScaleInverse(gfxFloat k) {
     168                 :         NS_ASSERTION(k > 0.0, "Invalid (negative) scale factor");
     169                 :         x /= k;
     170                 :         y /= k;
     171                 :         width /= k;
     172                 :         height /= k;
     173                 :     }
     174                 : };
     175                 : 
     176                 : struct THEBES_API gfxCornerSizes {
     177                 :     gfxSize sizes[NS_NUM_CORNERS];
     178                 : 
     179                 :     gfxCornerSizes () { }
     180                 : 
     181                 :     gfxCornerSizes (gfxFloat v) {
     182                 :         for (int i = 0; i < NS_NUM_CORNERS; i++)
     183                 :             sizes[i].SizeTo(v, v);
     184                 :     }
     185                 : 
     186                 :     gfxCornerSizes (gfxFloat tl, gfxFloat tr, gfxFloat br, gfxFloat bl) {
     187                 :         sizes[NS_CORNER_TOP_LEFT].SizeTo(tl, tl);
     188                 :         sizes[NS_CORNER_TOP_RIGHT].SizeTo(tr, tr);
     189                 :         sizes[NS_CORNER_BOTTOM_RIGHT].SizeTo(br, br);
     190                 :         sizes[NS_CORNER_BOTTOM_LEFT].SizeTo(bl, bl);
     191                 :     }
     192                 : 
     193               0 :     gfxCornerSizes (const gfxSize& tl, const gfxSize& tr, const gfxSize& br, const gfxSize& bl) {
     194               0 :         sizes[NS_CORNER_TOP_LEFT] = tl;
     195               0 :         sizes[NS_CORNER_TOP_RIGHT] = tr;
     196               0 :         sizes[NS_CORNER_BOTTOM_RIGHT] = br;
     197               0 :         sizes[NS_CORNER_BOTTOM_LEFT] = bl;
     198               0 :     }
     199                 : 
     200               0 :     const gfxSize& operator[] (mozilla::css::Corner index) const {
     201               0 :         return sizes[index];
     202                 :     }
     203                 : 
     204                 :     gfxSize& operator[] (mozilla::css::Corner index) {
     205                 :         return sizes[index];
     206                 :     }
     207                 : 
     208                 :     const gfxSize TopLeft() const { return sizes[NS_CORNER_TOP_LEFT]; }
     209                 :     gfxSize& TopLeft() { return sizes[NS_CORNER_TOP_LEFT]; }
     210                 : 
     211                 :     const gfxSize TopRight() const { return sizes[NS_CORNER_TOP_RIGHT]; }
     212                 :     gfxSize& TopRight() { return sizes[NS_CORNER_TOP_RIGHT]; }
     213                 : 
     214                 :     const gfxSize BottomLeft() const { return sizes[NS_CORNER_BOTTOM_LEFT]; }
     215                 :     gfxSize& BottomLeft() { return sizes[NS_CORNER_BOTTOM_LEFT]; }
     216                 : 
     217                 :     const gfxSize BottomRight() const { return sizes[NS_CORNER_BOTTOM_RIGHT]; }
     218                 :     gfxSize& BottomRight() { return sizes[NS_CORNER_BOTTOM_RIGHT]; }
     219                 : };
     220                 : #endif /* GFX_RECT_H */

Generated by: LCOV version 1.7