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

Side by Side Diff: content/shell/shell_mac.mm

Issue 15702006: [content shell] add support for running headless on mac (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: updates Created 7 years, 6 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
« no previous file with comments | « content/shell/shell.cc ('k') | content/shell/webkit_test_controller.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 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 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 #include "content/shell/shell.h" 5 #include "content/shell/shell.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 8
9 #include "base/logging.h" 9 #include "base/logging.h"
10 #import "base/memory/scoped_nsobject.h" 10 #import "base/memory/scoped_nsobject.h"
(...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after
123 123
124 namespace content { 124 namespace content {
125 125
126 void Shell::PlatformInitialize(const gfx::Size& default_window_size) { 126 void Shell::PlatformInitialize(const gfx::Size& default_window_size) {
127 } 127 }
128 128
129 void Shell::PlatformCleanUp() { 129 void Shell::PlatformCleanUp() {
130 } 130 }
131 131
132 void Shell::PlatformEnableUIControl(UIControl control, bool is_enabled) { 132 void Shell::PlatformEnableUIControl(UIControl control, bool is_enabled) {
133 if (headless_)
134 return;
135
133 int id; 136 int id;
134 switch (control) { 137 switch (control) {
135 case BACK_BUTTON: 138 case BACK_BUTTON:
136 id = IDC_NAV_BACK; 139 id = IDC_NAV_BACK;
137 break; 140 break;
138 case FORWARD_BUTTON: 141 case FORWARD_BUTTON:
139 id = IDC_NAV_FORWARD; 142 id = IDC_NAV_FORWARD;
140 break; 143 break;
141 case STOP_BUTTON: 144 case STOP_BUTTON:
142 id = IDC_NAV_STOP; 145 id = IDC_NAV_STOP;
143 break; 146 break;
144 default: 147 default:
145 NOTREACHED() << "Unknown UI control"; 148 NOTREACHED() << "Unknown UI control";
146 return; 149 return;
147 } 150 }
148 [[[window_ contentView] viewWithTag:id] setEnabled:is_enabled]; 151 [[[window_ contentView] viewWithTag:id] setEnabled:is_enabled];
149 } 152 }
150 153
151 void Shell::PlatformSetAddressBarURL(const GURL& url) { 154 void Shell::PlatformSetAddressBarURL(const GURL& url) {
155 if (headless_)
156 return;
157
152 NSString* url_string = base::SysUTF8ToNSString(url.spec()); 158 NSString* url_string = base::SysUTF8ToNSString(url.spec());
153 [url_edit_view_ setStringValue:url_string]; 159 [url_edit_view_ setStringValue:url_string];
154 } 160 }
155 161
156 void Shell::PlatformSetIsLoading(bool loading) { 162 void Shell::PlatformSetIsLoading(bool loading) {
157 } 163 }
158 164
159 void Shell::PlatformCreateWindow(int width, int height) { 165 void Shell::PlatformCreateWindow(int width, int height) {
166 if (headless_)
167 return;
168
160 NSRect initial_window_bounds = 169 NSRect initial_window_bounds =
161 NSMakeRect(0, 0, width, height + kURLBarHeight); 170 NSMakeRect(0, 0, width, height + kURLBarHeight);
162 NSRect content_rect = initial_window_bounds; 171 NSRect content_rect = initial_window_bounds;
163 NSUInteger style_mask = NSTitledWindowMask | 172 NSUInteger style_mask = NSTitledWindowMask |
164 NSClosableWindowMask | 173 NSClosableWindowMask |
165 NSMiniaturizableWindowMask | 174 NSMiniaturizableWindowMask |
166 NSResizableWindowMask; 175 NSResizableWindowMask;
167 CrShellWindow* window = 176 CrShellWindow* window =
168 [[CrShellWindow alloc] initWithContentRect:content_rect 177 [[CrShellWindow alloc] initWithContentRect:content_rect
169 styleMask:style_mask 178 styleMask:style_mask
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
222 [[url_edit_view cell] setWraps:NO]; 231 [[url_edit_view cell] setWraps:NO];
223 [[url_edit_view cell] setScrollable:YES]; 232 [[url_edit_view cell] setScrollable:YES];
224 url_edit_view_ = url_edit_view.get(); 233 url_edit_view_ = url_edit_view.get();
225 234
226 // show the window 235 // show the window
227 [window_ makeKeyAndOrderFront:nil]; 236 [window_ makeKeyAndOrderFront:nil];
228 } 237 }
229 238
230 void Shell::PlatformSetContents() { 239 void Shell::PlatformSetContents() {
231 NSView* web_view = web_contents_->GetView()->GetNativeView(); 240 NSView* web_view = web_contents_->GetView()->GetNativeView();
241
242 if (headless_) {
243 NSRect frame = NSMakeRect(
244 0, 0, kDefaultTestWindowWidthDip, kDefaultTestWindowHeightDip);
245 [web_view setFrame:frame];
246 [web_view setAutoresizingMask:(NSViewWidthSizable | NSViewHeightSizable)];
247 return;
248 }
249
232 NSView* content = [window_ contentView]; 250 NSView* content = [window_ contentView];
233 [content addSubview:web_view]; 251 [content addSubview:web_view];
234 252
235 NSRect frame = [content bounds]; 253 NSRect frame = [content bounds];
236 frame.size.height -= kURLBarHeight; 254 frame.size.height -= kURLBarHeight;
237 [web_view setFrame:frame]; 255 [web_view setFrame:frame];
238 [web_view setAutoresizingMask:(NSViewWidthSizable | NSViewHeightSizable)]; 256 [web_view setAutoresizingMask:(NSViewWidthSizable | NSViewHeightSizable)];
239 [web_view setNeedsDisplay:YES]; 257 [web_view setNeedsDisplay:YES];
240 } 258 }
241 259
242 void Shell::PlatformResizeSubViews() { 260 void Shell::PlatformResizeSubViews() {
243 // Not needed; subviews are bound. 261 // Not needed; subviews are bound.
244 } 262 }
245 263
246 void Shell::PlatformSetTitle(const string16& title) { 264 void Shell::PlatformSetTitle(const string16& title) {
265 if (headless_)
266 return;
267
247 NSString* title_string = base::SysUTF16ToNSString(title); 268 NSString* title_string = base::SysUTF16ToNSString(title);
248 [window_ setTitle:title_string]; 269 [window_ setTitle:title_string];
249 } 270 }
250 271
251 void Shell::Close() { 272 void Shell::Close() {
252 [window_ performClose:nil]; 273 if (headless_)
274 delete this;
275 else
276 [window_ performClose:nil];
253 } 277 }
254 278
255 void Shell::ActionPerformed(int control) { 279 void Shell::ActionPerformed(int control) {
256 switch (control) { 280 switch (control) {
257 case IDC_NAV_BACK: 281 case IDC_NAV_BACK:
258 GoBackOrForward(-1); 282 GoBackOrForward(-1);
259 break; 283 break;
260 case IDC_NAV_FORWARD: 284 case IDC_NAV_FORWARD:
261 GoBackOrForward(1); 285 GoBackOrForward(1);
262 break; 286 break;
(...skipping 27 matching lines...) Expand all
290 [[event.os_event characters] isEqual:@"l"]) { 314 [[event.os_event characters] isEqual:@"l"]) {
291 [window_ makeFirstResponder:url_edit_view_]; 315 [window_ makeFirstResponder:url_edit_view_];
292 return; 316 return;
293 } 317 }
294 318
295 [[NSApp mainMenu] performKeyEquivalent:event.os_event]; 319 [[NSApp mainMenu] performKeyEquivalent:event.os_event];
296 } 320 }
297 } 321 }
298 322
299 } // namespace content 323 } // namespace content
OLDNEW
« no previous file with comments | « content/shell/shell.cc ('k') | content/shell/webkit_test_controller.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698