LCOV - code coverage report
Current view: directory - dom/base - nsBarProps.cpp (source / functions) Found Hit Coverage
Test: app.info Lines: 127 0 0.0 %
Date: 2012-06-02 Functions: 39 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                 :  * Netscape Communications Corporation.
      19                 :  * Portions created by the Initial Developer are Copyright (C) 1998
      20                 :  * the Initial Developer. All Rights Reserved.
      21                 :  *
      22                 :  * Contributor(s):
      23                 :  *   Travis Bogard <travis@netscape.com>
      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 "nsBarProps.h"
      40                 : 
      41                 : #include "nsCOMPtr.h"
      42                 : #include "nscore.h"
      43                 : #include "nsGlobalWindow.h"
      44                 : #include "nsStyleConsts.h"
      45                 : #include "nsIDocShell.h"
      46                 : #include "nsIScriptSecurityManager.h"
      47                 : #include "nsIScrollable.h"
      48                 : #include "nsIWebBrowserChrome.h"
      49                 : #include "nsIDOMWindow.h"
      50                 : #include "nsDOMClassInfoID.h"
      51                 : 
      52                 : //
      53                 : //  Basic (virtual) BarProp class implementation
      54                 : //
      55               0 : nsBarProp::nsBarProp(nsGlobalWindow *aWindow)
      56                 : {
      57               0 :   mDOMWindow = aWindow;
      58               0 :   nsISupports *supwin = static_cast<nsIScriptGlobalObject *>(aWindow);
      59               0 :   mDOMWindowWeakref = do_GetWeakReference(supwin);
      60               0 : }
      61                 : 
      62               0 : nsBarProp::~nsBarProp()
      63                 : {
      64               0 : }
      65                 : 
      66                 : 
      67                 : DOMCI_DATA(BarProp, nsBarProp)
      68                 : 
      69                 : // QueryInterface implementation for BarProp
      70               0 : NS_INTERFACE_MAP_BEGIN(nsBarProp)
      71               0 :   NS_INTERFACE_MAP_ENTRY(nsIDOMBarProp)
      72               0 :   NS_INTERFACE_MAP_ENTRY(nsISupports)
      73               0 :   NS_DOM_INTERFACE_MAP_ENTRY_CLASSINFO(BarProp)
      74               0 : NS_INTERFACE_MAP_END
      75                 : 
      76                 : 
      77               0 : NS_IMPL_ADDREF(nsBarProp)
      78               0 : NS_IMPL_RELEASE(nsBarProp)
      79                 : 
      80                 : NS_IMETHODIMP
      81               0 : nsBarProp::GetVisibleByFlag(bool *aVisible, PRUint32 aChromeFlag)
      82                 : {
      83               0 :   *aVisible = false;
      84                 : 
      85               0 :   nsCOMPtr<nsIWebBrowserChrome> browserChrome = GetBrowserChrome();
      86               0 :   NS_ENSURE_TRUE(browserChrome, NS_OK);
      87                 : 
      88                 :   PRUint32 chromeFlags;
      89                 : 
      90               0 :   NS_ENSURE_SUCCESS(browserChrome->GetChromeFlags(&chromeFlags),
      91                 :                     NS_ERROR_FAILURE);
      92               0 :   if (chromeFlags & aChromeFlag)
      93               0 :     *aVisible = true;
      94                 : 
      95               0 :   return NS_OK;
      96                 : }
      97                 : 
      98                 : NS_IMETHODIMP
      99               0 : nsBarProp::SetVisibleByFlag(bool aVisible, PRUint32 aChromeFlag)
     100                 : {
     101               0 :   nsCOMPtr<nsIWebBrowserChrome> browserChrome = GetBrowserChrome();
     102               0 :   NS_ENSURE_TRUE(browserChrome, NS_OK);
     103                 : 
     104               0 :   bool enabled = false;
     105                 : 
     106                 :   nsCOMPtr<nsIScriptSecurityManager>
     107               0 :            securityManager(do_GetService(NS_SCRIPTSECURITYMANAGER_CONTRACTID));
     108               0 :   if (securityManager)
     109               0 :     securityManager->IsCapabilityEnabled("UniversalXPConnect", &enabled);
     110               0 :   if (!enabled)
     111               0 :     return NS_OK;
     112                 : 
     113                 :   PRUint32 chromeFlags;
     114                 : 
     115               0 :   NS_ENSURE_SUCCESS(browserChrome->GetChromeFlags(&chromeFlags),
     116                 :                     NS_ERROR_FAILURE);
     117               0 :   if (aVisible)
     118               0 :     chromeFlags |= aChromeFlag;
     119                 :   else
     120               0 :     chromeFlags &= ~aChromeFlag;
     121               0 :   NS_ENSURE_SUCCESS(browserChrome->SetChromeFlags(chromeFlags),
     122                 :                     NS_ERROR_FAILURE);
     123                 : 
     124               0 :   return NS_OK;
     125                 : }
     126                 : 
     127                 : already_AddRefed<nsIWebBrowserChrome>
     128               0 : nsBarProp::GetBrowserChrome()
     129                 : {
     130                 :   // Check that the window is still alive.
     131               0 :   nsCOMPtr<nsIDOMWindow> domwin(do_QueryReferent(mDOMWindowWeakref));
     132               0 :   if (!domwin)
     133               0 :     return nsnull;
     134                 : 
     135               0 :   nsIWebBrowserChrome *browserChrome = nsnull;
     136               0 :   mDOMWindow->GetWebBrowserChrome(&browserChrome);
     137               0 :   return browserChrome;
     138                 : }
     139                 : 
     140                 : //
     141                 : // MenubarProp class implementation
     142                 : //
     143                 : 
     144               0 : nsMenubarProp::nsMenubarProp(nsGlobalWindow *aWindow) 
     145               0 :   : nsBarProp(aWindow)
     146                 : {
     147               0 : }
     148                 : 
     149               0 : nsMenubarProp::~nsMenubarProp()
     150                 : {
     151               0 : }
     152                 : 
     153                 : NS_IMETHODIMP
     154               0 : nsMenubarProp::GetVisible(bool *aVisible)
     155                 : {
     156                 :   return nsBarProp::GetVisibleByFlag(aVisible,
     157               0 :                                      nsIWebBrowserChrome::CHROME_MENUBAR);
     158                 : }
     159                 : 
     160                 : NS_IMETHODIMP
     161               0 : nsMenubarProp::SetVisible(bool aVisible)
     162                 : {
     163                 :   return nsBarProp::SetVisibleByFlag(aVisible,
     164               0 :                                      nsIWebBrowserChrome::CHROME_MENUBAR);
     165                 : }
     166                 : 
     167                 : //
     168                 : // ToolbarProp class implementation
     169                 : //
     170                 : 
     171               0 : nsToolbarProp::nsToolbarProp(nsGlobalWindow *aWindow)
     172               0 :   : nsBarProp(aWindow)
     173                 : {
     174               0 : }
     175                 : 
     176               0 : nsToolbarProp::~nsToolbarProp()
     177                 : {
     178               0 : }
     179                 : 
     180                 : NS_IMETHODIMP
     181               0 : nsToolbarProp::GetVisible(bool *aVisible)
     182                 : {
     183                 :   return nsBarProp::GetVisibleByFlag(aVisible,
     184               0 :                                      nsIWebBrowserChrome::CHROME_TOOLBAR);
     185                 : }
     186                 : 
     187                 : NS_IMETHODIMP
     188               0 : nsToolbarProp::SetVisible(bool aVisible)
     189                 : {
     190                 :   return nsBarProp::SetVisibleByFlag(aVisible,
     191               0 :                                      nsIWebBrowserChrome::CHROME_TOOLBAR);
     192                 : }
     193                 : 
     194                 : //
     195                 : // LocationbarProp class implementation
     196                 : //
     197                 : 
     198               0 : nsLocationbarProp::nsLocationbarProp(nsGlobalWindow *aWindow)
     199               0 :   : nsBarProp(aWindow)
     200                 : {
     201               0 : }
     202                 : 
     203               0 : nsLocationbarProp::~nsLocationbarProp()
     204                 : {
     205               0 : }
     206                 : 
     207                 : NS_IMETHODIMP
     208               0 : nsLocationbarProp::GetVisible(bool *aVisible)
     209                 : {
     210                 :   return
     211                 :     nsBarProp::GetVisibleByFlag(aVisible,
     212               0 :                                 nsIWebBrowserChrome::CHROME_LOCATIONBAR);
     213                 : }
     214                 : 
     215                 : NS_IMETHODIMP
     216               0 : nsLocationbarProp::SetVisible(bool aVisible)
     217                 : {
     218                 :   return
     219                 :     nsBarProp::SetVisibleByFlag(aVisible,
     220               0 :                                 nsIWebBrowserChrome::CHROME_LOCATIONBAR);
     221                 : }
     222                 : 
     223                 : //
     224                 : // PersonalbarProp class implementation
     225                 : //
     226                 : 
     227               0 : nsPersonalbarProp::nsPersonalbarProp(nsGlobalWindow *aWindow)
     228               0 :   : nsBarProp(aWindow)
     229                 : {
     230               0 : }
     231                 : 
     232               0 : nsPersonalbarProp::~nsPersonalbarProp()
     233                 : {
     234               0 : }
     235                 : 
     236                 : NS_IMETHODIMP
     237               0 : nsPersonalbarProp::GetVisible(bool *aVisible)
     238                 : {
     239                 :   return
     240                 :     nsBarProp::GetVisibleByFlag(aVisible,
     241               0 :                                 nsIWebBrowserChrome::CHROME_PERSONAL_TOOLBAR);
     242                 : }
     243                 : 
     244                 : NS_IMETHODIMP
     245               0 : nsPersonalbarProp::SetVisible(bool aVisible)
     246                 : {
     247                 :   return
     248                 :     nsBarProp::SetVisibleByFlag(aVisible,
     249               0 :                                 nsIWebBrowserChrome::CHROME_PERSONAL_TOOLBAR);
     250                 : }
     251                 : 
     252                 : //
     253                 : // StatusbarProp class implementation
     254                 : //
     255                 : 
     256               0 : nsStatusbarProp::nsStatusbarProp(nsGlobalWindow *aWindow)
     257               0 :   : nsBarProp(aWindow)
     258                 : {
     259               0 : }
     260                 : 
     261               0 : nsStatusbarProp::~nsStatusbarProp()
     262                 : {
     263               0 : }
     264                 : 
     265                 : NS_IMETHODIMP
     266               0 : nsStatusbarProp::GetVisible(bool *aVisible)
     267                 : {
     268                 :   return nsBarProp::GetVisibleByFlag(aVisible,
     269               0 :                                      nsIWebBrowserChrome::CHROME_STATUSBAR);
     270                 : }
     271                 : 
     272                 : NS_IMETHODIMP
     273               0 : nsStatusbarProp::SetVisible(bool aVisible)
     274                 : {
     275                 :   return nsBarProp::SetVisibleByFlag(aVisible,
     276               0 :                                      nsIWebBrowserChrome::CHROME_STATUSBAR);
     277                 : }
     278                 : 
     279                 : //
     280                 : // ScrollbarsProp class implementation
     281                 : //
     282                 : 
     283               0 : nsScrollbarsProp::nsScrollbarsProp(nsGlobalWindow *aWindow)
     284               0 : : nsBarProp(aWindow)
     285                 : {
     286               0 : }
     287                 : 
     288               0 : nsScrollbarsProp::~nsScrollbarsProp()
     289                 : {
     290               0 : }
     291                 : 
     292                 : NS_IMETHODIMP
     293               0 : nsScrollbarsProp::GetVisible(bool *aVisible)
     294                 : {
     295               0 :   *aVisible = true; // one assumes
     296                 : 
     297               0 :   nsCOMPtr<nsIDOMWindow> domwin(do_QueryReferent(mDOMWindowWeakref));
     298               0 :   if (domwin) { // dom window not deleted
     299                 :     nsCOMPtr<nsIScrollable> scroller =
     300               0 :       do_QueryInterface(mDOMWindow->GetDocShell());
     301                 : 
     302               0 :     if (scroller) {
     303                 :       PRInt32 prefValue;
     304               0 :       scroller->GetDefaultScrollbarPreferences(
     305               0 :                   nsIScrollable::ScrollOrientation_Y, &prefValue);
     306               0 :       if (prefValue == nsIScrollable::Scrollbar_Never) // try the other way
     307               0 :         scroller->GetDefaultScrollbarPreferences(
     308               0 :                     nsIScrollable::ScrollOrientation_X, &prefValue);
     309                 : 
     310               0 :       if (prefValue == nsIScrollable::Scrollbar_Never)
     311               0 :         *aVisible = false;
     312                 :     }
     313                 :   }
     314                 : 
     315               0 :   return NS_OK;
     316                 : }
     317                 : 
     318                 : NS_IMETHODIMP
     319               0 : nsScrollbarsProp::SetVisible(bool aVisible)
     320                 : {
     321               0 :   bool     enabled = false;
     322                 : 
     323                 :   nsCOMPtr<nsIScriptSecurityManager>
     324               0 :            securityManager(do_GetService(NS_SCRIPTSECURITYMANAGER_CONTRACTID));
     325               0 :   if (securityManager)
     326               0 :     securityManager->IsCapabilityEnabled("UniversalXPConnect", &enabled);
     327               0 :   if (!enabled)
     328               0 :     return NS_OK;
     329                 : 
     330                 :   /* Scrollbars, unlike the other barprops, implement visibility directly
     331                 :      rather than handing off to the superclass (and from there to the
     332                 :      chrome window) because scrollbar visibility uniquely applies only
     333                 :      to the window making the change (arguably. it does now, anyway.)
     334                 :      and because embedding apps have no interface for implementing this
     335                 :      themselves, and therefore the implementation must be internal. */
     336                 : 
     337               0 :   nsCOMPtr<nsIDOMWindow> domwin(do_QueryReferent(mDOMWindowWeakref));
     338               0 :   if (domwin) { // dom window must still exist. use away.
     339                 :     nsCOMPtr<nsIScrollable> scroller =
     340               0 :       do_QueryInterface(mDOMWindow->GetDocShell());
     341                 : 
     342               0 :     if (scroller) {
     343                 :       PRInt32 prefValue;
     344                 : 
     345               0 :       if (aVisible) {
     346               0 :         prefValue = nsIScrollable::Scrollbar_Auto;
     347                 :       } else {
     348               0 :         prefValue = nsIScrollable::Scrollbar_Never;
     349                 :       }
     350                 : 
     351               0 :       scroller->SetDefaultScrollbarPreferences(
     352               0 :                   nsIScrollable::ScrollOrientation_Y, prefValue);
     353               0 :       scroller->SetDefaultScrollbarPreferences(
     354               0 :                   nsIScrollable::ScrollOrientation_X, prefValue);
     355                 :     }
     356                 :   }
     357                 : 
     358                 :   /* Notably absent is the part where we notify the chrome window using
     359                 :      GetBrowserChrome()->SetChromeFlags(). Given the possibility of multiple
     360                 :      DOM windows (multiple top-level windows, even) within a single
     361                 :      chrome window, the historical concept of a single "has scrollbars"
     362                 :      flag in the chrome is inapplicable, and we can't tell at this level
     363                 :      whether we represent the particular DOM window that makes this decision
     364                 :      for the chrome.
     365                 : 
     366                 :      So only this object (and its corresponding DOM window) knows whether
     367                 :      scrollbars are visible. The corresponding chrome window will need to
     368                 :      ask (one of) its DOM window(s) when it needs to know about scrollbar
     369                 :      visibility, rather than caching its own copy of that information.
     370                 :   */
     371                 : 
     372               0 :   return NS_OK;
     373                 : }
     374                 : 

Generated by: LCOV version 1.7