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

Side by Side Diff: chrome/browser/autocomplete/autocomplete_edit_view_gtk.cc

Issue 440003: gtk: Restore omnibox text selection on tab switch. (Closed)
Patch Set: Created 11 years, 1 month 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
OLDNEW
1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2009 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_gtk.h" 5 #include "chrome/browser/autocomplete/autocomplete_edit_view_gtk.h"
6 6
7 #include <gtk/gtk.h> 7 #include <gtk/gtk.h>
8 #include <gdk/gdkkeysyms.h> 8 #include <gdk/gdkkeysyms.h>
9 9
10 #include <algorithm> 10 #include <algorithm>
(...skipping 313 matching lines...) Expand 10 before | Expand all | Expand 10 after
324 324
325 if (contents) { 325 if (contents) {
326 selected_text_.clear(); 326 selected_text_.clear();
327 RevertAll(); 327 RevertAll();
328 const AutocompleteEditState* state = 328 const AutocompleteEditState* state =
329 GetStateAccessor()->GetProperty(contents->property_bag()); 329 GetStateAccessor()->GetProperty(contents->property_bag());
330 if (state) { 330 if (state) {
331 model_->RestoreState(state->model_state); 331 model_->RestoreState(state->model_state);
332 332
333 // Move the marks for the cursor and the other end of the selection to 333 // Move the marks for the cursor and the other end of the selection to
334 // the previously-saved offsets. 334 // the previously-saved offsets (but preserve PRIMARY).
335 GtkTextIter selection_iter, insert_iter; 335 StartUpdatingHighlightedText();
336 ItersFromCharRange( 336 SetSelectedRange(state->view_state.selection_range);
337 state->view_state.selection_range, &selection_iter, &insert_iter); 337 FinishUpdatingHighlightedText();
338 // TODO(derat): Restore the selection range instead of just the cursor
339 // ("insert") position. This in itself is trivial to do using
340 // gtk_text_buffer_select_range(), but then it also becomes necessary to
341 // invalidate hidden tabs' saved ranges when another tab or another app
342 // takes the selection, lest we incorrectly regrab a stale selection when
343 // a hidden tab is later shown.
344 gtk_text_buffer_place_cursor(text_buffer_, &insert_iter);
345 } 338 }
346 } else if (visibly_changed_permanent_text) { 339 } else if (visibly_changed_permanent_text) {
347 RevertAll(); 340 RevertAll();
348 // TODO(deanm): There should be code to restore select all here. 341 // TODO(deanm): There should be code to restore select all here.
349 } else if (changed_security_level) { 342 } else if (changed_security_level) {
350 EmphasizeURLComponents(); 343 EmphasizeURLComponents();
351 } 344 }
352 } 345 }
353 346
354 void AutocompleteEditViewGtk::OpenURL(const GURL& url, 347 void AutocompleteEditViewGtk::OpenURL(const GURL& url,
(...skipping 961 matching lines...) Expand 10 before | Expand all | Expand 10 after
1316 std::string utf8 = WideToUTF8(text); 1309 std::string utf8 = WideToUTF8(text);
1317 gtk_text_buffer_set_text(text_buffer_, utf8.data(), utf8.length()); 1310 gtk_text_buffer_set_text(text_buffer_, utf8.data(), utf8.length());
1318 SetSelectedRange(range); 1311 SetSelectedRange(range);
1319 } 1312 }
1320 1313
1321 void AutocompleteEditViewGtk::SetSelectedRange(const CharRange& range) { 1314 void AutocompleteEditViewGtk::SetSelectedRange(const CharRange& range) {
1322 GtkTextIter insert, bound; 1315 GtkTextIter insert, bound;
1323 ItersFromCharRange(range, &bound, &insert); 1316 ItersFromCharRange(range, &bound, &insert);
1324 gtk_text_buffer_select_range(text_buffer_, &insert, &bound); 1317 gtk_text_buffer_select_range(text_buffer_, &insert, &bound);
1325 } 1318 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698