Chromium Code Reviews| Index: components/omnibox/browser/omnibox_view.cc |
| diff --git a/components/omnibox/browser/omnibox_view.cc b/components/omnibox/browser/omnibox_view.cc |
| index cc88e37f71a508b48448853bc7f890915e5e3ddc..a50d7dd78117bebffbd6b4d5b6eaf1efa99b7add 100644 |
| --- a/components/omnibox/browser/omnibox_view.cc |
| +++ b/components/omnibox/browser/omnibox_view.cc |
| @@ -166,6 +166,48 @@ bool OmniboxView::IsIndicatingQueryRefinement() const { |
| void OmniboxView::OnMatchOpened(AutocompleteMatch::Type match_type) { |
| } |
| +void OmniboxView::GetTextState(OmniboxView::TextState& state) { |
| + state.text = GetText(); |
| + state.keyword = model()->keyword(); |
| + state.is_keyword_selected = model()->is_keyword_selected(); |
| + GetSelectionBounds(&state.sel_start, &state.sel_end); |
| +} |
| + |
| +OmniboxEditModel::TextStateChange OmniboxView::GetTextStateChange( |
| + const TextState& before, |
| + const TextState& after) { |
| + OmniboxEditModel::TextStateChange state_change; |
| + state_change.old_text = &before.text; |
| + state_change.new_text = &after.text; |
| + state_change.new_sel_start = after.sel_start; |
| + state_change.new_sel_end = after.sel_end; |
| + const bool old_sel_empty = before.sel_start == before.sel_end; |
| + const bool new_sel_empty = after.sel_start == after.sel_end; |
| + const bool sel_same_ignoring_direction = |
| + std::min(before.sel_start, before.sel_end) == |
| + std::min(after.sel_start, after.sel_end) && |
| + std::max(before.sel_start, before.sel_end) == |
| + std::max(after.sel_start, after.sel_end); |
| + state_change.selection_differs = |
| + !((old_sel_empty && new_sel_empty) || sel_same_ignoring_direction); |
|
Peter Kasting
2016/06/04 02:17:18
Nit: Distribute ! through
Tom (Use chromium acct)
2016/06/04 20:39:09
Done.
|
| + state_change.text_differs = before.text != after.text; |
| + state_change.keyword_differs = |
| + (after.is_keyword_selected != before.is_keyword_selected) || |
| + (after.is_keyword_selected && before.is_keyword_selected && |
| + after.keyword != before.keyword); |
| + |
| + // When the user has deleted text, we don't allow inline autocomplete. Make |
| + // sure to not flag cases like selecting part of the text and then pasting |
| + // (or typing) the prefix of that selection. (We detect these by making |
| + // sure the caret, which should be after any insertion, hasn't moved |
| + // forward of the old selection start.) |
| + state_change.just_deleted_text = |
| + (before.text.length() > after.text.length()) && |
| + (before.sel_start <= std::min(before.sel_start, before.sel_end)); |
| + |
| + return state_change; |
| +} |
| + |
| OmniboxView::OmniboxView(OmniboxEditController* controller, |
| std::unique_ptr<OmniboxClient> client) |
| : controller_(controller) { |