Chromium Code Reviews| Index: chrome/browser/ui/cocoa/autofill/autofill_popup_view_mac.mm |
| diff --git a/chrome/browser/ui/cocoa/autofill/autofill_popup_view_mac.mm b/chrome/browser/ui/cocoa/autofill/autofill_popup_view_mac.mm |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..0b02e46b42106ef4cff717a5473fdca7256f15b6 |
| --- /dev/null |
| +++ b/chrome/browser/ui/cocoa/autofill/autofill_popup_view_mac.mm |
| @@ -0,0 +1,84 @@ |
| +// Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| +// Use of this source code is governed by a BSD-style license that can be |
| +// found in the LICENSE file. |
| + |
| +#import <Cocoa/Cocoa.h> |
| + |
| +#include "chrome/browser/ui/cocoa/autofill/autofill_popup_view_mac.h" |
| + |
| +#include "base/logging.h" |
| +#include "chrome/browser/ui/autofill/autofill_popup_controller.h" |
| +#import "chrome/browser/ui/cocoa/autofill/autofill_popup_view_cocoa.h" |
| +#include "ui/base/cocoa/window_size_constants.h" |
| +#include "ui/gfx/rect.h" |
| + |
| +AutofillPopupViewMac::AutofillPopupViewMac( |
| + AutofillPopupController* controller) |
| + : controller_(controller) { |
| + window_ = |
| + [[NSWindow alloc] initWithContentRect:ui::kWindowSizeDeterminedLater |
| + styleMask:NSBorderlessWindowMask |
| + backing:NSBackingStoreBuffered |
| + defer:YES]; |
| + // Telling Cocoa that the window is opaque enables some drawing optimizations. |
| + [window_ setOpaque:YES]; |
| + |
| + view_ = [[[AutofillPopupViewCocoa alloc] |
| + initWithController:controller_ |
| + 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.
|
| + [window_ setContentView:view_]; |
| +} |
| + |
| +AutofillPopupViewMac::~AutofillPopupViewMac() { |
| + [view_ controllerDestroyed]; |
| + controller_->ViewDestroyed(); |
| + |
| + [window_ close]; |
| +} |
| + |
| +void AutofillPopupViewMac::Hide() { |
| + delete this; |
| +} |
| + |
| +void AutofillPopupViewMac::Show() { |
| + SetInitialBounds(); |
| + UpdateBoundsAndRedrawPopup(); |
| + [[controller_->container_view() window] addChildWindow:window_ |
| + ordered:NSWindowAbove]; |
| +} |
| + |
| +void AutofillPopupViewMac::InvalidateRow(size_t row) { |
| + gfx::Rect dirty_rect = controller_->GetRowBounds(row); |
| + [view_ setNeedsDisplayInRect:[view_ flipRectToNSRect:dirty_rect]]; |
| +} |
| + |
| +void AutofillPopupViewMac::UpdateBoundsAndRedrawPopup() { |
| + [window_ setFrame:NSRectFromCGRect(controller_->popup_bounds().ToCGRect()) |
| + display:YES]; |
| +} |
| + |
| +void AutofillPopupViewMac::SetInitialBounds() { |
| + // The bounds rect in Chrome's screen coordinates. |
| + // TODO(isherman): Does this handle Hi-DPI mode correctly? According to the |
| + // docs, the origin should be in screen coordinates, whereas the size should |
| + // 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.
|
| + gfx::Rect bounds(controller_->element_bounds().x(), |
| + 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.
|
| + controller_->GetPopupRequiredWidth(), |
| + controller_->GetPopupRequiredHeight()); |
| + |
| + // Flip coordinates back into Cocoa-land. |
| + // TODO(isherman): Does this handle multi-monitor setups correctly? |
| + NSScreen* screen = [[NSScreen screens] objectAtIndex:0]; |
| + 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.
|
| + |
| + // TODO(isherman): Position the popup correctly if it can't fit below the text |
| + // field: http://crbug.com/164603 |
| + |
| + controller_->SetPopupBounds(bounds); |
| +} |
| + |
| +AutofillPopupView* AutofillPopupView::Create( |
| + AutofillPopupController* controller) { |
| + return new AutofillPopupViewMac(controller); |
| +} |