summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--chrome/browser/cocoa/keyword_editor_cocoa_controller.h4
-rw-r--r--chrome/browser/cocoa/keyword_editor_cocoa_controller.mm41
2 files changed, 28 insertions, 17 deletions
diff --git a/chrome/browser/cocoa/keyword_editor_cocoa_controller.h b/chrome/browser/cocoa/keyword_editor_cocoa_controller.h
index 0757e69..6aac616 100644
--- a/chrome/browser/cocoa/keyword_editor_cocoa_controller.h
+++ b/chrome/browser/cocoa/keyword_editor_cocoa_controller.h
@@ -44,10 +44,6 @@ class KeywordEditorModelObserver : public TemplateURLModelObserver,
// Lazily converts the image at the given row and caches it in |iconImages_|.
NSImage* GetImageForRow(int row);
- protected:
- // Invalidates a range of the |iconImages_| cache.
- void InvalidateIconCache(int start, int length);
-
private:
KeywordEditorCocoaController* controller_;
diff --git a/chrome/browser/cocoa/keyword_editor_cocoa_controller.mm b/chrome/browser/cocoa/keyword_editor_cocoa_controller.mm
index 032ffbb..86b7e56 100644
--- a/chrome/browser/cocoa/keyword_editor_cocoa_controller.mm
+++ b/chrome/browser/cocoa/keyword_editor_cocoa_controller.mm
@@ -57,35 +57,54 @@ void KeywordEditorModelObserver::OnEditedKeyword(
}
void KeywordEditorModelObserver::OnModelChanged() {
- InvalidateIconCache(0, [iconImages_ count]);
int count = [controller_ controller]->table_model()->RowCount();
+ [iconImages_ setCount:0];
[iconImages_ setCount:count];
[controller_ modelChanged];
}
void KeywordEditorModelObserver::OnItemsChanged(int start, int length) {
- InvalidateIconCache(start, length);
+ DCHECK_LE(start + length, static_cast<int>([iconImages_ count]));
+ for (int i = start; i < (start + length); ++i) {
+ [iconImages_ replacePointerAtIndex:i withPointer:NULL];
+ }
+ DCHECK_EQ([controller_ controller]->table_model()->RowCount(),
+ static_cast<int>([iconImages_ count]));
[controller_ modelChanged];
}
void KeywordEditorModelObserver::OnItemsAdded(int start, int length) {
DCHECK_LE(start, static_cast<int>([iconImages_ count]));
- for (int i = 0; i < length; ++i) {
- [iconImages_ insertPointer:NULL atIndex:start]; // Values slide down.
+
+ // -[NSPointerArray insertPointer:atIndex:] throws if index == count.
+ // Instead expand the array with NULLs.
+ if (start == static_cast<int>([iconImages_ count])) {
+ [iconImages_ setCount:start + length];
+ } else {
+ for (int i = 0; i < length; ++i) {
+ [iconImages_ insertPointer:NULL atIndex:start]; // Values slide up.
+ }
}
+ DCHECK_EQ([controller_ controller]->table_model()->RowCount(),
+ static_cast<int>([iconImages_ count]));
[controller_ modelChanged];
}
void KeywordEditorModelObserver::OnItemsRemoved(int start, int length) {
DCHECK_LE(start + length, static_cast<int>([iconImages_ count]));
for (int i = 0; i < length; ++i) {
- [iconImages_ removePointerAtIndex:start]; // Values slide up.
+ [iconImages_ removePointerAtIndex:start]; // Values slide down.
}
+ DCHECK_EQ([controller_ controller]->table_model()->RowCount(),
+ static_cast<int>([iconImages_ count]));
[controller_ modelChanged];
}
NSImage* KeywordEditorModelObserver::GetImageForRow(int row) {
- DCHECK(row >= 0 && row < static_cast<int>([iconImages_ count]));
+ DCHECK_EQ([controller_ controller]->table_model()->RowCount(),
+ static_cast<int>([iconImages_ count]));
+ DCHECK_GE(row, 0);
+ DCHECK_LT(row, static_cast<int>([iconImages_ count]));
NSImage* image = static_cast<NSImage*>([iconImages_ pointerAtIndex:row]);
if (!image) {
const SkBitmap bitmapIcon =
@@ -99,13 +118,6 @@ NSImage* KeywordEditorModelObserver::GetImageForRow(int row) {
return image;
}
-void KeywordEditorModelObserver::InvalidateIconCache(int start, int length) {
- DCHECK_LE(start + length, static_cast<int>([iconImages_ count]));
- for (int i = start; i < (start + length); ++i) {
- [iconImages_ replacePointerAtIndex:i withPointer:NULL];
- }
-}
-
// KeywordEditorCocoaController -----------------------------------------------
namespace {
@@ -170,6 +182,8 @@ typedef std::map<Profile*,KeywordEditorCocoaController*> ProfileControllerMap;
- (void)dealloc {
controller_->table_model()->SetObserver(NULL);
controller_->url_model()->RemoveObserver(observer_.get());
+ [tableView_ setTarget:nil];
+ observer_.reset();
[super dealloc];
}
@@ -221,6 +235,7 @@ typedef std::map<Profile*,KeywordEditorCocoaController*> ProfileControllerMap;
- (void)modelChanged {
[tableView_ reloadData];
+ [self adjustEditingButtons];
}
- (KeywordEditorController*)controller {