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/metrics/histogram.h" | 10 #include "base/metrics/histogram.h" |
| (...skipping 220 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 231 // guard it with a test for whether the security level changed. | 231 // guard it with a test for whether the security level changed. |
| 232 // But AFAICT, that can only change if the text changed, and that | 232 // But AFAICT, that can only change if the text changed, and that |
| 233 // code compares the toolbar model security level with the local | 233 // code compares the toolbar model security level with the local |
| 234 // security level. Dig in and figure out why this isn't a no-op | 234 // security level. Dig in and figure out why this isn't a no-op |
| 235 // that should go away. | 235 // that should go away. |
| 236 EmphasizeURLComponents(); | 236 EmphasizeURLComponents(); |
| 237 } | 237 } |
| 238 } | 238 } |
| 239 | 239 |
| 240 void OmniboxViewMac::UpdatePlaceholderText() { | 240 void OmniboxViewMac::UpdatePlaceholderText() { |
| 241 if (chrome::ShouldDisplayOriginChip() || | 241 if (OmniboxFieldTrial::DisplayHintTextWhenPossible()) { |
|
Justin Donnelly
2014/12/03 16:07:25
It's probably worth double-checking that this fiel
groby-ooo-7-16
2015/01/10 00:54:06
DisplayHintText was introduced as part of origin c
| |
| 242 OmniboxFieldTrial::DisplayHintTextWhenPossible()) { | |
| 243 NSDictionary* placeholder_attributes = @{ | 242 NSDictionary* placeholder_attributes = @{ |
| 244 NSFontAttributeName : GetFieldFont(gfx::Font::NORMAL), | 243 NSFontAttributeName : GetFieldFont(gfx::Font::NORMAL), |
| 245 NSForegroundColorAttributeName : [NSColor disabledControlTextColor] | 244 NSForegroundColorAttributeName : [NSColor disabledControlTextColor] |
| 246 }; | 245 }; |
| 247 base::scoped_nsobject<NSMutableAttributedString> placeholder_text( | 246 base::scoped_nsobject<NSMutableAttributedString> placeholder_text( |
| 248 [[NSMutableAttributedString alloc] | 247 [[NSMutableAttributedString alloc] |
| 249 initWithString:base::SysUTF16ToNSString(GetHintText()) | 248 initWithString:base::SysUTF16ToNSString(GetHintText()) |
| 250 attributes:placeholder_attributes]); | 249 attributes:placeholder_attributes]); |
| 251 [[field_ cell] setPlaceholderAttributedString:placeholder_text]; | 250 [[field_ cell] setPlaceholderAttributedString:placeholder_text]; |
| 252 } | 251 } |
| (...skipping 576 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 829 } | 828 } |
| 830 } | 829 } |
| 831 } | 830 } |
| 832 | 831 |
| 833 return false; | 832 return false; |
| 834 } | 833 } |
| 835 | 834 |
| 836 void OmniboxViewMac::OnSetFocus(bool control_down) { | 835 void OmniboxViewMac::OnSetFocus(bool control_down) { |
| 837 model()->OnSetFocus(control_down); | 836 model()->OnSetFocus(control_down); |
| 838 controller()->OnSetFocus(); | 837 controller()->OnSetFocus(); |
| 839 | |
| 840 HandleOriginChipMouseRelease(); | |
| 841 } | 838 } |
| 842 | 839 |
| 843 void OmniboxViewMac::OnKillFocus() { | 840 void OmniboxViewMac::OnKillFocus() { |
| 844 // Tell the model to reset itself. | 841 // Tell the model to reset itself. |
| 845 model()->OnWillKillFocus(); | 842 model()->OnWillKillFocus(); |
| 846 model()->OnKillFocus(); | 843 model()->OnKillFocus(); |
| 847 | |
| 848 OnDidKillFocus(); | |
| 849 } | 844 } |
| 850 | 845 |
| 851 void OmniboxViewMac::OnMouseDown(NSInteger button_number) { | 846 void OmniboxViewMac::OnMouseDown(NSInteger button_number) { |
| 852 // Restore caret visibility whenever the user clicks in the the omnibox. This | 847 // Restore caret visibility whenever the user clicks in the the omnibox. This |
| 853 // is not always covered by OnSetFocus() because when clicking while the | 848 // is not always covered by OnSetFocus() because when clicking while the |
| 854 // omnibox has invisible focus does not trigger a new OnSetFocus() call. | 849 // omnibox has invisible focus does not trigger a new OnSetFocus() call. |
| 855 if (button_number == 0 || button_number == 1) | 850 if (button_number == 0 || button_number == 1) |
| 856 model()->SetCaretVisibility(true); | 851 model()->SetCaretVisibility(true); |
| 857 } | 852 } |
| 858 | 853 |
| (...skipping 166 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1025 | 1020 |
| 1026 NSUInteger OmniboxViewMac::GetTextLength() const { | 1021 NSUInteger OmniboxViewMac::GetTextLength() const { |
| 1027 return [field_ currentEditor] ? [[[field_ currentEditor] string] length] : | 1022 return [field_ currentEditor] ? [[[field_ currentEditor] string] length] : |
| 1028 [[field_ stringValue] length]; | 1023 [[field_ stringValue] length]; |
| 1029 } | 1024 } |
| 1030 | 1025 |
| 1031 bool OmniboxViewMac::IsCaretAtEnd() const { | 1026 bool OmniboxViewMac::IsCaretAtEnd() const { |
| 1032 const NSRange selection = GetSelectedRange(); | 1027 const NSRange selection = GetSelectedRange(); |
| 1033 return NSMaxRange(selection) == GetTextLength(); | 1028 return NSMaxRange(selection) == GetTextLength(); |
| 1034 } | 1029 } |
| OLD | NEW |