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

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

Issue 63085: Attempt to fix crash that I don't fully understand and can't repro :(... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: Created 11 years, 8 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
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2006-2008 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_view_win.h" 5 #include "chrome/browser/autocomplete/autocomplete_popup_view_win.h"
6 6
7 // TODO(deanm): Clean up these includes, not going to fight it now. 7 // TODO(deanm): Clean up these includes, not going to fight it now.
8 #include <atlbase.h> 8 #include <atlbase.h>
9 #include <atlapp.h> 9 #include <atlapp.h>
10 #include <atlcrack.h> 10 #include <atlcrack.h>
(...skipping 327 matching lines...) Expand 10 before | Expand all | Expand 10 after
338 338
339 // When the user has the left button down, update their selection 339 // When the user has the left button down, update their selection
340 // immediately (don't wait for mouseup). 340 // immediately (don't wait for mouseup).
341 if (keys & MK_LBUTTON) 341 if (keys & MK_LBUTTON)
342 model_->SetSelectedLine(new_hovered_line, false); 342 model_->SetSelectedLine(new_hovered_line, false);
343 } 343 }
344 } 344 }
345 345
346 void AutocompletePopupViewWin::OnPaint(HDC other_dc) { 346 void AutocompletePopupViewWin::OnPaint(HDC other_dc) {
347 const AutocompleteResult& result = model_->result(); 347 const AutocompleteResult& result = model_->result();
348 DCHECK(!result.empty()); // Shouldn't be drawing an empty popup. 348 CHECK(!result.empty()); // Shouldn't be drawing an empty popup; any empty
349 // result set should have synchronously closed us.
349 350
350 CPaintDC dc(m_hWnd); 351 CPaintDC dc(m_hWnd);
351 352
352 RECT rc; 353 RECT rc;
353 GetClientRect(&rc); 354 GetClientRect(&rc);
354 mirroring_context_->Initialize(rc.left, rc.right, 355 mirroring_context_->Initialize(rc.left, rc.right,
355 l10n_util::GetTextDirection() == l10n_util::RIGHT_TO_LEFT); 356 l10n_util::GetTextDirection() == l10n_util::RIGHT_TO_LEFT);
356 DrawBorder(rc, dc); 357 DrawBorder(rc, dc);
357 358
358 bool all_descriptions_empty = true; 359 bool all_descriptions_empty = true;
359 for (AutocompleteResult::const_iterator i(result.begin()); i != result.end(); 360 for (AutocompleteResult::const_iterator i(result.begin()); i != result.end();
360 ++i) { 361 ++i) {
361 if (!i->description.empty()) { 362 if (!i->description.empty()) {
362 all_descriptions_empty = false; 363 all_descriptions_empty = false;
363 break; 364 break;
364 } 365 }
365 } 366 }
366 367
367 // Only repaint the invalid lines. 368 // Only repaint the invalid lines.
369 // In rare cases, it seems possible to get line offsets off the end of the
370 // popup. I suspect this can happen when the user invalidates a new line
371 // (e.g. by moving the mouse) and, before the paint request is serviced, hits
372 // a key that causes autocomplete to run, causing the results list to become
373 // shorter (at least initially). So sanitize the line numbers here.
374 const size_t last_valid_line = result.size() - 1;
368 const size_t first_line = PixelToLine(dc.m_ps.rcPaint.top); 375 const size_t first_line = PixelToLine(dc.m_ps.rcPaint.top);
369 const size_t last_line = PixelToLine(dc.m_ps.rcPaint.bottom); 376 if (first_line > last_valid_line)
377 return;
378 const size_t last_line =
379 std::min(PixelToLine(dc.m_ps.rcPaint.bottom), last_valid_line);
380
370 for (size_t i = first_line; i <= last_line; ++i) { 381 for (size_t i = first_line; i <= last_line; ++i) {
371 DrawLineInfo::LineStatus status; 382 DrawLineInfo::LineStatus status;
372 // Selection should take precedence over hover. 383 // Selection should take precedence over hover.
373 if (i == model_->selected_line()) 384 if (i == model_->selected_line())
374 status = DrawLineInfo::SELECTED; 385 status = DrawLineInfo::SELECTED;
375 else if (i == model_->hovered_line()) 386 else if (i == model_->hovered_line())
376 status = DrawLineInfo::HOVERED; 387 status = DrawLineInfo::HOVERED;
377 else 388 else
378 status = DrawLineInfo::NORMAL; 389 status = DrawLineInfo::NORMAL;
379 DrawEntry(dc, rc, i, status, all_descriptions_empty, 390 DrawEntry(dc, rc, i, status, all_descriptions_empty,
(...skipping 276 matching lines...) Expand 10 before | Expand all | Expand 10 after
656 } 667 }
657 668
658 void AutocompletePopupViewWin::DrawStar(HDC dc, int x, int y) const { 669 void AutocompletePopupViewWin::DrawStar(HDC dc, int x, int y) const {
659 ChromeCanvas canvas(star_->width(), star_->height(), false); 670 ChromeCanvas canvas(star_->width(), star_->height(), false);
660 // Make the background completely transparent. 671 // Make the background completely transparent.
661 canvas.drawColor(SK_ColorBLACK, SkPorterDuff::kClear_Mode); 672 canvas.drawColor(SK_ColorBLACK, SkPorterDuff::kClear_Mode);
662 canvas.DrawBitmapInt(*star_, 0, 0); 673 canvas.DrawBitmapInt(*star_, 0, 0);
663 canvas.getTopPlatformDevice().drawToHDC( 674 canvas.getTopPlatformDevice().drawToHDC(
664 dc, mirroring_context_->GetLeft(x, x + star_->width()), y, NULL); 675 dc, mirroring_context_->GetLeft(x, x + star_->width()), y, NULL);
665 } 676 }
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698