OLD | NEW |
---|---|
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 <Cocoa/Cocoa.h> | 5 #import <Cocoa/Cocoa.h> |
6 | 6 |
7 #include "chrome/browser/ui/cocoa/autofill/autofill_popup_view_bridge.h" | 7 #include "chrome/browser/ui/cocoa/autofill/autofill_popup_view_bridge.h" |
8 | 8 |
9 #include "base/logging.h" | 9 #include "base/logging.h" |
10 #include "chrome/browser/ui/autofill/autofill_popup_controller.h" | 10 #include "chrome/browser/ui/autofill/autofill_popup_controller.h" |
11 #include "chrome/browser/ui/autofill/autofill_popup_view_delegate.h" | |
11 #import "chrome/browser/ui/cocoa/autofill/autofill_popup_view_cocoa.h" | 12 #import "chrome/browser/ui/cocoa/autofill/autofill_popup_view_cocoa.h" |
12 #include "ui/base/cocoa/window_size_constants.h" | |
13 #include "ui/gfx/rect.h" | 13 #include "ui/gfx/rect.h" |
14 | 14 |
15 namespace autofill { | 15 namespace autofill { |
16 | 16 |
17 AutofillPopupViewBridge::AutofillPopupViewBridge( | 17 AutofillPopupViewBridge::AutofillPopupViewBridge( |
18 AutofillPopupController* controller) | 18 AutofillPopupViewCocoa* view, AutofillPopupController* controller) |
Ilya Sherman
2014/05/09 21:51:28
nit: Please write one param per line if they don't
Patrick Dubroy
2014/05/12 14:13:39
Done.
| |
19 : controller_(controller) { | 19 : view_(view), controller_(controller) { |
Ilya Sherman
2014/05/09 21:51:28
nit: Likewise, please split this into two lines.
Patrick Dubroy
2014/05/12 14:13:39
Done.
| |
20 window_ = | |
21 [[NSWindow alloc] initWithContentRect:ui::kWindowSizeDeterminedLater | |
22 styleMask:NSBorderlessWindowMask | |
23 backing:NSBackingStoreBuffered | |
24 defer:YES]; | |
25 // Telling Cocoa that the window is opaque enables some drawing optimizations. | |
26 [window_ setOpaque:YES]; | |
27 | |
28 view_ = [[[AutofillPopupViewCocoa alloc] | |
29 initWithController:controller_ | |
30 frame:NSZeroRect] autorelease]; | |
31 [window_ setContentView:view_]; | |
32 } | 20 } |
33 | 21 |
34 AutofillPopupViewBridge::~AutofillPopupViewBridge() { | 22 AutofillPopupViewBridge::~AutofillPopupViewBridge() { |
35 [view_ controllerDestroyed]; | |
36 | |
37 // Remove the child window before closing, otherwise it can mess up | |
38 // display ordering. | |
39 [[window_ parentWindow] removeChildWindow:window_]; | |
40 | |
41 [window_ close]; | |
42 } | 23 } |
43 | 24 |
44 void AutofillPopupViewBridge::Hide() { | 25 void AutofillPopupViewBridge::Hide() { |
45 delete this; | 26 [view_ hidePopup]; |
Ilya Sherman
2014/05/09 21:51:28
There used to be a |delete this| call here. Who i
Patrick Dubroy
2014/05/12 14:13:39
Right, I screwed this up when I was refactoring. I
| |
46 } | 27 } |
47 | 28 |
48 void AutofillPopupViewBridge::Show() { | 29 void AutofillPopupViewBridge::Show() { |
49 UpdateBoundsAndRedrawPopup(); | 30 [view_ showPopup]; |
50 [[controller_->container_view() window] addChildWindow:window_ | |
51 ordered:NSWindowAbove]; | |
52 } | 31 } |
53 | 32 |
54 void AutofillPopupViewBridge::InvalidateRow(size_t row) { | 33 void AutofillPopupViewBridge::InvalidateRow(size_t row) { |
55 NSRect dirty_rect = | 34 [view_ invalidateRow:row]; |
56 NSRectFromCGRect(controller_->GetRowBounds(row).ToCGRect()); | |
57 [view_ setNeedsDisplayInRect:dirty_rect]; | |
58 } | 35 } |
59 | 36 |
60 void AutofillPopupViewBridge::UpdateBoundsAndRedrawPopup() { | 37 void AutofillPopupViewBridge::UpdateBoundsAndRedrawPopup() { |
61 NSRect frame = NSRectFromCGRect(controller_->popup_bounds().ToCGRect()); | 38 [view_ updateBoundsAndRedrawPopup]; |
62 | |
63 // Flip coordinates back into Cocoa-land. The controller's platform-neutral | |
64 // coordinate space places the origin at the top-left of the first screen, | |
65 // whereas Cocoa's coordinate space expects the origin to be at the | |
66 // bottom-left of this same screen. | |
67 NSScreen* screen = [[NSScreen screens] objectAtIndex:0]; | |
68 frame.origin.y = NSMaxY([screen frame]) - NSMaxY(frame); | |
69 | |
70 // TODO(isherman): The view should support scrolling if the popup gets too | |
71 // big to fit on the screen. | |
72 [window_ setFrame:frame display:YES]; | |
73 [view_ setNeedsDisplay:YES]; | |
74 } | 39 } |
75 | 40 |
76 AutofillPopupView* AutofillPopupView::Create( | 41 AutofillPopupView* AutofillPopupView::Create( |
77 AutofillPopupController* controller) { | 42 AutofillPopupController* controller) { |
78 return new AutofillPopupViewBridge(controller); | 43 AutofillPopupViewCocoa* view = |
44 [[[AutofillPopupViewCocoa alloc] | |
45 initWithController:controller | |
46 frame:NSZeroRect] autorelease]; | |
Ilya Sherman
2014/05/09 21:51:28
Autorelease doesn't seem safe here. What prevents
Patrick Dubroy
2014/05/12 14:13:39
Hmmm, good point. I've moved this code into the co
| |
47 return new AutofillPopupViewBridge(view, controller); | |
79 } | 48 } |
80 | 49 |
81 } // namespace autofill | 50 } // namespace autofill |
OLD | NEW |