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

Unified Diff: chrome/browser/ui/views/omnibox/omnibox_view_views.cc

Issue 12300008: Save/restore views omnibox selection on blur/focus, select all on click focus. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Sync and rebase Created 7 years, 10 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 | ui/views/controls/textfield/native_textfield_views.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/browser/ui/views/omnibox/omnibox_view_views.cc
diff --git a/chrome/browser/ui/views/omnibox/omnibox_view_views.cc b/chrome/browser/ui/views/omnibox/omnibox_view_views.cc
index 9fa1eeb345334e9a026966e9bf8f05d7bd8d8e35..3ae3fde20c9ceb423e10ea3913fd4e9bdf73618a 100644
--- a/chrome/browser/ui/views/omnibox/omnibox_view_views.cc
+++ b/chrome/browser/ui/views/omnibox/omnibox_view_views.cc
@@ -219,7 +219,6 @@ void OmniboxViewViews::OnBoundsChanged(const gfx::Rect& previous_bounds) {
}
bool OmniboxViewViews::OnMousePressed(const ui::MouseEvent& event) {
- const bool result = views::Textfield::OnMousePressed(event);
select_all_on_mouse_release_ =
(event.IsOnlyLeftMouseButton() || event.IsOnlyRightMouseButton()) &&
(!HasFocus() || (model()->focus_state() == OMNIBOX_FOCUS_INVISIBLE));
@@ -229,7 +228,7 @@ bool OmniboxViewViews::OnMousePressed(const ui::MouseEvent& event) {
// either SetFocus() or OmniboxEditModel::OnSetFocus().
if (select_all_on_mouse_release_)
model()->SetCaretVisibility(true);
- return result;
+ return views::Textfield::OnMousePressed(event);
Peter Kasting 2013/02/19 01:56:24 Does this need a comment about why it's important
msw 2013/02/19 02:14:11 AFAICT the order doesn't matter, I just switched i
}
bool OmniboxViewViews::OnMouseDragged(const ui::MouseEvent& event) {
@@ -241,8 +240,6 @@ void OmniboxViewViews::OnMouseReleased(const ui::MouseEvent& event) {
views::Textfield::OnMouseReleased(event);
if ((event.IsOnlyLeftMouseButton() || event.IsOnlyRightMouseButton()) &&
select_all_on_mouse_release_) {
- // Select all in the reverse direction so as not to scroll the caret
- // into view and shift the contents jarringly.
Peter Kasting 2013/02/19 01:56:24 Why delete this comment?
msw 2013/02/19 02:14:11 I restored it (I thought it might be unnecessary,
SelectAll(true);
}
select_all_on_mouse_release_ = false;
@@ -257,8 +254,8 @@ bool OmniboxViewViews::OnKeyPressed(const ui::KeyEvent& event) {
OnAfterPossibleChange();
return true;
}
- bool handled = views::Textfield::OnKeyPressed(event);
+ bool handled = views::Textfield::OnKeyPressed(event);
if (event.key_code() == ui::VKEY_RETURN) {
bool alt_held = event.IsAltDown();
model()->AcceptInput(alt_held ? NEW_FOREGROUND_TAB : CURRENT_TAB, false);
@@ -298,23 +295,9 @@ bool OmniboxViewViews::OnKeyPressed(const ui::KeyEvent& event) {
model()->OnUpOrDownKeyPressed(event.IsShiftDown() ? -1 : 1);
}
handled = true;
- } else {
- string16::size_type start = 0;
- string16::size_type end = 0;
- const size_t length = text().length();
- GetSelectionBounds(&start, &end);
- if (start != end || start < length) {
- OnBeforePossibleChange();
- SelectRange(ui::Range(length, length));
- OnAfterPossibleChange();
- handled = true;
- }
-
- // TODO(msw|oshima): Handle Instant.
}
}
- // TODO(msw|oshima): Handle page up and page down.
-
+ // TODO(msw): Handle Instant, tab through popup, tab to search, page up/down.
return handled;
}
@@ -335,11 +318,17 @@ void OmniboxViewViews::OnFocus() {
views::Textfield::OnFocus();
// TODO(oshima): Get control key state.
model()->OnSetFocus(false);
- // Don't call controller()->OnSetFocus as this view has already
- // acquired the focus.
+ // Don't call controller()->OnSetFocus, this view has already acquired focus.
+
+ // Restore a valid saved selection on tab-to-focus.
+ if (saved_temporary_selection_.IsValid() && !select_all_on_mouse_release_)
+ SelectRange(saved_temporary_selection_);
}
void OmniboxViewViews::OnBlur() {
+ // Save the selection to restore on tab-to-focus.
+ GetSelectedRange(&saved_temporary_selection_);
+
views::Textfield::OnBlur();
gfx::NativeView native_view = NULL;
#if defined(USE_AURA)
« no previous file with comments | « no previous file | ui/views/controls/textfield/native_textfield_views.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698