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

Side by Side Diff: chrome/browser/ui/cocoa/extensions/shell_window_cocoa.mm

Issue 10823195: Draggable region support for frameless app window on Mac. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fix per feedback Created 8 years, 4 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 | « chrome/browser/ui/cocoa/extensions/shell_window_cocoa.h ('k') | no next file » | 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 "chrome/browser/ui/cocoa/extensions/shell_window_cocoa.h" 5 #include "chrome/browser/ui/cocoa/extensions/shell_window_cocoa.h"
6 6
7 #include "base/mac/mac_util.h" 7 #include "base/mac/mac_util.h"
8 #include "base/sys_string_conversions.h" 8 #include "base/sys_string_conversions.h"
9 #include "chrome/browser/profiles/profile.h" 9 #include "chrome/browser/profiles/profile.h"
10 #include "chrome/browser/ui/cocoa/browser_window_utils.h" 10 #include "chrome/browser/ui/cocoa/browser_window_utils.h"
(...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after
132 if (base::mac::IsOSSnowLeopardOrEarlier() && 132 if (base::mac::IsOSSnowLeopardOrEarlier() &&
133 [window respondsToSelector:@selector(setBottomCornerRounded:)]) 133 [window respondsToSelector:@selector(setBottomCornerRounded:)])
134 [window setBottomCornerRounded:NO]; 134 [window setBottomCornerRounded:NO];
135 135
136 window_controller_.reset( 136 window_controller_.reset(
137 [[ShellWindowController alloc] initWithWindow:window.release()]); 137 [[ShellWindowController alloc] initWithWindow:window.release()]);
138 138
139 NSView* view = web_contents()->GetView()->GetNativeView(); 139 NSView* view = web_contents()->GetView()->GetNativeView();
140 [view setAutoresizingMask:NSViewWidthSizable | NSViewHeightSizable]; 140 [view setAutoresizingMask:NSViewWidthSizable | NSViewHeightSizable];
141 141
142 if (!has_frame_) {
143 // TODO(jeremya): this is a temporary hack to allow moving the window while
144 // we still don't have proper draggable region support.
145 NSView* controlRegion = [[ControlRegionView alloc] init];
146 [controlRegion setFrame:NSMakeRect(0, 0, NSWidth([view bounds]),
147 NSHeight([view bounds]) - 20)];
148 [controlRegion setAutoresizingMask:
149 NSViewWidthSizable | NSViewHeightSizable];
150 [view addSubview:controlRegion];
151 [controlRegion release];
152 }
153
154 InstallView(); 142 InstallView();
155 143
156 [[window_controller_ window] setDelegate:window_controller_]; 144 [[window_controller_ window] setDelegate:window_controller_];
157 [window_controller_ setShellWindow:this]; 145 [window_controller_ setShellWindow:this];
158 } 146 }
159 147
160 void ShellWindowCocoa::InstallView() { 148 void ShellWindowCocoa::InstallView() {
161 NSView* view = web_contents()->GetView()->GetNativeView(); 149 NSView* view = web_contents()->GetView()->GetNativeView();
162 if (has_frame_) { 150 if (has_frame_) {
163 [view setFrame:[[window() contentView] bounds]]; 151 [view setFrame:[[window() contentView] bounds]];
164 [[window() contentView] addSubview:view]; 152 [[window() contentView] addSubview:view];
165 } else { 153 } else {
166 // TODO(jeremya): find a cleaner way to send this information to the 154 // TODO(jeremya): find a cleaner way to send this information to the
167 // WebContentsViewCocoa view. 155 // WebContentsViewCocoa view.
168 DCHECK([view 156 DCHECK([view
169 respondsToSelector:@selector(setMouseDownCanMoveWindow:)]); 157 respondsToSelector:@selector(setMouseDownCanMoveWindow:)]);
170 [view setMouseDownCanMoveWindow:YES]; 158 [view setMouseDownCanMoveWindow:YES];
171 159
172 NSView* frameView = [[window() contentView] superview]; 160 NSView* frameView = [[window() contentView] superview];
173 [view setFrame:[frameView bounds]]; 161 [view setFrame:[frameView bounds]];
174 [frameView addSubview:view]; 162 [frameView addSubview:view];
175 163
176 [[window() standardWindowButton:NSWindowZoomButton] setHidden:YES]; 164 [[window() standardWindowButton:NSWindowZoomButton] setHidden:YES];
177 [[window() standardWindowButton:NSWindowMiniaturizeButton] setHidden:YES]; 165 [[window() standardWindowButton:NSWindowMiniaturizeButton] setHidden:YES];
178 [[window() standardWindowButton:NSWindowCloseButton] setHidden:YES]; 166 [[window() standardWindowButton:NSWindowCloseButton] setHidden:YES];
167
168 InstallDraggableRegionViews();
179 } 169 }
180 } 170 }
181 171
182 void ShellWindowCocoa::UninstallView() { 172 void ShellWindowCocoa::UninstallView() {
183 NSView* view = web_contents()->GetView()->GetNativeView(); 173 NSView* view = web_contents()->GetView()->GetNativeView();
184 [view removeFromSuperview]; 174 [view removeFromSuperview];
185 } 175 }
186 176
187 bool ShellWindowCocoa::IsActive() const { 177 bool ShellWindowCocoa::IsActive() const {
188 return [window() isKeyWindow]; 178 return [window() isKeyWindow];
(...skipping 143 matching lines...) Expand 10 before | Expand all | Expand 10 after
332 NSRect cocoa_bounds = NSMakeRect(checked_bounds.x(), 0, 322 NSRect cocoa_bounds = NSMakeRect(checked_bounds.x(), 0,
333 checked_bounds.width(), 323 checked_bounds.width(),
334 checked_bounds.height()); 324 checked_bounds.height());
335 // Flip coordinates based on the primary screen. 325 // Flip coordinates based on the primary screen.
336 NSScreen* screen = [[NSScreen screens] objectAtIndex:0]; 326 NSScreen* screen = [[NSScreen screens] objectAtIndex:0];
337 cocoa_bounds.origin.y = NSHeight([screen frame]) - checked_bounds.bottom(); 327 cocoa_bounds.origin.y = NSHeight([screen frame]) - checked_bounds.bottom();
338 328
339 [window() setFrame:cocoa_bounds display:YES]; 329 [window() setFrame:cocoa_bounds display:YES];
340 } 330 }
341 331
332 void ShellWindowCocoa::UpdateDraggableRegions(
333 const std::vector<extensions::DraggableRegion>& regions) {
334 // Draggable region is not supported for non-frameless window.
335 if (has_frame_)
336 return;
337
338 draggable_regions_ = regions;
339 InstallDraggableRegionViews();
340 }
341
342 void ShellWindowCocoa::InstallDraggableRegionViews() {
343 DCHECK(!has_frame_);
344
345 // All ControlRegionViews should be added as children of the WebContentsView,
346 // because WebContentsView will be removed and re-added when entering and
347 // leaving fullscreen mode.
348 NSView* contentView = web_contents()->GetView()->GetNativeView();
jeremya 2012/08/09 00:16:44 nit: perhaps call this webView to avoid confusion
jianli 2012/08/09 00:29:27 Done.
349 int contentHeight = NSHeight([contentView bounds]);
350
351 // Remove all ControlRegionViews that are added last time.
352 // Note that we need to copy subviews because [contentView subviews] returns
353 // the view's mutable internal array and we do not want to mutate the array
354 // while enumerating it.
355 NSArray* subviews = [[contentView subviews] copy];
356 for (NSView* subview in subviews) {
357 if ([subview isKindOfClass:[ControlRegionView class]]) {
358 [subview setHidden:YES];
jeremya 2012/08/09 00:16:44 curious: why do we need to setHidden here?
jianli 2012/08/09 00:29:27 Some sample code uses it before removing the view.
359 [subview removeFromSuperview];
360 }
361 }
362 [subviews release];
363
364 // Create and add ControlRegionView for each region that needs to be excluded
365 // from the dragging.
366 for (std::vector<extensions::DraggableRegion>::const_iterator iter =
367 draggable_regions_.begin();
368 iter != draggable_regions_.end(); ++iter) {
369 const extensions::DraggableRegion& region = *iter;
370 scoped_nsobject<NSView> controlRegion([[ControlRegionView alloc] init]);
371 [controlRegion setFrame:NSMakeRect(region.bounds.x(),
372 contentHeight - region.bounds.bottom(),
373 region.bounds.width(),
374 region.bounds.height())];
375 [contentView addSubview:controlRegion];
376 }
377 }
378
342 void ShellWindowCocoa::FlashFrame(bool flash) { 379 void ShellWindowCocoa::FlashFrame(bool flash) {
343 if (flash) { 380 if (flash) {
344 attention_request_id_ = [NSApp requestUserAttention:NSInformationalRequest]; 381 attention_request_id_ = [NSApp requestUserAttention:NSInformationalRequest];
345 } else { 382 } else {
346 [NSApp cancelUserAttentionRequest:attention_request_id_]; 383 [NSApp cancelUserAttentionRequest:attention_request_id_];
347 attention_request_id_ = 0; 384 attention_request_id_ = 0;
348 } 385 }
349 } 386 }
350 387
351 bool ShellWindowCocoa::IsAlwaysOnTop() const { 388 bool ShellWindowCocoa::IsAlwaysOnTop() const {
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
385 return [window_controller_ window]; 422 return [window_controller_ window];
386 } 423 }
387 424
388 // static 425 // static
389 ShellWindow* ShellWindow::CreateImpl(Profile* profile, 426 ShellWindow* ShellWindow::CreateImpl(Profile* profile,
390 const extensions::Extension* extension, 427 const extensions::Extension* extension,
391 const GURL& url, 428 const GURL& url,
392 const ShellWindow::CreateParams& params) { 429 const ShellWindow::CreateParams& params) {
393 return new ShellWindowCocoa(profile, extension, url, params); 430 return new ShellWindowCocoa(profile, extension, url, params);
394 } 431 }
OLDNEW
« no previous file with comments | « chrome/browser/ui/cocoa/extensions/shell_window_cocoa.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698