static WebCore::Frame* getFrameFromHandle(void* objectHandle)
{
    WebCore::Node* node = static_cast<WebCore::Node*>(objectHandle);
    if (!node->inDocument())
        return 0;
    WebCore::Document* document = node->document();
    if (!document)
        return 0;
    return document->frame();
}
Example #2
0
static QString dumpPath(WebCore::Node *node)
{
    QString str = node->nodeName();

    WebCore::Node *parent = node->parentNode();
    while (parent) {
        str.append(QLatin1String(" > "));
        str.append(parent->nodeName());
        parent = parent->parentNode();
    }
    return str;
}
BundleHitTestResultMediaType InjectedBundleHitTestResult::mediaType() const
{
#if !ENABLE(VIDEO)
    return BundleHitTestResultMediaTypeNone;
#else
    WebCore::Node* node = m_hitTestResult.innerNonSharedNode();
    if (!node->isElementNode())
        return BundleHitTestResultMediaTypeNone;
    
    if (!toElement(node)->isMediaElement())
        return BundleHitTestResultMediaTypeNone;
    
    return m_hitTestResult.mediaIsVideo() ? BundleHitTestResultMediaTypeVideo : BundleHitTestResultMediaTypeAudio;    
#endif
}
bool LayoutTestController::pauseTransitionAtTimeOnElementWithId(JSStringRef propertyName, double time, JSStringRef elementId)
{
    if (!mainFrame)
        return false;

    int nameLen = JSStringGetMaximumUTF8CStringSize(propertyName);
    int idLen = JSStringGetMaximumUTF8CStringSize(elementId);
    OwnArrayPtr<char> name = adoptArrayPtr(new char[nameLen]);
    OwnArrayPtr<char> eId = adoptArrayPtr(new char[idLen]);

    JSStringGetUTF8CString(propertyName, name.get(), nameLen);
    JSStringGetUTF8CString(elementId, eId.get(), idLen);

    WebCore::AnimationController* animationController = mainFrame->animation();
    if (!animationController)
        return false;

    WebCore::Node* node = mainFrame->document()->getElementById(eId.get());
    if (!node || !node->renderer())
        return false;

    return animationController->pauseTransitionAtTime(node->renderer(), name.get(), time);
}
Example #5
0
void EditorClientEA::setInputMethodState(bool active)
{
	WebCore::Node* pNode = NULL;
	Frame* frame = m_page->d->page->focusController()->focusedOrMainFrame();
	if (frame && frame->document() && frame->document()->focusedNode())
	{
		pNode = frame->document()->focusedNode();
	}	

	// Note by Arpit Baldeva: If on console(true by default on consoles/can be enabled on PC through emulation), 
	// we detect if the node was focused due to the user input or through javascript.
	// If the node was focused by user input(such as click), we present the editor(emulated keyboard on consoles, debug log on PC).
	// If the node was focused by javascript, we make the cursor jump to the node. In addition, we blur <input>/<textarea> element 
	// so that the user click can bring up the emulated keyboard.
	EA::WebKit::View* pView = m_page->view();
#if defined(EA_PLATFORM_CONSOLE)
	bool onConsole = true;
#elif defined(EA_PLATFORM_WINDOWS)
	bool onConsole = pView->IsEmulatingConsoleOnPC();
#elif defined(EA_PLATFORM_OSX)
	bool onConsole = false;
#endif
	
	if(onConsole && !pView->AllowJSTextInputStateNotificationOnConsole())
	{
		if(!m_page->handle()->mouseCausedEventActive)
		{
			pView->MoveMouseCursorToNode(pNode);
			if (pNode && pNode->isHTMLElement())
			{
				if(pNode->hasTagName(WebCore::HTMLNames::inputTag) || pNode->hasTagName(WebCore::HTMLNames::textareaTag)) 
				{
					HTMLElement* pElement = static_cast<HTMLElement*> (pNode);
					pElement->blur();
				}
			}
			return;
		}
	}
	
	// CSidhall 1/22/09 Added notify user app of text input state for possible virtual keyboard...
	// We can't fully trust the enabled flag because the input field might be a password in which case we still
	// want to activate the keyboard input. So we do our own checking and also get extra info...   

	//Note by Arpit Baldeva: We are interested in the <input> and <textarea> elements. The problem is that we can't rely on the shouldUseInputMethod() of node to reliably detect an
	//editable node since it does not include password(as noted above). Webkit trunk has some cryptic comment explaining why that is the right thing to do. So we do as follows. 
	// We could add a new method to the class hierarchy to achieve following but want to minimize the changes inside core layer.

	bool inputActive	= active;
	bool searchActive	= false;
	bool passwordActive = false;
	EA::WebKit::KeyboardType kbType = EA::WebKit::kDefaultKeyBoard;
	EA::WebKit::InputType inputType = EA::WebKit::kInputTypeNone;

	
    if( pNode && pNode->isHTMLElement())
	{
		if(pNode->hasTagName(WebCore::HTMLNames::inputTag) ) 
		{	
			HTMLInputElement* pInputElement = static_cast<HTMLInputElement*> (pNode);
			inputActive		= pInputElement->isTextField(); // This check makes sure that we are not firing this event with inputActive set to true in case of HTML like <input type="button" value="Click me" onclick="msg()">
			//+ Deprecated
			searchActive	= pInputElement->isSearchField();
			passwordActive	= pInputElement->isPasswordField();
			//-
			
			//New HTML5 input types (text field related)
			if(pInputElement->isEmailField())
				inputType = EA::WebKit::kInputTypeEmail;
			else if (pInputElement->isNumberField())
				inputType = EA::WebKit::kInputTypeNumber;
			else if(pInputElement->isSearchField())
				inputType = EA::WebKit::kInputTypeSearch;
			else if(pInputElement->isTelephoneField())
				inputType = EA::WebKit::kInputTypeTelephone;
			else if(pInputElement->isURLField())
				inputType = EA::WebKit::kInputTypeUrl;
			else if(pInputElement->isPasswordField())
				inputType = EA::WebKit::kInputTypePassword;

		}
/*			//Note by Arpit Baldeva: This will always come back as true but provided the commented out code here for the sack of clarity
		else if(pNode->hasTagName(WebCore::HTMLNames::textareaTag))
		{
			inputActive = enabled;
		}
*/

		HTMLElement* pElement = static_cast<HTMLElement*> (pNode);
		if(pElement->hasClass())
		{
			const WebCore::SpaceSplitString& classNames = pElement->classNames();
			for(int i = 0; i < EA::WebKit::kCountKeyBoardTypes; ++i)
			{
				if(classNames.contains(sKeyBoardClassMap[i].mKeyboardClass))
				{
					kbType = sKeyBoardClassMap[i].mKeyboardType;
					break;
				}
			}
		}
		// Update - 12/20/2010. Since we have the password information available from the HTML, we use it
		// if the keyboard is not overridden.
		if(passwordActive && (kbType == EA::WebKit::kDefaultKeyBoard))
		{
			kbType = EA::WebKit::kPasswordKeyBoard;
		}
    }    

    // Check if should disable the caret.
    if (pView->IsCaretDisabledOnConsole() && frame && frame->selection()) 
        frame->selection()->setCaretVisible(false);

	using namespace EA::WebKit;
	if(EAWebKitClient* const pClient = GetEAWebKitClient(pView))
	{
        // Store the current settings
        EA::WebKit::TextInputStateInfo textInfo;
        textInfo.mpView				= pView;
		textInfo.mpUserData			= pView->GetUserData();
        textInfo.mIsActivated		= inputActive;
        textInfo.mIsPasswordField	= passwordActive;
        textInfo.mIsSearchField		= searchActive;
		textInfo.mKeyboardType		= kbType;
		textInfo.mInputType			= inputType;

        pClient->TextInputState(textInfo);
    }
}
		void DocumentNavigator::FindBestNode(WebCore::Node* rootNode)
		{
			// Note by Arpit Baldeva - Changed the recursive algorithm to an iterative algorithm. This results in 25% to 40% increase in efficiency.
			
			while (rootNode) 
			{
				IsNodeNavigableDelegate nodeNavigableDelegate(mView);
				// As it turns out, getRect on HTMLElement is pretty expensive. So we don't do it inside the delegate as we require getRect here too. We do that check here.
				// It is at least ~15% more efficient and can be up to ~25% more efficient (depends on the page layout and current node you are at).
				nodeNavigableDelegate(rootNode,false);

				if (nodeNavigableDelegate.FoundNode())
				{
					WebCore::HTMLElement* htmlElement = (WebCore::HTMLElement*) rootNode;
					WebCore::IntRect rectAbsolute = htmlElement->getRect();		
					// Adjust the rectangle position based on the frame offset so that we have absolute geometrical position.
					WebCore::FrameView* pFrameView = htmlElement->document()->view(); //Can be NULL
					if(pFrameView)
					{
						rectAbsolute.setX(rectAbsolute.x() + pFrameView->x());
						rectAbsolute.setY(rectAbsolute.y() + pFrameView->y());
					}

					 /* printf("Looking at ELEMENT_NODE : nodeName=%S (%d,%d)->(%d,%d) ThetaRange(%f,%f)\n\n%S\n-----------------------------------\n", 
											htmlElement->tagName().charactersWithNullTermination(),
											rect.topLeft().x(),rect.topLeft().y(),
											rect.bottomRight().x(), rect.bottomRight().y(),
											mMinThetaRange,mMaxThetaRange,
											htmlElement->innerHTML().charactersWithNullTermination()
											);
										*/

					if (!WouldBeTrappedInElement(rectAbsolute,mStartingPosition,mDirection))
					{
						if (!TryingToDoPerpendicularJump(rectAbsolute,mPreviousNodeRect,mDirection))
						{
							if(rectAbsolute.width()>=1 && rectAbsolute.height() >= 1) //Avoid 0 size elements
							{
								if (doAxisCheck(rectAbsolute))
								{
									PolarRegion pr(rectAbsolute, mStartingPosition);

									if (pr.minR < mMinR )
									{
										if (areAnglesInRange(pr.minTheta,pr.maxTheta))
										{
											mMinR = pr.minR;

											EAW_ASSERT( *(uint32_t*)rootNode > 10000000u );

											//mBestNode = rootNode; //We don't assign it here since we do the Z-layer testing later on.
											FoundNodeInfo foundNodeInfo = {rootNode, mMinR};
											mNodeListContainer->mFoundNodes.push_back(foundNodeInfo);
											/*printf("Found ELEMENT_NODE : nodeName=%s (%d,%d)->(%d,%d) polar: R(%f,%f) Theta(%f,%f) ThetaRange(%f,%f)  \n", 
											(char*)htmlElement->nodeName().characters(),
											rect.topLeft().x(),rect.topLeft().y(),
											rect.bottomRight().x(), rect.bottomRight().y(),
											pr.minR,pr.maxR,pr.minTheta,pr.maxTheta,
											mMinThetaRange,mMaxThetaRange
											);*/
											
										} 
										else
										{
											
#if EAWEBKIT_ENABLE_JUMP_NAVIGATION_DEBUGGING
											mNodeListContainer->mRejectedByAngleNodes.push_back(rootNode);
#endif
											/*printf("RejectedA ELEMENT_NODE : nodeName=%s (%d,%d)->(%d,%d) polar: R(%f,%f) Theta(%f,%f) ThetaRange(%f,%f)  \n", 
											(char*)htmlElement->nodeName().characters(),
											rect.topLeft().x(),rect.topLeft().y(),
											rect.bottomRight().x(), rect.bottomRight().y(),
											pr.minR,pr.maxR,pr.minTheta,pr.maxTheta,
											mMinThetaRange,mMaxThetaRange
											);*/
										}
									} 
									else
									{
#if EAWEBKIT_ENABLE_JUMP_NAVIGATION_DEBUGGING
										mNodeListContainer->mRejectedByRadiusNodes.push_back(rootNode);
#endif
										/*printf("RejectedR ELEMENT_NODE : nodeName=%s (%d,%d)->(%d,%d) polar: R(%f,%f) Theta(%f,%f) ThetaRange(%f,%f)  \n", 
										(char*)htmlElement->nodeName().characters(),
										rect.topLeft().x(),rect.topLeft().y(),
										rect.bottomRight().x(), rect.bottomRight().y(),
										pr.minR,pr.maxR,pr.minTheta,pr.maxTheta,
										mMinThetaRange,mMaxThetaRange
										);*/
									}
								}
								else
								{
									//printf(" - failed axis check\n");
								}
							}
							else
							{
								//printf(" - too small\n");
							}
						}
						else 
						{
							//printf(" - perpendicular\n");
						}							
					}
					else
					{
#if EAWEBKIT_ENABLE_JUMP_NAVIGATION_DEBUGGING
						mNodeListContainer->mRejectedWouldBeTrappedNodes.push_back(rootNode);
#endif
					}
				}
				
				rootNode = rootNode->traverseNextNode();
			}

			// Make sure that this element can be jumped to by passing z-check. This makes sure that we jump only on the element
			// at the top most layer (For example, a CSS+JavaScript pop up).
			// We don't try and check against Z-layer in the loop above as it has significant performance penalty. On an average, it causes traversal to be 50% slower. So what we do 
			// instead is to collect all the nodes and at the end, traverse this list from the end to begining. It is important to traverse from end as that is where the most suited element is 
			// based on the position.

			WebCore::Node* bestNode = NULL;
			float radialDistance = FLT_MAX; // A high value so that the max distance between any two elements in the surface is under it.
			bool matched = false;
			for (WebCoreFoundNodeInfoListReverseIterator rIt = mNodeListContainer->mFoundNodes.rbegin(); rIt != mNodeListContainer->mFoundNodes.rend(); ++rIt)
			{
				bestNode = (*rIt).mFoundNode;
				radialDistance = (*rIt).mRadialDistance;
				WebCore::HTMLElement* element = (WebCore::HTMLElement*)bestNode;

				WebCore::Frame*		frame = element->document()->frame();
				WebCore::FrameView* pFrameView = element->document()->view(); 

				WebCore::IntRect rect = element->getRect(); //This list is decently small so we don't worry about caching the rect size.
				// ElementFromPoint expects the point in its own coordinate system so we don't need to adjust the rectangle to its absolute position
				// on screen
				// elementFromPoint API changed compared to 1.x. The simplest thing to do at the moment is to adjust our input.
				int inputX = (rect.x()+rect.width()/2 - pFrameView->scrollX())/frame->pageZoomFactor();
				int inputY = (rect.y()+rect.height()/2 - pFrameView->scrollY())/frame->pageZoomFactor();
				
				WebCore::Node* hitElement = mDocument->elementFromPoint(inputX,inputY);
				while (hitElement)
				{
					if(bestNode == hitElement)
					{
						matched = true;
						break;
					}
					hitElement = hitElement->parentNode();//We need to find the element that responds to the events as that is what we jump to. For example, we don't jump to a "span".
				};

				if(matched)
					break;
			}

			if(matched)
			{
				mBestNode = bestNode;
				mMinR = radialDistance;
			}
			else
			{
				mBestNode = 0; //We didn't match anything based on the Z-layer testing.
				mMinR = FLT_MAX;
			}


			// A way to do Post Order traversal.
			//while (WebCore::Node* firstChild = rootNode->firstChild())
			//	rootNode = firstChild;
			//while(rootNode)
			//{
			//	rootNode = rootNode->traverseNextNodePostOrder();
			//}


/*
			//////////////////////////////////////////////////////////////////////////
			// THEN, FIND THE CHILDREN
			if (rootNode && rootNode->childNodeCount() > 0)
			{
				PassRefPtr<WebCore::NodeList> children = rootNode->childNodes();

				const uint32_t length = children->length();

				for (uint32_t i=0; i < length; ++i)
				{
					WebCore::Node* child = children->item(i);
					if (child)
					{
						FindBestNode(child);
					}
				}
			}
*/		
		}