LCOV - code coverage report
Current view: directory - content/svg/content/src - nsDOMSVGZoomEvent.cpp (source / functions) Found Hit Coverage
Test: app.info Lines: 54 0 0.0 %
Date: 2012-06-02 Functions: 10 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 SVG Project code.
      16                 :  *
      17                 :  * The Initial Developer of the Original Code is Jonathan Watt.
      18                 :  * Portions created by the Initial Developer are Copyright (C) 2005
      19                 :  * the Initial Developer. All Rights Reserved.
      20                 :  *
      21                 :  * Contributor(s):
      22                 :  *   Jonathan Watt <jonathan.watt@strath.ac.uk> (original author)
      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                 : #include "nsDOMSVGZoomEvent.h"
      39                 : #include "nsContentUtils.h"
      40                 : #include "nsSVGRect.h"
      41                 : #include "DOMSVGPoint.h"
      42                 : #include "nsSVGSVGElement.h"
      43                 : #include "nsIDOMSVGSVGElement.h"
      44                 : #include "nsIContent.h"
      45                 : #include "nsIPresShell.h"
      46                 : #include "nsIDocument.h"
      47                 : #include "mozilla/dom/Element.h"
      48                 : 
      49                 : using namespace mozilla;
      50                 : using namespace mozilla::dom;
      51                 : 
      52                 : //----------------------------------------------------------------------
      53                 : // Implementation
      54                 : 
      55               0 : nsDOMSVGZoomEvent::nsDOMSVGZoomEvent(nsPresContext* aPresContext,
      56                 :                                      nsGUIEvent* aEvent)
      57                 :   : nsDOMUIEvent(aPresContext,
      58               0 :                  aEvent ? aEvent : new nsGUIEvent(false, NS_SVG_ZOOM, 0))
      59                 : {
      60               0 :   if (aEvent) {
      61               0 :     mEventIsInternal = false;
      62                 :   }
      63                 :   else {
      64               0 :     mEventIsInternal = true;
      65               0 :     mEvent->eventStructType = NS_SVGZOOM_EVENT;
      66               0 :     mEvent->time = PR_Now();
      67                 :   }
      68                 : 
      69               0 :   mEvent->flags |= NS_EVENT_FLAG_CANT_CANCEL;
      70                 : 
      71                 :   // We must store the "Previous" and "New" values before this event is
      72                 :   // dispatched. Reading the values from the root 'svg' element after we've
      73                 :   // been dispatched is not an option since event handler code may change
      74                 :   // currentScale and currentTranslate in response to this event.
      75                 :   nsIPresShell *presShell;
      76               0 :   if (mPresContext && (presShell = mPresContext->GetPresShell())) {
      77               0 :     nsIDocument *doc = presShell->GetDocument();
      78               0 :     if (doc) {
      79               0 :       Element *rootElement = doc->GetRootElement();
      80               0 :       if (rootElement) {
      81                 :         // If the root element isn't an SVG 'svg' element this QI will fail
      82                 :         // (e.g. if this event was created by calling createEvent on a
      83                 :         // non-SVGDocument). In these circumstances the "New" and "Previous"
      84                 :         // properties will be left null which is probably what we want.
      85               0 :         nsCOMPtr<nsIDOMSVGSVGElement> svgElement = do_QueryInterface(rootElement);
      86               0 :         if (svgElement) {
      87                 :           nsSVGSVGElement *SVGSVGElement =
      88               0 :             static_cast<nsSVGSVGElement*>(rootElement);
      89                 :   
      90               0 :           mNewScale = SVGSVGElement->GetCurrentScale();
      91               0 :           mPreviousScale = SVGSVGElement->GetPreviousScale();
      92                 : 
      93                 :           const nsSVGTranslatePoint& translate =
      94               0 :             SVGSVGElement->GetCurrentTranslate();
      95                 :           mNewTranslate =
      96               0 :             new DOMSVGPoint(translate.GetX(), translate.GetY());
      97               0 :           mNewTranslate->SetReadonly(true);
      98                 : 
      99                 :           const nsSVGTranslatePoint& prevTranslate =
     100               0 :             SVGSVGElement->GetPreviousTranslate();
     101                 :           mPreviousTranslate =
     102               0 :             new DOMSVGPoint(prevTranslate.GetX(), prevTranslate.GetY());
     103               0 :           mPreviousTranslate->SetReadonly(true);
     104                 :         }
     105                 :       }
     106                 :     }
     107                 :   }
     108               0 : }
     109                 : 
     110                 : 
     111                 : //----------------------------------------------------------------------
     112                 : // nsISupports methods:
     113                 : 
     114               0 : NS_IMPL_ADDREF_INHERITED(nsDOMSVGZoomEvent, nsDOMUIEvent)
     115               0 : NS_IMPL_RELEASE_INHERITED(nsDOMSVGZoomEvent, nsDOMUIEvent)
     116                 : 
     117                 : DOMCI_DATA(SVGZoomEvent, nsDOMSVGZoomEvent)
     118                 : 
     119               0 : NS_INTERFACE_MAP_BEGIN(nsDOMSVGZoomEvent)
     120               0 :   NS_INTERFACE_MAP_ENTRY(nsIDOMSVGZoomEvent)
     121               0 :   NS_DOM_INTERFACE_MAP_ENTRY_CLASSINFO(SVGZoomEvent)
     122               0 : NS_INTERFACE_MAP_END_INHERITING(nsDOMUIEvent)
     123                 : 
     124                 : 
     125                 : //----------------------------------------------------------------------
     126                 : // nsIDOMSVGZoomEvent methods:
     127                 : 
     128                 : /* readonly attribute SVGRect zoomRectScreen; */
     129               0 : NS_IMETHODIMP nsDOMSVGZoomEvent::GetZoomRectScreen(nsIDOMSVGRect **aZoomRectScreen)
     130                 : {
     131                 :   // The spec says about this attribute:
     132                 :   //
     133                 :   //   The specified zoom rectangle in screen units.
     134                 :   //   The object itself and its contents are both readonly.
     135                 :   //
     136                 :   // This is so badly underspecified we don't implement it. It was probably
     137                 :   // thrown in without much thought as a way of finding the zoom box ASV style
     138                 :   // zooming uses. I don't see how this is useful though since SVGZoom event's
     139                 :   // get dispatched *after* the zoom level has changed.
     140                 :   //
     141                 :   // Be sure to use NS_NewSVGReadonlyRect and not NS_NewSVGRect if we
     142                 :   // eventually do implement this!
     143                 : 
     144               0 :   *aZoomRectScreen = nsnull;
     145               0 :   NS_NOTYETIMPLEMENTED("nsDOMSVGZoomEvent::GetZoomRectScreen");
     146               0 :   return NS_ERROR_NOT_IMPLEMENTED;
     147                 : }
     148                 : 
     149                 : /* readonly attribute float previousScale; */
     150                 : NS_IMETHODIMP
     151               0 : nsDOMSVGZoomEvent::GetPreviousScale(float *aPreviousScale)
     152                 : {
     153               0 :   *aPreviousScale = mPreviousScale;
     154               0 :   return NS_OK;
     155                 : }
     156                 : 
     157                 : /* readonly attribute SVGPoint previousTranslate; */
     158                 : NS_IMETHODIMP
     159               0 : nsDOMSVGZoomEvent::GetPreviousTranslate(nsIDOMSVGPoint **aPreviousTranslate)
     160                 : {
     161               0 :   *aPreviousTranslate = mPreviousTranslate;
     162               0 :   NS_IF_ADDREF(*aPreviousTranslate);
     163               0 :   return NS_OK;
     164                 : }
     165                 : 
     166                 : /* readonly attribute float newScale; */
     167               0 : NS_IMETHODIMP nsDOMSVGZoomEvent::GetNewScale(float *aNewScale)
     168                 : {
     169               0 :   *aNewScale = mNewScale;
     170               0 :   return NS_OK;
     171                 : }
     172                 : 
     173                 : /* readonly attribute SVGPoint newTranslate; */
     174                 : NS_IMETHODIMP
     175               0 : nsDOMSVGZoomEvent::GetNewTranslate(nsIDOMSVGPoint **aNewTranslate)
     176                 : {
     177               0 :   *aNewTranslate = mNewTranslate;
     178               0 :   NS_IF_ADDREF(*aNewTranslate);
     179               0 :   return NS_OK;
     180                 : }
     181                 : 
     182                 : 
     183                 : ////////////////////////////////////////////////////////////////////////
     184                 : // Exported creation functions:
     185                 : 
     186                 : nsresult
     187               0 : NS_NewDOMSVGZoomEvent(nsIDOMEvent** aInstancePtrResult,
     188                 :                       nsPresContext* aPresContext,
     189                 :                       nsGUIEvent *aEvent)
     190                 : {
     191               0 :   nsDOMSVGZoomEvent* it = new nsDOMSVGZoomEvent(aPresContext, aEvent);
     192               0 :   if (!it)
     193               0 :     return NS_ERROR_OUT_OF_MEMORY;
     194                 : 
     195               0 :   return CallQueryInterface(it, aInstancePtrResult);
     196                 : }

Generated by: LCOV version 1.7