| 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 #include "ui/views/widget/native_widget_mac.h" | 5 #include "ui/views/widget/native_widget_mac.h" |
| 6 | 6 |
| 7 #import <Cocoa/Cocoa.h> | 7 #import <Cocoa/Cocoa.h> |
| 8 | 8 |
| 9 #include <utility> | 9 #include <utility> |
| 10 | 10 |
| (...skipping 673 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 684 BridgedNativeWidget* bridge = | 684 BridgedNativeWidget* bridge = |
| 685 NativeWidgetMac::GetBridgeForNativeWindow([native_view window]); | 685 NativeWidgetMac::GetBridgeForNativeWindow([native_view window]); |
| 686 if (!bridge) { | 686 if (!bridge) { |
| 687 // The NSWindow is not itself a views::Widget, but it may have children that | 687 // The NSWindow is not itself a views::Widget, but it may have children that |
| 688 // are. Support returning Widgets that are parented to the NSWindow, except: | 688 // are. Support returning Widgets that are parented to the NSWindow, except: |
| 689 // - Ignore requests for children of an NSView that is not a contentView. | 689 // - Ignore requests for children of an NSView that is not a contentView. |
| 690 // - We do not add a Widget for |native_view| to |children| (there is none). | 690 // - We do not add a Widget for |native_view| to |children| (there is none). |
| 691 if ([[native_view window] contentView] != native_view) | 691 if ([[native_view window] contentView] != native_view) |
| 692 return; | 692 return; |
| 693 | 693 |
| 694 for (NSWindow* native_child in [[native_view window] childWindows]) | 694 // Collect -sheets and -childWindows. A window should never appear in both, |
| 695 // since that causes AppKit to glitch. |
| 696 NSArray* sheet_children = [[native_view window] sheets]; |
| 697 for (NSWindow* native_child in sheet_children) |
| 695 GetAllChildWidgets([native_child contentView], children); | 698 GetAllChildWidgets([native_child contentView], children); |
| 699 |
| 700 for (NSWindow* native_child in [[native_view window] childWindows]) { |
| 701 DCHECK(![sheet_children containsObject:native_child]); |
| 702 GetAllChildWidgets([native_child contentView], children); |
| 703 } |
| 696 return; | 704 return; |
| 697 } | 705 } |
| 698 | 706 |
| 699 // If |native_view| is a subview of the contentView, it will share an | 707 // If |native_view| is a subview of the contentView, it will share an |
| 700 // NSWindow, but will itself be a native child of the Widget. That is, adding | 708 // NSWindow, but will itself be a native child of the Widget. That is, adding |
| 701 // bridge->..->GetWidget() to |children| would be adding the _parent_ of | 709 // bridge->..->GetWidget() to |children| would be adding the _parent_ of |
| 702 // |native_view|, not the Widget for |native_view|. |native_view| doesn't have | 710 // |native_view|, not the Widget for |native_view|. |native_view| doesn't have |
| 703 // a corresponding Widget of its own in this case (and so can't have Widget | 711 // a corresponding Widget of its own in this case (and so can't have Widget |
| 704 // children of its own on Mac). | 712 // children of its own on Mac). |
| 705 if (bridge->ns_view() != native_view) | 713 if (bridge->ns_view() != native_view) |
| 706 return; | 714 return; |
| 707 | 715 |
| 708 // Code expects widget for |native_view| to be added to |children|. | 716 // Code expects widget for |native_view| to be added to |children|. |
| 709 if (bridge->native_widget_mac()->GetWidget()) | 717 if (bridge->native_widget_mac()->GetWidget()) |
| 710 children->insert(bridge->native_widget_mac()->GetWidget()); | 718 children->insert(bridge->native_widget_mac()->GetWidget()); |
| 711 | 719 |
| 712 // When the NSWindow *is* a Widget, only consider child_windows(). I.e. do not | 720 // When the NSWindow *is* a Widget, only consider child_windows(). I.e. do not |
| 713 // look through -[NSWindow childWindows] as done for the (!bridge) case above. | 721 // look through -[NSWindow childWindows] as done for the (!bridge) case above. |
| 714 // -childWindows does not support hidden windows, and anything in there which | 722 // -childWindows does not support hidden windows, and anything in there which |
| 715 // is not in child_windows() would have been added by AppKit. | 723 // is not in child_windows() would have been added by AppKit. |
| 716 for (BridgedNativeWidget* child : bridge->child_windows()) | 724 for (BridgedNativeWidget* child : bridge->child_windows()) |
| 717 GetAllChildWidgets(child->ns_view(), children); | 725 GetAllChildWidgets(child->ns_view(), children); |
| 718 } | 726 } |
| 719 | 727 |
| 720 // static | 728 // static |
| 721 void NativeWidgetPrivate::GetAllOwnedWidgets(gfx::NativeView native_view, | 729 void NativeWidgetPrivate::GetAllOwnedWidgets(gfx::NativeView native_view, |
| 722 Widget::Widgets* owned) { | 730 Widget::Widgets* owned) { |
| 723 NOTIMPLEMENTED(); | 731 BridgedNativeWidget* bridge = |
| 732 NativeWidgetMac::GetBridgeForNativeWindow([native_view window]); |
| 733 if (!bridge) { |
| 734 GetAllChildWidgets(native_view, owned); |
| 735 return; |
| 736 } |
| 737 if (bridge->ns_view() != native_view) |
| 738 return; |
| 739 for (BridgedNativeWidget* child : bridge->child_windows()) |
| 740 GetAllChildWidgets(child->ns_view(), owned); |
| 724 } | 741 } |
| 725 | 742 |
| 726 // static | 743 // static |
| 727 void NativeWidgetPrivate::ReparentNativeView(gfx::NativeView native_view, | 744 void NativeWidgetPrivate::ReparentNativeView(gfx::NativeView native_view, |
| 728 gfx::NativeView new_parent) { | 745 gfx::NativeView new_parent) { |
| 729 BridgedNativeWidget* bridge = | 746 BridgedNativeWidget* bridge = |
| 730 NativeWidgetMac::GetBridgeForNativeWindow([native_view window]); | 747 NativeWidgetMac::GetBridgeForNativeWindow([native_view window]); |
| 731 if (bridge && bridge->parent() && | 748 if (bridge && bridge->parent() && |
| 732 bridge->parent()->GetNSWindow() == [new_parent window]) | 749 bridge->parent()->GetNSWindow() == [new_parent window]) |
| 733 return; // Nothing to do. | 750 return; // Nothing to do. |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 774 [[ViewsNSWindowCloseAnimator alloc] initWithWindow:window]; | 791 [[ViewsNSWindowCloseAnimator alloc] initWithWindow:window]; |
| 775 } | 792 } |
| 776 | 793 |
| 777 - (void)animationDidEnd:(NSAnimation*)animation { | 794 - (void)animationDidEnd:(NSAnimation*)animation { |
| 778 [window_ close]; | 795 [window_ close]; |
| 779 [animation_ setDelegate:nil]; | 796 [animation_ setDelegate:nil]; |
| 780 [self release]; | 797 [self release]; |
| 781 } | 798 } |
| 782 | 799 |
| 783 @end | 800 @end |
| OLD | NEW |