void* WKAccessibilityRootObject(WKBundlePageRef pageRef) { #if HAVE(ACCESSIBILITY) if (!pageRef) return 0; WebCore::Page* page = toImpl(pageRef)->corePage(); if (!page) return 0; WebCore::Frame* core = page->mainFrame(); if (!core || !core->document()) return 0; WebCore::AXObjectCache::enableAccessibility(); WebCore::AccessibilityObject* root = core->document()->axObjectCache()->rootObject(); if (!root) return 0; return root->wrapper(); #else return 0; #endif }
static void printFrames(const WebCore::Frame& frame, const WebCore::Frame* targetFrame, int indent) { if (&frame == targetFrame) { printf("--> "); printIndent(indent - 1); } else printIndent(indent); WebCore::FrameView* view = frame.view(); printf("Frame %p %dx%d\n", &frame, view ? view->width() : 0, view ? view->height() : 0); printIndent(indent); printf(" ownerElement=%p\n", frame.ownerElement()); printIndent(indent); printf(" frameView=%p (needs layout %d)\n", view, view ? view->needsLayout() : false); printIndent(indent); printf(" renderView=%p\n", view ? view->renderView() : nullptr); printIndent(indent); printf(" ownerRenderer=%p\n", frame.ownerRenderer()); printIndent(indent); printf(" document=%p (needs style recalc %d)\n", frame.document(), frame.document() ? frame.document()->childNeedsStyleRecalc() : false); printIndent(indent); printf(" uri=%s\n", frame.document()->documentURI().utf8().data()); for (WebCore::Frame* child = frame.tree().firstChild(); child; child = child->tree().nextSibling()) printFrames(*child, targetFrame, indent + 1); }
wxWebEditCommand::wxWebEditCommand(wxWebFrame* webframe) { if (webframe) { WebCore::Frame* frame = webframe->GetFrame(); if (frame && frame->document()) m_impl = new WebCoreEditCommandPrivate(new WebCore::WebCoreEditCommand(frame->document())); } }
// SAMSUNG CHANGE : CopyImage >> // Copy Image Issue on Nested Frame CachedResource *retrieveCachedResource(Frame* frame, String imageUrl) { if (NULL == frame || imageUrl.isEmpty()) return NULL; FrameTree *frameTree = frame->tree(); if (!frameTree) return frame->document()->cachedResourceLoader()->cachedResource(imageUrl); WebCore::Frame *childFrame = frameTree->firstChild(); Document *childFrameDocument = NULL; CachedResource* cachedResource = NULL; while (childFrame) { childFrameDocument = childFrame->document(); if (childFrameDocument) { cachedResource = childFrameDocument->cachedResourceLoader()->cachedResource(imageUrl); if (cachedResource) break; } cachedResource = retrieveCachedResource(childFrame, imageUrl); if (cachedResource) break; childFrame = childFrame->tree()->nextSibling(); } if (cachedResource) return cachedResource; else return frame->document()->cachedResourceLoader()->cachedResource(imageUrl); }
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; }
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; }
bool DumpRenderTreeSupportEfl::selectedRange(Evas_Object* ewkView, int* start, int* length) { if (!(start && length)) return false; DRT_SUPPRT_PAGE_GET_OR_RETURN(ewkView, page, false); if (!page->focusController() || !page->focusController()->focusedOrMainFrame()) return false; WebCore::Frame* frame = page->focusController()->focusedOrMainFrame(); RefPtr<WebCore::Range> range = frame->selection()->toNormalizedRange().get(); if (!range) return false; WebCore::Element* selectionRoot = frame->selection()->rootEditableElement(); WebCore::Element* scope = selectionRoot ? selectionRoot : frame->document()->documentElement(); RefPtr<WebCore::Range> testRange = WebCore::Range::create(scope->document(), scope, 0, range->startContainer(), range->startOffset()); *start = WebCore::TextIterator::rangeLength(testRange.get()); WebCore::ExceptionCode ec; testRange->setEnd(range->endContainer(), range->endOffset(), ec); *length = WebCore::TextIterator::rangeLength(testRange.get()); return true; }
void wxWebView::OnPaint(wxPaintEvent& event) { if (m_beingDestroyed || !m_mainFrame) return; WebCore::Frame* frame = m_mainFrame->GetFrame(); if (!frame || !frame->view()) return; wxAutoBufferedPaintDC dc(this); if (IsShown() && frame->document()) { #if USE(WXGC) wxGCDC gcdc(dc); #endif if (dc.IsOk()) { wxRect paintRect = GetUpdateRegion().GetBox(); #if USE(WXGC) WebCore::GraphicsContext gc(&gcdc); #else WebCore::GraphicsContext gc(&dc); #endif if (frame->contentRenderer()) { frame->view()->layoutIfNeededRecursive(); frame->view()->paint(&gc, paintRect); } } } }
// static WebRange WebRange::fromDocumentRange(WebFrame* frame, int start, int length) { WebCore::Frame* webFrame = static_cast<WebFrameImpl*>(frame)->frame(); Element* selectionRoot = webFrame->selection()->rootEditableElement(); Element* scope = selectionRoot ? selectionRoot : webFrame->document()->documentElement(); return TextIterator::rangeFromLocationAndLength(scope, start, length); }
void DumpRenderTreeSupportQt::setMediaType(QWebFrame* frame, const QString& type) { WebCore::Frame* coreFrame = QWebFramePrivate::core(frame); WebCore::FrameView* view = coreFrame->view(); view->setMediaType(type); coreFrame->document()->styleSelectorChanged(RecalcStyleImmediately); view->layout(); }
void BWebPage::handleMouseWheelChanged(BMessage* message) { WebCore::Frame* frame = fMainFrame->Frame(); if (!frame->view() || !frame->document()) return; PlatformWheelEvent event(message); frame->eventHandler()->handleWheelEvent(event); }
void WebView::OnPaint(wxPaintEvent& event) { if (m_beingDestroyed || !m_mainFrame) return; WebCore::Frame* frame = m_mainFrame->GetFrame(); if (!frame || !frame->view()) return; // we can't use wxAutoBufferedPaintDC here because it will not create // a 32-bit bitmap for its buffer. #if __WXMSW__ wxPaintDC paintdc(this); int width, height; paintdc.GetSize(&width, &height); wxBitmap bitmap(width, height, 32); wxMemoryDC dc(bitmap); #else wxPaintDC dc(this); #endif if (IsShown() && frame->document()) { #if USE(WXGC) #if wxCHECK_VERSION(2, 9, 2) && defined(wxUSE_CAIRO) && wxUSE_CAIRO wxGraphicsRenderer* renderer = wxGraphicsRenderer::GetCairoRenderer(); if (!renderer) renderer = wxGraphicsRenderer::GetDefaultRenderer(); wxGraphicsContext* context = renderer->CreateContext(dc); wxGCDC gcdc(context); #else wxGCDC gcdc(dc); #endif #endif if (dc.IsOk()) { wxRect paintRect = GetUpdateRegion().GetBox(); #if USE(WXGC) WebCore::GraphicsContext gc(&gcdc); #else WebCore::GraphicsContext gc(&dc); #endif if (frame->contentRenderer()) { frame->view()->updateLayoutAndStyleIfNeededRecursive(); frame->view()->paint(&gc, paintRect); #if __WXMSW__ dc.SelectObject(wxNullBitmap); paintdc.DrawBitmap(bitmap, 0, 0); #endif } } } }
void BWebPage::handleKeyEvent(BMessage* message) { WebCore::Frame* frame = fPage->focusController()->focusedOrMainFrame(); if (!frame->view() || !frame->document()) return; PlatformKeyboardEvent event(message); // Try to let WebCore handle this event if (!frame->eventHandler()->keyEvent(event) && message->what == B_KEY_DOWN) { // Handle keyboard scrolling (probably should be extracted to a method.) ScrollDirection direction; ScrollGranularity granularity; BString bytes = message->FindString("bytes"); switch (bytes.ByteAt(0)) { case B_UP_ARROW: granularity = ScrollByLine; direction = ScrollUp; break; case B_DOWN_ARROW: granularity = ScrollByLine; direction = ScrollDown; break; case B_LEFT_ARROW: granularity = ScrollByLine; direction = ScrollLeft; break; case B_RIGHT_ARROW: granularity = ScrollByLine; direction = ScrollRight; break; case B_HOME: granularity = ScrollByDocument; direction = ScrollUp; break; case B_END: granularity = ScrollByDocument; direction = ScrollDown; break; case B_PAGE_UP: granularity = ScrollByPage; direction = ScrollUp; break; case B_PAGE_DOWN: granularity = ScrollByPage; direction = ScrollDown; break; default: return; } frame->eventHandler()->scrollRecursively(direction, granularity); } }
static void printFrames(const WebCore::Frame& frame, const WebCore::Frame* targetFrame, int indent) { if (&frame == targetFrame) { printf("--> "); printIndent(indent - 1); } else printIndent(indent); WebCore::FrameView* view = frame.view(); printf("Frame %p %dx%d\n", &frame, view ? view->width() : 0, view ? view->height() : 0); printIndent(indent); printf(" ownerElement=%p\n", frame.ownerElement()); printIndent(indent); printf(" frameView=%p\n", view); printIndent(indent); printf(" document=%p\n", frame.document()); printIndent(indent); printf(" uri=%s\n\n", frame.document()->documentURI().utf8().data()); for (WebCore::Frame* child = frame.tree().firstChild(); child; child = child->tree().nextSibling()) printFrames(*child, targetFrame, indent + 1); }
bool DumpRenderTreeSupportEfl::pauseTransition(Evas_Object* ewkFrame, const char* name, const char* elementId, double time) { WebCore::Frame* frame = EWKPrivate::coreFrame(ewkFrame); if (!frame) return false; WebCore::Element* element = frame->document()->getElementById(elementId); if (!element || !element->renderer()) return false; return frame->animation()->pauseTransitionAtTime(element->renderer(), name, time); }
int DumpRenderTreeSupportEfl::numberOfPagesForElementId(const Evas_Object* ewkFrame, const char* elementId, float pageWidth, float pageHeight) { WebCore::Frame* frame = EWKPrivate::coreFrame(ewkFrame); if (!frame) return 0; WebCore::Element *element = frame->document()->getElementById(elementId); if (!element) return 0; return WebCore::PrintContext::pageNumberForElement(element, WebCore::FloatSize(pageWidth, pageHeight)); }
unsigned DumpRenderTreeSupportEfl::activeAnimationsCount(const Evas_Object* ewkFrame) { WebCore::Frame* frame = EWKPrivate::coreFrame(ewkFrame); if (!frame) return 0; WebCore::AnimationController* animationController = frame->animation(); if (!animationController) return 0; return animationController->numberOfActiveAnimations(frame->document()); }
String DumpRenderTreeSupportEfl::counterValueByElementId(const Evas_Object* ewkFrame, const char* elementId) { WebCore::Frame* frame = EWKPrivate::coreFrame(ewkFrame); if (!frame) return String(); WebCore::Element* element = frame->document()->getElementById(elementId); if (!element) return String(); return WebCore::counterValueForElement(element); }
HRESULT STDMETHODCALLTYPE WebHTMLRepresentation::documentSource( /* [retval][out] */ BSTR* source) { if (!source) return E_FAIL; *source = 0; HRESULT hr = S_OK; COMPtr<IWebDataSource> dataSource; hr = m_frame->dataSource(&dataSource); if (FAILED(hr)) return hr; COMPtr<IStream> data; hr = dataSource->data(&data); if (FAILED(hr)) return hr; STATSTG stat; hr = data->Stat(&stat, STATFLAG_NONAME); if (FAILED(hr)) return hr; if (stat.cbSize.HighPart || !stat.cbSize.LowPart) return E_FAIL; Vector<char> dataBuffer(stat.cbSize.LowPart); ULONG read; hr = data->Read(dataBuffer.data(), static_cast<ULONG>(dataBuffer.size()), &read); if (FAILED(hr)) return hr; WebCore::Frame* frame = core(m_frame); if (!frame) return E_FAIL; WebCore::Document* doc = frame->document(); if (!doc) return E_FAIL; WebCore::TextResourceDecoder* decoder = doc->decoder(); if (!decoder) return E_FAIL; *source = WebCore::BString(decoder->encoding().decode(dataBuffer.data(), dataBuffer.size())).release(); return S_OK; }
void BWebPage::handleMouseEvent(const BMessage* message) { WebCore::Frame* frame = fMainFrame->Frame(); if (!frame->view() || !frame->document()) return; PlatformMouseEvent event(message); switch (message->what) { case B_MOUSE_DOWN: // Handle context menus, if necessary. if (event.button() == RightButton) { fPage->contextMenuController()->clearContextMenu(); WebCore::Frame* focusedFrame = fPage->focusController()->focusedOrMainFrame(); focusedFrame->eventHandler()->sendContextMenuEvent(event); // If the web page implements it's own context menu handling, then // the contextMenu() pointer will be zero. In this case, we should // also swallow the event. ContextMenu* contextMenu = fPage->contextMenuController()->contextMenu(); if (contextMenu) { BMenu* platformMenu = contextMenu->releasePlatformDescription(); if (platformMenu) { // Need to convert the BMenu into BPopUpMenu. BPopUpMenu* popupMenu = new BPopUpMenu("context menu"); for (int32 i = platformMenu->CountItems() - 1; i >= 0; i--) { BMenuItem* item = platformMenu->RemoveItem(i); popupMenu->AddItem(item, 0); } BPoint screenLocation(event.globalPosition().x() + 2, event.globalPosition().y() + 2); popupMenu->Go(screenLocation, true, true, true); delete platformMenu; } } break; } // Handle regular mouse events. frame->eventHandler()->handleMousePressEvent(event); break; case B_MOUSE_UP: frame->eventHandler()->handleMouseReleaseEvent(event); break; case B_MOUSE_MOVED: default: frame->eventHandler()->mouseMoved(event); break; } }
bool DumpRenderTreeSupportEfl::elementDoesAutoCompleteForElementWithId(const Evas_Object* ewkFrame, const String& elementId) { WebCore::Frame* frame = EWKPrivate::coreFrame(ewkFrame); if (!frame) return false; WebCore::Document* document = frame->document(); ASSERT(document); WebCore::HTMLInputElement* inputElement = static_cast<WebCore::HTMLInputElement*>(document->getElementById(elementId)); if (!inputElement) return false; return inputElement->isTextField() && !inputElement->isPasswordField() && inputElement->shouldAutocomplete(); }
QVariantList DumpRenderTreeSupportQt::firstRectForCharacterRange(QWebPage* page, int location, int length) { WebCore::Frame* frame = page->handle()->page->focusController()->focusedOrMainFrame(); QVariantList rect; if ((location + length < location) && (location + length)) length = 0; Element* selectionRoot = frame->selection()->rootEditableElement(); Element* scope = selectionRoot ? selectionRoot : frame->document()->documentElement(); RefPtr<Range> range = TextIterator::rangeFromLocationAndLength(scope, location, length); if (!range) return QVariantList(); QRect resultRect = frame->editor()->firstRectForRange(range.get()); rect << resultRect.x() << resultRect.y() << resultRect.width() << resultRect.height(); return rect; }
void wxWebView::OnPaint(wxPaintEvent& event) { if (m_beingDestroyed || !m_mainFrame) return; WebCore::Frame* frame = m_mainFrame->GetFrame(); if (!frame || !frame->view()) return; wxAutoBufferedPaintDC dc(this); if (IsShown() && frame->document()) { #if USE(WXGC) wxGCDC gcdc(dc); #endif if (dc.IsOk()) { wxRect paintRect = GetUpdateRegion().GetBox(); WebCore::IntSize offset = frame->view()->scrollOffset(); #if USE(WXGC) gcdc.SetDeviceOrigin(-offset.width(), -offset.height()); #endif dc.SetDeviceOrigin(-offset.width(), -offset.height()); paintRect.Offset(offset.width(), offset.height()); #if USE(WXGC) WebCore::GraphicsContext* gc = new WebCore::GraphicsContext(&gcdc); #else WebCore::GraphicsContext* gc = new WebCore::GraphicsContext((wxWindowDC*)&dc); #endif if (gc && frame->contentRenderer()) { if (frame->view()->needsLayout()) frame->view()->layout(); frame->view()->paintContents(gc, paintRect); } delete gc; } } }
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; }
void wxWebView::OnPaint(wxPaintEvent& event) { if (m_beingDestroyed || !m_mainFrame) return; // WebView active state is based on TLW active state. wxTopLevelWindow* tlw = dynamic_cast<wxTopLevelWindow*>(wxGetTopLevelParent(this)); if (tlw && tlw->IsActive()) m_impl->page->focusController()->setActive(true); else { m_impl->page->focusController()->setActive(false); } WebCore::Frame* frame = m_mainFrame->GetFrame(); if (!frame || !frame->view()) return; wxAutoBufferedPaintDC dc(this); if (IsShown() && frame->document()) { #if USE(WXGC) wxGCDC gcdc(dc); #endif if (dc.IsOk()) { wxRect paintRect = GetUpdateRegion().GetBox(); #if USE(WXGC) WebCore::GraphicsContext gc(&gcdc); #else WebCore::GraphicsContext gc(&dc); #endif if (frame->contentRenderer()) { frame->view()->layoutIfNeededRecursive(); frame->view()->paint(&gc, paintRect); } } } }
bool DumpRenderTreeSupportEfl::pauseSVGAnimation(Evas_Object* ewkFrame, const char* animationId, const char* elementId, double time) { #if ENABLE(SVG) WebCore::Frame* frame = EWKPrivate::coreFrame(ewkFrame); if (!frame) return false; WebCore::Document* document = frame->document(); if (!document || !document->svgExtensions()) return false; WebCore::Element* element = document->getElementById(animationId); if (!element || !WebCore::SVGSMILElement::isSMILElement(element)) return false; return document->accessSVGExtensions()->sampleAnimationAtTime(elementId, static_cast<WebCore::SVGSMILElement*>(element), time); #else return false; #endif }
QVariantList DumpRenderTreeSupportQt::selectedRange(QWebPageAdapter *adapter) { WebCore::Frame* frame = adapter->page->focusController()->focusedOrMainFrame(); QVariantList selectedRange; RefPtr<Range> range = frame->selection()->toNormalizedRange().get(); Element* selectionRoot = frame->selection()->rootEditableElement(); Element* scope = selectionRoot ? selectionRoot : frame->document()->documentElement(); RefPtr<Range> testRange = Range::create(scope->document(), scope, 0, range->startContainer(), range->startOffset()); ASSERT(testRange->startContainer() == scope); int startPosition = TextIterator::rangeLength(testRange.get()); ExceptionCode ec; testRange->setEnd(range->endContainer(), range->endOffset(), ec); ASSERT(testRange->startContainer() == scope); int endPosition = TextIterator::rangeLength(testRange.get()); selectedRange << startPosition << (endPosition - startPosition); return selectedRange; }
bool DumpRenderTreeSupportQt::isPageBoxVisible(QWebFrame* frame, int pageIndex) { WebCore::Frame* coreFrame = QWebFramePrivate::core(frame); return coreFrame->document()->isPageBoxVisible(pageIndex); }
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; }
static void Sync(JNIEnv* env, jobject obj, jint frame) { WebCore::Frame* pFrame = (WebCore::Frame*)frame; ALOG_ASSERT(pFrame, "%s must take a valid frame pointer!", __FUNCTION__); WebCore::Settings* s = pFrame->settings(); if (!s) return; WebCore::CachedResourceLoader* cachedResourceLoader = pFrame->document()->cachedResourceLoader(); #ifdef ANDROID_LAYOUT jobject layout = env->GetObjectField(obj, gFieldIds->mLayoutAlgorithm); WebCore::Settings::LayoutAlgorithm l = (WebCore::Settings::LayoutAlgorithm) env->CallIntMethod(layout, gFieldIds->mOrdinal); if (s->layoutAlgorithm() != l) { s->setLayoutAlgorithm(l); if (pFrame->document()) { pFrame->document()->styleSelectorChanged(WebCore::RecalcStyleImmediately); if (pFrame->document()->renderer()) { recursiveCleanupForFullLayout(pFrame->document()->renderer()); ALOG_ASSERT(pFrame->view(), "No view for this frame when trying to relayout"); pFrame->view()->layout(); // FIXME: This call used to scroll the page to put the focus into view. // It worked on the WebViewCore, but now scrolling is done outside of the // WebViewCore, on the UI side, so there needs to be a new way to do this. //pFrame->makeFocusVisible(); } } } #endif jint textSize = env->GetIntField(obj, gFieldIds->mTextSize); float zoomFactor = textSize / 100.0f; if (pFrame->textZoomFactor() != zoomFactor) pFrame->setTextZoomFactor(zoomFactor); jstring str = (jstring)env->GetObjectField(obj, gFieldIds->mStandardFontFamily); s->setStandardFontFamily(jstringToWtfString(env, str)); str = (jstring)env->GetObjectField(obj, gFieldIds->mFixedFontFamily); s->setFixedFontFamily(jstringToWtfString(env, str)); str = (jstring)env->GetObjectField(obj, gFieldIds->mSansSerifFontFamily); s->setSansSerifFontFamily(jstringToWtfString(env, str)); str = (jstring)env->GetObjectField(obj, gFieldIds->mSerifFontFamily); s->setSerifFontFamily(jstringToWtfString(env, str)); str = (jstring)env->GetObjectField(obj, gFieldIds->mCursiveFontFamily); s->setCursiveFontFamily(jstringToWtfString(env, str)); str = (jstring)env->GetObjectField(obj, gFieldIds->mFantasyFontFamily); s->setFantasyFontFamily(jstringToWtfString(env, str)); str = (jstring)env->GetObjectField(obj, gFieldIds->mDefaultTextEncoding); s->setDefaultTextEncodingName(jstringToWtfString(env, str)); str = (jstring)env->GetObjectField(obj, gFieldIds->mUserAgent); WebFrame::getWebFrame(pFrame)->setUserAgent(jstringToWtfString(env, str)); WebViewCore::getWebViewCore(pFrame->view())->setWebRequestContextUserAgent(); jint cacheMode = env->GetIntField(obj, gFieldIds->mOverrideCacheMode); WebViewCore::getWebViewCore(pFrame->view())->setWebRequestContextCacheMode(cacheMode); str = (jstring)env->GetObjectField(obj, gFieldIds->mAcceptLanguage); WebRequestContext::setAcceptLanguage(jstringToWtfString(env, str)); jint size = env->GetIntField(obj, gFieldIds->mMinimumFontSize); s->setMinimumFontSize(size); size = env->GetIntField(obj, gFieldIds->mMinimumLogicalFontSize); s->setMinimumLogicalFontSize(size); size = env->GetIntField(obj, gFieldIds->mDefaultFontSize); s->setDefaultFontSize(size); size = env->GetIntField(obj, gFieldIds->mDefaultFixedFontSize); s->setDefaultFixedFontSize(size); jboolean flag = env->GetBooleanField(obj, gFieldIds->mLoadsImagesAutomatically); s->setLoadsImagesAutomatically(flag); if (flag) cachedResourceLoader->setAutoLoadImages(true); flag = env->GetBooleanField(obj, gFieldIds->mMediaPreloadEnabled); s->setMediaPreloadEnabled(flag); #ifdef ANDROID_BLOCK_NETWORK_IMAGE flag = env->GetBooleanField(obj, gFieldIds->mBlockNetworkImage); s->setBlockNetworkImage(flag); if(!flag) cachedResourceLoader->setBlockNetworkImage(false); #endif flag = env->GetBooleanField(obj, gFieldIds->mBlockNetworkLoads); WebFrame* webFrame = WebFrame::getWebFrame(pFrame); webFrame->setBlockNetworkLoads(flag); flag = env->GetBooleanField(obj, gFieldIds->mJavaScriptEnabled); s->setJavaScriptEnabled(flag); flag = env->GetBooleanField(obj, gFieldIds->mAllowUniversalAccessFromFileURLs); s->setAllowUniversalAccessFromFileURLs(flag); flag = env->GetBooleanField(obj, gFieldIds->mAllowFileAccessFromFileURLs); s->setAllowFileAccessFromFileURLs(flag); // Hyperlink auditing (the ping attribute) has similar privacy // considerations as does the running of JavaScript, so to keep the UI // simpler, we leverage the same setting. s->setHyperlinkAuditingEnabled(flag); // ON = 0 // ON_DEMAND = 1 // OFF = 2 jobject pluginState = env->GetObjectField(obj, gFieldIds->mPluginState); int state = env->CallIntMethod(pluginState, gFieldIds->mOrdinal); s->setPluginsEnabled(state < 2); #ifdef ANDROID_PLUGINS s->setPluginsOnDemand(state == 1); #endif #if ENABLE(OFFLINE_WEB_APPLICATIONS) // We only enable AppCache if it's been enabled with a call to // setAppCacheEnabled() and if a valid path has been supplied to // setAppCachePath(). Note that the path is applied to all WebViews // whereas enabling is applied per WebView. // WebCore asserts that the path is only set once. Since the path is // shared between WebViews, we can't do the required checks to guard // against this in the Java WebSettings. bool isPathValid = false; if (cacheStorage().cacheDirectory().isNull()) { str = static_cast<jstring>(env->GetObjectField(obj, gFieldIds->mAppCachePath)); // Check for non-null string as an optimization, as this is the common case. if (str) { String path = jstringToWtfString(env, str); ALOG_ASSERT(!path.empty(), "Java side should never send empty string for AppCache path"); // This database is created on the first load. If the file // doesn't exist, we create it and set its permissions. The // filename must match that in ApplicationCacheStorage.cpp. String filename = pathByAppendingComponent(path, "ApplicationCache.db"); int fd = open(filename.utf8().data(), O_CREAT, permissionFlags660); if (fd >= 0) { close(fd); cacheStorage().setCacheDirectory(path); isPathValid = true; } } } else isPathValid = true; flag = env->GetBooleanField(obj, gFieldIds->mAppCacheEnabled); s->setOfflineWebApplicationCacheEnabled(flag && isPathValid); jlong maxsize = env->GetLongField(obj, gFieldIds->mAppCacheMaxSize); cacheStorage().setMaximumSize(maxsize); #endif flag = env->GetBooleanField(obj, gFieldIds->mJavaScriptCanOpenWindowsAutomatically); s->setJavaScriptCanOpenWindowsAutomatically(flag); #ifdef ANDROID_LAYOUT flag = env->GetBooleanField(obj, gFieldIds->mUseWideViewport); s->setUseWideViewport(flag); #endif #ifdef ANDROID_MULTIPLE_WINDOWS flag = env->GetBooleanField(obj, gFieldIds->mSupportMultipleWindows); s->setSupportMultipleWindows(flag); #endif flag = env->GetBooleanField(obj, gFieldIds->mShrinksStandaloneImagesToFit); s->setShrinksStandaloneImagesToFit(flag); jlong maxImage = env->GetLongField(obj, gFieldIds->mMaximumDecodedImageSize); // Since in ImageSourceAndroid.cpp, the image will always not exceed // MAX_SIZE_BEFORE_SUBSAMPLE, there's no need to pass the max value to // WebCore, which checks (image_width * image_height * 4) as an // estimation against the max value, which is done in CachedImage.cpp. // And there're cases where the decoded image size will not // exceed the max, but the WebCore estimation will. So the following // code is commented out to fix those cases. // if (maxImage == 0) // maxImage = computeMaxBitmapSizeForCache(); s->setMaximumDecodedImageSize(maxImage); flag = env->GetBooleanField(obj, gFieldIds->mPrivateBrowsingEnabled); s->setPrivateBrowsingEnabled(flag); flag = env->GetBooleanField(obj, gFieldIds->mSyntheticLinksEnabled); s->setDefaultFormatDetection(flag); s->setFormatDetectionAddress(flag); s->setFormatDetectionEmail(flag); s->setFormatDetectionTelephone(flag); #if ENABLE(DATABASE) flag = env->GetBooleanField(obj, gFieldIds->mDatabaseEnabled); WebCore::Database::setIsAvailable(flag); flag = env->GetBooleanField(obj, gFieldIds->mDatabasePathHasBeenSet); if (flag) { // If the user has set the database path, sync it to the DatabaseTracker. str = (jstring)env->GetObjectField(obj, gFieldIds->mDatabasePath); if (str) { String path = jstringToWtfString(env, str); DatabaseTracker::tracker().setDatabaseDirectoryPath(path); // This database is created when the first HTML5 Database object is // instantiated. If the file doesn't exist, we create it and set its // permissions. The filename must match that in // DatabaseTracker.cpp. String filename = SQLiteFileSystem::appendDatabaseFileNameToPath(path, "Databases.db"); int fd = open(filename.utf8().data(), O_CREAT | O_EXCL, permissionFlags660); if (fd >= 0) close(fd); } } #endif #if ENABLE(DOM_STORAGE) flag = env->GetBooleanField(obj, gFieldIds->mDomStorageEnabled); s->setLocalStorageEnabled(flag); str = (jstring)env->GetObjectField(obj, gFieldIds->mDatabasePath); if (str) { WTF::String localStorageDatabasePath = jstringToWtfString(env,str); if (localStorageDatabasePath.length()) { localStorageDatabasePath = WebCore::pathByAppendingComponent( localStorageDatabasePath, "localstorage"); // We need 770 for folders mkdir(localStorageDatabasePath.utf8().data(), permissionFlags660 | S_IXUSR | S_IXGRP); s->setLocalStorageDatabasePath(localStorageDatabasePath); } } #endif flag = env->GetBooleanField(obj, gFieldIds->mGeolocationEnabled); GeolocationPermissions::setAlwaysDeny(!flag); str = (jstring)env->GetObjectField(obj, gFieldIds->mGeolocationDatabasePath); if (str) { String path = jstringToWtfString(env, str); GeolocationPermissions::setDatabasePath(path); GeolocationPositionCache::instance()->setDatabasePath(path); // This database is created when the first Geolocation object is // instantiated. If the file doesn't exist, we create it and set its // permissions. The filename must match that in // GeolocationPositionCache.cpp. String filename = SQLiteFileSystem::appendDatabaseFileNameToPath(path, "CachedGeoposition.db"); int fd = open(filename.utf8().data(), O_CREAT | O_EXCL, permissionFlags660); if (fd >= 0) close(fd); } flag = env->GetBooleanField(obj, gFieldIds->mXSSAuditorEnabled); s->setXSSAuditorEnabled(flag); #if ENABLE(LINK_PREFETCH) flag = env->GetBooleanField(obj, gFieldIds->mLinkPrefetchEnabled); s->setLinkPrefetchEnabled(flag); #endif size = env->GetIntField(obj, gFieldIds->mPageCacheCapacity); if (size > 0) { s->setUsesPageCache(true); WebCore::pageCache()->setCapacity(size); } else s->setUsesPageCache(false); #if ENABLE(WEB_AUTOFILL) flag = env->GetBooleanField(obj, gFieldIds->mAutoFillEnabled); // TODO: This updates the Settings WebCore side with the user's // preference for autofill and will stop WebCore making requests // into the chromium autofill code. That code in Chromium also has // a notion of being enabled/disabled that gets read from the users // preferences. At the moment, it's hardcoded to true on Android // (see chrome/browser/autofill/autofill_manager.cc:405). This // setting should probably be synced into Chromium also. s->setAutoFillEnabled(flag); if (flag) { EditorClientAndroid* editorC = static_cast<EditorClientAndroid*>(pFrame->page()->editorClient()); WebAutofill* webAutofill = editorC->getAutofill(); // Set the active AutofillProfile data. jobject autoFillProfile = env->GetObjectField(obj, gFieldIds->mAutoFillProfile); if (autoFillProfile) syncAutoFillProfile(env, autoFillProfile, webAutofill); else { // The autofill profile is null. We need to tell Chromium about this because // this may be because the user just deleted their profile but left the // autofill feature setting enabled. webAutofill->clearProfiles(); } } #endif // This is required to enable the XMLTreeViewer when loading an XML document that // has no style attached to it. http://trac.webkit.org/changeset/79799 s->setDeveloperExtrasEnabled(true); s->setSpatialNavigationEnabled(true); bool echoPassword = env->GetBooleanField(obj, gFieldIds->mPasswordEchoEnabled); s->setPasswordEchoEnabled(echoPassword); }