Chromium Code Reviews| 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 534 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1237 void BridgedNativeWidget::SetDraggable(bool draggable) { | 1233 void BridgedNativeWidget::SetDraggable(bool draggable) { |
| 1238 [bridged_view_ setMouseDownCanMoveWindow:draggable]; | 1234 [bridged_view_ setMouseDownCanMoveWindow:draggable]; |
| 1239 // AppKit will not update its cache of mouseDownCanMoveWindow unless something | 1235 // AppKit will not update its cache of mouseDownCanMoveWindow unless something |
| 1240 // changes. Previously we tried adding an NSView and removing it, but for some | 1236 // 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. | 1237 // reason it required reposting the mouse-down event, and didn't always work. |
| 1242 // Calling the below seems to be an effective solution. | 1238 // Calling the below seems to be an effective solution. |
| 1243 [window_ setMovableByWindowBackground:NO]; | 1239 [window_ setMovableByWindowBackground:NO]; |
| 1244 [window_ setMovableByWindowBackground:YES]; | 1240 [window_ setMovableByWindowBackground:YES]; |
| 1245 } | 1241 } |
| 1246 | 1242 |
| 1243 // TODO(karandeepb): Add tests to verify mask layer is correctly set up. | |
|
tapted
2016/03/04 04:15:01
we don't usually have TODO: add tests in code comm
| |
| 1244 void BridgedNativeWidget::UpdateMaskPath() { | |
| 1245 [bridged_view_ updateWindowMask]; | |
| 1246 | |
| 1247 // We only set the mask layer for windows with non-rectangular masks. | |
| 1248 if (![bridged_view_ windowMask]) { | |
| 1249 // Removing a mask after adding one isn't currently supported. | |
| 1250 DCHECK(![[compositor_superview_ layer] mask]); | |
| 1251 return; | |
| 1252 } | |
| 1253 | |
| 1254 CAShapeLayer* mask_layer = base::mac::ObjCCastStrict<CAShapeLayer>( | |
| 1255 [[compositor_superview_ layer] mask]); | |
| 1256 if (mask_layer) { | |
| 1257 [mask_layer setPath:[[bridged_view_ windowMask] gtm_CGPath]]; | |
| 1258 return; | |
| 1259 } | |
| 1260 | |
| 1261 // If mask layer does not exist yet, create one and set it as the background | |
| 1262 // layer's mask. Clipping will be done based on the alpha channel of the mask | |
| 1263 // layer. | |
| 1264 mask_layer = [CAShapeLayer layer]; | |
| 1265 [mask_layer setPath:[[bridged_view_ windowMask] gtm_CGPath]]; | |
| 1266 | |
| 1267 CALayer* background_layer = [compositor_superview_ layer]; | |
| 1268 [background_layer setMask:mask_layer]; | |
| 1269 [background_layer setMasksToBounds:YES]; | |
| 1270 } | |
| 1271 | |
| 1247 } // namespace views | 1272 } // namespace views |
| OLD | NEW |