layout/xul/nsXULLabelFrame.cpp

Fri, 16 Jan 2015 18:13:44 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Fri, 16 Jan 2015 18:13:44 +0100
branch
TOR_BUG_9701
changeset 14
925c144e1f1f
permissions
-rw-r--r--

Integrate suggestion from review to improve consistency with existing 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/. */
     6 /* derived class of nsBlockFrame used for xul:label elements */
     8 #include "mozilla/EventStateManager.h"
     9 #include "nsXULLabelFrame.h"
    10 #include "nsHTMLParts.h"
    11 #include "nsNameSpaceManager.h"
    13 using namespace mozilla;
    15 nsIFrame*
    16 NS_NewXULLabelFrame(nsIPresShell* aPresShell, nsStyleContext* aContext)
    17 {
    18   nsXULLabelFrame* it = new (aPresShell) nsXULLabelFrame(aContext);
    20   it->SetFlags(NS_BLOCK_FLOAT_MGR | NS_BLOCK_MARGIN_ROOT);
    22   return it;
    23 }
    25 NS_IMPL_FRAMEARENA_HELPERS(nsXULLabelFrame)
    27 // If you make changes to this function, check its counterparts 
    28 // in nsBoxFrame and nsTextBoxFrame
    29 nsresult
    30 nsXULLabelFrame::RegUnregAccessKey(bool aDoReg)
    31 {
    32   // if we have no content, we can't do anything
    33   if (!mContent)
    34     return NS_ERROR_FAILURE;
    36   // To filter out <label>s without a control attribute.
    37   // XXXjag a side-effect is that we filter out anonymous <label>s
    38   // in e.g. <menu>, <menuitem>, <button>. These <label>s inherit
    39   // |accesskey| and would otherwise register themselves, overwriting
    40   // the content we really meant to be registered.
    41   if (!mContent->HasAttr(kNameSpaceID_None, nsGkAtoms::control))
    42     return NS_OK;
    44   nsAutoString accessKey;
    45   mContent->GetAttr(kNameSpaceID_None, nsGkAtoms::accesskey, accessKey);
    47   if (accessKey.IsEmpty())
    48     return NS_OK;
    50   // With a valid PresContext we can get the ESM 
    51   // and register the access key
    52   EventStateManager* esm = PresContext()->EventStateManager();
    54   uint32_t key = accessKey.First();
    55   if (aDoReg)
    56     esm->RegisterAccessKey(mContent, key);
    57   else
    58     esm->UnregisterAccessKey(mContent, key);
    60   return NS_OK;
    61 }
    63 /////////////////////////////////////////////////////////////////////////////
    64 // nsIFrame
    66 void
    67 nsXULLabelFrame::Init(nsIContent*      aContent,
    68                       nsIFrame*        aParent,
    69                       nsIFrame*        aPrevInFlow)
    70 {
    71   nsBlockFrame::Init(aContent, aParent, aPrevInFlow);
    73   // register access key
    74   RegUnregAccessKey(true);
    75 }
    77 void
    78 nsXULLabelFrame::DestroyFrom(nsIFrame* aDestructRoot)
    79 {
    80   // unregister access key
    81   RegUnregAccessKey(false);
    82   nsBlockFrame::DestroyFrom(aDestructRoot);
    83 } 
    85 nsresult
    86 nsXULLabelFrame::AttributeChanged(int32_t aNameSpaceID,
    87                                   nsIAtom* aAttribute,
    88                                   int32_t aModType)
    89 {
    90   nsresult rv = nsBlockFrame::AttributeChanged(aNameSpaceID, 
    91                                                aAttribute, aModType);
    93   // If the accesskey changed, register for the new value
    94   // The old value has been unregistered in nsXULElement::SetAttr
    95   if (aAttribute == nsGkAtoms::accesskey || aAttribute == nsGkAtoms::control)
    96     RegUnregAccessKey(true);
    98   return rv;
    99 }
   101 nsIAtom*
   102 nsXULLabelFrame::GetType() const
   103 {
   104   return nsGkAtoms::XULLabelFrame;
   105 }
   107 /////////////////////////////////////////////////////////////////////////////
   108 // Diagnostics
   110 #ifdef DEBUG_FRAME_DUMP
   111 nsresult
   112 nsXULLabelFrame::GetFrameName(nsAString& aResult) const
   113 {
   114   return MakeFrameName(NS_LITERAL_STRING("XULLabel"), aResult);
   115 }
   116 #endif

mercurial