📄 webbasenetscapepluginview.mm
字号:
[notificationCenter removeObserver:self name:LoginWindowDidSwitchToUserNotification object:nil];}- (void)start{ ASSERT([self currentWindow]); if (_isStarted) return; ASSERT([self webView]); if (![[[self webView] preferences] arePlugInsEnabled]) return; Frame* frame = core([self webFrame]); if (!frame) return; Page* page = frame->page(); if (!page) return; bool wasDeferring = page->defersLoading(); if (!wasDeferring) page->setDefersLoading(true); BOOL result = [self createPlugin]; if (!wasDeferring) page->setDefersLoading(false); if (!result) return; _isStarted = YES; [[self webView] addPluginInstanceView:self]; [self updateAndSetWindow]; if ([self window]) { [self addWindowObservers]; if ([[self window] isKeyWindow]) { [self sendActivateEvent:YES]; } [self restartTimers]; } [self resetTrackingRect]; [self loadStream];}- (void)stop{ if (![self shouldStop]) return; [self removeTrackingRect]; if (!_isStarted) return; _isStarted = NO; [[self webView] removePluginInstanceView:self]; // Stop the timers [self stopTimers]; // Stop notifications and callbacks. [self removeWindowObservers]; [self destroyPlugin];}- (void)viewWillMoveToWindow:(NSWindow *)newWindow{ // We must remove the tracking rect before we move to the new window. // Once we move to the new window, it will be too late. [self removeTrackingRect]; [self removeWindowObservers]; // Workaround for: <rdar://problem/3822871> resignFirstResponder is not sent to first responder view when it is removed from the window [self setHasFocus:NO]; if (!newWindow) { if ([[self webView] hostWindow]) { // View will be moved out of the actual window but it still has a host window. [self stopTimers]; } else { // View will have no associated windows. [self stop]; // Stop observing WebPreferencesChangedNotification -- we only need to observe this when installed in the view hierarchy. // When not in the view hierarchy, -viewWillMoveToWindow: and -viewDidMoveToWindow will start/stop the plugin as needed. [[NSNotificationCenter defaultCenter] removeObserver:self name:WebPreferencesChangedNotification object:nil]; } }}- (void)viewWillMoveToSuperview:(NSView *)newSuperview{ if (!newSuperview) { // Stop the plug-in when it is removed from its superview. It is not sufficient to do this in -viewWillMoveToWindow:nil, because // the WebView might still has a hostWindow at that point, which prevents the plug-in from being destroyed. // There is no need to start the plug-in when moving into a superview. -viewDidMoveToWindow takes care of that. [self stop]; // Stop observing WebPreferencesChangedNotification -- we only need to observe this when installed in the view hierarchy. // When not in the view hierarchy, -viewWillMoveToWindow: and -viewDidMoveToWindow will start/stop the plugin as needed. [[NSNotificationCenter defaultCenter] removeObserver:self name:WebPreferencesChangedNotification object:nil]; }}- (void)viewDidMoveToWindow{ [self resetTrackingRect]; if ([self window]) { // While in the view hierarchy, observe WebPreferencesChangedNotification so that we can start/stop depending // on whether plugins are enabled. [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(preferencesHaveChanged:) name:WebPreferencesChangedNotification object:nil]; // View moved to an actual window. Start it if not already started. [self start]; [self restartTimers]; [self addWindowObservers]; } else if ([[self webView] hostWindow]) { // View moved out of an actual window, but still has a host window. // Call setWindow to explicitly "clip out" the plug-in from sight. // FIXME: It would be nice to do this where we call stopNullEvents in viewWillMoveToWindow. [self updateAndSetWindow]; }}- (void)viewWillMoveToHostWindow:(NSWindow *)hostWindow{ if (!hostWindow && ![self window]) { // View will have no associated windows. [self stop]; // Remove WebPreferencesChangedNotification observer -- we will observe once again when we move back into the window [[NSNotificationCenter defaultCenter] removeObserver:self name:WebPreferencesChangedNotification object:nil]; }}- (void)viewDidMoveToHostWindow{ if ([[self webView] hostWindow]) { // View now has an associated window. Start it if not already started. [self start]; }}#pragma mark NOTIFICATIONS- (void)windowWillClose:(NSNotification *)notification { [self stop]; } - (void)windowBecameKey:(NSNotification *)notification{ [self sendActivateEvent:YES]; [self setNeedsDisplay:YES]; [self restartTimers];}- (void)windowResignedKey:(NSNotification *)notification{ [self sendActivateEvent:NO]; [self setNeedsDisplay:YES]; [self restartTimers];}- (void)windowDidMiniaturize:(NSNotification *)notification{ [self stopTimers];}- (void)windowDidDeminiaturize:(NSNotification *)notification{ [self restartTimers];}- (void)loginWindowDidSwitchFromUser:(NSNotification *)notification{ [self stopTimers];}-(void)loginWindowDidSwitchToUser:(NSNotification *)notification{ [self restartTimers];}- (void)preferencesHaveChanged:(NSNotification *)notification{ WebPreferences *preferences = [[self webView] preferences]; BOOL arePlugInsEnabled = [preferences arePlugInsEnabled]; if ([notification object] == preferences && _isStarted != arePlugInsEnabled) { if (arePlugInsEnabled) { if ([self currentWindow]) { [self start]; } } else { [self stop]; [self setNeedsDisplay:YES]; } }}- (void)renewGState{ [super renewGState]; // -renewGState is called whenever the view's geometry changes. It's a little hacky to override this method, but // much safer than walking up the view hierarchy and observing frame/bounds changed notifications, since you don't // have to track subsequent changes to the view hierarchy and add/remove notification observers. // NSOpenGLView uses the exact same technique to reshape its OpenGL surface. // All of the work this method does may safely be skipped if the view is not in a window. When the view // is moved back into a window, everything should be set up correctly. if (![self window]) return; [self updateAndSetWindow]; [self resetTrackingRect]; // Check to see if the plugin view is completely obscured (scrolled out of view, for example). // For performance reasons, we send null events at a lower rate to plugins which are obscured. BOOL oldIsObscured = _isCompletelyObscured; _isCompletelyObscured = NSIsEmptyRect([self visibleRect]); if (_isCompletelyObscured != oldIsObscured) [self restartTimers];}- (BOOL)becomeFirstResponder{ [self setHasFocus:YES]; return YES;}- (BOOL)resignFirstResponder{ [self setHasFocus:NO]; return YES;}- (WebDataSource *)dataSource{ WebFrame *webFrame = kit(_element->document()->frame()); return [webFrame _dataSource];}- (WebFrame *)webFrame{ return [[self dataSource] webFrame];}- (WebView *)webView{ return [[self webFrame] webView];}- (NSWindow *)currentWindow{ return [self window] ? [self window] : [[self webView] hostWindow];}- (WebCore::HTMLPlugInElement*)element{ return _element.get();}// We want to treat these as regular keyboard events.- (void)cut:(id)sender{ [self keyDown:[NSApp currentEvent]];}- (void)copy:(id)sender{ [self keyDown:[NSApp currentEvent]];}- (void)paste:(id)sender{ [self keyDown:[NSApp currentEvent]];}- (void)selectAll:(id)sender{ [self keyDown:[NSApp currentEvent]];}// AppKit doesn't call mouseDown or mouseUp on right-click. Simulate control-click// mouseDown and mouseUp so plug-ins get the right-click event as they do in Carbon (3125743).- (void)rightMouseDown:(NSEvent *)theEvent{ [self mouseDown:theEvent];}- (void)rightMouseUp:(NSEvent *)theEvent{ [self mouseUp:theEvent];}@end#endif // ENABLE(NETSCAPE_PLUGIN_API)
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -