Chromium Code Reviews| 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::GetTextState(OmniboxView::TextState& 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 OmniboxEditModel::TextStateChange OmniboxView::GetTextStateChange( | |
| 177 const TextState& before, | |
| 178 const TextState& after) { | |
| 179 OmniboxEditModel::TextStateChange state_change; | |
| 180 state_change.old_text = &before.text; | |
| 181 state_change.new_text = &after.text; | |
| 182 state_change.new_sel_start = after.sel_start; | |
| 183 state_change.new_sel_end = after.sel_end; | |
| 184 const bool old_sel_empty = before.sel_start == before.sel_end; | |
| 185 const bool new_sel_empty = after.sel_start == after.sel_end; | |
| 186 const bool sel_same_ignoring_direction = | |
| 187 std::min(before.sel_start, before.sel_end) == | |
| 188 std::min(after.sel_start, after.sel_end) && | |
| 189 std::max(before.sel_start, before.sel_end) == | |
| 190 std::max(after.sel_start, after.sel_end); | |
| 191 state_change.selection_differs = | |
| 192 !((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.
| |
| 193 state_change.text_differs = before.text != after.text; | |
| 194 state_change.keyword_differs = | |
| 195 (after.is_keyword_selected != before.is_keyword_selected) || | |
| 196 (after.is_keyword_selected && before.is_keyword_selected && | |
| 197 after.keyword != before.keyword); | |
| 198 | |
| 199 // When the user has deleted text, we don't allow inline autocomplete. Make | |
| 200 // sure to not flag cases like selecting part of the text and then pasting | |
| 201 // (or typing) the prefix of that selection. (We detect these by making | |
| 202 // sure the caret, which should be after any insertion, hasn't moved | |
| 203 // forward of the old selection start.) | |
| 204 state_change.just_deleted_text = | |
| 205 (before.text.length() > after.text.length()) && | |
| 206 (before.sel_start <= std::min(before.sel_start, before.sel_end)); | |
| 207 | |
| 208 return state_change; | |
| 209 } | |
| 210 | |
| 169 OmniboxView::OmniboxView(OmniboxEditController* controller, | 211 OmniboxView::OmniboxView(OmniboxEditController* controller, |
| 170 std::unique_ptr<OmniboxClient> client) | 212 std::unique_ptr<OmniboxClient> client) |
| 171 : controller_(controller) { | 213 : controller_(controller) { |
| 172 // |client| can be null in tests. | 214 // |client| can be null in tests. |
| 173 if (client) { | 215 if (client) { |
| 174 model_.reset(new OmniboxEditModel(this, controller, std::move(client))); | 216 model_.reset(new OmniboxEditModel(this, controller, std::move(client))); |
| 175 } | 217 } |
| 176 } | 218 } |
| 177 | 219 |
| 178 void OmniboxView::TextChanged() { | 220 void OmniboxView::TextChanged() { |
| 179 EmphasizeURLComponents(); | 221 EmphasizeURLComponents(); |
| 180 if (model_.get()) | 222 if (model_.get()) |
| 181 model_->OnChanged(); | 223 model_->OnChanged(); |
| 182 } | 224 } |
| OLD | NEW |