bool ViewNavigationDelegate::ClickElementsByIdOrClass(const char* idOrClassName)
{
	EAW_ASSERT(idOrClassName);
	if(!idOrClassName || !idOrClassName[0])
		return false;

	IOverlayInputClient* pOverlayInputClient = mView->GetOverlayInputClient();

	if(pOverlayInputClient)
		pOverlayInputClient->OnFocusChangeEvent(false);

	bool elementClicked = false;

	WebCore::Frame* pFrame = mView->GetFrame();
	while(pFrame)
	{
		WebCore::Document* document = pFrame->document();
		EAW_ASSERT(document);

		ClickElementsByIdOrClassDelegate delegate(idOrClassName, true);
		DOMWalker<ClickElementsByIdOrClassDelegate> walker(document, delegate);	
		elementClicked = delegate.GetReturnValue();

		if(elementClicked)
			break;

		pFrame = pFrame->tree()->traverseNext();
	}

	return elementClicked;
}
Example #2
0
//--- MediaPlayerPrivateEA Class ---
MediaPlayerPrivateEA::MediaPlayerPrivateEA(MediaPlayer* player)
    : mpWebCorePlayer(player)
    , mpEAWebKitView(NULL)
    , mHandleID(++sIdGenerator)
    , mIsVisible(false)
    , mIsPlaying(false)
    , mIsFinished(false)
    , mIsLooping(false)
    , mIsVideo(false)    
    , mSize()
    , mNaturalSize()
    , mMovieRect()
    , mWindowRect()
    , mReadyState(MediaPlayer::HaveNothing)
    , mNetworkState(MediaPlayer::Empty)
    , mMediaState(EA::WebKit::MediaUpdateInfo::kIdle)
    , mUpdateTimer(this, &MediaPlayerPrivateEA::UpdateTimerFired)
{
    sRefCount++;    // The refcount is used to auto finalize.
    EAW_ASSERT(player);

    // Find out if this media is video.
    const HTMLMediaElement* element = static_cast<HTMLMediaElement*>(player->mediaPlayerClient());
    mIsVideo = element->isVideo();
}
bool ViewNavigationDelegate::JumpToId(const char* jumpToId)
{
	WebCore::Frame* pFrame = mView->GetFrame();
	// Search for the desired element in all the frames
	while(pFrame)
	{
		WebCore::Document* document = pFrame->document();
		EAW_ASSERT(document);

		if (document)
		{
			JumpToElementWithIdDelegate delegate1(mView, jumpToId);

			DOMWalker<JumpToElementWithIdDelegate> walker(document, delegate1);		
			WebCore::Element* element = delegate1.FoundElement();
			if (element)
			{
				return true;
			}
		}
		pFrame = pFrame->tree()->traverseNext();
	}

	return false;
}
Example #4
0
///////////////////////////////////////////////////////////////////////
// Javascript Callstack Helper
///////////////////////////////////////////////////////////////////////
void JSCallstackCallback(const eastl::vector<eastl::string8> &names, const eastl::vector<eastl::string8> &args, const eastl::vector<int> &lines, const eastl::vector<eastl::string8> &urls)
{
    if (EAWebKitClient *pClient = GetEAWebKitClient())
    {
        const char **nameArray = new const char*[names.size()];
        const char **argArray = new const char*[args.size()];
        int *lineArray = new int[lines.size()];
        const char **urlArray = new const char*[urls.size()];

        EAW_ASSERT(names.size() == args.size() && names.size() == lines.size() && names.size() == urls.size());
        for (int i = 0; i < (int) names.size(); ++i)
        {
            nameArray[i] = names[i].c_str();
            argArray[i] = args[i].c_str();
            lineArray[i] = lines[i];
            urlArray[i] = urls[i].c_str();
        }

        ReportJSCallstackInfo info;
        info.mDepth = (int)names.size();
        info.mNames = nameArray;
        info.mArgs = argArray;
        info.mLines = lineArray;
        info.mUrls = urlArray;

        pClient->ReportJSCallstack(info);

        delete[] nameArray;
        delete[] argArray;
        delete[] lineArray;
        delete[] urlArray;
    }
}
bool FileSystemDefault::OpenFile(FileObject fileObject, const char* path, int openFlags)
{
    FileInfo* pFileInfo = reinterpret_cast<FileInfo*>(fileObject);

    EAW_ASSERT(!pFileInfo->mbOpen);
	if(path && *path)
	{
		//Note by Arpit Baldeva - 
		//Paul Pedriana's real fix for the "\n" in the EAWebKit cookies file not working as intended.
		//Add binary flag 
		//http://msdn.microsoft.com/en-us/library/yeby3zcb%28VS.80%29.aspx
		//b Open in binary (untranslated) mode; translations involving carriage-return and linefeed characters are suppressed. 

	#ifdef _MSC_VER
		pFileInfo->mpFile = fopen(path, openFlags & kWrite ? "wb" : "rb");
	#else
		pFileInfo->mpFile = fopen(path, openFlags & kWrite ? "w" : "r");
	#endif
	}

    if(pFileInfo->mpFile)
        pFileInfo->mbOpen = true;

    return pFileInfo->mbOpen;
}
Example #6
0
const Cursor& enumeratedCursor(CursorId id)
{
    EAW_ASSERT(id < kCursorIdCount);
    Cursor& cursor = Cursor::GetCursorArray()[id];
    cursor.m_impl = id;  // .m_impl is always equal to id by defintion.
    return cursor;
}
Example #7
0
		double currentTime()
        {
			//If the application has installed a timer, use it. 
			if(EA::WebKit::gTimerCallback)
				return EA::WebKit::gTimerCallback();

			FILETIME      ft;
            LARGE_INTEGER li;
            double        dTime;

			SYSTEMTIME systime = {0};
			GetSystemTime(&systime);
			SystemTimeToFileTime(&systime, &ft);

            li.LowPart  = ft.dwLowDateTime;
            li.HighPart = ft.dwHighDateTime;

            // This function requires full double precision FPU math. Some applications reduce 
            // FPU precision in order to run faster. A prime example is DirectX applications. 
			SET_AUTOFPUPRECISION(EA::WebKit::kFPUPrecisionExtended);   

            dTime = (double)li.QuadPart;    // In 100-nanosecond intervals
            dTime /= 10000000.0;            // Convert to Seconds
            dTime -= 11644473600.0;         // Convert from January 1, 1601 to January 1, 1970

            // Make sure we don't have a time measurement bug.
            // If this assertion fails then most likely the 
            #ifdef EA_DEBUG 
                static double dLastTime = 0;
                EAW_ASSERT(dTime >= dLastTime);
                dLastTime = dTime;
            #endif

            return dTime;
        }
Example #8
0
void SoftwareSurface::Lock(SurfaceDescriptor *pSDOut, const IntRect *rect)
{
	EAW_ASSERT_MSG(mStride == mContentWidth * kBytesPerPixel, "Stride calculation mismatch");
	
	pSDOut->mStride = mStride; 
	if (rect)
    {
        pSDOut->mData = mData + (rect->mLocation.mX * kBytesPerPixel) + (rect->mLocation.mY * mStride) ;
        EAW_ASSERT(pSDOut->mData < mData + (mContentHeight * mStride));
        EAW_ASSERT(pSDOut->mData >= mData);
    }
    else
    {
        pSDOut->mData = mData;
    }

}
Example #9
0
bool EventHandler::passWheelEventToWidget(PlatformWheelEvent& event, Widget* widget)
{
    EAW_ASSERT(widget);
    if (!widget->isFrameView())
        return false;

    return static_cast<FrameView*>(widget)->frame()->eventHandler()->handleWheelEvent(event);
}
Example #10
0
bool FileSystemDefault::SetFilePosition(FileObject fileObject, int64_t position)
{
    FileInfo* pFileInfo = reinterpret_cast<FileInfo*>(fileObject);
    EAW_ASSERT(pFileInfo->mpFile);

    int status = fseek(pFileInfo->mpFile, (long) position, SEEK_SET); 
    return !status ? true : false;
}
Example #11
0
Cursor* Cursor::GetCursorArray()
{
    if(!m_spCursorArray)
    {
        m_spCursorArray = new Cursor[kCursorIdCount];
        EAW_ASSERT(m_spCursorArray);
    }
    return m_spCursorArray;
}
Example #12
0
MediaUpdateInfo& MediaPlayerPrivateEA::GetMediaUpdateInfo(void)
{
    if (!spMediaUpdateInfo)
    {
        spMediaUpdateInfo = new MediaUpdateInfo;
        EAW_ASSERT(spMediaUpdateInfo);
    }
    return *spMediaUpdateInfo;
}
int64_t FileSystemDefault::GetFilePosition(FileObject fileObject)
{
    FileInfo* pFileInfo = reinterpret_cast<FileInfo*>(fileObject);
	EAW_ASSERT(pFileInfo->mpFile);

	if(!pFileInfo->mpFile)
		return EA::WebKit::FileSystem::kSizeTypeError;
	
	return ftell(pFileInfo->mpFile);
}
void FileSystemDefault::CloseFile(FileObject fileObject)
{
    FileInfo* pFileInfo = reinterpret_cast<FileInfo*>(fileObject);

    EAW_ASSERT(pFileInfo->mbOpen);
    if(pFileInfo->mbOpen)
	{
		fclose(pFileInfo->mpFile);
		pFileInfo->mbOpen = false;
	}
}
bool ViewNavigationDelegate::ClickElementById(const char* id)
{
	EAW_ASSERT(id);
	if(!id || !id[0])
		return false;

	IOverlayInputClient* pOverlayInputClient = mView->GetOverlayInputClient();


	if(pOverlayInputClient)
		pOverlayInputClient->OnFocusChangeEvent(false);


	bool elementClicked = false;

	WebCore::Frame* pFrame = mView->GetFrame();
	while(pFrame)
	{
		WebCore::Document* document = pFrame->document();
		EAW_ASSERT(document);

		if (document)
		{
			WebCore::Element* element = document->getElementById(id);

			if (element && element->isHTMLElement())
			{    
				WebCore::HTMLElement* htmlElement = (WebCore::HTMLElement*)element;
				htmlElement->click();
				elementClicked = true;
			}
		}

		if(elementClicked)
			break;

		pFrame = pFrame->tree()->traverseNext();
	}

	return elementClicked;
}
int64_t FileSystemDefault::ReadFile(FileObject fileObject, void* buffer, int64_t size)
{
    FileInfo* pFileInfo = reinterpret_cast<FileInfo*>(fileObject);

    EAW_ASSERT(pFileInfo->mbOpen);
    int64_t result = (int64_t)fread(buffer, 1, size, pFileInfo->mpFile);

    if((result != size) && !feof(pFileInfo->mpFile))
        result = EA::WebKit::FileSystem::kSizeTypeError;

    return result;  // result might be different from size simply if the end of file was reached.
}
Example #17
0
void CookiesReceived(TransportInfo* pTInfo)
{
	if(!pTInfo)
		return;

	//Attach new cookies
	WebCore::ResourceHandleManager* pRHM = WebCore::ResourceHandleManager::sharedInstance();
	EAW_ASSERT(pRHM);

	EA::WebKit::CookieManager* pCM = pRHM->GetCookieManager();   
	pCM->OnHeadersRead(pTInfo);

}
Example #18
0
int32_t EAWebKitLib::LoadSSLCertificate(const uint8_t *pCACert, int32_t iCertSize)
{
	SET_AUTOFPUPRECISION(EA::WebKit::kFPUPrecisionExtended);

#if ENABLE(DIRTYSDK_IN_DLL)
    EAWEBKIT_THREAD_CHECK();
    EAWWBKIT_INIT_CHECK(); 
	int32_t result = ProtoSSLSetCACert(pCACert, iCertSize); 
	EAW_ASSERT(result > 0);
	return result;
#else
	EAW_ASSERT_MSG(false, "Invalid call. Loading certificates without enabling the DirtySDK code inside DLL\n");
	return -1;
#endif
}
Example #19
0
void ReattachCookies(TransportInfo* pTInfo)
{
	if(!pTInfo)
		return;

	//Remove existing cookies from the transport headers
	EA::WebKit::HeaderMap::iterator it;
	while((it = GetHeaderMap(pTInfo->mHeaderMapOut)->find_as(EA_CHAR16("Cookie"), EA::WebKit::str_iless())) != GetHeaderMap(pTInfo->mHeaderMapOut)->end())
		GetHeaderMap(pTInfo->mHeaderMapOut)->erase(it);

	//Attach new cookies
	WebCore::ResourceHandleManager* pRHM = WebCore::ResourceHandleManager::sharedInstance();
	EAW_ASSERT(pRHM);

	EA::WebKit::CookieManager* pCM = pRHM->GetCookieManager();   
	pCM->OnHeadersSend(pTInfo);
}
int64_t FileSystemDefault::GetFileSize(FileObject fileObject)
{
    FileInfo* pFileInfo = reinterpret_cast<FileInfo*>(fileObject); 

	EAW_ASSERT(pFileInfo->mpFile);
	
	if(!pFileInfo->mpFile)
		return EA::WebKit::FileSystem::kSizeTypeError;

    // Save the current offset. 
    const int savedPos = ftell(pFileInfo->mpFile); 

    // Read the size. 
    fseek(pFileInfo->mpFile, 0, SEEK_END); 
    const int endPos = ftell(pFileInfo->mpFile); 

    // Restore original offset. 
    fseek(pFileInfo->mpFile, savedPos, SEEK_SET); 

    return endPos; 
}
bool ViewNavigationDelegate::JumpToNearestElement(EA::WebKit::JumpDirection direction, bool scrollIfElementNotFound)
{

	// Note by Arpit Baldeva:
	// We have a problem here. mpModalInputClient object is supposed to be used for Modal input only however the only class using this object 
	// is html SELECT element(implemented as a popup). But in reality, html SELECT element is NOT modal. So it is little ill-conceived. 
	// For example, in all the browsers, if you scroll the mouse wheel on the frame, the SELECT element disappears and the actual frame scrolls.

	// For any modal input needs on a web page, the users are advised to use the Z-layer technique with Javascript/CSS - http://jqueryui.com/demos/dialog/#modal-confirmation.

	// The problem we want to solve here is have the SELECT element respond to the controller input correctly(select element one by one).
	// But the button event information is lost by the time we are in the EA::WebKit::View. For the foreseeable future, there is no candidate
	// other than html SELECT element which is implemented as a modal popup inside EAWebKit. So inside EA::WebKit::View, we create a dummy
	// button event from the Jump direction and make SELECT respond to it. If any other object starts using the modal input, this would need to be
	// revisited. But then, we'll need to solve a plethora of issues. So we do minimum work here to not break other things.

	IOverlayInputClient* pOverlayInputClient = mView->GetOverlayInputClient();

	bool handledByOverlayInputClient = false;
	if(pOverlayInputClient)
	{
		EA::WebKit::ButtonEvent btnEvent;
		switch(direction)
		{
			/*
			case EA::WebKit::JumpLeft:
			{
			btnEvent.mID = EA::WebKit::kButton0;
			handledByOverlayInputClient = pOverlayInputClient->OnButtonEvent(btnEvent);
			}
			*/
		case EA::WebKit::JumpUp:
			{
				btnEvent.mID = EA::WebKit::kButton1;
				handledByOverlayInputClient =  pOverlayInputClient->OnButtonEvent(btnEvent);
				break;
			}
			/*
			case EA::WebKit::JumpRight:
			{
			btnEvent.mID = EA::WebKit::kButton2;
			handledByOverlayInputClient =  pOverlayInputClient->OnButtonEvent(btnEvent);
			}
			*/
		case EA::WebKit::JumpDown:
			{
				btnEvent.mID = EA::WebKit::kButton3;
				handledByOverlayInputClient =  pOverlayInputClient->OnButtonEvent(btnEvent);
				break;
			}
		default:
			// We don't return and allow any other button press to go to the main View. At the same time, we make the SELECT element lose focus.
			{
				pOverlayInputClient->OnFocusChangeEvent(false);
				break;
			}
		}
	}

	if(handledByOverlayInputClient)
		return true;

	int lastX, lastY;
	mView->GetCursorPosition(lastX, lastY);

	// Following is a shortcut to drive navigation from a page.
	switch (direction)
	{
	case EA::WebKit::JumpRight:
		if (GetFixedString(mCachedNavigationRightId)->compare(""))
		{
			if (!GetFixedString(mCachedNavigationRightId)->compare("ignore"))
			{
				return false;
			}

			if (JumpToId(GetFixedString(mCachedNavigationRightId)->c_str()))
			{
				return true;
			}
		}
		break;

	case EA::WebKit::JumpDown:
		if (GetFixedString(mCachedNavigationDownId)->compare(""))
		{
			if (!GetFixedString(mCachedNavigationDownId)->compare("ignore"))
			{
				return false;
			}

			if (JumpToId(GetFixedString(mCachedNavigationDownId)->c_str()))
			{
				return true;
			}
		}
		break;

	case EA::WebKit::JumpLeft:
		if (GetFixedString(mCachedNavigationLeftId)->compare(""))
		{
			if (!GetFixedString(mCachedNavigationLeftId)->compare("ignore"))
			{
				return false;
			}

			if (JumpToId(GetFixedString(mCachedNavigationLeftId)->c_str()))
			{
				return true;
			}
		}
		break;

	case EA::WebKit::JumpUp:
		if (GetFixedString(mCachedNavigationUpId)->compare(""))
		{
			if (!GetFixedString(mCachedNavigationUpId)->compare("ignore"))
			{
				return false;
			}

			if (JumpToId(GetFixedString(mCachedNavigationUpId)->c_str()))
			{
				return true;
			}
		}
		break;

	default:
		EAW_FAIL_MSG("Should not have got here\n");
	}


	// Iterate over all the frames and find the closest element in any of all the frames.
	WebCore::Frame* pFrame		= mView->GetFrame();
	float currentRadialDistance = FLT_MAX; // A high value to start with so that the max distance between any two elements in the surface is under it.
	WebCore::Node* currentBestNode = NULL;
	while(pFrame)
	{
		WebCore::Document* document = pFrame->document();
		EAW_ASSERT(document);

		if(document)
		{
			WebCore::FrameView* pFrameView = document->view();
			WebCore::IntPoint scrollOffset;
			if(pFrameView)
			{
 				scrollOffset.setX(pFrameView->scrollOffset().width());
 				scrollOffset.setY(pFrameView->scrollOffset().height());
			}

			// We figure out the start position(It is center of the currently hovered element almost all the time but can be slightly different 
			// due to scroll sometimes).
			mCentreX = lastX + scrollOffset.x();
			mCentreY = lastY + scrollOffset.y();

			DocumentNavigator navigator(mView, document, direction, WebCore::IntPoint(mCentreX, mCentreY), mBestNodeX, mBestNodeY, mBestNodeWidth, mBestNodeHeight, mJumpNavigationParams.mNavigationTheta, mJumpNavigationParams.mStrictAxesCheck, currentRadialDistance);
			navigator.FindBestNode(document);

			if(navigator.GetBestNode())
			{
				currentBestNode			= navigator.GetBestNode();
				currentRadialDistance	= navigator.GetBestNodeRadialDistance();
			}

		}

		pFrame = pFrame->tree()->traverseNext();
	}

	bool foundSomething = false;
	if (currentBestNode) //We found the node to navigate. Move the cursor and we are done.
	{
		foundSomething = true;
		MoveMouseCursorToNode(currentBestNode, false);
	}
	else if(scrollIfElementNotFound)// Node is not found. 
	{
		// Based on the intended direction of movement, scroll so that some newer elements are visible.
		
		int cursorPosBeforeScrollX, cursorPosBeforeScrollY;
		mView->GetCursorPosition(cursorPosBeforeScrollX, cursorPosBeforeScrollY);

		switch(direction)
		{
		case EA::WebKit::JumpDown:
			{
				ScrollOnJump(true, -120, mJumpNavigationParams.mNumLinesToAutoScroll);
				break;
			}

		case EA::WebKit::JumpUp:
			{
				ScrollOnJump(true, 120, mJumpNavigationParams.mNumLinesToAutoScroll);
				break;
			}
		case EA::WebKit::JumpRight:
			{
				ScrollOnJump(false, -120, mJumpNavigationParams.mNumLinesToAutoScroll);
				break;
			}
		case EA::WebKit::JumpLeft:
			{
				ScrollOnJump(false, 120, mJumpNavigationParams.mNumLinesToAutoScroll);
				break;
			}
		default:
			{
				EAW_ASSERT_MSG(false, "Should not reach here\n");
			}
		}

		// We move the mouse cursor back to the location where the last best node was found. This is so that we don't end up with the cursor being in no man's land. While that may work 
		// for ordinary sites, it may not work well with customized pages that leverage CSS to visually indicate current position rather than a cursor graphic.
		// We don't call MoveMouseCursorToNode() with last cached node as there are edge cases where we may be holding an invalid node. Using a cached frame and checking against the
		// current valid frames safeguards against that.

		WebCore::IntSize scrollOffset;
		WebCore::Frame* pFrame1	= mView->GetFrame();
		while(pFrame1)
		{
			if(pFrame1 == mBestNodeFrame)//Find the frame where last best node existed.
			{
				if(pFrame1->view())
				{
					scrollOffset = pFrame1->view()->scrollOffset();//We read scroll offset here as it could have changed in the switch statement above.
					break;
				}
			}
			pFrame1 = pFrame1->tree()->traverseNext();
		}
		
		int targetcursorPosAfterScrollX, targetcursorPosAfterScrollY;
		targetcursorPosAfterScrollX = mBestNodeX + mBestNodeWidth / 2 - scrollOffset.width();
		targetcursorPosAfterScrollY = mBestNodeY + mBestNodeHeight/ 2 - scrollOffset.height();

		EA::WebKit::MouseMoveEvent moveEvent;
		memset( &moveEvent, 0, sizeof(moveEvent) );
		
		const int cursorInset = 5;// Make cursor stay inside 5 pixels from boundaries. No known issues but added this as a safety measure so that we do not lose cursor ever.
		
		int width = mView->GetSize().mWidth;
		int height = mView->GetSize().mHeight;

		moveEvent.mX	= Clamp( cursorInset, targetcursorPosAfterScrollX, width - cursorInset );
		moveEvent.mY	= Clamp( cursorInset, targetcursorPosAfterScrollY, height - cursorInset );


		mView->OnMouseMoveEvent(moveEvent);
		// We intentionally don't call JumpToNearestElement(direction, false) here to avoid recursion. We do it in the overloaded function above.
	}
		
	return foundSomething;
}
		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);
					}
				}
			}
*/		
		}
Example #23
0
void MediaPlayerPrivateEA::paint(GraphicsContext* context, const IntRect& r)
{
    if (!context)
        return;

    // Can get a NULL platform context so need to verify.  Seems that UpdateControlTints does what is called a "fake" paint
    // with a null platform context just to get an invalidate.
    PlatformContextCairo* pPlatformContext = context->platformContext();
    if (!pPlatformContext)
        return;

    cairo_t* cr = context->platformContext()->cr();
    if (!cr)
        return;

    MediaUpdateInfo& info = GetMediaUpdateInfo();
    const FrameView* pFV = mpWebCorePlayer->frameView();
    if (!pFV)
        return;

    // Convert and store movie rect to device coords using the graphic context.
    double x = (double) r.x();
    double y = (double) r.y();
    double w = (double) r.width();
    double h = (double) r.height();
    cairo_user_to_device (cr, &x, &y);
    cairo_user_to_device_distance(cr, &w, &h);  
    const IntRect rect((int) x, (int) y, (int) w, (int) h);
   
    // The intersection of frameView contents and the movie is used as clip rect for we just want to know what part of the movie is visible.
    IntRect clip = pFV->windowClipRect(true);
    clip.intersect(rect);
    
    // Find controls intersection
    HTMLMediaElement* element = static_cast<HTMLMediaElement*>(mpWebCorePlayer->mediaPlayerClient());
    if(element && element->controls())
    {
        MediaControls* pControls = element->mediaControls();    
        bool hideControls = pControls->shouldHideControls(); 
        if (!hideControls)
        {
            const int kControlHeight = 16;  // EAWebKitTODO: Consider finding a way to extract this info directly from the controls or pass as a theme param.
            
            IntRect boundingRect = pControls->getRect();
            x = (double) boundingRect.x();
            y = (double) boundingRect.y();
            w = (double) boundingRect.width();
            h = (double) (boundingRect.height() - kControlHeight);
            cairo_user_to_device (cr, &x, &y);
            cairo_user_to_device_distance(cr, &w, &h);  
            const IntRect ctrlRect((int) x, (int) y, (int) w, (int) h);
            clip.intersect(ctrlRect);
        }
    }

    if ((rect != mMovieRect) || (clip != mWindowRect))
    {
        mMovieRect = rect;      // Store copy locally to detect changes.
        mWindowRect = clip;

        info.mMovieRect = rect;
        info.mWindowRect = clip;
        ClientUpdate(MediaUpdateInfo::kWindowSize);
    }    
 
    ClientUpdate(MediaUpdateInfo::kPaint);
    if (info.mReturnData)
    {
        // Draw surface to view
#ifndef NDEBUG
        static bool sAssertChecked = false;
        if(!sAssertChecked)
        {
            EAW_ASSERT(!info.mReturnData);   
            sAssertChecked = true;
        }
#endif
        context->save(); 
        RefPtr<cairo_surface_t> cairoSurface = adoptRef(cairo_image_surface_create_for_data((unsigned char*) info.mReturnData, CAIRO_FORMAT_ARGB32, w, h, w * sizeof(uint32_t)));
        EAW_ASSERT(cairo_surface_status(cairoSurface.get()) == CAIRO_STATUS_SUCCESS);
        cairo_set_source_surface(cr, cairoSurface.get(), rect.x(), rect.y()); 
        cairo_paint(cr);
        context->restore(); 
    }
    else
    {
        // Draw a default black background.
        context->save(); 
        context->setStrokeStyle(NoStroke);
        context->setFillColor(Color::black, ColorSpaceDeviceRGB);
        context->drawRect(r);    
        context->restore();
    }
}