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

Side by Side Diff: chrome/browser/ui/cocoa/omnibox/omnibox_view_mac.mm

Issue 1144853003: Mac: Omnibox: Retain the "SelectAll" state after a navigation. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 7 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
« no previous file with comments | « no previous file | chrome/browser/ui/omnibox/omnibox_view_browsertest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
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
222 // Restore everything to the baseline look. 224 // Restore everything to the baseline look.
223 RevertAll(); 225 RevertAll();
224 226
225 // TODO(shess): Figure out how this case is used, to make sure 227 // TODO(shess): Figure out how this case is used, to make sure
226 // we're getting the selection and popup right. 228 // we're getting the selection and popup right.
Peter Kasting 2015/05/19 07:04:01 Nit: Remove TODO; copy comment from views code
tapted 2015/05/19 11:28:39 Done.
229 if (was_select_all && model()->has_focus())
230 SelectAll(false /* reversed: ignored on mac */);
Peter Kasting 2015/05/19 07:04:00 Reversed state shouldn't be ignored. You should s
tapted 2015/05/19 11:28:39 Done.
227 } else { 231 } else {
228 // TODO(shess): This corresponds to _win and _gtk, except those 232 // TODO(shess): This corresponds to _win and _gtk, except those
229 // guard it with a test for whether the security level changed. 233 // guard it with a test for whether the security level changed.
230 // But AFAICT, that can only change if the text changed, and that 234 // But AFAICT, that can only change if the text changed, and that
231 // code compares the toolbar model security level with the local 235 // 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 236 // security level. Dig in and figure out why this isn't a no-op
233 // that should go away. 237 // that should go away.
234 EmphasizeURLComponents(); 238 EmphasizeURLComponents();
235 } 239 }
236 } 240 }
(...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after
338 } 342 }
339 343
340 const NSRange selected_range = GetSelectedRange(); 344 const NSRange selected_range = GetSelectedRange();
341 *start = static_cast<size_t>(selected_range.location); 345 *start = static_cast<size_t>(selected_range.location);
342 *end = static_cast<size_t>(NSMaxRange(selected_range)); 346 *end = static_cast<size_t>(NSMaxRange(selected_range));
343 } 347 }
344 348
345 void OmniboxViewMac::SelectAll(bool reversed) { 349 void OmniboxViewMac::SelectAll(bool reversed) {
346 // TODO(shess): Figure out what |reversed| implies. The gtk version 350 // TODO(shess): Figure out what |reversed| implies. The gtk version
347 // has it imply inverting the selection front to back, but I don't 351 // has it imply inverting the selection front to back, but I don't
348 // even know if that makes sense for Mac. 352 // even know if that makes sense for Mac.
Peter Kasting 2015/05/19 07:04:00 Surely Mac can distinguish between a left-to-right
tapted 2015/05/19 11:28:39 Done+tested.
349 353
350 // TODO(shess): Verify that we should be stealing focus at this 354 // TODO(shess): Verify that we should be stealing focus at this
351 // point. 355 // point.
352 SetSelectedRange(NSMakeRange(0, GetTextLength())); 356 SetSelectedRange(NSMakeRange(0, GetTextLength()));
353 } 357 }
354 358
355 void OmniboxViewMac::RevertAll() { 359 void OmniboxViewMac::RevertAll() {
356 OmniboxView::RevertAll(); 360 OmniboxView::RevertAll();
357 [field_ clearUndoChain]; 361 [field_ clearUndoChain];
358 } 362 }
(...skipping 650 matching lines...) Expand 10 before | Expand all | Expand 10 after
1009 1013
1010 NSUInteger OmniboxViewMac::GetTextLength() const { 1014 NSUInteger OmniboxViewMac::GetTextLength() const {
1011 return [field_ currentEditor] ? [[[field_ currentEditor] string] length] : 1015 return [field_ currentEditor] ? [[[field_ currentEditor] string] length] :
1012 [[field_ stringValue] length]; 1016 [[field_ stringValue] length];
1013 } 1017 }
1014 1018
1015 bool OmniboxViewMac::IsCaretAtEnd() const { 1019 bool OmniboxViewMac::IsCaretAtEnd() const {
1016 const NSRange selection = GetSelectedRange(); 1020 const NSRange selection = GetSelectedRange();
1017 return NSMaxRange(selection) == GetTextLength(); 1021 return NSMaxRange(selection) == GetTextLength();
1018 } 1022 }
OLDNEW
« no previous file with comments | « no previous file | chrome/browser/ui/omnibox/omnibox_view_browsertest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698