Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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/widget_owner_nswindow_adapter.h" | 5 #import "ui/views/cocoa/widget_owner_nswindow_adapter.h" |
| 6 | 6 |
| 7 #import <Cocoa/Cocoa.h> | 7 #import <Cocoa/Cocoa.h> |
| 8 | 8 |
| 9 #include "base/logging.h" | 9 #include "base/logging.h" |
| 10 #include "ui/base/cocoa/cocoa_base_utils.h" | |
| 10 #include "ui/gfx/geometry/rect.h" | 11 #include "ui/gfx/geometry/rect.h" |
| 11 #include "ui/gfx/geometry/vector2d.h" | 12 #include "ui/gfx/geometry/vector2d.h" |
| 12 #import "ui/gfx/mac/coordinate_conversion.h" | 13 #import "ui/gfx/mac/coordinate_conversion.h" |
| 13 #import "ui/views/cocoa/bridged_native_widget.h" | 14 #import "ui/views/cocoa/bridged_native_widget.h" |
| 14 | 15 |
| 15 // Bridges an AppKit observer to observe when the (non-views) NSWindow owning a | 16 // Bridges an AppKit observer to observe when the (non-views) NSWindow owning a |
| 16 // views::Widget will close. | 17 // views::Widget will close. |
| 17 @interface WidgetOwnerNSWindowAdapterBridge : NSObject { | 18 @interface WidgetOwnerNSWindowAdapterBridge : NSObject { |
| 18 @private | 19 @private |
| 19 views::WidgetOwnerNSWindowAdapter* adapter_; // Weak. Owns us. | 20 views::WidgetOwnerNSWindowAdapter* adapter_; // Weak. Owns us. |
| (...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 67 | 68 |
| 68 NSWindow* WidgetOwnerNSWindowAdapter::GetNSWindow() { | 69 NSWindow* WidgetOwnerNSWindowAdapter::GetNSWindow() { |
| 69 return anchor_window_; | 70 return anchor_window_; |
| 70 } | 71 } |
| 71 | 72 |
| 72 gfx::Vector2d WidgetOwnerNSWindowAdapter::GetChildWindowOffset() const { | 73 gfx::Vector2d WidgetOwnerNSWindowAdapter::GetChildWindowOffset() const { |
| 73 NSRect rect_in_window = | 74 NSRect rect_in_window = |
| 74 [anchor_view_ convertRect:[anchor_view_ bounds] toView:nil]; | 75 [anchor_view_ convertRect:[anchor_view_ bounds] toView:nil]; |
| 75 // Ensure we anchor off the top-left of |anchor_view_| (rect_in_window.origin | 76 // Ensure we anchor off the top-left of |anchor_view_| (rect_in_window.origin |
| 76 // is the bottom-left of the view). | 77 // is the bottom-left of the view). |
| 77 // TODO(tapted): Use -[NSWindow convertRectToScreen:] when we ditch 10.6. | |
| 78 NSRect rect_in_screen = NSZeroRect; | 78 NSRect rect_in_screen = NSZeroRect; |
| 79 rect_in_screen.origin = | 79 rect_in_screen.origin = ui::ConvertPointFromWindowToScreen( |
| 80 [anchor_window_ convertBaseToScreen:NSMakePoint(NSMinX(rect_in_window), | 80 anchor_window_, |
| 81 NSMaxY(rect_in_window))]; | 81 NSMakePoint(NSMinX(rect_in_window), NSMaxY(rect_in_window))); |
|
Avi (use Gerrit)
2016/03/08 20:07:54
Can we rewrite this so we do:
NSRect rect_in_wind
erikchen
2016/03/08 20:57:41
Done.
| |
| 82 return gfx::ScreenRectFromNSRect(rect_in_screen).OffsetFromOrigin(); | 82 return gfx::ScreenRectFromNSRect(rect_in_screen).OffsetFromOrigin(); |
| 83 } | 83 } |
| 84 | 84 |
| 85 bool WidgetOwnerNSWindowAdapter::IsVisibleParent() const { | 85 bool WidgetOwnerNSWindowAdapter::IsVisibleParent() const { |
| 86 return [anchor_window_ isVisible]; | 86 return [anchor_window_ isVisible]; |
| 87 } | 87 } |
| 88 | 88 |
| 89 void WidgetOwnerNSWindowAdapter::RemoveChildWindow(BridgedNativeWidget* child) { | 89 void WidgetOwnerNSWindowAdapter::RemoveChildWindow(BridgedNativeWidget* child) { |
| 90 DCHECK_EQ(child, child_); | 90 DCHECK_EQ(child, child_); |
| 91 [GetNSWindow() removeChildWindow:child->ns_window()]; | 91 [GetNSWindow() removeChildWindow:child->ns_window()]; |
| 92 delete this; | 92 delete this; |
| 93 } | 93 } |
| 94 | 94 |
| 95 WidgetOwnerNSWindowAdapter::~WidgetOwnerNSWindowAdapter() { | 95 WidgetOwnerNSWindowAdapter::~WidgetOwnerNSWindowAdapter() { |
| 96 [[NSNotificationCenter defaultCenter] removeObserver:observer_bridge_]; | 96 [[NSNotificationCenter defaultCenter] removeObserver:observer_bridge_]; |
| 97 } | 97 } |
| 98 | 98 |
| 99 } // namespace views | 99 } // namespace views |
| OLD | NEW |