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" |
(...skipping 27 matching lines...) Expand all Loading... |
38 [[window_ parentWindow] removeChildWindow:window_]; | 38 [[window_ parentWindow] removeChildWindow:window_]; |
39 | 39 |
40 [window_ close]; | 40 [window_ close]; |
41 } | 41 } |
42 | 42 |
43 void AutofillPopupViewBridge::Hide() { | 43 void AutofillPopupViewBridge::Hide() { |
44 delete this; | 44 delete this; |
45 } | 45 } |
46 | 46 |
47 void AutofillPopupViewBridge::Show() { | 47 void AutofillPopupViewBridge::Show() { |
48 SetInitialBounds(); | |
49 UpdateBoundsAndRedrawPopup(); | 48 UpdateBoundsAndRedrawPopup(); |
50 [[controller_->container_view() window] addChildWindow:window_ | 49 [[controller_->container_view() window] addChildWindow:window_ |
51 ordered:NSWindowAbove]; | 50 ordered:NSWindowAbove]; |
52 } | 51 } |
53 | 52 |
54 void AutofillPopupViewBridge::InvalidateRow(size_t row) { | 53 void AutofillPopupViewBridge::InvalidateRow(size_t row) { |
55 NSRect dirty_rect = | 54 NSRect dirty_rect = |
56 NSRectFromCGRect(controller_->GetRowBounds(row).ToCGRect()); | 55 NSRectFromCGRect(controller_->GetRowBounds(row).ToCGRect()); |
57 [view_ setNeedsDisplayInRect:dirty_rect]; | 56 [view_ setNeedsDisplayInRect:dirty_rect]; |
58 } | 57 } |
59 | 58 |
60 void AutofillPopupViewBridge::UpdateBoundsAndRedrawPopup() { | 59 void AutofillPopupViewBridge::UpdateBoundsAndRedrawPopup() { |
61 NSRect frame = NSRectFromCGRect(controller_->popup_bounds().ToCGRect()); | 60 NSRect frame = NSRectFromCGRect(controller_->popup_bounds().ToCGRect()); |
62 | 61 |
63 // Flip coordinates back into Cocoa-land. | 62 // Flip coordinates back into Cocoa-land. |
64 // TODO(isherman): Does this agree with the controller's idea of handling | 63 // TODO(isherman): Does this agree with the controller's idea of handling |
65 // multi-monitor setups correctly? | 64 // multi-monitor setups correctly? |
66 NSScreen* screen = [[controller_->container_view() window] screen]; | 65 NSScreen* screen = [[controller_->container_view() window] screen]; |
67 frame.origin.y = NSHeight([screen frame]) - NSMaxY(frame); | 66 frame.origin.y = NSHeight([screen frame]) - NSMaxY(frame); |
68 | 67 |
69 // TODO(isherman): The view should support scrolling if the popup gets too | 68 // TODO(isherman): The view should support scrolling if the popup gets too |
70 // big to fit on the screen. | 69 // big to fit on the screen. |
71 [window_ setFrame:frame display:YES]; | 70 [window_ setFrame:frame display:YES]; |
72 } | 71 } |
73 | 72 |
74 void AutofillPopupViewBridge::SetInitialBounds() { | |
75 // The bounds rect in Chrome's screen coordinates. The popup should be | |
76 // positioned just below the element which initiated it. | |
77 gfx::Rect bounds(controller_->element_bounds().x(), | |
78 controller_->element_bounds().bottom(), | |
79 controller_->GetPopupRequiredWidth(), | |
80 controller_->GetPopupRequiredHeight()); | |
81 | |
82 // TODO(isherman): Position the popup correctly if it can't fit below the text | |
83 // field: http://crbug.com/164603 | |
84 | |
85 controller_->SetPopupBounds(bounds); | |
86 } | |
87 | |
88 AutofillPopupView* AutofillPopupView::Create( | 73 AutofillPopupView* AutofillPopupView::Create( |
89 AutofillPopupController* controller) { | 74 AutofillPopupController* controller) { |
90 return new AutofillPopupViewBridge(controller); | 75 return new AutofillPopupViewBridge(controller); |
91 } | 76 } |
OLD | NEW |