| OLD | NEW |
| 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/memory/ptr_util.h" | 10 #include "base/memory/ptr_util.h" |
| (...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 91 NSColor* HostTextColor(bool in_dark_mode) { | 91 NSColor* HostTextColor(bool in_dark_mode) { |
| 92 if (!ui::MaterialDesignController::IsModeMaterial()) { | 92 if (!ui::MaterialDesignController::IsModeMaterial()) { |
| 93 return [NSColor blackColor]; | 93 return [NSColor blackColor]; |
| 94 } | 94 } |
| 95 return in_dark_mode ? [NSColor whiteColor] : [NSColor blackColor]; | 95 return in_dark_mode ? [NSColor whiteColor] : [NSColor blackColor]; |
| 96 } | 96 } |
| 97 NSColor* SecureSchemeColor(bool in_dark_mode) { | 97 NSColor* SecureSchemeColor(bool in_dark_mode) { |
| 98 if (!ui::MaterialDesignController::IsModeMaterial()) { | 98 if (!ui::MaterialDesignController::IsModeMaterial()) { |
| 99 return ColorWithRGBBytes(0x07, 0x95, 0x00); | 99 return ColorWithRGBBytes(0x07, 0x95, 0x00); |
| 100 } | 100 } |
| 101 return in_dark_mode | 101 return in_dark_mode ? [NSColor colorWithCalibratedWhite:1 alpha:0.5] |
| 102 ? skia::SkColorToSRGBNSColor(SkColorSetA(SK_ColorWHITE, 0x7F)) | 102 : skia::SkColorToCalibratedNSColor(gfx::kGoogleGreen700); |
| 103 : skia::SkColorToSRGBNSColor(gfx::kGoogleGreen700); | |
| 104 } | 103 } |
| 105 NSColor* SecurityWarningSchemeColor(bool in_dark_mode) { | 104 NSColor* SecurityWarningSchemeColor(bool in_dark_mode) { |
| 106 return in_dark_mode | 105 return in_dark_mode ? [NSColor colorWithCalibratedWhite:1 alpha:0.5] |
| 107 ? skia::SkColorToSRGBNSColor(SkColorSetA(SK_ColorWHITE, 0x7F)) | 106 : skia::SkColorToCalibratedNSColor(gfx::kGoogleYellow700); |
| 108 : skia::SkColorToSRGBNSColor(gfx::kGoogleYellow700); | |
| 109 } | 107 } |
| 110 NSColor* SecurityErrorSchemeColor(bool in_dark_mode) { | 108 NSColor* SecurityErrorSchemeColor(bool in_dark_mode) { |
| 111 if (!ui::MaterialDesignController::IsModeMaterial()) { | 109 if (!ui::MaterialDesignController::IsModeMaterial()) { |
| 112 return ColorWithRGBBytes(0xa2, 0x00, 0x00); | 110 return ColorWithRGBBytes(0xa2, 0x00, 0x00); |
| 113 } | 111 } |
| 114 return in_dark_mode | 112 return in_dark_mode ? [NSColor colorWithCalibratedWhite:1 alpha:0.5] |
| 115 ? skia::SkColorToSRGBNSColor(SkColorSetA(SK_ColorWHITE, 0x7F)) | 113 : skia::SkColorToCalibratedNSColor(gfx::kGoogleRed700); |
| 116 : skia::SkColorToSRGBNSColor(gfx::kGoogleRed700); | |
| 117 } | 114 } |
| 118 | 115 |
| 119 const char kOmniboxViewMacStateKey[] = "OmniboxViewMacState"; | 116 const char kOmniboxViewMacStateKey[] = "OmniboxViewMacState"; |
| 120 | 117 |
| 121 // Store's the model and view state across tab switches. | 118 // Store's the model and view state across tab switches. |
| 122 struct OmniboxViewMacState : public base::SupportsUserData::Data { | 119 struct OmniboxViewMacState : public base::SupportsUserData::Data { |
| 123 OmniboxViewMacState(const OmniboxEditModel::State model_state, | 120 OmniboxViewMacState(const OmniboxEditModel::State model_state, |
| 124 const bool has_focus, | 121 const bool has_focus, |
| 125 const NSRange& selection) | 122 const NSRange& selection) |
| 126 : model_state(model_state), | 123 : model_state(model_state), |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 168 SkColor OmniboxViewMac::BaseTextColorSkia(bool in_dark_mode) { | 165 SkColor OmniboxViewMac::BaseTextColorSkia(bool in_dark_mode) { |
| 169 return in_dark_mode ? SkColorSetA(SK_ColorWHITE, 0x7F) | 166 return in_dark_mode ? SkColorSetA(SK_ColorWHITE, 0x7F) |
| 170 : SkColorSetA(SK_ColorBLACK, 0x7F); | 167 : SkColorSetA(SK_ColorBLACK, 0x7F); |
| 171 } | 168 } |
| 172 | 169 |
| 173 // static | 170 // static |
| 174 NSColor* OmniboxViewMac::BaseTextColor(bool in_dark_mode) { | 171 NSColor* OmniboxViewMac::BaseTextColor(bool in_dark_mode) { |
| 175 if (!ui::MaterialDesignController::IsModeMaterial()) { | 172 if (!ui::MaterialDesignController::IsModeMaterial()) { |
| 176 return [NSColor darkGrayColor]; | 173 return [NSColor darkGrayColor]; |
| 177 } | 174 } |
| 178 return skia::SkColorToSRGBNSColor(BaseTextColorSkia(in_dark_mode)); | 175 return skia::SkColorToCalibratedNSColor(BaseTextColorSkia(in_dark_mode)); |
| 179 } | 176 } |
| 180 | 177 |
| 181 OmniboxViewMac::OmniboxViewMac(OmniboxEditController* controller, | 178 OmniboxViewMac::OmniboxViewMac(OmniboxEditController* controller, |
| 182 Profile* profile, | 179 Profile* profile, |
| 183 CommandUpdater* command_updater, | 180 CommandUpdater* command_updater, |
| 184 AutocompleteTextField* field) | 181 AutocompleteTextField* field) |
| 185 : OmniboxView( | 182 : OmniboxView( |
| 186 controller, | 183 controller, |
| 187 base::WrapUnique(new ChromeOmniboxClient(controller, profile))), | 184 base::WrapUnique(new ChromeOmniboxClient(controller, profile))), |
| 188 profile_(profile), | 185 profile_(profile), |
| (...skipping 947 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1136 | 1133 |
| 1137 NSUInteger OmniboxViewMac::GetTextLength() const { | 1134 NSUInteger OmniboxViewMac::GetTextLength() const { |
| 1138 return [field_ currentEditor] ? [[[field_ currentEditor] string] length] : | 1135 return [field_ currentEditor] ? [[[field_ currentEditor] string] length] : |
| 1139 [[field_ stringValue] length]; | 1136 [[field_ stringValue] length]; |
| 1140 } | 1137 } |
| 1141 | 1138 |
| 1142 bool OmniboxViewMac::IsCaretAtEnd() const { | 1139 bool OmniboxViewMac::IsCaretAtEnd() const { |
| 1143 const NSRange selection = GetSelectedRange(); | 1140 const NSRange selection = GetSelectedRange(); |
| 1144 return NSMaxRange(selection) == GetTextLength(); | 1141 return NSMaxRange(selection) == GetTextLength(); |
| 1145 } | 1142 } |
| OLD | NEW |