| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 #ifndef CHROME_BROWSER_UI_COCOA_TABLE_ROW_NSIMAGE_CACHE_H_ | 5 #ifndef CHROME_BROWSER_UI_COCOA_TABLE_ROW_NSIMAGE_CACHE_H_ |
| 6 #define CHROME_BROWSER_UI_COCOA_TABLE_ROW_NSIMAGE_CACHE_H_ | 6 #define CHROME_BROWSER_UI_COCOA_TABLE_ROW_NSIMAGE_CACHE_H_ |
| 7 #pragma once | 7 #pragma once |
| 8 | 8 |
| 9 #import <Cocoa/Cocoa.h> | 9 #import <Cocoa/Cocoa.h> |
| 10 | 10 |
| 11 #include "base/memory/scoped_nsobject.h" | 11 #include "base/memory/scoped_nsobject.h" |
| 12 | 12 |
| 13 class SkBitmap; | 13 namespace gfx { |
| 14 class ImageSkia; |
| 15 } |
| 14 | 16 |
| 15 // There are several dialogs that display tabular data with one SkBitmap | 17 // There are several dialogs that display tabular data with one SkBitmap |
| 16 // per row. This class converts these SkBitmaps to NSImages on demand, and | 18 // per row. This class converts these SkBitmaps to NSImages on demand, and |
| 17 // caches the results. | 19 // caches the results. |
| 18 class TableRowNSImageCache { | 20 class TableRowNSImageCache { |
| 19 public: | 21 public: |
| 20 // Interface this cache expects for its table model. | 22 // Interface this cache expects for its table model. |
| 21 class Table { | 23 class Table { |
| 22 public: | 24 public: |
| 23 // Returns the number of rows in the table. | 25 // Returns the number of rows in the table. |
| 24 virtual int RowCount() const = 0; | 26 virtual int RowCount() const = 0; |
| 25 | 27 |
| 26 // Returns the icon of the |row|th row. | 28 // Returns the icon of the |row|th row. |
| 27 virtual SkBitmap GetIcon(int row) const = 0; | 29 virtual gfx::ImageSkia GetIcon(int row) const = 0; |
| 28 | 30 |
| 29 protected: | 31 protected: |
| 30 virtual ~Table() {} | 32 virtual ~Table() {} |
| 31 }; | 33 }; |
| 32 | 34 |
| 33 // |model| must outlive the cache. | 35 // |model| must outlive the cache. |
| 34 explicit TableRowNSImageCache(Table* model); | 36 explicit TableRowNSImageCache(Table* model); |
| 35 ~TableRowNSImageCache(); | 37 ~TableRowNSImageCache(); |
| 36 | 38 |
| 37 // Lazily converts the image at the given row and caches it in |icon_images_|. | 39 // Lazily converts the image at the given row and caches it in |icon_images_|. |
| 38 NSImage* GetImageForRow(int row); | 40 NSImage* GetImageForRow(int row); |
| 39 | 41 |
| 40 // Call these functions every time the table changes, to update the cache. | 42 // Call these functions every time the table changes, to update the cache. |
| 41 void OnModelChanged(); | 43 void OnModelChanged(); |
| 42 void OnItemsChanged(int start, int length); | 44 void OnItemsChanged(int start, int length); |
| 43 void OnItemsAdded(int start, int length); | 45 void OnItemsAdded(int start, int length); |
| 44 void OnItemsRemoved(int start, int length); | 46 void OnItemsRemoved(int start, int length); |
| 45 | 47 |
| 46 private: | 48 private: |
| 47 // The table model we query for row count and icons. | 49 // The table model we query for row count and icons. |
| 48 Table* model_; // weak | 50 Table* model_; // weak |
| 49 | 51 |
| 50 // Stores strong NSImage refs for icons. If an entry is NULL, it will be | 52 // Stores strong NSImage refs for icons. If an entry is NULL, it will be |
| 51 // created in GetImageForRow(). | 53 // created in GetImageForRow(). |
| 52 scoped_nsobject<NSPointerArray> icon_images_; | 54 scoped_nsobject<NSPointerArray> icon_images_; |
| 53 }; | 55 }; |
| 54 | 56 |
| 55 #endif // CHROME_BROWSER_UI_COCOA_TABLE_ROW_NSIMAGE_CACHE_H_ | 57 #endif // CHROME_BROWSER_UI_COCOA_TABLE_ROW_NSIMAGE_CACHE_H_ |
| 56 | |
| OLD | NEW |