| OLD | NEW |
| 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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 #import "chrome/browser/cocoa/geolocation_exceptions_window_controller.h" | 5 #import "chrome/browser/cocoa/simple_content_exceptions_window_controller.h" |
| 6 | 6 |
| 7 #include <set> | 7 #include <set> |
| 8 | 8 |
| 9 #include "app/l10n_util_mac.h" | 9 #include "app/l10n_util_mac.h" |
| 10 #include "app/table_model_observer.h" | 10 #include "app/table_model_observer.h" |
| 11 #import "base/mac_util.h" | 11 #import "base/mac_util.h" |
| 12 #import "base/scoped_nsobject.h" | 12 #import "base/scoped_nsobject.h" |
| 13 #include "base/sys_string_conversions.h" | 13 #include "base/sys_string_conversions.h" |
| 14 #include "chrome/browser/geolocation/geolocation_content_settings_map.h" | |
| 15 #include "chrome/browser/geolocation/geolocation_exceptions_table_model.h" | |
| 16 #include "grit/generated_resources.h" | 14 #include "grit/generated_resources.h" |
| 17 #include "third_party/GTM/AppKit/GTMUILocalizerAndLayoutTweaker.h" | 15 #include "third_party/GTM/AppKit/GTMUILocalizerAndLayoutTweaker.h" |
| 18 | 16 |
| 19 @interface GeolocationExceptionsWindowController (Private) | 17 @interface SimpleContentExceptionsWindowController (Private) |
| 20 - (id)initWithSettingsMap:(GeolocationContentSettingsMap*)settingsMap; | 18 - (id)initWithTableModel:(RemoveRowsTableModel*)model; |
| 21 - (void)selectedRows:(GeolocationExceptionsTableModel::Rows*)rows; | 19 - (void)selectedRows:(RemoveRowsTableModel::Rows*)rows; |
| 22 - (void)adjustEditingButtons; | 20 - (void)adjustEditingButtons; |
| 23 - (void)modelDidChange; | 21 - (void)modelDidChange; |
| 24 @end | 22 @end |
| 25 | 23 |
| 26 // Observer for the geolocation table model. | 24 // Observer for a RemoveRowsTableModel. |
| 27 class GeolocationObserverBridge : public TableModelObserver { | 25 class RemoveRowsObserverBridge : public TableModelObserver { |
| 28 public: | 26 public: |
| 29 GeolocationObserverBridge(GeolocationExceptionsWindowController* controller) | 27 RemoveRowsObserverBridge(SimpleContentExceptionsWindowController* controller) |
| 30 : controller_(controller) {} | 28 : controller_(controller) {} |
| 31 virtual ~GeolocationObserverBridge() {} | 29 virtual ~RemoveRowsObserverBridge() {} |
| 32 | 30 |
| 33 virtual void OnModelChanged() { | 31 virtual void OnModelChanged() { |
| 34 [controller_ modelDidChange]; | 32 [controller_ modelDidChange]; |
| 35 } | 33 } |
| 36 virtual void OnItemsChanged(int start, int length) { | 34 virtual void OnItemsChanged(int start, int length) { |
| 37 [controller_ modelDidChange]; | 35 [controller_ modelDidChange]; |
| 38 } | 36 } |
| 39 virtual void OnItemsAdded(int start, int length) { | 37 virtual void OnItemsAdded(int start, int length) { |
| 40 [controller_ modelDidChange]; | 38 [controller_ modelDidChange]; |
| 41 } | 39 } |
| 42 virtual void OnItemsRemoved(int start, int length) { | 40 virtual void OnItemsRemoved(int start, int length) { |
| 43 [controller_ modelDidChange]; | 41 [controller_ modelDidChange]; |
| 44 } | 42 } |
| 45 | 43 |
| 46 private: | 44 private: |
| 47 GeolocationExceptionsWindowController* controller_; // weak | 45 SimpleContentExceptionsWindowController* controller_; // weak |
| 48 }; | 46 }; |
| 49 | 47 |
| 50 namespace { | 48 namespace { |
| 51 | 49 |
| 52 const CGFloat kButtonBarHeight = 35.0; | 50 const CGFloat kButtonBarHeight = 35.0; |
| 53 | 51 |
| 54 GeolocationExceptionsWindowController* g_exceptionWindow = nil; | 52 SimpleContentExceptionsWindowController* g_exceptionWindow = nil; |
| 55 | 53 |
| 56 } // namespace | 54 } // namespace |
| 57 | 55 |
| 58 @implementation GeolocationExceptionsWindowController | 56 @implementation SimpleContentExceptionsWindowController |
| 59 | 57 |
| 60 + (id)controllerWithSettingsMap:(GeolocationContentSettingsMap*)settingsMap { | 58 + (id)controllerWithTableModel:(RemoveRowsTableModel*)model { |
| 61 if (!g_exceptionWindow) { | 59 if (!g_exceptionWindow) { |
| 62 g_exceptionWindow = [[GeolocationExceptionsWindowController alloc] | 60 g_exceptionWindow = [[SimpleContentExceptionsWindowController alloc] |
| 63 initWithSettingsMap:settingsMap]; | 61 initWithTableModel:model]; |
| 64 } | 62 } |
| 65 return g_exceptionWindow; | 63 return g_exceptionWindow; |
| 66 } | 64 } |
| 67 | 65 |
| 68 - (id)initWithSettingsMap:(GeolocationContentSettingsMap*)settingsMap { | 66 - (id)initWithTableModel:(RemoveRowsTableModel*)model { |
| 69 NSString* nibpath = | 67 NSString* nibpath = |
| 70 [mac_util::MainAppBundle() pathForResource:@"GeolocationExceptionsWindow" | 68 [mac_util::MainAppBundle() pathForResource:@"GeolocationExceptionsWindow" |
| 71 ofType:@"nib"]; | 69 ofType:@"nib"]; |
| 72 if ((self = [super initWithWindowNibPath:nibpath owner:self])) { | 70 if ((self = [super initWithWindowNibPath:nibpath owner:self])) { |
| 73 settingsMap_ = settingsMap; | 71 model_.reset(model); |
| 74 model_.reset(new GeolocationExceptionsTableModel(settingsMap_)); | 72 tableObserver_.reset(new RemoveRowsObserverBridge(self)); |
| 75 tableObserver_.reset(new GeolocationObserverBridge(self)); | |
| 76 model_->SetObserver(tableObserver_.get()); | 73 model_->SetObserver(tableObserver_.get()); |
| 77 | 74 |
| 78 // TODO(thakis): autoremember window rect. | 75 // TODO(thakis): autoremember window rect. |
| 79 // TODO(thakis): sorting support. | 76 // TODO(thakis): sorting support. |
| 80 } | 77 } |
| 81 return self; | 78 return self; |
| 82 } | 79 } |
| 83 | 80 |
| 84 - (void)awakeFromNib { | 81 - (void)awakeFromNib { |
| 85 DCHECK([self window]); | 82 DCHECK([self window]); |
| (...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 147 contextInfo:(void*)context { | 144 contextInfo:(void*)context { |
| 148 [sheet close]; | 145 [sheet close]; |
| 149 [sheet orderOut:self]; | 146 [sheet orderOut:self]; |
| 150 } | 147 } |
| 151 | 148 |
| 152 - (IBAction)closeSheet:(id)sender { | 149 - (IBAction)closeSheet:(id)sender { |
| 153 [NSApp endSheet:[self window]]; | 150 [NSApp endSheet:[self window]]; |
| 154 } | 151 } |
| 155 | 152 |
| 156 - (IBAction)removeRow:(id)sender { | 153 - (IBAction)removeRow:(id)sender { |
| 157 GeolocationExceptionsTableModel::Rows rows; | 154 RemoveRowsTableModel::Rows rows; |
| 158 [self selectedRows:&rows]; | 155 [self selectedRows:&rows]; |
| 159 model_->RemoveRows(rows); | 156 model_->RemoveRows(rows); |
| 160 } | 157 } |
| 161 | 158 |
| 162 - (IBAction)removeAll:(id)sender { | 159 - (IBAction)removeAll:(id)sender { |
| 163 model_->RemoveAll(); | 160 model_->RemoveAll(); |
| 164 } | 161 } |
| 165 | 162 |
| 166 // Table View Data Source ----------------------------------------------------- | 163 // Table View Data Source ----------------------------------------------------- |
| 167 | 164 |
| (...skipping 21 matching lines...) Expand all Loading... |
| 189 // Table View Delegate -------------------------------------------------------- | 186 // Table View Delegate -------------------------------------------------------- |
| 190 | 187 |
| 191 // When the selection in the table view changes, we need to adjust buttons. | 188 // When the selection in the table view changes, we need to adjust buttons. |
| 192 - (void)tableViewSelectionDidChange:(NSNotification*)notification { | 189 - (void)tableViewSelectionDidChange:(NSNotification*)notification { |
| 193 [self adjustEditingButtons]; | 190 [self adjustEditingButtons]; |
| 194 } | 191 } |
| 195 | 192 |
| 196 // Private -------------------------------------------------------------------- | 193 // Private -------------------------------------------------------------------- |
| 197 | 194 |
| 198 // Returns the selected rows. | 195 // Returns the selected rows. |
| 199 - (void)selectedRows:(GeolocationExceptionsTableModel::Rows*)rows { | 196 - (void)selectedRows:(RemoveRowsTableModel::Rows*)rows { |
| 200 NSIndexSet* selection = [tableView_ selectedRowIndexes]; | 197 NSIndexSet* selection = [tableView_ selectedRowIndexes]; |
| 201 for (NSUInteger index = [selection lastIndex]; index != NSNotFound; | 198 for (NSUInteger index = [selection lastIndex]; index != NSNotFound; |
| 202 index = [selection indexLessThanIndex:index]) | 199 index = [selection indexLessThanIndex:index]) |
| 203 rows->insert(index); | 200 rows->insert(index); |
| 204 } | 201 } |
| 205 | 202 |
| 206 // This method appropriately sets the enabled states on the table's editing | 203 // This method appropriately sets the enabled states on the table's editing |
| 207 // buttons. | 204 // buttons. |
| 208 - (void)adjustEditingButtons { | 205 - (void)adjustEditingButtons { |
| 209 GeolocationExceptionsTableModel::Rows rows; | 206 RemoveRowsTableModel::Rows rows; |
| 210 [self selectedRows:&rows]; | 207 [self selectedRows:&rows]; |
| 211 [removeButton_ setEnabled:model_->CanRemoveRows(rows)]; | 208 [removeButton_ setEnabled:model_->CanRemoveRows(rows)]; |
| 212 [removeAllButton_ setEnabled:([tableView_ numberOfRows] > 0)]; | 209 [removeAllButton_ setEnabled:([tableView_ numberOfRows] > 0)]; |
| 213 } | 210 } |
| 214 | 211 |
| 215 - (void)modelDidChange { | 212 - (void)modelDidChange { |
| 216 [tableView_ reloadData]; | 213 [tableView_ reloadData]; |
| 217 [self adjustEditingButtons]; | 214 [self adjustEditingButtons]; |
| 218 } | 215 } |
| 219 | 216 |
| 220 @end | 217 @end |
| OLD | NEW |