Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(235)

Side by Side Diff: chrome/browser/ui/cocoa/omnibox/omnibox_view_mac.mm

Issue 1819753003: Allow various font weights in gfx. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Use the std::tie in resource_bundle Created 4 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
64 // 64 //
65 // Other platforms don't appear to have the sense of "key window" that 65 // Other platforms don't appear to have the sense of "key window" that
66 // Mac does (I believe their fields lose focus when the window loses 66 // Mac does (I believe their fields lose focus when the window loses
67 // focus). Rather than modifying focus outside the control's edit 67 // focus). Rather than modifying focus outside the control's edit
68 // scope, when the window resigns key the autocomplete popup is 68 // scope, when the window resigns key the autocomplete popup is
69 // closed. model() still believes it has focus, and the popup will 69 // closed. model() still believes it has focus, and the popup will
70 // be regenerated on the user's next edit. That seems to match how 70 // be regenerated on the user's next edit. That seems to match how
71 // things work on other platforms. 71 // things work on other platforms.
72 72
73 namespace { 73 namespace {
74 const int kOmniboxLargeFontSizeDelta = 9;
75 const int kOmniboxNormalFontSizeDelta = 1;
76 const int kOmniboxSmallFontSizeDelta = 0;
74 77
75 // TODO(shess): This is ugly, find a better way. Using it right now 78 // TODO(shess): This is ugly, find a better way. Using it right now
76 // so that I can crib from gtk and still be able to see that I'm using 79 // so that I can crib from gtk and still be able to see that I'm using
77 // the same values easily. 80 // the same values easily.
78 NSColor* ColorWithRGBBytes(int rr, int gg, int bb) { 81 NSColor* ColorWithRGBBytes(int rr, int gg, int bb) {
79 DCHECK_LE(rr, 255); 82 DCHECK_LE(rr, 255);
80 DCHECK_LE(bb, 255); 83 DCHECK_LE(bb, 255);
81 DCHECK_LE(gg, 255); 84 DCHECK_LE(gg, 255);
82 return [NSColor colorWithCalibratedRed:static_cast<float>(rr)/255.0 85 return [NSColor colorWithCalibratedRed:static_cast<float>(rr)/255.0
83 green:static_cast<float>(gg)/255.0 86 green:static_cast<float>(gg)/255.0
(...skipping 427 matching lines...) Expand 10 before | Expand all | Expand 10 after
511 // |storage|. 514 // |storage|.
512 [field_ stringValue]; 515 [field_ stringValue];
513 } else { 516 } else {
514 SetText(GetText()); 517 SetText(GetText());
515 } 518 }
516 } 519 }
517 520
518 void OmniboxViewMac::ApplyTextStyle( 521 void OmniboxViewMac::ApplyTextStyle(
519 NSMutableAttributedString* attributedString) { 522 NSMutableAttributedString* attributedString) {
520 [attributedString addAttribute:NSFontAttributeName 523 [attributedString addAttribute:NSFontAttributeName
521 value:GetFieldFont(gfx::Font::NORMAL) 524 value:GetNormalFieldFont()
522 range:NSMakeRange(0, [attributedString length])]; 525 range:NSMakeRange(0, [attributedString length])];
523 526
524 // Make a paragraph style locking in the standard line height as the maximum, 527 // Make a paragraph style locking in the standard line height as the maximum,
525 // otherwise the baseline may shift "downwards". 528 // otherwise the baseline may shift "downwards".
526 base::scoped_nsobject<NSMutableParagraphStyle> paragraph_style( 529 base::scoped_nsobject<NSMutableParagraphStyle> paragraph_style(
527 [[NSMutableParagraphStyle alloc] init]); 530 [[NSMutableParagraphStyle alloc] init]);
528 CGFloat line_height = [[field_ cell] lineHeight]; 531 CGFloat line_height = [[field_ cell] lineHeight];
529 [paragraph_style setMaximumLineHeight:line_height]; 532 [paragraph_style setMaximumLineHeight:line_height];
530 [paragraph_style setMinimumLineHeight:line_height]; 533 [paragraph_style setMinimumLineHeight:line_height];
531 [paragraph_style setLineBreakMode:NSLineBreakByTruncatingTail]; 534 [paragraph_style setLineBreakMode:NSLineBreakByTruncatingTail];
(...skipping 538 matching lines...) Expand 10 before | Expand all | Expand 10 after
1070 // If the text field has a field editor, it's the first responder, meaning 1073 // If the text field has a field editor, it's the first responder, meaning
1071 // that it's already focused. makeFirstResponder: will select all, so only 1074 // that it's already focused. makeFirstResponder: will select all, so only
1072 // call it if this behavior is desired. 1075 // call it if this behavior is desired.
1073 if (select_all || ![field_ currentEditor]) 1076 if (select_all || ![field_ currentEditor])
1074 [[field_ window] makeFirstResponder:field_]; 1077 [[field_ window] makeFirstResponder:field_];
1075 DCHECK_EQ([field_ currentEditor], [[field_ window] firstResponder]); 1078 DCHECK_EQ([field_ currentEditor], [[field_ window] firstResponder]);
1076 } 1079 }
1077 } 1080 }
1078 1081
1079 // static 1082 // static
1080 NSFont* OmniboxViewMac::GetFieldFont(int style) { 1083 NSFont* OmniboxViewMac::GetNormalFieldFont() {
1081 // This value should be kept in sync with InstantPage::InitializeFonts.
1082 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance(); 1084 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance();
1083 return rb.GetFontList(ui::ResourceBundle::BaseFont).Derive(1, style) 1085 return rb
1084 .GetPrimaryFont().GetNativeFont(); 1086 .GetFontWithDelta(kOmniboxNormalFontSizeDelta, gfx::Font::NORMAL,
1085 } 1087 gfx::Font::Weight::NORMAL)
1086
1087 NSFont* OmniboxViewMac::GetLargeFont(int style) {
1088 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance();
1089 return rb.GetFontList(ui::ResourceBundle::LargeFont)
1090 .Derive(1, style)
1091 .GetPrimaryFont()
1092 .GetNativeFont(); 1088 .GetNativeFont();
1093 } 1089 }
1094 1090
1095 NSFont* OmniboxViewMac::GetSmallFont(int style) { 1091 NSFont* OmniboxViewMac::GetBoldFieldFont() {
1096 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance(); 1092 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance();
1097 return rb.GetFontList(ui::ResourceBundle::SmallFont) 1093 return rb
1098 .Derive(1, style) 1094 .GetFontWithDelta(kOmniboxNormalFontSizeDelta, gfx::Font::NORMAL,
1099 .GetPrimaryFont() 1095 gfx::Font::Weight::BOLD)
1100 .GetNativeFont(); 1096 .GetNativeFont();
1101 } 1097 }
1102 1098
1099 NSFont* OmniboxViewMac::GetLargeFont() {
1100 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance();
1101 return rb
1102 .GetFontWithDelta(kOmniboxLargeFontSizeDelta, gfx::Font::NORMAL,
1103 gfx::Font::Weight::NORMAL)
1104 .GetNativeFont();
1105 }
1106
1107 NSFont* OmniboxViewMac::GetSmallFont() {
1108 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance();
1109 return rb
1110 .GetFontWithDelta(kOmniboxSmallFontSizeDelta, gfx::Font::NORMAL,
1111 gfx::Font::Weight::NORMAL)
1112 .GetNativeFont();
1113 }
1114
1103 int OmniboxViewMac::GetOmniboxTextLength() const { 1115 int OmniboxViewMac::GetOmniboxTextLength() const {
1104 return static_cast<int>(GetTextLength()); 1116 return static_cast<int>(GetTextLength());
1105 } 1117 }
1106 1118
1107 NSUInteger OmniboxViewMac::GetTextLength() const { 1119 NSUInteger OmniboxViewMac::GetTextLength() const {
1108 return [field_ currentEditor] ? [[[field_ currentEditor] string] length] : 1120 return [field_ currentEditor] ? [[[field_ currentEditor] string] length] :
1109 [[field_ stringValue] length]; 1121 [[field_ stringValue] length];
1110 } 1122 }
1111 1123
1112 bool OmniboxViewMac::IsCaretAtEnd() const { 1124 bool OmniboxViewMac::IsCaretAtEnd() const {
1113 const NSRange selection = GetSelectedRange(); 1125 const NSRange selection = GetSelectedRange();
1114 return NSMaxRange(selection) == GetTextLength(); 1126 return NSMaxRange(selection) == GetTextLength();
1115 } 1127 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698