1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
|
// Copyright (c) 2009 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#import <Cocoa/Cocoa.h>
#include "app/table_model_observer.h"
#import "base/cocoa_protocols_mac.h"
#include "base/scoped_ptr.h"
#include "chrome/browser/cocoa/table_row_nsimage_cache.h"
#include "chrome/browser/search_engines/edit_search_engine_controller.h"
#include "chrome/browser/search_engines/keyword_editor_controller.h"
#include "chrome/browser/search_engines/template_url_model.h"
class EditSearchEngineControllerDelegate;
@class KeywordEditorCocoaController;
class Profile;
@class WindowSizeAutosaver;
// Very thin bridge that simply pushes notifications from C++ to ObjC.
class KeywordEditorModelObserver : public TemplateURLModelObserver,
public EditSearchEngineControllerDelegate,
public TableModelObserver,
public TableRowNSImageCache::Table {
public:
explicit KeywordEditorModelObserver(KeywordEditorCocoaController* controller);
virtual ~KeywordEditorModelObserver();
// Notification that the template url model has changed in some way.
virtual void OnTemplateURLModelChanged();
// Invoked from the EditSearchEngineController when the user accepts the
// edits. NOTE: |template_url| is the value supplied to
// EditSearchEngineController's constructor, and may be NULL. A NULL value
// indicates a new TemplateURL should be created rather than modifying an
// existing TemplateURL.
virtual void OnEditedKeyword(const TemplateURL* template_url,
const std::wstring& title,
const std::wstring& keyword,
const std::wstring& url);
// TableModelObserver overrides. Invalidate icon cache.
virtual void OnModelChanged();
virtual void OnItemsChanged(int start, int length);
virtual void OnItemsAdded(int start, int length);
virtual void OnItemsRemoved(int start, int length);
// TableRowNSImageCache::Table
virtual int RowCount() const;
virtual SkBitmap GetIcon(int row) const;
// Lazily converts the image at the given row and caches it in |icon_cache_|.
NSImage* GetImageForRow(int row);
private:
KeywordEditorCocoaController* controller_;
TableRowNSImageCache icon_cache_;
DISALLOW_COPY_AND_ASSIGN(KeywordEditorModelObserver);
};
// This controller manages a window with a table view of search engines. It
// acts as |tableView_|'s data source and delegate, feeding it data from the
// KeywordEditorController's |table_model()|.
@interface KeywordEditorCocoaController : NSWindowController
<NSWindowDelegate,
NSTableViewDataSource,
NSTableViewDelegate> {
IBOutlet NSTableView* tableView_;
IBOutlet NSButton* addButton_;
IBOutlet NSButton* removeButton_;
IBOutlet NSButton* makeDefaultButton_;
scoped_nsobject<NSTextFieldCell> groupCell_;
Profile* profile_; // weak
scoped_ptr<KeywordEditorController> controller_;
scoped_ptr<KeywordEditorModelObserver> observer_;
scoped_nsobject<WindowSizeAutosaver> sizeSaver_;
}
@property (readonly) KeywordEditorController* controller;
// Show the keyword editor associated with the given profile (or the
// original profile if this is an incognito profile). If no keyword
// editor exists for this profile, create one and show it. Any
// resulting editor releases itself when closed.
+ (void)showKeywordEditor:(Profile*)profile;
- (KeywordEditorController*)controller;
// Message forwarded by KeywordEditorModelObserver.
- (void)modelChanged;
- (IBAction)addKeyword:(id)sender;
- (IBAction)deleteKeyword:(id)sender;
- (IBAction)makeDefault:(id)sender;
@end
@interface KeywordEditorCocoaController (TestingAPI)
// Instances of this class are managed, use +showKeywordEditor:.
- (id)initWithProfile:(Profile*)profile;
// Returns a reference to the shared instance for the given profile,
// or nil if there is none.
+ (KeywordEditorCocoaController*)sharedInstanceForProfile:(Profile*)profile;
// Converts a row index in our table view (which has group header rows) into
// one in the |controller_|'s model, which does not have them.
- (int)indexInModelForRow:(NSUInteger)row;
@end
|