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

Unified 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: Less boilerplate 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | chrome/browser/ui/omnibox/omnibox_view_browsertest.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/browser/ui/cocoa/omnibox/omnibox_view_mac.mm
diff --git a/chrome/browser/ui/cocoa/omnibox/omnibox_view_mac.mm b/chrome/browser/ui/cocoa/omnibox/omnibox_view_mac.mm
index 7d296dd7b43eac1eeaa73540e8d966c7c8375408..efa97fe3e940f8fc6adb1e5faa78024854b9b69a 100644
--- a/chrome/browser/ui/cocoa/omnibox/omnibox_view_mac.mm
+++ b/chrome/browser/ui/cocoa/omnibox/omnibox_view_mac.mm
@@ -219,11 +219,25 @@ void OmniboxViewMac::Update() {
controller()->GetToolbarModel()->set_url_replacement_enabled(true);
model()->UpdatePermanentText();
+ const bool was_select_all = IsSelectAll();
+ NSTextView* text_view =
+ base::mac::ObjCCastStrict<NSTextView>([field_ currentEditor]);
+ const bool was_reversed =
+ [text_view selectionAffinity] == NSSelectionAffinityUpstream;
+
// Restore everything to the baseline look.
RevertAll();
- // TODO(shess): Figure out how this case is used, to make sure
- // we're getting the selection and popup right.
+ // Only select all when we have focus. If we don't have focus, selecting
+ // all is unnecessary since the selection will change on regaining focus,
+ // and can in fact cause artifacts, e.g. if the user is on the NTP and
+ // clicks a link to navigate, causing |was_select_all| to be vacuously true
+ // for the empty omnibox, and we then select all here, leading to the
+ // trailing portion of a long URL being scrolled into view. We could try
+ // and address cases like this, but it seems better to just not muck with
+ // things when the omnibox isn't focused to begin with.
+ if (was_select_all && model()->has_focus())
+ SelectAll(was_reversed);
} else {
// TODO(shess): This corresponds to _win and _gtk, except those
// guard it with a test for whether the security level changed.
@@ -343,13 +357,17 @@ void OmniboxViewMac::GetSelectionBounds(base::string16::size_type* start,
}
void OmniboxViewMac::SelectAll(bool reversed) {
- // TODO(shess): Figure out what |reversed| implies. The gtk version
- // has it imply inverting the selection front to back, but I don't
- // even know if that makes sense for Mac.
+ DCHECK(!in_coalesced_update_block_);
+ 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
+ return;
+
+ NSTextView* text_view =
+ base::mac::ObjCCastStrict<NSTextView>([field_ currentEditor]);
+ NSSelectionAffinity affinity =
+ reversed ? NSSelectionAffinityUpstream : NSSelectionAffinityDownstream;
+ NSRange range = NSMakeRange(0, GetTextLength());
- // TODO(shess): Verify that we should be stealing focus at this
- // point.
- SetSelectedRange(NSMakeRange(0, GetTextLength()));
+ [text_view setSelectedRange:range affinity:affinity stillSelecting:NO];
}
void OmniboxViewMac::RevertAll() {
« 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