Bug 1253840 - Remove .ini file as it's no longer necessary by passing on all platform...
[gecko.git] / widget / cocoa / VibrancyManager.h
blobb85b8b1e80225703a531b738fda33c08626bcf23
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 TOOLTIP,
26 MENU,
27 HIGHLIGHTED_MENUITEM,
28 SOURCE_LIST,
29 SOURCE_LIST_SELECTION,
30 ACTIVE_SOURCE_LIST_SELECTION
33 /**
34 * VibrancyManager takes care of updating the vibrant regions of a window.
35 * Vibrancy is a visual look that was introduced on OS X starting with 10.10.
36 * An app declares vibrant window regions to the window server, and the window
37 * server will display a blurred rendering of the screen contents from behind
38 * the window in these areas, behind the actual window contents. Consequently,
39 * the effect is only visible in areas where the window contents are not
40 * completely opaque. Usually this is achieved by clearing the background of
41 * the window prior to drawing in the vibrant areas. This is possible even if
42 * the window is declared as opaque.
44 class VibrancyManager {
45 public:
46 /**
47 * Create a new VibrancyManager instance and provide it with an NSView
48 * to attach NSVisualEffectViews to.
50 * @param aCoordinateConverter The nsChildView to use for converting
51 * nsIntRect device pixel coordinates into Cocoa NSRect coordinates. Must
52 * outlive this VibrancyManager instance.
53 * @param aContainerView The view that's going to be the superview of the
54 * NSVisualEffectViews which will be created for vibrant regions.
56 VibrancyManager(const nsChildView& aCoordinateConverter, NSView* aContainerView)
57 : mCoordinateConverter(aCoordinateConverter), mContainerView(aContainerView) {}
59 /**
60 * Update the placement of the NSVisualEffectViews inside the container
61 * NSView so that they cover aRegion, and create new NSVisualEffectViews
62 * or remove existing ones as needed.
63 * @param aType The vibrancy type to use in the region.
64 * @param aRegion The vibrant area, in device pixels.
65 * @return Whether the region changed.
67 bool UpdateVibrantRegion(VibrancyType aType, const LayoutDeviceIntRegion& aRegion);
69 bool HasVibrantRegions() { return !mVibrantRegions.IsEmpty(); }
71 LayoutDeviceIntRegion GetUnionOfVibrantRegions() const;
73 /**
74 * Create an NSVisualEffectView for the specified vibrancy type. The return
75 * value is not autoreleased. We return an object of type NSView* because we
76 * compile with an SDK that does not contain a definition for
77 * NSVisualEffectView.
78 * @param aIsContainer Whether this NSView will have child views. This value
79 * affects hit testing: Container views will pass through
80 * hit testing requests to their children, and leaf views
81 * will be transparent to hit testing.
83 static NSView* CreateEffectView(VibrancyType aType, BOOL aIsContainer = NO);
85 protected:
86 const nsChildView& mCoordinateConverter;
87 NSView* mContainerView;
88 nsClassHashtable<nsUint32HashKey, ViewRegion> mVibrantRegions;
91 } // namespace mozilla
93 #endif // VibrancyManager_h