Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(777)

Side by Side Diff: chrome/browser/ui/cocoa/simple_content_exceptions_window_controller.mm

Issue 6294008: [Mac] Organize some files into chrome/browser/ui/cocoa/content_settings/.... (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: Created 9 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
(Empty)
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
3 // found in the LICENSE file.
4
5 #import "chrome/browser/ui/cocoa/simple_content_exceptions_window_controller.h"
6
7 #include "app/l10n_util_mac.h"
8 #include "base/logging.h"
9 #import "base/mac/mac_util.h"
10 #import "base/scoped_nsobject.h"
11 #include "base/sys_string_conversions.h"
12 #include "grit/generated_resources.h"
13 #include "third_party/GTM/AppKit/GTMUILocalizerAndLayoutTweaker.h"
14 #include "ui/base/models/table_model_observer.h"
15
16 @interface SimpleContentExceptionsWindowController (Private)
17 - (id)initWithTableModel:(RemoveRowsTableModel*)model;
18 @end
19
20 namespace {
21
22 const CGFloat kButtonBarHeight = 35.0;
23
24 SimpleContentExceptionsWindowController* g_exceptionWindow = nil;
25
26 } // namespace
27
28 @implementation SimpleContentExceptionsWindowController
29
30 + (id)controllerWithTableModel:(RemoveRowsTableModel*)model {
31 if (!g_exceptionWindow) {
32 g_exceptionWindow = [[SimpleContentExceptionsWindowController alloc]
33 initWithTableModel:model];
34 }
35 return g_exceptionWindow;
36 }
37
38 - (id)initWithTableModel:(RemoveRowsTableModel*)model {
39 NSString* nibpath = [base::mac::MainAppBundle()
40 pathForResource:@"SimpleContentExceptionsWindow"
41 ofType:@"nib"];
42 if ((self = [super initWithWindowNibPath:nibpath owner:self])) {
43 model_.reset(model);
44
45 // TODO(thakis): autoremember window rect.
46 // TODO(thakis): sorting support.
47 }
48 return self;
49 }
50
51 - (void)awakeFromNib {
52 DCHECK([self window]);
53 DCHECK_EQ(self, [[self window] delegate]);
54 DCHECK(tableView_);
55 DCHECK(arrayController_);
56
57 CGFloat minWidth = [[removeButton_ superview] bounds].size.width +
58 [[doneButton_ superview] bounds].size.width;
59 [[self window] setMinSize:NSMakeSize(minWidth,
60 [[self window] minSize].height)];
61 NSDictionary* columns = [NSDictionary dictionaryWithObjectsAndKeys:
62 [NSNumber numberWithInt:IDS_EXCEPTIONS_HOSTNAME_HEADER], @"hostname",
63 [NSNumber numberWithInt:IDS_EXCEPTIONS_ACTION_HEADER], @"action",
64 nil];
65 [arrayController_ bindToTableModel:model_.get()
66 withColumns:columns
67 groupTitleColumn:@"hostname"];
68 }
69
70 - (void)setMinWidth:(CGFloat)minWidth {
71 NSWindow* window = [self window];
72 [window setMinSize:NSMakeSize(minWidth, [window minSize].height)];
73 if ([window frame].size.width < minWidth) {
74 NSRect frame = [window frame];
75 frame.size.width = minWidth;
76 [window setFrame:frame display:NO];
77 }
78 }
79
80 - (void)windowWillClose:(NSNotification*)notification {
81 g_exceptionWindow = nil;
82 [self autorelease];
83 }
84
85 // Let esc close the window.
86 - (void)cancel:(id)sender {
87 [self closeSheet:self];
88 }
89
90 - (void)keyDown:(NSEvent*)event {
91 NSString* chars = [event charactersIgnoringModifiers];
92 if ([chars length] == 1) {
93 switch ([chars characterAtIndex:0]) {
94 case NSDeleteCharacter:
95 case NSDeleteFunctionKey:
96 // Delete deletes.
97 if ([[tableView_ selectedRowIndexes] count] > 0)
98 [arrayController_ remove:event];
99 return;
100 }
101 }
102 [super keyDown:event];
103 }
104
105 - (void)attachSheetTo:(NSWindow*)window {
106 [NSApp beginSheet:[self window]
107 modalForWindow:window
108 modalDelegate:self
109 didEndSelector:@selector(sheetDidEnd:returnCode:contextInfo:)
110 contextInfo:nil];
111 }
112
113 - (void)sheetDidEnd:(NSWindow*)sheet
114 returnCode:(NSInteger)returnCode
115 contextInfo:(void*)context {
116 [sheet close];
117 [sheet orderOut:self];
118 }
119
120 - (IBAction)closeSheet:(id)sender {
121 [NSApp endSheet:[self window]];
122 }
123
124
125 @end
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698