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

Side by Side Diff: chrome/browser/ui/cocoa/location_bar/autocomplete_text_field_editor.mm

Issue 1866523002: [Mac] Update location bar colors when change themes in Material Design. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Clean up for review. 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) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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 #import "chrome/browser/ui/cocoa/location_bar/autocomplete_text_field_editor.h" 5 #import "chrome/browser/ui/cocoa/location_bar/autocomplete_text_field_editor.h"
6 6
7 #include "base/strings/string_util.h" 7 #include "base/strings/string_util.h"
8 #include "base/strings/sys_string_conversions.h" 8 #include "base/strings/sys_string_conversions.h"
9 #include "chrome/app/chrome_command_ids.h" // IDC_* 9 #include "chrome/app/chrome_command_ids.h" // IDC_*
10 #include "chrome/browser/themes/theme_service.h" 10 #include "chrome/browser/themes/theme_service.h"
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
62 // selectively enable them via context menu, but that submenu is not enabled 62 // selectively enable them via context menu, but that submenu is not enabled
63 // for the omnibox. The substitutions are unlikely to be useful in any case. 63 // for the omnibox. The substitutions are unlikely to be useful in any case.
64 // 64 //
65 // Also see http://crbug.com/173405 and http://crbug.com/528014. 65 // Also see http://crbug.com/173405 and http://crbug.com/528014.
66 NSTextCheckingTypes checkingTypes = 0; 66 NSTextCheckingTypes checkingTypes = 0;
67 [self setEnabledTextCheckingTypes:checkingTypes]; 67 [self setEnabledTextCheckingTypes:checkingTypes];
68 } 68 }
69 return self; 69 return self;
70 } 70 }
71 71
72 - (void)updateColorsToMatchTheme {
73 if (![[self window] inIncognitoMode]) {
74 return;
75 }
76
77 bool inDarkMode = [[self window] inIncognitoModeWithSystemTheme];
78 // Draw a light insertion point for MD Incognito.
79 NSColor* insertionPointColor =
80 inDarkMode ? [NSColor colorWithCalibratedWhite:1 alpha:0.75]
81 : [NSColor blackColor];
82 [self setInsertionPointColor:insertionPointColor];
83
84 NSColor* textSelectionColor = [NSColor selectedTextBackgroundColor];
85 if (inDarkMode) {
86 // In MD Incognito the text is light gray against a dark background. When
87 // selected, the light gray text against the selection color is illegible.
88 // Rather than tweak or change the selection color, make the text black when
89 // selected.
90 [self setSelectedTextAttributes:@{
91 NSForegroundColorAttributeName : [NSColor blackColor],
92 NSBackgroundColorAttributeName : textSelectionColor
93 }];
94 } else {
95 [self setSelectedTextAttributes:@{
96 NSBackgroundColorAttributeName : textSelectionColor
97 }];
98 }
99 }
100
72 - (void)viewDidMoveToWindow { 101 - (void)viewDidMoveToWindow {
73 // Only care about landing in a window when in Material Design mode. 102 // Only care about landing in a window when in Material Design mode.
74 if (![self window] || !ui::MaterialDesignController::IsModeMaterial()) { 103 if ([self window] && ui::MaterialDesignController::IsModeMaterial()) {
75 return; 104 [self updateColorsToMatchTheme];
76 } 105 }
77
78 // Only care about Incognito mode with a non-custom theme.
79 if (![[self window] inIncognitoModeWithSystemTheme]) {
80 return;
81 }
82
83 // Draw a light insertion point for MD Incognito.
84 [self setInsertionPointColor:
85 [NSColor colorWithCalibratedWhite:1 alpha:0.75]];
86 // In MD Incognito the text is light gray against a dark background. When
87 // selected, the light gray text against the selection color is illegible.
88 // Rather than tweak or change the selection color, make the text black when
89 // selected.
90 NSColor* textSelectionColor = [NSColor selectedTextBackgroundColor];
91 [self setSelectedTextAttributes:@{
92 NSForegroundColorAttributeName : [NSColor blackColor],
93 NSBackgroundColorAttributeName : textSelectionColor
94 }];
95 } 106 }
96 107
97 // If the entire field is selected, drag the same data as would be 108 // If the entire field is selected, drag the same data as would be
98 // dragged from the field's location icon. In some cases the textual 109 // dragged from the field's location icon. In some cases the textual
99 // contents will not contain relevant data (for instance, "http://" is 110 // contents will not contain relevant data (for instance, "http://" is
100 // stripped from URLs). 111 // stripped from URLs).
101 - (BOOL)dragSelectionWithEvent:(NSEvent *)event 112 - (BOOL)dragSelectionWithEvent:(NSEvent *)event
102 offset:(NSSize)mouseOffset 113 offset:(NSSize)mouseOffset
103 slideBack:(BOOL)slideBack { 114 slideBack:(BOOL)slideBack {
104 AutocompleteTextFieldObserver* observer = [self observer]; 115 AutocompleteTextFieldObserver* observer = [self observer];
(...skipping 458 matching lines...) Expand 10 before | Expand all | Expand 10 after
563 [self textStorage], 574 [self textStorage],
564 [[self delegate] suggestText], 575 [[self delegate] suggestText],
565 [[self delegate] suggestColor], 576 [[self delegate] suggestColor],
566 self, 577 self,
567 [self bounds]); 578 [self bounds]);
568 AutocompleteTextFieldObserver* observer = [self observer]; 579 AutocompleteTextFieldObserver* observer = [self observer];
569 if (observer) 580 if (observer)
570 observer->OnDidDrawRect(); 581 observer->OnDidDrawRect();
571 } 582 }
572 583
584 // ThemedWindowDrawing implementation.
585
586 - (void)windowDidChangeTheme {
587 if (!ui::MaterialDesignController::IsModeMaterial()) {
588 return;
589 }
590 [self updateColorsToMatchTheme];
591 }
592
593 - (void)windowDidChangeActive {
594 }
595
573 @end 596 @end
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698