| 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 AutofillPopupController* controller) |
| 19 : controller_(controller) { | 19 : controller_(controller) { |
| 20 window_ = | 20 view_.reset( |
| 21 [[NSWindow alloc] initWithContentRect:ui::kWindowSizeDeterminedLater | 21 [[AutofillPopupViewCocoa alloc] initWithController:controller |
| 22 styleMask:NSBorderlessWindowMask | 22 frame:NSZeroRect]); |
| 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 } | 23 } |
| 33 | 24 |
| 34 AutofillPopupViewBridge::~AutofillPopupViewBridge() { | 25 AutofillPopupViewBridge::~AutofillPopupViewBridge() { |
| 35 [view_ controllerDestroyed]; | 26 [view_ hidePopup]; |
| 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 } | 27 } |
| 43 | 28 |
| 44 void AutofillPopupViewBridge::Hide() { | 29 void AutofillPopupViewBridge::Hide() { |
| 45 delete this; | 30 delete this; |
| 46 } | 31 } |
| 47 | 32 |
| 48 void AutofillPopupViewBridge::Show() { | 33 void AutofillPopupViewBridge::Show() { |
| 49 UpdateBoundsAndRedrawPopup(); | 34 [view_ showPopup]; |
| 50 [[controller_->container_view() window] addChildWindow:window_ | |
| 51 ordered:NSWindowAbove]; | |
| 52 } | 35 } |
| 53 | 36 |
| 54 void AutofillPopupViewBridge::InvalidateRow(size_t row) { | 37 void AutofillPopupViewBridge::InvalidateRow(size_t row) { |
| 55 NSRect dirty_rect = | 38 [view_ invalidateRow:row]; |
| 56 NSRectFromCGRect(controller_->GetRowBounds(row).ToCGRect()); | |
| 57 [view_ setNeedsDisplayInRect:dirty_rect]; | |
| 58 } | 39 } |
| 59 | 40 |
| 60 void AutofillPopupViewBridge::UpdateBoundsAndRedrawPopup() { | 41 void AutofillPopupViewBridge::UpdateBoundsAndRedrawPopup() { |
| 61 NSRect frame = NSRectFromCGRect(controller_->popup_bounds().ToCGRect()); | 42 [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 } | 43 } |
| 75 | 44 |
| 76 AutofillPopupView* AutofillPopupView::Create( | 45 AutofillPopupView* AutofillPopupView::Create( |
| 77 AutofillPopupController* controller) { | 46 AutofillPopupController* controller) { |
| 78 return new AutofillPopupViewBridge(controller); | 47 return new AutofillPopupViewBridge(controller); |
| 79 } | 48 } |
| 80 | 49 |
| 81 } // namespace autofill | 50 } // namespace autofill |
| OLD | NEW |