LCOV - code coverage report
Current view: directory - layout/inspector/src - inFlasher.cpp (source / functions) Found Hit Coverage
Test: app.info Lines: 90 0 0.0 %
Date: 2012-06-02 Functions: 17 0 0.0 %

       1                 : /* ***** BEGIN LICENSE BLOCK *****
       2                 :  * Version: MPL 1.1/GPL 2.0/LGPL 2.1
       3                 :  *
       4                 :  * The contents of this file are subject to the Mozilla Public License Version
       5                 :  * 1.1 (the "License"); you may not use this file except in compliance with
       6                 :  * the License. You may obtain a copy of the License at
       7                 :  * http://www.mozilla.org/MPL/
       8                 :  *
       9                 :  * Software distributed under the License is distributed on an "AS IS" basis,
      10                 :  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
      11                 :  * for the specific language governing rights and limitations under the
      12                 :  * License.
      13                 :  *
      14                 :  * The Original Code is mozilla.org code.
      15                 :  *
      16                 :  * The Initial Developer of the Original Code is
      17                 :  * Netscape Communications Corporation.
      18                 :  * Portions created by the Initial Developer are Copyright (C) 2001
      19                 :  * the Initial Developer. All Rights Reserved.
      20                 :  *
      21                 :  * Contributor(s):
      22                 :  *   Joe Hewitt <hewitt@netscape.com> (original author)
      23                 :  *   Christopher A. Aillon <christopher@aillon.com>
      24                 :  *
      25                 :  * Alternatively, the contents of this file may be used under the terms of
      26                 :  * either the GNU General Public License Version 2 or later (the "GPL"), or
      27                 :  * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
      28                 :  * in which case the provisions of the GPL or the LGPL are applicable instead
      29                 :  * of those above. If you wish to allow use of your version of this file only
      30                 :  * under the terms of either the GPL or the LGPL, and not to allow others to
      31                 :  * use your version of this file under the terms of the MPL, indicate your
      32                 :  * decision by deleting the provisions above and replace them with the notice
      33                 :  * and other provisions required by the GPL or the LGPL. If you do not delete
      34                 :  * the provisions above, a recipient may use your version of this file under
      35                 :  * the terms of any one of the MPL, the GPL or the LGPL.
      36                 :  *
      37                 :  * ***** END LICENSE BLOCK ***** */
      38                 : 
      39                 : #include "inFlasher.h"
      40                 : #include "inLayoutUtils.h"
      41                 : 
      42                 : #include "nsIServiceManager.h"
      43                 : #include "nsIPresShell.h"
      44                 : #include "nsIFrame.h"
      45                 : #include "nsReadableUtils.h"
      46                 : #include "nsRenderingContext.h"
      47                 : 
      48                 : #include "prprf.h"
      49                 : 
      50                 : ///////////////////////////////////////////////////////////////////////////////
      51                 : 
      52               0 : inFlasher::inFlasher() :
      53                 :   mColor(NS_RGB(0,0,0)),
      54                 :   mThickness(0),
      55               0 :   mInvert(false)
      56                 : {
      57               0 : }
      58                 : 
      59               0 : inFlasher::~inFlasher()
      60                 : {
      61               0 : }
      62                 : 
      63               0 : NS_IMPL_ISUPPORTS1(inFlasher, inIFlasher)
      64                 : 
      65                 : ///////////////////////////////////////////////////////////////////////////////
      66                 : // inIFlasher
      67                 : 
      68                 : NS_IMETHODIMP
      69               0 : inFlasher::GetColor(nsAString& aColor)
      70                 : {
      71                 :   // Copied from nsGenericHTMLElement::ColorToString()
      72                 :   char buf[10];
      73                 :   PR_snprintf(buf, sizeof(buf), "#%02x%02x%02x",
      74               0 :               NS_GET_R(mColor), NS_GET_G(mColor), NS_GET_B(mColor));
      75               0 :   CopyASCIItoUTF16(buf, aColor);
      76                 : 
      77               0 :   return NS_OK;
      78                 : }
      79                 : 
      80                 : NS_IMETHODIMP
      81               0 : inFlasher::SetColor(const nsAString& aColor)
      82                 : {
      83               0 :   NS_ENSURE_FALSE(aColor.IsEmpty(), NS_ERROR_ILLEGAL_VALUE);
      84                 : 
      85               0 :   nsAutoString colorStr;
      86               0 :   colorStr.Assign(aColor);
      87                 : 
      88               0 :   if (colorStr.CharAt(0) != '#') {
      89               0 :     if (NS_ColorNameToRGB(colorStr, &mColor)) {
      90               0 :       return NS_OK;
      91                 :     }
      92                 :   }
      93                 :   else {
      94               0 :     colorStr.Cut(0, 1);
      95               0 :     if (NS_HexToRGB(colorStr, &mColor)) {
      96               0 :       return NS_OK;
      97                 :     }
      98                 :   }
      99                 : 
     100               0 :   return NS_ERROR_ILLEGAL_VALUE;
     101                 : }
     102                 : 
     103                 : NS_IMETHODIMP
     104               0 : inFlasher::GetThickness(PRUint16 *aThickness)
     105                 : {
     106               0 :   NS_PRECONDITION(aThickness, "Null pointer");
     107               0 :   *aThickness = mThickness;
     108               0 :   return NS_OK;
     109                 : }
     110                 : 
     111                 : NS_IMETHODIMP
     112               0 : inFlasher::SetThickness(PRUint16 aThickness)
     113                 : {
     114               0 :   mThickness = aThickness;
     115               0 :   return NS_OK;
     116                 : }
     117                 : 
     118                 : NS_IMETHODIMP
     119               0 : inFlasher::GetInvert(bool *aInvert)
     120                 : {
     121               0 :   NS_PRECONDITION(aInvert, "Null pointer");
     122               0 :   *aInvert = mInvert;
     123               0 :   return NS_OK;
     124                 : }
     125                 : 
     126                 : NS_IMETHODIMP
     127               0 : inFlasher::SetInvert(bool aInvert)
     128                 : {
     129               0 :   mInvert = aInvert;
     130               0 :   return NS_OK;
     131                 : }
     132                 : 
     133                 : NS_IMETHODIMP
     134               0 : inFlasher::RepaintElement(nsIDOMElement* aElement)
     135                 : {
     136               0 :   NS_ENSURE_ARG_POINTER(aElement);
     137               0 :   nsIFrame* frame = inLayoutUtils::GetFrameFor(aElement);
     138               0 :   if (!frame) return NS_OK;
     139                 : 
     140               0 :   frame->Invalidate(frame->GetRect());
     141                 : 
     142               0 :   return NS_OK;
     143                 : }
     144                 : 
     145                 : NS_IMETHODIMP
     146               0 : inFlasher::DrawElementOutline(nsIDOMElement* aElement)
     147                 : {
     148               0 :   NS_ENSURE_ARG_POINTER(aElement);
     149               0 :   nsCOMPtr<nsIDOMWindow> window = inLayoutUtils::GetWindowFor(aElement);
     150               0 :   if (!window) return NS_OK;
     151               0 :   nsCOMPtr<nsIPresShell> presShell = inLayoutUtils::GetPresShellFor(window);
     152               0 :   if (!presShell) return NS_OK;
     153                 : 
     154               0 :   nsIFrame* frame = inLayoutUtils::GetFrameFor(aElement);
     155                 : 
     156               0 :   bool isFirstFrame = true;
     157                 : 
     158               0 :   while (frame) {
     159               0 :     nsPoint offset;
     160               0 :     nsIWidget* widget = frame->GetNearestWidget(offset);
     161               0 :     if (widget) {
     162               0 :       nsRefPtr<nsRenderingContext> rcontext = new nsRenderingContext();
     163                 :       rcontext->Init(frame->PresContext()->DeviceContext(),
     164               0 :                      widget->GetThebesSurface());
     165                 : 
     166               0 :       nsRect rect(offset, frame->GetSize());
     167               0 :       if (mInvert) {
     168               0 :         rcontext->InvertRect(rect);
     169                 :       }
     170                 : 
     171               0 :       bool isLastFrame = frame->GetNextContinuation() == nsnull;
     172                 :       DrawOutline(rect.x, rect.y, rect.width, rect.height, rcontext,
     173               0 :                   isFirstFrame, isLastFrame);
     174               0 :       isFirstFrame = false;
     175                 :     }
     176               0 :     frame = frame->GetNextContinuation();
     177                 :   }
     178                 : 
     179               0 :   return NS_OK;
     180                 : }
     181                 : 
     182                 : NS_IMETHODIMP
     183               0 : inFlasher::ScrollElementIntoView(nsIDOMElement *aElement)
     184                 : {
     185               0 :   NS_ENSURE_ARG_POINTER(aElement);
     186               0 :   nsCOMPtr<nsIDOMWindow> window = inLayoutUtils::GetWindowFor(aElement);
     187               0 :   if (!window) {
     188               0 :     return NS_OK;
     189                 :   }
     190                 : 
     191               0 :   nsCOMPtr<nsIPresShell> presShell = inLayoutUtils::GetPresShellFor(window);
     192               0 :   if (!presShell) {
     193               0 :     return NS_OK;
     194                 :   }
     195                 : 
     196               0 :   nsCOMPtr<nsIContent> content = do_QueryInterface(aElement);
     197               0 :   presShell->ScrollContentIntoView(content,
     198                 :                                    NS_PRESSHELL_SCROLL_ANYWHERE /* VPercent */,
     199                 :                                    NS_PRESSHELL_SCROLL_ANYWHERE /* HPercent */,
     200               0 :                                    nsIPresShell::SCROLL_OVERFLOW_HIDDEN);
     201                 : 
     202               0 :   return NS_OK;
     203                 : }
     204                 : 
     205                 : ///////////////////////////////////////////////////////////////////////////////
     206                 : // inFlasher
     207                 : 
     208                 : void
     209               0 : inFlasher::DrawOutline(nscoord aX, nscoord aY, nscoord aWidth, nscoord aHeight,
     210                 :                        nsRenderingContext* aRenderContext,
     211                 :                        bool aDrawBegin, bool aDrawEnd)
     212                 : {
     213               0 :   aRenderContext->SetColor(mColor);
     214                 : 
     215               0 :   DrawLine(aX, aY, aWidth, DIR_HORIZONTAL, BOUND_OUTER, aRenderContext);
     216               0 :   if (aDrawBegin) {
     217               0 :     DrawLine(aX, aY, aHeight, DIR_VERTICAL, BOUND_OUTER, aRenderContext);
     218                 :   }
     219               0 :   DrawLine(aX, aY+aHeight, aWidth, DIR_HORIZONTAL, BOUND_INNER, aRenderContext);
     220               0 :   if (aDrawEnd) {
     221               0 :     DrawLine(aX+aWidth, aY, aHeight, DIR_VERTICAL, BOUND_INNER, aRenderContext);
     222                 :   }
     223               0 : }
     224                 : 
     225                 : void
     226               0 : inFlasher::DrawLine(nscoord aX, nscoord aY, nscoord aLength,
     227                 :                     bool aDir, bool aBounds,
     228                 :                     nsRenderingContext* aRenderContext)
     229                 : {
     230               0 :   nscoord thickTwips = nsPresContext::CSSPixelsToAppUnits(mThickness);
     231               0 :   if (aDir) { // horizontal
     232               0 :     aRenderContext->FillRect(aX, aY+(aBounds?0:-thickTwips), aLength, thickTwips);
     233                 :   } else { // vertical
     234               0 :     aRenderContext->FillRect(aX+(aBounds?0:-thickTwips), aY, thickTwips, aLength);
     235                 :   }
     236               0 : }

Generated by: LCOV version 1.7