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

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

Issue 1633403002: MacViews: Add native drop shadow to dialogs on OSX < 10.10. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 10 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/scoped_nsobject.h" 9 #import "base/mac/scoped_nsobject.h"
9 #include "base/strings/sys_string_conversions.h" 10 #include "base/strings/sys_string_conversions.h"
10 #include "skia/ext/skia_utils_mac.h" 11 #include "skia/ext/skia_utils_mac.h"
11 #include "ui/base/ime/input_method.h" 12 #include "ui/base/ime/input_method.h"
12 #include "ui/base/ime/text_input_client.h" 13 #include "ui/base/ime/text_input_client.h"
13 #include "ui/compositor/canvas_painter.h" 14 #include "ui/compositor/canvas_painter.h"
14 #import "ui/events/cocoa/cocoa_event_utils.h" 15 #import "ui/events/cocoa/cocoa_event_utils.h"
15 #include "ui/events/keycodes/dom/dom_code.h" 16 #include "ui/events/keycodes/dom/dom_code.h"
16 #import "ui/events/keycodes/keyboard_code_conversion_mac.h" 17 #import "ui/events/keycodes/keyboard_code_conversion_mac.h"
17 #include "ui/gfx/canvas_paint_mac.h" 18 #include "ui/gfx/canvas_paint_mac.h"
18 #include "ui/gfx/geometry/rect.h" 19 #include "ui/gfx/geometry/rect.h"
20 #include "ui/gfx/path.h"
21 #import "ui/gfx/path_mac.h"
22 #include "ui/gfx/scoped_ns_graphics_context_save_gstate_mac.h"
19 #include "ui/strings/grit/ui_strings.h" 23 #include "ui/strings/grit/ui_strings.h"
20 #include "ui/views/controls/menu/menu_config.h" 24 #include "ui/views/controls/menu/menu_config.h"
21 #include "ui/views/controls/menu/menu_controller.h" 25 #include "ui/views/controls/menu/menu_controller.h"
22 #include "ui/views/view.h" 26 #include "ui/views/view.h"
23 #include "ui/views/widget/widget.h" 27 #include "ui/views/widget/widget.h"
24 28
25 using views::MenuController; 29 using views::MenuController;
26 30
27 namespace { 31 namespace {
28 32
(...skipping 284 matching lines...) Expand 10 before | Expand all | Expand 10 after
313 return; 317 return;
314 318
315 if (drawMenuBackgroundForBlur_) { 319 if (drawMenuBackgroundForBlur_) {
316 const CGFloat radius = views::MenuConfig::instance().corner_radius; 320 const CGFloat radius = views::MenuConfig::instance().corner_radius;
317 [skia::SkColorToSRGBNSColor(0x01000000) set]; 321 [skia::SkColorToSRGBNSColor(0x01000000) set];
318 [[NSBezierPath bezierPathWithRoundedRect:[self bounds] 322 [[NSBezierPath bezierPathWithRoundedRect:[self bounds]
319 xRadius:radius 323 xRadius:radius
320 yRadius:radius] fill]; 324 yRadius:radius] fill];
321 } 325 }
322 326
327 views::Widget* widget = hostedView_->GetWidget();
328
329 // On OS versions earlier than Yosemite, to generate a drop shadow, we set an
330 // opaque background. This distorts windows with non rectangular shapes. To
331 // get around this, fill the path outside the window boundary with clearColor
332 // and tell Cococa to regenerate drop shadow. See crbug.com/543671.
333 // 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
334 if (widget->non_client_view() && base::mac::IsOSMavericksOrEarlier()) {
335 const NSRect frameRect = [self bounds];
336 gfx::Path windowMask;
337 widget->non_client_view()->GetWindowMask(gfx::Size(frameRect.size),
338 &windowMask);
339 if (!windowMask.isEmpty()) {
340 gfx::ScopedNSGraphicsContextSaveGState state;
341
342 // The outer rectangular path corresponding to the window.
343 NSBezierPath* outerPath = [NSBezierPath bezierPathWithRect:frameRect];
344
345 // Path corresponding to windowMask. This is in normal coordinate system
346 // (origin at top left of screen).
347 NSBezierPath* clippedPath = gfx::CreateNSBezierPathFromSkPath(windowMask);
348
349 // Convert to AppKit coordinate system.
350 NSAffineTransform* flipTransform = [NSAffineTransform transform];
351 [flipTransform translateXBy:0.0 yBy:frameRect.size.height];
352 [flipTransform scaleXBy:1.0 yBy:-1.0];
353 [clippedPath transformUsingAffineTransform:flipTransform];
354
355 [outerPath appendBezierPath:clippedPath];
356 [outerPath setWindingRule:NSEvenOddWindingRule];
357 [[NSGraphicsContext currentContext]
358 setCompositingOperation:NSCompositeCopy];
359 [[NSColor clearColor] set];
360
361 // Fill the region between clippedPath and its outer rectangular path with
362 // clear color. This causes the window to have the shape described by
363 // clippedPath.
364 [outerPath fill];
365 // Regerate drop shadow around the window boundary.
366 [[self window] invalidateShadow];
367 }
368 }
369
323 // If there's a layer, painting occurs in BridgedNativeWidget::OnPaintLayer(). 370 // If there's a layer, painting occurs in BridgedNativeWidget::OnPaintLayer().
324 if (hostedView_->GetWidget()->GetLayer()) 371 if (widget->GetLayer())
325 return; 372 return;
326 373
327 gfx::CanvasSkiaPaint canvas(dirtyRect, false /* opaque */); 374 gfx::CanvasSkiaPaint canvas(dirtyRect, false /* opaque */);
328 hostedView_->GetWidget()->OnNativeWidgetPaint( 375 widget->OnNativeWidgetPaint(ui::CanvasPainter(&canvas, 1.f).context());
329 ui::CanvasPainter(&canvas, 1.f).context());
330 } 376 }
331 377
332 - (NSTextInputContext*)inputContext { 378 - (NSTextInputContext*)inputContext {
333 // If the textInputClient_ does not exist, return nil since this view does not 379 // If the textInputClient_ does not exist, return nil since this view does not
334 // conform to NSTextInputClient protocol. 380 // conform to NSTextInputClient protocol.
335 if (!textInputClient_) 381 if (!textInputClient_)
336 return nil; 382 return nil;
337 383
338 // If a menu is active, and -[NSView interpretKeyEvents:] asks for the 384 // If a menu is active, and -[NSView interpretKeyEvents:] asks for the
339 // input context, return nil. This ensures the action message is sent to 385 // input context, return nil. This ensures the action message is sent to
(...skipping 395 matching lines...) Expand 10 before | Expand all | Expand 10 after
735 } 781 }
736 782
737 return [super accessibilityAttributeValue:attribute]; 783 return [super accessibilityAttributeValue:attribute];
738 } 784 }
739 785
740 - (id)accessibilityHitTest:(NSPoint)point { 786 - (id)accessibilityHitTest:(NSPoint)point {
741 return [hostedView_->GetNativeViewAccessible() accessibilityHitTest:point]; 787 return [hostedView_->GetNativeViewAccessible() accessibilityHitTest:point];
742 } 788 }
743 789
744 @end 790 @end
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698