OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 // This file defines helper functions shared by the various implementations | 5 // This file defines helper functions shared by the various implementations |
6 // of OmniboxView. | 6 // of OmniboxView. |
7 | 7 |
8 #include "components/omnibox/browser/omnibox_view.h" | 8 #include "components/omnibox/browser/omnibox_view.h" |
9 | 9 |
10 #include <utility> | 10 #include <utility> |
(...skipping 148 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
159 | 159 |
160 bool OmniboxView::IsIndicatingQueryRefinement() const { | 160 bool OmniboxView::IsIndicatingQueryRefinement() const { |
161 // The default implementation always returns false. Mobile ports can override | 161 // The default implementation always returns false. Mobile ports can override |
162 // this method and implement as needed. | 162 // this method and implement as needed. |
163 return false; | 163 return false; |
164 } | 164 } |
165 | 165 |
166 void OmniboxView::OnMatchOpened(AutocompleteMatch::Type match_type) { | 166 void OmniboxView::OnMatchOpened(AutocompleteMatch::Type match_type) { |
167 } | 167 } |
168 | 168 |
| 169 void OmniboxView::GetState(State* state) { |
| 170 state->text = GetText(); |
| 171 state->keyword = model()->keyword(); |
| 172 state->is_keyword_selected = model()->is_keyword_selected(); |
| 173 GetSelectionBounds(&state->sel_start, &state->sel_end); |
| 174 } |
| 175 |
| 176 OmniboxViewStateChanges OmniboxView::GetStateChanges(const State& before, |
| 177 const State& after) { |
| 178 OmniboxViewStateChanges state_changes; |
| 179 state_changes.old_text = &before.text; |
| 180 state_changes.new_text = &after.text; |
| 181 state_changes.new_sel_start = after.sel_start; |
| 182 state_changes.new_sel_end = after.sel_end; |
| 183 const bool old_sel_empty = before.sel_start == before.sel_end; |
| 184 const bool new_sel_empty = after.sel_start == after.sel_end; |
| 185 const bool sel_same_ignoring_direction = |
| 186 std::min(before.sel_start, before.sel_end) == |
| 187 std::min(after.sel_start, after.sel_end) && |
| 188 std::max(before.sel_start, before.sel_end) == |
| 189 std::max(after.sel_start, after.sel_end); |
| 190 state_changes.selection_differs = |
| 191 (!old_sel_empty || !new_sel_empty) && !sel_same_ignoring_direction; |
| 192 state_changes.text_differs = before.text != after.text; |
| 193 state_changes.keyword_differs = |
| 194 (after.is_keyword_selected != before.is_keyword_selected) || |
| 195 (after.is_keyword_selected && before.is_keyword_selected && |
| 196 after.keyword != before.keyword); |
| 197 |
| 198 // When the user has deleted text, we don't allow inline autocomplete. Make |
| 199 // sure to not flag cases like selecting part of the text and then pasting |
| 200 // (or typing) the prefix of that selection. (We detect these by making |
| 201 // sure the caret, which should be after any insertion, hasn't moved |
| 202 // forward of the old selection start.) |
| 203 state_changes.just_deleted_text = |
| 204 (before.text.length() > after.text.length()) && |
| 205 (after.sel_start <= std::min(before.sel_start, before.sel_end)); |
| 206 |
| 207 return state_changes; |
| 208 } |
| 209 |
169 OmniboxView::OmniboxView(OmniboxEditController* controller, | 210 OmniboxView::OmniboxView(OmniboxEditController* controller, |
170 std::unique_ptr<OmniboxClient> client) | 211 std::unique_ptr<OmniboxClient> client) |
171 : controller_(controller) { | 212 : controller_(controller) { |
172 // |client| can be null in tests. | 213 // |client| can be null in tests. |
173 if (client) { | 214 if (client) { |
174 model_.reset(new OmniboxEditModel(this, controller, std::move(client))); | 215 model_.reset(new OmniboxEditModel(this, controller, std::move(client))); |
175 } | 216 } |
176 } | 217 } |
177 | 218 |
178 void OmniboxView::TextChanged() { | 219 void OmniboxView::TextChanged() { |
179 EmphasizeURLComponents(); | 220 EmphasizeURLComponents(); |
180 if (model_.get()) | 221 if (model_.get()) |
181 model_->OnChanged(); | 222 model_->OnChanged(); |
182 } | 223 } |
OLD | NEW |