Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(134)

Unified Diff: ui/views/cocoa/bridged_native_widget.mm

Issue 1718043003: MacViews: Clip contents for non-rectangular windows. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: ui/views/cocoa/bridged_native_widget.mm
diff --git a/ui/views/cocoa/bridged_native_widget.mm b/ui/views/cocoa/bridged_native_widget.mm
index 6f5dec0f96864ede56c8a7cf940de5ebf964aa92..c61991ee8f82148df257121fc8e402e961354069 100644
--- a/ui/views/cocoa/bridged_native_widget.mm
+++ b/ui/views/cocoa/bridged_native_widget.mm
@@ -4,6 +4,8 @@
#import "ui/views/cocoa/bridged_native_widget.h"
+#import <Quartz/Quartz.h>
tapted 2016/02/24 05:05:03 this can be grouped with the other <> includes, si
karandeepb 2016/02/25 03:31:06 Done. Aren't stdint.h and stddef.h standard librar
tapted 2016/02/25 08:07:21 I guess it's a bit arbitrary, but I generally see
+
#import <objc/runtime.h>
#include <stddef.h>
#include <stdint.h>
@@ -22,6 +24,7 @@
#include "ui/gfx/geometry/dip_util.h"
#import "ui/gfx/mac/coordinate_conversion.h"
#import "ui/gfx/mac/nswindow_frame_controls.h"
+#import "ui/gfx/path_mac.h"
#include "ui/gfx/screen.h"
#import "ui/views/cocoa/bridged_content_view.h"
#import "ui/views/cocoa/cocoa_mouse_capture.h"
@@ -683,13 +686,10 @@ void BridgedNativeWidget::OnSizeChanged() {
MaybeWaitForFrame(new_size);
}
- // 10.9 is unable to generate a window shadow from the composited CALayer, so
- // use Quartz.
- // We don't update the window mask during a live resize, instead it is done
- // after the resize is completed in viewDidEndLiveResize: in
- // BridgedContentView.
- if (base::mac::IsOSMavericksOrEarlier() && ![window_ inLiveResize])
- [bridged_view_ updateWindowMask];
+ [bridged_view_ onSizeChanged];
tapted 2016/02/24 05:05:03 Yeah, I'd call the method updateWindowMask and inv
karandeepb 2016/02/25 03:31:06 Done.
+
+ // Update mask path to match the bridged view's new window mask.
+ UpdateMaskPath();
}
void BridgedNativeWidget::OnVisibilityChanged() {
@@ -1244,4 +1244,29 @@ void BridgedNativeWidget::SetDraggable(bool draggable) {
[window_ setMovableByWindowBackground:YES];
}
+void BridgedNativeWidget::UpdateMaskPath() {
+ // We only set the mask layer for windows with non-rectangular masks.
+ if (![bridged_view_ windowMask])
tapted 2016/02/24 05:05:03 perhaps after this, do { // Removing a mask aft
karandeepb 2016/02/25 03:31:06 Done.
+ return;
+
+ CAShapeLayer* mask_layer = base::mac::ObjCCastStrict<CAShapeLayer>(
+ [[compositor_superview_ layer] mask]);
+ if (mask_layer) {
+ [mask_layer
+ setPath:gfx::CreateCGPathFromNSBezierPath([bridged_view_ windowMask])];
+ return;
+ }
+
+ // If mask layer does not exist yet, create one and set it as the background
karandeepb 2016/02/24 04:27:18 Another place to initialize the mask layer could b
tapted 2016/02/24 05:05:03 I think this here is OK. E.g. it's feasible that w
karandeepb 2016/02/25 03:31:06 Done.
+ // layer's mask. Clipping will be done based on the alpha channel of the mask
+ // layer.
+ base::scoped_nsobject<CAShapeLayer> mask([[CAShapeLayer alloc] init]);
+ [mask setPath:gfx::CreateCGPathFromNSBezierPath([bridged_view_ windowMask])];
+ [mask setBackgroundColor:[[NSColor clearColor] CGColor]];
tapted 2016/02/24 05:05:03 There's a CGColor constant for this (also I think
karandeepb 2016/02/25 03:31:06 Done.
+
+ CALayer* background_layer = [compositor_superview_ layer];
+ [background_layer setMask:mask];
+ [background_layer setMasksToBounds:YES];
+}
+
} // namespace views
« ui/views/cocoa/bridged_content_view.h ('K') | « ui/views/cocoa/bridged_native_widget.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698