no bug - Import translations from android-l10n r=release a=l10n CLOSED TREE
[gecko.git] / widget / cocoa / VibrancyManager.h
blobc70ec60a3b96bc63c8e1d452a220d9669117ff99
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 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)
55 : mCoordinateConverter(aCoordinateConverter),
56 mContainerView(aContainerView) {}
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 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