Index: ui/views/cocoa/bridged_content_view.mm |
diff --git a/ui/views/cocoa/bridged_content_view.mm b/ui/views/cocoa/bridged_content_view.mm |
index 56e53abe4eaf4e947ae921953083f16ada4f8924..67dd94bc06c662267be5749b858e7c49576a6445 100644 |
--- a/ui/views/cocoa/bridged_content_view.mm |
+++ b/ui/views/cocoa/bridged_content_view.mm |
@@ -5,6 +5,7 @@ |
#import "ui/views/cocoa/bridged_content_view.h" |
#include "base/logging.h" |
+#import "base/mac/mac_util.h" |
#import "base/mac/scoped_nsobject.h" |
#include "base/strings/sys_string_conversions.h" |
#include "skia/ext/skia_utils_mac.h" |
@@ -16,6 +17,9 @@ |
#import "ui/events/keycodes/keyboard_code_conversion_mac.h" |
#include "ui/gfx/canvas_paint_mac.h" |
#include "ui/gfx/geometry/rect.h" |
+#include "ui/gfx/path.h" |
+#import "ui/gfx/path_mac.h" |
+#include "ui/gfx/scoped_ns_graphics_context_save_gstate_mac.h" |
#include "ui/strings/grit/ui_strings.h" |
#include "ui/views/controls/menu/menu_config.h" |
#include "ui/views/controls/menu/menu_controller.h" |
@@ -320,13 +324,55 @@ bool DispatchEventToMenu(views::Widget* widget, ui::KeyboardCode key_code) { |
yRadius:radius] fill]; |
} |
+ views::Widget* widget = hostedView_->GetWidget(); |
+ |
+ // On OS versions earlier than Yosemite, to generate a drop shadow, we set an |
+ // opaque background. This distorts windows with non rectangular shapes. To |
+ // get around this, fill the path outside the window boundary with clearColor |
+ // and tell Cococa to regenerate drop shadow. See crbug.com/543671. |
+ // TODO(karandeepb) check how this can be optimised. |
tapted
2016/01/28 05:59:22
It might be possible to paint this directly into [
karandeepb
2016/02/04 03:39:28
Giving background_layer a background color with th
|
+ if (widget->non_client_view() && base::mac::IsOSMavericksOrEarlier()) { |
+ const NSRect frameRect = [self bounds]; |
+ gfx::Path windowMask; |
+ widget->non_client_view()->GetWindowMask(gfx::Size(frameRect.size), |
+ &windowMask); |
+ if (!windowMask.isEmpty()) { |
+ gfx::ScopedNSGraphicsContextSaveGState state; |
+ |
+ // The outer rectangular path corresponding to the window. |
+ NSBezierPath* outerPath = [NSBezierPath bezierPathWithRect:frameRect]; |
+ |
+ // Path corresponding to windowMask. This is in normal coordinate system |
+ // (origin at top left of screen). |
+ NSBezierPath* clippedPath = gfx::CreateNSBezierPathFromSkPath(windowMask); |
+ |
+ // Convert to AppKit coordinate system. |
+ NSAffineTransform* flipTransform = [NSAffineTransform transform]; |
+ [flipTransform translateXBy:0.0 yBy:frameRect.size.height]; |
+ [flipTransform scaleXBy:1.0 yBy:-1.0]; |
+ [clippedPath transformUsingAffineTransform:flipTransform]; |
+ |
+ [outerPath appendBezierPath:clippedPath]; |
+ [outerPath setWindingRule:NSEvenOddWindingRule]; |
+ [[NSGraphicsContext currentContext] |
+ setCompositingOperation:NSCompositeCopy]; |
+ [[NSColor clearColor] set]; |
+ |
+ // Fill the region between clippedPath and its outer rectangular path with |
+ // clear color. This causes the window to have the shape described by |
+ // clippedPath. |
+ [outerPath fill]; |
+ // Regerate drop shadow around the window boundary. |
+ [[self window] invalidateShadow]; |
+ } |
+ } |
+ |
// If there's a layer, painting occurs in BridgedNativeWidget::OnPaintLayer(). |
- if (hostedView_->GetWidget()->GetLayer()) |
+ if (widget->GetLayer()) |
return; |
gfx::CanvasSkiaPaint canvas(dirtyRect, false /* opaque */); |
- hostedView_->GetWidget()->OnNativeWidgetPaint( |
- ui::CanvasPainter(&canvas, 1.f).context()); |
+ widget->OnNativeWidgetPaint(ui::CanvasPainter(&canvas, 1.f).context()); |
} |
- (NSTextInputContext*)inputContext { |