| OLD | NEW |
| 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 417 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 428 // where font or language choices cause the time label to be | 428 // where font or language choices cause the time label to be |
| 429 // horizontally large, we need to push everything to the right. | 429 // horizontally large, we need to push everything to the right. |
| 430 // | 430 // |
| 431 // If you fiddle with the calculations below, you may need to adjust | 431 // If you fiddle with the calculations below, you may need to adjust |
| 432 // the favicon painting in Paint() (and in GetDragRegion by extension). | 432 // the favicon painting in Paint() (and in GetDragRegion by extension). |
| 433 | 433 |
| 434 // First we calculate the ideal position of the title. | 434 // First we calculate the ideal position of the title. |
| 435 int title_x = kPageTitleOffset; | 435 int title_x = kPageTitleOffset; |
| 436 | 436 |
| 437 // We calculate the size of the star. | 437 // We calculate the size of the star. |
| 438 CSize star_size; | 438 gfx::Size star_size = star_toggle_->GetPreferredSize(); |
| 439 star_toggle_->GetPreferredSize(&star_size); | |
| 440 | 439 |
| 441 // Measure and lay out the time label, and potentially move | 440 // Measure and lay out the time label, and potentially move |
| 442 // our title to suit. | 441 // our title to suit. |
| 443 CSize time_size; | |
| 444 Time visit_time = model_->GetVisitTime(model_index_); | 442 Time visit_time = model_->GetVisitTime(model_index_); |
| 445 int time_x = kTimeOffset; | 443 int time_x = kTimeOffset; |
| 446 if (visit_time.is_null()) { | 444 if (visit_time.is_null()) { |
| 447 // We will get null times if the page has never been visited, for example, | 445 // We will get null times if the page has never been visited, for example, |
| 448 // bookmarks after you clear history. | 446 // bookmarks after you clear history. |
| 449 time_label_->SetText(std::wstring()); | 447 time_label_->SetText(std::wstring()); |
| 450 } else if (show_full_) { | 448 } else if (show_full_) { |
| 451 time_x = 0; | 449 time_x = 0; |
| 452 time_label_->SetText(base::TimeFormatShortDate(visit_time)); | 450 time_label_->SetText(base::TimeFormatShortDate(visit_time)); |
| 453 } else { | 451 } else { |
| 454 time_label_->SetText(base::TimeFormatTimeOfDay(visit_time)); | 452 time_label_->SetText(base::TimeFormatTimeOfDay(visit_time)); |
| 455 } | 453 } |
| 456 time_label_->GetPreferredSize(&time_size); | 454 gfx::Size time_size = time_label_->GetPreferredSize(); |
| 457 | 455 |
| 458 time_label_->SetBounds(time_x, kEntryPadding, | 456 time_label_->SetBounds(time_x, kEntryPadding, |
| 459 time_size.cx, time_size.cy); | 457 time_size.width(), time_size.height()); |
| 460 | 458 |
| 461 // Calculate the position of the favicon. | 459 // Calculate the position of the favicon. |
| 462 int favicon_x = title_x - kFavIconSize - kIconPadding; | 460 int favicon_x = title_x - kFavIconSize - kIconPadding; |
| 463 | 461 |
| 464 // Now we look to see if the favicon overlaps the time label, | 462 // Now we look to see if the favicon overlaps the time label, |
| 465 // and if so, we push the title to the right. If we're not | 463 // and if so, we push the title to the right. If we're not |
| 466 // showing the time label, then ignore this step. | 464 // showing the time label, then ignore this step. |
| 467 int overlap = favicon_x - (time_x + time_size.cx + kIconPadding); | 465 int overlap = favicon_x - (time_x + time_size.width() + kIconPadding); |
| 468 if (overlap < 0) { | 466 if (overlap < 0) { |
| 469 title_x -= overlap; | 467 title_x -= overlap; |
| 470 } | 468 } |
| 471 | 469 |
| 472 // Populate and measure the title label. | 470 // Populate and measure the title label. |
| 473 const std::wstring& title = model_->GetTitle(model_index_); | 471 const std::wstring& title = model_->GetTitle(model_index_); |
| 474 if (!title.empty()) | 472 if (!title.empty()) |
| 475 title_link_->SetText(title); | 473 title_link_->SetText(title); |
| 476 else | 474 else |
| 477 title_link_->SetText(l10n_util::GetString(IDS_HISTORY_UNTITLED_TITLE)); | 475 title_link_->SetText(l10n_util::GetString(IDS_HISTORY_UNTITLED_TITLE)); |
| 478 CSize title_size; | 476 gfx::Size title_size = title_link_->GetPreferredSize(); |
| 479 title_link_->GetPreferredSize(&title_size); | |
| 480 | 477 |
| 481 // Lay out the title label. | 478 // Lay out the title label. |
| 482 int max_title_x; | 479 int max_title_x; |
| 483 | 480 |
| 484 max_title_x = std::max(0, max_x - title_x); | 481 max_title_x = std::max(0, max_x - title_x); |
| 485 | 482 |
| 486 if (title_size.cx + kEntryPadding > max_title_x) { | 483 if (title_size.width() + kEntryPadding > max_title_x) { |
| 487 // We need to shrink the title to make everything fit. | 484 // We need to shrink the title to make everything fit. |
| 488 title_size.cx = max_title_x - kEntryPadding; | 485 title_size.set_width(max_title_x - kEntryPadding); |
| 489 } | 486 } |
| 490 title_link_->SetBounds(title_x, kEntryPadding, | 487 title_link_->SetBounds(title_x, kEntryPadding, |
| 491 title_size.cx, title_size.cy); | 488 title_size.width(), title_size.height()); |
| 492 | 489 |
| 493 // Lay out the star. | 490 // Lay out the star. |
| 494 if (model_->IsStarred(model_index_)) { | 491 if (model_->IsStarred(model_index_)) { |
| 495 star_toggle_->SetBounds(title_x + title_size.cx + kIconPadding, | 492 star_toggle_->SetBounds(title_x + title_size.width() + kIconPadding, |
| 496 kEntryPadding, star_size.cx, star_size.cy); | 493 kEntryPadding, star_size.width(), |
| 494 star_size.height()); |
| 497 star_toggle_->SetState(true); | 495 star_toggle_->SetState(true); |
| 498 star_toggle_->SetVisible(true); | 496 star_toggle_->SetVisible(true); |
| 499 } else { | 497 } else { |
| 500 star_toggle_->SetVisible(false); | 498 star_toggle_->SetVisible(false); |
| 501 } | 499 } |
| 502 | 500 |
| 503 // Lay out the snippet label. | 501 // Lay out the snippet label. |
| 504 snippet_label_->SetVisible(show_full_); | 502 snippet_label_->SetVisible(show_full_); |
| 505 if (show_full_) { | 503 if (show_full_) { |
| 506 const Snippet& snippet = model_->GetSnippet(model_index_); | 504 const Snippet& snippet = model_->GetSnippet(model_index_); |
| (...skipping 779 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1286 for (BreakOffsets::iterator i = break_offsets_.begin(); i != it; ++i) { | 1284 for (BreakOffsets::iterator i = break_offsets_.begin(); i != it; ++i) { |
| 1287 if (i->second.day) | 1285 if (i->second.day) |
| 1288 offset++; | 1286 offset++; |
| 1289 } | 1287 } |
| 1290 return offset; | 1288 return offset; |
| 1291 } | 1289 } |
| 1292 | 1290 |
| 1293 int HistoryView::GetDeleteControlWidth() { | 1291 int HistoryView::GetDeleteControlWidth() { |
| 1294 if (delete_control_width_) | 1292 if (delete_control_width_) |
| 1295 return delete_control_width_; | 1293 return delete_control_width_; |
| 1296 CSize pref; | |
| 1297 EnsureRenderer(); | 1294 EnsureRenderer(); |
| 1298 delete_renderer_->GetPreferredSize(&pref); | 1295 gfx::Size pref = delete_renderer_->GetPreferredSize(); |
| 1299 delete_control_width_ = pref.cx; | 1296 delete_control_width_ = pref.width(); |
| 1300 return delete_control_width_; | 1297 return delete_control_width_; |
| 1301 } | 1298 } |
| 1302 | 1299 |
| 1303 gfx::Rect HistoryView::CalculateDeleteControlBounds(int base_y) { | 1300 gfx::Rect HistoryView::CalculateDeleteControlBounds(int base_y) { |
| 1304 // NOTE: the height here is too big, it should be just big enough to show | 1301 // NOTE: the height here is too big, it should be just big enough to show |
| 1305 // the link. Additionally this should be baseline aligned with the date. I'm | 1302 // the link. Additionally this should be baseline aligned with the date. I'm |
| 1306 // not doing that now as a redesign of HistoryView is in the works. | 1303 // not doing that now as a redesign of HistoryView is in the works. |
| 1307 const int delete_width = GetDeleteControlWidth(); | 1304 const int delete_width = GetDeleteControlWidth(); |
| 1308 const int delete_x = width() - kRightMargin - delete_width; | 1305 const int delete_x = width() - kRightMargin - delete_width; |
| 1309 return gfx::Rect(delete_x, | 1306 return gfx::Rect(delete_x, |
| 1310 base_y + kDeleteControlOffset, | 1307 base_y + kDeleteControlOffset, |
| 1311 delete_width, | 1308 delete_width, |
| 1312 kBrowseResultsHeight); | 1309 kBrowseResultsHeight); |
| 1313 } | 1310 } |
| 1314 | 1311 |
| OLD | NEW |