📄 layouttestcontrollerwin.cpp
字号:
if (!PathAppendW(buffer, component.c_str())) return false; path = wstring(buffer); return true;}static bool followShortcuts(wstring& path){ if (PathFileExists(path.c_str())) return true; // Do we have a shortcut? wstring linkPath = path; linkPath.append(TEXT(".lnk")); if (!PathFileExists(linkPath.c_str())) return true; // We have a shortcut, find its target. COMPtr<IShellLink> shortcut(Create, CLSID_ShellLink); if (!shortcut) return false; COMPtr<IPersistFile> persistFile(Query, shortcut); if (!shortcut) return false; if (FAILED(persistFile->Load(linkPath.c_str(), STGM_READ))) return false; if (FAILED(shortcut->Resolve(0, 0))) return false; WCHAR targetPath[MAX_PATH]; DWORD targetPathLen = _countof(targetPath); if (FAILED(shortcut->GetPath(targetPath, targetPathLen, 0, 0))) return false; if (!PathFileExists(targetPath)) return false; // Use the target path as the result path instead. path = wstring(targetPath); return true;}static bool resolveCygwinPath(const wstring& cygwinPath, wstring& windowsPath){ wstring fileProtocol = L"file://"; bool isFileProtocol = cygwinPath.find(fileProtocol) != string::npos; if (cygwinPath[isFileProtocol ? 7 : 0] != '/') // ensure path is absolute return false; // Get the Root path. WCHAR rootPath[MAX_PATH]; DWORD rootPathSize = _countof(rootPath); DWORD keyType; DWORD result = ::SHGetValueW(HKEY_LOCAL_MACHINE, TEXT("SOFTWARE\\Cygnus Solutions\\Cygwin\\mounts v2\\/"), TEXT("native"), &keyType, &rootPath, &rootPathSize); if (result != ERROR_SUCCESS || keyType != REG_SZ) return false; windowsPath = wstring(rootPath, rootPathSize); int oldPos = isFileProtocol ? 8 : 1; while (1) { int newPos = cygwinPath.find('/', oldPos); if (newPos == -1) { wstring pathComponent = cygwinPath.substr(oldPos); if (!appendComponentToPath(windowsPath, pathComponent)) return false; if (!followShortcuts(windowsPath)) return false; break; } wstring pathComponent = cygwinPath.substr(oldPos, newPos - oldPos); if (!appendComponentToPath(windowsPath, pathComponent)) return false; if (!followShortcuts(windowsPath)) return false; oldPos = newPos + 1; } if (isFileProtocol) windowsPath = fileProtocol + windowsPath; return true;}static wstring cfStringRefToWString(CFStringRef cfStr){ Vector<wchar_t> v(CFStringGetLength(cfStr)); CFStringGetCharacters(cfStr, CFRangeMake(0, CFStringGetLength(cfStr)), (UniChar *)v.data()); return wstring(v.data(), v.size());}void LayoutTestController::setUserStyleSheetLocation(JSStringRef jsURL){ COMPtr<IWebView> webView; if (FAILED(frame->webView(&webView))) return; COMPtr<IWebPreferences> preferences; if (FAILED(webView->preferences(&preferences))) return; RetainPtr<CFStringRef> urlString(AdoptCF, JSStringCopyCFString(0, jsURL)); RetainPtr<CFURLRef> url(AdoptCF, CFURLCreateWithString(0, urlString.get(), 0)); if (!url) return; // Now copy the file system path, POSIX style. RetainPtr<CFStringRef> pathCF(AdoptCF, CFURLCopyFileSystemPath(url.get(), kCFURLPOSIXPathStyle)); if (!pathCF) return; wstring path = cfStringRefToWString(pathCF.get()); wstring resultPath; if (!resolveCygwinPath(path, resultPath)) return; // The path has been resolved, now convert it back to a CFURL. int result = WideCharToMultiByte(CP_UTF8, 0, resultPath.c_str(), resultPath.size() + 1, 0, 0, 0, 0); Vector<char> utf8Vector(result); result = WideCharToMultiByte(CP_UTF8, 0, resultPath.c_str(), resultPath.size() + 1, utf8Vector.data(), result, 0, 0); if (!result) return; url = CFURLCreateFromFileSystemRepresentation(0, (const UInt8*)utf8Vector.data(), utf8Vector.size() - 1, false); if (!url) return; resultPath = cfStringRefToWString(CFURLGetString(url.get())); BSTR resultPathBSTR = SysAllocStringLen(resultPath.data(), resultPath.size()); preferences->setUserStyleSheetLocation(resultPathBSTR); SysFreeString(resultPathBSTR);}void LayoutTestController::setPersistentUserStyleSheetLocation(JSStringRef jsURL){ RetainPtr<CFStringRef> urlString(AdoptCF, JSStringCopyCFString(0, jsURL)); ::setPersistentUserStyleSheetLocation(urlString.get());}void LayoutTestController::clearPersistentUserStyleSheet(){ ::setPersistentUserStyleSheetLocation(0);}void LayoutTestController::setWindowIsKey(bool flag){ COMPtr<IWebView> webView; if (FAILED(frame->webView(&webView))) return; COMPtr<IWebViewPrivate> viewPrivate; if (FAILED(webView->QueryInterface(&viewPrivate))) return; HWND webViewWindow; if (FAILED(viewPrivate->viewWindow((OLE_HANDLE*)&webViewWindow))) return; ::SendMessage(webViewWindow, flag ? WM_SETFOCUS : WM_KILLFOCUS, (WPARAM)::GetDesktopWindow(), 0);}void LayoutTestController::setSmartInsertDeleteEnabled(bool flag){ COMPtr<IWebView> webView; if (FAILED(frame->webView(&webView))) return; COMPtr<IWebViewEditing> viewEditing; if (FAILED(webView->QueryInterface(&viewEditing))) return; viewEditing->setSmartInsertDeleteEnabled(flag ? TRUE : FALSE);}void LayoutTestController::setJavaScriptProfilingEnabled(bool flag){ COMPtr<IWebView> webView; if (FAILED(frame->webView(&webView))) return; COMPtr<IWebViewPrivate> viewPrivate; if (FAILED(webView->QueryInterface(&viewPrivate))) return; COMPtr<IWebPreferences> preferences; if (FAILED(webView->preferences(&preferences))) return; COMPtr<IWebPreferencesPrivate> prefsPrivate(Query, preferences); if (!prefsPrivate) return; COMPtr<IWebInspector> inspector; if (FAILED(viewPrivate->inspector(&inspector))) return; prefsPrivate->setDeveloperExtrasEnabled(flag); inspector->setJavaScriptProfilingEnabled(flag);}void LayoutTestController::setSelectTrailingWhitespaceEnabled(bool flag){ COMPtr<IWebView> webView; if (FAILED(frame->webView(&webView))) return; COMPtr<IWebViewEditing> viewEditing; if (FAILED(webView->QueryInterface(&viewEditing))) return; viewEditing->setSelectTrailingWhitespaceEnabled(flag ? TRUE : FALSE);}static const CFTimeInterval waitToDumpWatchdogInterval = 10.0;static void waitUntilDoneWatchdogFired(CFRunLoopTimerRef timer, void* info){ const char* message = "FAIL: Timed out waiting for notifyDone to be called\n"; fprintf(stderr, message); fprintf(stdout, message); dump();}void LayoutTestController::setWaitToDump(bool waitUntilDone){ // Same as on mac. This can be shared. m_waitToDump = waitUntilDone; if (m_waitToDump && !waitToDumpWatchdog) { waitToDumpWatchdog = CFRunLoopTimerCreate(kCFAllocatorDefault, CFAbsoluteTimeGetCurrent() + waitToDumpWatchdogInterval, 0, 0, 0, waitUntilDoneWatchdogFired, NULL); CFRunLoopAddTimer(CFRunLoopGetCurrent(), waitToDumpWatchdog, kCFRunLoopCommonModes); }}int LayoutTestController::windowCount(){ return openWindows().size();}bool LayoutTestController::elementDoesAutoCompleteForElementWithId(JSStringRef id){ COMPtr<IDOMDocument> document; if (FAILED(frame->DOMDocument(&document))) return false; wstring idWstring = jsStringRefToWString(id); BSTR idBSTR = SysAllocStringLen((OLECHAR*)idWstring.c_str(), idWstring.length()); COMPtr<IDOMElement> element; HRESULT result = document->getElementById(idBSTR, &element); SysFreeString(idBSTR); if (FAILED(result)) return false; COMPtr<IWebFramePrivate> framePrivate(Query, frame); if (!framePrivate) return false; BOOL autoCompletes; if (FAILED(framePrivate->elementDoesAutoComplete(element.get(), &autoCompletes))) return false; return autoCompletes;}void LayoutTestController::execCommand(JSStringRef name, JSStringRef value){ wstring wName = jsStringRefToWString(name); wstring wValue = jsStringRefToWString(value); COMPtr<IWebView> webView; if (FAILED(frame->webView(&webView))) return; COMPtr<IWebViewPrivate> viewPrivate; if (FAILED(webView->QueryInterface(&viewPrivate))) return; BSTR nameBSTR = SysAllocStringLen((OLECHAR*)wName.c_str(), wName.length()); BSTR valueBSTR = SysAllocStringLen((OLECHAR*)wValue.c_str(), wValue.length()); viewPrivate->executeCoreCommandByName(nameBSTR, valueBSTR); SysFreeString(nameBSTR); SysFreeString(valueBSTR);}bool LayoutTestController::isCommandEnabled(JSStringRef /*name*/){ printf("ERROR: LayoutTestController::isCommandEnabled() not implemented\n"); return false;}void LayoutTestController::clearAllDatabases(){ printf("ERROR: LayoutTestController::clearAllDatabases() not implemented\n");}void LayoutTestController::setDatabaseQuota(unsigned long long quota){ printf("ERROR: LayoutTestController::setDatabaseQuota() not implemented\n");}bool LayoutTestController::pauseAnimationAtTimeOnElementWithId(JSStringRef animationName, double time, JSStringRef elementId){ COMPtr<IDOMDocument> document; if (FAILED(frame->DOMDocument(&document))) return false; BSTR idBSTR = JSStringCopyBSTR(elementId); COMPtr<IDOMElement> element; HRESULT hr = document->getElementById(idBSTR, &element); SysFreeString(idBSTR); if (FAILED(hr)) return false; COMPtr<IWebFramePrivate> framePrivate(Query, frame); if (!framePrivate) return false; BSTR nameBSTR = JSStringCopyBSTR(animationName); BOOL wasRunning = FALSE; hr = framePrivate->pauseAnimation(nameBSTR, element.get(), time, &wasRunning); SysFreeString(nameBSTR); return SUCCEEDED(hr) && wasRunning;}bool LayoutTestController::pauseTransitionAtTimeOnElementWithId(JSStringRef propertyName, double time, JSStringRef elementId){ COMPtr<IDOMDocument> document; if (FAILED(frame->DOMDocument(&document))) return false; BSTR idBSTR = JSStringCopyBSTR(elementId); COMPtr<IDOMElement> element; HRESULT hr = document->getElementById(idBSTR, &element); SysFreeString(idBSTR); if (FAILED(hr)) return false; COMPtr<IWebFramePrivate> framePrivate(Query, frame); if (!framePrivate) return false; BSTR nameBSTR = JSStringCopyBSTR(propertyName); BOOL wasRunning = FALSE; hr = framePrivate->pauseTransition(nameBSTR, element.get(), time, &wasRunning); SysFreeString(nameBSTR); return SUCCEEDED(hr) && wasRunning;}unsigned LayoutTestController::numberOfActiveAnimations() const{ COMPtr<IWebFramePrivate> framePrivate(Query, frame); if (!framePrivate) return 0; UINT number = 0; if (FAILED(framePrivate->numberOfActiveAnimations(&number))) return 0; return number;}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -