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

Side by Side 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: 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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
(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 // TODO(isherman): Should this be NSPopupMenuWindowLevel or perhaps
24 // NSFloatingWindowLevel or NSModalPanelWindowLevel instead?
Ilya Sherman 2013/01/04 01:24:29 Friendly Cocoa reviewers: Thoughts?
Scott Hess - ex-Googler 2013/01/05 01:06:49 Omnibox is at NSNormalWindowLevel. Levels are a b
Ilya Sherman 2013/01/05 03:14:10 Done.
25 [window_ setLevel:NSNormalWindowLevel];
26 // TODO(isherman): Are these explicit calls needed / recommended?
Ilya Sherman 2013/01/04 01:24:29 Friendly Cocoa reviewers: Thoughts?
Scott Hess - ex-Googler 2013/01/05 01:06:49 For borderless, you might need to disable moving b
Ilya Sherman 2013/01/05 03:14:10 It looks like everything works if I remove all of
27 [window_ setMovableByWindowBackground:NO];
28 [window_ setBackgroundColor:[NSColor clearColor]];
29 [window_ setAlphaValue:1.0];
30 [window_ setOpaque:YES];
31 [window_ setHasShadow:NO];
32 [window_ accessibilitySetOverrideValue:NSAccessibilityUnknownRole
33 forAttribute:NSAccessibilityRoleAttribute];
34
35 view_ = [[[AutofillPopupViewCocoa alloc]
36 initWithController:controller_
37 frame:[window_ frame]] autorelease];
38 [window_ setContentView:view_];
39 }
40
41 AutofillPopupViewMac::~AutofillPopupViewMac() {
42 [view_ controllerDestroyed];
Scott Hess - ex-Googler 2013/01/05 01:06:49 Since this is called from the destructor, you migh
Ilya Sherman 2013/01/05 03:14:10 Sorry, I'm confused -- document where?
Scott Hess - ex-Googler 2013/01/09 21:36:17 I mean that -controllerDestroyed cannot send any m
Ilya Sherman 2013/01/10 02:21:21 Done.
43 controller_->ViewDestroyed();
44
45 [window_ close];
46 }
47
48 void AutofillPopupViewMac::Hide() {
49 delete this;
50 }
51
52 void AutofillPopupViewMac::Show() {
53 SetInitialBounds();
54 UpdateBoundsAndRedrawPopup();
55 [[controller_->container_view() window] addChildWindow:window_
56 ordered:NSWindowAbove];
57 }
58
59 void AutofillPopupViewMac::InvalidateRow(size_t row) {
60 gfx::Rect dirty_rect = controller_->GetRowBounds(row);
61 [view_ setNeedsDisplayInRect:[view_ flipRectToNSRect:dirty_rect]];
62 }
63
64 void AutofillPopupViewMac::UpdateBoundsAndRedrawPopup() {
65 [window_ setFrame:NSRectFromCGRect(controller_->popup_bounds().ToCGRect())
66 display:YES];
67 }
68
69 void AutofillPopupViewMac::SetInitialBounds() {
70 // The bounds rect in Chrome's screen coordinates.
71 // TODO(isherman): Does this handle Hi-DPI mode correctly? According to the
72 // docs, the origin should be in screen coordinates, whereas the size should
73 // be in view coordinates.
Ilya Sherman 2013/01/04 01:24:29 Friendly Cocoa reviewers: Thoughts?
Scott Hess - ex-Googler 2013/01/05 01:06:49 I think I'm going to need to patch this in and loo
Ilya Sherman 2013/01/05 03:14:10 As preconditions, you'll need to enable the flag f
Scott Hess - ex-Googler 2013/01/09 21:36:17 Weird. When I double-click a field, then click (e
Ilya Sherman 2013/01/10 02:21:21 Huh, I don't see that behavior. I guess this mean
Ilya Sherman 2013/01/10 04:17:15 According to the docs, the separators do indeed me
74 gfx::Rect bounds(controller_->element_bounds().x(),
75 controller_->element_bounds().bottom(),
76 controller_->GetPopupRequiredWidth(),
77 controller_->GetPopupRequiredHeight());
78
79 // Flip coordinates back into Cocoa-land.
80 // TODO(isherman): Does this handle multi-monitor setups correctly?
81 NSScreen* screen = [[NSScreen screens] objectAtIndex:0];
82 bounds.set_y([screen frame].size.height - bounds.y() - bounds.height());
83
84 // TODO(isherman): Position the popup correctly if it can't fit below the text
85 // field: http://crbug.com/164603
86
87 controller_->SetPopupBounds(bounds);
88 }
89
90 AutofillPopupView* AutofillPopupView::Create(
91 AutofillPopupController* controller) {
92 return new AutofillPopupViewMac(controller);
93 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698