Backed out changeset 2450366cf7ca (bug 1891629) for causing win msix mochitest failures
[gecko.git] / widget / cocoa / VibrancyManager.h
blob43adace794d837db430a2687d7c5acbdd98c9aa4
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/. */
7 #ifndef VibrancyManager_h
8 #define VibrancyManager_h
10 #include "mozilla/EnumeratedArray.h"
11 #include "Units.h"
13 @class NSView;
14 class nsChildView;
16 namespace mozilla {
18 class ViewRegion;
20 enum class VibrancyType {
21 // Add new values here, or update MaxEnumValue below if you add them after.
22 Titlebar,
25 template <>
26 struct MaxContiguousEnumValue<VibrancyType> {
27 static constexpr auto value = VibrancyType::Titlebar;
30 /**
31 * VibrancyManager takes care of updating the vibrant regions of a window.
32 * Vibrancy is a visual look that was introduced on OS X starting with 10.10.
33 * An app declares vibrant window regions to the window server, and the window
34 * server will display a blurred rendering of the screen contents from behind
35 * the window in these areas, behind the actual window contents. Consequently,
36 * the effect is only visible in areas where the window contents are not
37 * completely opaque. Usually this is achieved by clearing the background of
38 * the window prior to drawing in the vibrant areas. This is possible even if
39 * the window is declared as opaque.
41 class VibrancyManager {
42 public:
43 /**
44 * Create a new VibrancyManager instance and provide it with an NSView
45 * to attach NSVisualEffectViews to.
47 * @param aCoordinateConverter The nsChildView to use for converting
48 * nsIntRect device pixel coordinates into Cocoa NSRect coordinates. Must
49 * outlive this VibrancyManager instance.
50 * @param aContainerView The view that's going to be the superview of the
51 * NSVisualEffectViews which will be created for vibrant regions.
53 VibrancyManager(const nsChildView& aCoordinateConverter,
54 NSView* aContainerView);
56 ~VibrancyManager();
58 /**
59 * Update the placement of the NSVisualEffectViews inside the container
60 * NSView so that they cover aRegion, and create new NSVisualEffectViews
61 * or remove existing ones as needed.
62 * @param aType The vibrancy type to use in the region.
63 * @param aRegion The vibrant area, in device pixels.
64 * @return Whether the region changed.
66 bool UpdateVibrantRegion(VibrancyType aType,
67 const LayoutDeviceIntRegion& aRegion);
69 protected:
70 const nsChildView& mCoordinateConverter;
71 NSView* mContainerView;
72 EnumeratedArray<VibrancyType, UniquePtr<ViewRegion>> mVibrantRegions;
75 } // namespace mozilla
77 #endif // VibrancyManager_h