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 1054 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::GetFieldFont(int style) { |
tapted
2016/03/27 23:10:02
Callers only ever pass in BOLD or NORMAL to this m
Mikus
2016/03/29 10:55:38
Done.
| |
1076 // This value should be kept in sync with InstantPage::InitializeFonts. | 1076 // This value should be kept in sync with InstantPage::InitializeFonts. |
1077 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance(); | 1077 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance(); |
1078 return rb.GetFontList(ui::ResourceBundle::BaseFont).Derive(1, style) | 1078 return rb.GetFontList(ui::ResourceBundle::BaseFont) |
1079 .GetPrimaryFont().GetNativeFont(); | 1079 .Derive(1, style, gfx::Font::Weight::NORMAL) |
1080 .GetPrimaryFont() | |
1081 .GetNativeFont(); | |
Peter Kasting
2016/03/26 00:56:51
Nit: Maybe:
namespace {
NSFont* GetFontForSizeAn
Mikus
2016/03/29 10:55:38
Not really needed anymore.
| |
1080 } | 1082 } |
1081 | 1083 |
1082 NSFont* OmniboxViewMac::GetLargeFont(int style) { | 1084 NSFont* OmniboxViewMac::GetLargeFont(int style) { |
1083 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance(); | 1085 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance(); |
1084 return rb.GetFontList(ui::ResourceBundle::LargeFont) | 1086 return rb.GetFontList(ui::ResourceBundle::LargeFont) |
1085 .Derive(1, style) | 1087 .Derive(1, style, gfx::Font::Weight::NORMAL) |
1086 .GetPrimaryFont() | 1088 .GetPrimaryFont() |
1087 .GetNativeFont(); | 1089 .GetNativeFont(); |
1088 } | 1090 } |
1089 | 1091 |
1090 NSFont* OmniboxViewMac::GetSmallFont(int style) { | 1092 NSFont* OmniboxViewMac::GetSmallFont(int style) { |
1091 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance(); | 1093 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance(); |
1092 return rb.GetFontList(ui::ResourceBundle::SmallFont) | 1094 return rb.GetFontList(ui::ResourceBundle::SmallFont) |
1093 .Derive(1, style) | 1095 .Derive(1, style, gfx::Font::Weight::NORMAL) |
1094 .GetPrimaryFont() | 1096 .GetPrimaryFont() |
1095 .GetNativeFont(); | 1097 .GetNativeFont(); |
1096 } | 1098 } |
1097 | 1099 |
1098 int OmniboxViewMac::GetOmniboxTextLength() const { | 1100 int OmniboxViewMac::GetOmniboxTextLength() const { |
1099 return static_cast<int>(GetTextLength()); | 1101 return static_cast<int>(GetTextLength()); |
1100 } | 1102 } |
1101 | 1103 |
1102 NSUInteger OmniboxViewMac::GetTextLength() const { | 1104 NSUInteger OmniboxViewMac::GetTextLength() const { |
1103 return [field_ currentEditor] ? [[[field_ currentEditor] string] length] : | 1105 return [field_ currentEditor] ? [[[field_ currentEditor] string] length] : |
1104 [[field_ stringValue] length]; | 1106 [[field_ stringValue] length]; |
1105 } | 1107 } |
1106 | 1108 |
1107 bool OmniboxViewMac::IsCaretAtEnd() const { | 1109 bool OmniboxViewMac::IsCaretAtEnd() const { |
1108 const NSRange selection = GetSelectedRange(); | 1110 const NSRange selection = GetSelectedRange(); |
1109 return NSMaxRange(selection) == GetTextLength(); | 1111 return NSMaxRange(selection) == GetTextLength(); |
1110 } | 1112 } |
OLD | NEW |