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 "chrome/browser/ui/cocoa/constrained_window/constrained_window_web_dialo
g_sheet.h" | 5 #import "chrome/browser/ui/cocoa/constrained_window/constrained_window_web_dialo
g_sheet.h" |
6 | 6 |
7 #include "ui/gfx/geometry/size.h" | 7 #include "ui/gfx/geometry/size.h" |
8 #include "ui/web_dialogs/web_dialog_delegate.h" | 8 #include "ui/web_dialogs/web_dialog_delegate.h" |
9 | 9 |
10 @implementation WebDialogConstrainedWindowSheet | 10 @implementation WebDialogConstrainedWindowSheet |
11 | 11 |
12 - (id)initWithCustomWindow:(NSWindow*)customWindow | 12 - (id)initWithCustomWindow:(NSWindow*)customWindow |
13 webDialogDelegate:(ui::WebDialogDelegate*)delegate { | 13 webDialogDelegate:(ui::WebDialogDelegate*)delegate { |
14 if (self = [super initWithCustomWindow:customWindow]) { | 14 if (self = [super initWithCustomWindow:customWindow]) { |
15 web_dialog_delegate_ = delegate; | 15 web_dialog_delegate_ = delegate; |
16 } | 16 } |
17 | 17 |
18 return self; | 18 return self; |
19 } | 19 } |
20 | 20 |
21 - (void)updateSheetPosition { | 21 - (void)updateSheetPosition { |
22 if (web_dialog_delegate_) { | 22 if (web_dialog_delegate_) { |
23 gfx::Size size; | 23 // If the dialog has autoresizing enabled and |current_size_| has been set, |
| 24 // GetDialogSize() doesn't modify |size|. |
| 25 gfx::Size size(current_size_.width, current_size_.height); |
24 web_dialog_delegate_->GetDialogSize(&size); | 26 web_dialog_delegate_->GetDialogSize(&size); |
| 27 DCHECK(!size.IsEmpty()); |
25 | 28 |
26 // If the dialog has autoresizing enabled, |size| will be empty. Use the | 29 NSSize content_size = NSMakeSize(size.width(), size.height()); |
27 // last known dialog size. | |
28 NSSize content_size = size.IsEmpty() ? current_size_ : | |
29 NSMakeSize(size.width(), size.height()); | |
30 [customWindow_ setContentSize:content_size]; | 30 [customWindow_ setContentSize:content_size]; |
31 } | 31 } |
32 [super updateSheetPosition]; | 32 [super updateSheetPosition]; |
33 } | 33 } |
34 | 34 |
35 - (void)resizeWithNewSize:(NSSize)size { | 35 - (void)resizeWithNewSize:(NSSize)size { |
36 current_size_ = size; | 36 current_size_ = size; |
37 [customWindow_ setContentSize:current_size_]; | 37 [customWindow_ setContentSize:current_size_]; |
38 | 38 |
39 // self's updateSheetPosition() sets |customWindow_|'s contentSize to a | 39 // self's updateSheetPosition() sets |customWindow_|'s contentSize to a |
40 // fixed dialog size. Here, we want to resize to |size| instead. Use | 40 // fixed dialog size. Here, we want to resize to |size| instead. Use |
41 // super rather than self to bypass the setContentSize() call for the fixed | 41 // super rather than self to bypass the setContentSize() call for the fixed |
42 // size. | 42 // size. |
43 [super updateSheetPosition]; | 43 [super updateSheetPosition]; |
44 } | 44 } |
45 | 45 |
46 @end | 46 @end |
OLD | NEW |