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 return std::max(size, info->size) - std::min(size, info->size); |
Lei Zhang
2011/06/13 22:01:15
can't we just do abs(size - info->size) instead?
tzik
2011/06/14 02:52:52
size - info->size is size_t expression, which is u
| |
329 } else if (info->type == SubDirInfo::Scalable) { | 329 } else if (info->type == SubDirInfo::Scalable) { |
330 if (size >= info->min_size && size <= info->max_size) { | 330 if (size >= info->min_size && size <= info->max_size) { |
Lei Zhang
2011/06/13 22:01:15
how about we rewrite this block to remove one laye
tzik
2011/06/14 02:52:52
Done.
| |
331 return 0; | 331 return 0; |
332 } else { | 332 } else { |
333 return abs(size - info->min_size) < abs(size - info->max_size) ? | 333 if (size < info->min_size) |
334 (size - info->min_size) : (size - info->max_size); | 334 return info->min_size - size; |
335 else | |
336 return size - info->max_size; | |
335 } | 337 } |
336 } else { | 338 } else { |
337 if (size >= info->size - info->threshold && | 339 if (size + info->threshold >= info->size && |
Lei Zhang
2011/06/13 22:01:15
Arg. I'm not even sure the old code was correct. :
tzik
2011/06/14 02:52:52
Done.
| |
338 size <= info->size + info->threshold) { | 340 size <= info->size + info->threshold) { |
339 return 0; | 341 return 0; |
340 } else { | 342 } else { |
341 return abs(size - info->size - info->threshold) < | 343 if (size < info->size + info->threshold) |
342 abs(size - info->size + info->threshold) | 344 return size - info->size - info->threshold; |
343 ? size - info->size - info->threshold | 345 else |
344 : size - info->size + info->threshold; | 346 return info->size - info->threshold - size; |
345 } | 347 } |
346 } | 348 } |
347 } | 349 } |
348 | 350 |
349 std::string IconTheme::ReadLine(FILE* fp) { | 351 std::string IconTheme::ReadLine(FILE* fp) { |
350 if (!fp) | 352 if (!fp) |
351 return ""; | 353 return ""; |
352 | 354 |
353 std::string result = ""; | 355 std::string result = ""; |
354 const size_t kBufferSize = 100; | 356 const size_t kBufferSize = 100; |
(...skipping 275 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
630 } else { | 632 } else { |
631 icon_file = LookupIconInDefaultTheme(icon_names[i], size); | 633 icon_file = LookupIconInDefaultTheme(icon_names[i], size); |
632 if (!icon_file.empty()) | 634 if (!icon_file.empty()) |
633 return icon_file; | 635 return icon_file; |
634 } | 636 } |
635 } | 637 } |
636 return FilePath(); | 638 return FilePath(); |
637 } | 639 } |
638 | 640 |
639 } // namespace mime_util | 641 } // namespace mime_util |
OLD | NEW |