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/password_generation_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 #import "chrome/browser/ui/cocoa/autofill/autofill_popup_view_cocoa.h" | 11 #import "chrome/browser/ui/cocoa/autofill/password_generation_popup_view_cocoa.h " |
12 #include "ui/base/cocoa/window_size_constants.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 PasswordGenerationPopupViewBridge::PasswordGenerationPopupViewBridge( |
18 AutofillPopupController* controller) | 18 PasswordGenerationPopupController* controller) |
19 : controller_(controller) { | 19 : controller_(controller) { |
20 window_ = | 20 window_ = |
21 [[NSWindow alloc] initWithContentRect:ui::kWindowSizeDeterminedLater | 21 [[NSWindow alloc] initWithContentRect:ui::kWindowSizeDeterminedLater |
22 styleMask:NSBorderlessWindowMask | 22 styleMask:NSBorderlessWindowMask |
23 backing:NSBackingStoreBuffered | 23 backing:NSBackingStoreBuffered |
24 defer:YES]; | 24 defer:YES]; |
25 // Telling Cocoa that the window is opaque enables some drawing optimizations. | 25 // Telling Cocoa that the window is opaque enables some drawing optimizations. |
26 [window_ setOpaque:YES]; | 26 [window_ setOpaque:YES]; |
27 | 27 |
28 view_ = [[[AutofillPopupViewCocoa alloc] | 28 view_ = [[[PasswordGenerationPopupViewCocoa alloc] |
29 initWithController:controller_ | 29 initWithController:controller_ |
30 frame:NSZeroRect] autorelease]; | 30 frame:NSZeroRect] autorelease]; |
31 | |
31 [window_ setContentView:view_]; | 32 [window_ setContentView:view_]; |
32 } | 33 } |
33 | 34 |
34 AutofillPopupViewBridge::~AutofillPopupViewBridge() { | 35 PasswordGenerationPopupViewBridge::~PasswordGenerationPopupViewBridge() { |
35 [view_ controllerDestroyed]; | 36 [view_ controllerDestroyed]; |
36 | 37 |
37 // Remove the child window before closing, otherwise it can mess up | 38 // Remove the child window before closing, otherwise it can mess up |
38 // display ordering. | 39 // display ordering. |
39 [[window_ parentWindow] removeChildWindow:window_]; | 40 [[window_ parentWindow] removeChildWindow:window_]; |
40 | 41 |
41 [window_ close]; | 42 [window_ close]; |
42 } | 43 } |
43 | 44 |
44 void AutofillPopupViewBridge::Hide() { | 45 void PasswordGenerationPopupViewBridge::Hide() { |
45 delete this; | 46 delete this; |
46 } | 47 } |
47 | 48 |
48 void AutofillPopupViewBridge::Show() { | 49 void PasswordGenerationPopupViewBridge::Show() { |
49 UpdateBoundsAndRedrawPopup(); | 50 UpdateBoundsAndRedrawPopup(); |
50 [[controller_->container_view() window] addChildWindow:window_ | 51 [[controller_->container_view() window] addChildWindow:window_ |
51 ordered:NSWindowAbove]; | 52 ordered:NSWindowAbove]; |
52 } | 53 } |
53 | 54 |
54 void AutofillPopupViewBridge::InvalidateRow(size_t row) { | 55 void PasswordGenerationPopupViewBridge::UpdateBoundsAndRedrawPopup() { |
55 NSRect dirty_rect = | |
56 NSRectFromCGRect(controller_->GetRowBounds(row).ToCGRect()); | |
57 [view_ setNeedsDisplayInRect:dirty_rect]; | |
58 } | |
59 | |
60 void AutofillPopupViewBridge::UpdateBoundsAndRedrawPopup() { | |
61 NSRect frame = NSRectFromCGRect(controller_->popup_bounds().ToCGRect()); | 56 NSRect frame = NSRectFromCGRect(controller_->popup_bounds().ToCGRect()); |
62 | 57 |
63 // Flip coordinates back into Cocoa-land. The controller's platform-neutral | 58 // 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, | 59 // 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 | 60 // whereas Cocoa's coordinate space expects the origin to be at the |
66 // bottom-left of this same screen. | 61 // bottom-left of this same screen. |
67 NSScreen* screen = [[NSScreen screens] objectAtIndex:0]; | 62 NSScreen* screen = [[NSScreen screens] objectAtIndex:0]; |
68 frame.origin.y = NSMaxY([screen frame]) - NSMaxY(frame); | 63 frame.origin.y = NSMaxY([screen frame]) - NSMaxY(frame); |
69 | 64 |
70 // TODO(isherman): The view should support scrolling if the popup gets too | 65 // TODO(isherman): The view should support scrolling if the popup gets too |
71 // big to fit on the screen. | 66 // big to fit on the screen. |
72 [window_ setFrame:frame display:YES]; | 67 [window_ setFrame:frame display:YES]; |
73 [view_ setNeedsDisplay:YES]; | 68 [view_ setNeedsDisplay:YES]; |
74 } | 69 } |
Ilya Sherman
2014/05/07 00:34:44
There's a whole bunch of duplicated code in this f
Patrick Dubroy
2014/05/07 16:48:36
I've taken a crack at it in the latest patchset. B
Ilya Sherman
2014/05/08 00:34:32
I'm fine with either composition or inheritance.
| |
75 | 70 |
76 AutofillPopupView* AutofillPopupView::Create( | 71 void PasswordGenerationPopupViewBridge::PasswordSelectionUpdated() { |
77 AutofillPopupController* controller) { | 72 NOTREACHED() << "Not implemented"; |
78 return new AutofillPopupViewBridge(controller); | 73 } |
74 | |
75 | |
76 PasswordGenerationPopupView* PasswordGenerationPopupView::Create( | |
77 PasswordGenerationPopupController* controller) { | |
78 return new PasswordGenerationPopupViewBridge(controller); | |
79 } | 79 } |
80 | 80 |
81 } // namespace autofill | 81 } // namespace autofill |
OLD | NEW |