| OLD | NEW |
| 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> |
| 7 #import <objc/runtime.h> | 8 #import <objc/runtime.h> |
| 8 #include <stddef.h> | 9 #include <stddef.h> |
| 9 #include <stdint.h> | 10 #include <stdint.h> |
| 10 | 11 |
| 11 #include "base/logging.h" | 12 #include "base/logging.h" |
| 12 #import "base/mac/foundation_util.h" | 13 #import "base/mac/foundation_util.h" |
| 13 #include "base/mac/mac_util.h" | 14 #include "base/mac/mac_util.h" |
| 14 #import "base/mac/sdk_forward_declarations.h" | 15 #import "base/mac/sdk_forward_declarations.h" |
| 15 #include "base/thread_task_runner_handle.h" | 16 #include "base/thread_task_runner_handle.h" |
| 17 #import "third_party/google_toolbox_for_mac/src/AppKit/GTMNSBezierPath+CGPath.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" |
| 25 #include "ui/gfx/screen.h" | 27 #include "ui/gfx/screen.h" |
| (...skipping 650 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 676 | 678 |
| 677 void BridgedNativeWidget::OnSizeChanged() { | 679 void BridgedNativeWidget::OnSizeChanged() { |
| 678 gfx::Size new_size = GetClientAreaSize(); | 680 gfx::Size new_size = GetClientAreaSize(); |
| 679 native_widget_mac_->GetWidget()->OnNativeWidgetSizeChanged(new_size); | 681 native_widget_mac_->GetWidget()->OnNativeWidgetSizeChanged(new_size); |
| 680 if (layer()) { | 682 if (layer()) { |
| 681 UpdateLayerProperties(); | 683 UpdateLayerProperties(); |
| 682 if ([window_ inLiveResize]) | 684 if ([window_ inLiveResize]) |
| 683 MaybeWaitForFrame(new_size); | 685 MaybeWaitForFrame(new_size); |
| 684 } | 686 } |
| 685 | 687 |
| 686 // 10.9 is unable to generate a window shadow from the composited CALayer, so | 688 UpdateMaskPath(); |
| 687 // use Quartz. | |
| 688 // We don't update the window mask during a live resize, instead it is done | |
| 689 // after the resize is completed in viewDidEndLiveResize: in | |
| 690 // BridgedContentView. | |
| 691 if (base::mac::IsOSMavericksOrEarlier() && ![window_ inLiveResize]) | |
| 692 [bridged_view_ updateWindowMask]; | |
| 693 } | 689 } |
| 694 | 690 |
| 695 void BridgedNativeWidget::OnVisibilityChanged() { | 691 void BridgedNativeWidget::OnVisibilityChanged() { |
| 696 OnVisibilityChangedTo([window_ isVisible]); | 692 OnVisibilityChangedTo([window_ isVisible]); |
| 697 } | 693 } |
| 698 | 694 |
| 699 void BridgedNativeWidget::OnVisibilityChangedTo(bool new_visibility) { | 695 void BridgedNativeWidget::OnVisibilityChangedTo(bool new_visibility) { |
| 700 if (window_visible_ == new_visibility) | 696 if (window_visible_ == new_visibility) |
| 701 return; | 697 return; |
| 702 | 698 |
| (...skipping 454 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1157 } | 1153 } |
| 1158 | 1154 |
| 1159 // Set the layer first to create a layer-hosting view (not layer-backed). | 1155 // Set the layer first to create a layer-hosting view (not layer-backed). |
| 1160 [compositor_superview_ setLayer:background_layer]; | 1156 [compositor_superview_ setLayer:background_layer]; |
| 1161 [compositor_superview_ setWantsLayer:YES]; | 1157 [compositor_superview_ setWantsLayer:YES]; |
| 1162 | 1158 |
| 1163 // The UI compositor should always be the first subview, to ensure webviews | 1159 // The UI compositor should always be the first subview, to ensure webviews |
| 1164 // are drawn on top of it. | 1160 // are drawn on top of it. |
| 1165 DCHECK_EQ(0u, [[bridged_view_ subviews] count]); | 1161 DCHECK_EQ(0u, [[bridged_view_ subviews] count]); |
| 1166 [bridged_view_ addSubview:compositor_superview_]; | 1162 [bridged_view_ addSubview:compositor_superview_]; |
| 1163 |
| 1164 // Create a mask layer for background_layer if necessary. |
| 1165 UpdateMaskPath(); |
| 1167 } | 1166 } |
| 1168 | 1167 |
| 1169 void BridgedNativeWidget::UpdateLayerProperties() { | 1168 void BridgedNativeWidget::UpdateLayerProperties() { |
| 1170 DCHECK(layer()); | 1169 DCHECK(layer()); |
| 1171 DCHECK(compositor_superview_); | 1170 DCHECK(compositor_superview_); |
| 1172 gfx::Size size_in_dip = GetClientAreaSize(); | 1171 gfx::Size size_in_dip = GetClientAreaSize(); |
| 1173 layer()->SetBounds(gfx::Rect(size_in_dip)); | 1172 layer()->SetBounds(gfx::Rect(size_in_dip)); |
| 1174 | 1173 |
| 1175 float scale_factor = GetDeviceScaleFactorFromView(compositor_superview_); | 1174 float scale_factor = GetDeviceScaleFactorFromView(compositor_superview_); |
| 1176 compositor_->SetScaleAndSize(scale_factor, | 1175 compositor_->SetScaleAndSize(scale_factor, |
| (...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1237 void BridgedNativeWidget::SetDraggable(bool draggable) { | 1236 void BridgedNativeWidget::SetDraggable(bool draggable) { |
| 1238 [bridged_view_ setMouseDownCanMoveWindow:draggable]; | 1237 [bridged_view_ setMouseDownCanMoveWindow:draggable]; |
| 1239 // AppKit will not update its cache of mouseDownCanMoveWindow unless something | 1238 // AppKit will not update its cache of mouseDownCanMoveWindow unless something |
| 1240 // changes. Previously we tried adding an NSView and removing it, but for some | 1239 // 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. | 1240 // reason it required reposting the mouse-down event, and didn't always work. |
| 1242 // Calling the below seems to be an effective solution. | 1241 // Calling the below seems to be an effective solution. |
| 1243 [window_ setMovableByWindowBackground:NO]; | 1242 [window_ setMovableByWindowBackground:NO]; |
| 1244 [window_ setMovableByWindowBackground:YES]; | 1243 [window_ setMovableByWindowBackground:YES]; |
| 1245 } | 1244 } |
| 1246 | 1245 |
| 1246 void BridgedNativeWidget::UpdateMaskPath() { |
| 1247 [bridged_view_ updateWindowMask]; |
| 1248 |
| 1249 // We only set the mask layer for windows with non-rectangular masks. |
| 1250 if (![bridged_view_ windowMask]) { |
| 1251 // Removing a mask after adding one isn't currently supported. |
| 1252 DCHECK(![[compositor_superview_ layer] mask]); |
| 1253 return; |
| 1254 } |
| 1255 |
| 1256 CAShapeLayer* mask_layer = base::mac::ObjCCastStrict<CAShapeLayer>( |
| 1257 [[compositor_superview_ layer] mask]); |
| 1258 if (mask_layer) { |
| 1259 [mask_layer setPath:[[bridged_view_ windowMask] gtm_CGPath]]; |
| 1260 return; |
| 1261 } |
| 1262 |
| 1263 // If mask layer does not exist yet, create one and set it as the background |
| 1264 // layer's mask. Clipping will be done based on the alpha channel of the mask |
| 1265 // layer. |
| 1266 mask_layer = [CAShapeLayer layer]; |
| 1267 [mask_layer setPath:[[bridged_view_ windowMask] gtm_CGPath]]; |
| 1268 |
| 1269 CALayer* background_layer = [compositor_superview_ layer]; |
| 1270 [background_layer setMask:mask_layer]; |
| 1271 [background_layer setMasksToBounds:YES]; |
| 1272 } |
| 1273 |
| 1247 } // namespace views | 1274 } // namespace views |
| OLD | NEW |