| OLD | NEW |
| 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 "base/mime_util.h" | 5 #include "base/mime_util.h" |
| 6 | 6 |
| 7 #include <gtk/gtk.h> | 7 #include <gtk/gtk.h> |
| 8 #include <sys/time.h> | 8 #include <sys/time.h> |
| 9 #include <time.h> | 9 #include <time.h> |
| 10 | 10 |
| (...skipping 180 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 191 subdir_iter != subdirs_.end(); | 191 subdir_iter != subdirs_.end(); |
| 192 ++subdir_iter) { | 192 ++subdir_iter) { |
| 193 SubDirInfo* info = &info_array_[subdir_iter->second]; | 193 SubDirInfo* info = &info_array_[subdir_iter->second]; |
| 194 if (MatchesSize(info, size) == 0) { | 194 if (MatchesSize(info, size) == 0) { |
| 195 icon_path = GetIconPathUnderSubdir(icon_name, subdir_iter->first); | 195 icon_path = GetIconPathUnderSubdir(icon_name, subdir_iter->first); |
| 196 if (!icon_path.empty()) | 196 if (!icon_path.empty()) |
| 197 return icon_path; | 197 return icon_path; |
| 198 } | 198 } |
| 199 } | 199 } |
| 200 // Now looking for the mostly matched. | 200 // Now looking for the mostly matched. |
| 201 int min_delta_seen = 9999; | 201 size_t min_delta_seen = 9999; |
| 202 | 202 |
| 203 for (subdir_iter = subdirs_.begin(); | 203 for (subdir_iter = subdirs_.begin(); |
| 204 subdir_iter != subdirs_.end(); | 204 subdir_iter != subdirs_.end(); |
| 205 ++subdir_iter) { | 205 ++subdir_iter) { |
| 206 SubDirInfo* info = &info_array_[subdir_iter->second]; | 206 SubDirInfo* info = &info_array_[subdir_iter->second]; |
| 207 int delta = abs(MatchesSize(info, size)); | 207 size_t delta = MatchesSize(info, size); |
| 208 if (delta < min_delta_seen) { | 208 if (delta < min_delta_seen) { |
| 209 FilePath path = GetIconPathUnderSubdir(icon_name, subdir_iter->first); | 209 FilePath path = GetIconPathUnderSubdir(icon_name, subdir_iter->first); |
| 210 if (!path.empty()) { | 210 if (!path.empty()) { |
| 211 min_delta_seen = delta; | 211 min_delta_seen = delta; |
| 212 icon_path = path; | 212 icon_path = path; |
| 213 } | 213 } |
| 214 } | 214 } |
| 215 } | 215 } |
| 216 | 216 |
| 217 if (!icon_path.empty() || !inherits || inherits_ == "") | 217 if (!icon_path.empty() || !inherits || inherits_ == "") |
| (...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 318 } | 318 } |
| 319 } | 319 } |
| 320 } | 320 } |
| 321 | 321 |
| 322 file_util::CloseFile(fp); | 322 file_util::CloseFile(fp); |
| 323 return info_array_ != NULL; | 323 return info_array_ != NULL; |
| 324 } | 324 } |
| 325 | 325 |
| 326 size_t IconTheme::MatchesSize(SubDirInfo* info, size_t size) { | 326 size_t IconTheme::MatchesSize(SubDirInfo* info, size_t size) { |
| 327 if (info->type == SubDirInfo::Fixed) { | 327 if (info->type == SubDirInfo::Fixed) { |
| 328 return size - info->size; | 328 if (size > info->size) |
| 329 return size - info->size; |
| 330 else |
| 331 return info->size - size; |
| 329 } else if (info->type == SubDirInfo::Scalable) { | 332 } else if (info->type == SubDirInfo::Scalable) { |
| 330 if (size >= info->min_size && size <= info->max_size) { | 333 if (size < info->min_size) |
| 331 return 0; | 334 return info->min_size - size; |
| 332 } else { | 335 if (size > info->max_size) |
| 333 return abs(size - info->min_size) < abs(size - info->max_size) ? | 336 return size - info->max_size; |
| 334 (size - info->min_size) : (size - info->max_size); | 337 return 0; |
| 335 } | |
| 336 } else { | 338 } else { |
| 337 if (size >= info->size - info->threshold && | 339 if (size + info->threshold < info->size) |
| 338 size <= info->size + info->threshold) { | 340 return info->size - size - info->threshold; |
| 339 return 0; | 341 if (size > info->size + info->threshold) |
| 340 } else { | 342 return size - info->size - info->threshold; |
| 341 return abs(size - info->size - info->threshold) < | 343 return 0; |
| 342 abs(size - info->size + info->threshold) | |
| 343 ? size - info->size - info->threshold | |
| 344 : size - info->size + info->threshold; | |
| 345 } | |
| 346 } | 344 } |
| 347 } | 345 } |
| 348 | 346 |
| 349 std::string IconTheme::ReadLine(FILE* fp) { | 347 std::string IconTheme::ReadLine(FILE* fp) { |
| 350 if (!fp) | 348 if (!fp) |
| 351 return ""; | 349 return ""; |
| 352 | 350 |
| 353 std::string result = ""; | 351 std::string result = ""; |
| 354 const size_t kBufferSize = 100; | 352 const size_t kBufferSize = 100; |
| 355 char buffer[kBufferSize]; | 353 char buffer[kBufferSize]; |
| (...skipping 274 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 630 } else { | 628 } else { |
| 631 icon_file = LookupIconInDefaultTheme(icon_names[i], size); | 629 icon_file = LookupIconInDefaultTheme(icon_names[i], size); |
| 632 if (!icon_file.empty()) | 630 if (!icon_file.empty()) |
| 633 return icon_file; | 631 return icon_file; |
| 634 } | 632 } |
| 635 } | 633 } |
| 636 return FilePath(); | 634 return FilePath(); |
| 637 } | 635 } |
| 638 | 636 |
| 639 } // namespace mime_util | 637 } // namespace mime_util |
| OLD | NEW |