Chromium Code Reviews| 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/metrics/histogram.h" | 10 #include "base/metrics/histogram.h" |
| (...skipping 201 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 212 void OmniboxViewMac::ResetTabState(WebContents* web_contents) { | 212 void OmniboxViewMac::ResetTabState(WebContents* web_contents) { |
| 213 StoreStateToTab(web_contents, nullptr); | 213 StoreStateToTab(web_contents, nullptr); |
| 214 } | 214 } |
| 215 | 215 |
| 216 void OmniboxViewMac::Update() { | 216 void OmniboxViewMac::Update() { |
| 217 if (model()->UpdatePermanentText()) { | 217 if (model()->UpdatePermanentText()) { |
| 218 // Something visibly changed. Re-enable URL replacement. | 218 // Something visibly changed. Re-enable URL replacement. |
| 219 controller()->GetToolbarModel()->set_url_replacement_enabled(true); | 219 controller()->GetToolbarModel()->set_url_replacement_enabled(true); |
| 220 model()->UpdatePermanentText(); | 220 model()->UpdatePermanentText(); |
| 221 | 221 |
| 222 const bool was_select_all = IsSelectAll(); | |
| 223 NSTextView* text_view = | |
| 224 base::mac::ObjCCastStrict<NSTextView>([field_ currentEditor]); | |
| 225 const bool was_reversed = | |
| 226 [text_view selectionAffinity] == NSSelectionAffinityUpstream; | |
| 227 | |
| 222 // Restore everything to the baseline look. | 228 // Restore everything to the baseline look. |
| 223 RevertAll(); | 229 RevertAll(); |
| 224 | 230 |
| 225 // TODO(shess): Figure out how this case is used, to make sure | 231 // Only select all when we have focus. If we don't have focus, selecting |
| 226 // we're getting the selection and popup right. | 232 // all is unnecessary since the selection will change on regaining focus, |
| 233 // and can in fact cause artifacts, e.g. if the user is on the NTP and | |
| 234 // clicks a link to navigate, causing |was_select_all| to be vacuously true | |
| 235 // for the empty omnibox, and we then select all here, leading to the | |
| 236 // trailing portion of a long URL being scrolled into view. We could try | |
| 237 // and address cases like this, but it seems better to just not muck with | |
| 238 // things when the omnibox isn't focused to begin with. | |
| 239 if (was_select_all && model()->has_focus()) | |
| 240 SelectAll(was_reversed); | |
| 227 } else { | 241 } else { |
| 228 // TODO(shess): This corresponds to _win and _gtk, except those | 242 // TODO(shess): This corresponds to _win and _gtk, except those |
| 229 // guard it with a test for whether the security level changed. | 243 // guard it with a test for whether the security level changed. |
| 230 // But AFAICT, that can only change if the text changed, and that | 244 // But AFAICT, that can only change if the text changed, and that |
| 231 // code compares the toolbar model security level with the local | 245 // code compares the toolbar model security level with the local |
| 232 // security level. Dig in and figure out why this isn't a no-op | 246 // security level. Dig in and figure out why this isn't a no-op |
| 233 // that should go away. | 247 // that should go away. |
| 234 EmphasizeURLComponents(); | 248 EmphasizeURLComponents(); |
| 235 } | 249 } |
| 236 } | 250 } |
| (...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 336 *start = *end = 0; | 350 *start = *end = 0; |
| 337 return; | 351 return; |
| 338 } | 352 } |
| 339 | 353 |
| 340 const NSRange selected_range = GetSelectedRange(); | 354 const NSRange selected_range = GetSelectedRange(); |
| 341 *start = static_cast<size_t>(selected_range.location); | 355 *start = static_cast<size_t>(selected_range.location); |
| 342 *end = static_cast<size_t>(NSMaxRange(selected_range)); | 356 *end = static_cast<size_t>(NSMaxRange(selected_range)); |
| 343 } | 357 } |
| 344 | 358 |
| 345 void OmniboxViewMac::SelectAll(bool reversed) { | 359 void OmniboxViewMac::SelectAll(bool reversed) { |
| 346 // TODO(shess): Figure out what |reversed| implies. The gtk version | 360 DCHECK(!in_coalesced_update_block_); |
| 347 // has it imply inverting the selection front to back, but I don't | 361 if (!model()->has_focus()) |
|
Peter Kasting
2015/05/19 21:32:55
This line isn't in views -- are you sure it's corr
tapted
2015/05/20 00:52:22
Yeah - this was to keep consistent with the behavi
| |
| 348 // even know if that makes sense for Mac. | 362 return; |
| 349 | 363 |
| 350 // TODO(shess): Verify that we should be stealing focus at this | 364 NSTextView* text_view = |
| 351 // point. | 365 base::mac::ObjCCastStrict<NSTextView>([field_ currentEditor]); |
| 352 SetSelectedRange(NSMakeRange(0, GetTextLength())); | 366 NSSelectionAffinity affinity = |
| 367 reversed ? NSSelectionAffinityUpstream : NSSelectionAffinityDownstream; | |
| 368 NSRange range = NSMakeRange(0, GetTextLength()); | |
| 369 | |
| 370 [text_view setSelectedRange:range affinity:affinity stillSelecting:NO]; | |
| 353 } | 371 } |
| 354 | 372 |
| 355 void OmniboxViewMac::RevertAll() { | 373 void OmniboxViewMac::RevertAll() { |
| 356 OmniboxView::RevertAll(); | 374 OmniboxView::RevertAll(); |
| 357 [field_ clearUndoChain]; | 375 [field_ clearUndoChain]; |
| 358 } | 376 } |
| 359 | 377 |
| 360 void OmniboxViewMac::UpdatePopup() { | 378 void OmniboxViewMac::UpdatePopup() { |
| 361 model()->SetInputInProgress(true); | 379 model()->SetInputInProgress(true); |
| 362 if (!model()->has_focus()) | 380 if (!model()->has_focus()) |
| (...skipping 646 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1009 | 1027 |
| 1010 NSUInteger OmniboxViewMac::GetTextLength() const { | 1028 NSUInteger OmniboxViewMac::GetTextLength() const { |
| 1011 return [field_ currentEditor] ? [[[field_ currentEditor] string] length] : | 1029 return [field_ currentEditor] ? [[[field_ currentEditor] string] length] : |
| 1012 [[field_ stringValue] length]; | 1030 [[field_ stringValue] length]; |
| 1013 } | 1031 } |
| 1014 | 1032 |
| 1015 bool OmniboxViewMac::IsCaretAtEnd() const { | 1033 bool OmniboxViewMac::IsCaretAtEnd() const { |
| 1016 const NSRange selection = GetSelectedRange(); | 1034 const NSRange selection = GetSelectedRange(); |
| 1017 return NSMaxRange(selection) == GetTextLength(); | 1035 return NSMaxRange(selection) == GetTextLength(); |
| 1018 } | 1036 } |
| OLD | NEW |