| 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/metrics/histogram.h" | 10 #include "base/metrics/histogram.h" |
| (...skipping 258 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 269 TextChanged(); | 269 TextChanged(); |
| 270 } | 270 } |
| 271 | 271 |
| 272 void OmniboxViewMac::SetForcedQuery() { | 272 void OmniboxViewMac::SetForcedQuery() { |
| 273 // We need to do this first, else |SetSelectedRange()| won't work. | 273 // We need to do this first, else |SetSelectedRange()| won't work. |
| 274 FocusLocation(true); | 274 FocusLocation(true); |
| 275 | 275 |
| 276 const base::string16 current_text(GetText()); | 276 const base::string16 current_text(GetText()); |
| 277 const size_t start = current_text.find_first_not_of(base::kWhitespaceUTF16); | 277 const size_t start = current_text.find_first_not_of(base::kWhitespaceUTF16); |
| 278 if (start == base::string16::npos || (current_text[start] != '?')) { | 278 if (start == base::string16::npos || (current_text[start] != '?')) { |
| 279 SetUserText(ASCIIToUTF16("?")); | 279 SetUserText(base::ASCIIToUTF16("?")); |
| 280 } else { | 280 } else { |
| 281 NSRange range = NSMakeRange(start + 1, current_text.size() - start - 1); | 281 NSRange range = NSMakeRange(start + 1, current_text.size() - start - 1); |
| 282 [[field_ currentEditor] setSelectedRange:range]; | 282 [[field_ currentEditor] setSelectedRange:range]; |
| 283 } | 283 } |
| 284 } | 284 } |
| 285 | 285 |
| 286 bool OmniboxViewMac::IsSelectAll() const { | 286 bool OmniboxViewMac::IsSelectAll() const { |
| 287 if (![field_ currentEditor]) | 287 if (![field_ currentEditor]) |
| 288 return true; | 288 return true; |
| 289 const NSRange all_range = NSMakeRange(0, GetTextLength()); | 289 const NSRange all_range = NSMakeRange(0, GetTextLength()); |
| (...skipping 145 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 435 [paragraph_style setMaximumLineHeight:line_height]; | 435 [paragraph_style setMaximumLineHeight:line_height]; |
| 436 [paragraph_style setMinimumLineHeight:line_height]; | 436 [paragraph_style setMinimumLineHeight:line_height]; |
| 437 [paragraph_style setLineBreakMode:NSLineBreakByTruncatingTail]; | 437 [paragraph_style setLineBreakMode:NSLineBreakByTruncatingTail]; |
| 438 [as addAttribute:NSParagraphStyleAttributeName value:paragraph_style | 438 [as addAttribute:NSParagraphStyleAttributeName value:paragraph_style |
| 439 range:as_entire_string]; | 439 range:as_entire_string]; |
| 440 | 440 |
| 441 url_parse::Component scheme, host; | 441 url_parse::Component scheme, host; |
| 442 AutocompleteInput::ParseForEmphasizeComponents( | 442 AutocompleteInput::ParseForEmphasizeComponents( |
| 443 display_text, &scheme, &host); | 443 display_text, &scheme, &host); |
| 444 bool grey_out_url = display_text.substr(scheme.begin, scheme.len) == | 444 bool grey_out_url = display_text.substr(scheme.begin, scheme.len) == |
| 445 UTF8ToUTF16(extensions::kExtensionScheme); | 445 base::UTF8ToUTF16(extensions::kExtensionScheme); |
| 446 if (model()->CurrentTextIsURL() && | 446 if (model()->CurrentTextIsURL() && |
| 447 (host.is_nonempty() || grey_out_url)) { | 447 (host.is_nonempty() || grey_out_url)) { |
| 448 [as addAttribute:NSForegroundColorAttributeName value:BaseTextColor() | 448 [as addAttribute:NSForegroundColorAttributeName value:BaseTextColor() |
| 449 range:as_entire_string]; | 449 range:as_entire_string]; |
| 450 | 450 |
| 451 if (!grey_out_url) { | 451 if (!grey_out_url) { |
| 452 [as addAttribute:NSForegroundColorAttributeName value:HostTextColor() | 452 [as addAttribute:NSForegroundColorAttributeName value:HostTextColor() |
| 453 range:ComponentToNSRange(host)]; | 453 range:ComponentToNSRange(host)]; |
| 454 } | 454 } |
| 455 } | 455 } |
| (...skipping 496 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 952 | 952 |
| 953 NSUInteger OmniboxViewMac::GetTextLength() const { | 953 NSUInteger OmniboxViewMac::GetTextLength() const { |
| 954 return [field_ currentEditor] ? [[[field_ currentEditor] string] length] : | 954 return [field_ currentEditor] ? [[[field_ currentEditor] string] length] : |
| 955 [[field_ stringValue] length]; | 955 [[field_ stringValue] length]; |
| 956 } | 956 } |
| 957 | 957 |
| 958 bool OmniboxViewMac::IsCaretAtEnd() const { | 958 bool OmniboxViewMac::IsCaretAtEnd() const { |
| 959 const NSRange selection = GetSelectedRange(); | 959 const NSRange selection = GetSelectedRange(); |
| 960 return NSMaxRange(selection) == GetTextLength(); | 960 return NSMaxRange(selection) == GetTextLength(); |
| 961 } | 961 } |
| OLD | NEW |