layout/xul/nsXULLabelFrame.cpp

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/layout/xul/nsXULLabelFrame.cpp	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,116 @@
     1.4 +/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
     1.5 +/* This Source Code Form is subject to the terms of the Mozilla Public
     1.6 + * License, v. 2.0. If a copy of the MPL was not distributed with this
     1.7 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
     1.8 +
     1.9 +/* derived class of nsBlockFrame used for xul:label elements */
    1.10 +
    1.11 +#include "mozilla/EventStateManager.h"
    1.12 +#include "nsXULLabelFrame.h"
    1.13 +#include "nsHTMLParts.h"
    1.14 +#include "nsNameSpaceManager.h"
    1.15 +
    1.16 +using namespace mozilla;
    1.17 +
    1.18 +nsIFrame*
    1.19 +NS_NewXULLabelFrame(nsIPresShell* aPresShell, nsStyleContext* aContext)
    1.20 +{
    1.21 +  nsXULLabelFrame* it = new (aPresShell) nsXULLabelFrame(aContext);
    1.22 +  
    1.23 +  it->SetFlags(NS_BLOCK_FLOAT_MGR | NS_BLOCK_MARGIN_ROOT);
    1.24 +
    1.25 +  return it;
    1.26 +}
    1.27 +
    1.28 +NS_IMPL_FRAMEARENA_HELPERS(nsXULLabelFrame)
    1.29 +
    1.30 +// If you make changes to this function, check its counterparts 
    1.31 +// in nsBoxFrame and nsTextBoxFrame
    1.32 +nsresult
    1.33 +nsXULLabelFrame::RegUnregAccessKey(bool aDoReg)
    1.34 +{
    1.35 +  // if we have no content, we can't do anything
    1.36 +  if (!mContent)
    1.37 +    return NS_ERROR_FAILURE;
    1.38 +
    1.39 +  // To filter out <label>s without a control attribute.
    1.40 +  // XXXjag a side-effect is that we filter out anonymous <label>s
    1.41 +  // in e.g. <menu>, <menuitem>, <button>. These <label>s inherit
    1.42 +  // |accesskey| and would otherwise register themselves, overwriting
    1.43 +  // the content we really meant to be registered.
    1.44 +  if (!mContent->HasAttr(kNameSpaceID_None, nsGkAtoms::control))
    1.45 +    return NS_OK;
    1.46 +
    1.47 +  nsAutoString accessKey;
    1.48 +  mContent->GetAttr(kNameSpaceID_None, nsGkAtoms::accesskey, accessKey);
    1.49 +
    1.50 +  if (accessKey.IsEmpty())
    1.51 +    return NS_OK;
    1.52 +
    1.53 +  // With a valid PresContext we can get the ESM 
    1.54 +  // and register the access key
    1.55 +  EventStateManager* esm = PresContext()->EventStateManager();
    1.56 +
    1.57 +  uint32_t key = accessKey.First();
    1.58 +  if (aDoReg)
    1.59 +    esm->RegisterAccessKey(mContent, key);
    1.60 +  else
    1.61 +    esm->UnregisterAccessKey(mContent, key);
    1.62 +
    1.63 +  return NS_OK;
    1.64 +}
    1.65 +
    1.66 +/////////////////////////////////////////////////////////////////////////////
    1.67 +// nsIFrame
    1.68 +
    1.69 +void
    1.70 +nsXULLabelFrame::Init(nsIContent*      aContent,
    1.71 +                      nsIFrame*        aParent,
    1.72 +                      nsIFrame*        aPrevInFlow)
    1.73 +{
    1.74 +  nsBlockFrame::Init(aContent, aParent, aPrevInFlow);
    1.75 +
    1.76 +  // register access key
    1.77 +  RegUnregAccessKey(true);
    1.78 +}
    1.79 +
    1.80 +void
    1.81 +nsXULLabelFrame::DestroyFrom(nsIFrame* aDestructRoot)
    1.82 +{
    1.83 +  // unregister access key
    1.84 +  RegUnregAccessKey(false);
    1.85 +  nsBlockFrame::DestroyFrom(aDestructRoot);
    1.86 +} 
    1.87 +
    1.88 +nsresult
    1.89 +nsXULLabelFrame::AttributeChanged(int32_t aNameSpaceID,
    1.90 +                                  nsIAtom* aAttribute,
    1.91 +                                  int32_t aModType)
    1.92 +{
    1.93 +  nsresult rv = nsBlockFrame::AttributeChanged(aNameSpaceID, 
    1.94 +                                               aAttribute, aModType);
    1.95 +
    1.96 +  // If the accesskey changed, register for the new value
    1.97 +  // The old value has been unregistered in nsXULElement::SetAttr
    1.98 +  if (aAttribute == nsGkAtoms::accesskey || aAttribute == nsGkAtoms::control)
    1.99 +    RegUnregAccessKey(true);
   1.100 +
   1.101 +  return rv;
   1.102 +}
   1.103 +
   1.104 +nsIAtom*
   1.105 +nsXULLabelFrame::GetType() const
   1.106 +{
   1.107 +  return nsGkAtoms::XULLabelFrame;
   1.108 +}
   1.109 +
   1.110 +/////////////////////////////////////////////////////////////////////////////
   1.111 +// Diagnostics
   1.112 +
   1.113 +#ifdef DEBUG_FRAME_DUMP
   1.114 +nsresult
   1.115 +nsXULLabelFrame::GetFrameName(nsAString& aResult) const
   1.116 +{
   1.117 +  return MakeFrameName(NS_LITERAL_STRING("XULLabel"), aResult);
   1.118 +}
   1.119 +#endif

mercurial