Make bottom corner more round
This commit is contained in:
		
					parent
					
						
							
								89546a9c19
							
						
					
				
			
			
				commit
				
					
						935d1e142f
					
				
			
		
					 2 changed files with 80 additions and 1 deletions
				
			
		| 
						 | 
					@ -5,6 +5,8 @@
 | 
				
			||||||
#include "base/mac/scoped_nsobject.h"
 | 
					#include "base/mac/scoped_nsobject.h"
 | 
				
			||||||
#include "ui/base/cocoa/base_view.h"
 | 
					#include "ui/base/cocoa/base_view.h"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					@class CAShapeLayer;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
namespace brightray {
 | 
					namespace brightray {
 | 
				
			||||||
class InspectableWebContentsViewMac;
 | 
					class InspectableWebContentsViewMac;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
| 
						 | 
					@ -19,6 +21,9 @@ using brightray::InspectableWebContentsViewMac;
 | 
				
			||||||
  BOOL devtools_visible_;
 | 
					  BOOL devtools_visible_;
 | 
				
			||||||
  BOOL devtools_docked_;
 | 
					  BOOL devtools_docked_;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  // Weak reference to the mask of the hosted layer.
 | 
				
			||||||
 | 
					  CAShapeLayer* layerMask_;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  DevToolsContentsResizingStrategy strategy_;
 | 
					  DevToolsContentsResizingStrategy strategy_;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -1,14 +1,24 @@
 | 
				
			||||||
#include "browser/mac/bry_inspectable_web_contents_view.h"
 | 
					#include "browser/mac/bry_inspectable_web_contents_view.h"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#import <QuartzCore/QuartzCore.h>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
#include "browser/inspectable_web_contents_impl.h"
 | 
					#include "browser/inspectable_web_contents_impl.h"
 | 
				
			||||||
#include "browser/inspectable_web_contents_view_mac.h"
 | 
					#include "browser/inspectable_web_contents_view_mac.h"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
#include "content/public/browser/render_widget_host_view.h"
 | 
					#include "content/public/browser/render_widget_host_view.h"
 | 
				
			||||||
#import "ui/base/cocoa/underlay_opengl_hosting_window.h"
 | 
					#include "ui/base/cocoa/animation_utils.h"
 | 
				
			||||||
 | 
					#include "ui/base/cocoa/underlay_opengl_hosting_window.h"
 | 
				
			||||||
#include "ui/gfx/mac/scoped_ns_disable_screen_updates.h"
 | 
					#include "ui/gfx/mac/scoped_ns_disable_screen_updates.h"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
using namespace brightray;
 | 
					using namespace brightray;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					namespace {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					// The radius of the rounded corners.
 | 
				
			||||||
 | 
					const CGFloat kRoundedCornerRadius = 4;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					}  // namespace
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@implementation BRYInspectableWebContentsView
 | 
					@implementation BRYInspectableWebContentsView
 | 
				
			||||||
 | 
					
 | 
				
			||||||
- (instancetype)initWithInspectableWebContentsViewMac:(InspectableWebContentsViewMac*)view {
 | 
					- (instancetype)initWithInspectableWebContentsViewMac:(InspectableWebContentsViewMac*)view {
 | 
				
			||||||
| 
						 | 
					@ -26,8 +36,14 @@ using namespace brightray;
 | 
				
			||||||
  [self addSubview:contentsView];
 | 
					  [self addSubview:contentsView];
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  // See https://code.google.com/p/chromium/issues/detail?id=348490.
 | 
					  // See https://code.google.com/p/chromium/issues/detail?id=348490.
 | 
				
			||||||
 | 
					  ScopedCAActionDisabler disabler;
 | 
				
			||||||
 | 
					  base::scoped_nsobject<CALayer> layer([[CALayer alloc] init]);
 | 
				
			||||||
 | 
					  [self setLayer:layer];
 | 
				
			||||||
  [self setWantsLayer:YES];
 | 
					  [self setWantsLayer:YES];
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  // See https://code.google.com/p/chromium/issues/detail?id=396264.
 | 
				
			||||||
 | 
					  [self updateLayerMask];
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  return self;
 | 
					  return self;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					@ -35,6 +51,12 @@ using namespace brightray;
 | 
				
			||||||
  [self adjustSubviews];
 | 
					  [self adjustSubviews];
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					// Every time the frame's size changes, the layer mask needs to be updated.
 | 
				
			||||||
 | 
					- (void)setFrameSize:(NSSize)newSize {
 | 
				
			||||||
 | 
					  [super setFrameSize:newSize];
 | 
				
			||||||
 | 
					  [self updateLayerMask];
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
- (IBAction)showDevTools:(id)sender {
 | 
					- (IBAction)showDevTools:(id)sender {
 | 
				
			||||||
  inspectableWebContentsView_->inspectable_web_contents()->ShowDevTools();
 | 
					  inspectableWebContentsView_->inspectable_web_contents()->ShowDevTools();
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
| 
						 | 
					@ -152,6 +174,58 @@ using namespace brightray;
 | 
				
			||||||
  [contentsView setFrame:[self flipRectToNSRect:new_contents_bounds]];
 | 
					  [contentsView setFrame:[self flipRectToNSRect:new_contents_bounds]];
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					// Creates a path whose bottom two corners are rounded.
 | 
				
			||||||
 | 
					// Caller takes ownership of the path.
 | 
				
			||||||
 | 
					- (CGPathRef)createRoundedBottomCornersPath:(NSSize)size {
 | 
				
			||||||
 | 
					  CGMutablePathRef path = CGPathCreateMutable();
 | 
				
			||||||
 | 
					  CGFloat width = size.width;
 | 
				
			||||||
 | 
					  CGFloat height = size.height;
 | 
				
			||||||
 | 
					  CGFloat cornerRadius = kRoundedCornerRadius;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  // Top left corner.
 | 
				
			||||||
 | 
					  CGPathMoveToPoint(path, NULL, 0, height);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  // Top right corner.
 | 
				
			||||||
 | 
					  CGPathAddLineToPoint(path, NULL, width, height);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  // Bottom right corner.
 | 
				
			||||||
 | 
					  CGPathAddArc(path,
 | 
				
			||||||
 | 
					               NULL,
 | 
				
			||||||
 | 
					               width - cornerRadius,
 | 
				
			||||||
 | 
					               cornerRadius,
 | 
				
			||||||
 | 
					               cornerRadius,
 | 
				
			||||||
 | 
					               0,
 | 
				
			||||||
 | 
					               -M_PI_2,
 | 
				
			||||||
 | 
					               true);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  // Bottom left corner.
 | 
				
			||||||
 | 
					  CGPathAddArc(path,
 | 
				
			||||||
 | 
					               NULL,
 | 
				
			||||||
 | 
					               cornerRadius,
 | 
				
			||||||
 | 
					               cornerRadius,
 | 
				
			||||||
 | 
					               cornerRadius,
 | 
				
			||||||
 | 
					               -M_PI_2,
 | 
				
			||||||
 | 
					               -M_PI,
 | 
				
			||||||
 | 
					               true);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  // Draw line back to top-left corner.
 | 
				
			||||||
 | 
					  CGPathAddLineToPoint(path, NULL, 0, height);
 | 
				
			||||||
 | 
					  CGPathCloseSubpath(path);
 | 
				
			||||||
 | 
					  return path;
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					// Updates the path of the layer mask to have make window have round corner.
 | 
				
			||||||
 | 
					- (void)updateLayerMask {
 | 
				
			||||||
 | 
					  if (![self layer].mask) {
 | 
				
			||||||
 | 
					    layerMask_ = [CAShapeLayer layer];
 | 
				
			||||||
 | 
					    [self layer].mask = layerMask_;
 | 
				
			||||||
 | 
					  }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  CGPathRef path = [self createRoundedBottomCornersPath:self.bounds.size];
 | 
				
			||||||
 | 
					  layerMask_.path = path;
 | 
				
			||||||
 | 
					  CGPathRelease(path);
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
#pragma mark - NSWindowDelegate
 | 
					#pragma mark - NSWindowDelegate
 | 
				
			||||||
 | 
					
 | 
				
			||||||
- (void)windowWillClose:(NSNotification*)notification {
 | 
					- (void)windowWillClose:(NSNotification*)notification {
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue