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