Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(3128)

Unified Diff: chrome/browser/ui/cocoa/autofill/autofill_popup_view_mac.mm

Issue 11740033: [Autofill] Add Mac implementation for the in-browser process popup view. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Screen handling Created 7 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
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..4d563f04c377f779a1385784e5ddc7829a8b3d2f
--- /dev/null
+++ b/chrome/browser/ui/cocoa/autofill/autofill_popup_view_mac.mm
@@ -0,0 +1,87 @@
+// 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"
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
+
+#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_ contentView] frame]] autorelease];
+ [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) {
+ NSRect dirty_rect =
+ NSRectFromCGRect(controller_->GetRowBounds(row).ToCGRect());
+ [view_ setNeedsDisplayInRect:dirty_rect];
+}
+
+void AutofillPopupViewMac::UpdateBoundsAndRedrawPopup() {
+ NSRect frame = NSRectFromCGRect(controller_->popup_bounds().ToCGRect());
+
+ // Flip coordinates back into Cocoa-land.
+ // TODO(isherman): Does this agree with the controller's idea of handling
+ // multi-monitor setups correctly?
+ NSScreen* screen = [[controller_->container_view() window] screen];
+ 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.
+
+ // TODO(isherman): The view should support scrolling if the popup gets too
+ // big to fit on the screen.
+ [window_ setFrame:frame display:YES];
+}
+
+void AutofillPopupViewMac::SetInitialBounds() {
+ // The bounds rect in Chrome's screen coordinates. The popup should be
+ // positioned just below the element which initiated it.
+ gfx::Rect bounds(controller_->element_bounds().x(),
+ controller_->element_bounds().bottom(),
+ controller_->GetPopupRequiredWidth(),
+ controller_->GetPopupRequiredHeight());
+
+ // 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);
+}

Powered by Google App Engine
This is Rietveld 408576698