LCOV - code coverage report
Current view: directory - layout/style - nsDOMMediaQueryList.h (source / functions) Found Hit Coverage
Test: app.info Lines: 4 1 25.0 %
Date: 2012-06-02 Functions: 8 1 12.5 %

       1                 : /* vim: set shiftwidth=2 tabstop=8 autoindent cindent expandtab: */
       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 nsDOMMediaQueryList.
      16                 :  *
      17                 :  * The Initial Developer of the Original Code is the Mozilla Foundation.
      18                 :  * Portions created by the Initial Developer are Copyright (C) 2011
      19                 :  * the Initial Developer. All Rights Reserved.
      20                 :  *
      21                 :  * Contributor(s):
      22                 :  *   L. David Baron <dbaron@dbaron.org>, Mozilla Corporation (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                 : /* implements DOM interface for querying and observing media queries */
      39                 : 
      40                 : #ifndef nsDOMMediaQueryList_h_
      41                 : #define nsDOMMediaQueryList_h_
      42                 : 
      43                 : #include "nsIDOMMediaQueryList.h"
      44                 : #include "nsCycleCollectionParticipant.h"
      45                 : #include "nsAutoPtr.h"
      46                 : #include "nsCOMPtr.h"
      47                 : #include "nsTArray.h"
      48                 : #include "prclist.h"
      49                 : 
      50                 : class nsPresContext;
      51                 : class nsMediaList;
      52                 : 
      53                 : class nsDOMMediaQueryList : public nsIDOMMediaQueryList,
      54                 :                             public PRCList
      55                 : {
      56                 : public:
      57                 :   // The caller who constructs is responsible for calling Evaluate
      58                 :   // before calling any other methods.
      59                 :   nsDOMMediaQueryList(nsPresContext *aPresContext,
      60                 :                       const nsAString &aMediaQueryList);
      61                 : private:
      62                 :   ~nsDOMMediaQueryList();
      63                 : 
      64                 : public:
      65               0 :   NS_DECL_CYCLE_COLLECTING_ISUPPORTS
      66            1464 :   NS_DECL_CYCLE_COLLECTION_CLASS(nsDOMMediaQueryList)
      67                 : 
      68                 :   NS_DECL_NSIDOMMEDIAQUERYLIST
      69                 : 
      70               0 :   struct HandleChangeData {
      71                 :     nsRefPtr<nsDOMMediaQueryList> mql;
      72                 :     nsCOMPtr<nsIDOMMediaQueryListListener> listener;
      73                 :   };
      74                 : 
      75                 :   typedef FallibleTArray< nsCOMPtr<nsIDOMMediaQueryListListener> > ListenerList;
      76                 :   typedef FallibleTArray<HandleChangeData> NotifyList;
      77                 : 
      78                 :   // Appends listeners that need notification to aListenersToNotify
      79                 :   void MediumFeaturesChanged(NotifyList &aListenersToNotify);
      80                 : 
      81               0 :   bool HasListeners() const { return !mListeners.IsEmpty(); }
      82                 : 
      83                 :   void RemoveAllListeners();
      84                 : 
      85                 : private:
      86                 :   void RecomputeMatches();
      87                 : 
      88                 :   // We only need a pointer to the pres context to support lazy
      89                 :   // reevaluation following dynamic changes.  However, this lazy
      90                 :   // reevaluation is perhaps somewhat important, since some usage
      91                 :   // patterns may involve the creation of large numbers of
      92                 :   // MediaQueryList objects which almost immediately become garbage
      93                 :   // (after a single call to the .matches getter).
      94                 :   //
      95                 :   // This pointer does make us a little more dependent on cycle
      96                 :   // collection.
      97                 :   //
      98                 :   // We have a non-null mPresContext for our entire lifetime except
      99                 :   // after cycle collection unlinking.  Having a non-null mPresContext
     100                 :   // is equivalent to being in that pres context's mDOMMediaQueryLists
     101                 :   // linked list.
     102                 :   nsRefPtr<nsPresContext> mPresContext;
     103                 : 
     104                 :   nsRefPtr<nsMediaList> mMediaList;
     105                 :   bool mMatches;
     106                 :   bool mMatchesValid;
     107                 :   ListenerList mListeners;
     108                 : };
     109                 : 
     110                 : #endif /* !defined(nsDOMMediaQueryList_h_) */

Generated by: LCOV version 1.7