LCOV - code coverage report
Current view: directory - content/events/src - nsDOMNotifyPaintEvent.cpp (source / functions) Found Hit Coverage
Test: app.info Lines: 93 0 0.0 %
Date: 2012-06-02 Functions: 11 0 0.0 %

       1                 : /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
       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 mozilla.org code.
      16                 :  *
      17                 :  * The Initial Developer of the Original Code is 
      18                 :  * Mozilla Corporation
      19                 :  * Portions created by the Initial Developer are Copyright (C) 2008
      20                 :  * the Initial Developer. All Rights Reserved.
      21                 :  *
      22                 :  * Contributor(s):
      23                 :  *  Robert O'Callahan <robert@ocallahan.org>
      24                 :  *
      25                 :  * Alternatively, the contents of this file may be used under the terms of
      26                 :  * either of the GNU General Public License Version 2 or later (the "GPL"),
      27                 :  * or 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 "base/basictypes.h"
      40                 : #include "IPC/IPCMessageUtils.h"
      41                 : #include "nsDOMNotifyPaintEvent.h"
      42                 : #include "nsContentUtils.h"
      43                 : #include "nsClientRect.h"
      44                 : #include "nsPaintRequest.h"
      45                 : #include "nsIFrame.h"
      46                 : 
      47               0 : nsDOMNotifyPaintEvent::nsDOMNotifyPaintEvent(nsPresContext* aPresContext,
      48                 :                                              nsEvent* aEvent,
      49                 :                                              PRUint32 aEventType,
      50                 :                                              nsInvalidateRequestList* aInvalidateRequests)
      51               0 : : nsDOMEvent(aPresContext, aEvent)
      52                 : {
      53               0 :   if (mEvent) {
      54               0 :     mEvent->message = aEventType;
      55                 :   }
      56               0 :   if (aInvalidateRequests) {
      57               0 :     mInvalidateRequests.SwapElements(aInvalidateRequests->mRequests);
      58                 :   }
      59               0 : }
      60                 : 
      61                 : DOMCI_DATA(NotifyPaintEvent, nsDOMNotifyPaintEvent)
      62                 : 
      63               0 : NS_INTERFACE_MAP_BEGIN(nsDOMNotifyPaintEvent)
      64               0 :   NS_INTERFACE_MAP_ENTRY(nsIDOMNotifyPaintEvent)
      65               0 :   NS_DOM_INTERFACE_MAP_ENTRY_CLASSINFO(NotifyPaintEvent)
      66               0 : NS_INTERFACE_MAP_END_INHERITING(nsDOMEvent)
      67                 : 
      68               0 : NS_IMPL_ADDREF_INHERITED(nsDOMNotifyPaintEvent, nsDOMEvent)
      69               0 : NS_IMPL_RELEASE_INHERITED(nsDOMNotifyPaintEvent, nsDOMEvent)
      70                 : 
      71                 : nsRegion
      72               0 : nsDOMNotifyPaintEvent::GetRegion()
      73                 : {
      74               0 :   nsRegion r;
      75               0 :   bool isTrusted = nsContentUtils::IsCallerTrustedForRead();
      76               0 :   for (PRUint32 i = 0; i < mInvalidateRequests.Length(); ++i) {
      77               0 :     if (!isTrusted &&
      78               0 :         (mInvalidateRequests[i].mFlags & nsIFrame::INVALIDATE_CROSS_DOC))
      79               0 :       continue;
      80                 : 
      81               0 :     r.Or(r, mInvalidateRequests[i].mRect);
      82               0 :     r.SimplifyOutward(10);
      83                 :   }
      84                 :   return r;
      85                 : }
      86                 : 
      87                 : NS_IMETHODIMP
      88               0 : nsDOMNotifyPaintEvent::GetBoundingClientRect(nsIDOMClientRect** aResult)
      89                 : {
      90                 :   // Weak ref, since we addref it below
      91               0 :   nsClientRect* rect = new nsClientRect();
      92               0 :   if (!rect)
      93               0 :     return NS_ERROR_OUT_OF_MEMORY;
      94                 : 
      95               0 :   NS_ADDREF(*aResult = rect);
      96               0 :   if (!mPresContext)
      97               0 :     return NS_OK;
      98                 : 
      99               0 :   rect->SetLayoutRect(GetRegion().GetBounds());
     100               0 :   return NS_OK;
     101                 : }
     102                 : 
     103                 : NS_IMETHODIMP
     104               0 : nsDOMNotifyPaintEvent::GetClientRects(nsIDOMClientRectList** aResult)
     105                 : {
     106                 :   nsRefPtr<nsClientRectList> rectList =
     107               0 :     new nsClientRectList(static_cast<nsIDOMEvent*>(static_cast<nsDOMEvent*>(this)));
     108               0 :   if (!rectList)
     109               0 :     return NS_ERROR_OUT_OF_MEMORY;
     110                 : 
     111               0 :   nsRegion r = GetRegion();
     112               0 :   nsRegionRectIterator iter(r);
     113               0 :   for (const nsRect* rgnRect = iter.Next(); rgnRect; rgnRect = iter.Next()) {
     114               0 :     nsRefPtr<nsClientRect> rect = new nsClientRect();
     115               0 :     if (!rect)
     116               0 :       return NS_ERROR_OUT_OF_MEMORY;
     117                 :     
     118               0 :     rect->SetLayoutRect(*rgnRect);
     119               0 :     rectList->Append(rect);
     120                 :   }
     121                 : 
     122               0 :   rectList.forget(aResult);
     123               0 :   return NS_OK;
     124                 : }
     125                 : 
     126                 : NS_IMETHODIMP
     127               0 : nsDOMNotifyPaintEvent::GetPaintRequests(nsIDOMPaintRequestList** aResult)
     128                 : {
     129                 :   nsRefPtr<nsPaintRequestList> requests =
     130               0 :     new nsPaintRequestList(static_cast<nsDOMEvent*>(this));
     131               0 :   if (!requests)
     132               0 :     return NS_ERROR_OUT_OF_MEMORY;
     133                 : 
     134               0 :   bool isTrusted = nsContentUtils::IsCallerTrustedForRead();
     135               0 :   for (PRUint32 i = 0; i < mInvalidateRequests.Length(); ++i) {
     136               0 :     if (!isTrusted &&
     137               0 :         (mInvalidateRequests[i].mFlags & nsIFrame::INVALIDATE_CROSS_DOC))
     138               0 :       continue;
     139                 : 
     140               0 :     nsRefPtr<nsPaintRequest> r = new nsPaintRequest();
     141               0 :     if (!r)
     142               0 :       return NS_ERROR_OUT_OF_MEMORY;
     143               0 :     r->SetRequest(mInvalidateRequests[i]);
     144               0 :     requests->Append(r);
     145                 :   }
     146                 : 
     147               0 :   requests.forget(aResult);
     148               0 :   return NS_OK;
     149                 : }
     150                 : 
     151                 : void
     152               0 : nsDOMNotifyPaintEvent::Serialize(IPC::Message* aMsg,
     153                 :                                  bool aSerializeInterfaceType)
     154                 : {
     155               0 :   if (aSerializeInterfaceType) {
     156               0 :     IPC::WriteParam(aMsg, NS_LITERAL_STRING("notifypaintevent"));
     157                 :   }
     158                 : 
     159               0 :   nsDOMEvent::Serialize(aMsg, false);
     160                 : 
     161               0 :   PRUint32 length = mInvalidateRequests.Length();
     162               0 :   IPC::WriteParam(aMsg, length);
     163               0 :   for (PRUint32 i = 0; i < length; ++i) {
     164               0 :     IPC::WriteParam(aMsg, mInvalidateRequests[i].mRect.x);
     165               0 :     IPC::WriteParam(aMsg, mInvalidateRequests[i].mRect.y);
     166               0 :     IPC::WriteParam(aMsg, mInvalidateRequests[i].mRect.width);
     167               0 :     IPC::WriteParam(aMsg, mInvalidateRequests[i].mRect.height);
     168               0 :     IPC::WriteParam(aMsg, mInvalidateRequests[i].mFlags);
     169                 :   }
     170               0 : }
     171                 : 
     172                 : bool
     173               0 : nsDOMNotifyPaintEvent::Deserialize(const IPC::Message* aMsg, void** aIter)
     174                 : {
     175               0 :   NS_ENSURE_TRUE(nsDOMEvent::Deserialize(aMsg, aIter), false);
     176                 : 
     177               0 :   PRUint32 length = 0;
     178               0 :   NS_ENSURE_TRUE(IPC::ReadParam(aMsg, aIter, &length), false);
     179               0 :   mInvalidateRequests.SetCapacity(length);
     180               0 :   for (PRUint32 i = 0; i < length; ++i) {
     181               0 :     nsInvalidateRequestList::Request req;
     182               0 :     NS_ENSURE_TRUE(IPC::ReadParam(aMsg, aIter, &req.mRect.x), false);
     183               0 :     NS_ENSURE_TRUE(IPC::ReadParam(aMsg, aIter, &req.mRect.y), false);
     184               0 :     NS_ENSURE_TRUE(IPC::ReadParam(aMsg, aIter, &req.mRect.width), false);
     185               0 :     NS_ENSURE_TRUE(IPC::ReadParam(aMsg, aIter, &req.mRect.height), false);
     186               0 :     NS_ENSURE_TRUE(IPC::ReadParam(aMsg, aIter, &req.mFlags), false);
     187               0 :     mInvalidateRequests.AppendElement(req);
     188                 :   }
     189                 : 
     190               0 :   return true;
     191                 : }
     192                 : 
     193               0 : nsresult NS_NewDOMNotifyPaintEvent(nsIDOMEvent** aInstancePtrResult,
     194                 :                                    nsPresContext* aPresContext,
     195                 :                                    nsEvent *aEvent,
     196                 :                                    PRUint32 aEventType,
     197                 :                                    nsInvalidateRequestList* aInvalidateRequests) 
     198                 : {
     199                 :   nsDOMNotifyPaintEvent* it =
     200                 :     new nsDOMNotifyPaintEvent(aPresContext, aEvent, aEventType,
     201               0 :                               aInvalidateRequests);
     202               0 :   if (nsnull == it) {
     203               0 :     return NS_ERROR_OUT_OF_MEMORY;
     204                 :   }
     205                 : 
     206               0 :   return CallQueryInterface(it, aInstancePtrResult);
     207                 : }

Generated by: LCOV version 1.7