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

Side by Side 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 unified diff | Download patch
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #import "ui/views/cocoa/bridged_native_widget.h" 5 #import "ui/views/cocoa/bridged_native_widget.h"
6 6
7 #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
8
7 #import <objc/runtime.h> 9 #import <objc/runtime.h>
8 #include <stddef.h> 10 #include <stddef.h>
9 #include <stdint.h> 11 #include <stdint.h>
10 12
11 #include "base/logging.h" 13 #include "base/logging.h"
12 #import "base/mac/foundation_util.h" 14 #import "base/mac/foundation_util.h"
13 #include "base/mac/mac_util.h" 15 #include "base/mac/mac_util.h"
14 #import "base/mac/sdk_forward_declarations.h" 16 #import "base/mac/sdk_forward_declarations.h"
15 #include "base/thread_task_runner_handle.h" 17 #include "base/thread_task_runner_handle.h"
16 #include "ui/accelerated_widget_mac/window_resize_helper_mac.h" 18 #include "ui/accelerated_widget_mac/window_resize_helper_mac.h"
17 #import "ui/base/cocoa/constrained_window/constrained_window_animation.h" 19 #import "ui/base/cocoa/constrained_window/constrained_window_animation.h"
18 #include "ui/base/hit_test.h" 20 #include "ui/base/hit_test.h"
19 #include "ui/base/ime/input_method.h" 21 #include "ui/base/ime/input_method.h"
20 #include "ui/base/ime/input_method_factory.h" 22 #include "ui/base/ime/input_method_factory.h"
21 #include "ui/gfx/display.h" 23 #include "ui/gfx/display.h"
22 #include "ui/gfx/geometry/dip_util.h" 24 #include "ui/gfx/geometry/dip_util.h"
23 #import "ui/gfx/mac/coordinate_conversion.h" 25 #import "ui/gfx/mac/coordinate_conversion.h"
24 #import "ui/gfx/mac/nswindow_frame_controls.h" 26 #import "ui/gfx/mac/nswindow_frame_controls.h"
27 #import "ui/gfx/path_mac.h"
25 #include "ui/gfx/screen.h" 28 #include "ui/gfx/screen.h"
26 #import "ui/views/cocoa/bridged_content_view.h" 29 #import "ui/views/cocoa/bridged_content_view.h"
27 #import "ui/views/cocoa/cocoa_mouse_capture.h" 30 #import "ui/views/cocoa/cocoa_mouse_capture.h"
28 #include "ui/views/cocoa/tooltip_manager_mac.h" 31 #include "ui/views/cocoa/tooltip_manager_mac.h"
29 #import "ui/views/cocoa/views_nswindow_delegate.h" 32 #import "ui/views/cocoa/views_nswindow_delegate.h"
30 #import "ui/views/cocoa/widget_owner_nswindow_adapter.h" 33 #import "ui/views/cocoa/widget_owner_nswindow_adapter.h"
31 #include "ui/views/view.h" 34 #include "ui/views/view.h"
32 #include "ui/views/views_delegate.h" 35 #include "ui/views/views_delegate.h"
33 #include "ui/views/widget/native_widget_mac.h" 36 #include "ui/views/widget/native_widget_mac.h"
34 #include "ui/views/widget/widget.h" 37 #include "ui/views/widget/widget.h"
(...skipping 641 matching lines...) Expand 10 before | Expand all | Expand 10 after
676 679
677 void BridgedNativeWidget::OnSizeChanged() { 680 void BridgedNativeWidget::OnSizeChanged() {
678 gfx::Size new_size = GetClientAreaSize(); 681 gfx::Size new_size = GetClientAreaSize();
679 native_widget_mac_->GetWidget()->OnNativeWidgetSizeChanged(new_size); 682 native_widget_mac_->GetWidget()->OnNativeWidgetSizeChanged(new_size);
680 if (layer()) { 683 if (layer()) {
681 UpdateLayerProperties(); 684 UpdateLayerProperties();
682 if ([window_ inLiveResize]) 685 if ([window_ inLiveResize])
683 MaybeWaitForFrame(new_size); 686 MaybeWaitForFrame(new_size);
684 } 687 }
685 688
686 // 10.9 is unable to generate a window shadow from the composited CALayer, so 689 [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.
687 // use Quartz. 690
688 // We don't update the window mask during a live resize, instead it is done 691 // Update mask path to match the bridged view's new window mask.
689 // after the resize is completed in viewDidEndLiveResize: in 692 UpdateMaskPath();
690 // BridgedContentView.
691 if (base::mac::IsOSMavericksOrEarlier() && ![window_ inLiveResize])
692 [bridged_view_ updateWindowMask];
693 } 693 }
694 694
695 void BridgedNativeWidget::OnVisibilityChanged() { 695 void BridgedNativeWidget::OnVisibilityChanged() {
696 OnVisibilityChangedTo([window_ isVisible]); 696 OnVisibilityChangedTo([window_ isVisible]);
697 } 697 }
698 698
699 void BridgedNativeWidget::OnVisibilityChangedTo(bool new_visibility) { 699 void BridgedNativeWidget::OnVisibilityChangedTo(bool new_visibility) {
700 if (window_visible_ == new_visibility) 700 if (window_visible_ == new_visibility)
701 return; 701 return;
702 702
(...skipping 534 matching lines...) Expand 10 before | Expand all | Expand 10 after
1237 void BridgedNativeWidget::SetDraggable(bool draggable) { 1237 void BridgedNativeWidget::SetDraggable(bool draggable) {
1238 [bridged_view_ setMouseDownCanMoveWindow:draggable]; 1238 [bridged_view_ setMouseDownCanMoveWindow:draggable];
1239 // AppKit will not update its cache of mouseDownCanMoveWindow unless something 1239 // AppKit will not update its cache of mouseDownCanMoveWindow unless something
1240 // changes. Previously we tried adding an NSView and removing it, but for some 1240 // changes. Previously we tried adding an NSView and removing it, but for some
1241 // reason it required reposting the mouse-down event, and didn't always work. 1241 // reason it required reposting the mouse-down event, and didn't always work.
1242 // Calling the below seems to be an effective solution. 1242 // Calling the below seems to be an effective solution.
1243 [window_ setMovableByWindowBackground:NO]; 1243 [window_ setMovableByWindowBackground:NO];
1244 [window_ setMovableByWindowBackground:YES]; 1244 [window_ setMovableByWindowBackground:YES];
1245 } 1245 }
1246 1246
1247 void BridgedNativeWidget::UpdateMaskPath() {
1248 // We only set the mask layer for windows with non-rectangular masks.
1249 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.
1250 return;
1251
1252 CAShapeLayer* mask_layer = base::mac::ObjCCastStrict<CAShapeLayer>(
1253 [[compositor_superview_ layer] mask]);
1254 if (mask_layer) {
1255 [mask_layer
1256 setPath:gfx::CreateCGPathFromNSBezierPath([bridged_view_ windowMask])];
1257 return;
1258 }
1259
1260 // 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.
1261 // layer's mask. Clipping will be done based on the alpha channel of the mask
1262 // layer.
1263 base::scoped_nsobject<CAShapeLayer> mask([[CAShapeLayer alloc] init]);
1264 [mask setPath:gfx::CreateCGPathFromNSBezierPath([bridged_view_ windowMask])];
1265 [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.
1266
1267 CALayer* background_layer = [compositor_superview_ layer];
1268 [background_layer setMask:mask];
1269 [background_layer setMasksToBounds:YES];
1270 }
1271
1247 } // namespace views 1272 } // namespace views
OLDNEW
« 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