gecko-dev/layout/printing/PrintPreviewUserEventSuppressor.h
Jonathan Watt dbcde07e70 Bug 1551882. Refactor the print preview listener code to make its purpose clear. r=bobowen
Differential Revision: https://phabricator.services.mozilla.com/D31252

--HG--
rename : layout/printing/nsPrintPreviewListener.cpp => layout/printing/PrintPreviewUserEventSuppressor.cpp
rename : layout/printing/nsPrintPreviewListener.h => layout/printing/PrintPreviewUserEventSuppressor.h
extra : rebase_source : a2bfc2635d8cb98ee7c93597c6f805122e99111f
extra : amend_source : 2d3c11cbc8e07fa90b1960c4e1a4422c12f2761b
2019-05-16 23:16:11 +01:00

54 lines
1.7 KiB
C++

/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* vim: set ts=8 sts=2 et sw=2 tw=80: */
/* 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 mozilla_PrintPreviewUserEventSuppressor_h
#define mozilla_PrintPreviewUserEventSuppressor_h
#include "nsCOMPtr.h"
#include "nsIDOMEventListener.h"
#include "mozilla/Attributes.h"
namespace mozilla {
namespace dom {
class EventTarget;
} // namespace dom
/**
* A class that filters out certain user events targeted at the given event
* target (a document). Intended for use with the Print Preview document to
* stop users from doing anything that would break printing invariants. (For
* example, blocks opening of the context menu, interaction with form controls,
* content selection, etc.)
*/
class PrintPreviewUserEventSuppressor final : public nsIDOMEventListener {
public:
NS_DECL_ISUPPORTS
NS_DECL_NSIDOMEVENTLISTENER
explicit PrintPreviewUserEventSuppressor(dom::EventTarget* aTarget);
/**
* Must be called before releasing this object in order to break the strong
* reference cycle between ourselves and the document we're listening to,
* or else the objects in the cylce will be leaked (since this class does
* not participate in cycle collection).
*/
void StopSuppressing() { RemoveListeners(); }
private:
~PrintPreviewUserEventSuppressor() { RemoveListeners(); }
void AddListeners();
void RemoveListeners();
nsCOMPtr<mozilla::dom::EventTarget> mEventTarget;
};
} // namespace mozilla
#endif // mozilla_PrintPreviewUserEventSuppressor_h