author Noemi Erli <nerli@mozilla.com>
Tue, 26 Feb 2019 03:43:12 +0200
changeset 461110 3c030119c0dcf447dd1afe7165b2d6846a0bc7f0
parent 448947 6f3709b3878117466168c40affa7bca0b60cf75b
permissions -rw-r--r--
Backed out 10 changesets (bug 1505871) for wrench bustages CLOSED TREE Backed out changeset 045ab0ec3613 (bug 1505871) Backed out changeset 6486435a048d (bug 1505871) Backed out changeset 9be871042749 (bug 1505871) Backed out changeset 0007feaf988d (bug 1505871) Backed out changeset 3cb8fb01e77e (bug 1505871) Backed out changeset 2fff213d97e3 (bug 1505871) Backed out changeset 1ad20d485eca (bug 1505871) Backed out changeset 0fd8742fa662 (bug 1505871) Backed out changeset 1899600a7985 (bug 1505871) Backed out changeset f9578d20e54e (bug 1505871)

/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* This Source Code Form is subject to the terms of the Mozilla Public
 * License, v. 2.0. If a copy of the MPL was not distributed with this
 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
#ifndef nsAutoRollup_h__
#define nsAutoRollup_h__

#include "mozilla/Attributes.h"  // for MOZ_RAII
#include "mozilla/StaticPtr.h"   // for StaticRefPtr
#include "nsIContent.h"

namespace mozilla {
namespace widget {

// A situation can occur when a mouse event occurs over a menu label while the
// menu popup is already open. The expected behaviour is to close the popup.
// This happens by calling nsIRollupListener::Rollup before the mouse event is
// processed. However, in cases where the mouse event is not consumed, this
// event will then get targeted at the menu label causing the menu to open
// again. To prevent this, we store in sLastRollup a reference to the popup
// that was closed during the Rollup call, and prevent this popup from
// reopening while processing the mouse event.
// sLastRollup can only be set while an nsAutoRollup is in scope;
// when it goes out of scope sLastRollup is cleared automatically.
// As sLastRollup is static, it can be retrieved by calling
// nsAutoRollup::GetLastRollup.
class MOZ_RAII nsAutoRollup {

  // Convenience constructor that creates a nsAutoRollup and also sets
  // the last rollup.
  explicit nsAutoRollup(nsIContent* aRollup);

  static void SetLastRollup(nsIContent* aLastRollup);
  // Return the popup that was last rolled up, or null if there isn't one.
  static nsIContent* GetLastRollup();

  // Whether sLastRollup was clear when this nsAutoRollup
  // was created.
  bool mWasClear;

  // The number of nsAutoRollup instances active.
  static uint32_t sCount;
  // The last rolled up popup.
  static StaticRefPtr<nsIContent> sLastRollup;

}  // namespace widget
}  // namespace mozilla

#endif  // nsAutoRollup_h__