| 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 671 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 682 [bridge->parent()->GetNSWindow() contentView]) | 682 [bridge->parent()->GetNSWindow() contentView]) |
| 683 : nullptr; | 683 : nullptr; |
| 684 return ancestor ? ancestor : bridge->native_widget_mac(); | 684 return ancestor ? ancestor : bridge->native_widget_mac(); |
| 685 } | 685 } |
| 686 | 686 |
| 687 // static | 687 // static |
| 688 void NativeWidgetPrivate::GetAllChildWidgets(gfx::NativeView native_view, | 688 void NativeWidgetPrivate::GetAllChildWidgets(gfx::NativeView native_view, |
| 689 Widget::Widgets* children) { | 689 Widget::Widgets* children) { |
| 690 BridgedNativeWidget* bridge = | 690 BridgedNativeWidget* bridge = |
| 691 NativeWidgetMac::GetBridgeForNativeWindow([native_view window]); | 691 NativeWidgetMac::GetBridgeForNativeWindow([native_view window]); |
| 692 if (!bridge) | 692 if (!bridge) { |
| 693 // The NSWindow is not itself a views::Widget, but it may have children that |
| 694 // are. Support returning Widgets that are parented to the NSWindow, except: |
| 695 // - Ignore requests for children of an NSView that is not a contentView. |
| 696 // - We do not add a Widget for |native_view| to |children| (there is none). |
| 697 if ([[native_view window] contentView] != native_view) |
| 698 return; |
| 699 |
| 700 for (NSWindow* native_child in [[native_view window] childWindows]) |
| 701 GetAllChildWidgets([native_child contentView], children); |
| 693 return; | 702 return; |
| 703 } |
| 694 | 704 |
| 695 // If |native_view| is a subview of the contentView, it will share an | 705 // If |native_view| is a subview of the contentView, it will share an |
| 696 // NSWindow, but will itself be a native child of the Widget. That is, adding | 706 // NSWindow, but will itself be a native child of the Widget. That is, adding |
| 697 // bridge->..->GetWidget() to |children| would be adding the _parent_ of | 707 // bridge->..->GetWidget() to |children| would be adding the _parent_ of |
| 698 // |native_view|, not the Widget for |native_view|. |native_view| doesn't have | 708 // |native_view|, not the Widget for |native_view|. |native_view| doesn't have |
| 699 // a corresponding Widget of its own in this case (and so can't have Widget | 709 // a corresponding Widget of its own in this case (and so can't have Widget |
| 700 // children of its own on Mac). | 710 // children of its own on Mac). |
| 701 if (bridge->ns_view() != native_view) | 711 if (bridge->ns_view() != native_view) |
| 702 return; | 712 return; |
| 703 | 713 |
| 704 // Code expects widget for |native_view| to be added to |children|. | 714 // Code expects widget for |native_view| to be added to |children|. |
| 705 if (bridge->native_widget_mac()->GetWidget()) | 715 if (bridge->native_widget_mac()->GetWidget()) |
| 706 children->insert(bridge->native_widget_mac()->GetWidget()); | 716 children->insert(bridge->native_widget_mac()->GetWidget()); |
| 707 | 717 |
| 718 // When the NSWindow *is* a Widget, only consider child_windows(). I.e. do not |
| 719 // look through -[NSWindow childWindows] as done for the (!bridge) case above. |
| 720 // -childWindows does not support hidden windows, and anything in there which |
| 721 // is not in child_windows() would have been added by AppKit. |
| 708 for (BridgedNativeWidget* child : bridge->child_windows()) | 722 for (BridgedNativeWidget* child : bridge->child_windows()) |
| 709 GetAllChildWidgets(child->ns_view(), children); | 723 GetAllChildWidgets(child->ns_view(), children); |
| 710 } | 724 } |
| 711 | 725 |
| 712 // static | 726 // static |
| 713 void NativeWidgetPrivate::GetAllOwnedWidgets(gfx::NativeView native_view, | 727 void NativeWidgetPrivate::GetAllOwnedWidgets(gfx::NativeView native_view, |
| 714 Widget::Widgets* owned) { | 728 Widget::Widgets* owned) { |
| 715 NOTIMPLEMENTED(); | 729 NOTIMPLEMENTED(); |
| 716 } | 730 } |
| 717 | 731 |
| (...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 766 [[ViewsNSWindowCloseAnimator alloc] initWithWindow:window]; | 780 [[ViewsNSWindowCloseAnimator alloc] initWithWindow:window]; |
| 767 } | 781 } |
| 768 | 782 |
| 769 - (void)animationDidEnd:(NSAnimation*)animation { | 783 - (void)animationDidEnd:(NSAnimation*)animation { |
| 770 [window_ close]; | 784 [window_ close]; |
| 771 [animation_ setDelegate:nil]; | 785 [animation_ setDelegate:nil]; |
| 772 [self release]; | 786 [self release]; |
| 773 } | 787 } |
| 774 | 788 |
| 775 @end | 789 @end |
| OLD | NEW |