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

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: Addressed review comments. 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..47b7bc39425100d3baa99692df04626968079183 100644
--- a/ui/views/cocoa/bridged_native_widget.mm
+++ b/ui/views/cocoa/bridged_native_widget.mm
@@ -4,6 +4,7 @@
#import "ui/views/cocoa/bridged_native_widget.h"
+#import <Quartz/Quartz.h>
#import <objc/runtime.h>
#include <stddef.h>
#include <stdint.h>
@@ -13,6 +14,7 @@
#include "base/mac/mac_util.h"
#import "base/mac/sdk_forward_declarations.h"
#include "base/thread_task_runner_handle.h"
+#import "third_party/google_toolbox_for_mac/src/AppKit/GTMNSBezierPath+CGPath.h"
#include "ui/accelerated_widget_mac/window_resize_helper_mac.h"
#import "ui/base/cocoa/constrained_window/constrained_window_animation.h"
#include "ui/base/hit_test.h"
@@ -683,13 +685,7 @@ 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];
+ UpdateMaskPath();
}
void BridgedNativeWidget::OnVisibilityChanged() {
@@ -1244,4 +1240,32 @@ void BridgedNativeWidget::SetDraggable(bool draggable) {
[window_ setMovableByWindowBackground:YES];
}
+void BridgedNativeWidget::UpdateMaskPath() {
+ [bridged_view_ updateWindowMask];
+
+ // We only set the mask layer for windows with non-rectangular masks.
+ if (![bridged_view_ windowMask]) {
+ // Removing a mask after adding one isn't currently supported.
+ DCHECK(![[compositor_superview_ layer] mask]);
+ return;
+ }
+
+ CAShapeLayer* mask_layer = base::mac::ObjCCastStrict<CAShapeLayer>(
+ [[compositor_superview_ layer] mask]);
+ if (mask_layer) {
+ [mask_layer setPath:[[bridged_view_ windowMask] gtm_CGPath]];
+ return;
+ }
+
+ // If mask layer does not exist yet, create one and set it as the background
+ // layer's mask. Clipping will be done based on the alpha channel of the mask
+ // layer.
+ mask_layer = [CAShapeLayer layer];
+ [mask_layer setPath:[[bridged_view_ windowMask] gtm_CGPath]];
+
+ CALayer* background_layer = [compositor_superview_ layer];
+ [background_layer setMask:mask_layer];
+ [background_layer setMasksToBounds:YES];
+}
+
} // namespace views
« ui/views/cocoa/bridged_content_view.mm ('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