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

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

Issue 2057043002: Align the Mac Omnibox items vertically again. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 6 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/memory/ptr_util.h" 10 #include "base/memory/ptr_util.h"
(...skipping 25 matching lines...) Expand all
36 #include "grit/theme_resources.h" 36 #include "grit/theme_resources.h"
37 #import "skia/ext/skia_utils_mac.h" 37 #import "skia/ext/skia_utils_mac.h"
38 #import "third_party/mozilla/NSPasteboard+Utils.h" 38 #import "third_party/mozilla/NSPasteboard+Utils.h"
39 #include "ui/base/clipboard/clipboard.h" 39 #include "ui/base/clipboard/clipboard.h"
40 #include "ui/base/clipboard/clipboard_util_mac.h" 40 #include "ui/base/clipboard/clipboard_util_mac.h"
41 #import "ui/base/cocoa/cocoa_base_utils.h" 41 #import "ui/base/cocoa/cocoa_base_utils.h"
42 #import "ui/base/l10n/l10n_util_mac.h" 42 #import "ui/base/l10n/l10n_util_mac.h"
43 #include "ui/base/material_design/material_design_controller.h" 43 #include "ui/base/material_design/material_design_controller.h"
44 #include "ui/base/resource/resource_bundle.h" 44 #include "ui/base/resource/resource_bundle.h"
45 #include "ui/gfx/color_palette.h" 45 #include "ui/gfx/color_palette.h"
46 #include "ui/gfx/font.h"
47 #include "ui/gfx/font_list.h" 46 #include "ui/gfx/font_list.h"
48 #include "ui/gfx/geometry/rect.h" 47 #include "ui/gfx/geometry/rect.h"
49 48
50 // TODO(ellyjones): Remove this when the deployment target is 10.9 or later. 49 // TODO(ellyjones): Remove this when the deployment target is 10.9 or later.
51 extern NSString* const NSAccessibilityPriorityKey; 50 extern NSString* const NSAccessibilityPriorityKey;
52 51
53 using content::WebContents; 52 using content::WebContents;
54 53
55 // Focus-handling between |field_| and model() is a bit subtle. 54 // Focus-handling between |field_| and model() is a bit subtle.
56 // Other platforms detect change of focus, which is inconvenient 55 // Other platforms detect change of focus, which is inconvenient
(...skipping 14 matching lines...) Expand all
71 // 70 //
72 // Other platforms don't appear to have the sense of "key window" that 71 // Other platforms don't appear to have the sense of "key window" that
73 // Mac does (I believe their fields lose focus when the window loses 72 // Mac does (I believe their fields lose focus when the window loses
74 // focus). Rather than modifying focus outside the control's edit 73 // focus). Rather than modifying focus outside the control's edit
75 // scope, when the window resigns key the autocomplete popup is 74 // scope, when the window resigns key the autocomplete popup is
76 // closed. model() still believes it has focus, and the popup will 75 // closed. model() still believes it has focus, and the popup will
77 // be regenerated on the user's next edit. That seems to match how 76 // be regenerated on the user's next edit. That seems to match how
78 // things work on other platforms. 77 // things work on other platforms.
79 78
80 namespace { 79 namespace {
81 const int kOmniboxLargeFontSizeDelta = 9;
82 const int kOmniboxNormalFontSizeDelta = 1;
83 const int kOmniboxSmallFontSizeDelta = 0;
84 const int kOmniboxSmallMaterialFontSizeDelta = -1;
85 80
86 // TODO(shess): This is ugly, find a better way. Using it right now 81 // TODO(shess): This is ugly, find a better way. Using it right now
87 // so that I can crib from gtk and still be able to see that I'm using 82 // so that I can crib from gtk and still be able to see that I'm using
88 // the same values easily. 83 // the same values easily.
89 NSColor* ColorWithRGBBytes(int rr, int gg, int bb) { 84 NSColor* ColorWithRGBBytes(int rr, int gg, int bb) {
90 DCHECK_LE(rr, 255); 85 DCHECK_LE(rr, 255);
91 DCHECK_LE(bb, 255); 86 DCHECK_LE(bb, 255);
92 DCHECK_LE(gg, 255); 87 DCHECK_LE(gg, 255);
93 return [NSColor colorWithCalibratedRed:static_cast<float>(rr)/255.0 88 return [NSColor colorWithCalibratedRed:static_cast<float>(rr)/255.0
94 green:static_cast<float>(gg)/255.0 89 green:static_cast<float>(gg)/255.0
(...skipping 447 matching lines...) Expand 10 before | Expand all | Expand 10 after
542 // more. Calling -stringValue ensures that |field_| reflects the changes to 537 // more. Calling -stringValue ensures that |field_| reflects the changes to
543 // |storage|. 538 // |storage|.
544 [field_ stringValue]; 539 [field_ stringValue];
545 } else { 540 } else {
546 SetText(GetText()); 541 SetText(GetText());
547 } 542 }
548 } 543 }
549 544
550 void OmniboxViewMac::ApplyTextStyle( 545 void OmniboxViewMac::ApplyTextStyle(
551 NSMutableAttributedString* attributedString) { 546 NSMutableAttributedString* attributedString) {
552 [attributedString addAttribute:NSFontAttributeName 547 [attributedString
553 value:GetNormalFieldFont() 548 addAttribute:NSFontAttributeName
554 range:NSMakeRange(0, [attributedString length])]; 549 value:GetFieldFont(gfx::Font::NORMAL, gfx::Font::Weight::NORMAL)
550 range:NSMakeRange(0, [attributedString length])];
555 551
556 // Make a paragraph style locking in the standard line height as the maximum, 552 // Make a paragraph style locking in the standard line height as the maximum,
557 // otherwise the baseline may shift "downwards". 553 // otherwise the baseline may shift "downwards".
558 base::scoped_nsobject<NSMutableParagraphStyle> paragraph_style( 554 base::scoped_nsobject<NSMutableParagraphStyle> paragraph_style(
559 [[NSMutableParagraphStyle alloc] init]); 555 [[NSMutableParagraphStyle alloc] init]);
560 CGFloat line_height = [[field_ cell] lineHeight]; 556 CGFloat line_height = [[field_ cell] lineHeight];
561 [paragraph_style setMaximumLineHeight:line_height]; 557 [paragraph_style setMaximumLineHeight:line_height];
562 [paragraph_style setMinimumLineHeight:line_height]; 558 [paragraph_style setMinimumLineHeight:line_height];
563 [paragraph_style setLineBreakMode:NSLineBreakByTruncatingTail]; 559 [paragraph_style setLineBreakMode:NSLineBreakByTruncatingTail];
564 [attributedString addAttribute:NSParagraphStyleAttributeName 560 [attributedString addAttribute:NSParagraphStyleAttributeName
(...skipping 512 matching lines...) Expand 10 before | Expand all | Expand 10 after
1077 // 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
1078 // that it's already focused. makeFirstResponder: will select all, so only 1074 // that it's already focused. makeFirstResponder: will select all, so only
1079 // call it if this behavior is desired. 1075 // call it if this behavior is desired.
1080 if (select_all || ![field_ currentEditor]) 1076 if (select_all || ![field_ currentEditor])
1081 [[field_ window] makeFirstResponder:field_]; 1077 [[field_ window] makeFirstResponder:field_];
1082 DCHECK_EQ([field_ currentEditor], [[field_ window] firstResponder]); 1078 DCHECK_EQ([field_ currentEditor], [[field_ window] firstResponder]);
1083 } 1079 }
1084 } 1080 }
1085 1081
1086 // static 1082 // static
1087 NSFont* OmniboxViewMac::GetNormalFieldFont() { 1083 NSFont* OmniboxViewMac::GetFieldFont(int style, gfx::Font::Weight weight) {
1084 // This value should be kept in sync with InstantPage::InitializeFonts.
1088 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance(); 1085 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance();
1089 return rb 1086 return rb.GetFontList(ui::ResourceBundle::BaseFont)
1090 .GetFontWithDelta(kOmniboxNormalFontSizeDelta, gfx::Font::NORMAL, 1087 .Derive(1, style, weight)
1091 gfx::Font::Weight::NORMAL) 1088 .GetPrimaryFont()
1092 .GetNativeFont(); 1089 .GetNativeFont();
1093 } 1090 }
1094 1091
1095 NSFont* OmniboxViewMac::GetBoldFieldFont() { 1092 NSFont* OmniboxViewMac::GetLargeFont(int style, gfx::Font::Weight weight) {
1096 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance(); 1093 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance();
1097 return rb 1094 return rb.GetFontList(ui::ResourceBundle::LargeFont)
tapted 2016/06/14 05:51:34 So the minimal fix seems to be to do // Request
1098 .GetFontWithDelta(kOmniboxNormalFontSizeDelta, gfx::Font::NORMAL, 1095 .Derive(1, style, weight)
1099 gfx::Font::Weight::BOLD) 1096 .GetPrimaryFont()
1100 .GetNativeFont(); 1097 .GetNativeFont();
1101 } 1098 }
1102 1099
1103 NSFont* OmniboxViewMac::GetLargeFont() { 1100 NSFont* OmniboxViewMac::GetSmallFont(int style, gfx::Font::Weight weight) {
1104 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance(); 1101 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance();
1105 return rb 1102 if (!ui::MaterialDesignController::IsModeMaterial()) {
1106 .GetFontWithDelta(kOmniboxLargeFontSizeDelta, gfx::Font::NORMAL, 1103 return rb.GetFontList(ui::ResourceBundle::SmallFont)
1107 gfx::Font::Weight::NORMAL) 1104 .Derive(1, style, weight)
1105 .GetPrimaryFont()
1106 .GetNativeFont();
1107 }
1108 return rb.GetFontListWithDelta(-2, gfx::Font::NORMAL)
1109 .Derive(1, style, weight)
1110 .GetPrimaryFont()
1108 .GetNativeFont(); 1111 .GetNativeFont();
1109 } 1112 }
1110 1113
1111 NSFont* OmniboxViewMac::GetSmallFont() {
1112 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance();
1113 if (!ui::MaterialDesignController::IsModeMaterial()) {
1114 return rb
1115 .GetFontWithDelta(kOmniboxSmallFontSizeDelta, gfx::Font::NORMAL,
1116 gfx::Font::Weight::NORMAL)
1117 .GetNativeFont();
1118 }
1119
1120 return rb
1121 .GetFontWithDelta(kOmniboxSmallMaterialFontSizeDelta, gfx::Font::NORMAL,
1122 gfx::Font::Weight::NORMAL)
1123 .GetNativeFont();
1124 }
1125
1126 int OmniboxViewMac::GetOmniboxTextLength() const { 1114 int OmniboxViewMac::GetOmniboxTextLength() const {
1127 return static_cast<int>(GetTextLength()); 1115 return static_cast<int>(GetTextLength());
1128 } 1116 }
1129 1117
1130 NSUInteger OmniboxViewMac::GetTextLength() const { 1118 NSUInteger OmniboxViewMac::GetTextLength() const {
1131 return [field_ currentEditor] ? [[[field_ currentEditor] string] length] : 1119 return [field_ currentEditor] ? [[[field_ currentEditor] string] length] :
1132 [[field_ stringValue] length]; 1120 [[field_ stringValue] length];
1133 } 1121 }
1134 1122
1135 bool OmniboxViewMac::IsCaretAtEnd() const { 1123 bool OmniboxViewMac::IsCaretAtEnd() const {
1136 const NSRange selection = GetSelectedRange(); 1124 const NSRange selection = GetSelectedRange();
1137 return NSMaxRange(selection) == GetTextLength(); 1125 return NSMaxRange(selection) == GetTextLength();
1138 } 1126 }
1139 1127
1140 void OmniboxViewMac::AnnounceAutocompleteForScreenReader( 1128 void OmniboxViewMac::AnnounceAutocompleteForScreenReader(
1141 const base::string16& display_text) { 1129 const base::string16& display_text) {
1142 NSString* announcement = 1130 NSString* announcement =
1143 l10n_util::GetNSStringF(IDS_ANNOUNCEMENT_COMPLETION_AVAILABLE_MAC, 1131 l10n_util::GetNSStringF(IDS_ANNOUNCEMENT_COMPLETION_AVAILABLE_MAC,
1144 display_text); 1132 display_text);
1145 NSDictionary* notification_info = @{ 1133 NSDictionary* notification_info = @{
1146 NSAccessibilityAnnouncementKey : announcement, 1134 NSAccessibilityAnnouncementKey : announcement,
1147 NSAccessibilityPriorityKey : @(NSAccessibilityPriorityHigh) 1135 NSAccessibilityPriorityKey : @(NSAccessibilityPriorityHigh)
1148 }; 1136 };
1149 NSAccessibilityPostNotificationWithUserInfo( 1137 NSAccessibilityPostNotificationWithUserInfo(
1150 [field_ window], 1138 [field_ window],
1151 NSAccessibilityAnnouncementRequestedNotification, 1139 NSAccessibilityAnnouncementRequestedNotification,
1152 notification_info); 1140 notification_info);
1153 } 1141 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698