Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 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 | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #import <Cocoa/Cocoa.h> | |
| 6 | |
| 7 #include "chrome/browser/ui/cocoa/autofill/autofill_popup_view_mac.h" | |
|
Nico
2013/01/11 16:27:38
I'm not a huge fan of _mac / _cocoa either, espec
Ilya Sherman
2013/01/11 23:32:26
Filed as [ http://crbug.com/169604 ]. Even if we
| |
| 8 | |
| 9 #include "base/logging.h" | |
| 10 #include "chrome/browser/ui/autofill/autofill_popup_controller.h" | |
| 11 #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" | |
| 14 | |
| 15 AutofillPopupViewMac::AutofillPopupViewMac( | |
| 16 AutofillPopupController* controller) | |
| 17 : controller_(controller) { | |
| 18 window_ = | |
| 19 [[NSWindow alloc] initWithContentRect:ui::kWindowSizeDeterminedLater | |
| 20 styleMask:NSBorderlessWindowMask | |
| 21 backing:NSBackingStoreBuffered | |
| 22 defer:YES]; | |
| 23 // Telling Cocoa that the window is opaque enables some drawing optimizations. | |
| 24 [window_ setOpaque:YES]; | |
| 25 | |
| 26 view_ = [[[AutofillPopupViewCocoa alloc] | |
| 27 initWithController:controller_ | |
| 28 frame:[[window_ contentView] frame]] autorelease]; | |
| 29 [window_ setContentView:view_]; | |
| 30 } | |
| 31 | |
| 32 AutofillPopupViewMac::~AutofillPopupViewMac() { | |
| 33 [view_ controllerDestroyed]; | |
| 34 controller_->ViewDestroyed(); | |
| 35 | |
| 36 [window_ close]; | |
| 37 } | |
| 38 | |
| 39 void AutofillPopupViewMac::Hide() { | |
| 40 delete this; | |
| 41 } | |
| 42 | |
| 43 void AutofillPopupViewMac::Show() { | |
| 44 SetInitialBounds(); | |
| 45 UpdateBoundsAndRedrawPopup(); | |
| 46 [[controller_->container_view() window] addChildWindow:window_ | |
| 47 ordered:NSWindowAbove]; | |
| 48 } | |
| 49 | |
| 50 void AutofillPopupViewMac::InvalidateRow(size_t row) { | |
| 51 NSRect dirty_rect = | |
| 52 NSRectFromCGRect(controller_->GetRowBounds(row).ToCGRect()); | |
| 53 [view_ setNeedsDisplayInRect:dirty_rect]; | |
| 54 } | |
| 55 | |
| 56 void AutofillPopupViewMac::UpdateBoundsAndRedrawPopup() { | |
| 57 NSRect frame = NSRectFromCGRect(controller_->popup_bounds().ToCGRect()); | |
| 58 | |
| 59 // Flip coordinates back into Cocoa-land. | |
| 60 // TODO(isherman): Does this agree with the controller's idea of handling | |
| 61 // multi-monitor setups correctly? | |
| 62 NSScreen* screen = [[controller_->container_view() window] screen]; | |
| 63 frame.origin.y = [screen frame].size.height - NSMaxY(frame); | |
|
Nico
2013/01/11 16:27:38
NSHeight()
Ilya Sherman
2013/01/11 23:32:26
Done.
| |
| 64 | |
| 65 // TODO(isherman): The view should support scrolling if the popup gets too | |
| 66 // big to fit on the screen. | |
| 67 [window_ setFrame:frame display:YES]; | |
| 68 } | |
| 69 | |
| 70 void AutofillPopupViewMac::SetInitialBounds() { | |
| 71 // The bounds rect in Chrome's screen coordinates. The popup should be | |
| 72 // positioned just below the element which initiated it. | |
| 73 gfx::Rect bounds(controller_->element_bounds().x(), | |
| 74 controller_->element_bounds().bottom(), | |
| 75 controller_->GetPopupRequiredWidth(), | |
| 76 controller_->GetPopupRequiredHeight()); | |
| 77 | |
| 78 // TODO(isherman): Position the popup correctly if it can't fit below the text | |
| 79 // field: http://crbug.com/164603 | |
| 80 | |
| 81 controller_->SetPopupBounds(bounds); | |
| 82 } | |
| 83 | |
| 84 AutofillPopupView* AutofillPopupView::Create( | |
| 85 AutofillPopupController* controller) { | |
| 86 return new AutofillPopupViewMac(controller); | |
| 87 } | |
| OLD | NEW |