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

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

Issue 184783007: [rAC, OSX] Fix Omnibox font issue (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: If at first you don't succeed Created 6 years, 9 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 | Annotate | Revision Log
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 383 matching lines...) Expand 10 before | Expand all | Expand 10 after
394 // text-field implementation. 394 // text-field implementation.
395 } 395 }
396 396
397 void OmniboxViewMac::SetTextAndSelectedRange(const base::string16& display_text, 397 void OmniboxViewMac::SetTextAndSelectedRange(const base::string16& display_text,
398 const NSRange range) { 398 const NSRange range) {
399 SetText(display_text); 399 SetText(display_text);
400 SetSelectedRange(range); 400 SetSelectedRange(range);
401 } 401 }
402 402
403 void OmniboxViewMac::EmphasizeURLComponents() { 403 void OmniboxViewMac::EmphasizeURLComponents() {
404 // Obtain the text before any editing - GetText will update the field's value
405 // from textStorage, and if EmphasizeURLComponents is called from within the
406 // editor's -resignFirstResponder, |field_| will have a text value that is
407 // stripped of all attributes. (Since the editor is about to die and has
408 // already synced the field to its value).
409 base::string16 text = GetText();
Scott Hess - ex-Googler 2014/03/06 02:42:24 I cannot understand how the comment applies at all
groby-ooo-7-16 2014/03/06 04:07:51 Unfortunately, it still is the firstResponder, exc
Scott Hess - ex-Googler 2014/03/06 06:30:32 Still nack. base::string16 cannot have Cocoa attr
groby-ooo-7-16 2014/03/06 19:07:58 It doesn't. It's a side effect. Sequence of events
Scott Hess - ex-Googler 2014/03/06 19:28:12 This implies that calling [field_ stringValue] aft
Scott Hess - ex-Googler 2014/03/06 20:54:28 OK, I'm reading old CLs trying to wrap my head aro
groby-ooo-7-16 2014/03/07 01:47:08 Based on my reading of old CL's, we cannot call se
410
404 NSTextView* editor = (NSTextView*)[field_ currentEditor]; 411 NSTextView* editor = (NSTextView*)[field_ currentEditor];
405 // If the autocomplete text field is in editing mode, then we can just change 412 // If the autocomplete text field is in editing mode, then we can just change
406 // its attributes through its editor. Otherwise, we simply reset its content. 413 // its attributes through its editor. Otherwise, we simply reset its content.
407 if (editor) { 414 if (editor) {
408 NSTextStorage* storage = [editor textStorage]; 415 NSTextStorage* storage = [editor textStorage];
409 [storage beginEditing]; 416 [storage beginEditing];
410 417
411 // Clear the existing attributes from the text storage, then 418 // Clear the existing attributes from the text storage, then
412 // overlay the appropriate Omnibox attributes. 419 // overlay the appropriate Omnibox attributes.
413 [storage setAttributes:[NSDictionary dictionary] 420 [storage setAttributes:[NSDictionary dictionary]
414 range:NSMakeRange(0, [storage length])]; 421 range:NSMakeRange(0, [storage length])];
415 ApplyTextAttributes(GetText(), storage); 422 ApplyTextAttributes(text, storage);
416 423
417 [storage endEditing]; 424 [storage endEditing];
418 } else { 425 } else {
419 SetText(GetText()); 426 SetText(text);
420 } 427 }
421 } 428 }
422 429
423 void OmniboxViewMac::ApplyTextAttributes(const base::string16& display_text, 430 void OmniboxViewMac::ApplyTextAttributes(const base::string16& display_text,
424 NSMutableAttributedString* as) { 431 NSMutableAttributedString* as) {
425 NSUInteger as_length = [as length]; 432 NSUInteger as_length = [as length];
426 NSRange as_entire_string = NSMakeRange(0, as_length); 433 NSRange as_entire_string = NSMakeRange(0, as_length);
427 434
428 [as addAttribute:NSFontAttributeName value:GetFieldFont() 435 [as addAttribute:NSFontAttributeName value:GetFieldFont()
429 range:as_entire_string]; 436 range:as_entire_string];
(...skipping 547 matching lines...) Expand 10 before | Expand all | Expand 10 after
977 984
978 NSUInteger OmniboxViewMac::GetTextLength() const { 985 NSUInteger OmniboxViewMac::GetTextLength() const {
979 return [field_ currentEditor] ? [[[field_ currentEditor] string] length] : 986 return [field_ currentEditor] ? [[[field_ currentEditor] string] length] :
980 [[field_ stringValue] length]; 987 [[field_ stringValue] length];
981 } 988 }
982 989
983 bool OmniboxViewMac::IsCaretAtEnd() const { 990 bool OmniboxViewMac::IsCaretAtEnd() const {
984 const NSRange selection = GetSelectedRange(); 991 const NSRange selection = GetSelectedRange();
985 return NSMaxRange(selection) == GetTextLength(); 992 return NSMaxRange(selection) == GetTextLength();
986 } 993 }
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698