示例#1
0
PassRefPtr<RenderStyle> StyleResolver::styleForElement(Element* element, RenderStyle* defaultParent)
{
    ASSERT(m_document.frame());
    ASSERT(m_document.settings());

    StyleResolverState state(m_document, element, defaultParent);

    if (state.parentStyle()) {
        SharedStyleFinder styleFinder(state.elementContext(), *this);
        if (RefPtr<RenderStyle> sharedStyle = styleFinder.findSharedStyle())
            return sharedStyle.release();
    }

    if (state.parentStyle()) {
        state.setStyle(RenderStyle::create());
        state.style()->inheritFrom(state.parentStyle());
    } else {
        state.setStyle(defaultStyleForElement());
        state.setParentStyle(RenderStyle::clone(state.style()));
    }

    state.fontBuilder().initForStyleResolve(&state.document(), state.style());

    {
        ElementRuleCollector collector(state.elementContext(), state.style());

        matchRules(*element, collector);

        applyMatchedProperties(state, collector.matchedResult());
    }

    // Cache our original display.
    state.style()->setOriginalDisplay(state.style()->display());

    StyleAdjuster adjuster;
    adjuster.adjustRenderStyle(state.style(), state.parentStyle(), *element);

    if (state.style()->hasViewportUnits())
        m_document.setHasViewportUnits();

    // Now return the style.
    return state.takeStyle();
}
示例#2
0
//Args	-	wVk (WORD) : Input to process : NOT NULL
//			lParam (LPARAM) : lParm passed from hooks
//return -	true : Input was eatten.
//			false : Input was not processed.
bool ProcessInput(WORD wVk, LPARAM lParam)
{
	try {

		WORD scancode = (WORD)(lParam >> 16);
		DWORD dwExtraInfo = GetMessageExtraInfo();
		// If VK_BACK and there is any DontEatBackspace, subtract the DontEatBackspace count from lParam
		if (wVk == VK_BACK && DontEatBackspace > 0 && ((BYTE)scancode == 0xff))
		{
			DontEatBackspace -= lParam & 0xFF;
			if (DontEatBackspace < 0) // lParam is larger then DontEatBackspace
			{ // Eat
				InternalEditor.Delete (0 - DontEatBackspace); // And delete additional sendBackspace (Hack for internal editor)
				DontEatBackspace = 0;
			}
			return false;
		}

		// Do not need to do anything, just pass it
		if (wVk == VK_CONTROL || wVk == VK_MENU || wVk == VK_SHIFT)
			return false;

		BYTE GlobalKeyStates[256];
		GetKeyboardState(GlobalKeyStates); // Get States

		// Store mod keys to use it later
		mksOldState.CTRL = GlobalKeyStates[VK_CONTROL] & 0x80;
		mksOldState.ALT = GlobalKeyStates[VK_MENU] & 0x80;
		mksOldState.SHIFT = GlobalKeyStates[VK_SHIFT] & 0x80;
		mksOldState.CAPS = GlobalKeyStates[VK_CAPITAL] & 0x81;

		Debug(L"CTRL = %x ALT = %x\n", mksOldState.CTRL, mksOldState.ALT);

		wchar_t wcInput = wVk;
		UINT usVk;

		if (usVk = TranslateToUnicode((WORD*)&wcInput, GlobalKeyStates)) // Get Ascii Value
		{ // If there is any ascii value
			if (matchRules(wcInput, usVk, GlobalKeyStates, true )) {// Match for the input
				// Found matched
				return true; // Eaten
			}
			else if (wVk == VK_BACK) {
				// If VK_BACK
				return false;
				//InternalEditor.Delete(lParam & 0xFF); // Delete from internal editor
			}
			else if (klf.layout.eat==true && //eat unused key
				mksOldState.CTRL==false && mksOldState.ALT==false &&
				wcInput > 0x20 && wcInput < 0x7F) {
					InternalEditor.undoEnd();
					return true;
			}
			else if (mksOldState.CTRL==false && mksOldState.ALT==false) {
				InternalEditor.AddInput(wcInput); // Not matched? Just store the input
				return false;
			}
		} else {
			if (wVk != 0xe7) {// unicode input
				if (matchRules(NULL, wVk, GlobalKeyStates, true )) {// Match for the input
					// Found matched
					return true; // Eaten
				}
			}
		}

		//If only one of these two keys are pressed
		if (mksOldState.CTRL ^ mksOldState.ALT){
			Debug(L"(isCTRL ^ isALT)\n");
			InternalEditor.Reset();// restart the internal editor's buffer
			return false;
		}
		
	} catch (...) {
		Debug(L"Caught exception!\n");
	}
	return false;
}
示例#3
0
bool getOutputAndSend(InputRuleInfo * ir_info, WORD wVk, LPBYTE KeyStates)
{
	boost::wcmatch matches;

	const wchar_t * srcString = InternalEditor.GetTextBackward(ir_info->it->estimated_length);
	if (!srcString)
		return false;

	boost::regex_match(srcString, matches, *ir_info->it->regex);

	int len = wcslen((wchar_t*)ir_info->it->rule_it->strOutRule);
	std::wstring outStr ;
	VIRTUALKEYS vks;
	SWITCHES sws;

	/*for (SWITCHES::iterator sws_it = ir_info->it->switches->begin();
		sws_it != ir_info->it->switches->end();
		sws_it++) {
			InternalEditor.invertSwitch(*sws_it);
	}*/

	if (!makeRegex(&outStr, &vks, &sws, ir_info->it->rule_it->strOutRule, len, false, &matches, &ir_info->it->cc))
		return false;

	sendSingleKey(VK_CONTROL, KEYEVENTF_KEYUP);
	sendSingleKey(VK_MENU, KEYEVENTF_KEYUP);
	//sendSingleKey(VK_SHIFT, KEYEVENTF_KEYUP);

	if (!outStr.length())
	{
		if (ir_info->deleted == false)
			// Delete recent added temporary input
			InternalEditor.Delete();

		sendBackspace(wcslen(srcString));

		if (mksOldState.CTRL)
			sendSingleKey(VK_CONTROL, 0);
		if (mksOldState.ALT)
			sendSingleKey(VK_MENU, 0);
		//if (mksOldState.SHIFT)
		//	sendSingleKey(VK_SHIFT, 0);
		return true;
	}

	std::wstring resultStr;
	//std::wstring * temp = new std::wstring(srcString);

	resultStr = boost::regex_replace((std::wstring)srcString, *ir_info->it->regex, outStr);
	//temp->clear();

	if (!resultStr.size()){
		//rise error
		//continue;
		return false;
	}
	if (ir_info->deleted == false)
		// Delete recently added temporary input
		InternalEditor.Delete();

	int srcStringStringLen = wcslen(srcString);

	outStr.assign(resultStr);

	if (srcStringStringLen) {
		int matchLength = getMatchLength(outStr.c_str(), srcString);

		if (matchLength < 0){
			sendBackspace(0 - matchLength);
			matchLength = getMatchLength(outStr.c_str(), srcString);
			sendBackspace(outStr.length() - matchLength);
		}
		else if (srcStringStringLen > matchLength){
			sendBackspace(srcStringStringLen - matchLength);
		}
		outStr.erase(0, matchLength);
	}

	sendKeyStrokes(&outStr);

	int strOutLength = outStr.length();
	if ( strOutLength == 1 && (outStr.at(0)>0x20 && outStr.at(0)<0x7F) ){} else 
	{
		// KeyUp match VKs
		for (VIRTUALKEYS::iterator vk_it = ir_info->it->vk->begin();
			vk_it != ir_info->it->vk->end();
			vk_it++){
				KeyStates[*vk_it] = 0;
		}
		// Do match again
		matchRules(0, 0, KeyStates, false);
	}

	if (mksOldState.CTRL)
		sendSingleKey(VK_CONTROL, 0);
	if (mksOldState.ALT)
		sendSingleKey(VK_MENU, 0);
	//if (mksOldState.SHIFT)
	//	sendSingleKey(VK_SHIFT, 0);

	return true;
}