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/Assertions.h"
11 #include "nsClassHashtable.h"
14 #include "ViewRegion.h"
16 #import <Foundation/NSGeometry.h>
24 enum class VibrancyType
{
31 SOURCE_LIST_SELECTION
,
32 ACTIVE_SOURCE_LIST_SELECTION
36 * VibrancyManager takes care of updating the vibrant regions of a window.
37 * Vibrancy is a visual look that was introduced on OS X starting with 10.10.
38 * An app declares vibrant window regions to the window server, and the window
39 * server will display a blurred rendering of the screen contents from behind
40 * the window in these areas, behind the actual window contents. Consequently,
41 * the effect is only visible in areas where the window contents are not
42 * completely opaque. Usually this is achieved by clearing the background of
43 * the window prior to drawing in the vibrant areas. This is possible even if
44 * the window is declared as opaque.
46 class VibrancyManager
{
49 * Create a new VibrancyManager instance and provide it with an NSView
50 * to attach NSVisualEffectViews to.
52 * @param aCoordinateConverter The nsChildView to use for converting
53 * nsIntRect device pixel coordinates into Cocoa NSRect coordinates. Must
54 * outlive this VibrancyManager instance.
55 * @param aContainerView The view that's going to be the superview of the
56 * NSVisualEffectViews which will be created for vibrant regions.
58 VibrancyManager(const nsChildView
& aCoordinateConverter
, NSView
* aContainerView
)
59 : mCoordinateConverter(aCoordinateConverter
), mContainerView(aContainerView
) {}
62 * Update the placement of the NSVisualEffectViews inside the container
63 * NSView so that they cover aRegion, and create new NSVisualEffectViews
64 * or remove existing ones as needed.
65 * @param aType The vibrancy type to use in the region.
66 * @param aRegion The vibrant area, in device pixels.
67 * @return Whether the region changed.
69 bool UpdateVibrantRegion(VibrancyType aType
, const LayoutDeviceIntRegion
& aRegion
);
71 bool HasVibrantRegions() { return !mVibrantRegions
.IsEmpty(); }
73 LayoutDeviceIntRegion
GetUnionOfVibrantRegions() const;
76 * Create an NSVisualEffectView for the specified vibrancy type. The return
77 * value is not autoreleased. We return an object of type NSView* because we
78 * compile with an SDK that does not contain a definition for
80 * @param aIsContainer Whether this NSView will have child views. This value
81 * affects hit testing: Container views will pass through
82 * hit testing requests to their children, and leaf views
83 * will be transparent to hit testing.
85 static NSView
* CreateEffectView(VibrancyType aType
, BOOL aIsContainer
= NO
);
88 const nsChildView
& mCoordinateConverter
;
89 NSView
* mContainerView
;
90 nsClassHashtable
<nsUint32HashKey
, ViewRegion
> mVibrantRegions
;
93 } // namespace mozilla
95 #endif // VibrancyManager_h