| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (C) 2005, 2006, 2008 Apple Inc. All rights reserved. | 2 * Copyright (C) 2005, 2006, 2008 Apple Inc. All rights reserved. |
| 3 * | 3 * |
| 4 * Redistribution and use in source and binary forms, with or without | 4 * Redistribution and use in source and binary forms, with or without |
| 5 * modification, are permitted provided that the following conditions | 5 * modification, are permitted provided that the following conditions |
| 6 * are met: | 6 * are met: |
| 7 * 1. Redistributions of source code must retain the above copyright | 7 * 1. Redistributions of source code must retain the above copyright |
| 8 * notice, this list of conditions and the following disclaimer. | 8 * notice, this list of conditions and the following disclaimer. |
| 9 * 2. Redistributions in binary form must reproduce the above copyright | 9 * 2. Redistributions in binary form must reproduce the above copyright |
| 10 * notice, this list of conditions and the following disclaimer in the | 10 * notice, this list of conditions and the following disclaimer in the |
| (...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 67 HistoryItem::HistoryItem(const String& urlString, const String& title, const Str
ing& alternateTitle, double time) | 67 HistoryItem::HistoryItem(const String& urlString, const String& title, const Str
ing& alternateTitle, double time) |
| 68 : m_urlString(urlString) | 68 : m_urlString(urlString) |
| 69 , m_originalURLString(urlString) | 69 , m_originalURLString(urlString) |
| 70 , m_title(title) | 70 , m_title(title) |
| 71 , m_displayTitle(alternateTitle) | 71 , m_displayTitle(alternateTitle) |
| 72 , m_lastVisitedTime(time) | 72 , m_lastVisitedTime(time) |
| 73 , m_lastVisitWasHTTPNonGet(false) | 73 , m_lastVisitWasHTTPNonGet(false) |
| 74 , m_lastVisitWasFailure(false) | 74 , m_lastVisitWasFailure(false) |
| 75 , m_isTargetItem(false) | 75 , m_isTargetItem(false) |
| 76 , m_visitCount(0) | 76 , m_visitCount(0) |
| 77 { | 77 { |
| 78 iconDatabase()->retainIconForPageURL(m_urlString); | 78 iconDatabase()->retainIconForPageURL(m_urlString); |
| 79 } | 79 } |
| 80 | 80 |
| 81 HistoryItem::HistoryItem(const KURL& url, const String& target, const String& pa
rent, const String& title) | 81 HistoryItem::HistoryItem(const KURL& url, const String& target, const String& pa
rent, const String& title) |
| 82 : m_urlString(url.string()) | 82 : m_urlString(url.string()) |
| 83 , m_originalURLString(url.string()) | 83 , m_originalURLString(url.string()) |
| 84 , m_target(target) | 84 , m_target(target) |
| 85 , m_parent(parent) | 85 , m_parent(parent) |
| 86 , m_title(title) | 86 , m_title(title) |
| 87 , m_lastVisitedTime(0) | 87 , m_lastVisitedTime(0) |
| (...skipping 19 matching lines...) Expand all Loading... |
| 107 , m_target(item.m_target) | 107 , m_target(item.m_target) |
| 108 , m_parent(item.m_parent) | 108 , m_parent(item.m_parent) |
| 109 , m_title(item.m_title) | 109 , m_title(item.m_title) |
| 110 , m_displayTitle(item.m_displayTitle) | 110 , m_displayTitle(item.m_displayTitle) |
| 111 , m_lastVisitedTime(item.m_lastVisitedTime) | 111 , m_lastVisitedTime(item.m_lastVisitedTime) |
| 112 , m_lastVisitWasHTTPNonGet(item.m_lastVisitWasHTTPNonGet) | 112 , m_lastVisitWasHTTPNonGet(item.m_lastVisitWasHTTPNonGet) |
| 113 , m_scrollPoint(item.m_scrollPoint) | 113 , m_scrollPoint(item.m_scrollPoint) |
| 114 , m_lastVisitWasFailure(item.m_lastVisitWasFailure) | 114 , m_lastVisitWasFailure(item.m_lastVisitWasFailure) |
| 115 , m_isTargetItem(item.m_isTargetItem) | 115 , m_isTargetItem(item.m_isTargetItem) |
| 116 , m_visitCount(item.m_visitCount) | 116 , m_visitCount(item.m_visitCount) |
| 117 , m_dailyVisitCounts(item.m_dailyVisitCounts) | |
| 118 , m_weeklyVisitCounts(item.m_weeklyVisitCounts) | |
| 119 , m_formContentType(item.m_formContentType) | 117 , m_formContentType(item.m_formContentType) |
| 120 { | 118 { |
| 121 ASSERT(!item.m_cachedPage); | 119 ASSERT(!item.m_cachedPage); |
| 122 | 120 |
| 123 if (item.m_formData) | 121 if (item.m_formData) |
| 124 m_formData = item.m_formData->copy(); | 122 m_formData = item.m_formData->copy(); |
| 125 | 123 |
| 126 unsigned size = item.m_subItems.size(); | 124 unsigned size = item.m_subItems.size(); |
| 127 m_subItems.reserveInitialCapacity(size); | 125 m_subItems.reserveInitialCapacity(size); |
| 128 for (unsigned i = 0; i < size; ++i) | 126 for (unsigned i = 0; i < size; ++i) |
| (...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 241 { | 239 { |
| 242 m_target = target; | 240 m_target = target; |
| 243 notifyHistoryItemChanged(); | 241 notifyHistoryItemChanged(); |
| 244 } | 242 } |
| 245 | 243 |
| 246 void HistoryItem::setParent(const String& parent) | 244 void HistoryItem::setParent(const String& parent) |
| 247 { | 245 { |
| 248 m_parent = parent; | 246 m_parent = parent; |
| 249 } | 247 } |
| 250 | 248 |
| 251 static inline int timeToDay(double time) | |
| 252 { | |
| 253 static const double secondsPerDay = 60 * 60 * 24; | |
| 254 return static_cast<int>(ceil(time / secondsPerDay)); | |
| 255 } | |
| 256 | |
| 257 void HistoryItem::padDailyCountsForNewVisit(double time) | |
| 258 { | |
| 259 if (m_dailyVisitCounts.isEmpty()) | |
| 260 m_dailyVisitCounts.prepend(m_visitCount); | |
| 261 | |
| 262 int daysElapsed = timeToDay(time) - timeToDay(m_lastVisitedTime); | |
| 263 | |
| 264 if (daysElapsed < 0) | |
| 265 daysElapsed = 0; | |
| 266 | |
| 267 Vector<int> padding; | |
| 268 padding.fill(0, daysElapsed); | |
| 269 m_dailyVisitCounts.prepend(padding); | |
| 270 } | |
| 271 | |
| 272 static const size_t daysPerWeek = 7; | |
| 273 static const size_t maxDailyCounts = 2 * daysPerWeek - 1; | |
| 274 static const size_t maxWeeklyCounts = 5; | |
| 275 | |
| 276 void HistoryItem::collapseDailyVisitsToWeekly() | |
| 277 { | |
| 278 while (m_dailyVisitCounts.size() > maxDailyCounts) { | |
| 279 int oldestWeekTotal = 0; | |
| 280 for (size_t i = 0; i < daysPerWeek; i++) | |
| 281 oldestWeekTotal += m_dailyVisitCounts[m_dailyVisitCounts.size() - da
ysPerWeek + i]; | |
| 282 m_dailyVisitCounts.shrink(m_dailyVisitCounts.size() - daysPerWeek); | |
| 283 m_weeklyVisitCounts.prepend(oldestWeekTotal); | |
| 284 } | |
| 285 | |
| 286 if (m_weeklyVisitCounts.size() > maxWeeklyCounts) | |
| 287 m_weeklyVisitCounts.shrink(maxWeeklyCounts); | |
| 288 } | |
| 289 | |
| 290 void HistoryItem::recordVisitAtTime(double time) | |
| 291 { | |
| 292 padDailyCountsForNewVisit(time); | |
| 293 | |
| 294 m_lastVisitedTime = time; | |
| 295 m_visitCount++; | |
| 296 | |
| 297 m_dailyVisitCounts[0]++; | |
| 298 | |
| 299 collapseDailyVisitsToWeekly(); | |
| 300 } | |
| 301 | |
| 302 void HistoryItem::setLastVisitedTime(double time) | 249 void HistoryItem::setLastVisitedTime(double time) |
| 303 { | 250 { |
| 304 if (m_lastVisitedTime != time) | 251 if (m_lastVisitedTime != time) { |
| 305 recordVisitAtTime(time); | 252 m_lastVisitedTime = time; |
| 253 m_visitCount++; |
| 254 } |
| 306 } | 255 } |
| 307 | 256 |
| 308 void HistoryItem::visited(const String& title, double time) | 257 void HistoryItem::visited(const String& title, double time) |
| 309 { | 258 { |
| 310 m_title = title; | 259 m_title = title; |
| 311 recordVisitAtTime(time); | 260 m_lastVisitedTime = time; |
| 261 m_visitCount++; |
| 312 } | 262 } |
| 313 | 263 |
| 314 int HistoryItem::visitCount() const | 264 int HistoryItem::visitCount() const |
| 315 { | 265 { |
| 316 return m_visitCount; | 266 return m_visitCount; |
| 317 } | 267 } |
| 318 | 268 |
| 319 void HistoryItem::recordInitialVisit() | |
| 320 { | |
| 321 ASSERT(!m_visitCount); | |
| 322 recordVisitAtTime(m_lastVisitedTime); | |
| 323 } | |
| 324 | |
| 325 void HistoryItem::setVisitCount(int count) | 269 void HistoryItem::setVisitCount(int count) |
| 326 { | 270 { |
| 327 m_visitCount = count; | 271 m_visitCount = count; |
| 328 } | 272 } |
| 329 | 273 |
| 330 void HistoryItem::adoptVisitCounts(Vector<int>& dailyCounts, Vector<int>& weekly
Counts) | |
| 331 { | |
| 332 m_dailyVisitCounts.clear(); | |
| 333 m_dailyVisitCounts.swap(dailyCounts); | |
| 334 m_weeklyVisitCounts.clear(); | |
| 335 m_weeklyVisitCounts.swap(weeklyCounts); | |
| 336 } | |
| 337 | |
| 338 const IntPoint& HistoryItem::scrollPoint() const | 274 const IntPoint& HistoryItem::scrollPoint() const |
| 339 { | 275 { |
| 340 return m_scrollPoint; | 276 return m_scrollPoint; |
| 341 } | 277 } |
| 342 | 278 |
| 343 void HistoryItem::setScrollPoint(const IntPoint& point) | 279 void HistoryItem::setScrollPoint(const IntPoint& point) |
| 344 { | 280 { |
| 345 m_scrollPoint = point; | 281 m_scrollPoint = point; |
| 346 } | 282 } |
| 347 | 283 |
| (...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 452 } | 388 } |
| 453 | 389 |
| 454 bool HistoryItem::isCurrentDocument(Document* doc) const | 390 bool HistoryItem::isCurrentDocument(Document* doc) const |
| 455 { | 391 { |
| 456 // FIXME: We should find a better way to check if this is the current docume
nt. | 392 // FIXME: We should find a better way to check if this is the current docume
nt. |
| 457 return urlString() == doc->url(); | 393 return urlString() == doc->url(); |
| 458 } | 394 } |
| 459 | 395 |
| 460 void HistoryItem::mergeAutoCompleteHints(HistoryItem* otherItem) | 396 void HistoryItem::mergeAutoCompleteHints(HistoryItem* otherItem) |
| 461 { | 397 { |
| 462 // FIXME: this is broken - we should be merging the daily counts | |
| 463 // somehow. but this is to support API that's not really used in | |
| 464 // practice so leave it broken for now. | |
| 465 ASSERT(otherItem); | 398 ASSERT(otherItem); |
| 466 if (otherItem != this) | 399 if (otherItem != this) |
| 467 m_visitCount += otherItem->m_visitCount; | 400 m_visitCount += otherItem->m_visitCount; |
| 468 } | 401 } |
| 469 | 402 |
| 470 void HistoryItem::addRedirectURL(const String& url) | 403 void HistoryItem::addRedirectURL(const String& url) |
| 471 { | 404 { |
| 472 if (!m_redirectURLs) | 405 if (!m_redirectURLs) |
| 473 m_redirectURLs.set(new Vector<String>); | 406 m_redirectURLs.set(new Vector<String>); |
| 474 | 407 |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 516 | 449 |
| 517 #ifndef NDEBUG | 450 #ifndef NDEBUG |
| 518 | 451 |
| 519 int showTree(const WebCore::HistoryItem* item) | 452 int showTree(const WebCore::HistoryItem* item) |
| 520 { | 453 { |
| 521 return item->showTree(); | 454 return item->showTree(); |
| 522 } | 455 } |
| 523 | 456 |
| 524 #endif | 457 #endif |
| 525 | 458 |
| OLD | NEW |