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

Side by Side Diff: ui/views/cocoa/bridged_content_view.mm

Issue 1718043003: MacViews: Clip contents for non-rectangular windows. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Addressed review comments. Created 4 years, 9 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
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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 "ui/views/cocoa/bridged_content_view.h" 5 #import "ui/views/cocoa/bridged_content_view.h"
6 6
7 #include "base/logging.h" 7 #include "base/logging.h"
8 #import "base/mac/mac_util.h" 8 #import "base/mac/mac_util.h"
9 #import "base/mac/scoped_nsobject.h" 9 #import "base/mac/scoped_nsobject.h"
10 #include "base/strings/sys_string_conversions.h" 10 #include "base/strings/sys_string_conversions.h"
(...skipping 210 matching lines...) Expand 10 before | Expand all | Expand 10 after
221 [self addTrackingArea:cursorTrackingArea_.get()]; 221 [self addTrackingArea:cursorTrackingArea_.get()];
222 } 222 }
223 return self; 223 return self;
224 } 224 }
225 225
226 - (void)clearView { 226 - (void)clearView {
227 textInputClient_ = nullptr; 227 textInputClient_ = nullptr;
228 hostedView_ = nullptr; 228 hostedView_ = nullptr;
229 [cursorTrackingArea_.get() clearOwner]; 229 [cursorTrackingArea_.get() clearOwner];
230 [self removeTrackingArea:cursorTrackingArea_.get()]; 230 [self removeTrackingArea:cursorTrackingArea_.get()];
231 windowMask_.reset();
tapted 2016/02/25 08:07:21 is this needed here? (i.e. was it to fix an error?
karandeepb 2016/03/04 03:01:55 Not really. This is called here - https://code.goo
tapted 2016/03/04 04:15:01 That shouldn't be necessary - if windowMask_ refer
231 } 232 }
232 233
233 - (void)processCapturedMouseEvent:(NSEvent*)theEvent { 234 - (void)processCapturedMouseEvent:(NSEvent*)theEvent {
234 if (!hostedView_) 235 if (!hostedView_)
235 return; 236 return;
236 237
237 NSWindow* source = [theEvent window]; 238 NSWindow* source = [theEvent window];
238 NSWindow* target = [self window]; 239 NSWindow* target = [self window];
239 DCHECK(target); 240 DCHECK(target);
240 241
(...skipping 20 matching lines...) Expand all
261 if (!view->GetTooltipText(viewPoint, &newTooltipText)) 262 if (!view->GetTooltipText(viewPoint, &newTooltipText))
262 DCHECK(newTooltipText.empty()); 263 DCHECK(newTooltipText.empty());
263 } 264 }
264 if (newTooltipText != lastTooltipText_) { 265 if (newTooltipText != lastTooltipText_) {
265 std::swap(newTooltipText, lastTooltipText_); 266 std::swap(newTooltipText, lastTooltipText_);
266 [self setToolTipAtMousePoint:base::SysUTF16ToNSString(lastTooltipText_)]; 267 [self setToolTipAtMousePoint:base::SysUTF16ToNSString(lastTooltipText_)];
267 } 268 }
268 } 269 }
269 270
270 - (void)updateWindowMask { 271 - (void)updateWindowMask {
271 DCHECK(![self inLiveResize]);
272 DCHECK(base::mac::IsOSMavericksOrEarlier());
273 DCHECK(hostedView_); 272 DCHECK(hostedView_);
274 273
275 views::Widget* widget = hostedView_->GetWidget(); 274 views::Widget* widget = hostedView_->GetWidget();
276 if (!widget->non_client_view()) 275 if (!widget->non_client_view())
277 return; 276 return;
278 277
279 const NSRect frameRect = [self bounds]; 278 const NSRect frameRect = [self bounds];
280 gfx::Path mask; 279 gfx::Path mask;
281 widget->non_client_view()->GetWindowMask(gfx::Size(frameRect.size), &mask); 280 widget->non_client_view()->GetWindowMask(gfx::Size(frameRect.size), &mask);
282 if (mask.isEmpty()) 281 if (mask.isEmpty())
283 return; 282 return;
284 283
285 windowMask_.reset([gfx::CreateNSBezierPathFromSkPath(mask) retain]); 284 windowMask_.reset([gfx::CreateNSBezierPathFromSkPath(mask) retain]);
286 285
287 // Convert to AppKit coordinate system. 286 // Convert to AppKit coordinate system.
288 NSAffineTransform* flipTransform = [NSAffineTransform transform]; 287 NSAffineTransform* flipTransform = [NSAffineTransform transform];
289 [flipTransform translateXBy:0.0 yBy:frameRect.size.height]; 288 [flipTransform translateXBy:0.0 yBy:frameRect.size.height];
290 [flipTransform scaleXBy:1.0 yBy:-1.0]; 289 [flipTransform scaleXBy:1.0 yBy:-1.0];
291 [windowMask_ transformUsingAffineTransform:flipTransform]; 290 [windowMask_ transformUsingAffineTransform:flipTransform];
292 } 291 }
293 292
293 - (NSBezierPath*)windowMask {
tapted 2016/02/25 08:07:21 nit: move up beneath clearView, since it roughly m
karandeepb 2016/03/04 03:01:56 Done.
294 return windowMask_.get();
295 }
296
294 // BridgedContentView private implementation. 297 // BridgedContentView private implementation.
295 298
296 - (void)handleKeyEvent:(NSEvent*)theEvent { 299 - (void)handleKeyEvent:(NSEvent*)theEvent {
297 if (!hostedView_) 300 if (!hostedView_)
298 return; 301 return;
299 302
300 DCHECK(theEvent); 303 DCHECK(theEvent);
301 ui::KeyEvent event(theEvent); 304 ui::KeyEvent event(theEvent);
302 if (DispatchEventToMenu(hostedView_->GetWidget(), event.key_code())) 305 if (DispatchEventToMenu(hostedView_->GetWidget(), event.key_code()))
303 return; 306 return;
(...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after
428 [super setFrameSize:newSize]; 431 [super setFrameSize:newSize];
429 if (!hostedView_) 432 if (!hostedView_)
430 return; 433 return;
431 434
432 hostedView_->SetSize(gfx::Size(newSize.width, newSize.height)); 435 hostedView_->SetSize(gfx::Size(newSize.width, newSize.height));
433 } 436 }
434 437
435 - (void)viewDidEndLiveResize { 438 - (void)viewDidEndLiveResize {
436 [super viewDidEndLiveResize]; 439 [super viewDidEndLiveResize];
437 440
438 // We prevent updating the window mask and clipping the border around the 441 // During a live resize, we prevent clipping the border around the view, which
439 // view, during a live resize. Hence update the window mask and redraw the 442 // is required to generate drop shadows on OSX 10.9. Hence redraw the view
440 // view after resize has completed. 443 // after resize has completed.
441 if (base::mac::IsOSMavericksOrEarlier()) { 444 if (base::mac::IsOSMavericksOrEarlier())
442 [self updateWindowMask];
443 [self setNeedsDisplay:YES]; 445 [self setNeedsDisplay:YES];
444 }
445 } 446 }
446 447
447 - (void)drawRect:(NSRect)dirtyRect { 448 - (void)drawRect:(NSRect)dirtyRect {
448 // Note that BridgedNativeWidget uses -[NSWindow setAutodisplay:NO] to 449 // Note that BridgedNativeWidget uses -[NSWindow setAutodisplay:NO] to
449 // suppress calls to this when the window is known to be hidden. 450 // suppress calls to this when the window is known to be hidden.
450 if (!hostedView_) 451 if (!hostedView_)
451 return; 452 return;
452 453
453 if (drawMenuBackgroundForBlur_) { 454 if (drawMenuBackgroundForBlur_) {
454 const CGFloat radius = views::MenuConfig::instance().corner_radius; 455 const CGFloat radius = views::MenuConfig::instance().corner_radius;
455 [skia::SkColorToSRGBNSColor(0x01000000) set]; 456 [skia::SkColorToSRGBNSColor(0x01000000) set];
456 [[NSBezierPath bezierPathWithRoundedRect:[self bounds] 457 [[NSBezierPath bezierPathWithRoundedRect:[self bounds]
457 xRadius:radius 458 xRadius:radius
458 yRadius:radius] fill]; 459 yRadius:radius] fill];
459 } 460 }
460 461
461 // On OS versions earlier than Yosemite, to generate a drop shadow, we set an 462 // On OS versions earlier than Yosemite, to generate a drop shadow, we set an
462 // opaque background. This causes windows with non rectangular shapes to have 463 // opaque background. This causes windows with non rectangular shapes to have
463 // square corners. To get around this, fill the path outside the window 464 // square corners. To get around this, fill the path outside the window
464 // boundary with clearColor and tell Cococa to regenerate drop shadow. See 465 // boundary with clearColor and tell Cococa to regenerate drop shadow. See
465 // crbug.com/543671. 466 // crbug.com/543671.
466 if (windowMask_ && ![self inLiveResize] && 467 if (windowMask_ && ![self inLiveResize] &&
467 !IsRectInsidePath(dirtyRect, windowMask_)) { 468 !IsRectInsidePath(dirtyRect, windowMask_) &&
468 DCHECK(base::mac::IsOSMavericksOrEarlier()); 469 base::mac::IsOSMavericksOrEarlier()) {
469 gfx::ScopedNSGraphicsContextSaveGState state; 470 gfx::ScopedNSGraphicsContextSaveGState state;
470 471
471 // The outer rectangular path corresponding to the window. 472 // The outer rectangular path corresponding to the window.
472 NSBezierPath* outerPath = [NSBezierPath bezierPathWithRect:[self bounds]]; 473 NSBezierPath* outerPath = [NSBezierPath bezierPathWithRect:[self bounds]];
473 474
474 [outerPath appendBezierPath:windowMask_]; 475 [outerPath appendBezierPath:windowMask_];
475 [outerPath setWindingRule:NSEvenOddWindingRule]; 476 [outerPath setWindingRule:NSEvenOddWindingRule];
476 [[NSGraphicsContext currentContext] 477 [[NSGraphicsContext currentContext]
477 setCompositingOperation:NSCompositeCopy]; 478 setCompositingOperation:NSCompositeCopy];
478 [[NSColor clearColor] set]; 479 [[NSColor clearColor] set];
(...skipping 425 matching lines...) Expand 10 before | Expand all | Expand 10 after
904 } 905 }
905 906
906 return [super accessibilityAttributeValue:attribute]; 907 return [super accessibilityAttributeValue:attribute];
907 } 908 }
908 909
909 - (id)accessibilityHitTest:(NSPoint)point { 910 - (id)accessibilityHitTest:(NSPoint)point {
910 return [hostedView_->GetNativeViewAccessible() accessibilityHitTest:point]; 911 return [hostedView_->GetNativeViewAccessible() accessibilityHitTest:point];
911 } 912 }
912 913
913 @end 914 @end
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698