Build fix for High Sierra 32 bit Mac
authorjbedard@apple.com <jbedard@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Thu, 28 Sep 2017 17:34:56 +0000 (17:34 +0000)
committerjbedard@apple.com <jbedard@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Thu, 28 Sep 2017 17:34:56 +0000 (17:34 +0000)
https://bugs.webkit.org/show_bug.cgi?id=177551
<rdar://problem/34690283>

Reviewed by Alexey Proskuryakov.

Some assertions have been removed from the SDK. Replace these assertions with equivalent
WTF assert code.  Since the files in this patch are using tabs, some style changes were
also made.

* Carbon/CarbonWindowAdapter.mm:
(+[CarbonWindowAdapter frameViewClassForStyleMask:]):
(-[CarbonWindowAdapter initWithContentRect:styleMask:backing:defer:]):
(-[CarbonWindowAdapter initWithCarbonWindowRef:takingOwnership:disableOrdering:carbon:]):
(-[CarbonWindowAdapter setViewsNeedDisplay:]):
(-[CarbonWindowAdapter initWithCarbonWindowRef:takingOwnership:]):
(-[CarbonWindowAdapter dealloc]):
(-[CarbonWindowAdapter windowRef]):
(-[CarbonWindowAdapter _hasWindowRef]):
(-[CarbonWindowAdapter _managesWindowRef]):
(-[CarbonWindowAdapter _removeWindowRef]):
(-[CarbonWindowAdapter _carbonWindowClass]):
(-[CarbonWindowAdapter reconcileToCarbonWindowBounds]):
(-[CarbonWindowAdapter sendSuperEvent:]):
(-[CarbonWindowAdapter relinquishFocus]):
(-[CarbonWindowAdapter _cancelKey:]):
(-[CarbonWindowAdapter _commonAwake]):
(-[CarbonWindowAdapter _destroyRealWindow:]):
(-[CarbonWindowAdapter _oldPlaceWindow:]):
(-[CarbonWindowAdapter _termWindowIfOwner]):
(-[CarbonWindowAdapter _windowMovedToRect:]):
(-[CarbonWindowAdapter constrainFrameRect:toScreen:]):
(-[CarbonWindowAdapter selectKeyViewFollowingView:]):
(-[CarbonWindowAdapter selectKeyViewPrecedingView:]):
(-[CarbonWindowAdapter canBecomeKeyWindow]):
(-[CarbonWindowAdapter canBecomeMainWindow]):
(-[CarbonWindowAdapter encodeWithCoder:]):
(-[CarbonWindowAdapter initWithCoder:]):
(-[CarbonWindowAdapter setContentView:]):
(-[CarbonWindowAdapter worksWhenModal]):
(-[CarbonWindowAdapter _setModalWindowLevel]):
(-[CarbonWindowAdapter _clearModalWindowLevel]):
(-[CarbonWindowAdapter carbonHICommandIDFromActionSelector:]):
(-[CarbonWindowAdapter sendCarbonProcessHICommandEvent:]):
(-[CarbonWindowAdapter sendCarbonUpdateHICommandStatusEvent:withMenuRef:andMenuItemIndex:]):
(-[CarbonWindowAdapter _handleRootBoundsChanged]):
(-[CarbonWindowAdapter _handleContentBoundsChanged]):
(-[CarbonWindowAdapter _handleCarbonEvent:callRef:]):
(NSCarbonWindowHandleEvent):
(-[CarbonWindowAdapter _reallyDoOrderWindow:relativeTo:findKey:forCounter:force:isModal:]):
(-[CarbonWindowAdapter _growBoxRect]):
* Carbon/HIWebView.mm:
(HIWebViewGetWebView):
(HIWebViewConstructor):
(HIWebViewDestructor):
(HIWebViewRegisterClass):
(GetBehaviors):
(Draw):
(HitTest):
(GetRegion):
(GetWindowRef):
(CreateNSEventAdoptingCGEvent):
(CopyEventCGEvent):
(CreateNSEventWithCarbonClickEvent):
(Click):
(CreateNSEventWithCarbonEvent):
(MouseUp):
(CreateNSEventWithCarbonMouseMoveEvent):
(MouseMoved):
(MouseDragged):
(MouseWheelMoved):
(ContextMenuClick):
(GetKind):
(BoundsChanged):
(OwningWindowChanged):
(WindowHandler):
(SyncFrame):
(SetFocusPart):
(AdvanceFocus):
(RelinquishFocus):
(ActiveStateChanged):
(ProcessCommand):
(UpdateCommandStatus):
(_NSSelectorForHICommand):
(HIWebViewEventHandler):
(StartUpdateObserver):
(StopUpdateObserver):
(UpdateObserver):

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@222614 268f45cc-cd09-0410-ab3c-d52691b4dbfc

Source/WebKitLegacy/mac/Carbon/CarbonWindowAdapter.mm
Source/WebKitLegacy/mac/Carbon/HIWebView.mm
Source/WebKitLegacy/mac/ChangeLog

index 1bd53e8..cf1c050 100644 (file)
@@ -76,6 +76,7 @@
 #import <pal/spi/mac/HIToolboxSPI.h>
 #import <pal/spi/mac/NSWindowSPI.h>
 #import <runtime/InitializeThreading.h>
+#import <wtf/Assertions.h>
 #import <wtf/MainThread.h>
 #import <wtf/RunLoop.h>
 
@@ -113,7 +114,8 @@ static OSStatus NSCarbonWindowHandleEvent(EventHandlerCallRef inEventHandlerCall
 
 
 // Return an appropriate window frame class.
-+ (Class)frameViewClassForStyleMask:(unsigned int)style {
++ (Class)frameViewClassForStyleMask:(unsigned)style
+{
 
     // There's only one appropriate window style, and only one appropriate window frame class.
     assert(style & _NSCarbonWindowMask);
@@ -123,16 +125,18 @@ static OSStatus NSCarbonWindowHandleEvent(EventHandlerCallRef inEventHandlerCall
 
 
 // Overriding of the parent class' designated initializer, just for safety's sake.
-- (id)initWithContentRect:(NSRect)contentRect styleMask:(unsigned int)style backing:(NSBackingStoreType)bufferingType defer:(BOOL)flag {
+- (id)initWithContentRect:(NSRect)contentRect styleMask:(unsigned)style backing:(NSBackingStoreType)bufferingType defer:(BOOL)flag
+{
 
     // Do the standard Cocoa thing.
     self = [super initWithContentRect:contentRect styleMask:style backing:bufferingType defer:flag];
-    if (self==nil) return nil;
+    if (self == nil)
+        return nil;
 
     // Simple.
-    _windowRef = NULL;
+    _windowRef = nullptr;
     _windowRefIsOwned = NO;
-    _eventHandler = NULL;
+    _eventHandler = nullptr;
     
     // Done.
     return self;
@@ -140,7 +144,8 @@ static OSStatus NSCarbonWindowHandleEvent(EventHandlerCallRef inEventHandlerCall
 }
 
 // Given a reference to a Carbon window that is to be encapsulated, an indicator of whether or not this object should take responsibility for disposing of the Carbon window, and an indicator of whether to disable Carbon window ordering, initialize.  This is the class' designated initializer.
-- (id)initWithCarbonWindowRef:(WindowRef)inWindowRef takingOwnership:(BOOL)inWindowRefIsOwned disableOrdering:(BOOL)inDisableOrdering carbon:(BOOL)inCarbon {
+- (id)initWithCarbonWindowRef:(WindowRef)inWindowRef takingOwnership:(BOOL)inWindowRefIsOwned disableOrdering:(BOOL)inDisableOrdering carbon:(BOOL)inCarbon
+{
 
     NSBackingStoreType backingStoreType;
     CarbonWindowContentView *carbonWindowContentView;
@@ -151,14 +156,14 @@ static OSStatus NSCarbonWindowHandleEvent(EventHandlerCallRef inEventHandlerCall
     unsigned int styleMask;
     void *nativeWindow;
     WindowModality windowModality;
-       ControlRef              contentView;
-       
+    ControlRef contentView;
+
     // Simple.
     // It's very weak to have to put this before the invocation of [super initWithContentRect:...], but -setContentView: is invoked from within that initializer.  It turns out that the common admonition about not calling virtual functions from within C++ constructors makes sense in Objective-C too.  M.P. Notice - 10/10/00
     _windowRef = inWindowRef;
     //_auxiliaryStorage->_windowRef = inWindowRef;
     _windowRefIsOwned = inWindowRefIsOwned;
-       _carbon = inCarbon;
+    _carbon = inCarbon;
 
     // Find out the window's CoreGraphics window reference.
     nativeWindow = (void*)GetNativeWindowFromWindowRef(inWindowRef);
@@ -171,9 +176,9 @@ static OSStatus NSCarbonWindowHandleEvent(EventHandlerCallRef inEventHandlerCall
 
     // Figure out the window's backing store type.
     // At one time, this had code stolen from CreatePlatformWindow in HIToolbox/Windows/Platform/CGSPlatform.c
-       // But now the non-retained window class is a Carbon secret that's not even in
-       // WindowsPriv.h; maybe we'll have to revisit this if someone needs to use WebKit
-       // in a non-retained window.
+    // But now the non-retained window class is a Carbon secret that's not even in
+    // WindowsPriv.h; maybe we'll have to revisit this if someone needs to use WebKit
+    // in a non-retained window.
 #pragma clang diagnostic push
 #pragma clang diagnostic ignored "-Wdeprecated-declarations"
     backingStoreType = NSBackingStoreRetained;
@@ -190,7 +195,7 @@ static OSStatus NSCarbonWindowHandleEvent(EventHandlerCallRef inEventHandlerCall
     if (windowFeatures & kWindowHasTitleBar)
         styleMask |= NSWindowStyleMaskTitled;
 
-    osStatus = GetWindowModality(_windowRef, &windowModality, NULL);
+    osStatus = GetWindowModality(_windowRef, &windowModality, nullptr);
     if (osStatus != noErr) {
         NSLog(@"Couldn't get window modality: error=%ld", osStatus);
         return nil;
@@ -200,7 +205,7 @@ static OSStatus NSCarbonWindowHandleEvent(EventHandlerCallRef inEventHandlerCall
     carbonWindowContentView = [[[CarbonWindowContentView alloc] init] autorelease];
 
     // Do some standard Cocoa initialization.  The defer argument's value is YES because we don't want -[NSWindow _commonAwake] to get called.  It doesn't appear that any relevant NSWindow code checks _wFlags.deferred, so we should be able to get away with the lie.
-    self = (CarbonWindowAdapter*)[super _initContent:NULL styleMask:styleMask backing:backingStoreType defer:YES contentView:carbonWindowContentView];
+    self = (CarbonWindowAdapter*)[super _initContent:nullptr styleMask:styleMask backing:backingStoreType defer:YES contentView:carbonWindowContentView];
     if (!self) return nil;
     assert(_contentView);
 
@@ -216,11 +221,11 @@ static OSStatus NSCarbonWindowHandleEvent(EventHandlerCallRef inEventHandlerCall
 
     // Install an event handler for the Carbon window events in which we're interested.
     const EventTypeSpec kEvents[] = {
-            { kEventClassWindow, kEventWindowActivated },
-            { kEventClassWindow, kEventWindowDeactivated },
-            { kEventClassWindow, kEventWindowBoundsChanged },
-            { kEventClassWindow, kEventWindowShown },
-            { kEventClassWindow, kEventWindowHidden }
+        { kEventClassWindow, kEventWindowActivated },
+        { kEventClassWindow, kEventWindowDeactivated },
+        { kEventClassWindow, kEventWindowBoundsChanged },
+        { kEventClassWindow, kEventWindowShown },
+        { kEventClassWindow, kEventWindowHidden }
     };
     
     const EventTypeSpec kControlBoundsChangedEvent = { kEventClassControl, kEventControlBoundsChanged };
@@ -243,7 +248,7 @@ static OSStatus NSCarbonWindowHandleEvent(EventHandlerCallRef inEventHandlerCall
             [self release];
             return nil;
     }
-       
+
     // Put a pointer to this Cocoa NSWindow in a Carbon window property tag.
     // Right now, this is just used by NSViewCarbonControl.  M.P. Notice - 10/9/00
     windowAsProperty = self;
@@ -264,20 +269,20 @@ static OSStatus NSCarbonWindowHandleEvent(EventHandlerCallRef inEventHandlerCall
 
 }
 
-- (void)setViewsNeedDisplay:(BOOL)wellDoThey {
-       // Make sure we can flush anything that needs it.
+- (void)setViewsNeedDisplay:(BOOL)wellDoThey
+{
+    // Make sure we can flush anything that needs it.
 
-       // We need to sync the context here. I was hoping I didn't need to do this,
-       // but apparently when scrolling, the AppKit view system draws directly.
-       // When this occurs, I cannot intercept it to make it draw in my HIView
-       // context. What ends up happening is that it draws, but nothing ever
-       // flushes it.
+    // We need to sync the context here. I was hoping I didn't need to do this,
+    // but apparently when scrolling, the AppKit view system draws directly.
+    // When this occurs, I cannot intercept it to make it draw in my HIView
+    // context. What ends up happening is that it draws, but nothing ever
+    // flushes it.
 
-       if ( [self windowNumber] != -1 )
-       {
-               CGContextRef cgContext = (CGContextRef)[[self _threadContext] graphicsPort];
-               CGContextSynchronize( cgContext );
-       }
+    if ([self windowNumber] != -1) {
+        CGContextRef cgContext = (CGContextRef)[[self _threadContext] graphicsPort];
+        CGContextSynchronize(cgContext);
+    }
 }
 
 + (void)initialize
@@ -288,14 +293,16 @@ static OSStatus NSCarbonWindowHandleEvent(EventHandlerCallRef inEventHandlerCall
 }
 
 // Given a reference to a Carbon window that is to be encapsulated, and an indicator of whether or not this object should take responsibility for disposing of the Carbon window, initialize.
-- (id)initWithCarbonWindowRef:(WindowRef)inWindowRef takingOwnership:(BOOL)inWindowRefIsOwned {
+- (id)initWithCarbonWindowRef:(WindowRef)inWindowRef takingOwnership:(BOOL)inWindowRefIsOwned
+{
     // for now, set disableOrdering to YES because that is what we've been doing and is therefore lower risk. However, I think it would be correct to set it to NO.
     return [self initWithCarbonWindowRef:inWindowRef takingOwnership:inWindowRefIsOwned disableOrdering:YES carbon:NO];
 }
 
 
 // Clean up.
-- (void)dealloc {
+- (void)dealloc
+{
     if (WebCoreObjCScheduleDeallocateOnMainThread([CarbonWindowAdapter class], self))
         return;
 
@@ -307,7 +314,8 @@ static OSStatus NSCarbonWindowHandleEvent(EventHandlerCallRef inEventHandlerCall
     [super dealloc];
 }
 
-- (WindowRef)windowRef {
+- (WindowRef)windowRef
+{
 
     // Simple.
     return _windowRef;
@@ -315,27 +323,31 @@ static OSStatus NSCarbonWindowHandleEvent(EventHandlerCallRef inEventHandlerCall
 }
 
 // should always be YES, but check in order to avoid initialization or deallocation surprises
-- (BOOL)_hasWindowRef {
-    return (_windowRef != NULL);
+- (BOOL)_hasWindowRef
+{
+    return (_windowRef != nullptr);
 }
 
 // an NSCarbonWindow does not manage the windowRef.  The windowRef manages the NSCarbonWindow
-- (BOOL)_managesWindowRef {
+- (BOOL)_managesWindowRef
+{
     return NO;
 }
 
-- (void)_removeWindowRef {
-    _windowRef = NULL;
-       
+- (void)_removeWindowRef
+{
+    _windowRef = nullptr;
+
     if (_eventHandler) RemoveEventHandler(_eventHandler);
-       
-       _eventHandler = NULL;
+
+    _eventHandler = nullptr;
 }
 
-- (WindowClass)_carbonWindowClass {
+- (WindowClass)_carbonWindowClass
+{
     WindowClass windowClass = kDocumentWindowClass;
     OSStatus osStatus;
-    
+
     if ([self _hasWindowRef]) {
         osStatus = GetWindowClass([self windowRef], &windowClass);
         if (osStatus != noErr) {
@@ -346,8 +358,8 @@ static OSStatus NSCarbonWindowHandleEvent(EventHandlerCallRef inEventHandlerCall
 }
 
 // Update this window's frame and content frame rectangles to match the Carbon window's structure bounds and content bounds rectangles.  Return yes if the update was really necessary, no otherwise.
-- (BOOL)reconcileToCarbonWindowBounds {
-
+- (BOOL)reconcileToCarbonWindowBounds
+{
     OSStatus osStatus;
     NSRect newContentFrameRect;
     NSRect newWindowFrameRect;
@@ -363,9 +375,11 @@ static OSStatus NSCarbonWindowHandleEvent(EventHandlerCallRef inEventHandlerCall
 
     // Get the Carbon window's bounds, which are expressed in global screen coordinates, with (0,0) at the top-left of the main screen.
     osStatus = GetWindowBounds(_windowRef, kWindowStructureRgn, &windowStructureBoundsRect);
-    if (osStatus!=noErr) NSLog(@"A Carbon window's structure bounds couldn't be gotten.");
+    if (osStatus != noErr)
+        NSLog(@"A Carbon window's structure bounds couldn't be gotten.");
     osStatus = GetWindowBounds(_windowRef, kWindowContentRgn, &windowContentBoundsRect);
-    if (osStatus!=noErr) NSLog(@"A Carbon window's content bounds couldn't be gotten.");
+    if (osStatus != noErr)
+        NSLog(@"A Carbon window's content bounds couldn't be gotten.");
 
     // Set the frame rectangle of the border view and this window from the Carbon window's structure region bounds.
     newWindowFrameRect.origin.x = windowStructureBoundsRect.left;
@@ -396,7 +410,8 @@ static OSStatus NSCarbonWindowHandleEvent(EventHandlerCallRef inEventHandlerCall
 
 
 // Handle an event just like an NSWindow would.
-- (void)sendSuperEvent:(NSEvent *)inEvent {
+- (void)sendSuperEvent:(NSEvent *)inEvent
+{
 
     // Filter out a few events that just result in complaints in the log.
     // Ignore some unknown event that gets sent when NSTextViews in printing accessory views are focused.  M.P. Notice - 12/7/00
@@ -425,9 +440,9 @@ static OSStatus NSCarbonWindowHandleEvent(EventHandlerCallRef inEventHandlerCall
     // Carbon thinks that a control has the keyboard focus,
     // or we wouldn't be being asked to relinquish focus.
 
-       firstResponder = [self firstResponder];
-       if ([firstResponder isKindOfClass:[NSView class]] ){
-               // Make the window the first responder, so that no view is the key view.
+    firstResponder = [self firstResponder];
+    if ([firstResponder isKindOfClass:[NSView class]]) {
+        // Make the window the first responder, so that no view is the key view.
         [self makeFirstResponder:self];
     }
 }
@@ -468,40 +483,15 @@ static OSStatus NSCarbonWindowHandleEvent(EventHandlerCallRef inEventHandlerCall
 // There's no override of _autoResizeState, despite the fact that NSWindow's operates on _windowNum, because it looks like it might work on Carbon windows as is.
 
 
-// Disappointingly, -_blockHeartBeat: is not immediately invoked to turn off heartbeating.  Heartbeating is turned off by setting the gDefaultButtonPaused global variable, and then this method is invoked later, if that global is set (at heartbeating time I guess).  Something has to change if we want to hook this up in Carbon windows.  M.P. Warning - 9/17/01
-/*
-// Do the right thing for a Carbon window.
-- (void)_blockHeartBeat:(BOOL)flag {
-
-    ControlRef defaultButton;
-    OSStatus osStatus;
-
-    // Do the standard Cocoa thing.
-    [super _blockHeartBeat:flag];
-
-    // If there's a default Carbon button in this Carbon window, make it stop pulsing, the Carbon way.
-    // This is inspired by HIToolbox/Controls/Definitions/ButtonCDEF.c's ButtonEventHandler().  M.P. Notice - 12/5/00
-    osStatus = GetWindowDefaultButton(_windowRef, &defaultButton);
-    if (osStatus==noErr && defaultButton) {
-        Boolean anotherButtonIsTracking = flag ? TRUE : FALSE;
-        osStatus = SetControlData(defaultButton, kControlNoPart, kControlPushButtonAnotherButtonTrackingTag, sizeof(Boolean), &anotherButtonIsTracking);
-        if (osStatus==noErr) DrawOneControl(defaultButton);
-        else NSLog(@"Some data couldn't be set in a Carbon control.");
-    }
-
-}
-*/
-
-
 // Do the right thing for a Carbon window.
-- (void)_cancelKey:(id)sender {
-
+- (void)_cancelKey:(id)sender
+{
     // Most of the time the handling of the cancel key will be done by Carbon, but this method will be invoked if an NSCarbonWindow is wrapping a Carbon window that contains an NSViewCarbonControl, and the escape key or whatever is pressed with an NSTextView focused.  Just do what Carbon would do.
     ControlRef cancelButton;
     GetWindowCancelButton(_windowRef, &cancelButton);
     if (cancelButton) {
         if (IsControlActive(cancelButton)) {
-            HIViewSimulateClick(cancelButton, kControlButtonPart, 0, NULL);
+            HIViewSimulateClick(cancelButton, kControlButtonPart, 0, nullptr);
         }
     }
 
@@ -510,8 +500,8 @@ static OSStatus NSCarbonWindowHandleEvent(EventHandlerCallRef inEventHandlerCall
 
 
 // Do the right thing for a Carbon window.
-- (void)_commonAwake {
-
+- (void)_commonAwake
+{
     // Complain, because this should never be called.  We insist that -[NSCarbonWindow initWithCarbonWindowRef] is the only valid initializer for instances of this class, and that there's no such thing as a one-shot NSCarbonWindow.
     NSLog(@"-[NSCarbonWindow _commonAwake] is not implemented.");
 
@@ -522,12 +512,11 @@ static OSStatus NSCarbonWindowHandleEvent(EventHandlerCallRef inEventHandlerCall
 
 
 // Do the right thing for a Carbon window.
-- (id)_destroyRealWindow:(BOOL)orderingOut {
-
+- (id)_destroyRealWindow:(BOOL)orderingOut
+{
     // Complain, because this should never be called.  We don't support one-shot NSCarbonWindows.
     NSLog(@"-[NSCarbonWindow _destroyRealWindow:] is not implemented.");
     return self;
-    
 }
 
 
@@ -550,8 +539,8 @@ static OSStatus NSCarbonWindowHandleEvent(EventHandlerCallRef inEventHandlerCall
 
 
 // Do what NSWindow would do, but then sychronize the Carbon window structures.
-- (void)_oldPlaceWindow:(NSRect)frameRect {
-
+- (void)_oldPlaceWindow:(NSRect)frameRect
+{
     OSStatus osStatus;
 
     // Do the standard Cocoa thing.
@@ -560,8 +549,8 @@ static OSStatus NSCarbonWindowHandleEvent(EventHandlerCallRef inEventHandlerCall
     // Tell Carbon to update its various regions.
     // Despite its name, this function should be called early and often, even if the window isn't visible yet.  2702648.  M.P. Notice - 7/24/01
     osStatus = _SyncWindowWithCGAfterMove(_windowRef);
-    if (osStatus!=noErr) NSLog(@"A Carbon window's bounds couldn't be synchronized (%i).", (int)osStatus);
-
+    if (osStatus != noErr)
+        NSLog(@"A Carbon window's bounds couldn't be synchronized (%i).", (int)osStatus);
 }
 
 
@@ -591,10 +580,12 @@ static OSStatus NSCarbonWindowHandleEvent(EventHandlerCallRef inEventHandlerCall
 
 // Do what NSWindow would do, but for a Carbon window.
 // This function is mostly cut-and-pasted from -[NSWindow _termWindowIfOwner].  M.P. Notice - 8/7/00
-- (void)_termWindowIfOwner {
+- (void)_termWindowIfOwner
+{
     [self _setWindowNumber:-1];
     _wFlags.isTerminating = YES;
-    if (_windowRef && _windowRefIsOwned) DisposeWindow(_windowRef);
+    if (_windowRef && _windowRefIsOwned)
+        DisposeWindow(_windowRef);
     // KW - need to clear window shadow state so it gets reset correctly when new window created
 //    if ([_borderView respondsToSelector:@selector(setShadowState:)]) {
 //        [_borderView setShadowState:kFrameShadowNone];
@@ -610,7 +601,8 @@ static OSStatus NSCarbonWindowHandleEvent(EventHandlerCallRef inEventHandlerCall
 
 
 // Do what NSWindow would do, but then sychronize the Carbon window structures.
-- (void)_windowMovedToRect:(NSRect)actualFrame {
+- (void)_windowMovedToRect:(NSRect)actualFrame
+{
 
     OSStatus osStatus;
 
@@ -625,45 +617,38 @@ static OSStatus NSCarbonWindowHandleEvent(EventHandlerCallRef inEventHandlerCall
 
 }
 
-- (NSRect)constrainFrameRect:(NSRect)actualFrame toScreen:(NSScreen *)screen {
+- (NSRect)constrainFrameRect:(NSRect)actualFrame toScreen:(NSScreen *)screen
+{
     // let Carbon decide window size and position
     return actualFrame;
 }
 
-- (void)selectKeyViewFollowingView:(NSView *)aView {
-       HIViewRef       view = NULL;
-       
-       view = [HIViewAdapter getHIViewForNSView:aView];
-       
-       if ( view )
-       {       
-               HIViewRef       contentView;
-               
-               GetRootControl( GetControlOwner( view ), &contentView );
-               HIViewAdvanceFocus( contentView, 0 );
-       }
-       else
-       {
-               [super selectKeyViewFollowingView:aView];
-       }
+- (void)selectKeyViewFollowingView:(NSView *)aView
+{
+    HIViewRef view = nullptr;
+    view = [HIViewAdapter getHIViewForNSView:aView];
+
+    if (view) {
+        HIViewRef contentView;
+        
+        GetRootControl(GetControlOwner(view), &contentView);
+        HIViewAdvanceFocus(contentView, 0);
+    } else
+        [super selectKeyViewFollowingView:aView];
 }
 
-- (void)selectKeyViewPrecedingView:(NSView *)aView {
-       HIViewRef       view = NULL;
-       
-       view = [HIViewAdapter getHIViewForNSView:aView];
-       
-       if ( view )
-       {       
-               HIViewRef       contentView;
-               
-               GetRootControl( GetControlOwner( view ), &contentView );
-               HIViewAdvanceFocus( contentView, shiftKey );
-       }
-       else
-       {
-               [super selectKeyViewPrecedingView:aView];
-       }
+- (void)selectKeyViewPrecedingView:(NSView *)aView
+{
+    HIViewRef view = nullptr;
+    view = [HIViewAdapter getHIViewForNSView:aView];
+
+    if (view) {
+        HIViewRef contentView;
+        
+        GetRootControl(GetControlOwner(view), &contentView);
+        HIViewAdvanceFocus(contentView, shiftKey);
+    } else
+        [super selectKeyViewPrecedingView:aView];
 }
 
 - (void)makeKeyWindow
@@ -674,13 +659,15 @@ static OSStatus NSCarbonWindowHandleEvent(EventHandlerCallRef inEventHandlerCall
 }
 
 // Do the right thing for a Carbon window.
-- (BOOL)canBecomeKeyWindow {
+- (BOOL)canBecomeKeyWindow
+{
 
     return YES;
 }
 
 // Do the right thing for a Carbon window.
-- (BOOL)canBecomeMainWindow {
+- (BOOL)canBecomeMainWindow
+{
     OSStatus osStatus;
     WindowClass windowClass;
     // By default, Carbon windows cannot become the main window.
@@ -704,7 +691,8 @@ static OSStatus NSCarbonWindowHandleEvent(EventHandlerCallRef inEventHandlerCall
 
 
 // Do the right thing for a Carbon window.
-- (void)encodeWithCoder:(NSCoder *)coder {
+- (void)encodeWithCoder:(NSCoder *)coder
+{
 
     // Actually, this will probably never be implemented.  M.P. Notice - 8/2/00
     NSLog(@"-[NSCarbonWindow encodeWithCoder:] is not implemented.");
@@ -716,7 +704,8 @@ static OSStatus NSCarbonWindowHandleEvent(EventHandlerCallRef inEventHandlerCall
 
 
 // Do the right thing for a Carbon window.
-- (id)initWithCoder:(NSCoder *)coder {
+- (id)initWithCoder:(NSCoder *)coder
+{
 
     // Actually, this will probably never be implemented.  M.P. Notice - 8/2/00
     NSLog(@"-[NSCarbonWindow initWithCoder:] is not implemented.");
@@ -735,21 +724,6 @@ static OSStatus NSCarbonWindowHandleEvent(EventHandlerCallRef inEventHandlerCall
 // There's no override of resizeToScreenWithEvent:, despite the fact that NSWindow's operates on _windowNum.
 // It looks like it's only called when an _NSForceResizeEventType event is passed into -[NSWindow sendEvent:], and I can't find any instances of that happening.
 
-/*
-// Do the right thing for a Carbon Window.
-- (void)sendEvent:(NSEvent *)theEvent {
-
-    // Not all events are handled in the same manner.
-    NSEventType eventType = [theEvent type];
-    if (eventType==NSAppKitDefined) {
-
-        // Handle the event the Cocoa way.  Carbon won't understand it anyway.
-        [super sendEvent:theEvent];
-
-    } 
-}
-*/
-
 // There's no override of setAcceptsMouseMovedEvents:, despite the fact that NSWindow's invokes [self windowNumber], because it looks like it might work on Carbon windows as is.
 
 
@@ -757,7 +731,8 @@ static OSStatus NSCarbonWindowHandleEvent(EventHandlerCallRef inEventHandlerCall
 
 
 // Do what NSWindow would do, but for a Carbon window.
-- (void)setContentView:(NSView *)aView {
+- (void)setContentView:(NSView *)aView
+{
 
     NSRect contentFrameRect;
     OSStatus osStatus;
@@ -799,16 +774,19 @@ static OSStatus NSCarbonWindowHandleEvent(EventHandlerCallRef inEventHandlerCall
 // There's no override of setDepthLimit:, despite the fact that NSWindow's invokes [self windowNumber], because it looks like it might work on Carbon windows as is.
 
 
-- (BOOL)worksWhenModal {
+- (BOOL)worksWhenModal
+{
     WindowClass windowClass = [self _carbonWindowClass];
     return (windowClass == kFloatingWindowClass || windowClass == kUtilityWindowClass);
 }
 
-- (void)_setModalWindowLevel {
+- (void)_setModalWindowLevel
+{
     return;
 }
 
-- (id)_clearModalWindowLevel {
+- (id)_clearModalWindowLevel
+{
     return nil;
 }
 
@@ -819,19 +797,27 @@ static OSStatus NSCarbonWindowHandleEvent(EventHandlerCallRef inEventHandlerCall
 // There's no override of windowNumber, despite the fact that NSWindow's returns _windowNum, because _windowNum is one of the instance variables whose value we're keeping synchronized with the Carbon window.
 
 
-- (UInt32)carbonHICommandIDFromActionSelector:(SEL)inActionSelector {
+- (UInt32)carbonHICommandIDFromActionSelector:(SEL)inActionSelector
+{
 
     // Initialize with the default return value.
     UInt32 hiCommandID = 0;
 
     // Pretty simple, if tedious.
-    if (inActionSelector==@selector(clear:)) hiCommandID = kHICommandClear;
-    else if (inActionSelector==@selector(copy:)) hiCommandID = kHICommandCopy;
-    else if (inActionSelector==@selector(cut:)) hiCommandID = kHICommandCut;
-    else if (inActionSelector==@selector(paste:)) hiCommandID = kHICommandPaste;
-    else if (inActionSelector==@selector(redo:)) hiCommandID = kHICommandRedo;
-    else if (inActionSelector==@selector(selectAll:)) hiCommandID = kHICommandSelectAll;
-    else if (inActionSelector==@selector(undo:)) hiCommandID = kHICommandUndo;
+    if (inActionSelector == @selector(clear:))
+        hiCommandID = kHICommandClear;
+    else if (inActionSelector == @selector(copy:))
+        hiCommandID = kHICommandCopy;
+    else if (inActionSelector  == @selector(cut:))
+        hiCommandID = kHICommandCut;
+    else if (inActionSelector == @selector(paste:))
+        hiCommandID = kHICommandPaste;
+    else if (inActionSelector == @selector(redo:))
+        hiCommandID = kHICommandRedo;
+    else if (inActionSelector == @selector(selectAll:))
+        hiCommandID = kHICommandSelectAll;
+    else if (inActionSelector == @selector(undo:))
+        hiCommandID = kHICommandUndo;
 
     // Done.
     return hiCommandID;
@@ -839,21 +825,22 @@ static OSStatus NSCarbonWindowHandleEvent(EventHandlerCallRef inEventHandlerCall
 }
 
 
-- (void)sendCarbonProcessHICommandEvent:(UInt32)inHICommandID {
+- (void)sendCarbonProcessHICommandEvent:(UInt32)inHICommandID
+{
 
     EventTargetRef eventTargetRef;
     HICommand hiCommand;
     OSStatus osStatus;
 
     // Initialize for safe error handling.
-    EventRef eventRef = NULL;
+    EventRef eventRef = nullptr;
 
     // Create a Process Command event.  Don't mention anything about the menu item, because we don't want the Carbon Event handler fiddling with it.
     hiCommand.attributes = 0;
     hiCommand.commandID = inHICommandID;
     hiCommand.menu.menuRef = 0;
     hiCommand.menu.menuItemIndex = 0;
-    osStatus = CreateEvent(NULL, kEventClassCommand, kEventCommandProcess, GetCurrentEventTime(), kEventAttributeNone, &eventRef);
+    osStatus = CreateEvent(nullptr, kEventClassCommand, kEventCommandProcess, GetCurrentEventTime(), kEventAttributeNone, &eventRef);
     if (osStatus!=noErr) {
         NSLog(@"CreateEvent() returned %i.", (int)osStatus);
         goto CleanUp;  
@@ -875,12 +862,13 @@ static OSStatus NSCarbonWindowHandleEvent(EventHandlerCallRef inEventHandlerCall
 CleanUp:
 
     // Clean up.
-    if (eventRef) ReleaseEvent(eventRef);
-
+    if (eventRef)
+        ReleaseEvent(eventRef);
 }
 
 
-- (Boolean)sendCarbonUpdateHICommandStatusEvent:(UInt32)inHICommandID withMenuRef:(MenuRef)inMenuRef andMenuItemIndex:(UInt16)inMenuItemIndex {
+- (Boolean)sendCarbonUpdateHICommandStatusEvent:(UInt32)inHICommandID withMenuRef:(MenuRef)inMenuRef andMenuItemIndex:(UInt16)inMenuItemIndex
+{
 
     EventTargetRef eventTargetRef;
     HICommand hiCommand;
@@ -888,14 +876,14 @@ CleanUp:
 
     // Initialize for safe error handling and flag returning.
     Boolean eventWasHandled = FALSE;
-    EventRef eventRef = NULL;
+    EventRef eventRef = nullptr;
 
     // Create a Process Command event.  Don't mention anything about the menu item, because we don't want the Carbon Event handler fiddling with it.
     hiCommand.attributes = kHICommandFromMenu;
     hiCommand.commandID = inHICommandID;
     hiCommand.menu.menuRef = inMenuRef;
     hiCommand.menu.menuItemIndex = inMenuItemIndex;
-    osStatus = CreateEvent(NULL, kEventClassCommand, kEventCommandUpdateStatus, GetCurrentEventTime(), kEventAttributeNone, &eventRef);
+    osStatus = CreateEvent(nullptr, kEventClassCommand, kEventCommandUpdateStatus, GetCurrentEventTime(), kEventAttributeNone, &eventRef);
     if (osStatus!=noErr) {
         NSLog(@"CreateEvent() returned %i.", (int)osStatus);
         goto CleanUp;
@@ -909,7 +897,7 @@ CleanUp:
     // Send a Carbon event to whatever has the Carbon user focus.
     eventTargetRef = GetUserFocusEventTarget();
     osStatus = SendEventToEventTarget(eventRef, eventTargetRef);
-    if (osStatus==noErr) {
+    if (osStatus == noErr) {
         eventWasHandled = TRUE;
     } else if (osStatus!=eventNotHandledErr) {
         NSLog(@"SendEventToEventTarget() returned %i.", (int)osStatus);
@@ -919,135 +907,130 @@ CleanUp:
 CleanUp:
 
     // Clean up.
-    if (eventRef) ReleaseEvent(eventRef);
+    if (eventRef)
+        ReleaseEvent(eventRef);
 
     // Done.
     return eventWasHandled;
-
 }
 
 - (void)_handleRootBoundsChanged
 {
-       HIViewRef       root = HIViewGetRoot( _windowRef ); 
-       HIRect          frame;
+    HIViewRef root = HIViewGetRoot(_windowRef); 
+    HIRect frame;
 
-       HIViewGetFrame( root, &frame );
-       [_borderView setFrameSize:*(NSSize*)&frame.size];
+    HIViewGetFrame(root, &frame);
+    [_borderView setFrameSize:*(NSSize*)&frame.size];
 }
 
 - (void)_handleContentBoundsChanged
 {
-       HIViewRef       root, contentView; 
-       HIRect          rootBounds, contentFrame;
-       NSRect          oldContentFrameRect;
-
-       root = HIViewGetRoot( _windowRef );
-       HIViewFindByID( root, kHIViewWindowContentID, &contentView );
-       HIViewGetFrame( contentView, &contentFrame );
-       HIViewGetBounds( root, &rootBounds );
-       
+    HIViewRef root, contentView; 
+    HIRect rootBounds, contentFrame;
+    NSRect oldContentFrameRect;
+
+    root = HIViewGetRoot(_windowRef);
+    HIViewFindByID(root, kHIViewWindowContentID, &contentView);
+    HIViewGetFrame(contentView, &contentFrame);
+    HIViewGetBounds(root, &rootBounds);
+
     // Set the content view's frame rect from the Carbon window's content region bounds.
-    contentFrame.origin.y = rootBounds.size.height - CGRectGetMaxY( contentFrame );
+    contentFrame.origin.y = rootBounds.size.height - CGRectGetMaxY(contentFrame);
 
     oldContentFrameRect = [(NSView *)_contentView frame];
-    if ( !NSEqualRects( *(NSRect*)&contentFrame, oldContentFrameRect ) ) {
+    if (!NSEqualRects(*(NSRect*)&contentFrame, oldContentFrameRect)) {
         [(NSView *)_contentView setFrame:*(NSRect*)&contentFrame];
     }
 }
 
-- (OSStatus)_handleCarbonEvent:(EventRef)inEvent callRef:(EventHandlerCallRef)inCallRef {
+- (OSStatus)_handleCarbonEvent:(EventRef)inEvent callRef:(EventHandlerCallRef)inCallRef
+{
     OSStatus result = eventNotHandledErr;
-    
-    switch ( GetEventClass( inEvent ) )
-    {
-               case kEventClassControl:
-                       {
-                               ControlRef              control;
-                               
-                               check( GetEventKind( inEvent ) == kEventControlBoundsChanged );
-                               
-                               GetEventParameter( inEvent, kEventParamDirectObject, typeControlRef, NULL,
-                                               sizeof( ControlRef ), NULL, &control );
-                               
-                               if ( control == HIViewGetRoot( _windowRef ) )
-                                       [self _handleRootBoundsChanged];
-                               else
-                                       [self _handleContentBoundsChanged];
-                       }
-                       break;
-                       
-       case kEventClassWindow:
-               switch ( GetEventKind( inEvent ) )
-               {
-                       case kEventWindowShown:
-                                       [self _setVisible:YES];
-                               break;
-                       
-                       case kEventWindowHidden:
-                                       [self _setVisible:NO];
-                               break;
-                       
-                       case kEventWindowActivated:
-                                       [self makeKeyWindow];
-                                       break;
-                               
-                       case kEventWindowDeactivated:
-                                       [self resignKeyWindow];
-                                       break;
-                               
-                               case kEventWindowBoundsChanged:
-                                       [self reconcileToCarbonWindowBounds];
-                                       break;
-                       }
-               break;
-       }
-       
+
+    switch (GetEventClass(inEvent)) {
+    case kEventClassControl:
+        ControlRef control;
+
+        ASSERT(GetEventKind(inEvent) == kEventControlBoundsChanged);
+
+        GetEventParameter(inEvent, kEventParamDirectObject, typeControlRef, nullptr, sizeof(ControlRef), nullptr, &control);
+
+        if (control == HIViewGetRoot(_windowRef))
+            [self _handleRootBoundsChanged];
+        else
+            [self _handleContentBoundsChanged];
+        break;
+
+    case kEventClassWindow:
+        switch (GetEventKind(inEvent)) {
+        case kEventWindowShown:
+            [self _setVisible:YES];
+            break;
+
+        case kEventWindowHidden:
+            [self _setVisible:NO];
+            break;
+
+        case kEventWindowActivated:
+            [self makeKeyWindow];
+            break;
+
+        case kEventWindowDeactivated:
+            [self resignKeyWindow];
+            break;
+
+        case kEventWindowBoundsChanged:
+            [self reconcileToCarbonWindowBounds];
+            break;
+        }
+        break;
+    }
+
     return result;
 }
 
 // Handle various events that Carbon is sending to our window.
-static OSStatus NSCarbonWindowHandleEvent(EventHandlerCallRef inEventHandlerCallRef, EventRef inEventRef, void *inUserData) {
-
+static OSStatus NSCarbonWindowHandleEvent(EventHandlerCallRef inEventHandlerCallRef, EventRef inEventRef, void *inUserData)
+{
     // default action is to send event to next handler.  We modify osStatus as necessary where we don't want this behavior
     OSStatus osStatus = eventNotHandledErr;
 
     // We do different things for different event types.
     CarbonWindowAdapter *carbonWindow = (CarbonWindowAdapter *)inUserData;
 
-       osStatus = [carbonWindow _handleCarbonEvent: inEventRef callRef: inEventHandlerCallRef];
-       
+    osStatus = [carbonWindow _handleCarbonEvent: inEventRef callRef: inEventHandlerCallRef];
+
     // Done.  If we want to propagate the event, we return eventNotHandledErr to send it to the next handler
     return osStatus;
-    
 }
 
 // [3364117] We need to make sure this does not fall through to the AppKit implementation! bad things happen.
-- (void)_reallyDoOrderWindow:(NSWindowOrderingMode)place relativeTo:(int)otherWin findKey:(BOOL)doKeyCalc forCounter:(BOOL)isACounter force:(BOOL)doForce isModal:(BOOL)isModal {
+- (void)_reallyDoOrderWindow:(NSWindowOrderingMode)place relativeTo:(int)otherWin findKey:(BOOL)doKeyCalc forCounter:(BOOL)isACounter force:(BOOL)doForce isModal:(BOOL)isModal
+{
 }
 
 - (NSRect) _growBoxRect
 {
-      WindowAttributes                attrs;
-      NSRect                                  retRect = NSZeroRect;
+    WindowAttributes attrs;
+    NSRect retRect = NSZeroRect;
 
-      GetWindowAttributes( _windowRef, &attrs );
+    GetWindowAttributes(_windowRef, &attrs);
 
-      if ( attrs & kWindowResizableAttribute )
-      {
-              HIRect          bounds, rect;
-              HIViewRef   view;
+    if (attrs & kWindowResizableAttribute) {
+        HIRect bounds, rect;
+        HIViewRef view;
 
-              HIViewGetBounds( HIViewGetRoot( _windowRef ), &bounds );
-              HIViewFindByID( HIViewGetRoot( _windowRef ), kHIViewWindowGrowBoxID, &view );
-              HIViewGetFrame( view, &rect );
+        HIViewGetBounds(HIViewGetRoot(_windowRef), &bounds);
+        HIViewFindByID(HIViewGetRoot(_windowRef), kHIViewWindowGrowBoxID, &view);
+        HIViewGetFrame(view, &rect);
 
-              rect.origin.y = bounds.size.height - CGRectGetMaxY( rect ) - 1;
-              rect.origin.x++;
+        rect.origin.y = bounds.size.height - CGRectGetMaxY(rect) - 1;
+        rect.origin.x++;
 
-              retRect = *(NSRect*)&rect;
-      }
+        retRect = *(NSRect*)&rect;
+    }
 
-      return retRect;
+    return retRect;
 }
 
 @end // implementation CarbonWindowAdapter
index db4bb64..9f5a3b1 100644 (file)
@@ -38,6 +38,7 @@
 #import <pal/spi/mac/NSEventSPI.h>
 #import <pal/spi/mac/NSGraphicsSPI.h>
 #import <pal/spi/mac/QuickDrawSPI.h>
+#import <wtf/Assertions.h>
 #import <wtf/ObjcRuntimeExtras.h>
 
 @interface NSWindow (AppKitSecretsHIWebViewKnows)
@@ -103,13 +104,13 @@ extern "C" void HIWebViewRegisterClass();
 
 struct HIWebView
 {
-    HIViewRef                                                  fViewRef;
+    HIViewRef fViewRef;
 
-    WebView*                                                   fWebView;
-    NSView*                                                            fFirstResponder;
-    CarbonWindowAdapter        *                               fKitWindow;
-    bool                                                               fIsComposited;
-    CFRunLoopObserverRef                               fUpdateObserver;
+    WebView* fWebView;
+    NSView* fFirstResponder;
+    CarbonWindowAdapter* fKitWindow;
+    bool fIsComposited;
+    CFRunLoopObserverRef fUpdateObserver;
 };
 typedef struct HIWebView HIWebView;
 
@@ -123,116 +124,99 @@ static const OSType NSViewCarbonControlFirstResponderViewPropertyTag = 'frvw';
 static const OSType NSCarbonWindowPropertyTag = 'win ';
 
 
-static SEL _NSSelectorForHICommand( const HICommand* hiCommand );
+static SEL _NSSelectorForHICommand(const HICommand*);
 
 static const EventTypeSpec kEvents[] = { 
-       { kEventClassHIObject, kEventHIObjectConstruct },
-       { kEventClassHIObject, kEventHIObjectDestruct },
-       
-       { kEventClassMouse, kEventMouseUp },
-       { kEventClassMouse, kEventMouseMoved },
-       { kEventClassMouse, kEventMouseDragged },
-       { kEventClassMouse, kEventMouseWheelMoved },
-
-       { kEventClassKeyboard, kEventRawKeyDown },
-       { kEventClassKeyboard, kEventRawKeyRepeat },
-
-       { kEventClassCommand, kEventCommandProcess },
-       { kEventClassCommand, kEventCommandUpdateStatus },
-
-       { kEventClassControl, kEventControlInitialize },
-       { kEventClassControl, kEventControlDraw },
-       { kEventClassControl, kEventControlHitTest },
-       { kEventClassControl, kEventControlGetPartRegion },
-       { kEventClassControl, kEventControlGetData },
-       { kEventClassControl, kEventControlBoundsChanged },
-       { kEventClassControl, kEventControlActivate },
-       { kEventClassControl, kEventControlDeactivate },
-       { kEventClassControl, kEventControlOwningWindowChanged },
-       { kEventClassControl, kEventControlClick },
-       { kEventClassControl, kEventControlContextualMenuClick },
-       { kEventClassControl, kEventControlSetFocusPart }
+    { kEventClassHIObject, kEventHIObjectConstruct },
+    { kEventClassHIObject, kEventHIObjectDestruct },
+    
+    { kEventClassMouse, kEventMouseUp },
+    { kEventClassMouse, kEventMouseMoved },
+    { kEventClassMouse, kEventMouseDragged },
+    { kEventClassMouse, kEventMouseWheelMoved },
+
+    { kEventClassKeyboard, kEventRawKeyDown },
+    { kEventClassKeyboard, kEventRawKeyRepeat },
+
+    { kEventClassCommand, kEventCommandProcess },
+    { kEventClassCommand, kEventCommandUpdateStatus },
+
+    { kEventClassControl, kEventControlInitialize },
+    { kEventClassControl, kEventControlDraw },
+    { kEventClassControl, kEventControlHitTest },
+    { kEventClassControl, kEventControlGetPartRegion },
+    { kEventClassControl, kEventControlGetData },
+    { kEventClassControl, kEventControlBoundsChanged },
+    { kEventClassControl, kEventControlActivate },
+    { kEventClassControl, kEventControlDeactivate },
+    { kEventClassControl, kEventControlOwningWindowChanged },
+    { kEventClassControl, kEventControlClick },
+    { kEventClassControl, kEventControlContextualMenuClick },
+    { kEventClassControl, kEventControlSetFocusPart }
 };
 
-#define kHIViewBaseClassID             CFSTR( "com.apple.hiview" )
-#define kHIWebViewClassID              CFSTR( "com.apple.HIWebView" )
-
-static HIWebView*              HIWebViewConstructor( HIViewRef inView );
-static void                            HIWebViewDestructor( HIWebView* view );
-
-static OSStatus                        HIWebViewEventHandler(
-                                                               EventHandlerCallRef     inCallRef,
-                                                               EventRef                        inEvent,
-                                                               void *                          inUserData );
-
-static UInt32                  GetBehaviors();
-static ControlKind             GetKind();
-static void                            Draw( HIWebView* inView, RgnHandle limitRgn, CGContextRef inContext );
-static ControlPartCode HitTest( HIWebView* view, const HIPoint* where );
-static OSStatus                        GetRegion( HIWebView* view, ControlPartCode inPart, RgnHandle outRgn );
-static void                            BoundsChanged(
-                                                               HIWebView*                      inView,
-                                                               UInt32                          inOptions,
-                                                               const HIRect*           inOriginalBounds,
-                                                               const HIRect*           inCurrentBounds );
-static void                            OwningWindowChanged(
-                                                               HIWebView*                      view,
-                                                               WindowRef                       oldWindow,
-                                                               WindowRef                       newWindow );
-static void                            ActiveStateChanged( HIWebView* view );
-
-static OSStatus                        Click( HIWebView* inView, EventRef inEvent );
-static OSStatus                        ContextMenuClick( HIWebView* inView, EventRef inEvent );
-static OSStatus                        MouseUp( HIWebView* inView, EventRef inEvent );
-static OSStatus                        MouseMoved( HIWebView* inView, EventRef inEvent );
-static OSStatus                        MouseDragged( HIWebView* inView, EventRef inEvent );
-static OSStatus                        MouseWheelMoved( HIWebView* inView, EventRef inEvent );
-
-static OSStatus                        ProcessCommand( HIWebView* inView, const HICommand* inCommand );
-static OSStatus                        UpdateCommandStatus( HIWebView* inView, const HICommand* inCommand );
-
-static OSStatus                        SetFocusPart(
-                                                               HIWebView*                              view,
-                                                               ControlPartCode                 desiredFocus,
-                                                               RgnHandle                               invalidRgn,
-                                                               Boolean                                 focusEverything,
-                                                               ControlPartCode*                actualFocus );
-static NSView*                 AdvanceFocus( HIWebView* view, bool forward );
-static void                            RelinquishFocus( HIWebView* view, bool inAutodisplay );
-
-static WindowRef               GetWindowRef( HIWebView* inView );
-static void                            SyncFrame( HIWebView* inView );
-
-static OSStatus                        WindowHandler( EventHandlerCallRef inCallRef, EventRef inEvent, void* inUserData );
-
-static void                            StartUpdateObserver( HIWebView* view );
-static void                            StopUpdateObserver( HIWebView* view );
+#define kHIViewBaseClassID CFSTR("com.apple.hiview")
+#define kHIWebViewClassID CFSTR("com.apple.HIWebView")
+
+static HIWebView* HIWebViewConstructor(HIViewRef inView);
+static void HIWebViewDestructor(HIWebView*);
+
+static OSStatus HIWebViewEventHandler(EventHandlerCallRef inCallRef, EventRef inEvent, void *inUserData);
+
+static UInt32 GetBehaviors();
+static ControlKind GetKind();
+static void Draw(HIWebView* inView, RgnHandle limitRgn, CGContextRef inContext);
+static ControlPartCode HitTest(HIWebView*, const HIPoint* where);
+static OSStatus GetRegion(HIWebView*, ControlPartCode inPart, RgnHandle outRgn);
+static void BoundsChanged(HIWebView* inView, UInt32 inOptions, const HIRect* inOriginalBounds, const HIRect* inCurrentBounds);
+static void OwningWindowChanged(HIWebView*, WindowRef oldWindow, WindowRef newWindow);
+static void ActiveStateChanged(HIWebView*);
+
+static OSStatus Click(HIWebView* inView, EventRef inEvent);
+static OSStatus ContextMenuClick(HIWebView* inView, EventRef inEvent);
+static OSStatus MouseUp(HIWebView* inView, EventRef inEvent);
+static OSStatus MouseMoved(HIWebView* inView, EventRef inEvent);
+static OSStatus MouseDragged(HIWebView* inView, EventRef inEvent);
+static OSStatus MouseWheelMoved(HIWebView* inView, EventRef inEvent);
+
+static OSStatus ProcessCommand(HIWebView* inView, const HICommand* inCommand);
+static OSStatus UpdateCommandStatus(HIWebView* inView, const HICommand* inCommand);
+
+static OSStatus SetFocusPart(HIWebView*, ControlPartCode desiredFocus, RgnHandle invalidRgn, Boolean focusEverything, ControlPartCode* actualFocus);
+static NSView* AdvanceFocus(HIWebView*, bool forward);
+static void RelinquishFocus(HIWebView*, bool inAutodisplay);
+
+static WindowRef GetWindowRef(HIWebView* inView);
+static void SyncFrame(HIWebView* inView);
+
+static OSStatus WindowHandler(EventHandlerCallRef inCallRef, EventRef inEvent, void* inUserData);
+
+static void StartUpdateObserver(HIWebView*);
+static void StopUpdateObserver(HIWebView*);
 
 //----------------------------------------------------------------------------------
 // HIWebViewCreate
 //----------------------------------------------------------------------------------
 //
-OSStatus
-HIWebViewCreate(HIViewRef* outControl)
+OSStatus HIWebViewCreate(HIViewRef* outControl)
 {
     HIWebViewRegisterClass();
-    return HIObjectCreate(kHIWebViewClassID, NULL, (HIObjectRef*)outControl);
+    return HIObjectCreate(kHIWebViewClassID, nullptr, (HIObjectRef*)outControl);
 }
 
 //----------------------------------------------------------------------------------
 // HIWebViewGetWebView
 //----------------------------------------------------------------------------------
 //
-WebView*
-HIWebViewGetWebView( HIViewRef inView )
+WebView* HIWebViewGetWebView(HIViewRef inView)
 {
-       HIWebView*      view = (HIWebView*)HIObjectDynamicCast( (HIObjectRef)inView, kHIWebViewClassID );
-       WebView*                        result = NULL;
-       
-       if ( view )
-               result = view->fWebView;
-       
-       return result;
+    HIWebView* view = (HIWebView*)HIObjectDynamicCast((HIObjectRef)inView, kHIWebViewClassID);
+    WebView* result = nullptr;
+
+    if (view)
+        result = view->fWebView;
+
+    return result;
 }
 
 //----------------------------------------------------------------------------------
@@ -240,38 +224,35 @@ HIWebViewGetWebView( HIViewRef inView )
 //----------------------------------------------------------------------------------
 //
 
-static HIWebView*
-HIWebViewConstructor( HIViewRef inView )
+static HIWebView* HIWebViewConstructor(HIViewRef inView)
 {
-       HIWebView*              view = (HIWebView*)malloc( sizeof( HIWebView ) );
-       
-       if ( view )
-       {
-               NSRect          frame = { { 0, 0 }, { 400, 400  } };
-       
-               view->fViewRef = inView;
-
-                WebView *webView = [[WebView alloc] initWithFrame: frame];
-                CFRetain(webView);
-                [webView release];
-               view->fWebView = webView;
-               [HIViewAdapter bindHIViewToNSView:inView nsView:view->fWebView];
-               
-               view->fFirstResponder = NULL;
-               view->fKitWindow = NULL;
+    HIWebView* view = (HIWebView*)malloc(sizeof(HIWebView));
+
+    if (view) {
+        NSRect frame = { { 0, 0 }, { 400, 400  } };
+
+        view->fViewRef = inView;
+
+        WebView *webView = [[WebView alloc] initWithFrame: frame];
+        CFRetain(webView);
+        [webView release];
+        view->fWebView = webView;
+        [HIViewAdapter bindHIViewToNSView:inView nsView:view->fWebView];
+
+        view->fFirstResponder = nullptr;
+        view->fKitWindow = nullptr;
         view->fIsComposited = false;
-        view->fUpdateObserver = NULL;
-       }
-       
-       return view;
+        view->fUpdateObserver = nullptr;
+    }
+
+    return view;
 }
 
 //----------------------------------------------------------------------------------
 // HIWebViewDestructor
 //----------------------------------------------------------------------------------
 //
-static void
-HIWebViewDestructor( HIWebView* inView )
+static void HIWebViewDestructor(HIWebView* inView)
 {
     [HIViewAdapter unbindNSView:inView->fWebView];
     CFRelease(inView->fWebView);
@@ -283,27 +264,24 @@ HIWebViewDestructor( HIWebView* inView )
 // HIWebViewRegisterClass
 //----------------------------------------------------------------------------------
 //
-void
-HIWebViewRegisterClass()
+void HIWebViewRegisterClass()
 {
-       static bool sRegistered;
-       
-       if ( !sRegistered )
-       {
-               HIObjectRegisterSubclass( kHIWebViewClassID, kHIViewBaseClassID, 0, HIWebViewEventHandler,
-                       GetEventTypeCount( kEvents ), kEvents, 0, NULL );
-               sRegistered = true;
-       }
+    static bool sRegistered;
+
+    if (!sRegistered) {
+        HIObjectRegisterSubclass(kHIWebViewClassID, kHIViewBaseClassID, 0, HIWebViewEventHandler,
+            GetEventTypeCount(kEvents), kEvents, 0, nullptr);
+        sRegistered = true;
+    }
 }
 
 //----------------------------------------------------------------------------------
 // GetBehaviors
 //----------------------------------------------------------------------------------
 //
-static UInt32
-GetBehaviors()
+static UInt32 GetBehaviors()
 {
-       return kControlSupportsDataAccess | kControlSupportsGetRegion | kControlGetsFocusOnClick;
+    return kControlSupportsDataAccess | kControlSupportsGetRegion | kControlGetsFocusOnClick;
 }
 
 static CGContextRef overrideCGContext(NSWindow *window, CGContextRef context)
@@ -326,48 +304,46 @@ static void restoreCGContext(NSWindow *window, CGContextRef savedContext)
 // Draw
 //----------------------------------------------------------------------------------
 //
-static void
-Draw( HIWebView* inView, RgnHandle limitRgn, CGContextRef inContext )
+static void Draw(HIWebView* inView, RgnHandle limitRgn, CGContextRef inContext)
 {
-       HIRect                          bounds;
-       Rect                            drawRect;
-       HIRect                          hiRect;
-       bool                            createdContext = false;
+    HIRect bounds;
+    Rect drawRect;
+    HIRect hiRect;
+    bool createdContext = false;
 
-    if (!inView->fIsComposited)
-    {
+    if (!inView->fIsComposited) {
         GrafPtr port;
         Rect portRect;
 
 #pragma clang diagnostic push
 #pragma clang diagnostic ignored "-Wdeprecated-declarations"
-        GetPort( &port );
-        GetPortBounds( port, &portRect );
-        CreateCGContextForPort( port, &inContext );
+        GetPort(&port);
+        GetPortBounds(port, &portRect);
+        CreateCGContextForPort(port, &inContext);
 #pragma clang diagnostic push
-        SyncCGContextOriginWithPort( inContext, port );
-        CGContextTranslateCTM( inContext, 0, (portRect.bottom - portRect.top) );
-        CGContextScaleCTM( inContext, 1, -1 );
+        SyncCGContextOriginWithPort(inContext, port);
+        CGContextTranslateCTM(inContext, 0, (portRect.bottom - portRect.top));
+        CGContextScaleCTM(inContext, 1, -1);
         createdContext = true;
     }
 
-       HIViewGetBounds( inView->fViewRef, &bounds );
+    HIViewGetBounds(inView->fViewRef, &bounds);
 
     CGContextRef savedContext = overrideCGContext(inView->fKitWindow, inContext);
     [NSGraphicsContext setCurrentContext:[inView->fKitWindow graphicsContext]];
 
-       GetRegionBounds( limitRgn, &drawRect );
+    GetRegionBounds(limitRgn, &drawRect);
 
-    if ( !inView->fIsComposited )
-        OffsetRect( &drawRect, (SInt16)-bounds.origin.x, (SInt16)-bounds.origin.y );
+    if (!inView->fIsComposited)
+        OffsetRect(&drawRect, (SInt16)-bounds.origin.x, (SInt16)-bounds.origin.y);
     
-       hiRect.origin.x = drawRect.left;
-       hiRect.origin.y = bounds.size.height - drawRect.bottom; // flip y
-       hiRect.size.width = drawRect.right - drawRect.left;
-       hiRect.size.height = drawRect.bottom - drawRect.top;
+    hiRect.origin.x = drawRect.left;
+    hiRect.origin.y = bounds.size.height - drawRect.bottom; // flip y
+    hiRect.size.width = drawRect.right - drawRect.left;
+    hiRect.size.height = drawRect.bottom - drawRect.top;
 
-//    printf( "Drawing: drawRect is (%g %g) (%g %g)\n", hiRect.origin.x, hiRect.origin.y,
-//            hiRect.size.width, hiRect.size.height );
+//    printf("Drawing: drawRect is (%g %g) (%g %g)\n", hiRect.origin.x, hiRect.origin.y,
+//            hiRect.size.width, hiRect.size.height);
 
     // FIXME: We need to do layout before Carbon has decided what region needs drawn.
     // In Cocoa we make sure to do layout and invalidate any new regions before draw, so everything
@@ -378,40 +354,40 @@ Draw( HIWebView* inView, RgnHandle limitRgn, CGContextRef inContext )
     if ([documentView isKindOfClass:[WebHTMLView class]])
         [(WebHTMLView *)documentView _web_updateLayoutAndStyleIfNeededRecursive];
 
-    if ( inView->fIsComposited )
+    if (inView->fIsComposited)
         [inView->fWebView displayIfNeededInRect: *(NSRect*)&hiRect];
     else
         [inView->fWebView displayRect:*(NSRect*)&hiRect];
 
     restoreCGContext(inView->fKitWindow, savedContext);
 
-    if ( !inView->fIsComposited )
+    if (!inView->fIsComposited)
     {
         HIViewRef      view;
-        HIViewFindByID( HIViewGetRoot( GetControlOwner( inView->fViewRef ) ), kHIViewWindowGrowBoxID, &view );
-        if ( view )
+        HIViewFindByID(HIViewGetRoot(GetControlOwner(inView->fViewRef)), kHIViewWindowGrowBoxID, &view);
+        if (view)
         {
-            HIRect     frame;
+            HIRect frame;
 
-            HIViewGetBounds( view, &frame );
-            HIViewConvertRect( &frame, view, NULL );
+            HIViewGetBounds(view, &frame);
+            HIViewConvertRect(&frame, view, nullptr);
 
             hiRect.origin.x = drawRect.left;
             hiRect.origin.y = drawRect.top;
             hiRect.size.width = drawRect.right - drawRect.left;
             hiRect.size.height = drawRect.bottom - drawRect.top;
 
-            HIViewConvertRect( &hiRect, inView->fViewRef, NULL );
+            HIViewConvertRect(&hiRect, inView->fViewRef, nullptr);
 
-            if ( CGRectIntersectsRect( frame, hiRect ) )
-                HIViewSetNeedsDisplay( view, true );
+            if (CGRectIntersectsRect(frame, hiRect))
+                HIViewSetNeedsDisplay(view, true);
         }
-     }
+    }
 
-    if ( createdContext )
+    if (createdContext)
     {
-        CGContextSynchronize( inContext );
-        CGContextRelease( inContext );
+        CGContextSynchronize(inContext);
+        CGContextRelease(inContext);
     }
 }
 
@@ -419,61 +395,50 @@ Draw( HIWebView* inView, RgnHandle limitRgn, CGContextRef inContext )
 // HitTest
 //----------------------------------------------------------------------------------
 //
-static ControlPartCode
-HitTest( HIWebView* view, const HIPoint* where )
+static ControlPartCode HitTest(HIWebView* view, const HIPoint* where)
 {
-       HIRect          bounds;
-       
-       HIViewGetBounds( view->fViewRef, &bounds );
-
-       if ( CGRectContainsPoint( bounds, *where ) )
-               return 1;
-       else
-               return kControlNoPart;
+    HIRect bounds;
+
+    HIViewGetBounds(view->fViewRef, &bounds);
+
+    if (CGRectContainsPoint(bounds, *where))
+        return 1;
+    return kControlNoPart;
 }
 
 //----------------------------------------------------------------------------------
 // GetRegion
 //----------------------------------------------------------------------------------
 //
-static OSStatus
-GetRegion(
-       HIWebView*                      inView,
-       ControlPartCode         inPart,
-       RgnHandle                       outRgn )
+static OSStatus GetRegion(HIWebView* inView, ControlPartCode inPart, RgnHandle outRgn)
 {
-       OSStatus         err = eventNotHandledErr;
-       
-       if ( inPart == -3 ) // kControlOpaqueMetaPart:
-       {
-               if ( [inView->fWebView isOpaque] )
-               {
-                       HIRect  bounds;
-                       Rect    temp;
-                       
-                       HIViewGetBounds( inView->fViewRef, &bounds );
-
-                       temp.top = (SInt16)bounds.origin.y;
-                       temp.left = (SInt16)bounds.origin.x;
-                       temp.bottom = (SInt16)CGRectGetMaxY( bounds );
-                       temp.right = (SInt16)CGRectGetMaxX( bounds );
-
-                       RectRgn( outRgn, &temp );
-                       err = noErr;
-               }
-       }
-       
-       return err;
+    OSStatus err = eventNotHandledErr;
+
+    if (inPart == -3 && [inView->fWebView isOpaque]) {
+        // kControlOpaqueMetaPart:
+        HIRect bounds;
+        Rect temp;
+
+        HIViewGetBounds(inView->fViewRef, &bounds);
+
+        temp.top = (SInt16)bounds.origin.y;
+        temp.left = (SInt16)bounds.origin.x;
+        temp.bottom = (SInt16)CGRectGetMaxY(bounds);
+        temp.right = (SInt16)CGRectGetMaxX(bounds);
+
+        RectRgn(outRgn, &temp);
+        err = noErr;
+    }
+
+    return err;
 }
 
-static WindowRef
-GetWindowRef( HIWebView* inView )
+static WindowRef GetWindowRef(HIWebView* inView)
 {
-       return GetControlOwner( inView->fViewRef );
+    return GetControlOwner(inView->fViewRef);
 }
 
-static NSEvent *
-CreateNSEventAdoptingCGEvent( CGEventRef cgEvent, EventRef eventRef )
+static NSEvent *CreateNSEventAdoptingCGEvent(CGEventRef cgEvent, EventRef eventRef)
 {
     NSEvent *result = [[NSEvent alloc] _initWithCGEvent:cgEvent eventRef:eventRef];
     CFRelease(cgEvent);
@@ -481,11 +446,11 @@ CreateNSEventAdoptingCGEvent( CGEventRef cgEvent, EventRef eventRef )
 }
 
 static Boolean
-CopyEventCGEvent( EventRef event, CGEventRef* cgEvent )
+CopyEventCGEvent(EventRef event, CGEventRef* cgEvent)
 {
     if ((*cgEvent = CopyEventCGEvent(event)))
         return true;
-    
+
     // This event might not have been created directly from a CGS event, and might not
     // have a CGEventRef associated with it. In that case, try using the event most
     // recently dispatched by the event dispatcher, which is likely to be the original
@@ -496,37 +461,36 @@ CopyEventCGEvent( EventRef event, CGEventRef* cgEvent )
     return false;
 }
 
-static NSEvent *
-CreateNSEventWithCarbonClickEvent( EventRef inEvent, WindowRef windowRef )
+static NSEvent *CreateNSEventWithCarbonClickEvent(EventRef inEvent, WindowRef windowRef)
 {
     EventRef newEvent;
     Point where;
     OSStatus err;
     UInt32 modifiers;
     Rect windRect;
-    
-    CGEventRef cgEvent = NULL;
+
+    CGEventRef cgEvent = nullptr;
     if (!CopyEventCGEvent(inEvent, &cgEvent))
         return nil;
-    
+
     // We need to make the event be a kEventMouseDown event, or the webkit might trip up when
     // we click on a Netscape plugin. It calls ConvertEventRefToEventRecord, assuming
     // that mouseDown was passed an event with a real mouse down eventRef. We just need a
     // minimal one here.
-    
-    err = CreateEvent(NULL, kEventClassMouse, kEventMouseDown, GetEventTime(inEvent), 0, &newEvent);
+
+    err = CreateEvent(nullptr, kEventClassMouse, kEventMouseDown, GetEventTime(inEvent), 0, &newEvent);
     if (err != noErr)
         return nil;
-    
-    GetEventParameter(inEvent, kEventParamWindowMouseLocation, typeQDPoint, NULL, sizeof(Point), NULL, &where);
+
+    GetEventParameter(inEvent, kEventParamWindowMouseLocation, typeQDPoint, nullptr, sizeof(Point), nullptr, &where);
     GetWindowBounds(windowRef, kWindowStructureRgn, &windRect);
     where.h += windRect.left;
     where.v += windRect.top;
-    
-    GetEventParameter(inEvent, kEventParamKeyModifiers, typeUInt32, NULL, sizeof(UInt32), NULL, &modifiers);
+
+    GetEventParameter(inEvent, kEventParamKeyModifiers, typeUInt32, nullptr, sizeof(UInt32), nullptr, &modifiers);
     SetEventParameter(newEvent, kEventParamMouseLocation, typeQDPoint, sizeof(Point), &where);
     SetEventParameter(newEvent, kEventParamKeyModifiers, typeUInt32, sizeof(UInt32), &modifiers);
-    
+
     return CreateNSEventAdoptingCGEvent(cgEvent, newEvent);
 }
 
@@ -534,8 +498,7 @@ CreateNSEventWithCarbonClickEvent( EventRef inEvent, WindowRef windowRef )
 // Click
 //----------------------------------------------------------------------------------
 //
-static OSStatus
-Click(HIWebView* inView, EventRef inEvent)
+static OSStatus Click(HIWebView* inView, EventRef inEvent)
 {
     NSEvent *kitEvent = CreateNSEventWithCarbonClickEvent(inEvent, GetWindowRef(inView));
 
@@ -552,8 +515,7 @@ Click(HIWebView* inView, EventRef inEvent)
     return noErr;
 }
 
-static NSEvent *
-CreateNSEventWithCarbonEvent( EventRef inEvent )
+static NSEvent *CreateNSEventWithCarbonEvent(EventRef inEvent)
 {
     NSEvent *event = [NSEvent eventWithEventRef:inEvent];
     if (!event)
@@ -566,8 +528,7 @@ CreateNSEventWithCarbonEvent( EventRef inEvent )
 // MouseUp
 //----------------------------------------------------------------------------------
 //
-static OSStatus
-MouseUp( HIWebView* inView, EventRef inEvent )
+static OSStatus MouseUp(HIWebView* inView, EventRef inEvent)
 {
     NSEvent* kitEvent = CreateNSEventWithCarbonEvent(inEvent);
 
@@ -575,11 +536,10 @@ MouseUp( HIWebView* inView, EventRef inEvent )
 
     [kitEvent release];
 
-       return noErr;
+    return noErr;
 }
 
-static NSEvent *
-CreateNSEventWithCarbonMouseMoveEvent( EventRef inEvent, NSWindow *window )
+static NSEvent *CreateNSEventWithCarbonMouseMoveEvent(EventRef inEvent, NSWindow *window)
 {
     NSEvent* kitEvent = [NSEvent eventWithEventRef:inEvent];
 
@@ -599,22 +559,20 @@ CreateNSEventWithCarbonMouseMoveEvent( EventRef inEvent, NSWindow *window )
 // MouseMoved
 //----------------------------------------------------------------------------------
 //
-static OSStatus
-MouseMoved( HIWebView* inView, EventRef inEvent )
+static OSStatus MouseMoved(HIWebView* inView, EventRef inEvent)
 {
     NSEvent *kitEvent = CreateNSEventWithCarbonMouseMoveEvent(inEvent, inView->fKitWindow);
     [inView->fKitWindow sendEvent:kitEvent];
-       [kitEvent release];
+    [kitEvent release];
 
-       return noErr;
+    return noErr;
 }
 
 //----------------------------------------------------------------------------------
 // MouseDragged
 //----------------------------------------------------------------------------------
 //
-static OSStatus
-MouseDragged( HIWebView* inView, EventRef inEvent )
+static OSStatus MouseDragged(HIWebView* inView, EventRef inEvent)
 {
     NSEvent* kitEvent = CreateNSEventWithCarbonEvent(inEvent);
 
@@ -622,15 +580,14 @@ MouseDragged( HIWebView* inView, EventRef inEvent )
 
     [kitEvent release];
 
-       return noErr;
+    return noErr;
 }
 
 //----------------------------------------------------------------------------------
 // MouseDragged
 //----------------------------------------------------------------------------------
 //
-static OSStatus
-MouseWheelMoved( HIWebView* inView, EventRef inEvent )
+static OSStatus MouseWheelMoved(HIWebView* inView, EventRef inEvent)
 {
     NSEvent* kitEvent = CreateNSEventWithCarbonEvent(inEvent);
 
@@ -638,23 +595,22 @@ MouseWheelMoved( HIWebView* inView, EventRef inEvent )
 
     [kitEvent release];
 
-       return noErr;
+    return noErr;
 }
 
 //----------------------------------------------------------------------------------
 // ContextMenuClick
 //----------------------------------------------------------------------------------
 //
-static OSStatus
-ContextMenuClick( HIWebView* inView, EventRef inEvent )
+static OSStatus ContextMenuClick(HIWebView* inView, EventRef inEvent)
 {
     NSView *webView = inView->fWebView;
     NSWindow *window = [webView window];
 
     // Get the point out of the event.
     HIPoint point;
-    GetEventParameter(inEvent, kEventParamMouseLocation, typeHIPoint, NULL, sizeof(point), NULL, &point);
-    HIViewConvertPoint(&point, inView->fViewRef, NULL);
+    GetEventParameter(inEvent, kEventParamMouseLocation, typeHIPoint, nullptr, sizeof(point), nullptr, &point);
+    HIViewConvertPoint(&point, inView->fViewRef, nullptr);
     
     // Flip the Y coordinate, since Carbon is flipped relative to the AppKit.
     NSPoint location = NSMakePoint(point.x, [window frame].size.height - point.y);
@@ -677,29 +633,21 @@ ContextMenuClick( HIWebView* inView, EventRef inEvent )
 // GetKind
 //----------------------------------------------------------------------------------
 //
-static ControlKind
-GetKind()
+static ControlKind GetKind()
 {
-       const ControlKind kMyKind = { 'appl', 'wbvw' };
-       
-       return kMyKind;
+    const ControlKind kMyKind = { 'appl', 'wbvw' };
+    
+    return kMyKind;
 }
 
 //----------------------------------------------------------------------------------
 // BoundsChanged
 //----------------------------------------------------------------------------------
 //
-static void
-BoundsChanged(
-       HIWebView*                      inView,
-       UInt32                          inOptions,
-       const HIRect*           inOriginalBounds,
-       const HIRect*           inCurrentBounds )
+static void BoundsChanged(HIWebView* inView, UInt32 inOptions, const HIRect* inOriginalBounds, const HIRect* inCurrentBounds)
 {
-       if ( inView->fWebView )
-       {
-               SyncFrame( inView );
-       }
+    if (inView->fWebView)
+        SyncFrame(inView);
 }
 
 //----------------------------------------------------------------------------------
@@ -707,17 +655,13 @@ BoundsChanged(
 //----------------------------------------------------------------------------------
 //
 static void
-OwningWindowChanged(
-       HIWebView*                      view,
-       WindowRef                       oldWindow,
-       WindowRef                       newWindow )
+OwningWindowChanged(HIWebView* view, WindowRef oldWindow, WindowRef newWindow)
 {
-    if ( newWindow ){
-        WindowAttributes       attrs;
+    if (newWindow) {
+        WindowAttributes attrs;
         
-        OSStatus err = GetWindowProperty(newWindow, NSAppKitPropertyCreator, NSCarbonWindowPropertyTag, sizeof(NSWindow *), NULL, &view->fKitWindow);
-        if ( err != noErr )
-        {
+        OSStatus err = GetWindowProperty(newWindow, NSAppKitPropertyCreator, NSCarbonWindowPropertyTag, sizeof(NSWindow *), nullptr, &view->fKitWindow);
+        if (err != noErr) {
             const EventTypeSpec kWindowEvents[] = {
             { kEventClassWindow, kEventWindowClosed },
             { kEventClassMouse, kEventMouseMoved },
@@ -733,151 +677,124 @@ OwningWindowChanged(
             view->fKitWindow = [[CarbonWindowAdapter alloc] initWithCarbonWindowRef: newWindow takingOwnership: NO disableOrdering:NO carbon:YES];
             SetWindowProperty(newWindow, NSAppKitPropertyCreator, NSCarbonWindowPropertyTag, sizeof(NSWindow *), &view->fKitWindow);
             
-            InstallWindowEventHandler( newWindow, WindowHandler, GetEventTypeCount( kWindowEvents ), kWindowEvents, newWindow, NULL );
+            InstallWindowEventHandler(newWindow, WindowHandler, GetEventTypeCount(kWindowEvents), kWindowEvents, newWindow, nullptr);
         }
         
         [[view->fKitWindow contentView] addSubview:view->fWebView];
         
-        GetWindowAttributes( newWindow, &attrs );
-        view->fIsComposited = ( ( attrs & kWindowCompositingAttribute ) != 0 );
+        GetWindowAttributes(newWindow, &attrs);
+        view->fIsComposited = attrs & kWindowCompositingAttribute;
         
-        SyncFrame( view );        
-    }
-    else
-    {
+        SyncFrame(view);        
+    } else {
         // Be sure to detach the cocoa view, too.
-        if ( view->fWebView )
+        if (view->fWebView)
             [view->fWebView removeFromSuperview];
         
-        view->fKitWindow = NULL; // break the ties that bind
+        view->fKitWindow = nullptr; // break the ties that bind
     }
 }
 
 //-------------------------------------------------------------------------------------
-//     WindowHandler
+//    WindowHandler
 //-------------------------------------------------------------------------------------
-//     Redirect mouse events to the views beneath them. This is required for WebKit to work
-//     properly. We install it once per window. We also tap into window close to release
-//     the NSWindow that shadows our Carbon window.
+//    Redirect mouse events to the views beneath them. This is required for WebKit to work
+//    properly. We install it once per window. We also tap into window close to release
+//    the NSWindow that shadows our Carbon window.
 //
-static OSStatus
-WindowHandler( EventHandlerCallRef inCallRef, EventRef inEvent, void* inUserData )
+static OSStatus WindowHandler(EventHandlerCallRef inCallRef, EventRef inEvent, void* inUserData)
 {
-       WindowRef       window = (WindowRef)inUserData;
-       OSStatus        result = eventNotHandledErr;
+    WindowRef window = (WindowRef)inUserData;
+    OSStatus result = eventNotHandledErr;
 
-    switch( GetEventClass( inEvent ) )
-    {
-       case kEventClassControl:
-            {
-            switch( GetEventKind( inEvent ) )
-            {
-                case kEventControlClick:
-                    {
-                        CarbonWindowAdapter *kitWindow;
-                        OSStatus err;
-                        
-                        err = GetWindowProperty( window, NSAppKitPropertyCreator, NSCarbonWindowPropertyTag, sizeof(NSWindow *), NULL, &kitWindow);
-                        
-                        // We must be outside the HIWebView, relinquish focus.
-                        [kitWindow relinquishFocus];
-                    }
-                    break;
-                }
-            }
+    NSWindow* kitWindow;
+    OSStatus err = noErr;
+    NSEvent* kitEvent;
+
+    switch (GetEventClass(inEvent)) {
+    case kEventClassControl:
+        switch (GetEventKind(inEvent)) {
+        case kEventControlClick:
+            CarbonWindowAdapter *kitWindow;
+
+            err = GetWindowProperty(window, NSAppKitPropertyCreator, NSCarbonWindowPropertyTag, sizeof(NSWindow *), nullptr, &kitWindow);
+                
+            // We must be outside the HIWebView, relinquish focus.
+            [kitWindow relinquishFocus];
             break;
+        }
+        break;
             
-       case kEventClassKeyboard:
-               {
-                NSWindow*              kitWindow;
-                OSStatus               err;
-                               NSEvent*                kitEvent;
-                               
-                               // if the first responder in the kit window is something other than the
-                               // window, we assume a subview of the webview is focused. we must send
-                               // the event to the window so that it goes through the kit's normal TSM
-                               // logic, and -- more importantly -- allows any delegates associated
-                               // with the first responder to have a chance at the event.
-                               
-                               err = GetWindowProperty( window, NSAppKitPropertyCreator, NSCarbonWindowPropertyTag, sizeof(NSWindow *), NULL, &kitWindow);
-                               if ( err == noErr )
-                               {
-                                       NSResponder* responder = [kitWindow firstResponder];
-                                       if ( responder != kitWindow )
-                                       {
-                        kitEvent = CreateNSEventWithCarbonEvent(inEvent);
-                                               
-                                               [kitWindow sendEvent:kitEvent];
-                                               [kitEvent release];
-                                               
-                                               result = noErr;
-                                       }
-                               }
-               }
-               break;
-
-        case kEventClassWindow:
-            {
-                NSWindow*      kitWindow;
-                OSStatus       err;
+    case kEventClassKeyboard:
+        // if the first responder in the kit window is something other than the
+        // window, we assume a subview of the webview is focused. we must send
+        // the event to the window so that it goes through the kit's normal TSM
+        // logic, and -- more importantly -- allows any delegates associated
+        // with the first responder to have a chance at the event.
+
+        err = GetWindowProperty(window, NSAppKitPropertyCreator, NSCarbonWindowPropertyTag, sizeof(NSWindow *), nullptr, &kitWindow);
+        if (err == noErr) {
+            NSResponder* responder = [kitWindow firstResponder];
+            if (responder != kitWindow) {
+                kitEvent = CreateNSEventWithCarbonEvent(inEvent);
+                
+                [kitWindow sendEvent:kitEvent];
+                [kitEvent release];
                 
-                err = GetWindowProperty( window, NSAppKitPropertyCreator, NSCarbonWindowPropertyTag, sizeof(NSWindow *), NULL, &kitWindow);
-                if ( err == noErr )
-                {
-                    [kitWindow _removeWindowRef];
-                    [kitWindow close];
-                }
-       
                 result = noErr;
             }
-            break;
+        }
+        break;
+
+    case kEventClassWindow:
         
-        case kEventClassMouse:
-            switch (GetEventKind(inEvent))
-            {
-                case kEventMouseMoved:
-                    {
-                        Point where;
-                        GetEventParameter(inEvent, kEventParamMouseLocation, typeQDPoint, NULL, sizeof(Point), NULL, &where);
-
-                        WindowRef temp;
-                        FindWindow(where, &temp);
-                        if (temp == window)
-                        {
-                            Rect bounds;
-                            GetWindowBounds(window, kWindowStructureRgn, &bounds);
-                            where.h -= bounds.left;
-                            where.v -= bounds.top;
-                            SetEventParameter(inEvent, kEventParamWindowRef, typeWindowRef, sizeof(WindowRef), &window);
-                            SetEventParameter(inEvent, kEventParamWindowMouseLocation, typeQDPoint, sizeof(Point), &where);
-
-                            OSStatus err = noErr;
-                            HIViewRef view = NULL;
-
-                            err = HIViewGetViewForMouseEvent(HIViewGetRoot(window), inEvent, &view);
-                            if (err == noErr && view && HIObjectIsOfClass((HIObjectRef)view, kHIWebViewClassID))
-                                result = SendEventToEventTargetWithOptions(inEvent, HIObjectGetEventTarget((HIObjectRef)view), kEventTargetDontPropagate);
-                        }
-                    }
-                    break;
-                
-                case kEventMouseUp:
-                case kEventMouseDragged:
-                case kEventMouseWheelMoved:
-                    {
-                        OSStatus err = noErr;
-                        HIViewRef view = NULL;
-
-                        err = HIViewGetViewForMouseEvent(HIViewGetRoot(window), inEvent, &view);
-                        if (err == noErr && view && HIObjectIsOfClass((HIObjectRef)view, kHIWebViewClassID))
-                            result = SendEventToEventTargetWithOptions(inEvent, HIObjectGetEventTarget((HIObjectRef)view), kEventTargetDontPropagate);
-                    }
-                    break;
+
+        err = GetWindowProperty(window, NSAppKitPropertyCreator, NSCarbonWindowPropertyTag, sizeof(NSWindow *), nullptr, &kitWindow);
+        if (err == noErr) {
+            [kitWindow _removeWindowRef];
+            [kitWindow close];
+        }
+        result = noErr;
+        break;
+
+    case kEventClassMouse:
+        switch (GetEventKind(inEvent)) {
+        case kEventMouseMoved:
+            Point where;
+            GetEventParameter(inEvent, kEventParamMouseLocation, typeQDPoint, nullptr, sizeof(Point), nullptr, &where);
+
+            WindowRef temp;
+            FindWindow(where, &temp);
+            if (temp == window) {
+                Rect bounds;
+                GetWindowBounds(window, kWindowStructureRgn, &bounds);
+                where.h -= bounds.left;
+                where.v -= bounds.top;
+                SetEventParameter(inEvent, kEventParamWindowRef, typeWindowRef, sizeof(WindowRef), &window);
+                SetEventParameter(inEvent, kEventParamWindowMouseLocation, typeQDPoint, sizeof(Point), &where);
+
+                HIViewRef view = nullptr;
+
+                err = HIViewGetViewForMouseEvent(HIViewGetRoot(window), inEvent, &view);
+                if (err == noErr && view && HIObjectIsOfClass((HIObjectRef)view, kHIWebViewClassID))
+                    result = SendEventToEventTargetWithOptions(inEvent, HIObjectGetEventTarget((HIObjectRef)view), kEventTargetDontPropagate);
             }
             break;
+                
+        case kEventMouseUp:
+        case kEventMouseDragged:
+        case kEventMouseWheelMoved:
+            HIViewRef view = nullptr;
+
+            err = HIViewGetViewForMouseEvent(HIViewGetRoot(window), inEvent, &view);
+            if (err == noErr && view && HIObjectIsOfClass((HIObjectRef)view, kHIWebViewClassID))
+                result = SendEventToEventTargetWithOptions(inEvent, HIObjectGetEventTarget((HIObjectRef)view), kEventTargetDontPropagate);
+            break;
+        }
+        break;
     }
 
-       return result;
+    return result;
 }
 
 
@@ -885,57 +802,52 @@ WindowHandler( EventHandlerCallRef inCallRef, EventRef inEvent, void* inUserData
 // SyncFrame
 //----------------------------------------------------------------------------------
 //
-static void
-SyncFrame( HIWebView* inView )
+static void SyncFrame(HIWebView* inView)
 {
-       HIViewRef       parent = HIViewGetSuperview( inView->fViewRef );
-       
-       if ( parent )
-       {
-        if ( inView->fIsComposited )
-        {
-            HIRect             frame;
-            HIRect             parentBounds;
-            NSPoint            origin;
-
-            HIViewGetFrame( inView->fViewRef, &frame );
-            HIViewGetBounds( parent, &parentBounds );
+    HIViewRef parent = HIViewGetSuperview(inView->fViewRef);
+    
+    if (parent) {
+        if (inView->fIsComposited) {
+            HIRect frame;
+            HIRect parentBounds;
+            NSPoint origin;
+
+            HIViewGetFrame(inView->fViewRef, &frame);
+            HIViewGetBounds(parent, &parentBounds);
             
             origin.x = frame.origin.x;
-            origin.y = parentBounds.size.height - CGRectGetMaxY( frame );
-//    printf( "syncing to (%g %g) (%g %g)\n", origin.x, origin.y,
-//            frame.size.width, frame.size.height );
+            origin.y = parentBounds.size.height - CGRectGetMaxY(frame);
+//    printf("syncing to (%g %g) (%g %g)\n", origin.x, origin.y,
+//            frame.size.width, frame.size.height);
             [inView->fWebView setFrameOrigin: origin];
             [inView->fWebView setFrameSize: *(NSSize*)&frame.size];
-        }
-        else
-        {
-            GrafPtr                    port = GetWindowPort( GetControlOwner( inView->fViewRef ) );
-            PixMapHandle       portPix = GetPortPixMap( port );
-            Rect                       bounds;
-            HIRect                     rootFrame;
-            HIRect                     frame;
-
-            GetControlBounds( inView->fViewRef, &bounds );
-            OffsetRect( &bounds, -(**portPix).bounds.left, -(**portPix).bounds.top );
-
-//            printf( "control lives at %d %d %d %d in window-coords\n", bounds.top, bounds.left,
-//                bounds.bottom, bounds.right );
+        } else {
+            GrafPtr port = GetWindowPort(GetControlOwner(inView->fViewRef));
+            PixMapHandle portPix = GetPortPixMap(port);
+            Rect bounds;
+            HIRect rootFrame;
+            HIRect frame;
+
+            GetControlBounds(inView->fViewRef, &bounds);
+            OffsetRect(&bounds, -(**portPix).bounds.left, -(**portPix).bounds.top);
+
+//            printf("control lives at %d %d %d %d in window-coords\n", bounds.top, bounds.left,
+//                bounds.bottom, bounds.right);
   
-            HIViewGetFrame( HIViewGetRoot( GetControlOwner( inView->fViewRef ) ), &rootFrame );
+            HIViewGetFrame(HIViewGetRoot(GetControlOwner(inView->fViewRef)), &rootFrame);
 
             frame.origin.x = bounds.left;
             frame.origin.y = rootFrame.size.height - bounds.bottom;
             frame.size.width = bounds.right - bounds.left;
             frame.size.height = bounds.bottom - bounds.top;
 
-//            printf( "   before frame convert (%g %g) (%g %g)\n", frame.origin.x, frame.origin.y,
-//                frame.size.width, frame.size.height );
+//            printf("   before frame convert (%g %g) (%g %g)\n", frame.origin.x, frame.origin.y,
+//                frame.size.width, frame.size.height);
             
             [inView->fWebView convertRect:*(NSRect*)&frame fromView:nil];
 
-//            printf( "   moving web view to (%g %g) (%g %g)\n", frame.origin.x, frame.origin.y,
-//                frame.size.width, frame.size.height );
+//            printf("   moving web view to (%g %g) (%g %g)\n", frame.origin.x, frame.origin.y,
+//                frame.size.width, frame.size.height);
 
             [inView->fWebView setFrameOrigin: *(NSPoint*)&frame.origin];
             [inView->fWebView setFrameSize: *(NSSize*)&frame.size];
@@ -947,180 +859,145 @@ SyncFrame( HIWebView* inView )
 // SetFocusPart
 //----------------------------------------------------------------------------------
 //
-static OSStatus
-SetFocusPart(
-       HIWebView*                              view,
-       ControlPartCode                 desiredFocus,
-       RgnHandle                               invalidRgn,
-       Boolean                                 focusEverything,
-       ControlPartCode*                actualFocus )
+static OSStatus SetFocusPart(HIWebView* view, ControlPartCode desiredFocus, RgnHandle invalidRgn, Boolean focusEverything, ControlPartCode* actualFocus)
 {
-    NSView *   freshlyMadeFirstResponderView;
-    SInt32             partCodeToReturn;
+    NSView *freshlyMadeFirstResponderView;
+    SInt32 partCodeToReturn;
 
     // Do what Carbon is telling us to do.
-    if ( desiredFocus == kControlFocusNoPart )
-       {
+    if (desiredFocus == kControlFocusNoPart) {
         // Relinquish the keyboard focus.
-        RelinquishFocus( view, true ); //(autodisplay ? YES : NO));
+        RelinquishFocus(view, true); // (autodisplay ? YES : NO));
         freshlyMadeFirstResponderView = nil;
         partCodeToReturn = kControlFocusNoPart;
-               //NSLog(@"Relinquished the key focus because we have no choice.");
-    }
-       else if ( desiredFocus == kControlFocusNextPart || desiredFocus == kControlFocusPrevPart )
-       {
-        BOOL goForward = (desiredFocus == kControlFocusNextPart );
+        // NSLog(@"Relinquished the key focus because we have no choice.");
+    } else if (desiredFocus == kControlFocusNextPart || desiredFocus == kControlFocusPrevPart) {
+        BOOL goForward = (desiredFocus == kControlFocusNextPart);
 
         // Advance the keyboard focus, maybe right off of this view.  Maybe a subview of this one already has the keyboard focus, maybe not.
-        freshlyMadeFirstResponderView = AdvanceFocus( view, goForward );
+        freshlyMadeFirstResponderView = AdvanceFocus(view, goForward);
         if (freshlyMadeFirstResponderView)
             partCodeToReturn = desiredFocus;
         else
             partCodeToReturn = kControlFocusNoPart;
-        //NSLog(freshlyMadeFirstResponderView ? @"Advanced the key focus." : @"Relinquished the key focus.");
-    }
-       else
-       {
-               // What's this?
-                if (desiredFocus != kControlIndicatorPart) {
-                    check(false);
-                }
-               freshlyMadeFirstResponderView = nil;
-               partCodeToReturn = desiredFocus;
+        // NSLog(freshlyMadeFirstResponderView ? @"Advanced the key focus." : @"Relinquished the key focus.");
+    } else {
+        // What's this?
+        if (desiredFocus != kControlIndicatorPart)
+            ASSERT_NOT_REACHED();
+        freshlyMadeFirstResponderView = nil;
+        partCodeToReturn = desiredFocus;
     }
 
-       view->fFirstResponder = freshlyMadeFirstResponderView;
+    view->fFirstResponder = freshlyMadeFirstResponderView;
 
-       *actualFocus = partCodeToReturn;
+    *actualFocus = partCodeToReturn;
 
-       // Done.
-       return noErr;
+    // Done.
+    return noErr;
 }
 
 //----------------------------------------------------------------------------------
 // AdvanceFocus
 //----------------------------------------------------------------------------------
 //
-static NSView*
-AdvanceFocus( HIWebView* view, bool forward )
+static NSView* AdvanceFocus(HIWebView* view, bool forward)
 {
-    NSResponder*               oldFirstResponder;
-    NSView*                            currentKeyView;
-    NSView*                            viewWeMadeFirstResponder;
+    NSResponder* oldFirstResponder;
+    NSView* currentKeyView;
+    NSView* viewWeMadeFirstResponder;
+    
+    // Focus on some part (subview) of this control (view).
+    // Maybe a subview of this one already has the keyboard focus, maybe not.
+    
+    oldFirstResponder = [view->fKitWindow firstResponder];
+
+    // If we tab out of our NSView, it will no longer be the responder
+    // when we get here. We'll try this trick for now. We might need to
+    // tag the view appropriately.
+
+    if (view->fFirstResponder && ((NSResponder*)view->fFirstResponder != oldFirstResponder))
+        return nullptr;
     
-    // Focus on some part (subview) of this control (view).  Maybe
-       //      a subview of this one already has the keyboard focus, maybe not.
-       
-       oldFirstResponder = [view->fKitWindow firstResponder];
-
-       // If we tab out of our NSView, it will no longer be the responder
-       // when we get here. We'll try this trick for now. We might need to
-       // tag the view appropriately.
-
-       if ( view->fFirstResponder && ( (NSResponder*)view->fFirstResponder != oldFirstResponder ) )
-       {
-               return NULL;
-       }
-       
-       if ( [oldFirstResponder isKindOfClass:[NSView class]] )
-       {
-               NSView*         tentativeNewKeyView;
+    if ([oldFirstResponder isKindOfClass:[NSView class]]) {
+        NSView* tentativeNewKeyView;
 
         // Some view in this window already has the keyboard focus.  It better at least be a subview of this one.
-        NSView*        oldFirstResponderView = (NSView *)oldFirstResponder;
-        check( [oldFirstResponderView isDescendantOf:view->fWebView] );
+        NSView* oldFirstResponderView = (NSView *)oldFirstResponder;
+        ASSERT([oldFirstResponderView isDescendantOf:view->fWebView]);
 
-               if ( oldFirstResponderView != view->fFirstResponder
-                       && ![oldFirstResponderView isDescendantOf:view->fFirstResponder] )
-               {
+        if (oldFirstResponderView != view->fFirstResponder && ![oldFirstResponderView isDescendantOf:view->fFirstResponder]) {
             // Despite our efforts to record what view we made the first responder
-                       // (for use in the next paragraph) we couldn't keep up because the user
-                       // has clicked in a text field to make it the key focus, instead of using
-                       // the tab key.  Find a control on which it's reasonable to invoke
-                       // -[NSView nextValidKeyView], taking into account the fact that
-                       // NSTextFields always pass on first-respondership to a temporarily-
-                       // contained NSTextView.
-
-                       NSView *viewBeingTested;
-                       currentKeyView = oldFirstResponderView;
-                       viewBeingTested = currentKeyView;
-                       while ( viewBeingTested != view->fWebView )
-                       {
-                               if ( [viewBeingTested isKindOfClass:[NSTextField class]] )
-                               {
-                                       currentKeyView = viewBeingTested;
-                                       break;
-                               }
-                               else
-                               {
-                                       viewBeingTested = [viewBeingTested superview];
-                               }
-                       }
-               }
-               else 
-               {
-                       // We recorded which view we made into the first responder the
-                       // last time the user hit the tab key, and nothing has invalidated
-                       // our recorded value since.
-                       
-                       currentKeyView = view->fFirstResponder;
-               }
+            // (for use in the next paragraph) we couldn't keep up because the user
+            // has clicked in a text field to make it the key focus, instead of using
+            // the tab key. Find a control on which it's reasonable to invoke
+            // -[NSView nextValidKeyView], taking into account the fact that
+            // NSTextFields always pass on first-respondership to a temporarily-
+            // contained NSTextView.
+
+            NSView *viewBeingTested;
+            currentKeyView = oldFirstResponderView;
+            viewBeingTested = currentKeyView;
+            while (viewBeingTested != view->fWebView) {
+                if ([viewBeingTested isKindOfClass:[NSTextField class]]) {
+                    currentKeyView = viewBeingTested;
+                    break;
+                }
+                viewBeingTested = [viewBeingTested superview];
+            }
+        } else {
+            // We recorded which view we made into the first responder the
+            // last time the user hit the tab key, and nothing has invalidated
+            // our recorded value since.
+            
+            currentKeyView = view->fFirstResponder;
+        }
 
         // Try to move on to the next or previous key view.  We use the laboriously
-               // recorded/figured currentKeyView instead of just oldFirstResponder as the
-               // jumping-off-point when searching for the next valid key view.  This is so
-               // we don't get fooled if we recently made some view the first responder, but
-               // it passed on first-responder-ness to some temporary subview.
-               
+        // recorded/figured currentKeyView instead of just oldFirstResponder as the
+        // jumping-off-point when searching for the next valid key view. This is so
+        // we don't get fooled if we recently made some view the first responder, but
+        // it passed on first-responder-ness to some temporary subview.
+        //
         // You can't put normal views in a window with Carbon-control-wrapped views.
-               // Stuff like this would break.  M.P. Notice - 12/2/00
+        // Stuff like this would break. M.P. Notice - 12/2/00
 
         tentativeNewKeyView = forward ? [currentKeyView nextValidKeyView] : [currentKeyView previousValidKeyView];
-        if ( tentativeNewKeyView && [tentativeNewKeyView isDescendantOf:view->fWebView] )
-               {
+        if (tentativeNewKeyView && [tentativeNewKeyView isDescendantOf:view->fWebView]) {
             // The user has tabbed to another subview of this control view.  Change the keyboard focus.
             //NSLog(@"Tabbed to the next or previous key view.");
 
             [view->fKitWindow makeFirstResponder:tentativeNewKeyView];
             viewWeMadeFirstResponder = tentativeNewKeyView;
-        }
-               else
-               {
+        } else {
             // The user has tabbed past the subviews of this control view.  The window is the first responder now.
             //NSLog(@"Tabbed past the first or last key view.");
             [view->fKitWindow makeFirstResponder:view->fKitWindow];
             viewWeMadeFirstResponder = nil;
         }
-    }
-       else
-       {
+    } else {
         // No view in this window has the keyboard focus.  This view should
-               // try to select one of its key subviews.  We're not interested in
-               // the subviews of sibling views here.
-
-               //NSLog(@"No keyboard focus in window. Attempting to set...");
-
-               NSView *tentativeNewKeyView;
-               check(oldFirstResponder==fKitWindow);
-               if ( [view->fWebView acceptsFirstResponder] )
-                       tentativeNewKeyView = view->fWebView;
-               else
-                       tentativeNewKeyView = [view->fWebView nextValidKeyView];
-        if ( tentativeNewKeyView && [tentativeNewKeyView isDescendantOf:view->fWebView] )
-               {
+        // try to select one of its key subviews. We're not interested in
+        // the subviews of sibling views here.
+
+        // NSLog(@"No keyboard focus in window. Attempting to set...");
+
+        NSView *tentativeNewKeyView;
+        ASSERT(oldFirstResponder == view->fKitWindow);
+        if ([view->fWebView acceptsFirstResponder])
+            tentativeNewKeyView = view->fWebView;
+        else
+            tentativeNewKeyView = [view->fWebView nextValidKeyView];
+        if (tentativeNewKeyView && [tentativeNewKeyView isDescendantOf:view->fWebView]) {
             // This control view has at least one subview that can take the keyboard focus.
-            if ( !forward )
-                       {
-                // The user has tabbed into this control view backwards.  Find
-                               // and select the last subview of this one that can take the
-                               // keyboard focus.  Watch out for loops of valid key views.
+            if (!forward) {
+                // The user has tabbed into this control view backwards. Find
+                // and select the last subview of this one that can take the
+                // keyboard focus. Watch out for loops of valid key views.
 
                 NSView *firstTentativeNewKeyView = tentativeNewKeyView;
                 NSView *nextTentativeNewKeyView = [tentativeNewKeyView nextValidKeyView];
-                while ( nextTentativeNewKeyView 
-                                               && [nextTentativeNewKeyView isDescendantOf:view->fWebView] 
-                                               && nextTentativeNewKeyView!=firstTentativeNewKeyView)
-                               {
+                while (nextTentativeNewKeyView && [nextTentativeNewKeyView isDescendantOf:view->fWebView] && nextTentativeNewKeyView != firstTentativeNewKeyView) {
                     tentativeNewKeyView = nextTentativeNewKeyView;
                     nextTentativeNewKeyView = [tentativeNewKeyView nextValidKeyView];
                 }
@@ -1131,9 +1008,7 @@ AdvanceFocus( HIWebView* view, bool forward )
             //NSLog(@"Tabbed into the first or last key view.");
             [view->fKitWindow makeFirstResponder:tentativeNewKeyView];
             viewWeMadeFirstResponder = tentativeNewKeyView;
-        }
-               else
-               {
+        } else {
             // This control view has no subviews that can take the keyboard focus.
             //NSLog(@"Can't tab into this view.");
             viewWeMadeFirstResponder = nil;
@@ -1149,59 +1024,53 @@ AdvanceFocus( HIWebView* view, bool forward )
 // RelinquishFocus
 //----------------------------------------------------------------------------------
 //
-static void
-RelinquishFocus( HIWebView* view, bool inAutodisplay )
+static void RelinquishFocus(HIWebView* view, bool inAutodisplay)
 {
-    NSResponder*  firstResponder;
+    NSResponder* firstResponder;
 
     // Apparently Carbon thinks that some subview of this control view has the keyboard focus,
-       // or we wouldn't be being asked to relinquish focus.
+    // or we wouldn't be being asked to relinquish focus.
 
-       firstResponder = [view->fKitWindow firstResponder];
-       if ( [firstResponder isKindOfClass:[NSView class]] )
-       {
-               // Some subview of this control view really is the first responder right now.
-               check( [(NSView *)firstResponder isDescendantOf:view->fWebView] );
+    firstResponder = [view->fKitWindow firstResponder];
+    if ([firstResponder isKindOfClass:[NSView class]]) {
+        // Some subview of this control view really is the first responder right now.
+        ASSERT([(NSView *)firstResponder isDescendantOf:view->fWebView]);
 
-               // Make the window the first responder, so that no view is the key view.
+        // Make the window the first responder, so that no view is the key view.
         [view->fKitWindow makeFirstResponder:view->fKitWindow];
 
-               //      If this control is not allowed to do autodisplay, don't let
-               //      it autodisplay any just-changed focus rings or text on the
-               //      next go around the event loop. I'm probably clearing more
-               //      dirty rects than I have to, but it doesn't seem to hurt in
-               //      the print panel accessory view case, and I don't have time
-               //      to figure out exactly what -[NSCell _setKeyboardFocusRingNeedsDisplay]
-               //      is doing when invoked indirectly from -makeFirstResponder up above.  M.P. Notice - 12/4/00
-
-               if ( !inAutodisplay )
-                       [[view->fWebView opaqueAncestor] _clearDirtyRectsForTree];
+        // If this control is not allowed to do autodisplay, don't let
+        // it autodisplay any just-changed focus rings or text on the
+        // next go around the event loop. I'm probably clearing more
+        // dirty rects than I have to, but it doesn't seem to hurt in
+        // the print panel accessory view case, and I don't have time
+        // to figure out exactly what -[NSCell _setKeyboardFocusRingNeedsDisplay]
+        // is doing when invoked indirectly from -makeFirstResponder up above. M.P. Notice - 12/4/00
+
+        if (!inAutodisplay)
+            [[view->fWebView opaqueAncestor] _clearDirtyRectsForTree];
+    } else {
+        // The Cocoa first responder does not correspond to the Carbon
+        // control that has the keyboard focus. This can happen when
+        // you've closed a dialog by hitting return in an NSTextView
+        // that's a subview of this one; Cocoa closed the window, and
+        // now Carbon is telling this control to relinquish the focus
+        // as it's being disposed. There's nothing to do.
+
+        ASSERT(firstResponder == view->fKitWindow);
     }
-       else
-       {
-               //  The Cocoa first responder does not correspond to the Carbon
-               //      control that has the keyboard focus.  This can happen when
-               //      you've closed a dialog by hitting return in an NSTextView
-               //      that's a subview of this one; Cocoa closed the window, and
-               //      now Carbon is telling this control to relinquish the focus
-               //      as it's being disposed.  There's nothing to do.
-
-               check(firstResponder==window);
-       }
 }
 
 //----------------------------------------------------------------------------------
 // ActiveStateChanged
 //----------------------------------------------------------------------------------
 //
-static void
-ActiveStateChanged( HIWebView* view )
+static void ActiveStateChanged(HIWebView* view)
 {
-       if ( [view->fWebView respondsToSelector:@selector(setEnabled)] )
-       {
-               [(NSControl*)view->fWebView setEnabled: IsControlEnabled( view->fViewRef )];
-               HIViewSetNeedsDisplay( view->fViewRef, true );
-       }
+    if ([view->fWebView respondsToSelector:@selector(setEnabled)]) {
+        [(NSControl*)view->fWebView setEnabled: IsControlEnabled(view->fViewRef)];
+        HIViewSetNeedsDisplay(view->fViewRef, true);
+    }
 }
 
 
@@ -1209,42 +1078,35 @@ ActiveStateChanged( HIWebView* view )
 // ProcessCommand
 //----------------------------------------------------------------------------------
 //
-static OSStatus
-ProcessCommand( HIWebView* inView, const HICommand* inCommand )
+static OSStatus ProcessCommand(HIWebView* inView, const HICommand* inCommand)
 {
-       OSStatus                result = eventNotHandledErr;
-       NSResponder*    resp;
-       
-       resp = [inView->fKitWindow firstResponder];
-
-       if ( [resp isKindOfClass:[NSView class]] )
-       {
-               NSView* respView = (NSView*)resp;
-
-               if ( respView == inView->fWebView
-                       || [respView isDescendantOf: inView->fWebView] )
-               {
-                       switch ( inCommand->commandID )
-                       {
-                               case kHICommandCut:
-                               case kHICommandCopy:
-                               case kHICommandPaste:
-                               case kHICommandClear:
-                               case kHICommandSelectAll:
-                                       {
-                                               SEL selector = _NSSelectorForHICommand( inCommand );
-                                               if ( [respView respondsToSelector:selector] )
-                                               {
-                                                       [respView performSelector:selector withObject:nil];
-                                                       result = noErr;
-                                               }
-                                       }
-                                       break;
-                       }
-               }
-       }
-       
-       return result;
+    OSStatus result = eventNotHandledErr;
+    NSResponder* resp;
+    
+    resp = [inView->fKitWindow firstResponder];
+
+    if ([resp isKindOfClass:[NSView class]]) {
+        NSView* respView = (NSView*)resp;
+
+        if (respView == inView->fWebView || [respView isDescendantOf: inView->fWebView]) {
+            switch (inCommand->commandID) {
+            case kHICommandCut:
+            case kHICommandCopy:
+            case kHICommandPaste:
+            case kHICommandClear:
+            case kHICommandSelectAll: {
+                SEL selector = _NSSelectorForHICommand(inCommand);
+                if ([respView respondsToSelector:selector]) {
+                    [respView performSelector:selector withObject:nil];
+                    result = noErr;
+                }
+                break;
+            }
+            }
+        }
+    }
+    
+    return result;
 }
 
 //----------------------------------------------------------------------------------
@@ -1252,49 +1114,39 @@ ProcessCommand( HIWebView* inView, const HICommand* inCommand )
 //----------------------------------------------------------------------------------
 //
 static OSStatus
-UpdateCommandStatus( HIWebView* inView, const HICommand* inCommand )
+UpdateCommandStatus(HIWebView* inView, const HICommand* inCommand)
 {
-       OSStatus                result = eventNotHandledErr;
-       MenuItemProxy*  proxy = NULL;
-       NSResponder*    resp;
-       
-       resp = [inView->fKitWindow firstResponder];
-       
-       if ( [resp isKindOfClass:[NSView class]] )
-       {
-               NSView* respView = (NSView*)resp;
-
-               if ( respView == inView->fWebView
-                       || [respView isDescendantOf: inView->fWebView] )
-               {
-                       if ( inCommand->attributes & kHICommandFromMenu )
-                       {
-                               SEL selector = _NSSelectorForHICommand( inCommand );
-       
-                               if ( selector )
-                               {
-                                       if ( [resp respondsToSelector: selector] )
-                                       {
-                                               proxy = [[MenuItemProxy alloc] initWithAction: selector];
-                                               
-                        // Can't use -performSelector:withObject: here because the method we're calling returns BOOL, while
-                        // -performSelector:withObject:'s return value is assumed to be an id.
-                        if (wtfObjcMsgSend<BOOL>(resp, @selector(validateUserInterfaceItem:), proxy))
-                                                       EnableMenuItem( inCommand->menu.menuRef, inCommand->menu.menuItemIndex );
-                                               else
-                                                       DisableMenuItem( inCommand->menu.menuRef, inCommand->menu.menuItemIndex );
-                                               
-                                               result = noErr;
-                                       }
-                               }
-                       }
-               }
-       }
-       
-       if ( proxy )
-               [proxy release];
-
-       return result;
+    OSStatus result = eventNotHandledErr;
+    MenuItemProxy* proxy = nullptr;
+    NSResponder* resp;
+    
+    resp = [inView->fKitWindow firstResponder];
+    
+    if ([resp isKindOfClass:[NSView class]]) {
+        NSView* respView = (NSView*)resp;
+
+        if ((respView == inView->fWebView || [respView isDescendantOf: inView->fWebView]) && inCommand->attributes & kHICommandFromMenu) {
+            SEL selector = _NSSelectorForHICommand(inCommand);
+    
+            if (selector && [resp respondsToSelector: selector]) {
+                proxy = [[MenuItemProxy alloc] initWithAction: selector];
+                    
+                // Can't use -performSelector:withObject: here because the method we're calling returns BOOL, while
+                // -performSelector:withObject:'s return value is assumed to be an id.
+                if (wtfObjcMsgSend<BOOL>(resp, @selector(validateUserInterfaceItem:), proxy))
+                    EnableMenuItem(inCommand->menu.menuRef, inCommand->menu.menuItemIndex);
+                else
+                    DisableMenuItem(inCommand->menu.menuRef, inCommand->menu.menuItemIndex);
+                    
+                result = noErr;
+            }
+        }
+    }
+    
+    if (proxy)
+        [proxy release];
+
+    return result;
 }
 
 // Blatantly stolen from AppKit and cropped a bit
@@ -1303,421 +1155,379 @@ UpdateCommandStatus( HIWebView* inView, const HICommand* inCommand )
 // _NSSelectorForHICommand
 //----------------------------------------------------------------------------------
 //
-static SEL
-_NSSelectorForHICommand( const HICommand* inCommand )
+static SEL _NSSelectorForHICommand(const HICommand* inCommand)
 {
-    switch ( inCommand->commandID )
-       {
-        case kHICommandUndo: return @selector(undo:);
-        case kHICommandRedo: return @selector(redo:);
-        case kHICommandCut  : return @selector(cut:);
-        case kHICommandCopy : return @selector(copy:);
-        case kHICommandPaste: return @selector(paste:);
-        case kHICommandClear: return @selector(delete:);
-        case kHICommandSelectAll: return @selector(selectAll:);
-        default: return NULL;
+    switch (inCommand->commandID) {
+    case kHICommandUndo:
+        return @selector(undo:);
+    case kHICommandRedo:
+        return @selector(redo:);
+    case kHICommandCut:
+        return @selector(cut:);
+    case kHICommandCopy:
+        return @selector(copy:);
+    case kHICommandPaste:
+        return @selector(paste:);
+    case kHICommandClear:
+        return @selector(delete:);
+    case kHICommandSelectAll:
+        return @selector(selectAll:);
+    default:
+        return nullptr;
     }
 
-    return NULL;
+    return nullptr;
 }
 
 
 //-----------------------------------------------------------------------------------
-//     HIWebViewEventHandler
+//    HIWebViewEventHandler
 //-----------------------------------------------------------------------------------
-//     Our object's virtual event handler method. I'm not sure if we need this these days.
-//     We used to do various things with it, but those days are long gone...
+//    Our object's virtual event handler method. I'm not sure if we need this these days.
+//    We used to do various things with it, but those days are long gone...
 //
 static OSStatus
-HIWebViewEventHandler(
-       EventHandlerCallRef     inCallRef,
-       EventRef                        inEvent,
-       void *                          inUserData )
+HIWebViewEventHandler(EventHandlerCallRef inCallRef, EventRef inEvent, void *inUserData)
 {
-       OSStatus                        result = eventNotHandledErr;
-       HIPoint                         where;
-       OSType                          tag;
-       void *                          ptr;
-       Size                            size;
-       UInt32                          features;
-       RgnHandle                       region = NULL;
-       ControlPartCode         part;
-       HIWebView*                      view = (HIWebView*)inUserData;
-
-        // [NSApp setWindowsNeedUpdate:YES] must be called before events so that ActivateTSMDocument is called to set an active document. 
-        // Without an active document, TSM will use a default document which uses a bottom-line input window which we don't want.
-        [NSApp setWindowsNeedUpdate:YES];
+    OSStatus result = eventNotHandledErr;
+    HIPoint where;
+    OSType tag;
+    void *ptr;
+    Size size;
+    UInt32 features;
+    RgnHandle region = nullptr;
+    ControlPartCode part;
+    HIWebView* view = (HIWebView*)inUserData;
+
+    // [NSApp setWindowsNeedUpdate:YES] must be called before events so that ActivateTSMDocument is called to set an active document. 
+    // Without an active document, TSM will use a default document which uses a bottom-line input window which we don't want.
+    [NSApp setWindowsNeedUpdate:YES];
         
-       switch ( GetEventClass( inEvent ) )
-       {
-               case kEventClassHIObject:
-                       switch ( GetEventKind( inEvent ) )
-                       {
-                               case kEventHIObjectConstruct:
-                                       {
-                                               HIObjectRef             object;
-
-                                               result = GetEventParameter( inEvent, kEventParamHIObjectInstance,
-                                                               typeHIObjectRef, NULL, sizeof( HIObjectRef ), NULL, &object );
-                                               require_noerr( result, MissingParameter );
-                                               
-                                               // on entry for our construct event, we're passed the
-                                               // creation proc we registered with for this class.
-                                               // we use it now to create the instance, and then we
-                                               // replace the instance parameter data with said instance
-                                               // as type void.
-
-                                               view = HIWebViewConstructor( (HIViewRef)object );
-
-                                               if ( view )
-                                               {
-                                                       SetEventParameter( inEvent, kEventParamHIObjectInstance,
-                                                                       typeVoidPtr, sizeof( void * ), &view ); 
-                                               }
-                                       }
-                                       break;
-                               
-                               case kEventHIObjectDestruct:
-                                       HIWebViewDestructor( view );
-                                       // result is unimportant
-                                       break;
-                       }
-                       break;
-
-               case kEventClassKeyboard:
-                       {
-                NSEvent* kitEvent = CreateNSEventWithCarbonEvent(inEvent);
-                               [view->fKitWindow sendSuperEvent:kitEvent];
-                               [kitEvent release];
-                               result = noErr;
-                       }
-                       break;
-
-               case kEventClassMouse:
-                       switch ( GetEventKind( inEvent ) )
-                       {
-                               case kEventMouseUp:
-                                       result = MouseUp( view, inEvent );
-                                       break;
-                               
-                               case kEventMouseWheelMoved:
-                                       result = MouseWheelMoved( view, inEvent );
-                                       break;
-
-                               case kEventMouseMoved:
-                                       result = MouseMoved( view, inEvent );
-                                       break;
-
-                               case kEventMouseDragged:
-                                       result = MouseDragged( view, inEvent );
-                                       break;
-                       }
-                       break;
-
-               case kEventClassCommand:
-                       {
-                               HICommand               command;
-                               
-                               result = GetEventParameter( inEvent, kEventParamDirectObject, typeHICommand, NULL,
-                                                               sizeof( HICommand ), NULL, &command );
-                               require_noerr( result, MissingParameter );
-                               
-                               switch ( GetEventKind( inEvent ) )
-                               {
-                                       case kEventCommandProcess:
-                                               result = ProcessCommand( view, &command );
-                                               break;
-                                       
-                                       case kEventCommandUpdateStatus:
-                                               result = UpdateCommandStatus( view, &command );
-                                               break;
-                               }
-                       }
-                       break;
-
-               case kEventClassControl:
-                       switch ( GetEventKind( inEvent ) )
-                       {
-                               case kEventControlInitialize:
-                                       features = GetBehaviors();
-                                       SetEventParameter( inEvent, kEventParamControlFeatures, typeUInt32,
-                                                       sizeof( UInt32 ), &features );
-                                       result = noErr;
-                                       break;
-                                       
-                               case kEventControlDraw:
-                                       {
-                                               CGContextRef            context = NULL;
-                                               
-                                               GetEventParameter( inEvent, kEventParamRgnHandle, typeQDRgnHandle, NULL,
-                                                               sizeof( RgnHandle ), NULL, &region );
-                                               GetEventParameter( inEvent, kEventParamCGContextRef, typeCGContextRef, NULL,
-                                                               sizeof( CGContextRef ), NULL, &context );
-
-                                               Draw( view, region, context );
-
-                                               result = noErr;
-                                       }
-                                       break;
-                               
-                               case kEventControlHitTest:
-                                       GetEventParameter( inEvent, kEventParamMouseLocation, typeHIPoint, NULL,
-                                                       sizeof( HIPoint ), NULL, &where );
-                                       part = HitTest( view, &where );
-                                       SetEventParameter( inEvent, kEventParamControlPart, typeControlPartCode, sizeof( ControlPartCode ), &part );
-                                       result = noErr;
-                                       break;
-                                       
-                               case kEventControlGetPartRegion:
-                                       GetEventParameter( inEvent, kEventParamControlPart, typeControlPartCode, NULL,
-                                                       sizeof( ControlPartCode ), NULL, &part );
-                                       GetEventParameter( inEvent, kEventParamControlRegion, typeQDRgnHandle, NULL,
-                                                       sizeof( RgnHandle ), NULL, &region );
-                                       result = GetRegion( view, part, region );
-                                       break;
-                               
-                               case kEventControlGetData:
-                                       GetEventParameter(inEvent, kEventParamControlPart, typeControlPartCode, NULL, sizeof(ControlPartCode), NULL, &part);
-                                       GetEventParameter(inEvent, kEventParamControlDataTag, typeEnumeration, NULL, sizeof(OSType), NULL, &tag);
-                                       GetEventParameter(inEvent, kEventParamControlDataBuffer, typePtr, NULL, sizeof(Ptr), NULL, &ptr);
-                                       GetEventParameter(inEvent, kEventParamControlDataBufferSize, typeByteCount, NULL, sizeof(Size), NULL, &size);
-
-                                       if (tag == kControlKindTag) {
-                                               Size outSize;
-                                               result = noErr;
-
-                                               if (ptr) {
-                                                       if (size != sizeof(ControlKind))
-                                                               result = errDataSizeMismatch;
-                                                       else
-                                                               (*(ControlKind *)ptr) = GetKind();
-                                               }
-
-                                               outSize = sizeof(ControlKind);
-                                               SetEventParameter(inEvent, kEventParamControlDataBufferSize, typeByteCount, sizeof(Size), &outSize);
-                                       }
-
-                                       break;
-                               
-                               case kEventControlBoundsChanged:
-                                       {
-                                               HIRect          prevRect, currRect;
-                                               UInt32          attrs;
-                                               
-                                               GetEventParameter( inEvent, kEventParamAttributes, typeUInt32, NULL,
-                                                               sizeof( UInt32 ), NULL, &attrs );
-                                               GetEventParameter( inEvent, kEventParamOriginalBounds, typeHIRect, NULL,
-                                                               sizeof( HIRect ), NULL, &prevRect );
-                                               GetEventParameter( inEvent, kEventParamCurrentBounds, typeHIRect, NULL,
-                                                               sizeof( HIRect ), NULL, &currRect );
-
-                                               BoundsChanged( view, attrs, &prevRect, &currRect );
-                                               result = noErr;
-                                       }
-                                       break;
-                               
-                               case kEventControlActivate:
-                                       ActiveStateChanged( view );
-                                       result = noErr;
-                                       break;
-                                       
-                               case kEventControlDeactivate:
-                                       ActiveStateChanged( view );
-                                       result = noErr;
-                                       break;
-                                                                                                                       
-                               case kEventControlOwningWindowChanged:
-                                       {
-                                               WindowRef               fromWindow, toWindow;
-                                               
-                                               result = GetEventParameter( inEvent, kEventParamControlOriginalOwningWindow, typeWindowRef, NULL,
-                                                                               sizeof( WindowRef ), NULL, &fromWindow );
-                                               require_noerr( result, MissingParameter );
-
-                                               result = GetEventParameter( inEvent, kEventParamControlCurrentOwningWindow, typeWindowRef, NULL,
-                                                                               sizeof( WindowRef ), NULL, &toWindow );
-                                               require_noerr( result, MissingParameter );
-
-                                               OwningWindowChanged( view, fromWindow, toWindow );
-                                               
-                                               result = noErr;
-                                       }
-                                       break;
-                                    
-                               case kEventControlClick:
-                                       result = Click( view, inEvent );
-                                       break;
+    switch (GetEventClass(inEvent)) {
+    case kEventClassHIObject:
+        switch (GetEventKind(inEvent)) {
+        case kEventHIObjectConstruct:
+            HIObjectRef object;
+
+            result = GetEventParameter(inEvent, kEventParamHIObjectInstance,
+            typeHIObjectRef, nullptr, sizeof(HIObjectRef), nullptr, &object);
+            ASSERT(!result);
+            if (result)
+                return result;
+
+            // on entry for our construct event, we're passed the
+            // creation proc we registered with for this class.
+            // we use it now to create the instance, and then we
+            // replace the instance parameter data with said instance
+            // as type void.
+
+            view = HIWebViewConstructor((HIViewRef)object);
+
+            if (view)
+                SetEventParameter(inEvent, kEventParamHIObjectInstance, typeVoidPtr, sizeof(void *), &view); 
+            break;
+                
+        case kEventHIObjectDestruct:
+            HIWebViewDestructor(view);
+            // result is unimportant
+            break;
+        }
+        break;
+
+    case kEventClassKeyboard: {
+        NSEvent* kitEvent = CreateNSEventWithCarbonEvent(inEvent);
+        [view->fKitWindow sendSuperEvent:kitEvent];
+        [kitEvent release];
+        result = noErr;
+        break;
+    }
+
+    case kEventClassMouse:
+        switch (GetEventKind(inEvent)) {
+        case kEventMouseUp:
+            result = MouseUp(view, inEvent);
+            break;
+        
+        case kEventMouseWheelMoved:
+            result = MouseWheelMoved(view, inEvent);
+            break;
+
+        case kEventMouseMoved:
+            result = MouseMoved(view, inEvent);
+            break;
+
+        case kEventMouseDragged:
+            result = MouseDragged(view, inEvent);
+            break;
+        }
+        break;
+
+    case kEventClassCommand:
+        HICommand command;
+        
+        result = GetEventParameter(inEvent, kEventParamDirectObject, typeHICommand, nullptr, sizeof(HICommand), nullptr, &command);
+        ASSERT(!result);
+        if (result)
+            return result;
+
+        switch (GetEventKind(inEvent)) {
+        case kEventCommandProcess:
+            result = ProcessCommand(view, &command);
+            break;
+    
+        case kEventCommandUpdateStatus:
+            result = UpdateCommandStatus(view, &command);
+            break;
+        }
+        break;
+
+    case kEventClassControl:
+        switch (GetEventKind(inEvent)) {
+        case kEventControlInitialize:
+            features = GetBehaviors();
+            SetEventParameter(inEvent, kEventParamControlFeatures, typeUInt32, sizeof(UInt32), &features);
+            result = noErr;
+            break;
+
+        case kEventControlDraw: {
+            CGContextRef context = nullptr;
+
+            GetEventParameter(inEvent, kEventParamRgnHandle, typeQDRgnHandle, nullptr, sizeof(RgnHandle), nullptr, &region);
+            GetEventParameter(inEvent, kEventParamCGContextRef, typeCGContextRef, nullptr, sizeof(CGContextRef), nullptr, &context);
+
+            Draw(view, region, context);
+            result = noErr;
+            break;
+        }
+
+        case kEventControlHitTest:
+            GetEventParameter(inEvent, kEventParamMouseLocation, typeHIPoint, nullptr, sizeof(HIPoint), nullptr, &where);
+            part = HitTest(view, &where);
+            SetEventParameter(inEvent, kEventParamControlPart, typeControlPartCode, sizeof(ControlPartCode), &part);
+            result = noErr;
+            break;
+
+        case kEventControlGetPartRegion:
+            GetEventParameter(inEvent, kEventParamControlPart, typeControlPartCode, nullptr, sizeof(ControlPartCode), nullptr, &part);
+            GetEventParameter(inEvent, kEventParamControlRegion, typeQDRgnHandle, nullptr, sizeof(RgnHandle), nullptr, &region);
+            result = GetRegion(view, part, region);
+            break;
+                
+        case kEventControlGetData: {
+            GetEventParameter(inEvent, kEventParamControlPart, typeControlPartCode, nullptr, sizeof(ControlPartCode), nullptr, &part);
+            GetEventParameter(inEvent, kEventParamControlDataTag, typeEnumeration, nullptr, sizeof(OSType), nullptr, &tag);
+            GetEventParameter(inEvent, kEventParamControlDataBuffer, typePtr, nullptr, sizeof(Ptr), nullptr, &ptr);
+            GetEventParameter(inEvent, kEventParamControlDataBufferSize, typeByteCount, nullptr, sizeof(Size), nullptr, &size);
+
+            if (tag == kControlKindTag) {
+                Size outSize;
+                result = noErr;
+
+                if (ptr) {
+                    if (size != sizeof(ControlKind))
+                        result = errDataSizeMismatch;
+                    else
+                        (*(ControlKind *)ptr) = GetKind();
+                }
+
+                outSize = sizeof(ControlKind);
+                SetEventParameter(inEvent, kEventParamControlDataBufferSize, typeByteCount, sizeof(Size), &outSize);
+            }
+            break;
+        }
+
+        case kEventControlBoundsChanged: {
+            HIRect prevRect, currRect;
+            UInt32 attrs;
+        
+            GetEventParameter(inEvent, kEventParamAttributes, typeUInt32, nullptr, sizeof(UInt32), nullptr, &attrs);
+            GetEventParameter(inEvent, kEventParamOriginalBounds, typeHIRect, nullptr, sizeof(HIRect), nullptr, &prevRect);
+            GetEventParameter(inEvent, kEventParamCurrentBounds, typeHIRect, nullptr, sizeof(HIRect), nullptr, &currRect);
+
+            BoundsChanged(view, attrs, &prevRect, &currRect);
+            result = noErr;
+            break;
+        }
+
+        case kEventControlActivate:
+            ActiveStateChanged(view);
+            result = noErr;
+            break;
+
+        case kEventControlDeactivate:
+            ActiveStateChanged(view);
+            result = noErr;
+            break;
+        
+        case kEventControlOwningWindowChanged: {
+            WindowRef fromWindow, toWindow;
+
+            result = GetEventParameter(inEvent, kEventParamControlOriginalOwningWindow, typeWindowRef, nullptr, sizeof(WindowRef), nullptr, &fromWindow);
+            ASSERT(!result);
+            if (result)
+                return result;
+
+            result = GetEventParameter(inEvent, kEventParamControlCurrentOwningWindow, typeWindowRef, nullptr, sizeof(WindowRef), nullptr, &toWindow);
+            ASSERT(!result);
+            if (result)
+                return result;
+
+            OwningWindowChanged(view, fromWindow, toWindow);
+            result = noErr;
+            break;
+        }
+
+        case kEventControlClick:
+            result = Click(view, inEvent);
+            break;
                                     
-                               case kEventControlContextualMenuClick:
-                                       result = ContextMenuClick( view, inEvent );
-                                       break;
+        case kEventControlContextualMenuClick:
+            result = ContextMenuClick(view, inEvent);
+            break;
                                     
-                               case kEventControlSetFocusPart:
-                                       {
-                                               ControlPartCode         desiredFocus;
-                                               RgnHandle                       invalidRgn;
-                                               Boolean                         focusEverything;
-                                               ControlPartCode         actualFocus;
-                                               
-                                               result = GetEventParameter( inEvent, kEventParamControlPart, typeControlPartCode, NULL,
-                                                                               sizeof( ControlPartCode ), NULL, &desiredFocus ); 
-                                               require_noerr( result, MissingParameter );
-                                               
-                                               GetEventParameter( inEvent, kEventParamControlInvalRgn, typeQDRgnHandle, NULL,
-                                                               sizeof( RgnHandle ), NULL, &invalidRgn );
-
-                                               focusEverything = false; // a good default in case the parameter doesn't exist
-
-                                               GetEventParameter( inEvent, kEventParamControlFocusEverything, typeBoolean, NULL,
-                                                               sizeof( Boolean ), NULL, &focusEverything );
-
-                                               result = SetFocusPart( view, desiredFocus, invalidRgn, focusEverything, &actualFocus );
-                                               
-                                               if ( result == noErr )
-                                                       verify_noerr( SetEventParameter( inEvent, kEventParamControlPart, typeControlPartCode,
-                                                                       sizeof( ControlPartCode ), &actualFocus ) );
-                                       }
-                                       break;
-                               
-                               // some other kind of Control event
-                               default:
-                                       break;
-                       }
-                       break;
-                       
-               // some other event class
-               default:
-                       break;
-       }
-
-MissingParameter:
-       return result;
+        case kEventControlSetFocusPart: {
+            ControlPartCode desiredFocus;
+            RgnHandle invalidRgn;
+            Boolean focusEverything;
+            ControlPartCode actualFocus;
+            
+            result = GetEventParameter(inEvent, kEventParamControlPart, typeControlPartCode, nullptr, sizeof(ControlPartCode), nullptr, &desiredFocus); 
+            ASSERT(!result);
+            if (result)
+                return result;
+
+            GetEventParameter(inEvent, kEventParamControlInvalRgn, typeQDRgnHandle, nullptr, sizeof(RgnHandle), nullptr, &invalidRgn);
+            focusEverything = false; // a good default in case the parameter doesn't exist
+            GetEventParameter(inEvent, kEventParamControlFocusEverything, typeBoolean, nullptr, sizeof(Boolean), nullptr, &focusEverything);
+
+            result = SetFocusPart(view, desiredFocus, invalidRgn, focusEverything, &actualFocus);
+            if (result == noErr)
+                ASSERT(!SetEventParameter(inEvent, kEventParamControlPart, typeControlPartCode, sizeof(ControlPartCode), &actualFocus));
+            break;
+        }
+
+        // some other kind of Control event
+        default:
+            break;
+        }
+        break;
+
+    // some other event class
+    default:
+        break;
+    }
+    return result;
 }
 
 
 static void UpdateObserver(CFRunLoopObserverRef observer, CFRunLoopActivity activity, void *info);
 
-static void
-StartUpdateObserver( HIWebView* view )
+static void StartUpdateObserver(HIWebView* view)
 {
-       CFRunLoopObserverContext        context;
-       CFRunLoopObserverRef            observer;
-    CFRunLoopRef                               mainRunLoop;
+    CFRunLoopObserverContext context;
+    CFRunLoopObserverRef observer;
+    CFRunLoopRef mainRunLoop;
     
-    check( view->fIsComposited == false );
-    check( view->fUpdateObserver == NULL );
+    ASSERT(!view->fIsComposited);
+    ASSERT(!view->fUpdateObserver);
 
-       context.version = 0;
-       context.info = view;
-       context.retain = NULL;
-       context.release = NULL;
-       context.copyDescription = NULL;
+    context.version = 0;
+    context.info = view;
+    context.retain = nullptr;
+    context.release = nullptr;
+    context.copyDescription = nullptr;
 
-    mainRunLoop = (CFRunLoopRef)GetCFRunLoopFromEventLoop( GetMainEventLoop() );
-       observer = CFRunLoopObserverCreate( NULL, kCFRunLoopEntry | kCFRunLoopBeforeWaiting, true, 0, UpdateObserver, &context );
-       CFRunLoopAddObserver( mainRunLoop, observer, kCFRunLoopCommonModes ); 
+    mainRunLoop = (CFRunLoopRef)GetCFRunLoopFromEventLoop(GetMainEventLoop());
+    observer = CFRunLoopObserverCreate(nullptr, kCFRunLoopEntry | kCFRunLoopBeforeWaiting, true, 0, UpdateObserver, &context);
+    CFRunLoopAddObserver(mainRunLoop, observer, kCFRunLoopCommonModes); 
 
     view->fUpdateObserver = observer;
     
-//    printf( "Update observer started\n" );
+    // printf("Update observer started\n");
 }
 
-static void
-StopUpdateObserver( HIWebView* view )
+static void StopUpdateObserver(HIWebView* view)
 {
-    check( view->fIsComposited == false );
-    check( view->fUpdateObserver != NULL );
+    ASSERT(!view->fIsComposited);
+    ASSERT(view->fUpdateObserver);
 
-    CFRunLoopObserverInvalidate( view->fUpdateObserver );
-    CFRelease( view->fUpdateObserver );
-    view->fUpdateObserver = NULL;
+    CFRunLoopObserverInvalidate(view->fUpdateObserver);
+    CFRelease(view->fUpdateObserver);
+    view->fUpdateObserver = nullptr;
 
-//    printf( "Update observer removed\n" );
+    // printf("Update observer removed\n");
 }
 
 static void 
-UpdateObserver( CFRunLoopObserverRef observer, CFRunLoopActivity activity, void *info )
+UpdateObserver(CFRunLoopObserverRef observer, CFRunLoopActivity activity, void *info)
 {
-       HIWebView*                      view = (HIWebView*)info;
-    RgnHandle                  region = NewRgn();
-    
-//    printf( "Update observer called\n" );
+    HIWebView* view = (HIWebView*)info;
+    RgnHandle region = NewRgn();
 
-    if ( region )
-    {
-        GetWindowRegion( GetControlOwner( view->fViewRef ), kWindowUpdateRgn, region );
+    // printf("Update observer called\n");
+
+    if (region) {
+        GetWindowRegion(GetControlOwner(view->fViewRef), kWindowUpdateRgn, region);
         
-        if ( !EmptyRgn( region ) )
-        {
-            RgnHandle          ourRgn = NewRgn();
-            Rect                       rect;
+        if (!EmptyRgn(region)) {
+            RgnHandle ourRgn = NewRgn();
+            Rect rect;
             
-            GetWindowBounds( GetControlOwner( view->fViewRef ), kWindowStructureRgn, &rect );
+            GetWindowBounds(GetControlOwner(view->fViewRef), kWindowStructureRgn, &rect);
             
-//            printf( "Update region is non-empty\n" );
-            
-            if ( ourRgn )
-            {
-                Rect           rect;
-                GrafPtr                savePort, port;
-                Point          offset = { 0, 0 };
+            // printf("Update region is non-empty\n");
+            if (ourRgn) {
+                Rect rect;
+                GrafPtr savePort, port;
+                Point offset = { 0, 0 };
                 
-                port = GetWindowPort( GetControlOwner( view->fViewRef ) );
+                port = GetWindowPort(GetControlOwner(view->fViewRef));
                 
-                GetPort( &savePort );
-                SetPort( port );
+                GetPort(&savePort);
+                SetPort(port);
                 
-                GlobalToLocal( &offset );
-                OffsetRgn( region, offset.h, offset.v );
+                GlobalToLocal(&offset);
+                OffsetRgn(region, offset.h, offset.v);
 
-                GetControlBounds( view->fViewRef, &rect );
-                RectRgn( ourRgn, &rect );
-                
-//                printf( "our control is at %d %d %d %d\n",
-//                        rect.top, rect.left, rect.bottom, rect.right );
+                GetControlBounds(view->fViewRef, &rect);
+                RectRgn(ourRgn, &rect);
                 
-                GetRegionBounds( region, &rect );
-//                printf( "region is at %d %d %d %d\n",
-//                        rect.top, rect.left, rect.bottom, rect.right );
+                // printf("our control is at %d %d %d %d\n", rect.top, rect.left, rect.bottom, rect.right);
+                GetRegionBounds(region, &rect);
+                // printf("region is at %d %d %d %d\n", rect.top, rect.left, rect.bottom, rect.right);
 
-                SectRgn( ourRgn, region, ourRgn );
+                SectRgn(ourRgn, region, ourRgn);
                 
-                GetRegionBounds( ourRgn, &rect );
-//                printf( "intersection is  %d %d %d %d\n",
-//                       rect.top, rect.left, rect.bottom, rect.right );
-                if ( !EmptyRgn( ourRgn ) )
-                {
-                    RgnHandle  saveVis = NewRgn();
+                GetRegionBounds(ourRgn, &rect);
+                // printf("intersection is  %d %d %d %d\n", rect.top, rect.left, rect.bottom, rect.right);
+                if (!EmptyRgn(ourRgn)) {
+                    RgnHandle saveVis = NewRgn();
                     
-//                    printf( "looks like we should draw\n" );
-
-                    if ( saveVis )
-                    {
-//                        RGBColor     kRedColor = { 0xffff, 0, 0 };
-                        
-                        GetPortVisibleRegion( GetWindowPort( GetControlOwner( view->fViewRef ) ), saveVis );
-                        SetPortVisibleRegion( GetWindowPort( GetControlOwner( view->fViewRef ) ), ourRgn );
+                    // printf("looks like we should draw\n");
+                    if (saveVis) {
+                        // RGBColor kRedColor = { 0xffff, 0, 0 };
+                        GetPortVisibleRegion(GetWindowPort(GetControlOwner(view->fViewRef)), saveVis);
+                        SetPortVisibleRegion(GetWindowPort(GetControlOwner(view->fViewRef)), ourRgn);
                         
-//                        RGBForeColor( &kRedColor );
-//                        PaintRgn( ourRgn );
-//                        QDFlushPortBuffer( port, NULL );
-//                        Delay( 15, NULL );
-
-                        Draw1Control( view->fViewRef );
-                        ValidWindowRgn( GetControlOwner( view->fViewRef ), ourRgn );
+                        // RGBForeColor(&kRedColor);
+                        // PaintRgn(ourRgn);
+                        // QDFlushPortBuffer(port, nullptr);
+                        // Delay(15, nullptr);
+                        Draw1Control(view->fViewRef);
+                        ValidWindowRgn(GetControlOwner(view->fViewRef), ourRgn);
                         
-                        SetPortVisibleRegion( GetWindowPort( GetControlOwner( view->fViewRef ) ), saveVis );
-                        DisposeRgn( saveVis );
+                        SetPortVisibleRegion(GetWindowPort(GetControlOwner(view->fViewRef)), saveVis);
+                        DisposeRgn(saveVis);
                     }
                 }
 
-                SetPort( savePort );
+                SetPort(savePort);
                 
-                DisposeRgn( ourRgn );
+                DisposeRgn(ourRgn);
             }
         }
         
-        DisposeRgn( region );
+        DisposeRgn(region);
     }
 }
 
index c3a092d..7c0cfe6 100644 (file)
@@ -1,3 +1,94 @@
+2017-09-28  Jonathan Bedard  <jbedard@apple.com>
+
+        Build fix for High Sierra 32 bit Mac
+        https://bugs.webkit.org/show_bug.cgi?id=177551
+        <rdar://problem/34690283>
+
+        Reviewed by Alexey Proskuryakov.
+
+        Some assertions have been removed from the SDK. Replace these assertions with equivalent
+        WTF assert code.  Since the files in this patch are using tabs, some style changes were
+        also made.
+
+        * Carbon/CarbonWindowAdapter.mm:
+        (+[CarbonWindowAdapter frameViewClassForStyleMask:]):
+        (-[CarbonWindowAdapter initWithContentRect:styleMask:backing:defer:]):
+        (-[CarbonWindowAdapter initWithCarbonWindowRef:takingOwnership:disableOrdering:carbon:]):
+        (-[CarbonWindowAdapter setViewsNeedDisplay:]):
+        (-[CarbonWindowAdapter initWithCarbonWindowRef:takingOwnership:]):
+        (-[CarbonWindowAdapter dealloc]):
+        (-[CarbonWindowAdapter windowRef]):
+        (-[CarbonWindowAdapter _hasWindowRef]):
+        (-[CarbonWindowAdapter _managesWindowRef]):
+        (-[CarbonWindowAdapter _removeWindowRef]):
+        (-[CarbonWindowAdapter _carbonWindowClass]):
+        (-[CarbonWindowAdapter reconcileToCarbonWindowBounds]):
+        (-[CarbonWindowAdapter sendSuperEvent:]):
+        (-[CarbonWindowAdapter relinquishFocus]):
+        (-[CarbonWindowAdapter _cancelKey:]):
+        (-[CarbonWindowAdapter _commonAwake]):
+        (-[CarbonWindowAdapter _destroyRealWindow:]):
+        (-[CarbonWindowAdapter _oldPlaceWindow:]):
+        (-[CarbonWindowAdapter _termWindowIfOwner]):
+        (-[CarbonWindowAdapter _windowMovedToRect:]):
+        (-[CarbonWindowAdapter constrainFrameRect:toScreen:]):
+        (-[CarbonWindowAdapter selectKeyViewFollowingView:]):
+        (-[CarbonWindowAdapter selectKeyViewPrecedingView:]):
+        (-[CarbonWindowAdapter canBecomeKeyWindow]):
+        (-[CarbonWindowAdapter canBecomeMainWindow]):
+        (-[CarbonWindowAdapter encodeWithCoder:]):
+        (-[CarbonWindowAdapter initWithCoder:]):
+        (-[CarbonWindowAdapter setContentView:]):
+        (-[CarbonWindowAdapter worksWhenModal]):
+        (-[CarbonWindowAdapter _setModalWindowLevel]):
+        (-[CarbonWindowAdapter _clearModalWindowLevel]):
+        (-[CarbonWindowAdapter carbonHICommandIDFromActionSelector:]):
+        (-[CarbonWindowAdapter sendCarbonProcessHICommandEvent:]):
+        (-[CarbonWindowAdapter sendCarbonUpdateHICommandStatusEvent:withMenuRef:andMenuItemIndex:]):
+        (-[CarbonWindowAdapter _handleRootBoundsChanged]):
+        (-[CarbonWindowAdapter _handleContentBoundsChanged]):
+        (-[CarbonWindowAdapter _handleCarbonEvent:callRef:]):
+        (NSCarbonWindowHandleEvent):
+        (-[CarbonWindowAdapter _reallyDoOrderWindow:relativeTo:findKey:forCounter:force:isModal:]):
+        (-[CarbonWindowAdapter _growBoxRect]):
+        * Carbon/HIWebView.mm:
+        (HIWebViewGetWebView):
+        (HIWebViewConstructor):
+        (HIWebViewDestructor):
+        (HIWebViewRegisterClass):
+        (GetBehaviors):
+        (Draw):
+        (HitTest):
+        (GetRegion):
+        (GetWindowRef):
+        (CreateNSEventAdoptingCGEvent):
+        (CopyEventCGEvent):
+        (CreateNSEventWithCarbonClickEvent):
+        (Click):
+        (CreateNSEventWithCarbonEvent):
+        (MouseUp):
+        (CreateNSEventWithCarbonMouseMoveEvent):
+        (MouseMoved):
+        (MouseDragged):
+        (MouseWheelMoved):
+        (ContextMenuClick):
+        (GetKind):
+        (BoundsChanged):
+        (OwningWindowChanged):
+        (WindowHandler):
+        (SyncFrame):
+        (SetFocusPart):
+        (AdvanceFocus):
+        (RelinquishFocus):
+        (ActiveStateChanged):
+        (ProcessCommand):
+        (UpdateCommandStatus):
+        (_NSSelectorForHICommand):
+        (HIWebViewEventHandler):
+        (StartUpdateObserver):
+        (StopUpdateObserver):
+        (UpdateObserver):
+
 2017-09-27  Wenson Hsieh  <wenson_hsieh@apple.com>
 
         Drag event DataTransfer has unexpected types "dyn.ah62d4..."