|
31 | 31 | #include "ui/gfx/skia_util.h"
|
32 | 32 | #include "ui/gl/gpu_switching_manager.h"
|
33 | 33 | #include "ui/views/background.h"
|
| 34 | +#include "ui/views/cocoa/bridged_native_widget_host_impl.h" |
34 | 35 | #include "ui/views/widget/widget.h"
|
35 | 36 |
|
| 37 | +// This view would inform Chromium to resize the hosted views::View. |
| 38 | +// |
| 39 | +// The overrided methods should behave the same with BridgedContentView. |
| 40 | +@interface ElectronAdapatedContentView : NSView { |
| 41 | + @private |
| 42 | + views::BridgedNativeWidgetHostImpl* bridge_host_; |
| 43 | +} |
| 44 | +@end |
| 45 | + |
| 46 | +@implementation ElectronAdapatedContentView |
| 47 | + |
| 48 | +- (id)initWithShell:(atom::NativeWindowMac*)shell { |
| 49 | + if ((self = [self init])) { |
| 50 | + bridge_host_ = views::BridgedNativeWidgetHostImpl::GetFromNativeWindow( |
| 51 | + shell->GetNativeWindow()); |
| 52 | + } |
| 53 | + return self; |
| 54 | +} |
| 55 | + |
| 56 | +- (void)viewDidMoveToWindow { |
| 57 | + // When this view is added to a window, AppKit calls setFrameSize before it is |
| 58 | + // added to the window, so the behavior in setFrameSize is not triggered. |
| 59 | + NSWindow* window = [self window]; |
| 60 | + if (window) |
| 61 | + [self setFrameSize:NSZeroSize]; |
| 62 | +} |
| 63 | + |
| 64 | +- (void)setFrameSize:(NSSize)newSize { |
| 65 | + // The size passed in here does not always use |
| 66 | + // -[NSWindow contentRectForFrameRect]. The following ensures that the |
| 67 | + // contentView for a frameless window can extend over the titlebar of the new |
| 68 | + // window containing it, since AppKit requires a titlebar to give frameless |
| 69 | + // windows correct shadows and rounded corners. |
| 70 | + NSWindow* window = [self window]; |
| 71 | + if (window && [window contentView] == self) { |
| 72 | + newSize = [window contentRectForFrameRect:[window frame]].size; |
| 73 | + // Ensure that the window geometry be updated on the host side before the |
| 74 | + // view size is updated. |
| 75 | + bridge_host_->bridge_impl()->UpdateWindowGeometry(); |
| 76 | + } |
| 77 | + |
| 78 | + [super setFrameSize:newSize]; |
| 79 | + |
| 80 | + // The OnViewSizeChanged is marked private in derived class. |
| 81 | + static_cast<remote_cocoa::mojom::BridgedNativeWidgetHost*>(bridge_host_) |
| 82 | + ->OnViewSizeChanged(gfx::Size(newSize.width, newSize.height)); |
| 83 | +} |
| 84 | + |
| 85 | +@end |
| 86 | + |
36 | 87 | // This view always takes the size of its superview. It is intended to be used
|
37 | 88 | // as a NSWindow's contentView. It is needed because NSWindow's implementation
|
38 | 89 | // explicitly resizes the contentView at inopportune times.
|
@@ -1496,10 +1547,15 @@ void ViewDidMoveToSuperview(NSView* self, SEL _cmd) {
|
1496 | 1547 | // `BridgedContentView` as content view, which does not support draggable
|
1497 | 1548 | // regions. In order to make draggable regions work, we have to replace the
|
1498 | 1549 | // content view with a simple NSView.
|
1499 |
| - container_view_.reset([[FullSizeContentView alloc] init]); |
| 1550 | + if (has_frame()) { |
| 1551 | + container_view_.reset( |
| 1552 | + [[ElectronAdapatedContentView alloc] initWithShell:this]); |
| 1553 | + } else { |
| 1554 | + container_view_.reset([[FullSizeContentView alloc] init]); |
| 1555 | + [container_view_ setFrame:[[[window_ contentView] superview] bounds]]; |
| 1556 | + } |
1500 | 1557 | [container_view_
|
1501 | 1558 | setAutoresizingMask:NSViewWidthSizable | NSViewHeightSizable];
|
1502 |
| - [container_view_ setFrame:[[[window_ contentView] superview] bounds]]; |
1503 | 1559 | [window_ setContentView:container_view_];
|
1504 | 1560 | AddContentViewLayers(IsMinimizable(), IsClosable());
|
1505 | 1561 | }
|
|
0 commit comments