Chromium Code Reviews| OLD | NEW |
|---|---|
| 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 #import "chrome/browser/ui/cocoa/browser_window_controller.h" | 11 #import "chrome/browser/ui/cocoa/browser_window_controller.h" |
| 11 #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" |
| 12 #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" |
| 13 #import "chrome/browser/ui/cocoa/location_bar/location_bar_decoration.h" | 14 #import "chrome/browser/ui/cocoa/location_bar/location_bar_decoration.h" |
| 14 #import "chrome/browser/ui/cocoa/toolbar/toolbar_controller.h" | 15 #import "chrome/browser/ui/cocoa/toolbar/toolbar_controller.h" |
| 15 #import "chrome/browser/ui/cocoa/url_drop_target.h" | 16 #import "chrome/browser/ui/cocoa/url_drop_target.h" |
| 16 #import "chrome/browser/ui/cocoa/view_id_util.h" | 17 #import "chrome/browser/ui/cocoa/view_id_util.h" |
| 18 #include "ui/base/material_design/material_design_controller.h" | |
| 17 #include "ui/gfx/scoped_ns_graphics_context_save_gstate_mac.h" | 19 #include "ui/gfx/scoped_ns_graphics_context_save_gstate_mac.h" |
| 18 | 20 |
| 19 namespace { | 21 namespace { |
| 20 const CGFloat kAnimationDuration = 0.2; | 22 const CGFloat kAnimationDuration = 0.2; |
| 21 } | 23 } |
| 22 | 24 |
| 23 @implementation AutocompleteTextField | 25 @implementation AutocompleteTextField |
| 24 | 26 |
| 25 @synthesize observer = observer_; | 27 @synthesize observer = observer_; |
| 26 | 28 |
| (...skipping 329 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 356 [nc removeObserver:self | 358 [nc removeObserver:self |
| 357 name:NSWindowDidResignKeyNotification | 359 name:NSWindowDidResignKeyNotification |
| 358 object:[self window]]; | 360 object:[self window]]; |
| 359 [nc removeObserver:self | 361 [nc removeObserver:self |
| 360 name:NSWindowDidResizeNotification | 362 name:NSWindowDidResizeNotification |
| 361 object:[self window]]; | 363 object:[self window]]; |
| 362 } | 364 } |
| 363 } | 365 } |
| 364 | 366 |
| 365 - (void)viewDidMoveToWindow { | 367 - (void)viewDidMoveToWindow { |
| 366 if ([self window]) { | 368 if (![self window]) { |
| 367 NSNotificationCenter* nc = [NSNotificationCenter defaultCenter]; | 369 return; |
| 368 [nc addObserver:self | 370 } |
| 369 selector:@selector(windowDidResignKey:) | 371 |
| 370 name:NSWindowDidResignKeyNotification | 372 // Invert the textfield's colors when Material Design and Incognito and not |
| 371 object:[self window]]; | 373 // a custom theme. |
| 372 [nc addObserver:self | 374 if (ui::MaterialDesignController::IsModeMaterial() && |
| 373 selector:@selector(windowDidResize:) | 375 [[self window] inIncognitoModeWithSystemTheme]) { |
|
Avi (use Gerrit)
2016/03/01 19:59:06
hasDarkTheme?
shrike
2016/03/01 20:30:14
For the omnibox/location bar, we want the dark sty
| |
| 374 name:NSWindowDidResizeNotification | 376 [self setTextColor:[NSColor whiteColor]]; |
| 375 object:[self window]]; | 377 [self setBackgroundColor: |
| 376 // Only register for drops if not in a popup window. Lazily create the | 378 [NSColor colorWithCalibratedWhite:115 / 255. alpha:1]]; |
| 377 // drop handler when the type of window is known. | 379 } |
| 378 BrowserWindowController* windowController = | 380 |
| 379 [BrowserWindowController browserWindowControllerForView:self]; | 381 NSNotificationCenter* nc = [NSNotificationCenter defaultCenter]; |
| 380 if ([windowController isTabbedWindow]) | 382 [nc addObserver:self |
| 383 selector:@selector(windowDidResignKey:) | |
| 384 name:NSWindowDidResignKeyNotification | |
| 385 object:[self window]]; | |
| 386 [nc addObserver:self | |
| 387 selector:@selector(windowDidResize:) | |
| 388 name:NSWindowDidResizeNotification | |
| 389 object:[self window]]; | |
| 390 // Only register for drops if not in a popup window. Lazily create the | |
| 391 // drop handler when the type of window is known. | |
| 392 BrowserWindowController* windowController = | |
| 393 [BrowserWindowController browserWindowControllerForView:self]; | |
| 394 if ([windowController isTabbedWindow]) | |
| 381 dropHandler_.reset([[URLDropTargetHandler alloc] initWithView:self]); | 395 dropHandler_.reset([[URLDropTargetHandler alloc] initWithView:self]); |
| 382 } | |
| 383 } | 396 } |
| 384 | 397 |
| 385 // NSTextField becomes first responder by installing a "field editor" | 398 // NSTextField becomes first responder by installing a "field editor" |
| 386 // subview. Clicks outside the field editor (such as a decoration) | 399 // subview. Clicks outside the field editor (such as a decoration) |
| 387 // will attempt to make the field the first-responder again, which | 400 // will attempt to make the field the first-responder again, which |
| 388 // causes a select-all, even if the decoration handles the click. If | 401 // causes a select-all, even if the decoration handles the click. If |
| 389 // the field editor is already in place, don't accept first responder | 402 // the field editor is already in place, don't accept first responder |
| 390 // again. This allows the selection to be unmodified if the click is | 403 // again. This allows the selection to be unmodified if the click is |
| 391 // handled by a decoration or context menu (|-mouseDown:| will still | 404 // handled by a decoration or context menu (|-mouseDown:| will still |
| 392 // change it if appropriate). | 405 // change it if appropriate). |
| (...skipping 127 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 520 NSMinY(frame), | 533 NSMinY(frame), |
| 521 suggestWidth, | 534 suggestWidth, |
| 522 NSHeight(frame)); | 535 NSHeight(frame)); |
| 523 | 536 |
| 524 gfx::ScopedNSGraphicsContextSaveGState saveGState; | 537 gfx::ScopedNSGraphicsContextSaveGState saveGState; |
| 525 NSRectClip(suggestRect); | 538 NSRectClip(suggestRect); |
| 526 [cell drawInteriorWithFrame:frame inView:controlView]; | 539 [cell drawInteriorWithFrame:frame inView:controlView]; |
| 527 } | 540 } |
| 528 | 541 |
| 529 } // namespace autocomplete_text_field | 542 } // namespace autocomplete_text_field |
| OLD | NEW |