Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(611)

Side by Side Diff: chrome/browser/autocomplete/autocomplete_popup_model.cc

Issue 6340012: Fix a DCHECK failure in AutocompleteEditModel::OnPopupDataChanged() (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Wrap long lines. Created 9 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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 #include "chrome/browser/autocomplete/autocomplete_popup_model.h" 5 #include "chrome/browser/autocomplete/autocomplete_popup_model.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 8
9 #include "unicode/ubidi.h" 9 #include "unicode/ubidi.h"
10 10
(...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after
115 match.is_history_what_you_typed_match; 115 match.is_history_what_you_typed_match;
116 } 116 }
117 117
118 if (line == selected_line_) 118 if (line == selected_line_)
119 return; // Nothing else to do. 119 return; // Nothing else to do.
120 120
121 // We need to update |selected_line_| before calling OnPopupDataChanged(), so 121 // We need to update |selected_line_| before calling OnPopupDataChanged(), so
122 // that when the edit notifies its controller that something has changed, the 122 // that when the edit notifies its controller that something has changed, the
123 // controller can get the correct updated data. 123 // controller can get the correct updated data.
124 // 124 //
125 // NOTE: We should never reach here with no selected line; the same code that 125 // |selected_line_| could be kNoMatch only when the previously selected line
126 // opened the popup and made it possible to get here should have also set a 126 // has just been deleted. In this case, the |edit_model_| has already been
127 // selected line. 127 // reverted to the default match, so we need to use the default match for
128 CHECK(selected_line_ != kNoMatch); 128 // |current_destination|, to make sure |edit_model_| can record it properly.
129 GURL current_destination(result.match_at(selected_line_).destination_url); 129 // This step is necessary because the default match may have been changed if
130 view_->InvalidateLine(selected_line_); 130 // the deleted item was the default match.
131 GURL current_destination;
132 if (selected_line_ != kNoMatch) {
133 current_destination = result.match_at(selected_line_).destination_url;
134 view_->InvalidateLine(selected_line_);
135 } else {
136 // We must have a default match if we get here.
137 CHECK(result.default_match() != result.end());
138 current_destination = result.default_match()->destination_url;
139 }
131 selected_line_ = line; 140 selected_line_ = line;
132 view_->InvalidateLine(selected_line_); 141 view_->InvalidateLine(selected_line_);
133 142
134 // Update the edit with the new data for this match. 143 // Update the edit with the new data for this match.
135 // TODO(pkasting): If |selected_line_| moves to the controller, this can be 144 // TODO(pkasting): If |selected_line_| moves to the controller, this can be
136 // eliminated and just become a call to the observer on the edit. 145 // eliminated and just become a call to the observer on the edit.
137 std::wstring keyword; 146 std::wstring keyword;
138 const bool is_keyword_hint = GetKeywordForMatch(match, &keyword); 147 const bool is_keyword_hint = GetKeywordForMatch(match, &keyword);
139 if (reset_to_default) { 148 if (reset_to_default) {
140 std::wstring inline_autocomplete_text; 149 std::wstring inline_autocomplete_text;
(...skipping 139 matching lines...) Expand 10 before | Expand all | Expand 10 after
280 // Cancel the query so the matches don't change on the user. 289 // Cancel the query so the matches don't change on the user.
281 controller_->Stop(false); 290 controller_->Stop(false);
282 291
283 const AutocompleteMatch& match = 292 const AutocompleteMatch& match =
284 controller_->result().match_at(selected_line_); 293 controller_->result().match_at(selected_line_);
285 if (match.deletable) { 294 if (match.deletable) {
286 const size_t selected_line = selected_line_; 295 const size_t selected_line = selected_line_;
287 controller_->DeleteMatch(match); // This may synchronously notify us that 296 controller_->DeleteMatch(match); // This may synchronously notify us that
288 // the results have changed. 297 // the results have changed.
289 const AutocompleteResult& result = controller_->result(); 298 const AutocompleteResult& result = controller_->result();
290 if (!result.empty()) { 299 if (!result.empty()) {
Peter Kasting 2011/01/24 23:25:52 If I'm not mistaken, we can change this conditiona
James Su 2011/01/25 02:24:55 It has an issue for the deleting default match cas
Peter Kasting 2011/01/25 02:36:20 But your code has an opposite problem: If we don't
James Su 2011/01/25 02:51:51 Isn't that guaranteed by above if (match.deletable
Peter Kasting 2011/01/25 04:23:20 Why don't we do this: Add a DCHECK(updated_latest_
James Su 2011/01/25 05:30:11 I just checked the source code, and yes it's proba
300 // Set |selected_line_| to kNoMatch to forcely select the line, even if
Peter Kasting 2011/01/24 23:25:52 I think if we change the conditional as I note abo
James Su 2011/01/25 02:24:55 See above.
Peter Kasting 2011/01/25 02:36:20 OK, but I still think this can be done more cleanl
James Su 2011/01/25 02:51:51 Ok I'll do it. It's actually my original approach.
301 // the value is not changed at all.
302 selected_line_ = kNoMatch;
291 // Move the selection to the next choice after the deleted one. 303 // Move the selection to the next choice after the deleted one.
292 // SetSelectedLine() will clamp to take care of the case where we deleted 304 // SetSelectedLine() will clamp to take care of the case where we deleted
293 // the last item. 305 // the last item.
294 // TODO(pkasting): Eventually the controller should take care of this 306 // TODO(pkasting): Eventually the controller should take care of this
295 // before notifying us, reducing flicker. At that point the check for 307 // before notifying us, reducing flicker. At that point the check for
296 // deletability can move there too. 308 // deletability can move there too.
297 SetSelectedLine(selected_line, false); 309 SetSelectedLine(selected_line, false);
298 } 310 }
299 } 311 }
300 } 312 }
301 313
302 void AutocompletePopupModel::Observe(NotificationType type, 314 void AutocompletePopupModel::Observe(NotificationType type,
303 const NotificationSource& source, 315 const NotificationSource& source,
304 const NotificationDetails& details) { 316 const NotificationDetails& details) {
305 DCHECK_EQ(NotificationType::AUTOCOMPLETE_CONTROLLER_RESULT_UPDATED, 317 DCHECK_EQ(NotificationType::AUTOCOMPLETE_CONTROLLER_RESULT_UPDATED,
306 type.value); 318 type.value);
307 319
308 const AutocompleteResult* result = 320 const AutocompleteResult* result =
309 Details<const AutocompleteResult>(details).ptr(); 321 Details<const AutocompleteResult>(details).ptr();
310 selected_line_ = result->default_match() == result->end() ? 322 selected_line_ = result->default_match() == result->end() ?
311 kNoMatch : static_cast<size_t>(result->default_match() - result->begin()); 323 kNoMatch : static_cast<size_t>(result->default_match() - result->begin());
312 // There had better not be a nonempty result set with no default match. 324 // There had better not be a nonempty result set with no default match.
313 CHECK((selected_line_ != kNoMatch) || result->empty()); 325 CHECK((selected_line_ != kNoMatch) || result->empty());
326 // We need to clear |manually_selected_match_|, as |selected_line_| has been
327 // reverted to the default match.
Peter Kasting 2011/01/24 23:25:52 Nit: I don't think this comment is necessary; it's
James Su 2011/01/25 02:24:55 Done.
328 manually_selected_match_.Clear();
314 // If we're going to trim the window size to no longer include the hovered 329 // If we're going to trim the window size to no longer include the hovered
315 // line, turn hover off. Practically, this shouldn't happen, but it 330 // line, turn hover off. Practically, this shouldn't happen, but it
316 // doesn't hurt to be defensive. 331 // doesn't hurt to be defensive.
317 if ((hovered_line_ != kNoMatch) && (result->size() <= hovered_line_)) 332 if ((hovered_line_ != kNoMatch) && (result->size() <= hovered_line_))
318 SetHoveredLine(kNoMatch); 333 SetHoveredLine(kNoMatch);
319 334
320 view_->UpdatePopupAppearance(); 335 view_->UpdatePopupAppearance();
321 edit_model_->PopupBoundsChangedTo(view_->GetTargetBounds()); 336 edit_model_->PopupBoundsChangedTo(view_->GetTargetBounds());
322 } 337 }
323 338
324 const SkBitmap* AutocompletePopupModel::GetSpecialIconForMatch( 339 const SkBitmap* AutocompletePopupModel::GetSpecialIconForMatch(
325 const AutocompleteMatch& match) const { 340 const AutocompleteMatch& match) const {
326 if (!match.template_url || !match.template_url->IsExtensionKeyword()) 341 if (!match.template_url || !match.template_url->IsExtensionKeyword())
327 return NULL; 342 return NULL;
328 343
329 return &profile_->GetExtensionService()->GetOmniboxPopupIcon( 344 return &profile_->GetExtensionService()->GetOmniboxPopupIcon(
330 match.template_url->GetExtensionId()); 345 match.template_url->GetExtensionId());
331 } 346 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698