| OLD | NEW |
| 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 212 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 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 } | 231 } |
| 232 | 232 |
| 233 - (NSBezierPath*)windowMask { |
| 234 return windowMask_.get(); |
| 235 } |
| 236 |
| 233 - (void)processCapturedMouseEvent:(NSEvent*)theEvent { | 237 - (void)processCapturedMouseEvent:(NSEvent*)theEvent { |
| 234 if (!hostedView_) | 238 if (!hostedView_) |
| 235 return; | 239 return; |
| 236 | 240 |
| 237 NSWindow* source = [theEvent window]; | 241 NSWindow* source = [theEvent window]; |
| 238 NSWindow* target = [self window]; | 242 NSWindow* target = [self window]; |
| 239 DCHECK(target); | 243 DCHECK(target); |
| 240 | 244 |
| 241 // If it's the view's window, process normally. | 245 // If it's the view's window, process normally. |
| 242 if ([target isEqual:source]) { | 246 if ([target isEqual:source]) { |
| (...skipping 18 matching lines...) Expand all Loading... |
| 261 if (!view->GetTooltipText(viewPoint, &newTooltipText)) | 265 if (!view->GetTooltipText(viewPoint, &newTooltipText)) |
| 262 DCHECK(newTooltipText.empty()); | 266 DCHECK(newTooltipText.empty()); |
| 263 } | 267 } |
| 264 if (newTooltipText != lastTooltipText_) { | 268 if (newTooltipText != lastTooltipText_) { |
| 265 std::swap(newTooltipText, lastTooltipText_); | 269 std::swap(newTooltipText, lastTooltipText_); |
| 266 [self setToolTipAtMousePoint:base::SysUTF16ToNSString(lastTooltipText_)]; | 270 [self setToolTipAtMousePoint:base::SysUTF16ToNSString(lastTooltipText_)]; |
| 267 } | 271 } |
| 268 } | 272 } |
| 269 | 273 |
| 270 - (void)updateWindowMask { | 274 - (void)updateWindowMask { |
| 271 DCHECK(![self inLiveResize]); | |
| 272 DCHECK(base::mac::IsOSMavericksOrEarlier()); | |
| 273 DCHECK(hostedView_); | 275 DCHECK(hostedView_); |
| 274 | 276 |
| 275 views::Widget* widget = hostedView_->GetWidget(); | 277 views::Widget* widget = hostedView_->GetWidget(); |
| 276 if (!widget->non_client_view()) | 278 if (!widget->non_client_view()) |
| 277 return; | 279 return; |
| 278 | 280 |
| 279 const NSRect frameRect = [self bounds]; | 281 const NSRect frameRect = [self bounds]; |
| 280 gfx::Path mask; | 282 gfx::Path mask; |
| 281 widget->non_client_view()->GetWindowMask(gfx::Size(frameRect.size), &mask); | 283 widget->non_client_view()->GetWindowMask(gfx::Size(frameRect.size), &mask); |
| 282 if (mask.isEmpty()) | 284 if (mask.isEmpty()) |
| (...skipping 145 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 428 [super setFrameSize:newSize]; | 430 [super setFrameSize:newSize]; |
| 429 if (!hostedView_) | 431 if (!hostedView_) |
| 430 return; | 432 return; |
| 431 | 433 |
| 432 hostedView_->SetSize(gfx::Size(newSize.width, newSize.height)); | 434 hostedView_->SetSize(gfx::Size(newSize.width, newSize.height)); |
| 433 } | 435 } |
| 434 | 436 |
| 435 - (void)viewDidEndLiveResize { | 437 - (void)viewDidEndLiveResize { |
| 436 [super viewDidEndLiveResize]; | 438 [super viewDidEndLiveResize]; |
| 437 | 439 |
| 438 // We prevent updating the window mask and clipping the border around the | 440 // 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 | 441 // is required to generate drop shadows on OSX 10.9. Hence redraw the view |
| 440 // view after resize has completed. | 442 // after resize has completed. |
| 441 if (base::mac::IsOSMavericksOrEarlier()) { | 443 if (base::mac::IsOSMavericksOrEarlier()) |
| 442 [self updateWindowMask]; | |
| 443 [self setNeedsDisplay:YES]; | 444 [self setNeedsDisplay:YES]; |
| 444 } | |
| 445 } | 445 } |
| 446 | 446 |
| 447 - (void)drawRect:(NSRect)dirtyRect { | 447 - (void)drawRect:(NSRect)dirtyRect { |
| 448 // Note that BridgedNativeWidget uses -[NSWindow setAutodisplay:NO] to | 448 // Note that BridgedNativeWidget uses -[NSWindow setAutodisplay:NO] to |
| 449 // suppress calls to this when the window is known to be hidden. | 449 // suppress calls to this when the window is known to be hidden. |
| 450 if (!hostedView_) | 450 if (!hostedView_) |
| 451 return; | 451 return; |
| 452 | 452 |
| 453 if (drawMenuBackgroundForBlur_) { | 453 if (drawMenuBackgroundForBlur_) { |
| 454 const CGFloat radius = views::MenuConfig::instance().corner_radius; | 454 const CGFloat radius = views::MenuConfig::instance().corner_radius; |
| 455 [skia::SkColorToSRGBNSColor(0x01000000) set]; | 455 [skia::SkColorToSRGBNSColor(0x01000000) set]; |
| 456 [[NSBezierPath bezierPathWithRoundedRect:[self bounds] | 456 [[NSBezierPath bezierPathWithRoundedRect:[self bounds] |
| 457 xRadius:radius | 457 xRadius:radius |
| 458 yRadius:radius] fill]; | 458 yRadius:radius] fill]; |
| 459 } | 459 } |
| 460 | 460 |
| 461 // On OS versions earlier than Yosemite, to generate a drop shadow, we set an | 461 // 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 | 462 // opaque background. This causes windows with non rectangular shapes to have |
| 463 // square corners. To get around this, fill the path outside the window | 463 // square corners. To get around this, fill the path outside the window |
| 464 // boundary with clearColor and tell Cococa to regenerate drop shadow. See | 464 // boundary with clearColor and tell Cococa to regenerate drop shadow. See |
| 465 // crbug.com/543671. | 465 // crbug.com/543671. |
| 466 if (windowMask_ && ![self inLiveResize] && | 466 if (windowMask_ && ![self inLiveResize] && |
| 467 !IsRectInsidePath(dirtyRect, windowMask_)) { | 467 !IsRectInsidePath(dirtyRect, windowMask_) && |
| 468 DCHECK(base::mac::IsOSMavericksOrEarlier()); | 468 base::mac::IsOSMavericksOrEarlier()) { |
| 469 gfx::ScopedNSGraphicsContextSaveGState state; | 469 gfx::ScopedNSGraphicsContextSaveGState state; |
| 470 | 470 |
| 471 // The outer rectangular path corresponding to the window. | 471 // The outer rectangular path corresponding to the window. |
| 472 NSBezierPath* outerPath = [NSBezierPath bezierPathWithRect:[self bounds]]; | 472 NSBezierPath* outerPath = [NSBezierPath bezierPathWithRect:[self bounds]]; |
| 473 | 473 |
| 474 [outerPath appendBezierPath:windowMask_]; | 474 [outerPath appendBezierPath:windowMask_]; |
| 475 [outerPath setWindingRule:NSEvenOddWindingRule]; | 475 [outerPath setWindingRule:NSEvenOddWindingRule]; |
| 476 [[NSGraphicsContext currentContext] | 476 [[NSGraphicsContext currentContext] |
| 477 setCompositingOperation:NSCompositeCopy]; | 477 setCompositingOperation:NSCompositeCopy]; |
| 478 [[NSColor clearColor] set]; | 478 [[NSColor clearColor] set]; |
| (...skipping 425 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 904 } | 904 } |
| 905 | 905 |
| 906 return [super accessibilityAttributeValue:attribute]; | 906 return [super accessibilityAttributeValue:attribute]; |
| 907 } | 907 } |
| 908 | 908 |
| 909 - (id)accessibilityHitTest:(NSPoint)point { | 909 - (id)accessibilityHitTest:(NSPoint)point { |
| 910 return [hostedView_->GetNativeViewAccessible() accessibilityHitTest:point]; | 910 return [hostedView_->GetNativeViewAccessible() accessibilityHitTest:point]; |
| 911 } | 911 } |
| 912 | 912 |
| 913 @end | 913 @end |
| OLD | NEW |