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 125 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 136 | 136 |
| 137 OmniboxViewMac::OmniboxViewMac(OmniboxEditController* controller, | 137 OmniboxViewMac::OmniboxViewMac(OmniboxEditController* controller, |
| 138 ToolbarModel* toolbar_model, | 138 ToolbarModel* toolbar_model, |
| 139 Profile* profile, | 139 Profile* profile, |
| 140 CommandUpdater* command_updater, | 140 CommandUpdater* command_updater, |
| 141 AutocompleteTextField* field) | 141 AutocompleteTextField* field) |
| 142 : OmniboxView(profile, controller, toolbar_model, command_updater), | 142 : OmniboxView(profile, controller, toolbar_model, command_updater), |
| 143 popup_view_(OmniboxPopupViewMac::Create(this, model(), field)), | 143 popup_view_(OmniboxPopupViewMac::Create(this, model(), field)), |
| 144 field_(field), | 144 field_(field), |
| 145 delete_was_pressed_(false), | 145 delete_was_pressed_(false), |
| 146 delete_at_end_pressed_(false), | 146 delete_at_end_pressed_(false) { |
| 147 line_height_(0) { | |
| 148 [field_ setObserver:this]; | 147 [field_ setObserver:this]; |
| 149 | 148 |
| 150 // Needed so that editing doesn't lose the styling. | 149 // Needed so that editing doesn't lose the styling. |
| 151 [field_ setAllowsEditingTextAttributes:YES]; | 150 [field_ setAllowsEditingTextAttributes:YES]; |
| 152 | 151 |
| 153 // Get the appropriate line height for the font that we use. | 152 // Get the appropriate line height for the font that we use. |
| 154 scoped_nsobject<NSLayoutManager> | 153 scoped_nsobject<NSLayoutManager> |
| 155 layoutManager([[NSLayoutManager alloc] init]); | 154 layoutManager([[NSLayoutManager alloc] init]); |
| 156 [layoutManager setUsesScreenFonts:YES]; | 155 [layoutManager setUsesScreenFonts:YES]; |
| 157 line_height_ = [layoutManager defaultLineHeightForFont:GetFieldFont()]; | |
| 158 DCHECK_GT(line_height_, 0); | |
| 159 } | 156 } |
| 160 | 157 |
| 161 OmniboxViewMac::~OmniboxViewMac() { | 158 OmniboxViewMac::~OmniboxViewMac() { |
| 162 // Destroy popup view before this object in case it tries to call us | 159 // Destroy popup view before this object in case it tries to call us |
| 163 // back in the destructor. | 160 // back in the destructor. |
| 164 popup_view_.reset(); | 161 popup_view_.reset(); |
| 165 | 162 |
| 166 // Disconnect from |field_|, it outlives this object. | 163 // Disconnect from |field_|, it outlives this object. |
| 167 [field_ setObserver:NULL]; | 164 [field_ setObserver:NULL]; |
| 168 } | 165 } |
| (...skipping 265 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 434 | 431 |
| 435 // A kinda hacky way to add breaking at periods. This is what Safari does. | 432 // A kinda hacky way to add breaking at periods. This is what Safari does. |
| 436 // This works for IDNs too, despite the "en_US". | 433 // This works for IDNs too, despite the "en_US". |
| 437 [as addAttribute:@"NSLanguage" value:@"en_US_POSIX" | 434 [as addAttribute:@"NSLanguage" value:@"en_US_POSIX" |
| 438 range:as_entire_string]; | 435 range:as_entire_string]; |
| 439 | 436 |
| 440 // Make a paragraph style locking in the standard line height as the maximum, | 437 // Make a paragraph style locking in the standard line height as the maximum, |
| 441 // otherwise the baseline may shift "downwards". | 438 // otherwise the baseline may shift "downwards". |
| 442 scoped_nsobject<NSMutableParagraphStyle> | 439 scoped_nsobject<NSMutableParagraphStyle> |
| 443 paragraph_style([[NSMutableParagraphStyle alloc] init]); | 440 paragraph_style([[NSMutableParagraphStyle alloc] init]); |
| 444 [paragraph_style setMaximumLineHeight:line_height_]; | 441 [paragraph_style setMaximumLineHeight:[[field_ cell] lineHeight]]; |
| 445 [paragraph_style setMinimumLineHeight:line_height_]; | 442 [paragraph_style setMinimumLineHeight:[[field_ cell] lineHeight]]; |
|
Scott Hess - ex-Googler
2013/05/23 20:08:02
Definitely memoize this, since the compiler cannot
sail
2013/05/23 20:45:44
Done.
| |
| 446 [as addAttribute:NSParagraphStyleAttributeName value:paragraph_style | 443 [as addAttribute:NSParagraphStyleAttributeName value:paragraph_style |
| 447 range:as_entire_string]; | 444 range:as_entire_string]; |
| 448 | 445 |
| 449 url_parse::Component scheme, host; | 446 url_parse::Component scheme, host; |
| 450 AutocompleteInput::ParseForEmphasizeComponents( | 447 AutocompleteInput::ParseForEmphasizeComponents( |
| 451 display_text, &scheme, &host); | 448 display_text, &scheme, &host); |
| 452 bool grey_out_url = display_text.substr(scheme.begin, scheme.len) == | 449 bool grey_out_url = display_text.substr(scheme.begin, scheme.len) == |
| 453 UTF8ToUTF16(extensions::kExtensionScheme); | 450 UTF8ToUTF16(extensions::kExtensionScheme); |
| 454 if (model()->CurrentTextIsURL() && | 451 if (model()->CurrentTextIsURL() && |
| 455 (host.is_nonempty() || grey_out_url)) { | 452 (host.is_nonempty() || grey_out_url)) { |
| (...skipping 521 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 977 | 974 |
| 978 NSUInteger OmniboxViewMac::GetTextLength() const { | 975 NSUInteger OmniboxViewMac::GetTextLength() const { |
| 979 return [field_ currentEditor] ? [[[field_ currentEditor] string] length] : | 976 return [field_ currentEditor] ? [[[field_ currentEditor] string] length] : |
| 980 [[field_ stringValue] length]; | 977 [[field_ stringValue] length]; |
| 981 } | 978 } |
| 982 | 979 |
| 983 bool OmniboxViewMac::IsCaretAtEnd() const { | 980 bool OmniboxViewMac::IsCaretAtEnd() const { |
| 984 const NSRange selection = GetSelectedRange(); | 981 const NSRange selection = GetSelectedRange(); |
| 985 return NSMaxRange(selection) == GetTextLength(); | 982 return NSMaxRange(selection) == GetTextLength(); |
| 986 } | 983 } |
| OLD | NEW |