LCOV - code coverage report
Current view: top level - layout/xul - nsXULLabelFrame.cpp (source / functions) Hit Total Coverage
Test: output.info Lines: 22 36 61.1 %
Date: 2017-07-14 16:53:18 Functions: 6 7 85.7 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
       2             : /* This Source Code Form is subject to the terms of the Mozilla Public
       3             :  * License, v. 2.0. If a copy of the MPL was not distributed with this
       4             :  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
       5             : 
       6             : /* derived class of nsBlockFrame used for xul:label elements */
       7             : 
       8             : #include "mozilla/EventStateManager.h"
       9             : #include "nsXULLabelFrame.h"
      10             : #include "nsHTMLParts.h"
      11             : #include "nsNameSpaceManager.h"
      12             : 
      13             : using namespace mozilla;
      14             : 
      15             : nsIFrame*
      16           5 : NS_NewXULLabelFrame(nsIPresShell* aPresShell, nsStyleContext* aContext)
      17             : {
      18           5 :   nsXULLabelFrame* it = new (aPresShell) nsXULLabelFrame(aContext);
      19           5 :   it->AddStateBits(NS_BLOCK_FORMATTING_CONTEXT_STATE_BITS);
      20           5 :   return it;
      21             : }
      22             : 
      23           5 : NS_IMPL_FRAMEARENA_HELPERS(nsXULLabelFrame)
      24             : 
      25             : // If you make changes to this function, check its counterparts
      26             : // in nsBoxFrame and nsTextBoxFrame
      27             : nsresult
      28           9 : nsXULLabelFrame::RegUnregAccessKey(bool aDoReg)
      29             : {
      30             :   // if we have no content, we can't do anything
      31           9 :   if (!mContent)
      32           0 :     return NS_ERROR_FAILURE;
      33             : 
      34             :   // To filter out <label>s without a control attribute.
      35             :   // XXXjag a side-effect is that we filter out anonymous <label>s
      36             :   // in e.g. <menu>, <menuitem>, <button>. These <label>s inherit
      37             :   // |accesskey| and would otherwise register themselves, overwriting
      38             :   // the content we really meant to be registered.
      39           9 :   if (!mContent->HasAttr(kNameSpaceID_None, nsGkAtoms::control))
      40           9 :     return NS_OK;
      41             : 
      42           0 :   nsAutoString accessKey;
      43           0 :   mContent->GetAttr(kNameSpaceID_None, nsGkAtoms::accesskey, accessKey);
      44             : 
      45           0 :   if (accessKey.IsEmpty())
      46           0 :     return NS_OK;
      47             : 
      48             :   // With a valid PresContext we can get the ESM
      49             :   // and register the access key
      50           0 :   EventStateManager* esm = PresContext()->EventStateManager();
      51             : 
      52           0 :   uint32_t key = accessKey.First();
      53           0 :   if (aDoReg)
      54           0 :     esm->RegisterAccessKey(mContent, key);
      55             :   else
      56           0 :     esm->UnregisterAccessKey(mContent, key);
      57             : 
      58           0 :   return NS_OK;
      59             : }
      60             : 
      61             : /////////////////////////////////////////////////////////////////////////////
      62             : // nsIFrame
      63             : 
      64             : void
      65           5 : nsXULLabelFrame::Init(nsIContent*       aContent,
      66             :                       nsContainerFrame* aParent,
      67             :                       nsIFrame*         aPrevInFlow)
      68             : {
      69           5 :   nsBlockFrame::Init(aContent, aParent, aPrevInFlow);
      70             : 
      71             :   // register access key
      72           5 :   RegUnregAccessKey(true);
      73           5 : }
      74             : 
      75             : void
      76           4 : nsXULLabelFrame::DestroyFrom(nsIFrame* aDestructRoot)
      77             : {
      78             :   // unregister access key
      79           4 :   RegUnregAccessKey(false);
      80           4 :   nsBlockFrame::DestroyFrom(aDestructRoot);
      81           4 : }
      82             : 
      83             : nsresult
      84           7 : nsXULLabelFrame::AttributeChanged(int32_t aNameSpaceID,
      85             :                                   nsIAtom* aAttribute,
      86             :                                   int32_t aModType)
      87             : {
      88           7 :   nsresult rv = nsBlockFrame::AttributeChanged(aNameSpaceID,
      89           7 :                                                aAttribute, aModType);
      90             : 
      91             :   // If the accesskey changed, register for the new value
      92             :   // The old value has been unregistered in nsXULElement::SetAttr
      93           7 :   if (aAttribute == nsGkAtoms::accesskey || aAttribute == nsGkAtoms::control)
      94           0 :     RegUnregAccessKey(true);
      95             : 
      96           7 :   return rv;
      97             : }
      98             : 
      99             : /////////////////////////////////////////////////////////////////////////////
     100             : // Diagnostics
     101             : 
     102             : #ifdef DEBUG_FRAME_DUMP
     103             : nsresult
     104           0 : nsXULLabelFrame::GetFrameName(nsAString& aResult) const
     105             : {
     106           0 :   return MakeFrameName(NS_LITERAL_STRING("XULLabel"), aResult);
     107             : }
     108             : #endif

Generated by: LCOV version 1.13