OLD | NEW |
1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2009 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 #include "chrome/browser/autocomplete/autocomplete_popup_view_mac.h" | 5 #include "chrome/browser/autocomplete/autocomplete_popup_view_mac.h" |
6 | 6 |
7 #include "app/gfx/text_elider.h" | 7 #include "app/gfx/text_elider.h" |
8 #include "base/sys_string_conversions.h" | 8 #include "base/sys_string_conversions.h" |
| 9 #include "base/gfx/rect.h" |
9 #include "chrome/browser/autocomplete/autocomplete_edit.h" | 10 #include "chrome/browser/autocomplete/autocomplete_edit.h" |
10 #include "chrome/browser/autocomplete/autocomplete_edit_view_mac.h" | 11 #include "chrome/browser/autocomplete/autocomplete_edit_view_mac.h" |
11 #include "chrome/browser/autocomplete/autocomplete_popup_model.h" | 12 #include "chrome/browser/autocomplete/autocomplete_popup_model.h" |
12 #include "chrome/browser/cocoa/event_utils.h" | 13 #include "chrome/browser/cocoa/event_utils.h" |
13 #include "chrome/browser/cocoa/nsimage_cache.h" | 14 #include "chrome/browser/cocoa/nsimage_cache.h" |
14 | 15 |
15 namespace { | 16 namespace { |
16 | 17 |
17 // The size delta between the font used for the edit and the result | 18 // The size delta between the font used for the edit and the result |
18 // rows. | 19 // rows. |
(...skipping 210 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
229 - (void)select:sender; | 230 - (void)select:sender; |
230 | 231 |
231 // Resize the popup when the field's window resizes. | 232 // Resize the popup when the field's window resizes. |
232 - (void)windowDidResize:(NSNotification*)notification; | 233 - (void)windowDidResize:(NSNotification*)notification; |
233 | 234 |
234 @end | 235 @end |
235 | 236 |
236 AutocompletePopupViewMac::AutocompletePopupViewMac( | 237 AutocompletePopupViewMac::AutocompletePopupViewMac( |
237 AutocompleteEditViewMac* edit_view, | 238 AutocompleteEditViewMac* edit_view, |
238 AutocompleteEditModel* edit_model, | 239 AutocompleteEditModel* edit_model, |
| 240 AutocompletePopupPositioner* positioner, |
239 Profile* profile, | 241 Profile* profile, |
240 NSTextField* field) | 242 NSTextField* field) |
241 : model_(new AutocompletePopupModel(this, edit_model, profile)), | 243 : model_(new AutocompletePopupModel(this, edit_model, profile)), |
242 edit_view_(edit_view), | 244 edit_view_(edit_view), |
| 245 positioner_(positioner), |
243 field_(field), | 246 field_(field), |
244 matrix_target_([[AutocompleteMatrixTarget alloc] initWithPopupView:this]), | 247 matrix_target_([[AutocompleteMatrixTarget alloc] initWithPopupView:this]), |
245 popup_(nil) { | 248 popup_(nil) { |
246 DCHECK(edit_view); | 249 DCHECK(edit_view); |
247 DCHECK(edit_model); | 250 DCHECK(edit_model); |
248 DCHECK(profile); | 251 DCHECK(profile); |
249 edit_model->set_popup_model(model_.get()); | 252 edit_model->set_popup_model(model_.get()); |
250 } | 253 } |
251 | 254 |
252 AutocompletePopupViewMac::~AutocompletePopupViewMac() { | 255 AutocompletePopupViewMac::~AutocompletePopupViewMac() { |
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
309 object:[field_ window]]; | 312 object:[field_ window]]; |
310 | 313 |
311 popup_.reset(nil); | 314 popup_.reset(nil); |
312 | 315 |
313 return; | 316 return; |
314 } | 317 } |
315 | 318 |
316 CreatePopupIfNeeded(); | 319 CreatePopupIfNeeded(); |
317 | 320 |
318 // Layout the popup and size it to land underneath the field. | 321 // Layout the popup and size it to land underneath the field. |
319 // TODO(shess) Consider refactoring to remove this depenency, | 322 NSRect r = NSRectFromCGRect(positioner_->GetPopupBounds().ToCGRect()); |
320 // because the popup doesn't need any of the field-like aspects of | |
321 // field_. The edit view could expose helper methods for attaching | |
322 // the window to the field. | |
323 | |
324 // Locate |field_| on the screen, and pad the left and right sides | |
325 // by the height to make it wide enough to include the star and go | |
326 // buttons. | |
327 // TODO(shess): This assumes that those buttons will be square. | |
328 // Better to plumb through so that this code can get the rect from | |
329 // the toolbar controller? | |
330 NSRect r = [field_ convertRect:[field_ bounds] toView:nil]; | |
331 r.origin.x -= r.size.height; | |
332 r.size.width += 2 * r.size.height; | |
333 r.origin = [[field_ window] convertBaseToScreen:r.origin]; | 323 r.origin = [[field_ window] convertBaseToScreen:r.origin]; |
334 DCHECK_GT(r.size.width, 0.0); | 324 DCHECK_GT(r.size.width, 0.0); |
335 | 325 |
336 // The popup's font is a slightly smaller version of what |field_| | 326 // The popup's font is a slightly smaller version of what |field_| |
337 // uses. | 327 // uses. |
338 NSFont* fieldFont = [field_ font]; | 328 NSFont* fieldFont = [field_ font]; |
339 const CGFloat resultFontSize = [fieldFont pointSize] + kEditFontAdjust; | 329 const CGFloat resultFontSize = [fieldFont pointSize] + kEditFontAdjust; |
340 gfx::Font resultFont = gfx::Font::CreateFont( | 330 gfx::Font resultFont = gfx::Font::CreateFont( |
341 base::SysNSStringToWide([fieldFont fontName]), (int)resultFontSize); | 331 base::SysNSStringToWide([fieldFont fontName]), (int)resultFontSize); |
342 | 332 |
(...skipping 267 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
610 DCHECK(popup_view_); | 600 DCHECK(popup_view_); |
611 | 601 |
612 // TODO(shess): UpdatePopupAppearance() is called frequently, so it | 602 // TODO(shess): UpdatePopupAppearance() is called frequently, so it |
613 // should be really cheap, but in this case we could probably make | 603 // should be really cheap, but in this case we could probably make |
614 // things even cheaper by refactoring between the popup-placement | 604 // things even cheaper by refactoring between the popup-placement |
615 // code and the matrix-population code. | 605 // code and the matrix-population code. |
616 popup_view_->UpdatePopupAppearance(); | 606 popup_view_->UpdatePopupAppearance(); |
617 } | 607 } |
618 | 608 |
619 @end | 609 @end |
OLD | NEW |