OLD | NEW |
1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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/resource_bundle.h" | 7 #include "app/resource_bundle.h" |
8 #include "app/text_elider.h" | 8 #include "app/text_elider.h" |
9 #include "base/sys_string_conversions.h" | 9 #include "base/sys_string_conversions.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" | |
14 #include "chrome/browser/cocoa/event_utils.h" | 13 #include "chrome/browser/cocoa/event_utils.h" |
15 #include "gfx/rect.h" | 14 #include "gfx/rect.h" |
16 #include "grit/theme_resources.h" | 15 #include "grit/theme_resources.h" |
17 #import "third_party/GTM/AppKit/GTMNSAnimation+Duration.h" | 16 #import "third_party/GTM/AppKit/GTMNSAnimation+Duration.h" |
18 #import "third_party/GTM/AppKit/GTMNSBezierPath+RoundRect.h" | 17 #import "third_party/GTM/AppKit/GTMNSBezierPath+RoundRect.h" |
19 | 18 |
20 namespace { | 19 namespace { |
21 | 20 |
22 // The size delta between the font used for the edit and the result | 21 // The size delta between the font used for the edit and the result |
23 // rows. | 22 // rows. |
(...skipping 223 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
247 | 246 |
248 // Return the currently highlighted row. Returns -1 if no row is | 247 // Return the currently highlighted row. Returns -1 if no row is |
249 // highlighted. | 248 // highlighted. |
250 - (NSInteger)highlightedRow; | 249 - (NSInteger)highlightedRow; |
251 | 250 |
252 @end | 251 @end |
253 | 252 |
254 AutocompletePopupViewMac::AutocompletePopupViewMac( | 253 AutocompletePopupViewMac::AutocompletePopupViewMac( |
255 AutocompleteEditViewMac* edit_view, | 254 AutocompleteEditViewMac* edit_view, |
256 AutocompleteEditModel* edit_model, | 255 AutocompleteEditModel* edit_model, |
257 const BubblePositioner* bubble_positioner, | |
258 Profile* profile, | 256 Profile* profile, |
259 NSTextField* field) | 257 NSTextField* field) |
260 : model_(new AutocompletePopupModel(this, edit_model, profile)), | 258 : model_(new AutocompletePopupModel(this, edit_model, profile)), |
261 edit_view_(edit_view), | 259 edit_view_(edit_view), |
262 bubble_positioner_(bubble_positioner), | |
263 field_(field), | 260 field_(field), |
264 popup_(nil) { | 261 popup_(nil) { |
265 DCHECK(edit_view); | 262 DCHECK(edit_view); |
266 DCHECK(edit_model); | 263 DCHECK(edit_model); |
267 DCHECK(profile); | 264 DCHECK(profile); |
268 edit_model->SetPopupModel(model_.get()); | 265 edit_model->SetPopupModel(model_.get()); |
269 } | 266 } |
270 | 267 |
271 AutocompletePopupViewMac::~AutocompletePopupViewMac() { | 268 AutocompletePopupViewMac::~AutocompletePopupViewMac() { |
272 // TODO(shess): Having to be aware of destructor ordering in this | 269 // TODO(shess): Having to be aware of destructor ordering in this |
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
319 [matrix setTarget:nil]; | 316 [matrix setTarget:nil]; |
320 | 317 |
321 popup_.reset(nil); | 318 popup_.reset(nil); |
322 | 319 |
323 return; | 320 return; |
324 } | 321 } |
325 | 322 |
326 CreatePopupIfNeeded(); | 323 CreatePopupIfNeeded(); |
327 | 324 |
328 // Layout the popup and size it to land underneath the field. | 325 // Layout the popup and size it to land underneath the field. |
329 NSRect r = | 326 // The field has a single-pixel border on the left and right. This |
330 NSRectFromCGRect(bubble_positioner_->GetLocationStackBounds().ToCGRect()); | 327 // needs to be factored out so that the popup window's border (which |
| 328 // is outside the frame) lines up. |
| 329 const int kLocationStackEdgeWidth = 1; |
| 330 NSRect r = NSInsetRect([field_ convertRect:[field_ bounds] toView:nil], |
| 331 kLocationStackEdgeWidth, 0); |
331 r.origin = [[field_ window] convertBaseToScreen:r.origin]; | 332 r.origin = [[field_ window] convertBaseToScreen:r.origin]; |
332 DCHECK_GT(r.size.width, 0.0); | 333 DCHECK_GT(r.size.width, 0.0); |
333 | 334 |
334 // The popup's font is a slightly smaller version of what |field_| | 335 // The popup's font is a slightly smaller version of what |field_| |
335 // uses. | 336 // uses. |
336 NSFont* fieldFont = [field_ font]; | 337 NSFont* fieldFont = [field_ font]; |
337 const CGFloat resultFontSize = [fieldFont pointSize] + kEditFontAdjust; | 338 const CGFloat resultFontSize = [fieldFont pointSize] + kEditFontAdjust; |
338 gfx::Font resultFont = gfx::Font::CreateFont( | 339 gfx::Font resultFont = gfx::Font::CreateFont( |
339 base::SysNSStringToWide([fieldFont fontName]), (int)resultFontSize); | 340 base::SysNSStringToWide([fieldFont fontName]), (int)resultFontSize); |
340 | 341 |
(...skipping 336 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
677 bottomRightCornerRadius:0.0]; | 678 bottomRightCornerRadius:0.0]; |
678 | 679 |
679 // Draw the matrix clipped to our border. | 680 // Draw the matrix clipped to our border. |
680 [NSGraphicsContext saveGraphicsState]; | 681 [NSGraphicsContext saveGraphicsState]; |
681 [path addClip]; | 682 [path addClip]; |
682 [super drawRect:rect]; | 683 [super drawRect:rect]; |
683 [NSGraphicsContext restoreGraphicsState]; | 684 [NSGraphicsContext restoreGraphicsState]; |
684 } | 685 } |
685 | 686 |
686 @end | 687 @end |
OLD | NEW |