Chromium Code Reviews| OLD | NEW |
|---|---|
| 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 #include "chrome/browser/ui/cocoa/omnibox/omnibox_view_mac.h" | 5 #include "chrome/browser/ui/cocoa/omnibox/omnibox_view_mac.h" |
| 6 | 6 |
| 7 #include <Carbon/Carbon.h> // kVK_Return | 7 #include <Carbon/Carbon.h> // kVK_Return |
| 8 | 8 |
| 9 #include "base/mac/foundation_util.h" | 9 #include "base/mac/foundation_util.h" |
| 10 #include "base/string_util.h" | 10 #include "base/string_util.h" |
| (...skipping 137 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 148 [field_ setObserver:this]; | 148 [field_ setObserver:this]; |
| 149 | 149 |
| 150 // Needed so that editing doesn't lose the styling. | 150 // Needed so that editing doesn't lose the styling. |
| 151 [field_ setAllowsEditingTextAttributes:YES]; | 151 [field_ setAllowsEditingTextAttributes:YES]; |
| 152 | 152 |
| 153 // Get the appropriate line height for the font that we use. | 153 // Get the appropriate line height for the font that we use. |
| 154 scoped_nsobject<NSLayoutManager> | 154 scoped_nsobject<NSLayoutManager> |
| 155 layoutManager([[NSLayoutManager alloc] init]); | 155 layoutManager([[NSLayoutManager alloc] init]); |
| 156 [layoutManager setUsesScreenFonts:YES]; | 156 [layoutManager setUsesScreenFonts:YES]; |
| 157 line_height_ = [layoutManager defaultLineHeightForFont:GetFieldFont()]; | 157 line_height_ = [layoutManager defaultLineHeightForFont:GetFieldFont()]; |
| 158 | |
| 159 // Extended instant uses a larger font so increase line height to reduce | |
| 160 // clipping. | |
|
Scott Hess - ex-Googler
2013/05/22 19:56:37
No, it's getting the line height from the font. I
sail
2013/05/22 20:23:55
The line height doesn't account for accents and st
Scott Hess - ex-Googler
2013/05/22 21:02:36
Yeah, but fields are doing this stuff somehow.
sail
2013/05/22 21:10:35
I'm not sure what this comment means.
| |
| 161 if (chrome::IsInstantExtendedAPIEnabled()) | |
| 162 line_height_ += 1; | |
| 163 | |
| 158 DCHECK_GT(line_height_, 0); | 164 DCHECK_GT(line_height_, 0); |
| 159 } | 165 } |
| 160 | 166 |
| 161 OmniboxViewMac::~OmniboxViewMac() { | 167 OmniboxViewMac::~OmniboxViewMac() { |
| 162 // Destroy popup view before this object in case it tries to call us | 168 // Destroy popup view before this object in case it tries to call us |
| 163 // back in the destructor. | 169 // back in the destructor. |
| 164 popup_view_.reset(); | 170 popup_view_.reset(); |
| 165 | 171 |
| 166 // Disconnect from |field_|, it outlives this object. | 172 // Disconnect from |field_|, it outlives this object. |
| 167 [field_ setObserver:NULL]; | 173 [field_ setObserver:NULL]; |
| (...skipping 263 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 431 | 437 |
| 432 [as addAttribute:NSFontAttributeName value:GetFieldFont() | 438 [as addAttribute:NSFontAttributeName value:GetFieldFont() |
| 433 range:as_entire_string]; | 439 range:as_entire_string]; |
| 434 | 440 |
| 435 // A kinda hacky way to add breaking at periods. This is what Safari does. | 441 // A kinda hacky way to add breaking at periods. This is what Safari does. |
| 436 // This works for IDNs too, despite the "en_US". | 442 // This works for IDNs too, despite the "en_US". |
| 437 [as addAttribute:@"NSLanguage" value:@"en_US_POSIX" | 443 [as addAttribute:@"NSLanguage" value:@"en_US_POSIX" |
| 438 range:as_entire_string]; | 444 range:as_entire_string]; |
| 439 | 445 |
| 440 // Make a paragraph style locking in the standard line height as the maximum, | 446 // Make a paragraph style locking in the standard line height as the maximum, |
| 441 // otherwise the baseline may shift "downwards". | 447 // otherwise the baseline may shift "downwards". |
|
Scott Hess - ex-Googler
2013/05/22 21:02:36
This seems like the relevant issue. Sure hope I d
| |
| 442 scoped_nsobject<NSMutableParagraphStyle> | 448 scoped_nsobject<NSMutableParagraphStyle> |
| 443 paragraph_style([[NSMutableParagraphStyle alloc] init]); | 449 paragraph_style([[NSMutableParagraphStyle alloc] init]); |
| 444 [paragraph_style setMaximumLineHeight:line_height_]; | 450 [paragraph_style setMaximumLineHeight:line_height_]; |
| 445 [paragraph_style setMinimumLineHeight:line_height_]; | 451 [paragraph_style setMinimumLineHeight:line_height_]; |
| 446 [as addAttribute:NSParagraphStyleAttributeName value:paragraph_style | 452 [as addAttribute:NSParagraphStyleAttributeName value:paragraph_style |
| 447 range:as_entire_string]; | 453 range:as_entire_string]; |
| 448 | 454 |
| 449 url_parse::Component scheme, host; | 455 url_parse::Component scheme, host; |
| 450 AutocompleteInput::ParseForEmphasizeComponents( | 456 AutocompleteInput::ParseForEmphasizeComponents( |
| 451 display_text, &scheme, &host); | 457 display_text, &scheme, &host); |
| (...skipping 525 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 977 | 983 |
| 978 NSUInteger OmniboxViewMac::GetTextLength() const { | 984 NSUInteger OmniboxViewMac::GetTextLength() const { |
| 979 return [field_ currentEditor] ? [[[field_ currentEditor] string] length] : | 985 return [field_ currentEditor] ? [[[field_ currentEditor] string] length] : |
| 980 [[field_ stringValue] length]; | 986 [[field_ stringValue] length]; |
| 981 } | 987 } |
| 982 | 988 |
| 983 bool OmniboxViewMac::IsCaretAtEnd() const { | 989 bool OmniboxViewMac::IsCaretAtEnd() const { |
| 984 const NSRange selection = GetSelectedRange(); | 990 const NSRange selection = GetSelectedRange(); |
| 985 return NSMaxRange(selection) == GetTextLength(); | 991 return NSMaxRange(selection) == GetTextLength(); |
| 986 } | 992 } |
| OLD | NEW |