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

Side by Side Diff: chrome/browser/ui/cocoa/autofill/autofill_popup_view_bridge.mm

Issue 267183002: Password manager: Implement password generation UI for Mac. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Rebase. Created 6 years, 7 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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
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_ controllerDestroyed];
36 27 [view_ hidePopup];
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 } 28 }
43 29
44 void AutofillPopupViewBridge::Hide() { 30 void AutofillPopupViewBridge::Hide() {
45 delete this; 31 delete this;
46 } 32 }
47 33
48 void AutofillPopupViewBridge::Show() { 34 void AutofillPopupViewBridge::Show() {
49 UpdateBoundsAndRedrawPopup(); 35 [view_ showPopup];
50 [[controller_->container_view() window] addChildWindow:window_
51 ordered:NSWindowAbove];
52 } 36 }
53 37
54 void AutofillPopupViewBridge::InvalidateRow(size_t row) { 38 void AutofillPopupViewBridge::InvalidateRow(size_t row) {
55 NSRect dirty_rect = 39 [view_ invalidateRow:row];
56 NSRectFromCGRect(controller_->GetRowBounds(row).ToCGRect());
57 [view_ setNeedsDisplayInRect:dirty_rect];
58 } 40 }
59 41
60 void AutofillPopupViewBridge::UpdateBoundsAndRedrawPopup() { 42 void AutofillPopupViewBridge::UpdateBoundsAndRedrawPopup() {
61 NSRect frame = NSRectFromCGRect(controller_->popup_bounds().ToCGRect()); 43 [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 } 44 }
75 45
76 AutofillPopupView* AutofillPopupView::Create( 46 AutofillPopupView* AutofillPopupView::Create(
77 AutofillPopupController* controller) { 47 AutofillPopupController* controller) {
78 return new AutofillPopupViewBridge(controller); 48 return new AutofillPopupViewBridge(controller);
79 } 49 }
80 50
81 } // namespace autofill 51 } // namespace autofill
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698