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

Side by Side Diff: chrome/browser/ui/cocoa/location_bar/autocomplete_text_field.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.h" 5 #import "chrome/browser/ui/cocoa/location_bar/autocomplete_text_field.h"
6 6
7 #include "base/logging.h" 7 #include "base/logging.h"
8 #import "base/mac/mac_util.h" 8 #import "base/mac/mac_util.h"
9 #import "base/mac/sdk_forward_declarations.h" 9 #import "base/mac/sdk_forward_declarations.h"
10 #include "chrome/browser/themes/theme_service.h" 10 #include "chrome/browser/themes/theme_service.h"
11 #import "chrome/browser/ui/cocoa/browser_window_controller.h" 11 #import "chrome/browser/ui/cocoa/browser_window_controller.h"
12 #import "chrome/browser/ui/cocoa/location_bar/autocomplete_text_field_cell.h" 12 #import "chrome/browser/ui/cocoa/location_bar/autocomplete_text_field_cell.h"
13 #import "chrome/browser/ui/cocoa/location_bar/autocomplete_text_field_editor.h" 13 #import "chrome/browser/ui/cocoa/location_bar/autocomplete_text_field_editor.h"
14 #import "chrome/browser/ui/cocoa/location_bar/location_bar_decoration.h" 14 #import "chrome/browser/ui/cocoa/location_bar/location_bar_decoration.h"
15 #include "chrome/browser/ui/cocoa/omnibox/omnibox_view_mac.h"
15 #import "chrome/browser/ui/cocoa/toolbar/toolbar_controller.h" 16 #import "chrome/browser/ui/cocoa/toolbar/toolbar_controller.h"
16 #import "chrome/browser/ui/cocoa/url_drop_target.h" 17 #import "chrome/browser/ui/cocoa/url_drop_target.h"
17 #import "chrome/browser/ui/cocoa/view_id_util.h" 18 #import "chrome/browser/ui/cocoa/view_id_util.h"
18 #import "ui/base/cocoa/nsview_additions.h" 19 #import "ui/base/cocoa/nsview_additions.h"
19 #include "ui/base/material_design/material_design_controller.h" 20 #include "ui/base/material_design/material_design_controller.h"
20 #include "ui/gfx/scoped_ns_graphics_context_save_gstate_mac.h" 21 #include "ui/gfx/scoped_ns_graphics_context_save_gstate_mac.h"
21 22
22 namespace { 23 namespace {
23 const CGFloat kAnimationDuration = 0.2; 24 const CGFloat kAnimationDuration = 0.2;
24 } 25 }
(...skipping 344 matching lines...) Expand 10 before | Expand all | Expand 10 after
369 } 370 }
370 371
371 - (void)windowDidChangeScreen { 372 - (void)windowDidChangeScreen {
372 // Inform the AutocompleteTextFieldCell's of the coordinate system line 373 // Inform the AutocompleteTextFieldCell's of the coordinate system line
373 // width needed to draw a single-pixel line. This value changes as we move 374 // width needed to draw a single-pixel line. This value changes as we move
374 // between Retina and non-Retina displays. 375 // between Retina and non-Retina displays.
375 [[self cell] setSinglePixelLineWidth:[self cr_lineWidth]]; 376 [[self cell] setSinglePixelLineWidth:[self cr_lineWidth]];
376 [self setNeedsDisplay]; 377 [self setNeedsDisplay];
377 } 378 }
378 379
380 - (void)updateColorsToMatchTheme {
381 if (![[self window] inIncognitoMode]) {
382 return;
383 }
384
385 // Invert the textfield's colors when Material Design and Incognito and not
386 // a custom theme.
387 bool inDarkMode = [[self window] inIncognitoModeWithSystemTheme];
388 [self setBackgroundColor:
389 inDarkMode ? [NSColor colorWithCalibratedWhite:115 / 255. alpha:1]
390 : [NSColor whiteColor]];
391 [self setTextColor:OmniboxViewMac::BaseTextColor(inDarkMode)];
392 }
393
379 - (void)viewDidMoveToWindow { 394 - (void)viewDidMoveToWindow {
380 if (![self window]) { 395 if (![self window]) {
381 return; 396 return;
382 } 397 }
383 398
384 // Allow the ToolbarController to take action upon the 399 // Allow the ToolbarController to take action upon the
385 // AutocompleteTextField being added to the window. 400 // AutocompleteTextField being added to the window.
386 if (ui::MaterialDesignController::IsModeMaterial()) { 401 if (ui::MaterialDesignController::IsModeMaterial()) {
387 BrowserWindowController* browserWindowController = 402 BrowserWindowController* browserWindowController =
388 [BrowserWindowController browserWindowControllerForView:self]; 403 [BrowserWindowController browserWindowControllerForView:self];
389 [[browserWindowController toolbarController] locationBarWasAddedToWindow]; 404 [[browserWindowController toolbarController] locationBarWasAddedToWindow];
390 }
391 405
392 // Invert the textfield's colors when Material Design and Incognito and not 406 [self updateColorsToMatchTheme];
393 // a custom theme.
394 if (ui::MaterialDesignController::IsModeMaterial() &&
395 [[self window] inIncognitoModeWithSystemTheme]) {
396 [self setTextColor:[NSColor whiteColor]];
397 [self setBackgroundColor:
398 [NSColor colorWithCalibratedWhite:115 / 255. alpha:1]];
399 } 407 }
400 408
401 NSNotificationCenter* nc = [NSNotificationCenter defaultCenter]; 409 NSNotificationCenter* nc = [NSNotificationCenter defaultCenter];
402 [nc addObserver:self 410 [nc addObserver:self
403 selector:@selector(windowDidResignKey:) 411 selector:@selector(windowDidResignKey:)
404 name:NSWindowDidResignKeyNotification 412 name:NSWindowDidResignKeyNotification
405 object:[self window]]; 413 object:[self window]];
406 [nc addObserver:self 414 [nc addObserver:self
407 selector:@selector(windowDidResize:) 415 selector:@selector(windowDidResize:)
408 name:NSWindowDidResizeNotification 416 name:NSWindowDidResizeNotification
(...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after
521 529
522 - (NSMenu*)decorationMenuForEvent:(NSEvent*)event { 530 - (NSMenu*)decorationMenuForEvent:(NSEvent*)event {
523 AutocompleteTextFieldCell* cell = [self cell]; 531 AutocompleteTextFieldCell* cell = [self cell];
524 return [cell decorationMenuForEvent:event inRect:[self bounds] ofView:self]; 532 return [cell decorationMenuForEvent:event inRect:[self bounds] ofView:self];
525 } 533 }
526 534
527 - (ViewID)viewID { 535 - (ViewID)viewID {
528 return VIEW_ID_OMNIBOX; 536 return VIEW_ID_OMNIBOX;
529 } 537 }
530 538
539 // ThemedWindowDrawing implementation.
540
541 - (void)windowDidChangeTheme {
542 if (!ui::MaterialDesignController::IsModeMaterial()) {
543 return;
544 }
545
546 [self updateColorsToMatchTheme];
547 }
548
549 - (void)windowDidChangeActive {
550 }
551
531 @end 552 @end
532 553
533 namespace autocomplete_text_field { 554 namespace autocomplete_text_field {
534 555
535 void DrawGrayTextAutocompletion(NSAttributedString* mainText, 556 void DrawGrayTextAutocompletion(NSAttributedString* mainText,
536 NSString* suggestText, 557 NSString* suggestText,
537 NSColor* suggestColor, 558 NSColor* suggestColor,
538 NSView* controlView, 559 NSView* controlView,
539 NSRect frame) { 560 NSRect frame) {
540 if (![suggestText length]) 561 if (![suggestText length])
(...skipping 20 matching lines...) Expand all
561 NSMinY(frame), 582 NSMinY(frame),
562 suggestWidth, 583 suggestWidth,
563 NSHeight(frame)); 584 NSHeight(frame));
564 585
565 gfx::ScopedNSGraphicsContextSaveGState saveGState; 586 gfx::ScopedNSGraphicsContextSaveGState saveGState;
566 NSRectClip(suggestRect); 587 NSRectClip(suggestRect);
567 [cell drawInteriorWithFrame:frame inView:controlView]; 588 [cell drawInteriorWithFrame:frame inView:controlView];
568 } 589 }
569 590
570 } // namespace autocomplete_text_field 591 } // namespace autocomplete_text_field
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698