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 499 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 510 // |storage|. | 510 // |storage|. |
| 511 [field_ stringValue]; | 511 [field_ stringValue]; |
| 512 } else { | 512 } else { |
| 513 SetText(GetText()); | 513 SetText(GetText()); |
| 514 } | 514 } |
| 515 } | 515 } |
| 516 | 516 |
| 517 void OmniboxViewMac::ApplyTextStyle( | 517 void OmniboxViewMac::ApplyTextStyle( |
| 518 NSMutableAttributedString* attributedString) { | 518 NSMutableAttributedString* attributedString) { |
| 519 [attributedString addAttribute:NSFontAttributeName | 519 [attributedString addAttribute:NSFontAttributeName |
| 520 value:GetFieldFont(gfx::Font::NORMAL) | 520 value:GetNormalFieldFont() |
| 521 range:NSMakeRange(0, [attributedString length])]; | 521 range:NSMakeRange(0, [attributedString length])]; |
| 522 | 522 |
| 523 // Make a paragraph style locking in the standard line height as the maximum, | 523 // Make a paragraph style locking in the standard line height as the maximum, |
| 524 // otherwise the baseline may shift "downwards". | 524 // otherwise the baseline may shift "downwards". |
| 525 base::scoped_nsobject<NSMutableParagraphStyle> paragraph_style( | 525 base::scoped_nsobject<NSMutableParagraphStyle> paragraph_style( |
| 526 [[NSMutableParagraphStyle alloc] init]); | 526 [[NSMutableParagraphStyle alloc] init]); |
| 527 CGFloat line_height = [[field_ cell] lineHeight]; | 527 CGFloat line_height = [[field_ cell] lineHeight]; |
| 528 [paragraph_style setMaximumLineHeight:line_height]; | 528 [paragraph_style setMaximumLineHeight:line_height]; |
| 529 [paragraph_style setMinimumLineHeight:line_height]; | 529 [paragraph_style setMinimumLineHeight:line_height]; |
| 530 [paragraph_style setLineBreakMode:NSLineBreakByTruncatingTail]; | 530 [paragraph_style setLineBreakMode:NSLineBreakByTruncatingTail]; |
| (...skipping 534 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1065 // If the text field has a field editor, it's the first responder, meaning | 1065 // If the text field has a field editor, it's the first responder, meaning |
| 1066 // that it's already focused. makeFirstResponder: will select all, so only | 1066 // that it's already focused. makeFirstResponder: will select all, so only |
| 1067 // call it if this behavior is desired. | 1067 // call it if this behavior is desired. |
| 1068 if (select_all || ![field_ currentEditor]) | 1068 if (select_all || ![field_ currentEditor]) |
| 1069 [[field_ window] makeFirstResponder:field_]; | 1069 [[field_ window] makeFirstResponder:field_]; |
| 1070 DCHECK_EQ([field_ currentEditor], [[field_ window] firstResponder]); | 1070 DCHECK_EQ([field_ currentEditor], [[field_ window] firstResponder]); |
| 1071 } | 1071 } |
| 1072 } | 1072 } |
| 1073 | 1073 |
| 1074 // static | 1074 // static |
| 1075 NSFont* OmniboxViewMac::GetFieldFont(int style) { | 1075 NSFont* OmniboxViewMac::GetNormalFieldFont() { |
| 1076 // This value should be kept in sync with InstantPage::InitializeFonts. | 1076 // This value should be kept in sync with InstantPage::InitializeFonts. |
|
tapted
2016/03/29 20:13:46
InstantPage::InitializeFonts doesn't seem to exist
Mikus
2016/03/30 13:58:24
Done.
| |
| 1077 const int kOmniboxNormalFontSizeDelta = 1; | |
|
msw
2016/03/29 19:18:14
nit: these probably belong in a file-local anon na
Mikus
2016/03/30 13:58:24
Done.
| |
| 1077 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance(); | 1078 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance(); |
| 1078 return rb.GetFontList(ui::ResourceBundle::BaseFont).Derive(1, style) | 1079 return rb |
| 1079 .GetPrimaryFont().GetNativeFont(); | 1080 .GetFontWithDelta(kOmniboxNormalFontSizeDelta, gfx::Font::NORMAL, |
| 1080 } | 1081 gfx::Font::Weight::NORMAL) |
| 1081 | |
| 1082 NSFont* OmniboxViewMac::GetLargeFont(int style) { | |
| 1083 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance(); | |
| 1084 return rb.GetFontList(ui::ResourceBundle::LargeFont) | |
| 1085 .Derive(1, style) | |
| 1086 .GetPrimaryFont() | |
| 1087 .GetNativeFont(); | 1082 .GetNativeFont(); |
| 1088 } | 1083 } |
| 1089 | 1084 |
| 1090 NSFont* OmniboxViewMac::GetSmallFont(int style) { | 1085 NSFont* OmniboxViewMac::GetBoldFieldFont() { |
| 1086 // This value should be kept in sync with InstantPage::InitializeFonts. | |
| 1087 const int kOmniboxNormalFontSizeDelta = 1; | |
| 1091 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance(); | 1088 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance(); |
| 1092 return rb.GetFontList(ui::ResourceBundle::SmallFont) | 1089 return rb |
| 1093 .Derive(1, style) | 1090 .GetFontWithDelta(kOmniboxNormalFontSizeDelta, gfx::Font::NORMAL, |
| 1094 .GetPrimaryFont() | 1091 gfx::Font::Weight::BOLD) |
| 1095 .GetNativeFont(); | 1092 .GetNativeFont(); |
| 1096 } | 1093 } |
| 1097 | 1094 |
| 1095 NSFont* OmniboxViewMac::GetLargeFont() { | |
| 1096 const int kOmniboxLargeFontSizeDelta = 9; | |
| 1097 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance(); | |
| 1098 return rb | |
| 1099 .GetFontWithDelta(kOmniboxLargeFontSizeDelta, gfx::Font::NORMAL, | |
| 1100 gfx::Font::Weight::NORMAL) | |
| 1101 .GetNativeFont(); | |
| 1102 } | |
| 1103 | |
| 1104 NSFont* OmniboxViewMac::GetSmallFont() { | |
| 1105 const int kOmniboxSmallFontSizeDelta = 0; | |
|
msw
2016/03/29 19:18:14
ha! the old code was getting the small font (-1 de
tapted
2016/03/29 20:13:46
Yeah although it's common for code to use rb.GetFo
Mikus
2016/03/30 13:58:24
Acknowledged.
| |
| 1106 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance(); | |
| 1107 return rb | |
| 1108 .GetFontWithDelta(kOmniboxSmallFontSizeDelta, gfx::Font::NORMAL, | |
| 1109 gfx::Font::Weight::NORMAL) | |
| 1110 .GetNativeFont(); | |
| 1111 } | |
| 1112 | |
| 1098 int OmniboxViewMac::GetOmniboxTextLength() const { | 1113 int OmniboxViewMac::GetOmniboxTextLength() const { |
| 1099 return static_cast<int>(GetTextLength()); | 1114 return static_cast<int>(GetTextLength()); |
| 1100 } | 1115 } |
| 1101 | 1116 |
| 1102 NSUInteger OmniboxViewMac::GetTextLength() const { | 1117 NSUInteger OmniboxViewMac::GetTextLength() const { |
| 1103 return [field_ currentEditor] ? [[[field_ currentEditor] string] length] : | 1118 return [field_ currentEditor] ? [[[field_ currentEditor] string] length] : |
| 1104 [[field_ stringValue] length]; | 1119 [[field_ stringValue] length]; |
| 1105 } | 1120 } |
| 1106 | 1121 |
| 1107 bool OmniboxViewMac::IsCaretAtEnd() const { | 1122 bool OmniboxViewMac::IsCaretAtEnd() const { |
| 1108 const NSRange selection = GetSelectedRange(); | 1123 const NSRange selection = GetSelectedRange(); |
| 1109 return NSMaxRange(selection) == GetTextLength(); | 1124 return NSMaxRange(selection) == GetTextLength(); |
| 1110 } | 1125 } |
| OLD | NEW |