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" | |
| 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_ frame]] autorelease]; | |
|
Scott Hess - ex-Googler
2013/01/09 21:36:17
[window_ frame] seems wrong. I expect that -setCo
Ilya Sherman
2013/01/10 02:21:21
Done.
| |
| 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 gfx::Rect dirty_rect = controller_->GetRowBounds(row); | |
| 52 [view_ setNeedsDisplayInRect:[view_ flipRectToNSRect:dirty_rect]]; | |
| 53 } | |
| 54 | |
| 55 void AutofillPopupViewMac::UpdateBoundsAndRedrawPopup() { | |
| 56 [window_ setFrame:NSRectFromCGRect(controller_->popup_bounds().ToCGRect()) | |
| 57 display:YES]; | |
| 58 } | |
| 59 | |
| 60 void AutofillPopupViewMac::SetInitialBounds() { | |
| 61 // The bounds rect in Chrome's screen coordinates. | |
| 62 // TODO(isherman): Does this handle Hi-DPI mode correctly? According to the | |
| 63 // docs, the origin should be in screen coordinates, whereas the size should | |
| 64 // be in view coordinates. | |
|
Scott Hess - ex-Googler
2013/01/09 21:36:17
I'm not sure the various coordinate systems this T
Ilya Sherman
2013/01/10 02:21:21
Done.
| |
| 65 gfx::Rect bounds(controller_->element_bounds().x(), | |
| 66 controller_->element_bounds().bottom(), | |
|
Scott Hess - ex-Googler
2013/01/09 21:36:17
I found this confusing until I read it a couple ti
Ilya Sherman
2013/01/10 02:21:21
Done.
| |
| 67 controller_->GetPopupRequiredWidth(), | |
| 68 controller_->GetPopupRequiredHeight()); | |
| 69 | |
| 70 // Flip coordinates back into Cocoa-land. | |
| 71 // TODO(isherman): Does this handle multi-monitor setups correctly? | |
| 72 NSScreen* screen = [[NSScreen screens] objectAtIndex:0]; | |
| 73 bounds.set_y([screen frame].size.height - bounds.y() - bounds.height()); | |
|
Scott Hess - ex-Googler
2013/01/09 21:36:17
*splode*
I don't fully understand this. Shouldn'
Ilya Sherman
2013/01/10 02:21:21
That's a really good point. Done.
| |
| 74 | |
| 75 // TODO(isherman): Position the popup correctly if it can't fit below the text | |
| 76 // field: http://crbug.com/164603 | |
| 77 | |
| 78 controller_->SetPopupBounds(bounds); | |
| 79 } | |
| 80 | |
| 81 AutofillPopupView* AutofillPopupView::Create( | |
| 82 AutofillPopupController* controller) { | |
| 83 return new AutofillPopupViewMac(controller); | |
| 84 } | |
| OLD | NEW |