diff options
author | pkasting@chromium.org <pkasting@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2008-12-01 21:53:05 +0000 |
---|---|---|
committer | pkasting@chromium.org <pkasting@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2008-12-01 21:53:05 +0000 |
commit | eff6f10a8b99b312fed63b680c91da37eae62188 (patch) | |
tree | 8dff037eb4ebe620f35b833ae543b5c6c86d6f5f /chrome | |
parent | a70e6de55fc1739b76bab19f3b93aad682029c71 (diff) | |
download | chromium_src-eff6f10a8b99b312fed63b680c91da37eae62188.zip chromium_src-eff6f10a8b99b312fed63b680c91da37eae62188.tar.gz chromium_src-eff6f10a8b99b312fed63b680c91da37eae62188.tar.bz2 |
<esc> in the AutocompleteEdit should select all the text when reverting to the permanent text. Only pass it through as an accelerator if we don't end up changing anything. Patch by Mohamed Mansour, r=me. See http://codereview.chromium.org/10800 .
BUG=4203
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@6168 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome')
-rw-r--r-- | chrome/browser/autocomplete/autocomplete_edit.cc | 58 | ||||
-rw-r--r-- | chrome/browser/autocomplete/autocomplete_edit.h | 5 |
2 files changed, 36 insertions, 27 deletions
diff --git a/chrome/browser/autocomplete/autocomplete_edit.cc b/chrome/browser/autocomplete/autocomplete_edit.cc index 6f0b5e1..cfef6a6 100644 --- a/chrome/browser/autocomplete/autocomplete_edit.cc +++ b/chrome/browser/autocomplete/autocomplete_edit.cc @@ -359,29 +359,30 @@ void AutocompleteEditModel::OnKillFocus() { } bool AutocompleteEditModel::OnEscapeKeyPressed() { - // Only do something when there is input in progress -- otherwise, if focus - // happens to be in the location bar, users can't still hit <esc> to stop a - // load. - if (!user_input_in_progress_) - return false; - - if (!has_temporary_text_ || - (popup_->URLsForCurrentSelection(NULL, NULL, NULL) == original_url_)) { - // The popup isn't open or the selection in it is still the default - // selection, so revert the box all the way back to its unedited state. - view_->RevertAll(); + if (has_temporary_text_ && + (popup_->URLsForCurrentSelection(NULL, NULL, NULL) != original_url_)) { + // The user typed something, then selected a different item. Restore the + // text they typed and change back to the default item. + // NOTE: This purposefully does not reset paste_state_. + just_deleted_text_ = false; + has_temporary_text_ = false; + keyword_ui_state_ = original_keyword_ui_state_; + popup_->ResetToDefaultMatch(); + view_->OnRevertTemporaryText(); return true; } - // The user typed something, then selected a different item. Restore the - // text they typed and change back to the default item. - // NOTE: This purposefully does not reset paste_state_. - just_deleted_text_ = false; - has_temporary_text_ = false; - keyword_ui_state_ = original_keyword_ui_state_; - popup_->ResetToDefaultMatch(); - view_->OnRevertTemporaryText(); - return true; + // If the user wasn't editing, but merely had focus in the edit, allow <esc> + // to be processed as an accelerator, so it can still be used to stop a load. + // When the permanent text isn't all selected we still fall through to the + // SelectAll() call below so users can arrow around in the text and then hit + // <esc> to quickly replace all the text; this matches IE. + if (!user_input_in_progress_ && view_->IsSelectAll()) + return false; + + view_->RevertAll(); + view_->SelectAll(true); + return false; } void AutocompleteEditModel::OnControlKeyChanged(bool pressed) { @@ -854,7 +855,8 @@ void AutocompleteEditView::Update(const TabContents* tab_for_state_restoring) { CHARRANGE sel; GetSelection(sel); const bool was_reversed = (sel.cpMin > sel.cpMax); - const bool was_sel_all = (sel.cpMin != sel.cpMax) && IsSelectAll(sel); + const bool was_sel_all = (sel.cpMin != sel.cpMax) && + IsSelectAllForRange(sel); RevertAll(); @@ -922,6 +924,12 @@ void AutocompleteEditView::SetWindowTextAndCaretPos(const std::wstring& text, PlaceCaretAt(caret_pos); } +bool AutocompleteEditView::IsSelectAll() { + CHARRANGE selection; + GetSel(selection); + return IsSelectAllForRange(selection); +} + void AutocompleteEditView::SelectAll(bool reversed) { if (reversed) SetSelection(GetTextLength(), 0); @@ -1804,9 +1812,7 @@ void AutocompleteEditView::OnPaste() { if (!text.empty()) { // If this paste will be replacing all the text, record that, so we can do // different behaviors in such a case. - CHARRANGE sel; - GetSel(sel); - if (IsSelectAll(sel)) + if (IsSelectAll()) model_->on_paste_replacing_all(); ReplaceSel(text.c_str(), true); } @@ -2047,7 +2053,7 @@ void AutocompleteEditView::PlaceCaretAt(std::wstring::size_type pos) { SetSelection(static_cast<LONG>(pos), static_cast<LONG>(pos)); } -bool AutocompleteEditView::IsSelectAll(const CHARRANGE& sel) const { +bool AutocompleteEditView::IsSelectAllForRange(const CHARRANGE& sel) const { const int text_length = GetTextLength(); return ((sel.cpMin == 0) && (sel.cpMax >= text_length)) || ((sel.cpMax == 0) && (sel.cpMin >= text_length)); @@ -2353,7 +2359,7 @@ void AutocompleteEditView::StartDragIfNecessary(const CPoint& point) { } const std::wstring start_text(GetText()); - if (IsSelectAll(sel)) { + if (IsSelectAllForRange(sel)) { // All the text is selected, export as URL. GURL url; std::wstring title; diff --git a/chrome/browser/autocomplete/autocomplete_edit.h b/chrome/browser/autocomplete/autocomplete_edit.h index 07324701..fc6398d 100644 --- a/chrome/browser/autocomplete/autocomplete_edit.h +++ b/chrome/browser/autocomplete/autocomplete_edit.h @@ -517,6 +517,9 @@ class AutocompleteEditView // Sets the window text and the caret position. void SetWindowTextAndCaretPos(const std::wstring& text, size_t caret_pos); + // Returns true if all text is selected. + bool IsSelectAll(); + // Selects all the text in the edit. Use this in place of SetSelAll() to // avoid selecting the "phantom newline" at the end of the edit. void SelectAll(bool reversed); @@ -724,7 +727,7 @@ class AutocompleteEditView // Returns true if |sel| represents a forward or backward selection of all the // text. - bool IsSelectAll(const CHARRANGE& sel) const; + bool IsSelectAllForRange(const CHARRANGE& sel) const; // Given an X coordinate in client coordinates, returns that coordinate // clipped to be within the horizontal bounds of the visible text. |