| 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" |
| 11 #include "base/strings/string_util.h" | 11 #include "base/strings/string_util.h" |
| 12 #include "base/strings/sys_string_conversions.h" | 12 #include "base/strings/sys_string_conversions.h" |
| 13 #include "base/strings/utf_string_conversions.h" | 13 #include "base/strings/utf_string_conversions.h" |
| 14 #include "chrome/browser/autocomplete/autocomplete_match.h" | 14 #include "chrome/browser/autocomplete/autocomplete_match.h" |
| 15 #include "chrome/browser/autocomplete/chrome_autocomplete_scheme_classifier.h" | 15 #include "chrome/browser/autocomplete/chrome_autocomplete_scheme_classifier.h" |
| 16 #include "chrome/browser/browser_process.h" | 16 #include "chrome/browser/browser_process.h" |
| 17 #include "chrome/browser/omnibox/omnibox_field_trial.h" |
| 17 #include "chrome/browser/search/search.h" | 18 #include "chrome/browser/search/search.h" |
| 18 #include "chrome/browser/ui/cocoa/location_bar/autocomplete_text_field_cell.h" | 19 #include "chrome/browser/ui/cocoa/location_bar/autocomplete_text_field_cell.h" |
| 19 #import "chrome/browser/ui/cocoa/location_bar/autocomplete_text_field_editor.h" | 20 #import "chrome/browser/ui/cocoa/location_bar/autocomplete_text_field_editor.h" |
| 20 #include "chrome/browser/ui/cocoa/omnibox/omnibox_popup_view_mac.h" | 21 #include "chrome/browser/ui/cocoa/omnibox/omnibox_popup_view_mac.h" |
| 21 #include "chrome/browser/ui/omnibox/omnibox_edit_controller.h" | 22 #include "chrome/browser/ui/omnibox/omnibox_edit_controller.h" |
| 22 #include "chrome/browser/ui/omnibox/omnibox_popup_model.h" | 23 #include "chrome/browser/ui/omnibox/omnibox_popup_model.h" |
| 23 #include "chrome/browser/ui/toolbar/toolbar_model.h" | 24 #include "chrome/browser/ui/toolbar/toolbar_model.h" |
| 24 #include "components/autocomplete/autocomplete_input.h" | 25 #include "components/autocomplete/autocomplete_input.h" |
| 25 #include "content/public/browser/web_contents.h" | 26 #include "content/public/browser/web_contents.h" |
| 26 #include "extensions/common/constants.h" | 27 #include "extensions/common/constants.h" |
| (...skipping 200 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 227 // guard it with a test for whether the security level changed. | 228 // guard it with a test for whether the security level changed. |
| 228 // But AFAICT, that can only change if the text changed, and that | 229 // But AFAICT, that can only change if the text changed, and that |
| 229 // code compares the toolbar model security level with the local | 230 // code compares the toolbar model security level with the local |
| 230 // security level. Dig in and figure out why this isn't a no-op | 231 // security level. Dig in and figure out why this isn't a no-op |
| 231 // that should go away. | 232 // that should go away. |
| 232 EmphasizeURLComponents(); | 233 EmphasizeURLComponents(); |
| 233 } | 234 } |
| 234 } | 235 } |
| 235 | 236 |
| 236 void OmniboxViewMac::UpdatePlaceholderText() { | 237 void OmniboxViewMac::UpdatePlaceholderText() { |
| 237 if (chrome::ShouldDisplayOriginChip()) { | 238 if (chrome::ShouldDisplayOriginChip() || |
| 239 OmniboxFieldTrial::DisplayHintTextWhenPossible()) { |
| 238 NSDictionary* placeholder_attributes = @{ | 240 NSDictionary* placeholder_attributes = @{ |
| 239 NSFontAttributeName : GetFieldFont(gfx::Font::NORMAL), | 241 NSFontAttributeName : GetFieldFont(gfx::Font::NORMAL), |
| 240 NSForegroundColorAttributeName : [NSColor disabledControlTextColor] | 242 NSForegroundColorAttributeName : [NSColor disabledControlTextColor] |
| 241 }; | 243 }; |
| 242 base::scoped_nsobject<NSMutableAttributedString> placeholder_text( | 244 base::scoped_nsobject<NSMutableAttributedString> placeholder_text( |
| 243 [[NSMutableAttributedString alloc] | 245 [[NSMutableAttributedString alloc] |
| 244 initWithString:base::SysUTF16ToNSString(GetHintText()) | 246 initWithString:base::SysUTF16ToNSString(GetHintText()) |
| 245 attributes:placeholder_attributes]); | 247 attributes:placeholder_attributes]); |
| 246 [[field_ cell] setPlaceholderAttributedString:placeholder_text]; | 248 [[field_ cell] setPlaceholderAttributedString:placeholder_text]; |
| 247 } | 249 } |
| (...skipping 772 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1020 | 1022 |
| 1021 NSUInteger OmniboxViewMac::GetTextLength() const { | 1023 NSUInteger OmniboxViewMac::GetTextLength() const { |
| 1022 return [field_ currentEditor] ? [[[field_ currentEditor] string] length] : | 1024 return [field_ currentEditor] ? [[[field_ currentEditor] string] length] : |
| 1023 [[field_ stringValue] length]; | 1025 [[field_ stringValue] length]; |
| 1024 } | 1026 } |
| 1025 | 1027 |
| 1026 bool OmniboxViewMac::IsCaretAtEnd() const { | 1028 bool OmniboxViewMac::IsCaretAtEnd() const { |
| 1027 const NSRange selection = GetSelectedRange(); | 1029 const NSRange selection = GetSelectedRange(); |
| 1028 return NSMaxRange(selection) == GetTextLength(); | 1030 return NSMaxRange(selection) == GetTextLength(); |
| 1029 } | 1031 } |
| OLD | NEW |