diff options
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. |