Disable view source for Developer Tools.
[chromium-blink-merge.git] / chrome / browser / ui / cocoa / table_row_nsimage_cache.h
blob4932aa2f558ef4fd8cfd15a67d377c50ddb58d78
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
3 // found in the LICENSE file.
5 #ifndef CHROME_BROWSER_UI_COCOA_TABLE_ROW_NSIMAGE_CACHE_H_
6 #define CHROME_BROWSER_UI_COCOA_TABLE_ROW_NSIMAGE_CACHE_H_
8 #import <Cocoa/Cocoa.h>
10 #include "base/mac/scoped_nsobject.h"
12 namespace gfx {
13 class ImageSkia;
16 // There are several dialogs that display tabular data with one SkBitmap
17 // per row. This class converts these SkBitmaps to NSImages on demand, and
18 // caches the results.
19 class TableRowNSImageCache {
20 public:
21 // Interface this cache expects for its table model.
22 class Table {
23 public:
24 // Returns the number of rows in the table.
25 virtual int RowCount() const = 0;
27 // Returns the icon of the |row|th row.
28 virtual gfx::ImageSkia GetIcon(int row) const = 0;
30 protected:
31 virtual ~Table() {}
34 // |model| must outlive the cache.
35 explicit TableRowNSImageCache(Table* model);
36 ~TableRowNSImageCache();
38 // Lazily converts the image at the given row and caches it in |icon_images_|.
39 NSImage* GetImageForRow(int row);
41 // Call these functions every time the table changes, to update the cache.
42 void OnModelChanged();
43 void OnItemsChanged(int start, int length);
44 void OnItemsAdded(int start, int length);
45 void OnItemsRemoved(int start, int length);
47 private:
48 // The table model we query for row count and icons.
49 Table* model_; // weak
51 // Stores strong NSImage refs for icons. If an entry is NULL, it will be
52 // created in GetImageForRow().
53 base::scoped_nsobject<NSPointerArray> icon_images_;
56 #endif // CHROME_BROWSER_UI_COCOA_TABLE_ROW_NSIMAGE_CACHE_H_