⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 carbonwindowadapter.mm

📁 linux下开源浏览器WebKit的源码,市面上的很多商用浏览器都是移植自WebKit
💻 MM
📖 第 1 页 / 共 3 页
字号:
    // Initialize for safe returning.    BOOL reconciliationWasNecessary = NO;    // Precondition check.    assert(_contentView);    // 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.");    osStatus = GetWindowBounds(_windowRef, kWindowContentRgn, &windowContentBoundsRect);    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;    newWindowFrameRect.origin.y = NSMaxY([[[NSScreen screens] objectAtIndex:0] frame]) - windowStructureBoundsRect.bottom;    newWindowFrameRect.size.width = windowStructureBoundsRect.right - windowStructureBoundsRect.left;    newWindowFrameRect.size.height = windowStructureBoundsRect.bottom - windowStructureBoundsRect.top;    if (!NSEqualRects(newWindowFrameRect, _frame)) {        [self _setFrame:newWindowFrameRect];        [_borderView setFrameSize:newWindowFrameRect.size];        reconciliationWasNecessary = YES;    }    // Set the content view's frame rect from the Carbon window's content region bounds.    newContentFrameRect.origin.x = windowContentBoundsRect.left - windowStructureBoundsRect.left;    newContentFrameRect.origin.y = windowStructureBoundsRect.bottom - windowContentBoundsRect.bottom;    newContentFrameRect.size.width = windowContentBoundsRect.right - windowContentBoundsRect.left;    newContentFrameRect.size.height = windowContentBoundsRect.bottom - windowContentBoundsRect.top;    oldContentFrameRect = [_contentView frame];    if (!NSEqualRects(newContentFrameRect, oldContentFrameRect)) {        [_contentView setFrame:newContentFrameRect];        reconciliationWasNecessary = YES;    }    // Done.    return reconciliationWasNecessary;}// Handle an event just like an NSWindow would.- (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    BOOL ignoreEvent = NO;    NSEventType eventType = [inEvent type];    if (eventType==NSSystemDefined) {        short eventSubtype = [inEvent subtype];        if (eventSubtype==7) {            ignoreEvent = YES;        }    } else if (eventType == NSKeyDown) {        // Handle command-space as [NSApp sendEvent:] does.        if ([NSInputContext processInputKeyBindings:inEvent]) {            return;        }    }        // Simple.    if (!ignoreEvent) [super sendEvent:inEvent];}- (void)relinquishFocus{    NSResponder*  firstResponder;    // 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.        [self makeFirstResponder:self];    }}- (BOOL)makeFirstResponder:(NSResponder *)aResponder{    // Let NSWindow focus the appropriate NSView.    if (![super makeFirstResponder:aResponder])        return NO;    // Now, if the view we're focusing is in a HIWebView, find the    // corresponding HIWebView for the NSView, and tell carbon to    // clear any focused control.    HIViewRef viewRef = 0;    NSResponder *firstResponder = [self firstResponder];        if ([firstResponder isKindOfClass:[NSView class]]) {        NSView *view = (NSView *)firstResponder;        while (view) {            viewRef = [HIViewAdapter getHIViewForNSView:view];            if (viewRef)                break;            view = [view superview];        }    }    HIViewRef focus;    GetKeyboardFocus (_windowRef, &focus);    if (focus != viewRef) {        SetKeyboardFocus (_windowRef, viewRef, kControlIndicatorPart );    }    return YES;}// There's no override of _addCursorRect:cursor:forView:, despite the fact that NSWindow's invokes [self windowNumber], because Carbon windows won't have subviews, and therefore won't have cursor rects.// 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 {    // 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);        }    }}// Do the right thing for a Carbon window.- (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.");}// There's no override of _commonInitFrame:styleMask:backing:defer:, despite the fact that NSWindow's modifies quite a few instance variables, because it gets called in a harmless way if the class instance is properly initialized with -[NSCarbonWindow initWithCarbonWindowRef:takingOwnership:].// Do the right thing for a Carbon window.- _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;    }// There's no override of _discardCursorRectsForView, despite the fact that NSWindow's invokes [self windowNumber], because Carbon windows won't have subviews, and therefore won't have cursor rects.// There's no override of _forceFlushWindowToScreen, despite the fact that NSWindow's invokes [self windowNumber], because it looks like it might work on Carbon windows as is.// There's no override of _getPositionFromServer, despite the fact that NSWindow's operates on _windowNum, because it's only called from -[NSApplication _activateWindows], which is hopefully about to become obsolete any second now.// There's no override of _globalWindowNum, despite the fact that NSWindow's invokes [self windowNumber], because it looks like it might work on Carbon windows as is.// There's no override of _initContent:styleMask:backing:defer:contentView:, despite the fact that NSWindow's modifies _auxiliaryStorage->_auxWFlags.hasShadow, because it will never get called if the class instance is properly initialized with -[NSCarbonWindow initWithCarbonWindowRef:takingOwnership:].// There's no override of _initContent:styleMask:backing:defer:counterpart:, despite the fact that NSWindow's modifies _auxiliaryStorage->_auxWFlags.hasShadow, because it will never get called if the class instance is properly initialized with -[NSCarbonWindow initWithCarbonWindowRef:takingOwnership:].// Do what NSWindow would do, but then sychronize the Carbon window structures.- (void)_oldPlaceWindow:(NSRect)frameRect {    OSStatus osStatus;    // Do the standard Cocoa thing.    [super _oldPlaceWindow:frameRect];    // 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 = WKSyncWindowWithCGAfterMove(_windowRef);    if (osStatus!=noErr) NSLog(@"A Carbon window's bounds couldn't be synchronized (%i).", (int)osStatus);}// There's no override of _orderOutAndCalcKeyWithCounter:, despite the fact that NSWindow's invokes [self windowNumber], because it looks like it might work on Carbon windows as is.// There's no override of _realHeartBeatThreadContext, despite the fact that NSWindows's invokes [self windowNumber], because it looks like it might not do anything that will effect a Carbon window.// There's no override of _registerWithDockIfNeeded, despite the fact that NSWindow's invokes [self windowNumber], because it looks like it might work on Carbon windows as is.// There's no override of _removeCursorRect:cursor:forView:, despite the fact that NSWindow's invokes [self windowNumber], because Carbon windows won't have subviews, and therefore won't have cursor rects.// There's no override of _setAvoidsActivation:, despite the fact that NSWindow's invokes [self windowNumber], because it looks like it might work on Carbon windows as is.// There's no override of _setFrame:, despite the fact that NSWindow's modifies _frame, because it looks like it might work on Carbon windows as is.  The synchronization of the Carbon window bounds rect to the Cocoa frame rect is done in the overrides of _oldPlaceWindow: and _windowMovedToRect:.// There's no override of _setFrameCommon:display:stashSize:, despite the fact that NSWindow's invokes [self windowNumber], because it looks like it might work on Carbon windows as is.// There's no override of _setWindowNumber:, despite the fact that NSWindow's modifies _windowNum and invokes [self windowNumber], because it looks like it might work on Carbon windows as is.// 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 {    [self _setWindowNumber:-1];    _wFlags.isTerminating = YES;    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];//    }    _wFlags.isTerminating = NO;}// There's no override of _threadContext, despite the fact that NSWindow's invokes [self windowNumber], because it looks like it might not do anything that will effect a Carbon window.// There's no override of _windowMoved:, despite the fact that NSWindow's operates on _windowNum, because it looks like it might work on Carbon windows as is.// Do what NSWindow would do, but then sychronize the Carbon window structures.- (void)_windowMovedToRect:(NSRect)actualFrame {    OSStatus osStatus;    // Do the standard Cocoa thing.    [super _windowMovedToRect:actualFrame];    // Let Carbon know that the window has been moved, unless this method is being called "early."    if (_wFlags.visible) {        osStatus = WKSyncWindowWithCGAfterMove(_windowRef);        if (osStatus!=noErr) NSLog(@"A Carbon window's bounds couldn't be synchronized (%i).", (int)osStatus);    }}- (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)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)makeKeyWindow {	[NSApp _setMouseActivationInProgress:NO];	[NSApp setIsActive:YES];	[super makeKeyWindow];	WKShowKeyAndMain();}// Do the right thing for a Carbon window.- (BOOL)canBecomeKeyWindow {    return YES;}// Do the right thing for a Carbon window.- (BOOL)canBecomeMainWindow {    OSStatus osStatus;    WindowClass windowClass;    // By default, Carbon windows cannot become the main window.    // What about when the default isn't right?  Requiring subclassing seems harsh.  M.P. Warning - 9/17/01    // KW -  modify this to allow document windows to become main    // This is primarily to get the right look, so that you don't have two windows that both look active - one Cocoa document and one Carbon document    osStatus = GetWindowClass(_windowRef, &windowClass);    return (osStatus == noErr && windowClass == kDocumentWindowClass);    }// There's no override of deminiaturize:, despite the fact that NSWindow's invokes [self windowNumber], because it looks like it might work on Carbon windows as is.// There's no override of disableCursorRects, despite the fact that NSWindow's invokes [self windowNumber], because Carbon windows won't have subviews, and therefore won't have cursor rects.// There's no override of enableCursorRects, despite the fact that NSWindow's invokes [self windowNumber], because Carbon windows won't have subviews, and therefore won't have cursor rects.// Do the right thing for a Carbon window.

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -