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 "base/gfx/rect.h" |
10 #include "chrome/browser/autocomplete/autocomplete_edit.h" | 10 #include "chrome/browser/autocomplete/autocomplete_edit.h" |
11 #include "chrome/browser/autocomplete/autocomplete_edit_view_mac.h" | 11 #include "chrome/browser/autocomplete/autocomplete_edit_view_mac.h" |
12 #include "chrome/browser/autocomplete/autocomplete_popup_model.h" | 12 #include "chrome/browser/autocomplete/autocomplete_popup_model.h" |
| 13 #include "chrome/browser/bubble_positioner.h" |
13 #include "chrome/browser/cocoa/event_utils.h" | 14 #include "chrome/browser/cocoa/event_utils.h" |
14 #include "chrome/browser/cocoa/nsimage_cache.h" | 15 #include "chrome/browser/cocoa/nsimage_cache.h" |
15 | 16 |
16 namespace { | 17 namespace { |
17 | 18 |
18 // The size delta between the font used for the edit and the result | 19 // The size delta between the font used for the edit and the result |
19 // rows. | 20 // rows. |
20 const int kEditFontAdjust = -1; | 21 const int kEditFontAdjust = -1; |
21 | 22 |
22 // How much to adjust the cell sizing up from the default determined | 23 // How much to adjust the cell sizing up from the default determined |
(...skipping 229 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
252 - (void)middleSelect:(id)sender; | 253 - (void)middleSelect:(id)sender; |
253 | 254 |
254 // Resize the popup when the field's window resizes. | 255 // Resize the popup when the field's window resizes. |
255 - (void)windowDidResize:(NSNotification*)notification; | 256 - (void)windowDidResize:(NSNotification*)notification; |
256 | 257 |
257 @end | 258 @end |
258 | 259 |
259 AutocompletePopupViewMac::AutocompletePopupViewMac( | 260 AutocompletePopupViewMac::AutocompletePopupViewMac( |
260 AutocompleteEditViewMac* edit_view, | 261 AutocompleteEditViewMac* edit_view, |
261 AutocompleteEditModel* edit_model, | 262 AutocompleteEditModel* edit_model, |
262 AutocompletePopupPositioner* positioner, | 263 const BubblePositioner* bubble_positioner, |
263 Profile* profile, | 264 Profile* profile, |
264 NSTextField* field) | 265 NSTextField* field) |
265 : model_(new AutocompletePopupModel(this, edit_model, profile)), | 266 : model_(new AutocompletePopupModel(this, edit_model, profile)), |
266 edit_view_(edit_view), | 267 edit_view_(edit_view), |
267 positioner_(positioner), | 268 bubble_positioner_(bubble_positioner), |
268 field_(field), | 269 field_(field), |
269 matrix_target_([[AutocompleteMatrixTarget alloc] initWithPopupView:this]), | 270 matrix_target_([[AutocompleteMatrixTarget alloc] initWithPopupView:this]), |
270 popup_(nil) { | 271 popup_(nil) { |
271 DCHECK(edit_view); | 272 DCHECK(edit_view); |
272 DCHECK(edit_model); | 273 DCHECK(edit_model); |
273 DCHECK(profile); | 274 DCHECK(profile); |
274 edit_model->SetPopupModel(model_.get()); | 275 edit_model->SetPopupModel(model_.get()); |
275 } | 276 } |
276 | 277 |
277 AutocompletePopupViewMac::~AutocompletePopupViewMac() { | 278 AutocompletePopupViewMac::~AutocompletePopupViewMac() { |
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
338 object:[field_ window]]; | 339 object:[field_ window]]; |
339 | 340 |
340 popup_.reset(nil); | 341 popup_.reset(nil); |
341 | 342 |
342 return; | 343 return; |
343 } | 344 } |
344 | 345 |
345 CreatePopupIfNeeded(); | 346 CreatePopupIfNeeded(); |
346 | 347 |
347 // Layout the popup and size it to land underneath the field. | 348 // Layout the popup and size it to land underneath the field. |
348 NSRect r = NSRectFromCGRect(positioner_->GetPopupBounds().ToCGRect()); | 349 NSRect r = |
| 350 NSRectFromCGRect(bubble_positioner_->GetLocationStackBounds().ToCGRect()); |
349 r.origin = [[field_ window] convertBaseToScreen:r.origin]; | 351 r.origin = [[field_ window] convertBaseToScreen:r.origin]; |
350 DCHECK_GT(r.size.width, 0.0); | 352 DCHECK_GT(r.size.width, 0.0); |
351 | 353 |
352 // The popup's font is a slightly smaller version of what |field_| | 354 // The popup's font is a slightly smaller version of what |field_| |
353 // uses. | 355 // uses. |
354 NSFont* fieldFont = [field_ font]; | 356 NSFont* fieldFont = [field_ font]; |
355 const CGFloat resultFontSize = [fieldFont pointSize] + kEditFontAdjust; | 357 const CGFloat resultFontSize = [fieldFont pointSize] + kEditFontAdjust; |
356 gfx::Font resultFont = gfx::Font::CreateFont( | 358 gfx::Font resultFont = gfx::Font::CreateFont( |
357 base::SysNSStringToWide([fieldFont fontName]), (int)resultFontSize); | 359 base::SysNSStringToWide([fieldFont fontName]), (int)resultFontSize); |
358 | 360 |
(...skipping 329 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
688 DCHECK(popup_view_); | 690 DCHECK(popup_view_); |
689 | 691 |
690 // TODO(shess): UpdatePopupAppearance() is called frequently, so it | 692 // TODO(shess): UpdatePopupAppearance() is called frequently, so it |
691 // should be really cheap, but in this case we could probably make | 693 // should be really cheap, but in this case we could probably make |
692 // things even cheaper by refactoring between the popup-placement | 694 // things even cheaper by refactoring between the popup-placement |
693 // code and the matrix-population code. | 695 // code and the matrix-population code. |
694 popup_view_->UpdatePopupAppearance(); | 696 popup_view_->UpdatePopupAppearance(); |
695 } | 697 } |
696 | 698 |
697 @end | 699 @end |
OLD | NEW |