OLD | NEW |
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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/autocomplete/autocomplete_edit_view_mac.h" | 5 #include "chrome/browser/autocomplete/autocomplete_edit_view_mac.h" |
6 | 6 |
7 #include <Carbon/Carbon.h> // kVK_Return | 7 #include <Carbon/Carbon.h> // kVK_Return |
8 | 8 |
9 #include "app/clipboard/clipboard.h" | 9 #include "app/clipboard/clipboard.h" |
10 #include "app/clipboard/scoped_clipboard_writer.h" | 10 #include "app/clipboard/scoped_clipboard_writer.h" |
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
54 // the same values easily. | 54 // the same values easily. |
55 const NSColor* ColorWithRGBBytes(int rr, int gg, int bb) { | 55 const NSColor* ColorWithRGBBytes(int rr, int gg, int bb) { |
56 DCHECK_LE(rr, 255); | 56 DCHECK_LE(rr, 255); |
57 DCHECK_LE(bb, 255); | 57 DCHECK_LE(bb, 255); |
58 DCHECK_LE(gg, 255); | 58 DCHECK_LE(gg, 255); |
59 return [NSColor colorWithCalibratedRed:static_cast<float>(rr)/255.0 | 59 return [NSColor colorWithCalibratedRed:static_cast<float>(rr)/255.0 |
60 green:static_cast<float>(gg)/255.0 | 60 green:static_cast<float>(gg)/255.0 |
61 blue:static_cast<float>(bb)/255.0 | 61 blue:static_cast<float>(bb)/255.0 |
62 alpha:1.0]; | 62 alpha:1.0]; |
63 } | 63 } |
64 const NSColor* SecureBackgroundColor() { | |
65 return ColorWithRGBBytes(255, 245, 195); // Yellow | |
66 } | |
67 const NSColor* NormalBackgroundColor() { | |
68 return [NSColor controlBackgroundColor]; | |
69 } | |
70 const NSColor* InsecureBackgroundColor() { | |
71 return [NSColor controlBackgroundColor]; | |
72 } | |
73 | 64 |
74 const NSColor* HostTextColor() { | 65 const NSColor* HostTextColor() { |
75 return [NSColor blackColor]; | 66 return [NSColor blackColor]; |
76 } | 67 } |
77 const NSColor* BaseTextColor() { | 68 const NSColor* BaseTextColor() { |
78 return [NSColor darkGrayColor]; | 69 return [NSColor darkGrayColor]; |
79 } | 70 } |
| 71 const NSColor* EVSecureSchemeColor() { |
| 72 return ColorWithRGBBytes(0x07, 0x95, 0x00); |
| 73 } |
80 const NSColor* SecureSchemeColor() { | 74 const NSColor* SecureSchemeColor() { |
81 return ColorWithRGBBytes(0x00, 0x96, 0x14); | 75 return ColorWithRGBBytes(0x00, 0x0e, 0x95); |
82 } | 76 } |
83 const NSColor* InsecureSchemeColor() { | 77 const NSColor* SecurityErrorSchemeColor() { |
84 return ColorWithRGBBytes(0xc8, 0x00, 0x00); | 78 return ColorWithRGBBytes(0xa2, 0x00, 0x00); |
85 } | 79 } |
86 | 80 |
87 // Store's the model and view state across tab switches. | 81 // Store's the model and view state across tab switches. |
88 struct AutocompleteEditViewMacState { | 82 struct AutocompleteEditViewMacState { |
89 AutocompleteEditViewMacState(const AutocompleteEditModel::State model_state, | 83 AutocompleteEditViewMacState(const AutocompleteEditModel::State model_state, |
90 const bool has_focus, const NSRange& selection) | 84 const bool has_focus, const NSRange& selection) |
91 : model_state(model_state), | 85 : model_state(model_state), |
92 has_focus(has_focus), | 86 has_focus(has_focus), |
93 selection(selection) { | 87 selection(selection) { |
94 } | 88 } |
(...skipping 308 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
403 [as addAttribute:NSForegroundColorAttributeName value:BaseTextColor() | 397 [as addAttribute:NSForegroundColorAttributeName value:BaseTextColor() |
404 range:NSMakeRange(0, [as length])]; | 398 range:NSMakeRange(0, [as length])]; |
405 | 399 |
406 [as addAttribute:NSForegroundColorAttributeName value:HostTextColor() | 400 [as addAttribute:NSForegroundColorAttributeName value:HostTextColor() |
407 range:ComponentToNSRange(host)]; | 401 range:ComponentToNSRange(host)]; |
408 } | 402 } |
409 | 403 |
410 // TODO(shess): GTK has this as a member var, figure out why. | 404 // TODO(shess): GTK has this as a member var, figure out why. |
411 // [Could it be to not change if no change? If so, I'm guessing | 405 // [Could it be to not change if no change? If so, I'm guessing |
412 // AppKit may already handle that.] | 406 // AppKit may already handle that.] |
413 const ToolbarModel::SecurityLevel scheme_security_level = | 407 const ToolbarModel::SecurityLevel security_level = |
414 toolbar_model_->GetSchemeSecurityLevel(); | 408 toolbar_model_->GetSecurityLevel(); |
415 | |
416 if (scheme_security_level == ToolbarModel::SECURE) { | |
417 [field_ setBackgroundColor:SecureBackgroundColor()]; | |
418 } else if (scheme_security_level == ToolbarModel::NORMAL) { | |
419 [field_ setBackgroundColor:NormalBackgroundColor()]; | |
420 } else if (scheme_security_level == ToolbarModel::INSECURE) { | |
421 [field_ setBackgroundColor:InsecureBackgroundColor()]; | |
422 } else { | |
423 NOTREACHED() << "Unexpected scheme_security_level: " | |
424 << scheme_security_level; | |
425 } | |
426 | 409 |
427 // Emphasize the scheme for security UI display purposes (if necessary). | 410 // Emphasize the scheme for security UI display purposes (if necessary). |
428 if (!model_->user_input_in_progress() && scheme.is_nonempty() && | 411 if (!model_->user_input_in_progress() && scheme.is_nonempty() && |
429 (scheme_security_level != ToolbarModel::NORMAL)) { | 412 (security_level != ToolbarModel::NONE)) { |
430 NSColor* color; | 413 NSColor* color; |
431 if (scheme_security_level == ToolbarModel::SECURE) { | 414 if (security_level == ToolbarModel::EV_SECURE) { |
432 color = SecureSchemeColor(); | 415 color = EVSecureSchemeColor(); |
433 } else { | 416 } else if (security_level == ToolbarModel::SECURITY_ERROR) { |
434 color = InsecureSchemeColor(); | 417 color = SecurityErrorSchemeColor(); |
435 // Add a strikethrough through the scheme. | 418 // Add a strikethrough through the scheme. |
436 [as addAttribute:NSStrikethroughStyleAttributeName | 419 [as addAttribute:NSStrikethroughStyleAttributeName |
437 value:[NSNumber numberWithInt:NSUnderlineStyleSingle] | 420 value:[NSNumber numberWithInt:NSUnderlineStyleSingle] |
438 range:ComponentToNSRange(scheme)]; | 421 range:ComponentToNSRange(scheme)]; |
| 422 } else { |
| 423 color = SecureSchemeColor(); |
439 } | 424 } |
440 [as addAttribute:NSForegroundColorAttributeName value:color | 425 [as addAttribute:NSForegroundColorAttributeName value:color |
441 range:ComponentToNSRange(scheme)]; | 426 range:ComponentToNSRange(scheme)]; |
442 } | 427 } |
443 | 428 |
444 [field_ setAttributedStringValue:as]; | 429 [field_ setAttributedStringValue:as]; |
445 | 430 |
446 // TODO(shess): This may be an appropriate place to call: | 431 // TODO(shess): This may be an appropriate place to call: |
447 // controller_->OnChanged(); | 432 // controller_->OnChanged(); |
448 // In the current implementation, this tells LocationBarViewMac to | 433 // In the current implementation, this tells LocationBarViewMac to |
(...skipping 411 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
860 clipboard->ReadBookmark(NULL, &url_str); | 845 clipboard->ReadBookmark(NULL, &url_str); |
861 // pass resulting url string through GURL to normalize | 846 // pass resulting url string through GURL to normalize |
862 GURL url(url_str); | 847 GURL url(url_str); |
863 if (url.is_valid()) { | 848 if (url.is_valid()) { |
864 return UTF8ToWide(url.spec()); | 849 return UTF8ToWide(url.spec()); |
865 } | 850 } |
866 } | 851 } |
867 | 852 |
868 return std::wstring(); | 853 return std::wstring(); |
869 } | 854 } |
OLD | NEW |