Bug 1880804 [wpt PR 44645] - Implement constructor in RTCEncodedVideoFrame, a=testonly
[gecko.git] / widget / nsAutoRollup.h
blobf6f3685887aad96bc1cb04ad096b2375a3f430ea
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 #ifndef nsAutoRollup_h__
6 #define nsAutoRollup_h__
8 #include "mozilla/Attributes.h" // for MOZ_RAII
9 #include "mozilla/StaticPtr.h" // for StaticRefPtr
10 #include "nsIContent.h"
12 namespace mozilla {
13 namespace widget {
15 // A situation can occur when a mouse event occurs over a menu label while the
16 // menu popup is already open. The expected behaviour is to close the popup.
17 // This happens by calling nsIRollupListener::Rollup before the mouse event is
18 // processed. However, in cases where the mouse event is not consumed, this
19 // event will then get targeted at the menu label causing the menu to open
20 // again. To prevent this, we store in sLastRollup a reference to the popup
21 // that was closed during the Rollup call, and prevent this popup from
22 // reopening while processing the mouse event.
23 // sLastRollup can only be set while an nsAutoRollup is in scope;
24 // when it goes out of scope sLastRollup is cleared automatically.
25 // As sLastRollup is static, it can be retrieved by calling
26 // nsAutoRollup::GetLastRollup.
27 class MOZ_RAII nsAutoRollup {
28 public:
29 nsAutoRollup();
30 ~nsAutoRollup();
32 // Convenience constructor that creates a nsAutoRollup and also sets
33 // the last rollup.
34 explicit nsAutoRollup(nsIContent* aRollup);
36 static void SetLastRollup(nsIContent* aLastRollup);
37 // Return the popup that was last rolled up, or null if there isn't one.
38 static nsIContent* GetLastRollup();
40 private:
41 // Whether sLastRollup was clear when this nsAutoRollup
42 // was created.
43 bool mWasClear;
45 // The number of nsAutoRollup instances active.
46 static uint32_t sCount;
47 // The last rolled up popup.
48 static StaticRefPtr<nsIContent> sLastRollup;
51 } // namespace widget
52 } // namespace mozilla
54 #endif // nsAutoRollup_h__