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

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: Added a comment. 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();
232 }
233
234 - (NSBezierPath*)windowMask {
235 return windowMask_.get();
231 } 236 }
232 237
233 - (void)processCapturedMouseEvent:(NSEvent*)theEvent { 238 - (void)processCapturedMouseEvent:(NSEvent*)theEvent {
234 if (!hostedView_) 239 if (!hostedView_)
235 return; 240 return;
236 241
237 NSWindow* source = [theEvent window]; 242 NSWindow* source = [theEvent window];
238 NSWindow* target = [self window]; 243 NSWindow* target = [self window];
239 DCHECK(target); 244 DCHECK(target);
240 245
(...skipping 20 matching lines...) Expand all
261 if (!view->GetTooltipText(viewPoint, &newTooltipText)) 266 if (!view->GetTooltipText(viewPoint, &newTooltipText))
262 DCHECK(newTooltipText.empty()); 267 DCHECK(newTooltipText.empty());
263 } 268 }
264 if (newTooltipText != lastTooltipText_) { 269 if (newTooltipText != lastTooltipText_) {
265 std::swap(newTooltipText, lastTooltipText_); 270 std::swap(newTooltipText, lastTooltipText_);
266 [self setToolTipAtMousePoint:base::SysUTF16ToNSString(lastTooltipText_)]; 271 [self setToolTipAtMousePoint:base::SysUTF16ToNSString(lastTooltipText_)];
267 } 272 }
268 } 273 }
269 274
270 - (void)updateWindowMask { 275 - (void)updateWindowMask {
271 DCHECK(![self inLiveResize]);
272 DCHECK(base::mac::IsOSMavericksOrEarlier());
273 DCHECK(hostedView_); 276 DCHECK(hostedView_);
274 277
275 views::Widget* widget = hostedView_->GetWidget(); 278 views::Widget* widget = hostedView_->GetWidget();
276 if (!widget->non_client_view()) 279 if (!widget->non_client_view())
277 return; 280 return;
278 281
279 const NSRect frameRect = [self bounds]; 282 const NSRect frameRect = [self bounds];
280 gfx::Path mask; 283 gfx::Path mask;
281 widget->non_client_view()->GetWindowMask(gfx::Size(frameRect.size), &mask); 284 widget->non_client_view()->GetWindowMask(gfx::Size(frameRect.size), &mask);
282 if (mask.isEmpty()) 285 if (mask.isEmpty())
(...skipping 145 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