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

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

Issue 17733005: [Autofill] (Mostly) fix Autofill popup positioning on multiple monitors. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Expand comment and use NSMaxY instead of NSHeight Created 7 years, 5 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
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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"
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after
85 85
86 void AutofillPopupViewBridge::InvalidateRow(size_t row) { 86 void AutofillPopupViewBridge::InvalidateRow(size_t row) {
87 NSRect dirty_rect = 87 NSRect dirty_rect =
88 NSRectFromCGRect(controller_->GetRowBounds(row).ToCGRect()); 88 NSRectFromCGRect(controller_->GetRowBounds(row).ToCGRect());
89 [view_ setNeedsDisplayInRect:dirty_rect]; 89 [view_ setNeedsDisplayInRect:dirty_rect];
90 } 90 }
91 91
92 void AutofillPopupViewBridge::UpdateBoundsAndRedrawPopup() { 92 void AutofillPopupViewBridge::UpdateBoundsAndRedrawPopup() {
93 NSRect frame = NSRectFromCGRect(controller_->popup_bounds().ToCGRect()); 93 NSRect frame = NSRectFromCGRect(controller_->popup_bounds().ToCGRect());
94 94
95 // Flip coordinates back into Cocoa-land. 95 // Flip coordinates back into Cocoa-land. The controller's platform-neutral
96 // TODO(isherman): Does this agree with the controller's idea of handling 96 // coordinate space places the origin at the top-left of the first screen,
97 // multi-monitor setups correctly? 97 // whereas Cocoa's coordinate space expects the origin to be at the
98 NSScreen* screen = [[controller_->container_view() window] screen]; 98 // bottom-left of this same screen.
99 frame.origin.y = NSHeight([screen frame]) - NSMaxY(frame); 99 NSScreen* screen = [[NSScreen screens] objectAtIndex:0];
100 frame.origin.y = NSMaxY([screen frame]) - NSMaxY(frame);
100 101
101 // Leave room for the border. 102 // Leave room for the border.
102 frame = NSInsetRect(frame, -kBorderWidth, -kBorderWidth); 103 frame = NSInsetRect(frame, -kBorderWidth, -kBorderWidth);
103 if (controller_->popup_bounds().y() > controller_->element_bounds().y()) { 104 if (controller_->popup_bounds().y() > controller_->element_bounds().y()) {
104 // Popup is below the element which initiated it. 105 // Popup is below the element which initiated it.
105 frame.origin.y -= kBorderWidth; 106 frame.origin.y -= kBorderWidth;
106 } else { 107 } else {
107 // Popup is above the element which initiated it. 108 // Popup is above the element which initiated it.
108 frame.origin.y += kBorderWidth; 109 frame.origin.y += kBorderWidth;
109 } 110 }
110 if (controller_->popup_bounds().x() == controller_->element_bounds().x()) { 111 if (controller_->popup_bounds().x() == controller_->element_bounds().x()) {
111 // Popup is anchored to the left of the element which initiated it. 112 // Popup is anchored to the left of the element which initiated it.
112 frame.origin.x += kBorderWidth; 113 frame.origin.x += kBorderWidth;
113 } else { 114 } else {
114 // Popup is anhored to the right of the element which initiated it. 115 // Popup is anhored to the right of the element which initiated it.
115 frame.origin.x -= kBorderWidth; 116 frame.origin.x -= kBorderWidth;
116 } 117 }
117 118
118 // TODO(isherman): The view should support scrolling if the popup gets too 119 // TODO(isherman): The view should support scrolling if the popup gets too
119 // big to fit on the screen. 120 // big to fit on the screen.
120 [window_ setFrame:frame display:YES]; 121 [window_ setFrame:frame display:YES];
121 } 122 }
122 123
123 AutofillPopupView* AutofillPopupView::Create( 124 AutofillPopupView* AutofillPopupView::Create(
124 AutofillPopupController* controller) { 125 AutofillPopupController* controller) {
125 return new AutofillPopupViewBridge(controller); 126 return new AutofillPopupViewBridge(controller);
126 } 127 }
127 128
128 } // namespace autofill 129 } // namespace autofill
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698