Bug 1673311 [wpt PR 26282] - Fieldset NG: Percentage heights for content elements...
[gecko.git] / widget / cocoa / VibrancyManager.h
blobc03a2868500856288aea1f6480187c278c3bb0e8
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"
12 #include "nsRegion.h"
13 #include "nsTArray.h"
14 #include "ViewRegion.h"
16 #import <Foundation/NSGeometry.h>
18 @class NSColor;
19 @class NSView;
20 class nsChildView;
22 namespace mozilla {
24 enum class VibrancyType {
25 LIGHT,
26 DARK,
27 TOOLTIP,
28 MENU,
29 HIGHLIGHTED_MENUITEM,
30 SHEET,
31 SOURCE_LIST,
32 SOURCE_LIST_SELECTION,
33 ACTIVE_SOURCE_LIST_SELECTION
36 /**
37 * VibrancyManager takes care of updating the vibrant regions of a window.
38 * Vibrancy is a visual look that was introduced on OS X starting with 10.10.
39 * An app declares vibrant window regions to the window server, and the window
40 * server will display a blurred rendering of the screen contents from behind
41 * the window in these areas, behind the actual window contents. Consequently,
42 * the effect is only visible in areas where the window contents are not
43 * completely opaque. Usually this is achieved by clearing the background of
44 * the window prior to drawing in the vibrant areas. This is possible even if
45 * the window is declared as opaque.
47 class VibrancyManager {
48 public:
49 /**
50 * Create a new VibrancyManager instance and provide it with an NSView
51 * to attach NSVisualEffectViews to.
53 * @param aCoordinateConverter The nsChildView to use for converting
54 * nsIntRect device pixel coordinates into Cocoa NSRect coordinates. Must
55 * outlive this VibrancyManager instance.
56 * @param aContainerView The view that's going to be the superview of the
57 * NSVisualEffectViews which will be created for vibrant regions.
59 VibrancyManager(const nsChildView& aCoordinateConverter, NSView* aContainerView)
60 : mCoordinateConverter(aCoordinateConverter), mContainerView(aContainerView) {}
62 /**
63 * Update the placement of the NSVisualEffectViews inside the container
64 * NSView so that they cover aRegion, and create new NSVisualEffectViews
65 * or remove existing ones as needed.
66 * @param aType The vibrancy type to use in the region.
67 * @param aRegion The vibrant area, in device pixels.
68 * @return Whether the region changed.
70 bool UpdateVibrantRegion(VibrancyType aType, const LayoutDeviceIntRegion& aRegion);
72 bool HasVibrantRegions() { return !mVibrantRegions.IsEmpty(); }
74 LayoutDeviceIntRegion GetUnionOfVibrantRegions() const;
76 /**
77 * Create an NSVisualEffectView for the specified vibrancy type. The return
78 * value is not autoreleased. We return an object of type NSView* because we
79 * compile with an SDK that does not contain a definition for
80 * NSVisualEffectView.
81 * @param aIsContainer Whether this NSView will have child views. This value
82 * affects hit testing: Container views will pass through
83 * hit testing requests to their children, and leaf views
84 * will be transparent to hit testing.
86 static NSView* CreateEffectView(VibrancyType aType, BOOL aIsContainer = NO);
88 protected:
89 const nsChildView& mCoordinateConverter;
90 NSView* mContainerView;
91 nsClassHashtable<nsUint32HashKey, ViewRegion> mVibrantRegions;
94 } // namespace mozilla
96 #endif // VibrancyManager_h