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

Side by Side Diff: ui/gfx/image/image_family.cc

Issue 13713002: ImageFamily: Renamed Get method to GetBest. (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: Created 7 years, 8 months 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
« no previous file with comments | « ui/gfx/image/image_family.h ('k') | ui/gfx/image/image_family_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 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 "ui/gfx/image/image_family.h" 5 #include "ui/gfx/image/image_family.h"
6 6
7 #include <cmath> 7 #include <cmath>
8 8
9 #include "ui/gfx/image/image.h" 9 #include "ui/gfx/image/image.h"
10 #include "ui/gfx/image/image_skia.h" 10 #include "ui/gfx/image/image_skia.h"
(...skipping 21 matching lines...) Expand all
32 float aspect = static_cast<float>(size.width()) / size.height(); 32 float aspect = static_cast<float>(size.width()) / size.height();
33 DCHECK_GT(aspect, 0.0f); 33 DCHECK_GT(aspect, 0.0f);
34 map_[MapKey(aspect, size.width())] = image; 34 map_[MapKey(aspect, size.width())] = image;
35 } 35 }
36 } 36 }
37 37
38 void ImageFamily::Add(const gfx::ImageSkia& image_skia) { 38 void ImageFamily::Add(const gfx::ImageSkia& image_skia) {
39 Add(gfx::Image(image_skia)); 39 Add(gfx::Image(image_skia));
40 } 40 }
41 41
42 const gfx::Image* ImageFamily::Get(int width, int height) const { 42 const gfx::Image* ImageFamily::GetBest(int width, int height) const {
43 if (map_.empty()) 43 if (map_.empty())
44 return NULL; 44 return NULL;
45 45
46 // If either |width| or |height| is 0, both are. 46 // If either |width| or |height| is 0, both are.
47 float desired_aspect; 47 float desired_aspect;
48 if (height == 0 || width == 0) { 48 if (height == 0 || width == 0) {
49 desired_aspect = 1.0f; 49 desired_aspect = 1.0f;
50 height = 0; 50 height = 0;
51 width = 0; 51 width = 0;
52 } else { 52 } else {
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after
115 DCHECK(greater_or_equal != map_.begin()); 115 DCHECK(greater_or_equal != map_.begin());
116 std::map<MapKey, gfx::Image>::const_iterator less_than = greater_or_equal; 116 std::map<MapKey, gfx::Image>::const_iterator less_than = greater_or_equal;
117 --less_than; 117 --less_than;
118 // This must be true because there must be at least one image with |aspect|. 118 // This must be true because there must be at least one image with |aspect|.
119 DCHECK_EQ(less_than->first.aspect(), aspect); 119 DCHECK_EQ(less_than->first.aspect(), aspect);
120 // We have found the largest image smaller than desired. 120 // We have found the largest image smaller than desired.
121 return &less_than->second; 121 return &less_than->second;
122 } 122 }
123 123
124 } // namespace gfx 124 } // namespace gfx
OLDNEW
« no previous file with comments | « ui/gfx/image/image_family.h ('k') | ui/gfx/image/image_family_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698