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.

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

mercurial