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

Side by Side Diff: chrome/browser/history_view.cc

Issue 13236: History View CRect to gfx Cleanup (Closed) Base URL: http://src.chromium.org/svn/trunk/src/
Patch Set: '' Created 12 years 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/history_view.h" 5 #include "chrome/browser/history_view.h"
6 6
7 #include "base/string_util.h" 7 #include "base/string_util.h"
8 #include "base/time_format.h" 8 #include "base/time_format.h"
9 #include "base/word_iterator.h" 9 #include "base/word_iterator.h"
10 #include "chrome/browser/browsing_data_remover.h" 10 #include "chrome/browser/browsing_data_remover.h"
(...skipping 257 matching lines...) Expand 10 before | Expand all | Expand 10 after
268 static const int kThumbnailHeight = kSearchResultsHeight - kEntryPadding * 2; 268 static const int kThumbnailHeight = kSearchResultsHeight - kEntryPadding * 2;
269 269
270 // The width of the thumbnail images. 270 // The width of the thumbnail images.
271 static const int kThumbnailWidth = static_cast<int>(1.44 * kThumbnailHeight); 271 static const int kThumbnailWidth = static_cast<int>(1.44 * kThumbnailHeight);
272 272
273 // The maximum width of a snippet - we want to constrain this to make 273 // The maximum width of a snippet - we want to constrain this to make
274 // snippets easier to read (like Google search results). 274 // snippets easier to read (like Google search results).
275 static const int kMaxSnippetWidth = 500; 275 static const int kMaxSnippetWidth = 500;
276 276
277 // Returns the bounds of the thumbnail. 277 // Returns the bounds of the thumbnail.
278 void GetThumbnailBounds(CRect* rect); 278 void GetThumbnailBounds(gfx::Rect* rect);
279 279
280 // Convert a GURL into a displayable string. 280 // Convert a GURL into a displayable string.
281 std::wstring DisplayURL(const GURL& url); 281 std::wstring DisplayURL(const GURL& url);
282 282
283 virtual void Paint(ChromeCanvas* canvas); 283 virtual void Paint(ChromeCanvas* canvas);
284 284
285 // Notification that the star was changed. 285 // Notification that the star was changed.
286 virtual void StarStateChanged(bool state); 286 virtual void StarStateChanged(bool state);
287 287
288 // Notification that the link was clicked. 288 // Notification that the link was clicked.
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
337 time_label_->SetHorizontalAlignment(views::Label::ALIGN_LEFT); 337 time_label_->SetHorizontalAlignment(views::Label::ALIGN_LEFT);
338 AddChildView(time_label_); 338 AddChildView(time_label_);
339 339
340 snippet_label_ = new SnippetRenderer(); 340 snippet_label_ = new SnippetRenderer();
341 AddChildView(snippet_label_); 341 AddChildView(snippet_label_);
342 } 342 }
343 343
344 HistoryItemRenderer::~HistoryItemRenderer() { 344 HistoryItemRenderer::~HistoryItemRenderer() {
345 } 345 }
346 346
347 void HistoryItemRenderer::GetThumbnailBounds(CRect* rect) { 347 void HistoryItemRenderer::GetThumbnailBounds(gfx::Rect* rect) {
348 DCHECK(rect); 348 DCHECK(rect);
349 rect->right = width() - kEntryPadding; 349 rect->set_x(width() - kEntryPadding - kThumbnailWidth);
350 rect->left = rect->right - kThumbnailWidth; 350 rect->set_y(kEntryPadding);
351 rect->top = kEntryPadding; 351 rect->set_width(kThumbnailWidth);
352 rect->bottom = rect->top + kThumbnailHeight; 352 rect->set_height(kThumbnailHeight);
353 } 353 }
354 354
355 std::wstring HistoryItemRenderer::DisplayURL(const GURL& url) { 355 std::wstring HistoryItemRenderer::DisplayURL(const GURL& url) {
356 std::string url_str = url.spec(); 356 std::string url_str = url.spec();
357 // Hide the "http://" prefix like web search does. 357 // Hide the "http://" prefix like web search does.
358 if (url_str.find("http://") == 0) 358 if (url_str.find("http://") == 0)
359 url_str.erase(0, strlen("http://")); 359 url_str.erase(0, strlen("http://"));
360 return UTF8ToWide(url_str); 360 return UTF8ToWide(url_str);
361 } 361 }
362 362
363 void HistoryItemRenderer::Paint(ChromeCanvas* canvas) { 363 void HistoryItemRenderer::Paint(ChromeCanvas* canvas) {
364 views::View::Paint(canvas); 364 views::View::Paint(canvas);
365 365
366 // Draw thumbnail or placeholder. 366 // Draw thumbnail or placeholder.
367 if (show_full_) { 367 if (show_full_) {
368 SkBitmap* thumbnail = model_->GetThumbnail(model_index_); 368 SkBitmap* thumbnail = model_->GetThumbnail(model_index_);
369 CRect thumbnail_rect; 369 gfx::Rect thumbnail_rect;
370 GetThumbnailBounds(&thumbnail_rect); // Includes border 370 GetThumbnailBounds(&thumbnail_rect); // Includes border
371 371
372 // If the UI layout is right-to-left, we must mirror the bounds so that we 372 // If the UI layout is right-to-left, we must mirror the bounds so that we
373 // render the bitmap in the correct position. 373 // render the bitmap in the correct position.
374 gfx::Rect mirrored_rect(thumbnail_rect); 374 thumbnail_rect.set_x(MirroredLeftPointForRect(thumbnail_rect));
375 thumbnail_rect.MoveToX(MirroredLeftPointForRect(mirrored_rect));
376 375
377 if (thumbnail) { 376 if (thumbnail) {
378 // This will create a MipMap for the bitmap if one doesn't exist already 377 // This will create a MipMap for the bitmap if one doesn't exist already
379 // (it's a NOP if a MipMap already exists). This will give much smoother 378 // (it's a NOP if a MipMap already exists). This will give much smoother
380 // results for the scaled-down thumbnails. 379 // results for the scaled-down thumbnails.
381 thumbnail->buildMipMap(false); 380 thumbnail->buildMipMap(false);
382 381
383 canvas->DrawBitmapInt( 382 canvas->DrawBitmapInt(
384 *thumbnail, 383 *thumbnail,
385 0, 0, thumbnail->width(), thumbnail->height(), 384 0, 0, thumbnail->width(), thumbnail->height(),
386 thumbnail_rect.left, thumbnail_rect.top, 385 thumbnail_rect.x(), thumbnail_rect.y(),
387 thumbnail_rect.Width(), thumbnail_rect.Height(), 386 thumbnail_rect.width(), thumbnail_rect.height(),
388 true); 387 true);
389 } else { 388 } else {
390 canvas->FillRectInt(SK_ColorWHITE, 389 canvas->FillRectInt(SK_ColorWHITE,
391 thumbnail_rect.left, thumbnail_rect.top, 390 thumbnail_rect.x(), thumbnail_rect.y(),
392 thumbnail_rect.Width(), thumbnail_rect.Height()); 391 thumbnail_rect.width(), thumbnail_rect.height());
393 } 392 }
394 canvas->DrawRectInt(SkColorSetRGB(153, 153, 191), 393 canvas->DrawRectInt(SkColorSetRGB(153, 153, 191),
395 thumbnail_rect.left, thumbnail_rect.top, 394 thumbnail_rect.x(), thumbnail_rect.y(),
396 thumbnail_rect.Width(), thumbnail_rect.Height()); 395 thumbnail_rect.width(), thumbnail_rect.height());
397 } 396 }
398 397
399 // Draw the favicon. 398 // Draw the favicon.
400 SkBitmap* favicon = model_->GetFavicon(model_index_); 399 SkBitmap* favicon = model_->GetFavicon(model_index_);
401 if (favicon) { 400 if (favicon) {
402 // WARNING: if you change these values, update the code that determines 401 // WARNING: if you change these values, update the code that determines
403 // whether we should allow a drag (GetDragRegion). 402 // whether we should allow a drag (GetDragRegion).
404 403
405 // We need to tweak the favicon position if the UI layout is RTL. 404 // We need to tweak the favicon position if the UI layout is RTL.
406 gfx::Rect favicon_bounds; 405 gfx::Rect favicon_bounds;
407 favicon_bounds.set_x(title_link_->x() - kIconPadding - kFavIconSize); 406 favicon_bounds.set_x(title_link_->x() - kIconPadding - kFavIconSize);
408 favicon_bounds.set_y(kEntryPadding); 407 favicon_bounds.set_y(kEntryPadding);
409 favicon_bounds.set_width(favicon->width()); 408 favicon_bounds.set_width(favicon->width());
410 favicon_bounds.set_height(favicon->height()); 409 favicon_bounds.set_height(favicon->height());
411 favicon_bounds.set_x(MirroredLeftPointForRect(favicon_bounds)); 410 favicon_bounds.set_x(MirroredLeftPointForRect(favicon_bounds));
412 411
413 // Drawing the bitmap using the possibly adjusted bounds. 412 // Drawing the bitmap using the possibly adjusted bounds.
414 canvas->DrawBitmapInt(*favicon, favicon_bounds.x(), favicon_bounds.y()); 413 canvas->DrawBitmapInt(*favicon, favicon_bounds.x(), favicon_bounds.y());
415 } 414 }
416 415
417 // The remainder of painting is handled by drawing our children, which 416 // The remainder of painting is handled by drawing our children, which
418 // is managed by the View class for us. 417 // is managed by the View class for us.
419 } 418 }
420 419
421 void HistoryItemRenderer::Layout() { 420 void HistoryItemRenderer::Layout() {
422 // Figure out the maximum x-position of any text. 421 // Figure out the maximum x-position of any text.
423 CRect thumbnail_rect; 422 gfx::Rect thumbnail_rect;
424 int max_x; 423 int max_x;
425 if (show_full_) { 424 if (show_full_) {
426 GetThumbnailBounds(&thumbnail_rect); 425 GetThumbnailBounds(&thumbnail_rect);
427 max_x = thumbnail_rect.left - kEntryPadding; 426 max_x = thumbnail_rect.x() - kEntryPadding;
428 } else { 427 } else {
429 max_x = width() - kEntryPadding; 428 max_x = width() - kEntryPadding;
430 } 429 }
431 430
432 // Calculate the ideal positions of some items. If possible, we 431 // Calculate the ideal positions of some items. If possible, we
433 // want the title to line up with kPageTitleOffset (and we would lay 432 // want the title to line up with kPageTitleOffset (and we would lay
434 // out the star and the favicon to the left of that), but in cases 433 // out the star and the favicon to the left of that), but in cases
435 // where font or language choices cause the time label to be 434 // where font or language choices cause the time label to be
436 // horizontally large, we need to push everything to the right. 435 // horizontally large, we need to push everything to the right.
437 // 436 //
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after
510 if (show_full_) { 509 if (show_full_) {
511 const Snippet& snippet = model_->GetSnippet(model_index_); 510 const Snippet& snippet = model_->GetSnippet(model_index_);
512 if (snippet.text().empty()) { 511 if (snippet.text().empty()) {
513 snippet_label_->SetSnippet(Snippet()); // Bug 843469 will fix this. 512 snippet_label_->SetSnippet(Snippet()); // Bug 843469 will fix this.
514 } else { 513 } else {
515 snippet_label_->SetSnippet(snippet); 514 snippet_label_->SetSnippet(snippet);
516 } 515 }
517 snippet_label_->SetBounds(title_x, 516 snippet_label_->SetBounds(title_x,
518 kEntryPadding + snippet_label_->GetLineHeight(), 517 kEntryPadding + snippet_label_->GetLineHeight(),
519 std::min( 518 std::min(
520 static_cast<int>(thumbnail_rect.left - 519 static_cast<int>(thumbnail_rect.x() -
521 title_x), 520 title_x),
522 kMaxSnippetWidth) - 521 kMaxSnippetWidth) -
523 kEntryPadding * 2, 522 kEntryPadding * 2,
524 snippet_label_->GetLineHeight() * 2); 523 snippet_label_->GetLineHeight() * 2);
525 } 524 }
526 } 525 }
527 526
528 int HistoryItemRenderer::GetDragOperations(int x, int y) { 527 int HistoryItemRenderer::GetDragOperations(int x, int y) {
529 if (GetDragRegion(x, y) != NONE) 528 if (GetDragRegion(x, y) != NONE)
530 return DragDropTypes::DRAG_COPY | DragDropTypes::DRAG_LINK; 529 return DragDropTypes::DRAG_COPY | DragDropTypes::DRAG_LINK;
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after
613 favicon_bounds.set_width(favicon->width()); 612 favicon_bounds.set_width(favicon->width());
614 favicon_bounds.set_height(favicon->height()); 613 favicon_bounds.set_height(favicon->height());
615 favicon_bounds.set_x(MirroredLeftPointForRect(favicon_bounds)); 614 favicon_bounds.set_x(MirroredLeftPointForRect(favicon_bounds));
616 if (favicon_bounds.Contains(x, y)) { 615 if (favicon_bounds.Contains(x, y)) {
617 return FAV_ICON; 616 return FAV_ICON;
618 } 617 }
619 } 618 }
620 619
621 // Is it over the thumbnail? 620 // Is it over the thumbnail?
622 if (show_full_ && model_->GetThumbnail(model_index_)) { 621 if (show_full_ && model_->GetThumbnail(model_index_)) {
623 CRect thumbnail_loc; 622 gfx::Rect thumbnail_loc;
624 GetThumbnailBounds(&thumbnail_loc); 623 GetThumbnailBounds(&thumbnail_loc);
625 624
626 // If the UI layout is right-to-left, we mirror the thumbnail bounds before 625 // If the UI layout is right-to-left, we mirror the thumbnail bounds before
627 // we check whether or not it contains the point in question. 626 // we check whether or not it contains the point in question.
628 gfx::Rect mirrored_loc(thumbnail_loc); 627 thumbnail_loc.set_x(MirroredLeftPointForRect(thumbnail_loc));
629 thumbnail_loc.MoveToX(MirroredLeftPointForRect(mirrored_loc)); 628 if (thumbnail_loc.Contains(x, y))
630 if (gfx::Rect(thumbnail_loc).Contains(x, y))
631 return THUMBNAIL; 629 return THUMBNAIL;
632 } 630 }
633 631
634 return NONE; 632 return NONE;
635 } 633 }
636 634
637 HistoryView::HistoryView(SearchableUIContainer* container, 635 HistoryView::HistoryView(SearchableUIContainer* container,
638 BaseHistoryModel* model, 636 BaseHistoryModel* model,
639 PageNavigator* navigator) 637 PageNavigator* navigator)
640 : container_(container), 638 : container_(container),
(...skipping 667 matching lines...) Expand 10 before | Expand all | Expand 10 after
1308 // NOTE: the height here is too big, it should be just big enough to show 1306 // NOTE: the height here is too big, it should be just big enough to show
1309 // the link. Additionally this should be baseline aligned with the date. I'm 1307 // the link. Additionally this should be baseline aligned with the date. I'm
1310 // not doing that now as a redesign of HistoryView is in the works. 1308 // not doing that now as a redesign of HistoryView is in the works.
1311 const int delete_width = GetDeleteControlWidth(); 1309 const int delete_width = GetDeleteControlWidth();
1312 const int delete_x = width() - kRightMargin - delete_width; 1310 const int delete_x = width() - kRightMargin - delete_width;
1313 return gfx::Rect(delete_x, 1311 return gfx::Rect(delete_x,
1314 base_y + kDeleteControlOffset, 1312 base_y + kDeleteControlOffset,
1315 delete_width, 1313 delete_width,
1316 kBrowseResultsHeight); 1314 kBrowseResultsHeight);
1317 } 1315 }
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